function thumbnail_create_post() { $id = $this->psi('id'); extract(doSlash(gpsa(array('thumbnail_clear_settings', 'thumbnail_delete', 'width', 'height', 'crop')))); if ($thumbnail_clear_settings) { $message = $this->thumbnail_clear_settings($id); } elseif ($thumbnail_delete) { $message = $this->thumbnail_delete($id); } else { $width = (int) $width; $height = (int) $height; if ($width != 0 || $height != 0) { if (img_makethumb($id, $width, $height, $crop)) { global $prefs; if ($width == 0) { $width = ''; } if ($height == 0) { $height = ''; } $prefs['thumb_w'] = $width; $prefs['thumb_h'] = $height; $prefs['thumb_crop'] = $crop; // hidden prefs set_pref('thumb_w', $width, 'image', 2); set_pref('thumb_h', $height, 'image', 2); set_pref('thumb_crop', $crop, 'image', 2); update_lastmod(); $message = gTxt('thumbnail_saved', array('{id}' => $id)); } else { $message = gTxt('thumbnail_not_saved', array('{id}' => $id)); } } else { $message = messenger('invalid_width_or_height', "({$width})/({$height})", ''); } } $this->_message($message); $this->_set_view('edit', $id); }
function image_data($file, $meta = '', $id = '', $uploaded = true) { global $txpcfg, $txp_user, $prefs, $file_max_upload_size; $extensions = array(0, '.gif', '.jpg', '.png', '.swf'); extract($txpcfg); $name = $file['name']; $error = $file['error']; $file = $file['tmp_name']; if ($uploaded) { $file = get_uploaded_file($file); if ($file_max_upload_size < filesize($file)) { unlink($file); return upload_get_errormsg(UPLOAD_ERR_FORM_SIZE); } } list($w, $h, $extension) = @getimagesize($file); if ($file !== false && @$extensions[$extension]) { $ext = $extensions[$extension]; $name = doSlash(substr($name, 0, strrpos($name, '.')) . $ext); if ($meta == false) { $meta = array('category' => '', 'caption' => '', 'alt' => ''); } extract(doSlash($meta)); $q = "\n\t\t\tname = '{$name}',\n\t\t\text = '{$ext}',\n\t\t\tw = {$w},\n\t\t\th = {$h},\n\t\t\talt = '{$alt}',\n\t\t\tcaption = '{$caption}',\n\t\t\tcategory = '{$category}',\n\t\t\tdate = now(),\n\t\t\tauthor = '{$txp_user}'\n\t\t"; if (empty($id)) { $rs = safe_insert('txp_image', $q); $id = $GLOBALS['ID'] = mysql_insert_id(); } else { $id = assert_int($id); $rs = safe_update('txp_image', $q, "id = {$id}"); } if (!$rs) { return gTxt('image_save_error'); } else { $newpath = IMPATH . $id . $ext; if (shift_uploaded_file($file, $newpath) == false) { $id = assert_int($id); safe_delete('txp_image', "id = {$id}"); safe_alter('txp_image', "auto_increment = {$id}"); if (isset($GLOBALS['ID'])) { unset($GLOBALS['ID']); } return $newpath . sp . gTxt('upload_dir_perms'); } else { @chmod($newpath, 0644); // Auto-generate a thumbnail using the last settings if (isset($prefs['thumb_w'], $prefs['thumb_h'], $prefs['thumb_crop'])) { img_makethumb($id, $prefs['thumb_w'], $prefs['thumb_h'], $prefs['thumb_crop']); } update_lastmod(); $message = gTxt('image_uploaded', array('{name}' => $name)); return array($message, $id); } } } else { // missing or invalid file if ($file === false) { return upload_get_errormsg($error); } else { return gTxt('only_graphic_files_allowed'); } } }