📄 main.php
字号:
<?php
// $Id: main.php,v 1.12 2004/12/26 19:12:04 onokazu Exp $
// ------------------------------------------------------------------------ //
// XOOPS - PHP Content Management System //
// Copyright (c) 2000 XOOPS.org //
// <http://www.xoops.org/> //
// ------------------------------------------------------------------------ //
// This program is free software; you can redistribute it and/or modify //
// it under the terms of the GNU General Public License as published by //
// the Free Software Foundation; either version 2 of the License, or //
// (at your option) any later version. //
// //
// You may not change or alter any portion of this comment or credits //
// of supporting developers from this source code or any supporting //
// source code which is considered copyrighted (c) material of the //
// original comment or credit authors. //
// //
// This program 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 this program; if not, write to the Free Software //
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA //
// ------------------------------------------------------------------------ //
// Author: Kazumi Ono (AKA onokazu) //
// URL: http://www.myweb.ne.jp/, http://www.xoops.org/, http://jp.xoops.org/ //
// Project: The XOOPS Project //
// ------------------------------------------------------------------------- //
if ( !is_object($xoopsUser) || !is_object($xoopsModule) || !$xoopsUser->isAdmin($xoopsModule->mid()) ) {
exit("Access Denied");
} else {
$op = 'list';
if (isset($_POST)) {
foreach ( $_POST as $k => $v ) {
${$k} = $v;
}
}
if (isset($_GET['op'])) {
$op = trim($_GET['op']);
}
if (isset($_GET['image_id'])) {
$image_id = intval($_GET['image_id']);
}
if (isset($_GET['imgcat_id'])) {
$imgcat_id = intval($_GET['imgcat_id']);
}
if ($op == 'list') {
$imgcat_handler = xoops_gethandler('imagecategory');
$imagecategorys =& $imgcat_handler->getObjects();
xoops_cp_header();
echo '<h4 style="text-align:left">'._IMGMANAGER.'</h4><ul>';
$catcount = count($imagecategorys);
$image_handler =& xoops_gethandler('image');
for ($i = 0; $i < $catcount; $i++) {
$count = $image_handler->getCount(new Criteria('imgcat_id', $imagecategorys[$i]->getVar('imgcat_id')));
echo '<li>'.$imagecategorys[$i]->getVar('imgcat_name').' ('.sprintf(_NUMIMAGES, '<b>'.$count.'</b>').') [<a href="admin.php?fct=images&op=listimg&imgcat_id='.$imagecategorys[$i]->getVar('imgcat_id').'">'._LIST.'</a>] [<a href="admin.php?fct=images&op=editcat&imgcat_id='.$imagecategorys[$i]->getVar('imgcat_id').'">'._EDIT.'</a>]';
if ($imagecategorys[$i]->getVar('imgcat_type') == 'C') {
echo ' [<a href="admin.php?fct=images&op=delcat&imgcat_id='.$imagecategorys[$i]->getVar('imgcat_id').'">'._DELETE.'</a>]';
}
echo '</li>';
}
echo '</ul>';
include_once XOOPS_ROOT_PATH.'/class/xoopsformloader.php';
if (!empty($catcount)) {
$form = new XoopsThemeForm(_ADDIMAGE, 'image_form', 'admin.php');
$form->setExtra('enctype="multipart/form-data"');
$form->addElement(new XoopsFormText(_IMAGENAME, 'image_nicename', 50, 255), true);
$select = new XoopsFormSelect(_IMAGECAT, 'imgcat_id');
$select->addOptionArray($imgcat_handler->getList());
$form->addElement($select, true);
$form->addElement(new XoopsFormFile(_IMAGEFILE, 'image_file', 5000000));
$form->addElement(new XoopsFormText(_IMGWEIGHT, 'image_weight', 3, 4, 0));
$form->addElement(new XoopsFormRadioYN(_IMGDISPLAY, 'image_display', 1, _YES, _NO));
$form->addElement(new XoopsFormHidden('op', 'addfile'));
$form->addElement(new XoopsFormHidden('fct', 'images'));
$form->addElement(new XoopsFormButton('', 'img_button', _SUBMIT, 'submit'));
$form->display();
}
$form = new XoopsThemeForm(_MD_ADDIMGCAT, 'imagecat_form', 'admin.php');
$form->addElement(new XoopsFormText(_MD_IMGCATNAME, 'imgcat_name', 50, 255), true);
$form->addElement(new XoopsFormSelectGroup(_MD_IMGCATRGRP, 'readgroup', true, XOOPS_GROUP_ADMIN, 5, true));
$form->addElement(new XoopsFormSelectGroup(_MD_IMGCATWGRP, 'writegroup', true, XOOPS_GROUP_ADMIN, 5, true));
$form->addElement(new XoopsFormText(_IMGMAXSIZE, 'imgcat_maxsize', 10, 10, 50000));
$form->addElement(new XoopsFormText(_IMGMAXWIDTH, 'imgcat_maxwidth', 3, 4, 120));
$form->addElement(new XoopsFormText(_IMGMAXHEIGHT, 'imgcat_maxheight', 3, 4, 120));
$form->addElement(new XoopsFormText(_MD_IMGCATWEIGHT, 'imgcat_weight', 3, 4, 0));
$form->addElement(new XoopsFormRadioYN(_MD_IMGCATDISPLAY, 'imgcat_display', 1, _YES, _NO));
$storetype = new XoopsFormRadio(_MD_IMGCATSTRTYPE.'<br /><span style="color:#ff0000;">'._MD_STRTYOPENG.'</span>', 'imgcat_storetype', 'file');
$storetype->addOptionArray(array('file' => _MD_ASFILE, 'db' => _MD_INDB));
$form->addElement($storetype);
$form->addElement(new XoopsFormHidden('op', 'addcat'));
$form->addElement(new XoopsFormHidden('fct', 'images'));
$form->addElement(new XoopsFormButton('', 'imgcat_button', _SUBMIT, 'submit'));
$form->display();
xoops_cp_footer();
exit();
}
if ($op == 'listimg') {
$imgcat_id = intval($imgcat_id);
if ($imgcat_id <= 0) {
redirect_header('admin.php?fct=images',1);
}
$imgcat_handler = xoops_gethandler('imagecategory');
$imagecategory =& $imgcat_handler->get($imgcat_id);
if (!is_object($imagecategory)) {
redirect_header('admin.php?fct=images',1);
}
$image_handler = xoops_gethandler('image');
xoops_cp_header();
echo '<a href="admin.php?fct=images">'. _MD_IMGMAIN .'</a> <span style="font-weight:bold;">»»</span> '.$imagecategory->getVar('imgcat_name').'<br /><br />';
$criteria = new Criteria('imgcat_id', $imgcat_id);
$imgcount = $image_handler->getCount($criteria);
$start = isset($_GET['start']) ? intval($_GET['start']) : 0;
$criteria->setStart($start);
$criteria->setLimit(20);
$images =& $image_handler->getObjects($criteria, true, false);
echo '<form action="admin.php" method="post">';
foreach (array_keys($images) as $i) {
echo '<table width="100%" class="outer"><tr><td width="30%" rowspan="6">';
if ($imagecategory->getVar('imgcat_storetype') == 'db') {
echo '<img src="'.XOOPS_URL.'/image.php?id='.$i.'" alt="" />';
} else {
echo '<img src="'.XOOPS_UPLOAD_URL.'/'.$images[$i]->getVar('image_name').'" alt="" />';
}
echo '</td><td class="head">'._IMAGENAME,'</td><td class="even"><input type="hidden" name="image_id[]" value="'.$i.'" /><input type="text" name="image_nicename[]" value="'.$images[$i]->getVar('image_nicename', 'E').'" size="20" maxlength="255" /></td></tr><tr><td class="head">'._IMAGEMIME.'</td><td class="odd">'.$images[$i]->getVar('image_mimetype').'</td></tr><tr><td class="head">'._IMAGECAT.'</td><td class="even"><select name="imgcat_id[]" size="1">';
$list =& $imgcat_handler->getList(array(), null, null, $imagecategory->getVar('imgcat_storetype'));
foreach ($list as $value => $name) {
$sel = '';
if ($value == $images[$i]->getVar('imgcat_id')) {
$sel = ' selected="selected"';
}
echo '<option value="'.$value.'"'.$sel.'>'.$name.'</option>';
}
echo '</select></td></tr><tr><td class="head">'._IMGWEIGHT.'</td><td class="odd"><input type="text" name="image_weight[]" value="'.$images[$i]->getVar('image_weight').'" size="3" maxlength="4" /></td></tr><tr><td class="head">'._IMGDISPLAY.'</td><td class="even"><input type="checkbox" name="image_display[]" value="1"';
if ($images[$i]->getVar('image_display') == 1) {
echo ' checked="checked"';
}
echo ' /></td></tr><tr><td class="head"> </td><td class="odd"><a href="admin.php?fct=images&op=delfile&image_id='.$i.'">'._DELETE.'</a></td></tr></table><br />';
}
if ($imgcount > 0) {
if ($imgcount > 20) {
include_once XOOPS_ROOT_PATH.'/class/pagenav.php';
$nav = new XoopsPageNav($imgcount, 20, $start, 'start', 'fct=images&op=listimg&imgcat_id='.$imgcat_id);
echo '<div text-align="right">'.$nav->renderNav().'</div>';
}
echo '<div style="text-align:center;"><input type="hidden" name="op" value="save" /><input type="hidden" name="fct" value="images" /><input type="submit" name="submit" value="'._SUBMIT.'" /></div></form>';
}
xoops_cp_footer();
exit();
}
if ($op == 'save') {
$count = count($image_id);
if ($count > 0) {
$image_handler =& xoops_gethandler('image');
$error = array();
for ($i = 0; $i < $count; $i++) {
$image =& $image_handler->get($image_id[$i]);
if (!is_object($image)) {
$error[] = sprintf(_FAILGETIMG, $image_id[$i]);
continue;
}
$image_display[$i] = empty($image_display[$i]) ? 0 : 1;
$image->setVar('image_display', $image_display[$i]);
$image->setVar('image_weight', $image_weight[$i]);
$image->setVar('image_nicename', $image_nicename[$i]);
$image->setVar('imgcat_id', $imgcat_id[$i]);
if (!$image_handler->insert($image)) {
$error[] = sprintf(_FAILSAVEIMG, $image_id[$i]);
}
}
if (count($error) > 0) {
xoops_cp_header();
foreach ($error as $err) {
echo $err.'<br />';
}
xoops_cp_footer();
exit();
}
}
redirect_header('admin.php?fct=images',2,_MD_AM_DBUPDATED);
}
if ($op == 'addfile') {
$imgcat_handler =& xoops_gethandler('imagecategory');
$imagecategory =& $imgcat_handler->get(intval($imgcat_id));
if (!is_object($imagecategory)) {
redirect_header('admin.php?fct=images',1);
}
include_once XOOPS_ROOT_PATH.'/class/uploader.php';
$uploader = new XoopsMediaUploader(XOOPS_UPLOAD_PATH, array('image/gif', 'image/jpeg', 'image/pjpeg', 'image/x-png', 'image/png', 'image/bmp'), $imagecategory->getVar('imgcat_maxsize'), $imagecategory->getVar('imgcat_maxwidth'), $imagecategory->getVar('imgcat_maxheight'));
$uploader->setPrefix('img');
$err = array();
$ucount = count($_POST['xoops_upload_file']);
for ($i = 0; $i < $ucount; $i++) {
if ($uploader->fetchMedia($_POST['xoops_upload_file'][$i])) {
if (!$uploader->upload()) {
$err[] = $uploader->getErrors();
} else {
$image_handler =& xoops_gethandler('image');
$image =& $image_handler->create();
$image->setVar('image_name', $uploader->getSavedFileName());
$image->setVar('image_nicename', $image_nicename);
$image->setVar('image_mimetype', $uploader->getMediaType());
$image->setVar('image_created', time());
$image_display = empty($image_display) ? 0 : 1;
$image->setVar('image_display', $image_display);
$image->setVar('image_weight', $image_weight);
$image->setVar('imgcat_id', $imgcat_id);
if ($imagecategory->getVar('imgcat_storetype') == 'db') {
$fp = @fopen($uploader->getSavedDestination(), 'rb');
$fbinary = @fread($fp, filesize($uploader->getSavedDestination()));
@fclose($fp);
$image->setVar('image_body', $fbinary, true);
@unlink($uploader->getSavedDestination());
}
if (!$image_handler->insert($image)) {
$err[] = sprintf(_FAILSAVEIMG, $image->getVar('image_nicename'));
}
}
} else {
$err[] = sprintf(_FAILFETCHIMG, $i);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -