-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathadmin_config.php
666 lines (580 loc) · 14.1 KB
/
admin_config.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
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
<?php
/**
* @file
* Admin UI.
*/
require_once("../../class2.php");
if(!e107::isInstalled('metatag') || !getperms("P"))
{
e107::redirect(e_BASE . 'index.php');
}
e107_require_once(e_PLUGIN . 'metatag/includes/metatag.class.php');
// [PLUGINS]/metatag/languages/[LANGUAGE]/[LANGUAGE]_admin.php
e107::lan('metatag', true, true);
/**
* Class metatag_admin.
*/
class metatag_admin_config extends e_admin_dispatcher
{
/**
* Required (set by child class).
*
* Controller map array in format.
* @code
* 'MODE' => array(
* 'controller' =>'CONTROLLER_CLASS_NAME',
* 'path' => 'CONTROLLER SCRIPT PATH',
* 'ui' => 'UI_CLASS', // extend of 'comments_admin_form_ui'
* 'uipath' => 'path/to/ui/',
* );
* @endcode
*
* @var array
*/
protected $modes = array(
'ajax' => array(
'controller' => 'metatag_admin_ajax_ui',
),
'main' => array(
'controller' => 'metatag_admin_ui',
'path' => null,
'ui' => 'metatag_admin_form_ui',
'uipath' => null
),
);
/**
* Optional (set by child class).
*
* Required for admin menu render. Format:
* @code
* 'mode/action' => array(
* 'caption' => 'Link title',
* 'perm' => '0',
* 'url' => '{e_PLUGIN}plugname/admin_config.php',
* ...
* );
* @endcode
*
* Note that 'perm' and 'userclass' restrictions are inherited from the $modes, $access and $perm, so you don't
* have to set that vars if you don't need any additional 'visual' control.
*
* All valid key-value pair (see e107::getNav()->admin function) are accepted.
*
* @var array
*/
protected $adminMenu = array(
'main/list' => array(
'caption' => LAN_METATAG_ADMIN_UI_01,
'perm' => 'P',
),
'opt1' => array(
'divider' => true,
),
'main/prefs' => array(
'caption' => LAN_METATAG_ADMIN_UI_09,
'perm' => 'P',
),
);
/**
* Optional (set by child class).
*
* @var string
*/
protected $menuTitle = LAN_PLUGIN_METATAG_NAME;
/**
* User defined constructor - called before _initController() method.
*/
public function init()
{
$meta = new metatag();
$meta->prepareDefaultTypes();
}
}
/**
* Class metatag_admin_ajax_ui.
*/
class metatag_admin_ajax_ui extends e_admin_ui
{
/**
* Initial function.
*/
public function init()
{
// Construct action string.
$action = varset($_GET['mode']) . '/' . varset($_GET['action']);
switch($action)
{
case 'ajax/revert':
$this->ajaxRevert();
break;
case 'ajax/cache':
$this->ajaxCache();
break;
}
}
/**
* Ajax Request handler.
*/
public function ajaxRevert()
{
$id = (int) varset($_GET['id'], 0);
if($id > 0)
{
$db = e107::getDb();
$type = $db->retrieve('metatag_default', 'type', 'id = ' . $id);
if(is_string($type))
{
$meta = new metatag();
$config = $meta->getAddonConfig();
$entityDefaults = varset($config[$type]['default'], array());
$update = array(
'data' => array(
'name' => varset($config[$type]['name'], ''),
'data' => $meta->serialize($entityDefaults),
),
'WHERE' => 'id = "' . (int) $id . '"',
);
$db->update('metatag_default', $update, false);
if($type == 'metatag_default')
{
$meta->clearCacheAll();
}
else
{
$meta->clearCacheByType($type);
}
}
}
$ajax = e107::getAjax();
$commands = array();
$commands[] = $ajax->commandInvoke('#uiModal', 'modal', array('hide'));
$ajax->response($commands);
exit;
}
/**
* Ajax Request handler.
*/
public function ajaxCache()
{
$id = (int) varset($_GET['id'], 0);
if($id > 0)
{
$db = e107::getDb();
$type = $db->retrieve('metatag_default', 'type', 'id = ' . $id);
if(is_string($type))
{
$meta = new metatag();
if($type == 'metatag_default')
{
$meta->clearCacheAll();
}
else
{
$meta->clearCacheByType($type);
}
}
}
$ajax = e107::getAjax();
$commands = array();
$commands[] = $ajax->commandInvoke('#uiModal', 'modal', array('hide'));
$ajax->response($commands);
exit;
}
}
/**
* Class metatag_admin_ui.
*/
class metatag_admin_ui extends e_admin_ui
{
/**
* Could be LAN constant (multi-language support).
*
* @var string plugin name
*/
protected $pluginTitle = LAN_PLUGIN_METATAG_NAME;
/**
* Plugin name.
*
* @var string
*/
protected $pluginName = "metatag";
/**
* Base event trigger name to be used. Leave blank for no trigger.
*
* @var string event name
*/
protected $eventName = 'metatag_default';
protected $table = "metatag_default";
protected $pid = "id";
/**
* Default (db) limit value.
*
* @var integer
*/
protected $perPage = 0;
/**
* @var boolean
*/
protected $batchDelete = false;
/**
* @var string SQL order, false to disable order, null is default order
*/
protected $listOrder = 'name';
protected $sortField = 'name';
protected $sortParent = 'parent';
protected $tabs = array(
LAN_METATAG_ADMIN_TAB_01,
);
/**
* @var array UI field data
*/
protected $fields = array(
'checkboxes' => array(
'title' => '',
'type' => 'hidden',
'data' => false,
),
'name' => array(
'title' => LAN_METATAG_ADMIN_UI_03,
'type' => 'method',
'width' => 'auto',
'thclass' => 'left',
'readonly' => true,
'inline' => false,
),
'type' => array(
'title' => LAN_METATAG_ADMIN_UI_02,
'type' => 'hidden',
'width' => 'auto',
'thclass' => 'left',
'readonly' => true,
'inline' => false,
),
'parent' => array(
'type' => 'hidden',
'readonly' => true,
'inline' => false,
),
'data' => array(
'type' => 'hidden',
'readonly' => true,
'inline' => false,
),
'options' => array(
'type' => 'method',
'width' => '10%',
'forced' => true,
'thclass' => 'center last',
'class' => 'center',
'sort' => false,
),
);
/**
* @var array default fields activated on List view
*/
protected $fieldpref = array(
'name',
'options',
);
/**
* @var array
*/
protected $afterSubmitOptions = array(
'list' => LAN_METATAG_ADMIN_UI_06,
'edit' => LAN_METATAG_ADMIN_UI_07,
);
protected $preftabs = array(
LAN_METATAG_ADMIN_UI_09,
);
protected $prefs = array(
'cache_expire' => array(
'title' => LAN_METATAG_ADMIN_UI_10,
'type' => 'dropdown',
'data' => 'int',
'writeParms' => array(
0 => LAN_METATAG_ADMIN_UI_11,
86400 => LAN_METATAG_ADMIN_UI_12,
604800 => LAN_METATAG_ADMIN_UI_13,
2629000 => LAN_METATAG_ADMIN_UI_14,
31536000 => LAN_METATAG_ADMIN_UI_15,
),
'tab' => 0,
),
'cache_disabled' => array(
'title' => LAN_METATAG_ADMIN_UI_23,
'type' => 'dropdown',
'data' => 'int',
'writeParms' => array(
0 => LAN_NO,
1 => LAN_YES,
),
'tab' => 0,
),
'override' => array(
'title' => LAN_METATAG_ADMIN_UI_25,
'type' => 'dropdown',
'data' => 'int',
'writeParms' => array(
0 => LAN_NO,
1 => LAN_YES,
),
'tab' => 0,
),
'groups' => array(
'title' => LAN_METATAG_ADMIN_UI_24,
'type' => 'checkboxes',
'data' => 'str',
'writeParms' => array(
'basic' => LAN_METATAG_ADMIN_PANEL_01 . '<br/><span class="small">' . LAN_METATAG_ADMIN_PANEL_01_DESC . '</span>',
'advanced' => LAN_METATAG_ADMIN_PANEL_02 . '<br/><span class="small">' . LAN_METATAG_ADMIN_PANEL_02_DESC . '</span>',
'opengraph' => LAN_METATAG_ADMIN_PANEL_03 . '<br/><span class="small">' . LAN_METATAG_ADMIN_PANEL_03_DESC . '</span>',
'facebook' => LAN_METATAG_ADMIN_PANEL_04 . '<br/><span class="small">' . LAN_METATAG_ADMIN_PANEL_04_DESC . '</span>',
'twitter' => LAN_METATAG_ADMIN_PANEL_05 . '<br/><span class="small">' . LAN_METATAG_ADMIN_PANEL_05_DESC . '</span>',
'dublin' => LAN_METATAG_ADMIN_PANEL_06 . '<br/><span class="small">' . LAN_METATAG_ADMIN_PANEL_06_DESC . '</span>',
'google' => LAN_METATAG_ADMIN_PANEL_07 . '<br/><span class="small">' . LAN_METATAG_ADMIN_PANEL_07_DESC . '</span>',
),
'tab' => 0,
),
);
/**
* User defined init.
*/
public function init()
{
e107::css('metatag', 'css/metatag.css');
e107::library('load', 'jquery.once');
e107::js('metatag', 'js/metatag.js');
}
/**
* User defined pre-create logic, return false to prevent DB query execution.
*
* @param $new_data
* Posted data.
* @param $old_data
*
* @return boolean
*/
public function beforeCreate($new_data, $old_data)
{
}
/**
* User defined after-create logic.
*
* @param $new_data
* Posted data.
* @param $old_data
* @param $id
*/
public function afterCreate($new_data, $old_data, $id)
{
}
/**
* User defined pre-update logic, return false to prevent DB query execution.
*
* @param $new_data
* Posted data.
* @param $old_data
* @param $id
*
* @return mixed
*/
public function beforeUpdate($new_data, $old_data, $id)
{
$data = array();
$meta = new metatag();
foreach($new_data['x_metatag_metatags'] as $key => $value)
{
$data[$key] = $value;
}
if($new_data['type'] != 'metatag_default')
{
$global = $meta->getGlobalMetaTags();
// Filter only values, which differ from the default/global ones.
foreach($data as $key => $value)
{
if(isset($global[$key]) && $global[$key] == $value)
{
// Unset value, so we will use top level (global) value.
unset($data[$key]);
}
}
}
// Unset empty values.
foreach($data as $key => $value)
{
if(empty($value))
{
unset($data[$key]);
}
}
$new_data['data'] = $meta->serialize($data);
return $new_data;
}
/**
* User defined after-update logic.
*
* @param $new_data
* Posted data.
* @param $old_data
* @param $id
*/
public function afterUpdate($new_data, $old_data, $id)
{
$meta = new metatag();
if($new_data['type'] == 'metatag_default')
{
$meta->clearCacheAll();
}
else
{
$meta->clearCacheByType($new_data['type']);
}
}
/**
* User defined pre-delete logic.
*/
public function beforeDelete($data, $id)
{
// Cancel deletion.
return false;
}
/**
* User defined after-delete logic.
*/
public function afterDelete($deleted_data, $id, $deleted_check)
{
// If this doesn't return with TRUE, "admin_metatag_default_deleted" event won't be fired.
return false;
}
}
/**
* Class metatag_admin_form_ui.
*/
class metatag_admin_form_ui extends e_admin_form_ui
{
/**
* Get item's name.
*
* @param $curVal
* @param $mode
* @param $parm
*
* @return string
*/
function name($curVal, $mode, $parm)
{
if($mode == 'read')
{
$listModel = $this->getController()->getListModel();
if($listModel)
{
$parent = $listModel->get('parent');
if($parent > 0)
{
$prefix = '<img src="' . e_IMAGE_ABS . 'generic/branchbottom.gif" class="icon" alt="" style="margin-left: 20px" /> ';
return $prefix . $curVal;
}
}
}
return $curVal;
}
/**
* Override the default Options field.
*
* @param $parms
* @param $value
* @param $id
* @param $attributes
*
* @return string
*/
function options($parms, $value, $id, $attributes)
{
$html = '';
if($attributes['mode'] == 'read')
{
$tp = e107::getParser();
// Edit button.
parse_str(str_replace('&', '&', e_QUERY), $query);
$query['action'] = 'edit';
$query['id'] = $id;
$query = http_build_query($query);
$link = array(
'href' => e_REQUEST_HTTP . '?' . $query,
'class' => 'btn btn-default action edit',
'title' => LAN_EDIT,
'data-toggle' => 'tooltip',
'data-placement' => 'top',
'data-animation' => 'false',
);
$link_attributes = '';
foreach($link as $name => $val)
{
$link_attributes .= ' ' . $name . '="' . $val . '"';
}
$html .= '<a' . $link_attributes . '>' . $tp->toGlyph('fa-edit') . '</a>';
// Revert button.
parse_str(str_replace('&', '&', e_QUERY), $query);
$query['mode'] = 'ajax';
$query['action'] = 'revert';
$query['id'] = $id;
$query = http_build_query($query);
$link = array(
'href' => '#',
'class' => 'btn btn-default action revert',
'title' => LAN_METATAG_ADMIN_UI_04,
'data-toggle' => 'tooltip',
'data-placement' => 'top',
'data-animation' => 'false',
'data-confirm-title' => LAN_METATAG_ADMIN_UI_16,
'data-confirm-message' => LAN_METATAG_ADMIN_UI_05,
'data-confirm-yes' => LAN_METATAG_ADMIN_UI_17,
'data-confirm-no' => LAN_METATAG_ADMIN_UI_18,
'data-confirm-url' => e_REQUEST_HTTP . '?' . $query,
);
$link_attributes = '';
foreach($link as $name => $val)
{
$link_attributes .= ' ' . $name . '="' . $val . '"';
}
$html .= '<a' . $link_attributes . '>' . $tp->toGlyph('fa-undo') . '</a>';
// Cache button.
parse_str(str_replace('&', '&', e_QUERY), $query);
$query['mode'] = 'ajax';
$query['action'] = 'cache';
$query['id'] = $id;
$query = http_build_query($query);
$link = array(
'href' => '#',
'class' => 'btn btn-default action cache',
'title' => LAN_METATAG_ADMIN_UI_08,
'data-toggle' => 'tooltip',
'data-placement' => 'top',
'data-animation' => 'false',
'data-confirm-title' => LAN_METATAG_ADMIN_UI_08,
'data-confirm-message' => LAN_METATAG_ADMIN_UI_21,
'data-confirm-yes' => LAN_METATAG_ADMIN_UI_19,
'data-confirm-no' => LAN_METATAG_ADMIN_UI_18,
'data-confirm-url' => e_REQUEST_HTTP . '?' . $query,
);
if($id == 1)
{
$link['data-confirm-message'] = LAN_METATAG_ADMIN_UI_20;
$link['data-confirm-yes'] = LAN_METATAG_ADMIN_UI_22;
}
$link_attributes = '';
foreach($link as $name => $val)
{
$link_attributes .= ' ' . $name . '="' . $val . '"';
}
$html .= '<a' . $link_attributes . '>' . $tp->toGlyph('fa-database') . '</a>';
$html = '<div class="btn-group">' . $html . '</div>';
}
return $html;
}
}
new metatag_admin_config();
require_once(e_ADMIN . "auth.php");
e107::getAdminUI()->runPage();
require_once(e_ADMIN . "footer.php");
exit;