Exemplo n.º 1
0
                     $src = $f->get_data();
                     $pos = strpos($src, $Config['k_append_url']);
                     if ($pos !== false) {
                         $src = substr($src, strlen($Config['k_append_url']));
                         $pos = strpos($src, $Config['UserFilesPath']);
                         if ($pos !== false) {
                             $src = substr($src, strlen($Config['UserFilesPath']));
                             $src = $Config['UserFilesAbsolutePath'] . $src;
                             // create thumbnail
                             $dest = null;
                             $w = $tb->width;
                             $h = $tb->height;
                             $crop = 1;
                             $enforce_max = 0;
                             $quality = $tb->quality;
                             $thumbnail = k_resize_image($src, $dest, $w, $h, $crop, $enforce_max, $quality, $crop_pos);
                             if ($FUNCS->is_error($thumbnail)) {
                                 die($thumbnail->err_msg);
                             }
                         }
                     }
                 } else {
                     die('No GD image library installed');
                 }
                 // Job done. Exit.
                 die('OK');
             }
             unset($f);
         }
     }
 }
Exemplo n.º 2
0
 function _process_image($src, $dest = null)
 {
     global $FUNCS;
     if (extension_loaded('gd') && function_exists('gd_info')) {
         require_once K_COUCH_DIR . 'includes/timthumb.php';
         if (!$dest) {
             // main image
             $dest = $src;
             $w = $this->width;
             $h = $this->height;
             $crop = $this->crop;
             $enforce_max = $crop ? 0 : $this->enforce_max;
             // make crop and enforce_max mutually exclusive
             $quality = $this->quality;
         } else {
             // thumbnail
             $w = $this->thumb_width;
             $h = $this->thumb_height;
             $crop = !$this->thumb_enforce_max;
             $enforce_max = $this->thumb_enforce_max;
             $quality = $this->thumb_quality;
         }
         return k_resize_image($src, $dest, $w, $h, $crop, $enforce_max, $quality);
     }
 }
