1
0
mirror of https://github.com/e107inc/e107.git synced 2025-01-17 12:48:24 +01:00
php-e107/e107_handlers/theme_handler.php

1376 lines
39 KiB
PHP
Raw Normal View History

2009-10-28 23:52:56 +00:00
<?php
2006-12-02 04:36:16 +00:00
/*
* e107 website system
*
* Copyright (C) 2001-2008 e107 Inc (e107.org)
* Released under the terms and conditions of the
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt)
*
* e107 Admin Theme Handler
*
* $Source: /cvs_backup/e107_0.8/e107_handlers/theme_handler.php,v $
* $Revision: 1.61 $
* $Date: 2009-11-02 01:10:50 $
* $Author: e107coders $
2009-10-28 23:45:46 +00:00
*/
2006-12-02 04:36:16 +00:00
2009-10-28 23:45:46 +00:00
if(!defined('e107_INIT'))
{
exit;
}
2006-12-02 04:36:16 +00:00
/**
* Base e107 Admin Theme Handler
*
* @package e107
* @category e107_handlers
* @version 1.0
* @author Cameron
* @copyright Copyright (c) 2009, e107 Inc.
*/
2009-10-28 23:45:46 +00:00
class themeHandler
{
2009-10-28 23:52:56 +00:00
2006-12-02 04:36:16 +00:00
var $themeArray;
var $action;
var $id;
2009-07-06 05:59:42 +00:00
var $frm;
var $fl;
2009-08-17 11:25:01 +00:00
var $themeConfigObj = null;
2009-09-17 00:13:40 +00:00
var $noLog = FALSE;
2009-10-28 23:45:46 +00:00
public $allowedCategories = array('generic',
'adult',
'blog',
'clan',
'children',
'corporate',
'forum',
'gaming',
'gallery',
'news',
'social',
'video',
'multimedia');
2006-12-02 04:36:16 +00:00
/* constructor */
2009-10-28 23:45:46 +00:00
function themeHandler()
{
2009-10-28 23:52:56 +00:00
global $emessage,$e107cache,$pref;
2009-10-28 23:45:46 +00:00
require_once (e_HANDLER."form_handler.php");
2009-10-28 23:52:56 +00:00
//enable inner tabindex counter
$this->frm = new e_form();
2009-10-28 23:45:46 +00:00
$this->fl = e107::getFile();
2009-07-06 05:59:42 +00:00
2009-10-28 23:45:46 +00:00
if(isset($_POST['upload']))
{
2009-10-28 23:45:46 +00:00
$this->themeUpload();
2006-12-02 04:36:16 +00:00
}
2009-10-28 23:45:46 +00:00
$this->themeArray = (defined('E107_INSTALL')) ? $this->getThemes('xml') : $this->getThemes();
// print_a($this -> themeArray);
foreach ($_POST as $key=>$post)
2006-12-02 04:36:16 +00:00
{
2009-10-28 23:45:46 +00:00
if(strstr($key, "preview"))
2006-12-02 04:36:16 +00:00
{
2009-10-28 23:45:46 +00:00
// $this -> id = str_replace("preview_", "", $key);
$this->id = key($post);
$this->themePreview();
2006-12-02 04:36:16 +00:00
}
2009-10-28 23:45:46 +00:00
if(strstr($key, "selectmain"))
2006-12-02 04:36:16 +00:00
{
2009-10-28 23:45:46 +00:00
// $this -> id = str_replace("selectmain_", "", $key);
$this->id = key($post);
$this->setTheme();
2006-12-02 04:36:16 +00:00
}
2009-10-28 23:45:46 +00:00
if(strstr($key, "selectadmin"))
2006-12-02 04:36:16 +00:00
{
2009-10-28 23:45:46 +00:00
$this->id = key($post);
$this->setAdminTheme();
$this->refreshPage('admin');
2006-12-02 04:36:16 +00:00
}
}
2009-10-28 23:45:46 +00:00
2006-12-02 04:36:16 +00:00
if(isset($_POST['submit_adminstyle']))
{
2009-10-28 23:45:46 +00:00
$this->id = $_POST['curTheme'];
if($this->setAdminStyle())
{
eMessage::getInstance()->add(TPVLAN_43, E_MESSAGE_SUCCESS);
}
e107::getConfig()->save(true);
2006-12-02 04:36:16 +00:00
}
2009-10-28 23:45:46 +00:00
2006-12-02 04:36:16 +00:00
if(isset($_POST['submit_style']))
{
2009-10-28 23:45:46 +00:00
$this->id = $_POST['curTheme'];
$this->SetCustomPages($_POST['custompages']);
$this->setStyle();
e107::getConfig()->save(true);
2009-10-28 23:52:56 +00:00
2006-12-02 04:36:16 +00:00
}
2009-10-28 23:45:46 +00:00
if(isset($_POST['installplugin']))
{
$key = key($_POST['installplugin']);
2009-10-28 23:45:46 +00:00
include_lan(e_LANGUAGEDIR.e_LANGUAGE."/admin/lan_plugin.php");
2009-10-28 23:45:46 +00:00
require_once (e_HANDLER."plugin_class.php");
$eplug = new e107plugin;
2009-10-28 23:45:46 +00:00
$message = $eplug->install_plugin($key);
$emessage->add($message, E_MESSAGE_SUCCESS);
}
2009-10-28 23:45:46 +00:00
if(isset($_POST['setMenuPreset']))
{
2009-10-28 23:45:46 +00:00
$key = key($_POST['setMenuPreset']);
include_lan(e_LANGUAGEDIR.e_LANGUAGE."/admin/lan_menus.php");
require_once (e_HANDLER."menumanager_class.php");
2009-08-16 16:30:56 +00:00
$men = new e_menuManager();
$men->curLayout = $key;
2009-10-28 23:52:56 +00:00
//menu_layout is left blank when it's default.
$men->dbLayout = ($men->curLayout != $pref['sitetheme_deflayout']) ? $men->curLayout : "";
2009-10-28 23:45:46 +00:00
if($areas = $men->menuSetPreset())
{
2009-10-28 23:45:46 +00:00
foreach ($areas as $val)
{
2009-10-28 23:45:46 +00:00
$ar[$val['menu_location']][] = $val['menu_name'];
}
2009-10-28 23:45:46 +00:00
foreach ($ar as $k=>$v)
{
2009-10-28 23:45:46 +00:00
$message .= MENLAN_14." ".$k." : ".implode(", ", $v)."<br />";
}
2009-10-28 23:45:46 +00:00
$emessage->add(MENLAN_43." : ".$key."<br />".$message, E_MESSAGE_SUCCESS);
}
2009-10-28 23:52:56 +00:00
}
2009-10-28 23:52:56 +00:00
2009-10-28 23:45:46 +00:00
}
2006-12-02 04:36:16 +00:00
2009-10-28 23:45:46 +00:00
function getThemes($mode = FALSE)
2006-12-02 04:36:16 +00:00
{
$themeArray = array();
2009-10-28 23:45:46 +00:00
2006-12-02 04:36:16 +00:00
$tloop = 1;
$handle = opendir(e_THEME);
2009-10-28 23:45:46 +00:00
while(false !== ($file = readdir($handle)))
{
2009-09-17 00:13:40 +00:00
if(($mode == 'xml') && !is_readable(e_THEME.$file."/theme.xml"))
{
continue;
}
2009-10-28 23:45:46 +00:00
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;
2006-12-02 04:36:16 +00:00
}
else
{
$themeArray[$file] = $this->getThemeInfo($file);
$themeArray[$file]['id'] = $tloop;
2006-12-02 04:36:16 +00:00
}
$tloop++;
2009-10-28 23:45:46 +00:00
}
}
2009-10-28 23:45:46 +00:00
closedir($handle);
/*
echo "<pre>";
print_r($themeArray);
echo "</pre>";*/
2009-10-28 23:45:46 +00:00
return $themeArray;
}
2009-10-28 23:45:46 +00:00
function getThemeInfo($file)
{
2009-10-28 23:45:46 +00:00
$STYLESHEET = FALSE;
$reject = array('$.',
'$..',
'/',
'CVS',
'thumbs.db',
'*._$',
'index',
'null*',
'e_*');
$handle2 = $this->fl->get_files(e_THEME.$file."/", ".php|.css|.xml|preview.jpg|preview.png", $reject, 1);
foreach ($handle2 as $fln)
{
$file2 = str_replace(e_THEME.$file."/", "", $fln['path']).$fln['fname'];
$themeArray[$file]['files'][] = $file2;
if(strstr($file2, "preview."))
{
$themeArray[$file]['preview'] = e_THEME.$file."/".$file2;
}
2009-10-28 23:45:46 +00:00
// ---------------- get information string for css file
2009-10-28 23:45:46 +00:00
if(strstr($file2, "css") && !strstr($file2, "menu.css") && strpos($file2, "e_") !== 0)
{
2009-10-28 23:52:56 +00:00
2009-10-28 23:45:46 +00:00
if($fp = fopen(e_THEME.$file."/".$file2, "r"))
{
// FIXME: use info from theme.xml alternateStyleSheet instead
$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)
{
2009-10-28 23:45:46 +00:00
$themeArray[$file]['multipleStylesheets'] = TRUE;
}
else
{
2009-10-28 23:45:46 +00:00
$STYLESHEET = TRUE;
}
}
}
2009-10-28 23:52:56 +00:00
2009-10-28 23:45:46 +00:00
} // end while..
2009-10-28 23:45:46 +00:00
// echo "<hr />";
// 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));
}
2009-10-28 23:45:46 +00:00
return $themeArray[$file];
2009-10-28 23:52:56 +00:00
2006-12-02 04:36:16 +00:00
}
2009-10-28 23:45:46 +00:00
2009-09-02 02:38:50 +00:00
/**
* Validate and return the name of the category
* @param object $categoryfromXML
2009-10-28 23:45:46 +00:00
* @return
2009-09-02 02:38:50 +00:00
*/
2009-10-28 23:45:46 +00:00
function getThemeCategory($categoryfromXML = '')
2009-09-02 02:38:50 +00:00
{
2009-09-17 00:13:40 +00:00
if(!$categoryfromXML)
{
2009-10-28 23:45:46 +00:00
return 'generic';
2009-09-17 00:13:40 +00:00
}
2009-10-28 23:45:46 +00:00
$tmp = explode(",", $categoryfromXML);
2009-09-02 02:38:50 +00:00
$category = array();
2009-10-28 23:45:46 +00:00
foreach ($tmp as $cat)
2009-09-02 02:38:50 +00:00
{
$cat = trim($cat);
2009-10-28 23:45:46 +00:00
if(in_array($cat, $this->allowedCategories))
2009-09-02 02:38:50 +00:00
{
$category[] = $cat;
}
else
{
2009-10-28 23:45:46 +00:00
$category[] = 'generic';
2009-09-02 02:38:50 +00:00
}
}
2009-10-28 23:45:46 +00:00
return implode(', ', $category);
2009-10-28 23:52:56 +00:00
2009-09-02 02:38:50 +00:00
}
2009-10-28 23:45:46 +00:00
2006-12-02 04:36:16 +00:00
function themeUpload()
{
2009-10-28 23:45:46 +00:00
if(!$_POST['ac'] == md5(ADMINPWCHANGE))
{
2006-12-02 04:36:16 +00:00
exit;
}
global $ns,$emessage;
2006-12-02 04:36:16 +00:00
extract($_FILES);
if(!is_writable(e_THEME))
{
2009-10-28 23:45:46 +00:00
// $ns->tablerender(TPVLAN_16, TPVLAN_20);
$emessage->add(TPVLAN_20, E_MESSAGE_INFO);
return FALSE;
}
else
{
2009-10-28 23:45:46 +00:00
require_once (e_HANDLER."upload_handler.php");
2006-12-02 04:36:16 +00:00
$fileName = $file_userfile['name'][0];
$fileSize = $file_userfile['size'][0];
$fileType = $file_userfile['type'][0];
2009-10-28 23:45:46 +00:00
if(strstr($file_userfile['type'][0], "gzip"))
{
2006-12-02 04:36:16 +00:00
$fileType = "tar";
2009-10-28 23:45:46 +00:00
}
else
if(strstr($file_userfile['type'][0], "zip"))
{
2006-12-02 04:36:16 +00:00
$fileType = "zip";
2009-10-28 23:45:46 +00:00
}
else
{
$emessage->add(TPVLAN_17, E_MESSAGE_ERROR);
2009-10-28 23:45:46 +00:00
// $ns->tablerender(TPVLAN_16, TPVLAN_17);
// require_once("footer.php");
return FALSE;
2006-12-02 04:36:16 +00:00
}
2009-10-28 23:45:46 +00:00
if($fileSize)
{
2009-10-28 23:52:56 +00:00
2006-12-02 04:36:16 +00:00
$uploaded = file_upload(e_THEME);
2009-10-28 23:45:46 +00:00
2006-12-02 04:36:16 +00:00
$archiveName = $uploaded[0]['name'];
2009-10-28 23:45:46 +00:00
if($fileType == "zip")
{
require_once (e_HANDLER."pclzip.lib.php");
2006-12-02 04:36:16 +00:00
$archive = new PclZip(e_THEME.$archiveName);
2009-10-28 23:45:46 +00:00
$unarc = ($fileList = $archive->extract(PCLZIP_OPT_PATH, e_THEME, PCLZIP_OPT_SET_CHMOD, 0666));
}
else
{
require_once (e_HANDLER."pcltar.lib.php");
2006-12-02 04:36:16 +00:00
$unarc = ($fileList = PclTarExtract($archiveName, e_THEME));
}
2009-10-28 23:45:46 +00:00
if(!$unarc)
{
if($fileType == "zip")
{
2009-10-28 23:45:46 +00:00
$error = TPVLAN_46." '".$archive->errorName(TRUE)."'";
}
else
{
$error = TPVLAN_47.PclErrorString().", ".TPVLAN_48.intval(PclErrorCode());
2006-12-02 04:36:16 +00:00
}
2009-10-28 23:45:46 +00:00
$emessage->add(TPVLAN_18." ".$archiveName." ".$error, E_MESSAGE_ERROR);
2009-10-28 23:45:46 +00:00
// $ns->tablerender(TPVLAN_16, TPVLAN_18." ".$archiveName." ".$error);
return FALSE;
2006-12-02 04:36:16 +00:00
}
2009-10-28 23:45:46 +00:00
2006-12-02 04:36:16 +00:00
$folderName = substr($fileList[0]['stored_filename'], 0, (strpos($fileList[0]['stored_filename'], "/")));
$emessage->add(TPVLAN_19, E_MESSAGE_SUCCESS);
2009-10-28 23:45:46 +00:00
if(varset($_POST['setUploadTheme']))
{
$themeArray = $this->getThemes();
$this->id = $themeArray[$folderName]['id'];
2009-10-28 23:45:46 +00:00
$this->setTheme();
2009-10-28 23:52:56 +00:00
}
2009-10-28 23:45:46 +00:00
// $ns->tablerender(TPVLAN_16, "<div class='center'>".TPVLAN_19."</div>");
2006-12-02 04:36:16 +00:00
@unlink(e_THEME.$archiveName);
}
}
}
2009-10-28 23:45:46 +00:00
function showThemes($mode = 'main')
2006-12-02 04:36:16 +00:00
{
global $ns,$pref,$emessage;
2009-10-28 23:45:46 +00:00
echo "<div>
2009-07-06 05:59:42 +00:00
<form enctype='multipart/form-data' method='post' action='".e_SELF."?".$mode."'>\n";
2009-10-28 23:45:46 +00:00
if($mode == "main" || !$mode) // Show Main Configuration
2006-12-02 04:36:16 +00:00
{
2009-10-28 23:45:46 +00:00
foreach ($this->themeArray as $key=>$theme)
2006-12-02 04:36:16 +00:00
{
2009-07-06 05:59:42 +00:00
if($key == $pref['sitetheme'])
{
2009-10-28 23:45:46 +00:00
$text = $this->renderTheme(1, $theme);
2009-07-06 05:59:42 +00:00
}
2006-12-02 04:36:16 +00:00
}
2009-10-28 23:45:46 +00:00
$ns->tablerender(TPVLAN_26." :: ".TPVLAN_33, $emessage->render().$text);
}
2009-10-28 23:52:56 +00:00
// Show Admin Configuration
if($mode == "admin")
2006-12-02 04:36:16 +00:00
{
2009-10-28 23:52:56 +00:00
2009-10-28 23:45:46 +00:00
foreach ($this->themeArray as $key=>$theme)
2006-12-02 04:36:16 +00:00
{
2009-07-06 05:59:42 +00:00
if($key == $pref['admintheme'])
{
2009-10-28 23:45:46 +00:00
$text = $this->renderTheme(2, $theme);
2009-07-06 05:59:42 +00:00
}
2006-12-02 04:36:16 +00:00
}
2009-10-28 23:45:46 +00:00
$ns->tablerender(TPVLAN_26." :: ".TPVLAN_34, $emessage->render().$text);
}
2009-10-28 23:52:56 +00:00
// Show Upload Form
if($mode == "upload")
{
2009-10-28 23:45:46 +00:00
$this->renderUploadForm();
2009-07-10 14:25:23 +00:00
}
2009-10-28 23:45:46 +00:00
2009-10-28 23:52:56 +00:00
// Show All Themes
if($mode == "choose")
2009-07-10 14:25:23 +00:00
{
$text = "";
2009-10-28 23:45:46 +00:00
foreach ($this->themeArray as $key=>$theme)
2009-07-10 14:25:23 +00:00
{
2009-10-28 23:45:46 +00:00
$text .= $this->renderTheme(FALSE, $theme);
2009-07-10 14:25:23 +00:00
}
2009-10-28 23:45:46 +00:00
$text .= "<div class='clear'>&nbsp;</div>";
$ns->tablerender(TPVLAN_26." :: ".TPVLAN_39, $emessage->render().$text);
2009-07-10 14:25:23 +00:00
}
2009-10-28 23:45:46 +00:00
2009-07-10 14:25:23 +00:00
echo "</form>\n</div>\n";
}
2009-10-28 23:45:46 +00:00
function renderUploadForm()
2009-07-10 14:25:23 +00:00
{
global $sql,$ns,$emessage;
2009-10-28 23:45:46 +00:00
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 = "
2009-07-10 14:25:23 +00:00
<div style='text-align:center'>
<table cellpadding='0' cellspacing='0' class='adminform'>
<colgroup span='2'>
<col class='col-label' />
<col class='col-control' />
</colgroup>
2009-07-06 05:59:42 +00:00
<tr>
2009-07-10 14:25:23 +00:00
<td>".TPVLAN_13."</td>
<td>
2009-07-06 05:59:42 +00:00
<input type='hidden' name='MAX_FILE_SIZE' value='{$max_file_size}' />
<input type='hidden' name='ac' value='".md5(ADMINPWCHANGE)."' />
<input class='tbox' type='file' name='file_userfile[]' size='50' />
</td>
</tr>
<tr>
<td>".TPVLAN_10."</td>
<td>
<input type='checkbox' name='setUploadTheme' value='1' />
2009-07-06 05:59:42 +00:00
</td>
</tr>
</table>
2009-07-10 14:25:23 +00:00
<div class='buttons-bar center'>";
2009-10-28 23:52:56 +00:00
2009-10-28 23:45:46 +00:00
$text .= $this->frm->admin_button('upload', TPVLAN_14, 'submit');
$text .= "
2009-07-10 14:25:23 +00:00
</div>
</div>\n";
2009-10-28 23:45:46 +00:00
}
$ns->tablerender(TPVLAN_26." :: ".TPVLAN_38, $emessage->render().$text);
2009-07-10 14:25:23 +00:00
}
2009-10-28 23:45:46 +00:00
function renderThemeInfo($theme)
2006-12-02 04:36:16 +00:00
{
2009-10-28 23:52:56 +00:00
2009-07-06 05:59:42 +00:00
// TO-DO : This SHOULD be loaded by ajax before release.
2009-10-28 23:45:46 +00:00
global $pref;
2006-12-02 04:36:16 +00:00
$author = ($theme['email'] ? "<a href='mailto:".$theme['email']."' title='".$theme['email']."'>".$theme['author']."</a>" : $theme['author']);
$website = ($theme['website'] ? "<a href='".$theme['website']."' rel='external'>".$theme['website']."</a>" : "");
$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>";
2009-10-28 23:45:46 +00:00
$text = "<div style='font-weight:bold;margin-bottom:10px'>".TPVLAN_7."</div>
2009-07-10 14:25:23 +00:00
<table class='adminlist' cellpadding='0' cellspacing='0'>";
$text .= $author ? "<tr><td style='vertical-align:top; width:24%'><b>".TPVLAN_4."</b>:</td><td style='vertical-align:top'>".$author."</td></tr>" : "";
$text .= $website ? "<tr><td style='vertical-align:top; width:24%'><b>".TPVLAN_5."</b>:</td><td style='vertical-align:top'>".$website."</td></tr>" : "";
$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>" : "";
$text .= "<tr><td style='vertical-align:top; width:24%'><b>".TPVLAN_49."</b>:</td>
<td style='vertical-align:top'>XHTML ";
2009-10-28 23:45:46 +00:00
$text .= ($theme['xhtmlcompliant']) ? ADMIN_TRUE_ICON : ADMIN_FALSE_ICON;
$text .= " &nbsp;&nbsp; CSS ";
2009-07-06 05:59:42 +00:00
$text .= ($theme['csscompliant']) ? ADMIN_TRUE_ICON : ADMIN_FALSE_ICON;
$text .= "</td></tr>";
2009-10-28 23:45:46 +00:00
2009-10-28 23:52:56 +00:00
// New in 0.8 WORK IN PROGRESS ----
if($theme['layouts'])
{
2009-10-28 23:45:46 +00:00
$itext .= "<tr>
<td style='vertical-align:top; width:24%'><b>".TPVLAN_50."</b>:</td>
<td style='vertical-align:top'><table class='fborder' style='margin-left:0px;margin-right:auto' >
<tr>";
$itext .= ($mode == 1) ? "<td class='fcaption' style='text-align:center;vertical-align:top;'>Default</td>" : "";
2009-10-28 23:45:46 +00:00
$itext .= "
<td class='fcaption'>Title</td>
<td class='fcaption'>Requirements</td>
<td class='fcaption' style='text-align:center;width:100px'>Menu Preset</td>
</tr>\n";
2009-10-28 23:52:56 +00:00
2009-10-28 23:45:46 +00:00
foreach ($theme['layouts'] as $key=>$val)
{
$itext .= "
<tr>";
if($mode == 1)
{
if(!$pref['sitetheme_deflayout'])
{
2009-10-28 23:45:46 +00:00
$pref['sitetheme_deflayout'] = ($val['@attributes']['default'] == 'true') ? $key : "";
// echo "------------- NODEFAULT";
}
$itext .= "
<td style='vertical-align:top width:auto;text-align:center'>
2009-10-28 23:45:46 +00:00
<input type='radio' name='layout_default' value='{$key}' ".($pref['sitetheme_deflayout'] == $key ? " checked='checked'" : "")." />
</td>";
}
2009-10-28 23:45:46 +00:00
$itext .= "<td style='vertical-align:top'>";
$itext .= ($val['@attributes']['previewFull']) ? "<a href='".e_THEME_ABS.$theme['path']."/".$val['@attributes']['previewFull']."' >" : "";
$itext .= $val['@attributes']['title'];
$itext .= ($val['@attributes']['previewFull']) ? "</a>" : "";
2009-10-28 23:45:46 +00:00
$itext .= ($pref['sitetheme_deflayout'] == $key) ? " (default)" : "";
$itext .= "</td>
<td style='vertical-align:top'>".$val['@attributes']['plugins']."&nbsp;</td>
<td style='vertical-align:top;text-align:center'>";
2009-10-28 23:45:46 +00:00
$itext .= ($val['menuPresets']) ? ADMIN_TRUE_ICON : "&nbsp;";
$itext .= "</td>
</tr>";
}
2009-10-28 23:45:46 +00:00
$itext .= "</table></td></tr>";
}
2009-10-28 23:45:46 +00:00
$text .= "<tr><td><b>".TPVLAN_22.": </b></td><td colspan='2'>";
foreach ($theme['css'] as $val)
2009-07-06 05:59:42 +00:00
{
2009-10-28 23:45:46 +00:00
$text .= $val['name']."<br />";
2009-07-06 05:59:42 +00:00
}
$text .= "</td></tr>";
2009-10-28 23:45:46 +00:00
$text .= $itext."</table>";
$text .= "<div class='right'><a href='#themeInfo_".$theme['id']."' class='e-expandit'>Close</a></div>";
return $text;
2009-07-06 05:59:42 +00:00
}
2009-10-28 23:45:46 +00:00
function loadThemeConfig()
{
$confile = e_THEME.$this->id."/".$this->id."_config.php";
2009-10-28 23:45:46 +00:00
2009-08-17 11:25:01 +00:00
if(($this->themeConfigObj === null) && is_readable($confile))
{
2009-10-28 23:52:56 +00:00
2009-10-28 23:45:46 +00:00
include ($confile);
$className = 'theme_'.$this->id;
2009-08-17 11:25:01 +00:00
if(class_exists($className))
{
$this->themeConfigObj = new $className();
}
else
{
2009-10-28 23:45:46 +00:00
$this->themeConfigObj = FALSE;
2009-08-17 11:25:01 +00:00
}
2009-10-28 23:45:46 +00:00
}
2009-10-28 23:52:56 +00:00
}
2009-10-28 23:45:46 +00:00
2009-10-28 23:52:56 +00:00
// TODO process custom theme configuration - .
function renderThemeConfig()
2009-07-06 05:59:42 +00:00
{
2009-10-28 23:45:46 +00:00
global $frm;
$this->loadThemeConfig();
if($this->themeConfigObj)
{
$var = call_user_func(array(&$this->themeConfigObj, 'config'));
foreach ($var as $val)
{
2009-10-28 23:45:46 +00:00
$text .= "<tr><td><b>".$val['caption']."</b>:</td><td colspan='2'>".$val['html']."</td></tr>";
}
2009-10-28 23:45:46 +00:00
return $text;
}
2009-10-28 23:52:56 +00:00
}
2009-10-28 23:45:46 +00:00
function renderThemeHelp()
{
2009-08-17 11:25:01 +00:00
if($this->themeConfigObj)
2009-10-28 23:45:46 +00:00
{
return call_user_func(array(&$this->themeConfigObj, 'help'));
}
2009-07-06 05:59:42 +00:00
}
2009-10-28 23:45:46 +00:00
2009-07-06 05:59:42 +00:00
function setThemeConfig()
{
2009-10-28 23:45:46 +00:00
$this->loadThemeConfig();
if($this->themeConfigObj)
{
return call_user_func(array(&$this->themeConfigObj, 'process'));
2009-08-17 11:25:01 +00:00
}
2009-07-06 05:59:42 +00:00
}
2009-10-28 23:45:46 +00:00
function renderTheme($mode = FALSE, $theme)
2009-07-06 05:59:42 +00:00
{
2009-10-28 23:52:56 +00:00
2009-07-06 05:59:42 +00:00
/*
2009-10-28 23:45:46 +00:00
mode = 0 :: normal
mode = 1 :: selected site theme
mode = 2 :: selected admin theme
*/
global $ns,$pref,$frm;
2006-12-02 04:36:16 +00:00
2009-10-28 23:45:46 +00:00
2009-07-06 05:59:42 +00:00
$author = ($theme['email'] ? "<a href='mailto:".$theme['email']."' title='".$theme['email']."'>".$theme['author']."</a>" : $theme['author']);
$website = ($theme['website'] ? "<a href='".$theme['website']."' rel='external'>".$theme['website']."</a>" : "");
$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>";
2009-10-28 23:45:46 +00:00
$previewbutton = (!$mode ? "<input class='button top' type='submit' name='preview_".$theme['id']."' value='".TPVLAN_9."' /> " : "");
2009-10-28 23:45:46 +00:00
$main_icon = ($pref['sitetheme'] != $theme['path']) ? "<input class='top' type='image' src='".e_IMAGE_ABS."admin_images/main_16.png' name='selectmain[".$theme['id']."]' alt='' title=\"".TPVLAN_10."\" />\n" : "<img src='".ADMIN_TRUE_ICON_PATH."' alt='' title='' class='icon S16' />";
2009-10-28 23:45:46 +00:00
$info_icon = "<a href='#themeInfo_".$theme['id']."' class='e-expandit' title='Click to select columns to display'><img src='".e_IMAGE_ABS."admin_images/info_16.png' alt='' title=\"".TPVLAN_7."\" class='icon S16' /></a>\n";
$preview_icon = "<input class='top' type='image' src='".e_IMAGE_ABS."admin_images/search_16.png' name=\"preview[".$theme['id']."]\" title='".TPVLAN_9." #".$theme['id']."' />\n";
$admin_icon = ($pref['admintheme'] != $theme['path']) ? "<input class='top' type='image' src='".e_IMAGE_ABS."e107_icon_16.png' name='selectadmin[".$theme['id']."]' alt='' title=\"".TPVLAN_32."\" />\n" : "<img src='".ADMIN_TRUE_ICON_PATH."' alt='' title='' class='icon S16' />";
2009-10-28 23:45:46 +00:00
$newpreview = "<a href='".e_BASE."news.php?themepreview.".$theme['id']."' title='".TPVLAN_9."' >".($theme['preview'] ? "<img src='".$theme['preview']."' style='width:200px; height:160px;' alt='' />" : "<img src='".e_IMAGE_ABS."admin_images/nopreview.png' style='width:200px;height:160px;' title='".TPVLAN_12."' alt='' />")."</a>";
2009-10-28 23:45:46 +00:00
2009-10-28 23:52:56 +00:00
// Choose a Theme to Install.
if(!$mode)
2009-07-06 05:59:42 +00:00
{
// styles NEED to be put into style.css
2009-10-28 23:45:46 +00:00
2009-07-06 05:59:42 +00:00
$borderStyle = (($pref['sitetheme'] == $theme['path']) || ($pref['admintheme'] == $theme['path'])) ? "border:1px solid black" : "border:1px dotted silver;background-color:#DDDDDD";
$text = "<div class='f-left block-text' style='margin:5px;".$borderStyle.";width:202px;height:160px'>
<div style='height:130px;overflow:hidden;border:1px solid black;margin-bottom:10px'>".$newpreview."</div>
<div class='f-left mediumtext' style='width:55%;font-weight:bold'>".$theme['name']." ".$theme['version']."</div>
<div class='f-right right' style='width:45%;height:16px'>\n\n\n".$main_icon.$admin_icon.$info_icon.$preview_icon."\n\n</div>";
//FIXME e-hideme doesn't work when JS is turned off.
// This popup information should be loaded with ajax.
// $text .= "<div id='themeInfo_".$theme['id']."' class='e-hideme col-selection' style='position:relative;top:30px;width:480px'>\n".$this->renderThemeInfo($theme)."</div>\n";
2009-07-06 05:59:42 +00:00
$text .= "</div>";
2009-10-28 23:45:46 +00:00
return $text;
2006-12-02 04:36:16 +00:00
}
2009-10-28 23:45:46 +00:00
$this->id = $theme['path'];
2009-10-28 23:52:56 +00:00
// load customn theme configuration fields.
$this->loadThemeConfig();
2009-10-28 23:45:46 +00:00
$text = "
<h2 class='caption'>".$theme['name']."</h2>
<div class='admintabs' id='tab-container'>";
2009-10-28 23:52:56 +00:00
2009-10-28 23:45:46 +00:00
if($this->themeConfigObj && call_user_func(array(&$this->themeConfigObj, 'help')))
{
$text .= "
<ul class='e-tabs e-hideme' id='core-thememanager-tabs'>
<li id='tab-thememanager-configure'><a href='#core-thememanager-configure'>".LAN_CONFIGURE."</a></li>
<li id='tab-thememanager-help'><a href='#core-thememanager-help'>".LAN_HELP."</a></li>
</ul>";
}
2009-10-28 23:45:46 +00:00
$text .= "
<div id='core-thememanager-configure'>
2009-07-10 14:25:23 +00:00
<table cellpadding='0' cellspacing='0' class='adminform'>
2009-08-06 22:27:47 +00:00
<colgroup span='3'>
2009-07-10 14:25:23 +00:00
<col class='col-label' />
<col class='col-control' />
2009-08-06 22:27:47 +00:00
<col class='col-control' />
2009-07-10 14:25:23 +00:00
</colgroup>
<tr>
<td><b>".TPVLAN_11."</b></td>
<td>".$theme['version']."</td>
<td class='center middle' rowspan='6' style='text-align:center; vertical-align:middle;width:25%'>".$newpreview."</td>
2009-07-10 14:25:23 +00:00
</tr>";
2009-10-28 23:52:56 +00:00
$text .= "<tr><td style='vertical-align:top; width:25%'><b>".TPVLAN_4."</b>:</td><td style='vertical-align:top'>".$author."</td></tr>";
$text .= "<tr><td style='vertical-align:top; width:25%'><b>".TPVLAN_5."</b>:</td><td style='vertical-align:top'>".$website."</td></tr>";
$text .= "<tr><td style='vertical-align:top; width:25%'><b>".TPVLAN_6."</b>:</td><td style='vertical-align:top'>".$theme['date']."</td></tr>";
2009-10-28 23:45:46 +00:00
$text .= "<tr><td style='vertical-align:top; width:25%'><b>".TPVLAN_7."</b>:</td><td style='vertical-align:top'>".$theme['info']."</td></tr>";
$text .= "<tr><td style='vertical-align:top; width:25%'><b>".LAN_CATEGORY."</b>:</td><td style='vertical-align:top'>".$theme['category']."</td></tr>";
$text .= "<tr><td style='vertical-align:top; width:25%'><b>".TPVLAN_49."</b>:</td>
<td style='vertical-align:top'>";
2009-10-28 23:45:46 +00:00
$text .= ($theme['xhtmlcompliant']) ? "W3C XHTML ".$theme['xhtmlcompliant'] : "Not Specified";
$text .= ($theme['csscompliant']) ? " &amp; CSS ".$theme['csscompliant'] : "";
2009-07-06 05:59:42 +00:00
$text .= "</td></tr>";
2009-10-28 23:45:46 +00:00
2009-10-28 23:52:56 +00:00
// site theme..
if($mode == 1)
2006-12-02 04:36:16 +00:00
{
2009-10-28 23:52:56 +00:00
2009-10-28 23:45:46 +00:00
$text .= "
<tr>
<td style='vertical-align:top; width:24%;'><b>".TPVLAN_53."</b></td>
<td colspan='2' style='vertical-align:top width:auto;'>";
2009-10-28 23:52:56 +00:00
2009-10-28 23:45:46 +00:00
if(varset($theme['plugins']))
{
foreach ($theme['plugins'] as $key=>$val)
{
$text .= $this->renderPlugins($theme['plugins']);
$text .= "&nbsp;";
}
}
$text .= "&nbsp;</td>
</tr>";
2009-10-28 23:52:56 +00:00
2009-10-28 23:45:46 +00:00
$text .= "
2009-07-06 05:59:42 +00:00
<tr>
<td style='vertical-align:top; width:24%;'><b>".TPVLAN_30."</b></td>
<td colspan='2' style='vertical-align:top width:auto;'>
2009-07-06 05:59:42 +00:00
<input type='radio' name='image_preload' value='1'".($pref['image_preload'] ? " checked='checked'" : "")." /> ".TPVLAN_28."&nbsp;&nbsp;
<input type='radio' name='image_preload' value='0'".(!$pref['image_preload'] ? " checked='checked'" : "")." /> ".TPVLAN_29."
</td>
</tr>";
}
2009-10-28 23:45:46 +00:00
2009-10-28 23:52:56 +00:00
// New in 0.8 ---- site theme.
if($mode == 1)
2009-07-06 05:59:42 +00:00
{
2009-10-28 23:52:56 +00:00
2009-10-28 23:45:46 +00:00
$itext = "<tr>
<td style='vertical-align:top; width:24%'><b>".TPVLAN_50."</b>:</td>
<td colspan='2' style='vertical-align:top'>
<table cellpadding='0' cellspacing='0' class='adminlist'>
<colgroup span='2'>
<col class='col-tm-layout-default' style='width:10%' />
<col class='col-tm-layout-name' style='width:20%' />
<col class='col-tm-layout-visibility' style='width:35%' />
<col class='col-tm-layout-preset' style='width:35%' />
</colgroup>
2009-07-06 05:59:42 +00:00
<tr>";
2009-10-28 23:45:46 +00:00
$itext .= ($mode == 1) ? "<td class='center top'>".TPVLAN_55."</td>" : "";
$itext .= "
<td>".TPVLAN_52."</td>
<td>".TPVLAN_56."</td>
<td>".TPVLAN_54."</td>
2009-07-06 05:59:42 +00:00
</tr>\n";
2009-10-28 23:52:56 +00:00
2009-10-28 23:45:46 +00:00
foreach ($theme['layouts'] as $key=>$val)
{
$itext .= "
2009-07-06 05:59:42 +00:00
<tr>";
2009-10-28 23:45:46 +00:00
if($mode == 1)
{
if(!$pref['sitetheme_deflayout'])
{
$pref['sitetheme_deflayout'] = ($val['@attributes']['default'] == 'true') ? $key : "";
}
$itext .= "<td class='center'>\n";
$itext .= "
<input type='radio' name='layout_default' value='{$key}' ".($pref['sitetheme_deflayout'] == $key ? " checked='checked'" : "")." />
2009-07-06 05:59:42 +00:00
</td>";
2009-10-28 23:45:46 +00:00
}
$itext .= "<td style='vertical-align:top'>";
2009-10-28 23:45:46 +00:00
$itext .= ($val['@attributes']['previewFull']) ? "<a href='".e_THEME_ABS.$theme['path']."/".$val['@attributes']['previewFull']."' >" : "";
$itext .= $val['@attributes']['title'];
$itext .= ($val['@attributes']['previewFull']) ? "</a>" : "";
$custompage_count = (isset($pref['sitetheme_custompages'][$key])) ? " [".count($pref['sitetheme_custompages'][$key])."]" : "";
$custompage_diz = "";
$count = 1;
if(isset($pref['sitetheme_custompages'][$key]) && count($pref['sitetheme_custompages'][$key]) > 0)
{
foreach ($pref['sitetheme_custompages'][$key] as $cp)
{
$custompage_diz .= "<a href='#element-to-be-shown' class='e-expandit'>".trim($cp)."</a>&nbsp;";
if($count > 4)
{
$custompage_diz .= "...";
break;
}
$count++;
}
}
else
{
$custompage_diz = "<a href='#element-to-be-shown' class='e-expandit'>None</a> ";
}
2009-10-28 23:45:46 +00:00
$itext .= "</td>
<td style='vertical-align:top'>";
2009-10-28 23:52:56 +00:00
// Default
$itext .= ($pref['sitetheme_deflayout'] != $key) ? $custompage_diz."<div class='e-hideme' id='element-to-be-shown'><textarea style='width:97%' rows='6' cols='20' name='custompages[".$key."]' >".(isset($pref['sitetheme_custompages'][$key]) ? implode("\n",
2009-10-28 23:52:56 +00:00
$pref['sitetheme_custompages'][$key]) : "")."</textarea></div>\n" : TPVLAN_55;
2009-10-28 23:45:46 +00:00
$itext .= "</td>";
$itext .= "<td>";
$itext .= (varset($val['menuPresets'])) ? $this->frm->admin_button("setMenuPreset[".$key."]", "Use Preset") : "";
$itext .= "</td>
2009-07-06 05:59:42 +00:00
</tr>";
2009-10-28 23:45:46 +00:00
}
$itext .= "</table></td></tr>";
2009-07-06 05:59:42 +00:00
}
2009-10-28 23:45:46 +00:00
// $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>" : "";
2009-10-28 23:45:46 +00:00
2009-10-24 07:53:30 +00:00
if($mode == 2)
{
2009-10-28 23:52:56 +00:00
2009-10-24 07:53:30 +00:00
$astext = "";
$file = e107::getFile();
2009-10-28 23:45:46 +00:00
$adminstyles = $file->get_files(e_ADMIN."includes");
$astext = "\n<select id='mode2' name='adminstyle' class='tbox'>\n";
foreach ($adminstyles as $as)
{
$style = str_replace(".php", "", $as['fname']);
$astext .= "<option value='{$style}'".($pref['adminstyle'] == $style ? " selected='selected'" : "").">".$style."</option>\n";
}
$astext .= "</select>";
2009-10-24 07:53:30 +00:00
$text .= "
<tr>
<td><b>".TPVLAN_41.":</b></td>
<td colspan='2'>".$astext."</td>
</tr>
\n";
}
2009-10-28 23:45:46 +00:00
$text .= $itext;
2009-07-06 05:59:42 +00:00
if(array_key_exists("multipleStylesheets", $theme) && $mode)
{
$text .= "
<tr><td style='vertical-align:top;'><b>".TPVLAN_22.":</b></td>
<td colspan='2' style='vertical-align:top'>
<table class='adminlist' style='width:100%' >
2009-07-06 05:59:42 +00:00
<tr>
<td class='center' style='width:10%'>".TPVLAN_55."</td>
<td style='width:20%'>".TPVLAN_52."</td>
<td class='left'>".TPVLAN_7."</td>
2009-10-28 23:45:46 +00:00
</tr>";
2009-08-06 22:27:47 +00:00
2009-10-28 23:52:56 +00:00
2009-10-28 23:45:46 +00:00
foreach ($theme['css'] as $css)
{
$text2 = "";
if($mode == 1 && substr($css['name'], 0, 6) == "admin_")
2006-12-02 04:36:16 +00:00
{
2009-10-28 23:45:46 +00:00
continue;
}
if($mode == 2)
{
if(!$css['nonadmin'])
2006-12-02 04:36:16 +00:00
{
2009-10-28 23:45:46 +00:00
$text2 = "
2009-07-06 05:59:42 +00:00
<td class='center'>
<input type='radio' name='admincss' value='".$css['name']."' ".($pref['admincss'] == $css['name'] || (!$pref['admincss'] && $css['name'] == "style.css") ? " checked='checked'" : "")." />
</td>
<td>".$css['name']."</td>
<td>".($css['info'] ? $css['info'] : ($css['name'] == "style.css" ? TPVLAN_23 : TPVLAN_24))."</td>\n";
2006-12-02 04:36:16 +00:00
}
2009-10-28 23:45:46 +00:00
}
if($mode == 1)
{
2006-12-02 04:36:16 +00:00
2009-10-28 23:52:56 +00:00
2009-10-28 23:45:46 +00:00
$text2 = "
2009-07-06 05:59:42 +00:00
<td class='center'>
<input type='radio' name='themecss' value='".$css['name']."' ".($pref['themecss'] == $css['name'] || (!$pref['themecss'] && $css['name'] == "style.css") ? " checked='checked'" : "")." />
</td>
<td>".$css['name']."
</td>
<td>".($css['info'] ? $css['info'] : ($css['name'] == "style.css" ? TPVLAN_23 : TPVLAN_24))."</td>\n";
2006-12-02 04:36:16 +00:00
}
2009-10-28 23:45:46 +00:00
$text .= ($text2) ? "<tr>".$text2."</tr>" : "";
2009-10-28 23:52:56 +00:00
2009-10-28 23:45:46 +00:00
}
$text .= "</table></td></tr>";
2006-12-02 04:36:16 +00:00
}
2009-10-28 23:45:46 +00:00
if($mode == 1)
{
2009-10-28 23:45:46 +00:00
$text .= $this->renderThemeConfig();
}
$text .= "</table>
2009-07-06 05:59:42 +00:00
<div class='center buttons-bar'>";
2009-10-28 23:52:56 +00:00
2009-10-28 23:45:46 +00:00
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');
2009-10-28 23:52:56 +00:00
2009-10-28 23:45:46 +00:00
}
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 .= "<input type='hidden' name='curTheme' value='".$theme['path']."' />";
$text .= "
2009-07-06 05:59:42 +00:00
</div>
</div>
<div id='core-thememanager-help' >".$this->renderThemeHelp()."</div>
</div>
\n";
2009-10-28 23:45:46 +00:00
2006-12-02 04:36:16 +00:00
return $text;
}
2009-10-28 23:45:46 +00:00
function renderPlugins($pluginOpts)
{
global $frm,$sql;
2009-10-28 23:45:46 +00:00
2009-10-28 23:52:56 +00:00
// if there is 1 entry, then it's not the same array.
$tmp = (varset($pluginOpts['plugin'][1])) ? $pluginOpts['plugin'] : $pluginOpts;
2009-10-28 23:45:46 +00:00
$text = "";
foreach ($tmp as $p)
{
$plug = trim($p['@attributes']['name']);
2009-10-28 23:45:46 +00:00
if(plugInstalled($plug))
{
2009-10-28 23:45:46 +00:00
$text .= $plug." ".ADMIN_TRUE_ICON;
}
else
{
2009-10-28 23:45:46 +00:00
// echo $plug;
if($sql->db_Select("plugin", "plugin_id", " plugin_path = '".$plug."' LIMIT 1 "))
{
$row = $sql->db_Fetch(MYSQL_ASSOC);
$name = "installplugin[".$row['plugin_id']."]";
2009-10-28 23:45:46 +00:00
$text .= $this->frm->admin_button($name, ADLAN_121." ".$plug."", 'delete');
}
else
{
2009-10-28 23:45:46 +00:00
$text .= (varset($p['@attributes']['url']) && ($p['@attributes']['url'] != 'core')) ? "<a rel='external' href='".$p['@attributes']['url']."'>".$plug."</a> " : "<i>".$plug."</i>";
$text .= ADMIN_FALSE_ICON;
}
2009-10-28 23:52:56 +00:00
}
2009-10-28 23:45:46 +00:00
$text .= "&nbsp;&nbsp;&nbsp;";
}
2009-10-28 23:45:46 +00:00
return $text;
}
2009-10-28 23:45:46 +00:00
function refreshPage($page = e_QUERY )
{
2009-10-28 23:45:46 +00:00
header("Location: ".e_SELF."?".$page);
exit;
}
2009-10-28 23:45:46 +00:00
2006-12-02 04:36:16 +00:00
function themePreview()
{
2009-10-28 23:45:46 +00:00
echo "<script type='text/javascript'>document.location.href='".e_BASE."index.php?themepreview.".$this->id."'</script>\n";
2006-12-02 04:36:16 +00:00
exit;
}
2009-10-28 23:45:46 +00:00
2006-12-02 04:36:16 +00:00
function showPreview()
{
2008-04-10 19:23:51 +00:00
include_lan(e_LANGUAGEDIR.e_LANGUAGE."/admin/lan_theme.php");
2006-12-02 04:36:16 +00:00
$text = "<br /><div class='indent'>".TPVLAN_1.".</div><br />";
global $ns;
$ns->tablerender(TPVLAN_2, $text);
}
2009-10-28 23:45:46 +00:00
2009-09-17 00:13:40 +00:00
/**
2009-10-28 23:45:46 +00:00
* Set Theme as Main Theme.
* @param object $name [optional] name (folder) of the theme to set.
* @return
2009-09-17 00:13:40 +00:00
*/
2009-10-28 23:45:46 +00:00
function setTheme($name = '')
2006-12-02 04:36:16 +00:00
{
2009-09-17 00:13:40 +00:00
$core = e107::getConfig('core');
2009-10-28 23:45:46 +00:00
$sql = e107::getDb();
2009-09-17 00:13:40 +00:00
$emessage = eMessage::getInstance();
2009-10-28 23:45:46 +00:00
$themeArray = $this->getThemes("id");
$name = ($name) ? $name : $themeArray[$this->id];
$layout = $pref['sitetheme_layouts'] = is_array($this->themeArray[$name]['layouts']) ? $this->themeArray[$name]['layouts'] : array();
$deflayout = $this->findDefault($name);
$customPages = $this->themeArray[$name]['custompages'];
$version = $this->themeArray[$name]['version'];
$core->set('sitetheme', $name);
$core->set('themecss', 'style.css');
$core->set('sitetheme_layouts', $layout);
$core->set('sitetheme_deflayout', $deflayout);
$core->set('sitetheme_custompages', $customPages);
$core->set('sitetheme_version', $version);
$core->set('sitetheme_releaseUrl', $this->themeArray[$name]['releaseUrl']);
$sql->db_Delete("menus", "menu_layout !='' ");
2009-09-17 00:13:40 +00:00
ecache::clear_sys();
2009-10-28 23:45:46 +00:00
if($core->save())
{
2009-09-17 00:13:40 +00:00
//TODO LANs
2009-10-28 23:45:46 +00:00
$emessage->add(TPVLAN_3." <b>'".$name." v".$version."'</b>", E_MESSAGE_SUCCESS);
$emessage->add("Default Layout: ".$deflayout, E_MESSAGE_SUCCESS);
$emessage->add("Custom Pages: ".$customPages, E_MESSAGE_SUCCESS);
2009-09-17 00:13:40 +00:00
2009-10-28 23:45:46 +00:00
$this->theme_adminlog('01', $name.', style.css');
2009-09-17 00:13:40 +00:00
return TRUE;
}
else
{
2009-10-28 23:45:46 +00:00
$emessage->add(TPVLAN_3." <b>'".$name."'</b>", E_MESSAGE_ERROR);
2009-09-17 00:13:40 +00:00
return FALSE;
}
2009-10-28 23:52:56 +00:00
2006-12-02 04:36:16 +00:00
}
2009-10-28 23:45:46 +00:00
function findDefault($theme)
{
if(varset($_POST['layout_default']))
{
2009-10-28 23:45:46 +00:00
return $_POST['layout_default'];
}
2009-10-28 23:45:46 +00:00
$l = $this->themeArray[$theme];
if(!$l)
{
2009-10-28 23:45:46 +00:00
$l = $this->getThemeInfo($theme);
}
2009-10-28 23:45:46 +00:00
if($l['layouts'])
{
2009-10-28 23:45:46 +00:00
foreach ($l['layouts'] as $key=>$val)
{
2009-10-28 23:45:46 +00:00
if(isset($val['@attributes']['default']) && ($val['@attributes']['default'] == "true"))
{
2009-10-28 23:45:46 +00:00
return $key;
}
}
}
else
{
2009-10-28 23:45:46 +00:00
return "";
}
}
2009-10-28 23:45:46 +00:00
2006-12-02 04:36:16 +00:00
function setAdminTheme()
{
global $pref,$e107cache,$ns,$emessage;
2009-10-28 23:45:46 +00:00
$themeArray = $this->getThemes("id");
$pref['admintheme'] = $themeArray[$this->id];
$pref['admincss'] = file_exists(e_THEME.$pref['admintheme'].'/admin_style.css') ? 'admin_style.css' : 'style.css';
$e107cache->clear_sys();
if(save_prefs())
{
2009-10-28 23:52:56 +00:00
// Default Message
$emessage->add(TPVLAN_40." <b>'".$themeArray[$this->id]."'</b>", E_MESSAGE_SUCCESS);
2009-10-28 23:45:46 +00:00
$this->theme_adminlog('02', $pref['admintheme'].', '.$pref['admincss']);
}
2009-10-28 23:45:46 +00:00
// $ns->tablerender("Admin Message", "<br /><div style='text-align:center;'>".TPVLAN_40." <b>'".$themeArray[$this -> id]."'</b>.</div><br />");
2009-10-28 23:45:46 +00:00
// $this->showThemes('admin');
2006-12-02 04:36:16 +00:00
}
2009-10-28 23:45:46 +00:00
2006-12-02 04:36:16 +00:00
function setStyle()
{
global $pref,$e107cache,$ns,$sql,$emessage;
//TODO adminlog
2009-10-28 23:45:46 +00:00
e107::getConfig()->setPosted('themecss', $_POST['themecss'])->setPosted('image_preload', $_POST['image_preload'])->setPosted('sitetheme_deflayout',
$_POST['layout_default']);
$msg = $this->setThemeConfig();
if($msg)
{
2009-10-28 23:45:46 +00:00
$emessage->add(TPVLAN_37, E_MESSAGE_SUCCESS);
if(is_array($msg))
2009-10-28 23:45:46 +00:00
$emessage->add($msg[0], $msg[1]);
}
2006-12-02 04:36:16 +00:00
}
2009-10-28 23:45:46 +00:00
2006-12-02 04:36:16 +00:00
function setAdminStyle()
{
global $pref,$e107cache,$ns,$emessage;
/*$pref['admincss'] = $_POST['admincss'];
2009-10-28 23:45:46 +00:00
$pref['adminstyle'] = $_POST['adminstyle'];
$e107cache->clear_sys();
if(save_prefs())
{
$emessage->add(TPVLAN_43, E_MESSAGE_SUCCESS);
$this->theme_adminlog('04',$pref['adminstyle'].', '.$pref['admincss']);
2009-10-28 23:45:46 +00:00
}
else
{
$emessage->add(TPVLAN_43, E_MESSAGE_ERROR);
}*/
2009-10-28 23:45:46 +00:00
//TODO adminlog
2009-10-28 23:45:46 +00:00
e107::getConfig()->setPosted('admincss', $_POST['admincss'])->setPosted('adminstyle', $_POST['adminstyle']);
return (e107::getConfig()->dataHasChangedFor('admincss') || e107::getConfig()->dataHasChangedFor('adminstyle'));
2006-12-02 04:36:16 +00:00
}
2009-10-28 23:45:46 +00:00
function SetCustomPages($array)
{
2009-10-28 23:45:46 +00:00
if(!is_array($array))
{
return;
}
//global $pref;
$key = key($array);
//['sitetheme_custompages']
$array[$key] = trim(str_replace("\r\n", "\n", $array[$key]));
$newprefs[$key] = array_filter(explode("\n", $array[$key]));
$newprefs[$key] = array_unique($newprefs[$key]);
2009-10-28 23:45:46 +00:00
if(e107::getPref('sitetheme_deflayout') == 'legacyCustom')
{
$newprefs['legacyCustom'] = array();
}
//setPosted couldn't be used here - sitetheme_custompages structure is not defined
e107::getConfig()->set('sitetheme_custompages', e107::getParser()->toDB($newprefs));
}
2009-10-28 23:45:46 +00:00
2008-11-02 10:28:30 +00:00
// Log event to admin log
2009-10-28 23:45:46 +00:00
function theme_adminlog($msg_num = '00', $woffle = '')
2008-11-02 10:28:30 +00:00
{
2009-09-17 00:13:40 +00:00
if($this->noLog)
{
return;
}
global $pref,$admin_log;
2008-11-02 10:28:30 +00:00
// if (!varset($pref['admin_log_log']['admin_banlist'],0)) return;
2009-10-28 23:45:46 +00:00
$admin_log->log_event('THEME_'.$msg_num, $woffle, E_LOG_INFORMATIVE, '');
2008-11-02 10:28:30 +00:00
}
2009-10-28 23:45:46 +00:00
function parse_theme_php($path)
{
2009-10-28 23:45:46 +00:00
$CUSTOMPAGES = "";
$fp = fopen(e_THEME.$path."/theme.php", "r");
$themeContents = fread($fp, filesize(e_THEME.$path."/theme.php"));
fclose($fp);
2009-10-28 23:45:46 +00:00
preg_match('/themename(\s*?=\s*?)("|\')(.*?)("|\');/si', $themeContents, $match);
2009-10-28 23:45:46 +00:00
$themeArray['name'] = varset($match[3], '');
preg_match('/themeversion(\s*?=\s*?)("|\')(.*?)("|\');/si', $themeContents, $match);
2009-10-28 23:45:46 +00:00
$themeArray['version'] = varset($match[3], '');
preg_match('/themeauthor(\s*?=\s*?)("|\')(.*?)("|\');/si', $themeContents, $match);
2009-10-28 23:45:46 +00:00
$themeArray['author'] = varset($match[3], '');
preg_match('/themeemail(\s*?=\s*?)("|\')(.*?)("|\');/si', $themeContents, $match);
2009-10-28 23:45:46 +00:00
$themeArray['email'] = varset($match[3], '');
preg_match('/themewebsite(\s*?=\s*?)("|\')(.*?)("|\');/si', $themeContents, $match);
2009-10-28 23:45:46 +00:00
$themeArray['website'] = varset($match[3], '');
preg_match('/themedate(\s*?=\s*?)("|\')(.*?)("|\');/si', $themeContents, $match);
2009-10-28 23:45:46 +00:00
$themeArray['date'] = varset($match[3], '');
preg_match('/themeinfo(\s*?=\s*?)("|\')(.*?)("|\');/si', $themeContents, $match);
2009-10-28 23:45:46 +00:00
$themeArray['info'] = varset($match[3], '');
preg_match('/xhtmlcompliant(\s*?=\s*?)(\S*?);/si', $themeContents, $match);
$xhtml = strtolower($match[2]);
$themeArray['xhtmlcompliant'] = ($xhtml == "true" ? "1.1" : false);
2009-10-28 23:45:46 +00:00
preg_match('/csscompliant(\s*?=\s*?)(\S*?);/si', $themeContents, $match);
$css = strtolower($match[2]);
$themeArray['csscompliant'] = ($css == "true" ? "2.1" : false);
2009-10-28 23:45:46 +00:00
/* preg_match('/CUSTOMPAGES(\s*?=\s*?)("|\')(.*?)("|\');/si', $themeContents, $match);
$themeArray['custompages'] = array_filter(explode(" ",$match[3]));*/
2009-10-28 23:45:46 +00:00
$themeContentsArray = explode("\n", $themeContents);
if(!$themeArray['name'])
{
unset($themeArray);
}
2009-10-28 23:45:46 +00:00
$lays['legacyDefault']['@attributes'] = array('title'=>'Default',
'preview'=>'',
'previewFull'=>'',
'plugins'=>'',
'default'=>'true');
2009-10-28 23:52:56 +00:00
// load custompages from theme.php only when theme.xml doesn't exist.
if(!file_exists(e_THEME.$path."theme.xml"))
{
2009-10-28 23:45:46 +00:00
foreach ($themeContentsArray as $line)
{
2009-10-28 23:45:46 +00:00
if(strstr($line, "CUSTOMPAGES"))
{
2009-10-28 23:45:46 +00:00
eval(str_replace("$", "\$", $line));
}
}
2009-10-28 23:45:46 +00:00
if(is_array($CUSTOMPAGES))
{
2009-10-28 23:45:46 +00:00
foreach ($CUSTOMPAGES as $key=>$val)
{
$themeArray['custompages'][$key] = explode(" ", $val);
}
}
elseif($CUSTOMPAGES)
{
2009-10-28 23:45:46 +00:00
$themeArray['custompages']['legacyCustom'] = explode(" ", $CUSTOMPAGES);
$lays['legacyCustom']['@attributes'] = array('title'=>'Custom',
'preview'=>'',
'previewFull'=>'',
'plugins'=>'');
}
}
2009-10-28 23:45:46 +00:00
2009-07-06 05:59:42 +00:00
$themeArray['path'] = $path;
$themeArray['layouts'] = $lays;
2009-10-28 23:45:46 +00:00
return $themeArray;
}
2009-10-28 23:45:46 +00:00
function parse_theme_xml($path)
{
global $tp;
2009-10-28 23:52:56 +00:00
// loadLanFiles($path, 'admin'); // Look for LAN files on default paths
2009-10-28 23:45:46 +00:00
require_once (e_HANDLER.'xml_class.php');
$xml = new xmlClass;
2009-10-28 23:52:56 +00:00
// layout should always be an array.
$xml->setOptArrayTags('layout');
2009-10-28 23:45:46 +00:00
$xml->setOptStringTags('menuPresets,customPages');
$vars = $xml->loadXMLfile(e_THEME.$path.'/theme.xml', true, true);
2009-10-28 23:45:46 +00:00
$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['releaseUrl'] = varset($vars['@attributes']['releaseUrl']);
$vars['email'] = varset($vars['author']['@attributes']['email']);
$vars['website'] = varset($vars['author']['@attributes']['url']);
$vars['author'] = varset($vars['author']['@attributes']['name']);
$vars['info'] = varset($vars['description']);
$vars['category'] = $this->getThemeCategory(varset($vars['category']));
$vars['xhtmlcompliant'] = varset($vars['compliance']['@attributes']['xhtml']);
$vars['csscompliant'] = varset($vars['compliance']['@attributes']['css']);
$vars['path'] = $path;
2009-09-17 00:13:40 +00:00
$vars['@attributes']['default'] = (varset($vars['@attributes']['default']) && strtolower($vars['@attributes']['default']) == 'true') ? 1 : 0;
2009-10-28 23:45:46 +00:00
unset($vars['authorEmail'], $vars['authorUrl'], $vars['xhtmlCompliant'], $vars['cssCompliant'], $vars['description']);
2009-09-17 00:13:40 +00:00
2009-10-28 23:45:46 +00:00
// Compile layout information into a more usable format.
2009-09-17 00:13:40 +00:00
2009-10-28 23:45:46 +00:00
$custom = array();
foreach ($vars['layouts'] as $layout)
{
2009-10-28 23:45:46 +00:00
foreach ($layout as $key=>$val)
{
2009-09-17 00:13:40 +00:00
$name = $val['@attributes']['name'];
unset($val['@attributes']['name']);
$lays[$name] = $val;
if(isset($val['customPages']))
{
2009-10-28 23:45:46 +00:00
$custom[$name] = array_filter(explode(" ", $val['customPages']));
}
}
2009-10-28 23:45:46 +00:00
}
$vars['layouts'] = $lays;
$vars['path'] = $path;
$vars['custompages'] = $custom;
2009-10-28 23:45:46 +00:00
return $vars;
}
2009-10-28 23:52:56 +00:00
}
interface e_theme_config
{
/**
* Triggered on theme settings submit
* Catch and save theme configuration
*/
public function process();
2009-10-28 23:45:46 +00:00
/**
* Theme configuration user interface
2009-10-28 23:45:46 +00:00
* Print out config fields
*/
public function config();
/**
* Theme help tab
2009-10-28 23:45:46 +00:00
* Print out theme help content
*/
public function help();
2007-01-17 20:47:41 +00:00
}