Hi, I'm not sure it's the right forum, but here goes -
Currently URL Rewrite module does not support page keyword making all pages >1 into links with &g2_page=2.
I'm proposing a simple addition -
1. Add
'page' => array(
'pattern' => '([0-9]*)',
'help' => $this->translate('Page number)'),
'function' => array('rewrite', 'RewriteSimpleHelper', 'parsePage')),
to getRewriteRules() in module.inc for Show Item
2. Add
function parsePage(&$url, &$params, &$entity) {
$url = str_replace('%page%', $params['page'], $url);
unset($params['page']);
return true;
}
function to RewriteSimpleHelper.class
And voila! Go to your site admin and add %page% to the Show Item link, for instance - /%path%/%page%
The rewrite pattern ([0-9]*) ensures that links without page numbers work fine too.
The only downside to this that I have not been able to figure out so far, is that all permalinks for the first page must have a "/" at the end.
Thanks!
Art
Posts: 8601
This is a great start! In parsePage I did $page = isset($params['page']) ? $params['page'] : ''; and used $page in the str_replace.. with that it works as you describe. There are a few things to think about before adding this in...
The second one maybe is ok.. for the first one, can we find a way to make non-albums work as before?
Posts: 8
Yes, I thought about it and I think it should be done with minimal impact on existing configurations... However I lacked knowledge to do that on my own
- Non albums could be excluded from the logic altogether. is it possible to determine whether the entity is an album or a photo?
I think I'm answering my own question - $entity->entityType will tell whether to perform the translation or not. Note, that this might be a weak point of this function because we will miss or misuse the new types added at a later date
- It is a problem for people who already bookmarked specific albums.
Solution 1: change the rewrite pattern to make the / at the end optional (no idea how at this moment).
Pros:
- existing links work exactly like before
Cons:
- albums cannot have numeric names
Solution 2: leave the way it is
Pros:
- links are consistent - the ones with a '/' at the end are album's first page
- does not matter what albums are called
Cons:
- existing bookmarks are not working anymore
This way or another we're going to have to bite the bullet and screw up some users in order to please the others
Or, make this configurable so users may choose
Thanks!
Art
Posts: 8
Just realized -
Since non-albums are processed with the same URL it would not be possible to just exclude them, the / at the end needs to be made optional in the rewrite rule..................
Posts: 8601
This %page% token is tricky because it is optional.. I wonder if we could use 2 rewrite rules, like this:
I'm not sure how to get URL rewrite module to write that, but if it could, would this work?
Note I changed [0-9]* to [0-9]+ in the first rule, so this one only matches when there IS a page number.
Seems like this could work for v/%path%/%page% .. what if someone did some other pattern like %page%::%path% or %path%@page%page% ? How could we parse these patterns into the approprite rules? ie, since %page% is optional, how do we know what to strip out of the pattern for the 2nd rule... for %path%/%page% we stripped the / before %page%
Posts: 8
i just tried, it does not seem possible to have two rewrite rules here. Rewrite admin does not allow to have two urls pointing to the same view (nor would I expect it to). If we really need the separation of album view and photo view we will also need it on the Gallery API level. At this point it's just one - ShowItem
also, we cannot strip anything exactly because the path may be completely different.
it looks like if %page% is optional the only way to have it is at the end of the url after a '/' or a '#' (the latter is not very good since I'm pretty sure search engines will ignore it)
i give up.
The modification I made with %page% and ([0-9]*) is suitable for me and, I'm sure, will be good enough for many users. Yes, the links will change, and some users will not want that so they won't do it. I really don't see any other solution at this point
Thanks!
Art
Posts: 8601
agreed, doesn't seem trivial to keep the non-album links as they were.
and, since we don't use this token by default it seems ok to put it in, and those that want it can use it as is... it's in svn now, give it a try!
Posts: 8
Hello,
I have problems making it work. I've added:
$rules[0] = array(
'comment' => $this->translate('Show Item'),
'match' => array('view' => 'core.ShowItem'),
'pattern' => 'v/%path%',
'keywords' => array(
'path' => array(
'pattern' => '([^?]+)',
'help' => $this->translate('Path to an item (eg, /album/image.jpg.html)'),
'function' => array('rewrite', 'RewriteSimpleHelper', 'parsePath')),
'page' => array(
'pattern' => '([0-9]*)',
'help' => $this->translate('Page number)'),
'function' => array('rewrite', 'RewriteSimpleHelper', 'parsePage')),
'language' => array(
'pattern' => '([a-z]{2}|[a-z]{2}_[A-Z]{2})',
'help' => $this->translate('Current language (eg, en or de)'),
'function' => array('rewrite', 'RewriteSimpleHelper', 'parseLanguage'))),
'onLoad' => array('rewrite', 'RewriteSimpleHelper', 'loadItemIdFromPath'),
'help' => $this->translate('The general URL for viewing items.'));
to module.inc
And I've added:
function parsePage(&$url, &$params, &$entity) {
$url = str_replace('%page%', $params['page'], $url);
unset($params['page']);
return true;
}
to RewriteSimpleHelper.class but it still does not works.
I get a
An error occured while trying to save your settings
Bad keyword.
Please advice,
Thanx.
Posts: 8
Well,
I've managed to make it work. The only problem is that the URL is:
domain.com/gallery2/album/picture_name.jpg/
Spent a few hours trying to move the "page" rule to anothere category but I was unable to make the / dissapear. There are so many flaws from search engine point of view. Lots of things needs to be taken care off before it will be trully search engine friendly.
PLease tell me if anyone find a sollution for making the URL domain.com/gallery2/album/picture_name.html and still keep the "page" option. I've tryed to make 2 rules on core.ShowItem but i was not able.
Thanx.
Posts: 324
I edited module.inc. and RewriteSimpleHelper.class according to these instructions and placed them in local directories in the URL rewrite module, but when I went to change /%path%/%page% in ShowItem I get an error that says "Bad Keyword"...do I have to deactivate and reactivate the module to get this to work? I am eager to resolve the problems with the page number nav on my site. Thanks!
Posts: 32509
no need to hack it.
see the message from mindless. it's in svn (our development repository / version) now.
you can upgrade to the latest nightly snapshot to get that feature.
in site admin -> rewrite, you can then use the "%page%" placeholder in the ShowItem rule.
Posts: 324
Do I have to upgrade to 2.2 before getting it from SVN?
Posts: 324
I tried installing the tortoise SVN app as i am on Windows...both the latest and an older version wouldn't install. I don't have unix shell access but I might be able to get my hosting TS to do it. Do I need to upgrade though?
Posts: 32509
just use the nightly snapshots, no need to use svn.
see the download page for nightly snapshots.
Posts: 324
ok...do I have to install ALL the files in nightly snapshot or can I just overwrite my current rewrite module files with the new ones from the snapshot? Also, should I deactivate the module first? Thanks!
Posts: 324
I tried just overwriting the URL rewrite module..got a version mismatch error...full upgrade it is
Posts: 1023
ichtyous,
just wanted to answer 'all' ;)
Gallery version = 2.2-svn core 1.1.16
PHP version = 5.1.6 apache2handler
Webserver = Apache/2.2.3 (Win32) DAV/2 PHP/5.1.6 mod_ssl/2.2.3 OpenSSL/0.9.8c
Database = mysql 5.1.11 beta-log,
Theme=PGlightbox,
Gallery-URL=http://lf-photodesign.de
Posts: 324
Lutz,
I installed your version and have it running now. The latest version of gallery 2.2 has included the page number fix...but it apparently it has a small glitch. For whatever reason, in galleries where I have the album theme set to display 2 columns and 3 rows (which is my default) and there are over 7 pages of items...the number 7 is repeated twice in the bottom page numer nav! One of them is a link and the other one is static, and it only happens with 7....take a look here for instance:
Landscape photos
Washington DC photos
Posts: 565
ichthyous----
You've got it hardcoded I think.
Search your template tree for the character sequence:
</a>7</a>
----best wishes, Robert
Posts: 324
what template is the page number nav in? Is that album.tpl?
Posts: 565
ichthyous----
It is in my own site's template...
...the "core.Pager" calls up the magic...
/modules/core/templates/blocks/local/Pager.tpl
So, it looks like you've got a small edit in the core to correct?
----best wishes, Robert
Posts: 324
I opened up pager.tpl and I didn't see anything wrong...strange. Does anyone know where something like this could be coming from?
Posts: 565
ichthyous----
I'm curious please upload your...
/modules/core/templates/blocks/Pager.tpl
/modules/core/templates/blocks/local/Pager.tpl
...files to the forum.
----best wishes, Robert
Posts: 324
Hello, I am wondering how to resolve one issue with the page number rewrites. The page numbering causes duplicate content pages, for example:
http://andrewprokos.com/photos/architecture/
http://andrewprokos.com/photos/architecture/1
These are both the same page, which would be seen as dupe content by the search engines. The second url is referred to by all the page number links. I tried to merge them using url rewrite and 301 redirect in htaccess, but these never work with gallery urls for some reason. Is there a way to set the pager to start at page 2 and skip page #1 altogether? Thanks!
Posts: 215
I've got this working for the standard albums, but not for the dynamic albums.
Does this need to be changed in every dynamic album too?
Ideally I'd like to be able to do www.example.com/key/Foo/274 to get page 274 of the Foo keyword list. when I tried to add %page% to the keyword it wouldn't accept the url rewrite specification
Posts: 215
Ok, I'll reply to my own question ;-)
I've experimented with the keyword dynamic album and managed to get this to work.
Is anyone working on the changes for the dynamic albums? If not I'm happy to post changes/diff's for the ones that I use ( URL, Rating, Dynaimc albums [updates, popular, random] )
This is also probably the wrong place to ask, but is there any reason why the downloadItem can't support the Path to the item e.g:
instead of:
d/%itemId%/%serialNumber%/%fileName%
being able to specify:
d/%path%/%serialNumber%/%fileName%
Posts: 215
If you want to change the keyword album so it supports the same format /key/%keyword%/%page% then in module.inc change the function getRewriteRules() as below:
/**
* @see GalleryModule::getRewriteRules
*/
function getRewriteRules() {
return array(
array('comment' => $this->translate('Keyword Album'),
'match' => array('view' => 'keyalbum.KeywordAlbum'),
'pattern' => 'key/%keyword%/%page%',
'help' => $this->translate('Short URL for Keyword Albums'),
'keywords' => array(
'keyword' => array('pattern' => '([^?/]+)',
'help' => $this->translate('Keyword to use for dynamic album')),
'page' => array('pattern' => '([0-9]*)',
'help' => $this->translate('Page number in a dynamic album')) )
));
Posts: 53
Gee, this worked swell. Changed the ShowItem to %page% and every album goes back to the homepage. It wouldn't let me change it back to %path%, every time I do it just takes me back to main.php and doesn't make the change. Oh yes, main.php is back after I finally got rid of that too.
Uninstalled the plugin thinking that would allow me to edit it. Reinstalled and still had a mess. Then I made the ultimate mistake of deleting the plugin hoping to clear things - only problem was all the changes I've made all today to clean up all the other URL problems are still in place and now the plug in will not even download properly.
Would love to hear any suggestions other than starting completely over. And would someone please explain why this is still an issue in the first place? Sheesh. From what I've seen in the forums today, this has been a problem since 2005. Why not fix the URLs properly and be done with it? Not a happy camper right now.
Posts: 32509
@micrafty:
> I've seen in the forums today, this has been a problem since 2005.
what? the short URL part for pages? the first official release with this functionality has been released in 2007 (Gallery 2.2).
> Why not fix the URLs properly and be done with it?
works for me.
please don't cross post. let's continue your case in the thread that you've started in the support forum.
--------------
Documentation: Support / Troubleshooting | Installation, Upgrade, Configuration and Usage
Posts: 30
Hello, I've switched on rewriting for page number but it seems it is working only INSIDE albums (is't not working on the home page). Does anybody know what's wrong?
Example:
http://www.pavelpola.cz/?g2_page=2 (wrong)
http://www.pavelpola.cz/foto/sumava-na-kolech/2 (correct)
_________________________________
Please visit my personal gallery: http://www.pavelpola.cz (mostly B&W pictures, Prague, nature, people)
Posts: 3
I have same problem.
pavel.pola's describtion is better then my in http://gallery.menalto.com/node/81643#comment-288881
Please, how can I fix it?
Posts: 215
I'm pretty sure this is a limitation of the URL rewrite rules, just like the first page isn't always correct. - I think I had the same problem at one point but I've since removed a most things from the root album pending a re-organization.
_________
Mark
Posts: 28
Thanks for topic