Advertisement
Guest User

postheader.php

a guest
Nov 9th, 2012
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.69 KB | None | 0 0
  1. postheader.php
  2.  
  3. <?php
  4.  
  5. class ppPostHeader {
  6.  
  7. private $post;
  8. private $dateBeforeTitle;
  9. private $dateSameLineWithTitle;
  10. private $dateInMeta;
  11.  
  12. public static function render( ppPost $post ) {
  13. $postHeader = new ppPostHeader( $post );
  14. echo $postHeader->completeMarkup();
  15. }
  16.  
  17. public function completeMarkup() {
  18. return
  19. '<div class="article-header ' . ppOpt::id( 'postdate_display' ) . '" data-role="header">' .
  20. $this->dateBeforeTitle .
  21. $this->titleDiv() .
  22. $this->entryMeta() .
  23. '</div>';
  24. }
  25.  
  26. protected function __construct( ppPost $post ) {
  27. $this->post = $post;
  28. $this->setupDateProperties();
  29. }
  30.  
  31. protected function titleDiv() {
  32. $linkedTitle = NrHtml::a(
  33. $this->post->permalink(),
  34. $this->post->title(),
  35. 'title=Permalink to ' . esc_attr( $this->post->title() ) . '&rel=bookmark'
  36. );
  37.  
  38. $title = ( is_singular() || is_404() ) ? $this->post->title() : $linkedTitle;
  39.  
  40. if ( !ppQuery::instance()->isGalleryQuasiPage() ) {
  41. if ( $this->editLinkBeforeTitle() ) {
  42. $title = ppUtil::ob( 'edit_post_link', 'Edit' ) . $title;
  43. } else {
  44. $title .= ppUtil::ob( 'edit_post_link', 'Edit' );
  45. }
  46. }
  47.  
  48. return
  49. '<div class="article-title-wrap">' .
  50. $this->dateSameLineWithTitle .
  51. NrHtml::h( $this->headerTagNum(), $title, 'class=article-title' ) .
  52. '</div>';
  53. }
  54.  
  55. protected function entryMeta() {
  56. if ( is_page() || is_404() || ppUtil::isEmptySearch() ) {
  57. return;
  58. }
  59.  
  60. $metaElements = '';
  61. if ( !is_search() ) {
  62. $metaElements .= $this->categoryList();
  63. $metaElements .= $this->tagList();
  64. $metaElements .= $this->commentCount();
  65. }
  66.  
  67. if ( $this->dateInMeta || $metaElements ) {
  68. return
  69. '<div class="article-meta article-meta-top">' .
  70. $this->dateInMeta . $metaElements .
  71. '</div>';
  72. }
  73. }
  74.  
  75. protected function dateMarkup() {
  76. return
  77. '<span class="article-date article-meta-item">
  78. <span>' .
  79. $this->publishedDay() . ' ' . $this->publishedTime() .
  80. '</span>
  81. </span>';
  82. }
  83.  
  84. protected function publishedDay() {
  85. if ( ppOpt::test( 'postdate_display', 'boxy' ) ) {
  86. $day = $this->post->publishedDate( 'd' );
  87. $month = $this->post->publishedDate( 'M' );
  88. $year = $this->post->publishedDate( 'Y' );
  89. return
  90. "<div class='boxy-date-wrap'>
  91. <span class='boxy-month'>$month</span>
  92. <span class='boxy-day'>$day</span>
  93. <span class='boxy-year'>$year</span>
  94. </div>";
  95.  
  96. } else if ( ppOpt::test( 'dateformat', 'custom' ) ) {
  97. return $this->post->publishedDate( ppOpt::id( 'dateformat_custom' ) );
  98.  
  99. } else {
  100. return $this->post->publishedDate( ppOpt::id( 'dateformat' ) );
  101. }
  102. }
  103.  
  104. protected function publishedTime() {
  105. if ( ppOpt::test( 'show_post_published_time', 'yes' ) && !ppOpt::test( 'postdate_display', 'boxy' ) ) {
  106. return get_the_time();
  107. }
  108. }
  109.  
  110. protected function headerTagNum() {
  111. if ( is_singular() ) {
  112. return '1';
  113. } elseif ( !is_archive() ) {
  114. return '2';
  115. } else {
  116. return '3';
  117. }
  118. }
  119.  
  120. protected function categoryList() {
  121. if ( ppOpt::test( 'categories_in_post_header', 'yes' ) ) {
  122. return ppHtml::categoryList();
  123. }
  124. }
  125.  
  126. protected function tagList() {
  127. if ( ppOpt::test( 'tags_in_post_header', 'yes' ) ) {
  128. return ppHtml::tagList();
  129. }
  130. }
  131.  
  132. protected function commentCount() {
  133. if ( ppOpt::test( 'comment_count_in_post_header', 'yes' ) && ppOpt::test( 'comments_enable', 'true' ) ) {
  134. return '<span class="article-header-comment-count article-meta-item">' . ucfirst( ppCommentsRenderer::countString( $this->post->commentsCount() ) ) . '</span>';
  135. }
  136. }
  137.  
  138. protected function setupDateProperties() {
  139. if ( is_page() || is_404() || ppUtil::isEmptySearch() ) {
  140. return;
  141. }
  142.  
  143. if ( ppOpt::test( 'postdate_display', 'boxy' ) ) {
  144. $this->dateBeforeTitle = $this->dateMarkup();
  145.  
  146. } else if ( ppOpt::test( 'postdate_display', 'normal' ) ) {
  147.  
  148. switch ( ppOpt::id( 'postdate_placement' ) ) {
  149.  
  150. case 'above':
  151. $this->dateBeforeTitle = $this->dateMarkup();
  152. break;
  153. case 'below':
  154. $this->dateInMeta = $this->dateMarkup();
  155. break;
  156. case 'withtitle' :
  157. $this->dateSameLineWithTitle = $this->dateMarkup();
  158. break;
  159. default:
  160. new ppIssue( 'Unknown "postdate_placement"' );
  161. }
  162. }
  163. }
  164.  
  165. protected function editLinkBeforeTitle() {
  166. if ( !ppOpt::test( 'post_header_align', 'right' ) ) {
  167. return false;
  168.  
  169. } else if ( ppOpt::test( 'postdate_display', 'boxy' ) ) {
  170. return true;
  171.  
  172. } else if ( !ppOpt::test( 'postdate_placement', 'withtitle' ) ) {
  173. return true;
  174.  
  175. } else {
  176. return false;
  177. }
  178. }
  179.  
  180. public static function advancedDateCss( $selector = '.article-date span' ) {
  181. if ( ppOpt::test( 'postdate_advanced_switch', 'off' ) || ppOpt::test( 'postdate_display', 'boxy' ) ) {
  182. return;
  183. }
  184.  
  185. $postdate_border_width = ppOpt::id( 'postdate_border_width' );
  186. $postdate_border_top = ppOpt::test( 'postdate_border_top', 'on' ) ? $postdate_border_width : '0';
  187. $postdate_border_btm = ppOpt::test( 'postdate_border_bottom', 'on' ) ? $postdate_border_width : '0';
  188. $postdate_border_left = ppOpt::test( 'postdate_border_left', 'on' ) ? $postdate_border_width : '0';
  189. $postdate_border_right = ppOpt::test( 'postdate_border_right', 'on' ) ? $postdate_border_width : '0';
  190.  
  191. return <<<CSS
  192. $selector {
  193. margin-right:0;
  194. border-top-width:{$postdate_border_top}px;
  195. border-bottom-width:{$postdate_border_btm}px;
  196. border-left-width:{$postdate_border_left}px;
  197. border-right-width:{$postdate_border_right}px;
  198. border-style:[~postdate_border_style];
  199. border-color:[~postdate_border_color];
  200. background-color:[~postdate_bg_color];
  201. padding:[~postdate_tb_padding]px [~postdate_lr_padding]px;
  202. }
  203. CSS;
  204. }
  205. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement