";
// $text .= '
';
$text .= "
";
$text .= $this->search('srch', $_GET['srch'], 'go');
$gets = $this->getController()->getQuery();
foreach($gets as $k=>$v)
{
if($k == 'srch' || $k == 'go')
{
continue;
}
$text .= $this->hidden($k,$v);
}
$text .= $this->renderPagination();
$text .= "
";
return $text;
}*/
function options()
{
$theme = $this->getController()->getListModel()->getData();
if($this->getController()->getAction() === 'online')
{
return $this->onlineOptions($theme);
}
else
{
return $this->chooseOptions($theme);
}
}
private function chooseOptions($theme)
{
$pref = e107::getPref();
$tp = e107::getParser();
$infoPath = e_SELF."?mode=".$_GET['mode']."&id=".$theme['path']."&action=info&iframe=1";
$previewPath = $tp->replaceConstants($theme['thumbnail'],'abs');
$disabled = '';
$mainTitle = TPVLAN_10;
// if(version_compare($compat,$version, '<=') === false)
if(!e107::isCompatible($theme['compatibility']))
{
$disabled = 'disabled';
$mainTitle = defset('TPVLAN_97', "This theme requires a newer version of e107.");
}
$main_icon = ($pref['sitetheme'] !== $theme['path']) ? "
" : "
";
$info_icon = "
".$tp->toGlyph('fa-info-circle',array('size'=>'2x'))."";
$admin_icon = '';
if(in_array($theme['path'], $this->approvedAdminThemes))
{
$admin_icon = ($pref['admintheme'] !== $theme['path'] ) ? "
" : "
";
}
$preview_icon = "
".$tp->toGlyph('fa-search',array('size'=>'2x'))."";
return $main_icon.$admin_icon.$info_icon.$preview_icon;
}
private function onlineOptions($theme)
{
$tp = e107::getParser();
$preview_icon = '';
$srcData = array(
'id' => $theme['id'],
'url' => $theme['url'],
'mode' => $theme['mode'],
'price' => $theme['price']
);
e107::getSession()->set('thememanager/online/'.$theme['id'], $theme);
$d = http_build_query($srcData,false,'&');
$base64 = base64_encode($d);
$id = $this->name2id($theme['name']);
if(!empty($theme['price'])) // Premium Theme
{
$LAN_DOWNLOAD = LAN_PURCHASE."/".LAN_DOWNLOAD;
$downloadUrl = e_SELF.'?mode=main&action=download&src='.base64_encode($d); // no iframe.
$mainTarget = '_blank';
$mainClass = '';
$modalCaption = ' '.LAN_PURCHASE.' '.$theme['name']." ".$theme['version'];
}
else // Free Theme
{
$LAN_DOWNLOAD = LAN_DOWNLOAD;
$downloadUrl = e_SELF.'?mode=main&iframe=1&action=download&src='.base64_encode($d);//$url.'&action=download';
$mainTarget = '_self';
$mainClass = 'e-modal';
$modalCaption = ' '.LAN_DOWNLOADING.' '.$theme['name']." ".$theme['version'];
}
// $url = e_SELF."?src=".$base64;
$infoUrl = e_SELF.'?mode=main&iframe=1&action=info&src='.$base64;
// $viewUrl = $theme['url'];
$main_icon = "
".$tp->toGlyph('fa-download',array('size'=>'2x'))."";
$info_icon = "
".$tp->toGlyph('fa-info-circle',array('size'=>'2x'))."";
if(!empty($theme['preview'][0]))
{
$previewPath = $theme['preview'][0];
if(!empty($theme['livedemo']))
{
$previewPath = $theme['livedemo'];
}
$preview_icon = "
".$tp->toGlyph('fa-search',array('size'=>'2x'))."";
}
return $main_icon.$info_icon.$preview_icon;
}
}
class theme_builder extends e_admin_ui
{
var $themeName = "";
var $remove = array();
function init()
{
}
function MainPage()
{
$ns = e107::getRender();
$tp = e107::getParser();
e107::getMessage()->addDebug("Disable debug to save generated files. ");
if(!empty($_GET['newtheme']))
{
$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)
{
return $this->step3();
}
if(vartrue($_GET['step']) == 2)
{
return $this->step2();
}
else
{
$ret = $this->step1();
$ret2 = $this->copyThemeForm();
$tabs = array(
0 => array('caption'=>$ret['caption'], 'text'=>$ret['text']),
1 => array('caption'=>$ret2['caption'], 'text'=>$ret2['text']),
);
return e107::getForm()->tabs($tabs);
// $text = $ns->tablerender(ADLAN_140.SEP.ADLAN_CL_6,e107::getForm()->tabs($tabs));
}
}
function step1()
{
$fl = e107::getFile();
$frm = e107::getForm();
$ns = e107::getRender();
$mes = e107::getMessage();
$plugFolders = $fl->get_dirs(e_THEME);
foreach($plugFolders as $dir)
{
if(file_exists(e_THEME.$dir."/theme.xml") || $dir == 'templates')
{
continue;
}
$newDir[$dir] = $dir;
}
$mes->addInfo(' '.TPVLAN_64.'
'.TPVLAN_65.'
- '.TPVLAN_66.'
- '.TPVLAN_67.'
');
$text = $frm->open('createPlugin','get',e_SELF."?mode=convert");
$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);
}
function step2()
{
$ns = e107::getRender();
$mes = e107::getMessage();
$frm = e107::getForm();
$data = array(
'main' => array('name','lang','version','date', 'compatibility'),
'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'),
// 'sitelinks' => array('url','description','icon','iconSmall')
);
$legacyFile = e_THEME.$this->themeName."/theme.php";
$newThemeXML = e_THEME.$this->themeName."/theme.xml";
if(file_exists($newThemeXML))
{
$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]);
if(strpos($m,'theme') === 0 || $m == "CUSTOMPAGES")
{
$search[] = $matches[0][$i];
}
}
$defaults = array(
"main-name" => vartrue($leg['themename']),
"author-name" => vartrue($leg['themeauthor']),
"author-url" => vartrue($leg['themewebsite']),
"description-description" => '',
"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");
}
$text = $frm->open('newtheme-step3','post', e_SELF.'?mode=convert&src='.$this->themeSrc.'&newtheme='.$this->themeName.'&step=3');
$text .= "
";
foreach($data as $key=>$val)
{
$text.= "$key |
";
foreach($val as $type)
{
$nm = $key.'-'.$type;
$name = "xml[$nm]";
$size = (count($val)==1) ? 'col-md-7' : 'col-md-2';
$text .= " ".$this->xmlInput($name, $key."-". $type, vartrue($defaults[$nm]))." ";
}
$text .= " |
";
}
$text .= "
";
$text .= "
"
.$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();
// return array('caption'=>TPVLAN_88.SEP. TPVLAN_CONV_2, 'text'=>$mes->render() . $text);
$this->addTitle(TPVLAN_CONV_2);
return $text;
//$ns->tablerender(TPVLAN_26.SEP.ADLAN_CL_6.SEP. TPVLAN_CONV_2, $mes->render() . $text);
}
function step3()
{
$ns = e107::getRender();
$mes = e107::getMessage();
// print_a($_POST);
$text = '';
if(!empty($_POST['xml']))
{
$xmlText = $this->createXml($_POST['xml']);
$text = $mes->render(). "
".$xmlText."
";
// $ns->tablerender("theme.xml", $mes->render(). "
".$xmlText."
");
}
$legacyFile = e_THEME.$this->themeName."/theme.php";
if(file_exists($legacyFile) && empty($this->themeSrc))
{
$legacyData = file_get_contents($legacyFile);
$legacyData = e107::getTheme()->upgradeThemeCode($legacyData);
$output = nl2br(htmlentities($legacyData));
$text .= $output;
// $ns->tablerender("theme.php (updated)", $output);
}
return $text;
}
function createXml($data)
{
$ns = e107::getRender();
$mes = e107::getMessage();
$tp = e107::getParser();
foreach($data as $key=>$val)
{
$key = strtoupper(str_replace("-","_",$key));
$newArray[$key] = $val;
}
if(!empty($newArray['CUSTOMPAGES']))
{
$newArray['CUSTOMPAGES'] = trim($newArray['CUSTOMPAGES']);
$LAYOUTS = "\n
\n";
$LAYOUTS .= " {CUSTOMPAGES}\n";
$LAYOUTS .= " ";
}
else
{
$LAYOUTS = "";
}
if(!empty($newArray['STYLESHEETS_STYLESHEETS']))
{
$STYLESHEETS = '';
foreach($newArray['STYLESHEETS_STYLESHEETS'] as $val)
{
if(empty($val['file']))
{
continue;
}
$STYLESHEETS .= "\t\t
\n";
}
if(!empty($STYLESHEETS))
{
$STYLESHEETS = "\n\t
\n".$STYLESHEETS."\t";
}
unset($newArray['STYLESHEETS_STYLESHEETS']);
}
else
{
$STYLESHEETS = "";
}
$newArray['STYLESHEETS'] = $STYLESHEETS;
// print_a($newArray);
$template = <<
{SUMMARY_SUMMARY}
{DESCRIPTION_DESCRIPTION}
{CATEGORY_CATEGORY}
{KEYWORDS_ONE}
{KEYWORDS_TWO}
{COPYRIGHT_COPYRIGHT}
preview.jpg
fullpreview.jpg
{STYLESHEETS}
{LAYOUTS}
TEMPLATE;
$template = str_replace("{LAYOUTS}",$LAYOUTS, $template);
$result = e107::getParser()->simpleParse($template, $newArray);
$path = e_THEME.$this->themeName."/theme.xml";
if(E107_DEBUG_LEVEL > 0)
{
$mes->addDebug("Debug Mode active - no file saved. ");
return htmlentities($result);
}
if(file_put_contents($path,$result))
{
$mes->addSuccess("Saved: ".$path);
}
else
{
$mes->addError("Couldn't Save: ".$path);
}
return htmlentities($result);
}
function xmlInput($name, $info, $default='')
{
$frm = e107::getForm();
list($cat,$type) = explode("-",$info);
$size = 30;
$help = '';
$sizex = '';
switch ($info)
{
case 'main-name':
$help = TPVLAN_CONV_3;
$required = true;
$pattern = "[A-Za-z 0-9]*";
break;
case 'main-lang':
$help = TPVLAN_CONV_4;
$required = false;
$placeholder= "LAN equivalent";
$pattern = "[A-Z0-9_]*";
break;
case 'main-date':
$help = TPVLAN_CONV_6;
$required = true;
$default = (empty($default)) ? time() : strtotime($default);
break;
case 'main-version':
$default = '1.0';
$required = true;
$help = TPVLAN_CONV_5;
$pattern = "^[\d]{1,2}\.[\d]{1,2}$";
break;
case 'main-compatibility':
$default = '2.0';
$required = true;
$help = TPVLAN_CONV_7;
$pattern = "^[\d]{1,2}\.[\d]{1,2}$";
break;
case 'author-name':
$default = (vartrue($default)) ? $default : USERNAME;
$required = true;
$help = TPVLAN_CONV_8;
$pattern = "[A-Za-z \.0-9]*";
break;
case 'author-url':
$required = true;
$help = TPVLAN_CONV_9;
// $pattern = "https?://.+";
break;
case 'livedemo-livedemo':
$required = false;
$help = TPVLAN_CONV_16;
$placeholder= "http://demo-of-my-theme.com";
// $pattern = "https?://.+";
break;
//case 'main-installRequired':
// return "Installation required: ".$frm->radio_switch($name,'',LAN_YES, LAN_NO);
//break;
case 'summary-summary':
$help = TPVLAN_CONV_10;
$required = true;
$size = 200;
$placeholder= " ";
$pattern = "[A-Za-z,() \.0-9]*";
break;
case 'keywords-one':
case 'keywords-two':
$help = TPVLAN_CONV_11;
$required = true;
$size = 20;
$placeholder= " ";
$pattern = '^[a-z]*$';
break;
case 'description-description':
$help = TPVLAN_CONV_12;
$required = true;
$size = 100;
$placeholder = " ";
$pattern = "[A-Za-z \.0-9]*";
break;
case 'category-category':
$help = TPVLAN_CONV_13;
$required = true;
$size = 20;
break;
default:
break;
}
$req = ($required == true) ? "&required=1" : "";
$placeholder = (varset($placeholder)) ? $placeholder : $type;
$pat = ($pattern) ? "&pattern=".$pattern : "";
$text = '';
switch ($type)
{
case 'stylesheets':
$fl = e107::getFile();
$fl->setMode('full');
$stylesheets = $fl->get_files(e_THEME.$this->themeName."/", "\.css", null, 1);
foreach($stylesheets as $key=>$path)
{
$file = str_replace(e_THEME.$this->themeName."/",'',$path);
$text .= "";
$text .= "
";
$text .= "
".$frm->checkbox($name.'['.$key.'][file]',$file, false, array('label'=>$file))."
".TPVLAN_CONV_14."
";
$text .= "
".$frm->text($name.'['.$key.'][name]', $default, $size, 'placeholder='.$file . $req. $pat)."
".TPVLAN_CONV_15."
";
// $text .= "
".$frm->checkbox('css['.$key.'][file]',$file, false, array('label'=>$file))."
";
// $text .= "
".$frm->text('css['.$key.'][name]', $default, $size, 'placeholder='.$placeholder . $req. $pat)."
";
$text .= "
";
$text .= "
";
}
return $text;
break;
case 'date':
$text = $frm->datepicker($name, $default, 'format=yyyy-mm-dd'.$req.'&size=block-level');
break;
case 'description':
$text = $frm->textarea($name,$default, 3, 100, $req.'&size=block-level'); // pattern not supported.
break;
case 'category':
$allowedCategories = array(
'generic', 'adult', 'blog', 'clan', 'children',
'corporate', 'forum', 'gaming', 'gallery', 'news',
'social', 'video', 'multimedia');
sort($allowedCategories);
$text = $frm->select($name, $allowedCategories,$default,'useValues=1&required=1', true);
break;
default:
$text = $frm->text($name, $default, $size, 'placeholder='.$placeholder . $req. $pat.'&size=block-level');
break;
}
$text .= ($help) ? "".$help."" : "";
return $text;
}
function copyThemeForm()
{
$frm = e107::getForm();
$folders = e107::getTheme()->clearCache()->getList('id'); // array_keys($list);
$text = $frm->open('copytheme','get','theme.php?mode=convert');
$text .= "
".$frm->admin_button('step', 2,'success', LAN_CREATE)."
";
$text .= $frm->close();
// $text = "Create a new theme based on ".e->select('copytheme',$list);
return array('caption'=>LAN_CREATE, 'text'=>$text);
}
private function copyTheme()
{
if(empty($this->themeSrc) || empty($this->themeName) || is_dir(e_THEME.$this->themeName))
{
return false;
}
if(e107::getFile()->copy(e_THEME.$this->themeSrc, e_THEME.$this->themeName))
{
$newfiles = scandir(e_THEME.$this->themeName);
foreach($newfiles as $file)
{
if(is_dir(e_THEME.$this->themeName.'/'.$file) || $file === '.' || $file === '..')
{
continue;
}
if(strpos($file,"admin_") === 0)
{
unlink(e_THEME.$this->themeName.'/'.$file);
}
}
}
return null;
}
}
/*
* After initialization we'll be able to call dispatcher via e107::getAdminUI()
* so this is the first we should do on admin page.
* Global instance variable is not needed.
* NOTE: class is auto-loaded - see class2.php __autoload()
*/
/* $dispatcher = */
new theme_admin();
/*
* Uncomment the below only if you disable the auto observing above
* Example: $dispatcher = new theme_admin(null, null, false);
*/
//$dispatcher->runObservers(true);
require_once(e_ADMIN."auth.php");
/*
* Send page content
*/
e107::getAdminUI()->runPage();
require_once(e_ADMIN."footer.php");
/* OBSOLETE - see admin_shortcodes::sc_admin_menu()
function admin_config_adminmenu()
{
//global $rp;
//$rp->show_options();
e107::getRegistry('admin/blank_dispatcher')->renderMenu();
}
*/
/* OBSOLETE - done within header.php
function headerjs() // needed for the checkboxes - how can we remove the need to duplicate this code?
{
return e107::getAdminUI()->getHeader();
}
*/