using functions from other plugins to get data or ..
ez |
|
---|---|
I sometimes need code or data that is cross plugin, so i want to use functions or I want to get data that come from other plugins. You can make what I call modules and they must be in the modules folder of any plugin.
/*====================================================================== Function: cf_load_module With this function we can load any code (called modules) from other plugins. In this way we can get/set any value from any plugin via functions that belong to that specific plugin. There can be separate modules that we can use... so we can devide functionality parameters: pluginname should be the pluginname modulename empty will load the default pluginname.module.php value will load pluginname.module.<value>.php return values: false if the file was not found or the plugin is inactive true if the file was found and loaded ======================================================================*/ function cf_load_module($pluginname='',$modulename='') { global $cfg,$sed_plugins; $ret=false; $pluginactive=false; if ($pluginname!="") { // check if plugin is active if (is_array($sed_plugins)) { foreach($sed_plugins as $i => $k) { if($k['pl_code']==$pluginname) { $pluginactive=true; break; } } } if (!$pluginactive) { // plugin is not installed return false; } if ($modulename!='') { $filename = $cfg['plugins_dir'].'/'.$pluginname.'/modules/'.$pluginname.'.module.'.$modulename.'.php'; } else { $filename = $cfg['plugins_dir'].'/'.$pluginname.'/modules/'.$pluginname.'.module.php'; } if (file_exists($filename)) { require_once($filename); $ret=true; } } return $ret; }
How to use it: if (cf_load_module("myproject","users")) { // 0 = current logged in user $ret=mod_mpr_users_getProjectRights('STRING',$userid,$projectid); }
Hope somebody can use the idea :D ==- I say: Keep it EZ -==
|