diff options
author | ben <ben@36083f99-b078-4883-b0ff-0f9b5a30f544> | 2008-03-11 17:18:49 +0000 |
---|---|---|
committer | ben <ben@36083f99-b078-4883-b0ff-0f9b5a30f544> | 2008-03-11 17:18:49 +0000 |
commit | 714ccd2989c219b592460d80b0a455baca1a5fd1 (patch) | |
tree | 128f5769c06418c80a29a54dce3ec0c10f2a47d3 | |
parent | 517d262f59179cd29036b4280a6c5ed5c3a87f33 (diff) | |
download | elgg-714ccd2989c219b592460d80b0a455baca1a5fd1.tar.gz elgg-714ccd2989c219b592460d80b0a455baca1a5fd1.tar.bz2 |
God bless 'em! Plugins now autoregister their own views.
git-svn-id: https://code.elgg.org/elgg/trunk@168 36083f99-b078-4883-b0ff-0f9b5a30f544
-rw-r--r-- | engine/lib/elgglib.php | 24 | ||||
-rw-r--r-- | engine/lib/plugins.php | 3 | ||||
-rw-r--r-- | mod/test/index.php | 4 | ||||
-rw-r--r-- | mod/test/start.php | 4 |
4 files changed, 29 insertions, 6 deletions
diff --git a/engine/lib/elgglib.php b/engine/lib/elgglib.php index f17a86458..973de2680 100644 --- a/engine/lib/elgglib.php +++ b/engine/lib/elgglib.php @@ -179,6 +179,30 @@ }
/**
+ * Auto-registers views from a particular starting location
+ *
+ * @param string $view_base The base of the view name
+ * @param string $folder The folder to begin looking in
+ * @param string $base_location_path The base views directory to use with set_view_location
+ */
+ function autoregister_views($view_base, $folder, $base_location_path) {
+
+ if (!isset($i)) $i = 0;
+ if ($handle = opendir($folder)) {
+ while ($view = readdir($handle)) {
+ if (!in_array($view,array('.','..','.svn','CVS')) && !is_dir($folder . "/" . $view)) {
+ if (substr_count($view,".php") > 0) {
+ set_view_location($view_base . "/" . str_replace(".php","",$view), $base_location_path);
+ }
+ } else if (!in_array($view,array('.','..','.svn','CVS')) && is_dir($folder . "/" . $view)) {
+ autoregister_views($view_base . "/" . $view, $folder . "/" . $view, $base_location_path);
+ }
+ }
+ }
+
+ }
+
+ /**
* Returns a representation of a full 'page' (which might be an HTML page, RSS file, etc, depending on the current view)
*
* @param unknown_type $title
diff --git a/engine/lib/plugins.php b/engine/lib/plugins.php index 34be9b7cf..92294faea 100644 --- a/engine/lib/plugins.php +++ b/engine/lib/plugins.php @@ -28,6 +28,9 @@ if (!in_array($mod,array('.','..','.svn','CVS')) && is_dir($CONFIG->pluginspath . "/" . $mod)) {
if (!@include($CONFIG->pluginspath . $mod . "/start.php"))
throw new PluginException("{$mod} is a misconfigured plugin.");
+ if (is_dir($CONFIG->pluginspath . $mod . "/views/default")) {
+ autoregister_views($mod,$CONFIG->pluginspath . $mod . "/views/default",$CONFIG->pluginspath . $mod . "/views");
+ }
}
}
}
diff --git a/mod/test/index.php b/mod/test/index.php index ffa4387e1..a8a9d347f 100644 --- a/mod/test/index.php +++ b/mod/test/index.php @@ -5,7 +5,7 @@ global $CONFIG;
//var_export($CONFIG);
-
- echo page_draw("Test plugin","");
+ $body = elgg_view("test/testplugin/pageshell");
+ page_draw("Test plugin",$body);
?>
\ No newline at end of file diff --git a/mod/test/start.php b/mod/test/start.php index f406b8abb..345ca7588 100644 --- a/mod/test/start.php +++ b/mod/test/start.php @@ -13,10 +13,6 @@ function test_init($event, $object_type, $object = null) {
global $CONFIG;
-
- // Let's add to the pageshell view.
- extend_view("pageshell", "testplugin/pageshell");
- set_view_location("testplugin/pageshell",$CONFIG->pluginspath . "test/views/");
// Test menu item
add_menu("Test plugin",$CONFIG->wwwroot . "mod/test/",array(
|