コード例 #1
0
<?php

require_once dirname(__FILE__) . "/includes/wpws-access.php";
require_once dirname(__FILE__) . "/includes/wpws-imageutils.php";
/*
ini_set("display_errors", 1);
error_reporting(E_ALL);/**/
$jail = realpath(wpws_getBasedir() . WP_UPLOAD_DIR);
if (!realpath($jail)) {
    die("WordPress Web Service plugin needs an update. The references upload directory is invalid or can't be read.");
}
$width = isset($_REQUEST["width"]) && is_numeric($_REQUEST["width"]) ? intval($_REQUEST["width"]) : false;
$height = isset($_REQUEST["height"]) && is_numeric($_REQUEST["height"]) ? intval($_REQUEST["height"]) : false;
$quality = isset($_REQUEST["quality"]) && is_numeric($_REQUEST["quality"]) ? intval($_REQUEST["quality"]) : 80;
$src = $_REQUEST["src"];
$file = realpath($jail . $src);
/*
 * src file must reside in jail directory
 */
if (wpws_ImageUtils::file_resides_in_directory($fail, $file)) {
    die("The requested file does not reside in the upload directory.");
}
$send_function_name = wpws_ImageUtils::get_send_function_name($file);
if (wpws_cacheIsFunctional()) {
    // Use the cache
    $mtime = filemtime($file);
    if (wpws_ImageUtils::cached_file_is_needed($src, $width, $height, $quality, $mtime)) {
        // Cache image
        wpws_ImageUtils::remove_cached_file($src, $width, $height, $quality);
        $resized_image = wpws_ImageUtils::generate_resized_image($file, $width, $height);
        $cache_filename = wpws_ImageUtils::generate_timestamped_cache_filename($src, $width, $height, $quality, $mtime);
コード例 #2
0
 /**
  * Extracts all <img>-Tage contained in a page determined by the $galleryId
  * Useful for paging are the parameters $start and $end. Both are optional and
  * if not supplied will return all Images.
  *
  * @param int id of the page to be returned as a Gallery
  * @param bool true if images of sub galleries should also be returned
  * @param int index of the first image to return
  * @param int index of the the last image to return
  * @return wpws_Image[]
  */
 function getImages($galleryId, $includeSubGalleries, $start = 1, $end = null)
 {
     $galleryId = is_numeric($galleryId) ? intval($galleryId) : 0;
     $includeSubGalleries = $includeSubGalleries ? true : false;
     $start = is_numeric($start) ? intval($start) : null;
     $end = is_numeric($end) ? intval($end) : null;
     $wpws_page = wp_WebService::getPage($galleryId);
     $html = $wpws_page->content;
     $xml = new SimpleXMLElement('<xml>' . utf8_encode(html_entity_decode($html)) . '</xml>');
     // Construct XPath query
     $q = "/descendant-or-self::img";
     $predicate = array();
     if ($start != null) {
         $predicate[] = "position() >= {$start}";
     }
     if ($end != null) {
         $predicate[] = "position() <= {$end}";
     }
     if (count($predicate) > 0) {
         $q .= "[" . implode(" and ", $predicate) . "]";
     }
     $xml_images = $xml->xpath($q);
     $wpws_images = array();
     foreach ($xml_images as $xml_image) {
         // Build original / full size image url
         // and pass the url to the resize script
         list(, $uri) = explode(WP_UPLOAD_DIR, strval($xml_image["src"]));
         // http://abc.de/blog/, 2010/xyz/img-120x120.jpg
         $originalUri = preg_replace("~-\\d+x\\d+~", "", $uri, 1);
         // 						2010/xyz/img.jpg
         $resizeableUrl = wpws_getPluginUrl() . "/resize_image.php?src=" . $originalUri . "&width=%{WIDTH}&height=%{HEIGHT}&quality=%{QUALITY}";
         $file = wpws_getBasedir() . WP_UPLOAD_DIR . $uri;
         list($width, $height) = getimagesize($file);
         $originalFile = wpws_getBasedir() . WP_UPLOAD_DIR . $originalUri;
         list($maxResizeableWidth, $maxResizeableHeight) = getimagesize($originalFile);
         $wpws_images[] = new wpws_Image($galleryId, strval($xml_image["src"]), $width, $height, $resizeableUrl, $maxResizeableWidth, $maxResizeableHeight, strval($xml_image["title"]), strval($xml_image["alt"]));
     }
     if ($includeSubGalleries) {
         $wpws_subPages = wp_WebService::getPages("child_of=" . $galleryId);
         foreach ($wpws_subPages as $wpws_subPage) {
             $wpws_subImages = wp_WebService::getImages($wpws_subPage->id);
             $wpws_images = array_merge($wpws_images, $wpws_subImages);
         }
     }
     return $wpws_images;
 }