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 Xmf\Module;
13:
14: /**
15: * Xmf\Module\Admin provides helpful methods for module administration
16: * uses.
17: *
18: * Xmf\Module\Admin also provides a method compatible subset of the
19: * Xoops 2.6 ModuleAdmin class for use in transition from 2.5 to 2.6
20: *
21: * @category Xmf\Module\Admin
22: * @package Xmf
23: * @author Richard Griffith <richard@geekwright.com>
24: * @copyright 2011-2013 XOOPS Project (http://xoops.org)
25: * @license GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html)
26: * @version Release: 1.0
27: * @link http://xoops.org
28: * @since 1.0
29: */
30: class Admin
31: {
32:
33: /**
34: * The real ModuleAdmin object
35: *
36: * @var object
37: */
38: private static $ModuleAdmin = null;
39: private $version26 = null;
40: private $lastInfoBoxTitle = null;
41: private static $paypal = '';
42:
43: /**
44: * Constructor
45: */
46: private function __construct()
47: {
48: $this->version26 = self::is26();
49: }
50:
51: /**
52: * Retrieve a module admin instance
53: *
54: * If we are on 2.6 this will be the a XoopsModuleAdmin instance.
55: * Older systems with the Frameworks based admin class will get
56: * an instance of this class which provides compatible methods
57: * built from the old Frameworks version.
58: *
59: * **Always use this to get the ModuleAdmin instance if you use
60: * anything (even the static methods) of this class.**
61: *
62: * @return object a ModuleAdmin instance.
63: *
64: * @since 1.0
65: */
66: public static function getInstance()
67: {
68:
69: static $instance;
70:
71: if ($instance === null) {
72: if (class_exists('\Xoops\Module\Admin', true)) {
73: $instance = new \Xoops\Module\Admin;
74: self::$ModuleAdmin = $instance;
75: } else {
76: \Xmf\Loader::loadFile(
77: \XoopsBaseConfig::get('root-path') .
78: '/Frameworks/moduleclasses/moduleadmin/moduleadmin.php'
79: );
80: self::$ModuleAdmin = new \ModuleAdmin;
81: $instance = new \Xmf\Module\Admin;
82: }
83:
84: }
85:
86: return $instance;
87:
88: }
89:
90: /**
91: * Are we in a 2.6 environment?
92: *
93: * just to help with other admin things than ModuleAdmin
94: *
95: * not part of 2.6 module admin
96: *
97: * @return bool true if we are in a 2.6 environment
98: */
99: public static function is26()
100: {
101: return class_exists('\Xoops', false);
102: }
103:
104: /**
105: * Get an appropriate imagePath for menu.php use.
106: *
107: * just to help with other admin things than ModuleAdmin
108: *
109: * not part of 2.6 module admin
110: *
111: * @param string $image icon name to prepend with path
112: *
113: * @return string true if we are in a 2.6 environment
114: */
115: public static function menuIconPath($image)
116: {
117: if (self::is26()) {
118: return($image);
119: } else {
120: $path='../../Frameworks/moduleclasses/icons/32/';
121:
122: return($path.$image);
123: }
124: }
125:
126: /**
127: * Add config line
128: *
129: * @param string $value message to include in config box
130: * @param string $type type of line to add
131: *
132: * @return bool
133: */
134: public function addConfigBoxLine($value = '', $type = 'default')
135: {
136: return self::$ModuleAdmin->addConfigBoxLine($value, $type);
137: }
138:
139: /**
140: * Add Info box
141: *
142: * @param string $title info box title
143: * @param string $type for compatibility only
144: * @param string $extra for compatibility only
145: *
146: * @return bool
147: */
148: public function addInfoBox($title, $type = 'default', $extra = '')
149: {
150: $this->lastInfoBoxTitle = $title;
151:
152: return self::$ModuleAdmin->addInfoBox($title);
153: }
154:
155: /**
156: * Add line to the info box
157: *
158: * @param string $text text to add to info box
159: * @param string $type type of infobox line
160: * @param string $color color for infobox line
161: *
162: * @return bool
163: */
164: public function addInfoBoxLine($text = '', $type = 'default', $color = 'inherit')
165: {
166: return self::$ModuleAdmin->addInfoBoxLine(
167: $this->lastInfoBoxTitle,
168: $text,
169: '',
170: $color,
171: $type
172: );
173: }
174:
175: /**
176: * Add Item button
177: *
178: * @param string $title title of button
179: * @param string $link link for button
180: * @param string $icon icon for button
181: * @param string $extra extra
182: *
183: * @return bool
184: */
185: public function addItemButton($title, $link, $icon = 'add', $extra = '')
186: {
187: return self::$ModuleAdmin->addItemButton($title, $link, $icon, $extra);
188: }
189:
190: /**
191: * Render all items buttons
192: *
193: * @param string $position button position (left, right)
194: * @param string $delimiter delimiter between buttons
195: *
196: * @return string
197: */
198: public function renderButton($position = null, $delimiter = " ")
199: {
200: if ($postion==null) {
201: $position = 'right';
202: }
203:
204: return self::$ModuleAdmin->renderButton($position, $delimiter);
205: }
206:
207: /**
208: * Display all item buttons
209: *
210: * @param string $position button position (left, right)
211: * @param string $delimiter delimiter between buttons
212: *
213: * @return void
214: */
215: public function displayButton($position = null, $delimiter = " ")
216: {
217: echo $this->renderButton($position, $delimiter);
218: }
219:
220: /**
221: * Render InfoBox
222: *
223: * @return string HTML rendered info box
224: */
225: public function renderInfoBox()
226: {
227: return self::$ModuleAdmin->renderInfoBox();
228: }
229:
230: /**
231: * Display InfoBox
232: *
233: * @return void
234: */
235: public function displayInfoBox()
236: {
237: echo $this->renderInfoBox();
238: }
239:
240: /**
241: * Render index page for admin
242: *
243: * @return string HTML rendered info box
244: */
245: public function renderIndex()
246: {
247: return self::$ModuleAdmin->renderIndex();
248: }
249:
250: /**
251: * Display index page for admin
252: *
253: * @return void
254: */
255: public function displayIndex()
256: {
257: echo $this->renderIndex();
258: }
259:
260: /**
261: * Display the navigation menu
262: *
263: * @param string $menu menu key (script name, i.e. index.php)
264: *
265: * @return void
266: */
267: public function displayNavigation($menu = '')
268: {
269: echo self::$ModuleAdmin->addNavigation($menu);
270: }
271:
272: /**
273: * Render about page
274: *
275: * @param bool $logo_xoops display XOOPS logo
276: *
277: * @return bool|mixed|string
278: */
279: public function renderAbout($logo_xoops = true)
280: {
281: return self::$ModuleAdmin->renderAbout(self::$paypal, $logo_xoops);
282: }
283:
284: /**
285: * set paypal for 2.5 renderAbout
286: *
287: * @param string $paypal PayPal identifier for donate button
288: *
289: * @return void
290: */
291: public static function setPaypal($paypal = '')
292: {
293: self::$paypal = $paypal;
294: }
295:
296: /**
297: * Display about page
298: *
299: * @param bool $logo_xoops display XOOPS logo
300: *
301: * @return void
302: */
303: public function displayAbout($logo_xoops = true)
304: {
305: echo $this->renderAbout($logo_xoops);
306: }
307:
308: // not in regular ModuleAdmin
309:
310: /**
311: * Add error to config box
312: *
313: * @param string $value the error message
314: *
315: * @return bool
316: */
317: public static function addConfigError($value = '')
318: {
319: if (self::is26()) {
320: $type='error';
321: } else {
322: $path=\XoopsBaseConfig::get('url').'/Frameworks/moduleclasses/icons/16/';
323: $line = "";
324: $line .= "<span style='color : red; font-weight : bold;'>";
325: $line .= "<img src='" . $path . "off.png' >";
326: $line .= $value;
327: $line .= "</span>";
328: $value=$line;
329: $type = 'default';
330: }
331:
332: return self::$ModuleAdmin->addConfigBoxLine($value, $type);
333: }
334:
335: /**
336: * Add accept (OK) message to config box
337: *
338: * @param string $value the OK message
339: *
340: * @return bool
341: */
342: public static function addConfigAccept($value = '')
343: {
344: if (self::is26()) {
345: $type='accept';
346: } else {
347: $path=\XoopsBaseConfig::get('url').'/Frameworks/moduleclasses/icons/16/';
348: $line = "";
349: $line .= "<span style='color : green;'>";
350: $line .= "<img src='" . $path . "on.png' >";
351: $line .= $value;
352: $line .= "</span>";
353: $value=$line;
354: $type = 'default';
355: }
356:
357: return self::$ModuleAdmin->addConfigBoxLine($value, $type);
358: }
359:
360: /**
361: * Get an appropriate URL for system provided icons.
362: *
363: * Things which were in Frameworks in 2.5 are in media in 2.6,
364: * making it harder to use and rely on the standard icons.
365: *
366: * not part of 2.6, just a transition assist
367: *
368: * @param string $name the image name to provide URL for, or blank
369: * to just get the URL path.
370: * @param string $size the icon size (directory). Valid values are
371: * 16, 32 or /. A '/' slash will simply set the
372: * path to the icon directory and append $image.
373: *
374: * @return string true if we are in a 2.6 environment
375: */
376: public static function iconUrl($name = '', $size = '32')
377: {
378: switch ($size) {
379: case '16':
380: $path='16/';
381: break;
382: case '/':
383: $path='';
384: break;
385: default:
386: case '32':
387: $path='32/';
388: break;
389: }
390:
391: if (self::is26()) {
392: $path='/media/xoops/images/icons/'.$path;
393: } else {
394: $path='/Frameworks/moduleclasses/icons/'.$path;
395: }
396:
397: return(\XoopsBaseConfig::get('url') . $path . $name);
398: }
399:
400: /**
401: * Check for installed module and version and do addConfigBoxLine()
402: *
403: * @param string $moddir - module directory name
404: * @param integer $minversion - minimum acceptable module version (100 = V1.00)
405: *
406: * @return bool true if requested version of the module is available
407: */
408: public static function checkModuleVersion($moddir, $minversion)
409: {
410: \Xmf\Language::load('main', 'xmf');
411: $return=false;
412: $helper=\Xmf\Module\Helper::getHelper($moddir);
413: if (is_object($helper) && is_object($helper->getModule())) {
414: $mod_modversion=$helper->getModule()->getVar('version');
415: $mod_version_f = $mod_modversion/100;
416: $min_version_f = $minversion/100;
417: $value = sprintf(
418: _AM_XMF_DEMOMVC_MODULE_VERSION,
419: strtoupper($moddir),
420: $min_version_f,
421: $mod_version_f
422: );
423: if ($mod_modversion>=$minversion) {
424: self::addConfigAccept($value);
425: $return=true;
426: } else {
427: self::addConfigError($value);
428: }
429: } else {
430: $value = sprintf(
431: _AM_XMF_DEMOMVC_MODULE_NOTFOUND,
432: strtoupper($moddir),
433: $minversion/100
434: );
435: self::addConfigError($value);
436: }
437:
438: return $return;
439: }
440: }
441: