rewrite token for gallery page url


several themes uses gallery.php as index page for their gallery (as offical zenpage and garland themes).

rewriteToken plugin allows to change some rewrited url.
but it doesn't allow to rewrite gallery url and it remains page/gallery

if you think it's a good idea, could you update this plugin to enable a token to change gallery url as needed?


  • acrylian Administrator
    edited October 2017

    The reason there is no rewrite token is that this is a plain custom page ulr (in theme terms).

    We will probably not add anything for it at this time as we have other ideas for this page going on. Since there is a mismatch in url structure if this is the base gallery url in relation to album pages anyway. It may be decoupled from the custom page url just like Zenpage pages are in the future. Then there will be surely a way to define its name.

  • sbillard Member
    edited October 2017
     * creates a rewrite rule for "page/gallery" and modifies the link to same to
     * follow the rule.
     * @author Stephen Billard (sbillard)
    $plugin_is_filter = 5 | FEATURE_PLUGIN;
    $plugin_description = gettext('Rewrite rule for the gallery custom page.');
    $plugin_author = "Stephen Billard (sbillard)";
    $_zp_conf_vars['special_pages']['gallery'] = array('define'  => '_GALLERY_PAGE_', 'rewrite'  => getOption('galleryToken_link'),
                    'option'     => 'galleryToken_link', 'default'   => '_PAGE_/gallery');
    $_zp_conf_vars['special_pages'][] = array('definition' => '%GALLERY_PAGE%', 'rewrite' => '_GALLERY_PAGE_');
    $_zp_conf_vars['special_pages'][] = array('define' => false, 'rewrite' => '%GALLERY_PAGE%', 'rule' => '^%REWRITE%/*$        index.php?p=' . 'gallery' . ' [L,QSA]');
  • vincent3569 Member
    edited October 2017

    thanks Stephen.

    my final plugin is as following:

    * creates a rewrite rule for "page/gallery".
    * @author Stephen Billard (sbillard)
    * @package plugins
    * @subpackage development
    $plugin_description=gettext('Rewrite rule for the gallery page.');
    $plugin_author="Stephen Billard";
    $_zp_conf_vars['special_pages']['gallery']=array('define' => '_GALLERY_PAGE_', 'rewrite' => getOption('gallery_link'), 'option' => 'gallery_link', 'default' => '_PAGE_/gallery');
    $_zp_conf_vars['special_pages'][]=array('definition' => '%GALLERY_PAGE%', 'rewrite' => '_GALLERY_PAGE_');
    $_zp_conf_vars['special_pages'][]=array('define' => false, 'rewrite' => '%GALLERY_PAGE%', 'rule' => '^%REWRITE%/*$ index.php?p=' . 'gallery' . ' [L,QSA]');
  • but it doesn't work.

    I have this in my admin:

    Rewrite Rules
    #### Definitions
    Define %GALLERY_PAGE%       gallery 


     #### Rules created by plugins
    rewriterule ^gallery/*$     index.php?p=gallery [L,QSA]


    Rewrite Tokens
    _GALLERY_PAGE_          gallery 

    but the rewrited url remains [domain_name]/page/gallery/

  • How are you creating the url?

  • vincent3569 Member
    edited October 2017

    I suppose it is linked with this function getGalleryIndexURL().
    there is this code:

        $custom_index = getOption('custom_index_page');
        if ($custom_index) {
            $link = rewrite_path('/' . _PAGE_ . '/' . $custom_index . '/', "/index.php?p=" . $custom_index);
        } else {
            $link = WEBPATH . "/";

    I really don't know if it follows the internal rewrite engine of Zenphoto and if rewrite token may be applied in that case.

  • Yes, that function does not do the rewrite rules. You should use the function getCustomPageURL() instead.

    Really, the getGalleryIndexURL() function should only return the index.php page. Themes should know if they are having a "gallery" page for the albums and act accordingly using getCustomPageURL('gallery') for the link. That is how it is with ZenPhoto20. Much less prone to error.

  • vincent3569 Member
    edited October 2017

    something goes wrong somewhere...
    I use printCustomPageURL(gettext('Gallery'), 'gallery'); in my theme, but it doesn't display the rewrited link.

    I add var_dump($_zp_conf_vars['special_pages']['gallery']); in my header and it return NULL.

    so it seems that plugin doesn't add values to $_zp_conf_vars['special_pages']

    and in the other hand, in this template function

    function getCustomPageURL($page, $q = '') {
        global $_zp_current_album, $_zp_conf_vars;
        if (array_key_exists($page, $_zp_conf_vars['special_pages'])) {
            $result_r = preg_replace('~^_PAGE_/~', _PAGE_ . '/', $_zp_conf_vars['special_pages'][$page]['rewrite']) . '/';
        } else {
            $result_r = '/' . _PAGE_ . '/' . $page . '/';

    we are allways in the else statement.

  • Are you sure the galleryToken plugin is enabled? Sure sounds like it is not. Also check the rewriteTokens plugin options to be sure that "gallery" is shown and has a value.

    I think also that the script above has an error. Probably should read $plugin_is_filter=5|CLASS_PLUGIN; to be sure it is loaded on the front end.

  • actually, the line should be as I originally quoted it: $plugin_is_filter=5|ADMIN_PLUGIN; but CLASS_PLUGIN should work as well.

  • Woops. forgot to check the text paste. Should be $plugin_is_filter=5|FEATURE_PLUGIN;

  • vincent3569 Member
    edited October 2017

    yes, galleryToken plugin is enabled.

    I change $plugin_is_filter as described and it works now.
    But I have a new trouble: get/printCustomPageURL() doesn't manage page number for gallery pages.

  • acrylian Administrator
    edited October 2017

    Actually it has a second parameter to append extra queries such as the page number. That should be something like &page=<number> actually.

    Btw, we have some plans with the gallery page that will also involve changes to the "galleryindex" page handling in the future.

  • vincent3569 Member
    edited October 2017

    yes of course.

    the fact is that getGalleryIndexURL() displays the page number organically, while with get/printCustomPageURL(), we have to calculate it before we call the function.

    I will be patient and I will waiting for the major release...

  • acrylian Administrator
    edited October 2017

    Internally getGalleryIndexURL() just does this:
    if (in_context(ZP_ALBUM) && $_zp_gallery_page != 'index.php') { $album = getUrAlbum($_zp_current_album); if (($page = $album->getGalleryPage()) > 1) { <link here> } }

    It also would use a custom index page if the the option custom_index_page is set.

    We have some term issues since normally "gallery" means the Zenphoto site in total so by default the home page isthe gallery index (= top level albums). Using a gallery page it is not or you even have two "gallery index" pages depending on the theme used.

    Thanks for the patience though. I would love it to happen faster.

  • I am a little confused here. Can you explain more on how you are using this? Normally the getGalleryIndexURL() and getCustomPageURL() are used when you are NOT on the target page. If that is the case how do you determine which page of the gallery the link should point to?

    If you are on the albums pages then the breadcrumbs functions should give you the correct (rewritten) links to other pages within the "gallery." However, that seems not the case. So a bug in those functions?

  • hi

    have a look on zenpage theme.
    in gallery.php, album.php and image.php, breadcrumb uses printGalleryIndexURL(), and in sidebar.php, the link to the gallery uses printCustomPageURL().

    if you have a gallery with more than one page, and your are on an album of the 2nd page, the gallery link in the breadcrumb gives you this url page/gallery/2/ and the gallery link in the sidebar gives you page/gallery/.

    for me it's OK because in the breadcrumb, I want to know on witch page I am (and go back to the right gallery page) and in sidebar, I don't want pagination (I only want to point to the root of the gallery).

    BUT, the printGalleryIndexURL() link can't be rewrited contrary to printGalleryIndexURL().

  • acrylian Administrator

    This function allows any page to be the index page. It simply does not know which page it is going to use until it gets the name set via the "custom_index_page" option which usees the page name and does not know about any rewriting. This is in this case "gallery".

    To rewrite this you need to hook into the getLink filter and modify the link there. That's called after the link is generated within that function.

  • unfortunatly, I don't understand nothing :-(
    you have to be more clear within an example

  • acrylian Administrator
    edited October 2017

    You need a plugin that also hooks on the getLink filter and then modify the url before returning it to match the rewritten one.

    zp_register_filter('getLink', 'modify_url'); function modify_url($link, $page) { if($page == "index.php") { // $link the is the url you need to modify to your rewrittten one } return $link; }

    Very quick example offhand, not tested.

  • There are two problems (bugs) that need to be fixed. First, the template-functions.php function getPageNumURL() needs to be fixed to handle custom pages:

    $pg = stripSuffix($_zp_gallery_page); if (array_key_exists($pg, $_zp_conf_vars['special_pages'])) { $pagination1 = preg_replace('~^_PAGE_/~', _PAGE_ . '/', $_zp_conf_vars['special_pages'][$pg]['rewrite']) . '/'; } else { $pagination1 = '/' . _PAGE_ . '/' . $pg . '/'; }

    Then the galleryToken plugin needs to have added a rewrite rule for handling the page numbers:

    $_zp_conf_vars['special_pages'][] = array('define' => false, 'rewrite' => '%GALLERY_PAGE%/([0-9]+)', 'rule' => '^%REWRITE%/*$ index.php?p=gallery&page=$1' . ' [L,QSA]');

  • acrylian Administrator

    Thanks for this actual contribution. Will look into that as soon as I get the time.

  • acrylian Administrator

    @vincent3569 I have decided I will add this to core tomorrow.

  • vincent3569 Member
    edited October 2017

    thanks Malte and Stephen!
    I made a pull request to fix a typo on the new getCustomGalleryIndexPage() function.

    with that, it works fine for my needs.

  • I do not see a "PAGE/gallery" value in admin>options>extensions>rewriteToken.

    Is it the right place to set the gallery url ?
    I use Zenphoto 1.4.14

  • acrylian Administrator
    edited February 27

    The change discussed is not in 1.4.14 but in the coming version 1.5. You can preview that as the support build (or master) from Github.

  • That's that, I just understand that the master branch is the one with the last commits. I have tested it, it's ok.

    The zip linked on the homepage is Zenphoto 1.4.14 Jan 28, 2017, and the new function since october 2017, so I mistakenly thought it was included.

  • acrylian Administrator

    We only will change the numer when we actually release it. Until then we keep the old version. Remember to re-run setup in case it doesn't request to run automatically.

Sign In or Register to comment.