/** * Creates a new plugin from path * * @note Internal: also supports database objects * * @warning Unlike other \ElggEntity objects, you cannot null instantiate * \ElggPlugin. You must provide the path to the plugin directory. * * @param string $path The absolute path of the plugin * * @throws PluginException */ public function __construct($path) { if (!$path) { throw new \PluginException("ElggPlugin cannot be null instantiated. You must pass a full path."); } if (is_object($path)) { // database object parent::__construct($path); $this->path = _elgg_services()->config->getPluginsPath() . $this->getID(); _elgg_cache_plugin_by_id($this); return; } if (is_numeric($path)) { // guid // @todo plugins with directory names of '12345' throw new \InvalidArgumentException('$path cannot be a GUID'); } $this->initializeAttributes(); // path checking is done in the package $path = sanitise_filepath($path); $this->path = $path; $path_parts = explode('/', rtrim($path, '/')); $plugin_id = array_pop($path_parts); $this->title = $plugin_id; // check if we're loading an existing plugin $existing_plugin = elgg_get_plugin_from_id($plugin_id); if ($existing_plugin) { $this->load($existing_plugin->guid); } _elgg_cache_plugin_by_id($this); }
/** * Loads the plugin by GUID or path. * * @warning Unlike other ElggEntity objects, you cannot null instantiate * ElggPlugin. You must point it to an actual plugin GUID or location. * * @param mixed $plugin The GUID of the ElggPlugin object or the path of the plugin to load. * * @throws PluginException */ public function __construct($plugin) { if (!$plugin) { throw new PluginException(elgg_echo('PluginException:NullInstantiated')); } // ElggEntity can be instantiated with a guid or an object. // @todo plugins w/id 12345 if (is_numeric($plugin) || is_object($plugin)) { parent::__construct($plugin); $this->path = elgg_get_plugins_path() . $this->getID(); } else { $plugin_path = elgg_get_plugins_path(); // not a full path, so assume an id // use the default path if (strpos($plugin, $plugin_path) !== 0) { $plugin = $plugin_path . $plugin; } // path checking is done in the package $plugin = sanitise_filepath($plugin); $this->path = $plugin; $path_parts = explode('/', rtrim($plugin, '/')); $plugin_id = array_pop($path_parts); $this->pluginID = $plugin_id; // check if we're loading an existing plugin $existing_plugin = elgg_get_plugin_from_id($this->pluginID); $existing_guid = null; if ($existing_plugin) { $existing_guid = $existing_plugin->guid; } // load the rest of the plugin parent::__construct($existing_guid); } _elgg_cache_plugin_by_id($this); }
/** * Creates a new plugin from path * * @internal also supports database objects * * @warning Unlike other ElggEntity objects, you cannot null instantiate * ElggPlugin. You must provide the path to the plugin directory. * * @param string $path The absolute path of the plugin * * @throws PluginException */ public function __construct($path) { if (!$path) { throw new PluginException("ElggPlugin cannot be null instantiated. You must pass a full path."); } if (is_object($path)) { // database object parent::__construct($path); $this->path = elgg_get_plugins_path() . $this->getID(); } else { if (is_numeric($path)) { // guid // @todo plugins with directory names of '12345' elgg_deprecated_notice("Use elgg_get_plugin_from_id() to load a plugin.", 1.9); parent::__construct($path); $this->path = elgg_get_plugins_path() . $this->getID(); } else { $mod_dir = elgg_get_plugins_path(); // not a full path, so assume a directory name and use the default path if (strpos($path, $mod_dir) !== 0) { elgg_deprecated_notice("You should pass a full path to ElggPlugin.", 1.9); $path = $mod_dir . $path; } // path checking is done in the package $path = sanitise_filepath($path); $this->path = $path; $path_parts = explode('/', rtrim($path, '/')); $plugin_id = array_pop($path_parts); $this->pluginID = $plugin_id; // check if we're loading an existing plugin $existing_plugin = elgg_get_plugin_from_id($this->pluginID); $existing_guid = null; if ($existing_plugin) { $existing_guid = $existing_plugin->guid; } // load the rest of the plugin parent::__construct($existing_guid); } } _elgg_cache_plugin_by_id($this); }