]> gitweb.fluxo.info Git - lorea/elgg.git/commitdiff
Fixes #2519 we can now register and load php libraries - blog plugin is using this
authorcash <cash@36083f99-b078-4883-b0ff-0f9b5a30f544>
Sat, 4 Dec 2010 22:51:37 +0000 (22:51 +0000)
committercash <cash@36083f99-b078-4883-b0ff-0f9b5a30f544>
Sat, 4 Dec 2010 22:51:37 +0000 (22:51 +0000)
git-svn-id: http://code.elgg.org/elgg/trunk@7532 36083f99-b078-4883-b0ff-0f9b5a30f544

engine/lib/elgglib.php
mod/blog/lib/blog.php [moved from mod/blog/blog_lib.php with 100% similarity]
mod/blog/start.php

index f41e5fd6a0ca1d8635a2a66f177d32b2cc5b4083..2184fee41c995bc9e7715c193fdf91141edbf5bd 100644 (file)
@@ -34,6 +34,7 @@ function _elgg_autoload($class) {
  * @param string $dir The dir to look in
  *
  * @return void
+ * @since 1.8.0
  */
 function elgg_register_classes($dir) {
        $classes = elgg_get_file_list($dir, array(), array(), array('.php'));
@@ -50,6 +51,7 @@ function elgg_register_classes($dir) {
  * @param string $location The location of the file
  *
  * @return void
+ * @since 1.8.0
  */
 function elgg_register_class($class, $location) {
        global $CONFIG;
@@ -61,6 +63,50 @@ function elgg_register_class($class, $location) {
        $CONFIG->classes[$class] = $location;
 }
 
+/**
+ * Register a php library.
+ *
+ * @param string $name     The name of the library
+ * @param string $location The location of the file
+ *
+ * @return void
+ * @since 1.8.0
+ */
+function elgg_register_library($name, $location) {
+       global $CONFIG;
+
+       if (!isset($CONFIG->libraries)) {
+               $CONFIG->libraries = array();
+       }
+
+       $CONFIG->libraries[$name] = $location;
+}
+
+/**
+ * Load a php library.
+ *
+ * @param string $name     The name of the library
+ *
+ * @return void
+ * @throws Exception
+ * @since 1.8.0
+ */
+function elgg_load_library($name) {
+       global $CONFIG;
+
+       if (!isset($CONFIG->libraries)) {
+               $CONFIG->libraries = array();
+       }
+
+       if (!isset($CONFIG->libraries[$name])) {
+               throw new Exception("Failed to load the $name library");
+       }
+
+       if (!include_once($CONFIG->libraries[$name])) {
+               throw new Exception("Failed to load the $name library");
+       }
+}
+
 /**
  * Forward to $location.
  *
similarity index 100%
rename from mod/blog/blog_lib.php
rename to mod/blog/lib/blog.php
index 0d0c58ac8acf34926d4893207c4d548aff4dbbef..9e3b8f300332d362b81eb16ae33bfc6b55613451 100644 (file)
  * Notifications
  */
 
+elgg_register_event_handler('init', 'system', 'blog_init');
+
 /**
  * Init blog plugin.
- *
- * @return TRUE
  */
 function blog_init() {
-       global $CONFIG;
-       require_once dirname(__FILE__) . '/blog_lib.php';
+       
+       elgg_register_library('elgg:blog', elgg_get_plugin_path() . 'blog/lib/blog.php');
 
        add_menu(elgg_echo('blog:blogs'), "pg/blog/", array());
 
@@ -47,8 +47,8 @@ function blog_init() {
 
        //add_widget_type('blog', elgg_echo('blog'), elgg_echo('blog:widget:description'), 'profile, dashboard');
 
-       $action_path = dirname(__FILE__) . '/actions/blog';
-
+       // register actions
+       $action_path = elgg_get_plugin_path() . 'blog/actions/blog';
        elgg_register_action('blog/save', "$action_path/save.php");
        elgg_register_action('blog/auto_save_revision', "$action_path/auto_save_revision.php");
        elgg_register_action('blog/delete', "$action_path/delete.php");
@@ -92,6 +92,8 @@ function blog_runonce() {
 function blog_page_handler($page) {
        global $CONFIG;
 
+       elgg_load_library('elgg:blog');
+
        // push breadcrumb
        elgg_push_breadcrumb(elgg_echo('blog:blogs'), "pg/blog");
 
@@ -201,5 +203,3 @@ function blog_profile_menu($hook, $entity_type, $return_value, $params) {
 
        return $return_value;
 }
-
-elgg_register_event_handler('init', 'system', 'blog_init');