XOOPS  2.6.0
functions.ini.php
Go to the documentation of this file.
1 <?php
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 
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 
47  function load_object()
48  {
49  return load_objectHandler();
50  }
51 
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 
82  function mod_loadFunctions($group = "", $dirname = "")
83  {
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 
105  function mod_loadRenderer($class, $dirname = "")
106  {
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")) {
125  function mod_constant($name)
126  {
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")) {
148  function mod_DB_prefix($name, $isRel = false)
149  {
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")):
167  function xoops_message($message, $userlevel = 0)
168  {
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 
197  function mod_message($message)
198  {
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 
218  function mod_getDirname($current_path = null)
219  {
220  if (DIRECTORY_SEPARATOR != '/') {
221  $current_path = str_replace(strpos($current_path, '\\\\', 2) ? '\\\\'
223  }
224  $url_arr = explode('/', strstr($current_path, '/modules/'));
225  return $url_arr[2];
226  }
227 
237  function mod_isModuleAction($dirname = "system")
238  {
240  $ret = @( // action module "system"
241  $xoops->isModule() && "system" == $xoops->module->getVar("dirname", "n") && // current dirname
242  ($dirname == $_POST["dirname"] || $dirname == $_POST["module"]) && // current op
243  ("update_ok" == $_POST["op"] || "install_ok" == $_POST["op"] || "uninstall_ok" == $_POST["op"]) && // current action
244  "modulesadmin" == $_POST["fct"]);
245  return $ret;
246  }
247 
248 endif;
249 ?>
$current_path
Definition: config.php:3
const FRAMEWORKS_ROOT_PATH
static getInstance()
Definition: Xoops.php:160
mod_message($message)
mod_isModuleAction($dirname="system")
defined('DS') or define('DS' DIRECTORY_SEPARATOR
Definition: common.php:41
$xoops
Definition: admin.php:25
load_functions($group="", $dirname="art")
mod_getDirname($current_path=null)
mod_loadRenderer($class, $dirname="")
static get($name)
global $xoopsDB
Definition: common.php:36
if(!function_exists("mod_constant")) if(!function_exists("mod_DB_prefix")) if(!function_exists("xoops_message"))($message, $userlevel=0) endif
load_object()
$GLOBALS['xoops']
Definition: common.php:33
$dirname
Definition: backend.php:38
load_objectHandler($handler="", $dirname="art")
mod_loadFunctions($group="", $dirname="")