/** * Constructor * * @access public * * Calls the parent constructor */ public function __construct() { parent::__construct(); if (defined('IMG_FILTER_PIXELATE') == FALSE) { $this->info['enabled'] = FALSE; } }
/** * Constructor * * @access public * * Calls the parent constructor */ public function __construct() { parent::__construct(); if (file_exists(PATH_THIRD . 'ce_img/pi.ce_img.php') != FALSE) { $this->info['enabled'] = TRUE; } }
/** * Constructor * * @access public * * Calls the parent constructor */ public function __construct() { parent::__construct(); if (class_exists('Imagick')) { $this->info['enabled'] = TRUE; } }
/** * Constructor * * @access public * * Calls the parent constructor */ public function __construct() { parent::__construct(); if (file_exists(PATH_THIRD . 'ce_img/pi.ce_img.php') != FALSE) { $this->info['enabled'] = TRUE; } if (defined('IMG_FILTER_PIXELATE') == FALSE) { $this->info['enabled'] = FALSE; } }
/** * Constructor * * @access public * * Calls the parent constructor */ public function __construct() { parent::__construct(); }
/** * Constructor * * @access public * * Calls the parent constructor */ public function __construct() { parent::__construct(); //if (function_exists('imagefilter') === false) $this->info['enabled'] = FALSE; }
function upload_file() { $this->EE->config->load('ci_config'); $this->EE->load->helper('url'); // ----------------------------------------- // EE 2.7 requires XID, flash based stuff breaks.. // ----------------------------------------- if ($this->EE->input->post('flash_upload') == 'yes') { if (version_compare(APP_VER, '2.7.0') >= 0) { $this->EE->security->restore_xid($this->EE->input->post('XID')); } } // ----------------------------------------- // Increase all types of limits! // ----------------------------------------- @set_time_limit(0); $conf = $this->EE->config->item('channel_images'); if (is_array($conf) === false) { $conf = array(); } if (isset($conf['infinite_memory']) === FALSE || $conf['infinite_memory'] == 'yes') { @ini_set('memory_limit', '64M'); @ini_set('memory_limit', '96M'); @ini_set('memory_limit', '128M'); @ini_set('memory_limit', '160M'); @ini_set('memory_limit', '192M'); @ini_set('memory_limit', '256M'); @ini_set('memory_limit', '320M'); @ini_set('memory_limit', '512M'); //@ini_set('memory_limit', -1); } error_reporting(E_ALL); @ini_set('display_errors', 1); $dbimage = FALSE; if ($this->EE->input->get_post('image_id') != FALSE) { $image_id = $this->EE->input->get_post('image_id'); $query = $this->EE->db->select('*')->from('exp_channel_images')->where('image_id', $image_id)->get(); if ($query->num_rows() == 0) { exit('IMAGE DOES NOT EXISTS'); } $dbimage = $query->row(); } // ----------------------------------------- // Standard Vars // ----------------------------------------- $o = array('success' => 'no', 'body' => ''); if ($dbimage == true) { $field_id = $dbimage->field_id; $key = time(); } else { $field_id = $this->EE->input->get_post('field_id'); $key = $this->EE->input->get_post('key'); } // ----------------------------------------- // Is our $_FILES empty? Commonly when EE does not like the mime-type // ----------------------------------------- if (isset($_FILES['channel_images_file']) == FALSE) { $o['body'] = $this->EE->lang->line('ci:file_arr_empty'); exit($this->EE->image_helper->generate_json($o)); } // ----------------------------------------- // Lets check for the key first // ----------------------------------------- if ($key == FALSE) { $o['body'] = $this->EE->lang->line('ci:tempkey_missing'); exit($this->EE->image_helper->generate_json($o)); } // ----------------------------------------- // Upload file too big (PHP.INI) // ----------------------------------------- if ($_FILES['channel_images_file']['error'] > 0) { $o['body'] = $this->EE->lang->line('ci:file_upload_error') . " ({$_FILES['channel_images_file']['error']})"; exit($this->EE->image_helper->generate_json($o)); } // ----------------------------------------- // Load Settings // ----------------------------------------- $settings = $this->EE->image_helper->grabFieldSettings($field_id); if (isset($settings['upload_location']) == FALSE) { $o['body'] = $this->EE->lang->line('ci:no_settings'); exit($this->EE->image_helper->generate_json($o)); } // ----------------------------------------- // Temp Dir to run Actions // ----------------------------------------- $temp_dir = $this->EE->channel_images->cache_path . 'channel_images/field_' . $field_id . '/' . $key . '/'; if (@is_dir($temp_dir) === FALSE) { @mkdir($temp_dir, 0777, true); @chmod($temp_dir, 0777); } // Last check, does the target dir exist, and is writable if (is_really_writable($temp_dir) !== TRUE) { $o['body'] = $this->EE->lang->line('ci:tempdir_error'); exit($this->EE->image_helper->generate_json($o)); } // ----------------------------------------- // File Name & Extension // ----------------------------------------- $original_filename = $_FILES['channel_images_file']['name']; //$original_filename = str_replace('@', '123atsign123', $original_filename); // Preserve the @ sign $original_filename = strtolower($this->EE->security->sanitize_filename($_FILES['channel_images_file']['name'])); $original_filename = str_replace(array(' ', '+', '%'), array('_', '', ''), $original_filename); //$original_filename = str_replace('123atsign123', '@', $original_filename); // Put it back! // Extension $extension = '.' . substr(strrchr($original_filename, '.'), 1); /* // Remove Accents and such if (function_exists('iconv') == TRUE) { try { $original_filename2 = @iconv("UTF-8", "ASCII//IGNORE//TRANSLIT", $original_filename); } catch (Exception $e) { $original_filename2 = $original_filename; } } else { $original_filename2 = $original_filename; } */ // The original file stays with the same name //$filename = $original_filename2;ß // ASCII Filename $filename = $this->ascii_string($original_filename); if (isset($conf['ascii_filename']) === TRUE && $conf['ascii_filename'] == 'no') { $filename = $original_filename; } // IOS6 ! if ($filename == 'image.jpg') { $filename = 'image_' . time() . '.jpg'; } // Replace Image? Lets overwrite! if ($dbimage == true) { $filename = $dbimage->filename; $extension = '.' . $dbimage->extension; } // Filesize $filesize = $_FILES['channel_images_file']['size']; // ----------------------------------------- // Filsize Limit? // ----------------------------------------- if (isset($settings['max_filesize']) === true && $settings['max_filesize'] != false) { if ($filesize > $settings['max_filesize'] * 1024) { $o['body'] = 'File size limit exceeded. (File: ' . (int) ($filesize / 1024) . 'KB - Max: ' . $settings['max_filesize'] . 'KB)'; exit($this->EE->image_helper->generate_json($o)); } } $filename_no_ext = str_replace($extension, '', $filename); // ----------------------------------------- // Unique Filenames! // ----------------------------------------- if (isset($_POST['filenames']) === true) { $_POST['filenames'] = explode('||', $_POST['filenames']); } if (isset($_POST['filenames']) === true && in_array($filename, $_POST['filenames']) === TRUE) { for ($i = 2; $i < 50; $i++) { if (in_array("{$filename_no_ext}-{$i}{$extension}", $_POST['filenames']) == false) { $filename = "{$filename_no_ext}-{$i}{$extension}"; break; } } } // ----------------------------------------- // Move File // ----------------------------------------- if (@move_uploaded_file($_FILES['channel_images_file']['tmp_name'], $temp_dir . $filename) === FALSE) { $o['body'] = $this->EE->lang->line('ci:file_move_error'); exit($this->EE->image_helper->generate_json($o)); } // Is it an image!? try { $test = getimagesize($temp_dir . $filename); if ($test == FALSE) { $o['body'] = 'Not an image'; exit($this->EE->image_helper->generate_json($o)); } } catch (Exception $e) { $o['body'] = 'Not an image'; exit($this->EE->image_helper->generate_json($o)); } // ----------------------------------------- // IPTC // ----------------------------------------- $iptc = array(); if ($settings['parse_iptc'] == 'yes') { getimagesize($temp_dir . $filename, $info); if (isset($info['APP13'])) { $iptc = iptcparse($info['APP13']); } //$this->EE->firephp->log($iptc); } // ----------------------------------------- // EXIF // ----------------------------------------- $exif = array(); if ($settings['parse_exif'] == 'yes') { if (function_exists('exif_read_data') === true) { $exif = @read_exif_data($temp_dir . $filename); //$this->EE->firephp->log($exif); } } // ----------------------------------------- // XMP // ----------------------------------------- $xmp = ''; if ($settings['parse_xmp'] == 'yes') { $xmp = $this->getXmpData($temp_dir . $filename, 102400); } // ----------------------------------------- // Convert to jpg? // ----------------------------------------- if (isset($settings['convert_jpg']) === TRUE && $settings['convert_jpg'] == 'yes' && ($extension == '.png' || $extension == '.gif')) { $original_path = $temp_dir . $filename; $filename = str_replace($extension, '.jpg', $filename); $extension = '.jpg'; if (class_exists('ImageAction') == FALSE) { include PATH_THIRD . 'channel_images/actions/imageaction.php'; } $class = new ImageAction(); $class->open_image($original_path); $class->save_image($temp_dir . $filename, false, 'jpg'); @unlink($original_path); } // ----------------------------------------- // Auto Rotate iPhone/Andriod pics (thanks to Stuart Barker) // ----------------------------------------- if (function_exists('exif_read_data') === true) { if (exif_imagetype($temp_dir . $filename) == IMAGETYPE_JPEG) { $this->adjustPicOrientation($temp_dir . $filename); } } // ----------------------------------------- // Load Actions :O // ----------------------------------------- $actions =& $this->EE->image_helper->get_actions(); // Just double check for actions groups if (isset($settings['action_groups']) == FALSE) { $settings['action_groups'] = array(); } // ----------------------------------------- // Loop over all action groups! // ----------------------------------------- foreach ($settings['action_groups'] as $group) { $size_name = $group['group_name']; $size_filename = str_replace($extension, "__{$size_name}{$extension}", $filename); // Make a copy of the file @copy($temp_dir . $filename, $temp_dir . $size_filename); @chmod($temp_dir . $size_filename, 0777); // ----------------------------------------- // Loop over all Actions and RUN! OMG! // ----------------------------------------- foreach ($group['actions'] as $action_name => $action_settings) { // RUN! $actions[$action_name]->settings = $action_settings; $actions[$action_name]->settings['field_settings'] = $settings; $res = $actions[$action_name]->run($temp_dir . $size_filename, $temp_dir); if ($res !== TRUE) { @unlink($temp_dir . $size_filename); $o['body'] = 'ACTION ERROR: ' . $res; exit($this->EE->image_helper->generate_json($o)); } } if (is_resource($this->EE->channel_images->image) == TRUE) { imagedestroy($this->EE->channel_images->image); } } // ----------------------------------------- // Keep Original Image? // ----------------------------------------- if (isset($settings['keep_original']) == TRUE && $settings['keep_original'] == 'no') { @unlink($temp_dir . $filename); } // ----------------------------------------- // Which Previews? // ----------------------------------------- if (empty($settings['action_groups']) == FALSE && (isset($settings['no_sizes']) == FALSE or $settings['no_sizes'] != 'yes')) { if (isset($settings['small_preview']) == FALSE or $settings['small_preview'] == FALSE) { $settings['small_preview'] = $settings['action_groups'][1]['group_name']; } if (isset($settings['big_preview']) == FALSE or $settings['big_preview'] == FALSE) { $settings['big_preview'] = $settings['action_groups'][1]['group_name']; } } else { // No sizes? Then lets make it be the the original one! $settings['small_preview'] = $filename; $settings['big_preview'] = $filename; } // Lets start our image array $image = array(); // Preview URL $preview_url = $this->EE->image_helper->get_router_url('url', 'simple_image_url'); // ----------------------------------------- // Generate Image URL's // ----------------------------------------- // Are we using the original file? if ($settings['small_preview'] == $filename) { $small_img_filename = $settings['small_preview']; $big_img_filename = $settings['small_preview']; } else { $small_img_filename = str_replace($extension, "__{$settings['small_preview']}{$extension}", urlencode($filename)); $big_img_filename = str_replace($extension, "__{$settings['big_preview']}{$extension}", urlencode($filename)); } // ----------------------------------------- // Output // ----------------------------------------- $image['success'] = 'yes'; $image['title'] = ucfirst(str_replace('_', ' ', str_replace($extension, '', $filename))); $image['url_title'] = url_title(trim(strtolower($image['title']))); $image['description'] = ''; $image['image_id'] = (string) 0; $image['category'] = ''; $image['cifield_1'] = ''; $image['cifield_2'] = ''; $image['cifield_3'] = ''; $image['cifield_4'] = ''; $image['cifield_5'] = ''; $image['filename'] = $filename; $image['filesize'] = (string) $filesize; $image['small_img_url'] = "{$preview_url}&f={$small_img_filename}&fid={$field_id}&d={$key}&temp_dir=yes"; $image['big_img_url'] = "{$preview_url}&f={$big_img_filename}&fid={$field_id}&d={$key}&temp_dir=yes"; // ----------------------------------------- // Parse output // ----------------------------------------- if (isset($settings['columns_default']) === true && is_array($settings['columns_default'])) { $vars = array(); $vars = $this->EE->channel_images_model->parseExif($vars, $exif); $vars = $this->EE->channel_images_model->parseXmp($vars, $xmp); $vars = $this->EE->channel_images_model->parseIptc($vars, $iptc); foreach ($vars as $k => $v) { unset($vars[$k]); $vars['{' . $k . '}'] = $v; } //$this->EE->firephp->log($vars); foreach ($settings['columns_default'] as $col => $val) { if ($col == 'desc') { $col = 'description'; } if ($col == 'row_num') { continue; } if ($col == 'id') { continue; } if ($col == 'image') { continue; } if ($col == 'filename') { continue; } if ($col == 'title' && $val == false) { continue; } $image[$col] = str_replace(array_keys($vars), array_values($vars), $val); } } // ----------------------------------------- // Finalize // ----------------------------------------- $image['iptc'] = base64_encode(serialize($iptc)); $image['exif'] = base64_encode(serialize($exif)); $image['xmp'] = base64_encode($xmp); if (isset($settings['default_category']) === TRUE && $settings['default_category'] != FALSE) { $image['category'] = $settings['default_category']; } if ($dbimage) { $this->replace_image($dbimage, $image, $settings, $temp_dir); } $out = trim($this->EE->image_helper->generate_json($image)); exit($out); }