Martijn Geerts Posted May 30, 2014 Share Posted May 30, 2014 This Module didn't have it's real own thread, now it has Markup RSS Enhanced This Module is the enhanced version of Ryan's Markup RSS Module and is completely compatible with it. In addition, this enhanced module supports the usage of enclosures a way of attaching multimedia content to RSS feeds. Give the RSS enhanced module a PageArray of pages and it will render a RSS feed from it. The Module should be used directly from your template file. In the examples the $rss variable is used for as instance of the module. $rss = $modules->get("MarkupRSSEnhanced"); Basic usage In case you only need 1 feed for your site, you need to setup the defaults in the Modules config. then you can use the code below. $items = $pages->find("limit=10, sort=-modified"); // $items, PageArray of Pages $rss = $modules->get("MarkupRSSEnhanced"); // load the module $rss->render($items); // render the feed Setup channel elements The channel element describes the RSS feed. There are 3 required channel elements: title $rss->title link $rss->url description $rss->description $rss->title = ''; // (string) Title of the feed. $rss->url = ''; // (string) URL of the website this feed lives. Example: http://www.your-domain.com/ $rss->description = ''; // (string) Phrase or sentence describing the channel. $rss->copyright = ''; // (string) Copyright notice for content in the channel. $rss->ttl = ''; // (string/integer) Number of minutes that how long it can be cached. Setup item elements Every page from the PageArray use the item element. $rss->itemTitleField = ''; // Fieldname to get value from $rss->itemDescriptionField = ''; // Fieldname to get value from $rss->itemDescriptionLength = ''; // Default 1024 $rss->itemEnclosureField = ''; // Fieldname to get file/image from $rss->itemDateField = ''; // Fieldname to get data from $rss->itemLinkField = ''; // Fieldname to get URL from or don't set to use $page->httpUrl $rss->itemAuthorField = ''; // If email address is used, itemAuthorElement should be set to author $rss->itemAuthorElement = 'dc:creator' // may be 'dc:creator' or 'author' Item element enclosure RSS enclosures are a way of attaching multimedia content to RSS feeds. All files with proper mime types are supported. If you asign an image field to the itemEnclosureField there are 3 extra options you could set. width The width of the image. height The height of the image. boundingbox Checking boundingbox will scale the image so that the whole image will fit in the specified width & height. This prevents cropping the image $rss->boundingbox = 1 // (integer) 1 or 0, on or off $rss->width = 400; // (integer) Max width of the image, 0 for proportional $rss->height = 300; // (integer) Max height of the image, 0 for proportional Prettify the feed Prettifying the feed is not supported by all clients. $rss->xsl = ''; // path to xls file $rss->css = ''; // path to css Download on GitHub View on the modules directory 9 Link to comment Share on other sites More sharing options...
Frank Vèssia Posted October 1, 2014 Share Posted October 1, 2014 Hi, I'm trying using this module with latest PW release but I got this error: Error: Call to undefined function finfo_open() (line 253 of /home/ilpepe/public_html/site/modules/MarkupRSSEnhanced.module) Link to comment Share on other sites More sharing options...
adrian Posted October 1, 2014 Share Posted October 1, 2014 http://stackoverflow.com/questions/3579072/php-fileinfo-is-undefined-function 2 Link to comment Share on other sites More sharing options...
Martijn Geerts Posted October 1, 2014 Author Share Posted October 1, 2014 (edited) What kind of environment you're running this? Edited October 1, 2014 by Martijn Geerts (looked at the same link as Adrian... tnx Adrian) Link to comment Share on other sites More sharing options...
Frank Vèssia Posted October 1, 2014 Share Posted October 1, 2014 so it's question of php...ok I'll try to install this fileinfo.so extension, thanks 1 Link to comment Share on other sites More sharing options...
horst Posted October 1, 2014 Share Posted October 1, 2014 @Martijn: maybe a check on install of the module or in the config-screen? if( !extension_loaded('fileinfo') && !@dl('fileinfo') ) { // missing PHP extension ... } 3 Link to comment Share on other sites More sharing options...
Martijn Geerts Posted October 1, 2014 Author Share Posted October 1, 2014 @Sevarf2, would you mind to try the following ? Add a new method somewhere in the module: /** * Return Mimetype * */ protected function mimetype($filename) { if (function_exists('finfo_open')) { $info = finfo_open(FILEINFO_MIME_TYPE); $mime = finfo_file($info, $filename); finfo_close($info); } else if (function_exists('mime_content_type')) { $mime = mime_content_type($filename); } else { $mime = 'application/octet-stream'; } return $mime; } And then change the code for the mime type: /* Disable this: */ // $info = finfo_open(FILEINFO_MIME_TYPE); // $mime = finfo_file($info, $field->filename); // finfo_close($info); /* add this: */ $mime = $this->mimetype($field->filename); 2 Link to comment Share on other sites More sharing options...
hellomoto Posted January 16, 2015 Share Posted January 16, 2015 The Module should be used directly from your template file. What template file? I have rss.php in my templates directory. How is the feed accessed? I need to make a blank RSS template in PW? Never mind that worked Link to comment Share on other sites More sharing options...
snobjorn Posted February 6, 2017 Share Posted February 6, 2017 Is there a way to append $rss->itemLinkField = ''; ? For use with campaign url or other tracking methods. E.g. such as this: $rss->itemLinkField = 'httpUrl' . '?utm_source=RSS_Feed&utm_medium=RSS&utm_campaign=RSS_Syndication'; Except that this wont work … I have also tried: $rss->itemLinkField = 'httpUrl'; $rss->itemLinkField .= '?utm_source=RSS_Feed&utm_medium=RSS&utm_campaign=RSS_Syndication'; Just to show what is not working, and what I am trying to achieve. Link to comment Share on other sites More sharing options...
abdus Posted March 16, 2017 Share Posted March 16, 2017 Hey, I sent a pull request to fix parsing error with message 'unicode entity not defined' when using author field that contains unicode (Turkish) characters. I also added atom namespace and atom:link property under channel to pass W3C validation. Link to comment Share on other sites More sharing options...
Alex CA Posted November 21, 2017 Share Posted November 21, 2017 (edited) I was just using this module "MarkupRSSEnhanced" to generate my rss feed. My RSS feed specifically pulls data from 2 different templates. Though both these templates have the same title field called 'Title', their description field varies (one has r_desc and the other has e_desc) Is there a way where I can configure the model in such a way to pick up either of r_desc or e_desc (whichever is present on the template) I also have the same problem with adding the image to rss also since one has field name r_pic and the other has e_pic. PS-I cannot change the field names since I recently took over the project I am working on and it has been implemented by many others before me. Edited November 21, 2017 by kongondo Moderator Note: Moved your post to the module's support forum Link to comment Share on other sites More sharing options...
Macrura Posted November 23, 2017 Share Posted November 23, 2017 @Alex CA you can change those fields when you instantiate the module: $rss = $modules->get("MarkupRSSEnhanced"); $rss->title = 'Title for this feed'; $rss->description = 'Description for this feed'; $rss->itemDescriptionField = 'r_desc'; // set your specific field here, e.g. r_desc or e_desc $rss->itemEnclosureField = 'r_pic'; // or e_pic $limit = 8; $items = $page->children("limit={$limit}, sort=-publish_start"); $rss->render($items); 1 Link to comment Share on other sites More sharing options...
Alex CA Posted November 28, 2017 Share Posted November 28, 2017 @Macrura I did see how to instantiate the module. But how do I make module pick up r_desc and r_pic when it's generating the RSS feed when I select pages with template='Template1' and then make it pick e_desc and e_pic when the template is='Template2'. My condition for the page selector for my RSS feed is $pages->find("template=". $template1 ."|". $template2.", sort=-modified,limit=20"); Link to comment Share on other sites More sharing options...
Macrura Posted December 2, 2017 Share Posted December 2, 2017 I think if i was faced with your situation, the first thing i would do (after cursing out the developer who setup that field structure) would be to add a runtime field and see if the module is able to pick up that: (in ready.php for example): wire()->addHookProperty('Page(template=Template1)::rss_desc', function($event) { $page = $event->object; $event->return = $page->r_desc; }); wire()->addHookProperty('Page(template=Template2)::rss_desc', function($event) { $page = $event->object; $event->return = $page->e_desc; }); wire()->addHookProperty('Page(template=Template1)::rss_pic', function($event) { $page = $event->object; $event->return = $page->r_pic; }); wire()->addHookProperty('Page(template=Template2)::rss_pic', function($event) { $page = $event->object; $event->return = $page->e_pic; }); Or I would just roll my own RSS feed using a class.. Link to comment Share on other sites More sharing options...
Alex CA Posted December 4, 2017 Share Posted December 4, 2017 @Macrura Thanks for all the help. The addHookProperty() did not work. Another simple solution (I should've tried it earlier ) is to directly use $rss->itemDescriptionField='e_desc|r_desc' Link to comment Share on other sites More sharing options...
Alex CA Posted December 6, 2017 Share Posted December 6, 2017 I do have another task what I am trying to solve with the help of RSS module. Suppose my rss feed is based on a page which uses template A and it is pulling data from all templates on the website which has template B (which is say b_title and b_description). Now, I have another field in template B which has a filed type Page(lets called this field b_page) which essentially is for pages of another template (let's call it template C).This template C consists of a field called c_img. Now I want my rss feed template(A.php) to pull the title and description from template B and the image for the rss feed from template C. How do I achieve the retrieval of the image? I have tried representing my problem with a picture below. My current code looks similar to this: <?php // rss-feed.php template file // retrieve the RSS module $rss = $modules->get("MarkupRSSEnhanced"); // configure the feed. see the actual module file for more optional config options. $rss->title = "Latest updates"; $rss->description = "The most recent pages "; $items = $pages->find("tempalte=". $templateB .", sort=-modified,limit=20"); $rss->itemDescriptionField = 'b_Desc'; $rss->itemEnclosureField = 'b_page[0]->c_img'; // we take the first one since this field can consist an array of pages // send the output of the RSS feed, and you are done $rss->render($items); ?> Link to comment Share on other sites More sharing options...
Alex CA Posted January 16, 2018 Share Posted January 16, 2018 @Macrura @Martijn Geerts , could you help me with this issue? Link to comment Share on other sites More sharing options...
Macrura Posted January 16, 2018 Share Posted January 16, 2018 If i were faced with your issue, i would change the structure of the pages and all of that, it doesn't make sense to me; i guess it must make complete sense to someone else, whoever set it up that way, but obviously the module author(s) never accounted for this sort of setup; You can also just roll your own RSS feed, then you don't need to be straddled with module interactions; it's not that hard to just make your own RSS class that takes into account any arbitrary structure and outputs it how you want; you could also just extend the module itself and modify the Module Class to a new one, and work from there until it works... 1 Link to comment Share on other sites More sharing options...
gr00__ Posted October 27, 2018 Share Posted October 27, 2018 Hi, I just installed the enhanced module on the latest version of PW, even though it is not strictly compatible. I am trying to set up an image from an images field as enclosure like this: $rss->itemEnclosureField = 'post_images'; I would like it to pick the first image from the field. However, the RSS feed is not changed and there are no errors in the error log. I made sure to call the rss with: $rss = $modules->get("MarkupRSSEnhanced"); @Macrura any ideas? Link to comment Share on other sites More sharing options...
Macrura Posted October 27, 2018 Share Posted October 27, 2018 did you set the enclosure field in the module settings; i know the module says you can set it from the api, just wondering what effect that has; also make sure the feed is not cached... 1 Link to comment Share on other sites More sharing options...
gr00__ Posted October 29, 2018 Share Posted October 29, 2018 @Macrura thanks for the help. Turns out it does work, but I was doing some images substitutions in another file which made me think I was getting incorrect results (was substituting for default picture when there was none, and RSS omits the enclosure tag if there aren't any). Link to comment Share on other sites More sharing options...
Ivan Gretsky Posted April 9, 2020 Share Posted April 9, 2020 Good day, @Martijn Geerts! This module does not state PW3 support. Do you see any potential problems? If not, maybe update the description? 1 Link to comment Share on other sites More sharing options...
Martijn Geerts Posted April 10, 2020 Author Share Posted April 10, 2020 Have not used it with PW3, now-a-days I use DomDocument 1 Link to comment Share on other sites More sharing options...
Ivan Gretsky Posted April 10, 2020 Share Posted April 10, 2020 1 hour ago, Martijn Geerts said: Have not used it with PW3, now-a-days I use DomDocument Could you please share a bit more. A simple gist would be perfect)) Link to comment Share on other sites More sharing options...
Martijn Geerts Posted April 13, 2020 Author Share Posted April 13, 2020 Hi @Ivan Gretsky The code I gonna paste here is a copy/paste from other work so there might be glitches. And you should use your own fieldnames etc. What you can do is: Create a template and template file for RSS name it rss. Template not ending with slash. (Name a the page that uses this template should end with .rss In the template file something like: <?php namespace ProcessWire; use DomDocument; use DOMElement; use DateTime; header('Content-Type: application/xml; charset=utf-8', true); date_default_timezone_set("Europe/Amsterdam"); setlocale(LC_MONETARY, 'nl_NL'); /** @var \DateTime */ $date = new DateTime('today midnight'); $items = $pages->find("YOUR SEARCH SELECTOR DON'T FORGET TO SET LIMIT"); /** * Start XML Object * * @var DOMDocument */ $dom = new DOMDocument("1.0", "UTF-8"); $root = $dom->appendChild($dom->createElement("rss")); $root->setAttribute("version","2.0"); $root->setAttribute("xmlns:dc","http://purl.org/dc/elements/1.1/"); $root->setAttribute("xmlns:content","http://purl.org/rss/1.0/modules/content/"); $root->setAttribute("xmlns:atom","http://www.w3.org/2005/Atom"); $link = $dom->createElement("atom:link"); $link->setAttribute("href", $page->httpUrl()); $link->setAttribute("rel","self"); $link->setAttribute("type","application/rss+xml"); $channel = $root->appendChild($dom->createElement("channel")); $channel->appendChild($link); $channel->appendChild($dom->createElement("title", $page->title)); $channel->appendChild($dom->createElement("description", $page->description)); $channel->appendChild($dom->createElement("link", $page->httpUrl)); $channel->appendChild($dom->createElement("language", "nl")); $channel->appendChild($dom->createElement("lastBuildDate", $date->format(DateTime::RFC2822))); $channel->appendChild($dom->createElement("generator", "DomDocument, ProcessWire")); foreach ($items as $item) { $dateInt = (int) $item->getUnformatted("date_start"); if (!$dateInt) $dateInt = (int) $item->modified; /** @var DateTime $date */ $date = new DateTime(date("Y-m-d", $dateInt)); /** @var DOMElement $parent */ $itemParent = $dom->createElement("item"); // Plain tags $elements = array( $dom->createElement("title", $item->title), $dom->createElement("description", htmlspecialchars($item->description)), $dom->createElement("link", $item->httpUrl()), ); // For closure $image = $images->first(); $image = $image->size(600, round(600 * 9 / 16)); $mime = $image->ext === 'jpg' ? "image/jpeg" : "image/png"; $enclosure = $dom->createElement("enclosure"); $enclosure->setAttribute('url', $image->httpUrl()); $enclosure->setAttribute('type', $mime); $enclosure->setAttribute('length', $image->filesize); $elements[] = $enclosure; foreach ($elements as $element) $itemParent->appendChild($element); $channel->appendChild($itemParent); } echo $dom->saveXML(); When you want to place the RSS in the root you could hide it for non superusers: /** * Hide RSS page * * Hide RSS page int pagelist for NON superusers * */ $wire->addHookBefore("ProcessPageList::find", function (HookEvent $event) { /** @var User $user */ $user = $this->wire("user"); if ($user->isSuperuser()) return; /** @var Page $page */ $page = $event->arguments(1); /** @var string $baseSelector */ $baseSelector = $event->arguments(0); $selector = $baseSelector . ", template!=rss"; $event->arguments(0, $selector); }); Hope this could be a good starting point for you. 2 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now