From c25dcd4533ec98c7e58c647e4b2c08169c6b7dc4 Mon Sep 17 00:00:00 2001 From: ben Date: Thu, 19 Jun 2008 20:18:40 +0000 Subject: Automatic RSS feeds! git-svn-id: https://code.elgg.org/elgg/trunk@1011 36083f99-b078-4883-b0ff-0f9b5a30f544 --- engine/lib/elgglib.php | 81 ++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 76 insertions(+), 5 deletions(-) (limited to 'engine') diff --git a/engine/lib/elgglib.php b/engine/lib/elgglib.php index d559e5131..261dc60cc 100644 --- a/engine/lib/elgglib.php +++ b/engine/lib/elgglib.php @@ -186,6 +186,50 @@ } + /** + * Returns whether the specified view exists + * + * @param string $view The view name + * @param string $viewtype The type of view + * @return true|false Depending on success + */ + function elgg_view_exists($view, $viewtype = "") { + + global $CONFIG; + + // If we haven't been asked for a specific view, assume default + if (empty($_SESSION['view'])) { + $_SESSION['view'] = "default"; + + // If we have a config default view for this site then use that instead of 'default' + if (/*(is_installed()) && */(!empty($CONFIG->view)) && (trim($CONFIG->view)!="")) + $_SESSION['view'] = $CONFIG->view; + } + if (empty($viewtype) && is_callable('get_input')) + $viewtype = get_input('view'); + if (empty($viewtype)) { + $viewtype = $_SESSION['view']; + } + + + if (!isset($CONFIG->views->locations[$view])) { + if (!isset($CONFIG->viewpath)) { + $location = dirname(dirname(dirname(__FILE__))) . "/views/"; + } else { + $location = $CONFIG->viewpath; + } + } else { + $location = $CONFIG->views->locations[$view]; + } + + if (file_exists($location . "{$viewtype}/{$view}.php")) { + return true; + } + + return false; + + } + /** * When given an entity, views it intelligently. * @@ -203,6 +247,9 @@ */ function elgg_view_entity(ElggEntity $entity, $viewtype = "", $full = false, $bypass = true, $debug = false) { + global $autofeed; + $autofeed = true; + $view = $entity->view; if (is_string($view)) { return elgg_view($view,array('entity' => $entity), $viewtype, $bypass, $debug); @@ -231,11 +278,17 @@ $subtype = $entity->getSubtype(); if (empty($subtype)) { $subtype = $entity_type; } - return elgg_view("{$entity_type}/{$subtype}",array( + if (elgg_view_exists("{$entity_type}/{$subtype}")) { + return elgg_view("{$entity_type}/{$subtype}",array( + 'entity' => $entity, + 'full' => $full + ), $viewtype, $bypass, $debug); + } else { + return elgg_view("{$entity_type}/default",array( 'entity' => $entity, 'full' => $full ), $viewtype, $bypass, $debug); - + } } /** @@ -303,9 +356,14 @@ $param_array['area' . $arg] = func_get_arg($arg); $arg++; } - return elgg_view("canvas/layouts/{$layout}",$param_array); + if (elgg_view_exists("canvas/layouts/{$layout}")) { + return elgg_view("canvas/layouts/{$layout}",$param_array); + } else { + return elgg_view("canvas/default",$param_array); + } } + /** * Sets an alternative function to handle templates, which will be passed to by elgg_view. @@ -1300,7 +1358,20 @@ return false; } - - + + /** + * Get the full URL of the current page. + * + * @return string The URL + */ + function full_url() + { + $s = empty($_SERVER["HTTPS"]) ? '' : ($_SERVER["HTTPS"] == "on") ? "s" : ""; + $protocol = substr(strtolower($_SERVER["SERVER_PROTOCOL"]), 0, strpos(strtolower($_SERVER["SERVER_PROTOCOL"]), "/")) . $s; + $port = ($_SERVER["SERVER_PORT"] == "80") ? "" : (":".$_SERVER["SERVER_PORT"]); + return $protocol . "://" . $_SERVER['SERVER_NAME'] . $port . $_SERVER['REQUEST_URI']; + } + + ?> \ No newline at end of file -- cgit v1.2.3