1

I am building an advanced image handler for Joomla 3x where images are built dynamically at run-time based on a number of parameters defined in tags inserted into articles. An example look like this:

{imgh}>>JSON code<<{/imgh}

where >>JSON code<< code could be as simple as this:

{"cmd": "get_image", "id": 306, "w": 600}

The JSON code translates into: "Fetch image with ID = 306, scale it to a width of 600 pixels (using Imagick) and return the <IMG...> tag to me complete with ALT text (fetched from database), download links, upscale links using modals etc.

I have managed to make it work (example at https://cnj.dk/gliding/jorn-rehne-andersen-fotoalbum-1982) but there is an efficiency problem with long articles containing many {imgh} tags. It turns out that even though a large article is broken into smaller pieces using "system-pagebreak" (the "insert Page Break" button in the editor), my "content" plugin will still be presented with the full article at every page display. Thus it will run the interpreter code on each and every {imgh} tag found in the entire article, even though it is only supposed to present a tiny fraction of it. From my plugin I could decide to count the appearances of the '<hr class="system-pagebreak" title="XXXX" />' and only work on the relevant ones but how can my plugin determine which page it is on?

Due to this problem the site linked above does not use "system-pagebreak" but I manually split it into sub-articles. That is not optimal though.

4
  • Which plugin event are you using?
    – Sharky
    Jan 30 at 21:52
  • Sharky: "Content" Jan 31 at 18:47
  • That's the plugin group. What's the name of the method in your plugin (e.g. onContentPrepare)?
    – Sharky
    Feb 1 at 6:55
  • Sorry, Sharky, it is "onContentPrepare". Feb 2 at 13:22
1

To answer your question, add a fourth optional argument to your onContentPrepare method. This will be the page number.

public function onContentPrepare($context, $item, $params, $page = 0)

Note that page numbering starts at 0 and sometimes first page can be null. You would also need to account for "All Pages" page.

However, after some testing, I think you don't really need this. Instead you could solve the issue by ordering your plugin after Content - Page Break plugin . This is because Page Break plugin does modify $item->text property to contain only the current page.

1
  • OMG, you are absolutely right, Sharky, I can tell by debugging. First method is somewhat inconvenient because, it turns out, both "first page" and "all pages" get identified by $page = NULL. Second method, however, works like a charm. Thanks a lot. I will credit you for the right answer:-) Feb 5 at 14:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.