예제 #1
0
 /**
  * Return the folder path used for resized images of $img
  *
  */
 static function Folder($img)
 {
     global $dataDir;
     $name = basename($img);
     return $dataDir . '/data/_resized' . common::DirName($img) . '/' . gp_resized::EncodePath($name);
 }
예제 #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);
     }
 }
예제 #3
0
 /**
  * Save new/rearranged sections
  *
  */
 function SaveSections()
 {
     global $page, $langmessage;
     $page->ajaxReplace = array();
     $original_sections = $this->file_sections;
     $unused_sections = $this->file_sections;
     //keep track of sections that aren't used
     $new_sections = array();
     $section_types = section_content::GetTypes();
     foreach ($_POST['section_order'] as $i => $arg) {
         // moved / copied sections
         if (ctype_digit($arg)) {
             $arg = (int) $arg;
             if (!isset($this->file_sections[$arg])) {
                 message($langmessage['OOPS'] . ' (Invalid Section Number)');
                 return false;
             }
             unset($unused_sections[$arg]);
             $new_section = $this->file_sections[$arg];
             $new_section['attributes'] = array();
             // otherwise, new sections
         } else {
             if (!isset($section_types[$arg])) {
                 message($langmessage['OOPS'] . ' (Unknown Type: ' . $arg . ')');
                 return false;
             }
             $new_section = gp_edit::DefaultContent($arg);
         }
         // attributes
         if (isset($_POST['attributes'][$i]) && is_array($_POST['attributes'][$i])) {
             foreach ($_POST['attributes'][$i] as $attr_name => $attr_value) {
                 $attr_name = strtolower($attr_name);
                 $attr_name = trim($attr_name);
                 $attr_value = trim($attr_value);
                 if (empty($attr_name) || empty($attr_value) || $attr_name == 'id' || substr($attr_name, 0, 7) == 'data-gp') {
                     continue;
                 }
                 $new_section['attributes'][$attr_name] = $attr_value;
             }
         }
         // wrapper section 'contains_sections'
         if ($new_section['type'] == 'wrapper_section') {
             $new_section['contains_sections'] = isset($_POST['contains_sections']) ? $_POST['contains_sections'][$i] : '0';
         }
         $new_sections[$i] = $new_section;
     }
     //make sure there's at least one section
     if (!$new_sections) {
         message($langmessage['OOPS'] . ' (1 Section Minimum)');
         return false;
     }
     $this->file_sections = $new_sections;
     $this->ResetFileTypes(false);
     // save a send message to user
     if (!$this->SaveThis()) {
         $this->file_sections = $original_sections;
         message($langmessage['OOPS'] . '(4)');
         return;
     }
     $page->ajaxReplace[] = array('ck_saved', '', '');
     message($langmessage['SAVED']);
     //update gallery info
     $this->GalleryEdited();
     //update usage of resized images
     foreach ($unused_sections as $section_data) {
         if (isset($section_data['resized_imgs'])) {
             includeFile('image.php');
             gp_resized::SetIndex();
             gp_edit::ResizedImageUse($section_data['resized_imgs'], array());
         }
     }
 }
예제 #4
0
 /**
  * Replace resized images with their originals
  *
  */
 static function RestoreImages($html_content, $img_list)
 {
     global $dirPrefix;
     includeFile('tool/HTML_Output.php');
     includeFile('image.php');
     gp_resized::SetIndex();
     //
     $images = array();
     foreach ($img_list as $index => $sizes) {
         if (!isset(gp_resized::$index[$index])) {
             continue;
         }
         $img = gp_resized::$index[$index];
         $original_path = $dirPrefix . '/data/_uploaded' . $img;
         foreach ($sizes as $size) {
             list($width, $height) = explode('x', $size);
             $resized_path = common::GetDir('/include/image.php', true) . '?i=' . $index . '&w=' . $width . '&h=' . $height;
             //not searching for the whole path in case the image was renamed
             $images[$resized_path] = $original_path;
         }
     }
     //resize images
     $gp_html_output = new gp_html_output($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;
         }
         $src = $node['attributes']['src'];
         foreach ($images as $resized => $original) {
             if (strpos($src, $resized) === 0) {
                 $gp_html_output->dom_array[$key]['attributes']['src'] = $original;
             }
         }
     }
     $gp_html_output->Rebuild();
     return $gp_html_output->result;
 }
예제 #5
0
 /**
  * Save new/rearranged sections
  *
  */
 public function SaveSections()
 {
     global $langmessage;
     $this->ajaxReplace = array();
     $original_sections = $this->file_sections;
     $unused_sections = $this->file_sections;
     //keep track of sections that aren't used
     $new_sections = array();
     //make sure section_order isn't empty
     if (empty($_POST['section_order'])) {
         msg($langmessage['OOPS'] . ' (Invalid Request)');
         return false;
     }
     foreach ($_POST['section_order'] as $i => $arg) {
         $new_section = $this->SaveSection($i, $arg, $unused_sections);
         if ($new_section === false) {
             return false;
         }
         $new_sections[$i] = $new_section;
     }
     //make sure there's at least one section
     if (empty($new_sections)) {
         msg($langmessage['OOPS'] . ' (1 Section Minimum)');
         return false;
     }
     $this->file_sections = array_values($new_sections);
     // save a send message to user
     if (!$this->SaveThis()) {
         $this->file_sections = $original_sections;
         msg($langmessage['OOPS'] . '(4)');
         return;
     }
     $this->ajaxReplace[] = array('ck_saved', '', '');
     //update gallery info
     $this->GalleryEdited();
     //update usage of resized images
     foreach ($unused_sections as $section_data) {
         if (isset($section_data['resized_imgs'])) {
             includeFile('image.php');
             \gp_resized::SetIndex();
             \gp\tool\Editing::ResizedImageUse($section_data['resized_imgs'], array());
         }
     }
 }
예제 #6
0
 /**
  * Remove a content area from a page
  *
  */
 function RmSection()
 {
     global $langmessage, $page;
     if (!isset($_POST['total']) || $_POST['total'] != count($this->file_sections)) {
         message($langmessage['OOPS']);
         return false;
     }
     if (!isset($_POST['section'])) {
         message($langmessage['OOPS'] . '(1)');
         return;
     }
     $section = $_POST['section'];
     if (!isset($this->file_sections[$section])) {
         message($langmessage['OOPS'] . '(2)');
         return;
     }
     $section_data = $this->file_sections[$section];
     array_splice($this->file_sections, $section, 1);
     $this->ResetFileTypes();
     if (!$this->SaveThis()) {
         message($langmessage['OOPS'] . '(4)');
         return;
     }
     if ($section_data['type'] == 'gallery') {
         $this->GalleryEdited();
     }
     //update usage of resized images
     if (isset($section_data['resized_imgs'])) {
         includeFile('image.php');
         gp_resized::SetIndex();
         gp_edit::ResizedImageUse($section_data['resized_imgs'], array());
     }
     message($langmessage['SAVED']);
 }
예제 #7
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);
     }
 }
예제 #8
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);
     */
 }
예제 #9
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);
     */
 }