1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394
|
<?php
/*
* Gallery - a web based photo album viewer and editor
* Copyright (C) 2000-2006 Bharat Mediratta
*
* 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.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*
* $Id: url.php 14310 2006-08-14 07:41:08Z jenst $
*/
?>
<?php
/**
* Functions that provide possibility to create and modify URLS
*
* @package urls
*/
/**
* Define Constants for Gallery pathes.
*/
function setGalleryPaths() {
if (defined('GALLERY_BASE')) {
return;
}
$currentFile = __FILE__;
if ( $currentFile == '/usr/share/gallery/lib/url.php') {
/* We assum Gallery runs on as Debian Package */
define ("GALLERY_CONFDIR", "/usr/share/gallery");
define ("GALLERY_SETUPDIR", "/var/lib/gallery/setup");
} else {
define ("GALLERY_CONFDIR", dirname(dirname(__FILE__)));
define ("GALLERY_SETUPDIR", dirname(dirname(__FILE__)) . "/setup");
}
define ("GALLERY_BASE", dirname(dirname(__FILE__)));
}
/**
*
*/
function getGalleryBaseUrl() {
global $gallery;
if (isset($gallery->app) && isset($gallery->app->photoAlbumURL)) {
$base = $gallery->app->photoAlbumURL;
}
elseif(where_i_am() == 'config') {
$base = '..';
} elseif (defined('GALLERY_URL')) {
$base = GALLERY_URL;
} else {
$base = '.';
}
return $base;
}
/**
* Any URL that you want to use can either be accessed directly
* in the case of a standalone Gallery, or indirectly if we're
* mbedded in another app such as Nuke. makeGalleryUrl() will
* always create the appropriate URL for you.
*
* @param string $target File with a relative path to the gallery base
* (eg, "album_permissions.php")
*
* @param array $args Optional array containg additional Urlargs.
* (eg, array("index" => 1, "set_albumName" => "foo"))
* @return string
*/
function makeGalleryUrl($target = '', $args = array()) {
global $gallery;
global $GALLERY_EMBEDDED_INSIDE;
global $GALLERY_EMBEDDED_INSIDE_TYPE;
global $GALLERY_MODULENAME;
global $modpath;
if (empty($GALLERY_MODULENAME)
&& $GALLERY_EMBEDDED_INSIDE =='nuke'
&& !empty($modpath)) {
$GALLERY_MODULENAME = basename(dirname($modpath));
}
/* Needed for phpBB2 */
global $userdata;
global $board_config;
/* Needed for Mambo / Joomla! */
global $MOS_GALLERY_PARAMS;
/* Needed for CPGNuke */
global $mainindex;
$url = '';
$prefix = '';
$isSetupUrl = (stristr($target,"setup")) ? true : false;
if(!urlIsRelative($gallery->app->photoAlbumURL)) {
$gUrl = parse_url($gallery->app->photoAlbumURL);
$urlprefix = $gUrl['scheme'] .'://'. $gUrl['host'];
}
else {
$urlprefix = '';
}
/* make sure the urlprefix doesnt end with a / */
$urlprefix = ereg_replace("\/$", "", $urlprefix);
/* Add the folder to the url when *Nuke is not direct in the main folder */
$addpath = substr($_SERVER['PHP_SELF'], 0, strrpos($_SERVER['PHP_SELF'], '/'));
if( isset($GALLERY_EMBEDDED_INSIDE) && !$isSetupUrl && where_i_am() != 'config') {
switch ($GALLERY_EMBEDDED_INSIDE_TYPE) {
case 'phpBB2':
$cookiename = $board_config['cookie_name'];
if(!isset($_COOKIE[$cookiename . '_sid'])) {
// no cookie so we need to pass the session ID manually.
$args["sid"] = $userdata['session_id'];
if(!isset($args["set_albumName"])) {
// This var is only passed some of the time and but is required so PUT IT IN when needed.
$args["set_albumName"] = $gallery->session->albumName;
}
}
case 'phpnuke':
case 'nsnnuke':
$args["op"] = "modload";
$args["name"] = $GALLERY_MODULENAME;
$args["file"] = "index";
/*
* include *must* be last so that the JavaScript code in
* view_album.php can append a filename to the resulting URL.
*/
$args["include"] = $target;
$url = $urlprefix . $addpath .'/modules.php';
break;
case 'cpgnuke':
$args["name"] = "$GALLERY_MODULENAME";
$args["file"] = "index";
/*
* include *must* be last so that the JavaScript code in
* view_album.php can append a filename to the resulting URL.
*/
$args["include"] = $target;
$url = $urlprefix . $addpath . "/$mainindex";
break;
case 'postnuke':
if (substr(_PN_VERSION_NUM, 0, 7) < "0.7.6.0") {
$args["op"] = "modload";
$args["file"] = "index";
$url = $urlprefix . $addpath . '/modules.php';
}
else {
$url = $urlprefix . pnGetBaseURI()."/index.php";
}
$args["name"] = $GALLERY_MODULENAME;
/*
* include *must* be last so that the JavaScript code in
* view_album.php can append a filename to the resulting URL.
*/
$args["include"] = $target;
break;
case 'mambo':
case 'joomla':
$args['option'] = $GALLERY_MODULENAME;
$args['Itemid'] = $MOS_GALLERY_PARAMS['itemid'];
$args['include'] = $target;
/* We cant/wantTo load the complete Mambo / Joomla! Environment into the pop up
** E.g. the Upload Framwork does not work then
** So we need to put necessary infos of Mambo / Joomla! into session.
*/
if ((isset($args['type']) && $args['type'] == 'popup') ||
(!empty($args['gallery_popup']))) {
$target = 'index.php';
} else {
if (!empty($gallery->session->mambo->mosRoot)) {
$url = $urlprefix . $gallery->session->mambo->mosRoot . 'index.php';
} else {
$url ='index.php';
}
}
break;
// Maybe something went wrong, we do nothing as URL we be build later.
default:
break;
}
}
if (empty($url)) {
$url = getGalleryBaseUrl() ."/$target";
}
if ($args) {
$i = 0;
foreach ($args as $key => $value) {
if ($i++) {
$url .= "&"; // should replace with & for validatation
} else {
$url .= "?";
}
if (! is_array($value)) {
$url .= "$key=$value";
} else {
$j = 0;
foreach ($value as $subkey => $subvalue) {
if ($j++) {
$url .= "&"; // should replace with & for validatation
}
$url .= $key .'[' . $subkey . ']=' . $subvalue;
}
}
}
}
return htmlspecialchars($url);
}
function makeGalleryHeaderUrl($target, $args=array()) {
$url = makeGalleryUrl($target, $args);
return unhtmlentities($url);
}
/*
* makeAlbumUrl is a wrapper around makeGalleryUrl. You tell it what
* album (and optional photo id) and it does the rest. You can also
* specify additional key/value pairs in the optional third argument.
*/
function makeAlbumUrl($albumName="", $photoId="", $args=array()) {
global $GALLERY_EMBEDDED_INSIDE, $GALLERY_EMBEDDED_INSIDE_TYPE;
global $gallery;
// We can use GeekLog with rewrite because Gallery is embedded in a different way.
if ( $gallery->app->feature["rewrite"] == 1 &&
(! $GALLERY_EMBEDDED_INSIDE || $GALLERY_EMBEDDED_INSIDE_TYPE == 'GeekLog')) {
if ($albumName) {
$target = urlencode ($albumName);
// Can't have photo without album
if ($photoId) {
$target .= "/".urlencode ($photoId);
}
} else {
$target = "albums.php";
}
} else {
if ($albumName) {
$args["set_albumName"] = urlencode ($albumName);
if ($photoId) {
$target = "view_photo.php";
$args["id"] = urlencode ($photoId);
} else {
$target = "view_album.php";
}
} else {
$target = "albums.php";
}
}
return makeGalleryUrl($target, $args);
}
function makeAlbumHeaderUrl($albumName="", $photoId="", $args=array()) {
$url = makeAlbumUrl($albumName, $photoId, $args);
return unhtmlentities($url);
}
function addUrlArg($url, $arg) {
if (strchr($url, "?")) {
return "$url&$arg"; // should replace with & for validatation
} else {
return "$url?$arg";
}
}
/**
* @param string $name Name of Image
* @param string $skinname Optional Name skin, if file is not found, fallback to default location
* @return string $retUrl Complete URL to the Image
*/
function getImagePath($name, $skinname = '') {
global $gallery;
$retUrl = '';
if (!$skinname) {
$skinname = $gallery->app->skinname;
}
/* We cant use makeGalleryUrl() here, as Gallery could be embedded. */
$base = getGalleryBaseUrl();
$defaultname = "$base/images/$name";
$fullname = dirname(dirname(__FILE__)) . "/skins/$skinname/images/$name";
$fullURL = "$base/skins/$skinname/images/$name";
if (fs_file_exists($fullname) && !broken_link($fullname)) {
$retUrl = $fullURL;
} else {
$retUrl = $defaultname;
}
return $retUrl;
}
/**
* @param string $name Name of Image
* @param string $skinname Optional Name skin, if file is not found, fallback to default location
* @return string $retPath Complete Path to the Image
* @author Jens Tkotz <jens@peino.de>
*/
function getAbsoluteImagePath($name, $skinname = '') {
global $gallery;
$retPath = '';
$base = dirname(dirname(__FILE__));
$defaultPath = "$base/images/$name";
/* Skin maybe 'none', but this is never found, so we fall back to default. */
if (!$skinname) {
$skinname = $gallery->app->skinname;
}
$skinPath = "$base/skins/$skinname/images/$name";
if (fs_file_exists($skinPath)) {
$retPath = $skinPath;
} else {
$retPath = $defaultPath;
}
return $retPath;
}
/**
* Checkes wether an URL is relative or not
* @param string $url
* @return boolean
* @author Jens Tkotz <jens@peino.de>
*/
function urlIsrelative($url) {
if (substr($url, 0,4) == 'http') {
return false;
}
else {
return true;
}
}
function broken_link($file) {
if (fs_is_link($file)) {
return !fs_is_file($file);
} else {
return 0;
}
}
function galleryLink($url, $content, $attrList = array()) {
$attrs = generateAttrs($attrList);
if (!empty($url)) {
$html = "<a href=\"$url\"$attrs>$content</a>\n";
}
else {
$html = "<a$attrs>$content</a>\n";
}
return $html;
}
?>
|