PageRenderTime 61ms CodeModel.GetById 28ms RepoModel.GetById 1ms app.codeStats 0ms

/e107_handlers/theme_handler.php

https://github.com/CasperGemini/e107
PHP | 2077 lines | 1347 code | 470 blank | 260 comment | 192 complexity | 307cc191a559014ec7713b91070e0cec MD5 | raw file
Possible License(s): GPL-2.0

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. /*
  3. * e107 website system
  4. *
  5. * Copyright (C) 2008-2013 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. * e107 Admin Theme Handler
  10. *
  11. */
  12. if(!defined('e107_INIT'))
  13. {
  14. exit;
  15. }
  16. class themeHandler
  17. {
  18. var $themeArray;
  19. var $action;
  20. var $id;
  21. var $frm;
  22. var $fl;
  23. var $themeConfigObj = null;
  24. var $noLog = FALSE;
  25. private $approvedAdminThemes = array('bootstrap','bootstrap3');
  26. public $allowedCategories = array('generic',
  27. 'adult',
  28. 'blog',
  29. 'clan',
  30. 'children',
  31. 'corporate',
  32. 'forum',
  33. 'gaming',
  34. 'gallery',
  35. 'news',
  36. 'social',
  37. 'video',
  38. 'multimedia');
  39. /**
  40. * Marketplace handler instance
  41. * @var e_marketplace
  42. */
  43. protected $mp;
  44. /* constructor */
  45. function __construct()
  46. {
  47. global $e107cache,$pref;
  48. $mes = e107::getMessage();
  49. require_once (e_HANDLER."form_handler.php");
  50. //enable inner tabindex counter
  51. $this->frm = new e_form();
  52. $this->fl = e107::getFile();
  53. if(isset($_POST['upload']))
  54. {
  55. $this->themeUpload();
  56. }
  57. if(vartrue($_POST['installContent']))
  58. {
  59. $this->installContent($_POST['installContent']);
  60. }
  61. $this->themeArray = (defined('E107_INSTALL')) ? $this->getThemes('xml') : $this->getThemes();
  62. // print_a($this -> themeArray);
  63. foreach ($_POST as $key=>$post)
  64. {
  65. if(strstr($key, "preview"))
  66. {
  67. // $this -> id = str_replace("preview_", "", $key);
  68. $this->id = key($post);
  69. $this->themePreview();
  70. }
  71. if(strstr($key, "selectmain"))
  72. {
  73. // $this -> id = str_replace("selectmain_", "", $key);
  74. $this->id = key($post);
  75. if($this->setTheme())
  76. {
  77. $mes->addSuccess(TPVLAN_3);
  78. }
  79. else
  80. {
  81. $mes->addError(TPVLAN_3);
  82. }
  83. }
  84. if(strstr($key, "selectadmin"))
  85. {
  86. $this->id = key($post);
  87. $this->setAdminTheme();
  88. $this->refreshPage('admin');
  89. }
  90. }
  91. if(isset($_POST['submit_adminstyle']))
  92. {
  93. $this->id = $_POST['curTheme'];
  94. if($this->setAdminStyle())
  95. {
  96. eMessage::getInstance()->add(TPVLAN_43, E_MESSAGE_SUCCESS);
  97. }
  98. e107::getConfig()->save(true);
  99. }
  100. if(isset($_POST['submit_style']))
  101. {
  102. $this->id = $_POST['curTheme'];
  103. $this->setLayouts(); // Update the layouts in case they have been manually changed.
  104. $this->SetCustomPages($_POST['custompages']);
  105. $this->setStyle();
  106. e107::getConfig()->save(true);
  107. }
  108. if(isset($_POST['installplugin']))
  109. {
  110. $key = key($_POST['installplugin']);
  111. include_lan(e_LANGUAGEDIR.e_LANGUAGE."/admin/lan_plugin.php");
  112. require_once (e_HANDLER."plugin_class.php");
  113. $eplug = new e107plugin;
  114. $message = $eplug->install_plugin($key);
  115. $mes->add($message, E_MESSAGE_SUCCESS);
  116. }
  117. if(isset($_POST['setMenuPreset']))
  118. {
  119. $key = key($_POST['setMenuPreset']);
  120. include_lan(e_LANGUAGEDIR.e_LANGUAGE."/admin/lan_menus.php");
  121. require_once (e_HANDLER."menumanager_class.php");
  122. $men = new e_menuManager();
  123. $men->curLayout = $key;
  124. //menu_layout is left blank when it's default.
  125. $men->dbLayout = ($men->curLayout != $pref['sitetheme_deflayout']) ? $men->curLayout : "";
  126. if($areas = $men->menuSetPreset())
  127. {
  128. foreach ($areas as $val)
  129. {
  130. $ar[$val['menu_location']][] = $val['menu_name'];
  131. }
  132. foreach ($ar as $k=>$v)
  133. {
  134. $message .= MENLAN_14." ".$k." : ".implode(", ", $v)."<br />";
  135. }
  136. $mes->add(MENLAN_43." : ".$key."<br />".$message, E_MESSAGE_SUCCESS);
  137. }
  138. }
  139. }
  140. function getThemes($mode = FALSE)
  141. {
  142. $themeArray = array();
  143. $tloop = 1;
  144. $fl = e107::getFile();
  145. $array = $fl->get_dirs(e_THEME);
  146. foreach($array as $file)
  147. {
  148. if(($mode == 'xml') && !is_readable(e_THEME.$file."/theme.xml"))
  149. {
  150. continue;
  151. }
  152. if($file != "." && $file != ".." && $file != "CVS" && $file != "templates" && is_dir(e_THEME.$file) && is_readable(e_THEME.$file."/theme.php"))
  153. {
  154. if($mode == "id")
  155. {
  156. $themeArray[$tloop] = $file;
  157. }
  158. else
  159. {
  160. $themeArray[$file] = $this->getThemeInfo($file);
  161. $themeArray[$file]['id'] = $tloop;
  162. }
  163. $tloop++;
  164. }
  165. }
  166. // echo "<pre>";
  167. // print_r($themeArray);
  168. // echo "</pre>";
  169. return $themeArray;
  170. }
  171. function getThemeInfo($file)
  172. {
  173. $mes = e107::getMessage();
  174. $reject = array('e_.*');
  175. $handle2 = e107::getFile()->get_files(e_THEME.$file."/", "\.php|\.css|\.xml|preview\.jpg|preview\.png", $reject, 1);
  176. foreach ($handle2 as $fln)
  177. {
  178. $file2 = str_replace(e_THEME.$file."/", "", $fln['path']).$fln['fname'];
  179. $themeArray[$file]['files'][] = $file2;
  180. if(strstr($file2, "preview."))
  181. {
  182. $themeArray[$file]['preview'] = e_THEME.$file."/".$file2;
  183. }
  184. // ---------------- get information string for css file - Legacy mode (no theme.xml)
  185. if(strstr($file2, ".css") && !strstr($file2, "menu.css") && strpos($file2, "e_") !== 0)
  186. {
  187. if($cssContents = file_get_contents(e_THEME.$file."/".$file2))
  188. {
  189. $nonadmin = preg_match('/\* Non-Admin(.*?)\*\//', $cssContents) ? true : false;
  190. preg_match('/\* info:(.*?)\*\//', $cssContents, $match);
  191. $match[1] = varset($match[1], '');
  192. $themeArray[$file]['css'][] = array("name"=>$file2, "info"=>$match[1], "nonadmin"=>$nonadmin);
  193. }
  194. else
  195. {
  196. // $mes->addDebug("Couldn't read file: ".e_THEME.$file."/".$file2);
  197. }
  198. }
  199. } // end while..
  200. // Load Theme information and merge with existing array. theme.xml (v2.x theme) is given priority over theme.php (v1.x).
  201. if(in_array("theme.xml", $themeArray[$file]['files']))
  202. {
  203. $themeArray[$file] = array_merge($themeArray[$file], $this->parse_theme_xml($file));
  204. }
  205. elseif(in_array("theme.php", $themeArray[$file]['files']))
  206. {
  207. $themeArray[$file] = array_merge($themeArray[$file], $this->parse_theme_php($file));
  208. }
  209. if(count($themeArray[$file]['css']) > 1)
  210. {
  211. $themeArray[$file]['multipleStylesheets'] = TRUE;
  212. }
  213. return $themeArray[$file];
  214. }
  215. /**
  216. * Validate and return the name of the categories.
  217. *
  218. * @param string [optional] $categoryfromXML
  219. * @return string
  220. */
  221. function getThemeCategory($categoryfromXML = '')
  222. {
  223. if(!$categoryfromXML)
  224. {
  225. return 'generic';
  226. }
  227. $tmp = explode(",", $categoryfromXML);
  228. $category = array();
  229. foreach ($tmp as $cat)
  230. {
  231. $cat = trim($cat);
  232. if(in_array($cat, $this->allowedCategories))
  233. {
  234. $category[] = $cat;
  235. }
  236. else
  237. {
  238. $category[] = 'generic';
  239. }
  240. }
  241. return implode(', ', $category);
  242. }
  243. function themeUpload()
  244. {
  245. if(!$_POST['ac'] == md5(ADMINPWCHANGE))
  246. {
  247. exit;
  248. }
  249. $mes = e107::getMessage();
  250. $ns = e107::getRender();
  251. extract($_FILES);
  252. //print_a($_FILES);
  253. if(!is_writable(e_THEME))
  254. {
  255. $mes->addInfo(TPVLAN_20);
  256. return FALSE;
  257. }
  258. else
  259. {
  260. // FIXME - temporary fixes to upload process, check required.
  261. // Probably in need of a rewrite to use process_uploaded_files();
  262. require_once (e_HANDLER."upload_handler.php");
  263. $fileName = $_FILES['file_userfile']['name'][0];
  264. $fileSize = $_FILES['file_userfile']['size'][0];
  265. $fileType = $_FILES['file_userfile']['type'][0]; // type is returned as mime type (application/octet-stream) not as zip/rar
  266. // There may be a better way to do this.. MIME may not be secure enough
  267. // process_uploaded_files() ?
  268. $mime_zip = array("application/octet-stream", "application/zip", "multipart/x-zip");
  269. $mime_gzip = array("application/x-gzip", "multipart/x-gzip");
  270. // rar?
  271. if(in_array($fileType, $mime_zip))
  272. {
  273. $fileType = "zip";
  274. }
  275. elseif(in_array($fileType, $mime_gzip))
  276. {
  277. $fileType = "gzip";
  278. }
  279. else
  280. {
  281. $mes->addError(TPVLAN_17);
  282. return FALSE;
  283. }
  284. if($fileSize)
  285. {
  286. $uploaded = file_upload(e_THEME);
  287. $archiveName = $uploaded[0]['name'];
  288. if($fileType == "zip")
  289. {
  290. require_once (e_HANDLER."pclzip.lib.php");
  291. $archive = new PclZip(e_THEME.$archiveName);
  292. $unarc = ($fileList = $archive->extract(PCLZIP_OPT_PATH, e_THEME, PCLZIP_OPT_SET_CHMOD, 0666)); // FIXME - detect folder structure similar to 'Find themes'
  293. }
  294. else
  295. {
  296. require_once (e_HANDLER."pcltar.lib.php");
  297. $unarc = ($fileList = PclTarExtract($archiveName, e_THEME)); // FIXME - detect folder structure similar to 'Find themes'
  298. }
  299. if(!$unarc)
  300. {
  301. if($fileType == "zip")
  302. {
  303. $error = TPVLAN_46." '".$archive->errorName(TRUE)."'";
  304. }
  305. else
  306. {
  307. $error = TPVLAN_47.PclErrorString().", ".TPVLAN_48.intval(PclErrorCode());
  308. }
  309. $mes->addError(TPVLAN_18." ".$archiveName." ".$error);
  310. return FALSE;
  311. }
  312. $folderName = substr($fileList[0]['stored_filename'], 0, (strpos($fileList[0]['stored_filename'], "/")));
  313. $mes->addSuccess(TPVLAN_19);
  314. if(varset($_POST['setUploadTheme']))
  315. {
  316. $themeArray = $this->getThemes();
  317. $this->id = $themeArray[$folderName]['id'];
  318. if($this->setTheme())
  319. {
  320. $mes->addSuccess(TPVLAN_3);
  321. }
  322. else
  323. {
  324. $mes->addError("Could not change site theme."); // TODO LAN
  325. }
  326. }
  327. @unlink(e_THEME.$archiveName);
  328. }
  329. }
  330. }
  331. private function search($name, $searchVal, $submitName, $filterName='', $filterArray=false, $filterVal=false)
  332. {
  333. $frm = e107::getForm();
  334. $text = '<span class="input-append e-search"><i class="icon-search"></i>
  335. '.$frm->text($name, $searchVal,20,'class=search-query').'
  336. <button class="btn btn-primary" name="'.$submitName.'" type="submit">'.LAN_GO.'</button>
  337. </span>';
  338. // $text .= $this->admin_button($submitName,LAN_SEARCH,'search');
  339. return $text;
  340. }
  341. /**
  342. * Temporary, e107::getMarketplace() coming soon
  343. * @return e_marketplace
  344. */
  345. public function getMarketplace()
  346. {
  347. if(null === $this->mp)
  348. {
  349. require_once(e_HANDLER.'e_marketplace.php');
  350. $this->mp = new e_marketplace(); // autodetect the best method
  351. }
  352. return $this->mp;
  353. }
  354. function renderOnline($ajax=false)
  355. {
  356. global $e107SiteUsername, $e107SiteUserpass;
  357. $xml = e107::getXml();
  358. $mes = e107::getMessage();
  359. $frm = e107::getForm();
  360. $ns = e107::getRender();
  361. $mp = $this->getMarketplace();
  362. $from = intval(varset($_GET['frm']));
  363. $limit = 96; // FIXME - ajax pages load
  364. $srch = preg_replace('/[^\w]/','', vartrue($_GET['srch']));
  365. // check for cURL
  366. if(!function_exists(curl_init))
  367. {
  368. $mes->addWarning("cURL is currently required to use this feature. Contact your webhosting provider to enable cURL"); // TODO LAN?
  369. }
  370. // auth
  371. $mp->generateAuthKey($e107SiteUsername, $e107SiteUserpass);
  372. // do the request, retrieve and parse data
  373. $xdata = $mp->call('getList', array(
  374. 'type' => 'theme',
  375. 'params' => array('limit' => $limit, 'search' => $srch, 'from' => $from)
  376. ));
  377. $total = $xdata['params']['count'];
  378. // OLD BIT OF CODE ------------------------------->
  379. /*$file = "http://e107.org/feed?type=theme&frm=".$from."&srch=".$srch."&limit=".$limit;
  380. $mes->addDebug("File = ".$file);
  381. $xml->setOptArrayTags('theme,screenshots/image'); // make sure 'theme' tag always returns an array
  382. // $xdata = $xml->loadXMLfile($file,'advanced',true);
  383. $xdata = $xml->loadXMLfile($file,true,false);
  384. $total = $xdata['@attributes']['total'];*/
  385. // OLD BIT OF CODE ------------------------------->
  386. $amount =$limit;
  387. /*
  388. if($total > $amount)
  389. {
  390. //$parms = $total.",".$amount.",".$from.",".e_SELF.'?mode='.$_GET['mode'].'&amp;frm=[FROM]';
  391. $url = rawurlencode(e_SELF.'?mode='.$_GET['mode'].'&frm=[FROM]');
  392. $parms = "total=".$total."&amount=".$amount."&current=".$from."&url=".$url."&caption=off&tmpl=basic&navcount=4&glyphs=1";
  393. $text .= "<div class='span5' style='margin-left: 100px;margin-top:10px'>".$tp->parseTemplate("{NEXTPREV=$parms}",TRUE)."</div>";
  394. }
  395. */
  396. // print_a($xdata);
  397. $c = 1;
  398. $text = "<form class='form-search' action='".e_SELF."?".e_QUERY."' id='core-plugin-list-form' method='get'>";
  399. $text .= '<div id="myCarousel" class="carousel slide" data-interval="false">';
  400. $text .= "<div class='form-inline clearfix row-fluid'>";
  401. $text .= $this->search('srch', $srch, 'go', $filterName, $filterArray, $filterVal).$frm->hidden('mode','online');
  402. $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>';
  403. $text .= "{CAROUSEL_INDICATORS}";
  404. $text .= "</div>";
  405. $text .= '<div id="shop" style="margin-top:10px;min-height:585px" class=" carousel-inner">';
  406. if(is_array($xdata['data'] ))
  407. {
  408. $text .= '<div class="active item">';
  409. $slides = array();
  410. foreach($xdata['data'] as $r)
  411. {
  412. if(E107_DBG_PATH)
  413. {
  414. $mes->addDebug(print_a($r,true));
  415. }
  416. $theme = array(
  417. 'id' => $r['params']['id'],
  418. 'type' => 'theme',
  419. 'mode' => $r['params']['mode'],
  420. 'name' => stripslashes($r['name']),
  421. 'category' => $r['category'],
  422. 'preview' => varset($r['screenshots']['image']),
  423. 'date' => $r['date'],
  424. 'version' => $r['version'],
  425. 'thumbnail' => $r['thumbnail'],
  426. 'url' => $r['urlView'],
  427. 'author' => $r['author'],
  428. 'website' => $r['authorUrl'],
  429. 'compatibility' => $r['compatibility'],
  430. 'description' => $r['description'],
  431. 'price' => $r['price'],
  432. 'livedemo' => $r['livedemo'],
  433. );
  434. $text .= $this->renderTheme(FALSE, $theme);
  435. $c++;
  436. if($c == 19)
  437. {
  438. $text .= '</div><div class="item">';
  439. $slides[] = 1;
  440. $c = 1;
  441. }
  442. /*
  443. [author] => e107 Inc
  444. [summary] => Bootstrap e107 admin theme
  445. [category] => generic
  446. [keywords] => Array
  447. (
  448. [word] => Array
  449. (
  450. [0] => bootstrap
  451. [1] => clean
  452. )
  453. )
  454. [name] => bootstrap
  455. [version] => 1.0
  456. [date] => 2012-12-01
  457. [compatibility] => 2.0
  458. [releaseUrl] =>
  459. [email] => e107inc@something.com
  460. [website] => http://e107.org
  461. [info] => Bootstrap e107 admin theme
  462. [compliance] => Array
  463. (
  464. [@attributes] => Array
  465. (
  466. [xhtml] =>
  467. [css] =>
  468. )
  469. )
  470. [xhtmlcompliant] =>
  471. [csscompliant] =>
  472. [path] => bootstrap
  473. */
  474. }
  475. $text .= "<div class='clear'>&nbsp;</div>";
  476. $text .= "</div>";
  477. $text .= "</div>";
  478. }
  479. else
  480. {
  481. $mes->addInfo("No Themes found which match your search criteria");
  482. }
  483. $indicators = '<ol class="carousel-indicators span6">
  484. <li data-target="#myCarousel" data-slide-to="0" class="active"></li>';
  485. foreach($slides as $key=>$v)
  486. {
  487. $id = $key + 1;
  488. $indicators .= '<li data-target="#myCarousel" data-slide-to="'.$id.'"></li>';
  489. }
  490. $indicators .= '</ol>';
  491. $text = str_replace("{CAROUSEL_INDICATORS}",$indicators,$text);
  492. $text .= "</form>";
  493. $ns->tablerender(TPVLAN_26.SEP."Available for Download", $mes->render().$text);
  494. }
  495. function showThemes($mode = 'main')
  496. {
  497. global $pref;
  498. $mes = e107::getMessage();
  499. $ns = e107::getRender();
  500. $tp = e107::getParser();
  501. $frm = e107::getForm();
  502. echo "<div>";
  503. if($mode == "main" || !$mode) // Show Main Configuration
  504. {
  505. foreach ($this->themeArray as $key=>$theme)
  506. {
  507. if($key == $pref['sitetheme'])
  508. {
  509. $text = $this->renderTheme(1, $theme);
  510. }
  511. }
  512. echo "<form enctype='multipart/form-data' method='post' action='".e_SELF."?".$mode."'>\n";
  513. $ns->tablerender(TPVLAN_26.SEP.TPVLAN_33, $mes->render().$text);
  514. echo "</form>";
  515. }
  516. // Show Admin Configuration
  517. if($mode == "admin")
  518. {
  519. foreach ($this->themeArray as $key=>$theme)
  520. {
  521. if($key == $pref['admintheme'])
  522. {
  523. $text = $this->renderTheme(2, $theme);
  524. }
  525. }
  526. echo "<form enctype='multipart/form-data' method='post' action='".e_SELF."?".$mode."'>\n";
  527. $ns->tablerender(TPVLAN_26.SEP.TPVLAN_34, $mes->render().$text);
  528. echo "</form>";
  529. }
  530. // Show Upload Form
  531. if($mode == "upload")
  532. {
  533. $this->renderUploadForm();
  534. }
  535. // Show All Themes
  536. if($mode == "choose")
  537. {
  538. $text = "";
  539. foreach ($this->themeArray as $key=>$theme)
  540. {
  541. $text .= $this->renderTheme(FALSE, $theme);
  542. // print_a($theme);
  543. }
  544. $text .= "<div class='clear'>&nbsp;</div>";
  545. echo "<form enctype='multipart/form-data' method='post' action='".e_SELF."?".$mode."'>\n";
  546. $ns->tablerender(TPVLAN_26.SEP.TPVLAN_39, $mes->render().$text);
  547. $text .= "</form>";
  548. }
  549. if($mode == "online")
  550. {
  551. $this->renderOnline();
  552. }
  553. echo "</div>\n";
  554. }
  555. function renderUploadForm()
  556. {
  557. $mes = e107::getMessage();
  558. $ns = e107::getRender();
  559. $sql = e107::getDb();
  560. $frm = e107::getForm();
  561. if(!is_writable(e_THEME))
  562. {
  563. $ns->tablerender(TPVLAN_16, TPVLAN_15);
  564. $text = "";
  565. }
  566. else
  567. {
  568. require_once(e_HANDLER.'upload_handler.php');
  569. $max_file_size = get_user_max_upload();
  570. $text = "
  571. <form enctype='multipart/form-data' action='".e_SELF."' method='post'>
  572. <table class='table adminform'>
  573. <colgroup>
  574. <col class='col-label' />
  575. <col class='col-control' />
  576. </colgroup>
  577. <tr>
  578. <td>".TPVLAN_13."</td>
  579. <td>
  580. <input type='hidden' name='MAX_FILE_SIZE' value='{$max_file_size}' />
  581. <input type='hidden' name='ac' value='".md5(ADMINPWCHANGE)."' />
  582. <input class='tbox' type='file' name='file_userfile[]' size='50' />
  583. </td>
  584. </tr>
  585. <tr>
  586. <td>".TPVLAN_10."</td>
  587. <td><input type='checkbox' name='setUploadTheme' value='1' /></td>
  588. </tr>
  589. </table>
  590. <div class='buttons-bar center'>".$frm->admin_button('upload', TPVLAN_14, 'submit')."</div>
  591. </form>
  592. ";
  593. }
  594. $ns->tablerender(TPVLAN_26.SEP.TPVLAN_38, $mes->render().$text);
  595. }
  596. function renderThemeInfo($theme)
  597. {
  598. global $pref;
  599. $author = ($theme['email'] ? "<a href='mailto:".$theme['email']."' title='".$theme['email']."'>".$theme['author']."</a>" : $theme['author']);
  600. $website = ($theme['website'] ? "<a href='".$theme['website']."' rel='external'>".$theme['website']."</a>" : "");
  601. $preview = "<a href='".SITEURL."news.php?themepreview.".$theme['id']."' title='".TPVLAN_9."' >".($theme['preview'] ? "<img src='".$theme['preview']."' style='border: 1px solid #000;width:200px' alt='' />" : "<img src='".e_IMAGE_ABS."admin_images/nopreview.png' title='".TPVLAN_12."' alt='' />")."</a>";
  602. $description = vartrue($theme['description'],'');
  603. $compat = (intval($theme['compatibility']) == 2) ? "<span class='label label-warning'>".number_format($theme['compatibility'], 1, '.','')."</span><span class='text-warning'> Recommended!</span>": vartrue(number_format($theme['compatibility'], 1, '.',''),'1.0');
  604. $price = ($theme['price'] > 0) ? "<span class='label label-info'><i class='icon-shopping-cart icon-white'></i> ".$theme['price']."</span>" : "<span class='label label-success'>".Free."</span>";
  605. $text = "<table class='table table-striped'>";
  606. // $text .= "<tr><th colspan='2'><h3>".$theme['name']." ".$theme['version']."</h3></th></tr>";
  607. $text .= $author ? "<tr><td style='vertical-align:top; width:24%'><b>".TPVLAN_4."</b>:</td><td style='vertical-align:top'>".$author."</td></tr>" : "";
  608. $text .= $website ? "<tr><td style='vertical-align:top; width:24%'><b>".TPVLAN_5."</b>:</td><td style='vertical-align:top'>".$website."</td></tr>" : "";
  609. $text .= $theme['date'] ? "<tr><td style='vertical-align:top; width:24%'><b>".TPVLAN_6."</b>:</td><td style='vertical-align:top'>".$theme['date']."</td></tr>" : "";
  610. $text .= $compat ? "<tr><td style='vertical-align:top; width:24%'><b>".TPVLAN_57."</b>:</td><td style='vertical-align:top'>".$compat."</td></tr>" : "";
  611. $text .= "<tr><td style='vertical-align:top; width:24%'><b>Price</b>:</td><td style='vertical-align:top'>".$price."</td></tr>";
  612. $text .= $description ? "<tr><td style='vertical-align:top; width:24%'><b>Description</b>:</td><td style='vertical-align:top'>".$description."</td></tr>" : "";
  613. // $text .= "<tr><td style='vertical-align:top; width:24%'><b>".TPVLAN_49."</b>:</td>
  614. // <td style='vertical-align:top'>XHTML ";
  615. // $text .= ($theme['xhtmlcompliant']) ? ADMIN_TRUE_ICON : ADMIN_FALSE_ICON;
  616. // $text .= " &nbsp;&nbsp; CSS ";
  617. // $text .= ($theme['csscompliant']) ? ADMIN_TRUE_ICON : ADMIN_FALSE_ICON;
  618. // $text .= "</td></tr>";
  619. if(vartrue($theme['category']))
  620. {
  621. $text .= "<tr><td><b>Category</b></td><td>".$theme['category']."</td></tr>";
  622. }
  623. // New in 0.8 WORK IN PROGRESS ----
  624. if($theme['layouts'])
  625. {
  626. $itext .= "<tr>
  627. <td style='vertical-align:top; width:24%'><b>".TPVLAN_50."</b>:</td>
  628. <td class='well' style='vertical-align:top'>
  629. <table class='table' style='margin-left:0px;margin-right:auto' >
  630. <tr>";
  631. $itext .= ($mode == 1) ? "<td class='fcaption' style='text-align:center;vertical-align:top;'>Default</td>" : "";
  632. $itext .= "
  633. <th class='fcaption'>Title</th>
  634. <th class='fcaption'>Requirements</th>
  635. <th class='fcaption' style='text-align:center;width:100px'>Menu Preset</th>
  636. </tr>\n";
  637. foreach ($theme['layouts'] as $key=>$val)
  638. {
  639. $itext .= "
  640. <tr>";
  641. if($mode == 1)
  642. {
  643. if(!$pref['sitetheme_deflayout'])
  644. {
  645. $pref['sitetheme_deflayout'] = ($val['@attributes']['default'] == 'true') ? $key : "";
  646. // echo "------------- NODEFAULT";
  647. }
  648. $itext .= "
  649. <td style='vertical-align:top width:auto;text-align:center'>
  650. <input type='radio' name='layout_default' value='{$key}' ".($pref['sitetheme_deflayout'] == $key ? " checked='checked'" : "")." />
  651. </td>";
  652. }
  653. $itext .= "<td style='vertical-align:top'>";
  654. $itext .= ($val['@attributes']['previewFull']) ? "<a href='".e_THEME_ABS.$theme['path']."/".$val['@attributes']['previewFull']."' >" : "";
  655. $itext .= $val['@attributes']['title'];
  656. $itext .= ($val['@attributes']['previewFull']) ? "</a>" : "";
  657. $itext .= ($pref['sitetheme_deflayout'] == $key) ? " (default)" : "";
  658. $itext .= "</td>
  659. <td style='vertical-align:top'>".$val['@attributes']['plugins']."&nbsp;</td>
  660. <td style='vertical-align:top;text-align:center'>";
  661. $itext .= ($val['menuPresets']) ? ADMIN_TRUE_ICON : "&nbsp;";
  662. $itext .= "</td>
  663. </tr>";
  664. }
  665. $itext .= "</table></td></tr>";
  666. }
  667. // $text .= "<tr><td><b>".TPVLAN_22.": </b></td><td colspan='2'>";
  668. // foreach ($theme['css'] as $val)
  669. // {
  670. // $text .= $val['name']."<br />";
  671. // }
  672. // $text .= "</td></tr>";
  673. $text .= $itext."</table>";
  674. if(count($theme['preview']))
  675. {
  676. $text .= "<tr><td colspan='2'>";
  677. foreach($theme['preview'] as $pic)
  678. {
  679. $picFull = (substr($pic,0,4) == 'http') ? $pic : e_THEME.$theme['path']."/".$pic;
  680. $text .= "<div style='padding:5px;width:700px'>
  681. <img src='".$picFull."' alt=\"".$theme['name']."\" />
  682. </div>";
  683. }
  684. // $text .= "</td>
  685. // </tr>";
  686. }
  687. // $text .= "<div class='right'><a href='#themeInfo_".$theme['id']."' class='e-expandit'>Close</a></div>";
  688. if(E107_DEBUG_LEVEL > 0)
  689. {
  690. $text .= print_a($theme, true);
  691. }
  692. return $text;
  693. }
  694. function loadThemeConfig()
  695. {
  696. $mes = e107::getMessage();
  697. $newConfile = e_THEME.$this->id."/theme_config.php";
  698. $legacyConfile = e_THEME.$this->id."/".$this->id."_config.php"; // @Deprecated
  699. if(is_readable($newConfile))
  700. {
  701. $confile = $newConfile;
  702. }
  703. elseif(is_readable($legacyConfile))// TODO Eventually remove it.
  704. {
  705. // NOTE: this is debug info.. do not translate.
  706. e107::getMessage()->addDebug("Deprecated Theme Config File found! Rename <b>".$this->id."_config.php.</b> to <b>theme_config.php</b> to correct this issue. .");
  707. $confile = $legacyConfile;
  708. }
  709. else
  710. {
  711. return;
  712. }
  713. if(($this->themeConfigObj === null) )
  714. {
  715. $mes->addDebug("Loading : ".$confile);
  716. include ($confile);
  717. $className = 'theme_'.$this->id;
  718. if(class_exists($className))
  719. {
  720. $this->themeConfigObj = new $className();
  721. }
  722. else
  723. {
  724. $this->themeConfigObj = FALSE;
  725. }
  726. }
  727. }
  728. // TODO process custom theme configuration - .
  729. function renderThemeConfig()
  730. {
  731. $mes = e107::getMessage();
  732. $mes->addDebug("Rendering Theme Config");
  733. $this->loadThemeConfig();
  734. if($this->themeConfigObj)
  735. {
  736. $var = call_user_func(array(&$this->themeConfigObj, 'config'));
  737. vartrue($text); // avoid notice
  738. foreach ($var as $val)
  739. {
  740. $text .= "<tr><td><b>".$val['caption']."</b>:</td><td colspan='2'>".$val['html']."</td></tr>";
  741. }
  742. return $text;
  743. }
  744. }
  745. function renderThemeHelp()
  746. {
  747. if($this->themeConfigObj)
  748. {
  749. return call_user_func(array(&$this->themeConfigObj, 'help'));
  750. }
  751. }
  752. function setThemeConfig()
  753. {
  754. $this->loadThemeConfig();
  755. if($this->themeConfigObj)
  756. {
  757. return call_user_func(array(&$this->themeConfigObj, 'process'));
  758. }
  759. }
  760. /**
  761. mode = 0 :: normal
  762. mode = 1 :: selected site theme
  763. mode = 2 :: selected admin theme
  764. */
  765. function renderTheme($mode = FALSE, $theme)
  766. {
  767. $ns = e107::getRender();
  768. $pref = e107::getPref();
  769. $frm = e107::getForm();
  770. $tp = e107::getParser();
  771. $author = ($theme['email'] ? "<a href='mailto:".$theme['email']."' title='".$theme['email']."'>".$theme['author']."</a>" : $theme['author']);
  772. $website = ($theme['website'] ? "<a href='".$theme['website']."' rel='external'>".$theme['website']."</a>" : "");
  773. // $preview = "<a href='".e_BASE."news.php?themepreview.".$theme['id']."' title='".TPVLAN_9."' >".($theme['preview'] ? "<img src='".$theme['preview']."' style='border: 1px solid #000;width:200px' alt='' />" : "<img src='".e_IMAGE_ABS."admin_images/nopreview.png' title='".TPVLAN_12."' alt='' />")."</a>";
  774. $main_icon = ($pref['sitetheme'] != $theme['path']) ? "<button class='btn btn-small btn-sm btn-inverse' type='submit' name='selectmain[".$theme['id']."]' alt=\"".TPVLAN_10."\" title=\"".TPVLAN_10."\" >".$tp->toGlyph('fa-home',array('size'=>'2x'))."</button>" : "<button class='btn btn-small btn-sm btn-inverse' type='button'>".$tp->toGlyph('fa-check',array('size'=>'2x'))."</button>";
  775. // $info_icon = "<a data-toggle='modal' data-target='".e_SELF."' href='#themeInfo_".$theme['id']."' class='e-tip' title='".TPVLAN_7."'><img src='".e_IMAGE_ABS."admin_images/info_32.png' alt='' class='icon S32' /></a>";
  776. $info_icon = "<a class='btn btn-small btn-sm btn-inverse' data-toggle='modal' data-modal-caption=\"".$theme['name']." ".$theme['version']."\" href='".e_SELF."?id=".$theme['path']."' data-target='#uiModal' title='".TPVLAN_7."'>".$tp->toGlyph('fa-info-circle',array('size'=>'2x'))."</a>";
  777. // $preview_icon = "<a title='Preview : ".$theme['name']."' rel='external' class='e-dialog' href='".e_BASE."index.php?themepreview.".$theme['id']."'>".E_32_SEARCH."</a>";
  778. $admin_icon = ($pref['admintheme'] != $theme['path'] ) ? "<button class='btn 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>\n" : "<button class='btn btn-small btn-sm btn-inverse' type='button'>".$tp->toGlyph('fa-check',array('size'=>'2x'))."</button>";
  779. $price = '';
  780. if(substr($theme['thumbnail'],0,4) == 'http')
  781. {
  782. $thumbPath = $theme['thumbnail'];
  783. $previewPath = $theme['preview'][0];
  784. }
  785. elseif(vartrue($theme['preview'][0]))
  786. {
  787. $thumbPath = e_THEME.$theme['path'] ."/".$theme['preview'][0];
  788. $previewPath = e_THEME.$theme['path'] ."/".$theme['preview'][0];
  789. }
  790. else
  791. {
  792. $thumbPath = e_IMAGE_ABS."admin_images/nopreview.png";
  793. $previewPath = e_BASE."index.php?themepreview.".$theme['id'];
  794. }
  795. $thumbnail = "<img src='".$thumbPath."' style='width:200px; height:130px;' alt='' />";
  796. if($_GET['mode'] == 'online')
  797. {
  798. $d = http_build_query($theme,false,'&');
  799. $url = e_SELF."?src=".base64_encode($d);
  800. $id = $frm->name2id($theme['name']);
  801. $LAN_DOWNLOAD = ($theme['price'] > 0) ? "Buy/Download" : "Download";
  802. /*
  803. if($this->mp->hasAuthKey())
  804. {
  805. $action = 'download';
  806. $caption = "Downloading ".$theme['name']." ".$theme['version'];
  807. }
  808. else
  809. {
  810. $action = 'login';
  811. $caption = "Please login to your e107.org account to proceed..";
  812. }
  813. */
  814. $downloadUrl = e_SELF.'?action='.$action.'&amp;src='.base64_encode($d);//$url.'&amp;action=download';
  815. $infoUrl = $url.'&amp;action=info';
  816. $viewUrl = $theme['url'];
  817. //$main_icon = "<a data-src='".$downloadUrl."' href='{$downloadUrl}' data-target='{$id}' data-loading='".e_IMAGE."/generic/loading_32.gif' class='-e-ajax' title='".$LAN_DOWNLOAD."' ><img class='top' src='".e_IMAGE_ABS."icons/download_32.png' alt='' /></a> ";
  818. // $main_icon = "<a data-toggle='modal' data-modal-caption=\"".$caption."\" href='{$downloadUrl}' data-cache='false' data-target='#uiModal' title='".$LAN_DOWNLOAD."' >".$tp->toGlyph('download',array('size'=>'2x'))."</a> ";
  819. // Temporary Pop-up version.
  820. $main_icon = "<a class='e-modal btn btn-small btn-inverse' data-modal-caption=\"".$theme['name']." ".$theme['version']."\" rel='external' href='{$viewUrl}' data-cache='false' title='".$LAN_DOWNLOAD."' >".$tp->toGlyph('download',array('size'=>'2x'))."</a> ";
  821. $info_icon = "<a class='btn btn-small btn-inverse' data-toggle='modal' data-modal-caption=\"".$theme['name']." ".$theme['version']."\" href='".$infoUrl."' data-cache='false' data-target='#uiModal' title='".TPVLAN_7."'>".$tp->toGlyph('fa-info-circle',array('size'=>'2x'))."</a>";
  822. if($theme['livedemo'])
  823. {
  824. $previewPath = $theme['livedemo'];
  825. }
  826. //XXX modal-Cache is currently enabled by default. Awaiting inclusion of data-cache feature.
  827. // See here: https://github.com/twitter/bootstrap/pull/4224
  828. $price = ($theme['price'] > 0) ? "<span class='label label-info pull-right'><i class='icon-shopping-cart icon-white'></i> ".$theme['price']."</span>" : "<span class='label label-success pull-right'>".Free."</span>";
  829. }
  830. $preview_icon = "<a class='e-modal btn btn-small btn-inverse' title='Preview/Live-Demo : ".$theme['name']."' data-modal-caption=\"".$theme['name']." ".$theme['version']."\" rel='external' href='".$previewPath."'>".$tp->toGlyph('fa-search',array('size'=>'2x'))."</a>";
  831. if(!in_array($theme['path'], $this->approvedAdminThemes))
  832. {
  833. $admin_icon = "";
  834. }
  835. if($theme['name'] == 'bootstrap')
  836. {
  837. // print_a($theme);
  838. }
  839. //
  840. // $thumbPath = (substr($theme['thumbnail'],0,4) == 'http') ? $theme['thumbnail'] : e_THEME.$theme['path'] ."/".$theme['preview'][0];
  841. // $thumbnail = "<a href='".e_BASE."news.php?themepreview.".$theme['id']."' title='".TPVLAN_9."' >";
  842. // $thumbnail .= "</a>";
  843. // Choose a Theme to Install.
  844. if(!$mode)
  845. {
  846. // styles NEED to be put into style.css
  847. if($pref['sitetheme'] == $theme['path'])
  848. {
  849. $borderStyle = "admin-theme-cell-site";
  850. }
  851. elseif($pref['admintheme'] == $theme['path'])
  852. {
  853. $borderStyle = "admin-theme-cell-admin";
  854. }
  855. else
  856. {
  857. $borderStyle = "admin-theme-cell-default";
  858. }
  859. $borderStyle = 'well';
  860. $text = "
  861. <div class='f-left block-text admin-theme-cell ".$borderStyle."'>
  862. <div class='well admin-theme-thumb'>".$thumbnail."</div>
  863. <div id='".$frm->name2id($theme['name'])."' class='btn-group admin-theme-options'>".$main_icon.$admin_icon.$info_icon.$preview_icon."</div>
  864. <div class='admin-theme-title'><small style='white-space:nowrap;display:inline-block;width:160px;overflow:hidden'>".$theme['name']." ".$theme['version']."</small>
  865. ".$price."
  866. </div>
  867. </div>";
  868. return $text;
  869. }
  870. $this->id = $theme['path'];
  871. // load customn theme configuration fields.
  872. $this->loadThemeConfig();
  873. $text = "
  874. <h2 class='caption'>".$theme['name']."</h2>
  875. <ul class='nav nav-tabs'>
  876. <li class='active'><a data-toggle='tab' href='#core-thememanager-configure'>".LAN_CONFIGURE."</a></li>";
  877. if($this->themeConfigObj && call_user_func(array(&$this->themeConfigObj, 'help')))
  878. {
  879. $text .= "<li><a data-toggle='tab' href='#core-thememanager-help'>".LAN_HELP."</a></li>\n";
  880. }
  881. if($this->themeConfigObj && call_user_func(array(&$this->themeConfigObj, 'config')) && $mode == 1)
  882. {
  883. $text .= "<li><a data-toggle='tab' href='#core-thememanager-customconfig'>".LAN_CUSTOM."</a></li>\n";
  884. }
  885. $text .= "</ul>
  886. <div class='tab-content'>
  887. <div class='tab-pane active' id='core-thememanager-configure'>
  888. <table class='table adminform'>
  889. <colgroup>
  890. <col class='col-label' />
  891. <col class='col-control' />
  892. <col class='col-control' />
  893. </colgroup>
  894. <tr>
  895. <td><b>".TPVLAN_11."</b></td>
  896. <td>".$theme['version']."</td>
  897. <td class='well center middle' rowspan='6' style='text-align:center; vertical-align:middle;width:25%'>".$thumbnail."</td>
  898. </tr>";
  899. $text .= "<tr><td style='vertical-align:top; width:25%'><b>".TPVLAN_4."</b>:</td><td style='vertical-align:top'>".$author."</td></tr>";
  900. $text .= "<tr><td style='vertical-align:top; width:25%'><b>".TPVLAN_5."</b>:</td><td style='vertical-align:top'>".$website."</td></tr>";
  901. $text .= "<tr><td style='vertical-align:top; width:25%'><b>".TPVLAN_6."</b>:</td><td style='vertical-align:top'>".$theme['date']."</td></tr>";
  902. $text .= "<tr><td style='vertical-align:top; width:25%'><b>".TPVLAN_7."</b>:</td><td style='vertical-align:top'>".strip_tags($theme['info'],'b')."</td></tr>";
  903. $text .= "<tr><td style='vertical-align:top; width:25%'><b>".LAN_CATEGORY."</b>:</td><td style='vertical-align:top'>".$theme['category']."</td></tr>";
  904. // $text .= "<tr><td style='vertical-align:top; width:25%'><b>Price</b>:</td><td style='vertical-align:top'>".$price."</td></tr>";
  905. $text .= "<tr><td style='vertical-align:top; width:25%'><b>".TPVLAN_49."</b>:</td>
  906. <td style='vertical-align:top' colspan='2'>";
  907. $text .= ($theme['xhtmlcompliant']) ? "W3C XHTML ".$theme['xhtmlcompliant'] : "Not Specified";
  908. $text .= ($theme['csscompliant']) ? " &amp; CSS ".$theme['csscompliant'] : "";
  909. $text .= "</td></tr>";
  910. // site theme..
  911. if($mode == 1)
  912. {
  913. $text .= "
  914. <tr>
  915. <td style='vertical-align:top; width:24%;'><b>".TPVLAN_53."</b></td>
  916. <td colspan='2' style='vertical-align:top width:auto;'>";
  917. if(varset($theme['plugins']))
  918. {
  919. foreach ($theme['plugins'] as $key=>$val)
  920. {
  921. $text .= $this->renderPlugins($theme['plugins']);
  922. $text .= "&nbsp;";
  923. }
  924. }
  925. $text .= "&nbsp;</td>
  926. </tr>";
  927. $text .= "
  928. <tr>
  929. <td style='vertical-align:top; width:24%;'><b>".TPVLAN_30."</b></td>
  930. <td colspan='2' style='vertical-align:top width:auto;'>
  931. <input type='radio' name='image_preload' value='1'".($pref['image_preload'] ? " checked='checked'" : "")." /> ".TPVLAN_28."&nbsp;&nbsp;
  932. <input type='radio' name='image_preload' value='0'".(!$pref['image_preload'] ? " checked='checked'" : "")." /> ".TPVLAN_29."
  933. </td>
  934. </tr>";
  935. }
  936. // New in 0.8 ---- site theme.
  937. if($mode == 1)
  938. {
  939. $itext = "<tr>
  940. <td style='vertical-align:top; width:24%'><b>".TPVLAN_50."</b>:</td>
  941. <td colspan='2' style='vertical-align:top'>
  942. <table class='table adminlist'>
  943. <colgroup>
  944. <col class='col-tm-layout-default' style='width:10%' />
  945. <col class='col-tm-layout-name' style='width:40%' />
  946. <col class='col-tm-layout-visibility' style='width:30%' />
  947. <col class='col-tm-layout-preset' style='width:20%' />
  948. </colgroup>
  949. <tr>";
  950. $itext .= ($mode == 1) ? "<th class='center top'>".TPVLAN_55."</th>" : "";
  951. $itext .= "
  952. <th>".TPVLAN_52."</th>
  953. <th>".TPVLAN_56."</th>
  954. <th class='text-right' style='text-align:right'>".TPVLAN_54."</th>
  955. </tr>\n";
  956. foreach ($theme['layouts'] as $key=>$val)
  957. {
  958. $itext .= "
  959. <tr>";
  960. if($mode == 1)
  961. {
  962. if(!$pref['sitetheme_deflayout'])
  963. {
  964. $pref['sitetheme_deflayout'] = ($val['@attributes']['default'] == 'true') ? $key : "";
  965. }
  966. $itext .= "<td class='center'>\n";
  967. $itext .= "<input id='".$frm->name2id($key)."' type='radio' name='layout_default' value='{$key}' ".($pref['sitetheme_deflayout'] == $key ? " checked='checked'" : "")." />
  968. </td>";
  969. }
  970. $itext .= "<td style='vertical-align:top'><label for='".$frm->name2id($key)."'>";
  971. // $itext .= ($val['@attributes']['previewFull']) ? "<a href='".e_THEME_ABS.$theme['path']."/".$val['@attributes']['previewFull']."' >" : "";
  972. $itext .= $val['@attributes']['title'];
  973. // $itext .= ($val['@attributes']['previewFull']) ? "</a>" : "";
  974. $custompage_count = (isset($pref['sitetheme_custompages'][$key])) ? " [".count($pref['sitetheme_custompages'][$key])."]" : "";
  975. $custompage_diz = "";
  976. $count = 1;
  977. if(isset($pref['sitetheme_custompages'][$key]) && count($pref['sitetheme_custompages'][$key]) > 0)
  978. {
  979. foreach ($pref['sitetheme_custompages'][$key] as $cp)
  980. {
  981. $custompage_diz .= "<a href='#element-to-be-shown-{$key}' class='btn btn-mini e-expandit'>".trim($cp)."</a>&nbsp;";
  982. if($count > 4)
  983. {
  984. $custompage_diz .= "...";
  985. break;
  986. }
  987. $count++;
  988. }
  989. }
  990. else
  991. {
  992. $custompage_diz = "<a href='#element-to-be-shown-{$key}' title='Set pages which should automatically use this layout. One per line.' class='e-tip btn btn-mini e-expandit'>None</a> ";
  993. }
  994. $itext .= "</label></td>
  995. <td style='vertical-align:top'>";
  996. // Default
  997. $itext .= ($pref['sitetheme_deflayout'] != $key) ? $custompage_diz."<div class='e-hideme' id='element-to-be-shown-{$key}'><textarea style='width:97%' rows='6' placeholder='usersettings.php' cols='20' name='custompages[".$key."]' >".(isset($pref['sitetheme_custompages'][$key]) ? implode("\n", $pref['sitetheme_custompages'][$key]) : "")."</textarea></div>\n" : TPVLAN_55;
  998. $itext .= "</td>";
  999. $itext .= "<td>";
  1000. if(varset($val['menuPresets']))
  1001. {
  1002. $itext .= $this->renderPresets($key);
  1003. }
  1004. $itext .= "</td>
  1005. </tr>";
  1006. }
  1007. $itext .= "</table></td></tr>";
  1008. }
  1009. // $itext .= !$mode ? "<tr><td style='vertical-align:top;width:24%'><b>".TPVLAN_8."</b>:</td><td style='vertical-align:top'>".$previewbutton.$selectmainbutton.$selectadminbutton."</td></tr>" : "";
  1010. if($mode == 2)
  1011. {
  1012. $astext = "";
  1013. $file = e107::getFile();
  1014. $adminstyles = $file->get_files(e_ADMIN."includes");
  1015. $astext = "\n<select id='mode2' name='adminstyle' class='tbox'>\n";
  1016. foreach ($adminstyles as $as)
  1017. {
  1018. $style = str_replace(".php", "", $as['fname']);
  1019. $astext .= "<option value='{$style}'".($pref['adminstyle'] == $style ? " selected='selected'" : "").">".$style."</option>\n";
  1020. }
  1021. $astext .= "</select>";
  1022. $text .= "
  1023. <tr>
  1024. <td><b>".TPVLAN_41.":</b></td>
  1025. <td colspan='2'>".$astext."</td>
  1026. </tr>
  1027. \n";
  1028. }
  1029. $text .= $itext;
  1030. if(array_key_exists("multipleStylesheets", $theme) && $mode)
  1031. {
  1032. $text .= "
  1033. <tr><td style='vertical-align:top;'><b>".TPVLAN_22.":</b></td>
  1034. <td colspan='2' style='vertical-align:top'>
  1035. <table class='table adminlist' >
  1036. <tr>
  1037. <td class='center' style='width:10%'>".TPVLAN_55."</td>
  1038. <td style='width:20%'>".TPVLAN_52."</td>
  1039. <td class='left'>".TPVLAN_7."</td>
  1040. </tr>";
  1041. foreach ($theme['css'] as $css)
  1042. {
  1043. $text2 = "";
  1044. if($mode == 2) // ADMIN MODE
  1045. {
  1046. if($css['name'] == "style.css" || !vartrue($css['info'])) // Hide the admin css unless it has a header. eg. /* info: Default stylesheet */
  1047. {
  1048. continue;
  1049. }
  1050. if(!$css['nonadmin'])
  1051. {
  1052. $for = $frm->name2id("admincss-".$css['name']);
  1053. $text2 = "
  1054. <td class='center'>".
  1055. $frm->radio('admincss', $css['name'], vartrue($pref['admincss'])== $css['name'])."
  1056. </td>
  1057. <td><label for='".$for."'>".$css['info']."</label></td>";
  1058. $text2 .= "<td>".($css['info'] ? $css['info'] : ($css['name'] == "admin_style.css" ? TPVLAN_23 : TPVLAN_24))."</td>\n";
  1059. }
  1060. }
  1061. if($mode == 1) // SITE-THEME Mode
  1062. {
  1063. if(substr($css['name'], 0, 6) == "admin_")
  1064. {
  1065. continue;
  1066. }
  1067. $text2 = "
  1068. <td class='center'>
  1069. <input id='".$frm->name2id($css['name'])."' type='radio' name='themecss' value='".$css['name']."' ".($pref['themecss'] == $css['name'] || (!$pref['themecss'] && $css['name'] == "style.css") ? " checked='checked'" : "")." />
  1070. </td>
  1071. <td><label for='".$frm->name2id($css['name'])."' >".$css['name']."</lable></td>
  1072. <td>".($css['info'] ? $css['info'] : ($css['name'] == "style.css" ? TPVLAN_23 : TPVLAN_24))."</td>\n";
  1073. }
  1074. $text .= ($text2) ? "<tr>".$text2."</tr>" : "";
  1075. }
  1076. $text .= "</table></td></tr>";
  1077. }
  1078. /*
  1079. if($mode == 1)
  1080. {
  1081. $text .= $this->renderThemeConfig();
  1082. }
  1083. */
  1084. $text .= "</table>
  1085. <div class='center buttons-bar'>";
  1086. if($mode == 2) // admin
  1087. {
  1088. $mainid = "selectmain[".$theme['id']."]";
  1089. $text .= $this->frm->admin_button('submit_adminstyle', TPVLAN_35, 'update');
  1090. //$text .= $this->frm->admin_button($mainid, TPVLAN_10, 'other');
  1091. }
  1092. else // main
  1093. {
  1094. $adminid = "selectadmin[".$theme['id']."]";
  1095. $text .= $this->frm->admin_button('submit_style', TPVLAN_35, 'update');
  1096. //$text .= $this->frm->admin_button($adminid, TPVLAN_32, 'other');
  1097. }
  1098. $text .= "<input type='hidden' name='curTheme' value='".$theme['path']."' />";
  1099. $text .= "</div>
  1100. </div>
  1101. <div class='tab-pane' id='core-thememanager-help'>".$this->renderThemeHelp()."</div>
  1102. <div class='tab-pane' id='core-thememanager-customconfig'>
  1103. <table class='table adminform'>
  1104. <colgroup>
  1105. <col class='col-label' />
  1106. <col class='col-control' />
  1107. <col class='col-control' />
  1108. </colgroup>
  1109. ".$this->renderThemeConfig()."
  1110. </table>
  1111. </div>
  1112. </div>
  1113. \n";
  1114. return $text;
  1115. }
  1116. function renderPresets($key)
  1117. {
  1118. require_once (e_HANDLER."menumanager_class.php");
  1119. $frm = e107::getForm();
  1120. $men = new e_menuManager();
  1121. $men->curLayout = $key;
  1122. $preset = $men->getMenuPreset();
  1123. $text .= "<div class='btn-group pull-right'>".$frm->admin_button("setMenuPreset[".$key."]", "Activate Menus",'other');
  1124. $text .= '<button class="btn btn-primary dropdown-toggle" data-toggle="dropdown">
  1125. <span class="caret"></span>
  1126. </button>
  1127. <ul class="dropdown-menu col-selection">
  1128. <!-- dropdown menu links -->
  1129. <li><strong>Activate the following:</strong></li>
  1130. ';
  1131. foreach($preset as $val)
  1132. {
  1133. $text .= "<li><a title='".$val['menu_name']."'>".str_replace("_menu","",$val['menu_name'])."</a></li>";
  1134. }
  1135. // $itext .= "<div class='field-help'>".print_a($preset ,true)."</div>";
  1136. $text .= "</ul></div>";
  1137. return $text;
  1138. }
  1139. function renderPlugins($pluginOpts)
  1140. {
  1141. global $frm,$sql;
  1142. // if there is 1 entry, then it's not the same array.
  1143. $tmp = (varset($pluginOpts['plugin'][1])) ? $pluginOpts['plugin'] : $pluginOpts;
  1144. $text = "";
  1145. foreach ($tmp as $p)
  1146. {
  1147. $plug = trim($p['@attributes']['name']);
  1148. if(plugInstalled($plug))
  1149. {
  1150. $text .= $plug." ".ADMIN_TRUE_ICON;
  1151. }
  1152. else
  1153. {
  1154. // echo $plug;
  1155. if($sql->db_Select("plugin", "plugin_id", " plugin_path = '".$plug."' LIMIT 1 "))
  1156. {
  1157. $row = $sql->db_Fetch(MYSQL_ASSOC);
  1158. $name = "installplugin[".$row['plugin_id']."]";
  1159. $text .= $this->frm->admin_button($name, ADLAN_121." ".$plug."", 'delete');
  1160. }
  1161. else
  1162. {
  1163. $text .= (varset($p['@attributes']['url']) && ($p['@attributes']['url'] != 'core')) ? "<a rel='external' href='".$p['@attributes']['url']."'>".$plug."</a> " : "<i>".$plug."</i>";
  1164. $text .= ADMIN_FALSE_ICON;
  1165. }
  1166. }
  1167. $text .= "&nbsp;&nbsp;&nbsp;";
  1168. }
  1169. return $text;
  1170. }
  1171. function refreshPage($page = e_QUERY )
  1172. {
  1173. header("Location: ".e_SELF."?".$page);
  1174. exit;
  1175. }
  1176. function themePreview()
  1177. {
  1178. echo "<script type='text/javascript'>document.location.href='".e_BASE."index.php?themepreview.".$this->id."'</script>\n";
  1179. exit;
  1180. }
  1181. function showPreview()
  1182. {
  1183. include_lan(e_LANGUAGEDIR.e_LANGUAGE."/admin/lan_theme.php");
  1184. $text = "<br /><div class='indent'>".TPVLAN_1.".</div><br />";
  1185. global $ns;
  1186. $ns->tablerender(TPVLAN_2, $text);
  1187. }
  1188. /**
  1189. * Set Theme as Main Theme.
  1190. *
  1191. * @param string $name [optional] name (folder) of the theme to set.
  1192. * @return boolean TRUE on success, FALSE otherwise
  1193. */
  1194. function setTheme($name = '', $contentCheck = true)
  1195. {
  1196. $core = e107::getConfig('core');
  1197. $sql = e107::getDb();
  1198. $mes = e107::getMessage();
  1199. $themeArray = $this->getThemes("id");
  1200. $name = ($name) ? $name : vartrue($themeArray[$this->id]);
  1201. $layout = $pref['sitetheme_layouts'] = is_array($this->themeArray[$name]['layouts']) ? $this->themeArray[$name]['layouts'] : array();
  1202. $deflayout = $this->findDefault($name);
  1203. $customPages = $this->themeArray[$name]['custompages'];
  1204. $version = $this->themeArray[$name]['version'];
  1205. $core->set('sitetheme', $name);
  1206. $core->set('themecss', 'style.css');
  1207. $core->set('sitetheme_layouts', $layout);
  1208. $core->set('sitetheme_deflayout', $deflayout);
  1209. $core->set('sitetheme_custompages', $customPages);
  1210. $core->set('sitetheme_version', $version);
  1211. // $core->set('sitetheme_releaseUrl', $this->themeArray[$name]['releaseUrl']);
  1212. if($contentCheck === true)
  1213. {
  1214. $sql->db_Delete("menus", "menu_layout !='' ");
  1215. }
  1216. e107::getCache()->clear();
  1217. if($core->save())
  1218. {
  1219. //TODO LANs
  1220. $mes->addDebug("Default Layout: ".$deflayout);
  1221. $mes->addDebug("Custom Pages: ".print_a($customPages,true));
  1222. $med = e107::getMedia();
  1223. $med->import('_common_image', e_THEME.$name, "^.*?logo.*?(\.png|\.jpeg|\.jpg|\.JPG|\.GIF|\.PNG)$");
  1224. $med->import('_common_image', e_THEME.$name, '', 'min-size=20000');
  1225. if($contentCheck === true)
  1226. {
  1227. $this->installContentCheck($name);
  1228. }
  1229. $this->theme_adminlog('01', $name.', style.css');
  1230. return TRUE;
  1231. }
  1232. else
  1233. {
  1234. // $mes->add(TPVLAN_3." <b>'".$name."'</b>", E_MESSAGE_ERROR);
  1235. return FALSE;
  1236. }
  1237. }
  1238. function installContentCheck($name)
  1239. {
  1240. $file = e_THEME.$name."/install/install.xml";
  1241. $frm = e107::getForm();
  1242. if(!is_readable($file))
  1243. {
  1244. return false;
  1245. }
  1246. $mes = e107::getMessage();
  1247. $xmlArray = e107::getXml()-> loadXMLfile($file, 'advanced');
  1248. $text = "
  1249. <form action='".e_SELF."' method='post'>
  1250. <div>This theme would like to make the following changes to your database:
  1251. <ul>";
  1252. $lng = e107::getLanguage();
  1253. foreach($xmlArray['database']['dbTable'] as $key=>$val)
  1254. {
  1255. $count = count($val['item']);
  1256. $data = array('x'=> $count, 'y' => $val['@attributes']['name']);
  1257. $lan = "Replace/Overwrite [x] record(s) in your [y] table. ";
  1258. $text .= "<li>".$lng->translate($lan, $data)."</li>";
  1259. }
  1260. $text .= "</ul>
  1261. ".$frm->admin_button('installContent',$name, 'warning', "Agree")."
  1262. ".$frm->admin_button('dismiss',0, 'cancel', 'Dismiss')."
  1263. </div>
  1264. </form>
  1265. ";
  1266. // $text .= print_a($xmlArray, true);
  1267. $mes->addWarning($text);
  1268. }
  1269. function installContent($name)
  1270. {
  1271. $mes = e107::getMessage();
  1272. $file = e_THEME.$name."/install/install.xml";
  1273. e107::getXml()->e107Import($file, 'replace', true, false); // Overwrite specific core pref and tables entries.
  1274. $mes->addSuccess(LAN_UPDATED);
  1275. }
  1276. function findDefault($theme)
  1277. {
  1278. if(varset($_POST['layout_default']))
  1279. {
  1280. return $_POST['layout_default'];
  1281. }
  1282. $l = $this->themeArray[$theme];
  1283. if(!$l)
  1284. {
  1285. $l = $this->getThemeInfo($theme);
  1286. }
  1287. if($l['layouts'])
  1288. {
  1289. foreach ($l['layouts'] as $key=>$val)
  1290. {
  1291. if(isset($val['@attributes']['default']) && ($val['@attributes']['default'] == "true"))
  1292. {
  1293. return $key;
  1294. }
  1295. }
  1296. }
  1297. else
  1298. {
  1299. return "";
  1300. }
  1301. }
  1302. function setAdminTheme()
  1303. {
  1304. global $pref,$e107cache;
  1305. $ns = e107::getRender();
  1306. $mes = e107::getMessage();
  1307. $themeArray = $this->getThemes("id");
  1308. $pref['admintheme'] = $themeArray[$this->id];
  1309. $pref['admincss'] = file_exists(e_THEME.$pref['admintheme'].'/admin_dark.css') ? 'admin_dark.css' : 'admin_light.css';
  1310. $e107cache->clear_sys();
  1311. if(save_prefs())
  1312. {
  1313. // Default Message
  1314. $mes->add(TPVLAN_40." <b>'".$themeArray[$this->id]."'</b>", E_MESSAGE_SUCCESS);
  1315. $this->theme_adminlog('02', $pref['admintheme'].', '.$pref['admincss']);
  1316. }
  1317. // $ns->tablerender("Admin Message", "<br /><div style='text-align:center;…

Large files files are truncated, but you can click here to view the full file