XOOPS  2.6.0
xoops_images.php
Go to the documentation of this file.
1 <?php
15 
17 if (!$helper) {
18  ob_end_flush();
19  return;
20 }
21 
22 require_once dirname(__FILE__).'/../../../../../../mainfile.php';
23 
25 $xoops->simpleHeader(false);
26 
27 $helper->loadLanguage('admin');
28 $helper->loadLanguage('tinymce');
29 $helper->loadLanguage('main');
30 
31 $op = Request::getCmd('op', 'list');
32 $imgcat_id = Request::getInt('imgcat_id', 0);
33 $start = Request::getInt('start', 0);
34 
35 $groups = $xoops->getUserGroups();
36 
38 switch ($op) {
39  case 'list':
40  default:
41  // Category Select form
42  $param = array('imgcat_id' => $imgcat_id, 'target' => null);
43  $form = $helper->getForm($param, 'category_imagemanager');
44  $xoopsTpl->assign('form_category', $form->render());
45 
46  if ($imgcat_id > 0) {
47  $imgcount = $helper->getHandlerImages()->countByCategory($imgcat_id);
48  $images = $helper->getHandlerImages()->getByCategory($imgcat_id, $start, $helper->getConfig('images_pager'), true);
49  $category = $helper->getHandlerCategories()->get($imgcat_id);
50 
51  foreach (array_keys($images) as $i) {
52  if ($category->getVar('imgcat_storetype') == 'db') {
53  $src = $helper->url("image.php?id=" . $images[$i]->getVar('image_id'));
54  } else {
55  $xoops_uploads_url = \XoopsBaseConfig::get('uploads-url');
56  $src = $xoops_uploads_url . '/' . $images[$i]->getVar('image_name');
57  }
58  $xoopsTpl->append('images', array(
59  'id' => $images[$i]->getVar('image_id'),
60  'nicename' => $images[$i]->getVar('image_nicename'),
61  'mimetype' => $images[$i]->getVar('image_mimetype'),
62  'src' => $src,
63  ));
64  }
65  }
66  break;
67 
68  case 'upload':
69  $category = $helper->getHandlerCategories()->get($imgcat_id);
70  if ($imgcat_id > 0 && is_object($category)) {
71  $perm_handler = $xoops->getHandlerGroupperm();
72  if ($perm_handler->checkRight('imgcat_write', $imgcat_id, $groups)) {
73  $xoops->simpleHeader();
74  $xoopsTpl = new XoopsTpl();
75  $obj = $helper->getHandlerImages()->create();
76  $obj->setVar('imgcat_id', $imgcat_id);
77  $form = $helper->getForm(array('obj' => $obj, 'target' => null), 'image_imagemanager');
78  $xoopsTpl->assign('form', $form->render());
79  }
80 
81  }
82  break;
83 
84  case 'save':
85  if (!$xoops->security()->check()) {
86  $xoops->redirect('xoops_images.php?imgcat_id=' . $imgcat_id, 3, implode('<br />', $xoops->security()->getErrors()));
87  }
88 
89  $mimetypes = array('image/gif', 'image/jpeg', 'image/pjpeg', 'image/x-png', 'image/png');
91 
92  $category = $helper->getHandlerCategories()->get($imgcat_id);
93  $image_id = Request::getInt('image_id', 0);
94  $obj = $helper->getHandlerImages()->create();
95 
96  $obj->setVar('image_nicename', Request::getString('image_nicename', ''));
97  $obj->setVar('image_created', time());
98  $obj->setVar('image_display', Request::getInt('image_display', 1));
99  $obj->setVar('image_weight', Request::getInt('image_weight', 0));
100  $obj->setVar('imgcat_id', $imgcat_id);
101 
102  $xoops_upload_file = Request::getArray('xoops_upload_file', array());
103 
104  $uploader = new XoopsMediaUploader(
105  \XoopsBaseConfig::get('uploads-path') . '/images',
106  $mimetypes,
107  $category->getVar('imgcat_maxsize'),
108  $category->getVar('imgcat_maxwidth'),
109  $category->getVar('imgcat_maxheight')
110  );
111  if ($uploader->fetchMedia($xoops_upload_file[0])) {
112  $uploader->setPrefix("img");
113  if (!$uploader->upload()) {
114  $msg[] = $uploader->getErrors();
115  $obj->setVar('image_name', 'blank.gif');
116  $obj->setVar('image_mimetype', 'image/gif');
117  } else {
118  $obj->setVar('image_mimetype', $uploader->getMediaType());
119  if ($category->getVar('imgcat_storetype') == 'db') {
120  $fp = @fopen($uploader->getSavedDestination(), 'rb');
121  $fbinary = @fread($fp, filesize($uploader->getSavedDestination()));
122  @fclose($fp);
123  $image_body = $fbinary;
124  } else {
125  $obj->setVar('image_name', 'images/' . $uploader->getSavedFileName());
126  }
127  }
128  }
129 
130  if ($image_id = $helper->getHandlerImages()->insert($obj)) {
131  if ($category->getVar('imgcat_storetype') == 'db') {
132  $imagebody = $helper->getHandlerImagesBody()->get($image_id);
133  if (!is_object($imagebody)) {
134  $imagebody = $helper->getHandlerImagesBody()->create();
135  $imagebody->setVar('image_id', $image_id);
136  }
137  $imagebody->setVar('image_body', $image_body);
138  if ($helper->getHandlerImagesBody()->insert($imagebody)) {
139  @unlink($uploader->getSavedDestination());
140  }
141  }
142  $xoops->redirect('xoops_images.php?imgcat_id=' . $imgcat_id, 2, implode('<br />', $msg));
143  }
144  echo $xoops->alert('error', $obj->getHtmlErrors());
145  break;
146 }
147 $xoopsTpl->display('module:images/images_tinymce.tpl');
148 $xoops->simpleFooter();
$i
Definition: dialog.php:68
static getInstance()
Definition: Xoops.php:160
$form
Definition: xoops_code.php:21
$xoops
static get($name)
static getHelper($dirname= 'system')
Definition: Helper.php:27
$groups
$imgcat_id
$helper
if(!is_object($module)||!$module->getVar('isactive')) $msg
Definition: groupperm.php:38
$image_id
Definition: image.php:30
$start
$op
$xoopsTpl
$mimetypes
const _AM_IMAGES_IMG_SAVE
Definition: admin.php:61