You are here

function querypath_examples_show_rss in QueryPath 7.3

Same name and namespace in other branches
  1. 6 querypath_examples.module \querypath_examples_show_rss()
  2. 7.2 querypath_examples.module \querypath_examples_show_rss()

Display the titles of each item in the RSS feed.

1 string reference to 'querypath_examples_show_rss'
querypath_examples_menu in ./querypath_examples.module
Implements hook_menu();

File

./querypath_examples.module, line 90
The main file for querypath_examples.

Code

function querypath_examples_show_rss() {
  $out = '<h2>' . t('Items in the RSS Feed') . '</h2>';
  $out .= '<p>' . t('Display a linked title to each item in the RSS feed') . '</p>';
  $out .= '<p>' . t('Behind the scenes, this is fetching the RSS feed over HTTP, parsing it, and then creating a list of linked items.') . '</p>';
  $url = url('rss.xml', array(
    'absolute' => TRUE,
  ));
  foreach (qp($url, 'item') as $item) {
    $title = $item
      ->find('title')
      ->text();
    $link = $item
      ->next('link')
      ->text();
    $out .= '<p>' . l($title, $link) . '</p>';
  }
  $code = '<?php
  $url = url(\'rss.xml\', array(\'absolute\' => TRUE));
  foreach (qp($url, \'item\') as $item) {
    $title = $item->find(\'title\')->text();
    $link = $item->next(\'link\')->text();

    $out .= \'<p>\' . l($title, $link) . \'</p>\';
  }
  ?>';
  $out .= '<h2>' . t('The Code:') . '</h2>';
  $out .= highlight_string($code, TRUE);
  $out .= '<h2>' . t('References:') . '</h2>';
  $out .= l('The QueryPath API', 'http://querypath.org');
  return $out;
}