1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10:
11:
12: 13: 14: 15: 16: 17: 18: 19:
20:
21: class MenusDecorator
22: {
23: 24: 25: 26: 27:
28: static function getDecorators($dirname)
29: {
30: $available = self::getAvailableDecorators();
31: if (!in_array($dirname, array_keys($available))) {
32: return false;
33: }
34: return $available[$dirname];
35: }
36:
37: 38: 39:
40: static function getAvailableDecorators()
41: {
42: static $decorators = false;
43: if (!is_array($decorators)) {
44: $decorators = array();
45: $helper = Menus::getInstance();
46:
47: $dirnames = XoopsLists::getDirListAsArray($helper->path('decorators/'), '');
48: foreach ($dirnames as $dirname) {
49: if (XoopsLoad::loadFile($helper->path("decorators/{$dirname}/decorator.php"))) {
50: $className = 'Menus' . ucfirst($dirname) . 'Decorator';
51: $class = new $className($dirname);
52: if ($class instanceof MenusDecoratorAbstract && $class instanceof MenusDecoratorInterface) {
53: $decorators[$dirname] = $class;
54: }
55: }
56: }
57: }
58: return $decorators;
59: }
60: }
61:
62: class MenusDecoratorAbstract
63: {
64: 65: 66:
67: public function __construct($dirname)
68: {
69: $this->loadLanguage($dirname);
70: }
71:
72: 73: 74:
75: public function loadLanguage($name)
76: {
77: $helper = Menus::getInstance();
78:
79: $language = XoopsLocale::getLegacyLanguage();
80: $path = $helper->path("decorators/{$name}/language");
81: if (!$ret = XoopsLoad::loadFile("{$path}/{$language}/decorator.php")) {
82: $ret = XoopsLoad::loadFile("{$path}/english/decorator.php");
83: }
84: return $ret;
85: }
86: }
87:
88: interface MenusDecoratorInterface {
89:
90: 91: 92:
93: function start();
94:
95: 96: 97:
98: function end(&$menus);
99:
100: 101: 102:
103: function decorateMenu(&$menu);
104:
105: 106: 107:
108: function hasAccess($menu, &$hasAccess);
109:
110: 111: 112:
113: function accessFilter(&$accessFilter);
114: }
115: