PageRenderTime 48ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/include/AMP/Content/Article/Public/List.php

https://github.com/radicalsuz/amp
PHP | 279 lines | 188 code | 51 blank | 40 comment | 37 complexity | 5248556b7fd8c35cd4bac592a1c80b0b MD5 | raw file
Possible License(s): AGPL-1.0, GPL-2.0, LGPL-2.1, LGPL-2.0
  1. <?php
  2. require_once('AMP/Display/List.php');
  3. require_once('AMP/Content/Article.inc.php');
  4. class Article_Public_List extends AMP_Display_List {
  5. var $name = 'Article_List';
  6. var $_source_object = 'Article';
  7. var $_suppress_messages = true;
  8. var $_pager_active = true;
  9. var $_pager_limit = 100;
  10. var $_class_pager = 'AMP_Display_Pager_Content';
  11. var $_path_pager = 'AMP/Display/Pager/Content.php';
  12. var $_source_criteria = array( 'displayable' => 1 );
  13. var $_sort_sql_default = 'default';
  14. var $_sort_sql_translations = array(
  15. 'default' => 'date DESC, id DESC'
  16. );
  17. var $_css_class_author = AMP_CONTENT_CSS_CLASS_LIST_ARTICLE_AUTHOR ;
  18. var $_css_class_source = AMP_CONTENT_CSS_CLASS_LIST_ARTICLE_SOURCE;
  19. var $_css_class_container_list = "article_public_list list_block";
  20. var $_search;
  21. var $_search_fields_xml = 'AMP/Content/Article/Public/Search/Fields.xml';
  22. //section, class, or tag this list represents
  23. var $_source_container;
  24. function Article_Public_List ( $container = false, $criteria = array(), $limit = null ) {
  25. $this->__construct($container, $criteria, $limit );
  26. }
  27. function __construct( $container= false, $criteria = array( ), $limit = null ) {
  28. $source = $this->_init_container( $container );
  29. parent::__construct( $source, $criteria, $limit );
  30. }
  31. function _init_identity( ) {
  32. parent::_init_identity( );
  33. if( isset( $this->_source_container )) {
  34. $this->_css_class_container_list = $this->_css_class_container_list . ' list_' . strtolower( get_class( $this->_source_container )) . '_' . $this->_source_container->id;
  35. }
  36. }
  37. function _init_container( $container ) {
  38. if ( !$container ) return false;
  39. if ( is_array( $container )) return $container;
  40. $allowed_containers = array( 'section', 'contentclass', 'amp_content_tag');
  41. if ( array_search( strtolower( get_class( $container )), $allowed_containers) === FALSE ) {
  42. return $container;
  43. }
  44. $this->_source_container = &$container;
  45. return false;
  46. }
  47. function _init_pager( $limit = null ) {
  48. $has_pager = parent::_init_pager( $limit );
  49. if( $has_pager && isset( $this->_source_container )) {
  50. $this->_pager->describe( $this->_source_container->getName( ));
  51. }
  52. }
  53. function set_container( &$container ) {
  54. $this->_source_container = &$container;
  55. }
  56. function _init_display_methods( ) {
  57. if ( $this->_item_display_method == '_renderItem' ) {
  58. return parent::_init_display_methods( );
  59. }
  60. }
  61. function _renderItem( &$source ) {
  62. $text = $this->render_title( $source )
  63. . $this->render_byline($source )
  64. . $this->render_date( $source )
  65. . $this->render_blurb( $source );
  66. $image = $this->render_image( $source );
  67. $image_css = $image ? AMP_CONTENT_CSS_CLASS_LIST_IMAGE : AMP_CONTENT_CSS_CLASS_LIST_IMAGE_EMPTY;
  68. $description_css = $image ? AMP_CONTENT_CSS_CLASS_LIST_DESCRIPTION_WITH_IMAGE : AMP_CONTENT_CSS_CLASS_LIST_DESCRIPTION;
  69. return $this->_renderer->div( $image, array( 'class' => $image_css ))
  70. . $this->_renderer->div( $text, array( 'class' => $description_css ));
  71. }
  72. function _renderHeader( ) {
  73. //stub
  74. return $this->render_search_form( )
  75. . $this->_renderPagerHeader( );
  76. }
  77. function &_init_search_factory( ) {
  78. $false = false;
  79. //check to see if a custom search method has been defined, the parent method will call that
  80. if( ( $this->_search_create_method == 'create_search_form') && isset( $this->_source_container ) && method_exists( $this->_source_container, 'getAllowSearchDisplay')) {
  81. if ( method_exists( $this->_source_container, 'getCustomSearch') && ( $search_method = $this->_source_container->getCustomSearch( ))) {
  82. $this->set_display_search_method( $search_method );
  83. }
  84. }
  85. $base_search = &parent::_init_search_factory( );
  86. return $base_search;
  87. }
  88. function &create_search_form( ) {
  89. $false = false;
  90. //if this is not a section based list, use the parent search create method
  91. if( !( isset( $this->_source_container ) && ( strtolower( get_class( $this->_source_container )) == 'section' ))) {
  92. $result = &parent::create_search_form( );
  93. return $result;
  94. }
  95. //if the section does not allow search display, return false
  96. if ( !$this->_source_container->getAllowSearchDisplay( )) return $false;
  97. //have a search created based on xml
  98. $search = $this->create_search_form_from_xml( );
  99. return $search;
  100. }
  101. function &create_search_form_from_xml( ) {
  102. $search = parent::create_search_form_from_xml( );
  103. if( !$search ) return $search;
  104. //set defaults for the current section
  105. $search->add_field( 'section_logic', array( 'type' => 'hidden', 'value' => $this->_source_container->id ));
  106. $search->add_field( 'template_section', array( 'type' => 'hidden', 'value' => $this->_source_container->id ));
  107. return $search;
  108. }
  109. function url_for( $source ) {
  110. if ( !method_exists( $source, 'getURL' )) return false;
  111. return $source->getURL( );
  112. }
  113. function render_title( $source ) {
  114. $url = $this->url_for( $source );
  115. return $this->_renderer->link( $url, $source->getName( ), array( 'class' => AMP_CONTENT_CSS_CLASS_LIST_ARTICLE_TITLE ))
  116. . $this->_renderer->newline( );
  117. }
  118. /*
  119. function render_source( &$article ) {
  120. $author = $article->getAuthor();
  121. $source_name = $article->getSource();
  122. $source_url = $article->getSourceUrl();
  123. if (!(trim($author) || $source_name || $source_url)) return false;
  124. $output_author = FALSE;
  125. $output_source = FALSE;
  126. if (trim($author)) {
  127. $output_author = $this->_renderer->span( sprintf( AMP_TEXT_BYLINE_SLUG, converttext($author)), array( 'class' => AMP_CONTENT_CSS_CLASS_LIST_ARTICLE_AUTHOR ));
  128. }
  129. if ($source_name || $source_url) {
  130. if ( !$source_name ) {
  131. $source_name = $source_url;
  132. }
  133. $output_source = $this->_renderer->span( $this->_renderer->link( $source_url, $source_name ), array( 'class' => AMP_CONTENT_CSS_CLASS_LIST_ARTICLE_SOURCE ));
  134. }
  135. if (!$output_author){
  136. return $output_source . $this->_renderer->newline();
  137. }
  138. if ( !$output_source ) {
  139. return $output_author . $this->_renderer->newline();
  140. }
  141. return $output_author . ', '
  142. . $output_source . $this->_renderer->newline();
  143. }
  144. */
  145. function render_byline( $source ) {
  146. $output_author = $this->render_author( $source );
  147. $output_source = $this->render_source( $source );
  148. if ( !( $output_source || $output_author )) return false;
  149. if (!$output_author){
  150. return $output_source . $this->_renderer->newline();
  151. }
  152. if ( !$output_source ) {
  153. return $output_author . $this->_renderer->newline();
  154. }
  155. return $output_author . ',' . $this->_renderer->space()
  156. . $output_source . $this->_renderer->newline();
  157. }
  158. function render_author( $source ) {
  159. $author = $source->getAuthor();
  160. if (!trim($author)) return false;
  161. return $this->_renderer->span( sprintf( AMP_TEXT_BYLINE_SLUG, converttext($author)), array( 'class' => $this->_css_class_author ));
  162. }
  163. function render_source( $source ) {
  164. $source_name = $source->getSource();
  165. $source_url = $source->getSourceUrl();
  166. if (!( $source_name || $source_url )) return false;
  167. if ( !$source_name ) {
  168. $source_name = $source_url;
  169. }
  170. return $this->_renderer->span( $this->_renderer->link( $source_url, $source_name ), array( 'class' => $this->_css_class_source ));
  171. }
  172. function render_date( &$source ) {
  173. $date = $source->getItemDate();
  174. if (!$date) return false;
  175. return $this->_renderer->span( DoDate( $date, AMP_CONTENT_DATE_FORMAT), array( 'class' => AMP_CONTENT_CSS_CLASS_LIST_ARTICLE_DATE ))
  176. . $this->_renderer->newline();
  177. }
  178. function render_image( &$source ) {
  179. $image = $source->getImageFile();
  180. if ( !$image) return $this->render_image_media_thumbnail( $source );
  181. $img_output = $this->_renderer->image( AMP_image_url( $image->getName(), AMP_IMAGE_CLASS_THUMB));
  182. $url = $this->url_for( $source ) ;
  183. if ( !$url ) {
  184. return $img_output;
  185. }
  186. return $this->_renderer->link( $url, $img_output );
  187. }
  188. function render_image_media_thumbnail( $source ) {
  189. $image_url = $source->getMediaThumbnailUrl( );
  190. if ( !$image_url ) return false;
  191. return $this->_renderer->link(
  192. $this->url_for( $source ),
  193. $this->_renderer->image( $image_url )
  194. );
  195. }
  196. function render_blurb( $source ) {
  197. if( !( $blurb = $source->getBlurb( ))) return false;
  198. return $this->_renderer->div( $source->getBlurb(), array( 'class' => AMP_CONTENT_CSS_CLASS_LIST_BLURB ) );
  199. }
  200. function _output_empty( ) {
  201. return $this->render_search_form( );
  202. }
  203. function _init_sort_sql( &$source ) {
  204. $sort_options = AMP_lookup( 'list_sort_options_article');
  205. if ( $sort_options ) {
  206. $this->_sort_sql_translations = array_merge( $this->_sort_sql_translations, $sort_options );
  207. }
  208. return parent::_init_sort_sql( $source );
  209. }
  210. function _sort_requested( ) {
  211. $http_request = parent::_sort_requested( );
  212. if ( $http_request || !isset( $this->_source_container )) return $http_request;
  213. if ( !method_exists( $this->_source_container, 'getListSort')) return false;
  214. return $this->_source_container->getListSort( );
  215. }
  216. function addFilter( $filter_name, $filter_var=null ) {
  217. $filter_def = isset( $filter_var ) ? array( 'name' => $filter_name, 'var' => $filter_var ) : $filter_name;
  218. $this->_source_criteria['filter'] = $filter_def;
  219. $this->__construct( false, $this->_source_criteria );
  220. }
  221. }
  222. ?>