summaryrefslogtreecommitdiff
path: root/rankings.php
blob: d5ad640a91cadca6ddee77a3bb3276e9047dc49f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
<?php
/**
 * @version $Header$
 *
 * @package blogs
 * @subpackage functions
 */

// Copyright (c) 2002-2003, Luis Argerich, Garland Foster, Eduardo Polidor, et. al.
// All Rights Reserved. See below for details and a complete list of authors.
// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See http://www.gnu.org/copyleft/lesser.html for details.

/**
 * required setup
 */
require_once( '../kernel/includes/setup_inc.php' );

include_once( LIBERTY_PKG_PATH . 'LibertyContent.php' );
require_once( BLOGS_PKG_PATH . 'BitBlog.php' );
require_once( BLOGS_PKG_PATH . 'BitBlogPost.php' );

$gBitSystem->verifyPackage( 'blogs' );
$gBitSystem->verifyFeature( 'blog_rankings' );
$gBitSystem->verifyPermission( 'p_blogs_view' );

$rankingOptions = array(
	array(
		'output' => tra( 'Most Often Viewed' ),
		'value' => 'hits_desc'
	),
	array(
		'output' => tra( 'Most Recently Modified' ),
		'value' => 'last_modified_desc'
	),
	array(
		'output' => tra( 'Most Active Authors' ),
		'value' => 'top_authors'
	),
);
$gBitSmarty->assign( 'rankingOptions', $rankingOptions );

if( !empty( $_REQUEST['sort_mode'] ) ) {
	switch( $_REQUEST['sort_mode'] ) {
		case 'last_modified_desc':
			$gBitSmarty->assign( 'attribute', 'last_modified' );
			$_REQUEST['attribute'] = tra( 'Date of last modification' );
			break;
		case 'top_authors':
			$gBitSmarty->assign( 'attribute', 'ag_hits' );
			$_REQUEST['attribute'] = tra( 'Hits to items by this Author' );
			break;
		default:
			$gBitSmarty->assign( 'attribute', 'hits' );
			$_REQUEST['attribute'] = tra( 'Hits' );
			break;
	}
} else {
	$gBitSmarty->assign( 'attribute', 'hits' );
	$_REQUEST['attribute'] = tra( 'Hits' );
}

$_REQUEST['title']             = tra( 'Blog Post Rankings' );
$_REQUEST['content_type_guid'] = BITBLOGPOST_CONTENT_TYPE_GUID;
$_REQUEST['max_records']       = !empty( $_REQUEST['max_records'] ) ? $_REQUEST['max_records'] : 10;

if( empty( $gContent ) ) {
	$gContent = new LibertyContent();
}
$rankList = $gContent->getContentRanking( $_REQUEST );
$gBitSmarty->assign( 'rankList', $rankList );

$gBitSystem->display( 'bitpackage:liberty/rankings.tpl', tra( "Blog Post Rankings" ) , array( 'display_mode' => 'display' ));




/* ---- below is what blog rankings was - might want to canabalize some of it eventually ---- */
/*

require_once( '../kernel/includes/setup_inc.php' );


$gBitSystem->verifyPackage( 'blogs' );

$gBitSystem->verifyFeature( 'blog_rankings' );

$gBitSystem->verifyPermission( 'p_blogs_view' );

require_once( BLOGS_PKG_PATH . 'BitBlog.php' );
require_once( BLOGS_PKG_PATH . 'BitBlogPost.php' );

$allrankings = array(
	array(
	'name' => tra('Most visited blogs'),
	'value' => 'blog_ranking_top_blogs'
),
	array(
	'name' => tra('Last posts'),
	'value' => 'blog_ranking_last_posts'
),
	/**
	 * @todo reenable once we have activity implemented
	array(
	'name' => tra('Most active blogs'),
	'value' => 'blog_ranking_top_active_blogs'
)
	**/
