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

Plugin class fixes regarding plugins that don't require installation and plugin table updates.

This commit is contained in:
Cameron 2017-02-08 17:37:24 -08:00
parent aaf450ea93
commit 478f488337
2 changed files with 191 additions and 14 deletions

View File

@ -206,7 +206,10 @@ class plugin_ui extends e_admin_ui
public function init()
{
if(!e_QUERY)
{
e107::getPlug()->clearCache();
}
@ -4179,7 +4182,7 @@ class pluginBuilder
'about' => EPL_ADLAN_154
);
$text = $frm->select($name, $options, $default,'required=1&class=null', true);
$text = $frm->select($name, $options, $default,'required=1&class=form-control', true);
break;
case 'keywordDropDown':
@ -4208,7 +4211,7 @@ class pluginBuilder
sort($options);
$text = $frm->select($name, $options, $default,'required=1&class=null&useValues=1', true);
$text = $frm->select($name, $options, $default,'required=1&class=form-control&useValues=1', true);
break;
@ -5206,7 +5209,7 @@ exit;
{
if(file_put_contents($generatedFile, $startPHP .$text . $endPHP))
{
$message = str_replace("[x]", "<a href='".$generatedFile."'>".EPL_ADLAN_216."</a>", EPL_ADLAN_217);
$message = str_replace("[x]", "<a class='alert-link' href='".$generatedFile."'>".EPL_ADLAN_216."</a>", EPL_ADLAN_217);
$mes->addSuccess($message);
}
else

View File

@ -37,21 +37,65 @@ class e_plugin
const CACHETIME = 120; // 2 hours
const CACHETAG = "Meta_plugin";
protected $_addon_types = array(
'e_admin',
'e_bb',
'e_cron',
'e_notify',
'e_linkgen',
'e_list',
'e_meta', // @Deprecated
'e_emailprint',
'e_frontpage',
'e_latest', /* @deprecated - see e_dashboard */
'e_status', /* @deprecated - see e_dashboard */
'e_menu',
'e_search',
'e_shortcode',
'e_module',
'e_event',
'e_comment',
'e_sql',
'e_dashboard', // Admin Front-Page addon.
// 'e_userprofile', @deprecated @see e_user
'e_header', // loaded in header prior to javascript manager.
'e_footer', // Loaded in footer prior to javascript manager.
// 'e_userinfo', @deprecated @see e_user
'e_tagwords',
'e_url', // simple mod-rewrite.
'e_mailout',
'e_sitelink', // sitelinks generator.
'e_tohtml', /* @deprecated - use e_parse */
'e_featurebox',
'e_parse',
'e_related',
'e_rss',
'e_upload',
'e_user',
'e_library', // For third-party libraries are defined by plugins/themes.
);
private $_accepted_categories = array('settings'=>LAN_SETTINGS, 'users'=>ADLAN_36, 'content'=>ADLAN_CL_3,'tools'=> ADLAN_CL_6, 'manage'=>LAN_MANAGE,'misc'=> ADLAN_CL_8, 'menu'=>'menu', 'about'=> 'about');
function __construct()
{
$this->init();
$this->_init();
if(empty($this->_ids))
{
$this->initIDs();
$this->_initIDs();
}
}
/**
/**
* Load specified plugin data.
* @param string $plugdir
* @return e_plugin
@ -68,11 +112,16 @@ class e_plugin
return $this->_accepted_categories;
}
public function getDetected()
{
return array_keys($this->_data);
}
public function clearCache()
{
$this->init(true);
$this->initIDs();
$this->_init(true);
$this->_initIDs();
return $this;
}
@ -264,7 +313,7 @@ class e_plugin
}
private function initIDs()
private function _initIDs()
{
$sql = e107::getDb();
@ -287,12 +336,130 @@ class e_plugin
}
$detected = $this->getDetected();
$runUpdate = false;
foreach($detected as $path) // add a missing plugin to the database table.
{
if(!isset($this->_ids[$path]) && !empty($this->_data[$path]['@attributes']))
{
$this->load($path);
$row = $this->_getFields();
//var_dump($row);
if(!$sql->insert('plugin',$row))
{
e107::getDebug()->log("Unable to insert plugin data into table".print_a($row,true));
}
else
{
$this->_addons[$path] = !empty($row['plugin_addons']) ? explode(',',$row['plugin_addons']) : null;
$runUpdate = true;
if($row['plugin_installflag'] == 1)
{
e107::getConfig()->setPref('plug_installed/'.$path, $row['plugin_version'])->save(false,true,false);
}
}
}
}
if($runUpdate === true) // clearCache
{
$this->_init(true);
}
}
private function init($force=false)
private function _getFields()
{
$ret = array(
'plugin_name' => $this->getName('db'),
'plugin_version' => $this->getVersion(),
'plugin_path' => $this->_plugdir,
'plugin_installflag' => ($this->getInstallRequired() === true) ? 0 : 1,
'plugin_addons' => $this->getAddons(),
'plugin_category' => $this->getCategory()
);
return $ret;
}
/**
*Returns a list of addons available for the currently loaded plugin.
* @return string (comma separated)
*/
public function getAddons()
{
$allFiles = $this->_data[$this->_plugdir]['files'];
$addons = array();
foreach($this->_addon_types as $ad)
{
$file = $ad.".php";
if(in_array($file,$allFiles))
{
$addons[] = $ad;
}
}
foreach($allFiles as $file)
{
if(substr($file, -8) === "_sql.php")
{
$addons[] = str_replace(".php", '', $file);
}
if(substr($file, -3) === ".bb")
{
$addons[] = $file;
}
if(substr($file, -3) === ".sc")
{
$addons[] = $file;
}
if(preg_match('/^bb_(.*)\.php$/',$file))
{
$addons[] = $file;
}
}
if(!empty($this->_data[$this->_plugdir]['shortcodes']))
{
foreach($this->_data[$this->_plugdir]['shortcodes'] as $val)
{
$addons[] = 'sc_'.$val;
}
}
return implode(',', $addons);
}
private function _init($force=false)
{
$cacheTag = self::CACHETAG;
@ -309,6 +476,7 @@ class e_plugin
foreach($dirs as $plugName)
{
$ret = null;
if($plugName === '.' || $plugName === '..' || !is_dir(e_PLUGIN.$plugName))
{
@ -355,16 +523,16 @@ class e_plugin
}
public function getName()
public function getName($mode=null)
{
if(!empty($this->_data[$this->_plugdir]['@attributes']['lan']) && defined($this->_data[$this->_plugdir]['@attributes']['lan']))
{
return constant($this->_data[$this->_plugdir]['@attributes']['lan']);
return ($mode === 'db') ? $this->_data[$this->_plugdir]['@attributes']['lan'] : constant($this->_data[$this->_plugdir]['@attributes']['lan']);
}
if(isset($this->_data[$this->_plugdir]['@attributes']['name']))
{
return e107::getParser()->toHTML($this->_data[$this->_plugdir]['@attributes']['name'],FALSE,"defs, emotes_off");
return ($mode === 'db') ? $this->_data[$this->_plugdir]['@attributes']['name'] : e107::getParser()->toHTML($this->_data[$this->_plugdir]['@attributes']['name'],FALSE,"defs, emotes_off");
}
return false;
@ -451,6 +619,12 @@ class e_plugin
$ret['administration']['configFile'] = varset($ret['adminLinks']['link'][0]['@attributes']['url']);
$ret['legacy'] = false;
if (is_dir(e_PLUGIN.$plugName."/shortcodes/single/"))
{
$ret['shortcodes'] = preg_grep('/^([^.])/', scandir(e_PLUGIN.$plugName,SCANDIR_SORT_ASCENDING));
}
return $ret;
}