frm = new e_form(); //enable inner tabindex counter if (isset($_POST['upload'])) { $this -> themeUpload(); } $this -> themeArray = $this -> getThemes(); foreach($_POST as $key => $post) { if(strstr($key,"preview")) { // $this -> id = str_replace("preview_", "", $key); $this -> id = key($post); $this -> themePreview(); } if(strstr($key,"selectmain")) { // $this -> id = str_replace("selectmain_", "", $key); $this -> id = key($post); $this -> setTheme(); } if(strstr($key,"selectadmin")) { $this -> id = key($post); $this -> setAdminTheme(); } } if(isset($_POST['submit_adminstyle'])) { $this -> id = $_POST['curTheme']; $this -> setAdminStyle(); } if(isset($_POST['submit_style'])) { $this -> id = $_POST['curTheme']; $this -> setStyle(); } } function getThemes($mode=FALSE) { $themeArray = array(); $tloop = 1; $handle = opendir(e_THEME); while (false !== ($file = readdir($handle))) { if ($file != "." && $file != ".." && $file != "CVS" && $file != "templates" && is_dir(e_THEME.$file) && is_readable(e_THEME.$file."/theme.php") ) { if($mode == "id") { $themeArray[$tloop] = $file; } else { $themeArray[$file]['id'] = $tloop; } $tloop++; $STYLESHEET = FALSE; if(!$mode) { $handle2 = opendir(e_THEME.$file."/"); while (false !== ($file2 = readdir($handle2))) // Read files in theme directory { if ($file2 != "." && $file2 != ".." && $file != "CVS" && !is_dir(e_THEME.$file."/".$file2)) { $themeArray[$file]['files'][] = $file2; if(strstr($file2, "preview.")) { $themeArray[$file]['preview'] = e_THEME.$file."/".$file2; } if(strstr($file2, "css") && !strstr($file2, "menu.css") && strpos($file2, "e_") !== 0 && strpos($file2, "admin_") !== 0) { /* get information string for css file */ $fp=fopen(e_THEME.$file."/".$file2, "r"); $cssContents = fread ($fp, filesize(e_THEME.$file."/".$file2)); fclose($fp); $nonadmin = preg_match('/\* Non-Admin(.*?)\*\//', $cssContents) ? true : false; preg_match('/\* info:(.*?)\*\//', $cssContents, $match); $match[1]=varset($match[1],''); $themeArray[$file]['css'][] = array("name" => $file2, "info" => $match[1], "nonadmin" => $nonadmin); if($STYLESHEET) { $themeArray[$file]['multipleStylesheets'] = TRUE; } else { $STYLESHEET = TRUE; } } } } // end while.. closedir($handle2); // Load Theme information and merge with existing array. theme.xml (0.8 themes) is given priority over theme.php (0.7). if(in_array("theme.xml",$themeArray[$file]['files']) ) { $themeArray[$file] = array_merge($themeArray[$file], $this->parse_theme_xml($file)); } elseif(in_array("theme.php",$themeArray[$file]['files'])) { $themeArray[$file] = array_merge($themeArray[$file], $this->parse_theme_php($file)); } } } } closedir($handle); /*echo "
";
		print_r($themeArray['e107v4a']);
		echo "
"; */ return $themeArray; } function themeUpload() { if (!$_POST['ac'] == md5(ADMINPWCHANGE)) { exit; } global $ns; extract($_FILES); if(!is_writable(e_THEME)) { $ns->tablerender(TPVLAN_16, TPVLAN_20); } else { require_once(e_HANDLER."upload_handler.php"); $fileName = $file_userfile['name'][0]; $fileSize = $file_userfile['size'][0]; $fileType = $file_userfile['type'][0]; if(strstr($file_userfile['type'][0], "gzip")) { $fileType = "tar"; } else if (strstr($file_userfile['type'][0], "zip")) { $fileType = "zip"; } else { $ns->tablerender(TPVLAN_16, TPVLAN_17); require_once("footer.php"); exit; } if ($fileSize) { $uploaded = file_upload(e_THEME); $archiveName = $uploaded[0]['name']; if($fileType == "zip") { require_once(e_HANDLER."pclzip.lib.php"); $archive = new PclZip(e_THEME.$archiveName); $unarc = ($fileList = $archive -> extract(PCLZIP_OPT_PATH, e_THEME, PCLZIP_OPT_SET_CHMOD, 0666)); } else { require_once(e_HANDLER."pcltar.lib.php"); $unarc = ($fileList = PclTarExtract($archiveName, e_THEME)); } if(!$unarc) { if($fileType == "zip") { $error = TPVLAN_46." '".$archive -> errorName(TRUE)."'"; } else { $error = TPVLAN_47.PclErrorString().", ".TPVLAN_48.intval(PclErrorCode()); } $ns->tablerender(TPVLAN_16, TPVLAN_18." ".$archiveName." ".$error); require_once("footer.php"); exit; } $folderName = substr($fileList[0]['stored_filename'], 0, (strpos($fileList[0]['stored_filename'], "/"))); $ns->tablerender(TPVLAN_16, "
".TPVLAN_19."
"); @unlink(e_THEME.$archiveName); } } } function showThemes($mode='main') { global $ns, $pref; echo "
\n"; if($mode == "main" || !$mode) // Show Main Configuration { foreach($this -> themeArray as $key => $theme) { if($key == $pref['sitetheme']) { $text = $this -> renderTheme(1, $theme); } } $ns->tablerender(TPVLAN_26." :: ".TPVLAN_33, $text); } if($mode == "admin") // Show Admin Configuration { foreach($this -> themeArray as $key => $theme) { if($key == $pref['admintheme']) { $text = $this -> renderTheme(2, $theme); } } $ns->tablerender(TPVLAN_26." :: ".TPVLAN_34, $text); } if($mode == "upload") // Show Upload Form { if(!is_writable(e_THEME)) { $ns->tablerender(TPVLAN_16, TPVLAN_15); $text = ""; } else { require_once(e_HANDLER.'upload_handler.php'); $max_file_size = get_user_max_upload(); $text = "
".TPVLAN_13."
"; $text .= $this->frm->admin_button('upload', TPVLAN_14, 'submit'); $text .= "

\n"; } $ns->tablerender(TPVLAN_26." :: ".TPVLAN_38, $text); } if($mode == "choose") // Show All Themes { $text = ""; foreach($this -> themeArray as $key => $theme) { // if($key != $pref['admintheme'] && $key != $pref['sitetheme']) // { $text .= $this -> renderTheme(FALSE, $theme); // } } $ns->tablerender(TPVLAN_26." :: ".TPVLAN_39, $text); } echo "
\n
\n"; } function renderThemeInfo($theme) { // TO-DO : This SHOULD be loaded by ajax before release. global $pref; $author = ($theme['email'] ? "".$theme['author']."" : $theme['author']); $website = ($theme['website'] ? "".$theme['website']."" : ""); $preview = "".($theme['preview'] ? "" : "").""; $text = "
".TPVLAN_7."
"; $text .= $author ? "" : ""; $text .= $website ? "" : ""; $text .= $theme['date'] ? "" : ""; $text .= ""; if($theme['layouts']) // New in 0.8 WORK IN PROGRESS ---- { $itext .= ""; } $text .= ""; $text .= $itext."
".TPVLAN_4.":".$author."
".TPVLAN_5.":".$website."
".TPVLAN_6.":".$theme['date']."
".TPVLAN_49.": XHTML "; $text .= ($theme['xhtmlcompliant']) ? ADMIN_TRUE_ICON : ADMIN_FALSE_ICON; $text .= "    CSS "; $text .= ($theme['csscompliant']) ? ADMIN_TRUE_ICON : ADMIN_FALSE_ICON; $text .= "
".TPVLAN_50.": "; $itext .= ($mode == 1) ? "" : ""; $itext .= " \n"; foreach($theme['layouts'] as $key=>$val) { $itext .= " "; if($mode == 1) { if(!$pref['sitetheme_deflayout']) { $pref['sitetheme_deflayout'] = ($val['@attributes']['default']=='true') ? $key : ""; // echo "------------- NODEFAULT"; } $itext .= " "; } $itext .= ""; } $itext .= "
DefaultTitle Requirements Menu Preset
"; $itext .= ($val['@attributes']['previewFull']) ? "" : ""; $itext .= $val['@attributes']['title']; $itext .= ($val['@attributes']['previewFull']) ? "" : ""; $itext .= ($pref['sitetheme_deflayout'] == $key) ? " (default)" : ""; $itext .= " ".$val['@attributes']['requiredPlugins']."  "; $itext .= ($val['menuPresets']) ? ADMIN_TRUE_ICON: " "; $itext .= "
".TPVLAN_22.": "; foreach($theme['css'] as $val) { $text .= $val['name']."
"; } $text .= "
"; $text .= "
Close
"; return $text; } function renderThemeConfig() // process custom theme configuration - TODO. { $confile = e_THEME.$this->id."/".$this->id."_config.php"; if(is_readable($confile)) { include_once($confile); if(function_exists($this->id."_config")) { $var = call_user_func($this->id."_config"); foreach($var as $val) { $text .= "".$val['caption'].":".$val['html'].""; } return $text; } } } function setThemeConfig() { $confile = e_THEME.$this->id."/".$this->id."_config.php"; include($confile); if(function_exists($this->id."_process")) { $text = call_user_func($this->id."_process"); } return $text; } function renderTheme($mode=FALSE, $theme) { /* mode = 0 :: normal mode = 1 :: selected site theme mode = 2 :: selected admin theme */ global $ns, $pref; $author = ($theme['email'] ? "".$theme['author']."" : $theme['author']); $website = ($theme['website'] ? "".$theme['website']."" : ""); $preview = "".($theme['preview'] ? "" : "").""; $previewbutton = (!$mode ? " " : ""); $main_icon = ($pref['sitetheme'] != $theme['path']) ? "\n" : ADMIN_TRUE_ICON; $info_icon = "\n"; $preview_icon = "\n"; $admin_icon = ($pref['admintheme'] != $theme['path']) ? "\n" : ADMIN_TRUE_ICON; $newpreview = "".($theme['preview'] ? "" : "").""; if(!$mode) // Choose a Theme to Install. { // styles NEED to be put into style.css $borderStyle = (($pref['sitetheme'] == $theme['path']) || ($pref['admintheme'] == $theme['path'])) ? "border:1px solid black" : "border:1px dotted silver;background-color:#DDDDDD"; $text = "
".$newpreview."
".$theme['name']." ".$theme['version']."
\n\n\n".$main_icon.$admin_icon.$info_icon.$preview_icon."\n\n
\n".$this->renderThemeInfo($theme)."
"; return $text; } $this->id = $theme['path']; $text = "
"; $text .= ""; $text .= ""; $text .= ""; $text .= ""; $text .= " "; if($mode == 1) { $text .= " "; } if($theme['layouts']) // New in 0.8 ---- { $itext .= ""; } // $itext .= !$mode ? "" : ""; $text .= $itext; if(array_key_exists("multipleStylesheets", $theme) && $mode) { $text .= " "; } if($mode == 2) { $astext = ""; require_once(e_HANDLER."file_class.php"); $file = new e_file; $adminstyles = $file -> get_files(e_ADMIN."includes"); $astext = "\n"; $text .= " \n"; } $text .= $this->renderThemeConfig(); $text .= "

".$theme['name']."

".TPVLAN_11."".$theme['version']." $newpreview
".TPVLAN_4.":".$author."
".TPVLAN_5.":".$website."
".TPVLAN_6.":".$theme['date']."
".TPVLAN_49.": XHTML "; $text .= ($theme['xhtmlcompliant']) ? ADMIN_TRUE_ICON : "X"; $text .= "    CSS "; $text .= ($theme['csscompliant']) ? ADMIN_TRUE_ICON : "X"; $text .= "
".TPVLAN_7.":".$theme['info']."
".TPVLAN_30." ".TPVLAN_28."   ".TPVLAN_29."
".TPVLAN_50.": "; $itext .= ($mode == 1) ? "" : ""; $itext .= " \n"; foreach($theme['layouts'] as $key=>$val) { $itext .= " "; if($mode == 1) { if(!$pref['sitetheme_deflayout']) { $pref['sitetheme_deflayout'] = ($val['@attributes']['default']=='true') ? $key : ""; // echo "------------- NODEFAULT"; } $itext .= " "; } $itext .= ""; } $itext .= "
".TPVLAN_55."".TPVLAN_52." ".TPVLAN_53." ".TPVLAN_54."
"; $itext .= ($val['@attributes']['previewFull']) ? "" : ""; $itext .= $val['@attributes']['title']; $itext .= ($val['@attributes']['previewFull']) ? "" : ""; $itext .= ($pref['sitetheme_deflayout'] == $key) ? " (default)" : ""; $itext .= " ".$val['@attributes']['requiredPlugins']."  "; $itext .= ($val['menuPresets']) ? ADMIN_TRUE_ICON : " "; $itext .= "
".TPVLAN_8.":".$previewbutton.$selectmainbutton.$selectadminbutton."
".TPVLAN_22.": \n"; foreach($theme['css'] as $css) { $text .= "\n"; if($mode == 2) { if (!$css['nonadmin']) { $text .= " \n"; } } if($mode == 1) { $text .= " \n"; } $text .= ""; } $text .= "
".TPVLAN_55." ".TPVLAN_52." ".TPVLAN_7."
".$css['name']." ".($css['info'] ? $css['info'] : ($css['name'] == "style.css" ? TPVLAN_23 : TPVLAN_24))." ".$css['name']." ".($css['info'] ? $css['info'] : ($css['name'] == "style.css" ? TPVLAN_23 : TPVLAN_24))."
".TPVLAN_41.": ".$astext."
"; if($mode == 2) // admin { $mainid = "selectmain[".$theme['id']."]"; $text .= $this->frm->admin_button('submit_adminstyle', TPVLAN_35, 'update'); $text .= $this->frm->admin_button($mainid, TPVLAN_10, 'submit'); } else // main { $adminid = "selectadmin[".$theme['id']."]"; $text .= $this->frm->admin_button('submit_style', TPVLAN_35, 'update'); $text .= $this->frm->admin_button($adminid, TPVLAN_32, 'submit'); } $text .= ""; $text .= "
\n"; return $text; } function themePreview() { echo "\n"; exit; } function showPreview() { include_lan(e_LANGUAGEDIR.e_LANGUAGE."/admin/lan_theme.php"); $text = "
".TPVLAN_1.".

"; global $ns; $ns->tablerender(TPVLAN_2, $text); } function setTheme() { global $pref, $e107cache, $ns; $themeArray = $this -> getThemes("id"); $pref['sitetheme'] = $themeArray[$this -> id]; $pref['themecss'] ='style.css'; $pref['sitetheme_deflayout'] = $this->findDefault($themeArray[$this -> id]); $pref['sitetheme_layouts'] = is_array($this->themeArray[$pref['sitetheme']]['layouts']) ? $this->themeArray[$pref['sitetheme']]['layouts'] : array(); $e107cache->clear_sys(); save_prefs(); $this->theme_adminlog('01',$pref['sitetheme'].', '.$pref['themecss']); $ns->tablerender("Admin Message", "
".TPVLAN_3." '".$themeArray[$this -> id]."'.

"); } function findDefault($theme) { if(varset($_POST['layout_default'])) { return $_POST['layout_default']; } $l = $this->themeArray[$theme]; foreach($l['layouts'] as $key=>$val) { if(isset($val['@attributes']['default']) && ($val['@attributes']['default'] == "true")) { return $key; } } } function setAdminTheme() { global $pref, $e107cache, $ns; $themeArray = $this -> getThemes("id"); $pref['admintheme'] = $themeArray[$this -> id]; $pref['admincss'] = file_exists(THEME.'admin_style.css') ? 'admin_style.css' : 'style.css'; $e107cache->clear_sys(); save_prefs(); $this->theme_adminlog('02',$pref['admintheme'].', '.$pref['admincss']); $ns->tablerender("Admin Message", "
".TPVLAN_40." '".$themeArray[$this -> id]."'.

"); // $this->showThemes('admin'); } function setStyle() { global $pref, $e107cache, $ns; $pref['themecss'] = $_POST['themecss']; $pref['image_preload'] = $_POST['image_preload']; $pref['sitetheme_deflayout'] = $_POST['layout_default']; $e107cache->clear_sys(); save_prefs(); $custom_message = $this -> setThemeConfig(); $this->theme_adminlog('03',$pref['image_preload'].', '.$pref['themecss']); $ns->tablerender(TPVLAN_36, "
".TPVLAN_37.".
".$custom_message."

"); } function setAdminStyle() { global $pref, $e107cache, $ns; $pref['admincss'] = $_POST['admincss']; $pref['adminstyle'] = $_POST['adminstyle']; $e107cache->clear_sys(); save_prefs(); $this->theme_adminlog('04',$pref['adminstyle'].', '.$pref['admincss']); $ns->tablerender(TPVLAN_36, "
".TPVLAN_43.".

"); } // Log event to admin log function theme_adminlog($msg_num='00', $woffle='') { global $pref, $admin_log; // if (!varset($pref['admin_log_log']['admin_banlist'],0)) return; $admin_log->log_event('THEME_'.$msg_num,$woffle,E_LOG_INFORMATIVE,''); } function parse_theme_php($path) { $fp=fopen(e_THEME.$path."/theme.php", "r"); $themeContents = fread ($fp, filesize(e_THEME.$path."/theme.php")); fclose($fp); preg_match('/themename(\s*?=\s*?)("|\')(.*?)("|\');/si', $themeContents, $match); $themeArray['name'] = varset($match[3],''); preg_match('/themeversion(\s*?=\s*?)("|\')(.*?)("|\');/si', $themeContents, $match); $themeArray['version'] = varset($match[3],''); preg_match('/themeauthor(\s*?=\s*?)("|\')(.*?)("|\');/si', $themeContents, $match); $themeArray['author'] = varset($match[3],''); preg_match('/themeemail(\s*?=\s*?)("|\')(.*?)("|\');/si', $themeContents, $match); $themeArray['email'] = varset($match[3],''); preg_match('/themewebsite(\s*?=\s*?)("|\')(.*?)("|\');/si', $themeContents, $match); $themeArray['website'] = varset($match[3],''); preg_match('/themedate(\s*?=\s*?)("|\')(.*?)("|\');/si', $themeContents, $match); $themeArray['date'] = varset($match[3],''); preg_match('/themeinfo(\s*?=\s*?)("|\')(.*?)("|\');/si', $themeContents, $match); $themeArray['info'] = varset($match[3],''); preg_match('/xhtmlcompliant(\s*?=\s*?)(\S*?);/si', $themeContents, $match); $xhtml = strtolower($match[2]); $themeArray['xhtmlcompliant'] = ($xhtml == "true" ? true : false); preg_match('/csscompliant(\s*?=\s*?)(\S*?);/si', $themeContents, $match); $css = strtolower($match[2]); $themeArray['csscompliant'] = ($css == "true" ? true : false); if (!$themeArray['name']) { unset($themeArray); } $themeArray['path'] = $path; return $themeArray; } function parse_theme_xml($path) { global $tp; // loadLanFiles($path, 'admin'); // Look for LAN files on default paths require_once(e_HANDLER.'xml_class.php'); $xml = new xmlClass; $vars = $xml->loadXMLfile(e_THEME.$path.'/theme.xml', true, true); $vars['name'] = varset($vars['@attributes']['name']); $vars['version'] = varset($vars['@attributes']['version']); $vars['date'] = varset($vars['@attributes']['date']); $vars['compatibility'] = varset($vars['@attributes']['compatibility']); $vars['email'] = varset($vars['author']['@attributes']['email']); $vars['website'] = varset($vars['author']['@attributes']['url']); $tmp = varset($vars['author']['@attributes']['name']); $vars['author'] = $tmp; $vars['info'] = $vars['description']; $vars['xhtmlcompliant'] = (strtolower($vars['compliance']['@attributes']['xhtml']) == 'true' ? 1 : 0); $vars['csscompliant'] = (strtolower($vars['compliance']['@attributes']['css']) == 'true' ? 1 : 0); $vars['path'] = $path; $vars['@attributes']['default'] = (strtolower($vars['@attributes']['default'])=='true') ? 1 : 0; unset($vars['authorEmail'],$vars['authorUrl'],$vars['xhtmlCompliant'],$vars['cssCompliant'],$vars['description']); // Compile layout information into a more usable format. foreach($vars['layouts'] as $layout) { foreach($layout as $key=>$val) { $name = $val['@attributes']['name']; unset($val['@attributes']['name']); $lays[$name] = $val; } } $vars['layouts'] = $lays; $vars['path'] = $path; return $vars; } } ?>