예제 #1
0
 public function edit_image_save()
 {
     @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');
     }
     error_reporting(E_ALL);
     @ini_set('display_errors', 1);
     // -----------------------------------------
     // Vars
     // -----------------------------------------
     $key = $this->EE->input->post('key');
     $akey = $key + 1;
     $filename = $this->EE->input->post('filename');
     $image_id = $this->EE->input->post('image_id');
     $field_id = $this->EE->input->post('field_id');
     $entry_id = $this->EE->input->post('entry_id');
     $regen_sizes = $this->EE->input->post('regen_sizes');
     $size = $this->EE->input->post('size');
     if ($image_id > 0) {
         $query = $this->EE->db->select('*')->from('exp_channel_images')->where('image_id', $image_id)->get();
         if ($query->row('link_image_id') > 0) {
             $field_id = $query->row('link_field_id');
             $entry_id = $query->row('link_entry_id');
         }
         //----------------------------------------
         // Size Metadata!
         //----------------------------------------
         $metadata = array();
         if ($query->row('sizes_metadata') != FALSE) {
             $temp = explode('/', $query->row('sizes_metadata'));
             foreach ($temp as $row) {
                 if ($row == FALSE) {
                     continue;
                 }
                 $temp2 = explode('|', $row);
                 // In some installs size is not set.
                 if (isset($temp2[3]) === FALSE or $temp2[3] == FALSE) {
                     $temp2[3] = 0;
                 }
                 if (isset($temp2[2]) === FALSE or $temp2[2] == FALSE) {
                     $temp2[2] = 0;
                 }
                 if (isset($temp2[1]) === FALSE or $temp2[1] == FALSE) {
                     $temp2[1] = 0;
                 }
                 $metadata[$temp2[0]] = array('width' => $temp2[1], 'height' => $temp2[2], 'size' => $temp2[3]);
             }
         }
     }
     // Extension
     $extension = '.' . substr(strrchr($filename, '.'), 1);
     // Grab Fields Settings
     if ($field_id == false) {
         exit('Missing Field_ID');
     }
     $settings = $this->EE->image_helper->grabFieldSettings($field_id);
     // -----------------------------------------
     // Load Location
     // -----------------------------------------
     $location_type = $settings['upload_location'];
     $location_class = 'CI_Location_' . $location_type;
     // Load Settings
     if (isset($settings['locations'][$location_type]) == FALSE) {
         $o['body'] = $this->EE->lang->line('ci:location_settings_failure');
         exit($this->EE->image_helper->generate_json($o));
     }
     $location_settings = $settings['locations'][$location_type];
     // Load Main Class
     if (class_exists('Image_Location') == FALSE) {
         require PATH_THIRD . 'channel_images/locations/image_location.php';
     }
     // Try to load Location Class
     if (class_exists($location_class) == FALSE) {
         $location_file = PATH_THIRD . 'channel_images/locations/' . $location_type . '/' . $location_type . '.php';
         if (file_exists($location_file) == FALSE) {
             $o['body'] = $this->EE->lang->line('ci:location_load_failure');
             exit($this->EE->image_helper->generate_json($o));
         }
         require $location_file;
     }
     // Init
     $LOC = new $location_class($location_settings);
     $temp_dir = $this->EE->channel_images->cache_path . 'channel_images/field_' . $field_id . '/' . $akey . '/';
     // Remove the other images
     @unlink($temp_dir . 'SCALED_' . $filename);
     @unlink($temp_dir . 'BW_' . $filename);
     @unlink($temp_dir . 'BW_SCALED_' . $filename);
     // Load the API
     if (class_exists('Channel_Images_API') != TRUE) {
         include 'api.channel_images.php';
     }
     $API = new Channel_Images_API();
     // -----------------------------------------
     // Regenerate All sizes?
     // -----------------------------------------
     if ($size == 'ORIGINAL' && $regen_sizes == 'yes') {
         $API->run_actions($filename, $field_id, $temp_dir);
     }
     if ($size != 'ORIGINAL') {
         if (isset($this->EE->channel_images->actions) === FALSE) {
             $this->EE->channel_images->actions = $this->EE->image_helper->get_actions();
         }
         foreach ($settings['action_groups'] as $group) {
             $size_name = $group['group_name'];
             if ($size_name != $size) {
                 continue;
             }
             $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!
                 $this->EE->channel_images->actions[$action_name]->settings = $action_settings;
                 $this->EE->channel_images->actions[$action_name]->settings['field_settings'] = $settings;
                 $res = $this->EE->channel_images->actions[$action_name]->run($temp_dir . $size_filename, $temp_dir);
                 if ($res !== TRUE) {
                     @unlink($temp_dir . $size_filename);
                     return FALSE;
                 }
             }
             if (is_resource($this->EE->channel_images->image) == TRUE) {
                 imagedestroy($this->EE->channel_images->image);
             }
             if ($image_id > 0) {
                 // Parse Image Size
                 $imginfo = @getimagesize($temp_dir . $size_filename);
                 $filesize = @filesize($temp_dir . $size_filename);
                 $metadata[strtolower($size_name)] = array('width' => @$imginfo[0], 'height' => @$imginfo[1], 'size' => $filesize);
             }
             // Remove the original image
             @unlink($temp_dir . $filename);
         }
     }
     if ($image_id > 0) {
         $API->upload_images($entry_id, $field_id, $temp_dir);
     } else {
         // Loop over all files
         $tempfiles = @scandir($temp_dir);
         if (is_array($tempfiles) == TRUE) {
             foreach ($tempfiles as $tempfile) {
                 if ($tempfile == '.' or $tempfile == '..') {
                     continue;
                 }
                 $file = $temp_dir . '/' . $tempfile;
                 //$res = $LOC->upload_file($file, $tempfile, $entry_id);
                 copy($file, $this->EE->channel_images->cache_path . 'channel_images/field_' . $field_id . '/' . $key . '/' . $tempfile);
                 @unlink($file);
             }
         }
         @rmdir($temp_dir);
     }
     if ($image_id > 0) {
         // -----------------------------------------
         // Parse Size Metadata!
         // -----------------------------------------
         $mt = '';
         foreach ($settings['action_groups'] as $group) {
             $name = strtolower($group['group_name']);
             // sometimes it's just not found, odd
             if (isset($metadata[$name]) === false) {
                 continue;
             }
             $mt .= $name . '|' . implode('|', $metadata[$name]) . '/';
         }
         // -----------------------------------------
         // Update Image
         // -----------------------------------------
         $this->EE->db->set('sizes_metadata', $mt);
         $this->EE->db->where('image_id', $image_id);
         $this->EE->db->update('exp_channel_images');
     }
     @unlink($temp_dir . $filename);
     exit;
 }
예제 #2
0
 public function editor_before_replace($obj, $data)
 {
     // Check if we're not the only one using this hook
     if ($this->EE->extensions->last_call !== false) {
         $data = $this->EE->extensions->last_call;
     }
     if (class_exists('Channel_Images_API') === false) {
         require PATH_THIRD . 'channel_images/api.channel_images.php';
     }
     $API = new Channel_Images_API();
     $entry_id = 0;
     if (isset($obj->row['entry_id']) === true) {
         $entry_id = $obj->row['entry_id'];
     }
     $data = $API->generateUrlsFromTags($data, $entry_id, true);
     return $data;
 }