* modify it under the terms of the GNU General Public License * as published by the Free Software Foundation, version 2. * * Textpattern is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with Textpattern. If not, see <http://www.gnu.org/licenses/>. */ if (!defined('txpinterface')) { die('txpinterface is undefined.'); } global $extensions; $extensions = get_safe_image_types(); include txpath . '/lib/class.thumb.php'; if ($event == 'image') { require_privs('image'); global $all_image_cats, $all_image_authors; $all_image_cats = getTree('root', 'image'); $all_image_authors = the_privileged('image.edit.own'); $available_steps = array('image_list' => false, 'image_edit' => false, 'image_insert' => true, 'image_replace' => true, 'image_save' => true, 'thumbnail_insert' => true, 'image_change_pageby' => true, 'thumbnail_create' => true, 'thumbnail_delete' => true, 'image_multi_edit' => true); if ($step && bouncer($step, $available_steps)) { $step(); } else { image_list(); } } // ------------------------------------------------------------- function image_list($message = '')
/** * Uploads an image. * * Can be used to upload a new image or replace an existing one. * If $id is specified, the image will be replaced. If $uploaded is set FALSE, * $file can take a local file instead of HTTP file upload variable. * * All uploaded files will included on the Images panel. * * @param array $file HTTP file upload variables * @param array $meta Image meta data, allowed keys 'caption', 'alt', 'category' * @param int $id Existing image's ID * @param bool $uploaded If FALSE, $file takes a filename instead of upload vars * @return array|string An array of array(message, id) on success, localized error string on error * @package Image * @example * print_r(image_data( * $_FILES['myfile'], * array( * 'caption' => '', * 'alt' => '', * 'category' => '', * ) * )); */ function image_data($file, $meta = array(), $id = 0, $uploaded = true) { global $txp_user, $event; $name = $file['name']; $error = $file['error']; $file = $file['tmp_name']; if ($uploaded) { $file = get_uploaded_file($file); if (get_pref('file_max_upload_size') < filesize($file)) { unlink($file); return upload_get_errormsg(UPLOAD_ERR_FORM_SIZE); } } if (empty($file)) { return upload_get_errormsg(UPLOAD_ERR_NO_FILE); } list($w, $h, $extension) = getimagesize($file); $ext = get_safe_image_types($extension); if (!$ext) { return gTxt('only_graphic_files_allowed'); } $name = substr($name, 0, strrpos($name, '.')) . $ext; $safename = doSlash($name); $meta = lAtts(array('category' => '', 'caption' => '', 'alt' => ''), (array) $meta, false); extract(doSlash($meta)); $q = "\n name = '{$safename}',\n ext = '{$ext}',\n w = {$w},\n h = {$h},\n alt = '{$alt}',\n caption = '{$caption}',\n category = '{$category}',\n date = now(),\n author = '" . doSlash($txp_user) . "'\n "; if (empty($id)) { $rs = safe_insert('txp_image', $q); if ($rs) { $id = $GLOBALS['ID'] = $rs; } $update = false; } else { $id = assert_int($id); $rs = safe_update('txp_image', $q, "id = {$id}"); $update = true; } if (!$rs) { return gTxt('image_save_error'); } $newpath = IMPATH . $id . $ext; if (shift_uploaded_file($file, $newpath) == false) { if (!$update) { safe_delete('txp_image', "id = {$id}"); } unset($GLOBALS['ID']); return $newpath . sp . gTxt('upload_dir_perms'); } @chmod($newpath, 0644); // GD is supported if (check_gd($ext)) { // Auto-generate a thumbnail using the last settings if (get_pref('thumb_w') > 0 || get_pref('thumb_h') > 0) { $t = new txp_thumb($id); $t->crop = (bool) get_pref('thumb_crop'); $t->hint = '0'; $t->width = (int) get_pref('thumb_w'); $t->height = (int) get_pref('thumb_h'); $t->write(); } } $message = gTxt('image_uploaded', array('{name}' => $name)); update_lastmod('image_uploaded', compact('id', 'name', 'ext', 'w', 'h', 'alt', 'caption', 'category', 'txpuser')); // call post-upload plugins with new image's $id callback_event('image_uploaded', $event, false, $id); return array($message, $id); }