XOOPS 2.5.6  Final
 All Classes Namespaces Files Functions Variables Pages
moduleadmin.php
Go to the documentation of this file.
1 <?php
18 {
19 
20  var $_itemButton = array();
21  var $_itemInfoBox = array();
22  var $_itemInfoBoxLine = array();
23  var $_itemConfigBoxLine = array();
24  var $_obj = array();
25 
29  function __construct()
30  {
31  //global $xoopsModule, $xoTheme;
32  global $xoopsModule;
33  $this->_obj =& $xoopsModule;
34  echo "<style type=\"text/css\" media=\"screen\">@import \"" . XOOPS_URL . "/Frameworks/moduleclasses/moduleadmin/css/admin.css\";</style>";
35  //$xoTheme->addStylesheet("Frameworks/moduleclasses/moduleadmin/css/admin.css");
36  $this -> loadLanguage();
37  }
38 
39  function getInfo()
40  {
41  $infoArray = array();
42  if (!isset($infoArray) or empty($infoArray)) {
43  $infoArray = array();
44  $infoArray['version'] = $this->getVersion();
45  $infoArray['releasedate'] = $this->getReleaseDate();
46  $infoArray['methods'] = $this->getClassMethods();
47  }
48  return $infoArray;
49  }
50 
55  function getVersion()
56  {
60  Include_once 'xoops_version.php';
62  return $version;
63  }
64 
69  function getReleaseDate()
70  {
74  Include_once 'xoops_version.php';
76  return $releasedate;
77  }
78 
84  function getClassMethods()
85  {
86  $myMethods = get_class_methods(__CLASS__);
87  return $myMethods;
88  }
89 
90  //******************************************************************************************************************
91  // loadLanguage
92  //******************************************************************************************************************
93  // Loaf the language file.
94  //******************************************************************************************************************
95  function loadLanguage() {
96  $language = $GLOBALS['xoopsConfig']['language'];
97  if ( !file_exists($fileinc = XOOPS_ROOT_PATH . "/Frameworks/moduleclasses/moduleadmin/language/{$language}/main.php" )){
98  if ( !file_exists($fileinc = XOOPS_ROOT_PATH . "/Frameworks/moduleclasses/moduleadmin/language/english/main.php" )){
99  return false;
100  }
101  }
102  $ret = include_once $fileinc;
103  return $ret;
104  }
105  //******************************************************************************************************************
106  // renderMenuIndex
107  //******************************************************************************************************************
108  // Creating a menu icon in the index
109  //******************************************************************************************************************
110  function renderMenuIndex()
111  {
112  $path = XOOPS_URL . "/modules/" . $this->_obj->getVar('dirname') . "/";
113  $pathsystem = XOOPS_URL . "/modules/system/";
114  $this->_obj->loadAdminMenu();
115  $ret = "<div class=\"rmmenuicon\">\n";
116  foreach (array_keys( $this->_obj->adminmenu) as $i) {
117  if ($this->_obj->adminmenu[$i]['link'] != 'admin/index.php'){
118  $ret .= "<a href=\"../" . $this->_obj->adminmenu[$i]['link'] . "\" title=\"" . $this->_obj->adminmenu[$i]['title'] . "\">";
119  $ret .= "<img src=\"" . $path . $this->_obj->adminmenu[$i]['icon']. "\" alt=\"" . $this->_obj->adminmenu[$i]['title'] . "\" />";
120  $ret .= "<span>" . $this->_obj->adminmenu[$i]['title'] . "</span>";
121  $ret .= "</a>";
122  }
123  }
124  if ($this->_obj->getInfo('help')) {
125  if (substr(XOOPS_VERSION, 0, 9) >= 'XOOPS 2.5'){
126  $ret .= "<a href=\"" . $pathsystem . "help.php?mid=" . $this->_obj->getVar('mid', 's') . "&amp;" . $this->_obj->getInfo('help') . "\" title=\"" . _AM_SYSTEM_HELP . "\">";
127  $ret .= "<img width=\"32px\" src=\"" . XOOPS_URL . "/Frameworks/moduleclasses/icons/32/help.png\" alt=\"" . _AM_SYSTEM_HELP . "\" /> ";
128  $ret .= "<span>" . _AM_SYSTEM_HELP . "</span>";
129  $ret .= "</a>";
130  }
131  }
132  $ret .= "</div>\n<div style=\"clear: both;\"></div>\n";
133  return $ret;
134  }
135  //******************************************************************************************************************
136  // renderButton
137  //******************************************************************************************************************
138  // Creating button
139  //******************************************************************************************************************
140  function renderButton($position = "right", $delimeter = "&nbsp;")
141  {
142  $path = XOOPS_URL . "/Frameworks/moduleclasses/icons/32/";
143  switch ($position)
144  {
145  default:
146  case "right":
147  $ret = "<div class=\"floatright\">\n";
148  break;
149 
150  case "left":
151  $ret = "<div class=\"floatleft\">\n";
152  break;
153 
154  case "center":
155  $ret = "<div class=\"aligncenter\">\n";
156  }
157  $ret .= "<div class=\"xo-buttons\">\n";
158  foreach (array_keys( $this -> _itemButton) as $i) {
159  $ret .= "<a class='ui-corner-all tooltip' href='" . $this -> _itemButton[$i]['link'] . "' title='" . $this -> _itemButton[$i]['title'] . "'>";
160  $ret .= "<img src='" . $path . $this -> _itemButton[$i]['icon'] . "' title='" . $this -> _itemButton[$i]['title'] . "' />" . $this -> _itemButton[$i]['title'] . ' ' . $this -> _itemButton[$i]['extra'];
161  $ret .= "</a>\n";
162  $ret .= $delimeter;
163  }
164  $ret .= "</div>\n</div>\n";
165  $ret .= "<br />&nbsp;<br /><br />";
166  return $ret;
167  }
168 
169  function addItemButton($title, $link, $icon = 'add', $extra = '')
170  {
171  $ret['title'] = $title;
172  $ret['link'] = $link;
173  $ret['icon'] = $icon . '.png';
174  $ret['extra'] = $extra;
175  $this -> _itemButton[] = $ret;
176  return true;
177 
178  }
179  //******************************************************************************************************************
180  // addConfigBoxLine
181  //******************************************************************************************************************
182  // $value: value
183  // $type: type of config: 1- "default": Just a line with value.
184  // 2- "folder": check if this is an folder.
185  // 3- "chmod": check if this is the good chmod.
186  // For this type ("chmod"), the value is an array: array(path, chmod)
187  //******************************************************************************************************************
188  function addConfigBoxLine($value = '', $type = 'default')
189  {
190  $line = "";
191  $path = XOOPS_URL . "/Frameworks/moduleclasses/icons/16/";
192  switch ($type)
193  {
194  default:
195  case "default":
196  $line .= "<span>" . $value . "</span>";
197  break;
198 
199  case "folder":
200  if (!is_dir($value)){
201  $line .= "<span style='color : red; font-weight : bold;'>";
202  $line .= "<img src='" . $path . "off.png' >";
203  $line .= sprintf(_AM_MODULEADMIN_CONFIG_FOLDERKO, $value);
204  $line .= "</span>\n";
205  }else{
206  $line .= "<span style='color : green;'>";
207  $line .= "<img src='" . $path . "on.png' >";
208  $line .= sprintf(_AM_MODULEADMIN_CONFIG_FOLDEROK, $value);
209  $line .= "</span>\n";
210  }
211  break;
212 
213  case "chmod":
214  if (is_dir($value[0])){
215  if (substr(decoct(fileperms($value[0])),2) != $value[1]) {
216  $line .= "<span style='color : red; font-weight : bold;'>";
217  $line .= "<img src='" . $path . "off.png' >";
218  $line .= sprintf(_AM_MODULEADMIN_CONFIG_CHMOD, $value[0], $value[1], substr(decoct(fileperms($value[0])),2));
219  $line .= "</span>\n";
220  }else{
221  $line .= "<span style='color : green;'>";
222  $line .= "<img src='" . $path . "on.png' >";
223  $line .= sprintf(_AM_MODULEADMIN_CONFIG_CHMOD, $value[0], $value[1], substr(decoct(fileperms($value[0])),2));
224  $line .= "</span>\n";
225  }
226  }
227  break;
228  }
229  $this -> _itemConfigBoxLine[] = $line;
230  return true;
231  }
232  //******************************************************************************************************************
233  // renderIndex
234  //******************************************************************************************************************
235  // Creating an index
236  //******************************************************************************************************************
237  function renderIndex()
238  {
239  $ret = "<table>\n<tr>\n";
240  $ret .= "<td width=\"40%\">\n";
241  $ret .= $this -> renderMenuIndex();
242  $ret .= "</td>\n";
243  $ret .= "<td width=\"60%\">\n";
244  $ret .= $this -> renderInfoBox();
245  $ret .= "</td>\n";
246  $ret .= "</tr>\n";
247  // If you use a config label
248  if ($this->_obj->getInfo('min_php') || $this->_obj->getInfo('min_xoops') || !empty($this -> _itemConfigBoxLine)){
249  $ret .= "<tr>\n";
250  $ret .= "<td colspan=\"2\">\n";
251  $ret .= "<fieldset><legend class=\"label\">";
253  $ret .= "</legend>\n";
254 
255  // php version
256  $path = XOOPS_URL . "/Frameworks/moduleclasses/icons/16/";
257  if ($this->_obj->getInfo('min_php')){
258  if (phpversion() < $this->_obj->getInfo('min_php')){
259  $ret .= "<span style='color : red; font-weight : bold;'><img src='" . $path . "off.png' >" . sprintf(_AM_MODULEADMIN_CONFIG_PHP, $this->_obj->getInfo('min_php'), phpversion()) . "</span>\n";
260  }else{
261  $ret .= "<span style='color : green;'><img src='" . $path . "on.png' >" . sprintf(_AM_MODULEADMIN_CONFIG_PHP, $this->_obj->getInfo('min_php'), phpversion()) . "</span>\n";
262  }
263  $ret .= "<br />";
264  }
265 
266  // Database version
267  $path = XOOPS_URL . "/Frameworks/moduleclasses/icons/16/";
268  $dbarray=$this->_obj->getInfo('min_db');
269  if ($dbarray[XOOPS_DB_TYPE]) {
270  switch (XOOPS_DB_TYPE) {
271  case "mysql":
272  $dbCurrentVersion= mysql_get_server_info();
273  break;
274  case "mysqli":
275  $dbCurrentVersion = mysqli_get_server_info();
276  break;
277  case "pdo":
278  global $xoopsDB;
279  $dbCurrentVersion = $xoopsDB->getAttribute(PDO::ATTR_SERVER_VERSION);
280  break;
281  default:
282  $dbCurrentVersion = '0';
283  break;
284  }
285  $currentVerParts = explode('.', (string)$dbCurrentVersion);
286  $iCurrentVerParts = array_map('intval', $currentVerParts);
287  $dbRequiredVersion = $dbarray[XOOPS_DB_TYPE];
288  $reqVerParts = explode('.', (string)$dbRequiredVersion);
289  $iReqVerParts = array_map('intval', $reqVerParts);
290  $icount = $j = count($iReqVerParts);
291  $reqVer = $curVer = 0;
292  for ($i=0; $i<$icount; $i++) {
293  $j--;
294  $reqVer += $iReqVerParts[$i] * pow(10, $j);
295  if (isset($iCurrentVerParts[$i])) {
296  $curVer += $iCurrentVerParts[$i] * pow(10, $j);
297  } else {
298  $curVer = $curVer * pow(10, $j);
299  }
300  }
301  if ($reqVer > $curVer) {
302  $ret .= "<span style='color : red; font-weight : bold;'><img src='" . $path . "off.png' >" . sprintf(XOOPS_DB_TYPE.' '._AM_MODULEADMIN_CONFIG_DB, $dbRequiredVersion, $dbCurrentVersion) . "</span><br />\n";
303  } else {
304  $ret .= "<span style='color : green;'><img src='" . $path . "on.png' >" . sprintf(strtoupper(XOOPS_DB_TYPE).' '._AM_MODULEADMIN_CONFIG_DB, $dbRequiredVersion, $dbCurrentVersion) . "</span><br />\n";
305  }
306  }
307 
308  // xoops version
309  if ($this->_obj->getInfo('min_xoops')){
310  if (substr(XOOPS_VERSION, 6, strlen(XOOPS_VERSION)-6) < $this->_obj->getInfo('min_xoops')){
311  $ret .= "<span style='color : red; font-weight : bold;'><img src='" . $path . "off.png' >" . sprintf(_AM_MODULEADMIN_CONFIG_XOOPS, $this->_obj->getInfo('min_xoops'), substr(XOOPS_VERSION, 6, strlen(XOOPS_VERSION)-6)) . "</span>\n";
312  }else{
313  $ret .= "<span style='color : green;'><img src='" . $path . "on.png' >" . sprintf(_AM_MODULEADMIN_CONFIG_XOOPS, $this->_obj->getInfo('min_xoops'), substr(XOOPS_VERSION, 6, strlen(XOOPS_VERSION)-6)) . "</span>\n";
314  }
315  $ret .= "<br />";
316  }
317 
318  // ModuleAdmin version
319  if ($this->_obj->getInfo('min_admin')){
320  if ($this->getVersion() < $this->_obj->getInfo('min_admin')){
321  $ret .= "<span style='color : red; font-weight : bold;'><img src='" . $path . "off.png' >" . sprintf(_AM_MODULEADMIN_CONFIG_ADMIN, $this->_obj->getInfo('min_admin'), $this->getVersion()) . "</span>\n";
322  }else{
323  $ret .= "<span style='color : green;'><img src='" . $path . "on.png' >" . sprintf(_AM_MODULEADMIN_CONFIG_ADMIN, $this->_obj->getInfo('min_admin'), $this->getVersion()) . "</span>\n";
324  }
325  $ret .= "<br />";
326  }
327  if (!empty($this -> _itemConfigBoxLine)){
328  foreach (array_keys( $this -> _itemConfigBoxLine) as $i) {
329  $ret .= $this -> _itemConfigBoxLine[$i];
330  $ret .= "<br />";
331  }
332  }
333  $ret .= "</fieldset>\n";
334  $ret .= "</td>\n";
335  $ret .= "</tr>\n";
336  }
337  $ret .= "</table>\n";
338  return $ret;
339  }
340  //******************************************************************************************************************
341  // addInfoBox
342  //******************************************************************************************************************
343  // $title: title of an InfoBox
344  //******************************************************************************************************************
345  function addInfoBox($title)
346  {
347  $ret['title'] = $title;
348  $this -> _itemInfoBox[] = $ret;
349  return true;
350  }
351  //******************************************************************************************************************
352  // addInfoBoxLine
353  //******************************************************************************************************************
354  // $label: title of InfoBox Line
355  // $text:
356  // $type: type of config: 1- "default": Just a line with value.
357  // 2- "information": check if this is an folder.
358  // 3- "chmod": check if this is the good chmod.
359  // For this type ("chmod"), the value is an array: array(path, chmod)
360  //******************************************************************************************************************
361  function addInfoBoxLine($label, $text, $value = '', $color = 'inherit', $type = 'default')
362  {
363  $ret['label'] = $label;
364  $line = "";
365  switch ($type)
366  {
367  default:
368  case "default":
369  $line .= sprintf($text, "<span style='color : " . $color . "; font-weight : bold;'>" . $value . "</span>");
370  break;
371 
372  case "information":
373  $line .= $text;
374  break;
375  }
376  $ret['line'] = $line;
377  $this -> _itemInfoBoxLine[] = $ret;
378  return true;
379  }
380  function renderInfoBox()
381  {
382  $ret = "";
383  foreach (array_keys( $this -> _itemInfoBox) as $i) {
384  $ret .= "<fieldset><legend class=\"label\">";
385  $ret .= $this -> _itemInfoBox[$i]['title'];
386  $ret .= "</legend>\n";
387  foreach (array_keys( $this -> _itemInfoBoxLine) as $k) {
388  if ($this -> _itemInfoBoxLine[$k]['label'] == $this -> _itemInfoBox[$i]['title']){
389  $ret .= $this -> _itemInfoBoxLine[$k]['line'];
390  $ret .= "<br />";
391  }
392  }
393  $ret .= "</fieldset>\n";
394  $ret .= "<br/>\n";
395  }
396  return $ret;
397  }
398 
399 
400  function renderAbout($paypal = '', $logo_xoops = true)
401  {
402  $path = XOOPS_URL . "/Frameworks/moduleclasses/icons/32/";
403 
404  $ret = "<table>\n<tr>\n";
405  $ret .= "<td width=\"50%\">\n";
406  $date = explode('/',$this->_obj->getInfo('release_date'));
407  $author = explode(',',$this->_obj->getInfo('author'));
408  $nickname = explode(',',$this->_obj->getInfo('nickname'));
409  $release_date = formatTimestamp(mktime(0, 0, 0, $date[1], $date[2], $date[0]), 's');
410  $module_info = '<div id="about"><label>' . _AM_MODULEADMIN_ABOUT_DESCRIPTION . '</label><text>' . $this->_obj->getInfo("description") . '</text><br />
411  <label>' . _AM_MODULEADMIN_ABOUT_UPDATEDATE . '</label><text class="bold">' . formatTimestamp($this->_obj->getVar("last_update"),"m") . '</text><br />
412  <label>' . _AM_MODULEADMIN_ABOUT_MODULESTATUS . '</label><text>' . $this->_obj->getInfo("module_status") . '</text><br />
413  <label>' . _AM_MODULEADMIN_ABOUT_WEBSITE . '</label><text><a class="tooltip" href="http://' . $this->_obj->getInfo("module_website_url") . '" rel="external" title="'. $this->_obj->getInfo("module_website_name") . ' - ' . $this->_obj->getInfo("module_website_url") . '">
414  ' . $this->_obj->getInfo("module_website_name") . '</a></text></div>';
415  $ret .= "<table>\n<tr>\n<td width=\"100px\">\n";
416  $ret .= "<img src='" . XOOPS_URL . "/modules/" . $this->_obj->getVar('dirname') . "/" . $this->_obj->getInfo('image') . "' alt='" . $this->_obj->getVar('name') . "' style='float: left; margin-right: 10px;' />\n";
417  $ret .= "</td><td>\n";
418  $ret .= "<div style='margin-top: 1px; margin-bottom: 4px; font-size: 18px; line-height: 18px; color: #2F5376; font-weight: bold;'>\n";
419  $ret .= $this->_obj->getInfo('name') . " " . $this->_obj->getInfo('version') . " " . $this->_obj->getInfo('module_status') . " (" . $release_date . ")\n";
420  $ret .= "<br />\n";
421  $ret .= "</div>\n";
422  $ret .= "<div style='line-height: 16px; font-weight: bold;'>\n";
423  $ret .= "by ";
424  foreach (array_keys($author) as $i) {
425  $ret .= $author[$i];
426  if (isset($nickname[$i]) && $nickname[$i] !='') {
427  $ret .= " (" . $nickname[$i] . "), ";
428  }else{
429  $ret .= ", ";
430  }
431  }
432  $ret = substr($ret,0,-2);
433  $ret .= "</div>\n";
434  $ret .= "<div style='line-height: 16px;'>\n";
435  $ret.= "<a href=\"http://" . $this->_obj->getInfo('license_url'). "\" target=\"_blank\" >" . $this->_obj->getInfo('license'). "</a>\n";
436  $ret .= "<br />\n";
437  $ret .= "<a href=\"http://" . $this->_obj->getInfo('website') . "\" target=\"_blank\" >" . $this->_obj->getInfo('website') . "</a>\n";
438  $ret .= "<br />\n";
439  $ret .= "<br />\n";
440  if ($paypal != ''){
441  $ret .= '<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
442  <input type="hidden" name="cmd" value="_s-xclick">
443  <input type="hidden" name="hosted_button_id" value="' . $paypal . '">
444  <input type="image" src="https://www.paypal.com/en_US/i/btn/btn_donate_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
445  <img alt="" border="0" src="https://www.paypal.com/fr_FR/i/scr/pixel.gif" width="1" height="1">
446  </form>';
447  }
448  $ret .= "</div>\n";
449  $ret .= "</td>\n</tr>\n</table>\n";
451  $this -> addInfoBoxLine(_AM_MODULEADMIN_ABOUT_MODULEINFO, $module_info, '', '', 'information');
452  $ret .= $this -> renderInfoBox();
453  $ret .= "</td>\n";
454  $ret .= "<td width=\"50%\">\n";
455  $ret .= "<fieldset><legend class=\"label\">\n";
457  $ret .= "</legend><br/>\n";
458  $ret .= "<div class=\"txtchangelog\">\n";
459  $language = $GLOBALS['xoopsConfig']['language'];
460  if ( !is_file( XOOPS_ROOT_PATH . "/modules/" . $this->_obj->getVar("dirname") . "/language/" . $language . "/changelog.txt" ) ){
461  $language = 'english';
462  }
463  $language = empty($language) ? $GLOBALS['xoopsConfig']['language'] : $language;
464  $file = XOOPS_ROOT_PATH. "/modules/" . $this->_obj->getVar("dirname") . "/language/" . $language . "/changelog.txt";
465  if ( is_readable( $file ) ){
466  $ret .= utf8_encode(implode("<br />", file( $file ))) . "\n";
467  }else{
468  $file = XOOPS_ROOT_PATH. "/modules/" . $this->_obj->getVar("dirname") . "/docs/changelog.txt";
469  if ( is_readable( $file ) ){
470  $ret .= utf8_encode(implode("<br />", file( $file ))) . "\n";
471  }
472  }
473  $ret .= "</div>\n";
474  $ret .= "</fieldset>\n";
475  $ret .= "</td>\n";
476  $ret .= "</tr>\n";
477  $ret .= "</table>\n";
478  if ($logo_xoops == true){
479  $ret .= "<div align=\"center\">";
480  $ret .= "<a href=\"http://www.xoops.org\" target=\"_blank\"><img src=\"" . $path . "xoopsmicrobutton.gif\" alt=\"XOOPS\" title=\"XOOPS\"></a>";
481  $ret .= "</div>";
482  }
483  return $ret;
484  }
485 
486  function addNavigation($menu = '')
487  {
488  $ret = "";
489  $navigation = "";
490  $path = XOOPS_URL . "/modules/" . $this->_obj->getVar('dirname') . "/";
491  $this->_obj->loadAdminMenu();
492  foreach (array_keys( $this->_obj->adminmenu) as $i) {
493  if ($this->_obj->adminmenu[$i]['link'] == "admin/" . $menu){
494  $navigation .= $this->_obj->adminmenu[$i]['title'] . " | ";
495  $ret = "<div class=\"CPbigTitle\" style=\"background-image: url(" . $path . $this->_obj->adminmenu[$i]['icon'] . "); background-repeat: no-repeat; background-position: left; padding-left: 50px;\">
496  <strong>" . $this->_obj->adminmenu[$i]['title'] . "</strong></div><br />";
497  }else{
498  $navigation .= "<a href = '../" . $this->_obj->adminmenu[$i]['link'] . "'>" . $this->_obj->adminmenu[$i]['title'] . "</a> | ";
499  }
500  }
501  if (substr(XOOPS_VERSION, 0, 9) < 'XOOPS 2.5'){
502  $navigation .= "<a href = '../../system/admin.php?fct=preferences&op=showmod&mod=" . $this->_obj->getVar('mid') . "'>" . _MI_SYSTEM_ADMENU6 . "</a>";
503  $ret = $navigation . "<br /><br />" . $ret;
504  }
505  return $ret;
506  }
507 }
508 ?>