Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2025-08-03 03:37:57

giz
Plugin Author
From: New Zealand
Registered: 2004-07-26
Posts: 360
Website GitHub Twitter

How do I avoid getting “Restricted area” errors?

I’m almost there with a new plugin, all_pic, but am stumped.

How can I safely run an admin-side Ajax request in Textpattern 4.9+ from a plugin (Type 4), triggered by a blur() or change() event, to fetch dynamic field data — and avoid getting“Restricted area” errors?


// php
if(@txpinterface == 'admin') {
	register_callback('all_pic','article');
	register_callback('all_pic_css','admin_side','head_end');
	register_callback('all_pic_js_config', 'admin_side', 'head_end');
	register_callback('all_pic_js', 'admin_side', 'head_end');
	register_callback('all_pic_ajax_get_thumbs', 'all_pic', 'get_thumbs');
	//register_callback('all_pic_ajax_get_thumbs', 'admin-ajax', 'all_pic_get_thumbs');
}


function all_pic_ajax_get_thumbs() {
	if (!is_logged_in()) {
		exit('Not authorized');
	}

	$ids = gps('ids');
	if (!$ids) {
		exit('No IDs provided');
	}

	$idArray = explode(',', $ids);
	echo all_pic_render_thumbs($idArray);
	exit;
}

// js line 62 https://github.com/gizulor/all_pic/blob/main/all_pic.js 

$thumbInputs.on('input', debounce(function() {
      const $input = $(this);
      const container = $input.next().find('.all_pics');
      const value = $input.val().split(/[ ,]+/).map(s => s.trim()).filter(Boolean);

      const currentIds = container.find('.all_pics__item').map(function() {
        return this.className.replace(/.*id(\d+).*/, '$1');
      }).get();

      // Remove missing thumbs
      currentIds.forEach(id => {
        if (!value.includes(id)) {
          container.find(`.id${id}`).remove();
        }
      });

      const newIds = value.filter(id => !currentIds.includes(id));
      if (!newIds.length) return;

      // Fetch thumbs
      $.ajax({
        url: '/textpattern/index.php',
        method: 'POST',
        data: {
          event: 'all_pic',
          step: 'get_thumbs',
          ids: newIds.join(',')
        },
        success: function(html) {
          const $temp = $('<div>').html(html);
          newIds.forEach(function(id) {
            const $thumb = $temp.find(`.id${id}`);
            if ($thumb.length) {
              container.append($thumb);
            } else {
              console.warn(`No thumb found in Ajax for id ${id}`);
            }
          });
        },
        error: function(xhr) {
          console.error('Ajax thumb fetch failed:', xhr.responseText);
        }
      });
    }, 400));

all_pic

  • In the Write panel, find and add images to the Article Image field or any specified custom field
  • The default Images panel opens in a SideView, providing full search and edit capabilities
  • Build gallery shortcodes for insertion into any textarea
  • Thumbnail previews, reordered via dragging

What started as an attempt to get bot_image_upload to work properly with multiple fields, branched off into a hacked-together but largely functional variant.

Since then I’ve had help from a friendly LLM (ChatGTP). I’m interested in everyones’ opinion on the code.

Offline

#2 2025-08-03 10:05:07

etc
Developer
Registered: 2010-11-11
Posts: 5,420
Website GitHub

Re: How do I avoid getting “Restricted area” errors?

I think you should (at least) add _txp_token to your data, see e.g. l.598 of textpattern.js.

Offline

#3 2025-08-03 19:17:36

giz
Plugin Author
From: New Zealand
Registered: 2004-07-26
Posts: 360
Website GitHub Twitter

Re: How do I avoid getting “Restricted area” errors?

etc wrote #340055:

I think you should (at least) add _txp_token to your data, see e.g. l.598 of textpattern.js.

Thanks; on-it!

Offline

#4 2025-08-15 20:30:16

giz
Plugin Author
From: New Zealand
Registered: 2004-07-26
Posts: 360
Website GitHub Twitter

Re: How do I avoid getting “Restricted area” errors?

Can I be added to the Plugin Authors group?

Thanks!

Offline

#5 2025-08-15 20:44:17

gaekwad
Server grease monkey
From: People's Republic of Cornwall
Registered: 2005-11-19
Posts: 4,408
GitHub

Re: How do I avoid getting “Restricted area” errors?

giz wrote #340199:

Can I be added to the Plugin Authors group?

Please proceed to github.com/textpattern/textpattern.github.io/issues and fill out the paperwork (choose: ‘Register author prefix’ issue type), operators are standing by.

(Plus it lets me check the docs site updates are working as expected.)

Offline

#6 2025-08-15 20:55:32

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,862
Website GitHub

Re: How do I avoid getting “Restricted area” errors?

giz wrote #340199:

Can I be added to the Plugin Authors group?

I presume you mean on the forum, as your ‘all’ prefix is already registered.

Edit: Done.

Last edited by Bloke (2025-08-15 20:58:12)


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Online

#7 Yesterday 00:08:34

giz
Plugin Author
From: New Zealand
Registered: 2004-07-26
Posts: 360
Website GitHub Twitter

Re: How do I avoid getting “Restricted area” errors?

Thanks!

Offline

Board footer

Powered by FluxBB