| [ Index ] |
PHP Cross Reference of Xoops v2.4.5 code documentation |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * Initial functions 4 * 5 * @copyright The XOOPS project http://sourceforge.net/projects/xoops/ 6 * @license http://www.fsf.org/copyleft/gpl.html GNU public license 7 * @author Taiwen Jiang <phppp@users.sourceforge.net> 8 * @since 1.00 9 * @version $Id: functions.ini.php 2223 2008-10-04 04:46:03Z phppp $ 10 * @package Frameworks 11 * @subpackage art 12 */ 13 14 if (substr(XOOPS_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", XOOPS_ROOT_PATH . "/Frameworks"); 22 23 /** 24 * Load declaration of an object handler 25 * 26 * 27 * @param string $handler handler name, optional 28 * @return bool 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 function load_object() 46 { 47 return load_objectHandler(); 48 } 49 50 /** 51 * Load a collective functions of Frameworks 52 * 53 * @param string $group name of the collective functions, empty for functions.php 54 * @return bool 55 */ 56 function load_functions($group = "", $dirname = "art") 57 { 58 $dirname = ("" == $dirname ) ? "art" : $dirname; 59 $constant = strtoupper( "frameworks_{$dirname}_functions" . (($group) ? "_{$group}" : "")); 60 if (defined($constant)) return true; 61 return include_once FRAMEWORKS_ROOT_PATH . "/{$dirname}/functions.{$group}" . (empty($group) ? "" : "." ) . "php"; 62 } 63 64 65 /** 66 * Load a collective functions of a module 67 * 68 * The function file should be located in /modules/MODULE/functions.{$group}.php 69 * To avoid slowdown caused by include_once, a constant is suggested in the corresponding file: capitalized {$dirname}_{functions}[_{$group}] 70 * 71 * The function is going to be formulated to use xos_kernel_Xoops2::loadService() in XOOPS 2.3+ 72 * 73 * @param string $group name of the collective functions, empty for functions.php 74 * @param string $dirname module dirname, optional 75 * @return bool 76 */ 77 function mod_loadFunctions($group = "", $dirname = "") 78 { 79 $dirname = !empty($dirname) ? $dirname : $GLOBALS["xoopsModule"]->getVar("dirname", "n"); 80 $constant = strtoupper( "{$dirname}_functions" . ( ($group) ? "_{$group}" : "" ) . "_loaded" ); 81 if (defined($constant)) return true; 82 $filename = XOOPS_ROOT_PATH . "/modules/{$dirname}/include/functions.{$group}" . (empty($group) ? "" : "." ) . "php"; 83 return include_once $filename; 84 } 85 86 /** 87 * Load renderer for a class 88 * 89 * The class file should be located in /modules/MODULE/{$class}.renderer.php 90 * The classf name should be defined as Capitalized(module_dirname)Capitalized(class_name)Renderer 91 * 92 * @param string $class name of the classname 93 * @param string $dirname module dirname, optional 94 * @return bool 95 */ 96 function mod_loadRenderer($class, $dirname = "") 97 { 98 $dirname = !empty($dirname) ? $dirname : $GLOBALS["xoopsModule"]->getVar("dirname", "n"); 99 $renderer = ucfirst($dirname) . ucfirst($class) . "Renderer"; 100 if (!class_exists($renderer)) { 101 require_once XOOPS_ROOT_PATH . "/modules/{$dirname}/class/{$class}.renderer.php"; 102 } 103 $instance = eval("{$renderer}::instance()"); 104 return $instance; 105 } 106 107 /** 108 * Get localized string if it is defined 109 * 110 * @param string $name string to be localized 111 */ 112 if (!function_exists("mod_constant")) { 113 function mod_constant($name) 114 { 115 if (!empty($GLOBALS["VAR_PREFIXU"]) && @defined($GLOBALS["VAR_PREFIXU"] . "_" . strtoupper($name))) { 116 return CONSTANT($GLOBALS["VAR_PREFIXU"] . "_" . strtoupper($name)); 117 } elseif (!empty($GLOBALS["xoopsModule"]) && @defined(strtoupper($GLOBALS["xoopsModule"]->getVar("dirname", "n") . "_" . $name))) { 118 return CONSTANT(strtoupper($GLOBALS["xoopsModule"]->getVar("dirname", "n") . "_" . $name)); 119 } elseif (defined(strtoupper($name))) { 120 return CONSTANT(strtoupper($name)); 121 } else { 122 return str_replace("_", " ", strtolower($name)); 123 } 124 } 125 } 126 127 /** 128 * Get completed DB prefix if it is defined 129 * 130 * @param string $name string to be completed 131 * @param boolean $isRel relative - do not add XOOPS->DB prefix 132 */ 133 if (!function_exists("mod_DB_prefix")) { 134 function mod_DB_prefix($name, $isRel = false) 135 { 136 $relative_name = $GLOBALS["MOD_DB_PREFIX"] . "_" . $name; 137 if ($isRel) return $relative_name; 138 return $GLOBALS["xoopsDB"]->prefix($relative_name); 139 } 140 } 141 142 /** 143 * Display contents of a variable, an array or an object or an array of objects 144 * 145 * @param mixed $message variable/array/object 146 */ 147 if (!function_exists("xoops_message")): 148 function xoops_message( $message, $userlevel = 0) 149 { 150 global $xoopsUser; 151 152 if (!$xoopsUser) $level = 0; 153 elseif ($xoopsUser->isAdmin()) $level = 99; 154 else $level = 1; 155 if ($userlevel > $level) return; 156 157 echo "<div style=\"clear:both\"> </div>"; 158 if (is_array($message) || is_object($message)) { 159 echo "<div><pre>"; 160 print_r($message); 161 echo "</pre></div>"; 162 } else { 163 echo "<div>{$message}</div>"; 164 } 165 echo "<div style=\"clear:both\"> </div>"; 166 } 167 endif; 168 function mod_message( $message ) 169 { 170 global $xoopsModuleConfig; 171 if (!empty($xoopsModuleConfig["do_debug"])) { 172 if (is_array($message) || is_object($message)) { 173 echo "<div><pre>"; 174 print_r($message); 175 echo "</pre></div>"; 176 } else { 177 echo "<div>$message</div>"; 178 } 179 } 180 return true; 181 } 182 183 /** 184 * Get dirname of a module according to current path 185 * 186 * @param string $current_path path to where the function is called 187 * @return string $dirname 188 */ 189 function mod_getDirname($current_path= null) 190 { 191 if ( DIRECTORY_SEPARATOR != '/' ) $current_path = str_replace( strpos( $current_path, '\\\\', 2 ) ? '\\\\' : DIRECTORY_SEPARATOR, '/', $current_path); 192 $url_arr = explode('/', strstr($current_path, '/modules/')); 193 return $url_arr[2]; 194 } 195 196 /** 197 * Is a module being installed, updated or uninstalled 198 * Used for setting module configuration default values or options 199 * 200 * The function should be in functions.admin.php, however it requires extra inclusion in xoops_version.php if so 201 * 202 * @param string $dirname dirname of current module 203 * @return bool 204 */ 205 function mod_isModuleAction($dirname = "system") 206 { 207 $ret = @( 208 // action module "system" 209 !empty($GLOBALS["xoopsModule"]) && "system" == $GLOBALS["xoopsModule"]->getVar("dirname", "n") 210 && 211 // current dirname 212 ($dirname == $_POST["dirname"] || $dirname == $_POST["module"]) 213 && 214 // current op 215 ("update_ok" == $_POST["op"] || "install_ok" == $_POST["op"] || "uninstall_ok" == $_POST["op"]) 216 && 217 // current action 218 "modulesadmin" == $_POST["fct"] 219 ); 220 return $ret; 221 } 222 223 endif; 224 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Sun Aug 1 01:39:09 2010 |