]> gitweb.fluxo.info Git - lorea/elgg.git/commitdiff
Fixes #3310. Applied lie2815's patch to use activate.php and deactivate.php instead...
authorbrettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544>
Sat, 16 Apr 2011 22:10:52 +0000 (22:10 +0000)
committerbrettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544>
Sat, 16 Apr 2011 22:10:52 +0000 (22:10 +0000)
git-svn-id: http://code.elgg.org/elgg/trunk@9002 36083f99-b078-4883-b0ff-0f9b5a30f544

engine/classes/ElggPlugin.php
engine/classes/ElggPluginManifest.php
engine/classes/ElggPluginManifestParser18.php
languages/en.php
mod/blog/manifest.xml
mod/blog/start.php
mod/categories/manifest.xml
mod/categories/start.php

index 55be2b887ee5c8b150f4d72edaac48715faf032d..34e8e6732c64fae865110df5792e9217c5a77a4b 100644 (file)
@@ -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);
        }
 
        /**
index a0ec478a93bab8c5c5905170aedd05bb5d21f950..0f3b1d7a862654102bb82163a49e3064c6b56cc6 100644 (file)
@@ -576,36 +576,6 @@ class ElggPluginManifest {
                return $normalized;
        }
 
-       /**
-        * Returns the functions to run upon activation
-        *
-        *  @return array
-        */
-       public function getOnActivate() {
-               $functions = $this->parser->getAttribute('on_activate');
-
-               if (!$functions) {
-                       $functions = array();
-               }
-
-               return $functions;
-       }
-
-       /**
-        * Returns the functions to run upon deactivation
-        *
-        *  @return array
-        */
-       public function getOnDeactivate() {
-               $functions = $this->parser->getAttribute('on_deactivate');
-
-               if (!$functions) {
-                       $functions = array();
-               }
-
-               return $functions;
-       }
-
        /**
         * Returns the admin interface to use.
         *
index 38734f6b48449f0631d769b4d5d20bde4372c2d8..db8b3dc6a51e22758394ef01c2ea556a561c5ac3 100644 (file)
@@ -15,8 +15,8 @@ class ElggPluginManifestParser18 extends ElggPluginManifestParser {
        protected $validAttributes = array(
                'name', 'author', 'version', 'blurb', 'description',
                'website', 'copyright', 'license', 'requires', 'suggests',
-               'screenshot', 'category', 'conflicts', 'provides', 'on_activate',
-               'on_deactivate', 'admin_interface', 'activate_on_install'
+               'screenshot', 'category', 'conflicts', 'provides',
+               'admin_interface', 'activate_on_install'
        );
 
        /**
@@ -52,8 +52,6 @@ class ElggPluginManifestParser18 extends ElggPluginManifestParser {
                                        break;
 
                                // arrays
-                               case 'on_activate':
-                               case 'on_deactivate':
                                case 'category':
                                        $parsed[$element->name][] = $element->content;
                                        break;
index 86fa9c7e7e1592060a0ee9ef5c9c0349cbe6a2d3..6e24edb2d9ffcad59a3f50a21638b967aa238e4e 100644 (file)
@@ -78,7 +78,7 @@ $english = array(
        'ElggPluginPackage:InvalidPlugin:InvalidProvides' => 'Invalid provides type "%s"',
        'ElggPluginPackage:InvalidPlugin:CircularDep' => 'Invalid %s dependency "%s" in plugin %s.  Plugins cannot conflict with or require something they provide!',
 
-       'ElggPlugin:Exception:CannotIncludeStart' => 'Cannot include start.php for plugin %s (guid: %s) at %s.  Check permissions!',
+       'ElggPlugin:Exception:CannotIncludeFile' => 'Cannot include %s for plugin %s (guid: %s) at %s.  Check permissions!',
        'ElggPlugin:Exception:CannotRegisterViews' => 'Cannot open views dir for plugin %s (guid: %s) at %s.  Check permissions!',
        'ElggPlugin:Exception:CannotRegisterLanguages' => 'Cannot register languages for plugin %s (guid: %s) at %s.  Check permissions!',
        'ElggPlugin:Exception:CannotRegisterClasses' => 'Cannot register classes for plugin %s (guid: %s) at %s.  Check permissions!',
@@ -579,7 +579,7 @@ $english = array(
 'This page is the Admin Dashboard and provides a quick overview of your system. '
 . "You can <a class=\"elgg-toggler\" href=\"#widgets-add-panel\">add</a>"
 . " and rearrange widgets to show the information you care about.  The menu to the right is oranganized into"
-. " three areas: 
+. " three areas:
        <ul>
                <li>Administer - Everyday tasks like monitoring reported content, checking online users, and viewing logs.</li>
                <li>Configure - Configuration settings likes the site name, the active plugins, and plugin settings.</li>
@@ -597,7 +597,7 @@ $english = array(
 . " <a href=\"http://docs.elgg.org/wiki/Category:Administration_FAQ\">FAQs</a>, <a href=\"http://docs.elgg.org/wiki/Administration_Manual\">"
 . "manuals</a>, <a href=\"http://blog.elgg.org/\">Elgg news</a>, and <a href=\"http://community.elgg.org/pg/groups/world/\">support forums</a>"
 . " at the <a href=\"http://community.elgg.org/\">Elgg Community</a>.",
-       
+
        'admin:widget:admin_welcome:outro' => 'Thank you for using Elgg!',
 
        'admin:footer:faq' => 'Administration FAQ',
index 4d853a9aab265ada9160bee5aa969845c3a1d455..f0ec96e8bf8c807fa9cf4e7286441f44ff37f4a3 100644 (file)
@@ -16,5 +16,4 @@
        </requires>
        <admin_interface>simple</admin_interface>
        <activate_on_install>true</activate_on_install>
-       <on_activate>blog_on_activate</on_activate>
 </plugin_manifest>
index 7d42e80b9dc4f95c8b0a5891b7ebedd8074846b7..33c6ee20db39f11c1f6d04b65c15b7ea76a23064 100644 (file)
@@ -18,7 +18,7 @@ elgg_register_event_handler('init', 'system', 'blog_init');
  * Init blog plugin.
  */
 function blog_init() {
-       
+
        elgg_register_library('elgg:blog', elgg_get_plugins_path() . 'blog/lib/blog.php');
 
        // add a site navigation item
@@ -101,14 +101,14 @@ function blog_page_handler($page) {
        // @todo remove the forwarder in 1.9
        // forward to correct URL for bookmarks pre-1.7.5
        blog_url_forwarder($page);
-       
+
        // push all blogs breadcrumb
        elgg_push_breadcrumb(elgg_echo('blog:blogs'), "blog/all");
 
        if (!isset($page[0])) {
                $page[0] = 'all';
        }
-       
+
        $page_type = $page[0];
        switch ($page_type) {
                case 'owner':
@@ -143,7 +143,7 @@ function blog_page_handler($page) {
                        $params = blog_get_page_content_list();
                        break;
        }
-       
+
        $params['sidebar'] .= elgg_view('blog/sidebar', array('page' => $page_type));
 
        $body = elgg_view_layout('content', $params);
@@ -224,13 +224,6 @@ function blog_ecml_views_hook($hook, $entity_type, $return_value, $params) {
        return $return_value;
 }
 
-/**
- * Runs when blog plugin is activated. See manifest file.
- */
-function blog_on_activate() {
-       add_subtype('object', 'blog', 'ElggBlog');
-}
-
 /**
  * When upgrading, check if the ElggBlog class has been registered as this
  * was added in Elgg 1.8
index f02d7a8cbb808df71c7f2c6a8e06d16d1bb18baa..43df13d0290d50ae750651f0c2bae441696c8494 100644 (file)
@@ -14,6 +14,4 @@
                <version>2010030101</version>
        </requires>
        <admin_interface>advanced</admin_interface>
-       <on_activate>categories_on_activate</on_activate>
-       <on_deactivate>categories_on_deactivate</on_deactivate>
 </plugin_manifest>
index 190996d9b80fe2cae23311b6f4dc299df7bf7de6..ff5b01efcf1326fbb91a21345edb98bf5c8aab79 100644 (file)
@@ -54,24 +54,3 @@ function categories_save($event, $object_type, $object) {
        }
        return TRUE;
 }
-
-/**
- * Add a reminder to set default categories.
- */
-function categories_on_activate() {
-       $site = elgg_get_site_entity();
-       
-       if (!$site->categories) {
-               $url = elgg_normalize_url('admin/plugin_settings/categories');
-               $message = elgg_echo('categories:on_enable_reminder', array($url));
-               elgg_add_admin_notice('categories_admin_notice_no_categories', $message);
-       }
-       return TRUE;
-}
-
-/**
- * Clean up admin notices on disable.
- */
-function categories_on_deactivate() {
-       elgg_delete_admin_notice('categories_admin_notice_no_categories');
-}