/** * bring the file size from remote file; aka url */ function get_remote_file_size($url, $method = "GET", $data = "", $redirect = 10) { $url = parse_url($url); $fp = @fsockopen($url['host'], !empty($url['port']) ? (int) $url['port'] : 80, $errno, $errstr, 30); if ($fp) { $path = (!empty($url['path']) ? $url['path'] : "/") . (!empty($url['query']) ? "?" . $url['query'] : ""); $header = "\r\nHost: " . $url['host']; if ("post" == strtolower($method)) { $header .= "\r\nContent-Length: " . strlen($data); } fputs($fp, $method . " " . $path . " HTTP/1.0" . $header . "\r\n\r\n" . ("post" == strtolower($method) ? $data : "")); if (!feof($fp)) { $scheme = fgets($fp); list(, $code) = explode(" ", $scheme); $headers = array("Scheme" => $scheme); } while (!feof($fp)) { $h = fgets($fp); if ($h == "\r\n" or $h == "\n") { break; } list($key, $value) = explode(":", $h, 2); $headers[$key] = trim($value); if ($code >= 300 and $code < 400 and strtolower($key) == "location" and $redirect > 0) { return get_remote_file_size($headers[$key], $method, $data, --$redirect); } } $body = ""; /*while ( !feof($fp) ) $body .= fgets($fp);*/ fclose($fp); } else { return array("error" => array("errno" => $errno, "errstr" => $errstr)); } return (string) $headers["Content-Length"]; }
function show_image($image_row, $mode = "", $show_link = 1, $detailed_view = 0) { global $self_url, $site_template, $site_sess, $user_info, $config, $cat_cache, $lang, $additional_image_fields, $user_table_fields, $url_show_profile; $is_new = $image_row['image_date'] >= time() - 60 * 60 * 24 * $config['new_cutoff'] ? 1 : 0; $description = !empty($image_row['image_description']) ? format_text($image_row['image_description'], 1, 0, 1) : REPLACE_EMPTY; if (!empty($image_row['image_keywords'])) { $split_keywords = explode(",", $image_row['image_keywords']); $keywords = ""; foreach ($split_keywords as $key => $val) { $url_val = $val; if (preg_match('/[^a-z0-9]+/i', $url_val)) { $url_val = '"' . $url_val . '"'; } $keywords .= ($keywords != "" ? ", " : "") . "<a href=\"" . $site_sess->url(ROOT_PATH . "search.php?search_keywords=" . urlencode($url_val)) . "\">" . format_text($val, 2) . "</a>"; } } else { $keywords = REPLACE_EMPTY; } if (!check_permission("auth_readcomment", $image_row['cat_id'])) { $image_row['image_allow_comments'] = 0; } $num_comments = $image_row['image_allow_comments'] == 1 ? $image_row['image_comments'] : ""; if ($user_info['user_level'] != GUEST) { $lightbox_url = $self_url; $lightbox_url .= !empty($mode) ? (strpos($lightbox_url, '?') !== false ? "&" : "?") . "mode=" . $mode : ""; $lightbox_url .= strpos($lightbox_url, '?') !== false ? "&" : "?"; if (check_lightbox($image_row['image_id'])) { $lightbox_url .= "action=removefromlightbox&id=" . $image_row['image_id']; $lightbox_button = "<a href=\"" . $site_sess->url($lightbox_url) . "\"><img src=\"" . get_gallery_image("lightbox_yes.gif") . "\" border=\"0\" alt=\"\" /></a>"; } else { $lightbox_url .= "action=addtolightbox&id=" . $image_row['image_id']; $lightbox_button = "<a href=\"" . $site_sess->url($lightbox_url) . "\"><img src=\"" . get_gallery_image("lightbox_no.gif") . "\" border=\"0\" alt=\"\" /></a>"; } } else { $lightbox_button = "<img src=\"" . get_gallery_image("lightbox_off.gif") . "\" border=\"0\" alt=\"\" />"; } if (!check_permission("auth_download", $image_row['cat_id'])) { $download_button = "<img src=\"" . get_gallery_image("download_off.gif") . "\" border=\"0\" alt=\"\" />"; $download_zip_button = function_exists("gzcompress") && function_exists("crc32") ? "<img src=\"" . get_gallery_image("download_zip_off.gif") . "\" border=\"0\" alt=\"\" />" : ""; $allow_download = 0; clear_download_token($image_row['image_id']); } else { $target = !empty($image_row['image_download_url']) && !is_remote_file($image_row['image_download_url']) && !is_local_file($image_row['image_download_url']) ? "target=\"_blank\"" : ""; $download_button = "<a href=\"" . $site_sess->url(ROOT_PATH . "download.php?" . URL_IMAGE_ID . "=" . $image_row['image_id']) . "\"" . $target . "><img src=\"" . get_gallery_image("download.gif") . "\" border=\"0\" alt=\"\" /></a>"; $download_zip_button = $target == "" && function_exists("gzcompress") && function_exists("crc32") ? "<a href=\"" . $site_sess->url(ROOT_PATH . "download.php?action=zip&" . URL_IMAGE_ID . "=" . $image_row['image_id']) . "\"" . $target . "><img src=\"" . get_gallery_image("download_zip.gif") . "\" border=\"0\" alt=\"\" /></a>" : ""; $allow_download = 1; set_download_token($image_row['image_id']); } if (!check_permission("auth_sendpostcard", $image_row['cat_id'])) { $postcard_button = "<img src=\"" . get_gallery_image("postcard_off.gif") . "\" border=\"0\" alt=\"\" />"; } else { $postcard_button = "<a href=\"" . $site_sess->url(ROOT_PATH . "postcards.php?" . URL_IMAGE_ID . "=" . $image_row['image_id'] . (!empty($mode) ? "&mode=" . $mode : "")) . "\"><img src=\"" . get_gallery_image("postcard.gif") . "\" border=\"0\" alt=\"\" /></a>"; } if (!check_permission("auth_viewimage", $image_row['cat_id']) || !check_permission("auth_viewcat", $image_row['cat_id'])) { $show_link = 0; } $file_size = "n/a"; if (!is_remote($image_row['image_media_file'])) { if ($file_size = @filesize(MEDIA_PATH . "/" . $image_row['cat_id'] . "/" . $image_row['image_media_file'])) { $file_size = format_file_size($file_size); } } elseif ($detailed_view) { $file_size = get_remote_file_size($image_row['image_media_file']); } if (isset($image_row[$user_table_fields['user_name']]) && $image_row['user_id'] != GUEST) { $user_name = format_text($image_row[$user_table_fields['user_name']], 2); $user_profile_link = !empty($url_show_profile) ? str_replace("{user_id}", $image_row['user_id'], $url_show_profile) : ROOT_PATH . "member.php?action=showprofile&" . URL_USER_ID . "=" . $image_row['user_id']; $user_name_link = "<a href=\"" . $site_sess->url($user_profile_link) . "\">" . $user_name . "</a>"; } else { $user_name = format_text($lang['userlevel_guest'], 2); $user_name_link = $user_name; } $site_template->register_vars(array("image_id" => $image_row['image_id'], "user_id" => $image_row['user_id'], "user_name" => $user_name, "user_name_link" => $user_name_link, "image_name" => format_text($image_row['image_name'], 2), "image_description" => $description, "image_keywords" => $keywords, "image_date" => format_date($config['date_format'] . " " . $config['time_format'], $image_row['image_date']), "image_is_new" => $is_new, "lang_new" => $lang['new'], "image_active" => $image_row['image_active'], "cat_id" => $image_row['cat_id'], "cat_name" => format_text($image_row['cat_name'], 2), "cat_url" => $site_sess->url(ROOT_PATH . "categories.php?" . URL_CAT_ID . "=" . $image_row['cat_id']), "image_downloads" => $image_row['image_downloads'], "image_votes" => $image_row['image_votes'], "image_rating" => $image_row['image_rating'], "image_hits" => $image_row['image_hits'], "allow_comments" => $image_row['image_allow_comments'], "lang_comments" => $lang['comments'], "image_comments" => $num_comments, "lightbox_button" => $lightbox_button, "postcard_button" => $postcard_button, "download_button" => $download_button, "download_zip_button" => $download_zip_button, "image_download_url" => $image_row['image_download_url'], "allow_download" => $allow_download, "url_download" => $site_sess->url(ROOT_PATH . "download.php?" . URL_IMAGE_ID . "=" . $image_row['image_id']), "image_file_size" => $file_size, "image_url" => $show_link ? $site_sess->url(ROOT_PATH . "details.php?" . URL_IMAGE_ID . "=" . $image_row['image_id'] . (!empty($mode) ? "&mode=" . $mode : "")) : "", "thumbnail" => get_thumbnail_code($image_row['image_media_file'], $image_row['image_thumb_file'], $image_row['image_id'], $image_row['cat_id'], $image_row['image_name'], $mode, $show_link), "thumbnail_openwindow" => get_thumbnail_code($image_row['image_media_file'], $image_row['image_thumb_file'], $image_row['image_id'], $image_row['cat_id'], $image_row['image_name'], $mode, $show_link, 1), "image_file_name" => $image_row['image_media_file'], "thumbnail_file_name" => $image_row['image_thumb_file'])); if (!empty($additional_image_fields)) { $additional_field_array = array(); foreach ($additional_image_fields as $key => $val) { $additional_field_array[$key] = !empty($image_row[$key]) ? format_text($image_row[$key], 1) : REPLACE_EMPTY; $additional_field_array['lang_' . $key] = $val[0]; } if (!empty($additional_field_array)) { $site_template->register_vars($additional_field_array); } } $rate_form = ""; if (check_permission("auth_vote", $image_row['cat_id'])) { $site_template->register_vars("rate", $lang['rate']); $rate_form = $site_template->parse_template("rate_form"); } $site_template->register_vars("rate_form", $rate_form); $site_template->register_vars(array("image" => get_media_code($image_row['image_media_file'], $image_row['image_id'], $image_row['cat_id'], $image_row['image_name'], $mode, $show_link, $detailed_view))); return true; }
// Find all CSS: foreach ($html->find('link') as $element) { if (strpos($element->href, '.css') !== false) { $sizeCSS = get_remote_file_size($element->href); $totalSize = $totalSize + $sizeCSS; $sizeCSS += $sizeCSS; $totalNumResources += 1; $totalNumResourcesCSS += 1; } } echo "CSS: {$totalNumResourcesCSS} Request, {$sizeCSS} Bytes<br>"; //find all javascript: foreach ($html->find('script') as $element) { //check to see if it is javascript file: if (strpos($element->src, '.js') !== false) { $sizeJS = get_remote_file_size($element->src); $totalSize = $totalSize + $sizeJS; $sizeJS += $sizeJS; $totalNumResources += 1; $totalNumResourcesJS += 1; } } echo "JS: {$totalNumResourcesJS} Request, {$sizeJS} Bytes<br>"; echo "Final total download size: {$totalSize} Bytes<br>"; echo "Final total HTTP requests: {$totalNumResources}<br>"; function get_remote_file_size($url) { $headers = get_headers('http://www.care2.com', 1); if (isset($headers['Content-Length'])) { return $headers['Content-Length']; }
/** * Processing current upload, aka 'after user click upload button to upload his files' */ function process() { global $SQL, $dbprefix, $config, $lang; ($hook = kleeja_run_hook('kljuploader_process_func')) ? eval($hook) : null; //run hook # check folder our real folder if (!file_exists($this->folder)) { if (!make_folder($this->folder)) { $this->messages[] = array($lang['CANT_DIR_CRT'], 'index_err'); } } # check the live-exts-folder, live exts plugin codes if (!empty($config['imagefolderexts']) && !file_exists($config['imagefolder'])) { if (!make_folder($config['imagefolder'])) { $this->messages[] = array($lang['CANT_DIR_CRT'], 'index_err'); } } # when uploading_type = 1, then we upload from _file input # if uploading_type = 2, then we uploading from url which is disabled by default and is buggy $uploading_type = isset($_POST['submitr']) ? 1 : (isset($_POST['submittxt']) ? 2 : false); # add your uploading_type through the hook ($hook = kleeja_run_hook('kljuploader_process_func_uploading_type')) ? eval($hook) : null; //run hook #no uploading yet, or just go to index.php, so we have make a new session if (!$uploading_type) { unset($_SESSION['FIILES_NOT_DUPLI'], $_SESSION['FIILES_NOT_DUPLI_LINKS']); } # is captcha on, and there is uploading going on if ($this->safe_code && $uploading_type) { #captcha is wrong if (!kleeja_check_captcha()) { return $this->messages[] = array($lang['WRONG_VERTY_CODE'], 'index_err'); } } # to prevent flooding, user must wait, waiting-time is grapped from Kleeja settings, admin is exceptional if (!$this->user_is_adm && user_is_flooding($this->id_user)) { return $this->messages[] = array(sprintf($lang['YOU_HAVE_TO_WAIT'], $this->id_user == '-1' ? $config['guestsectoupload'] : $config['usersectoupload']), 'index_err'); } # flooading .. if ($uploading_type == 1 && isset($_SESSION['FIILES_NOT_DUPLI'])) { for ($i = 0; $i <= $this->filesnum; $i++) { if (!empty($_SESSION['FIILES_NOT_DUPLI']['file_' . $i . '_']['name']) && !empty($_FILES['file_' . $i . '_']['name']) && $_SESSION['FIILES_NOT_DUPLI']['file_' . $i . '_']['name'] == $_FILES['file_' . $i . '_']['name']) { redirect('./'); } } } if ($uploading_type == 2 && isset($_SESSION['FIILES_NOT_DUPLI_LINKS'])) { for ($i = 0; $i <= $this->filesnum; $i++) { if (!empty($_SESSION['FIILES_NOT_DUPLI_LINKS']['file_' . $i . '_']) && !empty($_POST['file_' . $i . '_']) && trim($_POST['file_' . $i . '_']) != $lang['PAST_URL_HERE'] && trim($_SESSION['FIILES_NOT_DUPLI_LINKS']['file_' . $i . '_']) != $lang['PAST_URL_HERE'] && $_SESSION['FIILES_NOT_DUPLI_LINKS']['file_' . $i . '_'] == $_POST['file_' . $i . '_']) { redirect('./'); } } } # flooding code, making sure every ok session is cleared if (isset($_POST['submitr'])) { if (isset($_SESSION['FIILES_NOT_DUPLI'])) { unset($_SESSION['FIILES_NOT_DUPLI']); } $_SESSION['FIILES_NOT_DUPLI'] = $_FILES; } elseif (isset($_POST['submittxt'])) { if (isset($_SESSION['FIILES_NOT_DUPLI_LINKS'])) { unset($_SESSION['FIILES_NOT_DUPLI_LINKS']); } $_SESSION['FIILES_NOT_DUPLI_LINKS'] = $_POST; } #now close session to let user open any other page in Kleeja @session_write_close(); # uploading process, empty check-list for now $check = false; # add your uploading_type through the hook ($hook = kleeja_run_hook('kljuploader_process_func_uploading_type_later')) ? eval($hook) : null; //run hook # do upload switch ($uploading_type) { #uploading from a _files input case 1: ($hook = kleeja_run_hook('kljuploader_process_func_uploading_type_1')) ? eval($hook) : null; //run hook # loop the uploaded files for ($i = 0; $i <= $this->filesnum; $i++) { //no file! if (empty($_FILES['file_' . $i . '_']['tmp_name'])) { continue; } # file name $this->filename = isset($_FILES['file_' . $i . '_']['name']) ? htmlspecialchars(str_replace(array(';', ','), '', $_FILES['file_' . $i . '_']['name'])) : ''; # add the file to the check-list $check .= isset($_FILES['file_' . $i . '_']['name']) ? $_FILES['file_' . $i . '_']['name'] : ''; # get the extension of file $this->typet = strtolower(array_pop(explode('.', $this->filename))); # them the size $this->sizet = !empty($_FILES['file_' . $i . '_']['size']) ? intval($_FILES['file_' . $i . '_']['size']) : null; # get the other filename, changed depend on kleeja settings $this->filename2 = change_filename_decoding($this->filename, $i, $this->typet, $this->decode); # filename templates {rand:..}, {date:..} $this->filename2 = change_filename_templates(trim($this->prefix) . $this->filename2); ($hook = kleeja_run_hook('kljuploader_process_func_uploading_type_1_loop')) ? eval($hook) : null; //run hook # file exists before? change it a little if (file_exists($this->folder . '/' . $this->filename2)) { $this->filename2 = change_filename_decoding($this->filename2, $i, $this->typet, 'exists'); } # now, let process it if (!in_array(strtolower($this->typet), array_keys($this->types))) { # guest if ($this->id_user == '-1') { $this->messages[] = array(sprintf($lang['FORBID_EXT'], $this->typet) . '<br /> <a href="' . ($config['mod_writer'] ? "register.html" : "ucp.php?go=register") . '" title="' . htmlspecialchars($lang['REGISTER']) . '">' . $lang['REGISTER'] . '</a>', 'index_err'); } else { $this->messages[] = array(sprintf($lang['FORBID_EXT'], $this->typet), 'index_err'); } } elseif (preg_match("#[\\\\/\\:\\*\\?\\<\\>\\|\"]#", $this->filename2)) { $this->messages[] = array(sprintf($lang['WRONG_F_NAME'], htmlspecialchars($_FILES['file_' . $i . '_']['name'])), 'index_err'); } elseif (ext_check_safe($_FILES['file_' . $i . '_']['name']) == false) { $this->messages[] = array(sprintf($lang['WRONG_F_NAME'], htmlspecialchars($_FILES['file_' . $i . '_']['name'])), 'index_err'); } elseif (check_mime_type($_FILES['file_' . $i . '_']['type'], in_array(strtolower($this->typet), array('gif', 'png', 'jpg', 'jpeg', 'bmp')), $_FILES['file_' . $i . '_']['tmp_name']) == false) { $this->messages[] = array(sprintf($lang['NOT_SAFE_FILE'], htmlspecialchars($_FILES['file_' . $i . '_']['name'])), 'index_err'); } elseif ($this->types[strtolower($this->typet)] > 0 && $this->sizet >= $this->types[strtolower($this->typet)]) { $this->messages[] = array(sprintf($lang['SIZE_F_BIG'], htmlspecialchars($_FILES['file_' . $i . '_']['name']), Customfile_size($this->types[strtolower($this->typet)])), 'index_err'); } else { ($hook = kleeja_run_hook('kljuploader_process_func_uploading_type_1_loop_upload')) ? eval($hook) : null; //run hook #if this is listed as live-ext from Kleeja settings $live_exts = array_map('trim', explode(',', $config['imagefolderexts'])); $folder_to_upload = $this->folder; if (in_array(strtolower($this->typet), $live_exts)) { # live-exts folder, if empty use default folder $folder_to_upload = trim($config['imagefolder']) == '' ? trim($config['foldername']) : trim($config['imagefolder']); # change to time decoding for filename if ((int) $config['imagefoldere']) { //$this->filename2 = change_filename_decoding($this->filename2, $i, $this->typet, 'time'); } } # now, upload the file $file = move_uploaded_file($_FILES['file_' . $i . '_']['tmp_name'], $folder_to_upload . "/" . $this->filename2); if ($file) { $this->saveit($this->filename2, $folder_to_upload, $this->sizet, $this->typet, $this->filename); } else { $this->messages[] = array(sprintf($lang['CANT_UPLAOD'], $this->filename2), 'index_err'); } } } #loop # well, there is no file uploaded if (!isset($check) || empty($check)) { $this->messages[] = array($lang['CHOSE_F'], 'index_err'); } break; #uploading from a url text-input #uploading from a url text-input case 2: #if not enabled, quit it if ((int) $config['www_url'] != '1') { break; } ($hook = kleeja_run_hook('kljuploader_process_func_uploading_type_2')) ? eval($hook) : null; //run hook #loop text inputs for ($i = 0; $i <= $this->filesnum; $i++) { # get file name $this->filename = isset($_POST['file_' . $i . '_']) ? basename(htmlspecialchars($_POST['file_' . $i . '_'])) : ''; //print $this->filename; # add it to the check-list $check .= isset($_POST['file_' . $i . '_']) && trim($_POST['file_' . $i . '_']) != $lang['PAST_URL_HERE'] ? $_POST['file_' . $i . '_'] : ''; # file extension, type $this->typet = explode(".", $this->filename); if (in_array($this->typet[count($this->typet) - 1], array('html', 'php', 'html'))) { $this->typet = strtolower($this->typet[count($this->typet) - 2]); } else { $this->typet = strtolower($this->typet[count($this->typet) - 1]); } # change to another filename depend on kleeja settings $this->filename2 = change_filename_decoding($this->filename, $i, $this->typet, $this->decode); $this->filename2 = change_filename_templates(trim($this->prefix) . $this->filename2); ($hook = kleeja_run_hook('kljuploader_process_func_uploading_type_2_loop')) ? eval($hook) : null; //run hook # process is begun if (empty($_POST['file_' . $i . '_']) || trim($_POST['file_' . $i . '_']) == $lang['PAST_URL_HERE']) { #if empty is not big deal, it's a multi-text-input, remember? } elseif (!in_array(strtolower($this->typet), array_keys($this->types))) { $this->messages[] = array(sprintf($lang['FORBID_EXT'], htmlspecialchars($_POST['file_' . $i . '_']), $this->typet), 'index_err'); } elseif (file_exists($this->folder . '/' . $this->filename2)) { $this->messages[] = array(sprintf($lang['SAME_FILE_EXIST'], htmlspecialchars($this->filename2)), 'index_err'); } else { ($hook = kleeja_run_hook('kljuploader_process_func_uploading_type_2_loop_upload')) ? eval($hook) : null; //run hook #if this is listed as live-ext from Kleeja settings $live_exts = explode(',', $config['imagefolderexts']); $folder_to_upload = $this->folder; if (in_array(strtolower($this->typet), $live_exts)) { # live-exts folder, if empty use default folder $folder_to_upload = trim($config['imagefolder']) == '' ? trim($config['foldername']) : trim($config['imagefolder']); # change to time decoding for filename if ((int) $config['imagefoldere']) { //$this->filename2 = change_filename_decoding($this->filename2, $i, $this->typet, 'time'); } } #no prefix ? http or even ftp, then add one if (!in_array(substr($_POST['file_' . $i . '_'], 0, 4), array('http', 'ftp:'))) { $_POST['file_' . $i . '_'] = 'http://' . $_POST['file_' . $i . '_']; } #get size, if big quit it $this->sizet = get_remote_file_size($_POST['file_' . $i . '_']); if ($this->types[strtolower($this->typet)] > 0 && $this->sizet >= $this->types[strtolower($this->typet)]) { $this->messages[] = array(sprintf($lang['SIZE_F_BIG'], htmlspecialchars($_POST['file_' . $i . '_']), Customfile_size($this->types[strtolower($this->typet)])), 'index_err'); } else { #get remote data, if no data quit it $data = fetch_remote_file($_POST['file_' . $i . '_'], $folder_to_upload . "/" . $this->filename2, 6, false, 2, true); if ($data === false) { $this->messages[] = array($lang['URL_CANT_GET'], 'index_err'); } else { $this->saveit($this->filename2, $folder_to_upload, $this->sizet, $this->typet); } } } #else } #end loop # if not file uploaded as the check-list said, then show error if (!isset($check) || empty($check)) { $this->messages[] = array($lang['CHOSE_F'], 'index_err'); } break; default: ($hook = kleeja_run_hook('kljuploader_process_switch_default_func')) ? eval($hook) : null; //run hook } #end switch }