-
Notifications
You must be signed in to change notification settings - Fork 1
/
testimonials_menu.php
116 lines (89 loc) · 2.21 KB
/
testimonials_menu.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
<?php
/**
* Testimonials plugin for e107 v2.
*
* @file
* Class to render Testimonials menu.
*/
if(!defined('e107_INIT'))
{
exit;
}
// [PLUGINS]/testimonials/languages/[LANGUAGE]/[LANGUAGE]_front.php
e107::lan('testimonials', false, true);
class testimonials_menu
{
/**
* Store plugin preferences.
*
* @var mixed|null
*/
private $plugPrefs = null;
/**
* Store testimonial items.
*
* @var array
*/
private $testimonials = array();
/**
* Constructor.
*/
function __construct()
{
// Get plugin preferences.
$this->plugPrefs = e107::getPlugConfig('testimonials')->getPref();
$this->renderMenu();
}
/**
* Render testimonials menu.
*/
function renderMenu()
{
$cache = e107::getConfig();
// if(!$text = $cache->get("testimonials"))
// {
$this->getItems();
$template = e107::getTemplate('testimonials');
$sc = e107::getScBatch('testimonials', true);
$tp = e107::getParser();
$sc->setVars(array('count' => count($this->testimonials)));
$text = $tp->parseTemplate($template['menu_header'], true, $sc);
foreach($this->testimonials as $key => $val)
{
$val['active'] = ((int) $key === 0);
$sc->setVars($val);
$text .= $tp->parseTemplate($template['menu_body'], true, $sc);
}
$text .= $tp->parseTemplate($template['menu_footer'], true, $sc);
$cache->set("testimonials", $text);
// }
e107::getRender()->tablerender(LAN_TESTIMONIALS_01, $text);
unset($text);
}
/**
* Select messages from database.
*/
function getItems()
{
$db = e107::getDb('testimonials');
$query = 'SELECT t.*, u.user_id, u.user_name FROM #testimonials AS t ';
$query .= 'LEFT JOIN #user AS u ON SUBSTRING_INDEX(t.tm_name,".",1) = u.user_id ';
$query .= 'WHERE t.tm_blocked = 0 ';
$query .= 'ORDER BY rand() ';
$query .= 'LIMIT 0, ' . (int) $this->plugPrefs['tm_menu_items'];
$db->gen($query);
while($row = $db->fetch())
{
$item = $row;
list($tm_uid, $tm_nick) = explode(".", $row['tm_name'], 2);
$item['user_name'] = $tm_nick;
if (!empty($item['tm_url'])) {
if (strpos($item['tm_url'], 'http') === FALSE) {
$item['tm_url'] = 'http://' . $item['tm_url'];
}
}
$this->testimonials[] = $item;
}
}
}
new testimonials_menu();