2007-09-05 08:31:48 +00:00
< ? php
/**
* @ file
2013-01-04 18:37:34 +00:00
* User page callbacks for the Aggregator module .
2007-09-05 08:31:48 +00:00
*/
2013-02-01 17:35:27 +00:00
use Drupal\aggregator\Plugin\Core\Entity\Feed ;
2013-02-26 23:29:42 +00:00
use Drupal\Core\Entity\EntityInterface ;
2013-02-01 17:35:27 +00:00
2007-09-05 08:31:48 +00:00
/**
2013-01-04 18:37:34 +00:00
* Page callback : Displays all the items captured from the particular feed .
2011-11-10 03:02:40 +00:00
*
2013-02-01 17:35:27 +00:00
* @ param \Drupal\aggregator\Plugin\Core\Entity\Feed $feed
2010-03-24 08:51:42 +00:00
* The feed for which to display all items .
2007-12-16 21:01:45 +00:00
*
2013-01-04 18:37:34 +00:00
* @ return string
* The rendered list of items for the feed .
*
2011-11-10 03:02:40 +00:00
* @ see aggregator_menu ()
2007-09-05 08:31:48 +00:00
*/
2013-02-01 17:35:27 +00:00
function aggregator_page_source ( Feed $feed ) {
$feed_source = entity_view ( $feed , 'default' );
2007-10-02 16:03:17 +00:00
2007-09-13 08:02:38 +00:00
// It is safe to include the fid in the query because it's loaded from the
2011-09-21 09:32:00 +00:00
// database by aggregator_feed_load().
$items = aggregator_load_feed_items ( 'source' , $feed );
2007-10-02 16:03:17 +00:00
2007-09-13 08:02:38 +00:00
return _aggregator_page_list ( $items , arg ( 3 ), $feed_source );
2007-09-05 08:31:48 +00:00
}
/**
2011-11-30 03:16:37 +00:00
* Form constructor to show all items captured from a feed .
2011-11-10 03:02:40 +00:00
*
2010-03-24 08:51:42 +00:00
* @ param $feed
2013-01-04 18:37:34 +00:00
* The feed for which to list all of the aggregated items .
*
* @ return string
* The rendered list of items for the feed .
2007-12-16 21:01:45 +00:00
*
2011-11-10 03:02:40 +00:00
* @ see aggregator_menu ()
2010-03-24 08:51:42 +00:00
* @ see aggregator_page_source ()
2011-11-10 03:02:40 +00:00
* @ ingroup forms
2007-09-05 08:31:48 +00:00
*/
2010-03-24 08:51:42 +00:00
function aggregator_page_source_form ( $form , $form_state , $feed ) {
return aggregator_page_source ( $feed );
}
2007-09-05 08:31:48 +00:00
2010-03-24 08:51:42 +00:00
/**
2011-11-30 03:16:37 +00:00
* Form constructor to list items aggregated in a category .
2011-11-10 03:02:40 +00:00
*
2010-03-24 08:51:42 +00:00
* @ param $category
2013-01-04 18:37:34 +00:00
* The category for which to list all of the aggregated items .
*
* @ return string
* The rendered list of items for the feed .
2010-03-24 08:51:42 +00:00
*
2011-11-10 03:02:40 +00:00
* @ see aggregator_menu ()
* @ ingroup forms
2010-03-24 08:51:42 +00:00
*/
function aggregator_page_category ( $category ) {
2013-02-01 17:35:27 +00:00
drupal_add_feed ( 'aggregator/rss/' . $category -> cid , config ( 'system.site' ) -> get ( 'name' ) . ' ' . t ( 'aggregator - @title' , array ( '@title' => $category -> title )));
2007-09-05 08:31:48 +00:00
// It is safe to include the cid in the query because it's loaded from the
2011-09-21 09:32:00 +00:00
// database by aggregator_category_load().
$items = aggregator_load_feed_items ( 'category' , $category );
2007-10-02 16:03:17 +00:00
2007-09-13 08:02:38 +00:00
return _aggregator_page_list ( $items , arg ( 3 ));
}
2010-03-24 08:51:42 +00:00
/**
2011-11-30 03:16:37 +00:00
* Form constructor to list items aggregated in a category .
2011-11-10 03:02:40 +00:00
*
2010-03-24 08:51:42 +00:00
* @ param $category
2013-01-04 18:37:34 +00:00
* The category for which to list all of the aggregated items .
*
* @ return string
* The rendered list of items for the feed .
2010-03-24 08:51:42 +00:00
*
2011-11-10 03:02:40 +00:00
* @ see aggregator_menu ()
2010-03-24 08:51:42 +00:00
* @ see aggregator_page_category ()
2011-11-10 03:02:40 +00:00
* @ ingroup forms
2010-03-24 08:51:42 +00:00
*/
function aggregator_page_category_form ( $form , $form_state , $category ) {
return aggregator_page_category ( $category );
}
2007-09-13 08:02:38 +00:00
/**
2011-11-09 15:46:01 +00:00
* Loads and optionally filters feed items .
2007-12-16 21:01:45 +00:00
*
2008-10-20 12:57:35 +00:00
* @ param $type
2011-11-09 15:46:01 +00:00
* The type of filter for the items . Possible values are :
* - sum : No filtering .
* - source : Filter the feed items , limiting the result to items from a
* single source .
* - category : Filter the feed items by category .
2008-10-20 12:57:35 +00:00
* @ param $data
2011-11-09 15:46:01 +00:00
* Feed or category data used for filtering . The type and value of $data
* depends on $type :
* - source : $data is an object with $data -> fid identifying the feed used to
* as filter .
* - category : $data is an array with $data [ 'cid' ] being the category id to
* filter on .
* The $data parameter is not used when $type is 'sum' .
*
2007-12-16 21:01:45 +00:00
* @ return
* An array of the feed items .
2007-09-13 08:02:38 +00:00
*/
2013-02-01 17:35:27 +00:00
function aggregator_load_feed_items ( $type , $data = NULL , $limit = 20 ) {
2007-09-13 08:02:38 +00:00
$items = array ();
2008-10-20 12:57:35 +00:00
switch ( $type ) {
case 'sum' :
2011-11-09 15:46:01 +00:00
$query = db_select ( 'aggregator_item' , 'i' );
$query -> join ( 'aggregator_feed' , 'f' , 'i.fid = f.fid' );
2013-02-01 17:35:27 +00:00
$query -> fields ( 'i' , array ( 'iid' ));
2008-10-20 12:57:35 +00:00
break ;
case 'source' :
2011-11-09 15:46:01 +00:00
$query = db_select ( 'aggregator_item' , 'i' );
$query
2013-02-01 17:35:27 +00:00
-> fields ( 'i' , array ( 'iid' ))
-> condition ( 'i.fid' , $data -> id ());
2008-10-20 12:57:35 +00:00
break ;
case 'category' :
2011-11-09 15:46:01 +00:00
$query = db_select ( 'aggregator_category_item' , 'c' );
$query -> leftJoin ( 'aggregator_item' , 'i' , 'c.iid = i.iid' );
$query -> leftJoin ( 'aggregator_feed' , 'f' , 'i.fid = f.fid' );
$query
2013-02-01 17:35:27 +00:00
-> fields ( 'i' , array ( 'iid' ))
-> condition ( 'cid' , $data -> cid );
2008-10-20 12:57:35 +00:00
break ;
}
2011-11-09 15:46:01 +00:00
$result = $query
2012-06-05 05:42:19 +00:00
-> extend ( 'Drupal\Core\Database\Query\PagerSelectExtender' )
2013-02-01 17:35:27 +00:00
-> limit ( $limit )
2011-11-09 15:46:01 +00:00
-> orderBy ( 'i.timestamp' , 'DESC' )
-> orderBy ( 'i.iid' , 'DESC' )
-> execute ();
2013-02-01 17:35:27 +00:00
$items = entity_load_multiple ( 'aggregator_item' , $result -> fetchCol ());
2007-09-13 08:02:38 +00:00
return $items ;
2007-09-05 08:31:48 +00:00
}
/**
2007-12-16 21:01:45 +00:00
* Prints an aggregator page listing a number of feed items .
*
* Various menu callbacks use this function to print their feeds .
*
* @ param $items
* The items to be listed .
* @ param $op
2011-11-10 03:02:40 +00:00
* Which form should be added to the items . Only 'categorize' is now
* recognized .
2007-12-16 21:01:45 +00:00
* @ param $feed_source
* The feed source URL .
2011-11-10 03:02:40 +00:00
*
2007-12-16 21:01:45 +00:00
* @ return
2013-01-04 18:37:34 +00:00
* The rendered list of items for the feed .
2007-09-05 08:31:48 +00:00
*/
2007-09-13 08:02:38 +00:00
function _aggregator_page_list ( $items , $op , $feed_source = '' ) {
if ( user_access ( 'administer news feeds' ) && ( $op == 'categorize' )) {
// Get form data.
2013-02-01 17:35:27 +00:00
$build = aggregator_categorize_items ( $items , $feed_source );
2007-09-05 08:31:48 +00:00
}
else {
2013-02-01 17:35:27 +00:00
// Assemble output.
$build = array (
'#type' => 'container' ,
'#attributes' => array ( 'class' => array ( 'aggregator-wrapper' )),
);
$build [ 'feed_source' ] = is_array ( $feed_source ) ? $feed_source : array ( '#markup' => $feed_source );
if ( $items ) {
$build [ 'items' ] = entity_view_multiple ( $items , 'default' );
$build [ 'pager' ][ '#markup' ] = theme ( 'pager' );
2007-09-05 08:31:48 +00:00
}
}
2008-05-15 21:27:32 +00:00
2013-02-01 17:35:27 +00:00
return $build ;
2007-09-05 08:31:48 +00:00
}
/**
2011-11-10 03:02:40 +00:00
* Form constructor to build the page list form .
2007-09-05 08:31:48 +00:00
*
2013-01-04 18:37:34 +00:00
* @ param array $items
2007-12-16 21:01:45 +00:00
* An array of the feed items .
2013-01-04 18:37:34 +00:00
* @ param string $feed_source
* ( optional ) The feed source URL . Defaults to an empty string .
*
* @ return array
* An array of FAPI elements .
2011-11-10 03:02:40 +00:00
*
2008-01-08 10:35:43 +00:00
* @ see aggregator_categorize_items_submit ()
2013-01-04 18:37:34 +00:00
* @ see theme_aggregator_categorize_items ()
* @ ingroup forms
2007-09-05 08:31:48 +00:00
*/
2007-09-13 08:02:38 +00:00
function aggregator_categorize_items ( $items , $feed_source = '' ) {
$form [ '#submit' ][] = 'aggregator_categorize_items_submit' ;
2008-05-15 21:27:32 +00:00
$form [ 'feed_source' ] = array (
'#value' => $feed_source ,
);
2007-09-05 08:31:48 +00:00
$categories = array ();
$done = FALSE ;
2013-04-06 21:21:11 +00:00
$form [ 'items' ] = array (
'#type' => 'table' ,
'#header' => array ( '' , t ( 'Categorize' )),
2008-05-15 21:27:32 +00:00
);
2013-04-06 21:21:11 +00:00
if ( $items && $form_items = entity_view_multiple ( $items , 'default' )) {
foreach ( element_children ( $form_items ) as $iid ) {
$categories_result = db_query ( 'SELECT c.cid, c.title, ci.iid FROM {aggregator_category} c LEFT JOIN {aggregator_category_item} ci ON c.cid = ci.cid AND ci.iid = :iid' , array ( ':iid' => $iid ));
$selected = array ();
foreach ( $categories_result as $category ) {
if ( ! $done ) {
$categories [ $category -> cid ] = check_plain ( $category -> title );
}
if ( $category -> iid ) {
$selected [] = $category -> cid ;
}
2007-09-05 08:31:48 +00:00
}
2013-04-06 21:21:11 +00:00
$done = TRUE ;
$form [ 'items' ][ $iid ][ 'item' ] = $form_items [ $iid ];
$form [ 'items' ][ $iid ][ 'categories' ] = array (
'#type' => config ( 'aggregator.settings' ) -> get ( 'source.category_selector' ),
'#default_value' => $selected ,
'#options' => $categories ,
'#size' => 10 ,
'#multiple' => TRUE ,
'#parents' => array ( 'categories' , $iid ),
);
2007-09-05 08:31:48 +00:00
}
}
2013-04-06 21:21:11 +00:00
2010-04-24 14:49:14 +00:00
$form [ 'actions' ] = array ( '#type' => 'actions' );
2010-01-03 21:01:04 +00:00
$form [ 'actions' ][ 'submit' ] = array ( '#type' => 'submit' , '#value' => t ( 'Save categories' ));
2013-04-06 21:21:11 +00:00
$form [ 'pager' ] = array ( '#theme' => 'pager' );
2007-09-05 08:31:48 +00:00
return $form ;
}
2007-12-16 21:01:45 +00:00
/**
2011-11-10 03:02:40 +00:00
* Form submission handler for aggregator_categorize_items () .
2007-12-16 21:01:45 +00:00
*/
2007-09-13 08:02:38 +00:00
function aggregator_categorize_items_submit ( $form , & $form_state ) {
2007-12-17 13:05:30 +00:00
if ( ! empty ( $form_state [ 'values' ][ 'categories' ])) {
foreach ( $form_state [ 'values' ][ 'categories' ] as $iid => $selection ) {
2008-10-20 12:57:35 +00:00
db_delete ( 'aggregator_category_item' )
-> condition ( 'iid' , $iid )
-> execute ();
$insert = db_insert ( 'aggregator_category_item' ) -> fields ( array ( 'iid' , 'cid' ));
$has_values = FALSE ;
2007-12-17 13:05:30 +00:00
foreach ( $selection as $cid ) {
2008-10-20 12:57:35 +00:00
if ( $cid && $iid ) {
$has_values = TRUE ;
$insert -> values ( array (
'iid' => $iid ,
'cid' => $cid ,
));
2007-12-17 13:05:30 +00:00
}
2007-09-05 08:31:48 +00:00
}
2008-10-20 12:57:35 +00:00
if ( $has_values ) {
$insert -> execute ();
}
2007-09-05 08:31:48 +00:00
}
}
drupal_set_message ( t ( 'The categories have been saved.' ));
}
2012-03-14 04:26:18 +00:00
/**
* Default theme implementation to present a linked feed item for summaries .
*
* @ param $variables
* An associative array containing :
* - item_link : Link to item .
* - item_age : Age of the item .
*
* @ see template_preprocess ()
* @ see template_preprocess_aggregator_summary_item ()
*/
function theme_aggregator_summary_item ( $variables ) {
return $variables [ 'item_url' ] . ' ' . $variables [ 'item_age' ];
}
2007-09-05 08:31:48 +00:00
/**
2011-11-10 03:02:40 +00:00
* Processes variables for aggregator - item . tpl . php .
2007-09-05 08:31:48 +00:00
*
2007-09-13 08:02:38 +00:00
* @ see aggregator - item . tpl . php
2007-09-05 08:31:48 +00:00
*/
2007-09-13 08:02:38 +00:00
function template_preprocess_aggregator_item ( & $variables ) {
2013-02-01 17:35:27 +00:00
$item = $variables [ 'aggregator_item' ];
2007-09-13 08:02:38 +00:00
2013-02-01 17:35:27 +00:00
$variables [ 'feed_url' ] = check_url ( $item -> link -> value );
$variables [ 'feed_title' ] = check_plain ( $item -> title -> value );
$variables [ 'content' ] = aggregator_filter_xss ( $item -> description -> value );
2007-09-05 08:31:48 +00:00
2007-09-13 08:02:38 +00:00
$variables [ 'source_url' ] = '' ;
$variables [ 'source_title' ] = '' ;
2013-02-01 17:35:27 +00:00
if ( isset ( $item -> ftitle ) && isset ( $item -> fid -> value )) {
$variables [ 'source_url' ] = url ( " aggregator/sources/ $item->fid ->value " );
2007-09-13 08:02:38 +00:00
$variables [ 'source_title' ] = check_plain ( $item -> ftitle );
2007-09-05 08:31:48 +00:00
}
2013-02-01 17:35:27 +00:00
if ( date ( 'Ymd' , $item -> timestamp -> value ) == date ( 'Ymd' )) {
$variables [ 'source_date' ] = t ( '%ago ago' , array ( '%ago' => format_interval ( REQUEST_TIME - $item -> timestamp -> value )));
2007-09-05 08:31:48 +00:00
}
else {
2013-02-01 17:35:27 +00:00
$variables [ 'source_date' ] = format_date ( $item -> timestamp -> value , 'medium' );
2007-09-05 08:31:48 +00:00
}
2007-09-13 08:02:38 +00:00
$variables [ 'categories' ] = array ();
foreach ( $item -> categories as $category ) {
2008-04-14 17:48:46 +00:00
$variables [ 'categories' ][ $category -> cid ] = l ( $category -> title , 'aggregator/categories/' . $category -> cid );
2007-09-05 08:31:48 +00:00
}
}
/**
2013-01-04 18:37:34 +00:00
* Page callback : Displays all the feeds used by the Aggregator module .
*
* @ return string
* An HTML - formatted string .
2011-11-10 03:02:40 +00:00
*
* @ see aggregator_menu ()
2007-09-05 08:31:48 +00:00
*/
function aggregator_page_sources () {
2013-02-01 17:35:27 +00:00
$feeds = entity_load_multiple ( 'aggregator_feed' );
2007-09-05 08:31:48 +00:00
2013-02-01 17:35:27 +00:00
$build = array (
'#type' => 'container' ,
'#attributes' => array ( 'class' => array ( 'aggregator-wrapper' )),
'#sorted' => TRUE ,
);
foreach ( $feeds as $feed ) {
2007-09-05 08:31:48 +00:00
// Most recent items:
2007-09-13 08:02:38 +00:00
$summary_items = array ();
2012-07-25 15:10:29 +00:00
$aggregator_summary_items = config ( 'aggregator.settings' ) -> get ( 'source.list_max' );
if ( $aggregator_summary_items ) {
2013-02-01 17:35:27 +00:00
if ( $items = aggregator_load_feed_items ( 'source' , $feed , $aggregator_summary_items )) {
$summary_items = entity_view_multiple ( $items , 'summary' );
2007-09-05 08:31:48 +00:00
}
}
2013-02-01 17:35:27 +00:00
$feed -> url = url ( 'aggregator/sources/' . $feed -> id ());
$build [ $feed -> id ()] = array (
'#theme' => 'aggregator_summary_items' ,
'#summary_items' => $summary_items ,
'#source' => $feed ,
);
2007-09-05 08:31:48 +00:00
}
2013-02-01 17:35:27 +00:00
$build [ 'feed_icon' ] = array (
'#theme' => 'feed_icon' ,
'#url' => 'aggregator/opml' ,
'#title' => t ( 'OPML feed' ),
);
return $build ;
2007-09-05 08:31:48 +00:00
}
/**
2013-01-04 18:37:34 +00:00
* Page callback : Displays all the categories used by the Aggregator module .
*
* @ return string
* An HTML formatted string .
2011-11-10 03:02:40 +00:00
*
* @ see aggregator_menu ()
2007-09-05 08:31:48 +00:00
*/
function aggregator_page_categories () {
$result = db_query ( 'SELECT c.cid, c.title, c.description FROM {aggregator_category} c LEFT JOIN {aggregator_category_item} ci ON c.cid = ci.cid LEFT JOIN {aggregator_item} i ON ci.iid = i.iid GROUP BY c.cid, c.title, c.description' );
2013-02-01 17:35:27 +00:00
$build = array (
'#type' => 'container' ,
'#attributes' => array ( 'class' => array ( 'aggregator-wrapper' )),
'#sorted' => TRUE ,
);
$aggregator_summary_items = config ( 'aggregator.settings' ) -> get ( 'source.list_max' );
2008-10-20 12:57:35 +00:00
foreach ( $result as $category ) {
2013-02-01 17:35:27 +00:00
$summary_items = array ();
2012-07-25 15:10:29 +00:00
if ( $aggregator_summary_items ) {
2013-02-01 17:35:27 +00:00
if ( $items = aggregator_load_feed_items ( 'category' , $category , $aggregator_summary_items )) {
$summary_items = entity_view_multiple ( $items , 'summary' );
2007-09-05 08:31:48 +00:00
}
}
2008-04-14 17:48:46 +00:00
$category -> url = url ( 'aggregator/categories/' . $category -> cid );
2013-02-01 17:35:27 +00:00
$build [ $category -> cid ] = array (
'#theme' => 'aggregator_summary_items' ,
'#summary_items' => $summary_items ,
'#source' => $category ,
);
2007-09-05 08:31:48 +00:00
}
2013-02-01 17:35:27 +00:00
return $build ;
2007-09-05 08:31:48 +00:00
}
/**
2011-11-10 03:02:40 +00:00
* Page callback : Generates an RSS 0.92 feed of aggregator items or categories .
*
2013-01-04 18:37:34 +00:00
* @ return string
* An HTML formatted string .
*
2011-11-10 03:02:40 +00:00
* @ see aggregator_menu ()
2007-09-05 08:31:48 +00:00
*/
function aggregator_page_rss () {
$result = NULL ;
2012-07-26 21:09:56 +00:00
$rss_config = config ( 'system.rss' );
2008-05-15 21:27:32 +00:00
// arg(2) is the passed cid, only select for that category.
2007-09-05 08:31:48 +00:00
if ( arg ( 2 )) {
2008-10-20 12:57:35 +00:00
$category = db_query ( 'SELECT cid, title FROM {aggregator_category} WHERE cid = :cid' , array ( ':cid' => arg ( 2 ))) -> fetchObject ();
2012-07-26 21:09:56 +00:00
$result = db_query_range ( 'SELECT i.*, f.title AS ftitle, f.link AS flink FROM {aggregator_category_item} c LEFT JOIN {aggregator_item} i ON c.iid = i.iid LEFT JOIN {aggregator_feed} f ON i.fid = f.fid WHERE cid = :cid ORDER BY timestamp DESC, i.iid DESC' , 0 , $rss_config -> get ( 'items.limit' ), array ( ':cid' => $category -> cid ));
2007-09-05 08:31:48 +00:00
}
2008-05-15 21:27:32 +00:00
// Or, get the default aggregator items.
2007-09-05 08:31:48 +00:00
else {
2007-09-13 08:02:38 +00:00
$category = NULL ;
2012-07-26 21:09:56 +00:00
$result = db_query_range ( 'SELECT i.*, f.title AS ftitle, f.link AS flink FROM {aggregator_item} i INNER JOIN {aggregator_feed} f ON i.fid = f.fid ORDER BY i.timestamp DESC, i.iid DESC' , 0 , $rss_config -> get ( 'items.limit' ));
2007-09-13 08:02:38 +00:00
}
2008-05-15 21:27:32 +00:00
2008-10-20 12:57:35 +00:00
$feeds = $result -> fetchAll ();
2009-10-09 01:00:08 +00:00
return theme ( 'aggregator_page_rss' , array ( 'feeds' => $feeds , 'category' => $category ));
2007-09-13 08:02:38 +00:00
}
/**
2010-04-13 15:23:03 +00:00
* Prints the RSS page for a feed .
2007-09-13 08:02:38 +00:00
*
2009-10-09 01:00:08 +00:00
* @ param $variables
* An associative array containing :
* - feeds : An array of the feeds to theme .
* - category : A common category , if any , for all the feeds .
*
2010-04-13 15:23:03 +00:00
* @ return void
*
2007-09-13 08:02:38 +00:00
* @ ingroup themeable
*/
2009-10-09 01:00:08 +00:00
function theme_aggregator_page_rss ( $variables ) {
$feeds = $variables [ 'feeds' ];
$category = $variables [ 'category' ];
2009-09-30 18:36:02 +00:00
drupal_add_http_header ( 'Content-Type' , 'application/rss+xml; charset=utf-8' );
2007-09-13 08:02:38 +00:00
$items = '' ;
2012-07-26 21:09:56 +00:00
$feed_length = config ( 'system.rss' ) -> get ( 'items.view_mode' );
2007-09-13 08:02:38 +00:00
foreach ( $feeds as $feed ) {
switch ( $feed_length ) {
2007-09-05 08:31:48 +00:00
case 'teaser' :
2012-07-25 15:10:29 +00:00
$summary = text_summary ( $feed -> description , NULL , config ( 'aggregator.settings' ) -> get ( 'items.teaser_length' ));
2009-06-12 08:39:40 +00:00
if ( $summary != $feed -> description ) {
$summary .= '<p><a href="' . check_url ( $feed -> link ) . '">' . t ( 'read more' ) . " </a></p> \n " ;
2007-09-05 08:31:48 +00:00
}
2009-06-12 08:39:40 +00:00
$feed -> description = $summary ;
2007-09-05 08:31:48 +00:00
break ;
case 'title' :
2007-09-13 08:02:38 +00:00
$feed -> description = '' ;
2007-09-05 08:31:48 +00:00
break ;
}
2008-04-14 17:48:46 +00:00
$items .= format_rss_item ( $feed -> ftitle . ': ' . $feed -> title , $feed -> link , $feed -> description , array ( 'pubDate' => date ( 'r' , $feed -> timestamp )));
2007-09-05 08:31:48 +00:00
}
2012-07-02 17:20:33 +00:00
$site_name = config ( 'system.site' ) -> get ( 'name' );
2008-04-14 17:48:46 +00:00
$url = url (( isset ( $category ) ? 'aggregator/categories/' . $category -> cid : 'aggregator' ), array ( 'absolute' => TRUE ));
2007-12-16 18:06:27 +00:00
$description = isset ( $category ) ? t ( '@site_name - aggregated feeds in category @title' , array ( '@site_name' => $site_name , '@title' => $category -> title )) : t ( '@site_name - aggregated feeds' , array ( '@site_name' => $site_name ));
2007-09-13 08:02:38 +00:00
2008-05-15 21:27:32 +00:00
$output = " <?xml version= \" 1.0 \" encoding= \" utf-8 \" ?> \n " ;
2007-09-05 08:31:48 +00:00
$output .= " <rss version= \" 2.0 \" > \n " ;
2007-12-16 18:06:27 +00:00
$output .= format_rss_channel ( t ( '@site_name aggregator' , array ( '@site_name' => $site_name )), $url , $description , $items );
2007-09-05 08:31:48 +00:00
$output .= " </rss> \n " ;
print $output ;
}
/**
2011-11-10 03:02:40 +00:00
* Page callback : Generates an OPML representation of all feeds .
*
2007-12-16 21:01:45 +00:00
* @ param $cid
2013-01-04 18:37:34 +00:00
* ( optional ) If set , feeds are exported only from a category with this ID .
* Otherwise , all feeds are exported . Defaults to NULL .
*
* @ return string
* An OPML formatted string .
2011-11-10 03:02:40 +00:00
*
* @ see aggregator_menu ()
2007-09-05 08:31:48 +00:00
*/
function aggregator_page_opml ( $cid = NULL ) {
if ( $cid ) {
2008-10-20 12:57:35 +00:00
$result = db_query ( 'SELECT f.title, f.url FROM {aggregator_feed} f LEFT JOIN {aggregator_category_feed} c on f.fid = c.fid WHERE c.cid = :cid ORDER BY title' , array ( ':cid' => $cid ));
2007-09-05 08:31:48 +00:00
}
else {
$result = db_query ( 'SELECT * FROM {aggregator_feed} ORDER BY title' );
}
2007-10-02 16:03:17 +00:00
2008-10-20 12:57:35 +00:00
$feeds = $result -> fetchAll ();
2009-10-09 01:00:08 +00:00
return theme ( 'aggregator_page_opml' , array ( 'feeds' => $feeds ));
2007-09-13 08:02:38 +00:00
}
/**
2013-01-04 18:37:34 +00:00
* Prints the OPML page for the feed .
2007-09-13 08:02:38 +00:00
*
2013-01-04 18:37:34 +00:00
* @ param array $variables
2009-10-09 01:00:08 +00:00
* An associative array containing :
* - feeds : An array of the feeds to theme .
*
2007-09-13 08:02:38 +00:00
* @ ingroup themeable
*/
2009-10-09 01:00:08 +00:00
function theme_aggregator_page_opml ( $variables ) {
$feeds = $variables [ 'feeds' ];
2009-09-30 18:36:02 +00:00
drupal_add_http_header ( 'Content-Type' , 'text/xml; charset=utf-8' );
2007-09-05 08:31:48 +00:00
2008-05-15 21:27:32 +00:00
$output = " <?xml version= \" 1.0 \" encoding= \" utf-8 \" ?> \n " ;
2007-09-05 08:31:48 +00:00
$output .= " <opml version= \" 1.1 \" > \n " ;
$output .= " <head> \n " ;
2012-07-02 17:20:33 +00:00
$output .= '<title>' . check_plain ( config ( 'system.site' ) -> get ( 'name' )) . " </title> \n " ;
2009-09-25 23:53:26 +00:00
$output .= '<dateModified>' . gmdate ( DATE_RFC2822 , REQUEST_TIME ) . " </dateModified> \n " ;
2007-09-05 08:31:48 +00:00
$output .= " </head> \n " ;
$output .= " <body> \n " ;
2007-09-13 08:02:38 +00:00
foreach ( $feeds as $feed ) {
2008-04-14 17:48:46 +00:00
$output .= '<outline text="' . check_plain ( $feed -> title ) . '" xmlUrl="' . check_url ( $feed -> url ) . " \" /> \n " ;
2007-09-05 08:31:48 +00:00
}
$output .= " </body> \n " ;
$output .= " </opml> \n " ;
print $output ;
}
/**
2011-11-10 03:02:40 +00:00
* Processes variables for aggregator - summary - items . tpl . php .
2007-09-05 08:31:48 +00:00
*
2010-10-15 23:37:55 +00:00
* @ see aggregator - summary - items . tpl . php
2007-09-13 08:02:38 +00:00
*/
function template_preprocess_aggregator_summary_items ( & $variables ) {
2013-02-26 23:29:42 +00:00
$variables [ 'title' ] = check_plain ( $variables [ 'source' ] instanceof EntityInterface ? $variables [ 'source' ] -> label () : $variables [ 'source' ] -> title );
2013-02-01 17:35:27 +00:00
$summary_items = array ();
foreach ( element_children ( $variables [ 'summary_items' ]) as $key ) {
$summary_items [] = $variables [ 'summary_items' ][ $key ];
}
$variables [ 'summary_list' ] = array (
'#theme' => 'item_list' ,
'#items' => $summary_items ,
);
2013-02-26 23:29:42 +00:00
$variables [ 'source_url' ] = $variables [ 'source' ] instanceof EntityInterface ? $variables [ 'source' ] -> url -> value : $variables [ 'source' ] -> url ;
2007-09-13 08:02:38 +00:00
}
/**
2011-11-10 03:02:40 +00:00
* Processes variables for aggregator - summary - item . tpl . php .
2007-09-13 08:02:38 +00:00
*
* @ see aggregator - summary - item . tpl . php
2007-09-05 08:31:48 +00:00
*/
2007-09-13 08:02:38 +00:00
function template_preprocess_aggregator_summary_item ( & $variables ) {
2013-02-01 17:35:27 +00:00
$item = $variables [ 'aggregator_item' ];
2007-09-13 08:02:38 +00:00
2013-02-01 17:35:27 +00:00
$variables [ 'item_url' ] = l ( check_plain ( $item -> label ()), check_url ( url ( $item -> link -> value , array ( 'absolute' => TRUE ))), array (
2012-03-14 04:26:18 +00:00
'attributes' => array (
'class' => array ( 'feed-item-url' ,),
),
));
$variables [ 'item_age' ] = theme ( 'datetime' , array (
'attributes' => array (
2013-02-01 17:35:27 +00:00
'datetime' => format_date ( $item -> timestamp -> value , 'html_datetime' , '' , 'UTC' ),
2012-03-14 04:26:18 +00:00
'class' => array ( 'feed-item-age' ,),
),
2013-02-01 17:35:27 +00:00
'text' => t ( '%age old' , array ( '%age' => format_interval ( REQUEST_TIME - $item -> timestamp -> value ))),
2012-03-14 04:26:18 +00:00
'html' => TRUE ,
));
2007-09-05 08:31:48 +00:00
}
/**
2011-11-10 03:02:40 +00:00
* Processes variables for aggregator - feed - source . tpl . php .
2007-09-05 08:31:48 +00:00
*
2007-09-13 08:02:38 +00:00
* @ see aggregator - feed - source . tpl . php
2007-09-05 08:31:48 +00:00
*/
2007-09-13 08:02:38 +00:00
function template_preprocess_aggregator_feed_source ( & $variables ) {
2013-02-01 17:35:27 +00:00
$feed = $variables [ 'aggregator_feed' ];
2007-10-02 16:03:17 +00:00
2013-02-01 17:35:27 +00:00
$variables [ 'source_icon' ] = theme ( 'feed_icon' , array ( 'url' => $feed -> url -> value , 'title' => t ( '!title feed' , array ( '!title' => $feed -> label ()))));
2011-10-10 00:52:35 +00:00
2013-02-01 17:35:27 +00:00
if ( ! empty ( $feed -> image -> value ) && $feed -> label () && ! empty ( $feed -> link -> value )) {
$variables [ 'source_image' ] = l ( theme ( 'image' , array ( 'path' => $feed -> image -> value , 'alt' => $feed -> title -> value )), $feed -> link -> value , array ( 'html' => TRUE , 'attributes' => array ( 'class' => 'feed-image' )));
2011-10-10 00:52:35 +00:00
}
else {
$variables [ 'source_image' ] = '' ;
}
2013-02-01 17:35:27 +00:00
$variables [ 'source_description' ] = aggregator_filter_xss ( $feed -> description -> value );
$variables [ 'source_url' ] = check_url ( url ( $feed -> link -> value , array ( 'absolute' => TRUE )));
2007-09-05 08:31:48 +00:00
if ( $feed -> checked ) {
2013-02-01 17:35:27 +00:00
$variables [ 'last_checked' ] = t ( '@time ago' , array ( '@time' => format_interval ( REQUEST_TIME - $feed -> checked -> value )));
2007-09-05 08:31:48 +00:00
}
else {
2007-09-13 08:02:38 +00:00
$variables [ 'last_checked' ] = t ( 'never' );
2007-09-05 08:31:48 +00:00
}
if ( user_access ( 'administer news feeds' )) {
2009-08-24 17:11:42 +00:00
$variables [ 'last_checked' ] = l ( $variables [ 'last_checked' ], 'admin/config/services/aggregator' );
2007-09-05 08:31:48 +00:00
}
}