Exemplo n.º 3
0
 function store_posted_changes($post_val)
 {
     global $FUNCS, $Config, $AUTH;
     if ($this->deleted) {
         return;
     }
     // no need to store
     // rearrange posted rows
     //$data = is_array( $post_val ) ? $FUNCS->sanitize_deep( $post_val ) : array();
     $data = is_array($post_val) ? $post_val : array();
     // was messing up no_xss_check. Individual fields will do this anyway.
     if (count($data)) {
         $sort_field = '_f_' . $this->name . '_sortorder';
         if (strlen(trim($_POST[$sort_field]))) {
             $arr_sort = array_map("trim", explode(',', $_POST[$sort_field]));
             $tmp = array();
             $x = 0;
             foreach ($arr_sort as $pos) {
                 if (is_numeric($pos) && isset($data[$pos])) {
                     $tmp[$x++] = $data[$pos];
                 }
             }
             $data = $tmp;
         }
     }
     // dynamic params
     for ($y = 0; $y < count($this->cells); $y++) {
         $c =& $this->cells[$y];
         $c->resolve_dynamic_params();
         unset($c);
     }
     $this->validation_errors = 0;
     $this->data = array();
     $this->rendered_data = array();
     $this->rendered_deleted_html = array();
     $sep = '';
     for ($row = 0; $row < count($data); $row++) {
         // recreate each row
         for ($y = 0; $y < count($this->cells); $y++) {
             // hydrate cell with data from database
             $c =& $this->cells[$y];
             $c->store_data_from_saved($this->orig_data[$row][$c->name]);
             $c->err_msg = '';
             // pass posted data to each cell
             $c->store_posted_changes($data[$row][$c->name]);
             if ($c->modified) {
                 $this->modified = 1;
             }
             unset($c);
         }
         // At this point we have a complete row of hydrated cells for further processing
         for ($y = 0; $y < count($this->cells); $y++) {
             $c =& $this->cells[$y];
             // Validate
             if (!$c->validate()) {
                 $this->validation_errors++;
                 $err_row = $row + 1;
                 $this->err_msg .= $sep . 'Row ' . $err_row . ' - ' . $c->label . ': ' . $c->err_msg;
                 $sep = '<br>';
             }
             // Process
             if ($c->modified) {
                 // good time to process image data
                 if ($c->k_type == 'image') {
                     // Resize
                     $resized = 0;
                     $domain_prefix = $Config['k_append_url'] . $Config['UserFilesPath'] . 'image/';
                     if (extension_loaded('gd') && function_exists('gd_info')) {
                         $src = $c->get_data();
                         if (strpos($src, $domain_prefix) === 0) {
                             // process image only if local
                             $src = substr($src, strlen($domain_prefix));
                             if ($src) {
                                 $src = $Config['UserFilesAbsolutePath'] . 'image/' . $src;
                                 // OK to resize now
                                 $dest = $src;
                                 $w = $c->width;
                                 $h = $c->height;
                                 $crop = $c->crop;
                                 $enforce_max = $crop ? 0 : $c->enforce_max;
                                 // make crop and enforce_max mutually exclusive
                                 $quality = $c->quality;
                                 $res = k_resize_image($src, $dest, $w, $h, $crop, $enforce_max, $quality);
                                 if ($FUNCS->is_error($res)) {
                                     $c->err_msg = $res->err_msg;
                                     //$this->validation_errors++;
                                     // TODO: Non critical error. Will continue but have to report.
                                 }
                             }
                         }
                     }
                 }
             }
             // get data to save (will be used if no validation errors occur)
             if ($c->k_type == 'image' || $c->k_type == 'file') {
                 $this->data[$row][$c->name] = $c->data;
                 // backward compatibility.. raw data without domain info
             } else {
                 $this->data[$row][$c->name] = $c->get_data_to_save();
             }
             // get rendered markup (will be used if validation errors occur)
             $input_name = 'f_' . $this->name . '[' . $row . '][' . $c->name . ']';
             $input_id = 'f_' . $this->name . '-' . $row . '-' . $c->name;
             $err_class = $c->err_msg ? ' highlite' : '';
             $html = '<td class="editable' . $err_class . '"><div style="position:relative;">';
             $html .= $c->_render($input_name, $input_id);
             if ($c->deleted && $AUTH->user->access_level >= K_ACCESS_LEVEL_SUPER_ADMIN) {
                 $html .= '<div class="k_cell_deleted">&nbsp;</div>';
                 if ($x == 0) {
                     $this->rendered_deleted_html[] = $c->_html;
                 }
             }
             $html .= '</div></td>';
             $this->rendered_data[$row][$c->name] = $html;
             unset($c);
         }
     }
     // for each row
     if (count($this->orig_data) != count($this->data)) {
         $this->modified = 1;
     }
 }
