Exemple #1
0
 function attachmentElement($var, $label, $value_file, $value_text, $options)
 {
     global $config;
     $default_options = array('style' => false, 'help' => false, 'class' => false, 'module_id' => false);
     $options = array_merge($default_options, $options);
     $id = $this->html_id . '_' . $var;
     $html = '<div class="attachment-element">';
     $html .= '<p class="attachment-element-label">' . escape($label) . '</p>';
     $html .= '<p class="attachment-element-file"><input id="is_' . $id . '" type="checkbox" name="is_' . $var . '" ' . @($value_file != '' ? 'checked' : '') . ' onchange="$(\'#' . $id . '_preview\').toggle($(\'#is_' . $id . '\').attr(\'checked\'))" /> ';
     $html .= '<input id="' . $id . '_file" class="file" type="file" name="' . $var . '" onchange="if($(\'#' . $id . '_file\').val()!=\'\') { $(\'#is_' . $id . '\').attr(\'checked\',true); $(\'#' . $id . '_preview\').remove() }" /></p>';
     $html .= '<p class="attachment-element-text"><input id="' . $id . '_text" class="string" type="text" name="' . $var . '_text" value="' . escape($value_text) . '" /></p>';
     if ($options['module_id'] != false && $value_file != '') {
         list($file_id, $file_ext) = explode('.', $value_file);
         $html .= '<p class="attachment-element-preview">';
         $url = $config[$options['module_id']]['upload_url'] . $value_file;
         if (is_file_type('image', $value_file)) {
             $path_image_list = image_cache_get($options['module_id'], $file_id, 'list_tiny');
             if ($path_image_list !== false) {
                 $html .= '<a href="' . $url . '"><img id="' . $id . '_preview" src="' . $path_image_list . '" /></a>';
             }
         } else {
             $path = $config[$options['module_id']]['upload_path'] . $value_file;
             $title = $value_text != '' ? $value_text : 'Документ';
             $stat = file_extension($path) . ', ' . str_format_human_file_size(filesize($path));
             $html .= '<a href="' . $url . '">' . escape($title) . '</a> (' . $stat . ')';
         }
         $html .= '</p>';
     }
     $html .= '</div>';
     return $html;
 }
function image_cache_get($module_name, $file_id, $format_name)
{
    global $config;
    $upload_path = $config[$module_name]['upload_path'];
    $upload_url = $config[$module_name]['upload_url'];
    // jpg или png
    $format = isset($config['image_cache'][$format_name]['format']) ? $config['image_cache'][$format_name]['format'] : 'jpg';
    $cache_file_path = $upload_path . 'cache/' . $format_name . '/' . $file_id . '.' . $format;
    if (file_exists($cache_file_path)) {
        $filemtime = filemtime($cache_file_path);
        if (!isset($config['image_cache'][$format_name]['update_before']) || $config['image_cache'][$format_name]['update_before'] < $filemtime) {
            return $upload_url . 'cache/' . $format_name . '/' . $file_id . '.' . $filemtime . '.' . $format;
        }
    }
    $extension = '';
    foreach (array('jpg', 'gif', 'png', 'bmp') as $temp) {
        if (file_exists($upload_path . $file_id . '.' . $temp)) {
            $extension = $temp;
            break;
        }
    }
    $source_file_path = $upload_path . $file_id . '.' . $extension;
    if (!$extension) {
        //		user_error('image_cache_get() source file not exists "'.$source_file_path.'"', E_USER_WARNING);
        return false;
    }
    if (!is_file_type('image', $source_file_path)) {
        user_error('image_cache_get() source file is not image ' . $source_file_path, E_USER_WARNING);
        return false;
    }
    if (!isset($config['image_cache'][$format_name])) {
        user_error('image_cache_get() format not exists "' . $format_name . '"', E_USER_WARNING);
        return false;
    }
    if (!file_exists($upload_path . 'cache/')) {
        mkdir($upload_path . 'cache/');
    }
    if (!file_exists($upload_path . 'cache/' . $format_name . '/')) {
        mkdir($upload_path . 'cache/' . $format_name . '/');
    }
    ini_set('memory_limit', '1024M');
    $parts = @getimagesize($source_file_path);
    // если фотография слишком большая пропускаем создание превью
    if ($parts[0] > 6000 || $parts[1] > 6000) {
        return false;
    }
    switch ($parts['mime']) {
        case 'image/jpeg':
            $image = imageCreateFromJPEG($source_file_path);
            break;
        case 'image/png':
            $image = imageCreateFromPNG($source_file_path);
            break;
        case 'image/gif':
            $image = imageCreateFromGIF($source_file_path);
            break;
            /*		
            		case 'image/bmp':
            		case 'image/x-ms-bmp':
            			$image = imageCreateFromBMP($source_file_path); break; 
            */
        /*		
        		case 'image/bmp':
        		case 'image/x-ms-bmp':
        			$image = imageCreateFromBMP($source_file_path); break; 
        */
        default:
            // user_error('image_cache_get() non supported mime "'.$parts['mime'].'" - "'.$source_file_path.'"', E_USER_WARNING);
            return false;
    }
    $is_alfa = $format == 'png' ? true : false;
    foreach ($config['image_cache'][$format_name] as $action => $params) {
        switch ($action) {
            case 'resize_crop':
                image_cache_resize_crop($image, $params['width'], $params['height']);
                break;
            case 'resize_fit_height':
                image_cache_resize_fit_height($image, $params['height']);
                break;
            case 'resize_fit':
                image_cache_resize_fit($image, $params['width'], $params['height']);
                break;
            case 'resize_fit_max':
                image_cache_resize_fit_max($image, $params['width'], $params['height'], $is_alfa);
                break;
            case 'unsharp_mask':
                image_cache_unsharp_mask($image);
                break;
            case 'hd_sharpen':
                image_cache_hd_sharpen($image);
                break;
            case 'watermark':
                image_cache_watermark($image, $params['path'], $params['random_shift']);
                break;
            case 'quality':
                $quality = $params;
        }
    }
    if ($format == 'png') {
        imagePNG($image, $cache_file_path);
    } else {
        imageJPEG($image, $cache_file_path, JPEG_QUALITY);
    }
    imageDestroy($image);
    $filemtime = filemtime($cache_file_path);
    $new_image_path = $upload_path . 'cache/' . $format_name . '/' . $file_id . '.' . $format;
    return $upload_url . 'cache/' . $format_name . '/' . $file_id . '.' . $filemtime . '.' . $format;
}
Exemple #3
0
function delete_file_ftp($host, $name, $pass, $upload_path, $file_name)
{
    $path = $upload_path . $file_name;
    if (file_exists($path) && is_file($path) && is_writable($path)) {
        $conn_id = ftp_connect($host);
        $login_result = ftp_login($conn_id, $name, $pass);
        ftp_pasv($conn_id, true);
        if (is_file_type('image', $file_name)) {
            image_cache_clear($upload_path, $file_name);
        }
        ftp_delete($conn_id, $path);
        ftp_quit($conn_id);
        unlink($path);
    }
}