Esempio n. 1
0
 /**
  * Registers the plugin's views
  *
  * @throws PluginException
  * @return true
  */
 protected function registerViews()
 {
     $view_dir = "{$this->path}/views/";
     // plugins don't have to have views.
     if (!is_dir($view_dir)) {
         return true;
     }
     // but if they do, they have to be readable
     $handle = opendir($view_dir);
     if (!$handle) {
         $msg = elgg_echo('ElggPlugin:Exception:CannotRegisterViews', array($this->getID(), $this->guid, $view_dir));
         throw new PluginException($msg);
     }
     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)) {
                 elgg_register_viewtype($view_type);
             } else {
                 $msg = elgg_echo('ElggPlugin:Exception:CannotRegisterViews', array($this->getID(), $view_type_dir));
                 throw new PluginException($msg);
             }
         }
     }
     return true;
 }
Esempio n. 2
0
File: views.php Progetto: rasul/Elgg
/**
 * Auto-registers views from a location.
 *
 * @note Views in plugin/views/ are automatically registered for active plugins.
 * Plugin authors would only need to call this if optionally including
 * an entire views structure.
 *
 * @param string $view_base          Optional The base of the view name without the view type.
 * @param string $folder             Required The folder to begin looking in
 * @param string $base_location_path The base views directory to use with elgg_set_view_location()
 * @param string $viewtype           The type of view we're looking at (default, rss, etc)
 *
 * @return void
 * @since 1.7.0
 * @see elgg_set_view_location()
 * @todo This seems overly complicated.
 */
function autoregister_views($view_base, $folder, $base_location_path, $viewtype)
{
    if (!isset($i)) {
        $i = 0;
    }
    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 . "/";
                    } else {
                        $view_base_new = "";
                    }
                    elgg_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)) {
                    if (!empty($view_base)) {
                        $view_base_new = $view_base . "/";
                    } else {
                        $view_base_new = "";
                    }
                    autoregister_views($view_base_new . $view, $folder . "/" . $view, $base_location_path, $viewtype);
                }
            }
        }
        return TRUE;
    }
    return FALSE;
}
Esempio n. 3
0
/**
 * 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
 * @param string $viewtype The type of view we're looking at (default, rss, etc)
 */
function autoregister_views($view_base, $folder, $base_location_path, $viewtype)
{
    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 || substr_count($view, ".png") > 0) {
                    if (!empty($view_base)) {
                        $view_base_new = $view_base . "/";
                    } else {
                        $view_base_new = "";
                    }
                    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)) {
                    if (!empty($view_base)) {
                        $view_base_new = $view_base . "/";
                    } else {
                        $view_base_new = "";
                    }
                    autoregister_views($view_base_new . $view, $folder . "/" . $view, $base_location_path, $viewtype);
                }
            }
        }
    }
}
Esempio n. 4
0
/**
 * For now, loads plugins directly
 *
 * @todo Add proper plugin handler that launches plugins in an admin-defined order and activates them on admin request
 * @package Elgg
 * @subpackage Core
 */
function load_plugins()
{
    global $CONFIG;
    $cache = elgg_get_filepath_cache();
    if (!empty($CONFIG->pluginspath)) {
        // See if we have cached values for things
        $cached_view_paths = $cache->load('view_paths');
        if ($cached_view_paths) {
            $CONFIG->views = unserialize($cached_view_paths);
        }
        // temporary disable all plugins if there is a file called 'disabled' in the plugin dir
        if (file_exists($CONFIG->pluginspath . "disabled")) {
            return;
        }
        $plugins = get_plugin_list();
        if (sizeof($plugins)) {
            foreach ($plugins as $mod) {
                if (is_plugin_enabled($mod)) {
                    if (file_exists($CONFIG->pluginspath . $mod)) {
                        if (!(include $CONFIG->pluginspath . $mod . "/start.php")) {
                            throw new PluginException(sprintf(elgg_echo('PluginException:MisconfiguredPlugin'), $mod));
                        }
                        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);
                                        }
                                    }
                                }
                            }
                        }
                        if (is_dir($CONFIG->pluginspath . $mod . "/languages")) {
                            register_translations($CONFIG->pluginspath . $mod . "/languages/");
                        }
                    }
                }
            }
        }
        // Cache results
        if (!$cached_view_paths) {
            $cache->save('view_paths', serialize($CONFIG->views));
        }
    }
}
/**
 * For now, loads plugins directly
 *
 * @todo Add proper plugin handler that launches plugins in an admin-defined order and activates them on admin request
 * @package Elgg
 * @subpackage Core
 */
function load_plugins()
{
    global $CONFIG;
    if (!empty($CONFIG->pluginspath)) {
        // See if we have cached values for things
        $cached_view_paths = elgg_filepath_cache_load();
        if ($cached_view_paths) {
            $CONFIG->views = unserialize($cached_view_paths);
        }
        // temporary disable all plugins if there is a file called 'disabled' in the plugin dir
        if (file_exists($CONFIG->pluginspath . "disabled")) {
            return;
        }
        $plugins = get_plugin_list();
        if (sizeof($plugins)) {
            foreach ($plugins as $mod) {
                if (is_plugin_enabled($mod)) {
                    if (file_exists($CONFIG->pluginspath . $mod)) {
                        if (!(include $CONFIG->pluginspath . $mod . "/start.php")) {
                            // automatically disable the bad plugin
                            disable_plugin($mod);
                            // register error rather than rendering the site unusable with exception
                            register_error(sprintf(elgg_echo('PluginException:MisconfiguredPlugin'), $mod));
                            // continue loading remaining plugins
                            continue;
                        }
                        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);
                                        }
                                    }
                                }
                            }
                        }
                        if (is_dir($CONFIG->pluginspath . $mod . "/languages")) {
                            register_translations($CONFIG->pluginspath . $mod . "/languages/");
                        }
                    }
                }
            }
        }
        // Cache results
        if (!$cached_view_paths) {
            elgg_filepath_cache_save(serialize($CONFIG->views));
        }
    }
}