Jump to content

Markup RSS Enhanced


Martijn Geerts
 Share

Recommended Posts

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:

  1. title $rss->title
  2. link $rss->url
  3. 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.

  1. width The width of the image.
  2. height The height of the image.
  3. 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

  • Like 9
Link to comment
Share on other sites

  • 4 months later...

@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);

  • Like 2
Link to comment
Share on other sites

  • 3 months later...
  • 2 years later...

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

  • 1 month later...

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

  • 8 months later...

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 by kongondo
Moderator Note: Moved your post to the module's support forum
Link to comment
Share on other sites

@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);

 

  • Like 1
Link to comment
Share on other sites

@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

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

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); 

?>


 

s.png

Link to comment
Share on other sites

  • 1 month later...

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...

  • Like 1
Link to comment
Share on other sites

  • 9 months later...

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

@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

  • 1 year later...

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.

  • Like 2
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Similar Content

    • By Marco Ro
      Hi guys!
      I'm a bit anxious because this is the first module I present! (beta modulo) But I will finally be able to share something with the community too! :)
      This is a BETA version of the PayPal payment system called: PayPal Commerce Platform.
      It is an advanced system (Business Pro account is needed) that brings various benefits in terms of fees and above all integrates direct payment with credit/debit cards. 
      The module integrates with Padloper 0.0.2, which is the current installation I'm using.
      This system integrates the classic PayPal buy button, the alternative or local payment method and the new payment system: credit/debit cards that doesn't go through the PayPal account. It is a Stripe-style payment, it connects directly with the bank and integrates 3D security validation.
      I say that it is a BETA because this module currently only works with Sandbox account, to put it live you need to change API url manually (manually for the moment).
      Because this module is not ready for live:
      I would like to have your opinion on how I built the module (is the first one I do). I don't want to share something that is not fish but I need a comparison with someone more experienced than me, for be sure that this is the best way to code the module.
      If you want to try this I created a git, you will find all the instructions for installation and correct operation. (Git has a MIT licensed)
      https://github.com/MarcooRo/processwire-PayPal-Commerce-Platform I hope I did something that you guys can like :)
    • By monollonom
      (once again I was surprised to see a work of mine pop up in the newsletter, this time without even listing the module on PW modules website 😅. Thx @teppo !)
      FieldtypeQRCode
      Github: https://github.com/romaincazier/FieldtypeQRCode
      Modules directory: https://processwire.com/modules/fieldtype-qrcode/
      A simple fieldtype generating a QR Code from the public URL of the page, and more.
      Using the PHP library QR Code Generator by Kazuhiko Arase.

      Options
      In the field’s Details tab you can change between .gif or .svg formats. If you select .svg you will have the option to directly output the markup instead of a base64 image. SVG is the default.
      You can also change what is used to generate the QR code and even have several sources. The accepted sources (separated by a comma) are: httpUrl, editUrl, or the name of any text/URL/file/image field.
      If LanguageSupport is installed the compatible sources (httpUrl, text field, ...) will return as many QR codes as there are languages. Note however that when outputting on the front-end, only the languages visible to the user will be generated.
      Formatting
      Unformatted value
      When using $page->getUnformatted("qrcode_field") it returns an array with the following structure:
      [ [ "label" => string, // label used in the admin "qr" => string, // the qrcode image "source" => string, // the source, as defined in the configuration "text" => string // and the text used to generate the qrcode ], ... ] Formatted value
      The formatted value is an <img>/<svg> (or several right next to each other). There is no other markup.
      Should you need the same markup as in the admin you could use:
      $field = $fields->get("qrcode_field"); $field->type->markupValue($page, $field, $page->getUnformatted("qrcode_field")); But it’s a bit cumbersome, plus you need to import the FieldtypeQRCode's css/js. Best is to make your own markup using the unformatted value.
      Static QR code generator
      You can call FieldtypeQRCode::generateQRCode to generate any QR code you want. Its arguments are:
      string $text bool $svg Generate the QR code as svg instead of gif ? (default=true) bool $markup If svg, output its markup instead of a base64 ? (default=false) Hooks
      Please have a look at the source code for more details about the hookable functions.
      Examples
      $wire->addHookAfter("FieldtypeQRCode::getQRText", function($event) { $page = $event->arguments("page"); $event->return = $page->title; // or could be: $event->return = "Your custom text"; }) $wire->addHookAfter("FieldtypeQRCode::generateQRCodes", function($event) { $qrcodes = $event->return; // keep everything except the QR codes generated from editUrl foreach($qrcodes as $key => &$qrcode) { if($qrcode["source"] === "editUrl") { unset($qrcodes[$key]); } } unset($qrcode); $event->return = $qrcodes; })
    • By Sebi
      AppApiFile adds the /file endpoint to the AppApi routes definition. Makes it possible to query files via the api. 
      This module relies on the base module AppApi, which must be installed before AppApiFile can do its work.
      Features
      You can access all files that are uploaded at any ProcessWire page. Call api/file/route/in/pagetree?file=test.jpg to access a page via its route in the page tree. Alternatively you can call api/file/4242?file=test.jpg (e.g.,) to access a page by its id. The module will make sure that the page is accessible by the active user.
      The GET-param "file" defines the basename of the file which you want to get.
      The following GET-params (optional) can be used to manipulate an image:
      width height maxwidth maxheight cropX cropY Use GET-Param format=base64 to receive the file in base64 format.
    • By MarkE
      This fieldtype and inputfield bundle was built for storing measurement values within a field, rendering them in a variety of formats and converting them to other units or otherwise modifying them via the API.
      The API consists of a number of predefined functions, some of which include...
      render() for rendering the measurement object, valueAs() for converting the value to another unit value, convertTo() for converting the whole measurement object to different units, and add() and subtract() for for modifying the stored value by the value (converted as required) in another measurement. In the admin the inputfield includes a checkbox (which can be optionally disabled) for converting values on page save. For an example if a value was typed in as centimeters, the unit was changed to metres, and the page saved with this checkbox selected, said value would be automatically converted so that e.g. 170 cm becomes 1.7 m.

      A simple length field using Fieldtype Measurement and Inputfield Measurement.
      Combination units (e.g. feet and inches) are also supported.
      Please note that this module is 'proof of concept' at the moment - there are limited units available and quite a lot of code tidying to do. More units will be added shortly.
      See the GitHub at https://github.com/MetaTunes/FieldtypeMeasurement for full details and updates.
    • By tcnet
      File Manager for ProcessWire is a module to manager files and folders from the CMS backend. It supports creating, deleting, renaming, packing, unpacking, uploading, downloading and editing of files and folders. The integrated code editor ACE supports highlighting of all common programming languages.
      https://github.com/techcnet/ProcessFileManager

      Warning
      This module is probably the most powerful module. You might destroy your processwire installation if you don't exactly know what you doing. Be careful and use it at your own risk!
      ACE code editor
      This module uses ACE code editor available from: https://github.com/ajaxorg/ace

      Dragscroll
      This module uses the JavaScript dragscroll available from: http://github.com/asvd/dragscroll. Dragscroll adds the ability to drag the table horizontally with the mouse pointer.
      PHP File Manager
      This module uses a modified version of PHP File Manager available from: https://github.com/alexantr/filemanager
       
×
×
  • Create New...