blogs
[ class tree: blogs ] [ index: blogs ] [ all elements ]

Source for file rankings.php

Documentation is available at rankings.php

  1. <?php
  2. /**
  3.  * @version $Header$
  4.  *
  5.  * @package blogs
  6.  * @subpackage functions
  7.  */
  8.  
  9. // Copyright (c) 2002-2003, Luis Argerich, Garland Foster, Eduardo Polidor, et. al.
  10. // All Rights Reserved. See below for details and a complete list of authors.
  11. // Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See http://www.gnu.org/copyleft/lesser.html for details.
  12.  
  13. /**
  14.  * required setup
  15.  */
  16. require_once'../kernel/setup_inc.php' );
  17.  
  18. include_onceLIBERTY_PKG_PATH 'LibertyContent.php' );
  19. require_onceBLOGS_PKG_PATH 'BitBlog.php' );
  20. require_onceBLOGS_PKG_PATH 'BitBlogPost.php' );
  21.  
  22. $gBitSystem->verifyPackage'blogs' );
  23. $gBitSystem->verifyFeature'blog_rankings' );
  24. $gBitSystem->verifyPermission'p_blogs_view' );
  25.  
  26. $rankingOptions array(
  27.     array(
  28.         'output' => tra'Most Often Viewed' ),
  29.         'value' => 'hits_desc'
  30.     ),
  31.     array(
  32.         'output' => tra'Most Recently Modified' ),
  33.         'value' => 'last_modified_desc'
  34.     ),
  35.     array(
  36.         'output' => tra'Most Active Authors' ),
  37.         'value' => 'top_authors'
  38.     ),
  39. );
  40. $gBitSmarty->assign'rankingOptions'$rankingOptions );
  41.  
  42. if!empty$_REQUEST['sort_mode') ) {
  43.     switch$_REQUEST['sort_mode'{
  44.         case 'last_modified_desc':
  45.             $gBitSmarty->assign'attribute''last_modified' );
  46.             $_REQUEST['attribute'tra'Date of last modification' );
  47.             break;
  48.         case 'top_authors':
  49.             $gBitSmarty->assign'attribute''ag_hits' );
  50.             $_REQUEST['attribute'tra'Hits to items by this Author' );
  51.             break;
  52.         default:
  53.             $gBitSmarty->assign'attribute''hits' );
  54.             $_REQUEST['attribute'tra'Hits' );
  55.             break;
  56.     }
  57. else {
  58.     $gBitSmarty->assign'attribute''hits' );
  59.     $_REQUEST['attribute'tra'Hits' );
  60. }
  61.  
  62. $_REQUEST['title']             tra'Blog Post Rankings' );
  63. $_REQUEST['content_type_guid'BITBLOGPOST_CONTENT_TYPE_GUID;
  64. $_REQUEST['max_records']       !empty$_REQUEST['max_records'$_REQUEST['max_records'10;
  65.  
  66. ifempty$gContent ) ) {
  67.     $gContent new LibertyContent();
  68. }
  69. $rankList $gContent->getContentRanking$_REQUEST );
  70. $gBitSmarty->assign'rankList'$rankList );
  71.  
  72. $gBitSystem->display'bitpackage:liberty/rankings.tpl'tra"Blog Post Rankings" array'display_mode' => 'display' ));
  73.  
  74.  
  75.  
  76.  
  77. /* ---- below is what blog rankings was - might want to canabalize some of it eventually ---- */
  78. /*
  79.  
  80. require_once( '../kernel/setup_inc.php' );
  81.  
  82.  
  83. $gBitSystem->verifyPackage( 'blogs' );
  84.  
  85. $gBitSystem->verifyFeature( 'blog_rankings' );
  86.  
  87. $gBitSystem->verifyPermission( 'p_blogs_view' );
  88.  
  89. require_once( BLOGS_PKG_PATH . 'BitBlog.php' );
  90. require_once( BLOGS_PKG_PATH . 'BitBlogPost.php' );
  91.  
  92. $allrankings = array(
  93.     array(
  94.     'name' => tra('Most visited blogs'),
  95.     'value' => 'blog_ranking_top_blogs'
  96. ),
  97.     array(
  98.     'name' => tra('Last posts'),
  99.     'value' => 'blog_ranking_last_posts'
  100. ),
  101.     /**
  102.      * @todo reenable once we have activity implemented
  103.     array(
  104.     'name' => tra('Most active blogs'),
  105.     'value' => 'blog_ranking_top_active_blogs'
  106. )
  107.     **/
  108. /*
  109. );
  110.  
  111. $gBitSmarty->assign('allrankings', $allrankings);
  112.  
  113. if (!isset($_REQUEST["which"])) {
  114.     $which = 'blog_ranking_top_blogs';
  115. } else {
  116.     $which = $_REQUEST["which"];
  117. }
  118.  
  119. $gBitSmarty->assign('which', $which);
  120.  
  121. // Get the page from the request var or default it to HomePage
  122. if (!isset($_REQUEST["limit"])) {
  123.     $limit = 10;
  124. } else {
  125.     $limit = $_REQUEST["limit"];
  126. }
  127.  
  128. $gBitSmarty->assign_by_ref('limit', $limit);
  129.  
  130. // Rankings:
  131. // Top Pages
  132. // Last pages
  133. // Top Authors -- Would be nice.
  134. $rankings = array();
  135.  
  136. $rankings = $which($limit);
  137.  
  138. $gBitSmarty->assign_by_ref('rankings', $rankings);
  139. $gBitSmarty->assign('rpage', 'rankings.php');
  140.  
  141. // Display the template
  142. $gBitSystem->display( 'bitpackage:blogs/ranking.tpl', tra($rankings['title']), array( 'display_mode' => 'display' ));
  143.  
  144. // =============================== some ranking functions - as soon as blogs are part of LibertyContent, we can use LibertyContent::getContentRanking()
  145. function blog_ranking_top_blogs($limit) {
  146.     global $gBitSystem;
  147.     $list_hash['sort_mode'] = 'lch.hits_desc';
  148.     $list_hash['max_records'] = $limit;
  149.     $b = new BitBlog();
  150.     $list = $b->getList($list_hash);
  151.     $query = "select p.*, lc.* FROM `".BIT_DB_PREFIX."blog_posts` p LEFT JOIN `".BIT_DB_PREFIX."liberty_content` lc ON (p.`content_id` = lc.`content_id`) WHERE p.blog_id = ? ORDER BY p.post_id desc";
  152.     foreach($list['data'] as $key => $blog) {
  153.         $result = $gBitSystem->mDb->query($query, array($blog['blog_id']), $gBitSystem->getConfig('blogs_top_post_count', 3));
  154.  
  155.         while ($ret = $result->fetchRow()) {
  156.             $ret['display_url'] = BitBlogPost::getDisplayUrlFromHash($ret['content_id']);
  157.             $list['data'][$key]['post_array'][] = $ret;
  158.         }
  159.     }
  160.     $list['title'] = tra("Most Visited Blogs");
  161.     return $list;
  162. }
  163.  
  164. /** TODO: This should be changed when we start using activity in the blog.
  165.           We should check TW 1.9 for code for that field in the blog. */
  166. /*
  167. function blog_ranking_top_active_blogs($limit) {
  168.     global $gBitSystem;
  169.     $list_hash['sort_mode'] = 'b.activity';
  170.     $list_hash['max_records'] = $limit;
  171.     $b = new BitBlog();
  172.     $list = $b->getList($list_hash);
  173.     $query = "select p.*, lc.* FROM `".BIT_DB_PREFIX."blog_posts` p LEFT JOIN `".BIT_DB_PREFIX."liberty_content` lc ON (p.`content_id` = lc.`content_id`) WHERE p.blog_id = ? ORDER BY p.post_id desc";
  174.     foreach($list['data'] as $key => $blog) {
  175.         $result = $gBitSystem->mDb->query($query, array($blog['blog_id']), $gBitSystem->getConfig('blogs_top_post_count', 3));
  176.  
  177.         while ($ret = $result->fetchRow()) {
  178.             $ret['display_url'] = BitBlogPost::getDisplayUrlFromHash($ret['content_id']);
  179.             $list['data'][$key]['post_array'][] = $ret;
  180.         }
  181.     }
  182.     $list['title'] = tra("Most Visited Blogs");
  183.     return $list;
  184. }
  185.  
  186. function blog_ranking_last_posts($limit) {
  187.     global $gBitSystem;
  188.     $list_hash['max_records'] = $limit;
  189.     $list_hash['sort_mode'] = 'created_desc';
  190.     $list_hash['max_records'] = $limit;
  191.     $bp = new BitBlogPost();
  192.     $posts = $bp->getList($list_hash);
  193.     // Extract blog_ids to load the blogs.
  194.     foreach( $posts['data'] as $key => $post) {
  195.         $blog_ids[$post['blog_id']] = $post['blog_id'];
  196.     }
  197.     if (!empty($blog_ids)) {
  198.       $b = new BitBlog();
  199.       $blog_hash['sort_mode'] = 'lch.hits_desc';
  200.       $blog_hash['find'] = $blog_ids;
  201.       $blogs = $b->getList($blog_hash);
  202.       $list['data'] = array();
  203.       // Reorganize blogs by id
  204.       foreach($blogs['data'] as $key => $blog) {
  205.         $list['data'][$blog['blog_id']] = $blog;
  206.       }
  207.       // And merge in posts
  208.       foreach($posts['data'] as $key => $post) {
  209.         $post['post_url'] = $bp->getDisplayUrl($post['content_id']);
  210.         $list['data'][$post['blog_id']]['post_array'][] = $post;
  211.       }
  212.     }
  213.     $list['title'] = 'Last Posts';
  214.     return $list;
  215. }
  216. */
  217. ?>

Documentation generated on Wed, 29 Jul 2015 13:57:17 +0000 by phpDocumentor 1.5.0-lsces