1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10:
11:
12: namespace Xoops\Module;
13:
14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24:
25: class Admin
26: {
27: 28: 29: 30: 31:
32: public $tplModule = 'system';
33:
34: 35: 36: 37: 38:
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:
49: 50: 51: 52: 53:
54: private $tips = '';
55:
56: 57: 58: 59: 60:
61: private $itemButton = array();
62:
63: 64: 65: 66: 67:
68: private $itemInfoBox = array();
69:
70: 71: 72: 73: 74:
75: private $itemConfigBoxLine = array();
76:
77: 78: 79: 80: 81:
82: private $bread = array();
83:
84: 85: 86: 87: 88:
89: private $module = null;
90:
91: 92: 93:
94: public function __construct()
95: {
96: $xoops = \Xoops::getInstance();
97: $this->module = $xoops->module;
98: $xoops->theme()->addStylesheet('media/xoops/css/moduladmin.css');
99: }
100:
101: 102: 103: 104: 105: 106: 107: 108: 109:
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:
119: 120: 121: 122: 123: 124: 125: 126:
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(
153: \XoopsLocale::EF_FOLDER_MUST_BE_WITH_CHMOD,
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(
163: \XoopsLocale::EF_FOLDER_MUST_BE_WITH_CHMOD,
164: $value[0],
165: $value[1],
166: substr(decoct(fileperms($value[0])), 2)
167: )
168: );
169: }
170: }
171: break;
172:
173: case "extension":
174: $xoops = \Xoops::getInstance();
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":
194: $xoops = \Xoops::getInstance();
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":
214: $xoops = \Xoops::getInstance();
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:
237: 238: 239: 240: 241: 242: 243: 244: 245:
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:
255: 256: 257: 258: 259: 260: 261: 262: 263:
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:
279: 280: 281: 282: 283: 284: 285: 286: 287: 288:
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:
299: 300: 301: 302: 303: 304: 305:
306: public function addTips($text = '')
307: {
308: $this->tips = $text;
309: }
310:
311: 312: 313: 314: 315: 316: 317:
318: private function getTplPath($type = '')
319: {
320: return 'admin:' . $this->tplModule . '/' . $this->tplFile[$type];
321: }
322:
323: 324: 325: 326: 327:
328: public function renderBreadcrumb()
329: {
330: $xoops = \Xoops::getInstance();
331: $xoops->tpl()->assign('xo_admin_breadcrumb', $this->bread);
332: return $xoops->tpl()->fetch($this->getTplPath('bread'));
333: }
334:
335: 336: 337: 338: 339:
340: public function displayBreadcrumb()
341: {
342: echo $this->renderBreadcrumb();
343: }
344:
345: 346: 347: 348: 349: 350: 351: 352:
353: public function renderButton($position = "floatright", $delimiter = " ")
354: {
355: $xoops = \Xoops::getInstance();
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:
363: 364: 365: 366: 367: 368: 369: 370:
371: public function displayButton($position = "floatright", $delimiter = " ")
372: {
373: echo $this->renderButton($position, $delimiter);
374: }
375:
376: 377: 378: 379: 380:
381: public function renderInfoBox()
382: {
383: $xoops = \Xoops::getInstance();
384: $xoops->tpl()->assign('xo_admin_box', $this->itemInfoBox);
385: return $xoops->tpl()->fetch($this->getTplPath('infobox'));
386: }
387:
388: 389: 390: 391: 392:
393: public function displayInfoBox()
394: {
395: echo $this->renderInfoBox();
396: }
397:
398: 399: 400: 401: 402:
403: public function renderIndex()
404: {
405: $xoops = \Xoops::getInstance();
406: $this->module->loadAdminMenu();
407: foreach (array_keys($this->module->adminmenu) as $i) {
408: if (\XoopsLoad::fileExists($xoops->path("media/xoops/images/icons/32/" . $this->module->adminmenu[$i]['icon']))) {
409: $this->module->adminmenu[$i]['icon'] = $xoops->url("media/xoops/images/icons/32/" . $this->module->adminmenu[$i]['icon']);
410: } elseif (\XoopsLoad::fileExists($xoops->path("modules/" . $xoops->module->dirname() . "/assets/icons/32/" . $this->module->adminmenu[$i]['icon']))) {
411: $this->module->adminmenu[$i]['icon'] = $xoops->url("modules/" . $xoops->module->dirname() . "/assets/icons/32/" . $this->module->adminmenu[$i]['icon']);
412: } else {
413: $this->module->adminmenu[$i]['icon'] = $xoops->url("modules/" . $xoops->module->dirname() . "/icons/32/" . $this->module->adminmenu[$i]['icon']);
414: }
415: $xoops->tpl()->append('xo_admin_index_menu', $this->module->adminmenu[$i]);
416: }
417: if ($this->module->getInfo('help')) {
418: $help = array();
419: $help['link'] = '../system/help.php?mid=' . $this->module->getVar('mid', 's')
420: . "&" . $this->module->getInfo('help');
421: $help['icon'] = $xoops->url("/media/xoops/images/icons/32/help.png");
422: $help['title'] = \XoopsLocale::HELP;
423: $xoops->tpl()->append('xo_admin_index_menu', $help);
424: }
425: $xoops->tpl()->assign('xo_admin_box', $this->itemInfoBox);
426:
427:
428: if ($this->module->getInfo('min_php') || $this->module->getInfo('min_xoops')
429: || $this->module->getInfo('min_db') || !empty($this->itemConfigBoxLine)
430: ) {
431:
432: if ($this->module->getInfo('min_php')) {
433: if (0 >= version_compare(phpversion(), $this->module->getInfo('min_php'))) {
434: $this->addConfigBoxLine(
435: sprintf(
436: \XoopsLocale::F_MINIMUM_PHP_VERSION_REQUIRED,
437: $this->module->getInfo('min_php'),
438: phpversion()
439: ),
440: 'error'
441: );
442: } else {
443: $this->addConfigBoxLine(
444: sprintf(
445: \XoopsLocale::F_MINIMUM_PHP_VERSION_REQUIRED,
446: $this->module->getInfo('min_php'),
447: phpversion()
448: ),
449: 'accept'
450: );
451: }
452: }
453:
454:
455:
456:
457:
458:
459:
460:
461:
462:
463:
464:
465:
466:
467:
468:
469:
470:
471:
472: $dbarray = $this->module->getInfo('min_db');
473: if ($dbarray !== false) {
474: $dbCurrentPlatform = $xoops->db()->getDatabasePlatform()->getName();
475: $dbCurrentVersion = $xoops->db()->getWrappedConnection()->getServerVersion();
476: if (isset($dbarray[$dbCurrentPlatform])) {
477: $dbRequiredVersion = $dbarray[$dbCurrentPlatform];
478: if (0 >= version_compare($dbCurrentVersion, $dbRequiredVersion)) {
479: $this->addConfigBoxLine(
480: sprintf(
481: strtoupper(\XoopsBaseConfig::get('db-type')) . ' '
482: . \XoopsLocale::F_MINIMUM_DATABASE_VERSION_REQUIRED,
483: $dbRequiredVersion,
484: $dbCurrentVersion
485: ),
486: 'error'
487: );
488: } else {
489: $this->addConfigBoxLine(
490: sprintf(
491: strtoupper(\XoopsBaseConfig::get('db-type')) . ' ' . \XoopsLocale::F_MINIMUM_DATABASE_VERSION_REQUIRED,
492: $dbRequiredVersion,
493: $dbCurrentVersion
494: ),
495: 'accept'
496: );
497: }
498: } else {
499: $this->addConfigBoxLine(
500: sprintf(\XoopsLocale::EF_DATABASE_NOT_SUPPORTED, $dbCurrentPlatform),
501: 'error'
502: );
503: }
504: }
505:
506:
507: if ($this->module->getInfo('min_xoops')) {
508: $xoopsVersion = substr(\Xoops::VERSION, 6);
509: $xoopsCmpVersion = str_ireplace(['Alpha', 'Beta', 'RC'], ['0Alpha', '0Beta', '0RC'], $xoopsVersion);
510: if (0 >= version_compare($xoopsCmpVersion, $this->module->getInfo('min_xoops'))) {
511: $this->addConfigBoxLine(
512: sprintf(
513: \XoopsLocale::F_MINIMUM_XOOPS_VERSION_REQUIRED,
514: $this->module->getInfo('min_xoops'),
515: $xoopsVersion
516: ),
517: 'error'
518: );
519: } else {
520: $this->addConfigBoxLine(
521: sprintf(
522: \XoopsLocale::F_MINIMUM_XOOPS_VERSION_REQUIRED,
523: $this->module->getInfo('min_xoops'),
524: $xoopsVersion
525: ),
526: 'accept'
527: );
528: }
529: }
530: $xoops->tpl()->assign('xo_admin_index_config', $this->itemConfigBoxLine);
531: }
532: return $xoops->tpl()->fetch($this->getTplPath('index'));
533: }
534:
535: 536: 537: 538: 539:
540: public function displayIndex()
541: {
542: echo $this->renderIndex();
543: }
544:
545: 546: 547: 548: 549: 550: 551:
552: public function renderNavigation($menu = '')
553: {
554: $xoops = \Xoops::getInstance();
555: $ret = array();
556:
557: $this->module->loadAdminMenu();
558: foreach (array_keys($this->module->adminmenu) as $i) {
559: if ($this->module->adminmenu[$i]['link'] == "admin/" . $menu) {
560: if (\XoopsLoad::fileExists($xoops->path("media/xoops/images/icons/32/" . $this->module->adminmenu[$i]['icon']))) {
561: $this->module->adminmenu[$i]['icon'] = $xoops->url("media/xoops/images/icons/32/". $this->module->adminmenu[$i]['icon']);
562: } elseif (\XoopsLoad::fileExists($xoops->path("modules/" . $xoops->module->dirname() . "/assets/icons/32/" . $this->module->adminmenu[$i]['icon']))) {
563: $this->module->adminmenu[$i]['icon'] = $xoops->url("modules/" . $xoops->module->dirname() . "/assets/icons/32/" . $this->module->adminmenu[$i]['icon']);
564: } else {
565: $this->module->adminmenu[$i]['icon'] = $xoops->url("modules/" . $xoops->module->dirname() . "/icons/32/". $this->module->adminmenu[$i]['icon']);
566: }
567: $xoops->tpl()->assign('xo_sys_navigation', $this->module->adminmenu[$i]);
568: $ret[] = $xoops->tpl()->fetch($this->getTplPath('nav'));
569: }
570: }
571: return $ret;
572: }
573:
574: 575: 576: 577: 578: 579: 580:
581: public function displayNavigation($menu = '')
582: {
583: $items = $this->renderNavigation($menu);
584: foreach ($items as $item) {
585: echo $item;
586: }
587: }
588:
589: 590: 591: 592: 593:
594: public function renderTips()
595: {
596: $xoops = \Xoops::getInstance();
597: $xoops->tpl()->assign('xo_admin_tips', $this->tips);
598: return $xoops->tpl()->fetch($this->getTplPath('tips'));
599: }
600:
601: 602: 603: 604: 605:
606: public function displayTips()
607: {
608: echo $this->renderTips();
609: }
610:
611: 612: 613: 614: 615: 616: 617:
618: public function renderAbout($logo_xoops = true)
619: {
620: $xoops = \Xoops::getInstance();
621:
622: $date = explode('/', $this->module->getInfo('release_date'));
623: $author = explode(',', $this->module->getInfo('author'));
624: $nickname = explode(',', $this->module->getInfo('nickname'));
625: $release_date = \XoopsLocale::formatTimestamp(mktime(0, 0, 0, $date[1], $date[2], $date[0]), 's');
626:
627: $author_list = '';
628: foreach (array_keys($author) as $i) {
629: $author_list .= $author[$i];
630: if (isset($nickname[$i]) && $nickname[$i] != '') {
631: $author_list .= " (" . $nickname[$i] . "), ";
632: } else {
633: $author_list .= ", ";
634: }
635: }
636: $changelog = '';
637: $language = $xoops->getConfig('locale');
638: if (!is_file(
639: \XoopsBaseConfig::get('root-path') . "/modules/" . $this->module->getVar("dirname")
640: . "/locale/" . $language . "/changelog.txt"
641: )) {
642: $language = 'en_US';
643: }
644: $file = \XoopsBaseConfig::get('root-path') . "/modules/" . $this->module->getVar("dirname")
645: . "/locale/" . $language . "/changelog.txt";
646: if (is_readable($file)) {
647: $changelog = utf8_encode(implode("<br />", file($file))) . "\n";
648: } else {
649: $file = \XoopsBaseConfig::get('root-path') . "/modules/" . $this->module->getVar("dirname") . "/docs/changelog.txt";
650: if (is_readable($file)) {
651: $changelog = utf8_encode(implode("<br />", file($file))) . "\n";
652: }
653: }
654: $author_list = substr($author_list, 0, -2);
655:
656: $this->module->setInfo('release_date', $release_date);
657: $this->module->setInfo('author_list', $author_list);
658: if (is_array($this->module->getInfo('paypal'))) {
659: $this->module->setInfo('paypal', $this->module->getInfo('paypal'));
660: }
661: $this->module->setInfo('changelog', $changelog);
662: $xoops->tpl()->assign('module', $this->module);
663:
664: $this->addInfoBox(\XoopsLocale::MODULE_INFORMATION, 'info', 'id="xo-about"');
665: $this->addInfoBoxLine(
666: \XoopsLocale::C_DESCRIPTION . ' ' . $this->module->getInfo("description"),
667: 'info'
668: );
669: $this->addInfoBoxLine(
670: \XoopsLocale::C_UPDATE_DATE . ' <span class="bold">'
671: . \XoopsLocale::formatTimestamp($this->module->getVar("last_update"), "m")
672: . '</span>',
673: 'info'
674: );
675: $this->addInfoBoxLine(
676: \XoopsLocale::C_WEBSITE . ' <a class="xo-tooltip" href="http://'
677: . $this->module->getInfo("module_website_url")
678: . '" rel="external" title="'
679: . $this->module->getInfo("module_website_name") . ' - '
680: . $this->module->getInfo("module_website_url") . '">'
681: . $this->module->getInfo("module_website_name") . '</a>',
682: 'info'
683: );
684:
685: $xoops->tpl()->assign('xoops_logo', $logo_xoops);
686: $xoops->tpl()->assign('xo_admin_box', $this->itemInfoBox);
687: return $xoops->tpl()->fetch($this->getTplPath('about'));
688: }
689:
690: 691: 692: 693: 694: 695: 696:
697: public function displayAbout($logo_xoops = true)
698: {
699: echo $this->renderAbout($logo_xoops);
700: }
701: }
702: