Exemplo n.º 1
0
     $msg = $res ? _AM_NEWBB_PERMSET : _AM_NEWBB_PERMNOTSET;
     redirect_header('index.php', 2, $msg . ': ' . $path);
     exit;
     break;
 case "senddigest":
     $digest_handler =& xoops_getmodulehandler('digest', 'newbb');
     $res = $digest_handler->process(true);
     $msg = $res ? _AM_NEWBB_DIGEST_FAILED : _AM_NEWBB_DIGEST_SENT;
     redirect_header('index.php', 2, $msg);
     exit;
     break;
 case "default":
 default:
     xoops_cp_header();
     $xTheme->loadModuleAdminMenu(0, "Index");
     $imageLibs = newbb_getImageLibs();
     echo "<fieldset><legend style='font-weight: bold; color: #900;'>" . _AM_NEWBB_PREFERENCES . "</legend>";
     echo "<div style='padding: 12px;'>" . _AM_NEWBB_POLLMODULE . ": ";
     $module_handler =& xoops_gethandler('module');
     $xoopspoll =& $module_handler->getByDirname('xoopspoll');
     if (is_object($xoopspoll)) {
         $isOK = $xoopspoll->getVar('isactive');
     } else {
         $isOK = false;
     }
     echo $isOK ? _AM_NEWBB_AVAILABLE : _AM_NEWBB_NOTAVAILABLE;
     echo "</div>";
     echo "<div style='padding: 8px;'>";
     echo "<a href='http://www.imagemagick.org' target='_blank'>" . _AM_NEWBB_IMAGEMAGICK . "&nbsp;</a>";
     if (array_key_exists('imagemagick', $imageLibs)) {
         echo "<strong><font color='green'>" . _AM_NEWBB_AUTODETECTED . $imageLibs['imagemagick'] . "</font></strong>";
Exemplo n.º 2
0
function newbb_createThumbnail($source, $thumb_width)
{
    global $xoopsModuleConfig;
    $img_path = XOOPS_ROOT_PATH . '/' . $xoopsModuleConfig['dir_attachments'];
    $thumb_path = $img_path . '/thumbs';
    $src_file = $img_path . '/' . $source;
    $new_file = $thumb_path . '/' . $source;
    $imageLibs = newbb_getImageLibs();
    if (!filesize($src_file) || !is_readable($src_file)) {
        return false;
    }
    if (!is_dir($thumb_path) || !is_writable($thumb_path)) {
        return false;
    }
    $imginfo = @getimagesize($src_file);
    if (NULL == $imginfo) {
        return false;
    }
    if ($imginfo[0] < $thumb_width) {
        return false;
    }
    $newWidth = (int) min($imginfo[0], $thumb_width);
    $newHeight = (int) ($imginfo[1] * $newWidth / $imginfo[0]);
    if ($xoopsModuleConfig['image_lib'] == 1 or $xoopsModuleConfig['image_lib'] == 0) {
        if (preg_match("#[A-Z]:|\\\\#Ai", __FILE__)) {
            $cur_dir = dirname(__FILE__);
            $src_file_im = '"' . $cur_dir . '\\' . strtr($src_file, '/', '\\') . '"';
            $new_file_im = '"' . $cur_dir . '\\' . strtr($new_file, '/', '\\') . '"';
        } else {
            $src_file_im = @escapeshellarg($src_file);
            $new_file_im = @escapeshellarg($new_file);
        }
        $path = empty($xoopsModuleConfig['path_magick']) ? "" : $xoopsModuleConfig['path_magick'] . "/";
        $magick_command = $path . 'convert -quality 85 -antialias -sample ' . $newWidth . 'x' . $newHeight . ' ' . $src_file_im . ' +profile "*" ' . str_replace('\\', '/', $new_file_im) . '';
        @passthru($magick_command);
        if (file_exists($new_file)) {
            return true;
        }
    }
    if ($xoopsModuleConfig['image_lib'] == 2 or $xoopsModuleConfig['image_lib'] == 0) {
        $path = empty($xoopsModuleConfig['path_netpbm']) ? "" : $xoopsModuleConfig['path_netpbm'] . "/";
        if (eregi("\\.png", $source)) {
            $cmd = $path . "pngtopnm {$src_file} | " . $path . "pnmscale -xysize {$newWidth} {$newHeight} | " . $path . "pnmtopng > {$new_file}";
        } else {
            if (eregi("\\.(jpg|jpeg)", $source)) {
                $cmd = $path . "jpegtopnm {$src_file} | " . $path . "pnmscale -xysize {$newWidth} {$newHeight} | " . $path . "ppmtojpeg -quality=90 > {$new_file}";
            } else {
                if (eregi("\\.gif", $source)) {
                    $cmd = $path . "giftopnm {$src_file} | " . $path . "pnmscale -xysize {$newWidth} {$newHeight} | ppmquant 256 | " . $path . "ppmtogif > {$new_file}";
                }
            }
        }
        @exec($cmd, $output, $retval);
        if (file_exists($new_file)) {
            return true;
        }
    }
    $type = $imginfo[2];
    $supported_types = array();
    if (!extension_loaded('gd')) {
        return false;
    }
    if (function_exists('imagegif')) {
        $supported_types[] = 1;
    }
    if (function_exists('imagejpeg')) {
        $supported_types[] = 2;
    }
    if (function_exists('imagepng')) {
        $supported_types[] = 3;
    }
    $imageCreateFunction = function_exists('imagecreatetruecolor') ? "imagecreatetruecolor" : "imagecreate";
    if (in_array($type, $supported_types)) {
        switch ($type) {
            case 1:
                if (!function_exists('imagecreatefromgif')) {
                    return false;
                }
                $im = imagecreatefromgif($src_file);
                $new_im = imagecreate($newWidth, $newHeight);
                imagecopyresized($new_im, $im, 0, 0, 0, 0, $newWidth, $newHeight, $imginfo[0], $imginfo[1]);
                imagegif($new_im, $new_file);
                imagedestroy($im);
                imagedestroy($new_im);
                break;
            case 2:
                $im = imagecreatefromjpeg($src_file);
                $new_im = $imageCreateFunction($newWidth, $newHeight);
                imagecopyresized($new_im, $im, 0, 0, 0, 0, $newWidth, $newHeight, $imginfo[0], $imginfo[1]);
                imagejpeg($new_im, $new_file, 90);
                imagedestroy($im);
                imagedestroy($new_im);
                break;
            case 3:
                $im = imagecreatefrompng($src_file);
                $new_im = $imageCreateFunction($newWidth, $newHeight);
                imagecopyresized($new_im, $im, 0, 0, 0, 0, $newWidth, $newHeight, $imginfo[0], $imginfo[1]);
                imagepng($new_im, $new_file);
                imagedestroy($im);
                imagedestroy($new_im);
                break;
        }
    }
    if (file_exists($new_file)) {
        return true;
    } else {
        return false;
    }
}