Announcement

  •  » Engine
  •  » plug-in help

#1 2010-11-09 20:33:52

stellablue
Member
Hawaii
2010-10-25
14

plug-in help

Hi piwigo developers,

I wrote a plug-in, named pAnchor, for piwigo that greatly improves browsing and slideshow experience by embedding a html page anchor on picture page and plug-in adds #anchor_name to all the relevant urls on the picture.php page for both static view and slideshow view.  works nice!

My question is that in order for this plug-in to work, the template needs <a id="pAnchor" name="{$PANCHOR_NAME}"></a>, so what is best way for plug-in to add element  to template or does this require manual edit of picture.tpl to add element?  User could be using any theme and customized in almost any way possible. Plus end user may want to locate the anchor in different part of page for  their specific case.

thanks - stellablue

Last edited by stellablue (2010-11-09 20:37:46)

Offline

 

#2 2010-11-09 21:18:02

ddtddt
Piwigo Team
Quetigny - France
2007-07-27
7207

Re: plug-in help

Hi :-)

You can use prefilter
http://www.smarty.net/manual/en/advance … ilters.php

In Piwigo

add_event_handler('loc_begin_picture', 'namefunction1');

function namefunction1()
{
    global $template;
    $template->set_prefilter('picture', 'namefunction2');
}

function namefunction1($content, &$smarty)
{
  $search = 'elementA';
 
  $replacement = 'elementA + your code';

  return preg_replace($search, $replacement, $content);
}

exemple [extension by ddtddt] AddInfo on picture page


You love Piwigo so don't hesitate to participate, learn more on the "Contribute to Piwigo" page. If you don't have much time for contribution, you can also help the project with a donation.

Offline

 

#3 2010-11-09 21:24:18

plg
Piwigo Team
Nantes, France, Europe
2002-04-05
13791

Re: plug-in help

I was also answering to your question stellablue and I also advise your to use Smarty prefilters. Here is my version of the plugin code:

Code:

add_event_handler('loc_end_picture', 'pAnchor_add_anchor');
function pAnchor_add_anchor()
{
  global $template;
  $template->set_prefilter('picture', 'pAnchor_add_anchor_prefilter');
}

function pAnchor_add_anchor_prefilter($content, &$smarty)
{
  $search = '#<div id="imageHeaderBar"#';
  $replacement = '<a name="pAnchor"></a><div id="imageHeaderBar"';
  return preg_replace($search, $replacement, $content);
}

In this very specific case, you can also write

Code:

add_event_handler('loc_end_picture', 'pAnchor_add_anchor');
function pAnchor_add_anchor()
{
  global $template;
  $template->assign(
    'PLUGIN_PICTURE_BEFORE',
    '<a name="pAnchor"></a>'
    );
}

but this is very very specific, you'd better learn to use Smarty prefilters, they let you do nearly anything you need to transform *.tpl files.

Offline

 

#4 2010-11-09 21:27:32

plg
Piwigo Team
Nantes, France, Europe
2002-04-05
13791

Re: plug-in help

In the set_prefilter function, the first argument is "picture". This is the key corresponding to picture.tpl file for the $template->set_filenames function call. "grep picture.tpl" on *.php files.

Code:

  $template->set_filenames( array('picture' => 'picture.tpl'));

Offline

 

#5 2010-11-09 22:16:35

stellablue
Member
Hawaii
2010-10-25
14

Re: plug-in help

Thanks ddtddt & plg!!  prefilter will do the trick.  Can I be assured that  <div id="imageToolBar"> exists in .tpl?  Do all themes have this element to reference?  I suppose it could fail gracefully if div not found or push error and inform user to disable plug-in or manual place <a name="{$PANCHOR_NAME}></a> in picture.tpl.

well, let me implement the prefilter.  Is best way to add a single css style definition (for this plugin) by using the $template->append('header_elements', $css_code)?  - stellablue

(edit:  grep totally awesome, use it plenty to search within piwigo for vars, trigger_events and such!)

Last edited by stellablue (2010-11-09 22:19:21)

Offline

 

#6 2010-11-09 22:23:58

ddtddt
Piwigo Team
Quetigny - France
2007-07-27
7207

Re: plug-in help

stellablue wrote:

Is best way to add a single css style definition (for this plugin) by using the $template->append('header_elements', $css_code)?  - stellablue

Yes it's a good solution


You love Piwigo so don't hesitate to participate, learn more on the "Contribute to Piwigo" page. If you don't have much time for contribution, you can also help the project with a donation.

Offline

 

#7 2010-11-09 22:44:12

stellablue
Member
Hawaii
2010-10-25
14

Re: plug-in help

great thanks!  Ok, got the prefilter in and plug-in works!  question I have is I had followed a post on plug-in development that made my plug-in a class and the add_event_handler call was different that what you recommended (ref [Forum, topic 14880] Create a Piwigo extension for dumies).

I just left those functions you recommended  out of the class definition.  But how should plug-ins be made as public functions or classes?

here are the 2 statements (first is part of  pAnchor class in $obj):

add_event_handler('render_element_content', array(&$obj, 'pAnchor_links'),50,2);

(this is what you recommended)
add_event_handler('loc_end_picture', 'pAnchor_add_anchor');


Could I have put your functions in pAnchor class and setup proper pre-filter?

thanks again - stellablue

PS: when plug-in totally polished, what is recommend testing & submittal to pwigo?

Offline

 

#8 2010-11-17 01:27:30

plg
Piwigo Team
Nantes, France, Europe
2002-04-05
13791

Re: plug-in help

stellablue wrote:

But how should plug-ins be made as public functions or classes?

It's up to you. Some coders prefer classes (like grum), some other don't care that much (like me).

The only thing I've been blocked recently was that I couldn't use a class method for setting a prefilter.

stellablue wrote:

PS: when plug-in totally polished, what is recommend testing & submittal to pwigo?

I recommend:

1) you create your extension on http://piwigo.org/ext
2) you ask for a place on Subversion repository (there is a button on http://piwigo.org/ext for your extension)
3) you commit your code into Subversion
4) you release a first revision (describe it as "for beta test only") and ask for tests on the forum
5) fix bugs/add features/publish new revisions of your plugin

Offline

 

#9 2010-11-17 21:56:34

stellablue
Member
Hawaii
2010-10-25
14

Re: plug-in help

Hi plg,

thanks for your help.  Yes, I ran into same road-block with prefilter inside class definition.  No matter how you specify the prefilter function, php kicks back an error.  Must be something inherit in smarty about resolving the prefilter function address inside an class object, no?

I will create my extensions at the link you provided. 
  1.  The pAnchor one (adds # page anchor to urls for improved browsing) works well.  It searches for the <div id="imageHeaderBar"> by default and adds the anchor.  The search string is defined in main.inc.php for the plugin and can be adjusted for different templates.

2. the pGravator plugin sets a template array variable {$gravatars} with the gravatar image urls.  Now, I adjusted comments-list.tpl for my theme to utilize this variable and style correctly.  How would others implement this?  Is it ok to expect piwigo users to adjust .tpl / css for a plug-in?  I could provide snippets so users can incorporate into their theme. 

3. the fsSlideShow plugin is the fullscreen flash slideshow works good, but I have discovered some licensing issues.  I am exploring an open-source solution so a fullscreen plugin is available.  if you wish to discuss please send pm or to my account e-mail.

thanks again for your help and patience with a piwigo rookie ;-)

Offline

 
  •  » Engine
  •  » plug-in help

Board footer

Powered by FluxBB

github twitter newsletter Donate Piwigo.org © 2002-2024 · Contact