-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
242 lines (187 loc) · 4.95 KB
/
index.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
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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
<?php
/*
* e107 website system
*
* Copyright (C) 2008-2012 e107 Inc (e107.org)
* Released under the terms and conditions of the
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt)
*
* Cron Administration
*
* $URL: https://e107.svn.sourceforge.net/svnroot/e107/trunk/e107_0.8/e107_admin/cron.php $
* $Id: cron.php 12492 2011-12-30 16:09:10Z e107steved $
*
*/
/**
*
* @package e107
* @subpackage frontend
* @version $Id$
* Ultra-simple Image-Gallery
*/
/*
* THIS SCRIPT IS HIGHLY EXPERIMENTAL. USE AT OWN RISK.
*/
/**
* Class plugin_gallery_index_controller.
*/
class plugin_gallery_index_controller extends eControllerFront
{
/**
* Plugin name - used to check if plugin is installed
* Set this only if plugin requires installation
* @var string
*/
protected $plugin = 'gallery';
/**
* Default controller access
* @var integer
*/
protected $userclass = e_UC_PUBLIC;
/**
* User input filter
* Format 'action' => array(var => validationArray)
* @var array
*/
protected $filter = array(
'category' => array(
'cat' => array('regex', '/[\w\pL\s\-+.,]+/u'),
),
'list' => array(
'cat' => array('regex', '/[\w\pL\s\-+.,]+/u'),
'frm' => array('int'),
),
);
/**
* @var array
*/
protected $catList;
public function init()
{
e107::plugLan('gallery', 'front');
e107::css('gallery', 'css/gallery.css');
$this->catList = e107::getMedia()->getCategories('gallery');
}
public function actionIndex()
{
if(isset($_GET['cat']) && !empty($_GET['cat']))
{
$this->_forward('list');
}
else
{
$this->_forward('category');
}
}
private function getTemplate()
{
$template = (array) e107::getTemplate('gallery');
$oldKeys = array(
'list_start', 'list_item', 'list_caption', 'list_end',
'cat_start', 'cat_item', 'cat_caption', 'cat_end'
);
if(isset($template['list_start']))
{
foreach($oldKeys as $k)
{
list($main,$sub) = explode("_",$k);
$template[$main][$sub] = $template[$k];
unset($template[$k]);
}
}
return $template;
}
public function actionCategory()
{
// print_a("Hi there");
$template = $this->getTemplate();
$template = array_change_key_case($template);
$sc = e107::getScBatch('gallery', true);
$sc->breadcrumb();
// $text = "";
if(defset('BOOTSTRAP') === true || defset('BOOTSTRAP') === 2) // Convert bootsrap3 to bootstrap2 compat.
{
$template['cat_start'] = str_replace('row', 'row-fluid', $template['cat_start']);
}
$text = e107::getParser()->parseTemplate($template['cat']['start'], true, $sc);
foreach($this->catList as $val)
{
$sc->setVars($val);
$text .= e107::getParser()->parseTemplate($template['cat']['item']);
}
$text .= e107::getParser()->parseTemplate($template['cat']['end'], true, $sc);
if(isset($template['cat']['caption']))
{
$title = e107::getParser()->parseTemplate($template['cat']['caption'], true, $sc);
$this->addTitle($title)->addBody($text);
}
else
{
$this->addTitle(LAN_PLUGIN_GALLERY_TITLE)->addBody($text);
}
}
public function actionList()
{
$plugPrefs = e107::getPlugConfig('gallery')->getPref();
$request = $this->getRequest();
// use only filtered variables
$cid = $request->getRequestParam('cat');
if($cid && !isset($this->catList[$cid]))
{
// get ID by SEF
$_cid = null;
foreach($this->catList as $id => $row)
{
if($cid === $row['media_cat_sef'])
{
$_cid = $id;
break;
}
}
$cid = $_cid;
}
if(empty($cid) || !isset($this->catList[$cid]))
{
$this->_forward('category');
return;
}
$tp = e107::getParser();
$template = $this->getTemplate();
$template = array_change_key_case($template);
$sc = e107::getScBatch('gallery', true);
if(defset('BOOTSTRAP') === true || defset('BOOTSTRAP') === 2) // Convert bootsrap3 to bootstrap2 compat.
{
$template['list_start'] = str_replace('row', 'row-fluid', $template['list_start']);
}
$sc->total = e107::getMedia()->countImages($cid);
$sc->amount = varset($plugPrefs['perpage'], 12);
$sc->curCat = $cid;
$sc->from = $request->getRequestParam('frm', 0);
$orderBy = varset($plugPrefs['orderby'], 'media_id DESC');
$list = e107::getMedia()->getImages($cid, $sc->from, $sc->amount, null, $orderBy);
$catname = $tp->toHTML($this->catList[$cid]['media_cat_title'], false, 'defs');
$cat = $this->catList[$cid];
$inner = "";
foreach($list as $row)
{
$sc->setVars($row)
->addVars($cat);
$inner .= $tp->parseTemplate($template['list']['item'], true, $sc);
}
$sc->breadcrumb();
$text = $tp->parseTemplate($template['list']['start'], true, $sc);
$text .= $inner;
$text .= $tp->parseTemplate($template['list']['end'], true, $sc);
if(isset($template['list']['caption']))
{
$title = $tp->parseTemplate($template['list']['caption'], true, $sc);
$this->addTitle($title)->addBody($text);
}
else
{
$this->addTitle(LAN_PLUGIN_GALLERY_TITLE)
->addTitle($catname)
->addBody($text);
}
}
}