diff --git a/e107_admin/theme.php b/e107_admin/theme.php index 627824e9d..2c1189696 100644 --- a/e107_admin/theme.php +++ b/e107_admin/theme.php @@ -193,16 +193,16 @@ if($mode == 'download' && !empty($_GET['src'])) echo $mes->render('default', 'debug'); } -elseif(vartrue($_POST['selectadmin'])) +elseif(!empty($_POST['selectadmin'])) { $mode = "admin"; } -if(vartrue($_POST['upload'])) +if(!empty($_POST['upload'])) { $mode = "upload"; } -elseif(vartrue($_POST['selectmain']) || varset($_POST['setUploadTheme'])) +elseif(!empty($_POST['selectmain']) || isset($_POST['setUploadTheme'])) { $mode = "main"; } @@ -248,7 +248,7 @@ function theme_adminmenu() $var['upload']['text'] = TPVLAN_38; $var['upload']['link'] = e_SELF."?mode=upload"; - $var['convert']['text'] = TPVLAN_63; + $var['convert']['text'] = ADLAN_CL_6; $var['convert']['link'] = e_SELF."?mode=convert"; // $selected = (e_QUERY) ? e_QUERY : "main"; @@ -264,7 +264,28 @@ class theme_builder function __construct() { - $this->themeName = $_GET['newtheme']; + + $ns = e107::getRender(); + $tp = e107::getParser(); + + e107::getMessage()->addDebug("Disable debug to save generated files. "); + + + $this->themeName = $tp->filter($_GET['newtheme'],'w'); + + if(!empty($_GET['src'])) + { + $this->themeSrc = $tp->filter($_GET['src'],'w'); + $this->copyTheme(); + /* $src = $tp->filter($_GET['src'],'w'); + $name = $tp->filter($_GET['f']); + $title = $tp->filter($_GET['t']); + + $this->copyTheme($src,$name,$title);*/ + + } + + if(vartrue($_GET['step']) == 3) { @@ -278,8 +299,21 @@ class theme_builder } else { - $this->step1(); + $ret = $this->step1(); + $ret2 = $this->copyThemeForm(); + + $tabs = array( + 0 => array('caption'=>$ret['caption'], 'text'=>$ret['text']), + 1 => array('caption'=>$ret2['caption'], 'text'=>$ret2['text']), + + ); + + $ns->tablerender(ADLAN_140.SEP."Tools",e107::getForm()->tabs($tabs)); } + + + + } @@ -315,6 +349,7 @@ class theme_builder + ".TPVLAN_68." ".$frm->select("newtheme",$newDir)." @@ -328,13 +363,15 @@ class theme_builder "; */ - $text .= " + $text .= "
".$frm->admin_button('step', 2,'other',LAN_GO)."
"; $text .= $frm->close(); + + return array('caption'=>TPVLAN_88, 'text'=>$mes->render() . $text); $ns->tablerender(TPVLAN_26.SEP.TPVLAN_88.SEP. TPVLAN_CONV_1, $mes->render() . $text); @@ -351,11 +388,13 @@ class theme_builder $data = array( 'main' => array('name','lang','version','date', 'compatibility'), - 'author' => array('name','url'), + 'author' => array('name','url'), 'summary' => array('summary'), 'description' => array('description'), + 'keywords' => array('one','two'), 'category' => array('category'), + 'livedemo' => array('livedemo'), 'copyright' => array('copyright'), 'stylesheets' => array('stylesheets') // 'adminLinks' => array('url','description','icon','iconSmall','primary'), @@ -363,24 +402,63 @@ class theme_builder ); $legacyFile = e_THEME.$this->themeName."/theme.php"; - if(file_exists($legacyFile)) + + + + $newThemeXML = e_THEME.$this->themeName."/theme.xml"; + if(file_exists($newThemeXML)) { - $legacyData = file_get_contents($legacyFile); - + $info = e107::getTheme()->getThemeInfo($this->themeName); + + e107::getDebug()->log($info); + + if($this->themeSrc) // New theme copied from another + { + $defaults = array( + "main-name" => ucfirst($this->themeName), + 'category-category' => vartrue($info['category']), + ); + } + else + { + $defaults = array( + "main-name" => vartrue($info['name']), + "main-date" => vartrue($info['date']), + "main-version" => vartrue($info['version']), + "author-name" => vartrue($info['author']), + "author-url" => vartrue($info['website']), + "description-description" => vartrue($info['description']), + "summary-summary" => vartrue($info['summary']), + 'category-category' => vartrue($info['category']), + // "custompages" => vartrue($leg['CUSTOMPAGES']), + ); + } + + if(!empty($info['keywords']['word'])) + { + $defaults['keywords-one'] = $info['keywords']['word'][0]; + $defaults['keywords-two'] = $info['keywords']['word'][1]; + } + + } + elseif(file_exists($legacyFile)) + { + $legacyData = file_get_contents($legacyFile); + $regex = '/\$([\w]*)\s*=\s*("|\')([\w @.\/:<\>,\'\[\] !()]*)("|\');/im'; preg_match_all($regex, $legacyData, $matches); - + $leg = array(); - + foreach($matches[1] as $i => $m) { - $leg[$m] = strip_tags($matches[3][$i]); + $leg[$m] = strip_tags($matches[3][$i]); if(substr($m,0,5) == 'theme' || $m == "CUSTOMPAGES") { - $search[] = $matches[0][$i]; - } + $search[] = $matches[0][$i]; + } } - + $defaults = array( "main-name" => vartrue($leg['themename']), "author-name" => vartrue($leg['themeauthor']), @@ -389,16 +467,16 @@ class theme_builder "summary-summary" => vartrue($leg['themeinfo']), "custompages" => vartrue($leg['CUSTOMPAGES']), ); - + $search[] = "Steve Dunstan"; $search[] = "jalist@e107.org"; - + $_SESSION['themebulder-remove'] = $search; - - $mes->addInfo("Loading theme.php file"); - } + + $mes->addInfo("Loading theme.php file"); + } - $text = $frm->open('newtheme-step3','post', e_SELF.'?mode=convert&newtheme='.$this->themeName.'&step=3'); + $text = $frm->open('newtheme-step3','post', e_SELF.'?mode=convert&src='.$this->themeSrc.'&newtheme='.$this->themeName.'&step=3'); $text .= ""; foreach($data as $key=>$val) { @@ -421,14 +499,16 @@ class theme_builder $text .= "
"; $text .= "
" - .$frm->hidden('newtheme', $this->themeName) - .$frm->hidden('xml[custompages]', trim(vartrue($leg['CUSTOMPAGES']))) + .$frm->hidden('newtheme', $this->themeName); + $text .= $frm->hidden('xml[custompages]', trim(vartrue($leg['CUSTOMPAGES']))) .$frm->admin_button('step', 3,'other',LAN_GENERATE)."
"; $text .= $frm->close(); - $ns->tablerender(TPVLAN_26.SEP.TPVLAN_88.SEP. TPVLAN_CONV_2, $mes->render() . $text); + // return array('caption'=>TPVLAN_88.SEP. TPVLAN_CONV_2, 'text'=>$mes->render() . $text); + + $ns->tablerender(TPVLAN_26.SEP.ADLAN_CL_6.SEP. TPVLAN_CONV_2, $mes->render() . $text); } @@ -439,56 +519,28 @@ class theme_builder // print_a($_POST); - if($_POST['xml']) + if(!empty($_POST['xml'])) { $xmlText = $this->createXml($_POST['xml']); - } - - $ns->tablerender("theme.xml", $mes->render(). "
".$xmlText."
"); - + $ns->tablerender("theme.xml", $mes->render(). "
".$xmlText."
"); + } + + $legacyFile = e_THEME.$this->themeName."/theme.php"; - if(file_exists($legacyFile)) + if(file_exists($legacyFile) && empty($this->themeSrc)) { - $legacyData = file_get_contents($legacyFile); + $legacyData = file_get_contents($legacyFile); + $legacyData = e107::getTheme()->upgradeThemeCode($legacyData); + + $output = nl2br(htmlentities($legacyData)); + + $ns->tablerender("theme.php (updated)", $output); } - $legacyData = $this->cleanUp($legacyData); - - $output = nl2br(htmlentities($legacyData)); - - // $legacyData = str_replace("\n\n\n","\n",$legacyData); - - $ns->tablerender("theme.php (updated)", $output); + } - function cleanUp($text) - { - $search = array(); - $replace = array(); - - $search[0] = '$HEADER '; - $replace[0] = '$HEADER["default"] '; - - $search[1] = '$FOOTER '; - $replace[1] = '$FOOTER["default"] '; - - // Early 0.6 and 0.7 Themes - - $search[2] = '$CUSTOMHEADER '; - $replace[2] = '$HEADER["custom"] '; - - $search[3] = '$CUSTOMFOOTER '; - $replace[3] = '$FOOTER["custom"] '; - - //TODO Handle v1.x style themes. eg. $CUSTOMHEADER['something']; - - $text = str_replace($_SESSION['themebulder-remove'],"",$text); - - $text = str_replace($search, $replace, $text); - - return $text; - } function createXml($data) @@ -503,7 +555,7 @@ class theme_builder $newArray[$key] = $val; } - if(vartrue($newArray['CUSTOMPAGES'])) + if(!empty($newArray['CUSTOMPAGES'])) { $newArray['CUSTOMPAGES'] = trim($newArray['CUSTOMPAGES']); $LAYOUTS = "\n\n"; @@ -515,15 +567,24 @@ class theme_builder $LAYOUTS = ""; } - if(vartrue($newArray['STYLESHEETS_STYLESHEETS'])) + if(!empty($newArray['STYLESHEETS_STYLESHEETS'])) { - $STYLESHEETS = "\n\t\n"; + $STYLESHEETS = ''; foreach($newArray['STYLESHEETS_STYLESHEETS'] as $val) { + if(empty($val['file'])) + { + continue; + } + $STYLESHEETS .= "\t\t\n"; } - $STYLESHEETS .= "\t"; - + + if(!empty($STYLESHEETS)) + { + $STYLESHEETS = "\n\t\n".$STYLESHEETS."\t"; + } + unset($newArray['STYLESHEETS_STYLESHEETS']); } else @@ -538,15 +599,15 @@ class theme_builder $template = <<