plugin_init_function.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. /*
  3. * Krpano100 插件主入口程序
  4. * ============================================================================
  5. * 技术支持:2015-2099 成都世纪川翔科技有限公司
  6. * 官网地址: http://www.krpano100.com
  7. * ----------------------------------------------------------------------------
  8. * $Author: wanghao 932625974#qq.com $
  9. * $Id: bind.php 28028 2016-06-19Z wanghao $
  10. */
  11. if(!defined('IN_T')){
  12. die('hacking attempt');
  13. }
  14. //获取插件目录下的所有配置
  15. //@param $type: 编辑页 edit, 显示页 view
  16. //@param $refresh: 强制刷新session,重新读取数据
  17. //@param $return: 是否返回,为ture则返回而不输出
  18. function plugin_get_plugins($type, $refresh=false, $return=false){
  19. //session保存了模块权限,且不刷新
  20. if($_SESSION[$type] && !$refresh){
  21. $plugins = $_SESSION[$type];
  22. }
  23. else{
  24. $plugins = array();
  25. //遍历plugin目录
  26. $dir = dirname(__FILE__).'/';
  27. if ($dh = opendir($dir)){
  28. while(($file = readdir($dh)) !== false)
  29. {
  30. if((is_dir($dir.$file)) && $file!="." && $file!="..")
  31. {
  32. //存在功能模块,则加载该模块的配置文件
  33. if (file_exists($dir.$file.'/config.php')) {
  34. require_once($dir.$file.'/config.php');
  35. }
  36. }
  37. }
  38. closedir($dh);
  39. }
  40. if(!empty($plugins)){
  41. //管理员后台不会进行此操作,level_enable总是为0,忽略该值
  42. if($type=='edit' && $GLOBALS['user']['level']>0){
  43. $sql = "select privileges from ".$GLOBALS['Base']->table('user_level')." where id=".$GLOBALS['user']['level']."";
  44. $level = $GLOBALS['Db']->query($sql,"One");
  45. $level = explode(',',$level);
  46. }
  47. foreach ($plugins as $k => $v) {
  48. if(in_array($k,$level)){
  49. $plugins[$k]['level_enable'] = 1; //该用户组可用
  50. }
  51. else{
  52. $plugins[$k]['level_enable'] = 0; //该用户组不可用
  53. }
  54. $key1[] = $plugins[$k]['level_enable'];
  55. $key2[] = $v[$type.'_sort'];
  56. }
  57. //对模块进行前台排序
  58. array_multisort($key1,SORT_NUMERIC,SORT_DESC,$key2,SORT_NUMERIC,SORT_ASC,$plugins);
  59. }
  60. }
  61. //print_r($plugins);
  62. //直接返回,不赋值session
  63. if($return){
  64. return $plugins;
  65. }
  66. //输出前台
  67. else{
  68. //赋值到session
  69. $_SESSION[$type] = $plugins;
  70. $GLOBALS['tp']->assign('plugins',$plugins);
  71. }
  72. }
  73. ?>