Exemple #1
0
    error(__('You are not allowed to do this action', 'rmcommon'));
}
if (!$xoopsUser) {
    error(__('You are not allowed to do this action', 'rmcommon'));
}
if ($category <= 0) {
    error(__('Sorry, category has not been specified!', 'rmcommon'));
}
$cat = new RMImageCategory($category);
if ($cat->isNew()) {
    error(__('Sorry, the specified category has not been found!', 'rmcommon'));
}
if ($cat->getVar('status') != 'open') {
    error(__('Sorry, the specified category is closed!', 'rmcommon'));
}
if (!$cat->user_allowed_toupload($xoopsUser)) {
    error(__('Sorry, you can not upload images!', 'rmcommon'));
}
// Cargamos la imágen
$updir = XOOPS_UPLOAD_PATH . '/' . date('Y', time());
if (!file_exists($updir)) {
    mkdir($updir);
    chmod($updir, octdec('0777'));
}
$updir .= '/' . date('m', time());
if (!file_exists($updir)) {
    mkdir($updir);
    chmod($updir, octdec('0777'));
}
if (!file_exists($updir . '/sizes')) {
    mkdir($updir . '/sizes');
Exemple #2
0
function resize_images()
{
    global $xoopsUser, $xoopsLogger, $xoopsSecurity;
    set_time_limit(0);
    error_reporting(0);
    $xoopsLogger->activated = false;
    $params = rmc_server_var($_GET, 'data', '');
    $id = rmc_server_var($_GET, 'img', 0);
    if ($params == '') {
        send_error(__('Unauthorized!', 'rmcommon'));
    }
    if ($id <= 0) {
        send_error(__('Invalid image!', 'rmcommon'));
    }
    $params = TextCleaner::decrypt($params);
    $data = explode('|', $params);
    if ($data[0] != $xoopsUser->uid()) {
        send_error(__('Unauthorized!', 'rmcommon'));
    }
    if ($data[1] != RMCURL . '/images.php') {
        send_error(__('Unauthorized!', 'rmcommon'));
    }
    if (!$xoopsSecurity->check(false, $data[2])) {
        send_error(__('Unauthorized!', 'rmcommon'));
    }
    $image = new RMImage($id);
    if ($image->isNew()) {
        send_error(__('Image not found!', 'rmcommon'));
    }
    // Resize image
    $cat = new RMImageCategory($image->getVar('cat'));
    if (!$cat->user_allowed_toupload($xoopsUser)) {
        send_error(__('Unauthorized', 'rmcommon'));
    }
    $sizes = $cat->getVar('sizes');
    $updir = XOOPS_UPLOAD_PATH . '/' . date('Y', $image->getVar('date')) . '/' . date('m', time());
    $upurl = XOOPS_UPLOAD_URL . '/' . date('Y', $image->getVar('date')) . '/' . date('m', time());
    $width = 0;
    $tfile = '';
    foreach ($sizes as $size) {
        if ($size['width'] <= 0 && $size['height'] <= 0) {
            continue;
        }
        $fd = pathinfo($updir . '/' . $image->getVar('file'));
        $name = $updir . '/sizes/' . $fd['filename'] . '_' . $size['width'] . 'x' . $size['height'] . '.' . $fd['extension'];
        $sizer = new RMImageResizer($updir . '/' . $image->getVar('file'), $name);
        switch ($size['type']) {
            case 'crop':
                $sizer->resizeAndCrop($size['width'], $size['height']);
                break;
            default:
                if ($size['width'] <= 0 || $size['height'] <= 0) {
                    $sizer->resizeWidth($size['width']);
                } else {
                    $sizer->resizeWidthOrHeight($size['width'], $size['height']);
                }
                break;
        }
        if ($size['width'] <= $width || $width == 0) {
            $width = $size['width'];
            $tfile = str_replace(XOOPS_UPLOAD_PATH, XOOPS_UPLOAD_URL, $name);
        }
    }
    $ret['message'] = sprintf(__('%s done!', 'rmcommon'), $image->getVar('file'));
    $ret['done'] = 1;
    $ret['file'] = $tfile;
    $ret['title'] = $image->getVar('title');
    echo json_encode($ret);
    die;
}