* GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * * @link http://www.easyscp.net * @author EasySCP Team */ require '../include/easyscp-lib.php'; $cfg = EasySCP_Registry::get('Config'); if (!$cfg->LOSTPASSWORD) { throw new EasySCP_Exception_Production(tr('Retrieving lost passwords is currently not possible')); } // check if GD library is available if (!check_gd()) { throw new EasySCP_Exception(tr("GD PHP Extension not loaded!")); } // check if captch fonts exist if (!captcha_fontfile_exists()) { throw new EasySCP_Exception(tr("Captcha fontfile not found!")); } // remove old unique keys removeOldKeys($cfg->LOSTPASSWORD_TIMEOUT); if (isset($_SESSION['user_theme'])) { $theme_color = $_SESSION['user_theme']; } else { $theme_color = $cfg->USER_INITIAL_THEME; } $tpl = EasySCP_TemplateEngine::getInstance(); $tpl->assign(array('TR_PAGE_TITLE' => tr('EasySCP - Virtual Hosting Control System'), 'TR_WEBMAIL_SSL_LINK' => 'webmail', 'TR_FTP_SSL_LINK' => 'ftp', 'TR_PMA_SSL_LINK' => 'pma'));
function edit_view($id = '') { global $txpcfg, $img_dir, $file_max_upload_size; $out = array(); if (!$id) { $id = assert_int(gps('id')); } extract($this->context); $categories = tree_get('txp_category', NULL, "type='image'"); $rs = safe_row("*", "txp_image", "id = {$id}"); if ($rs) { extract($rs); if ($ext != '.swf') { $img = '<img src="' . hu . $img_dir . '/' . $id . $ext . '" height="' . $h . '" width="' . $w . '" alt="" "title="' . $id . $ext . ' (' . $w . ' × ' . $h . ')" />'; } else { $img = ''; } if ($thumbnail and $ext != '.swf') { $thumb = '<img src="' . hu . $img_dir . '/' . $id . 't' . $ext . '" alt="" />'; } else { $thumb = ''; } $out[] = startTable('edit') . tr(td($img . br . upload_form(gTxt('replace_image'), 'replace_image_form', 'replace', $this->event, $id, $file_max_upload_size, 'image-replace', ''))) . tr(td(join('', array($thumbnail ? $thumb . br : '', upload_form(gTxt('upload_thumbnail'), 'upload_thumbnail', 'thumbnail_insert', $this->event, $id, $file_max_upload_size, 'upload-thumbnail', ''))))); $out[] = check_gd($ext) ? $this->thumb_ui($id, $thumbnail) : ''; $out[] = tr(td(form(graf('<label for="image-name">' . gTxt('image_name') . '</label>' . br . fInput('text', 'name', $name, 'edit', '', '', '', '', 'image-name')) . graf('<label for="image-category">' . gTxt('image_category') . '</label>' . br . categorySelectInput('image', 'category', $category, 'image-category')) . graf('<label for="alt-text">' . gTxt('alt_text') . '</label>' . br . fInput('text', 'alt', $alt, 'edit', '', '', 50, '', 'alt-text')) . graf('<label for="caption">' . gTxt('caption') . '</label>' . br . text_area('caption', '100', '400', $caption, 'caption')) . n . graf(fInput('submit', '', gTxt('save'), 'publish')) . n . hInput('id', $id) . n . eInput($this->event) . n . sInput('save') . n . hInput('sort', $sort) . n . hInput('dir', $dir) . n . hInput('page', $page) . n . hInput('search_method', $search_method) . n . hInput('crit', $crit)))) . endTable(); } return join('', $out); }
function image_edit($message = '', $id = '') { global $prefs, $file_max_upload_size, $txp_user, $event, $all_image_cats; if (!$id) { $id = gps('id'); } $id = assert_int($id); $rs = safe_row("*, unix_timestamp(date) as uDate", "txp_image", "id = {$id}"); if ($rs) { extract($rs); if (!has_privs('image.edit') && !($author === $txp_user && has_privs('image.edit.own'))) { image_list(gTxt('restricted_area')); return; } pagetop(gTxt('edit_image'), $message); extract(gpsa(array('page', 'sort', 'dir', 'crit', 'search_method'))); if ($ext != '.swf') { $aspect = $h == $w ? ' square' : ($h > $w ? ' portrait' : ' landscape'); $img_info = $id . $ext . ' (' . $w . ' × ' . $h . ')'; $img = '<div class="fullsize-image"><img class="content-image" src="' . imagesrcurl($id, $ext) . "?{$uDate}" . '" alt="' . $img_info . '" title="' . $img_info . '" /></div>'; } else { $img = $aspect = ''; } if ($thumbnail and $ext != '.swf') { $thumb_info = $id . 't' . $ext . ' (' . $thumb_w . ' × ' . $thumb_h . ')'; $thumb = '<img class="content-image" src="' . imagesrcurl($id, $ext, true) . "?{$uDate}" . '" alt="' . $thumb_info . '" ' . ($thumb_w ? 'width="' . $thumb_w . '" height="' . $thumb_h . '" title="' . $thumb_info . '"' : '') . ' />'; } else { $thumb = ''; if ($thumb_w == 0) { $thumb_w = get_pref('thumb_w', 0); } if ($thumb_h == 0) { $thumb_h = get_pref('thumb_h', 0); } } echo n . '<div id="' . $event . '_container" class="txp-container">'; echo pluggable_ui('image_ui', 'fullsize_image', $img, $rs), '<section class="txp-edit">', hed(gTxt('edit_image'), 2), pluggable_ui('image_ui', 'image_edit', wrapGroup('image_edit_group', upload_form('', '', 'image_replace', 'image', $id, $file_max_upload_size, 'image_replace', 'image-replace'), 'replace_image', 'replace-image', 'replace_image_form'), $rs), pluggable_ui('image_ui', 'thumbnail_image', '<div class="thumbnail-edit">' . ($thumbnail ? $thumb . n . dLink('image', 'thumbnail_delete', 'id', $id, '', '', '', '', array($page, $sort, $dir, $crit, $search_method)) : '') . '</div>', $rs), pluggable_ui('image_ui', 'thumbnail_edit', wrapGroup('thumbnail_edit_group', upload_form('', '', 'thumbnail_insert', 'image', $id, $file_max_upload_size, 'upload_thumbnail', 'thumbnail-upload'), 'upload_thumbnail', 'thumbnail-upload', 'upload_thumbnail'), $rs), check_gd($ext) ? pluggable_ui('image_ui', 'thumbnail_create', wrapGroup('thumbnail_create_group', form(graf(n . '<label for="width">' . gTxt('thumb_width') . '</label>' . fInput('text', 'width', @$thumb_w, 'input-xsmall', '', '', INPUT_XSMALL, '', 'width') . n . '<label for="height">' . gTxt('thumb_height') . '</label>' . fInput('text', 'height', @$thumb_h, 'input-xsmall', '', '', INPUT_XSMALL, '', 'height') . n . '<label for="crop">' . gTxt('keep_square_pixels') . '</label>' . checkbox('crop', 1, @$prefs['thumb_crop'], '', 'crop') . fInput('submit', '', gTxt('Create')), ' class="edit-alter-thumbnail"') . hInput('id', $id) . eInput('image') . sInput('thumbnail_create') . hInput('sort', $sort) . hInput('dir', $dir) . hInput('page', $page) . hInput('search_method', $search_method) . hInput('crit', $crit), '', '', 'post', 'edit-form', '', 'thumbnail_alter_form'), 'create_thumbnail', 'thumbnail-alter', 'create_thumbnail'), $rs) : '', '<div class="image-detail">', form(inputLabel('image_name', fInput('text', 'name', $name, '', '', '', INPUT_REGULAR, '', 'image_name'), 'image_name') . inputLabel('image_category', treeSelectInput('category', $all_image_cats, $category, 'image_category'), 'image_category') . inputLabel('image_alt_text', fInput('text', 'alt', $alt, '', '', '', INPUT_REGULAR, '', 'image_alt_text'), 'alt_text') . inputLabel('image_caption', text_area('caption', 0, 0, $caption, 'image_caption', TEXTAREA_HEIGHT_SMALL, INPUT_LARGE), 'caption', '', '', '') . pluggable_ui('image_ui', 'extend_detail_form', '', $rs) . graf(fInput('submit', '', gTxt('save'), 'publish')) . hInput('id', $id) . eInput('image') . sInput('image_save') . hInput('sort', $sort) . hInput('dir', $dir) . hInput('page', $page) . hInput('search_method', $search_method) . hInput('crit', $crit), '', '', 'post', 'edit-form', '', 'image_details_form'), '</div>', '</section>' . n . '</div>'; } }
/** * 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); }
function image_data($file, $meta = '', $id = '', $uploaded = true) { global $txpcfg, $extensions, $txp_user, $prefs, $file_max_upload_size, $event; 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); } } if (empty($file)) { return upload_get_errormsg(UPLOAD_ERR_NO_FILE); } list($w, $h, $extension) = getimagesize($file); if ($file !== false && @$extensions[$extension]) { $ext = $extensions[$extension]; $name = substr($name, 0, strrpos($name, '.')) . $ext; $safename = doSlash($name); if ($meta == false) { $meta = array('category' => '', 'caption' => '', 'alt' => ''); } extract(doSlash($meta)); $q = "\n\t\t\t\tname = '{$safename}',\n\t\t\t\text = '{$ext}',\n\t\t\t\tw = {$w},\n\t\t\t\th = {$h},\n\t\t\t\talt = '{$alt}',\n\t\t\t\tcaption = '{$caption}',\n\t\t\t\tcategory = '{$category}',\n\t\t\t\tdate = now(),\n\t\t\t\tauthor = '" . doSlash($txp_user) . "'\n\t\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); // GD is supported if (check_gd($ext)) { // Auto-generate a thumbnail using the last settings if (isset($prefs['thumb_w'], $prefs['thumb_h'], $prefs['thumb_crop'])) { $width = intval($prefs['thumb_w']); $height = intval($prefs['thumb_h']); if ($width > 0 or $height > 0) { $t = new txp_thumb($id); $t->crop = $prefs['thumb_crop'] == '1'; $t->hint = '0'; $t->width = $width; $t->height = $height; $t->write(); } } } $message = gTxt('image_uploaded', array('{name}' => $name)); update_lastmod(); // call post-upload plugins with new image's $id callback_event('image_uploaded', $event, false, $id); return array($message, $id); } } } else { if ($file === false) { return upload_get_errormsg($error); } else { return gTxt('only_graphic_files_allowed'); } } }
/** * Renders and outputs the image editor panel. * * @param string|array $message The activity message * @param int $id The image ID */ function image_edit($message = '', $id = '') { global $prefs, $file_max_upload_size, $txp_user, $event, $all_image_cats; if (!$id) { $id = gps('id'); } $id = assert_int($id); $rs = safe_row("*, UNIX_TIMESTAMP(date) AS uDate", 'txp_image', "id = {$id}"); if ($rs) { extract($rs); if (!has_privs('image.edit') && !($author === $txp_user && has_privs('image.edit.own'))) { image_list(gTxt('restricted_area')); return; } pagetop(gTxt('edit_image'), $message); extract(gpsa(array('page', 'sort', 'dir', 'crit', 'search_method'))); if ($ext != '.swf') { $aspect = $h == $w ? ' square' : ($h > $w ? ' portrait' : ' landscape'); $img_info = $id . $ext . ' (' . $w . ' × ' . $h . ')'; $img = '<div class="fullsize-image"><img class="content-image" src="' . imagesrcurl($id, $ext) . "?{$uDate}" . '" alt="' . $img_info . '" title="' . $img_info . '" /></div>'; } else { $img = $aspect = ''; } if ($thumbnail and $ext != '.swf') { $thumb_info = $id . 't' . $ext . ' (' . $thumb_w . ' × ' . $thumb_h . ')'; $thumb = '<img class="content-image" src="' . imagesrcurl($id, $ext, true) . "?{$uDate}" . '" alt="' . $thumb_info . '" title="' . $thumb_info . '" />'; } else { $thumb = ''; if ($thumb_w == 0) { $thumb_w = get_pref('thumb_w', 0); } if ($thumb_h == 0) { $thumb_h = get_pref('thumb_h', 0); } } $imageBlock = array(); $thumbBlock = array(); $imageBlock[] = pluggable_ui('image_ui', 'fullsize_image', $img, $rs); $imageBlock[] = pluggable_ui('image_ui', 'image_edit', upload_form('replace_image', 'replace_image_form', 'image_replace', 'image', $id, $file_max_upload_size, 'image-upload', ' image-replace'), $rs); $thumbBlock[] = hed(gTxt('create_thumbnail') . popHelp('create_thumbnail'), 3); $thumbBlock[] = check_gd($ext) ? pluggable_ui('image_ui', 'thumbnail_create', form(graf(n . '<label for="width">' . gTxt('thumb_width') . '</label>' . fInput('text', 'width', @$thumb_w, 'input-xsmall', '', '', INPUT_XSMALL, '', 'width') . n . '<label for="height">' . gTxt('thumb_height') . '</label>' . fInput('text', 'height', @$thumb_h, 'input-xsmall', '', '', INPUT_XSMALL, '', 'height') . n . '<label for="crop">' . gTxt('keep_square_pixels') . '</label>' . checkbox('crop', 1, @$prefs['thumb_crop'], '', 'crop') . fInput('submit', '', gTxt('create')), ' class="edit-alter-thumbnail"') . hInput('id', $id) . eInput('image') . sInput('thumbnail_create') . hInput('sort', $sort) . hInput('dir', $dir) . hInput('page', $page) . hInput('search_method', $search_method) . hInput('crit', $crit), '', '', 'post', '', '', 'thumbnail_alter_form'), $rs) : ''; $thumbBlock[] = pluggable_ui('image_ui', 'thumbnail_image', '<div class="thumbnail-image">' . ($thumbnail ? $thumb . n . dLink('image', 'thumbnail_delete', 'id', $id, '', '', '', '', array($page, $sort, $dir, $crit, $search_method)) : '') . '</div>', $rs); $thumbBlock[] = pluggable_ui('image_ui', 'thumbnail_edit', upload_form('upload_thumbnail', 'upload_thumbnail', 'thumbnail_insert', 'image', $id, $file_max_upload_size, 'thumbnail-upload', ' thumbnail-upload'), $rs); echo n . tag(hed(gTxt('edit_image'), 1, array('class' => 'txp-heading')) . n . implode(n, $imageBlock) . '<hr />' . tag(implode(n, $thumbBlock), 'section', array('class' => 'thumbnail-alter')), 'div', array('class' => 'txp-layout-4col-cell-1-2-3')) . '<div class="txp-layout-4col-cell-4alt">', form(graf(fInput('submit', '', gTxt('save'), 'publish'), array('class' => 'txp-save')) . wrapGroup('image-details', inputLabel('image_name', fInput('text', 'name', $name, '', '', '', INPUT_REGULAR, '', 'image_name'), 'image_name', '', array('class' => 'txp-form-field edit-image-name')) . inputLabel('image_category', event_category_popup('image', $category, 'image_category') . n . eLink('category', 'list', '', '', gTxt('edit'), '', '', '', 'txp-option-link'), 'image_category', '', array('class' => 'txp-form-field edit-image-category')) . inputLabel('image_alt_text', fInput('text', 'alt', $alt, '', '', '', INPUT_REGULAR, '', 'image_alt_text'), 'alt_text', '', array('class' => 'txp-form-field edit-image-alt-text')) . inputLabel('image_caption', '<textarea id="image_caption" name="caption" cols="' . INPUT_LARGE . '" rows="' . TEXTAREA_HEIGHT_SMALL . '">' . $caption . '</textarea>', 'caption', '', array('class' => 'txp-form-field txp-form-field-textarea edit-image-caption')) . pluggable_ui('image_ui', 'extend_detail_form', '', $rs) . hInput('id', $id) . eInput('image') . sInput('image_save') . hInput('sort', $sort) . hInput('dir', $dir) . hInput('page', $page) . hInput('search_method', $search_method) . hInput('crit', $crit), 'image_details'), '', '', 'post', '', '', 'image_details_form'), '</div>'; } }