diff options
| author | brettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544> | 2011-04-16 22:10:52 +0000 | 
|---|---|---|
| committer | brettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544> | 2011-04-16 22:10:52 +0000 | 
| commit | 6729a2d0d2faeb07ca8e79b5162c3be269e01b66 (patch) | |
| tree | 119609339fa2914d81f43a98a8f9fd6193db0d34 /engine/classes/ElggPlugin.php | |
| parent | 2b2afd98c05139c1a5c25f1752e2bb412e26e335 (diff) | |
| download | elgg-6729a2d0d2faeb07ca8e79b5162c3be269e01b66.tar.gz elgg-6729a2d0d2faeb07ca8e79b5162c3be269e01b66.tar.bz2  | |
Fixes #3310. Applied lie2815's patch to use activate.php and deactivate.php instead of manifest on_de/activate fields in plugins.
git-svn-id: http://code.elgg.org/elgg/trunk@9002 36083f99-b078-4883-b0ff-0f9b5a30f544
Diffstat (limited to 'engine/classes/ElggPlugin.php')
| -rw-r--r-- | engine/classes/ElggPlugin.php | 86 | 
1 files changed, 37 insertions, 49 deletions
diff --git a/engine/classes/ElggPlugin.php b/engine/classes/ElggPlugin.php index 55be2b887..34e8e6732 100644 --- a/engine/classes/ElggPlugin.php +++ b/engine/classes/ElggPlugin.php @@ -639,24 +639,14 @@ class ElggPlugin extends ElggObject {  			// if there are any on_enable functions, start the plugin now and run them  			// Note: this will not run re-run the init hooks! -			$functions = $this->manifest->getOnActivate(); -			if ($return && $functions) { -				$flags = ELGG_PLUGIN_INCLUDE_START | ELGG_PLUGIN_REGISTER_CLASSES -						| ELGG_PLUGIN_REGISTER_LANGUAGES | ELGG_PLUGIN_REGISTER_VIEWS; - -				$this->start($flags); -				foreach ($functions as $function) { -					if (!is_callable($function)) { -						$return = false; -					} else { -						$result = call_user_func($function); -						// allow null to mean "I don't care" like other subsystems -						$return = ($result === false) ? false: true; -					} - -					if ($return === false) { -						break; -					} +			if ($return) { +				if ($this->canIncludeFile('activate.php')) { +					$flags = ELGG_PLUGIN_INCLUDE_START | ELGG_PLUGIN_REGISTER_CLASSES +							| ELGG_PLUGIN_REGISTER_LANGUAGES | ELGG_PLUGIN_REGISTER_VIEWS; + +					$this->start($flags); + +					$return = $this->includeFile('activate.php');  				}  			} @@ -690,27 +680,10 @@ class ElggPlugin extends ElggObject {  		$return = elgg_trigger_event('deactivate', 'plugin', $params); -		// run any deactivate functions -		// check for the manifest in case we haven't fully loaded the plugin. -		if ($this->manifest) { -			$functions = $this->manifest->getOnDeactivate(); -		} else { -			$functions = array(); -		} - -		if ($return && $functions) { -			foreach ($functions as $function) { -				if (!is_callable($function)) { -					$return = false; -				} else { -					$result = call_user_func($function); -					// allow null to mean "I don't care" like other subsystems -					$return = ($result === false) ? false : true; -				} - -				if ($return === false) { -					break; -				} +		// run any deactivate code +		if ($return) { +			if ($this->canIncludeFile('deactivate.php')) { +				$return = $this->includeFile('deactivate.php');  			}  		} @@ -736,7 +709,7 @@ class ElggPlugin extends ElggObject {  		// include start file  		if ($flags & ELGG_PLUGIN_INCLUDE_START) { -			$this->includeStart(); +			$this->includeFile('start.php');  		}  		// include views @@ -761,24 +734,39 @@ class ElggPlugin extends ElggObject {  	// start helpers  	/** -	 * Includes the plugin's start file +	 * Includes one of the plugins files +	 * +	 * @param string $filename The name of the file  	 *  	 * @throws PluginException -	 * @return true +	 * @return mixed The return value of the included file (or 1 if there is none)  	 */ -	protected function includeStart() { +	protected function includeFile($filename) {  		// This needs to be here to be backwards compatible for 1.0-1.7.  		// They expect the global config object to be available in start.php. -		global $CONFIG; +		if ($filename == 'start.php') { +			global $CONFIG; +		} + +		$filepath = "$this->path/$filename"; -		$start = "$this->path/start.php"; -		if (!include($start)) { -			$msg = elgg_echo('ElggPlugin:Exception:CannotIncludeStart', -							array($this->getID(), $this->guid, $this->path)); +		if (!$this->canIncludeFile($filename)) { +			$msg = elgg_echo('ElggPlugin:Exception:CannotIncludeFile', +							array($filename, $this->getID(), $this->guid, $this->path));  			throw new PluginException($msg);  		} -		return true; +		return include $filepath; +	} + +	/** +	 * Checks whether a plugin file with the given name exists +	 * +	 * @param string $filename The name of the file +	 * @return bool +	 */ +	protected function canIncludeFile($filename) { +		return file_exists($this->path.'/'.$filename);  	}  	/**  | 
