1<?php
2/*
3 * e107 website system
4 *
5 * Copyright (C) 2008-2016 e107 Inc (e107.org)
6 * Released under the terms and conditions of the
7 * GNU General Public License (http://www.gnu.org/licenses/gpl.txt)
8 *
9 * @file
10 * Class installations to handle configuration forms on Admin UI.
11 */
12
13$eplug_admin = true;
14
15require_once("../../class2.php");
16
17if(!getperms("P") || !e107::isInstalled('gallery'))
18{
19	e107::redirect('admin');
20	exit();
21}
22
23// [PLUGINS]/gallery/languages/[LANGUAGE]/[LANGUAGE]_admin.php
24e107::lan('gallery', true, true);
25
26$e_sub_cat = 'gallery';
27
28
29/**
30 * Class plugin_gallery_admin.
31 */
32class plugin_gallery_admin extends e_admin_dispatcher
33{
34
35	/**
36	 * Required (set by child class).
37	 *
38	 * Controller map array in format.
39	 * @code
40	 *  'MODE' => array(
41	 *      'controller' =>'CONTROLLER_CLASS_NAME',
42	 *      'path' => 'CONTROLLER SCRIPT PATH',
43	 *      'ui' => 'UI_CLASS', // extend of 'comments_admin_form_ui'
44	 *      'uipath' => 'path/to/ui/',
45	 *  );
46	 * @endcode
47	 *
48	 * @var array
49	 */
50	protected $modes = array(
51		'main' => array(
52			'controller' => 'gallery_cat_admin_ui',
53			'path'       => null,
54			'ui'         => 'gallery_cat_admin_form_ui',
55			'uipath'     => null
56		),
57		'cat'  => array(
58			'controller' => 'gallery_cat_ui',
59			'path'       => null,
60			'ui'         => 'gallery_cat_form_ui',
61			'uipath'     => null
62		)
63	);
64
65	/**
66	 * Optional (set by child class).
67	 *
68	 * Required for admin menu render. Format:
69	 * @code
70	 *  'mode/action' => array(
71	 *      'caption' => 'Link title',
72	 *      'perm' => '0',
73	 *      'url' => '{e_PLUGIN}plugname/admin_config.php',
74	 *      ...
75	 *  );
76	 * @endcode
77	 *
78	 * Note that 'perm' and 'userclass' restrictions are inherited from the $modes, $access and $perm, so you don't
79	 * have to set that vars if you don't need any additional 'visual' control.
80	 *
81	 * All valid key-value pair (see e107::getNav()->admin function) are accepted.
82	 *
83	 * @var array
84	 */
85	protected $adminMenu = array(
86		'main/prefs' => array('caption' => LAN_PREFS, 'perm' => 'P'),
87		'main/list'  => array('caption' => LAN_CATEGORIES, 'perm'    => 'P'),
88		'main/create'  => array('caption' => LAN_CREATE, 'perm'    => 'P'),
89	);
90
91	/**
92	 * Optional (set by child class).
93	 *
94	 * @var string
95	 */
96	protected $menuTitle = LAN_PLUGIN_GALLERY_TITLE;
97
98	/**
99	 * Initial function.
100	 */
101	function init()
102	{
103
104		if(E107_DEBUG_LEVEL > 0)
105		{
106			$this->adminMenu['main/list'] = array(
107				'caption' => LAN_CATEGORY,
108				'perm'    => 'P',
109			);
110		}
111	}
112
113}
114
115
116/**
117 * Class gallery_cat_admin_ui.
118 */
119class gallery_cat_admin_ui extends e_admin_ui
120{
121
122	/**
123	 * Could be LAN constant (multi-language support).
124	 *
125	 * @var string plugin name
126	 */
127	protected $pluginTitle = LAN_PLUGIN_GALLERY_TITLE;
128
129	/**
130	 * Plugin name.
131	 *
132	 * @var string
133	 */
134	protected $pluginName = 'gallery';
135
136	/**
137	 * Plugin table.
138	 *
139	 * @var string
140	 */
141	protected $table = "core_media_cat";
142
143	/**
144	 * Primary key in plugin table.
145	 *
146	 * @var string
147	 */
148	protected $pid = "media_cat_id";
149
150	/**
151	 * Default (db) limit value.
152	 *
153	 * @var integer
154	 */
155	protected $perPage = 10;
156
157	/**
158	 * SQL order, false to disable order, null is default order.
159	 *
160	 * @var string
161	 */
162	protected $listOrder = 'media_cat_order';
163
164	/**
165	 * SQL query for listing. Without any Order or Limit.
166	 *
167	 * @var string
168	 */
169	protected $listQry = "SELECT * FROM `#core_media_cat` WHERE media_cat_owner = 'gallery' ";
170
171	/**
172	 * UI field data.
173	 *
174	 * @var array
175	 */
176	protected $fields = array(
177		'checkboxes'         => array(
178			'title'   => '',
179			'type'    => null,
180			'width'   => '5%',
181			'forced'  => true,
182			'thclass' => 'center',
183			'class'   => 'center',
184		),
185		'media_cat_image'    => array(
186			'title'     => LAN_IMAGE,
187			'type'      => 'image',
188			'data'      => 'str',
189			'width'     => '100px',
190			'thclass'   => 'center',
191			'class'     => 'center',
192			'readParms' => 'thumb=60&thumb_urlraw=0&thumb_aw=60',
193			'readonly'  => false,
194			'batch'     => false,
195			'filter'    => false,
196		),
197		'media_cat_owner'    => array(
198			'title'      => LAN_OWNER,
199			'type'       => 'hidden',
200			'nolist'     => true,
201			'width'      => 'auto',
202			'thclass'    => 'left',
203			'readonly'   => false,
204			'writeParms' => 'value=gallery',
205		),
206		'media_cat_category' => array(
207			'title'    => LAN_CATEGORY,
208			'type'     => 'hidden',
209			'nolist'   => true,
210			'width'    => 'auto',
211			'thclass'  => 'left',
212			'readonly' => true,
213		),
214		'media_cat_title'    => array(
215			'title'    => LAN_TITLE,
216			'type'     => 'text',
217			'width'    => 'auto',
218			'thclass'  => 'left',
219			'readonly' => false,
220			'inline'   => true,
221		),
222		'media_cat_sef'      => array(
223			'title'   => LAN_SEFURL,
224			'type'    => 'text',
225			'inline'  => true,
226			'width'   => 'auto',
227			'thclass' => 'left',
228		),
229		'media_cat_diz'      => array(
230			'title'     => LAN_DESCRIPTION,
231			'type'      => 'bbarea',
232			'width'     => '30%',
233			'readParms' => 'expand=...&truncate=150&bb=1',
234			'readonly'  => false,
235		),
236		'media_cat_class'    => array(
237			'title'  => LAN_VISIBILITY,
238			'type'   => 'userclass',
239			'width'  => 'auto',
240			'data'   => 'int',
241			'filter' => true,
242			'batch'  => true,
243		),
244		'media_cat_order'    => array(
245			'title'   => LAN_ORDER,
246			'type'    => 'text',
247			'width'   => 'auto',
248			'thclass' => 'center',
249			'class'   => 'center',
250		),
251		'options'            => array(
252			'title'   => LAN_OPTIONS,
253			'type'    => null,
254			'width'   => '5%',
255			'forced'  => true,
256			'thclass' => 'center last',
257			'class'   => 'right',
258		),
259	);
260
261	/**
262	 * Referenced from $prefs property per field - 'tab => xxx' where xxx is the tab key (identifier).
263	 *
264	 * Example:
265	 * @code
266	 *  array(
267	 *      '0' => 'Tab label',
268	 *      '1' => 'Another label',
269	 *  );
270	 * @endcode
271	 *
272	 * @var array
273	 *  Edit/create form tabs.
274	 */
275	protected $preftabs = array(
276		LAN_GENERAL,
277		LAN_GALLERY_ADMIN_03,
278		LAN_GALLERY_ADMIN_32,
279	);
280
281	/**
282	 * Plugin Preference description array.
283	 *
284	 * @var array
285	 */
286	protected $prefs = array(
287		'popup_w'                    => array(
288			'title' => LAN_GALLERY_ADMIN_04,
289			'tab'   => 0,
290			'type'  => 'text',
291			'data'  => 'int',
292			'help'  => LAN_GALLERY_ADMIN_05,
293		),
294		'popup_h'                    => array(
295			'title' => LAN_GALLERY_ADMIN_06,
296			'tab'   => 0,
297			'type'  => 'text',
298			'data'  => 'int',
299			'help'  => LAN_GALLERY_ADMIN_07,
300		),
301		'downloadable'               => array(
302			'title' => LAN_GALLERY_ADMIN_08,
303			'tab'   => 0,
304			'type'  => 'boolean',
305			'data'  => 'int',
306			'help'  => LAN_GALLERY_ADMIN_09,
307		),
308		'slideshow_category'         => array(
309			'title' => LAN_GALLERY_ADMIN_10,
310			'tab'   => 1,
311			'type'  => 'dropdown',
312			'data'  => 'str',
313			'help'  => LAN_GALLERY_ADMIN_11,
314		),
315		'slideshow_duration'         => array(
316			'title' => LAN_GALLERY_ADMIN_12,
317			'type'  => 'number',
318			'tab'   => 1,
319			'data'  => 'integer',
320			'help'  => LAN_GALLERY_ADMIN_13,
321		),
322		'slideshow_auto'             => array(
323			'title' => LAN_GALLERY_ADMIN_14,
324			'type'  => 'boolean',
325			'tab'   => 1,
326			'data'  => 'integer',
327			'help'  => LAN_GALLERY_ADMIN_15,
328		),
329		'slideshow_freq'             => array(
330			'title' => LAN_GALLERY_ADMIN_16,
331			'type'  => 'number',
332			'tab'   => 1,
333			'data'  => 'integer',
334			'help'  => LAN_GALLERY_ADMIN_17,
335		),
336		'slideshow_effect'           => array(
337			'title' => LAN_GALLERY_ADMIN_18,
338			'type'  => 'dropdown',
339			'tab'   => 1,
340			'data'  => 'str',
341			'help'  => LAN_GALLERY_ADMIN_19
342		),
343		'perpage'                    => array(
344			'title' => LAN_GALLERY_ADMIN_20,
345			'tab'   => 0,
346			'type'  => 'number',
347			'data'  => 'int',
348			'help'  => LAN_GALLERY_ADMIN_21,
349		),
350		'orderby'                    => array(
351			'title'      => LAN_GALLERY_ADMIN_22,
352			'tab'        => 0,
353			'type'       => 'dropdown',
354			'data'       => 'str',
355			'writeParms' => array(
356				'optArray' => array(
357					'media_id ASC'       => LAN_GALLERY_ADMIN_23,
358					'media_id DESC'      => LAN_GALLERY_ADMIN_24,
359					'media_name ASC'     => LAN_GALLERY_ADMIN_25,
360					'media_name DESC'    => LAN_GALLERY_ADMIN_26,
361					'media_caption ASC'  => LAN_GALLERY_ADMIN_27,
362					'media_caption DESC' => LAN_GALLERY_ADMIN_28,
363				),
364			),
365		),
366		'pp_global'                  => array(
367			'title'      => LAN_GALLERY_ADMIN_70,
368			'type'       => 'boolean',
369			'data'       => 'int',
370			'tab'        => 2,
371		),
372		'pp_hook'                    => array(
373			'title'      => LAN_GALLERY_ADMIN_71,
374			'type'       => 'text',
375			'data'       => 'str',
376			'writeParms' => array(
377				'default' => 'data-gal',
378			),
379			'tab'        => 2,
380		),
381		'pp_animation_speed'         => array(
382			'title'      => LAN_GALLERY_ADMIN_33,
383			'type'       => 'dropdown',
384			'data'       => 'str',
385			'writeParms' => array(
386				'optArray' => array(
387					'fast'   => LAN_GALLERY_ADMIN_62,
388					'slow'   => LAN_GALLERY_ADMIN_63,
389					'normal' => LAN_GALLERY_ADMIN_64,
390				),
391			),
392			'tab'        => 2,
393		),
394		'pp_slideshow'               => array(
395			'title'      => LAN_GALLERY_ADMIN_34,
396			'type'       => 'text',
397			'data'       => 'int',
398			'writeParms' => array(
399				'default' => 5000,
400			),
401			'tab'        => 2,
402		),
403		'pp_autoplay_slideshow'      => array(
404			'title'      => LAN_GALLERY_ADMIN_35,
405			'type'       => 'boolean',
406			'data'       => 'int',
407			'tab'        => 2,
408		),
409		'pp_opacity'                 => array(
410			'title'      => LAN_GALLERY_ADMIN_36,
411			'help'       => LAN_GALLERY_ADMIN_37,
412			'type'       => 'text',
413			'data'       => 'float',
414			'writeParms' => array(
415				'default' => 0.80,
416			),
417			'tab'        => 2,
418		),
419		'pp_show_title'              => array(
420			'title'      => LAN_GALLERY_ADMIN_38,
421			'type'       => 'boolean',
422			'data'       => 'int',
423			'tab'        => 2,
424		),
425		'pp_allow_resize'            => array(
426			'title'      => LAN_GALLERY_ADMIN_39,
427			'help'       => LAN_GALLERY_ADMIN_40,
428			'type'       => 'boolean',
429			'data'       => 'int',
430			'tab'        => 2,
431		),
432		'pp_default_width'           => array(
433			'title'      => LAN_GALLERY_ADMIN_41,
434			'type'       => 'text',
435			'data'       => 'int',
436			'writeParms' => array(
437				'default' => 500,
438			),
439			'tab'        => 2,
440		),
441		'pp_default_height'          => array(
442			'title'      => LAN_GALLERY_ADMIN_42,
443			'type'       => 'text',
444			'data'       => 'int',
445			'writeParms' => array(
446				'default' => 344,
447			),
448			'tab'        => 2,
449		),
450		'pp_counter_separator_label' => array(
451			'title'      => LAN_GALLERY_ADMIN_43,
452			'help'       => LAN_GALLERY_ADMIN_44,
453			'type'       => 'text',
454			'data'       => 'str',
455			'writeParms' => array(
456				'default' => '/',
457			),
458			'tab'        => 2,
459		),
460		'pp_theme'                   => array(
461			'title'      => LAN_THEME,
462			'type'       => 'dropdown',
463			'data'       => 'str',
464			'writeParms' => array(
465				'optArray' => array(
466					'pp_default'    => LAN_DEFAULT,
467					'light_rounded' => LAN_GALLERY_ADMIN_65,
468					'dark_rounded'  => LAN_GALLERY_ADMIN_66,
469					'light_square'  => LAN_GALLERY_ADMIN_67,
470					'dark_square'   => LAN_GALLERY_ADMIN_68,
471					'facebook'      => LAN_GALLERY_ADMIN_69,
472				),
473			),
474			'tab'        => 2,
475		),
476		'pp_horizontal_padding'      => array(
477			'title'      => LAN_GALLERY_ADMIN_46,
478			'help'       => LAN_GALLERY_ADMIN_47,
479			'type'       => 'text',
480			'data'       => 'int',
481			'writeParms' => array(
482				'default' => 20,
483			),
484			'tab'        => 2,
485		),
486		'pp_hideflash'               => array(
487			'title'      => LAN_GALLERY_ADMIN_48,
488			'help'       => LAN_GALLERY_ADMIN_49,
489			'type'       => 'boolean',
490			'data'       => 'int',
491			'tab'        => 2,
492		),
493		'pp_wmode'                   => array(
494			'title'      => LAN_GALLERY_ADMIN_50,
495			'help'       => LAN_GALLERY_ADMIN_51,
496			'type'       => 'text',
497			'data'       => 'str',
498			'writeParms' => array(
499				'default' => 'opaque',
500			),
501			'tab'        => 2,
502		),
503		'pp_autoplay'                => array(
504			'title'      => LAN_GALLERY_ADMIN_52,
505			'type'       => 'boolean',
506			'data'       => 'int',
507			'tab'        => 2,
508		),
509		'pp_modal'                   => array(
510			'title'      => LAN_GALLERY_ADMIN_53,
511			'help'       => LAN_GALLERY_ADMIN_54,
512			'type'       => 'boolean',
513			'data'       => 'int',
514			'tab'        => 2,
515		),
516		'pp_deeplinking'             => array(
517			'title'      => LAN_GALLERY_ADMIN_55,
518			'help'       => LAN_GALLERY_ADMIN_56,
519			'type'       => 'boolean',
520			'data'       => 'int',
521			'tab'        => 2,
522		),
523		'pp_overlay_gallery'         => array(
524			'title'      => LAN_GALLERY_ADMIN_57,
525			'help'       => LAN_GALLERY_ADMIN_58,
526			'type'       => 'boolean',
527			'data'       => 'int',
528			'tab'        => 2,
529		),
530		'pp_keyboard_shortcuts'      => array(
531			'title'      => LAN_GALLERY_ADMIN_59,
532			'help'       => LAN_GALLERY_ADMIN_60,
533			'type'       => 'boolean',
534			'data'       => 'int',
535			'tab'        => 2,
536		),
537		'pp_ie6_fallback'            => array(
538			'title'      => LAN_GALLERY_ADMIN_61,
539			'type'       => 'boolean',
540			'data'       => 'int',
541			'tab'        => 2,
542		),
543	);
544
545	private $ownerCount;
546
547	/**
548	 * Initial function.
549	 */
550	function init()
551	{
552		$effects = array(
553			'scrollHorz' => LAN_GALLERY_ADMIN_29,
554			'scrollVert' => LAN_GALLERY_ADMIN_30,
555			'fade'       => LAN_GALLERY_ADMIN_31,
556		);
557
558		$this->prefs['slideshow_effect']['writeParms'] = $effects;
559		$this->prefs['slideshow_effect']['readParms'] = $effects;
560
561		$categories = e107::getMedia()->getCategories('gallery');
562		$cats = array();
563		foreach($categories as $k => $var)
564		{
565			$id = preg_replace("/[^0-9]/", '', $k);
566			$cats[$id] = $var['media_cat_title'];
567		}
568
569		$this->prefs['slideshow_category']['writeParms'] = $cats;
570		$this->prefs['slideshow_category']['readParms'] = $cats;
571
572		$mes = e107::getMessage();
573		$tp = e107::getParser();
574
575		$x = LAN_PLUGIN_GALLERY_TITLE;
576		$y = "<a href='" . e_ADMIN . "image.php'>" . LAN_MEDIAMANAGER . "</a>";
577
578		$message = $tp->lanVars(LAN_GALLERY_ADMIN_01, array($x, $y), true);
579		$mes->addInfo($message);
580
581		$this->setGalleryCount();
582	}
583
584
585
586	function setGalleryCount()
587	{
588
589		$sql = e107::getDb();
590
591		if($sql->gen("SELECT media_cat_owner,  MAX(CAST(SUBSTRING_INDEX(media_cat_category, '_', -1 ) AS UNSIGNED)) as maxnum, count(media_cat_id) as number FROM `#core_media_cat`  GROUP BY media_cat_owner"))
592		{
593			while($row = $sql->fetch())
594			{
595				$this->ownerCount[$row['media_cat_owner']] = $row['number'];
596				$own = $row['media_cat_owner'];
597			//	if(!in_array($own,$this->restricted))
598				{
599//					$this->fields['media_cat_owner']['writeParms'][$own] = $own;
600
601					if($row['maxnum'] > 0)
602					{
603						$this->ownerCount[$row['media_cat_owner']] = $row['maxnum']; // $maxnum;
604					}
605				}
606			}
607		}
608
609		e107::getMessage()->addDebug("Max value for category names: ".print_a($this->ownerCount,true));
610
611
612
613
614	}
615
616
617	public function beforeCreate($new_data, $old_data)
618	{
619		$new_data = $this->setCategory($new_data);
620
621		return $new_data;
622	}
623
624
625	public function beforeUpdate($new_data, $old_data, $id)
626	{
627	//	$new_data = $this->setCategory($new_data);
628
629		return $new_data;
630	}
631
632	private function setCategory($new_data)
633	{
634		$type = 'image_';
635
636		$increment = ($this->ownerCount['gallery'] +1);
637
638		$new_data['media_cat_owner'] = 'gallery';
639		$new_data['media_cat_category'] = 'gallery_'.$type.$increment;
640
641		if(empty($new_data['media_cat_sef']))
642		{
643			 $new_data['media_cat_sef'] = eHelper::title2sef($new_data['media_cat_title']);
644		}
645
646		return $new_data;
647	}
648
649
650	function galleryPage()
651	{
652		$mes = e107::getMessage();
653		$tp = e107::getParser();
654
655		$x = LAN_PLUGIN_GALLERY_TITLE;
656		$y = "<a href='" . e_ADMIN . "image.php'>" . LAN_MEDIAMANAGER . "</a>";
657
658		$message = $tp->lanVars(LAN_GALLERY_ADMIN_01, array($x, $y), true);
659		$mes->addInfo($message);
660	}
661
662}
663
664
665class gallery_cat_admin_form_ui extends e_admin_form_ui
666{
667
668	// Override the default Options field.
669	public function gallery_category_parent($curVal, $mode)
670	{
671		// TODO - catlist combo without current cat ID in write mode, parents only for batch/filter.
672		// Get UI instance.
673		$controller = $this->getController();
674		switch($mode)
675		{
676			case 'read':
677				return e107::getParser()->toHTML($controller->getDownloadCategoryTree($curVal), false, 'TITLE');
678				break;
679
680			case 'write':
681				return $this->selectbox('gallery_category_parent', $controller->getDownloadCategoryTree(), $curVal);
682				break;
683
684			case 'filter':
685			case 'batch':
686				return $controller->getDownloadCategoryTree();
687				break;
688		}
689	}
690
691}
692
693
694class gallery_main_admin_ui extends e_admin_ui
695{
696
697
698}
699
700
701class gallery_main_admin_form_ui extends e_admin_form_ui
702{
703
704
705}
706
707
708new plugin_gallery_admin();
709require_once(e_ADMIN . "auth.php");
710e107::getAdminUI()->runPage(); //gallery/includes/admin.php is auto-loaded.
711require_once(e_ADMIN . "footer.php");
712exit;
713