1<?php
2/*
3 * e107 website system
4 *
5 * Copyright (C) 2008-2009 e107 Inc (e107.org)
6 * blankd under the terms and conditions of the
7 * GNU General Public License (http://www.gnu.org/licenses/gpl.txt)
8 *
9 * e107 blank Plugin
10 *
11 * $Source: /cvs_backup/e107_0.8/e107_plugins/blank/admin_config.php,v $
12 * $Revision$
13 * $Date$
14 * $Author$
15 *
16*/
17
18require_once("../class2.php");
19
20if (!getperms("1|TMP"))
21{
22	e107::redirect('admin');
23	exit;
24}
25
26e107::coreLan('theme', true);
27
28if(!empty($_GET['iframe']))
29{
30	define('e_IFRAME', true);
31}
32
33
34class theme_admin extends e_admin_dispatcher
35{
36	/**
37	 * Format: 'MODE' => array('controller' =>'CONTROLLER_CLASS'[, 'index' => 'list', 'path' => 'CONTROLLER SCRIPT PATH', 'ui' => 'UI CLASS NAME child of e_admin_ui', 'uipath' => 'UI SCRIPT PATH']);
38	 * Note - default mode/action is autodetected in this order:
39	 * - $defaultMode/$defaultAction (owned by dispatcher - see below)
40	 * - $adminMenu (first key if admin menu array is not empty)
41	 * - $modes (first key == mode, corresponding 'index' key == action)
42	 * @var array
43	 */
44	protected $modes = array(
45		'main'		=> array(
46						'controller' => 'theme_admin_ui',
47						'path' 		=> null,
48						'ui' 		=> 'theme_admin_form_ui',
49						'uipath' => null
50		),
51		'convert'		=> array(
52						'controller' => 'theme_builder',
53						'path' 		=> null,
54						'ui' 		=> 'theme_admin_form_ui',
55						'uipath' => null
56		),
57	);
58
59
60	protected $adminMenu = array(
61		'main/main'			=> array('caption'=> TPVLAN_33, 'perm' => '0|1|TMP'),
62		'main/admin' 		=> array('caption'=> TPVLAN_34, 'perm' => '0'),
63		'main/choose' 		=> array('caption'=> TPVLAN_51, 'perm' => '0'),
64		'main/online'		=> array('caption'=> TPVLAN_62, 'perm' => '0'),
65		'main/upload'		=> array('caption'=> TPVLAN_38, 'perm' => '0'),
66		'convert/main'		=> array('caption'=> ADLAN_CL_6, 'perm' => '0')
67	);
68
69
70	protected $adminMenuAliases = array(
71		'main/edit'	=> 'main/list'
72	);
73
74	protected $adminMenuIcon = 'e-themes-24';
75
76	protected $menuTitle = TPVLAN_26;
77
78	function init()
79	{
80
81	}
82
83
84
85	function handleAjax()
86	{
87		if(empty($_GET['action']))
88		{
89			return null;
90		}
91
92
93		require_once(e_HANDLER."theme_handler.php");
94		$themec = new themeHandler;
95
96		switch ($_GET['action'])
97		{
98			case 'login':
99				$mp = $themec->getMarketplace();
100				echo $mp->renderLoginForm();
101				exit;
102			break;
103
104				/*
105				case 'download':
106					$string =  base64_decode($_GET['src']);
107					parse_str($string, $p);
108					$mp = $themec->getMarketplace();
109					$mp->generateAuthKey($e107SiteUsername, $e107SiteUserpass);
110					// Server flush useless. It's ajax ready state 4, we can't flush (sadly) before that (at least not for all browsers)
111					echo "<pre>Connecting...\n"; flush();
112					// download and flush
113					$mp->download($p['id'], $p['mode'], $p['type']);
114					echo "</pre>"; flush();
115					exit;
116				break;
117				*/
118
119				case 'info':
120					if(!empty($_GET['src']))
121					{
122						$string =  base64_decode($_GET['src']);
123						parse_str($string,$p);
124						$themeInfo = e107::getSession()->get('thememanager/online/'.intval($p['id']));
125						echo $themec->renderThemeInfo($themeInfo);
126					}
127				break;
128
129				case 'preview':
130					// Theme Info Ajax
131					$tm = (string) $_GET['id'];
132					$data = $themec->getThemeInfo($tm);
133					echo $themec->renderThemeInfo($data);
134				//	exit;
135				break;
136
137			}
138		/*
139			if(vartrue($_GET['src'])) // Process Theme Download.
140			{
141				$string =  base64_decode($_GET['src']);
142				parse_str($string,$p);
143
144				if(vartrue($_GET['info']))
145				{
146					echo $themec->renderThemeInfo($p);
147				//	print_a($p);
148					exit;
149				}
150
151				$remotefile = $p['url'];
152
153				e107::getFile()->download($remotefile,'theme');
154				exit;
155
156			}
157		*/
158			// Theme Info Ajax
159			// FIXME  addd action=preview to the url, remove this block
160			if(!empty($_GET['id']))
161			{
162				$tm = (string) $_GET['id'];
163				$data = $themec->getThemeInfo($tm);
164				echo $themec->renderThemeInfo($data);
165			}
166
167			require_once(e_ADMIN."footer.php");
168			exit;
169
170		}
171
172
173
174
175}
176
177
178
179class theme_admin_ui extends e_admin_ui
180{
181		// required
182		protected $pluginTitle      = TPVLAN_26;
183		protected $pluginName       = 'core';
184		protected $table            = false;
185		protected $listQry          = false;
186		protected $pid              = "id";
187		protected $perPage          = 10;
188		protected $batchDelete      = false;
189
190	//	protected \$sortField		= 'somefield_order';
191	//	protected \$sortParent      = 'somefield_parent';
192	//	protected \$treePrefix      = 'somefield_title';
193		protected $grid             = array('price'=>'price', 'version'=>'version','title'=>'name', 'image'=>'thumbnail',  'body'=>'',  'class'=>'col-md-2 col-sm-3', 'perPage'=>12, 'carousel'=>true, 'toggleButton'=>false);
194
195
196    	protected  $fields = array(
197			'checkboxes'				=> array('title'=> '', 					'type' => null,			'data' => null,			'width'=>'5%', 		'thclass' =>'center', 'forced'=> TRUE,  'class'=>'center', 'toggle' => 'e-multiselect'),
198			'id'					    => array('title'=> LAN_ID, 				'type' => 'number',		'data' => 'int',		'width'=>'5%',		'thclass' => '',  'class'=>'center',	'forced'=> TRUE, 'primary'=>TRUE/*, 'noedit'=>TRUE*/), //Primary ID is not editable
199           	'name'				        => array('title'=> LAN_TITLE, 			'type' => 'text',		'data' => 'str',		'width'=>'5%',		'thclass' => '',	'forced'=> TRUE, 'primary'=>TRUE/*, 'noedit'=>TRUE*/), //Primary ID is not editable
200            'thumbnail'	   			    => array('title'=> LAN_IMAGE, 			'type' => 'image',      'readParms'=>array('thumb'=>1,'w'=>300,'h'=>169,'crop'=>1, 'link'=>false, 'fallback'=>'{e_IMAGE}admin_images/nopreview.png'),	'data' => 'str',		'width'=>'auto',	'thclass' => '', 'batch' => TRUE, 'filter'=>TRUE),
201			'folder' 				    => array('title'=> 'Folder', 			'type' => 'text', 		'data' => 'str',		'width' => 'auto',	'thclass' => ''),
202			'category' 				    => array('title'=> LAN_CATEGORY, 				'type' => 'text', 		'data' => 'str',		'width' => 'auto',	'thclass' => ''),
203			'version' 			        => array('title'=> 'Version',			'type' => 'text', 		'data' => 'str',		'width' => 'auto',	'thclass' => ''),
204			'price' 				    => array('title'=> LAN_AUTHOR,			'type' => 'method', 		'data' => 'str',		'width' => 'auto',	'thclass' => 'left'),
205     //    	'blank_authorURL' 			=> array('title'=> "Url", 				'type' => 'url', 		'data' => 'str',		'width' => 'auto',	'thclass' => 'left'),
206     //       'blank_date' 				=> array('title'=> LAN_DATE, 			'type' => 'datestamp', 	'data' => 'int',		'width' => 'auto',	'thclass' => '', 'readParms' => 'long', 'writeParms' => 'type=datetime'),
207	//		'blank_compatibility' 		=> array('title'=> 'Compatible',			'type' => 'text', 		'data' => 'str',		'width' => '10%',	'thclass' => 'center' ),
208		//	'blank_url' 				=> array('title'=> LAN_URL,		'type' => 'file', 		'data' => 'str',		'width' => '20%',	'thclass' => 'center',	'batch' => TRUE, 'filter'=>TRUE, 'parms' => 'truncate=30', 'validate' => false, 'help' => 'Enter blank URL here', 'error' => 'please, ener valid URL'),
209	//		'test_list_1'				=> array('title'=> 'test 1',			'type' => 'boolean', 		'data' => 'int',		'width' => '5%',	'thclass' => 'center',	'batch' => TRUE, 'filter'=>TRUE, 'noedit' => true),
210			'options' 					=> array('title'=> LAN_OPTIONS, 		'type' => 'method', 		'data' => null,			'width' => '10%',	'thclass' => 'center last', 'class' => 'center last', 'forced'=>TRUE)
211		);
212
213		//required - default column user prefs
214	//	protected $fieldpref = array('checkboxes', 'blank_id', 'blank_type', 'blank_url', 'blank_compatibility', 'options');
215
216		// optional, if $pluginName == 'core', core prefs will be used, else e107::getPluginConfig($pluginName);
217		protected $prefs = array();
218
219		protected $themeObj;
220
221		public function __construct($request,$response,$params=array())
222		{
223			require_once(e_HANDLER."theme_handler.php");
224			$this->themeObj = new themeHandler; // handles POSTed data.
225			parent::__construct($request,$response,$params);
226		}
227
228		// optional
229		public function init()
230		{
231
232			e107::css('inline', '
233
234
235				.admin-ui-grid .price {
236				position: absolute;
237			/*	bottom: 68px;*/
238				top:0;
239				right: 18px;
240				}
241
242				.overlay-title { padding-bottom:7px }
243
244			');
245
246
247
248
249			$this->themeObj ->postObserver();
250
251				$this->grid['template'] = '
252
253				 <div class="panel panel-primary">
254					<div class="e-overlay" >{IMAGE}
255						<div class="e-overlay-content">
256						<div class="overlay-title">{TITLE} v{VERSION}</div>
257						{OPTIONS}
258						</div>
259					</div>
260					<div class="panel-footer"><small>{TITLE}</small>{PRICE}</div>
261				</div>
262
263
264				';
265		}
266
267		public function _setTreeModel()
268		{
269			if($this->getAction() === 'online')
270			{
271				$this->_tree_model = new theme_admin_online_tree_model;
272			}
273			else
274			{
275				$this->_tree_model = new theme_admin_tree_model;// new theme_model_admin_tree();
276			}
277
278			return $this;
279		}
280
281		public function ChooseObserver() // action = choose
282		{
283			$mes = e107::getMessage();
284			$tp = e107::getParser();
285
286			if(!empty($_POST['selectmain']))
287			{
288				$id = key($_POST['selectmain']);
289				$message = $tp->lanVars(TPVLAN_94,$id);
290
291				if($this->themeObj->setTheme($id))
292				{
293					$mes->addSuccess($message);
294
295					// clear infopanel in admin dashboard.
296					e107::getCache()->clear('Infopanel_theme', true);
297					e107::getSession()->clear('addons-update-status');
298					e107::getSession()->set('addons-update-checked',false); // set to recheck it.
299				}
300				else
301				{
302					$mes->addError($message);
303				}
304			}
305
306
307
308
309			$param = array();
310			$this->perPage = 0;
311			$param['limitFrom'] = (int) $this->getQuery('from', 0);
312			$param['limitTo']   = 0 ; // (int) $this->getPerPage();
313			$param['searchqry'] = $this->getQuery('searchquery', '');
314
315			$this->getTreeModel()->setParams($param)->loadBatch(); // load the tree model above from the class below.
316		}
317
318		public function OnlineObserver()
319		{
320			$this->ChooseObserver();
321		}
322
323		public function ChooseAjaxObserver()
324		{
325			$this->ChooseObserver();
326		}
327
328		public function MainPage()
329		{
330			if(empty($_POST) && deftrue('e_DEVELOPER') || deftrue('e_DEBUG')) // check for new theme media and import.
331			{
332				$name = e107::getPref('sitetheme');
333				e107::getMedia()->import('_common_image', e_THEME.$name, '', 'min-size=10000');
334				e107::getMessage()->addInfo('Developer/Debug Mode: Scanning theme images folder for new media to import.');
335			}
336
337			$message = e107::getMessage()->render();
338			return $message.$this->renderThemeConfig('front');
339		}
340
341		public function AdminPage()
342		{
343			return $this->renderThemeConfig('admin');
344		}
345
346		private function search($name, $searchVal, $submitName, $filterName='', $filterArray=false, $filterVal=false)
347		{
348			$frm = e107::getForm();
349
350			return $frm->search($name, $searchVal, $submitName, $filterName, $filterArray, $filterVal);
351
352		}
353
354		public function OnlinePageOld()
355		{
356			global $e107SiteUsername, $e107SiteUserpass;
357			$xml 	= e107::getXml();
358			$mes 	= e107::getMessage();
359			$frm 	= e107::getForm();
360
361			require_once(e_HANDLER.'e_marketplace.php');
362
363			$mp 	= new e_marketplace(); // autodetect the best method
364			$from 	= intval(varset($_GET['frm']));
365			$limit 	= 96; // FIXME - ajax pages load
366			$srch 	= preg_replace('/[^\w]/','', vartrue($_GET['srch']));
367
368			// check for cURL
369			if(!function_exists('curl_init'))
370			{
371				$mes->addWarning(TPVLAN_79);
372			}
373
374			// auth
375			$mp->generateAuthKey($e107SiteUsername, $e107SiteUserpass);
376
377			// do the request, retrieve and parse data
378			$xdata = $mp->call('getList', array(
379				'type' => 'theme',
380				'params' => array('limit' => $limit, 'search' => $srch, 'from' => $from)
381			));
382			$total = $xdata['params']['count'];
383
384
385
386			$amount =$limit;
387
388
389			$c = 1;
390
391		/*	$text = "<form class='form-search' action='".e_SELF."?".e_QUERY."' id='core-plugin-list-form' method='get'>";
392			$text .= '<div id="myCarousel"  class="carousel slide" data-interval="false">';
393			$text .= "<div class='form-inline clearfix row-fluid'>";
394			$text .= $this->search('srch', $srch, 'go', $filterName, $filterArray, $filterVal).$frm->hidden('mode','online');
395			$text .= '<div class="btn-group" style="margin-left:10px"><a class="btn btn-primary" href="#myCarousel" data-slide="prev">&lsaquo;</a><a class="btn btn-primary" href="#myCarousel" data-slide="next">&rsaquo;</a></div>';
396			$text .= "{CAROUSEL_INDICATORS}";
397			$text .= "</div>";
398			$text .= '<div id="shop" style="margin-top:10px;min-height:585px" class=" carousel-inner">';*/
399
400			if(is_array($xdata['data'] ))
401			{
402
403				$text = '<div  class="active item">';
404
405				$slides = array();
406
407				foreach($xdata['data'] as $r)
408				{
409					if(E107_DBG_PATH)
410					{
411						$mes->addDebug(print_a($r,true));
412					}
413
414					$theme = array(
415						'id'			=> $r['params']['id'],
416						'type'			=> 'theme',
417						'mode'			=> $r['params']['mode'],
418						'name'			=> stripslashes($r['name']),
419						'category'		=> $r['category'],
420						'preview' 		=> varset($r['screenshots']['image']),
421						'date'			=> $r['date'],
422						'version'		=> $r['version'],
423						'thumbnail'		=> $r['thumbnail'],
424						'url'			=> $r['urlView'],
425						'author'		=> $r['author'],
426						'website'		=> $r['authorUrl'],
427						'compatibility'	=> $r['compatibility'],
428						'description'	=> $r['description'],
429						'price'			=> $r['price'],
430						'livedemo'		=> $r['livedemo'],
431					);
432
433
434					$text .= $this->themeObj->renderTheme(FALSE, $theme);
435
436					$c++;
437
438					if($c == 19)
439					{
440						$text .= '</div><div class="item">';
441						$slides[] = 1;
442						$c = 1;
443					}
444
445				}
446
447
448				$text .= "<div class='clear'>&nbsp;</div>";
449				$text .= "</div>";
450				$text .= "</div>";
451			}
452			else
453			{
454				$mes->addInfo(TPVLAN_80);
455			}
456
457			 $indicators = '<ol class="carousel-indicators col-md-6 span6">
458				<li data-target="#myCarousel" data-slide-to="0" class="active"></li>';
459
460			foreach($slides as $key=>$v)
461			{
462				$id = $key + 1;
463				$indicators .= '<li data-target="#myCarousel" data-slide-to="'.$id.'"></li>';
464			}
465
466			$indicators .=	'</ol>';
467
468			$text = str_replace("{CAROUSEL_INDICATORS}",$indicators,$text);
469
470			$text .= "</form>";
471
472			return $text;
473		}
474
475
476		public function InfoPage()
477		{
478			if(!empty($_GET['src'])) // online mode.
479			{
480				$string =  base64_decode($_GET['src']);
481				parse_str($string,$p);
482				$themeInfo = e107::getSession()->get('thememanager/online/'.intval($p['id']));
483				return $this->themeObj->renderThemeInfo($themeInfo);
484			}
485
486
487			if(empty($_GET['id']))
488			{
489				echo "invalid URL";
490				return null;
491			}
492
493			$tm = (string) $this->getId();
494			$themeMeta  = e107::getTheme($tm)->get();
495			echo $this->themeObj->renderThemeInfo($themeMeta);
496
497		}
498
499		public function DownloadPage()
500		{
501			$frm = e107::getForm();
502			$mes = e107::getMessage();
503			$string =  base64_decode($_GET['src']);
504			parse_str($string, $data);
505
506			if(!empty($data['price']))
507			{
508				e107::getRedirect()->go($data['url']);
509				return true;
510			}
511
512			if(deftrue('e_DEBUG_MARKETPLACE'))
513			{
514				echo "<b>DEBUG MODE ACTIVE (no downloading)</b><br />";
515				echo '$_GET: ';
516				print_a($_GET);
517
518				echo 'base64 decoded and parsed as $data:';
519				print_a($data);
520				return false;
521			}
522
523			require_once(e_HANDLER.'e_marketplace.php');
524
525			$mp 	= new e_marketplace(); // autodetect the best method
526
527		    $mes->addSuccess(TPVLAN_85);
528
529			if($mp->download($data['id'], $data['mode'], 'theme')) // download and unzip theme.
530			{
531				// Auto install?
532			//	$text = e107::getPlugin()->install($data['plugin_folder']);
533			//	$mes->addInfo($text);
534
535				e107::getTheme()->clearCache();
536				return $mes->render('default', 'success');
537			}
538			else
539			{
540				return $mes->addError('Unable to continue')->render('default', 'error');
541			}
542
543			/*echo $mes->render('default', 'debug');
544				echo "download page";*/
545
546
547		}
548
549		public function UploadPage()
550		{
551
552			$frm = e107::getForm();
553
554			if(!is_writable(e_THEME))
555			{
556				return e107::getMessage()->addWarning(TPVLAN_15)->render();
557			}
558			else
559			{
560				require_once(e_HANDLER.'upload_handler.php');
561				$max_file_size = get_user_max_upload();
562
563				$text = "
564				<form enctype='multipart/form-data' action='".e_SELF."' method='post'>
565					<table class='table adminform'>
566						<colgroup>
567							<col class='col-label' />
568							<col class='col-control' />
569						</colgroup>
570					<tr>
571						<td>".TPVLAN_13."</td>
572						<td>
573							<input type='hidden' name='MAX_FILE_SIZE' value='{$max_file_size}' />
574							<input type='hidden' name='ac' value='".md5(ADMINPWCHANGE)."' />
575							<input class='tbox' type='file' name='file_userfile[]' size='50' />
576						</td>
577					</tr>
578	                <tr>
579						<td>".TPVLAN_10."</td>
580						<td><input type='checkbox' name='setUploadTheme' value='1' /></td>
581					</tr>
582					</table>
583
584				<div class='buttons-bar center'>".$frm->admin_button('upload', 1, 'submit', LAN_UPLOAD)."</div>
585				</form>
586				";
587			}
588
589			return $text;
590
591		}
592
593
594		/**
595		 * Check theme.php code for methods incompatible with PHP7.
596		 * @param $code
597		 * @return bool
598		 */
599		private function containsErrors($code)
600		{
601			if(PHP_MAJOR_VERSION < 6)
602			{
603				return false;
604			}
605
606			$dep = array('call_user_method(', 'call_user_method_array(', 'define_syslog_variables', 'ereg(','ereg_replace(',
607			'eregi(', 'eregi_replace(', 'set_magic_quotes_runtime(', 'magic_quotes_runtime(', 'session_register(', 'session_unregister(', 'session_is_registered(',
608			'set_socket_blocking(', 'split(', 'spliti(', 'sql_regcase(', 'mysql_db_query(', 'mysql_escape_string(');
609
610			foreach($dep as $test)
611			{
612				if(strpos($code, $test) !== false)
613				{
614					e107::getMessage()->addDebug("Incompatible function <b>".rtrim($test,"(")."</b> found in theme.php");
615					return true;
616				}
617
618			}
619
620			return false;
621
622		}
623
624
625
626
627		private function renderThemeConfig($type = 'front')
628		{
629			$frm = e107::getForm();
630			$themeMeta  = e107::getTheme($type)->get();
631
632			$themeFileContent = file_get_contents(e_THEME.$themeMeta['path']."/theme.php");
633
634
635			if($this->containsErrors($themeFileContent))
636			{
637				e107::getMessage()->setTitle("Incompatibility Detected", E_MESSAGE_ERROR)->addError("This theme is not compatible with your version of PHP.");
638			}
639
640			$this->addTitle("<span class='text-warning'>".$themeMeta['name']."</span>");
641
642			$mode = ($type == 'front') ? 1 : 2;
643
644			$text = $frm->open($type.'-form', 'post');
645			$text .= $this->themeObj->renderTheme($mode, $themeMeta);
646			$text .= $frm->close();
647
648			return $text;
649		}
650
651
652		public function ChoosePage()
653		{
654			return $this->GridPage();
655		}
656
657		public function ChooseAjaxPage()
658		{
659			return $this->GridAjaxPage();
660		}
661
662		public function OnlinePage()
663		{
664
665			if(!function_exists('curl_init'))
666			{
667				e107::getMessage()->addWarning(TPVLAN_79);
668			}
669
670			return $this->GridPage();
671		}
672
673		public function OnlineAjaxPage()
674		{
675			return $this->GridAjaxPage();
676		}
677
678
679		public function renderHelp()
680		{
681
682			$tp = e107::getParser();
683
684			$type= $this->getMode()."/".$this->getAction();
685
686			switch($type)
687			{
688				case "main/main":
689					$text = "<b>".TPVLAN_56."</b><br />"; // Visbility Filter
690					$text .= "<br />".$tp->toHTML(TPVLANHELP_03,true);
691					$text .= "<ul style='padding-left:10px;margin-top:10px'><li>".$tp->toHTML(TPVLANHELP_04,true)."</li>";
692					$text .= "<li>".$tp->toHTML(TPVLANHELP_05,true)."</li></ul>";
693					break;
694
695				case "label2":
696					//  code
697					break;
698
699				default:
700					$text = TPVLANHELP_01."<br /><br />".TPVLANHELP_02;
701			}
702
703
704
705
706			return array('caption'=>LAN_HELP, 'text'=>$text);
707
708
709
710
711		}
712
713
714}
715
716
717class theme_admin_tree_model extends e_tree_model
718{
719
720	/**
721	 * Load data from theme meta file.
722	 * @param bool $force
723	 */
724	function loadBatch($force=false)
725	{
726		$themeList  = e107::getTheme()->getList();
727		$newArray   = array();
728		$parms      = $this->getParams();
729		$siteTheme  = e107::getPref('sitetheme');
730
731		if($parms['limitFrom'] == 0 && empty($parms['searchqry'])) // place the sitetheme first.
732		{
733
734			$newArray[] = $themeList[$siteTheme];
735		}
736
737		foreach($themeList as $k=>$v)
738		{
739
740			if(!empty($parms['searchqry']) && stripos($v['description'],$parms['searchqry']) === false && stripos($v['folder'],$parms['searchqry']) === false && stripos($v['name'],$parms['searchqry']) === false)
741			{
742				continue;
743			}
744
745			if($v['path'] == $siteTheme)
746			{
747				continue;
748			}
749
750			$newArray[] = $v;
751		}
752
753		if(!empty($parms['limitTo']) && empty($parms['searchqry']))
754		{
755			$arr = array_slice($newArray, $parms['limitFrom'], $parms['limitTo']);
756		}
757		else
758		{
759			$arr = $newArray;
760		}
761
762
763		foreach($arr as $k=>$v)
764		{
765
766			$v['id'] = $k;
767
768			$v['thumbnail'] = !empty($v['thumbnail']) ? '{e_THEME}'.$v['path'].'/'.$v['thumbnail'] : null;
769			$tmp = new e_model($v);
770			$this->setNode($k,$tmp);
771
772		}
773
774		$this->setTotal(count($newArray));
775	}
776
777
778}
779
780
781
782class theme_admin_online_tree_model extends e_tree_model
783{
784
785	/**
786	 * Load data from theme meta file.
787	 * @param bool $force
788	 */
789	function loadBatch($force=false)
790	{
791		$themeList  = e107::getTheme()->getList();
792
793		$parms      = $this->getParams();
794
795		$mes 	= e107::getMessage();
796		require_once(e_HANDLER.'e_marketplace.php');
797
798		$mp 	= new e_marketplace(); // autodetect the best method
799		$from 	= intval(varset($_GET['frm']));
800		$limit 	= 96; // FIXME - ajax pages load
801		$srch 	= preg_replace('/[^\w]/','', vartrue($_GET['srch']));
802
803		// do the request, retrieve and parse data
804		$xdata = $mp->call('getList', array(
805				'type' => 'theme',
806				'params' => array('limit' => $limit, 'search' => $srch, 'from' => $from)
807			));
808
809		$total = $xdata['params']['count'];
810
811		$c = 0;
812		if(is_array($xdata['data'] ))
813		{
814
815			foreach($xdata['data'] as $r)
816			{
817				if(E107_DBG_PATH)
818				{
819					$mes->addDebug(print_a($r,true));
820				}
821
822				$v = array(
823						'id'			=> $r['params']['id'],
824						'type'			=> 'theme',
825						'mode'			=> $r['params']['mode'],
826						'name'			=> stripslashes($r['name']),
827						'category'		=> $r['category'],
828						'preview' 		=> varset($r['screenshots']['image']),
829						'date'			=> $r['date'],
830						'version'		=> $r['version'],
831						'thumbnail'		=> $r['thumbnail'],
832						'url'			=> $r['urlView'],
833						'author'		=> $r['author'],
834						'website'		=> $r['authorUrl'],
835						'compatibility'	=> $r['compatibility'],
836						'description'	=> $r['description'],
837						'price'			=> $r['price'],
838						'livedemo'		=> $r['livedemo'],
839					);
840
841
842				$c++;
843				$tmp = new e_model($v);
844				$this->setNode($r['params']['id'],$tmp);
845
846			}
847		}
848
849/*
850		foreach($themeList as $k=>$v)
851		{
852
853			$v['id'] = $k;
854
855			$v['thumbnail'] = !empty($v['thumbnail']) ? '{e_THEME}'.$v['path'].'/'.$v['thumbnail'] : null;
856			$tmp = new e_model($v);
857			$this->setNode($k,$tmp);
858
859		}*/
860
861		$this->setTotal($c);
862	}
863
864
865}
866
867
868
869
870
871
872class theme_admin_form_ui extends e_admin_form_ui
873{
874
875
876
877	function price($curVal)
878	{
879		if($this->getController()->getAction() == 'choose')
880		{
881			$sitetheme = e107::getPref('sitetheme');
882			$path = $this->getController()->getListModel()->get('path');
883
884			if($sitetheme == $path)
885			{
886				return "<span class='pull-right text-warning'><i class='fa fa-home'></i></span>";
887			}
888
889			return '';
890		}
891
892		$text =(!empty($curVal)) ? "<span class='label label-primary'><i class='icon-shopping-cart icon-white'></i> ".$curVal."</span>" : "<span class='label label-success'>".TPVLAN_76."</span>";
893
894		return '<span class="price pull-right">'.$text.'</span>';
895	}
896
897
898
899	function renderFilter($current_query = array(), $location = '', $input_options = array())
900	{
901		if($this->getController()->getAction() == 'choose')
902		{
903			return parent::renderFilter($current_query,$location,$input_options);
904		}
905		//	print_a($text);
906
907	//	return $text;
908			$text = "<form class='form-search' action='".e_SELF."' id='core-plugin-list-form' method='get'>
909			<fieldset id='admin-ui-list-filter' class='e-filter'>
910			<div class='col-md-12'>";
911		//	$text .= '<div id="myCarousel"  class="carousel slide" data-interval="false">';
912			$text .= "<div class='form-inline clearfix row-fluid'>";
913			$text .= $this->search('srch', $_GET['srch'], 'go'/*, $filterName, $filterArray, $filterVal*/);
914
915			$gets = $this->getController()->getQuery();
916
917			foreach($gets as $k=>$v)
918			{
919				if($k == 'srch' || $k == 'go')
920				{
921					continue;
922				}
923				$text .= $this->hidden($k,$v);
924			}
925
926			$text .= $this->renderPagination();
927			$text .= "</div>
928					</div></fieldset></form>";
929
930		return $text;
931	}
932
933	function options()
934	{
935
936		$theme = $this->getController()->getListModel()->getData();
937
938		if($this->getController()->getAction() === 'online')
939		{
940			return $this->onlineOptions($theme);
941		}
942		else
943		{
944			return $this->chooseOptions($theme);
945
946		}
947
948	}
949
950	private function chooseOptions($theme)
951	{
952		$pref = e107::getPref();
953		$tp = e107::getParser();
954
955		$infoPath       = e_SELF."?mode=".$_GET['mode']."&id=".$theme['path']."&action=info&iframe=1";
956		$previewPath    = $tp->replaceConstants($theme['thumbnail'],'abs');
957
958		$version = $tp->filter(e_VERSION,'version');
959		$compat = $tp->filter($theme['compatibility'], 'version');
960
961		$disabled = '';
962		$mainTitle = TPVLAN_10;
963
964		if(version_compare($compat,$version, '<=') === false)
965		{
966			$disabled = 'disabled';
967			$mainTitle = defset('TPVLAN_97', "This theme requires a newer version of e107.");
968		}
969
970	//	e107::getDebug()->log($theme['path']." - ".$disabled. "  (".$compat.")");
971
972		$main_icon 		= ($pref['sitetheme'] != $theme['path']) ? "<button class='btn btn-default btn-secondary btn-small btn-sm btn-inverse' type='submit' ".$disabled."   name='selectmain[".$theme['path']."]' alt=\"".$mainTitle."\" title=\"".$mainTitle."\" >".$tp->toGlyph('fa-home',array('size'=>'2x'))."</button>" : "<button class='btn btn-small btn-default btn-secondary btn-sm btn-inverse' type='button'>".$tp->toGlyph('fa-check',array('size'=>'2x'))."</button>";
973		$info_icon 		= "<a class='btn btn-default btn-secondary btn-small btn-sm btn-inverse e-modal'  data-modal-caption=\"".$theme['name']." ".$theme['version']."\" href='".$infoPath."'  title='".TPVLAN_7."'>".$tp->toGlyph('fa-info-circle',array('size'=>'2x'))."</a>";
974	//	$admin_icon 	= ($pref['admintheme'] != $theme['path'] ) ? "<button class='btn btn-default btn-small btn-sm btn-inverse' type='submit'   name='selectadmin[".$theme['id']."]' alt=\"".TPVLAN_32."\" title=\"".TPVLAN_32."\" >".$tp->toGlyph('fa-gears',array('size'=>'2x'))."</button>" : "<button class='btn btn-small btn-default btn-sm btn-inverse' type='button'>".$tp->toGlyph('fa-check',array('size'=>'2x'))."</button>";
975
976		$preview_icon 	= "<a class='e-modal btn btn-default btn-secondary btn-sm btn-small btn-inverse' title=' ".TPVLAN_70." ".$theme['name']."' data-modal-caption=\"".$theme['name']." ".$theme['version']."\" rel='external'  href='".$previewPath."'>".$tp->toGlyph('fa-search',array('size'=>'2x'))."</a>";
977
978		return $main_icon.$info_icon.$preview_icon;
979	}
980
981
982	private function onlineOptions($theme)
983	{
984		$tp = e107::getParser();
985		$preview_icon = '';
986
987		$srcData = array(
988				'id'    => $theme['id'],
989				'url'   => $theme['url'],
990				'mode'  => $theme['mode'],
991				'price' => $theme['price']
992		);
993
994		e107::getSession()->set('thememanager/online/'.$theme['id'], $theme);
995
996		$d = http_build_query($srcData,false,'&');
997		$base64 = base64_encode($d);
998
999		$id = $this->name2id($theme['name']);
1000
1001		if(!empty($theme['price'])) // Premium Theme
1002		{
1003			$LAN_DOWNLOAD = LAN_PURCHASE."/".LAN_DOWNLOAD;
1004			$downloadUrl = e_SELF.'?mode=main&action=download&src='.base64_encode($d); // no iframe.
1005			$mainTarget = '_blank';
1006			$mainClass = '';
1007			$modalCaption = ' '.LAN_PURCHASE.' '.$theme['name']." ".$theme['version'];
1008		}
1009		else // Free Theme
1010		{
1011			$LAN_DOWNLOAD = LAN_DOWNLOAD;
1012			$downloadUrl = e_SELF.'?mode=main&iframe=1&action=download&src='.base64_encode($d);//$url.'&amp;action=download';
1013			$mainTarget = '_self';
1014			$mainClass = 'e-modal';
1015			$modalCaption =  ' '.LAN_DOWNLOADING.' '.$theme['name']." ".$theme['version'];
1016		}
1017
1018	//	$url = e_SELF."?src=".$base64;
1019		$infoUrl = e_SELF.'?mode=main&iframe=1&action=info&src='.$base64;
1020	//	$viewUrl = $theme['url'];
1021		$main_icon = "<a class='".$mainClass." btn-default btn-secondary btn btn-sm btn-small btn-inverse' target='".$mainTarget."' data-modal-caption=\"".$modalCaption."\"  href='{$downloadUrl}' data-cache='false' title='".$LAN_DOWNLOAD."' >".$tp->toGlyph('fa-download',array('size'=>'2x'))."</a>";
1022		$info_icon 	= "<a class='btn btn-default btn-secondary btn-sm btn-small btn-inverse e-modal' data-toggle='modal' data-modal-caption=\"".$theme['name']." ".$theme['version']."\" href='".$infoUrl."' data-cache='false'  title='".TPVLAN_7."'>".$tp->toGlyph('fa-info-circle',array('size'=>'2x'))."</a>";
1023
1024		if(!empty($theme['preview'][0]))
1025		{
1026			$previewPath = $theme['preview'][0];
1027
1028			if(!empty($theme['livedemo']))
1029			{
1030				$previewPath = $theme['livedemo'];
1031			}
1032
1033			$preview_icon 	= "<a class='e-modal btn btn-default btn-secondary btn-sm btn-small btn-inverse' title=' ".TPVLAN_70." ".$theme['name']."' data-modal-caption=\"".$theme['name']." ".$theme['version']."\" rel='external'  href='".$previewPath."'>".$tp->toGlyph('fa-search',array('size'=>'2x'))."</a>";
1034		}
1035
1036		return $main_icon.$info_icon.$preview_icon;
1037
1038	}
1039
1040}
1041
1042
1043
1044
1045
1046
1047class theme_builder extends e_admin_ui
1048{
1049	var $themeName = "";
1050	var $remove = array();
1051
1052		function init()
1053		{
1054
1055
1056
1057
1058
1059
1060		}
1061
1062		function MainPage()
1063		{
1064				$ns = e107::getRender();
1065			$tp = e107::getParser();
1066
1067			e107::getMessage()->addDebug("Disable debug to save generated files. ");
1068
1069
1070			$this->themeName = $tp->filter($_GET['newtheme'],'w');
1071
1072			if(!empty($_GET['src']))
1073			{
1074				$this->themeSrc = $tp->filter($_GET['src'],'w');
1075				$this->copyTheme();
1076			/*	$src = $tp->filter($_GET['src'],'w');
1077				$name = $tp->filter($_GET['f']);
1078				$title = $tp->filter($_GET['t']);
1079
1080				$this->copyTheme($src,$name,$title);*/
1081
1082			}
1083
1084
1085
1086			if(vartrue($_GET['step']) == 3)
1087			{
1088				return $this->step3();
1089
1090			}
1091
1092			if(vartrue($_GET['step']) == 2)
1093			{
1094				return $this->step2();
1095			}
1096			else
1097			{
1098				$ret = $this->step1();
1099				$ret2 = $this->copyThemeForm();
1100
1101				$tabs = array(
1102					0 => array('caption'=>$ret['caption'], 'text'=>$ret['text']),
1103					1 => array('caption'=>$ret2['caption'], 'text'=>$ret2['text']),
1104
1105				);
1106
1107				return e107::getForm()->tabs($tabs);
1108
1109				// $text = $ns->tablerender(ADLAN_140.SEP.ADLAN_CL_6,e107::getForm()->tabs($tabs));
1110			}
1111
1112
1113		}
1114
1115		function step1()
1116		{
1117
1118			$fl = e107::getFile();
1119			$frm = e107::getForm();
1120			$ns = e107::getRender();
1121			$mes = e107::getMessage();
1122
1123			$plugFolders = $fl->get_dirs(e_THEME);
1124			foreach($plugFolders as $dir)
1125			{
1126				if(file_exists(e_THEME.$dir."/theme.xml") || $dir == 'templates')
1127				{
1128					continue;
1129				}
1130				$newDir[$dir] = $dir;
1131			}
1132
1133			$mes->addInfo(' '.TPVLAN_64.' <br />
1134       '.TPVLAN_65.'
1135            <ul>
1136						<li> '.TPVLAN_66.'</li>
1137						<li> '.TPVLAN_67.'</li>
1138				</ul>
1139	');
1140
1141			$text = $frm->open('createPlugin','get',e_SELF."?mode=convert");
1142			$text .= "<table class='table adminform'>
1143						<colgroup>
1144							<col class='col-label' />
1145							<col class='col-control' />
1146						</colgroup>
1147						<tbody>
1148				<tr>
1149					<td> ".TPVLAN_68."</td>
1150					<td>".$frm->select("newtheme",$newDir)."</td>
1151				</tr>";
1152
1153				/*
1154				$text .= "
1155				<tr>
1156					<td>Create Files</td>
1157					<td>".$frm->checkbox('createFiles',1,1)."</td>
1158				</tr>";
1159				*/
1160
1161			$text .= "</tbody>
1162				</table>
1163				<div class='buttons-bar center'>
1164				".$frm->admin_button('step', 2,'other',LAN_GO)."
1165				</div>";
1166
1167			$text .= $frm->close();
1168
1169			return array('caption'=>TPVLAN_88, 'text'=>$mes->render() . $text);
1170
1171		//	$ns->tablerender(TPVLAN_26.SEP.TPVLAN_88.SEP. TPVLAN_CONV_1, $mes->render() . $text);
1172
1173		}
1174
1175		function step2()
1176		{
1177			$ns = e107::getRender();
1178			$mes = e107::getMessage();
1179			$frm = e107::getForm();
1180
1181
1182
1183
1184			$data = array(
1185				'main' 			=> array('name','lang','version','date', 'compatibility'),
1186			    'author' 		=> array('name','url'),
1187				'summary'		=> array('summary'),
1188				'description' 	=> array('description'),
1189
1190				'keywords' 		=> array('one','two'),
1191				'category'		=> array('category'),
1192				'livedemo'      => array('livedemo'),
1193				'copyright' 	=> array('copyright'),
1194				'stylesheets' 	=> array('stylesheets')
1195		//		'adminLinks'	=> array('url','description','icon','iconSmall','primary'),
1196		//		'sitelinks'		=> array('url','description','icon','iconSmall')
1197			);
1198
1199			$legacyFile = e_THEME.$this->themeName."/theme.php";
1200
1201
1202
1203			$newThemeXML = e_THEME.$this->themeName."/theme.xml";
1204			if(file_exists($newThemeXML))
1205			{
1206				$info = e107::getTheme()->getThemeInfo($this->themeName);
1207
1208				e107::getDebug()->log($info);
1209
1210				if($this->themeSrc) // New theme copied from another
1211				{
1212					$defaults = array(
1213						"main-name"				=> ucfirst($this->themeName),
1214						'category-category'     => vartrue($info['category']),
1215					);
1216				}
1217				else
1218				{
1219					$defaults = array(
1220						"main-name"					=> vartrue($info['name']),
1221						"main-date"                 => vartrue($info['date']),
1222						"main-version"				=> vartrue($info['version']),
1223						"author-name"				=> vartrue($info['author']),
1224						"author-url"				=> vartrue($info['website']),
1225						"description-description"	=> vartrue($info['description']),
1226						"summary-summary"			=> vartrue($info['summary']),
1227						'category-category'         => vartrue($info['category']),
1228				//		"custompages"				=> vartrue($leg['CUSTOMPAGES']),
1229					);
1230				}
1231
1232				if(!empty($info['keywords']['word']))
1233				{
1234					$defaults['keywords-one'] = $info['keywords']['word'][0];
1235					$defaults['keywords-two'] = $info['keywords']['word'][1];
1236				}
1237
1238			}
1239			elseif(file_exists($legacyFile))
1240			{
1241				$legacyData = file_get_contents($legacyFile);
1242
1243				$regex = '/\$([\w]*)\s*=\s*("|\')([\w @.\/:<\>,\'\[\] !()]*)("|\');/im';
1244				preg_match_all($regex, $legacyData, $matches);
1245
1246				$leg = array();
1247
1248				foreach($matches[1] as $i => $m)
1249				{
1250					$leg[$m] = strip_tags($matches[3][$i]);
1251					if(substr($m,0,5) == 'theme' || $m == "CUSTOMPAGES")
1252					{
1253						$search[] = $matches[0][$i];
1254					}
1255				}
1256
1257				$defaults = array(
1258					"main-name"					=> vartrue($leg['themename']),
1259					"author-name"				=> vartrue($leg['themeauthor']),
1260					"author-url"				=> vartrue($leg['themewebsite']),
1261					"description-description"	=> '',
1262					"summary-summary"			=> vartrue($leg['themeinfo']),
1263					"custompages"				=> vartrue($leg['CUSTOMPAGES']),
1264				);
1265
1266				$search[] = "Steve Dunstan";
1267				$search[] = "jalist@e107.org";
1268
1269				$_SESSION['themebulder-remove'] = $search;
1270
1271				$mes->addInfo("Loading theme.php file");
1272			}
1273
1274			$text = $frm->open('newtheme-step3','post', e_SELF.'?mode=convert&src='.$this->themeSrc.'&newtheme='.$this->themeName.'&step=3');
1275			$text .= "<table class='table adminlist'>";
1276			foreach($data as $key=>$val)
1277			{
1278				$text.= "<tr><td>$key</td><td>
1279				<div class='controls'>";
1280				foreach($val as $type)
1281				{
1282					$nm = $key.'-'.$type;
1283					$name = "xml[$nm]";
1284					$size = (count($val)==1) ? 'col-md-7' : 'col-md-2';
1285					$text .= "<div class='{$size}'>".$this->xmlInput($name, $key."-". $type, vartrue($defaults[$nm]))."</div>";
1286				}
1287
1288				$text .= "</div></td></tr>";
1289
1290
1291			}
1292
1293
1294			$text .= "</table>";
1295			$text .= "
1296			<div class='buttons-bar center'>"
1297			.$frm->hidden('newtheme', $this->themeName);
1298			$text .= $frm->hidden('xml[custompages]', trim(vartrue($leg['CUSTOMPAGES'])))
1299			.$frm->admin_button('step', 3,'other',LAN_GENERATE)."
1300			</div>";
1301
1302			$text .= $frm->close();
1303
1304		//	return array('caption'=>TPVLAN_88.SEP. TPVLAN_CONV_2, 'text'=>$mes->render() . $text);
1305			$this->addTitle(TPVLAN_CONV_2);
1306
1307			return $text;
1308
1309			//$ns->tablerender(TPVLAN_26.SEP.ADLAN_CL_6.SEP. TPVLAN_CONV_2, $mes->render() . $text);
1310		}
1311
1312
1313		function step3()
1314		{
1315			$ns = e107::getRender();
1316			$mes = e107::getMessage();
1317
1318		//	print_a($_POST);
1319			$text = '';
1320
1321			if(!empty($_POST['xml']))
1322			{
1323				$xmlText =	$this->createXml($_POST['xml']);
1324				$text = $mes->render(). "<pre>".$xmlText."</pre>";
1325			//	$ns->tablerender("theme.xml", $mes->render(). "<pre>".$xmlText."</pre>");
1326			}
1327
1328
1329			$legacyFile = e_THEME.$this->themeName."/theme.php";
1330			if(file_exists($legacyFile) && empty($this->themeSrc))
1331			{
1332				$legacyData = file_get_contents($legacyFile);
1333				$legacyData = e107::getTheme()->upgradeThemeCode($legacyData);
1334
1335				$output = nl2br(htmlentities($legacyData));
1336
1337				$text .= $output;
1338			//	$ns->tablerender("theme.php (updated)",  $output);
1339			}
1340
1341			return $text;
1342		}
1343
1344
1345
1346
1347		function createXml($data)
1348		{
1349			$ns = e107::getRender();
1350			$mes = e107::getMessage();
1351			$tp = e107::getParser();
1352
1353			foreach($data as $key=>$val)
1354			{
1355				$key = strtoupper(str_replace("-","_",$key));
1356				$newArray[$key] = $val;
1357			}
1358
1359			if(!empty($newArray['CUSTOMPAGES']))
1360			{
1361				$newArray['CUSTOMPAGES'] = trim($newArray['CUSTOMPAGES']);
1362				$LAYOUTS = "\n<layout name='custom' title='Custom'>\n";
1363				$LAYOUTS .= "			<custompages>{CUSTOMPAGES}</custompages>\n";
1364				$LAYOUTS .= "		</layout>";
1365			}
1366			else
1367			{
1368				$LAYOUTS = "";
1369			}
1370
1371			if(!empty($newArray['STYLESHEETS_STYLESHEETS']))
1372			{
1373				$STYLESHEETS = '';
1374				foreach($newArray['STYLESHEETS_STYLESHEETS'] as $val)
1375				{
1376					if(empty($val['file']))
1377					{
1378						continue;
1379					}
1380
1381					$STYLESHEETS .= "\t\t<css file=\"".$val['file']."\" name=\"".$val['name']."\" />\n";
1382				}
1383
1384				if(!empty($STYLESHEETS))
1385				{
1386					$STYLESHEETS = "\n\t<stylesheets>\n".$STYLESHEETS."\t</stylesheets>";
1387				}
1388
1389				unset($newArray['STYLESHEETS_STYLESHEETS']);
1390			}
1391			else
1392			{
1393				$STYLESHEETS = "";
1394			}
1395
1396			$newArray['STYLESHEETS'] = $STYLESHEETS;
1397
1398		//	print_a($newArray);
1399
1400
1401$template = <<<TEMPLATE
1402<?xml version="1.0" encoding="utf-8"?>
1403<e107Theme name="{MAIN_NAME}" lan="{MAIN_LANG}" version="{MAIN_VERSION}" date="{MAIN_DATE}" compatibility="{MAIN_COMPATIBILITY}" livedemo="{LIVEDEMO_LIVEDEMO}">
1404	<author name="{AUTHOR_NAME}" url="{AUTHOR_URL}" />
1405	<summary lan="">{SUMMARY_SUMMARY}</summary>
1406	<description lan="">{DESCRIPTION_DESCRIPTION}</description>
1407	<category>{CATEGORY_CATEGORY}</category>
1408	<keywords>
1409		<word>{KEYWORDS_ONE}</word>
1410		<word>{KEYWORDS_TWO}</word>
1411	</keywords>
1412	<copyright>{COPYRIGHT_COPYRIGHT}</copyright>
1413	<screenshots>
1414		<image>preview.jpg</image>
1415		<image>fullpreview.jpg</image>
1416	</screenshots>{STYLESHEETS}
1417	<layouts>
1418		<layout name='default' title='Default' default='true' />{LAYOUTS}
1419	</layouts>
1420</e107Theme>
1421TEMPLATE;
1422
1423
1424			$template = str_replace("{LAYOUTS}",$LAYOUTS, $template);
1425
1426			$result = e107::getParser()->simpleParse($template, $newArray);
1427			$path = e_THEME.$this->themeName."/theme.xml";
1428
1429
1430			if(E107_DEBUG_LEVEL > 0)
1431			{
1432				$mes->addDebug("Debug Mode active - no file saved. ");
1433				return  htmlentities($result);
1434			}
1435
1436
1437
1438			if(file_put_contents($path,$result))
1439			{
1440				$mes->addSuccess("Saved: ".$path);
1441			}
1442			else
1443			{
1444				$mes->addError("Couldn't Save: ".$path);
1445			}
1446
1447
1448
1449			return  htmlentities($result);
1450
1451
1452		}
1453
1454
1455
1456		function xmlInput($name, $info, $default='')
1457		{
1458			$frm = e107::getForm();
1459			list($cat,$type) = explode("-",$info);
1460
1461			$size 		= 30;
1462			$help		= '';
1463			$sizex      = '';
1464
1465			switch ($info)
1466			{
1467
1468				case 'main-name':
1469					$help 		= TPVLAN_CONV_3;
1470					$required 	= true;
1471					$pattern 	= "[A-Za-z 0-9]*";
1472				break;
1473
1474				case 'main-lang':
1475					$help 		= TPVLAN_CONV_4;
1476					$required 	= false;
1477					$placeholder= "LAN equivalent";
1478					$pattern 	= "[A-Z0-9_]*";
1479				break;
1480
1481				case 'main-date':
1482					$help 		= TPVLAN_CONV_6;
1483					$required 	= true;
1484					$default = (empty($default)) ? time() : strtotime($default);
1485				break;
1486
1487				case 'main-version':
1488					$default 	= '1.0';
1489					$required 	= true;
1490					$help 		= TPVLAN_CONV_5;
1491					$pattern	= "^[\d]{1,2}\.[\d]{1,2}$";
1492				break;
1493
1494				case 'main-compatibility':
1495					$default 	= '2.0';
1496					$required 	= true;
1497					$help 		= TPVLAN_CONV_7;
1498					$pattern	= "^[\d]{1,2}\.[\d]{1,2}$";
1499				break;
1500
1501				case 'author-name':
1502					$default 	= (vartrue($default)) ? $default : USERNAME;
1503					$required 	= true;
1504					$help 		= TPVLAN_CONV_8;
1505					$pattern	= "[A-Za-z \.0-9]*";
1506				break;
1507
1508				case 'author-url':
1509					$required 	= true;
1510					$help 		= TPVLAN_CONV_9;
1511				//	$pattern	= "https?://.+";
1512				break;
1513
1514				case 'livedemo-livedemo':
1515					$required 	= false;
1516					$help 		= TPVLAN_CONV_16;
1517					$placeholder= "http://demo-of-my-theme.com";
1518				//	$pattern	= "https?://.+";
1519				break;
1520
1521				//case 'main-installRequired':
1522				//	return "Installation required: ".$frm->radio_switch($name,'',LAN_YES, LAN_NO);
1523				//break;
1524
1525				case 'summary-summary':
1526					$help 		= TPVLAN_CONV_10;
1527					$required 	= true;
1528					$size 		= 200;
1529					$placeholder= " ";
1530					$pattern	= "[A-Za-z,() \.0-9]*";
1531				break;
1532
1533				case 'keywords-one':
1534				case 'keywords-two':
1535					$help 		= TPVLAN_CONV_11;
1536					$required 	= true;
1537					$size 		= 20;
1538					$placeholder= " ";
1539					$pattern 	= '^[a-z]*$';
1540				break;
1541
1542				case 'description-description':
1543					$help 		= TPVLAN_CONV_12;
1544					$required 	= true;
1545					$size 		= 100;
1546					$placeholder = " ";
1547					$pattern	= "[A-Za-z \.0-9]*";
1548				break;
1549
1550
1551				case 'category-category':
1552					$help 		= TPVLAN_CONV_13;
1553					$required 	= true;
1554					$size 		= 20;
1555				break;
1556
1557				default:
1558
1559				break;
1560			}
1561
1562			$req = ($required == true) ? "&required=1" : "";
1563			$placeholder = (varset($placeholder)) ? $placeholder : $type;
1564			$pat = ($pattern) ? "&pattern=".$pattern : "";
1565			$text = '';
1566
1567			switch ($type)
1568			{
1569
1570				case 'stylesheets':
1571					$fl = e107::getFile();
1572
1573					$fl->setMode('full');
1574					$stylesheets = $fl->get_files(e_THEME.$this->themeName."/", "\.css", null, 1);
1575					foreach($stylesheets as $key=>$path)
1576					{
1577						$file = str_replace(e_THEME.$this->themeName."/",'',$path);
1578						$text .= "<div class='row-fluid'>";
1579						$text .= "<div class='controls'>";
1580						$text .= "<div class='col-md-3'>".$frm->checkbox($name.'['.$key.'][file]',$file, false, array('label'=>$file))."
1581						<div class='field-help'>".TPVLAN_CONV_14."</div></div>";
1582						$text .= "<div class='col-md-3'>".$frm->text($name.'['.$key.'][name]', $default, $size, 'placeholder='.$file . $req. $pat)."
1583						<div class='field-help'>".TPVLAN_CONV_15."</div></div>";
1584					//	$text .= "<div class='span2'>".$frm->checkbox('css['.$key.'][file]',$file, false, array('label'=>$file))."</div>";
1585					//	$text .= "<div class='span2'>".$frm->text('css['.$key.'][name]', $default, $size, 'placeholder='.$placeholder . $req. $pat)."</div>";
1586						$text .= "</div>";
1587						$text .= "</div>";
1588					}
1589
1590
1591					return $text;
1592				break;
1593
1594
1595				case 'date':
1596					$text = $frm->datepicker($name, $default, 'format=yyyy-mm-dd'.$req.'&size=block-level');
1597				break;
1598
1599				case 'description':
1600					$text = $frm->textarea($name,$default, 3, 100, $req.'&size=block-level');	// pattern not supported.
1601				break;
1602
1603
1604				case 'category':
1605
1606				$allowedCategories = array(
1607					'generic', 'adult', 'blog', 'clan', 'children',
1608					'corporate', 'forum', 'gaming', 'gallery', 'news',
1609		 			'social', 'video', 'multimedia');
1610
1611				sort($allowedCategories);
1612
1613					$text = $frm->select($name, $allowedCategories,$default,'useValues=1&required=1', true);
1614				break;
1615
1616
1617				default:
1618					$text = $frm->text($name, $default, $size, 'placeholder='.$placeholder . $req. $pat.'&size=block-level');
1619				break;
1620			}
1621
1622
1623			$text .= ($help) ? "<span class='field-help'>".$help."</span>" : "";
1624			return $text;
1625
1626		}
1627
1628
1629
1630
1631
1632		function copyThemeForm()
1633		{
1634
1635			$frm = e107::getForm();
1636
1637			$list = e107::getTheme()->clearCache()->getThemeList(); // (e_THEME);
1638
1639			$folders = array_keys($list);
1640
1641			$text = $frm->open('copytheme','get','theme.php?mode=convert');
1642			$text .= "<table class='table adminform'>
1643						<colgroup>
1644							<col class='col-label' />
1645							<col class='col-control' />
1646						</colgroup>
1647				<tr>
1648					<td>".TPVLAN_91."</td>
1649					<td>".$frm->select("src",$folders,'',array('useValues'=>1))."</td>
1650				</tr>
1651
1652				<tr>
1653					<td>".TPVLAN_92."</td>
1654					<td>".$frm->text("newtheme",'',25, array('pattern'=>'[a-z_0-9]*', 'required'=>1))."</td>
1655				</tr>
1656
1657				";
1658
1659				/*
1660				$text .= "
1661				<tr>
1662					<td>Create Files</td>
1663					<td>".$frm->checkbox('createFiles',1,1)."</td>
1664				</tr>";
1665				*/
1666
1667			$text .= "
1668				</table>
1669					<div class='buttons-bar center'>
1670				".$frm->admin_button('step', 2,'success', LAN_CREATE)."
1671				</div>";
1672
1673
1674
1675
1676				$text .= $frm->close();
1677
1678
1679		//	$text = "Create a new theme based on ".e->select('copytheme',$list);
1680
1681
1682			return array('caption'=>LAN_CREATE, 'text'=>$text);
1683
1684		}
1685
1686		private function copyTheme()
1687		{
1688			if(empty($this->themeSrc) || empty($this->themeName) || is_dir(e_THEME.$this->themeName))
1689			{
1690				return false;
1691			}
1692
1693			if(e107::getFile()->copy(e_THEME.$this->themeSrc, e_THEME.$this->themeName))
1694			{
1695				$newfiles = scandir(e_THEME.$this->themeName);
1696
1697				foreach($newfiles as $file)
1698				{
1699					if(is_dir(e_THEME.$this->themeName.'/'.$file) || $file === '.' || $file === '..')
1700					{
1701						continue;
1702					}
1703
1704					if(strpos($file,"admin_") === 0)
1705					{
1706						unlink(e_THEME.$this->themeName.'/'.$file);
1707					}
1708
1709
1710
1711				}
1712
1713			}
1714
1715			return null;
1716		}
1717
1718
1719
1720
1721}
1722
1723/*
1724 * After initialization we'll be able to call dispatcher via e107::getAdminUI()
1725 * so this is the first we should do on admin page.
1726 * Global instance variable is not needed.
1727 * NOTE: class is auto-loaded - see class2.php __autoload()
1728 */
1729/* $dispatcher = */
1730
1731new theme_admin();
1732
1733/*
1734 * Uncomment the below only if you disable the auto observing above
1735 * Example: $dispatcher = new theme_admin(null, null, false);
1736 */
1737//$dispatcher->runObservers(true);
1738
1739require_once(e_ADMIN."auth.php");
1740
1741/*
1742 * Send page content
1743 */
1744e107::getAdminUI()->runPage();
1745
1746
1747
1748
1749require_once(e_ADMIN."footer.php");
1750
1751/* OBSOLETE - see admin_shortcodes::sc_admin_menu()
1752function admin_config_adminmenu()
1753{
1754	//global $rp;
1755	//$rp->show_options();
1756	e107::getRegistry('admin/blank_dispatcher')->renderMenu();
1757}
1758*/
1759
1760/* OBSOLETE - done within header.php
1761function headerjs() // needed for the checkboxes - how can we remove the need to duplicate this code?
1762{
1763	return e107::getAdminUI()->getHeader();
1764}
1765*/
1766
1767