本文整理汇总了PHP中Plugins::class_from_filename方法的典型用法代码示例。如果您正苦于以下问题:PHP Plugins::class_from_filename方法的具体用法?PHP Plugins::class_from_filename怎么用?PHP Plugins::class_from_filename使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Plugins
的用法示例。
在下文中一共展示了Plugins::class_from_filename方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: activate_plugin
/**
* Activates a plugin file
*/
public static function activate_plugin( $file )
{
$ok = true;
// Keep stream handler and strip base path from stored path
$stream = '';
if(preg_match('#^([^:]+://)#i', $file, $matches)) {
$stream = $matches[1];
$short_file = $file; //$stream . MultiByte::substr( preg_replace('#^([^:]+://)#i', '', $file), strlen( HABARI_PATH ) );
}
else {
$short_file = MultiByte::substr( $file, strlen( HABARI_PATH ) );
}
//Utils::debug($stream, $file);die();
$activated = Options::get( 'active_plugins' );
if ( !is_array( $activated ) || !in_array( $short_file, $activated ) ) {
include_once( $file );
$class = Plugins::class_from_filename( $file );
$plugin = Plugins::load( $class );
$ok = Plugins::filter( 'activate_plugin', $ok, $file ); // Allow plugins to reject activation
}
else if ( is_array( $activated) && in_array( $short_file, $activated ) ) {
$ok = false;
}
if ( $ok ) {
$activated[$class] = $short_file;
Options::set( 'active_plugins', $activated );
$versions = Options::get( 'pluggable_versions' );
if(!isset($versions[$class])) {
$versions[$class] = $plugin->get_version();
Options::set( 'pluggable_versions', $versions );
}
if ( method_exists( $plugin, 'action_plugin_activation' ) ) {
$plugin->action_plugin_activation( $file ); // For the plugin to install itself
}
Plugins::act( 'plugin_activated', $file ); // For other plugins to react to a plugin install
EventLog::log( _t( 'Activated Plugin: %s', array( $plugin->info->name ) ), 'notice', 'plugin', 'habari' );
}
return $ok;
}
示例2: upgrade_db_post_4291
private function upgrade_db_post_4291()
{
// get all plugins so the legacy ones can be deactivated.
$active_plugins = Plugins::list_active();
$all_plugins = Installhandler::get_plugins();
$legacy_plugins = array();
foreach ($all_plugins as $plugin) {
if (!isset($plugin['info'])) {
$key = array_search($plugin['file'], $active_plugins);
$legacy_plugins[$key] = $plugin['file'];
}
}
$valid_plugins = array_diff_key(Options::get('active_plugins'), $legacy_plugins);
// valid_plugins contains only working plugins, but the classnames are missing. The following was previously upgrade_db_post_3484()
$new_plugins = array();
if (is_array($valid_plugins)) {
foreach ($valid_plugins as $filename) {
if (!file_exists($filename)) {
// try adding base path to stored path
$filename = HABARI_PATH . $filename;
}
if (file_exists($filename)) {
// it is now safe to do this since plugins with info() functions are not in $valid_plugins
require_once $filename;
$class = Plugins::class_from_filename($filename);
$short_file = substr($filename, strlen(HABARI_PATH));
if ($class) {
$new_plugins[$class] = $short_file;
}
}
}
}
// replace option with only the usuable plugins
Options::set('active_plugins', $new_plugins);
}
示例3: upgrade_db_post_3484
private function upgrade_db_post_3484()
{
$new_plugins = array();
$plugins = Options::get('active_plugins');
if (is_array($plugins)) {
foreach ($plugins as $filename) {
if (!file_exists($filename)) {
// try adding base path to stored path
$filename = HABARI_PATH . $filename;
}
if (file_exists($filename)) {
require_once $filename;
$class = Plugins::class_from_filename($filename);
$short_file = substr($filename, strlen(HABARI_PATH));
if ($class) {
$new_plugins[$class] = $short_file;
}
}
}
}
Options::set('active_plugins', $new_plugins);
}
示例4: activate_plugin
/**
* Activates a plugin file
*/
public static function activate_plugin($file)
{
$ok = true;
// strip base path from stored path
$short_file = MultiByte::substr($file, strlen(HABARI_PATH));
$activated = Options::get('active_plugins');
if (!is_array($activated) || !in_array($short_file, $activated)) {
include_once $file;
$class = Plugins::class_from_filename($file);
$plugin = Plugins::load($class);
$ok = Plugins::filter('activate_plugin', $ok, $file);
// Allow plugins to reject activation
} else {
if (is_array($activated) && in_array($short_file, $activated)) {
$ok = false;
}
}
if ($ok) {
$activated[$class] = $short_file;
Options::set('active_plugins', $activated);
$versions = Options::get('pluggable_versions');
if (!isset($versions[$class])) {
$versions[$class] = $plugin->get_version();
Options::set('pluggable_versions', $versions);
}
if (method_exists($plugin, 'action_plugin_activation')) {
$plugin->action_plugin_activation($file);
// For the plugin to install itself
}
Plugins::act('plugin_activated', $file);
// For other plugins to react to a plugin install
EventLog::log(_t('Activated Plugin: %s', array($plugin->info->name)), 'notice', 'plugin', 'habari');
}
return $ok;
}
示例5: activate_plugin
/**
* Activates a plugin file
*/
public static function activate_plugin($file)
{
$ok = true;
// check for a URL-looking filename, which probably indicates a PHAR-format plugin
if (preg_match('#^([^:]+://)#i', $file, $matches)) {
// we need the entire path to the file
$short_file = $file;
} else {
// trim off the leading habari path from the filename
$short_file = MultiByte::substr($file, strlen(HABARI_PATH));
}
//Activate all dependency plugins first
$provider_data = self::provided(null, true, true);
$providing_data = self::provided();
$info = self::load_info($file);
if (isset($info->requires)) {
$dependencies = array();
foreach ($info->requires->feature as $feature) {
// Does something already provide this required feature?
if (isset($providing_data[(string) $feature])) {
continue;
}
// Could one inactive thing provide this required feature?
if (isset($provider_data[(string) $feature]) && count($provider_data[(string) $feature]) == 1) {
$dependencies[] = reset($provider_data[(string) $feature]);
} else {
return false;
}
}
// Try to activate the dependencies we accumulated just then
foreach ($dependencies as $dependency) {
$result = self::activate_plugin($dependency);
// Couldn't activate a dependency? Can't activate this one.
if (!$result) {
return false;
}
}
}
$activated = Options::get('active_plugins');
if (!is_array($activated) || !in_array($short_file, $activated)) {
include_once $file;
$class = Plugins::class_from_filename($file);
$plugin = Plugins::load($class);
$ok = Plugins::filter('activate_plugin', $ok, $file);
// Allow plugins to reject activation
} else {
if (is_array($activated) && in_array($short_file, $activated)) {
$ok = false;
}
}
if ($ok) {
$activated[$class] = $short_file;
Options::set('active_plugins', $activated);
$versions = Options::get('pluggable_versions');
if (!isset($versions[$class])) {
$versions[$class] = $plugin->get_version();
Options::set('pluggable_versions', $versions);
}
if (method_exists($plugin, 'action_plugin_activation')) {
$plugin->action_plugin_activation($file);
// For the plugin to install itself
}
Plugins::act('plugin_activated', $file);
// For other plugins to react to a plugin install
EventLog::log(_t('Activated Plugin: %s', array($plugin->info->name)), 'notice', 'plugin', 'habari');
}
return $ok;
}
示例6: load
/**
* function load
* Initialize all loaded plugins by calling their load() method
* @param string $file the class name to load
* @param boolean $activate True if the plugin's load() method should be called
* @return Plugin The instantiated plugin class
**/
public static function load($file, $activate = true)
{
$class = Plugins::class_from_filename($file);
$plugin = new $class();
if ($activate) {
self::$plugins[$plugin->plugin_id] = $plugin;
$plugin->load();
}
return $plugin;
}