(root)/shared-urls.php - Rev 469
Rev 466 |
Blame |
Compare with Previous |
Last modification |
View Log
| RSS feed
<?php
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* This file is part of Travelsized CMS
* A content management system with modules, based on wiki syntax
*
* Author: Dan Jensen <admin@leinir.dk>
* Copyright 2003/2004
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* The GNU General Public License is available at: http://www.gnu.org/copyleft/
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/**
* Returns the current url of the page
*/
function siteURL
($removepagename = false) {
$s = empty($_SERVER["HTTPS"]) ?
''
: ($_SERVER["HTTPS"] == "on") ?
"s"
: "";
$protocol = strleft
(strtolower($_SERVER["SERVER_PROTOCOL"]), "/").$s;
$port = ($_SERVER["SERVER_PORT"] == "80") ?
"" : (":".$_SERVER["SERVER_PORT"]);
if ($removepagename) {
$pagename = $protocol . "://" . $_SERVER['SERVER_NAME'] . $port . substr($_SERVER['SCRIPT_NAME'], 0, strlen($_SERVER['SCRIPT_NAME']) - 9);
} else {
$pagename = $protocol . "://" . $_SERVER['SERVER_NAME'] . $port . $_SERVER['SCRIPT_NAME'];
}
return $pagename;
}
/**
* Returns the URL of the current page
*
* @param header Format the URL so that it will work in a header (for example for use with Location:)
* @param absoluteURL Add siteURL to the returned URL
* @param extraReqVars An array containing pairs of name=values to add to the URL
*
* @return string The URL
*/
function thisPageURL
($header = false, $absoluteURL = true, $extraReqVars = "")
{
global $page_id, $language, $viewUser, $globalID, $systemOptions;
$reqVars = array();
global $systemOptions;
if( $systemOptions["rewrite"] == 1 )
$temp_absoluteurl = siteURL
( true );
else
$temp_absoluteurl = siteURL
() . "?globalID=";
/*if( $absoluteURL )
$temp_absoluteurl = siteURL(true);
else
$temp_absoluteurl = "./";*/
if( $header )
$separator = "&";
else
$separator = "&";
if( $globalID != "" )
$thispageurl = $temp_absoluteurl . $globalID;
else
{
if( array_key_exists( "userlist_page", $_REQUEST ) )
$reqVars["userlist_page"] = $_REQUEST["userlist_page"];
if( array_key_exists( "user_id", $_REQUEST ) )
$reqVars["user_id"] = $_REQUEST["user_id"];
if( $viewUser != "" )
$reqVars["user_id"] = $viewUser;
if( array_key_exists( "module", $_REQUEST ) )
$reqVars["module"] = $_REQUEST["module"];
if( array_key_exists( "action", $_REQUEST ) )
$reqVars["action"] = $_REQUEST["action"];
if( array_key_exists( "profile_mode", $_REQUEST ) )
$reqVars["profile_mode"] = $_REQUEST['profile_mode'];
if( array_key_exists( "language", $_REQUEST ) )
$reqVars["language"] = $language;
$thispageurl = $temp_absoluteurl . "index.php?page_id=$page_id";
}
if( array_key_exists( "returnID", $_REQUEST ) )
$reqVars["returnID"] = $_REQUEST["returnID"];
if( is_array( $extraReqVars ) )
{
foreach( $extraReqVars as $name => $value )
$reqVars[$name] = $value;
}
$extraparams = "";
foreach( $reqVars as $name => $value )
$extraparams .= $separator . $name . "=" . $value;
return $thispageurl . $extraparams;
}
/**
* Returns the url that corresponds to the globalID
*
* @param splitID The global ID to check
*
* @return string A string containing the URL corresponding to the globalID, if existing
*/
function globalID_user
( $splitID )
{
global $viewUser;
$pageID = null;
if( $splitID[0] == "user" )
{
$pageID = $_REQUEST["page_id"] = "13";
$viewUser = $splitID[1];
switch( $splitID[2] )
{
case null:
case "view":
break; // Then we're simply viewing the profile
case "new":
$_REQUEST["profile_mode"] = "new";
break;
case "mypage":
$_REQUEST["profile_mode"] = "mypage";
break;
case "edit":
$_REQUEST["profile_mode"] = "edit";
if( array_key_exists( 3, $splitID) )
$_REQUEST["edit_section"] = $splitID[3];
else
$_REQUEST["edit_section"] = "general_information";
break;
case "contact":
$_REQUEST["profile_mode"] = "contact";
break;
default:
// Then it's a module - we don't handle those, pass on the torch!
return null;
}
}
return $pageID;
}
$modules_globalID[] = "globalID_user";
/**
* Takes a global ID and passes it to each module's globalID handler
* and sets the a header to redirect to the corresponding URL, or returns
* a negative page ID, so that the main function knows to show an unknown page
*
* Create functions named globalID_modulename which take a split globalID array
* and add it into the global $modules_globalID[] array
* Sample function:
\code
function globalID_foo( $splitID )
{
$pageID = null;
// Is the globalID directly aimed at this module?
if( $splitID[0] == "foo" )
{
$pageID = $foo_pageID;
}
// Or is it aimed at the module's profile module?
else if( $splitID[0] == "user" && $splitID[2] == "foo" )
{
$_REQUEST["user_id"] = $splitID[1];
$_REQUEST["module"] = "profilemodule_foo";
$pageID = "13";
}
return $pageID;
}
\endcode
*
* @return integer the base pageID if found
*/
function handleGlobalID
()
{
global $modules_globalID, $page_id, $globalID;
// Strip trailing slashes...
while( substr( $globalID, -1 ) == "/" )
$globalID = substr( $globalID, 0, -1 );
$splitID = split( "/", $globalID );
foreach( $modules_globalID as $key => $function )
{
$tmpVal = $function( $splitID );
if( $tmpVal != null )
$pageID = $tmpVal;
}
// If we didn't find one... reset the pageID to the already set one and return that one in stead
if( $pageID == null )
$pageID = $page_id;
return $pageID;
}
/**
* Will return the an array with information for the thumbnail for a specified global ID
*
* @param globalID The global ID to fetch thumbnail information for
*
* @return Array containing array( "uri" => the fully qualified URI for the thumbnail, "width" => the width in pixels, "height" => the height in pixels )
*/
function getGlobalIDThumbnail
( $globalID )
{
global $setup_folder;
if( $globalID == "" )
$splitID = array();
else
$splitID = split( "/", $globalID );
if( $splitID[0] == "content" || count( $splitID ) == 0 )
{
// if it's content, get that an image describing that...
$data = array( "uri" => siteURL
(true) . $setup_folder . "/images/thumb-content.png", "width" => 64, "height" => 64 );
}
else if( $splitID[0] == "user" )
{
$modulefunction = "globalIDThumbnail_" . $splitID[2];
// if it's user
if( array_key_exists( 2, $splitID ) && function_exists($modulefunction))
{
// and if its a module with a getthumbnail function that exists...
$data = $modulefunction($splitID);
}
else
{
// otherwise just get that user's avatar
$imageFile = getAvatarThumbnail
( $splitID[1] );
list($width, $height) = getimagesize($imageFile);
$uri = siteURL
(true) . $imageFile;
$data = array( "uri" => $uri, "width" => $width, "height" => $height );
}
}
else
{
// if it's a module, which is the last possibility (not a user and not a piece of content)
$modulefunction = "globalIDThumbnail_" . $splitID[0];
if( function_exists($modulefunction) )
{
// pass it on to the module if the function exists
$data = $modulefunction($splitID);
}
else
{
// otherwise just return a generic thumbnail image
$data = array( "uri" => siteURL
(true) . $setup_folder . "/images/thumb-generic.png", "width" => 64, "height" => 64 );
}
}
return $data;
}
/**
* Will return the appropriate URL for a page from a global ID
*
* @param globalID The global ID to create a URL for
* @param extraReqVars An array containing pairs of name=values to add to the URL
*
* @return string The URL
*/
function globalIDtoURL
( $globalID, $extraReqVars = null )
{
global $systemOptions;
if( $systemOptions["rewrite"] == 1 )
$toplevel = siteURL
( true );
else
$toplevel = siteURL
() . "?globalID=";
$extraparams = "";
if( $extraReqVars != null )
foreach( $extraReqVars as $name => $value )
$extraparams .= "&" . $name . "=" . $value;
return $toplevel . $globalID . $extraparams;
}
?>