$lat = NULL; $lon = NULL; if (isset($data)) { if (!$up_thumb) { if (function_exists("ImageCreateFromString") && !strstr($type, "gif")) { if ($img = @imagecreatefromstring($data)) { $size_x = imagesx($img); $size_y = imagesy($img); if ($size_x > $size_y) { $tscale = (int) $size_x / $gal_info["thumbSizeX"]; } else { $tscale = (int) $size_y / $gal_info["thumbSizeY"]; } $tw = (int) ($size_x / $tscale); $ty = (int) ($size_y / $tscale); if (chkgd2()) { $t = imagecreatetruecolor($tw, $ty); imagecopyresampled($t, $img, 0, 0, 0, 0, $tw, $ty, $size_x, $size_y); } else { $t = imagecreate($tw, $ty); $imagegallib->ImageCopyResampleBicubic($t, $img, 0, 0, 0, 0, $tw, $ty, $size_x, $size_y); } // CHECK IF THIS TEMP IS WRITEABLE OR CHANGE THE PATH TO A WRITEABLE DIRECTORY //$tmpfname = 'temp.jpg'; $tmpfname = tempnam($prefs['tmpDir'], "TMPIMG"); imagejpeg($t, $tmpfname); // Now read the information $fp = fopen($tmpfname, "rb"); $t_data = fread($fp, filesize($tmpfname)); fclose($fp); unlink($tmpfname);
/** * @param $data * @return mixed */ function capture_images($data) { global $prefs, $tikilib; if ($prefs['cacheimages'] != 'y') { return $data; } preg_match_all("/src=\"([^\"]+)\"/", $data, $reqs1); preg_match_all("/src=\\'([^\\']+)\\'/", $data, $reqs2); preg_match_all("/src=([A-Za-z0-9\\:\\?\\=\\/\\\\.\\-\\_]+)\\}/", $data, $reqs3); preg_match_all("/src=([A-Za-z0-9\\:\\?\\=\\/\\\\.\\-\\_]+) /", $data, $reqs4); $merge = array_merge($reqs1[1], $reqs2[1], $reqs3[1], $reqs4[1]); $merge = array_unique($merge); //print_r($merge); // Now for each element in the array capture the image and // if the capture was successful then change the reference to the // internal image $page_data = $data; foreach ($merge as $img) { // This prevents caching images if (!strstr($img, "img/wiki_up") && !strstr($img, "show_image.php") && !strstr($img, "nocache") && @getimagesize($img)) { //print("Procesando: $img<br />"); @($fp = fopen($img, "r")); if ($fp) { $data = ''; while (!feof($fp)) { $data .= fread($fp, 4096); } //print("Imagen leida:".strlen($data)." bytes<br />"); fclose($fp); if (strlen($data) > 0) { $url_info = parse_url($img); $pinfo = pathinfo($url_info["path"]); $type = "image/" . $pinfo["extension"]; $name = $pinfo["basename"]; $size = strlen($data); $url = $img; if (function_exists("ImageCreateFromString") && !strstr($type, "gif")) { $img = imagecreatefromstring($data); $size_x = imagesx($img); $size_y = imagesy($img); // Fix the ratio values for system gallery $gal_info["thumbSizeX"] = 90; $gal_info["thumbSizeY"] = 90; if ($size_x > $size_y) { $tscale = (int) $size_x / $gal_info["thumbSizeX"]; } else { $tscale = (int) $size_y / $gal_info["thumbSizeY"]; } $tw = (int) ($size_x / $tscale); $ty = (int) ($size_y / $tscale); if (chkgd2()) { $t = imagecreatetruecolor($tw, $ty); imagecopyresampled($t, $img, 0, 0, 0, 0, $tw, $ty, $size_x, $size_y); } else { $t = imagecreate($tw, $ty); $this->ImageCopyResampleBicubic($t, $img, 0, 0, 0, 0, $tw, $ty, $size_x, $size_y); } // CHECK IF THIS TEMP IS WRITEABLE OR CHANGE THE PATH TO A WRITEABLE DIRECTORY //$tmpfname = 'temp.jpg'; //$tmpfname = tempnam("/tmp", "img"); $tmpfname = tempnam($prefs['tmpDir'], "img"); imagejpeg($t, $tmpfname); // Now read the information $fp = fopen($tmpfname, "rb"); $t_data = fread($fp, filesize($tmpfname)); fclose($fp); unlink($tmpfname); $t_pinfo = pathinfo($tmpfname); $t_type = $t_pinfo["extension"]; $t_type = 'image/' . $t_type; $imageId = $this->insert_image(0, '', '', $name, $type, $data, $size, $size_x, $size_y, 'admin', $t_data, $t_type, NULL, NULL, $gal_info); //print("Imagen generada en $imageId<br />"); } else { //print("No GD detected generating image without thumbnail<br />"); $imageId = $this->insert_image(0, '', '', $name, $type, $data, $size, 100, 100, 'admin', '', '', NULL, NULL, $gal_info); //print("Imagen en $imageId<br />"); } // Now change it! //print("Changing $url to imageId: $imageId"); $uri = parse_url($_SERVER["REQUEST_URI"]); $path = str_replace("tiki-editpage", "show_image", $uri["path"]); $path = str_replace("tiki-edit_article", "show_image", $path); $page_data = str_replace($url, $tikilib->httpPrefix(true) . $path . '?id=' . $imageId, $page_data); } // if strlen } // if $fp } } // foreach return $page_data; }
/** * sets the avatar from a given image file's URL * * @return string URL for the current page */ function set_avatar_from_url($url, $userwatch = "", $name = "") { global $user, $prefs; $access = TikiLib::lib('access'); $access->check_feature('feature_userPreferences'); $access->check_user($user); $userprefslib = TikiLib::lib('userprefs'); $imagegallib = TikiLib::lib('imagegal'); if (empty($userwatch)) { $userwatch = $user; } $data = file_get_contents($url); list($iwidth, $iheight, $itype, $iattr) = getimagesize($url); $itype = image_type_to_mime_type($itype); // Get proper file size of image $imgdata = get_headers($url, true); if (isset($imgdata['Content-Length'])) { # Return file size $size = (int) $imgdata['Content-Length']; } // Store full-size file gallery image if that is required if ($prefs["user_store_file_gallery_picture"] == 'y') { $fgImageId = $userprefslib->set_file_gallery_image($userwatch, $name, $size, $itype, $data); } // Store small avatar if ($prefs['user_small_avatar_size']) { $avsize = $prefs['user_small_avatar_size']; } else { $avsize = "45"; //default } if (($iwidth == $avsize and $iheight <= $avsize) || ($iwidth <= $avsize and $iheight == $avsize)) { $userprefslib->set_user_avatar($userwatch, 'u', '', $name, $size, $itype, $data); } else { if (function_exists("ImageCreateFromString") && !strstr($type, "gif")) { $img = imagecreatefromstring($data); $size_x = imagesx($img); $size_y = imagesy($img); /* if the square crop is set, crop the image before resizing */ if ($prefs['user_small_avatar_square_crop']) { $crop_size = min($size_x, $size_y); $offset_x = ($size_x - $crop_size) / 2; $offset_y = ($size_y - $crop_size) / 2; $crop_array = array('x' => $offset_x, 'y' => $offset_y, 'width' => $crop_size, 'height' => $crop_size); $img = imagecrop($img, $crop_array); $size_x = $size_y = $crop_size; } if ($size_x > $size_y) { $tscale = (int) $size_x / $avsize; } else { $tscale = (int) $size_y / $avsize; } $tw = (int) ($size_x / $tscale); $ty = (int) ($size_y / $tscale); if ($tw > $size_x) { $tw = $size_x; } if ($ty > $size_y) { $ty = $size_y; } if (chkgd2()) { $t = imagecreatetruecolor($tw, $ty); imagecopyresampled($t, $img, 0, 0, 0, 0, $tw, $ty, $size_x, $size_y); } else { $t = imagecreate($tw, $ty); $imagegallib->ImageCopyResampleBicubic($t, $img, 0, 0, 0, 0, $tw, $ty, $size_x, $size_y); } // CHECK IF THIS TEMP IS WRITEABLE OR CHANGE THE PATH TO A WRITEABLE DIRECTORY $tmpfname = tempnam($prefs['tmpDir'], "TMPIMG"); imagejpeg($t, $tmpfname); // Now read the information $fp = fopen($tmpfname, "rb"); $t_data = fread($fp, filesize($tmpfname)); fclose($fp); unlink($tmpfname); $t_type = 'image/jpeg'; $userprefslib->set_user_avatar($userwatch, 'u', '', $name, $size, $t_type, $t_data); } else { $userprefslib->set_user_avatar($userwatch, 'u', '', $name, $size, $type, $data); } } TikiLib::events()->trigger('tiki.user.avatar', array('type' => 'user', 'object' => $userwatch, 'user' => $userwatch)); }