/** * Replace css resized images with resized copies of the original * ckeditor uses style height/width * */ static function ResizeImages(&$html_content, &$img_list) { includeFile('tool/HTML_Output.php'); 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_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; } $original_src = $node['attributes']['src']; $resized_data = gp_edit::ResizedImage($node['attributes']); if ($resized_data !== false) { $img = $resized_data['img']; $index = $resized_data['index']; $resized_src = common::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; gp_edit::ResizedImageUse($orig_list, $img_list); gp_resized::SaveIndex(); }
/** * 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']); }
/** * 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()); } } }
/** * 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); } }