function path() { return Upload::get_cache_dir($this->id); }
} if ($media->thumb->last_saved) { readfile($media->thumb->last_saved); } else { // last resort $media->thumb->output(); } $globals['access_log'] = false; die; } $errn = 404; break; case "tmp_thumb": // Temporal filenames $name = preg_replace('/^tmp_thumb\\-/', '', $filename); $path = Upload::get_cache_dir() . '/tmp/'; $pathname = $path . $name; $thumbname = "{$path}/{$filename}"; if (!file_exists($pathname)) { syslog(LOG_INFO, "Meneame, ooops, couldn't find {$pathname}"); $errn = 404; break; } require_once mnminclude . "simpleimage.php"; $thumb = new SimpleImage(); $thumb->load($pathname); $thumb->resize($globals['media_thumb_size'], $globals['media_thumb_size'], true); if (!$thumb->save($thumbname, -1)) { $errn = 503; break; }
header('Content-Type: application/json; charset=UTF-8'); array_push($globals['cache-control'], 'no-cache'); http_cache(); $r = new stdClass(); $headers = request_headers(); if (!$current_user->user_id) { die; } // If the header is available, chech the size if (isset($headers['X-File-Size']) && $headers['X-File-Size'] > 0 && Upload::current_user_limit_exceded($headers['X-File-Size'])) { $r->error = _("Límite de ficheros excedidos"); syslog(LOG_INFO, "File size exceeded " . $headers['X-File-Size']); echo json_encode($r); die; } $dir = Upload::get_cache_dir() . '/tmp'; if (!file_exists($dir)) { $old_mask = umask(0); $res = @mkdir($dir, 0777, true); umask($old_mask); } $source = file_get_contents('php://input'); if (Upload::current_user_limit_exceded(strlen($source))) { $r->error = _("Límite de ficheros excedidos"); echo json_encode($r); die; } // Delete old files first $older = time() - 1800; $iterator = new DirectoryIterator($dir); foreach ($iterator as $fileinfo) {
function get_thumb($debug = false, $url = false) { global $globals; $site = false; if (empty($this->url)) { if (!$this->read()) { return false; } } $blog = new Blog(); $blog->id = $this->blog; if ($blog->read()) { $site = $blog->url; } if (!empty($url)) { $this->image_parser = new HtmlImages($url); } else { $this->image_parser = new HtmlImages($this->url, $site); $this->image_parser->debug = $debug; $this->image_parser->referer = $this->get_permalink(); } if ($debug) { echo "<!-- Meneame, before image_parser -->\n"; } $img = $this->image_parser->get(); if ($debug) { echo "<!-- Meneame, after image_parser: {$img->url} -->\n"; } $this->thumb_status = 'checked'; $this->thumb = ''; if ($img) { $filepath = Upload::get_cache_dir() . "/tmp/thumb-{$this->id}.jpg"; $thumbnail = $img->scale($globals['medium_thumb_size']); $thumbnail->save($filepath, IMAGETYPE_JPEG); if (!$this->move_tmp_image(basename($filepath), 'image/jpeg')) { $this->thumb_status = 'error'; if ($debug) { echo "<!-- Meneame, error saving thumbnail " . $this->get_permalink() . " -->\n"; } } else { $this->image_parser->seen_add($img->url); $this->thumb_status = 'remote'; if ($debug) { echo "<!-- Meneame, new thumbnail {$img->url} -->\n"; } } } $this->store_thumb_status(); return $this->has_thumb(); }
function try_thumb($base) { global $globals; $final_size = Link::thumb_sizes($base); if (!$final_size) { return false; } $dir = Upload::get_cache_dir($this->id); $output_filename = "{$base}-{$this->id}.jpg"; require_once mnminclude . "simpleimage.php"; $f = false; $input = new SimpleImage(); foreach (Link::thumb_sizes() as $b => $s) { if ($b == 'thumb') { $delete = true; // Mark as deleted if the last does not exist $root = ""; } else { $delete = false; $root = $b; } $filename = "{$root}-{$this->id}.jpg"; // Check first if the file exists if (is_readable("{$dir}/{$filename}")) { $f = "{$dir}/{$filename}"; } else { $f = $this->thumb_download($b, $delete); } if ($f && $input->load($f)) { break; } } if (!$input->image) { return false; } if ($input->getWidth() <= $final_size) { if ($f != "{$dir}/{$output_filename}") { copy($f, "{$dir}/{$output_filename}"); } } else { $input->resize($final_size, $final_size); $input->save("{$dir}/{$output_filename}"); } @chmod($f, 0777); @chmod("{$dir}/{$output_filename}", 0777); return "{$dir}/{$output_filename}"; }
function avatars_remove_user_files($user) { global $globals; if ($globals['Amazon_S3_media_bucket']) { Media::rm("avatars/{$user}-*"); } if ($globals['Amazon_S3_local_cache'] || !$globals['Amazon_S3_media_bucket']) { $subdir = Upload::get_cache_dir($user); if ($subdir && ($handle = @opendir($subdir))) { while (false !== ($file = readdir($handle))) { if (preg_match("/^{$user}-/", $file)) { @unlink($subdir . '/' . $file); } } closedir($handle); } } }