XOOPS 2.5.6  Final
 All Classes Namespaces Files Functions Variables Pages
xoopsemotions.php
Go to the documentation of this file.
1 <?php
17 // load mainfile.php - start
18 $current_path = dirname(__FILE__);
19 if ( DIRECTORY_SEPARATOR != "/" ) {
20  $current_path = str_replace( DIRECTORY_SEPARATOR, "/", $current_path);
21 }
22 $xoops_root_path = substr($current_path, 0, strpos(strtolower($current_path), "/class/xoopseditor/tinymce/"));
23 include_once $xoops_root_path . "/mainfile.php";
24 if (!defined("XOOPS_ROOT_PATH")) { die("XOOPS root path not defined"); }
25 // load mainfile.php - end
26 
27 // get current filename
28 $current_file = basename(__FILE__);
29 
30 // load language definitions
31 xoops_loadLanguage("admin", "system");
32 xoops_loadLanguage("admin/smilies", "system");
33 xoops_loadLanguage("misc");
34 
35 // include system category definitions - start
36 include_once XOOPS_ROOT_PATH."/modules/system/constants.php";
37 
38 // check user/group
39 $groups = is_object( $GLOBALS["xoopsUser"] ) ? $GLOBALS["xoopsUser"]->getGroups() : array( XOOPS_GROUP_ANONYMOUS );
41 $admin = $gperm_handler->checkRight( 'system_admin', XOOPS_SYSTEM_SMILE, $groups );
42 
43 $op = '';
44 if (!empty($_GET['op'])) {
45  $op = trim( $_GET['op'] );
46 } elseif (!empty($_POST['op'])) {
47  $op = trim( $_POST['op'] );
48 }
49 
51 
52 if ( $admin && $op == 'SmilesAdd' ) {
53  if (!$GLOBALS['xoopsSecurity']->check()) {
54  redirect_header($current_file, 3, implode('<br />', $GLOBALS['xoopsSecurity']->getErrors()));
55  }
57  include_once XOOPS_ROOT_PATH.'/class/uploader.php';
58  $uploader = new XoopsMediaUploader(XOOPS_UPLOAD_PATH, array('image/gif', 'image/jpeg', 'image/pjpeg', 'image/x-png', 'image/png'), 100000, 120, 120);
59  $uploader->setPrefix('smil');
60  if ($uploader->fetchMedia($_POST['xoops_upload_file'][0])) {
61  if (!$uploader->upload()) {
62  $err = $uploader->getErrors();
63  } else {
64  $smile_url = $uploader->getSavedFileName();
65  $smile_code = $myts->stripSlashesGPC($_POST['smile_code']);
66  $smile_desc = $myts->stripSlashesGPC($_POST['smile_desc']);
67  $smile_display = intval($_POST['smile_display']) > 0 ? 1 : 0;
68  $newid = $db->genId($db->prefix('smilies')."_id_seq");
69  $sql = sprintf("INSERT INTO %s (id, code, smile_url, emotion, display) VALUES (%d, %s, %s, %s, %d)", $db->prefix('smiles'), $newid, $db->quoteString($smile_code), $db->quoteString($smile_url), $db->quoteString($smile_desc), $smile_display);
70  if (!$db->query($sql)) {
71  $err = 'Failed storing smiley data into the database';
72  }
73  }
74  } else {
75  $err = $uploader->getErrors();
76  }
77  if (!isset($err)) {
78  unset($_SESSION['XoopsEmotions']);
79  unset($_SESSION['XoopsEmotions_expire']);
81  } else {
83  }
84 }
85 
86 $time = time();
87 if ( !isset( $_SESSION['XoopsEmotions'] ) && @$_SESSION['XoopsEmotions_expire'] < $time ) {
88  $_SESSION['XoopsEmotions'] = $myts->getSmileys();
89  $_SESSION['XoopsEmotions_expire'] = $time + 300;
90 }
91 
92 //xoops_header(false);
93 echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">';
94 echo '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="' . _LANGCODE . '" lang="' . _LANGCODE . '">';
95 echo '<head>';
96 echo '<meta http-equiv="content-type" content="text/html; charset=' . _CHARSET . '" />';
97 echo '<meta http-equiv="content-language" content="' . _LANGCODE . '" />';
98 ?>
99 <head>
100  <title>{#xoopsemotions_dlg.title}</title>
101  <script type="text/javascript" src="../../tiny_mce_popup.js"></script>
102  <script type="text/javascript" src="../../utils/mctabs.js"></script>
103  <script type="text/javascript" src="../../utils/form_utils.js"></script>
104  <script type="text/javascript" src="../../utils/validate.js"></script>
105  <script type="text/javascript" src="js/xoopsemotions.js"></script>
106  <link href="<?php echo xoops_getcss($xoopsConfig['theme_set']); ?>" rel="stylesheet" type="text/css" />
107  <link href="css/xoopsemotions.css" rel="stylesheet" type="text/css" />
108  <base target="_self" />
109 </head>
110 <body>
111 
112 <?php
113 if ( !$_SESSION['XoopsEmotions'] && !$admin) {
114  echo "<div class='xoopsEmotions'>";
115  echo "<div>{#xoopsemotions_dlg.error_noemotions}</div>";
116  echo "</div>";
117  echo "<div class='mceActionPanel floatright'>";
118  echo "<input type='button' id='cancel' name='cancel' value='{#cancel}' onclick='tinyMCEPopup.close();' />";
119  echo "</div>";
120  xoops_footer();
121  exit();
122 }
123 ?>
124 
125 <div class="tabs">
126  <ul>
127  <li id="tab_emotionsbrowser" class="current"><span><a href="javascript:mcTabs.displayTab('tab_emotionsbrowser','emotionsbrowser_panel');" onmousedown="return false;">{#xoopsemotions_dlg.tab_emotionsbrowser}</a></span></li>
128  <?php
129  if ($admin) {
130  echo '<li id="tab_emotionsadmin"><span><a href="javascript:mcTabs.displayTab(\'tab_emotionsadmin\',\'emotionsadmin_panel\');" onmousedown="return false;">{#xoopsemotions_dlg.tab_emotionsadmin}</a></span></li>';
131  }
132  ?>
133  </ul>
134 </div>
135 
136 <div class="panel_wrapper">
137  <div id="emotionsbrowser_panel" class="panel current" style="overflow:auto;">
138  <?php
139  if ( $smiles = $_SESSION['XoopsEmotions'] ) {
140  echo "<div><strong>" . _MSC_CLICKASMILIE . "</strong></div>";
141  echo "<div class='xoopsEmotions'>";
142  $count = count($smiles);
143 
144  for ($i = 0; $i < $count; $i++) {
145  if ( $op == '' ) {
146  if ( $smiles[$i]['display'] ) {
147  echo '<img class="xoopsEmotions" onclick="XoopsemotionsDialog.insert(this);" src="' . XOOPS_UPLOAD_URL . '/' . $smiles[$i]['smile_url'] . '" alt="' . $myts->htmlspecialchars($smiles[$i]['emotion']) . '" title="' . $myts->htmlspecialchars($smiles[$i]['emotion']) . '" />';
148  }
149  } else {
150  echo '<img class="xoopsEmotions" onclick="XoopsemotionsDialog.insert(this);" src="' . XOOPS_UPLOAD_URL . '/' . $smiles[$i]['smile_url'] . '" alt="' . $myts->htmlspecialchars($smiles[$i]['emotion']) . '" title="' . $myts->htmlspecialchars($smiles[$i]['emotion']) . '" />';
151  }
152  }
153  if ( $op == '' ) {
154  echo '<div class="xoopsEmotions">';
155  echo '<a class="xoopsEmotions" href="' . $current_file . '?op=' . _MORE . '">' . _MORE . '</a>';
156  echo '</div>';
157  }
158  echo "</div>";
159  } else {
160  echo "<div>{#xoopsemotions_dlg.error_noemotions}</div>";
161  }
162  ?>
163  <div class="mceActionPanel floatright">
164  <input type="button" id="cancel" name="cancel" value="{#cancel}" onclick="tinyMCEPopup.close();" />
165  </div>
166  </div>
167 
168  <div id="emotionsadmin_panel" class="panel" style="overflow:auto;">
169  <?php
170  if ($admin) {
171  include_once XOOPS_ROOT_PATH.'/class/xoopsformloader.php';
172 
173  $smile_form = new XoopsThemeForm(_AM_ADDSMILE, 'smileform', $current_file, 'post', true);
174  $smile_form->setExtra('enctype="multipart/form-data"');
175  $smile_form->addElement(new XoopsFormText(_AM_SMILECODE, 'smile_code', 26, 25, ''), true);
176  $smile_form->addElement(new XoopsFormText(_AM_SMILEEMOTION, 'smile_desc', 26, 25, ''), true);
177  $smile_select = new XoopsFormFile('', 'smile_url', 5000000);
178  $smile_label = new XoopsFormLabel('', '<img src="'.XOOPS_UPLOAD_URL.'/blank.gif" alt="" />');
179  $smile_tray = new XoopsFormElementTray(_IMAGEFILE.':', '&nbsp;');
180  $smile_tray->addElement($smile_select);
181  $smile_tray->addElement($smile_label);
182  $smile_form->addElement($smile_tray);
183  $smile_form->addElement(new XoopsFormRadioYN(_AM_DISPLAYF, 'smile_display', 1));
184  $smile_form->addElement(new XoopsFormHidden('id', ''));
185  $smile_form->addElement(new XoopsFormHidden('op', 'SmilesAdd'));
186  $smile_form->addElement(new XoopsFormHidden('fct', 'smilies'));
187  $smile_form->addElement(new XoopsFormButton('', 'submit', _SUBMIT, 'submit'));
188 
189  $smile_form->display();
190  }
191  ?>
192  <div class="mceActionPanel floatright">
193  <input type="button" id="cancel" name="cancel" value="{#cancel}" onclick="tinyMCEPopup.close();" />
194  </div>
195  </div>
196 
197 </div>
198 <?php xoops_footer(); ?>