Exemplo n.º 4
0
 function save()
 {
     global $DB, $FUNCS, $AUTH, $Config;
     // ensure the person setting levels is privileged enough
     //if( $this->access_level > $AUTH->user->access_level ){
     if ($this->get_access_level($inherited) > $AUTH->user->access_level) {
         //take into account access control placed on template and folders
         die("Cheating?!");
     }
     $DB->begin();
     // Pre-save..
     // Adjust system fields.
     // If name empty, we create it from title field if set
     $title = trim($this->fields[0]->get_data());
     $name = trim($this->fields[1]->get_data());
     if ($this->tpl_nested_pages || $this->fields[1]->modified || $name == '' && $title != '') {
         $this->_lock_template();
         // serialize access.. lock template
     }
     if ($name == '' && $title != '') {
         $name = $FUNCS->get_clean_url($title);
         // verify the name does not already exist
         $unique = false;
         $unique_id = 1;
         $orig_name = $name;
         while (!$unique) {
             $rs = $DB->select(K_TBL_PAGES, array('id'), "page_name='" . $DB->sanitize($name) . "' and NOT id=" . $DB->sanitize($this->id) . " and template_id='" . $DB->sanitize($this->tpl_id) . "'");
             if (!count($rs)) {
                 $unique = true;
             } else {
                 $name = $orig_name . '-' . $unique_id++;
             }
         }
         $this->fields[1]->store_posted_changes($name);
     }
     $this->fields[0]->data = $title;
     // Folder ID
     $folder_id = intval($this->fields[2]->get_data());
     if (!$folder_id) {
         $this->fields[2]->store_posted_changes('-1');
     }
     // Publish date
     $publish_date = trim($this->fields[3]->get_data());
     if ($publish_date != '0000-00-00 00:00:00') {
         $publish_date2 = $FUNCS->make_date($publish_date);
         if ($publish_date != $publish_date2) {
             $this->fields[3]->store_posted_changes($publish_date2);
         }
     }
     // Access level
     $access_level = intval($this->fields[4]->get_data());
     if ($access_level < 0) {
         $access_level = 0;
     }
     if ($access_level > $AUTH->user->access_level) {
         $access_level = $AUTH->user->access_level;
     }
     $this->fields[4]->data = $access_level;
     // Weight field of nested pages..
     if ($this->tpl_nested_pages) {
         $weight = trim($this->fields[7]->get_data());
         if (!$weight || $this->fields[6]->modified) {
             // if new page or parent page changed
             // Calculate a weight that will place it below the last child of its parent
             $tree = $FUNCS->get_nested_pages($this->tpl_id, $this->tpl_name, $this->tpl_access_level);
             $nested_parent_id = $this->fields[6]->data;
             $nested_parent_page = $nested_parent_id != -1 ? $tree->find_by_id($nested_parent_id) : $tree;
             if (!$nested_parent_page) {
                 die('ERROR: Parent page ' . $nested_parent_id . ' not found');
             }
             $this->fields[7]->store_posted_changes(count($nested_parent_page->children) + 1);
             $refresh_tree = 1;
             // signal to add the new page into tree
         }
         // If pointer-page, fill details of the link
         if ($this->fields[12]->modified || $this->fields[13]->modified) {
             $this->fields[13]->store_posted_changes($FUNCS->analyze_link($this->fields[12]->get_data()));
             $this->fields[13]->modified = 1;
             $this->fields[12]->modified = 1;
             //mutually dependent
         }
     }
     // Weight of a gallery page. Make it the last in its folder.
     if ($this->tpl_gallery) {
         //todo
     }
     // Validate all fields before persistng changes
     $errors = 0;
     for ($x = 0; $x < count($this->fields); $x++) {
         $f =& $this->fields[$x];
         $f->page_id = $this->id;
         if (!$f->validate()) {
             $errors++;
         }
     }
     if ($errors) {
         $DB->rollback();
         return $errors;
     }
     if ($this->id == -1) {
         // New page. Create a record for it first.
         $last_id = $this->create($title, $name);
         if ($FUNCS->is_error($last_id)) {
             die("Failed to insert record for new page in K_TBL_PAGES");
         }
         $this->id = $last_id;
         $rs = $DB->select(K_TBL_PAGES, array('*'), "id='" . $DB->sanitize($this->id) . "'");
         if (!count($rs)) {
             die("Failed to insert record for new page in K_TBL_PAGES");
         }
         $rec = $rs[0];
         foreach ($rec as $k => $v) {
             $this->{$k} = $v;
         }
         unset($this->template_id);
     }
     $arr_update = array();
     $arr_custom_fields = array();
     $arr_fulltext_update = array();
     unset($f);
     for ($x = 0; $x < count($this->fields); $x++) {
         $f =& $this->fields[$x];
         if (defined('K_PHP_4') && $last_id) {
             $f->page->id = $this->id;
         }
         // PHP4 loses reference of new parent page ??
         if ($f->modified) {
             if ($f->system) {
                 $name = substr($f->name, 2);
                 // remove the 'k_' prefix from system fields
                 $prev_value = $this->{$name};
                 $this->{$name} = $arr_update[$name] = $f->get_data_to_save();
                 // if folder changed, have to set new parents
                 if ($name == 'page_folder_id') {
                     if ($this->page_folder_id != -1) {
                         // set the page's containing folder (if the page resides in any)
                         $this->folder =& $this->folders->find_by_id($this->page_folder_id);
                         if (!$this->folder) {
                             die('ERROR: Folder id ' . $this->page_folder_id . ' not found');
                         }
                     } else {
                         unset($this->folder);
                     }
                 } elseif ($name == 'page_title') {
                     $arr_fulltext_update['title'] = $FUNCS->strip_tags($f->get_data());
                 } elseif ($name == 'nested_parent_id' && $this->tpl_nested_pages) {
                     // The children of the original parent of this nested page will require reordering.. post save processing.
                     $reset_weights_of = $prev_value;
                 }
             } else {
                 if ($f->k_type == 'image') {
                     // Resize
                     $resized = 0;
                     $domain_prefix = $Config['k_append_url'] . $Config['UserFilesPath'] . 'image/';
                     if (extension_loaded('gd') && function_exists('gd_info')) {
                         $src = $f->get_data();
                         if (strpos($src, $domain_prefix) === 0) {
                             // process image only if local
                             $src = substr($src, strlen($domain_prefix));
                             if ($src) {
                                 $src = $Config['UserFilesAbsolutePath'] . 'image/' . $src;
                                 // is EXIF data required?
                                 if ($this->tpl_gallery && K_EXTRACT_EXIF_DATA && $f->name == 'gg_image') {
                                     require_once K_COUCH_DIR . 'includes/phpExifRW/exifReader.inc';
                                     $exifreader = new phpExifReader($src);
                                     if (!($exifreader->errno || $exifreader->errorno)) {
                                         $exifreader->ImageReadMode = 1;
                                         $exifdata = $FUNCS->filterExif($exifreader->getImageInfo());
                                         $resized = 1;
                                         // do not manipulate uploaded image if contains exif (GD destroys exif).
                                     }
                                 }
                                 if (!$resized) {
                                     // OK to resize now
                                     $dest = $src;
                                     $w = $f->width;
                                     $h = $f->height;
                                     $crop = $f->crop;
                                     $enforce_max = $crop ? 0 : $f->enforce_max;
                                     // make crop and enforce_max mutually exclusive
                                     $quality = $f->quality;
                                     $res = k_resize_image($src, $dest, $w, $h, $crop, $enforce_max, $quality);
                                     if ($FUNCS->is_error($res)) {
                                         //$f->err_msg = $res->err_msg;
                                         //$errors++;
                                         // TODO: Non critical error. Will continue but have to report.
                                     } else {
                                         $resized = 1;
                                         // signal ok for creating thumbnail
                                     }
                                 }
                             }
                         }
                     }
                     // Find any associated thumbnail fields and update thumbnails (only for local files)
                     for ($t = 0; $t < count($this->fields); $t++) {
                         $tb =& $this->fields[$t];
                         if (!$tb->system && $tb->k_type == 'thumbnail' && $tb->assoc_field == $f->name) {
                             if ($resized) {
                                 // create thumbnail
                                 $dest = null;
                                 $w = $tb->width;
                                 $h = $tb->height;
                                 // Make provision for enforce max. Make crop & enforce_max exclusive.
                                 $enforce_max = $tb->enforce_max;
                                 $crop = $enforce_max ? 0 : 1;
                                 $quality = $tb->quality;
                                 $thumbnail = k_resize_image($src, $dest, $w, $h, $crop, $enforce_max, $quality);
                                 if ($FUNCS->is_error($thumbnail)) {
                                     //$tb->err_msg = $thumbnail->err_msg;
                                     //$errors++;
                                     // TODO: Non critical error. Will continue but have to report.
                                 } else {
                                     $tb->modified = 1;
                                     $path_parts = $FUNCS->pathinfo($f->get_data());
                                     $img_path = $path_parts['dirname'] . '/';
                                     $img_path = substr($img_path, strlen($domain_prefix));
                                     if ($img_path) {
                                         $thumbnail = $img_path . $thumbnail;
                                     }
                                     $tb->data = ':' . $thumbnail;
                                     // add marker
                                     $arr_custom_fields[$tb->id]['data'] = $tb->data;
                                     $arr_custom_fields[$tb->id]['type'] = $tb->search_type;
                                     $arr_custom_fields[$tb->id]['strip_domain'] = 1;
                                 }
                             } else {
                                 $tb->data = '';
                                 $arr_custom_fields[$tb->id]['data'] = '';
                                 $arr_custom_fields[$tb->id]['type'] = $tb->search_type;
                             }
                         }
                         unset($tb);
                     }
                     // Update meta data of gallery pages
                     if ($this->tpl_gallery && $f->name == 'gg_image') {
                         if ($resized) {
                             clearstatcache();
                             $path_parts = $FUNCS->pathinfo($f->get_data());
                             $arr_update['file_name'] = $path_parts['basename'];
                             $arr_update['file_ext'] = $path_parts['extension'];
                             $arr_update['file_size'] = @filesize($src);
                             if (is_array($exifdata) && count($exifdata)) {
                                 $arr_update['file_meta'] = $FUNCS->serialize($exifdata);
                             } else {
                                 $arr_update['file_meta'] = '';
                             }
                         } else {
                             $arr_update['file_name'] = '';
                             $arr_update['file_ext'] = '';
                             $arr_update['file_size'] = 0;
                             $arr_update['file_meta'] = '';
                         }
                     }
                 }
                 if ($f->k_type != 'thumbnail') {
                     // all the rest
                     if ($f->k_type == 'image' || $f->k_type == 'file') {
                         $arr_custom_fields[$f->id]['data'] = $f->data;
                         // raw data without domain info
                         $arr_custom_fields[$f->id]['strip_domain'] = 1;
                     } else {
                         $arr_custom_fields[$f->id]['data'] = $f->get_data_to_save();
                     }
                     $arr_custom_fields[$f->id]['type'] = $f->search_type;
                     if ($f->udf) {
                         $arr_custom_fields[$f->id]['not_searchable'] = !$FUNCS->udfs[$f->k_type]['searchable'];
                         $arr_custom_fields[$f->id]['search_data'] = $f->get_search_data();
                     } else {
                         // core types
                         if ($f->k_type == 'textarea' && $f->no_xss_check || $f->k_type == 'password') {
                             $arr_custom_fields[$f->id]['not_searchable'] = 1;
                             // code & password exempt ..
                         }
                     }
                 }
             }
         }
         unset($f);
     }
     $arr_update['modification_date'] = $FUNCS->get_current_desktop_time();
     // update page record
     $rs = $DB->update(K_TBL_PAGES, $arr_update, "id='" . $DB->sanitize($this->id) . "'");
     if ($rs == -1) {
         die("ERROR: Unable to save data in K_TBL_PAGES");
     }
     // update the custom fields
     if (count($arr_custom_fields)) {
         foreach ($arr_custom_fields as $k => $v) {
             $arr_custom_update = array('value' => $v['data']);
             if ($v['type'] == 'text') {
                 $data_table = K_TBL_DATA_TEXT;
                 if (isset($v['search_data'])) {
                     // udf
                     $arr_custom_update['search_value'] = $v['not_searchable'] == 1 ? '' : $FUNCS->strip_tags($v['search_data']);
                 } else {
                     // core types
                     if ($v['strip_domain'] && substr($v['data'], 0, 1) == ':') {
                         $arr_custom_update['search_value'] = substr($v['data'], 1);
                         //..or should the entire path be stripped?
                     } else {
                         $arr_custom_update['search_value'] = $v['not_searchable'] == 1 ? '' : $FUNCS->strip_tags($v['data']);
                         //TODO: strip shortcodes
                     }
                 }
             } else {
                 $data_table = K_TBL_DATA_NUMERIC;
             }
             $rs = $DB->update($data_table, $arr_custom_update, "page_id='" . $DB->sanitize($this->id) . "' AND field_id='" . $DB->sanitize($k) . "'");
             if ($rs == -1) {
                 die("ERROR: Unable to save data in K_TBL_DATA");
             }
         }
         // refresh the custom fields before displaying back
         $this->_fill_custom_fields();
         // get the consolidated text data for this page (only from 'textarea', 'richtext' and 'text' editable regions)
         $full_text = '';
         $rs = $DB->select(K_TBL_DATA_TEXT . ' dt, ' . K_TBL_FIELDS . ' f ', array('field_id', 'f.k_type as field_type', 'search_value'), "dt.page_id='" . $DB->sanitize($this->id) . "' AND dt.field_id=f.id");
         if (count($rs)) {
             foreach ($rs as $rec) {
                 if (($rec['field_type'] == 'textarea' || $rec['field_type'] == 'richtext' || $rec['field_type'] == 'text' || !$FUNCS->is_core_type($rec['field_type'])) && $rec['search_value']) {
                     $full_text .= $rec['search_value'] . ' ';
                 }
             }
         }
         $arr_fulltext_update['content'] = $full_text;
     }
     // update modification time_stamp
     $this->modification_date = $arr_update['modification_date'];
     // update full-text MyISAM table for searching
     if (count($arr_fulltext_update)) {
         $rs = $DB->update(K_TBL_FULLTEXT, $arr_fulltext_update, "page_id='" . $DB->sanitize($this->id) . "'");
         if ($rs == -1) {
             die("ERROR: Unable to update data in K_TBL_FULLTEXT");
         }
     }
     // post save processing.. adjust weights of remaining children of the previous parent of this nested page.
     if ($reset_weights_of) {
         $this->reset_weights_of($reset_weights_of);
     } elseif ($refresh_tree) {
         $FUNCS->get_nested_pages($this->tpl_id, $this->tpl_name, $this->tpl_access_level, 'weightx', 'asc', 1);
     }
     $DB->commit();
     // Invalidate cache
     //$FUNCS->invalidate_cache();
     return $errors;
 }
