Esempio n. 1
0
 /**
  * Replace css resized images with resized copies of the original
  * ckeditor uses style height/width
  *
  */
 public static function ResizeImages(&$html_content, &$img_list)
 {
     includeFile('image.php');
     \gp_resized::SetIndex();
     $orig_list = array();
     if (is_array($img_list)) {
         $orig_list = $img_list;
     }
     $img_list = array();
     //resize images
     $gp_html_output = new \gp\tool\Editing\HTML($html_content);
     foreach ($gp_html_output->dom_array as $key => $node) {
         if (!is_array($node) || !array_key_exists('tag', $node)) {
             continue;
         }
         $tag = $node['tag'];
         if ($tag != 'img' || !isset($node['attributes']['src'])) {
             continue;
         }
         $resized_data = self::ResizedImage($node['attributes']);
         if ($resized_data !== false) {
             $img = $resized_data['img'];
             $index = $resized_data['index'];
             $resized_src = \gp\tool::GetDir('/include/image.php', true) . '?i=' . $index . '&w=' . $resized_data['w'] . '&h=' . $resized_data['h'] . '&img=' . rawurlencode($img);
             $gp_html_output->dom_array[$key]['attributes']['src'] = $resized_src;
             $img_list[$index][] = $resized_data['w'] . 'x' . $resized_data['h'];
             $img_list[$index] = array_unique($img_list[$index]);
             \gp_resized::$index[$index] = $img;
         }
     }
     $gp_html_output->Rebuild();
     $html_content = $gp_html_output->result;
     self::ResizedImageUse($orig_list, $img_list);
     \gp_resized::SaveIndex();
 }
Esempio n. 2
0
 /**
  * Get the content of the file in the trash so we can restore file information
  *  - resized images
  *  - \gp\special\Galleries::UpdateGalleryInfo($title,$content)
  *
  */
 public static function RestoreFile($title, $file, $title_info)
 {
     $file_sections = \gp\tool\Files::Get($file, 'file_sections');
     // Restore resized images
     if (count($file_sections)) {
         includeFile('image.php');
         \gp_resized::SetIndex();
         foreach ($file_sections as $section => $section_data) {
             if (!isset($section_data['resized_imgs'])) {
                 continue;
             }
             foreach ($section_data['resized_imgs'] as $image_index => $sizes) {
                 if (!isset(\gp_resized::$index[$image_index])) {
                     continue;
                 }
                 $img = \gp_resized::$index[$image_index];
                 foreach ($sizes as $size) {
                     list($width, $height) = explode('x', $size);
                     \gp\tool\Editing::CreateImage($img, $width, $height);
                 }
             }
             \gp\tool\Editing::ResizedImageUse(array(), $section_data['resized_imgs']);
         }
         \gp_resized::SaveIndex();
     }
     // Restore Galleries
     if (strpos($title_info['type'], 'gallery') !== false) {
         \gp\special\Galleries::UpdateGalleryInfo($title, $file_sections);
     }
 }
Esempio n. 3
0
 /**
  * Get the content of the file in the trash so we can restore file information
  *  - resized images
  *  - special_galleries::UpdateGalleryInfo($title,$content)
  *
  */
 function RestoreFile($title, $file, $title_info)
 {
     //get the file data
     $file_sections = array();
     ob_start();
     include $file;
     ob_get_clean();
     // Restore resized images
     if (count($file_sections)) {
         includeFile('image.php');
         gp_resized::SetIndex();
         foreach ($file_sections as $section => $section_data) {
             if (!isset($section_data['resized_imgs'])) {
                 continue;
             }
             foreach ($section_data['resized_imgs'] as $image_index => $sizes) {
                 if (!isset(gp_resized::$index[$image_index])) {
                     continue;
                 }
                 $img = gp_resized::$index[$image_index];
                 foreach ($sizes as $size) {
                     list($width, $height) = explode('x', $size);
                     gp_edit::CreateImage($img, $width, $height);
                 }
             }
             gp_edit::ResizedImageUse(array(), $section_data['resized_imgs']);
         }
         gp_resized::SaveIndex();
     }
     // Restore Galleries
     if (strpos($title_info['type'], 'gallery') !== false) {
         includeFile('special/special_galleries.php');
         special_galleries::UpdateGalleryInfo($title, $file_sections);
     }
 }
