1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12:
13:
14: if (substr(\XoopsBaseConfig('version'), 0, 9) < "XOOPS 2.3") {
15: trigger_error("The package only works for XOOPS 2.3+", E_USER_ERROR);
16: }
17:
18: if (!defined("FRAMEWORKS_ART_FUNCTIONS_INI")):
19: define("FRAMEWORKS_ART_FUNCTIONS_INI", true);
20:
21: define("FRAMEWORKS_ROOT_PATH", \XoopsBaseConfig::get('root-path') . "/Frameworks");
22:
23: 24: 25: 26: 27: 28: 29:
30: function load_objectHandler($handler = "", $dirname = "art")
31: {
32: if (empty($handler)) {
33: $handlerClass = "ArtObject";
34: $fileName = "object.php";
35: } else {
36: $handlerClass = "ArtObject" . ucfirst($handler) . "Handler";
37: $fileName = "object.{$handler}.php";
38: }
39:
40: class_exists($handlerClass) || require_once FRAMEWORKS_ROOT_PATH . "/{$dirname}/{$fileName}";
41: return class_exists($handlerClass);
42: }
43:
44: 45: 46:
47: function load_object()
48: {
49: return load_objectHandler();
50: }
51:
52: 53: 54: 55: 56: 57: 58:
59: function load_functions($group = "", $dirname = "art")
60: {
61: $dirname = ("" == $dirname) ? "art" : $dirname;
62: $constant = strtoupper("frameworks_{$dirname}_functions" . (($group) ? "_{$group}" : ""));
63: if (defined($constant)) {
64: return true;
65: }
66: return include_once FRAMEWORKS_ROOT_PATH . "/{$dirname}/functions.{$group}" . (empty($group) ? "" : ".") . "php";
67: }
68:
69:
70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81:
82: function mod_loadFunctions($group = "", $dirname = "")
83: {
84: $xoops = Xoops::getInstance();
85:
86: $dirname = !empty($dirname) ? $dirname : $xoops->moduleDirname;
87: $constant = strtoupper("{$dirname}_functions" . (($group) ? "_{$group}" : "") . "_loaded");
88: if (defined($constant)) {
89: return true;
90: }
91: $filename = \XoopsBaseConfig::get('root-path') . "/modules/{$dirname}/include/functions.{$group}" . (empty($group) ? "" : ".") . "php";
92: return include_once $filename;
93: }
94:
95: 96: 97: 98: 99: 100: 101: 102: 103: 104:
105: function mod_loadRenderer($class, $dirname = "")
106: {
107: $xoops = Xoops::getInstance();
108: $dirname = !empty($dirname) ? $dirname : $xoops->moduleDirname;
109: $renderer = ucfirst($dirname) . ucfirst($class) . "Renderer";
110: if (!class_exists($renderer)) {
111: require_once \XoopsBaseConfig::get('root-path') . "/modules/{$dirname}/class/{$class}.renderer.php";
112: }
113: $instance = eval("{$renderer}::instance()");
114: return $instance;
115: }
116:
117:
118: if (!function_exists("mod_constant")) {
119: 120: 121: 122: 123: 124:
125: function mod_constant($name)
126: {
127: $xoops = Xoops::getInstance();
128: if (!empty($GLOBALS["VAR_PREFIXU"]) && @defined($GLOBALS["VAR_PREFIXU"] . "_" . strtoupper($name))) {
129: return constant($GLOBALS["VAR_PREFIXU"] . "_" . strtoupper($name));
130: } elseif (!empty($xoops->module) && @defined(strtoupper($xoops->module->getVar("dirname", "n") . "_" . $name))) {
131: return constant(strtoupper($xoops->module->getVar("dirname", "n") . "_" . $name));
132: } elseif (defined(strtoupper($name))) {
133: return constant(strtoupper($name));
134: } else {
135: return str_replace("_", " ", strtolower($name));
136: }
137: }
138: }
139:
140: if (!function_exists("mod_DB_prefix")) {
141: 142: 143: 144: 145: 146: 147:
148: function mod_DB_prefix($name, $isRel = false)
149: {
150: $xoops = Xoops::getInstance();
151: $relative_name = $GLOBALS["MOD_DB_PREFIX"] . "_" . $name;
152: if ($isRel) {
153: return $relative_name;
154: }
155: return $xoopsDB->prefix($relative_name);
156: }
157: }
158:
159: if (!function_exists("xoops_message")):
160: 161: 162: 163: 164: 165: 166:
167: function xoops_message($message, $userlevel = 0)
168: {
169: $xoops = Xoops::getInstance();
170: if (!$xoops->isUser()) {
171: $level = 0;
172: } elseif ($xoops->user->isAdmin()) {
173: $level = 99;
174: } else {
175: $level = 1;
176: }
177: if ($userlevel > $level) {
178: return;
179: }
180:
181: echo "<div style=\"clear:both\"> </div>";
182: if (is_array($message) || is_object($message)) {
183: echo "<div><pre>";
184: print_r($message);
185: echo "</pre></div>";
186: } else {
187: echo "<div>{$message}</div>";
188: }
189: echo "<div style=\"clear:both\"> </div>";
190: }
191: endif;
192:
193: 194: 195: 196:
197: function mod_message($message)
198: {
199: $xoops = Xoops::getInstance();
200: if (!empty($xoops->moduleConfig["do_debug"])) {
201: if (is_array($message) || is_object($message)) {
202: echo "<div><pre>";
203: print_r($message);
204: echo "</pre></div>";
205: } else {
206: echo "<div>$message</div>";
207: }
208: }
209: return true;
210: }
211:
212: 213: 214: 215: 216: 217:
218: function mod_getDirname($current_path = null)
219: {
220: if (DIRECTORY_SEPARATOR !== '/') {
221: $current_path = str_replace(strpos($current_path, '\\\\', 2) ? '\\\\'
222: : DIRECTORY_SEPARATOR, '/', $current_path);
223: }
224: $url_arr = explode('/', strstr($current_path, '/modules/'));
225: return $url_arr[2];
226: }
227:
228: 229: 230: 231: 232: 233: 234: 235: 236:
237: function mod_isModuleAction($dirname = "system")
238: {
239: $xoops = Xoops::getInstance();
240: $ret = @(
241: $xoops->isModule() && "system" === $xoops->module->getVar("dirname", "n") &&
242: ($dirname == $_POST["dirname"] || $dirname == $_POST["module"]) &&
243: ("update_ok" === $_POST["op"] || "install_ok" === $_POST["op"] || "uninstall_ok" === $_POST["op"]) &&
244: "modulesadmin" === $_POST["fct"]);
245: return $ret;
246: }
247:
248: endif;
249: