From 2f724e6b682f69f3a9bfa31b3f761beb8ae7c0d0 Mon Sep 17 00:00:00 2001 From: CaMer0n Date: Mon, 17 Nov 2008 07:17:23 +0000 Subject: [PATCH] theme.xml parser and theming improvements - a work in progress. --- e107_handlers/theme_handler.php | 298 ++++++++++++++------- e107_languages/English/admin/lan_theme.php | 11 +- e107_themes/e107v4a/theme.php | 65 ++++- e107_themes/e107v4a/theme.xml | 15 +- e107_themes/templates/header_default.php | 13 +- 5 files changed, 303 insertions(+), 99 deletions(-) diff --git a/e107_handlers/theme_handler.php b/e107_handlers/theme_handler.php index 58ad1fa79..6ecac8f25 100644 --- a/e107_handlers/theme_handler.php +++ b/e107_handlers/theme_handler.php @@ -11,9 +11,9 @@ | GNU General Public License (http://gnu.org). | | $Source: /cvs_backup/e107_0.8/e107_handlers/theme_handler.php,v $ -| $Revision: 1.11 $ -| $Date: 2008-11-02 10:28:25 $ -| $Author: e107steved $ +| $Revision: 1.12 $ +| $Date: 2008-11-17 07:17:23 $ +| $Author: e107coders $ +----------------------------------------------------------------------------+ */ @@ -70,95 +70,78 @@ class themeHandler{ function getThemes($mode=FALSE) { $themeArray = array(); + $themeArray[0] = ""; // Fix for 'preview theme'. $tloop = 1; $handle = opendir(e_THEME); - while (false !== ($file = readdir($handle))) + while (false !== ($file = readdir($handle))) { - if ($file != "." && $file != ".." && $file != "CVS" && $file != "templates" && is_dir(e_THEME.$file) && file_exists(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)) + if ($file != "." && $file != ".." && $file != "CVS" && $file != "templates" && is_dir(e_THEME.$file) && is_readable(e_THEME.$file."/theme.php") ) + { + if($mode == "id") { - $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; - } - } + $themeArray[$tloop] = $file; } - - - if($file2=='theme.php') + else { - $fp=fopen(e_THEME.$file."/theme.php", "r"); - $themeContents = fread ($fp, filesize(e_THEME.$file."/theme.php")); - fclose($fp); - preg_match('/themename(\s*?=\s*?)("|\')(.*?)("|\');/si', $themeContents, $match); - $themeArray[$file]['name'] = varset($match[3],''); - preg_match('/themeversion(\s*?=\s*?)("|\')(.*?)("|\');/si', $themeContents, $match); - $themeArray[$file]['version'] = varset($match[3],''); - preg_match('/themeauthor(\s*?=\s*?)("|\')(.*?)("|\');/si', $themeContents, $match); - $themeArray[$file]['author'] = varset($match[3],''); - preg_match('/themeemail(\s*?=\s*?)("|\')(.*?)("|\');/si', $themeContents, $match); - $themeArray[$file]['email'] = varset($match[3],''); - preg_match('/themewebsite(\s*?=\s*?)("|\')(.*?)("|\');/si', $themeContents, $match); - $themeArray[$file]['website'] = varset($match[3],''); - preg_match('/themedate(\s*?=\s*?)("|\')(.*?)("|\');/si', $themeContents, $match); - $themeArray[$file]['date'] = varset($match[3],''); - preg_match('/themeinfo(\s*?=\s*?)("|\')(.*?)("|\');/si', $themeContents, $match); - $themeArray[$file]['info'] = varset($match[3],''); - - preg_match('/xhtmlcompliant(\s*?=\s*?)(\S*?);/si', $themeContents, $match); - $xhtml = strtolower($match[2]); - $themeArray[$file]['xhtmlcompliant'] = ($xhtml == "true" ? true : false); - - preg_match('/csscompliant(\s*?=\s*?)(\S*?);/si', $themeContents, $match); - $css = strtolower($match[2]); - $themeArray[$file]['csscompliant'] = ($css == "true" ? true : false); - - if (!$themeArray[$file]['name']) - { - unset($themeArray[$file]); - } + $themeArray[$file]['id'] = $tloop; } - } - closedir($handle2); - } - } + $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; } @@ -169,9 +152,12 @@ class themeHandler{ } global $ns; extract($_FILES); - if(!is_writable(e_THEME)) { + if(!is_writable(e_THEME)) + { $ns->tablerender(TPVLAN_16, TPVLAN_20); - } else { + } + else + { require_once(e_HANDLER."upload_handler.php"); $fileName = $file_userfile['name'][0]; $fileSize = $file_userfile['size'][0]; @@ -304,11 +290,13 @@ class themeHandler{ mode = 2 :: selected admin theme */ + define("IMAGE_CHECK",""); + global $ns, $pref, $imode; $author = ($theme['email'] ? "".$theme['author']."" : $theme['author']); $website = ($theme['website'] ? "".$theme['website']."" : ""); - $preview = "".($theme['preview'] ? "" : "").""; + $preview = "".($theme['preview'] ? "" : "").""; $selectmainbutton = ($mode != 1 ? "" : ""); $selectadminbutton = ($mode != 2 ? "" : ""); $previewbutton = (!$mode ? " " : ""); @@ -327,8 +315,66 @@ class themeHandler{ $itext = $author ? "".TPVLAN_4.":".$author."" : ""; $itext .= $website ? "".TPVLAN_5.":".$website."" : ""; $itext .= $theme['date'] ? "".TPVLAN_6.":".$theme['date']."" : ""; + $itext .= "".TPVLAN_49.": + XHTML "; + $itext .= ($theme['xhtmlcompliant']) ? IMAGE_CHECK : "X"; + $itext .= "    CSS "; + $itext .= ($theme['csscompliant']) ? IMAGE_CHECK : "X"; + $itext .= ""; + if($theme['xhtmlcompliant'] || $theme['xhtmlcompliant']) + + + + $itext .= $theme['info'] ? "".TPVLAN_7.":".$theme['info']."" : ""; - $itext .= !$mode ? "".TPVLAN_8.":".$previewbutton.$selectmainbutton.$selectadminbutton."" : ""; + + if($theme['layouts']) // New in 0.8 WORK IN PROGRESS ---- + { + $itext .= " + ".TPVLAN_50.": + + "; + $itext .= ($mode == 1) ? "" : ""; + $itext .= " + + + + \n"; + + foreach($theme['layouts'] as $key=>$val) + { + $itext .= " + "; + if($mode == 1) + { + if(!$pref['theme_deflayout']) + { + $pref['theme_deflayout'] = ($val['@attributes']['default']) ? $key : ""; + } + $itext .= " + "; + } + + $itext .= " + + + "; + } + + $itext .= "
DefaultTitleRequirementsMenu Preset
+ + "; + $itext .= ($val['@attributes']['previewFull']) ? "" : ""; + $itext .= $val['@attributes']['title']; + $itext .= ($val['@attributes']['previewFull']) ? "" : ""; + $itext .= ($pref['theme_deflayout'] == $key) ? " (default)" : ""; + $itext .= "".$val['@attributes']['requiredPlugins']." "; + $itext .= ($val['menuPresets']) ? IMAGE_CHECK : " "; + $itext .= "
"; + } + + + $itext .= !$mode ? "".TPVLAN_8.":".$previewbutton.$selectmainbutton.$selectadminbutton."" : ""; if ($itext) { @@ -377,7 +423,7 @@ class themeHandler{ $text .= " - @@ -413,13 +459,13 @@ class themeHandler{
".TPVLAN_30." + ".TPVLAN_30." ".TPVLAN_28."   ".TPVLAN_29."
\n"; } - if($theme['xhtmlcompliant'] || $theme['xhtmlcompliant']) + /*if($theme['xhtmlcompliant'] || $theme['xhtmlcompliant']) { $text .= "
"; $text .= ($theme['xhtmlcompliant']) ? " ": ""; $text .= ($theme['csscompliant']) ? " " : ""; $text .= "
"; - } + }*/ $text .= "\n"; return $text; @@ -469,6 +515,7 @@ class themeHandler{ global $pref, $e107cache, $ns; $pref['themecss'] = $_POST['themecss']; $pref['image_preload'] = $_POST['image_preload']; + $pref['theme_deflayout'] = $_POST['layout_default']; $e107cache->clear_sys(); save_prefs(); $this->theme_adminlog('03',$pref['image_preload'].', '.$pref['themecss']); @@ -495,5 +542,76 @@ class themeHandler{ $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); + } + return $themeArray; + } + + function parse_theme_xml($path) + { + global $tp; + // include_lan_admin($path); // 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['email'] = $vars['authorEmail']; + $vars['website'] = $vars['authorUrl']; + $vars['info'] = $vars['description']; + $vars['xhtmlcompliant'] = (strtolower($vars['xhtmlCompliant']) == "true") ? 1 : 0; + $vars['csscompliant'] = (strtolower($vars['cssCompliant']) == "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; + + return $vars; + } + } ?> \ No newline at end of file diff --git a/e107_languages/English/admin/lan_theme.php b/e107_languages/English/admin/lan_theme.php index 819a8c1ab..0b152e055 100644 --- a/e107_languages/English/admin/lan_theme.php +++ b/e107_languages/English/admin/lan_theme.php @@ -4,9 +4,9 @@ | e107 website system - Language File. | | $Source: /cvs_backup/e107_0.8/e107_languages/English/admin/lan_theme.php,v $ -| $Revision: 1.2 $ -| $Date: 2007-02-04 21:42:55 $ -| $Author: e107steved $ +| $Revision: 1.3 $ +| $Date: 2008-11-17 07:17:23 $ +| $Author: e107coders $ +----------------------------------------------------------------------------+ */ define("TPVLAN_1", "You are looking at a preview of the '".PREVIEWTHEMENAME."' theme. It has not been set as the main theme for your site, it has been activated to provide a preview of how the theme looks.
To set this theme as your site theme, return to your theme manager and select 'Set As Site Theme'.
To preview more themes please click here"); @@ -64,4 +64,9 @@ define("TPVLAN_46", "PCLZIP extract error:"); define("TPVLAN_47", "PCLTAR extract error: "); define("TPVLAN_48", "code:"); +define("TPVLAN_49", "Compliance"); +define("TPVLAN_50", "Layouts"); + + + ?> \ No newline at end of file diff --git a/e107_themes/e107v4a/theme.php b/e107_themes/e107v4a/theme.php index 0f0298192..5214f2fe6 100644 --- a/e107_themes/e107v4a/theme.php +++ b/e107_themes/e107v4a/theme.php @@ -11,8 +11,8 @@ | GNU General Public License (http://gnu.org). | | $Source: /cvs_backup/e107_0.8/e107_themes/e107v4a/theme.php,v $ -| $Revision: 1.3 $ -| $Date: 2008-02-23 23:51:39 $ +| $Revision: 1.4 $ +| $Date: 2008-11-17 07:17:23 $ | $Author: e107coders $ +----------------------------------------------------------------------------+ */ @@ -99,6 +99,67 @@ $FOOTER['3_column'] = "; +// 2 Column Layout ------------------------------------------------------------ + +$HEADER['2_column'] = +" + + + + + +
+{CUSTOM=clock} + +{CUSTOM=search+".THEME_ABS."images/search.png+18+19} +
+ + + + + + + + + + + + + + + + + +
+{SITELINKS=menu} +{MENU=1} +"; + + +$FOOTER['2_column'] = +"
+ +{SITEDISCLAIMER} +
+{THEME_DISCLAIMER} +
+
+ + + + + +
+  +{MENU=3} + +{MENU=4} +
+
"; function rand_tag(){ $tags = file(e_BASE."files/taglines.txt"); diff --git a/e107_themes/e107v4a/theme.xml b/e107_themes/e107v4a/theme.xml index 02e1d818e..cd65710ef 100644 --- a/e107_themes/e107v4a/theme.xml +++ b/e107_themes/e107v4a/theme.xml @@ -12,6 +12,19 @@ true true - + + + + + + + + + + + + + + \ No newline at end of file diff --git a/e107_themes/templates/header_default.php b/e107_themes/templates/header_default.php index b71fc8448..ea903ca81 100644 --- a/e107_themes/templates/header_default.php +++ b/e107_themes/templates/header_default.php @@ -6,9 +6,9 @@ | Released under the terms and conditions of the GNU General Public License (http://gnu.org). | | $Source: /cvs_backup/e107_0.8/e107_themes/templates/header_default.php,v $ -| $Revision: 1.23 $ -| $Date: 2008-11-09 20:31:10 $ -| $Author: secretr $ +| $Revision: 1.24 $ +| $Date: 2008-11-17 07:17:23 $ +| $Author: e107coders $ +-----------------------------------------------------------------------------------------------+ */ @@ -444,6 +444,13 @@ if ($e107_popup != 1) { // // M: Send top of body for custom pages and for news // + $def = $pref['theme_deflayout']; + if(is_array($HEADER) && isset($HEADER[$def]) && isset($FOOTER[$def])) + { + $HEADER = $HEADER[$def]; + $FOOTER = $FOOTER[$def]; + } + if(isset($CUSTOMPAGES)) { if (is_array($CUSTOMPAGES))