Esempio n. 4
0
 /**
  *  Performs actions after changes are made to files in elFinder
  *
  */
 static function FinderChange($cmd, $result, $args, $elfinder)
 {
     global $dataDir, $config;
     includeFile('image.php');
     gp_resized::SetIndex();
     $base_dir = $dataDir . '/data/_uploaded';
     $thumb_dir = $dataDir . '/data/_uploaded/image/thumbnails';
     admin_uploaded::SetRealPath($result, $elfinder);
     switch ($cmd) {
         case 'rename':
             admin_uploaded::RenameResized($result['removed'][0], $result['added'][0]);
             break;
         case 'rm':
             admin_uploaded::RemoveResized($result['removed']);
             break;
         case 'paste':
             admin_uploaded::MoveResized($result['removed'], $result['added']);
             break;
             //check the image size
         //check the image size
         case 'upload':
             admin_uploaded::MaxSize($result['added']);
             break;
     }
     //removed files first
     //	- Remove associated thumbnail
     if (isset($result['removed']) && count($result['removed']) > 0) {
         foreach ($result['removed'] as $removed) {
             $removed_path = $removed['realpath'];
             $thumb_path = str_replace($base_dir, $thumb_dir, $removed_path) . '.jpg';
             if (file_exists($thumb_path)) {
                 unlink($thumb_path);
             }
         }
     }
     //addded files
     if (isset($result['added']) && count($result['added']) > 0) {
         foreach ($result['added'] as $added) {
             $added_path = $added['realpath'];
             $thumb_path = str_replace($base_dir, $thumb_dir, $added_path) . '.jpg';
             gpFiles::CheckDir($thumb_dir);
             thumbnail::createSquare($added_path, $thumb_path, $config['maxthumbsize']);
             gpPlugin::Action('FileUploaded', $added_path);
         }
     }
     //changed files (resized)
     if (isset($result['changed']) && count($result['changed']) > 0) {
         foreach ($result['changed'] as $changed) {
             $changed_path = $changed['realpath'];
             $thumb_path = str_replace($base_dir, $thumb_dir, $changed_path) . '.jpg';
             gpFiles::CheckDir($thumb_dir);
             thumbnail::createSquare($changed_path, $thumb_path, $config['maxthumbsize']);
         }
     }
     gp_resized::SaveIndex();
     //debug
     /*
     $log_file = $dataDir.'/data/_temp/finder_log-all_vars.txt';
     $data = get_defined_vars();
     $content = print_r($data,true);
     gpFiles::Save($log_file,$content);
     */
 }
Esempio n. 5
0
 /**
  *  Performs actions after changes are made to files in finder
  *
  */
 static function FinderChange($cmd, $result, $args, $finder)
 {
     global $dataDir, $config;
     includeFile('image.php');
     gp_resized::SetIndex();
     $base_dir = $dataDir . '/data/_uploaded';
     $thumb_dir = $dataDir . '/data/_uploaded/image/thumbnails';
     admin_uploaded::SetRealPath($result, $finder);
     switch ($cmd) {
         case 'rename':
             admin_uploaded::RenameResized($result['removed'][0], $result['added'][0]);
             break;
         case 'rm':
             admin_uploaded::RemoveResized($result['removed']);
             break;
         case 'paste':
             admin_uploaded::MoveResized($result['removed'], $result['added']);
             break;
             //check the image size
         //check the image size
         case 'upload':
             admin_uploaded::MaxSize($result['added']);
             break;
     }
     //removed files first
     //	- Remove associated thumbnail
     if (isset($result['removed']) && count($result['removed']) > 0) {
         foreach ($result['removed'] as $removed) {
             $removed_path = $removed['realpath'];
             gpPlugin::Action('FileDeleted', $removed_path);
             $thumb_path = str_replace($base_dir, $thumb_dir, $removed_path);
             if (file_exists($thumb_path)) {
                 if (is_dir($thumb_path)) {
                     gpFiles::RmAll($thumb_path);
                 } else {
                     unlink($thumb_path);
                 }
                 continue;
             }
             $thumb_path = str_replace($base_dir, $thumb_dir, $removed_path) . '.jpg';
             if (file_exists($thumb_path)) {
                 unlink($thumb_path);
             }
         }
     }
     //addded files
     if (isset($result['added']) && count($result['added']) > 0) {
         foreach ($result['added'] as $added) {
             gpPlugin::Action('FileUploaded', $added['realpath']);
             self::CreateThumbnail($added['realpath']);
         }
     }
     //changed files (resized)
     if (isset($result['changed']) && count($result['changed']) > 0) {
         foreach ($result['changed'] as $changed) {
             gpPlugin::Action('FileChanged', $changed['realpath']);
             self::CreateThumbnail($changed['realpath']);
         }
     }
     gp_resized::SaveIndex();
     //debug
     /*
     $log_file = $dataDir.'/data/_temp/finder_log-'.time().'.txt';
     $data = get_defined_vars();
     $content = print_r($data,true).'<hr/>';
     $fp = fopen($log_file,'a');
     fwrite($fp,$content);
     */
 }