Hi,
I searched the forums concerning using RSS in G2. I've see posts saying it should be pretty easy to create a module for RSS. I've also read that RSS can be used in 1.4.4-pl2.
Is there such a module for G2? If not, is somebody working on it?
Thanks.
Carl
Posts: 8601
No module yet, and I'm not aware of anyone working on it.. if anyone wants to take a shot at it just let us know.. we'll give you some pointers on constructing a G2 module.
Posts: 13
Thanks for the quick response. I could consider trying to write the module. It shouldn't be that hard, right? :wink:
Posts: 8601
Probably not too hard.. though I'm not up on RSS, so you'll have to help me understand what the module needs to do before I can help get you started on G2.. (or someone who knows RSS and G2 can chip in here.....) I haven't even used the feature in G1.
Posts: 13
Actually, I'm not even sure anymore it would have to be a "module".
It could be an independant PHP file that queries the database directly to get the description and URL of the last additions. This simple PHP script could have an optional argument to restrict the query to an album.
With my very limited understanding of G2 (I just installed it for the first time yesterday), I don't know what would be the benefits or the disadvantes of creating a module instead of a single PHP page.
Posts: 7994
You're right that you could create a simple PHP page to query the database. But you're really better off making it a module because then you can use the G2 framework which means that among other things:
If you're interested, come talk to us on the #gallery channel on irc.freenode.net, or keep posting here and we'll help.[/]
Posts: 8601
Here's some places to look to get started..
after you define your view you can access it like this:
yourserver.com/gallery2/main.php?g2_view=modulename:ViewName[/]
Posts: 13
OK, that work. Thanks! For now, I have an empty RSS file (no items) when I access my view. That's a good start :wink:
Now, what I have to figure out is how to get the la N items, their urls and descriptions. If you have suggestions where to look for examples, that would be appreciated. I'll be looking at the imageblock module tomorrow for inspiration.
Posts: 8601
if you want a parameter to your view our standard one is g2_itemId, ie
g2_view=modulename:ViewName&g2_itemId=number
GalleryView has a convenience method to load that item:
list ($ret, $item) = $this->_getItem();
This loads the item id specified, or the root album of the gallery if itemId is not specified.
you can use GalleryUtilities::getRequestVariables to get any other query parameters you may need.
I think there's a GalleryCoreApi to get all children of an album, in case you need that. You can do $item->getCanContainChildren() on any item to check if you can retrieve it's children.
Posts: 13
Ok, I'm getting closer to a first working prototype. I have plenty of ideas to make this more flexible, but I want to make a simple version first.
I tried to use the GalleryTemplate class to generate the XML using templates, but I wasn't able to make it work. So now I'm back to writing the XML using "print" commands. It's not bad because the format probably won't evolve anyway.
I have a question to be able to continue though. I see in the templates commands of this form.
{g->url arg1="view=core:ShowItem" arg2="itemId=`$block.id`"}
How can I do that in PHP? I'm sure there is a function in the Gallery API, but I just can't find it. In other words, I'm looking for a function that will give me an URL to the item given it's item ID. Can you point me to it? Thanks.
Posts: 13
Answering to my own post... I know... :wink:
I found it.
$urlGenerator = $gallery->getUrlGenerator();
$url = $urlGenerator->generateUrl(array('view' => 'core:ShowItem', 'itemId' => $itemId));
I should be able to get it to work now.
Posts: 13
Ok, I got something that at least works for the top gallery and is recursive. I'm of course opened to discussion on improvements. It also works for any album if you know the itemId for that album. Of course, the best thing would be to have the module display a small RSS link for the current album. I also currently have an admin section that let's you choose the number of items that are going to show up in the RSS feed, but it's not easily accessible right now (have to type the URL :-\ ) and I can't fully test it because I only have a tiny gallery copntaining 3 photos :wink:
Actuallly, I've got a few things I'd like to see implemented to give more flexibility:
Options in the module admin:
1) Let the admin choose what type of items can be viewed. Currently, only GalleryPhotoItem can be viewed (hardcoded)
2) Choose between creation and modification timestamp
Options that could be passed as arguments:
1) Possibility of having a RSS feed for the comments
2) Choose if the RSS feed should be recursive or not. Currently recursive only.
3) Choose between title and summary for the RSS "title" tag. I really don't like the fact that G2 shows the filename, so I curerntly use the summary.
Possible optimisations:
1) I'm sure the code will be slow for huge galleries. The best way to approach this would probably be to have a direct call to MySQL/Postgres/Whatever that returns the right number of items in the correct order. But for now, I have done it the way it was suggested to me, which means that PHP is comparing timestamps.
2) We could probably use templates instead of "print" commands in PHP. I'm not sure we would gain anything from this though.
So, I could commit this stuff if you would like me to. Just let me know how to approach this. I could send you a tar.gz of my module if you want. Also, I wanted to say that I developped a lot by imitation (and mostly cut-paste-modify :wink, so puting my name in the author section of the copyright feels a bit weird. Just let me know what I should do about this.
Looking forward to hear from you guys.
Posts: 13
beckett asked me to give a link to the RSS module code:
http://www.carlrobitaille.org/downloads/rss-module-0.1.tar.gz
Posts: 7994
I reviewed the code and sent La_Maudite a review. He'll work with us on improving the module so that we can get it committed.
Posts: 8601
Take a look at modules/register/classes/GalleryPendingUserHelper::_sendEmail for an example of using GalleryTemplate directly.
Posts: 52
What's the status on this? </curious>
Posts: 328
geddeth, there is a task for rss support, you can find a link to a forum topic there, and some other notes. There seemed to be some activity some months ago, but it dried out (see forum post), maybe you can revive it? ;)
Cheers,
Ernesto
Posts: 52
If it really has stagnated, I'll definetely do that. ;) What say you, La Maudite? Wanna hook up?
Posts: 5
I have also looked at this, and am interesting and willing to help get rss support into G2.
Posts: 52
Great, so we have a team already! I have the resources available to set up a mailinglist and CVS module for development, but it may be a bit overkill for this. What do people think? We could continue where La Maudite left off (does anyone have anything newer than the link he provided from this thread?) and coordinate our efforts via the mailing list, and then hand the source over to the G2 devs when we have something solid.
Any other/better ideas?
Posts: 328
geddeth, you could use gallery-devel mailing list or the forums to interact, no need to add yet another forum. Most fun happens on irc (#gallery on Freenode). If you come up with something following our coding guidelines, cover all your code with unit-tests, post it to the forums so we can review it and include that to G2's main CVS tree.
Posts: 13
Hi,
Thanks to geddeth for telling me that I should read this thread. I'll be glad to give the code away for you guys to continue the work. Unfortunately, I didn't have time to work on it for quite some time. But I have a better and working version of the RSS module. I had private discussions with Bharat, and that is why I haven't updated thread when I had the working prototype or reading the thread after that. Sorry about that guys and many thanks to geddeth for contacting me about it.
Here is a cut-paste of the message I sent Bharat on 2004-10-21:
=====================
I have reached a working prototype, at last. I wasn't expecting at first to
have different codes for the Photos and Comments and was trying to have a
single code. Spent some time before I realized that Comments are not Items
and that had major impacts. But now, I have a working RSS code for photos and
comments for a given album.
It's working, but I have with me a list of options to put in the Admin
section. I also have a some issues with the session, and Bharat knows about
it. Anyway, even if I'm not ready to release, I thought you guys might want
to see it working.
http://www.carlrobitaille.org/photos/main.php/view/?g2_page=1
Note that I just found out the the main page without the /view/?g2_page=1
doesn't show the links at the bottom of the left sidebar.
http://www.carlrobitaille.org/photos/main.php
It has probably something to do with not having an itemId in the arguments.
Anyway. If you go to any album (or sub-album) you'll see two new links at the
bottom left:
"RSS Photots"
"RSS Comments"
These are for the current album and all it's decendants. I decided to link the
new comments to the view image page instead of the comment page because there
wasn't any advantage to link to the former. I also have a "dummy" argument
"commentId" that is not used by G2 but distinguishes the links between
comments of the same photo. This is useful for HTML based RSS readers like
mine to know what you already read ;-)
http://www.carlrobitaille.org/rssfeeds/?id=CarlRobitaille.org%3A+UPPJ+photos
I'll let you know when I have all the options (and other stuff I have to put
in) in place. If you want to download the current code:
http://www.carlrobitaille.org/downloads/rss-module-0.2.tar.gz
=====================
I haven't worked on it since then, so you can take it as is. On the other hand, I've been using it for more than a month now and it works great for me. As I said in my email to Bharat, I had ideas of options and improvements I could put into the RSS module, but I haven't had time to do that. I could make a list of those improvements/options if you'd like to have them.
Hope this will be a good start for your work guys.
Cheers.
Carl
Posts: 13
Someone pointed out to me that the <lastBuildDate> and <pubDate> tags didn't have a good format. I fixed that (modified RSS.tpl and RSSItem.tpl) and made a new tar.gz.
rss-module-0.2.1.tar.gz
I didn't see the error before because I'm using a PHP script I wrote using MagpieRSS to read my RSS feeds, and I'm not using these tags.
Posts: 7994
I finally got around to doing a full code review on your module. It looks really great; you've definitely gotten most of the principles of G2 down. I'd like to get your code into the main codebase but there are a few things that we need to clean up first. Most of my comments are relatively small cosmetic things revolving around style and naming. The main big thing is that we need unit tests for GalleryRSSHelper.class and AdminRSSController.
If you're low on time, we can help out with this. But it'll happen faster if you can push it over the finish line! Thanks!
GalleryRSSHelper.class:
will only get photo items. You won't get subclasses of GalleryPhotoItem
which means that any new extensions that people add (PanoramaPhotoItem)
won't show up. Instead, you should join through the GalleryPhotoItem
table because all subclasses will have a row there too. I think you can
just add this to the where clause:
[GalleryEntity::id] = [GalleryPhotoItem::id]
and [GalleryPhotoItem] to the from clause and drop the entityType comparison.
Looks like that's what you did in fetchLastGalleryComment
RSS.inc
for phpdoc; only use it when you're documenting a method, not inside a method.
list ($ret, $module) = GalleryCoreApi::loadPlugin('module', 'rss');
then translate all the strings:
$module->translate('Missing itemId argument')
RSS.tpl
RSSLinks.tpl
RSSItem.tpl
AdminRSS.tpl
module.inc
(you can use earlier revisions, but those versions are current)
[/]
[/]
[/]
[/]
[/]
[/]
[/]
Posts: 52
First things first: La Maudite has allowed me to continue work on his excellent RSS module. However, having no experience with the G2 API, I have spent quite a lot of time reviewing the G2 Development StarterKit, the Developer's Guide, the G2 API docs, other modules and of course La Maudite's RSS module itself in order to gain insight into this whole business. I found the hardest bit was to get acquainted with the Smarty API and G2's interaction with it, which is just another way of saying that the G2 API is well thought-through and relatively easy to comprehend.
That being said, I have far from understood all that is going on in this RSS module. So excuse me (Bharat especially) if I've been rather slow in getting this (otherwise simple) module out into the open again, after I promised to do so. I believe the steep learningcurve (and the holidays :lol were my major time-consumers in the past weeks.
So - on to business: the current status of the module can be found here, aptly version-bumped to 0.2.2. It is usable with current CVS, but retains the functionality that La Maudite described earlier in this thread. In module.inc, I have changed the way the (auto-)configuration of the module happens, since I believe 0.2.1 used an old method for this (pun intended ;-)). A diff between module.inc in 0.2.1 and 0.2.2 should reveal these changes.
Regarding your code review, Bharat, these are my comments (or questions, rather):
I have not looked into this. I'd like to, but I feel that you are also interested in getting the module into CVS soon, in which case it would probably be faster if someone on the team could help out. In any case, I'll look into how this is done (and do it, I hope) within a week.
I've changed it to $template->fetch(dirname(__FILE__) . 'modules/rss/templates/RSS.tpl'); - I assume that is what is meant.
I really think La Maudite is in a much better position to answer this than I. If no arguments against changing it appear, I'll do so.
Don't know what this means, sorry. I haven't quite grasped how localization works yet.
Don't know how this works, but have added the g->text function call to the template.
I assume this means removing the g-> text function calls? This is not done yet.
The rest of the changes have been implemented, and the module seems to function properly, so at present I'm assuming I've done it right. However, I've only tested to see that the XML was created properly and updated along with the gallery, nothing else yet.
Lastly, thanks Bharat, for taking the time to do such a thorough review of the code, it gave me further insight into how the G2 API functions and is to be used.
Best regards,
G.[/]
[/]
[/]
[/]
[/]
Posts: 13
I've looked at it and the reason I wasn't using a foreach is that I didn't know foreach and each mixed well. As you can see in the line following the while statement I'm doing calling each on $children. See the comment on GalleryRSSHelper::fetchLastGalleryComment to see how the data is returned:
I'm sure the data could be returned differently to be able to do a foreach. Also, maybe the each statement isn't incompatible with the foreach. Not coding in PHP frequently, I'm not sure about the latter.[/]
Posts: 52
rss-module-0.2.3.tar.gz
Comments are more than welcome. :wink:
BTW: Anonymous comments don't have an e-mail address, but they have to for the comments RSS feed, if we want it to validate. Now it defaults to
. Aside from the fact that default e-mail addresses Are Really Bad, what other options do we have?
Cheers,
G.
Posts: 3236
Do you happen to know the email address of any very (un)popular spammers? Maybe we could contribute to the email they get from site harvesters
Posts: 7994
This is looking really good! It's getting pretty close. We still do need unit tests, and I don't think that I'm going to have a lot of time to write them myself (I'm now spending most of my evenings doing code reviews .. that's a good thing but it's not leaving me much time to code!). They're not all that hard; if you can take a shot at them I'll be happy to give lots of guidance.
General:
GalleryRssHelper.class:
Now we have all the comments (in the order that we wanted them) and we have all the items that the comments will refer to (unordered, but we don't care about the order). Then in RSS.inc:
This way we iterate over the comments, and then when we want to get the parent item's data, we grab the parent from the parent's hash map and use it.
RSS.inc
here instead.
RSS.tpl
<description>{g->text text=$RSS.description}</description>
should be<description>$RSS.description</description>
since the description is pure content; it can't be localized. Anything in {g->text} blocks must be a constant that can be separated out and passed to localizers for translation. Same for language, docs and generator, they should be:language and docs are constant. They can't be translated. generator is pure content from the user like the description.
RSSLinks.tpl
which means that you don't need $RSS['moduleUrl'] in module.inc
RSSItem.tpl
module.inc:
[/]
[/]
[/]
[/]
[/]
[/]
[/]
Posts: 52
Thanks, Bharat, for yet another great review to work with. I'll get cracking on it instantly, including the unit tests.
I totally understand the PHP-related argumentation and will change the modulenames, functions and variables, but do you also mean it to include PhpDocumentor tags (i.e. @package and @subpackage) and RssModule->setName('Rss')? After all, the common practice is to write abbreviations like that in capitals, and the EXIF module seems to stick to this notion as well.
G.
Edit: Scratch that last question, I get it now
Posts: 4
geddeth: regarding the encoding: Gallery ensures that the encoding is always UTF-8 (at least, the Global template seems to assume so.) Therefore, iso-8859-1 can simply be replaced with utf-8, or, if you prefer, left out of the prolog altogether (making it <?xml version="1.0" ?>.) The default encoding for XML is utf-8, so leaving it off is the same as changing it.
Posts: 52
crschmidt, I followed your recommendation and eliminated the string completely. Seems to work fine, also with e.g. Danish vowels (æøå).
G.
Posts: 52
I don't quite understand. In the beginning of your post, you suggest it be altered to
foreach ($comments as $comment) {
which seems to work fine?The other issues you mentioned are all implemented now.
Also, is there anywhere I can look for directions regarding unit tests? I've searched the forums, read the Developer's guide and am now checking out source (core->AdminCreateGroupControllerTest among others), but I really feel a bit in the dark here, possibly because I've never worked with XP before.
I'll keep cut'n'pasting for now, maybe something will work.
Cheers,
G.
Posts: 52
And indeed it did .. it seems I have a working unit test for the admin module (not sure if I need more). I was figuring out why it kept failing, and eventually removed the line:
$results['return'] = 1;
from handleRequest(), since as far as I could gather, it had no function. Please correct me if I'm wrong. :DAnyway, the unit test is extremely simple. Guess that's because the module itself is actually not very complex.
The module has been version-bumped and is availabe here:
rss-module-0.2.4.tar.gz
Here's a snippet from the README inside the archive:
Since I took over development from La Maudite, I've focused only on streamlining the code in order to make it fit for inclusion in G2. Thus, I've not added any new functionality or altered the existing. Instead, I've collected my own thoughts and La Maudite's (see earlier in this thread) for a future revision, as you can see from the README above. I'd be happy to hear (more) comments and ideas for the module, so that there is something to work with when the time is ripe to expand the functionality.
Cheers,
G.
Posts: 7994
This is looking great! Looks like you rolled in all of my suggestions and are pretty close to the end. My review comments are of a much more subtle nature now. I think that we're getting pretty close to the point where we can commit this. I think that will make everybody very happy
General
The long term right solution for this is to create an interface in the GalleryComment module and move the fetchRecentGalleryComments API method into it, then create an implementation of that interface and publish it. This is better because it means that the comment module can change around as much as it wants, and you don't have to try to keep up with its database structure. Let's go with the quick hack for now and then after the RSS module gets committed we can start the process of moving the API method over. It won't take all that long, but it's an easy thing to do afterwards.
AdminRssControllerTest.class
you should do:
It's a better pattern and does the error handling correctly. I used to do it the way you have above, but I've been updating that code wherever I find it.
AdminRss.inc
GalleryRssHelper.class
I tested this out locally and it seems to do the same thing. This is the kind of refactor that's really easy to do after you have unit tests because if the unit test is well written, then you can tinker with the SQL as much as you want as long as the test passes.
Rss.inc
module.inc:
RssItem.tpl
[/]
[/]
[/]
[/]
[/]
[/]
[/]
Posts: 52
Just so noone thinks I've forgotten: I'm still working on this. Real Life (tm) has prevented me from doing much progress lately, but it's coming along ;)
G.
Posts: 5
i have downloaded this module,
but how can use it ?
there is no rss.php file.
who can help me ?
Posts: 32509
lixp, I didn't try this module but usually, you just extract the module in the /modules folder of your G2. then browse to site admin -> modules and activate (& configure) the module.
Posts: 5
i want to use gallery2 in plog. In gallery1.44, there was a rss.php file in gallery folder. and i can use rss.php to get some album items in my plog.
but in gallery2,things changed.
Posts: 5
Rss 0.2.4 Adds RSS feeds to your albums and comments
Incompatible module!
Core API Required: 1.0 (available: 0.8)
where can i get core api 1.0?
Posts: 32509
on this website, there is a menu on the upper left corner. click on "Download Now!" and in the G2 paragraph, click on jmullans nightly snapshots link.
Download the most recent nightly snapshot of gallery2 and there you are.
If your current version is newer than G2 alpha 2 (or was it 4?),you can upgrade your current installation. If it is older, you'll have to install everything again. How to upgrade is described in the forums.
Posts: 5
thxs.
and now ,
the following :
Rss 0.2.4 Adds RSS feeds to your albums and comments
Incompatible module!
Core API Required: 1.0 (available: 3.2)
Module API Required: 0.8 (available: 0.9)
Posts: 24
Wanted to download 'rss-module-0.2.4.tar.gz', but cannot connect to the server.
anyone out there who can e-mail me or provide it for download?
thanx in advance
RaVen
Posts: 5
i use the gallery2 latest version.
but cannot use rss module.
Rss 0.2.4 Adds RSS feeds to your albums and comments
Incompatible module!
Core API Required: 1.0 (available: 3.2)
Module API Required: 0.8 (available: 0.9)
who can help me ?
Posts: 3236
lixp, you should probably just not worry about it until its included in the g2 releases. It looks like the module wants an older version of module api, so i'd suggest just not worrying about it.
Posts: 13451
I haven't been following this thread very closely, and I might be repeating something someone has already asked for, but here it goes anyway.
I would love it if the url for the rss feed makes it possible to change what the output of it is. By that i mean that an url like http://example.com/g2/rss.php?album=test&show=all will feed me with an rss including all images (if anon users have permissions to do so in the given album) and that http://example.com/g2/rss.php?album=test&show=highlight only gives the current highlight for the album. In the same context, a &show=latest will show the last X (configurable) uploaded images to the album.
That way, one could incorporate album's into another page, completely separate from the Gallery install. My idea is to do this in Wordpress, where I can post something about my new pictures, and include the thumbnails, with links, in the post itself, without having to hack Wordpress or Gallery code at all.
Also, this might be a nice way for G2 to be able to support a "Gallery of Gallery installs" as well, grab the RSS feed from a bunch of installs and display them in an album on your own install? G2 would have to incorporate it's own feed-reader for that to work though. Magpie RSS looks like a likely candidate for a module?
Posts: 239
much love homey. ttys
Posts: 10
Is there any chance this module could work towards the same format as the RSS support in Gallery v1. Many people use RSS from gallery 1 to integrate with blogs / other parts of their sites etc.. Seems sensible.
I'd work on it myself but I havent got that great an understanding of Gallery 2 yet, also I dont want to duplicate efforts...
Otherwise is there a quick hack that will add the thumbnail url to the existing feed in Gallery 2?
- Ross
Posts: 239
I have taken this over, the two other who have worked on it have donated the code to us.
I will most likely be redoing a majority of the code, and my goal is to be able to support any type of rss feed (0.8, 0.9, 2.0 ... etc).
I would also like to let the feed be customizable. I begin work this week, so if you have any ideas or comments please get them to me sooner rather than later.
I really don't have much experience with RSS, but I think I can make this work for everyone.
Thanks
Posts: 100
I'm fighting the same battle as those two above me struggling with the wrong API version. Isn't there any way to fix those for those using the latest version of G2 (beta 4 is it?). Can I update the API modules by hand or can I edit the .ini file or something like this to fit the requirements? This module would be really usefull to me right now and I wish that I didnt have to wait for the final version of G2 to use it. Thanks for your time and support.
" Rss 0.2.4 Adds RSS feeds to your albums and comments
Incompatible module!
Core API Required: 1.0 (available: 5.1)
Module API Required: 0.8 (available: 0.10) "
Posts: 7994
You can update the RSS module to conform to the latest API. We document all of our API changes so you have to go through the module and figure out what needs to be changed to conform to the new APIs. You don't need to wait for G2 final for this, you can fix it today.