XOOPS  2.6.0
imagemanager.php
Go to the documentation of this file.
1 <?php
2 /*
3  You may not change or alter any portion of this comment or credits
4  of supporting developers from this source code or any supporting source code
5  which is considered copyrighted (c) material of the original comment or credit authors.
6 
7  This program is distributed in the hope that it will be useful,
8  but WITHOUT ANY WARRANTY; without even the implied warranty of
9  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 */
11 
13 
24 include dirname(dirname(__DIR__)) . '/mainfile.php';
25 
28 $helper->loadLanguage('main');
29 $helper->loadLanguage('admin');
30 
31 $op = Request::getCmd('op', 'list');
32 $target = Request::getWord('target', '');
33 $imgcat_id = Request::getInt('imgcat_id', 0);
34 $start = Request::getInt('start', 0);
35 
36 if (empty($target)) {
37  exit('Target not set');
38 }
39 
40 $groups = $xoops->getUserGroups();
41 
42 $xoops->simpleHeader();
44 $xoopsTpl->assign('sitename', htmlspecialchars($xoops->getConfig('sitename'), ENT_QUOTES));
45 $xoopsTpl->assign('target', htmlspecialchars($target, ENT_QUOTES));
46 
47 switch ($op) {
48  case 'list':
49  default:
50  // Category Select form
51  $param = array('imgcat_id' => $imgcat_id, 'target' => $target);
52  $form = $helper->getForm($param, 'category_imagemanager');
53  $xoopsTpl->assign('form_category', $form->render());
54 
55  if ($imgcat_id > 0) {
56  $imgcount = $helper->getHandlerImages()->countByCategory($imgcat_id);
57  $images = $helper->getHandlerImages()->getByCategory($imgcat_id, $start, $helper->getConfig('images_pager'), true);
58  $category = $helper->getHandlerCategories()->get($imgcat_id);
59 
60  foreach (array_keys($images) as $i) {
61  if ($category->getVar('imgcat_storetype') == 'db') {
62  $lcode = '[img align=left id=' . $images[$i]->getVar('image_id') . ']' . $images[$i]->getVar('image_nicename') . '[/img]';
63  $code = '[img align=center id=' . $images[$i]->getVar('image_id') . ']' . $images[$i]->getVar('image_nicename') . '[/img]';
64  $rcode = '[img align=right id=' . $images[$i]->getVar('image_id') . ']' . $images[$i]->getVar('image_nicename') . '[/img]';
65  $src = $helper->url("image.php?id=" . $images[$i]->getVar('image_id'));
66  } else {
67  $lcode = '[img align=left]' . \XoopsBaseConfig::get('uploads-url') . '/' . $images[$i]->getVar('image_name') . '[/img]';
68  $code = '[img align=center]' . \XoopsBaseConfig::get('uploads-url') . '/' . $images[$i]->getVar('image_name') . '[/img]';
69  $rcode = '[img align=right]' . \XoopsBaseConfig::get('uploads-url') . '/' . $images[$i]->getVar('image_name') . '[/img]';
70  $src = \XoopsBaseConfig::get('uploads-url') . '/' . $images[$i]->getVar('image_name');
71  }
72  $xoopsTpl->append('images', array(
73  'id' => $images[$i]->getVar('image_id'),
74  'nicename' => $images[$i]->getVar('image_nicename'),
75  'mimetype' => $images[$i]->getVar('image_mimetype'),
76  'src' => $src,
77  'lxcode' => $lcode,
78  'xcode' => $code,
79  'rxcode' => $rcode
80  ));
81  }
82  }
83  break;
84 
85  case 'upload':
86  $category = $helper->getHandlerCategories()->get($imgcat_id);
87  if ($imgcat_id > 0 && is_object($category)) {
88  $perm_handler = $xoops->getHandlerGroupperm();
89  if ($perm_handler->checkRight('imgcat_write', $imgcat_id, $groups)) {
90  $xoops->simpleHeader();
91  $xoopsTpl = new XoopsTpl();
92  $obj = $helper->getHandlerImages()->create();
93  $obj->setVar('imgcat_id', $imgcat_id);
94  $form = $helper->getForm(array('obj' => $obj, 'target' => $target), 'image_imagemanager');
95  $xoopsTpl->assign('form', $form->render());
96  }
97  }
98  break;
99 
100  case 'save':
101  if (!$xoops->security()->check()) {
102  $xoops->redirect('imagemanager.php?imgcat_id=' . $imgcat_id, 3, implode('<br />', $xoops->security()->getErrors()));
103  }
104 
105  $mimetypes = array('image/gif', 'image/jpeg', 'image/pjpeg', 'image/x-png', 'image/png');
107 
108  $category = $helper->getHandlerCategories()->get($imgcat_id);
109  $image_id = Request::getInt('image_id', 0);
110  $obj = $helper->getHandlerImages()->create();
111 
112  $obj->setVar('image_nicename', Request::getString('image_nicename', ''));
113  $obj->setVar('image_created', time());
114  $obj->setVar('image_display', Request::getInt('image_display', 1));
115  $obj->setVar('image_weight', Request::getInt('image_weight', 0));
116  $obj->setVar('imgcat_id', $imgcat_id);
117 
118  $xoops_upload_file = Request::getArray('xoops_upload_file', array());
119 
120  $uploader = new XoopsMediaUploader(
121  \XoopsBaseConfig::get('uploads-url') . '/images',
122  $mimetypes,
123  $category->getVar('imgcat_maxsize'),
124  $category->getVar('imgcat_maxwidth'),
125  $category->getVar('imgcat_maxheight')
126  );
127  if ($uploader->fetchMedia($xoops_upload_file[0])) {
128  $uploader->setPrefix("img");
129  if (!$uploader->upload()) {
130  $msg[] = $uploader->getErrors();
131  $obj->setVar('image_name', 'blank.gif');
132  $obj->setVar('image_mimetype', 'image/gif');
133  } else {
134  $obj->setVar('image_mimetype', $uploader->getMediaType());
135  if ($category->getVar('imgcat_storetype') == 'db') {
136  $fp = @fopen($uploader->getSavedDestination(), 'rb');
137  $fbinary = @fread($fp, filesize($uploader->getSavedDestination()));
138  @fclose($fp);
139  $image_body = $fbinary;
140  } else {
141  $obj->setVar('image_name', 'images/' . $uploader->getSavedFileName());
142  }
143  }
144  }
145 
146  if ($image_id = $helper->getHandlerImages()->insert($obj)) {
147  if ($category->getVar('imgcat_storetype') == 'db') {
148  $imagebody = $helper->getHandlerImagesBody()->get($image_id);
149  if (!is_object($imagebody)) {
150  $imagebody = $helper->getHandlerImagesBody()->create();
151  $imagebody->setVar('image_id', $image_id);
152  }
153  $imagebody->setVar('image_body', $image_body);
154  if ($helper->getHandlerImagesBody()->insert($imagebody)) {
155  @unlink($uploader->getSavedDestination());
156  }
157  }
158  $xoops->redirect('imagemanager.php?target=' . $target . '&imgcat_id=' . $imgcat_id, 2, implode('<br />', $msg));
159  }
160  echo $xoops->alert('error', $obj->getHtmlErrors());
161  break;
162 }
163 $xoopsTpl->assign('xsize', 800);
164 $xoopsTpl->assign('ysize', 600);
165 $xoopsTpl->display('module:images/images_imagemanager.tpl');
166 $xoops->simpleFooter();
$i
Definition: dialog.php:68
static getInstance()
Definition: Xoops.php:160
$helper
static getInstance()
Definition: helper.php:34
$form
Definition: xoops_code.php:21
$imgcat_id
$xoops
exit
Definition: browse.php:104
$op
$xoopsTpl
static get($name)
if(empty($target)) $groups
if(!is_object($module)||!$module->getVar('isactive')) $msg
Definition: groupperm.php:38
$image_id
Definition: image.php:30
$start
$code
Definition: lostpass.php:48
$target
$mimetypes
const _AM_IMAGES_IMG_SAVE
Definition: admin.php:61