zen.php 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. <?php
  2. /**
  3. * The zen file of admin module of ZenTaoPMS.
  4. *
  5. * @copyright Copyright 2009-2023 禅道软件(青岛)有限公司(ZenTao Software (Qingdao) Co., Ltd. www.zentao.net)
  6. * @license ZPL(https://zpl.pub/page/zplv12.html) or AGPL(https://www.gnu.org/licenses/agpl-3.0.en.html)
  7. * @author Gang Liu <liugang@easycorp.ltd>
  8. * @package admin
  9. * @link https://www.zentao.net
  10. */
  11. class adminZen extends admin
  12. {
  13. /**
  14. * The extension manager version. Don't change it.
  15. */
  16. const EXT_MANAGER_VERSION = '1.3';
  17. /**
  18. * Sync extensions from zentao official website by api.
  19. *
  20. * @param string $type plugin|patch
  21. * @param int $limit
  22. * @param bool $hasInternet
  23. * @access protected
  24. * @return bool
  25. */
  26. protected function syncExtensions($type = 'plugin', $limit = 5)
  27. {
  28. $searchType = $type == 'plugin' ? 'byModule,offcial' : 'byModule';
  29. $param = $type == 'plugin' ? '' : 'MTIxOA==';
  30. $extensions = $this->loadModel('extension')->getExtensionsByAPI($searchType, $param, 0, $limit);
  31. $extensions = isset($extensions->extensions) ? (array)$extensions->extensions : array();
  32. $plugins = array();
  33. foreach($extensions as $extension)
  34. {
  35. if($type == 'patch' and !isset($extension->compatibleRelease)) continue;
  36. $extension->viewLink = str_replace(array('info', 'client'), '', $extension->viewLink);
  37. $plugins[] = $extension;
  38. }
  39. return $this->loadModel('setting')->setItem("system.common.zentaoWebsite.$type", json_encode($plugins));
  40. }
  41. /**
  42. * Sync public classes from zentao official website by api.
  43. *
  44. * @param int $limit
  45. * @access protected
  46. * @return bool
  47. */
  48. protected function syncPublicClasses($limit = 3)
  49. {
  50. $apiURL = $this->config->admin->videoAPIURL;
  51. $data = $this->fetchAPI($apiURL);
  52. $courses = $data->videos;
  53. $index = 1;
  54. $publicClass = array();
  55. foreach($courses as $course)
  56. {
  57. if($index > $limit) break;
  58. $publicClass[$index] = new stdClass();
  59. $publicClass[$index]->name = $course->title;
  60. $publicClass[$index]->image = $this->config->admin->cdnRoot . $course->image->list[0]->middleURL;
  61. $publicClass[$index]->viewLink = $this->config->admin->apiRoot . '/publicclass/' . ($course->alias ? "{$course->alias}-" : '') . "{$course->id}.html";
  62. $index ++;
  63. }
  64. return $this->loadModel('setting')->setItem('system.common.zentaoWebsite.publicClass', json_encode($publicClass));
  65. }
  66. /**
  67. * Sync dynamics from zentao official website by API.
  68. *
  69. * @param int $limit
  70. * @access protected
  71. * @return bool
  72. */
  73. protected function syncDynamics($limit = 2)
  74. {
  75. $apiURL = $this->config->admin->downloadAPIURL;
  76. $data = $this->fetchAPI($apiURL);
  77. $articles = $data->articles;
  78. $index = 1;
  79. $dynamics = array();
  80. foreach($articles as $article)
  81. {
  82. if($index > $limit) break;
  83. $tagKey = $this->config->edition . 'Tag';
  84. if(!isset($this->lang->admin->$tagKey)) break;
  85. if(!preg_match("/{$this->lang->admin->$tagKey}\d/", $article->title)) continue;
  86. $dynamics[$index] = new stdClass();
  87. $dynamics[$index]->id = $article->id;
  88. $dynamics[$index]->title = $article->title;
  89. $dynamics[$index]->addedDate = $article->addedDate;
  90. $dynamics[$index]->link = $this->config->admin->apiRoot . "/download/{$article->alias}-{$article->id}.html";
  91. $index ++;
  92. }
  93. return $this->loadModel('setting')->setItem('system.common.zentaoWebsite.dynamic', json_encode($dynamics));
  94. }
  95. /**
  96. * Fetch data from an API.
  97. *
  98. * @param string $url
  99. * @access protected
  100. * @return bool|array|object
  101. */
  102. protected function fetchAPI($url)
  103. {
  104. $version = $this->loadModel('upgrade')->getOpenVersion(str_replace('.', '_', $this->config->version));
  105. $version = str_replace('_', '.', $version);
  106. $url .= (strpos($url, '?') === false ? '?' : '&') . 'lang=' . str_replace('-', '_', $this->app->getClientLang()) . '&managerVersion=' . self::EXT_MANAGER_VERSION . '&zentaoVersion=' . $version . '&edition=' . $this->config->edition;
  107. $result = json_decode(preg_replace('/[[:cntrl:]]/mu', '', common::http($url)));
  108. if(!isset($result->status)) return false;
  109. if($result->status != 'success') return false;
  110. if(isset($result->data)) return json_decode($result->data);
  111. }
  112. /**
  113. * 发送验证码。
  114. * Send code by API.
  115. *
  116. * @param string $type mobile|email
  117. * @access protected
  118. * @return string
  119. */
  120. protected function sendCodeByAPI($type)
  121. {
  122. $apiConfig = $this->admin->getApiConfig();
  123. $module = $type == 'mobile' ? 'sms' : 'mail';
  124. $apiURL = $this->config->admin->apiRoot . "/{$module}-apiSendCode.json";
  125. $params['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest';
  126. $params[$apiConfig->sessionVar] = $apiConfig->sessionID;
  127. if(isset($this->config->global->community) and $this->config->global->community != 'na') $this->post->set('account', $this->config->global->community);
  128. $param = http_build_query($params);
  129. return common::http($apiURL . '?' . $param, $_POST);
  130. }
  131. /**
  132. * 认证手机或邮箱。
  133. * Certify by API.
  134. *
  135. * @param string $type mobile|email
  136. * @access protected
  137. * @return string
  138. */
  139. protected function certifyByAPI($type)
  140. {
  141. $apiConfig = $this->admin->getApiConfig();
  142. $module = $type == 'mobile' ? 'sms' : 'mail';
  143. $apiURL = $this->config->admin->apiRoot . "/{$module}-apiCertify.json";
  144. $params['u'] = $this->config->global->community;
  145. $params['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest';
  146. $params[$apiConfig->sessionVar] = $apiConfig->sessionID;
  147. $params['k'] = $this->admin->getSignature($params);
  148. $param = http_build_query($params);
  149. return common::http($apiURL . '?' . $param, $_POST);
  150. }
  151. /**
  152. * 认证公司。
  153. * Set company by API.
  154. *
  155. * @access protected
  156. * @return string
  157. */
  158. protected function setCompanyByAPI()
  159. {
  160. $apiConfig = $this->admin->getApiConfig();
  161. $apiURL = $this->config->admin->apiRoot . "/user-apiSetCompany.json";
  162. $params['u'] = $this->config->global->community;
  163. $params['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest';
  164. $params[$apiConfig->sessionVar] = $apiConfig->sessionID;
  165. $params['k'] = $this->admin->getSignature($params);
  166. $param = http_build_query($params);
  167. return common::http($apiURL . '?' . $param, $_POST);
  168. }
  169. /**
  170. * 获取禅道官网数据。
  171. * Get zentao.net data.
  172. *
  173. * @access protected
  174. * @return object
  175. */
  176. protected function getZentaoData()
  177. {
  178. $data = new stdclass();
  179. $data->hasData = true;
  180. $data->dynamics = array();
  181. $data->classes = array();
  182. $data->plugins = array();
  183. $data->patches = array();
  184. $zentaoData = !empty($this->config->zentaoWebsite) ? $this->config->zentaoWebsite : null;
  185. if(empty($zentaoData))
  186. {
  187. $data->hasData = false;
  188. if($this->config->edition == 'open')
  189. {
  190. $data->plugins = array(
  191. zget($this->config->admin->plugins, '250', ''),
  192. zget($this->config->admin->plugins, '191', ''),
  193. zget($this->config->admin->plugins, '196', '')
  194. );
  195. }
  196. else
  197. {
  198. $data->plugins = array(
  199. zget($this->config->admin->plugins, '198', ''),
  200. zget($this->config->admin->plugins, '194', ''),
  201. zget($this->config->admin->plugins, '203', '')
  202. );
  203. }
  204. }
  205. else
  206. {
  207. if(!empty($zentaoData->dynamic)) $data->dynamics = json_decode($zentaoData->dynamic);
  208. if(!empty($zentaoData->publicClass)) $data->classes = json_decode($zentaoData->publicClass);
  209. if(!empty($zentaoData->plugin)) $data->plugins = json_decode($zentaoData->plugin);
  210. if(!empty($zentaoData->patch)) $data->patches = json_decode($zentaoData->patch);
  211. if(common::checkNotCN()) array_pop($data->plugins);
  212. }
  213. return $data;
  214. }
  215. }