1
0
mirror of https://github.com/e107inc/e107.git synced 2025-08-11 17:14:42 +02:00

e_plugin class optimized.

This commit is contained in:
Cameron
2017-02-04 12:49:44 -08:00
parent 20e9f97bb0
commit 479cdd7d8f
3 changed files with 60 additions and 44 deletions

View File

@@ -292,7 +292,7 @@ class e_db_mysql
if($this->mySQLserver === 'localhost') if($this->mySQLserver === 'localhost')
{ {
$this->mySQLserver = '127.0.0.1'; // faster by almost 1 second. $this->mySQLserver = '127.0.0.1'; // faster by almost 1 second.
} }

View File

@@ -32,6 +32,7 @@ class e_plugin
protected $_ids = array(); protected $_ids = array();
protected $_installed = array(); protected $_installed = array();
protected $_addons = array(); protected $_addons = array();
protected $_plugdir = null; // the currently loaded plugin
const CACHETIME = 120; // 2 hours const CACHETIME = 120; // 2 hours
const CACHETAG = "Meta_plugin"; const CACHETAG = "Meta_plugin";
@@ -41,15 +42,28 @@ class e_plugin
function __construct() function __construct()
{ {
$this->load(); $this->init();
if(empty($this->_ids)) if(empty($this->_ids))
{ {
$this->loadIDs(); $this->initIDs();
} }
} }
/**
* Load specified plugin data.
* @param string $plugdir
* @return e_plugin
*/
public function load($plugdir)
{
$this->_plugdir = (string) $plugdir;
return $this;
}
public function clearCache() public function clearCache()
{ {
e107::getCache()->clear(self::CACHETAG); e107::getCache()->clear(self::CACHETAG);
@@ -60,45 +74,45 @@ class e_plugin
return $this->_installed; return $this->_installed;
} }
public function getId($plugdir) public function getId()
{ {
if(isset($this->_ids[$plugdir])) if(isset($this->_ids[$this->_plugdir]))
{ {
return $this->_ids[$plugdir]; return $this->_ids[$this->_plugdir];
} }
return false; return false;
} }
public function getCategory($plugdir) public function getCategory()
{ {
if(!isset($this->_data[$plugdir]['category'])) if(!isset($this->_data[$this->_plugdir]['category']))
{ {
return false; return false;
} }
return $this->_data[$plugdir]['category']; return $this->_data[$this->_plugdir]['category'];
} }
public function getDescription($plugdir) public function getDescription()
{ {
if(!isset($this->_data[$plugdir]['description']['@value'])) if(!isset($this->_data[$this->_plugdir]['description']['@value']))
{ {
return false; return false;
} }
return $this->_data[$plugdir]['description']['@value']; return $this->_data[$this->_plugdir]['description']['@value'];
} }
public function getIcon($plugdir, $size = 16) public function getIcon($size = 16)
{ {
$link = $this->_data[$plugdir]['adminLinks']['link'][0]['@attributes']; $link = $this->_data[$this->_plugdir]['adminLinks']['link'][0]['@attributes'];
$k = array(16 => 'iconSmall', 32 => 'icon', 128=>'icon128'); $k = array(16 => 'iconSmall', 32 => 'icon', 128=>'icon128');
$def = array(16 => E_16_PLUGIN, 32 => E_32_PLUGIN); $def = array(16 => E_16_PLUGIN, 32 => E_32_PLUGIN);
@@ -110,16 +124,16 @@ class e_plugin
return $def[$size]; return $def[$size];
} }
$caption = $this->getName($plugdir); $caption = $this->getName();
return "<img src='".e_PLUGIN_ABS.$plugdir.'/'.$link[$key] ."' alt=\"".$caption."\" class='icon S".$size."' />"; return "<img src='".e_PLUGIN_ABS.$this->_plugdir.'/'.$link[$key] ."' alt=\"".$caption."\" class='icon S".$size."' />";
} }
public function getAdminCaption($plugdir) public function getAdminCaption()
{ {
$att = $this->_data[$plugdir]['adminLinks']['link'][0]['@attributes']; $att = $this->_data[$this->_plugdir]['adminLinks']['link'][0]['@attributes'];
if(empty($att['description'])) if(empty($att['description']))
{ {
@@ -132,11 +146,11 @@ class e_plugin
public function getAdminUrl($plugdir) public function getAdminUrl()
{ {
if(isset($this->_data[$plugdir]['administration']['configFile'])) if(isset($this->_data[$this->_plugdir]['administration']['configFile']))
{ {
return e_PLUGIN_ABS.$plugdir.'/'.$this->_data[$plugdir]['administration']['configFile']; return e_PLUGIN_ABS.$this->_plugdir.'/'.$this->_data[$this->_plugdir]['administration']['configFile'];
} }
return false; return false;
@@ -144,7 +158,7 @@ class e_plugin
} }
private function loadIDs() private function initIDs()
{ {
$sql = e107::getDb(); $sql = e107::getDb();
@@ -172,7 +186,7 @@ class e_plugin
} }
private function load($force=false) private function init($force=false)
{ {
$cacheTag = self::CACHETAG; $cacheTag = self::CACHETAG;
@@ -223,28 +237,28 @@ class e_plugin
} }
public function getMeta($plugdir) public function getMeta()
{ {
if(isset($this->_data[$plugdir])) if(isset($this->_data[$this->_plugdir]))
{ {
return $this->_data[$plugdir]; return $this->_data[$this->_plugdir];
} }
return false; return false;
} }
public function getName($plugdir) public function getName()
{ {
if(!empty($this->_data[$plugdir]['@attributes']['lan']) && defined($this->_data[$plugdir]['@attributes']['lan'])) if(!empty($this->_data[$this->_plugdir]['@attributes']['lan']) && defined($this->_data[$this->_plugdir]['@attributes']['lan']))
{ {
return constant($this->_data[$plugdir]['@attributes']['lan']); return constant($this->_data[$this->_plugdir]['@attributes']['lan']);
} }
if(isset($this->_data[$plugdir]['@attributes']['name'])) if(isset($this->_data[$this->_plugdir]['@attributes']['name']))
{ {
return e107::getParser()->toHTML($this->_data[$plugdir]['@attributes']['name'],FALSE,"defs, emotes_off"); return e107::getParser()->toHTML($this->_data[$this->_plugdir]['@attributes']['name'],FALSE,"defs, emotes_off");
} }
return false; return false;

View File

@@ -1003,11 +1003,13 @@ i.e-cat_users-32{ background-position: -555px 0; width: 32px; height: 32px; }
e107::loadLanFiles($path, 'admin'); e107::loadLanFiles($path, 'admin');
} }
$plug->load($path);
$key = ($linkStyle === 'standard') ? "plugnav-".$path : 'p-'.$path; $key = ($linkStyle === 'standard') ? "plugnav-".$path : 'p-'.$path;
$url = $plug->getAdminUrl($path); $url = $plug->getAdminUrl();
$cat = $plug->getCategory($path); $cat = $plug->getCategory();
if(empty($url) || $cat === 'menu') if(empty($url) || $cat === 'menu')
{ {
@@ -1017,25 +1019,25 @@ i.e-cat_users-32{ background-position: -555px 0; width: 32px; height: 32px; }
// Keys compatible with legacy and new admin layouts. // Keys compatible with legacy and new admin layouts.
$arr[$key] = array( $arr[$key] = array(
'text' => $plug->getName($path), 'text' => $plug->getName(),
'description' => $plug->getDescription($path), 'description' => $plug->getDescription(),
'link' => $url, 'link' => $url,
'image' => $plug->getIcon($path,16), 'image' => $plug->getIcon(16),
'image_large' => $plug->getIcon($path,32), 'image_large' => $plug->getIcon(32),
'category' => $cat, 'category' => $cat,
'perm' => "P".$plug->getId($path), 'perm' => "P".$plug->getId(),
'sort' => 2, 'sort' => 2,
'sub_class' => null, 'sub_class' => null,
// Legacy Keys. // Legacy Keys.
'key' => $key, 'key' => $key,
'title' => $plug->getName($path), 'title' => $plug->getName(),
'caption' => $plug->getAdminCaption($path), 'caption' => $plug->getAdminCaption(),
'perms' => "P".$plug->getId($path), 'perms' => "P".$plug->getId(),
'icon' => $plug->getIcon($path,16), 'icon' => $plug->getIcon(16),
'icon_32' => $plug->getIcon($path,32), 'icon_32' => $plug->getIcon(32),
'cat' => $this->plugCatToCoreCat($plug->getCategory($path)) 'cat' => $this->plugCatToCoreCat($plug->getCategory())
); );