]> gitweb.fluxo.info Git - lorea/elgg.git/commitdiff
Refs #2115: Added elgg_is_valid_view_type(). Currently calculated at each load but...
authorbrettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544>
Fri, 28 May 2010 23:14:07 +0000 (23:14 +0000)
committerbrettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544>
Fri, 28 May 2010 23:14:07 +0000 (23:14 +0000)
Cleaned up autoregister_views() and load_plugins() code.
Added spaces between function params in numerous places.  C'mon guys...spaces are free.

git-svn-id: http://code.elgg.org/elgg/trunk@6274 36083f99-b078-4883-b0ff-0f9b5a30f544

engine/lib/elgglib.php
engine/lib/plugins.php

index 110cafcab3b0bb23fd7484c6a345ae5b0731e009..9d0bae0b6d24ba910e31238d5f7fde6ff5bfe870 100644 (file)
@@ -1473,6 +1473,8 @@ function autoregister_views($view_base, $folder, $base_location_path, $viewtype)
        if ($handle = opendir($folder)) {
                while ($view = readdir($handle)) {
                        if (!in_array($view,array('.','..','.svn','CVS')) && !is_dir($folder . "/" . $view)) {
+                               // this includes png files because some icons are stored within view directories.
+                               // See commit [1705]
                                if ((substr_count($view,".php") > 0) || (substr_count($view,".png") > 0)) {
                                        if (!empty($view_base)) {
                                                $view_base_new = $view_base . "/";
@@ -1480,9 +1482,9 @@ function autoregister_views($view_base, $folder, $base_location_path, $viewtype)
                                                $view_base_new = "";
                                        }
 
-                                       set_view_location($view_base_new . str_replace(".php","",$view), $base_location_path, $viewtype);
+                                       set_view_location($view_base_new . str_replace('.php', '', $view), $base_location_path, $viewtype);
                                }
-                       } else if (!in_array($view,array('.','..','.svn','CVS')) && is_dir($folder . "/" . $view)) {
+                       } else if (!in_array($view, array('.', '..', '.svn', 'CVS')) && is_dir($folder . "/" . $view)) {
                                if (!empty($view_base)) {
                                        $view_base_new = $view_base . "/";
                                } else {
@@ -1491,7 +1493,10 @@ function autoregister_views($view_base, $folder, $base_location_path, $viewtype)
                                autoregister_views($view_base_new . $view, $folder . "/" . $view, $base_location_path, $viewtype);
                        }
                }
+               return TRUE;
        }
+
+       return FALSE;
 }
 
 /**
@@ -3151,11 +3156,26 @@ function __elgg_shutdown_hook() {
  * @return unknown_type
  */
 function elgg_init() {
+       global $CONFIG;
+
        // Page handler for JS
        register_page_handler('js','js_page_handler');
 
        // Register an event triggered at system shutdown
        register_shutdown_function('__elgg_shutdown_hook');
+
+       // discover the built-in view types
+       // @todo cache this
+       $view_path = $CONFIG->viewpath;
+       $CONFIG->view_types = array();
+
+       $views = scandir($view_path);
+
+       foreach ($views as $view) {
+               if ('.' !== substr($view, 0, 1) && is_dir($view_path . $view)) {
+                       $CONFIG->view_types[] = $view;
+               }
+       }
 }
 
 function elgg_walled_garden_index() {
@@ -3342,6 +3362,11 @@ function elgg_http_url_is_identical($url1, $url2, $ignore_params = array('offset
        return TRUE;
 }
 
+/**
+ * Checks walled garden status upon Elgg init.
+ *
+ * @since 1.8
+ */
 function elgg_walled_garden() {
        global $CONFIG;
 
@@ -3351,6 +3376,18 @@ function elgg_walled_garden() {
        }
 }
 
+/**
+ * Checks if $view_type is valid on this installation.
+ *
+ * @param string $view_type
+ * @return bool
+ */
+function elgg_is_valid_view_type($view_type) {
+       global $CONFIG;
+
+       return in_array($view_type, $CONFIG->view_types);
+}
+
 /**
  * Some useful constant definitions
  */
index b365585c8884a93da0119fa4a026e6c630a1f84c..b8cf5c2d289957fed8ab9a309fed1da652e6da6a 100644 (file)
@@ -239,11 +239,18 @@ function load_plugins() {
                                                }
 
                                                if (!$cached_view_paths) {
-                                                       if (is_dir($CONFIG->pluginspath . $mod . "/views")) {
-                                                               if ($handle = opendir($CONFIG->pluginspath . $mod . "/views")) {
-                                                                       while ($viewtype = readdir($handle)) {
-                                                                               if (!in_array($viewtype,array('.','..','.svn','CVS')) && is_dir($CONFIG->pluginspath . $mod . "/views/" . $viewtype)) {
-                                                                                       autoregister_views("",$CONFIG->pluginspath . $mod . "/views/" . $viewtype,$CONFIG->pluginspath . $mod . "/views/", $viewtype);
+                                                       $view_dir = $CONFIG->pluginspath . $mod . '/views/';
+
+                                                       if (is_dir($view_dir) && ($handle = opendir($view_dir))) {
+                                                               while (FALSE !== ($view_type = readdir($handle))) {
+                                                                       $view_type_dir = $view_dir . $view_type;
+
+                                                                       if ('.' !== substr($view_type, 0, 1) && is_dir($view_type_dir)) {
+                                                                               if (autoregister_views('', $view_type_dir, $view_dir, $view_type)) {
+                                                                                       // add the valid view type.
+                                                                                       if (!in_array($view_type, $CONFIG->view_types)) {
+                                                                                               $CONFIG->view_types[] = $view_type;
+                                                                                       }
                                                                                }
                                                                        }
                                                                }