]> gitweb.fluxo.info Git - lorea/elgg.git/commitdiff
Fixes #2547: Plugins can now participate in autoloading classes.
authorewinslow <ewinslow@36083f99-b078-4883-b0ff-0f9b5a30f544>
Thu, 14 Oct 2010 07:52:31 +0000 (07:52 +0000)
committerewinslow <ewinslow@36083f99-b078-4883-b0ff-0f9b5a30f544>
Thu, 14 Oct 2010 07:52:31 +0000 (07:52 +0000)
git-svn-id: http://code.elgg.org/elgg/trunk@7074 36083f99-b078-4883-b0ff-0f9b5a30f544

engine/lib/elgglib.php
engine/lib/plugins.php
engine/start.php
mod/blog/blog_lib.php

index 4376ca53f0fc832704cb81287f593cbb6e279cea..5b224e0be70429083af9842f2b243e3727a696f2 100644 (file)
@@ -2200,8 +2200,30 @@ function js_page_handler($page) {
        }
 }
 
-function __autoload($class) {
-       require_once dirname(dirname(__FILE__))."/classes/$class.php";
+function __elgg_autoload($class) {
+       global $CONFIG;
+
+       if (!include($CONFIG->classes[$class])) {
+               throw new Exception("Failed to autoload $class");
+       }       
+}
+
+function elgg_register_classes($dir) {
+       $classes = elgg_get_file_list($dir, array(), array(), array('.php'));
+       
+       foreach ($classes as $class) {
+               elgg_register_class(basename($class, '.php'), $class);
+       }
+}
+
+function elgg_register_class($class, $location) {
+       global $CONFIG;
+
+       if (!isset($CONFIG->classes)) {
+               $CONFIG->classes = array();
+       }
+       
+       $CONFIG->classes[$class] = $location;
 }
 
 /**
@@ -2233,7 +2255,7 @@ function __elgg_shutdown_hook() {
  */
 function elgg_init() {
        global $CONFIG;
-
+       
        register_action('comments/add');
        register_action('comments/delete');
        register_action('likes/add');
index a36f2bf6dfdd2bdd531173c3f35a638e9951a79f..52f498bf7d9e5a1e6ca16d911312fe4f5f4d7f06 100644 (file)
@@ -191,6 +191,10 @@ function load_plugins() {
                                                if (is_dir($CONFIG->pluginspath . $mod . "/languages")) {
                                                        register_translations($CONFIG->pluginspath . $mod . "/languages/");
                                                }
+                                               
+                                               if (is_dir($CONFIG->pluginspath . "$mod/classes")) {
+                                                       elgg_register_classes($CONFIG->pluginspath . "$mod/classes");
+                                               }
                                        }
                                }
                        }
index a84a19e0da7099de4559d6743fe371ea68a5ba0a..0bf652cb681e33b490c32352056c733ca9667957 100644 (file)
@@ -77,7 +77,6 @@ foreach ($required_files as $file) {
 set_error_handler('__elgg_php_error_handler');
 set_exception_handler('__elgg_php_exception_handler');
 
-
 /**
  * Load the system settings
  */
@@ -113,6 +112,10 @@ foreach($lib_files as $file) {
        }
 }
 
+// prep core classes to be autoloadable
+spl_autoload_register('__elgg_autoload');
+elgg_register_classes(dirname(__FILE__).'/classes');
+
 // confirm that the installation completed successfully
 verify_installation();
 
index 3152cccada4eeb2cc1da376e0d0f75063322e7d4..1895930aa4c848199d6097590ae9cb06bb9e5ec5 100644 (file)
@@ -278,42 +278,3 @@ function blog_get_blog_months($user_guid = NULL, $container_guid = NULL) {
 
        return get_data($q);
 }
-
-/**
- * Extended class to override the time_created
- */
-class ElggBlog extends ElggObject {
-       protected function initialise_attributes() {
-               parent::initialise_attributes();
-
-               // override the default file subtype.
-               $this->attributes['subtype'] = 'blog';
-       }
-
-       /**
-        * @todo this won't work until we have date l10n working.
-        * Rewrite the time created to be publish time.
-        * This is a bit dirty, but required for proper sorting.
-        */
-//     public function save() {
-//             if (parent::save()) {
-//                     global $CONFIG;
-//
-//                     // try to grab the publish date, but default to now.
-//                     foreach (array('publish_date', 'time_created') as $field) {
-//                             if (isset($this->$field) && $this->field) {
-//                                     $published = $this->field;
-//                                     break;
-//                             }
-//                     }
-//                     if (!$published) {
-//                             $published = time();
-//                     }
-//
-//                     $sql = "UPDATE {$CONFIG->dbprefix}entities SET time_created = '$published', time_updated = '$published' WHERE guid = '{$this->getGUID()}'";
-//                     return update_data($sql);
-//             }
-//
-//             return FALSE;
-//     }
-}
\ No newline at end of file