/*
);

$gBitSmarty->assign('allrankings', $allrankings);

if (!isset($_REQUEST["which"])) {
	$which = 'blog_ranking_top_blogs';
} else {
	$which = $_REQUEST["which"];
}

$gBitSmarty->assign('which', $which);

// Get the page from the request var or default it to HomePage
if (!isset($_REQUEST["limit"])) {
	$limit = 10;
} else {
	$limit = $_REQUEST["limit"];
}

$gBitSmarty->assignByRef('limit', $limit);

// Rankings:
// Top Pages
// Last pages
// Top Authors -- Would be nice.
$rankings = array();

$rankings = $which($limit);

$gBitSmarty->assignByRef('rankings', $rankings);
$gBitSmarty->assign('rpage', 'rankings.php');

// Display the template
$gBitSystem->display( 'bitpackage:blogs/ranking.tpl', tra($rankings['title']), array( 'display_mode' => 'display' ));

// =============================== some ranking functions - as soon as blogs are part of LibertyContent, we can use LibertyContent::getContentRanking()
function blog_ranking_top_blogs($limit) {
	global $gBitSystem;
	$list_hash['sort_mode'] = 'lch.hits_desc';
	$list_hash['max_records'] = $limit;
	$b = new BitBlog();
	$list = $b->getList($list_hash);
	$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";
	foreach($list['data'] as $key => $blog) {
		$result = $gBitSystem->mDb->query($query, array($blog['blog_id']), $gBitSystem->getConfig('blogs_top_post_count', 3));

		while ($ret = $result->fetchRow()) {
			$ret['display_url'] = BitBlogPost::getDisplayUrlFromHash($ret['content_id']);
			$list['data'][$key]['post_array'][] = $ret;
		}
	}
	$list['title'] = tra("Most Visited Blogs");
	return $list;
}

/** TODO: This should be changed when we start using activity in the blog.
          We should check TW 1.9 for code for that field in the blog. */
/*
function blog_ranking_top_active_blogs($limit) {
	global $gBitSystem;
	$list_hash['sort_mode'] = 'b.activity';
	$list_hash['max_records'] = $limit;
	$b = new BitBlog();
	$list = $b->getList($list_hash);
	$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";
	foreach($list['data'] as $key => $blog) {
		$result = $gBitSystem->mDb->query($query, array($blog['blog_id']), $gBitSystem->getConfig('blogs_top_post_count', 3));

		while ($ret = $result->fetchRow()) {
			$ret['display_url'] = BitBlogPost::getDisplayUrlFromHash($ret['content_id']);
			$list['data'][$key]['post_array'][] = $ret;
		}
	}
	$list['title'] = tra("Most Visited Blogs");
	return $list;
}

function blog_ranking_last_posts($limit) {
	global $gBitSystem;
	$list_hash['max_records'] = $limit;
	$list_hash['sort_mode'] = 'created_desc';
	$list_hash['max_records'] = $limit;
	$bp = new BitBlogPost();
	$posts = $bp->getList($list_hash);
	// Extract blog_ids to load the blogs.
	foreach( $posts['data'] as $key => $post) {
		$blog_ids[$post['blog_id']] = $post['blog_id'];
	}
	if (!empty($blog_ids)) {
	  $b = new BitBlog();
	  $blog_hash['sort_mode'] = 'lch.hits_desc';
	  $blog_hash['find'] = $blog_ids;
	  $blogs = $b->getList($blog_hash);
	  $list['data'] = array();
	  // Reorganize blogs by id
	  foreach($blogs['data'] as $key => $blog) {
	    $list['data'][$blog['blog_id']] = $blog;
	  }
	  // And merge in posts
	  foreach($posts['data'] as $key => $post) {
	    $post['post_url'] = $bp->getDisplayUrl($post['content_id']);
	    $list['data'][$post['blog_id']]['post_array'][] = $post;
	  }
	}
	$list['title'] = 'Last Posts';
	return $list;
}
*/
?>