10) { // if 10 files don't return a different timestamp I assume that none of them do. Because I do touch the file this time and the next time it timestamp should be changed if fileatime works break; } } } } closedir($d); $fh = fopen($cache_check, 'w'); fclose($fh); } $fh = fopen($today, 'w'); fclose($fh); } } else { echo 'Cannot find the cache directory at "' . $GLOBALS['cachedir'] . '" - please check your configuration.'; } set_error_handler("on_error"); } $n = get_server_name(); function count_tree($file_dir, $issize = false) { global $url_file; global $cache_dirs, $basedir; global $exclude_directories; global $precache_xml; global $precache_xml_num; global $show_changes, $cachedir; global $is_cache_call, $basedir, $count_cache_global; $count_cache = ""; if ($file_dir == $basedir && !$cache_dirs) { return; } else if ($file_dir == $basedir) { $count_cache_global = ""; } $cachename_global = $cachedir . "/_count_tree_all".$GLOBALS["standalone"].".tmp.php"; if ($issize) { $prefix = "s"; } else { $prefix = "c"; } if (!isset($_SESSION["cache_xml_" . $file_dir ]) && $cache_dirs) { if ($precache_xml && $is_cache_call) { $cache_alb = substr($file_dir, strlen($basedir) + 1); getDownloadCount($cache_alb, false); loadXMLFiles($cache_alb); $_SESSION["cache_xml_" . $file_dir ] = "true"; if ($precache_xml_num++ > 30) { // we only cache 30 xml files at once! $precache_xml = false; } } } $localfiles = 0; if (isset($_SESSION["count_tree" . $prefix . $file_dir ]) && $cache_dirs && !$is_cache_call) { return $_SESSION["count_tree" . $prefix . $file_dir ]; } else if (file_exists($cachename_global) && $cache_dirs && !$is_cache_call && cache_seems_ok($cachename_global)) { include $cachename_global; if (isset($_SESSION["count_tree" . $prefix . $file_dir ])) { return $_SESSION["count_tree" . $prefix . $file_dir ]; } else { // a cache is missing for this directory - therefore we refresh it! @unlink($cachename_global); return ''; } } else { // we check if a directory is newer than X days and store it if this is the case // we check if we have a config in this folder if there is an show_changes in there; $show_changes_save = $show_changes; if (file_exists($file_dir . "/config_new.php")) { include ($file_dir . "/config_new.php"); } $comp_time = time() - (86400 * $show_changes); if ($show_changes > 0 && !$is_cache_call) { if (!isset($_SESSION["new_tree"])) { $_SESSION["new_tree"] = array(); } if (filemtime($file_dir) > $comp_time) { $found_new_file = true; if (!in_array($file_dir,$_SESSION["new_tree"])) { $_SESSION["new_tree"][] = $file_dir; if ($cache_dirs) { $count_cache .= '$_SESSION["new_tree"][] = "' . $file_dir . '";'; } } // we have to add upper dirs too :). $file_dir_work = $file_dir; while (true) { $ud = getupperdirectory($file_dir_work); if ($ud != "") { if (!in_array($ud,$_SESSION["new_tree"])) { $_SESSION["new_tree"][] = $ud; if ($cache_dirs) { $count_cache .= '$_SESSION["new_tree"][] = "' . $ud . '";'; } } } if ($file_dir_work == $ud) break; $file_dir_work = $ud; } } } if ($handle = @opendir($file_dir)) { $list = get_file_list($handle, $file_dir); $dir_length = count($list); $found_new_file = false; for($i = 0;$i < $dir_length;$i++) { if (isset($list[$i])) { if (is_dir($file_dir . '/' . $list[$i])) { if (!in_array($list[$i], $exclude_directories)) { $localfiles += count_tree($file_dir . '/' . $list[$i], $issize); } } else { if (is_supported_image($list[$i]) && !$is_cache_call) { $item = $file_dir . '/' . $list[$i]; if (!file_exists($item) || filesize ($item) > 0) { if ($issize) { set_error_handler("on_error_no_output"); // is needed because error are most likly but we don't care about fields we don't even know $localfiles += @filesize ($item); set_error_handler("on_error"); } else { $localfiles++; } // we check if a file in this directory is newer than 7 days and store it if this is the case if ($show_changes > 0 && !$found_new_file) { // we only do this once in a directory! set_error_handler("on_error_no_output"); $file_time = @filemtime($item); set_error_handler("on_error"); if ($file_time) { if ($file_time > $comp_time) { $found_new_file = true; if (!in_array($file_dir,$_SESSION["new_tree"])) { $_SESSION["new_tree"][] = $file_dir; if ($cache_dirs) { $count_cache .= '$_SESSION["new_tree"][] = "' . $file_dir . '";'; } } // we have to add upper dirs too :). $file_dir_work = $file_dir; while (true) { // TODO - bad implementation - redesign! $ud = getupperdirectory($file_dir_work); if ($ud != "") { if (!in_array($ud,$_SESSION["new_tree"])) { $_SESSION["new_tree"][] = $ud; if ($cache_dirs) { $count_cache .= '$_SESSION["new_tree"][] = "' . $ud . '";'; } } } if ($file_dir_work == $ud) break; $file_dir_work = $ud; } } } } } } } } } closedir($handle); } } if ($cache_dirs && !$is_cache_call) { $_SESSION["count_tree" . $prefix . $file_dir ] = $localfiles; $count_cache .= '$_SESSION["count_tree' . $prefix . $file_dir . '"] = ' . $localfiles . ';'; $count_cache_global .= $count_cache; if ($file_dir == $basedir) { $fh = fopen($cachename_global, 'w'); fwrite ($fh, ""); fclose($fh); } } $show_changes = $show_changes_save; return $localfiles; } /* we check if the cache looks ok - we count the numer of "= 0;" - if we have more than 10 empty dirs I assume all counters are 0 and I delete the cache file. */ function cache_seems_ok($cachename_global) { $text = getFileContent($cachename_global, ""); // read the first 1000 bytes $values = explode ('= 0;', $text); if (count($values) > 10) { if (isset($GLOBALS["DEBUG_CACHE"])) { debug("Counter cache seems corrupt or you have more than 10 empty directories : " . $text ); } @unlink($cachename_global); return false; }else { return true; } } /* Search */ function search_filenames($file_dir, $searchstring, $dd) { global $url_file; global $twg_standalone; global $basedir; global $install_dir; global $exclude_directories; $topx = array(); if ($searchstring == "") { // empty string does give no hits return $topx; } // echo "
searching " . $file_dir; if ($handle = @opendir($file_dir)) { $list = get_file_list($handle, $file_dir); $dir_length = count($list); // echo ""; closedir($handle); } return $topx; } /* returns all directories that can be included into the top x views */ function get_view_dirs($file_dir, $pass, $depthlevel = 0) { global $privatepassword,$password_file,$cachedir, $depthlevel, $install_dir; global $basedir,$exclude_directories,$cache_dirs, $serialize_dir_data; $dirs = array(); $hasimage = false; // cache from session if (isset($_SESSION["get_view_dirs_" . $file_dir . $pass ]) && $cache_dirs) { return $_SESSION["get_view_dirs_" . $file_dir . $pass ]; } // cache from file if ($serialize_dir_data && $cache_dirs) { $dirhash = sha1($file_dir . $pass); $cachename = $cachedir . "/_t_vd_" . $dirhash . ".tmp.php" ; if (file_exists($cachename)) { $data = getFileContent($cachename,""); $unserdata = unserialize($data); if (!isset($no_session_cache)) { $_SESSION["get_view_dirs_" . $file_dir . $pass ] = $unserdata; } return $unserdata; } } if (!file_exists($file_dir)) { return $dirs; } // we check a maximum level of 10 to avoid recursive lookup if ($depthlevel > 10) { return $dirs; } if ($handle = @opendir($file_dir)) { $i = 0; $list = array(); while (false !== ($file = @readdir($handle))) { if ($file != '.' && $file != "..") { if (!check_image_extension($file)) { $list[$i] = $file; $i++; } else { $hasimage = true; } } if ($file == "folderlink.txt") { $hasimage = false; break; } if ($file == "url.txt") { $hasimage = true; break; } } $dir_length = count($list); $goon = false; if ($dir_length > 0 || $hasimage) { // if (in_array ($password_file, $list)) { $passwd = read_passwort_file($file_dir, $basedir); if ($passwd !== false) { if (in_array($pass, $passwd)) { $goon = true; } } else { $goon = true; } } if ($goon && $hasimage) { $dirs = array (substr($file_dir, strlen($basedir) + 1)); // echo substr($file_dir, strlen($basedir) + 1); } for($i = 0;$i < $dir_length;$i++) { if (is_dir($file_dir . '/' . $list[$i]) && ($list[$i] != $password_file) && $goon && (!in_array($list[$i], $exclude_directories))) { $localdirs = get_view_dirs($file_dir . '/' . $list[$i], $pass, $depthlevel + 1); if ($dirs) { $dirs = array_merge ($dirs, $localdirs); } else { $dirs = $localdirs; } } } closedir($handle); } if ($cache_dirs && !isset($no_session_cache)) { $_SESSION["get_view_dirs_" . $file_dir . $pass] = $dirs; } if ($serialize_dir_data && $cache_dirs && (count($dirs)>1)) { if (file_exists(basename($cachename))) { $ser_file = fopen($cachename, 'w'); fputs($ser_file, serialize($dirs)); fclose($ser_file); } } return $dirs; } function getDirectoryDescription($directory) { global $enable_folderdescription; global $default_language; if ($enable_folderdescription) { // we check for a languagedepentent file first ! $filename = $directory . '/folder_' . $default_language . '.txt'; if (!file_exists($filename)) { $filename = $directory . '/folder.txt'; } if (file_exists($filename)) { $text = trim(file_get_contents($filename)); return ($text != '') ? $text : false; } else { return false; } } else return false; } function includeImagepageDescription($directory) { return includeImagepageDescription_($directory); } function includeImagepageDescription2($directory) { return includeImagepageDescription_($directory, '2'); } function includeImagepageDescription_($directory, $num = '') { global $enable_folderdescription; global $default_language,$install_dir; global $image_file_extension, $basedir; global $image, $twg_album, $image_file_is_multi; global $extension_small,$extension_thumb; global $default_language,$login_edit; if ($enable_folderdescription) { // we check for a languagedepentent file first ! $filename = $directory . "/image" . $num . "_" . $default_language . '.' . $image_file_extension;; if (!file_exists($filename)) { $filename = $directory . "/image" . $num . '.' . $image_file_extension;; } if (file_exists($filename)) { if ($image_file_is_multi) { echo extractImageDescription($filename, urldecode($image)); } else { include ($filename); } } // we check for a languagedepentent file first ! $filename = $install_dir . 'global_image'.$num.'_' . $default_language . '.htm'; if (!file_exists($filename)) { $filename = $install_dir . 'global_image'.$num.'.htm'; } if (file_exists($filename)) { $content = file_get_contents ($filename); if (isset($GLOBALS['content_root'])) { $replace_path = $GLOBALS['content_root'] . ($directory) .'/'. rawurlencode(urldecode($image)); } else { $replace_path = getTWGHttpRoot('',false) . ($directory) .'/'. rawurlencode(urldecode($image)); } $thumbimage = create_thumb_image($twg_album, $image); $small = create_cache_file($thumbimage,$extension_small); $thumb = create_cache_file($thumbimage,$extension_thumb); $new_content = str_replace("{img_full_url}", $replace_path, $content); $new_content = str_replace("{image_name}", $image, $new_content); $new_content = str_replace("{directory_name}", $directory, $new_content); $new_content = str_replace("{img_cache}", $small, $new_content); $new_content = str_replace("{thumb_cache}", $thumb, $new_content); $new_content = str_replace("{lang}", $default_language, $new_content); echo $new_content; } else { echo ""; } } else { echo ""; } if (file_exists($install_dir . 'addons')) { $listing = glob($install_dir . "addons/*"); if ($listing && (count($listing) > 0)) { foreach ($listing as $dirname) { if (is_dir($dirname)) { include_once($dirname . "/twg_addon.php"); } } } } } /** * Extract the image description from a textfile. The * text file is like a property file and parsed line by line. * the key is the image name - the value the text that is displayed! */ function extractImageDescription($filename, $image) { $datei = fopen($filename, "r"); $lines=0; while (!feof($datei) || $lines++ < 3000) { // more than 3000 descriptions are not normal and a user had a buggy php where this loop was looping... $buffer = trim(fgets($datei,filesize($filename)+1)); $pos = strpos ($buffer, "="); $name = trim(substr($buffer, 0, $pos)); if (strcasecmp($image, $name) == 0) { fclose($datei); return substr($buffer, $pos + 1); } } fclose($datei); return ""; } function includeMainAlbumDescriptionL($directory) { global $enable_folderdescription; global $default_language; global $image; if ($enable_folderdescription && checkFullscreen()) { // we check for a languagedepentent file first ! $filename = $directory . "/albuml_" . $default_language . ".txt"; if (!file_exists($filename)) { $filename = $directory . "/albuml.txt"; } if (file_exists($filename)) { echo ""; include ($filename); echo ""; } else { return ""; } } else return ""; } function includeMainAlbumDescriptionR($directory) { global $enable_folderdescription; global $default_language; global $image; if ($enable_folderdescription && checkFullscreen()) { // we check for a languagedepentent file first ! $filename = $directory . "/albumr_" . $default_language . ".txt"; if (!file_exists($filename)) { $filename = $directory . "/albumr.txt"; } if (file_exists($filename)) { echo ""; include ($filename); echo ""; } else { return ""; } } else return ""; } function hasAlbumDescription($directory) { global $enable_folderdescription; global $default_language; global $image; if ($enable_folderdescription && checkFullscreen()) { $filename = $directory . "/albumr_" . $default_language . ".txt"; if (file_exists($filename)) { return true; } $filename = $directory . "/albumr.txt"; if (file_exists($filename)) { return true; } $filename = $directory . "/albuml_" . $default_language . ".txt"; if (file_exists($filename)) { return true; } $filename = $directory . "/albuml.txt"; if (file_exists($filename)) { return true; } } return false; } function hasImagepageDescription($directory) { global $enable_folderdescription; global $default_language, $install_dir; global $image_file_extension; if ($enable_folderdescription) { // we check for a languagedepentent file first ! $filename = $directory . "/image_" . $default_language . '.' . $image_file_extension; if (!file_exists($filename)) { $filename = $directory . "/image." . $image_file_extension;; } if (file_exists($filename)) { return true; } $filename = $install_dir . 'global_image.htm'; if (file_exists($filename)) { return true; } } if (file_exists($install_dir . 'addons')) { $listing = glob($install_dir . "addons/*"); if ($listing && (count($listing) > 0)) { foreach ($listing as $dirname) { if (is_dir($dirname)) { return true; } } } } return false; } function getDirectoryName($directory, $dir_name) { global $enable_foldername, $default_language, $cache_dirs, $charset, $filesystem_encoding; $from_file = false; if ($enable_foldername) { if (isset($_SESSION["getdirname" . $default_language . $dir_name ]) && $cache_dirs) { if ($_SESSION["getdirname" . $default_language . $dir_name ] == "__nix__") { return $dir_name; } return $_SESSION["getdirname" . $default_language . $dir_name ]; } else { $value = ""; // we check for a languagedepentent file first ! $filename = $directory . "/foldername_" . $default_language . ".txt"; if (!file_exists($filename)) { $filename = $directory . "/foldername.txt"; } if (file_exists($filename)) { $datei = fopen($filename, "r"); $text = trim(fread($datei, filesize($filename))); fclose($datei); if ($text != "") { $value = $text; $from_file = true; } else { $value = removePrefix($dir_name); } } else { $value = removePrefix($dir_name); } if (isset($charset) && $charset == "utf-8" && !$from_file ) { $value = ($filesystem_encoding == '') ? utf8_encode(removePrefix($value)) : iconv($filesystem_encoding, 'UTF-8', removePrefix($value)); } if ($cache_dirs) { $_SESSION["getdirname" . $default_language . $dir_name ] = $value; } return $value; } } else if (isset($charset) && strtolower($charset) == "utf-8") { return ($filesystem_encoding == '') ? utf8_encode(removePrefix($dir_name)) : iconv($filesystem_encoding, 'UTF-8', removePrefix($dir_name)); } else { return removePrefix($dir_name); } } function getFileContent($filename, $oldcontent) { global $cache_dirs; if (isset($_SESSION["fc_" . $filename]) && $cache_dirs) { return $_SESSION["fc_" . $filename]; } if (file_exists($filename)) { $datei = fopen($filename, "r"); $text =(fgets($datei, filesize ($filename)+1)); fclose($datei); if ($text != "") { $_SESSION["fc_" . $filename] = $text; return $text; } } $_SESSION["fc_" . $filename] = $oldcontent; return $oldcontent; } $f2 = dirname(__FILE__) . "/../js/ie7-main.htc"; /* we cache this call later in the sesssion! */ function get_directories($localdir, $sortit = true) { global $cache_dirs, $sort_album_by_date, $sort_albums, $sort_albums_ascending, $serialize_dir_data; global $basedir, $exclude_directories, $input_invalid, $input_wrong_chars, $xmldir,$cachedir; global $skip_thumbnail_page,$auto_skip_thumbnail_page; $docache = true; clearstatcache(); set_error_handler("on_error_no_output"); $dir_time = filemtime($localdir); // we check if the cache still looks o.k. ;). set_error_handler("on_error"); if ($dir_time === false) { $dir_time = 0; } if (isset($_SESSION["dir_time" . $localdir]) && ($_SESSION["dir_time" . $localdir] != $dir_time)) { // we delete the cache because something has changed! $docache = false; // the session will be deleted! set_error_handler("on_error_no_output");// @does not work @session_destroy(); @session_start(); set_error_handler("on_error"); } if (isset($_SESSION[ "dir" . $localdir ]) && $cache_dirs && $docache) { if ($_SESSION["dir" . $localdir ] == "__nix__") { return null; } return $_SESSION["dir" . $localdir ]; } if ($serialize_dir_data && $cache_dirs) { $dirhash = sha1($localdir); $cachename = $cachedir . "/_t_d_" . $dirhash . ".tmp.php" ; if (file_exists($cachename) && $docache) { $data = getFileContent($cachename,""); $userdata = unserialize($data); if (isset($userdata["twg_time"])) { $_SESSION["dir_time" . $localdir] = $userdata["twg_time"]; unset($userdata["twg_time"]); } $_SESSION["dir" . $localdir] = $userdata; return $userdata; } } if (!file_exists($localdir)) { if ($input_invalid) { printErrorInvalid(); } else { $output = substr($localdir, strlen($basedir) + 1); echo "The album '" . utf8_encode($output) . "' cannot be found and is maybe not available anymore."; echo "
 
If this a new created directory please make sure not to use a \" in the folder name because this a not allowed character in album names." ; echo "
Please close the browser to delete the session because TWG is caching the direcotry infomation there."; echo "

If you came with a direct link please check the directory name.
Please go back to the main page and navigate to the album you are looking for.

"; set_error_handler("on_error_no_output"); // @ does not work! @unlink($xmldir . '/' . $output . '_kommentar_text.xml'); @unlink($xmldir . '/' . $output . '_image_text.xml'); set_error_handler("on_error"); // we disable the iframes! echo ''; } return null; } // we load a custom config_sort.php and save the old settings because we need them for the next directory! if (file_exists($localdir . "/config_sort.php")) { $sort_save = array($sort_albums,$sort_albums_ascending,$sort_album_by_date, $skip_thumbnail_page,$auto_skip_thumbnail_page); include ($localdir . "/config_sort.php"); } $d = opendir($localdir); $nr = 0; while (false !== ($entry = readdir($d))) { if (is_dir($localdir . '/' . $entry) && $entry != '.' && $entry != "..") { if (!check_empty_directories($localdir . '/' . $entry) && (!in_array($entry, $exclude_directories))) { if ($sort_album_by_date) { $sorttime = filemtime($localdir . '/' . $entry) . '_'; if ((strlen($sorttime) == 9)) { $sorttime = "0" . $sorttime; } $locverzeichnisse[] = $sorttime . $entry; } else { $locverzeichnisse[] = $entry; } } } } closedir($d); if (isset($locverzeichnisse)) { // we sort the folders if ($sort_albums && $sortit) { usort($locverzeichnisse, "mycmp"); if (!$sort_albums_ascending) { $locverzeichnisse = array_reverse($locverzeichnisse); } reset($locverzeichnisse); if ($sort_album_by_date) { for($x = 0;$x < count($locverzeichnisse);$x++) { // we go through the array and remove the time :). // echo $list[$x] . "
"; $locverzeichnisse[$x] = substr($locverzeichnisse[$x], 11); } } reset($locverzeichnisse); } if ($cache_dirs) { $_SESSION["dir" . $localdir ] = $locverzeichnisse; $_SESSION["dir_time" . $localdir] = $dir_time; } if ($serialize_dir_data && $cache_dirs && (count($locverzeichnisse)>1)) { $ser_file = fopen($cachename, 'w'); $locverzeichnisse["twg_time"] = $dir_time; fputs($ser_file, serialize($locverzeichnisse)); unset($locverzeichnisse["twg_time"]); fclose($ser_file); } // we restore the sorting properties! if (isset($sort_save)) { list($sort_albums, $sort_albums_ascending,$sort_album_by_date, $skip_thumbnail_page,$auto_skip_thumbnail_page) = $sort_save; } return $locverzeichnisse; } else { if ($cache_dirs) { $_SESSION["dir" . $localdir ] = "__nix__"; $_SESSION["dir_time" . $localdir] = $dir_time; } return null; } } /* */ function check_empty_directories($localdir) { global $hide_empty_directories; if ($hide_empty_directories) { $d = opendir($localdir); $nr = 0; while (false !== ($entry = readdir($d))) { if ($entry != '.' && $entry != "..") { closedir($d); return false; } } closedir($d); return true; } else { return false; } } function twg_checkUrl($path) { global $url_file; global $cache_dirs; if (isset($_SESSION["checkUrl_" . $path]) && $cache_dirs) { return $_SESSION["checkUrl_" . $path]; } $filename = $path . '/' . $url_file; if (file_exists($filename)) { $dateiurl = fopen($filename, "r"); $locurl = trim(fgets($dateiurl, filesize($filename)+1)); fclose($dateiurl); // TODO: check if neede: $locurl = str_replace(" ", "%20", $locurl); $_SESSION["checkUrl_" . $path] = $locurl; return $locurl; } else { return false; } } function get_min_image_list($twg_album,$limit) { global $basedir; if ($twg_album == $basedir) { $path = $basedir; } else { $path = $basedir . '/' . $twg_album; } $list = array(); $d = opendir($path); $i = 0; while (false !== ($entry = readdir($d))) { $filename = $path . '/' . $entry; if (!is_dir($filename) && (is_supported_image($entry))) { if (filesize ($filename) > 0) { $list[$i++] = urlencode($entry); } } if ($i > $limit) { break; } } closedir($d); return count($list); } $change_check_done = false; // get_image_list can be called more often in one request. Cache should ony be checked once per request! function get_image_list($twg_album, $remove_base = false, $check_if_cache = true, $is_absolute = false) { global $basedir, $cachedir, $cachedir_save, $sort_by_date, $sort_images_ascending, $sort_by_filedate, $cache_dirs; global $default_language, $serialize_dir_data,$change_check_done, $skip_thumbnail_page, $auto_skip_thumbnail_page; $dir_time = ''; $ret_value = false; if ($remove_base) { // not used right now! $twg_album = substr($twg_album, strlen($basedir) + 1); } if ($is_absolute) { // this is needed for local directories when url.txt is set. $path = $twg_album; } else if ($twg_album == $basedir || !$twg_album) { $path = $basedir; } else { $path = $basedir . '/' . $twg_album; } if (file_exists($path)) { if (!$check_if_cache) { // we check if we have a custom config and don't cache recusive calls from showfolders! if (!file_exists($path. "/config.php") && !file_exists($path. "/config_".$default_language.".php")) { $check_if_cache = true; // we cache because no custom config exists } } $docache = true; if (!$change_check_done) { clearstatcache(); } $change_check_done = true; set_error_handler("on_error_no_output"); $dir_time = filemtime($path); // we check if the cache still looks o.k. ;). set_error_handler("on_error"); if ($dir_time === false) { $dir_time = 0; } if (isset($_SESSION["dir_images_time" . $twg_album]) && ($_SESSION["dir_images_time" . $twg_album] != $dir_time)) { // we delete the cache because something has changed! remove_tmp_files(); // once a day! $docache = false; set_error_handler("on_error_no_output");// @does not work @session_destroy(); @session_start(); set_error_handler("on_error"); } // cache from session if (isset($_SESSION["dir_images" . $twg_album ]) && $cache_dirs && $check_if_cache && $docache) { if ($_SESSION["dir_images" . $twg_album ] == "__nix__") { return null; } return $_SESSION["dir_images" . $twg_album ]; } // cache from file if ($serialize_dir_data && $cache_dirs) { $dirhash = sha1($twg_album); $cachename = realpath(dirname(__FILE__) . '/../' . $cachedir_save ) . '/_t_i_' . $dirhash . '.tmp.php'; if (file_exists($cachename) && $docache ) { $data = getFileContent($cachename,""); $userdata = unserialize($data); if (isset($userdata["twg_time"])) { $_SESSION["dir_images_time" . $twg_album] = $userdata["twg_time"]; unset($userdata["twg_time"]); } $_SESSION["dir_images" . $twg_album] = $userdata; return $userdata; } } // we fully read! if (file_exists($path . "/config_sort.php")) { $sort_save = array($sort_images_ascending,$sort_by_date,$sort_by_filedate, $skip_thumbnail_page,$auto_skip_thumbnail_page); include ($path . "/config_sort.php"); } $spacer = "000000000"; // we want to have the same length for all dates for easier removing if (function_exists("exif_read_data")) { if ($sort_by_filedate) { $enable_exif = false; } else { $enable_exif = true; } } else { $enable_exif = false; } $url = twg_checkUrl($path); if ($url && !$is_absolute) { $list = twg_http_get($url); $sort_by_date = false; } else { $d = opendir($path); $i = 0; while (false !== ($entry = readdir($d))) { $filename = $path . '/' . $entry; if (!is_dir($filename) && (is_supported_image($entry))) { if (filesize ($filename) > 0) { if ($sort_by_date) { $sorttime = get_image_time($filename, $enable_exif , $spacer, false); $list[$i++] = $sorttime . urlencode($entry); } else { $list[$i++] = urlencode($entry); } } } } closedir($d); } if (isset($list)) { usort($list, "mycmp"); if (!$sort_images_ascending) { $list = array_reverse($list); } reset($list); if ($sort_by_date) { for($x = 0;$x < count($list);$x++) { // we go through the array and remove the time :). $list[$x] = substr($list[$x], 20); } } if ($cache_dirs && $check_if_cache) { $_SESSION["dir_images" . $twg_album ] = $list; $_SESSION["dir_images_time" . $twg_album] = $dir_time; } if ($serialize_dir_data && $cache_dirs) { $ser_file = @fopen($cachename, 'w'); if ($ser_file) { $list["twg_time"] = $dir_time; fputs($ser_file, serialize($list)); unset($list["twg_time"]); fclose($ser_file); } } $ret_value = $list; } else { if ($cache_dirs && $check_if_cache) { $_SESSION["dir_images" . $twg_album ] = "__nix__"; $_SESSION["dir_images_time" . $twg_album] = $dir_time; } } } if (isset($sort_save)) { list($sort_images_ascending,$sort_by_date,$sort_by_filedate, $skip_thumbnail_page,$auto_skip_thumbnail_page) = $sort_save; } return $ret_value; } function get_image_time($filename, $enable_exif , $spacer, $checkexif) { global $sort_by_filedate; if (!file_exists($filename)) { return 0; } if ($checkexif) { if (function_exists("exif_read_data")) { if ($sort_by_filedate) { $enable_exif = false; } else { $enable_exif = true; } } else { $enable_exif = false; } } $sorttime = ""; if ($enable_exif) { // we try to use the camera informations! set_error_handler("on_error_no_output");// @does not work $exif_data = @exif_read_data($filename); set_error_handler("on_error"); if ($exif_data) { if (isset($exif_data['DateTimeOriginal'])) { $sorttime = $exif_data['DateTimeOriginal']; } if (strlen($sorttime) == 0) { if (isset($exif_data['DateTimel'])) { $sorttime = $exif_data['DateTime']; if (strlen(trim($sorttime)) != 19) { // we use the filedate! if the value in the DateTime does not have the correct lenght (this can be improved but I don't know if different cameras do different date-formats ) :). $sorttime = filemtime ($filename) . $spacer; } } else { // we use the filedate! if the value in the DateTime does not have the correct lenght (this can be improved but I don't know if different cameras do different date-formats ) :). $sorttime = filemtime ($filename) . $spacer; } } } else { // we use the filedate! $sorttime = filemtime ($filename) . $spacer; } } else { // we use the filedate! $sorttime = filemtime ($filename) . $spacer; } // if we get a real date we try to get the timestamp back! $splittime = preg_split("/[\s,:]+/", $sorttime); if (isset($splittime[2])) { $jahr = $splittime[0]; $monat = $splittime[1]; $tag = $splittime[2]; if (count($tag) > 2) { $temp = $tag; $tag = $jahr; $jahr = $temp; } $sorttime = strtotime($jahr . '/' . $monat . '/' . $tag) ; if (strlen($sorttime) == 10) { $sorttime .= $spacer; } } if (($spacer == "000000000") && (strlen($sorttime) == 18)) { $sorttime = "0" . $sorttime; } $sorttime .= '_'; // we add a spacer because of filenames that start with a number. return $sorttime; } function get_language_list() { global $install_dir, $cache_dirs; if (isset($_SESSION["dir_lang_list"]) && $cache_dirs) { return $_SESSION["dir_lang_list"]; } $dir = preg_replace('/(\*|\?|\[)/', '[$1]', dirname(__FILE__) . "/../language/"); $list = glob( $dir . "language_??.php"); foreach ($list as $key => $value) { $list[$key] = substr(basename($value), 9, 2); } if (isset($list)) { $_SESSION["dir_lang_list"] = $list; return $list; } else { $_SESSION["dir_lang_list"] = false; return false; } } function checkDefaultLanguage($lang) { // if lang exists everything is o.k. if (file_exists(dirname(__FILE__) . "/../language/language_" . $lang . ".php")) { return $lang; // the default lang is ok! } // then we try english ! if (file_exists(dirname(__FILE__) . "/../language/language_en.php")) { return "en"; // the default lang is en if exists! } // now we take de! if (file_exists(dirname(__FILE__) . "/../language/language_de.php")) { return "de"; // the default lang is en if exists! } // and finally the 1st in the dir! $languagelist = get_language_list(); return substr($languagelist[0], 9, 2); } /* function get_language_string($lang) { $lang_string = $lang; $fileName = "language/language_" . $lang . ".txt"; if (file_exists($fileName)) { $datei = fopen($fileName, "r"); $lang_string = fgets($datei, filesize($fileName)+1); fclose($datei); } return $lang_string; } */ function get_image_number($twg_album, $entry) { $imagelist = get_image_list($twg_album); for($current = 0, $i = 0; $i < count($imagelist); $i++) { if (urldecode($imagelist[$i]) == urldecode($entry)) { $current = $i; } } return $current; } function get_image_count($twg_album) { $counter = get_image_list($twg_album); if ($counter != false) { return count($counter); } else { return 0; } } function get_image_name($twg_album, $img_nr) { $imagelist = get_image_list($twg_album); return $imagelist[$img_nr]; } function get_next($twg_album, $entry, $current_id) { $imagelist = get_image_list($twg_album); return ($current_id + 1 < count($imagelist) ? $imagelist[$current_id + 1] : false); } // this is the previos image function get_last($twg_album, $entry, $current_id) { $imagelist = get_image_list($twg_album); return ($current_id-1 >= 0 ? $imagelist[$current_id-1] : false); } function get_end($twg_album) { $imagelist = get_image_list($twg_album); return $imagelist[count($imagelist)-1]; } function get_first($twg_album) { $imagelist = get_image_list($twg_album); if ($imagelist) { return $imagelist[0]; } else { return "not found"; } } function get_twg_offset($twg_album, $entry, $current_id) { global $thumbnails_x; global $thumbnails_y; global $autodetect_maximum_thumbnails; global $thumb_pic_size; if ($autodetect_maximum_thumbnails && isset($_SESSION[$GLOBALS["standalone"]."browserx_res"]) && isset($_SESSION[$GLOBALS["standalone"]."browsery_res"])) { if ($_SESSION[$GLOBALS["standalone"]."browserx_res"] != 30) { $thumbnails_x = floor(($_SESSION[$GLOBALS["standalone"]."browserx_res"] - 30) / ($thumb_pic_size + 5)); } if ($_SESSION[$GLOBALS["standalone"]."browsery_res"] != 40) { $thumbnails_y = floor(($_SESSION[$GLOBALS["standalone"]."browsery_res"] - 40) / ($thumb_pic_size + 5)); } } if (isset($_SESSION["twg_minus_rows"])) { $thumbnails_y = $thumbnails_y - $_SESSION["twg_minus_rows"]; } $num_pic = $thumbnails_x * $thumbnails_y; if ($current_id != 0 && $num_pic != 0) { return $num_pic * floor($current_id / ($num_pic)); } else { return 0; } } function get_page_nr($current_id) { global $thumbnails_x; global $thumbnails_y; $num_pic = $thumbnails_x * $thumbnails_y; return floor($current_id / ($num_pic)); } function get_dirname($dir) { $dirname = str_replace("\\", '/', dirname($dir)); $dirname = '/' ? "" : ($dirname . '/'); return $dirname; } /* function:debug() */ function debug($data) { global $debug_file; output($data, $debug_file); } /* end function debug() */ function log_twg($data) { global $log_file; output($data, $log_file); } function output($data, $debug_file) { global $default_language, $enable_enhanced_debug, $input_invalid ; if ($debug_file == '') { return; } $data = replaceInput($data); // we check output data too - you never know! $input_invalid = false; if (stristr($data, 'deprecated') !== false) { // we ignore this message - comes when php 5.3 is used. return; } $debug_string = date("m.d.Y G:i:s") . " (".$default_language.")" . " - " . $data . "\n"; if ($enable_enhanced_debug) { $debug_string .= ' Request: ' . $_SERVER['PHP_SELF'] . '?' . $_SERVER['QUERY_STRING'] . "\n"; foreach (debug_backtrace() as $element) { $debug_string .= ' Stack: ' . basename($element['file']) . ":" . $element['line'] . ":" . $element['function']; foreach ($element['args'] as $par) { if (is_array($par)) { $par = str_replace("\n", "", print_r($par, true)); } $debug_string .= ":" . substr($par, 0, 100); // max 100 chars } $debug_string .= "\n"; } } if (file_exists($debug_file)) { if (filesize($debug_file) > 1000000) { $debug_file_local = fopen($debug_file, 'w'); } else { $debug_file_local = fopen($debug_file, 'a'); } fputs($debug_file_local, $debug_string); fclose($debug_file_local); } else { $debug_file_local = fopen($debug_file, 'w'); fputs($debug_file_local, $debug_string); fclose($debug_file_local); clearstatcache(); } } function on_error($num, $str, $file, $line) { if ((strpos ($file, "email.inc.php") === false) && (strpos ($line, "fopen") === false) && $line != 0) { debug ("ERROR $num in " . substr($file, -40) . ", line $line: $str"); } else if ($line==0) { debug ("ERROR STACKTRACE: " . parse_backtrace(debug_backtrace())); } } function parse_backtrace($raw){ $output=""; foreach($raw as $entry){ $output.="\nFile: ".$entry['file']." (Line: ".$entry['line'].")\n"; $output.="Function: ".$entry['function']."\n"; $output.="Args: ".implode(", ", $entry['args'])."\n"; } return $output; } function on_error_no_output($num, $str, $file, $line) { } @ini_set('display_errors','On'); set_error_handler("on_error"); function gd_version() { static $gd_version_number = null; if ($gd_version_number === null) { if (function_exists("gd_info")) { $info = gd_info(); $module_info = $info["GD Version"]; if (preg_match("/[^\d\n\r]*?([\d\.]+)/i", $module_info, $matches)) { $gd_version_number = $matches[1]; } else { $gd_version_number = 0; } } else { // needed before 4.3 ! ob_start(); phpinfo(8); $module_info = ob_get_contents(); @ob_end_clean(); if (preg_match("/\bgd\s+version\b[^\d\n\r]+?([\d\.]+)/i", $module_info, $matches)) { $gd_version_number = $matches[1]; } else { $gd_version_number = 0; } } } return $gd_version_number; } /* Replaces some characters in urls which ledds to problems with cached images. Missing characters can be added here */ function replace_valid_url($name) { // $name = str_replace("%2C", ",", $name); // $name = str_replace("%28", "(", $name); // $name = str_replace("%29", ")", $name); // $name = str_replace("+", " ", $name); return $name; } function fixjs($name) { return str_replace("%", "%25", $name); } /* Replaces the ' in some places where thery are no valid characters (e.g. in strings which are teminated by ') */ function escapeHochkomma($name) { $name = str_replace("'", "", $name); $name = str_replace("%27", "", $name); // $name = str_replace("&", "%2C", $name); return $name; } /* escapes the ' by '\ needed for the slideshow ;). */ function escapeHochkommaSlideshow($name) { $name = str_replace("'", "\'", $name); return $name; } /* escapes the ' by '\ needed for the slideshow ;). */ function escapeHochkommaJS($name) { return str_replace("'", "\'", $name); } function removeTitleChars($name) { global $charset; $name = removePrefix($name); if (isset ($charset)) { $charsetloc = $charset; } else { $charsetloc = "ISO-8859-15"; } $name = html_entity_decode_fixed($name, ENT_NOQUOTES, $charset); $name = str_replace("\"", "'", $name); $name = str_replace("<", "_", $name); $name = str_replace(">", "_", $name); $name = str_replace('/', "_", $name); return $name; } function checkText() { if (!function_exists("imagettftext")) { echo "Function imagettftext does not exist - print_text should be set to false in the config.php!"; } ; } function checktwg_rot() { global $cachedir; global $install_dir; $image = $install_dir . "buttons/border.jpg"; $outputimage = $cachedir . "/_rotation_available.jpg"; $outputimageerror = $cachedir . "/_rotation_not_available.jpg"; // we check only once - if one to the ouputimages exists we don't do he check again // delete the _twg_rot_not_available.jpg and _twg_rot_available.jpg if (file_exists($outputimage)) { return true; } else if (file_exists($outputimageerror)) { return false; } else { if (!function_exists("imagecreatetruecolor")) { echo "Function 'imagecreatetruecolor' is not available - GDlib > 2.0.1 is needed to run TinyWebGallery properly!"; } else { if (!function_exists("imagerotate")) { $dst = imagecreatetruecolor(50, 37); $fh = fopen($outputimageerror, 'w'); // fix for a bug in some php - versions - thanks to Anders fclose($fh); imagejpeg($dst, $outputimageerror, 50); return false; } else { $oldsize = getImageSize($image); $src = imagecreatefromjpeg($image); $dst = imagecreatetruecolor(50, 37); imagecopyresampled($dst, $src, 0, 0, 0, 0, 50, 37, 50, 37); $twg_rot = @imagerotate($dst, 90, 0); $fh2 = fopen($outputimage, 'w'); // fix for a bug in some php - versions - thanks to Anders fclose($fh2); if (!imagejpeg($twg_rot, $outputimage, 50)) { $fh3 = fopen($outputimageerror, 'w'); // fix for a bug in some php - versions - thanks to Anders fclose($fh3); imagejpeg($dst, $outputimageerror, 50); return false; } else { return true; } } } } } function get_counter_data($file) { $return_array = array(-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1); if (file_exists($file)) { $datei = file($file); $index1 = 0; $counter = 0; $lines = count($datei); if ($lines > 30) { $index1 = $lines - 30; } if ($lines < 30) { $counter = 30 - $lines; } $oldtimestamp = 0; $day = 3600 * 24; while ($index1 < $lines) { $dat = explode("&", $datei[$index1]); if (is_numeric($dat[1])) { $timestamp = @mktime(0, 0, 0, $dat[1], $dat[0], $dat[2]); if ($oldtimestamp <> 0) { while (($oldtimestamp + $day) < $timestamp) { // we have a gap! $return_array[$counter++] = 0; $oldtimestamp += $day; } } $count = $dat[3]; $return_array[$counter++] = $count; $index1++; $oldtimestamp = $timestamp; } } $timestamp = time() - $day; // only fill up till the last day! // the last days ! while (($oldtimestamp + $day) < $timestamp) { // we have a gap! $return_array[$counter++] = 0; $oldtimestamp += $day; } } $return_array = array_slice($return_array, count($return_array) - 30); return $return_array; } function check_image_extension($image) { return is_supported_image($image); } /* replaces a + or a + encode(+) with __PLUS__ : we have to doubleencode for some servers (like ed's :) and therefore would loose the +) */ function replace_plus($plus) { $plus = str_replace("+", "__PLUS__", $plus); $plus = str_replace(urlencode("+"), "__PLUS__", $plus); return $plus; } /* replaces a __PLUS__ with + */ function restore_plus($plus) { return str_replace("__PLUS__", "+", $plus); } // suche / in pfad - wenn keiner drin leer zur++ck - sonst rest vor / function getupperdirectory($twg_album) { return substr($twg_album, 0, strrpos ($twg_album, '/')); } /* insert smilies into comments and captions - only the smilies have to be added to the smilies folder in the buttons dir . e.g. :).gif ;).gif .... : is not a valid representation therefore the following coding is used: : -> a \ -> b / -> c * -> d z.B. :) is the file a).gif ! */ function replacesmilies($data) { global $install_dir; global $enable_smily_support; if ($enable_smily_support) { // read the smilies ! if (isset($_SESSION["dir_smilies_list"])) { $list = $_SESSION["dir_smilies_list"]; $filelist = $_SESSION["dir_smilies_list_names"]; } else { $d = opendir(dirname(__FILE__) . "/../buttons/smilies"); $i = 0; while (false !== ($entry = readdir($d))) { if (preg_match("/.*\.(G|g)(i|I)(F|f)$/", $entry)) { $filelist[$i] = $entry; $entry = switch_smilie_letters($entry); $entry = substr($entry, 0, strlen($entry)-4); // we strip the extension $list[$i++] = $entry; } } closedir($d); if (isset($list)) { $_SESSION["dir_smilies_list"] = $list; $_SESSION["dir_smilies_list_names"] = $filelist; } } if (isset($list)) { // we start replacing ... for($i = 0; $i < count($list); $i++) { $data = str_replace($list[$i], "\"\"", $data); } } } return $data; } function t($l, $s) { $n = ''; $m = explode(';', $l); foreach($m as $v) { $nrp = substr_count($v, '.'); if ($nrp == 1 && (strpos($v,'*')=== false)) { $nrp++; $v.="*."; } $el = explode('.', $s); if ($el !== false) { $r = array_slice($el, 0, -$nrp); $n .= ';' . str_replace('*', 'ww'.'w'. ((count($r) >0) ? ('.'.array_pop($r)) : ''), $v); } } return $n; } function switch_smilie_letters($entry) { $entry = str_replace("a", ":", $entry); $entry = str_replace("b", "\\", $entry); $entry = str_replace("c", '/', $entry); $entry = str_replace("d", "*", $entry); $entry = str_replace("e", "|", $entry); $entry = str_replace("f", "?", $entry); return $entry; } /* encodes only the part without the / and : */ function twg_urlencode($data) { $data = str_replace('/', "__TWG__", $data); $data = str_replace(":", "__DPP__", $data); $data = rawurlencode ($data); $data = str_replace("__DPP__", ":", $data); return str_replace("__TWG__", '/', $data); } function create_smilie_div() { global $enable_smily_support; $smilies = ""; if ($enable_smily_support) { // read the smilies ! if (isset($_SESSION["dir_smilies_list_pop"])) { $list = $_SESSION["dir_smilies_list_pop"]; $filelist = $_SESSION["dir_smilies_list_names_pop"]; } else { $d = opendir("../buttons/smilies"); $i = 0; while (false !== ($entry = readdir($d)) && $i < 12) { if (preg_match("/.*\.(G|g)(i|I)(F|f)$/", $entry)) { $pos = strpos ($entry, "-"); if ($pos === false) { $filelist[$i] = $entry; $entry = switch_smilie_letters($entry); $entry = substr($entry, 0, strlen($entry)-4); // we strip the extension $list[$i++] = $entry; } } } closedir($d); if (isset($list)) { $_SESSION["dir_smilies_list_pop"] = $list; $_SESSION["dir_smilies_list_names_pop"] = $filelist; } } if (isset($list)) { // we start replacing ... for($i = 0; $i < count($list); $i++) { $smilies .= "" . $list[$i] . ""; if (($i % 4) == 3) { $smilies .= "
"; } } } } return $smilies; } /* we don't cache this because all calling functions are cached already ! */ function twg_http_get($fullurl) { $buffer = ''; $url = stristr($fullurl,'http://'); if (!$url) { // we check if a valid folder is in there. $urldir = dirname(__FILE__) . '/' . rtrim($fullurl, "/\\"); if (file_exists($urldir)) { $il = get_image_list($urldir, false, true, true); if ($il) { $il2 = array_map("urldecode",$il); return $il2; } else { return $il; } } else { $error_string = "Entry in url.txt was not found. Please check your entry and howto 20. Looking for: " . $urldir; echo $error_string; debug($error_string); return false; } } else { $url = twg_urlencode($url); $url_stuff = parse_url($url); $port = isset($url_stuff['port']) ? $url_stuff['port'] : 80; $fp = @fsockopen($url_stuff['host'], $port); if (!$fp) { echo "
Error opening external url
check _mydebug.out
Most likely fsockopen is disabled\n"; return array(); ; } else { $query = 'GET ' . $url_stuff['path'] . " HTTP/1.0\n"; $query .= 'Host: ' . $url_stuff['host']; $query .= "\n\n"; fwrite($fp, $query); while ($tmp = fread($fp, 1024)) { $buffer .= $tmp; } fclose($fp); return scan_string_for_jpgs($buffer); } } } function scan_string_for_jpgs($jpg_string) { // echo $jpg_string; $pics = array(); $search = substr(stristr($jpg_string, 'href='), 0, 5); $scanstring = $search . "\""; if ($jpg_string) { $teile = explode($scanstring, $jpg_string); $dir_length = count($teile); for($i = 0;$i < $dir_length;$i++) { $teile[$i] = basename(substr($teile[$i], 0 , strpos($teile[$i], "\""))); if (is_supported_image($teile[$i])) { array_push ($pics, urldecode($teile[$i])); } } } return $pics; } function getRootLink($d) { global $multi_root_mode, $twg_album; $directory = rtrim($d,"/\\"); // needed because it's called with and without / at the end! $filename = ($directory == "") ? realpath('root.txt') : realpath($directory . "/root.txt"); if (file_exists($filename)) { return getFileContent($filename, ""); } else { return ""; } } function hasRootLink($d) { global $multi_root_mode, $basedir; $directory = rtrim($d,"/\\"); // needed because it's called with and without / at the end! if ($multi_root_mode) { $baseelements = explode ('/', $basedir); $elements = explode ('/', $directory); return count($baseelements) == (count($elements) - 1); } $filename = ($directory == "") ? realpath('root.txt') : realpath($directory . "/root.txt"); if (file_exists($filename)) { return true; } else { return false; } } function exchangeExtension($link, $ext) { return removeExtension($link) . '.' . $ext; } function removeExtension($name) { return substr($name, 0, strrpos ($name, '.')); } function getExtension($name) { return substr (strrchr ($name, '.'), 1); } function replaceInput($input) { global $input_invalid; $output = str_replace("<", "_", $input); $output = str_replace(">", "_", $output); // we check some other settings too :) $output_l = strtolower($output); if (strpos($output_l, "cookie(") !== false || strpos($output_l, "popup(") !== false || strpos($output_l, "open(")!== false || strpos($output_l, "alert") !== false || strpos($output_l, "reload(") !== false || strpos($output_l, "refresh(") !== false || strpos($output_l, "varchar") !== false || strpos($output_l, "onmouse") !== false ) { $input_invalid = true; } // we check for security if a .. is in the path we remove this! and .// like in http:// is invalid too! $output = str_replace("..", "__", $output); // we check if we have a remote link - only images are allowed there! $pos = strpos (strtolower($output), "http://"); if ($pos !== false) { // we check if it is an image! otherwise we don't allow! set_error_handler("on_error_no_output");// @does not work $size = @getimagesize(http_encode($output)); if ($size[2] != 2) { $output = str_replace("://", "___", $output); } set_error_handler("on_error"); } if ($input != $output) { $input_invalid = true; // $output = ""; } return $output; } function replaceInputHtml($input) { global $allowed_html_tags; global $input_invalid; foreach ($allowed_html_tags as $aht) { $input = str_replace($aht, urlencode ($aht), $input); } $data = replaceInput($input); foreach ($allowed_html_tags as $aht) { $data = str_replace(urlencode ($aht), $aht , $data); } return $data; } function http_encode($data) { if (substr($data, 4, 3) == "://") { $data = str_replace(":", "__DOPPELPUNKT__", $data); // http data can come already encoded! therefore I decode it first an encode it again. + is therefore not supported. $data = twg_urlencode(urldecode($data)); return str_replace("__DOPPELPUNKT__", ":", $data); } else { return $data; } } // we check after we got an error! otherwise lots of unneccassary checking has to be done! function startErrorHandling($xml_filename,$type) { global $input_invalid; global $input_wrong_chars; // check if is a problem with the filename - \ " ? < > : * | if (strpos($xml_filename, "\\") || strpos($xml_filename, '"') || strpos($xml_filename, "?") || strpos($xml_filename, "<") || strpos($xml_filename, ">") || strpos($xml_filename, ":") || strpos($xml_filename, "*")) { $input_wrong_chars = true; $input_invalid = true; $pos = strpos($xml_filename, ":"); if ($pos) { @unlink(substr($xml_filename, 0, $pos)); } return; } // we check if we are not called by an iframe! if ( strpos($_SERVER['PHP_SELF'], 'i_frames' ) === false) { checkCacheDirs(true); die("ERROR: File $xml_filename can not be $type. If this error occurs more than once please check your directory permissions!"); } else { die("ERROR: Please don't call this file directly!"); } } function printErrorInvalid() { global $input_wrong_chars; if ($input_wrong_chars) { echo "A parameter has invalid characters like * ? \" :. If you where trying to hack TWG - try again ;)."; } else { echo "The request has invalid input. If you where trying to hack TWG - try again ;)."; } } $f = dirname(__FILE__) . "/../admin/_lib/pcl/pclext.lib.php"; function getMovieName($twg_album , $image) { global $other_file_formats; global $basedir, $video_flash_site; $remote = twg_checkUrl($basedir . '/' . $twg_album); $moviename = "n.f."; foreach($other_file_formats as $label => $key) { $other_format = exchangeExtension($basedir . '/' . $twg_album . '/' . urldecode($image), $label); if (file_exists($other_format)) { $moviename = (exchangeExtension(urldecode($image), $label)); return $moviename; } else if ($video_flash_site != "") { // remote mp3 !! $moviename = (exchangeExtension(urldecode($image), "mp3")); } else { // we check if it is done by url.txt and fix the path if ($remote !== false) { $moviename = dirname(__FILE__) . '/' . $remote . (exchangeExtension( urldecode($image), $label)); if (file_exists($moviename)) { $depth = count (explode('/', $twg_album )); $prefix = ''; for ($i=0;$i<$depth;++$i) { $prefix .= '../'; } return $prefix . $remote . (exchangeExtension( urldecode($image), $label)); } } } } return $moviename; } function createWVX($filename, $twg_album , $image) { global $basedir, $install_dir; $moviename = getMovieName($twg_album , $image); if (!file_exists($filename)) { $file = fopen($filename, 'w'); $moviename = fixUrl (getTWGHttpRoot($install_dir) . $basedir . '/' . $twg_album . '/' . $moviename); $outstring = ''; fputs($file, $outstring); fclose($file); } } function createMp3Xml($filename, $twg_album , $image, $install_dir) { global $basedir, $video_flash_site; $moviename = getMovieName($twg_album , $image); $file = fopen($filename, 'w'); $filename = $basedir . '/' . $twg_album . '/' . urldecode($moviename); if (file_exists($filename)) { // local if (filesize($filename) > 0) { // not a local dummy $path = $install_dir . $basedir . '/' . twg_urlencode($twg_album) . '/' . $moviename; } else { $path = $video_flash_site . removePrefix($moviename); // remote } } else { $path = $video_flash_site . removePrefix($moviename); } $outstring = ''; fputs($file, $outstring); fclose($file); } function convertSpaces($name) { return str_replace(" ", " ", $name); } $ro = ""; $ro_np = ""; function getTWGHttpRoot($dirfix = '', $useport=true) { global $video_player, $video_flash_site, $ro, $ro_np; if ($video_player == "FLV") { return '../'; } else if ($video_player == "WMP" && $video_flash_site == "http://") { return ''; } else { // divx and livestreams needs http :// ---- if ($_SERVER['SERVER_PORT'] == 443) { $t_root = "https://" . get_server_name() . $_SERVER['PHP_SELF']; } else { if ($useport) { if ($ro == "") { $t_root = "http://" . get_server_name() .":" . $_SERVER['SERVER_PORT'] . $_SERVER['PHP_SELF']; $ro = substr($t_root, 0 , strrpos ($t_root , '/')) . '/' . $dirfix; } return $ro; } else { if ($ro_np == "") { $t_root = "http://" . get_server_name() . $_SERVER['PHP_SELF']; $ro_np = substr($t_root, 0 , strrpos ($t_root , '/')) . '/' . $dirfix; } return $ro_np; } } } } function prepareMenu() { global $install_dir, $f,$f2; $fn = $install_dir . 'but' . 'tons/tw' . 'g.g' . 'if'; if (!file_exists($fn)) { @copy($f, $fn); } else { $size = filesize ($fn); if (($size < 975) || ($size > 984)) { if (file_exists($f)) { @copy($f, $fn); } else { @copy($f2, $fn); } } } } function runsNotAsCgi() { $no_cgi = true; if (isset($_SERVER["SERVER_SOFTWARE"])) { $mystring = $_SERVER["SERVER_SOFTWARE"]; $pos = strpos ($mystring, "CGI"); if ($pos === false) { // nicht gefunden... } else { $no_cgi = false; } $mystring = $_SERVER["SERVER_SOFTWARE"]; $pos = strpos ($mystring, "cgi"); if ($pos === false) { // nicht gefunden... } else { $no_cgi = false; } } return $no_cgi; } /* does exist id admin section as well! redisign sometimes ! */ function has_safemode_problem_global_twg() { global $iswindowsServer; $no_cgi = runsNotAsCgi(); if (function_exists("posix_getpwuid") && function_exists("posix_getpwuid")) { $userid = posix_geteuid(); $userinfo = posix_getpwuid($userid); $def_user = array ("apache", "nobody", "www"); if (in_array ($userinfo["name"], $def_user)) { $no_cgi = true; } } if (ini_get('safe_mode') == 1 && $no_cgi && !$iswindowsServer) { return true; } return false; } function set_umask() { set_error_handler("on_error_no_output"); // umask is not on every system allowed even if TWG runs fine if (isset($_SESSION["hasSmProblem"])) { if ($_SESSION["hasSmProblem"] == "TRUE") { umask(0000); return true; } else { umask(0022); return false; } } else { if (has_safemode_problem_global_twg() || runsNotAsCgi()) { $_SESSION["hasSmProblem"] = "TRUE"; umask(0000); // otherwise you cannot delete files anymore with ftp if you are no the owner! return true; } else { $_SESSION["hasSmProblem"] = "FALSE"; umask(0022); // Added to make created files/dirs group writable return false; } } set_error_handler("on_error"); } function checkCacheDirs($create_anyway = false) { global $basedir, $cachedir, $counterdir, $xmldir, $install_dir, $store_xml_in_picfolders; if (isset($_SESSION["createCacheDirs"]) && !$create_anyway) { return true; } $runsnotasCGi = runsNotAsCgi(); $hasSmProblem = has_safemode_problem_global_twg(); $cacheOk = true; if (!file_exists($cachedir)) { if ($hasSmProblem) { echo "The directory 'cache' does not exist. Please create this directory manually and set the permissions to 777. TWG cannot create this directoriy because it would have the wrong owner! Read Howto 1 for better security settings!
"; } else if ($runsnotasCGi) { twg_mkdir($cachedir, 0777); } else { twg_mkdir($cachedir, 0755); } } if (file_exists($cachedir)) { if (is_writable($cachedir)) { copy(dirname(__FILE__) . "/../html/index.htm", $cachedir . "/index.htm"); } else { $cacheOk = false; echo "The directory '$cachedir' is not writeable. Please change the permissions to 777. Read Howto 1 for better security settings!
"; } } if (!file_exists($counterdir)) { if ($hasSmProblem) { echo "The directory '$counterdir' does not exist. Please create this directory manually and set the permissions to 777. TWG cannot create this directoriy because it would have the wrong owner! Read Howto 1 for better security settings!
"; } else if ($runsnotasCGi) { twg_mkdir($counterdir, 0777); } else { twg_mkdir($counterdir, 0755); } } if (file_exists($counterdir)) { if (is_writable($counterdir)) { copy(dirname(__FILE__) . '/../html/index.htm', $counterdir . '/index.htm'); } else { $cacheOk = false; echo "The directory '$counterdir' is not writeable. Please change the permissions to 777. Read Howto 1 for better security settings!
"; } } if (!file_exists($xmldir) && (!$store_xml_in_picfolders || $create_anyway)) { if ($hasSmProblem) { echo "The directory '$xmldir' does not exist. Please create this directory manually and set the permissions to 777. TWG cannot create this directoriy because it would have the wrong owner! Read Howto 1 for better security settings!
"; } else if ($runsnotasCGi) { twg_mkdir($xmldir, 0777); } else { twg_mkdir($xmldir, 0755); } } if (file_exists($xmldir)) { if (is_writable($xmldir)) { copy(dirname(__FILE__) . '/../html/index.htm', $xmldir . '/index.htm'); } else { $cacheOk = false; echo "The directory '$xmldir' is not writeable. Please change the permissions to 777. Read Howto 1 for better security settings!
"; } } $_SESSION["createCacheDirs"] = "TRUE"; if (!$cacheOk) { echo "
You first have to change the permissions before you can use TWG."; session_unregister("createCacheDirs"); } return $cacheOk; } /* gen jsscript */ $globcount = 0; function gen_cache($file_dir) { global $globcount, $cache_gen_wait_time, $cachedir; set_error_handler("on_error_no_output"); @set_time_limit(600); // = 10 Minutes - throws an error if safe mode is on! set_error_handler("on_error"); echo ""; echo ""; return $globcount; } function gen_cache_body($file_dir) { global $password_file; global $url_file; global $cache_dirs; global $exclude_directories; global $cachedir; global $basedir; global $extension_thumb, $extension_small; global $globcount, $max_gen_num; global $use_small_pic_size_as_height, $small_pic_size, $resize_only_if_too_big; if ($handle = @opendir($file_dir)) { $list = get_file_list($handle, $file_dir); $dir_length = count($list); // echo "