From dd624054a469d9e8ceb91cc2ee3f63a393f016db Mon Sep 17 00:00:00 2001 From: ben Date: Fri, 15 Feb 2008 11:49:32 +0000 Subject: Plugins can now extend views. git-svn-id: https://code.elgg.org/elgg/trunk@37 36083f99-b078-4883-b0ff-0f9b5a30f544 --- engine/lib/elgglib.php | 80 +++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 70 insertions(+), 10 deletions(-) (limited to 'engine') diff --git a/engine/lib/elgglib.php b/engine/lib/elgglib.php index b68258470..218e2cb07 100644 --- a/engine/lib/elgglib.php +++ b/engine/lib/elgglib.php @@ -94,17 +94,32 @@ $viewtype = $_SESSION['view']; } + if (isset($CONFIG->views->extensions[$view])) { + $viewlist = $CONFIG->views->extensions[$view]; + } else { + $viewlist = array(500 => $view); + } + ob_start(); - if (!@include($CONFIG->viewpath . "views/{$viewtype}/{$view}.php")) { - $success = false; - if ($viewtype != "default") { - if (@include($CONFIG->viewpath . "views/default/{$view}.php")) { - $success = true; - } - } - if (!$success && $debug == true) { - echo " [This view ({$view}) does not exist] "; - } + foreach($viewlist as $view) { + + if (!isset($CONFIG->views->locations[$view])) { + $location = $CONFIG->viewpath . "views/"; + } else { + $location = $CONFIG->views->locations[$view]; + } + if (!@include($location . "{$viewtype}/{$view}.php")) { + $success = false; + if ($viewtype != "default") { + if (@include($location . "views/default/{$view}.php")) { + $success = true; + } + } + if (!$success && $CONFIG->debug == true) { + echo " [This view ({$view}) does not exist] "; + } + } + } $content = ob_get_clean(); @@ -112,6 +127,51 @@ } + /** + * Extends a view by adding other views to be displayed at the same time. + * + * @param string $view The view to add to. + * @param string $view_name The name of the view to extend + * @param int $priority The priority, from 0 to 1000, to add at (lowest numbers will be displayed first) + */ + function extend_view($view, $view_name, $priority = 501) { + + global $CONFIG; + if (!isset($CONFIG->views)) { + $CONFIG->views = new stdClass; + } + if (!isset($CONFIG->views->extensions)) { + $CONFIG->views->extensions = array(); + } + if (!isset($CONFIG->views->extensions[$view])) { + $CONFIG->views[$view][500] = "{$view}"; + } + while(isset($CONFIG->views->extensions[$view][$priority])) { + $priority++; + } + $CONFIG->views->extensions[$view][$priority] = "{$view_name}"; + ksort($CONFIG->views->extensions[$view]); + + } + + /** + * Set an alternative base location for a view (as opposed to the default of $CONFIG->viewpath) + * + * @param string $view The name of the view + * @param string $location The base location path + */ + function set_view_location($view, $location) { + + global $CONFIG; + if (!isset($CONFIG->views)) { + $CONFIG->views = new stdClass; + } + if (!isset($CONFIG->views->locations)) { + $CONFIG->views->locations = array($view => $location); + } + + } + /** * Returns a representation of a full 'page' (which might be an HTML page, RSS file, etc, depending on the current view) * -- cgit v1.2.3