"; echo ""; echo "".sprintf(gettext('Page access %2$s (%1$s)'),$err, $text)."

"; echo ""; } /** * Checks to see if a URL is valid * * @param string $url the URL being checked * @return bool */ function isValidURL($url) { return preg_match('|^http(s)?://[a-z0-9-]+(.[a-z0-9-]+)*(:[0-9]+)?(/.*)?$|i', $url); } /** * Provide an alternative to glob which does not return filenames with accented charactes in them * * @param string $pattern the 'pattern' for matching files * @param bit $flags glob 'flags' */ function safe_glob($pattern, $flags=0) { $split=explode('/',$pattern); $match=array_pop($split); $path_return = $path = implode('/',$split); if (empty($path)) { $path = '.'; } else { $path_return = $path_return . '/'; } if (!is_dir($path)) return array(); if (($dir=opendir($path))!==false) { $glob=array(); while(($file=readdir($dir))!==false) { if (safe_fnmatch($match,$file)) { if ((is_dir("$path/$file"))||(!($flags&GLOB_ONLYDIR))) { if ($flags&GLOB_MARK) $file.='/'; $glob[]=$path_return.$file; } } } closedir($dir); if (!($flags&GLOB_NOSORT)) sort($glob); return $glob; } else { return array(); } } /** * pattern match function Works with accented characters where the PHP one does not. * * @param string $pattern pattern * @param string $string haystack * @return bool */ function safe_fnmatch($pattern, $string) { return @preg_match('/^' . strtr(addcslashes($pattern, '\\.+^$(){}=!<>|'), array('*' => '.*', '?' => '.?')) . '$/i', $string); } /** * Returns the value of a cookie from either the cookies or from $_SESSION[] * * @param string $name the name of the cookie */ function zp_getCookie($name) { if (DEBUG_LOGIN) { if (isset($_SESSION[$name])) { $sessionv = $_SESSION[$name]; } else { $sessionv = ''; } if (isset($_COOKIE[$name])) { $cookiev = $_COOKIE[$name]; } else { $cookiev = ''; } debugLog("zp_getCookie($name): SESSION[".session_id()."]=".$sessionv.", COOKIE=".$cookiev); } if (isset($_COOKIE[$name]) && !empty($_COOKIE[$name])) { return $_COOKIE[$name]; } if (isset($_SESSION[$name])) { return $_SESSION[$name]; } return false; } /** * Sets a cookie both in the browser cookies and in $_SESSION[] * * @param string $name The 'cookie' name * @param string $value The value to be stored * @param timestamp $time The time the cookie expires * @param string $path The path on the server in which the cookie will be available on */ function zp_setCookie($name, $value, $time=0, $path='/') { if (DEBUG_LOGIN) debugLog("zp_setCookie($name, $value, $time, $path)::album_session=".getOption('album_session')); if ($time < time() || !getOption('album_session')) { setcookie($name, $value, $time, $path); } if ($time < time()) { if (isset($_SESSION)) unset($_SESSION[$name]); if (isset($_COOKIE)) unset($_COOKIE[$name]); } else { $_SESSION[$name] = $value; $_COOKIE[$name] = $value; } } /** * encodes for cookie **/ function cookiecode($text) { return md5($text); } /** * returns a list of comment record 'types' for "images" * @param string $quote quotation mark to use * * @return string */ function zp_image_types($quote) { global $_zp_extra_filetypes; $typelist = $quote.'images'.$quote.','.$quote.'_images'.$quote.','; $types = array_unique($_zp_extra_filetypes); foreach ($types as $type) { $typelist .= $quote.strtolower($type).'s'.$quote.','; } return substr($typelist, 0, -1); } /** * Returns video argument of the current Image. * * @param object $image optional image object * @return bool */ function isImageVideo($image=NULL) { if (is_null($image)) { if (!in_context(ZP_IMAGE)) return false; global $_zp_current_image; $image = $_zp_current_image; } return strtolower(get_class($image)) == 'video'; } /** * Returns true if the image is a standard photo type * * @param object $image optional image object * @return bool */ function isImagePhoto($image=NULL) { if (is_null($image)) { if (!in_context(ZP_IMAGE)) return false; global $_zp_current_image; $image = $_zp_current_image; } $class = strtolower(get_class($image)); return $class == '_image' || $class == 'transientimage'; } /** * Copies a directory recursively * @param string $srcdir the source directory. * @param string $dstdir the destination directory. * @return the total number of files copied. */ function dircopy($srcdir, $dstdir) { $num = 0; if(!is_dir($dstdir)) mkdir($dstdir); if($curdir = opendir($srcdir)) { while($file = readdir($curdir)) { if($file != '.' && $file != '..') { $srcfile = $srcdir . '/' . $file; $dstfile = $dstdir . '/' . $file; if(is_file($srcfile)) { if(is_file($dstfile)) $ow = filemtime($srcfile) - filemtime($dstfile); else $ow = 1; if($ow > 0) { if(copy($srcfile, $dstfile)) { touch($dstfile, filemtime($srcfile)); $num++; } } } else if(is_dir($srcfile)) { $num += dircopy($srcfile, $dstfile, $verbose); } } } closedir($curdir); } return $num; } /** * Returns a byte size from a size value (eg: 100M). * * @param int $bytes * @return string */ function byteConvert( $bytes ) { if ($bytes<=0) return '0 Byte'; $convention=1024; //[1000->10^x|1024->2^x] $s=array('Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB'); $e=floor(log($bytes,$convention)); return round($bytes/pow($convention,$e),2).' '.$s[$e]; } /** * Returns an i.php "image name" for an image not within the albums structure * * @param string $image Path to the image * @return string */ function makeSpecialImageName($image) { $filename = basename($image); $i = strpos($image, ZENFOLDER); if ($i === false) { $folder = '_{'.basename(dirname(dirname($image))).'}_{'.basename(dirname($image)).'}_'; } else { $folder = '_{'.ZENFOLDER.'}_{'.substr($image, $i + strlen(ZENFOLDER) + 1 , - strlen($filename) - 1).'}_'; } return $folder.$filename; } /** * Converts a datetime to connoical form * * @param string $datetime input date/time string * @param bool $raw set to true to return the timestamp otherwise you get a string * @return mixed */ function dateTimeConvert($datetime, $raw=false) { // Convert 'yyyy:mm:dd hh:mm:ss' to 'yyyy-mm-dd hh:mm:ss' for Windows' strtotime compatibility $datetime = preg_replace('/(\d{4}):(\d{2}):(\d{2})/', ' \1-\2-\3', $datetime); $time = @strtotime($datetime); if ($time == -1 || $time == false) return false; if ($raw) return $time; return date('Y-m-d H:i:s', $time); } /*** Context Manipulation Functions *******/ /******************************************/ /* Contexts are simply constants that tell us what variables are available to us * at any given time. They should be set and unset with those variables. */ // Contexts (Bitwise and combinable) define("ZP_INDEX", 1); define("ZP_ALBUM", 2); define("ZP_IMAGE", 4); define("ZP_COMMENT", 8); define("ZP_SEARCH", 16); define("ZP_SEARCH_LINKED", 32); define("ZP_ALBUM_LINKED", 64); define('ZP_IMAGE_LINKED', 128); define('ZP_ZENPAGE_NEWS_ARTICLE', 256); define('ZP_ZENPAGE_NEWS_CATEGORY', 512); define('ZP_ZENPAGE_NEWS_DATE', 1024); define('ZP_ZENPAGE_PAGE', 2048); if(getOption('zp_plugin_zenpage')) { require_once(dirname(__FILE__).PLUGIN_FOLDER.'zenpage/zenpage-template-functions.php'); } function get_context() { global $_zp_current_context; return $_zp_current_context; } function set_context($context) { global $_zp_current_context; $_zp_current_context = $context; } function in_context($context) { return get_context() & $context; } function add_context($context) { set_context(get_context() | $context); } function rem_context($context) { global $_zp_current_context; set_context(get_context() & ~$context); } // Use save and restore rather than add/remove when modifying contexts. function save_context() { global $_zp_current_context, $_zp_current_context_restore; $_zp_current_context_restore = $_zp_current_context; } function restore_context() { global $_zp_current_context, $_zp_current_context_restore; $_zp_current_context = $_zp_current_context_restore; } setexifvars(); ?>