plugin.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <?php
  2. phpinfo();
  3. /**
  4. * plugin.php 插件入口
  5. *
  6. * @copyright (C) 2005-2010 PHPCMS
  7. * @license http://www.phpcms.cn/license/
  8. * @lastmodify 2013-06-07
  9. */
  10. define('PHPCMS_PATH', dirname(__FILE__).DIRECTORY_SEPARATOR);
  11. include PHPCMS_PATH.'phpcms/base.php';
  12. $param = pc_base::load_sys_class('param');
  13. pc_base::load_sys_func('plugin');
  14. $cache = '';
  15. if(isset($_GET['id'])) {
  16. if(!preg_match("/^[a-z0-9_\-]+$/i",$_GET['id'])) showmessage((L('illegal_parameters')));
  17. list($identification, $filename,$action) = explode('-', $_GET['id']);
  18. $filename = !empty($filename) ? $filename : $identification;
  19. $action = !empty($action) ? $action : 'init';
  20. }
  21. if(!preg_match("/^[a-z0-9_\-]+$/i", $identification)) showmessage(L('plugin_not_exist','','plugin'));
  22. $cache = getcache($identification,'plugins');
  23. if(!$cache['disable'] || $filename=='plugin_admin' || $filename=='hook') {
  24. showmessage(L('plugin_not_exist','','plugin'));
  25. } else {
  26. $status = plugin_stat($cache['appid']);
  27. if($status== 0 || $app_status == 1) {
  28. showmessage(L('plugin_developing','','plugin'));
  29. } elseif($status== 3) {
  30. showmessage(L('plugin_be_locked','','plugin'));
  31. }
  32. $iframe = string2array($cache['iframe']);
  33. if($iframe['url']) {
  34. $cache_var = getcache($identification.'_var','plugins');
  35. plugin_base::creat_iframe($cache,$cache_var);
  36. } else {
  37. plugin_base::creat_app($identification, $filename, $action);
  38. }
  39. }
  40. class plugin_base {
  41. /**
  42. * 初始化插件
  43. */
  44. public static function creat_app($id,$file,$action) {
  45. define('PLUGIN_ID', $id);
  46. define('PLUGIN_FILE', $file);
  47. define('PLUGIN_ACTION', $action);
  48. self::plugin_init();
  49. }
  50. /**
  51. * 调用插件方法
  52. */
  53. private function plugin_init() {
  54. $controller = self::load_controller();
  55. if (method_exists($controller, PLUGIN_ACTION)) {
  56. if (preg_match('/^[_]/i', PLUGIN_ACTION)) {
  57. exit('Plugin Error:You are visiting the action is to protect the private action');
  58. } else {
  59. call_user_func(array($controller, PLUGIN_ACTION));
  60. }
  61. } else {
  62. exit(L('plugin_error_or_not_exist','','plugin'));
  63. }
  64. }
  65. /**
  66. * 加载插件控制器
  67. * @param string $filename
  68. * @param string $m
  69. * @return obj
  70. */
  71. private function load_controller($filename = '', $m = '') {
  72. if (empty($filename)) $filename = PLUGIN_FILE;
  73. if (empty($m)) $m = PLUGIN_ID;
  74. $filepath = PC_PATH.'plugin'.DIRECTORY_SEPARATOR.$m.DIRECTORY_SEPARATOR.$filename.'.class.php';
  75. if (file_exists($filepath) && $filename !='plugin_admin') {
  76. $classname = $filename;
  77. include $filepath;
  78. if ($mypath = pc_base::my_path($filepath)) {
  79. $classname = 'MY_'.$filename;
  80. include $mypath;
  81. }
  82. return new $classname;
  83. } else {
  84. exit(L('plugin_error_or_not_exist','','plugin'));
  85. }
  86. }
  87. /**
  88. * 加载插件模板
  89. */
  90. final public static function plugin_tpl($file, $identification = '') {
  91. $identification = empty($identification) && defined('PLUGIN_ID') ? PLUGIN_ID : $identification;
  92. if(empty($identification)) return false;
  93. return PC_PATH.'plugin'.DIRECTORY_SEPARATOR.$identification.DIRECTORY_SEPARATOR.'templates'.DIRECTORY_SEPARATOR.$file.'.tpl.php';
  94. }
  95. public static function creat_iframe($cache = '',$cache_var = '') {
  96. $iframe = string2array($cache['iframe']);
  97. $width = $cache_var['width'] ? $cache_var['width'] : $iframe['width'];
  98. $height = $cache_var['height'] ? $cache_var['height'] : $iframe['width'];
  99. $url = $iframe['url'];
  100. $SEO = seo(1, 0, $cache['name'], $cache['description'], $cache['name']);
  101. include template('plugin','iframe');
  102. }
  103. }
  104. ?>