XOOPS  2.6.0
Admin.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 
12 namespace Xoops\Module;
13 
25 class Admin
26 {
32  public $tplModule = 'system';
33 
39  public $tplFile = array(
40  'index' => 'admin_index.tpl',
41  'about' => 'admin_about.tpl',
42  'infobox' => 'admin_infobox.tpl',
43  'bread' => 'admin_breadcrumb.tpl',
44  'button' => 'admin_buttons.tpl',
45  'tips' => 'admin_tips.tpl',
46  'nav' => 'admin_navigation.tpl',
47  );
48 
54  private $tips = '';
55 
61  private $itemButton = array();
62 
68  private $itemInfoBox = array();
69 
75  private $itemConfigBoxLine = array();
76 
82  private $bread = array();
83 
89  private $module = null;
90 
94  public function __construct()
95  {
97  $this->module = $xoops->module;
98  $xoops->theme()->addStylesheet('media/xoops/css/moduladmin.css');
99  }
100 
110  public function addBreadcrumbLink($title = '', $link = '', $home = false)
111  {
112  if ($title != '') {
113  $this->bread[] = array(
114  'link' => $link, 'title' => $title, 'home' => $home
115  );
116  }
117  }
118 
127  public function addConfigBoxLine($value = '', $type = 'default')
128  {
129  switch ($type) {
130  default:
131  case "default":
132  $this->itemConfigBoxLine[] = array('type' => $type, 'text' => $value);
133  break;
134 
135  case "folder":
136  if (!is_dir($value)) {
137  $this->itemConfigBoxLine[] = array(
138  'type' => 'error', 'text' => sprintf(\XoopsLocale::EF_FOLDER_DOES_NOT_EXIST, $value)
139  );
140  } else {
141  $this->itemConfigBoxLine[] = array(
142  'type' => 'accept', 'text' => sprintf(\XoopsLocale::SF_FOLDER_EXISTS, $value)
143  );
144  }
145  break;
146 
147  case "chmod":
148  if (is_dir($value[0])) {
149  if (substr(decoct(fileperms($value[0])), 2) != $value[1]) {
150  $this->itemConfigBoxLine[] = array(
151  'type' => 'error',
152  'text' => sprintf(
154  $value[0],
155  $value[1],
156  substr(decoct(fileperms($value[0])), 2)
157  )
158  );
159  } else {
160  $this->itemConfigBoxLine[] = array(
161  'type' => 'accept',
162  'text' => sprintf(
164  $value[0],
165  $value[1],
166  substr(decoct(fileperms($value[0])), 2)
167  )
168  );
169  }
170  }
171  break;
172 
173  case "extension":
175  if (is_array($value)) {
176  $text = $value[0];
177  $type = $value[1];
178  } else {
179  $text = $value;
180  $type = 'error';
181  }
182  if ($xoops->isActiveModule($text) == false) {
183  $this->itemConfigBoxLine[] = array(
184  'type' => $type, 'text' => sprintf(\XoopsLocale::EF_EXTENSION_IS_NOT_INSTALLED, $text)
185  );
186  } else {
187  $this->itemConfigBoxLine[] = array(
188  'type' => 'accept', 'text' => sprintf(\XoopsLocale::SF_EXTENSION_IS_INSTALLED, $text)
189  );
190  }
191  break;
192 
193  case "module":
195  if (is_array($value)) {
196  $text = $value[0];
197  $type = $value[1];
198  } else {
199  $text = $value;
200  $type = 'error';
201  }
202  if ($xoops->isActiveModule($text) == false) {
203  $this->itemConfigBoxLine[] = array(
204  'type' => $type, 'text' => sprintf(\XoopsLocale::F_MODULE_IS_NOT_INSTALLED, $text)
205  );
206  } else {
207  $this->itemConfigBoxLine[] = array(
208  'type' => 'accept', 'text' => sprintf(\XoopsLocale::F_MODULE_IS_INSTALLED, $text)
209  );
210  }
211  break;
212 
213  case "service":
215  if (is_array($value)) {
216  $text = $value[0];
217  $type = $value[1];
218  } else {
219  $text = $value;
220  $type = 'error';
221  }
222  if ($xoops->service($text)->isAvailable()) {
223  $this->itemConfigBoxLine[] = array(
224  'type' => 'accept', 'text' => sprintf(\XoopsLocale::SF_SERVICE_IS_INSTALLED, $text)
225  );
226  } else {
227  $this->itemConfigBoxLine[] = array(
228  'type' => $type, 'text' => sprintf(\XoopsLocale::EF_SERVICE_IS_NOT_INSTALLED, $text)
229  );
230  }
231  break;
232 
233  }
234  return true;
235  }
236 
246  public function addInfoBox($title, $type = 'default', $extra = '')
247  {
248  $ret['title'] = $title;
249  $ret['type'] = $type;
250  $ret['extra'] = $extra;
251  $this->itemInfoBox[] = $ret;
252  return true;
253  }
254 
264  public function addInfoBoxLine($text = '', $type = 'default', $color = 'inherit')
265  {
266  $ret = array();
267  $ret['text'] = $text;
268  $ret['color'] = $color;
269 
270  foreach (array_keys($this->itemInfoBox) as $i) {
271  if ($this->itemInfoBox[$i]['type'] == $type) {
272  $this->itemInfoBox[$i]['line'][] = $ret;
273  unset($ret);
274  }
275  }
276  return true;
277  }
278 
289  public function addItemButton($title, $link, $icon = 'add', $extra = '')
290  {
291  $ret['title'] = $title;
292  $ret['link'] = $link;
293  $ret['icon'] = $icon;
294  $ret['extra'] = $extra;
295  $this->itemButton[] = $ret;
296  return true;
297  }
298 
306  public function addTips($text = '')
307  {
308  $this->tips = $text;
309  }
310 
318  private function getTplPath($type = '')
319  {
320  return 'admin:' . $this->tplModule . '/' . $this->tplFile[$type];
321  }
322 
328  public function renderBreadcrumb()
329  {
331  $xoops->tpl()->assign('xo_admin_breadcrumb', $this->bread);
332  return $xoops->tpl()->fetch($this->getTplPath('bread'));
333  }
334 
340  public function displayBreadcrumb()
341  {
342  echo $this->renderBreadcrumb();
343  }
344 
353  public function renderButton($position = "floatright", $delimiter = "&nbsp;")
354  {
356 
357  $xoops->tpl()->assign('xo_admin_buttons_position', $position);
358  $xoops->tpl()->assign('xo_admin_buttons_delim', $delimiter);
359  $xoops->tpl()->assign('xo_admin_buttons', $this->itemButton);
360  return $xoops->tpl()->fetch($this->getTplPath('button'));
361  }
362 
371  public function displayButton($position = "floatright", $delimiter = "&nbsp;")
372  {
373  echo $this->renderButton($position, $delimiter);
374  }
375 
381  public function renderInfoBox()
382  {
384  $xoops->tpl()->assign('xo_admin_box', $this->itemInfoBox);
385  return $xoops->tpl()->fetch($this->getTplPath('infobox'));
386  }
387 
393  public function displayInfoBox()
394  {
395  echo $this->renderInfoBox();
396  }
397 
403  public function renderIndex()
404  {
406  $this->module->loadAdminMenu();
407  foreach (array_keys($this->module->adminmenu) as $i) {
409  $xoops->path(
410  "/media/xoops/images/icons/32/" . $this->module->adminmenu[$i]['icon']
411  )
412  )) {
413  $this->module->adminmenu[$i]['icon'] = $xoops->url(
414  "/media/xoops/images/icons/32/"
415  . $this->module->adminmenu[$i]['icon']
416  );
417  } else {
418  $this->module->adminmenu[$i]['icon'] = $xoops->url(
419  "/modules/" . $xoops->module->dirname()
420  . "/icons/32/" . $this->module->adminmenu[$i]['icon']
421  );
422  }
423  $xoops->tpl()->append('xo_admin_index_menu', $this->module->adminmenu[$i]);
424  }
425  if ($this->module->getInfo('help')) {
426  $help = array();
427  $help['link'] = '../system/help.php?mid=' . $this->module->getVar('mid', 's')
428  . "&amp;" . $this->module->getInfo('help');
429  $help['icon'] = $xoops->url("/media/xoops/images/icons/32/help.png");
430  $help['title'] = \XoopsLocale::HELP;
431  $xoops->tpl()->append('xo_admin_index_menu', $help);
432  }
433  $xoops->tpl()->assign('xo_admin_box', $this->itemInfoBox);
434 
435  // If you use a config label
436  if ($this->module->getInfo('min_php') || $this->module->getInfo('min_xoops')
437  || !empty($this->itemConfigBoxLine)
438  ) {
439  // PHP version
440  if ($this->module->getInfo('min_php')) {
441  if (0 >= version_compare(phpversion(), $this->module->getInfo('min_php'))) {
442  $this->addConfigBoxLine(
443  sprintf(
445  $this->module->getInfo('min_php'),
446  phpversion()
447  ),
448  'error'
449  );
450  } else {
451  $this->addConfigBoxLine(
452  sprintf(
454  $this->module->getInfo('min_php'),
455  phpversion()
456  ),
457  'accept'
458  );
459  }
460  }
461  // Database version
462  // @todo this needs a major rethink for Doctrine
463  // a specific driver might be required, but Doctrine obscures specific version
464  $dbarray = $this->module->getInfo('min_db');
465  if ($dbarray[\XoopsBaseConfig::get('db-type')]) {
466  switch (\XoopsBaseConfig::get('db-type')) {
467  case "mysql":
468  $dbCurrentVersion = mysql_get_server_info();
469  break;
470  case "mysqli":
471  $dbCurrentVersion = mysqli_get_server_info();
472  break;
473  case "pdo":
474  $dbCurrentVersion = $xoops->db()->getAttribute(PDO::ATTR_SERVER_VERSION);
475  break;
476  default:
477  $dbCurrentVersion = '0';
478  break;
479  }
480  $currentVerParts = explode('.', (string)$dbCurrentVersion);
481  $iCurrentVerParts = array_map('intval', $currentVerParts);
482  $dbRequiredVersion = $dbarray[\XoopsBaseConfig::get('db-type')];
483  $reqVerParts = explode('.', (string)$dbRequiredVersion);
484  $iReqVerParts = array_map('intval', $reqVerParts);
485  $icount = $j = count($iReqVerParts);
486  $reqVer = $curVer = 0;
487  for ($i = 0; $i < $icount; ++$i) {
488  $j--;
489  $reqVer += $iReqVerParts[$i] * pow(10, $j);
490  if (isset($iCurrentVerParts[$i])) {
491  $curVer += $iCurrentVerParts[$i] * pow(10, $j);
492  } else {
493  $curVer = $curVer * pow(10, $j);
494  }
495  }
496  if ($reqVer > $curVer) {
497  $this->addConfigBoxLine(
498  sprintf(
499  strtoupper(\XoopsBaseConfig::get('db-type')) . ' '
501  $dbRequiredVersion,
502  $dbCurrentVersion
503  ),
504  'error'
505  );
506  } else {
507  $this->addConfigBoxLine(
508  sprintf(
510  $dbRequiredVersion,
511  $dbCurrentVersion
512  ),
513  'accept'
514  );
515  }
516  }
517 
518  // xoops version
519  if ($this->module->getInfo('min_xoops')) {
520  $xoopsVersion = substr(\Xoops::VERSION, 6); // skip 'XOOPS ' prefix
521  if (version_compare($xoopsVersion, $this->module->getInfo('min_xoops')) >= 0) {
522  $this->addConfigBoxLine(
523  sprintf(
525  $this->module->getInfo('min_xoops'),
526  $xoopsVersion
527  ),
528  'error'
529  );
530  } else {
531  $this->addConfigBoxLine(
532  sprintf(
534  $this->module->getInfo('min_xoops'),
535  $xoopsVersion
536  ),
537  'accept'
538  );
539  }
540  }
541  $xoops->tpl()->assign('xo_admin_index_config', $this->itemConfigBoxLine);
542  }
543  return $xoops->tpl()->fetch($this->getTplPath('index'));
544  }
545 
551  public function displayIndex()
552  {
553  echo $this->renderIndex();
554  }
555 
563  public function renderNavigation($menu = '')
564  {
566  $ret = array();
567 
568  $this->module->loadAdminMenu();
569  foreach (array_keys($this->module->adminmenu) as $i) {
570  if ($this->module->adminmenu[$i]['link'] == "admin/" . $menu) {
572  $xoops->path("/media/xoops/images/icons/32/" . $this->module->adminmenu[$i]['icon'])
573  )) {
574  $this->module->adminmenu[$i]['icon'] = $xoops->url(
575  "/media/xoops/images/icons/32/"
576  . $this->module->adminmenu[$i]['icon']
577  );
578  } else {
579  $this->module->adminmenu[$i]['icon'] = $xoops->url(
580  "/modules/" . $xoops->module->dirname() . "/icons/32/"
581  . $this->module->adminmenu[$i]['icon']
582  );
583  }
584  $xoops->tpl()->assign('xo_sys_navigation', $this->module->adminmenu[$i]);
585  $ret[] = $xoops->tpl()->fetch($this->getTplPath('nav'));
586  }
587  }
588  return $ret;
589  }
590 
598  public function displayNavigation($menu = '')
599  {
600  $items = $this->renderNavigation($menu);
601  foreach ($items as $item) {
602  echo $item;
603  }
604  }
605 
611  public function renderTips()
612  {
614  $xoops->tpl()->assign('xo_admin_tips', $this->tips);
615  return $xoops->tpl()->fetch($this->getTplPath('tips'));
616  }
617 
623  public function displayTips()
624  {
625  echo $this->renderTips();
626  }
627 
635  public function renderAbout($logo_xoops = true)
636  {
638 
639  $date = explode('/', $this->module->getInfo('release_date'));
640  $author = explode(',', $this->module->getInfo('author'));
641  $nickname = explode(',', $this->module->getInfo('nickname'));
642  $release_date = \XoopsLocale::formatTimestamp(mktime(0, 0, 0, $date[1], $date[2], $date[0]), 's');
643 
644  $author_list = '';
645  foreach (array_keys($author) as $i) {
646  $author_list .= $author[$i];
647  if (isset($nickname[$i]) && $nickname[$i] != '') {
648  $author_list .= " (" . $nickname[$i] . "), ";
649  } else {
650  $author_list .= ", ";
651  }
652  }
653  $changelog = '';
654  $language = $xoops->getConfig('locale');
655  if (!is_file(
656  \XoopsBaseConfig::get('root-path') . "/modules/" . $this->module->getVar("dirname")
657  . "/locale/" . $language . "/changelog.txt"
658  )) {
659  $language = 'en_US';
660  }
661  $file = \XoopsBaseConfig::get('root-path') . "/modules/" . $this->module->getVar("dirname")
662  . "/locale/" . $language . "/changelog.txt";
663  if (is_readable($file)) {
664  $changelog = utf8_encode(implode("<br />", file($file))) . "\n";
665  } else {
666  $file = \XoopsBaseConfig::get('root-path') . "/modules/" . $this->module->getVar("dirname") . "/docs/changelog.txt";
667  if (is_readable($file)) {
668  $changelog = utf8_encode(implode("<br />", file($file))) . "\n";
669  }
670  }
671  $author_list = substr($author_list, 0, -2);
672 
673  $this->module->setInfo('release_date', $release_date);
674  $this->module->setInfo('author_list', $author_list);
675  if (is_array($this->module->getInfo('paypal'))) {
676  $this->module->setInfo('paypal', $this->module->getInfo('paypal'));
677  }
678  $this->module->setInfo('changelog', $changelog);
679  $xoops->tpl()->assign('module', $this->module);
680 
681  $this->addInfoBox(\XoopsLocale::MODULE_INFORMATION, 'info', 'id="xo-about"');
682  $this->addInfoBoxLine(
683  \XoopsLocale::C_DESCRIPTION . ' ' . $this->module->getInfo("description"),
684  'info'
685  );
686  $this->addInfoBoxLine(
687  \XoopsLocale::C_UPDATE_DATE . ' <span class="bold">'
688  . \XoopsLocale::formatTimestamp($this->module->getVar("last_update"), "m")
689  . '</span>',
690  'info'
691  );
692  $this->addInfoBoxLine(
693  \XoopsLocale::C_WEBSITE . ' <a class="xo-tooltip" href="http://'
694  . $this->module->getInfo("module_website_url")
695  . '" rel="external" title="'
696  . $this->module->getInfo("module_website_name") . ' - '
697  . $this->module->getInfo("module_website_url") . '">'
698  . $this->module->getInfo("module_website_name") . '</a>',
699  'info'
700  );
701 
702  $xoops->tpl()->assign('xoops_logo', $logo_xoops);
703  $xoops->tpl()->assign('xo_admin_box', $this->itemInfoBox);
704  return $xoops->tpl()->fetch($this->getTplPath('about'));
705  }
706 
714  public function displayAbout($logo_xoops = true)
715  {
716  echo $this->renderAbout($logo_xoops);
717  }
718 }
static formatTimestamp($time, $format= 'l', $timeoffset=null)
Definition: Abstract.php:289
$i
Definition: dialog.php:68
const C_UPDATE_DATE
Definition: en_US.php:193
static getInstance()
Definition: Xoops.php:160
if(!isset($xoops->paths[$path_type])) if($path_type== 'var') $file
Definition: browse.php:55
const C_WEBSITE
Definition: en_US.php:197
const SF_SERVICE_IS_INSTALLED
Definition: en_US.php:994
const EF_FOLDER_DOES_NOT_EXIST
Definition: en_US.php:250
$text
Definition: qrrender.php:27
const EF_SERVICE_IS_NOT_INSTALLED
Definition: en_US.php:268
$link
Definition: userinfo.php:84
const VERSION
Definition: Xoops.php:28
renderButton($position="floatright", $delimiter="&nbsp;")
Definition: Admin.php:353
const F_MINIMUM_DATABASE_VERSION_REQUIRED
Definition: en_US.php:423
const SF_FOLDER_EXISTS
Definition: en_US.php:987
const F_MINIMUM_PHP_VERSION_REQUIRED
Definition: en_US.php:424
addInfoBox($title, $type= 'default', $extra= '')
Definition: Admin.php:246
addInfoBoxLine($text= '', $type= 'default', $color= 'inherit')
Definition: Admin.php:264
const SF_EXTENSION_IS_INSTALLED
Definition: en_US.php:986
const F_MINIMUM_XOOPS_VERSION_REQUIRED
Definition: en_US.php:425
renderNavigation($menu= '')
Definition: Admin.php:563
const F_MODULE_IS_NOT_INSTALLED
Definition: en_US.php:428
$xoops
Definition: admin.php:25
getTplPath($type= '')
Definition: Admin.php:318
displayButton($position="floatright", $delimiter="&nbsp;")
Definition: Admin.php:371
addConfigBoxLine($value= '', $type= 'default')
Definition: Admin.php:127
addItemButton($title, $link, $icon= 'add', $extra= '')
Definition: Admin.php:289
$menu
static fileExists($file)
Definition: xoopsload.php:506
const EF_FOLDER_MUST_BE_WITH_CHMOD
Definition: en_US.php:252
const EF_EXTENSION_IS_NOT_INSTALLED
Definition: en_US.php:240
static get($name)
const C_DESCRIPTION
Definition: en_US.php:179
renderAbout($logo_xoops=true)
Definition: Admin.php:635
addBreadcrumbLink($title= '', $link= '', $home=false)
Definition: Admin.php:110
$type
Definition: misc.php:33
const MODULE_INFORMATION
Definition: en_US.php:841
$language
addTips($text= '')
Definition: Admin.php:306
const F_MODULE_IS_INSTALLED
Definition: en_US.php:427
displayNavigation($menu= '')
Definition: Admin.php:598
$j
Definition: help.php:169
displayAbout($logo_xoops=true)
Definition: Admin.php:714