Exemplo n.º 5
0
 function thumbnail($params, $node)
 {
     global $FUNCS, $Config;
     require_once K_COUCH_DIR . 'includes/timthumb.php';
     extract($FUNCS->get_named_vars(array('src' => '', 'width' => '', 'height' => '', 'enforce_max' => '0', 'quality' => '80'), $params));
     $src = trim($src);
     if (!$src) {
         return;
     }
     $dest = null;
     $width = abs((int) $width);
     $height = abs((int) $height);
     $enforce_max = $enforce_max == 1 ? 1 : 0;
     $crop = !$enforce_max;
     $quality = (int) $quality;
     if ($quality <= 0) {
         $quality = '80';
     } elseif ($quality > 100) {
         $quality = '100';
     }
     // Make sure the source image lies within our upload image folder
     $domain_prefix = $Config['k_append_url'] . $Config['UserFilesPath'] . 'image/';
     if (strpos($src, $domain_prefix) === 0) {
         // process image only if local
         $orig_src = $src;
         $src = substr($src, strlen($domain_prefix));
         if ($src) {
             $src = $Config['UserFilesAbsolutePath'] . 'image/' . $src;
             // Call timthumb to create thumbnail
             $thumbnail = k_resize_image($src, $dest, $width, $height, $crop, $enforce_max, $quality, 'middle', 1);
             if ($FUNCS->is_error($thumbnail)) {
                 return 'ERROR: ' . $thumbnail->err_msg;
             }
             $path_parts = $FUNCS->pathinfo($orig_src);
             return $path_parts['dirname'] . '/' . $thumbnail;
         }
     } else {
         return 'ERROR: Can only create thumbnails of images that are found within or below ' . $domain_prefix;
     }
 }