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-08-18 21:16:19 +00:00
use Drupal\aggregator\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-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
*
2013-08-03 11:15:55 +00:00
* @ param string $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 .
2013-08-03 11:15:55 +00:00
* @ param mixed $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' .
2013-08-03 11:15:55 +00:00
* @ param int $limit
* ( optional ) The number of records to return . Defaults to 20.
2011-11-09 15:46:01 +00:00
*
2013-08-03 11:15:55 +00:00
* @ deprecated Use \Drupal\aggregator\ItemStorageController :: loadAll () for
* loading all feed items , \Drupal\aggregator\ItemStorageController :: loadByFeed ()
* for loading feed items filtered by the source feed , and \Drupal\aggregator\ItemStorageController :: loadByCategory ()
* for loading feed items filtered by the feed category .
*
* @ return \Drupal\aggregator\ItemInterface []
2007-12-16 21:01:45 +00:00
* 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 ) {
2013-09-16 03:58:06 +00:00
$storage_controller = \Drupal :: entityManager () -> getStorageController ( 'aggregator_item' );
2008-10-20 12:57:35 +00:00
switch ( $type ) {
case 'sum' :
2013-08-03 11:15:55 +00:00
return $storage_controller -> loadAll ( $limit );
2008-10-20 12:57:35 +00:00
case 'source' :
2013-08-03 11:15:55 +00:00
return $storage_controller -> loadByFeed ( $data -> id (), $limit );
2008-10-20 12:57:35 +00:00
case 'category' :
2013-08-03 11:15:55 +00:00
return $storage_controller -> loadByCategory ( $data -> cid , $limit );
2008-10-20 12:57:35 +00:00
}
2007-09-05 08:31:48 +00:00
}
/**
Issue #1896060 by shanethehat, Cottser, joelpittet, disasm, ParisLiakos, Floydm, stevector, jenlampton, c4rl, mr.baileys, thedavidmeister, jwilson3: aggregator.module - Convert PHPTemplate templates to Twig.
2013-05-24 16:57:09 +00:00
* Prepares variables for aggregator item templates .
2007-09-05 08:31:48 +00:00
*
Issue #1896060 by shanethehat, Cottser, joelpittet, disasm, ParisLiakos, Floydm, stevector, jenlampton, c4rl, mr.baileys, thedavidmeister, jwilson3: aggregator.module - Convert PHPTemplate templates to Twig.
2013-05-24 16:57:09 +00:00
* Default template : aggregator - item . html . twig .
*
* @ param array $variables
* An associative array containing :
* - aggregator_item : An individual feed item for display on the aggregator
* page .
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
}
Issue #1896060 by shanethehat, Cottser, joelpittet, disasm, ParisLiakos, Floydm, stevector, jenlampton, c4rl, mr.baileys, thedavidmeister, jwilson3: aggregator.module - Convert PHPTemplate templates to Twig.
2013-05-24 16:57:09 +00:00
$variables [ 'attributes' ][ 'class' ][] = 'feed-item' ;
2007-09-05 08:31:48 +00:00
}
/**
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 ()
2013-09-18 18:30:30 +00:00
*
* @ deprecated Use \Drupal\aggregator\Controller\AggregatorController :: opmlPage ()
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 ();
2013-06-24 08:12:50 +00:00
$aggregator_page_opml = array (
'#theme' => 'aggregator_page_opml' ,
'#feeds' => $feeds ,
);
return drupal_render ( $aggregator_page_opml );
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 " ;
2013-09-16 03:58:06 +00:00
$output .= '<title>' . check_plain ( \Drupal :: 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 ;
}
/**
Issue #1896060 by shanethehat, Cottser, joelpittet, disasm, ParisLiakos, Floydm, stevector, jenlampton, c4rl, mr.baileys, thedavidmeister, jwilson3: aggregator.module - Convert PHPTemplate templates to Twig.
2013-05-24 16:57:09 +00:00
* Prepares variables for aggregator summary templates .
2007-09-05 08:31:48 +00:00
*
Issue #1896060 by shanethehat, Cottser, joelpittet, disasm, ParisLiakos, Floydm, stevector, jenlampton, c4rl, mr.baileys, thedavidmeister, jwilson3: aggregator.module - Convert PHPTemplate templates to Twig.
2013-05-24 16:57:09 +00:00
* Default template : aggregator - summary - items . html . twig .
*
* @ param array $variables
* An associative array containing :
2013-08-18 21:16:19 +00:00
* - source : A Drupal\aggregator\Entity\Feed instance representing
Issue #1896060 by shanethehat, Cottser, joelpittet, disasm, ParisLiakos, Floydm, stevector, jenlampton, c4rl, mr.baileys, thedavidmeister, jwilson3: aggregator.module - Convert PHPTemplate templates to Twig.
2013-05-24 16:57:09 +00:00
* the feed source .
* - summary_items : An array of feed items .
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
}
/**
Issue #1896060 by shanethehat, Cottser, joelpittet, disasm, ParisLiakos, Floydm, stevector, jenlampton, c4rl, mr.baileys, thedavidmeister, jwilson3: aggregator.module - Convert PHPTemplate templates to Twig.
2013-05-24 16:57:09 +00:00
* Processes variables for aggregator summary item templates .
2007-09-13 08:02:38 +00:00
*
Issue #1896060 by shanethehat, Cottser, joelpittet, disasm, ParisLiakos, Floydm, stevector, jenlampton, c4rl, mr.baileys, thedavidmeister, jwilson3: aggregator.module - Convert PHPTemplate templates to Twig.
2013-05-24 16:57:09 +00:00
* Default template : aggregator - summary - item . html . twig .
*
* @ param array $variables
* An associative array containing :
* - aggregator_item : The feed item .
* - view_mode : How the item is being displayed .
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-10-02 12:58:01 +00:00
$variables [ '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' ,),
),
));
2013-10-02 12:58:01 +00:00
$variables [ 'age' ] = array (
2013-06-24 08:12:50 +00:00
'#theme' => 'datetime' ,
'#attributes' => array (
2013-02-01 17:35:27 +00:00
'datetime' => format_date ( $item -> timestamp -> value , 'html_datetime' , '' , 'UTC' ),
2013-10-02 12:58:01 +00:00
'class' => array ( 'feed-item-age' ),
2012-03-14 04:26:18 +00:00
),
2013-06-24 08:12:50 +00:00
'#text' => t ( '%age old' , array ( '%age' => format_interval ( REQUEST_TIME - $item -> timestamp -> value ))),
'#html' => TRUE ,
);
2007-09-05 08:31:48 +00:00
}
/**
Issue #1896060 by shanethehat, Cottser, joelpittet, disasm, ParisLiakos, Floydm, stevector, jenlampton, c4rl, mr.baileys, thedavidmeister, jwilson3: aggregator.module - Convert PHPTemplate templates to Twig.
2013-05-24 16:57:09 +00:00
* Prepares variables for aggregator feed source templates .
*
* Default template : aggregator - feed - source . html . twig .
2007-09-05 08:31:48 +00:00
*
Issue #1896060 by shanethehat, Cottser, joelpittet, disasm, ParisLiakos, Floydm, stevector, jenlampton, c4rl, mr.baileys, thedavidmeister, jwilson3: aggregator.module - Convert PHPTemplate templates to Twig.
2013-05-24 16:57:09 +00:00
* @ param array $variables
* An associative array containing :
2013-08-18 21:16:19 +00:00
* - aggregator_feed : A Drupal\aggregator\Entity\Feed instance
Issue #1896060 by shanethehat, Cottser, joelpittet, disasm, ParisLiakos, Floydm, stevector, jenlampton, c4rl, mr.baileys, thedavidmeister, jwilson3: aggregator.module - Convert PHPTemplate templates to Twig.
2013-05-24 16:57:09 +00:00
* representing the feed source .
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-06-24 08:12:50 +00:00
$feed_icon = array (
'#theme' => 'feed_icon' ,
'#url' => $feed -> url -> value ,
'#title' => t ( '!title feed' , array ( '!title' => $feed -> label ())),
);
$variables [ 'source_icon' ] = drupal_render ( $feed_icon );
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 )) {
2013-06-24 08:12:50 +00:00
$image = array (
'#theme' => 'image' ,
'#path' => $feed -> image -> value ,
'#alt' => $feed -> title -> value ,
);
$variables [ 'source_image' ] = l ( $image , $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
}
Issue #1896060 by shanethehat, Cottser, joelpittet, disasm, ParisLiakos, Floydm, stevector, jenlampton, c4rl, mr.baileys, thedavidmeister, jwilson3: aggregator.module - Convert PHPTemplate templates to Twig.
2013-05-24 16:57:09 +00:00
$variables [ 'attributes' ][ 'class' ][] = 'feed-source' ;
2007-09-05 08:31:48 +00:00
}