PageRenderTime 48ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/api/manyou/js.php

https://github.com/kuaileshike/upload
PHP | 268 lines | 230 code | 32 blank | 6 comment | 47 complexity | 599fccd7a9ddeae82f54dac173c86d98 MD5 | raw file
  1. <?php
  2. /**
  3. * [Discuz!] (C)2001-2099 Comsenz Inc.
  4. * This is NOT a freeware, use is subject to license terms
  5. *
  6. * $Id: js.php 25510 2011-11-14 02:22:26Z yexinhao $
  7. */
  8. define('IN_API', true);
  9. define('CURSCRIPT', 'api');
  10. require_once('../../source/class/class_core.php');
  11. require_once('../../source/function/function_home.php');
  12. $cachelist = array();
  13. $discuz = C::app();
  14. $discuz->cachelist = $cachelist;
  15. $discuz->init_cron = false;
  16. $discuz->init_setting = true;
  17. $discuz->init_user = $_GET['module'] == 'Search' ? true : false;
  18. $discuz->init_session = false;
  19. $discuz->init();
  20. $js = "if(!window['ManYou']) {window['ManYou']={};}\n";
  21. $id = $_GET['module'] . '_' . $_GET['method'];
  22. $js .= "if(!window['ManYou.$id']) {window['ManYou.$id']={};}\n";
  23. if(empty($_G['setting']['my_siteid']) || empty($_G['setting']['my_sitekey'])) {
  24. echo $js . 'ManYou.' . $id . '={status:"error", result: "plug-in has not been opened"};';
  25. exit;
  26. }
  27. $jsapi = new JSAPI();
  28. $result = $jsapi->request_parse();
  29. $json = $jsapi->response_format($result);
  30. echo $js . "ManYou.$id=" . $json;
  31. class JSAPI {
  32. function request_check() {
  33. return true;
  34. global $_G;
  35. $module = $_GET['module'];
  36. $method = $_GET['method'];
  37. $params = (array) $_GET['params'];
  38. ksort($params);
  39. $args = $delimiter = '';
  40. foreach ($params as $k => $v) {
  41. $args .= $delimiter . "params[$k]" . '=' . $v ;
  42. $delimiter = '&';
  43. }
  44. $sig = $_GET['sig'];
  45. $secret = md5($module . '|'. $method . '|' . $args . '|' . $_GET['ts'] .'|'. $_GET['salt'] . '|' . $_G['setting']['my_sitekey']);
  46. if ($sig != $secret) {
  47. return array('result' => 'error', 'reason' => 'signature error');
  48. }
  49. return true;
  50. }
  51. function request_parse() {
  52. $module = $_GET['module'];
  53. $method = $_GET['method'];
  54. $params = $_GET['params'];
  55. $res = $this->request_check();
  56. if ($res === true) {
  57. $clazz = $module . '.' . $method;
  58. switch($clazz) {
  59. case 'Thread.getReplyAndView' :
  60. $args = array($params['tids']);
  61. break;
  62. case 'Search.getHeader' :
  63. $args = array();
  64. break;
  65. default :
  66. return array('status' => 'error', 'result' => 'unknown method' . $clazz);
  67. }
  68. $result = call_user_func_array(array(&$module, $method), $args);
  69. $res = array('status' => 'ok', 'result' => $result);
  70. }
  71. return $res;
  72. }
  73. function response_format($result) {
  74. if(function_exists('json_encode')) {
  75. $json = json_encode($result);
  76. } elseif(function_exists('mb_internal_encoding')) {
  77. $json = $this->php2json($result);
  78. } else {
  79. $json = '{"status":"error","result":"unsuport json_encode or mb_internal_encoding"}';
  80. }
  81. return $json;
  82. }
  83. function json_encode_string($in_str) {
  84. mb_internal_encoding("UTF-8");
  85. $convmap = array(0x80, 0xFFFF, 0, 0xFFFF);
  86. $str = "";
  87. for($i=mb_strlen($in_str)-1; $i>=0; $i--) {
  88. $mb_char = mb_substr($in_str, $i, 1);
  89. if(mb_ereg("&#(\\d+);", mb_encode_numericentity($mb_char, $convmap, "UTF-8"), $match)) {
  90. $str = sprintf("\\u%04x", $match[1]) . $str;
  91. } else {
  92. $str = $mb_char . $str;
  93. }
  94. }
  95. return $str;
  96. }
  97. function _array2json($array) {
  98. $piece = array();
  99. foreach ($array as $k => $v) {
  100. $piece[] = $k . ':' . $this->php2json($v);
  101. }
  102. if ($piece) {
  103. $json = '{' . implode(',', $piece) . '}';
  104. } else {
  105. $json = '[]';
  106. }
  107. return $json;
  108. }
  109. function php2json($value) {
  110. if (is_array($value)) {
  111. return $this->_array2json($value);
  112. }
  113. if (is_string($value)) {
  114. $value = str_replace(array("\n", "\t"), array(), $value);
  115. $value = addslashes($value);
  116. $value = $this->json_encode_string($value);
  117. return '"'.$value.'"';
  118. }
  119. if (is_bool($value)) {
  120. return $value ? 'true' : 'false';
  121. }
  122. if (is_null($value)) {
  123. return 'null';
  124. }
  125. return $value;
  126. }
  127. }
  128. Cloud::loadFile('Service_SearchHelper');
  129. class Thread {
  130. function getReplyAndView($tids) {
  131. if (!$tids) {
  132. return array();
  133. }
  134. $tids = explode(',', $tids);
  135. $res = array();
  136. $threads = Cloud_Service_SearchHelper::getThreads($tids);
  137. foreach($threads as $thread) {
  138. $res[$thread['tId']] = array('tid' => $thread['tId'],
  139. 'replies' => $thread['replyNum'],
  140. 'views' => $thread['viewNum'],
  141. );
  142. }
  143. return $res;
  144. }
  145. }
  146. class Search {
  147. function getReplyAndView($tids) {
  148. if (!$tids) {
  149. return array();
  150. }
  151. $res = array();
  152. $threads = Cloud_Service_SearchHelper::getThreads($tids);
  153. foreach($threads as $thread) {
  154. $res[$thread['tId']] = array('tid' => $thread['tId'],
  155. 'replies' => $thread['replyNum'],
  156. 'views' => $thread['viewNum'],
  157. );
  158. }
  159. return $res;
  160. }
  161. function getHeader() {
  162. global $_G;
  163. $leftHtmlCode = '<div id="navs-wraper-v2" class="v2" onmouseover="document.getElementById(\'navs-menu\').style.display=\'block\'" onmouseout="document.getElementById(\'navs-menu\').style.display=\'none\'">';
  164. $leftHtmlCode .= '<p id="return-homepage"><a href="'.(!empty($_G['setting']['defaultindex']) ? $_G['setting']['defaultindex'] : 'forum.php').'">' . lang('home/template', 'return_homepage') . '</a></p>' . "\n";
  165. $leftHtmlCode .= "<ul id=\"navs-menu\">\n";
  166. foreach($_G['setting']['navs'] as $navsid => $nav) {
  167. $nav['nav'] = '<li ' . $nav['nav'] . '></li>';
  168. if($nav['available']) {
  169. if($navsid == 6 && !empty($_G['setting']['plugins']['jsmenu'])) {
  170. $leftHtmlCode .= "\t$nav[nav]\n";
  171. } else {
  172. if(!$nav['level'] || ($nav['level'] == 1 && $_G['uid']) || ($nav['level'] == 2 && $_G['adminid'] > 0) || ($nav['level'] == 3 && $_G['adminid'] == 1)) {
  173. $leftHtmlCode .= "\t$nav[nav]\n";
  174. }
  175. }
  176. }
  177. }
  178. $leftHtmlCode .= "</ul></div>\n";
  179. $rightHtmlCode = "<p>\n";
  180. if($_G['uid']) {
  181. $rightHtmlCode .= "\t<strong><a href=\"home.php?mod=space\" class=\"noborder\" target=\"_blank\">{$_G[member][username]}</a></strong>\n";
  182. if($_G['group']['allowinvisible']) {
  183. $rightHtmlCode .= "<span id=\"loginstatus\" class=\"xg1\"><a href=\"member.php?mod=switchstatus\" title=\"".lang('template', 'login_switch_invisible_mode')."\">";
  184. if($_G['session']['invisible']) {
  185. $rightHtmlCode .= lang('template', 'login_invisible_mode');
  186. } else {
  187. $rightHtmlCode .= lang('template', 'login_normal_mode');
  188. }
  189. $rightHtmlCode .= "</a></span>\n";
  190. }
  191. $rightHtmlCode .= "\t<span class=\"pipe\">|</span><a href=\"home.php?mod=space&do=home\">".lang('template', 'my_space')."</a>\n";
  192. $rightHtmlCode .= "\t<span class=\"xg1\"><a href=\"home.php?mod=spacecp\">".lang('template', 'setup')."</a></span>\n";
  193. $rightHtmlCode .= "\t<span class=\"pipe\">|</span><a href=\"home.php?mod=space&do=notice\" id=\"myprompt\"".($_G['member']['newprompt'] ? ' class="new"' : '').">".lang('template', 'notice').($_G['member']['newprompt'] ? '('.$_G['member']['newprompt'].')' : '')."</a><span id=\"myprompt_check\"></span>\n";
  194. $rightHtmlCode .= "\t<span class=\"pipe\">|</span><a href=\"home.php?mod=space&do=pm\" id=\"pm_ntc\"".($_G['member']['newpm'] ? ' class="new"' : '').">".lang('template', 'pm_center').($_G['member']['newpm'] ? '('.$_G['member']['newpm'].')' : '')."</a>\n";
  195. if($_G['group']['allowmanagearticle'] || $_G['group']['allowdiy']) {
  196. $rightHtmlCode .= "\t<span class=\"pipe\">|</span><a href=\"portal.php?mod=portalcp\" target=\"_blank\">".lang('template', 'portal_manage')."</a>\n";
  197. }
  198. if($_G['uid'] && $_G['adminid'] > 1) {
  199. $rightHtmlCode .= "\t<span class=\"pipe\">|</span><a href=\"forum.php?mod=modcp&fid=$_G[fid]\" target=\"_blank\">".$_G['setting']['navs']['2']['navname'].lang('template', 'manage')."</a>\n";
  200. }
  201. if($_G['uid'] && ($_G['adminid'] == 1 || $_G['member']['allowadmincp'])) {
  202. $rightHtmlCode .= "\t<span class=\"pipe\">|</span><a href=\"admin.php\" target=\"_blank\">".lang('template', 'admincp')."</a>\n";
  203. }
  204. $rightHtmlCode .= "\t<span class=\"pipe\">|</span><a href=\"member.php?mod=logging&action=logout&formhash=".FORMHASH."\">".lang('template', 'logout')."</a>\n";
  205. } elseif(!empty($_G['cookie']['loginuser'])) {
  206. $rightHtmlCode .= "\t<strong><a id=\"loginuser\" class=\noborder\">".$_G['cookie']['loginuser']."</a></strong>\n";
  207. $rightHtmlCode .= "\t<span class=\"pipe\">|</span><a href=\"member.php?mod=logging&action=login\">".lang('template', 'activation')."</a>\n";
  208. $rightHtmlCode .= "\t<span class=\"pipe\">|</span><a href=\"member.php?mod=logging&action=logout&formhash={FORMHASH}\">".lang('template', 'logout')."</a>\n";
  209. } else {
  210. $rightHtmlCode .= "\t<a href=\"member.php?mod=".$_G['setting']['regname']."\" class=\"noborder\">".$_G['setting']['reglinkname']."</a>\n";
  211. $rightHtmlCode .= "\t<span class=\"pipe\">|</span><a href=\"member.php?mod=logging&action=login\">".lang('template', 'login')."</a>\n";
  212. }
  213. $rightHtmlCode .= "\t</p>\n";
  214. $leftHtmlCode = urlcovert($leftHtmlCode, $_G['siteurl']);
  215. $rightHtmlCode = urlcovert($rightHtmlCode, $_G['siteurl']);
  216. if(strtolower($_G['config']['output']['charset']) != 'utf-8') {
  217. require_once libfile('class/chinese');
  218. $chinese = new Chinese($_G['config']['output']['charset'], 'utf-8', true);
  219. $leftHtmlCode = $chinese->Convert($leftHtmlCode);
  220. $rightHtmlCode = $chinese->Convert($rightHtmlCode);
  221. }
  222. $ret = array('left' => $leftHtmlCode, 'right' => $rightHtmlCode);
  223. return $ret;
  224. }
  225. }
  226. function urlcovert($html, $siteurl) {
  227. if(preg_match_all("/\s+href=\"(.+?)\"/is", $html, $match)) {
  228. foreach($match[1] as $key => $val) {
  229. if(preg_match('/^http:\/\//is', $val) || $val == 'javascript:;' || $val{0} == '#') continue;
  230. $html = str_replace($match[0][$key], ' href="'.$siteurl.$val.'"', $html);
  231. }
  232. }
  233. return $html;
  234. }