Example #1
0
 /**
  * Check the path of the img, return full path of image if the requested image is found
  *
  */
 function __construct()
 {
     global $dataDir;
     if (!isset($_GET['w']) || !isset($_GET['h']) || !isset($_GET['img'])) {
         self::Send404();
         //dies
     }
     $img = $_GET['img'];
     $height = $_GET['h'];
     $width = $_GET['w'];
     $index = $_GET['i'];
     if (!is_numeric($height) || !is_numeric($width)) {
         self::Send404();
         //dies
     }
     $img = gpFiles::NoNull($img);
     //check file path
     if (strpos($img, './') !== false || strpos($img, '%2f') !== false || strpos($img, '%2F') !== false) {
         return false;
     }
     //make sure the index is set
     gp_resized::SetIndex();
     if (!isset(self::$index[$index])) {
         self::Send404();
         //dies
     }
     //if the image has been renamed, redirect to the new name
     $index_img = self::$index[$index];
     if ($index_img != $img) {
         $path = common::GetDir('/include/image.php', false) . '?i=' . $index . '&w=' . $width . '&h=' . $height . '&img=' . rawurlencode($index_img);
         common::Redirect($path);
     }
     $info = self::ImageInfo($img, $width, $height);
     $folder = $dataDir . '/data/_resized/' . $info['index'];
     $full_path = $folder . '/' . $info['name'];
     //if it exists return true
     if (file_exists($full_path)) {
         header('Cache-Control: public, max-age=5184000');
         //60 days
         //attempt to send 304
         $stats = lstat($full_path);
         if ($stats) {
             common::Send304(common::GenEtag($stats['mtime'], $stats['size']));
         }
         header('Content-Transfer-Encoding: binary');
         header('Content-Type: ' . $info['ctype']);
         readfile($full_path);
         die;
     }
     //redirect to next largest image if available
     $usage = self::GetUsage($info['index']);
     foreach ($usage as $size => $data) {
         if (!$data['uses']) {
             continue;
         }
         list($use_width, $use_height) = explode('x', $size);
         if ($use_width >= $width && $use_height > $height || $use_width > $width && $use_height >= $height) {
             $path = common::GetDir('/include/image.php', false) . '?i=' . $index . '&w=' . $use_width . '&h=' . $use_height . '&img=' . rawurlencode($img);
             common::Redirect($path);
             //dies
         }
     }
     //redirect to full size image
     $original = common::GetDir('/data/_uploaded' . $img, false);
     common::Redirect($original);
     //dies
 }
Example #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);
     }
 }
Example #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());
         }
     }
 }
Example #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;
 }
Example #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());
         }
     }
 }
Example #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']);
 }
Example #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);
     }
 }
Example #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);
     */
 }
Example #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);
     */
 }