PageRenderTime 106ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/panel/postfooter.php

https://github.com/karlforshaw/One-Panel
PHP | 217 lines | 141 code | 71 blank | 5 comment | 19 complexity | e4da7e0def570881274eb321d983827e MD5 | raw file
  1. <?php
  2. class AuthorProfileLinkFeature extends OnePanelFeature {
  3. protected $title = 'Author Profile Link';
  4. protected $help_text = 'This module will display a Author Profile link beneath each blog entry.';
  5. public function Render() {
  6. return $this->RenderOnOff();
  7. }
  8. }
  9. class RSSLinkFeature extends OnePanelFeature {
  10. protected $title = 'RSS Link';
  11. protected $help_text = 'Enable RSS Link to display a "Subscribe" link beneath blog entires.';
  12. public function Render() {
  13. return $this->RenderOnOff();
  14. }
  15. }
  16. class RelatedArticlesFeature extends OnePanelFeature {
  17. protected $title = 'Related Articles';
  18. protected $help_text = 'Enable Related Articles to display on-topic blog entires beneath your articles.';
  19. public function Render() {
  20. return $this->RenderOnOff();
  21. }
  22. public function GetChunk() {
  23. global $post;
  24. $post_id = $post->ID;
  25. $post_title = $post->post_title;
  26. $keywords = explode( ' ', $post_title );
  27. $word_count = count( $keywords );
  28. $overusedwords = array( '', 'a', 'an', 'the', 'and', 'of', 'i', 'to', 'is', 'in', 'with', 'for', 'as', 'that', 'on', 'at', 'this', 'my', 'was', 'our', 'it', 'you', 'we', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '10', 'about', 'after', 'all', 'almost', 'along', 'also', 'amp', 'another', 'any', 'are', 'area', 'around', 'available', 'back', 'be', 'because', 'been', 'being', 'best', 'better', 'big', 'bit', 'both', 'but', 'by', 'c', 'came', 'can', 'capable', 'control', 'could', 'course', 'd', 'dan', 'day', 'decided', 'did', 'didn', 'different', 'div', 'do', 'doesn', 'don', 'down', 'drive', 'e', 'each', 'easily', 'easy', 'edition', 'end', 'enough', 'even', 'every', 'example', 'few', 'find', 'first', 'found', 'from', 'get', 'go', 'going', 'good', 'got', 'gt', 'had', 'hard', 'has', 'have', 'he', 'her', 'here', 'how', 'if', 'into', 'isn', 'just', 'know', 'last', 'left', 'li', 'like', 'little', 'll', 'long', 'look', 'lot', 'lt', 'm', 'made', 'make', 'many', 'mb', 'me', 'menu', 'might', 'mm', 'more', 'most', 'much', 'name', 'nbsp', 'need', 'new', 'no', 'not', 'now', 'number', 'off', 'old', 'one', 'only', 'or', 'original', 'other', 'out', 'over', 'part', 'place', 'point', 'pretty', 'probably', 'problem', 'put', 'quite', 'quot', 'r', 're', 'really', 'results', 'right', 's', 'same', 'saw', 'see', 'set', 'several', 'she', 'sherree', 'should', 'since', 'size', 'small', 'so', 'some', 'something', 'special', 'still', 'stuff', 'such', 'sure', 'system', 't', 'take', 'than', 'their', 'them', 'then', 'there', 'these', 'they', 'thing', 'things', 'think', 'those', 'though', 'through', 'time', 'today', 'together', 'too', 'took', 'two', 'up', 'us', 'use', 'used', 'using', 've', 'very', 'want', 'way', 'well', 'went', 'were', 'what', 'when', 'where', 'which', 'while', 'white', 'who', 'will', 'would', 'your');
  29. if ($word_count == 0) {
  30. return false;
  31. }
  32. global $wpdb;
  33. $sql = "SELECT ID AS id, post_title AS post_title, post_content AS post_content FROM " . DB_NAME . ".{$wpdb->prefix}posts WHERE ";
  34. for ($i=0; $i < $word_count; $i++) {
  35. $keyword = mysql_real_escape_string($keywords[$i]);
  36. if (! in_array( $keyword, $overusedwords )) {
  37. $sql .= "post_title LIKE '%{$keyword}%' AND ID != {$post_id} AND post_type='post' AND post_status='publish' ";
  38. if ($i + 1 != $word_count) $sql .= "OR ";
  39. }
  40. }
  41. $sql .= 'LIMIT 3';
  42. $result = mysql_query( $sql );
  43. $error = '<div id="related-articles">
  44. <div class="error">There are no related articles.</div>
  45. </div>';
  46. $return = '';
  47. if (! $result) {
  48. return $error;
  49. }
  50. else {
  51. $num_rows = mysql_numrows( $result );
  52. $return .= '<div id="related-articles"><div class="title">' . OnePanelLanguage::GetText( 'related' ) . '</div>';
  53. if ($num_rows > 0) {
  54. for ($i=0; $i < $num_rows; $i++) {
  55. $id = mysql_result( $result, $i, 'ID' );
  56. $title = mysql_result( $result, $i, 'post_title' );
  57. $content = mysql_result( $result, $i, 'post_content' );
  58. $return .= '<div class="related-article">';
  59. $return .= OnePanelTheme::GetThumbnail( $id );
  60. $return .= '<div class="title"><a href="' . get_permalink( $id ) .'">' . substr( $title, 0, 39 ) . '...</a></div>';
  61. $return .= substr(strip_tags( $content ), 0, 135) . '...';
  62. $return .= '</div>';
  63. }
  64. $return .= '</div>';
  65. return $return;
  66. }
  67. else {
  68. return $error;
  69. }
  70. }
  71. }
  72. }
  73. class SocialBookmarksFeature extends OnePanelFeature {
  74. protected $title = 'Social Bookmarks';
  75. protected $help_text = 'Enable this module to allow readers to submit your posts to Social Bookmarking websites.';
  76. public function Render() {
  77. return $this->RenderOnOff();
  78. }
  79. }
  80. class TagsFeature extends OnePanelFeature {
  81. protected $title = 'Tags';
  82. protected $help_text = 'Enable this module to display tags beneath blog entires.';
  83. public function Render() {
  84. return $this->RenderOnOff();
  85. }
  86. }
  87. class PostFooter extends OnePanelModule {
  88. protected $title = 'Post Footer';
  89. protected $help_text = 'Use Post Footer to activate Related Articles, Tags, Social Bookmarks and more.';
  90. protected $description = 'Offer your readers more with a selection of extras that are accessible below your posts. Keep visitors interested with other Related Articles, or give them the ability to submit your articles to various social bookmarking websites.';
  91. protected $short_description = 'Use Post Footer to activate Related Articles, Tags, Social Bookmarks and more.';
  92. protected $keywords = array( 'post footer', 'post', 'footer', 'author profile link', 'author', 'profile', 'link', 'related articles', 'related posts', 'related', 'rss link', 'rss', 'social bookmarks', 'social', 'bookmarks', 'bookmarking', 'digg', 'stumble', 'delicious', 'reddit', 'yahoo', 'google', 'tags', 'tag', 'tagged' );
  93. protected $categories = array( 'Appearance' );
  94. public function Render() {
  95. $this->GenericRender();
  96. }
  97. public function RegisterFeatures() {
  98. $this->RegisterFeature( 'AuthorProfileLinkFeature' );
  99. $this->RegisterFeature( 'RSSLinkFeature' );
  100. $this->RegisterFeature( 'RelatedArticlesFeature' );
  101. $this->RegisterFeature( 'SocialBookmarksFeature' );
  102. $this->RegisterFeature( 'TagsFeature' );
  103. }
  104. public function BuildChunks() {
  105. // Author Profile Link
  106. $enabled = $this->features['AuthorProfileLinkFeature']->IsActive();
  107. if ($enabled) {
  108. $this->chunks['AuthorProfileLink'] = '<div id="author-profile-link">' . OnePanelLanguage::GetText( 'author_view' ) . '</div>';
  109. }
  110. // RSS Link
  111. $enabled = $this->features['RSSLinkFeature']->IsActive();
  112. if ($enabled) {
  113. $this->chunks['RSSLink'] = '<div id="rss-link">' . OnePanelLanguage::GetText( 'subscribe_via' ) . '</div>';
  114. }
  115. // Related Articles
  116. $enabled = $this->features['RelatedArticlesFeature']->IsActive();
  117. if ($enabled) {
  118. $this->chunks['RelatedArticles'] = $this->features['RelatedArticlesFeature']->GetChunk();
  119. }
  120. // Social Bookmarks
  121. $enabled = $this->features['SocialBookmarksFeature']->IsActive();
  122. if ($enabled) {
  123. $chunk = '<div id="social-bookmarks">';
  124. $chunk .= '<a class="digg" href="http://digg.com/submit?phase=2&url=' . get_permalink() . '&title=' . get_the_title() . '">Digg it</a>';
  125. $chunk .= '<a class="stumble" href="http://www.stumbleupon.com/submit?url=' . get_permalink() . '&title=' . get_the_title() . '">Stumble</a>';
  126. $chunk .= '<a class="delicious" href="http://del.icio.us/post?url=' . get_permalink() . '&title=' . get_the_title() . '"> del.icio.us</a>';
  127. $chunk .= '<a class="reddit" href="http://reddit.com/submit?url=' . get_permalink() . '&title=' . get_the_title() . '">reddit</a>';
  128. $chunk .= '<a class="yahoo" href="http://myweb2.search.yahoo.com/myresults/bookmarklet?t=' . get_the_title() . '&u=' . get_permalink() . '">Yahoo</a>';
  129. $chunk .= '<a class="google" href="http://www.google.com/bookmarks/mark?op=edit&bkmk=' . get_permalink() . '&title=' . get_the_title() . '">Google</a>';
  130. $chunk .= '</div>';
  131. $this->chunks['SocialBookmarks'] = &$chunk;
  132. }
  133. // Tags
  134. $enabled = $this->features['TagsFeature']->IsActive();
  135. if ($enabled) {
  136. global $post;
  137. $tags = get_the_term_list( $post->ID, 'post_tag', '<div class="tag">','', '</div>');
  138. if (! empty( $tags )) {
  139. $this->chunks['Tags'] = '<div id="tags"><div class="title">' . OnePanelLanguage::GetText( 'tags' ) . '</div>' .$tags . '</div>' . "\n";
  140. }
  141. else {
  142. $this->chunks['Tags'] = '<div id="no-tags">' . OnePanelLanguage::GetText( 'no_tags' ) . '</div>' . "\n";
  143. }
  144. }
  145. }
  146. }