示例#1
0
        }
        $from = addslashes($_FILES['site_favicon']['tmp_name']);
        $to = addslashes($newdir . '/favicon.png');
        CoreGraphics::resize($from, $to, 32, 32);
    }
    if (isset($_FILES['site_logo']) && file_exists($_FILES['site_logo']['tmp_name'])) {
        $tmpname = addslashes($_FILES['site_logo']['tmp_name']);
        $newdir = USERBASE . '/f/skin_files';
        if (!file_exists($newdir)) {
            mkdir($newdir);
        }
        $files = glob($newdir . '/logo-*');
        foreach ($files as $f) {
            unlink($f);
        }
        CoreGraphics::convert($_FILES['site_logo']['tmp_name'], $newdir . '/logo.png');
    }
    $pageLengthLimit = $_REQUEST['site_page_length_limit'];
    if (!empty($pageLengthLimit) && is_numeric($pageLengthLimit)) {
        $DBVARS['site_page_length_limit'] = $pageLengthLimit;
    } else {
        if (isset($DBVARS['site_page_length_limit'])) {
            unset($DBVARS['site_page_length_limit']);
        }
    }
    Core_configRewrite();
    Core_cacheClear();
    echo '<em>' . __('options updated') . '</em>';
}
if ($action == 'remove_logo') {
    unlink(USERBASE . '/f/skin_files/logo.png');
示例#2
0
/**
 * set the icon of a category
 *
 * @return array result of upload
 */
function Products_adminCategorySetIcon()
{
    $cat_id = (int) $_REQUEST['cat_id'];
    $cat = ProductCategory::getInstance($cat_id);
    $dir = USERBASE . '/f/products/categories/' . $cat_id;
    @mkdir($dir, 0777, true);
    $tmpname = $_FILES['Filedata']['tmp_name'];
    list($width, $height) = getimagesize($tmpname);
    $thumbw = (int) $cat->vals['thumbsize_w'];
    $thumbh = (int) $cat->vals['thumbsize_h'];
    if ($width > $thumbw || $height > $thumbh) {
        CoreGraphics::resize($tmpname, $dir . '/icon.png', $thumbw, $thumbh);
    } else {
        move_uploaded_file($tmpname, $dir . '/icon.png');
    }
    return array('ok' => 1);
}
示例#3
0
/**
 * display an theme's screenshot
 *
 * @param string $file the screenshot
 *
 * @return null
 */
function ThemesApi_displayImage($file)
{
    if (!file_exists($file) || !filesize($file)) {
        die(__('File %1 does not exist', array($file), 'core'));
    }
    $arr = getimagesize($file);
    if ($arr[0] > 240 || $arr[1] > 172) {
        $md5 = USERBASE . '/ww.cache/screenshots/' . md5($file) . '.png';
        if (!file_exists($md5)) {
            @mkdir(USERBASE . '/ww.cache/screenshots');
            CoreGraphics::resize($file, $md5, 240, 172);
        }
        $file = $md5;
    }
    /**
     * set headers and read file
     */
    header('Content-type: image/png');
    header('Content-Transfer-Encoding: Binary');
    header('Content-length: ' . filesize($file));
    readfile($file);
}
示例#4
0
/**
 * return a logo HTML string if the admin uploaded one
 *
 * @param array $vars array of logo parameters (width, height)
 *
 * @return string
 */
function Template_logoDisplay($vars)
{
    $vars = array_merge(array('width' => 64, 'height' => 64), $vars);
    $image_file_orig = USERBASE . '/f/skin_files/logo.png';
    if (!file_exists($image_file_orig)) {
        return '';
    }
    $x = (int) $vars['width'];
    $y = (int) $vars['height'];
    $geometry = $x . 'x' . $y;
    $image_file = USERBASE . '/f/skin_files/logo-' . $geometry . '.png';
    if (!file_exists($image_file) || filectime($image_file) < filectime($image_file_orig)) {
        CoreGraphics::resize($image_file_orig, $image_file, $x, $y);
    }
    $size = getimagesize($image_file);
    return '<img class="logo" src="/i/blank.gif" style="' . 'background:url(/f/skin_files/logo-' . $geometry . '.png) no-repeat;' . 'width:' . $size[0] . 'px;height:' . $size[1] . 'px;" />';
}
示例#5
0
 /**
  * resize an image
  *
  * @param string  $from      file to convert
  * @param string  $to        convert to what
  * @param int     $width     width to convert to
  * @param int     $height    height to convert to
  * @param boolean $keepratio keep image ratio, or force an exact resize
  *
  * @return null
  */
 static function resize($from, $to, $width, $height, $keepratio = true)
 {
     if (!file_exists($from) && @fopen($from, 'r') != true) {
         return false;
     }
     switch (@$GLOBALS['DBVARS']['graphics-method']) {
         case 'imagick':
             // {
             $thumb = new Imagick();
             $thumb->read($from);
             $thumb->setImageOpacity(1.0);
             $thumb->resizeImage($width, $height, Imagick::FILTER_LANCZOS, 1, true);
             $thumb->writeImage($to);
             $thumb->clear();
             $thumb->destroy();
             break;
             // }
         // }
         default:
             // { fallback to GD
             $extFrom = CoreGraphics::getType($from);
             switch (preg_replace('/.*\\./', '', $to)) {
                 case 'png':
                     // {
                     $extTo = 'png';
                     break;
                     // }
                 // }
                 default:
                     $extTo = 'jpeg';
             }
             $size = getimagesize($from);
             if ($size === false) {
                 return false;
             }
             $load = 'imagecreatefrom' . $extFrom;
             $save = 'image' . $extTo;
             if (!function_exists($load) || !function_exists($save)) {
                 return false;
             }
             if (strpos($from, '/') !== 0) {
                 // external image
                 $tmp = USERBASE . '/ww.cache/' . md5($from) . '.' . $extFrom;
                 if (!file_exists($tmp)) {
                     copy($from, $tmp);
                 }
                 $im = $load($tmp);
                 unlink($tmp);
             } else {
                 $im = $load($from);
             }
             if ($keepratio) {
                 $multx = $size[0] / $width;
                 $multy = $size[1] / $height;
                 if ($multx > $multy) {
                     $mult = $multx;
                 } else {
                     $mult = $multy;
                 }
                 $width = $size[0] / $mult;
                 $height = $size[1] / $mult;
             }
             $imresized = imagecreatetruecolor($width, $height);
             imagealphablending($imresized, false);
             imagecopyresampled($imresized, $im, 0, 0, 0, 0, $width, $height, $size[0], $size[1]);
             imagesavealpha($imresized, true);
             $save($imresized, $to, $extTo == 'jpeg' ? 100 : 9);
             imagedestroy($imresized);
             imagedestroy($im);
             // }
     }
     return true;
 }
示例#6
0
/**
 * retrieve an image
 *
 * @return null
 */
function Core_getImg()
{
    $w = isset($_REQUEST['w']) ? (int) $_REQUEST['w'] : 0;
    $h = isset($_REQUEST['h']) ? (int) $_REQUEST['h'] : 0;
    if (isset($_REQUEST['base64'])) {
        $f = base64_decode($_REQUEST['base64']);
        if (@fopen($f, 'r') != true) {
            header("HTTP/1.0 404 Not Found");
            echo 'file does not exist';
            Core_quit();
        }
    } else {
        $f = USERBASE . '/f/' . $_REQUEST['_remainder'];
        if (!file_exists($f)) {
            header("HTTP/1.0 404 Not Found");
            echo 'file does not exist';
            Core_quit();
        }
    }
    $ext = strtolower(preg_replace('/.*\\./', '', $f));
    switch ($ext) {
        case 'jpg':
        case 'jpe':
            // {
            $ext = 'jpeg';
            break;
            // }
        // }
        case 'png':
        case 'gif':
        case 'jpeg':
            // {
            break;
            // }
        // }
        default:
            // {
            echo 'unhandled image extension ' . $ext;
            Core_quit();
            // }
    }
    if (strpos($f, '/.') != false) {
        return false;
        // hack attempt
    }
    if ($w || $h) {
        list($width, $height) = getimagesize($f);
        $resize = 0;
        if ($w && $width > $w) {
            $height *= $w / $width;
            $width = $w;
            $resize = 1;
        }
        if ($h && $height > $h) {
            $width *= $h / $height;
            $height = $h;
            $resize = 1;
        }
        if ($resize) {
            $width = (int) $width;
            $height = (int) $height;
            @mkdir(USERBASE . '/ww.cache/resized.images');
            $c = USERBASE . '/ww.cache/resized.images/' . md5($f) . ',' . $width . 'x' . $height . '.png';
            if (!file_exists($c) || filesize($c) == 0) {
                CoreGraphics::resize($f, $c, $width, $height);
            }
            $f = $c;
            $ext = 'png';
        }
    }
    header('Content-type: image/' . $ext);
    header('Cache-Control: max-age=2592000, public');
    header('Expires-Active: On');
    header('Expires: Fri, 1 Jan 2500 01:01:01 GMT');
    header('Pragma:');
    header('Content-Length: ' . filesize($f));
    readfile($f);
    Core_quit();
}