-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWePortal.ContentProvider.Recent.php
132 lines (118 loc) · 3.33 KB
/
WePortal.ContentProvider.Recent.php
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
<?php
/**
* Recent topics/post content provider
*
* @package Dragooon:WePortal
* @author Shitiz "Dragooon" Garg <Email [email protected]> <Url http://smf-media.com>
* @copyright Shitiz "Dragooon" Garg <[email protected]>
* @license
* Without express written permission from the author, you cannot redistribute, in any form,
* modified or unmodified versions of the file or the package.
* The header in all the source files must remain intact
*
* Failure to comply with the above will result in lapse of the agreement, upon which you must
* destory all copies of this package, or parts of it, within 48 hours.
*
* THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY WARRANTY. ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE TO ANY PARTY FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* ARISING IN ANY WAY OUT OF THE USE OR MISUSE OF THIS PACKAGE.
*
* @version 0.1 "We're in the right direction!"
*/
/**
* Hook callback for "weportal_providers" to add the Recent block
*
* @param array &$content_providers List of current content providers
* @return void
*/
function weportal_provider_recent_hook(&$content_providers)
{
$content_providers[] = 'Recent';
}
/**
* Recent posts and topics block
*/
class WePContentProvider_Recent extends WePContentProvider
{
/**
* Stores the posts which are later rendered
*/
protected $posts = array();
/**
* Our name
*/
protected static $name = 'Recent Posts/Topics';
/**
* Parses the content and stores it
*
* @access public
* @return void
*/
public function prepare()
{
global $memberContext;
// Are we fetching posts? If so, fetch posts
// BTW, I managed to make a fool out of myself over this at {@link http://wedge.org}
if ($this->parameters['mode'] == 1)
$posts = ssi_recentPosts((int) $this->parameters['limit'], null, null, 'array');
// Otherwise we're fetching topics
else
$posts = ssi_recentTopics((int) $this->parameters['limit'], null, null, 'array');
$members = array();
foreach ($posts as $k => $post)
{
if (!empty($post['poster']['id']))
$members[] = $post['poster']['id'];
if (strlen($post['preview']) > 125)
$posts[$k]['preview'] = substr($post['preview'], 0, 125) . '...';
}
// Load the avatars
loadMemberData($members);
foreach ($posts as $k => $post)
{
loadMemberContext($post['poster']['id']);
if (!isset($memberContext[$post['poster']['id']]))
continue;
$posts[$k]['poster']['avatar'] = $memberContext[$post['poster']['id']]['avatar']['href'];
}
$this->posts = $posts;
}
/**
* Returns the parameters used by ACP
*
* @static
* @access public
* @return array
*/
public static function getParameters()
{
global $txt;
return array(
'type' => array(
'type' => 'select',
'label' => $txt['wep_type'],
'options' => array(
1 => $txt['wep_recent_posts'],
2 => $txt['wep_recent_topics'],
),
),
'limit' => array(
'type' => 'text',
'subtype' => 'int',
'label' => $txt['wep_recent_limit'],
),
);
}
/**
* Outputs the output for this block
*
* @access public
* @return void
*/
public function render()
{
echo template_weblock_recent($this->posts);
}
}