3297f10ade6cdf8fc2905800ceb2de75a89e50a7.svn-base 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <?php
  2. /**
  3. * 基类处理方法
  4. *
  5. * @author widuu <admin@widuu.com>
  6. * @document https://github.com/widuu/qiniu_ueditor_1.4.3
  7. */
  8. class Base{
  9. // 配置文件信息
  10. protected $config;
  11. // Ueditor配置信息
  12. protected $ue_config;
  13. public function __construct($config){
  14. $this->config = $config;
  15. $this->ue_config = $this->config();
  16. }
  17. /**
  18. * Ueditor 获取配置信息的返回方法
  19. *
  20. * @return array
  21. * @author widuu <admin@widuu.com>
  22. */
  23. public function config(){
  24. $ueditor_config = json_decode(preg_replace("/\/\*[\s\S]+?\*\//", "", file_get_contents( UEDITOR_PATH . "config.json") ), true);
  25. return $ueditor_config;
  26. }
  27. /**
  28. * 判断方法是否存在并调用方法
  29. *
  30. * @return array
  31. * @author widuu <admin@widuu.com>
  32. */
  33. public function __call( $method , $params ){
  34. if( method_exists($this, $method) ){
  35. $this->$method();
  36. }
  37. if( $this->hasUploadMethod( $method ) ){
  38. if( strpos(strtolower($method),"upload") !== false ){
  39. return $this->upload($method);
  40. }else if( strpos(strtolower($method),"list") !== false ){
  41. return $this->listFile($method);
  42. }
  43. }
  44. return array(
  45. 'state' => 'ERROR',
  46. 'error' => $method.' upload method not exists'
  47. );
  48. }
  49. /**
  50. * 获取json配置里边的上传参数
  51. *
  52. * @return array
  53. * @author widuu <admin@widuu.com>
  54. */
  55. public function setUploadConfig($method){
  56. $ue_config = $this->getUeConfig();
  57. $config = $this->config;
  58. $root_path = $config['root_path'];
  59. $config_prefix = ltrim($method,"upload");
  60. $config = array(
  61. "pathFormat" => $ue_config[$config_prefix.'PathFormat'],
  62. "maxSize" => $ue_config[$config_prefix.'MaxSize'],
  63. "allowFiles" => $ue_config[$config_prefix.'AllowFiles'],
  64. "fieldName" => $ue_config[$config_prefix.'FieldName'],
  65. "base64" => 'upload',
  66. "rootPath" => $root_path
  67. );
  68. // scrawl 上传参数
  69. if( $config_prefix == 'scrawl' ){
  70. $config['oriName'] = 'scrawl.png';
  71. $config['base64'] = 'base64';
  72. }
  73. return $config;
  74. }
  75. /**
  76. * 判断json中是否定义了方法
  77. *
  78. * @return boolean
  79. * @author widuu <admin@widuu.com>
  80. */
  81. public function hasUploadMethod( $action_name ){
  82. $ue_config = $this->getUeConfig();
  83. $action = strtolower($action_name);
  84. if( in_array( $action , $ue_config ) ){
  85. return true;
  86. }
  87. return false;
  88. }
  89. /**
  90. * 获取Ueditor配置文件信息
  91. *
  92. * @return array
  93. * @author widuu <admin@widuu.com>
  94. */
  95. public function getUeConfig(){
  96. $config = array();
  97. if( count($this->ue_config) > 1 ){
  98. $config = $this->ue_config;
  99. }else{
  100. $config = $this->config();
  101. }
  102. return $config;
  103. }
  104. }