forked from Moc/cookbook
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cookbook_categories_menu.php
119 lines (93 loc) · 3.07 KB
/
cookbook_categories_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
117
118
119
<?php
/*
* CookBook - an e107 plugin by Tijn Kuyper (http://www.tijnkuyper.nl)
*
* Released under the terms and conditions of the
* Apache License 2.0 (see LICENSE file or http://www.apache.org/licenses/LICENSE-2.0)
*
* Latest recipes menu
*/
if(!defined('e107_INIT'))
{
require_once("../../class2.php");
}
if(!e107::isInstalled('cookbook'))
{
return '';
}
// Load the LAN files
e107::lan('cookbook', false, true);
if(!class_exists('cookbook_categoriesmenu'))
{
class cookbook_categoriesmenu
{
public $template = array();
function __construct()
{
$this->template = e107::getTemplate('cookbook', 'cookbook_categoriesmenu', 'default');
}
public function render($parm = null)
{
$text = '';
$sql = e107::getDb();
//$limit = 10; // Number of categories to display // Unused for now
// Retrieve the categories
if($count = $sql->count('cookbook_categories'))
{
if($categories = $sql->retrieve('cookbook_categories', 'c_id', '', true))
{
// Load shortcodes
$sc = e107::getScBatch('cookbook', TRUE);
foreach($categories as $category)
{
// Convert to vars used in shortcodes:
$category['r_category'] = $category['c_id'];
// Pass vars to shortcodes
$sc->setVars($category);
// Return render item from template
$text .= e107::getParser()->parseTemplate($this->template['item'], true, $sc);
}
}
else
{
$text = LAN_ERROR;
// If SQL error, show to admins.
if(ADMIN && $sql->getLastErrorNumber())
{
$text = 'SQL Error #'.$sql->getLastErrorNumber().': '.$sql->getLastErrorText();
}
}
return $text;
}
// No categories
else
{
$text = LAN_CB_NOCATS;
}
return $text;
}
}
}
$class = new cookbook_categoriesmenu;
if(!isset($parm))
{
$parm = null;
}
$text = $class->render($parm);
// Set default caption
$caption = LAN_CATEGORIES;
// Allow for custom caption through shortcode parm
if (!empty($parm))
{
if(isset($parm['caption'][e_LANGUAGE]))
{
$caption = empty($parm['caption'][e_LANGUAGE]) ? LAN_CATEGORIES : $parm['caption'][e_LANGUAGE];
}
}
// Pass caption to shortcode in template
$var = array('COOKBOOK_CATEGORIESMENU_CAPTION' => $caption);
$caption = e107::getParser()->simpleParse($class->template['caption'], $var);
// Load start and end from template
$start = $class->template['start'];
$end = $class->template['end'];
e107::getRender()->tablerender($caption, $start . $text . $end, 'cookbook_categoriesmenu');