diff options
author | ben <ben@36083f99-b078-4883-b0ff-0f9b5a30f544> | 2008-10-06 14:17:14 +0000 |
---|---|---|
committer | ben <ben@36083f99-b078-4883-b0ff-0f9b5a30f544> | 2008-10-06 14:17:14 +0000 |
commit | 3f009c92127e4033cd799f73d2d7ff9d729cd5e5 (patch) | |
tree | 87608802d6e2049712a5a77ba3043a35dbef4364 /engine/lib | |
parent | 811215c4855d6698324e33f981db8d9a7eb8db46 (diff) | |
download | elgg-3f009c92127e4033cd799f73d2d7ff9d729cd5e5.tar.gz elgg-3f009c92127e4033cd799f73d2d7ff9d729cd5e5.tar.bz2 |
Introducing elgg_view_tree, for getting an array of views
git-svn-id: https://code.elgg.org/elgg/trunk@2186 36083f99-b078-4883-b0ff-0f9b5a30f544
Diffstat (limited to 'engine/lib')
-rw-r--r-- | engine/lib/elgglib.php | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/engine/lib/elgglib.php b/engine/lib/elgglib.php index 17766053c..4c98c84c4 100644 --- a/engine/lib/elgglib.php +++ b/engine/lib/elgglib.php @@ -295,6 +295,67 @@ return false;
}
+
+ /**
+ * When given a partial view root (eg 'js' or 'page_elements'), returns an array of views underneath it
+ *
+ * @param string $view_root The root view
+ * @return array A list of view names underneath that root view
+ */
+ function elgg_view_tree($view_root) {
+
+ global $CONFIG;
+ static $treecache;
+
+ function get_views($dir, $base) {
+ $return = array();
+ if (file_exists($dir) && is_dir($dir)) {
+ if ($handle = opendir($dir)) {
+ while ($view = readdir($handle)) {
+ if (!in_array($view, array('.','..'))) {
+ if (is_dir($view)) {
+ if ($val = get_views($dir . '/' . $view, $base . '/' . $view)) {
+ array_merge($return, $val);
+ }
+ } else {
+ $view = str_replace('.php','',$view);
+ $return[] = $base . '/' . $view;
+ }
+ }
+ }
+ }
+ }
+ return $return;
+ }
+
+ // Has the treecache been initialised?
+ if (!isset($treecache)) $treecache = array();
+ // A little light internal caching
+ if (!empty($treecache[$view_root])) return $treecache[$view_root];
+
+ // Examine $CONFIG->views->locations
+ if (isset($CONFIG->views->locations)) {
+ foreach($CONFIG->views->locations as $view => $path) {
+ $pos = strpos($view,$view_root);
+ if ($pos === 0) {
+ $treecache[$view_root][] = $view;
+ }
+ }
+ }
+
+ // Now examine core
+ $location = $CONFIG->viewpath;
+ $viewtype = elgg_get_viewtype();
+ $root = $location . $viewtype . '/' . $view_root;
+ echo $root;
+ if (file_exists($root) && is_dir($root)) {
+ $val = get_views($root, $view_root);
+ if (!is_array($treecache[$view_root])) $treecache[$view_root] = array();
+ $treecache[$view_root] = array_merge($treecache[$view_root], $val);
+ }
+
+ return $treecache[$view_root];
+ }
/**
* When given an entity, views it intelligently.
|