/
admin.php
499 lines (457 loc) · 13.6 KB
/
admin.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
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
<?php
/*
# -- BEGIN LICENSE BLOCK ----------------------------------
#
# This file is part of MAGIX CMS.
# MAGIX CMS, The content management system optimized for users
# Copyright (C) 2008 - 2013 magix-cms.com <support@magix-cms.com>
#
# OFFICIAL TEAM :
#
# * Gerits Aurelien (Author - Developer) <aurelien@magix-cms.com> <contact@aurelien-gerits.be>
#
# Redistributions of files must retain the above copyright notice.
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# -- END LICENSE BLOCK -----------------------------------
# DISCLAIMER
# Do not edit or add to this file if you wish to upgrade MAGIX CMS to newer
# versions in the future. If you wish to customize MAGIX CMS for your
# needs please refer to http://www.magix-cms.com for more information.
*/
/**
* MAGIX CMS
* @category blocklink
* @package plugins
* @copyright MAGIX CMS Copyright (c) 2008 - 2015 Gerits Aurelien,
* http://www.magix-cms.com, http://www.magix-cjquery.com
* @license Dual licensed under the MIT or GPL Version 3 licenses.
* @version 2.0
* Author: Salvatore Di Salvo
* Date: 13-01-16
* Time: 15:00
* @name blocklink
* Le plugin blocklink
*/
class plugins_blocklink_admin extends DBblocklink{
/**
*
* @var idadmin
*/
protected $template;
public $idadmin;
/**
*
* @var idlang
*/
public $idlang;
/**
* Les variables globales
*/
public $action,$tab,$getlang,$edit,$message;
public $title, $blank, $ltype, $content, $url, $idlink, $order, $q, $type;
public static $notify = array('plugin'=>'true','template'=>'message-blocklink.tpl','method'=>'display','assignFetch'=>'notifier');
/**
* Construct class
*/
public function __construct(){
if(class_exists('backend_model_message')){
$this->message = new backend_model_message();
}
if(magixcjquery_filter_request::isGet('action')){
$this->action = magixcjquery_form_helpersforms::inputClean($_GET['action']);
}
if(magixcjquery_filter_request::isGet('tab')){
$this->tab = magixcjquery_form_helpersforms::inputClean($_GET['tab']);
}
if(magixcjquery_filter_request::isGet('getlang')){
$this->getlang = magixcjquery_form_helpersforms::inputNumeric($_GET['getlang']);
}
if(magixcjquery_filter_request::isGet('edit')){
$this->edit = magixcjquery_form_helpersforms::inputNumeric($_GET['edit']);
}
# ADD PAGE
if(magixcjquery_filter_request::isPost('title')){
$this->title = magixcjquery_form_helpersforms::inputClean($_POST['title']);
}
if(magixcjquery_filter_request::isPost('type')){
$this->ltype = magixcjquery_form_helpersforms::inputClean($_POST['type']);
}
if(magixcjquery_filter_request::isPost('content')){
$this->content = magixcjquery_form_helpersforms::inputClean($_POST['content']);
}
if(magixcjquery_filter_request::isPost('url')){
$this->url = magixcjquery_form_helpersforms::inputClean($_POST['url']);
}
if(magixcjquery_filter_request::isPost('blank')){
$this->blank = magixcjquery_form_helpersforms::inputClean($_POST['blank']);
}
# EDIT LINK
if(magixcjquery_filter_request::isPOST('idlink')){
$this->idlink = magixcjquery_form_helpersforms::inputNumeric($_POST['idlink']);
}
# DELETE LINK
if(magixcjquery_filter_request::isPOST('delete')){
$this->delete = magixcjquery_form_helpersforms::inputNumeric($_POST['delete']);
}
# ORDER LINK
if(magixcjquery_filter_request::isPost('order')){
$this->order = magixcjquery_form_helpersforms::arrayClean($_POST['order']);
}
// Ajax search
if(magixcjquery_filter_request::isGet('search_type')){
$this->type = magixcjquery_form_helpersforms::inputClean($_GET['search_type']);
}
if(magixcjquery_filter_request::isGet('q')){
$this->q = magixcjquery_form_helpersforms::inputClean($_GET['q']);
}
$this->template = new backend_controller_plugins();
}
/**
* Retourne le message de notification
* @param $type
*/
private function notify($type){
$this->message->getNotify($type,self::$notify);
}
/**
* @access private
* Installation des tables mysql du plugin
*/
private function install_table(){
if(parent::c_show_table() == 0){
$this->template->db_install_table('db.sql', 'request/install.tpl');
}else{
return true;
}
}
/**
*
*/
public function save($type)
{
if( !empty($this->title) && !empty($this->url) ){
$page = array(
'idlang' => $this->getlang,
'title' => $this->title,
'content' => ( (isset($this->content) && !empty($this->content))?$this->content:NULL ),
'url' => $this->url,
'blank' => ( (isset($this->blank) && !empty($this->blank))?1:0 ),
'ltype' => $this->ltype
);
switch ($type) {
case 'add':
$c = parent::c_link($this->getlang);
if ($c != null)
$page['lorder'] = $c['nb'];
else
$page['lorder'] = 0;
parent::i_link($page);
$this->template->assign('links',parent::getLastlink($this->getlang));
$header= new magixglobal_model_header();
$header->head_expires("Mon, 26 Jul 1997 05:00:00 GMT");
$header->head_last_modified(gmdate( "D, d M Y H:i:s" ) . "GMT");
$header->pragma();
$header->cache_control("nocache");
$header->getStatus('200');
$header->json_header("UTF-8");
$this->message->json_post_response(true,'save',self::$notify,$this->template->fetch('loop/list.tpl'));
break;
case 'update':
$page['id'] = $this->idlink;
parent::u_link($page);
$this->notify('save');
break;
}
}
}
public function del()
{
parent::d_link($this->delete);
$this->notify('delete');
}
/**
* Execute Update AJAX FOR order
* @access private
*
*/
private function update_order(){
if(isset($this->order)){
$p = $this->order;
for ($i = 0; $i < count($p); $i++) {
parent::u_order($i,$p[$i]);
}
}
}
/**
* Affiche les pages de l'administration du plugin
* @access public
*/
public function run(){
if(self::install_table() == true){
if (isset($this->tab) && $this->tab == 'about')
{
$this->template->display('about.tpl');
}
elseif (!isset($this->tab) || (isset($this->tab) && $this->tab == 'index'))
{
if(isset($this->action)) {
if ($this->action == 'edit') {
if ( isset($this->idlink) && is_numeric($this->idlink) && $this->idlink != '' ) {
if ( isset($this->title) && isset($this->url) ) {
$this->save('update');
}
} elseif ( isset($this->title) && isset($this->url) ) {
$this->save('add');
} elseif ( isset($this->edit) && is_numeric($this->edit) ) {
$this->template->assign('link',parent::g_link($this->edit));
$this->template->display('modal/edit.tpl');
}
} elseif ($this->action == 'delete') {
if ( isset($this->delete) && is_numeric($this->delete) ) {
$this->del();
}
} elseif ($this->action == 'order' && isset($this->order)) {
$this->update_order();
} elseif ($this->action == 'getlist') {
$this->template->assign('links',parent::getLastlink($this->getlang));
$this->template->display('loop/list.tpl');
} elseif ($this->action == 'list') {
$this->template->assign('links',parent::getlinks($this->getlang));
$this->template->display('index.tpl');
} elseif ($this->action == 'search') {
if (isset($this->q) && isset($this->type)) {
$results = parent::search($this->type,$this->q,$this->getlang);
//var_dump($results);
$iso = parent::getIso($this->getlang);
$this->template->assign('iso',$iso['iso']);
$this->template->assign('type',$this->type);
$this->template->assign('search_results',$results);
$this->template->display('loop/results.tpl');
}
}
}
}
}
}
/**
* Set Configuration pour le menu
* @return array
*/
public function setConfig(){
return array(
'url'=> array(
'lang'=>'list',
'action'=>'list',
'name'=>'Bloc Liens'
)
);
}
}
class DBblocklink{
/**
* Vérifie si les tables du plugin sont installé
* @access protected
* return integer
*/
protected function c_show_table(){
$table = 'mc_plugins_blocklink';
return magixglobal_model_db::layerDB()->showTable($table);
}
/**
* @param $lang
* @return array
*/
protected function getIso($lang)
{
$query = "SELECT iso FROM mc_lang WHERE idlang = $lang";
return magixglobal_model_db::layerDB()->selectOne($query);
}
// GET
/**
* @param $idlang
* @return array
*/
protected function getLinks($idlang)
{
$query = "SELECT idlink as id, title, content, url, blank, ltype FROM mc_plugins_blocklink WHERE idlang = :idlang ORDER BY lorder";
return magixglobal_model_db::layerDB()->select($query, array(
':idlang' => $idlang
));
}
/**
* @return array
*/
protected function getLastLink($idlang)
{
$query = "SELECT idlink as id, title, content, url, blank, ltype FROM `mc_plugins_blocklink` WHERE idlang = :idlang ORDER BY idlink DESC LIMIT 1";
return magixglobal_model_db::layerDB()->select($query, array(
':idlang' => $idlang
));
}
/**
* @param $id
* @return array
*/
protected function g_link($id)
{
$query = "SELECT idlink as id, title, content, url, blank, ltype
FROM mc_plugins_blocklink
JOIN mc_lang USING(idlang)
WHERE idlink = :id";
return magixglobal_model_db::layerDB()->selectOne($query, array(
':id' => $id
));
}
/**
* @param $idlang
* @return array
*/
protected function c_link($idlang)
{
$query = "SELECT COUNT(idlink) as nb FROM mc_plugins_blocklink WHERE idlang = :idlang";
return magixglobal_model_db::layerDB()->selectOne($query, array(
':idlang' => $idlang
));
}
// INSERT
/**
* @param $page
*/
protected function i_link($page)
{
$query = "INSERT INTO mc_plugins_blocklink (idlang,title,content,url,blank,ltype,lorder) VALUES (:idlang,:title,:content,:url,:blank,:ltype,:lorder)";
magixglobal_model_db::layerDB()->insert($query,array(
':idlang' => $page['idlang'],
':title' => $page['title'],
':content' => $page['content'],
':url' => $page['url'],
':blank' => $page['blank'],
':ltype' => $page['ltype'],
':lorder' => $page['lorder']
));
}
// UPDATE
/**
* @param $page
*/
protected function u_link($page)
{
$query = "UPDATE mc_plugins_blocklink
SET
idlang = :idlang,
title = :title,
content = :content,
url = :url,
blank = :blank,
ltype = :ltype
WHERE idlink = :id";
magixglobal_model_db::layerDB()->insert($query,array(
':id' => $page['id'],
':idlang' => $page['idlang'],
':title' => $page['title'],
':content' => $page['content'],
':url' => $page['url'],
':blank' => $page['blank'],
':ltype' => $page['ltype']
));
}
/**
* Met à jour l'ordre d'affichage des pages
* @param $i
* @param $id
*/
protected function u_order($i,$id){
$sql = 'UPDATE mc_plugins_blocklink SET lorder = :i WHERE idlink = :id';
magixglobal_model_db::layerDB()->update($sql,
array(
':i'=>$i,
':id'=>$id
)
);
}
// DELETE
/**
* @param $id
*/
protected function d_link($id)
{
$query = "DELETE FROM mc_plugins_blocklink WHERE idlink = :id";
magixglobal_model_db::layerDB()->delete($query,array(':id'=>$id));
}
// AJAX SEARCH
/**
* @param $type
* @param $str
* @param $idlang
* @return array
*/
protected function search($type, $str, $idlang)
{
$limit = 10;
if ($type == 'cat')
{
$query = "SELECT
`c`.`idclc` as parent,
`c`.`pathclibelle` as uriparent,
`c`.`clibelle` as nameparent,
`s`.`idcls` as id,
`s`.`slibelle` as name,
`s`.`pathslibelle` as uri
FROM `mc_catalog_c` as `c`
LEFT JOIN `mc_catalog_s` as `s`
ON `c`.`idclc` = `s`.`idclc`
WHERE
`c`.`idlang` = :idlang
AND
`s`.`slibelle` LIKE '%".addslashes($str)."%'
ORDER BY `s`.`idcls`";
$query .= ($limit?" LIMIT ".$limit:"");
$data1 = magixglobal_model_db::layerDB()->select($query,array(':idlang' => $idlang));
$query = "SELECT
`c`.`idclc` as id,
`c`.`clibelle` as name,
`c`.`pathclibelle` as uri
FROM `mc_catalog_c` as `c`
WHERE
`c`.`idlang` = :idlang
AND
`c`.`clibelle` LIKE '%".addslashes($str)."%'
ORDER BY `c`.`idclc`";
$query .= ($limit?" LIMIT ".$limit:"");
$data2 = magixglobal_model_db::layerDB()->select($query,array(':idlang' => $idlang));
return array_merge($data1,$data2);
}
elseif ($type == 'cms')
{
$query = "SELECT
`p`.`idpage` as id,
`p`.`title_page` as name,
`p`.`uri_page` as uri,
`p`.`idcat_p` as parent,
`parent`.`uri_page` as `uriparent`,
`parent`.`title_page` as `nameparent`
FROM `mc_cms_pages` as `p`
LEFT JOIN `mc_cms_pages` as `parent`
ON `p`.`idcat_p` = `parent`.`idpage`
WHERE
`p`.`idlang` = :idlang
AND
`p`.`title_page` LIKE '%".addslashes($str)."%'
ORDER BY `p`.`idpage`";
$query .= ($limit?" LIMIT ".$limit:"");
return magixglobal_model_db::layerDB()->select($query,array(':idlang' => $idlang));
}
}
}
?>