mirror of
https://github.com/e107inc/e107.git
synced 2025-07-28 18:30:53 +02:00
Plugin/Theme "new version" alerts on admin dashboard. Overwriting enabled during download - existing plugins/theme now moved out of the way and backed up.Theme-dir scanning improved and optimized for speed.
This commit is contained in:
@@ -147,16 +147,33 @@ class admin_start
|
||||
$this->deleteDeprecated();
|
||||
}
|
||||
|
||||
e107::getDb()->db_Mark_Time('Check New Install');
|
||||
$this->checkNewInstall();
|
||||
e107::getDb()->db_Mark_Time('Check Core Update');
|
||||
$this->checkCoreUpdate();
|
||||
e107::getDb()->db_Mark_Time('Check Plugin Update');
|
||||
$this->checkPluginUpdate();
|
||||
e107::getDb()->db_Mark_Time('Check Theme Update');
|
||||
$this->checkThemeUpdate();
|
||||
e107::getDb()->db_Mark_Time('Check Paths');
|
||||
$this->checkPaths();
|
||||
e107::getDb()->db_Mark_Time('Check Timezone');
|
||||
$this->checkTimezone();
|
||||
e107::getDb()->db_Mark_Time('Check Writable');
|
||||
$this->checkWritable();
|
||||
$this->checkHtmlarea();
|
||||
e107::getDb()->db_Mark_Time('Check HTMLArea');
|
||||
$this->checkHtmlarea();
|
||||
e107::getDb()->db_Mark_Time('Check Incompatible Plugins');
|
||||
$this->checkIncompatiblePlugins();
|
||||
e107::getDb()->db_Mark_Time('Check Filetypes');
|
||||
$this->checkFileTypes();
|
||||
e107::getDb()->db_Mark_Time('Check Suspect Files');
|
||||
$this->checkSuspiciousFiles();
|
||||
e107::getDb()->db_Mark_Time('Check Deprecated');
|
||||
$this->checkDeprecated();
|
||||
e107::getDb()->db_Mark_Time('Check Password Encryption');
|
||||
$this->checkPasswordEncryption();
|
||||
e107::getDb()->db_Mark_Time('Check Htaccess');
|
||||
$this->checkHtaccess();
|
||||
|
||||
if($this->refresh == true)
|
||||
@@ -206,6 +223,118 @@ class admin_start
|
||||
}
|
||||
|
||||
|
||||
private function checkCoreUpdate()
|
||||
{
|
||||
// auto db update
|
||||
if ('0' != ADMINPERMS)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
//$sc = e107::getScBatch('admin');
|
||||
//echo $tp->parseTemplate('{ADMIN_COREUPDATE=alert}',true, $sc);
|
||||
|
||||
global $dont_check_update, $e107info;
|
||||
global $dbupdate, $dbupdatep, $e107cache;
|
||||
|
||||
require_once(e_ADMIN.'update_routines.php');
|
||||
update_check();
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
private function checkPluginUpdate()
|
||||
{
|
||||
require_once(e_HANDLER.'e_marketplace.php');
|
||||
$mp = new e_marketplace(); // autodetect the best method
|
||||
|
||||
$versions = $mp->getVersionList('plugin');
|
||||
|
||||
$plugins = e107::getPref('plug_installed');
|
||||
|
||||
if(empty($plugins))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
$tp = e107::getParser();
|
||||
|
||||
foreach($plugins as $folder=>$version)
|
||||
{
|
||||
|
||||
if(!empty($versions[$folder]['version']) && version_compare( $version, $versions[$folder]['version'], '<'))
|
||||
{
|
||||
$link = "<a rel='external' href='".$versions[$folder]['url']."'>".$versions[$folder]['name']."</a>";
|
||||
|
||||
$dl = $mp->getDownloadModal('plugin', $versions[$folder]);
|
||||
|
||||
$caption = LAN_DOWNLOAD.": ".$versions[$folder]['name']." ".$versions[$folder]['version'];
|
||||
|
||||
$lans = array('x'=>$link, 'y'=>LAN_PLUGIN);
|
||||
$message = $tp->lanVars(LAN_NEWER_VERSION_OF_X, $lans);
|
||||
$message .= " <a href='".$dl."' class='e-modal' data-modal-caption=\"".$caption."\" title=\"".LAN_DOWNLOAD."\">".$tp->toGlyph('fa-cloud-download')."</a>";
|
||||
|
||||
|
||||
e107::getMessage()->addInfo($message);
|
||||
e107::getMessage()->addDebug("Local version: ".$version." Remote version: ".$versions[$folder]['version']);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
private function checkThemeUpdate()
|
||||
{
|
||||
require_once(e_HANDLER.'e_marketplace.php');
|
||||
$mp = new e_marketplace(); // autodetect the best method
|
||||
|
||||
$versions = $mp->getVersionList('theme');
|
||||
|
||||
$themes = scandir(e_THEME);
|
||||
|
||||
if(empty($themes))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
$tp = e107::getParser();
|
||||
|
||||
$list = e107::getTheme()->getThemeList();
|
||||
|
||||
foreach($list as $data)
|
||||
{
|
||||
|
||||
$folder = $data['path'];
|
||||
$version = $data['version'];
|
||||
|
||||
if(!empty($versions[$folder]['version']) && version_compare( $version, $versions[$folder]['version'], '<'))
|
||||
{
|
||||
$link = "<a rel='external' href='".$versions[$folder]['url']."'>".$versions[$folder]['name']."</a>";
|
||||
|
||||
$lans = array('x'=>$link, 'y'=>LAN_THEME);
|
||||
|
||||
$dl = $mp->getDownloadModal('theme', $versions[$folder]);
|
||||
|
||||
$caption = LAN_DOWNLOAD.": ".$versions[$folder]['name']." ".$versions[$folder]['version'];
|
||||
|
||||
$message = $tp->lanVars(LAN_NEWER_VERSION_OF_X, $lans);
|
||||
$message .= " <a href='".$dl."' class='e-modal' data-modal-caption=\"".$caption."\" title=\"".LAN_DOWNLOAD."\">".$tp->toGlyph('fa-cloud-download')."</a>";
|
||||
|
||||
|
||||
e107::getMessage()->addInfo($message);
|
||||
e107::getMessage()->addDebug("Local version: ".$version." Remote version: ".$versions[$folder]['version']);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@@ -486,15 +615,7 @@ class admin_start
|
||||
// ---------------------------------------------------------
|
||||
|
||||
|
||||
// auto db update
|
||||
if ('0' == ADMINPERMS)
|
||||
{
|
||||
$sc = e107::getScBatch('admin');
|
||||
echo $tp->parseTemplate('{ADMIN_COREUPDATE=alert}',true, $sc);
|
||||
|
||||
require_once(e_ADMIN.'update_routines.php');
|
||||
update_check();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
@@ -24,183 +24,9 @@ $e_sub_cat = 'database';
|
||||
require_once ("auth.php");
|
||||
require_once ("update_routines.php");
|
||||
|
||||
|
||||
|
||||
//
|
||||
|
||||
// Carry out CORE updates
|
||||
/*
|
||||
function run_updates($dbupdate)
|
||||
{
|
||||
global $mes;
|
||||
|
||||
foreach($dbupdate as $func => $rmks)
|
||||
{
|
||||
if(function_exists('update_'.$func)) // Legacy Method.
|
||||
{
|
||||
$installed = call_user_func("update_".$func);
|
||||
//?! (LAN_UPDATE == $_POST[$func])
|
||||
if(varsettrue($_POST['update_core'][$func]) && !$installed)
|
||||
{
|
||||
if(function_exists("update_".$func))
|
||||
{
|
||||
$message = LAN_UPDATE_7." {$rmks}";
|
||||
$error = call_user_func("update_".$func, "do");
|
||||
if($error != '')
|
||||
{
|
||||
$mes->add($message, E_MESSAGE_ERROR);
|
||||
$mes->add($error, E_MESSAGE_ERROR);
|
||||
}
|
||||
else $mes->add($message, E_MESSAGE_SUCCESS);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
function run_updates_plugin($func,$check=TRUE) // New for {plugin}_setup.php
|
||||
{
|
||||
if(class_exists($func.'_setup'))
|
||||
{
|
||||
$class = $func.'_setup';
|
||||
$setObj = new $class;
|
||||
|
||||
if(method_exists($setObj,'upgrade_post'))
|
||||
{
|
||||
return $setObj->upgrade_post($check);
|
||||
}
|
||||
// print_a($setObj);
|
||||
// echo "<br />Found: ".$func;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
function show_updates($dbupdate, $what)
|
||||
{
|
||||
global $frm;
|
||||
$mes = e107::getMessage();
|
||||
|
||||
$caption = constant('LAN_UPDATE_CAPTION_'.strtoupper($what));
|
||||
$text = "
|
||||
<form method='post' action='".e_SELF."'>
|
||||
<fieldset id='core-e107-update-{$what}'>
|
||||
<legend>{$caption}</legend>
|
||||
<table class='table adminlist'>
|
||||
<colgroup>
|
||||
<col style='width: 60%' />
|
||||
<col style='width: 40%' />
|
||||
</colgroup>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>".LAN_UPDATE_55."</th>
|
||||
<th class='last'>".LAN_UPDATE_2."</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
";
|
||||
|
||||
$updates = 0;
|
||||
|
||||
// asort($dbupdate);
|
||||
|
||||
foreach($dbupdate as $func => $rmks)
|
||||
{
|
||||
if(function_exists("update_".$func))
|
||||
{
|
||||
$text .= "<tr><td>{$rmks}</td>";
|
||||
|
||||
if(call_user_func("update_".$func))
|
||||
{
|
||||
$text .= "<td>".LAN_UPDATE_3."</td>";
|
||||
}
|
||||
else
|
||||
{
|
||||
$updates ++;
|
||||
$text .= "<td>".$frm->admin_button('update_core['.$func.']', LAN_UPDATE, 'warning', '', "id=e-{$func}")."</td>";
|
||||
}
|
||||
$text .= "</tr>\n";
|
||||
}
|
||||
|
||||
if(class_exists($func.'_setup')) // plugin_setup.php
|
||||
{
|
||||
$text .= "<tr><td>{$rmks}</td>";
|
||||
|
||||
$reason = run_updates_plugin($func,TRUE); // TRUE = Just check if needed.
|
||||
if(!$reason)
|
||||
{
|
||||
$text .= "<td>".LAN_UPDATE_3."</td>";
|
||||
}
|
||||
else
|
||||
{
|
||||
$updates ++;
|
||||
$mes->addDebug($reason);
|
||||
$text .= "<td>".$frm->admin_button('update['.$func.']', LAN_UPDATE, 'warning')."</td>";
|
||||
}
|
||||
$text .= "</tr>\n";
|
||||
}
|
||||
}
|
||||
|
||||
$text .= "
|
||||
</tbody>
|
||||
</table>
|
||||
</fieldset>
|
||||
</form>
|
||||
";
|
||||
|
||||
echo $text;
|
||||
return $updates; // Number of updates to do
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
|
||||
new e107Update($dbupdate);
|
||||
|
||||
|
||||
require_once ("footer.php");
|
||||
|
||||
|
||||
|
||||
/*
|
||||
|
||||
if(varset($_POST['update_core']) && is_array($_POST['update_core']))
|
||||
{
|
||||
$message = run_updates($dbupdate);
|
||||
}
|
||||
|
||||
if(varset($_POST['update']) && is_array($_POST['update'])) // Do plugin updates
|
||||
{
|
||||
$func = key($_POST['update']);
|
||||
run_updates_plugin($func,FALSE);
|
||||
}
|
||||
|
||||
$total_updates = 0;
|
||||
|
||||
ob_start();
|
||||
if(isset($dbupdatep))
|
||||
{ // Show plugin updates done
|
||||
$total_updates += show_updates($dbupdatep, 'plugin');
|
||||
}
|
||||
// Show core updates done
|
||||
$total_updates += show_updates($dbupdate, 'core');
|
||||
$text = ob_get_contents();
|
||||
ob_end_clean();
|
||||
|
||||
$e107->ns->tablerender(LAN_UPDATE_56, $mes->render().$text);
|
||||
|
||||
if($total_updates == 0)
|
||||
{ // No updates needed - clear the cache to be sure
|
||||
$e107cache->set_sys("nq_admin_updatecheck", time().', 1, '.$e107info['e107_version'], TRUE);
|
||||
}
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
?>
|
@@ -162,6 +162,7 @@ class pluginmanager_form extends e_form
|
||||
if ($this->plug['plugin_version'] != $this->plug_vars['@attributes']['version'] && $this->plug['plugin_installflag'])
|
||||
{
|
||||
// $text .= "<br /><input type='button' class='btn' onclick=\"location.href='".e_SELF."?upgrade.{$this->plug['plugin_id']}'\" title='".EPL_UPGRADE." to v".$this->plug_vars['@attributes']['version']."' value='".EPL_UPGRADE."' />";
|
||||
e107::getMessage()->addInfo("<b>".$tp->toHtml($this->plug['plugin_name'],false,'TITLE')."</b> is ready to be upgraded. (see below)"); // TODO LAN
|
||||
$text .= "<a class='btn btn-default' href='".e_SELF."?upgrade.{$this->plug['plugin_id']}' title=\"".EPL_UPGRADE." v".$this->plug_vars['@attributes']['version']."\" >".ADMIN_UPGRADEPLUGIN_ICON."</a>";
|
||||
}
|
||||
|
||||
@@ -1471,7 +1472,7 @@ class pluginManager{
|
||||
$pgf->plug = $plug;
|
||||
$text .= $pgf->renderTableRow($this->fields, $this->fieldpref, $data, 'plugin_id');
|
||||
|
||||
|
||||
/*
|
||||
$folder = $plug['plugin_path'];
|
||||
if(!empty($versions[$folder]['version']) && version_compare( $plug['plugin_version'], $versions[$folder]['version'], '<'))
|
||||
{
|
||||
@@ -1480,7 +1481,7 @@ class pluginManager{
|
||||
$lan = "A newer version of [x] is available for download.";
|
||||
e107::getMessage()->addInfo($tp->lanVars($lan,$link));
|
||||
e107::getMessage()->addDebug("Local version: ".$plug['plugin_version']." Remote version: ".$versions[$folder]['version']);
|
||||
}
|
||||
}*/
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -59,7 +59,7 @@ $dbupdate = array(); // Array of core upgrade actions
|
||||
|
||||
global $e107cache;
|
||||
|
||||
if (is_readable(e_ADMIN.'ver.php'))
|
||||
if(is_readable(e_ADMIN.'ver.php'))
|
||||
{
|
||||
include(e_ADMIN.'ver.php');
|
||||
}
|
||||
@@ -168,7 +168,7 @@ class e107Update
|
||||
if(varset($_POST['update_core']) && is_array($_POST['update_core']))
|
||||
{
|
||||
$func = key($_POST['update_core']);
|
||||
$message = $this->updateCore($func);
|
||||
$this->updateCore($func);
|
||||
}
|
||||
|
||||
if(varset($_POST['update']) && is_array($_POST['update'])) // Do plugin updates
|
||||
@@ -176,11 +176,7 @@ class e107Update
|
||||
$func = key($_POST['update']);
|
||||
$this->updatePlugin($func);
|
||||
}
|
||||
|
||||
if(vartrue($message))
|
||||
{
|
||||
$mes->addSuccess($message);
|
||||
}
|
||||
|
||||
|
||||
$this->renderForm();
|
||||
}
|
||||
@@ -425,17 +421,22 @@ function update_check()
|
||||
if ($update_needed === TRUE)
|
||||
{
|
||||
$frm = e107::getForm();
|
||||
$label = LAN_UPDATE." ".e107::getParser()->toGlyph('fa-arrow-right');
|
||||
|
||||
|
||||
$txt = "
|
||||
$text = "
|
||||
<form method='post' action='".e_ADMIN_ABS."e107_update.php'>
|
||||
<div>
|
||||
".ADLAN_120."
|
||||
".$frm->admin_button('e107_system_update', LAN_UPDATE, 'other')."
|
||||
</div>
|
||||
<p>".ADLAN_120."</p>
|
||||
".$frm->admin_button('e107_system_update', 'update', 'other', $label)."
|
||||
</div><br />
|
||||
</form>
|
||||
";
|
||||
|
||||
$mes->addInfo($txt);
|
||||
|
||||
|
||||
// $text = ADLAN_120. "<a class='btn btn-xs btn-inline' href='".e_ADMIN_ABS."e107_update.php'>". e107::getParser()->toGlyph('fa-chevron-circle-right')."</a>";
|
||||
// $text .= "<hr />";
|
||||
$mes->addInfo($text);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -201,6 +201,7 @@ class e107
|
||||
'e_ranks' => '{e_HANDLER}e_ranks_class.php',
|
||||
'e_shortcode' => '{e_HANDLER}shortcode_handler.php',
|
||||
'e_system_user' => '{e_HANDLER}user_model.php',
|
||||
'e_theme' => '{e_HANDLER}theme_handler.php',
|
||||
'e_upgrade' => '{e_HANDLER}e_upgrade_class.php',
|
||||
'e_user_model' => '{e_HANDLER}user_model.php',
|
||||
'e_user' => '{e_HANDLER}user_model.php',
|
||||
@@ -1302,7 +1303,7 @@ class e107
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
/**
|
||||
* Retrieve rater singleton object
|
||||
*
|
||||
* @return rater
|
||||
@@ -1384,6 +1385,19 @@ class e107
|
||||
return self::getSingleton('e_menu', true);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Retrieve rater singleton object
|
||||
*
|
||||
* @return e_theme
|
||||
*/
|
||||
public static function getTheme()
|
||||
{
|
||||
return self::getSingleton('e_theme', true);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Retrieve URL singleton object
|
||||
*
|
||||
|
@@ -225,6 +225,54 @@ class e_marketplace
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $data - e107.org plugin/theme feed data.
|
||||
*/
|
||||
public function getDownloadModal($type='plugin',$data)
|
||||
{
|
||||
|
||||
$url = false;
|
||||
|
||||
if($type === 'plugin')
|
||||
{
|
||||
|
||||
$srcData = array(
|
||||
'plugin_id' => $data['params']['id'],
|
||||
'plugin_folder' => $data['folder'],
|
||||
'plugin_price' => $data['price'],
|
||||
'plugin_mode' => $data['params']['mode'],
|
||||
'plugin_url' => $data['url'],
|
||||
);
|
||||
|
||||
|
||||
|
||||
$d = http_build_query($srcData,false,'&');
|
||||
$url = e_ADMIN.'plugin.php?mode=download&src='.base64_encode($d);
|
||||
}
|
||||
|
||||
if($type === 'theme')
|
||||
{
|
||||
$srcData = array(
|
||||
'id' => $data['params']['id'],
|
||||
'url' => $data['url'],
|
||||
'mode' => 'addon',
|
||||
'price' => $data['price']
|
||||
);
|
||||
|
||||
$d = http_build_query($srcData,false,'&');
|
||||
$url = e_ADMIN.'theme.php?mode=download&src='.base64_encode($d);//$url.'&action=download';
|
||||
|
||||
}
|
||||
|
||||
|
||||
return $url;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public function getVersionList($type='plugin')
|
||||
{
|
||||
$cache = e107::getCache();
|
||||
@@ -408,7 +456,7 @@ abstract class e_marketplace_adapter_abstract
|
||||
}
|
||||
|
||||
|
||||
if($fl->unzipArchive($localfile,$type))
|
||||
if($fl->unzipArchive($localfile,$type, true))
|
||||
{
|
||||
$mes->addSuccess(TPVLAN_82);
|
||||
return true;
|
||||
|
@@ -1321,7 +1321,7 @@ class e_file
|
||||
* @param string $type - addon type, either 'plugin' or 'theme', (possibly 'language' in future).
|
||||
* @return string unzipped folder name on success or false.
|
||||
*/
|
||||
public function unzipArchive($localfile, $type)
|
||||
public function unzipArchive($localfile, $type, $overwrite=false)
|
||||
{
|
||||
$mes = e107::getMessage();
|
||||
|
||||
@@ -1329,7 +1329,7 @@ class e_file
|
||||
|
||||
$dir = false;
|
||||
|
||||
if(class_exists('ZipArchive') && e_DEBUG === true) // PHP7 compat. method.
|
||||
if(class_exists('ZipArchive')) // PHP7 compat. method.
|
||||
{
|
||||
$zip = new ZipArchive;
|
||||
|
||||
@@ -1377,15 +1377,30 @@ class e_file
|
||||
|
||||
if($dir && is_dir($destpath.$dir))
|
||||
{
|
||||
$mes->addError("(".ucfirst($type).") Already Downloaded - ".basename($destpath).'/'.$dir);
|
||||
|
||||
if(file_exists(e_TEMP.$localfile))
|
||||
{
|
||||
@unlink(e_TEMP.$localfile);
|
||||
if($overwrite === true)
|
||||
{
|
||||
if(file_exists(e_TEMP.$localfile))
|
||||
{
|
||||
$time = date("YmdHi");
|
||||
if(rename($destpath.$dir, e_BACKUP.$dir."_".$time))
|
||||
{
|
||||
$mes->addSuccess("Old folder moved to backup directory");
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
$mes->addError("(".ucfirst($type).") Already Downloaded - ".basename($destpath).'/'.$dir);
|
||||
|
||||
if(file_exists(e_TEMP.$localfile))
|
||||
{
|
||||
@unlink(e_TEMP.$localfile);
|
||||
}
|
||||
|
||||
$this->removeDir(e_TEMP.$dir);
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->removeDir(e_TEMP.$dir);
|
||||
return false;
|
||||
}
|
||||
|
||||
if(empty($dir))
|
||||
|
@@ -16,6 +16,482 @@ if(!defined('e107_INIT'))
|
||||
}
|
||||
|
||||
|
||||
// new in v.2.1.4
|
||||
/**
|
||||
* Retrieve info about themes on the system. - optimized for speed.
|
||||
* Class e_theme
|
||||
*/
|
||||
class e_theme
|
||||
{
|
||||
|
||||
private static $allowedCategories = array(
|
||||
'generic',
|
||||
'adult',
|
||||
'blog',
|
||||
'clan',
|
||||
'children',
|
||||
'corporate',
|
||||
'forum',
|
||||
'gaming',
|
||||
'gallery',
|
||||
'news',
|
||||
'social',
|
||||
'video',
|
||||
'multimedia'
|
||||
);
|
||||
|
||||
|
||||
private static $cacheTime = 120; // 2 hours
|
||||
|
||||
|
||||
function __construct()
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get a list of all themes in theme folder and its data.
|
||||
* @param bool|false xml|false
|
||||
* @param bool|false $force force a refresh ie. ignore cached list.
|
||||
* @return array
|
||||
*/
|
||||
public static function getThemeList($mode = false, $force = false)
|
||||
{
|
||||
$themeArray = array();
|
||||
|
||||
$tloop = 1;
|
||||
|
||||
$array = scandir(e_THEME);
|
||||
|
||||
$cacheTag = "Theme_meta";
|
||||
|
||||
if($force === false && $tmp = e107::getCache()->retrieve($cacheTag, self::$cacheTime, true, true))
|
||||
{
|
||||
return e107::unserialize($tmp);
|
||||
}
|
||||
|
||||
foreach($array as $file)
|
||||
{
|
||||
|
||||
if(($mode == 'xml') && !is_readable(e_THEME.$file."/theme.xml"))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
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] = self::getThemeInfo($file);
|
||||
$themeArray[$file]['id'] = $tloop;
|
||||
}
|
||||
$tloop++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$cacheSet = e107::serialize($themeArray,'json');
|
||||
|
||||
e107::getCache()->set($cacheTag,$cacheSet,true,true,true);
|
||||
|
||||
return $themeArray;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public static function getThemeInfo($file)
|
||||
{
|
||||
$reject = array('e_.*');
|
||||
|
||||
$handle2 = e107::getFile()->get_files(e_THEME.$file."/", "\.php|\.css|\.xml|preview\.jpg|preview\.png", $reject, 1);
|
||||
|
||||
$themeArray = array();
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
// ---------------- get information string for css file - Legacy mode (no theme.xml)
|
||||
|
||||
if(strstr($file2, ".css") && !strstr($file2, "menu.css") && strpos($file2, "e_") !== 0)
|
||||
{
|
||||
if($cssContents = file_get_contents(e_THEME.$file."/".$file2))
|
||||
{
|
||||
$nonadmin = preg_match('/\* Non-Admin(.*?)\*\//', $cssContents) ? true : false;
|
||||
preg_match('/\* info:(.*?)\*\//', $cssContents, $match);
|
||||
$match[1] = varset($match[1], '');
|
||||
$scope = ($nonadmin == true) ? 'front' : '';
|
||||
|
||||
|
||||
$themeArray[$file]['css'][] = array("name"=>$file2, "info"=>$match[1], "scope"=>$scope, "nonadmin"=>$nonadmin);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
// $mes->addDebug("Couldn't read file: ".e_THEME.$file."/".$file2);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} // end foreach
|
||||
|
||||
|
||||
|
||||
// Load Theme information and merge with existing array. theme.xml (v2.x theme) is given priority over theme.php (v1.x).
|
||||
|
||||
if(in_array("theme.xml", $themeArray[$file]['files']))
|
||||
{
|
||||
$themeArray[$file] = array_merge($themeArray[$file], self::parse_theme_xml($file));
|
||||
}
|
||||
elseif(in_array("theme.php", $themeArray[$file]['files']))
|
||||
{
|
||||
$themeArray[$file] = array_merge($themeArray[$file], self::parse_theme_php($file));
|
||||
}
|
||||
|
||||
if(!empty($themeArray[$file]['css']) && count($themeArray[$file]['css']) > 1)
|
||||
{
|
||||
$themeArray[$file]['multipleStylesheets'] = true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
return $themeArray[$file];
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
private static function parse_theme_php($path)
|
||||
{
|
||||
$CUSTOMPAGES = "";
|
||||
$tp = e107::getParser();
|
||||
$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" ? "1.1" : false);
|
||||
|
||||
preg_match('/csscompliant(\s*?=\s*?)(\S*?);/si', $themeContents, $match);
|
||||
$css = strtolower($match[2]);
|
||||
$themeArray['csscompliant'] = ($css == "true" ? "2.1" : false);
|
||||
|
||||
/* preg_match('/CUSTOMPAGES(\s*?=\s*?)("|\')(.*?)("|\');/si', $themeContents, $match);
|
||||
$themeArray['custompages'] = array_filter(explode(" ",$match[3]));*/
|
||||
|
||||
$themeContentsArray = explode("\n", $themeContents);
|
||||
|
||||
preg_match_all("#\\$"."CUSTOMHEADER\[(\"|')(.*?)('|\")\].*?#",$themeContents,$match);
|
||||
$customHeaderArray = $match[2];
|
||||
|
||||
preg_match_all("#\\$"."CUSTOMFOOTER\[(\"|')(.*?)('|\")\].*?#",$themeContents,$match);
|
||||
$customFooterArray = $match[2];
|
||||
|
||||
if(!$themeArray['name'])
|
||||
{
|
||||
unset($themeArray);
|
||||
}
|
||||
|
||||
|
||||
$lays['legacyDefault']['@attributes'] = array('title'=>'Default',
|
||||
'plugins'=>'',
|
||||
'default'=>'true');
|
||||
|
||||
// load custompages from theme.php only when theme.xml doesn't exist.
|
||||
if(!file_exists(e_THEME.$path."theme.xml"))
|
||||
{
|
||||
foreach ($themeContentsArray as $line)
|
||||
{
|
||||
if(strstr($line, "CUSTOMPAGES"))
|
||||
{
|
||||
eval(str_replace("$", "\$", $line)); // detect arrays also.
|
||||
}
|
||||
}
|
||||
|
||||
if(is_array($CUSTOMPAGES))
|
||||
{
|
||||
foreach ($CUSTOMPAGES as $key=>$val)
|
||||
{
|
||||
$themeArray['custompages'][$key] = explode(" ", $val);
|
||||
}
|
||||
}
|
||||
elseif($CUSTOMPAGES)
|
||||
{
|
||||
$themeArray['custompages']['legacyCustom'] = explode(" ", $CUSTOMPAGES);
|
||||
$lays['legacyCustom']['@attributes'] = array('title'=>'Custom',
|
||||
'plugins'=>'');
|
||||
}
|
||||
|
||||
|
||||
foreach($customHeaderArray as $tm)
|
||||
{
|
||||
$lays[$tm]['@attributes'] = array('title'=>str_replace("_"," ",$tm),
|
||||
'plugins'=>'');
|
||||
}
|
||||
|
||||
foreach($customFooterArray as $tm)
|
||||
{
|
||||
$lays[$tm]['@attributes'] = array('title'=>str_replace("_"," ",$tm),
|
||||
'plugins'=>'');
|
||||
}
|
||||
}
|
||||
|
||||
$themeArray['path'] = $path;
|
||||
$themeArray['layouts'] = $lays;
|
||||
|
||||
if(file_exists(e_THEME.$path."/preview.jpg"))
|
||||
{
|
||||
$themeArray['preview'] = array("preview.jpg");
|
||||
$themeArray['thumbnail'] = "preview.jpg";
|
||||
}
|
||||
|
||||
if(file_exists(e_THEME.$path."/preview.png"))
|
||||
{
|
||||
$themeArray['preview'] = array("preview.png");
|
||||
$themeArray['thumbnail'] = "preview.png";
|
||||
}
|
||||
// echo "<h2>".$themeArray['name']."</h2>";
|
||||
// print_a($lays);
|
||||
|
||||
return $themeArray;
|
||||
}
|
||||
|
||||
private static function parse_theme_xml($path)
|
||||
{
|
||||
$tp = e107::getParser();
|
||||
$xml = e107::getXml();
|
||||
|
||||
// loadLanFiles($path, 'admin'); // Look for LAN files on default paths
|
||||
// layout should always be an array.
|
||||
$xml->setOptArrayTags('layout,screenshots/image');
|
||||
$xml->setOptStringTags('menuPresets,customPages,custompages');
|
||||
|
||||
|
||||
// $vars = $xml->loadXMLfile(e_THEME.$path.'/theme.xml', true, true);
|
||||
// $oldvars =
|
||||
$vars = $xml->loadXMLfile(e_THEME.$path.'/theme.xml', 'advanced', true); // must be 'advanced'
|
||||
|
||||
if($path == "bootstrap3" )
|
||||
{
|
||||
// echo "<table class='table table-bordered'>
|
||||
// <tr><th>old</th><th>new parser</th></tr>
|
||||
// <tr><td>".print_a($oldvars,true)."</td><td>".print_a($vars,true)."</td></tr></table>";
|
||||
}
|
||||
|
||||
|
||||
$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'] = self::getThemeCategory(varset($vars['category']));
|
||||
$vars['xhtmlcompliant'] = varset($vars['compliance']['@attributes']['xhtml']);
|
||||
$vars['csscompliant'] = varset($vars['compliance']['@attributes']['css']);
|
||||
$vars['path'] = $path;
|
||||
$vars['@attributes']['default'] = (varset($vars['@attributes']['default']) && strtolower($vars['@attributes']['default']) == 'true') ? 1 : 0;
|
||||
$vars['preview'] = varset($vars['screenshots']['image']);
|
||||
$vars['thumbnail'] = varset($vars['preview'][0]);
|
||||
|
||||
if(!empty($vars['themePrefs']))
|
||||
{
|
||||
|
||||
foreach($vars['themePrefs']['pref'] as $k=>$val)
|
||||
{
|
||||
$name = $val['@attributes']['name'];
|
||||
$vars['preferences'][$name] = $val['@value'];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
unset($vars['authorEmail'], $vars['authorUrl'], $vars['xhtmlCompliant'], $vars['cssCompliant'], $vars['description'],$vars['screenshots']);
|
||||
|
||||
// Compile layout information into a more usable format.
|
||||
|
||||
|
||||
$custom = array();
|
||||
/*
|
||||
foreach ($vars['layouts'] as $layout)
|
||||
{
|
||||
foreach ($layout as $key=>$val)
|
||||
{
|
||||
$name = $val['@attributes']['name'];
|
||||
unset($val['@attributes']['name']);
|
||||
$lays[$name] = $val;
|
||||
|
||||
|
||||
if(isset($val['customPages']))
|
||||
{
|
||||
$cusArray = explode(" ", $val['customPages']);
|
||||
$custom[$name] = array_filter($cusArray);
|
||||
}
|
||||
if(isset($val['custompages']))
|
||||
{
|
||||
$cusArray = explode(" ", $val['custompages']);
|
||||
$custom[$name] = array_filter(explode(" ", $val['custompages']));
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
$lays = array();
|
||||
|
||||
foreach($vars['layouts']['layout'] as $k=>$val)
|
||||
{
|
||||
$name = $val['@attributes']['name'];
|
||||
unset($val['@attributes']['name']);
|
||||
$lays[$name] = $val;
|
||||
|
||||
|
||||
if(isset($val['custompages']))
|
||||
{
|
||||
if(is_string($val['custompages']))
|
||||
{
|
||||
$custom[$name] = array_filter(explode(" ", $val['custompages']));
|
||||
}
|
||||
elseif(is_array($val['custompages']))
|
||||
{
|
||||
$custom[$name] = $val['custompages'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$vars['layouts'] = $lays;
|
||||
$vars['path'] = $path;
|
||||
$vars['custompages'] = $custom;
|
||||
|
||||
if(!empty($vars['stylesheets']['css']))
|
||||
{
|
||||
$vars['css'] = array();
|
||||
|
||||
foreach($vars['stylesheets']['css'] as $val)
|
||||
{
|
||||
$notadmin = vartrue($val['@attributes']['admin']) ? false : true;
|
||||
|
||||
$vars['css'][] = array("name" => $val['@attributes']['file'], "info"=> $val['@attributes']['name'], "nonadmin"=>$notadmin, 'scope'=> vartrue($val['@attributes']['scope']));
|
||||
}
|
||||
|
||||
unset($vars['stylesheets']);
|
||||
}
|
||||
|
||||
|
||||
$vars['glyphs'] = array();
|
||||
if(!empty($vars['glyphicons']['glyph']))
|
||||
{
|
||||
|
||||
foreach($vars['glyphicons']['glyph'] as $val)
|
||||
{
|
||||
$vars['glyphs'][] = array(
|
||||
'name' => $val['@attributes']['name'],
|
||||
'pattern' => $val['@attributes']['pattern'],
|
||||
'path' => $val['@attributes']['path'],
|
||||
'prefix' => $val['@attributes']['prefix'],
|
||||
'tag' => $val['@attributes']['tag'],
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
unset($vars['glyphicons']);
|
||||
|
||||
}
|
||||
|
||||
|
||||
if($path == "leasure" )
|
||||
{
|
||||
|
||||
// $mes->addDebug("<h2>".$path."</h2>");
|
||||
// $mes->addDebug(print_a($vars,true));
|
||||
// $mes->addDebug("<hr />");
|
||||
}
|
||||
|
||||
if($path == "bootstrap3" )
|
||||
{
|
||||
// print_a($vars);
|
||||
// echo "<table class='table'><tr><td>".print_a($vars,true)."</td><td>".print_a($adv,true)."</td></tr></table>";
|
||||
}
|
||||
|
||||
|
||||
return $vars;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Validate and return the name of the categories.
|
||||
*
|
||||
* @param string [optional] $categoryfromXML
|
||||
* @return string
|
||||
*/
|
||||
private static function getThemeCategory($categoryfromXML = '')
|
||||
{
|
||||
if(!$categoryfromXML)
|
||||
{
|
||||
return 'generic';
|
||||
}
|
||||
|
||||
$tmp = explode(",", $categoryfromXML);
|
||||
$category = array();
|
||||
foreach ($tmp as $cat)
|
||||
{
|
||||
$cat = trim($cat);
|
||||
if(in_array($cat, self::$allowedCategories))
|
||||
{
|
||||
$category[] = $cat;
|
||||
}
|
||||
else
|
||||
{
|
||||
$category[] = 'generic';
|
||||
}
|
||||
}
|
||||
|
||||
return implode(', ', $category);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class themeHandler
|
||||
{
|
||||
|
||||
|
@@ -503,5 +503,7 @@ define("LAN_CREATE_ANOTHER", "create another");
|
||||
define("LAN_EDIT_CURRENT", "edit current");
|
||||
define("LAN_MAINTENANCE", "Maintenance");
|
||||
define("LAN_RETURN_TO_FRONT_PANEL", "Return to Front Panel");
|
||||
define("LAN_CHANGE_LANGUAGE", "Change Language");
|
||||
define("LAN_CHANGE_LANGUAGE", "Change Language");
|
||||
|
||||
define("LAN_NEWER_VERSION_OF_X", "A newer version of the [x] [y] is available for download."); // x= Name y = Theme | Plugin
|
||||
|
||||
|
Reference in New Issue
Block a user