XOOPS  2.6.0
smilies.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 
25 include __DIR__ . '/header.php';
26 
27 // Call Header & ...
28 $xoops->header('admin:smilies/smilies_smilies.tpl');
29 $admin_page = new \Xoops\Module\Admin();
30 $admin_page->renderNavigation('smilies.php');
31 $xoops->theme()->addScript('media/xoops/xoops.js');
32 $xoops->theme()->addStylesheet('modules/system/css/admin.css');
33 
34 // Parameters
35 $nb_smilies = $helper->getConfig('smilies_pager');
36 $mimetypes = array('image/gif', 'image/jpeg', 'image/pjpeg', 'image/x-png', 'image/png');
37 $upload_size = 50000;
38 
40 
41 // Get $_GET, $_POST, ...
42 $op = Request::getCmd('op', 'list');
43 $start = Request::getInt('start', 0);
44 
45 switch ($op) {
46  case 'list':
47  default:
48  $admin_page->addTips(_AM_SMILIES_TIPS);
49  $admin_page->addItemButton(_AM_SMILIES_ADD, 'smilies.php?op=add', 'add');
50  $admin_page->renderTips();
51  $admin_page->renderButton();
52 
53  $smilies_count = $helper->getHandlerSmilies()->getCount();
54  $smilies = $helper->getHandlerSmilies()->getSmilies($start, $nb_smilies, false);
55 
56  $xoops->tpl()->assign('smilies', $smilies);
57  $xoops->tpl()->assign('smilies_count', $smilies_count);
58 
59  // Display Page Navigation
60  if ($smilies_count > $nb_smilies) {
61  $nav = new XoopsPageNav($smilies_count, $nb_smilies, $start, 'start', 'op=list');
62  $xoops->tpl()->assign('nav_menu', $nav->renderNav(2));
63  }
64  break;
65 
66  // New smilie
67  case 'add':
68  $admin_page->addItemButton(_AM_SMILIES_LIST, 'smilies.php', 'application-view-detail');
69  $admin_page->renderButton();
70  $xoops->tpl()->assign('info_msg', $xoops->alert('info', $info_msg, _AM_SMILIES_ALERT_INFO_TITLE));
71  // Create form
72  $obj = $helper->getHandlerSmilies()->create();
73  $form = $helper->getForm($obj, 'smilies');
74  $xoops->tpl()->assign('form', $form->render());
75  break;
76 
77  // Edit smilie
78  case 'edit':
79  $admin_page->addItemButton(_AM_SMILIES_LIST, 'smilies.php', 'application-view-detail');
80  $admin_page->renderButton();
81  $xoops->tpl()->assign('info_msg', $xoops->alert('info', $info_msg, _AM_SMILIES_ALERT_INFO_TITLE));
82  // Create form
83  $smiley_id = Request::getInt('smiley_id', 0);
84  $obj = $helper->getHandlerSmilies()->get($smiley_id);
85  $form = $helper->getForm($obj, 'smilies');
86  $xoops->tpl()->assign('form', $form->render());
87  break;
88 
89  // Save smilie
90  case 'save':
91  if (!$xoops->security()->check()) {
92  $xoops->redirect('smilies.php', 3, implode('<br />', $xoops->security()->getErrors()));
93  }
94 
95  $smiley_id = Request::getInt('smiley_id', 0);
96  if (isset($smiley_id) && $smiley_id !=0) {
97  $obj = $helper->getHandlerSmilies()->get($smiley_id);
98  } else {
99  $obj = $helper->getHandlerSmilies()->create();
100  }
101 
102  $obj->setVar('smiley_code', Request::getString('smiley_code', ''));
103  $obj->setVar('smiley_emotion', Request::getString('smiley_emotion', ''));
104  $obj->setVar('smiley_display', Request::getBool('smiley_display', true));
105  $obj->setVar('smiley_url', 'smilies/' . Request::getPath('smiley_url', ''));
106  $xoops_upload_file = Request::getArray('xoops_upload_file', array());
107 
108  $error_msg = '';
109  if ($_FILES[$xoops_upload_file[0]]['error'] === 0) {
110  $uploader = new XoopsMediaUploader(\XoopsBaseConfig::get('uploads-path') . '/smilies', $mimetypes, $upload_size, null, null);
111  if ($uploader->fetchMedia($xoops_upload_file[0])) {
112  $uploader->setPrefix('smil');
113  if (!$uploader->upload()) {
114  $error_msg .= $uploader->getErrors();
115  $obj->setVar('smiley_url', 'blank.gif');
116  } else {
117  $obj->setVar('smiley_url', 'smilies/' . $uploader->getSavedFileName());
118  }
119  }
120  }
121  if ($error_msg == '') {
122  if ($helper->getHandlerSmilies()->insert($obj)) {
123  $xoops->redirect('smilies.php', 2, _AM_SMILIES_SAVE);
124  }
125  $error_msg .= $obj->getHtmlErrors();
126  }
127  $admin_page->addItemButton(_AM_SMILIES_LIST, 'smilies.php', 'application-view-detail');
128  $admin_page->renderButton();
129  $xoops->tpl()->assign('info_msg', $xoops->alert('info', $info_msg, _AM_SMILIES_ALERT_INFO_TITLE));
130  $xoops->tpl()->assign('error_msg', $xoops->alert('error', $error_msg, _AM_SMILIES_ALERT_ERROR_TITLE));
131  $form = $helper->getForm($obj, 'smilies');
132  $xoops->tpl()->assign('form', $form->render());
133  break;
134 
135  //Del a smilie
136  case 'del':
137  $smiley_id = Request::getInt('smiley_id', 0);
138  $ok = Request::getInt('ok', 0);
139  $obj = $helper->getHandlerSmilies()->get($smiley_id);
140 
141  if ($ok == 1) {
142  if (!$xoops->security()->check()) {
143  $xoops->redirect('smilies.php', 3, implode(',', $xoops->security()->getErrors()));
144  }
145  $path_file = \XoopsBaseConfig::get('uploads-path') . '/' . $obj->getVar('smile_url');
146  if ($helper->getHandlerSmilies()->delete($obj)) {
147  if (is_file($path_file)) {
148  chmod($path_file, 0777);
149  unlink($path_file);
150  }
151  $xoops->redirect('smilies.php', 2, _AM_SMILIES_DELETED);
152  } else {
153  echo $xoops->alert('error', $obj->getHtmlErrors());
154  }
155  } else {
156  $smilies_img = ($obj->getVar('smiley_url')) ? $obj->getVar('smiley_url') : 'blank.gif';
157  echo $xoops->confirm(array(
158  'ok' => 1, 'smiley_id' => $smiley_id, 'op' => 'del'
159  ), \XoopsBaseConfig::get('url') . '/modules/smilies/admin/smilies.php', sprintf(_AM_SMILIES_SUREDEL) . '<br /><strong>' . $obj->getVar('smiley_emotion') . '</strong><br /><img src="' . \XoopsBaseConfig::get('uploads-url') . '/' . $smilies_img . '" alt="' . $obj->getVar('smiley_emotion') . '"><br />');
160  }
161  break;
162 
163  case 'smilies_update_display':
164  $smiley_id = Request::getInt('smiley_id', 0);
165  if ($smiley_id > 0) {
166  $obj = $helper->getHandlerSmilies()->get($smiley_id);
167  $old = $obj->getVar('smiley_display');
168  $obj->setVar('smiley_display', !$old);
169  if ($helper->getHandlerSmilies()->insert($obj)) {
170  exit;
171  }
172  echo $obj->getHtmlErrors();
173  }
174  break;
175 }
176 $xoops->footer();
const _AM_SMILIES_ALERT_INFO_MIMETYPES
Definition: admin.php:47
const _AM_SMILIES_ADD
Definition: admin.php:23
$admin_page
Definition: smilies.php:29
$nb_smilies
Definition: smilies.php:35
const _AM_SMILIES_LIST
Definition: admin.php:32
$form
Definition: xoops_code.php:21
exit
Definition: browse.php:104
$op
Definition: smilies.php:42
const _AM_SMILIES_ALERT_INFO_TITLE
Definition: admin.php:45
$upload_size
Definition: smilies.php:37
$xoops
Definition: admin.php:25
const _AM_SMILIES_TIPS
Definition: admin.php:50
$start
Definition: smilies.php:43
$info_msg
Definition: smilies.php:39
const _AM_SMILIES_SUREDEL
Definition: admin.php:39
static get($name)
const _AM_SMILIES_ALERT_ERROR_TITLE
Definition: admin.php:44
$mimetypes
Definition: smilies.php:36
$helper
const _AM_SMILIES_DELETED
Definition: admin.php:26
const _AM_SMILIES_SAVE
Definition: admin.php:38
const _AM_SMILIES_ALERT_INFO_MAXFILE
Definition: admin.php:46