5_cloudsearch_module.tpl.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887
  1. <?php if(!defined('IN_DISCUZ')) exit('Access Denied'); function tpl_cloudsearch_index_top($recwords, $searchparams, $srchotquery, $position = 'hotopicf') {
  2. global $_G;
  3. if($recwords) {
  4. $recwords_tmp = $recwords;
  5. $recwords = array();
  6. foreach ($recwords_tmp as $k => $v) {
  7. $recwords[$k+1] = $v;?><?php }?><?php }?><?php
  8. $return = <<<EOF
  9. EOF;
  10. if(is_array($recwords) && count($recwords) > 0 && !empty($searchparams['url'])) {
  11. $return .= <<<EOF
  12. <div class="fl bm">
  13. <div class="bm bmw hottopic cl">
  14. <div class="bm_h cl">
  15. <span class="y"></span>
  16. <h2>
  17. EOF;
  18. if($_G['fid']) {
  19. $return .= <<<EOF
  20. 本版
  21. EOF;
  22. }
  23. $return .= <<<EOF
  24. 热门话题</h2>
  25. </div>
  26. <style>
  27. .filter { padding: 10px; border-bottom: none; font-size: 12px; color: #999; }
  28. .filter ul {}
  29. .filter li { float: left; margin-right: 16px; height: 22px; line-height: 22px; white-space:nowrap; width:12.5%; }
  30. .filter li a { margin-right: 2px; text-decoration: none; color: #369; }
  31. .filter li.clewcolor a { background:url(source/plugin/cloudsearch/template/keyword_hot.gif) no-repeat 100% 2px; margin-right: 2px; text-decoration: none; color: #F00; padding-right:18px; }
  32. .filter li a:hover { text-decoration: underline; }
  33. .filter li a:visited { text-decoration: none; color: #666; }
  34. .filter li.clewcolor a:visited { text-decoration: none; color: #F00; }
  35. .filter .number { color: #666; }
  36. .filter li.clewcolor .number { color:#F00; }
  37. </style>
  38. <div class="filter">
  39. <ul class="cl">
  40. EOF;
  41. if(is_array($recwords)) foreach($recwords as $key => $recword) { if($encodeWord=rawurlencode(trim($recword['word']))) { if(empty($recword['inc_num'])) {
  42. $return .= <<<EOF
  43. <li><a href="{$searchparams['url']}?q={$encodeWord}&source=word.{$position}.{$key}{$srchotquery}&num={$recword['result_num']}" sc="1" target="_blank">{$recword['word']}<span class="number">({$recword['result_num']})</span></a></li>
  44. EOF;
  45. } else {
  46. $return .= <<<EOF
  47. <li class="clewcolor"><a href="{$searchparams['url']}?q={$encodeWord}&source=word.{$position}.{$key}{$srchotquery}&num={$recword['result_num']}" sc="1" target="_blank">{$recword['word']}<span class="number">({$recword['result_num']})</span></a></li>
  48. EOF;
  49. } } }
  50. $return .= <<<EOF
  51. </ul>
  52. </div>
  53. </div>
  54. </div>
  55. EOF;
  56. }
  57. $return .= <<<EOF
  58. EOF;
  59. ?><?php return $return;?><?php }
  60. function tpl_cloudsearch_global_footer_formula_output() {
  61. global $_G;
  62. $formHash = FORMHASH;
  63. $cookie = $_G['cookie']['ffids' . $_G['uid']];?><?php
  64. $return = <<<EOF
  65. EOF;
  66. if(!$cookie) {
  67. $return .= <<<EOF
  68. <script type="text/javascript">
  69. _attachEvent(window, 'load', getForbiddenFormula, document);
  70. function getForbiddenFormula() {
  71. var toGetForbiddenFormulaFIds = function () {
  72. ajaxget('plugin.php?id=cloudsearch&formhash={$formHash}');
  73. };
  74. var a = document.body.getElementsByTagName('a');
  75. for(var i = 0;i < a.length;i++){
  76. if(a[i].getAttribute('sc')) {
  77. a[i].setAttribute('mid', hash(a[i].href));
  78. a[i].onmousedown = function() {toGetForbiddenFormulaFIds();};
  79. }
  80. }
  81. var btn = document.body.getElementsByTagName('button');
  82. for(var i = 0;i < btn.length;i++){
  83. if(btn[i].getAttribute('sc')) {
  84. btn[i].setAttribute('mid', hash(btn[i].id));
  85. btn[i].onmousedown = function() {toGetForbiddenFormulaFIds();};
  86. }
  87. }
  88. }
  89. </script>
  90. EOF;
  91. }
  92. $return .= <<<EOF
  93. EOF;
  94. ?><?php return $return;?><?php }
  95. function tpl_cloudsearch_viewthread_postbottom_output() {?><?php
  96. $return = <<<EOF
  97. <div id="relate_subject"></div>
  98. EOF;
  99. ?><?php return $return;?><?php }
  100. function tpl_cloudsearch_forumdisplay_threadtype_extra_output($recwords) {
  101. global $_G;?><?php
  102. $__IMGDIR = IMGDIR;$return = <<<EOF
  103. <style>
  104. .sort_ttp { padding-top: 0;margin-bottom:5px;}
  105. .sort_tit { padding:4px 8px 3px 0; color:#999; }
  106. .loadingCloud { text-align:center;line-height:50px; }
  107. </style>
  108. <script>
  109. var currentKeyword = '';
  110. var currentOrder = '';
  111. function switchkeyword(keyword, order, page) {
  112. page = page ? page : 1;
  113. order = order ? order : '';
  114. if (currentKeyword == keyword && order == '' && page == 1) {
  115. window.location = 'forum.php?mod=forumdisplay&fid={$_G['fid']}';
  116. return true;
  117. }
  118. if (currentKeyword != '') {
  119. $("ckw_"+currentKeyword).className = '';
  120. }
  121. $("ckw_"+keyword).className = 'xw1 a';
  122. currentKeyword = keyword;
  123. currentOrder = order;
  124. getclouddata(keyword, order, page);
  125. }
  126. function switchPage(page) {
  127. getclouddata(currentKeyword, currentOrder, page);
  128. }
  129. function switchOrder(order) {
  130. currentOrder = order;
  131. getclouddata(currentKeyword, order, 1);
  132. }
  133. function getclouddata(keyword, order, page) {
  134. $("threadlist").innerHTML = '<div class="loadingCloud"><img src="{$__IMGDIR}/loading.gif" alt="loading..." class="vm" /> 正在加载……</div>';
  135. ajaxget('forum.php?mod=forumdisplay&fid={$_G['fid']}&cloudop=relatedthread&page='+page+'&of='+order+'&keyword='+keyword);
  136. }
  137. function succeedhandle_getRelatedData(url, msg, data) {
  138. if(data['threaddiv']) {
  139. $("threadlist").innerHTML = data['threaddiv'];
  140. $("fd_page_top").innerHTML = $("fd_page_bottom").innerHTML = data['page'];
  141. }
  142. }
  143. function errorhandle_getRelatedData(msg, data) {
  144. showError(msg);
  145. }
  146. </script>
  147. <ul class="ttp cl" id="thread_types2" style="padding-top:0px;">
  148. <li class="sort_tit">热门话题</li>
  149. EOF;
  150. if(is_array($recwords)) foreach($recwords as $keyword) {
  151. $return .= <<<EOF
  152. <li id="ckw_{$keyword['0']}"><a href="javascript:void(0);return false;" onclick="switchkeyword('{$keyword['0']}');">{$keyword['0']}</a></li>
  153. EOF;
  154. }
  155. $return .= <<<EOF
  156. </ul>
  157. EOF;
  158. ?><?php return $return;?><?php }
  159. function tpl_cloudsearch_forumdisplay_threadtype_inner_output() {
  160. global $_G;?><?php
  161. $return = <<<EOF
  162. <style>
  163. .sort_tit { padding:4px 8px 3px 0; color:#999; }
  164. </style>
  165. <li class="sort_tit">主题分类</li>
  166. EOF;
  167. ?><?php return $return;?><?php }
  168. function tpl_cloudsearch_collection_viewoptions_output() {
  169. global $_G;?><?php
  170. $return = <<<EOF
  171. <a href="forum.php?mod=collection&amp;action=view&amp;ctid={$_G['collection']['ctid']}&amp;op=related" class="xi2">搜索相关主题</a>
  172. <span class="pipe">|</span>
  173. EOF;
  174. ?><?php return $return;?><?php }
  175. function tpl_cloudsearch_collection_relatedop_output($threadlist, $multipage) {
  176. global $_G;?><?php
  177. $__IMGDIR = IMGDIR;$__FORMHASH = FORMHASH;$return = <<<EOF
  178. <ul class="ttp bm cl cttp">
  179. <li
  180. EOF;
  181. if(!$_GET['keyword']) {
  182. $return .= <<<EOF
  183. class="xw1 a"
  184. EOF;
  185. }
  186. $return .= <<<EOF
  187. >
  188. <a href="forum.php?mod=collection&amp;action=view&amp;ctid={$_G['collection']['ctid']}&amp;op=related" class="xi2">{$_G['collection']['name']}</a>
  189. </li>
  190. EOF;
  191. if(is_array($_G['collection']['arraykeyword'])) foreach($_G['collection']['arraykeyword'] as $kid => $unique_keyword) {
  192. $return .= <<<EOF
  193. <li
  194. EOF;
  195. if($unique_keyword == $_GET['keyword']) {
  196. $return .= <<<EOF
  197. class="xw1 a"
  198. EOF;
  199. }
  200. $return .= <<<EOF
  201. >
  202. <a href="forum.php?mod=collection&amp;action=view&amp;ctid={$_G['collection']['ctid']}&amp;op=related&amp;keyword={$_G['collection']['urlkeyword'][$kid]}" class="xi2">{$unique_keyword}</a>
  203. </li>
  204. EOF;
  205. }
  206. $return .= <<<EOF
  207. </ul>
  208. <div class="tl bm">
  209. EOF;
  210. if($threadlist) {
  211. $return .= <<<EOF
  212. <form action="forum.php?mod=collection&amp;action=edit&amp;op=addthread" method="POST">
  213. <div class="th">
  214. <table cellspacing="0" cellpadding="0">
  215. <tr>
  216. <td class="icn"></td>
  217. <td class="o"><label class="z" onclick="checkall(this.form, 'tids')"><input class="pc" type="checkbox" name="chkall" title="!checkall!" /></label></td>
  218. <td class="common">帖子</td>
  219. <td class="forum">版块</td>
  220. <td class="by">作者</td>
  221. </tr>
  222. </table>
  223. </div>
  224. <div class="bm_c">
  225. <table cellspacing="0" cellpadding="0">
  226. EOF;
  227. if(is_array($threadlist)) foreach($threadlist as $thread) {
  228. $return .= <<<EOF
  229. <tr>
  230. <td class="icn">
  231. EOF;
  232. if($thread['icon']) {
  233. $return .= <<<EOF
  234. <img src="{$thread['icon']}" />
  235. EOF;
  236. } else {
  237. $return .= <<<EOF
  238. <img src="{$__IMGDIR}/folder_common.gif" />
  239. EOF;
  240. }
  241. $return .= <<<EOF
  242. </td>
  243. <td class="o">
  244. EOF;
  245. if(!isset($thread['icon'])) {
  246. $return .= <<<EOF
  247. <input type="checkbox" value="{$thread['tThreadId']}" name="tids[]" />
  248. EOF;
  249. }
  250. $return .= <<<EOF
  251. </td>
  252. <th>
  253. EOF;
  254. if(!isset($thread['icon'])) {
  255. $return .= <<<EOF
  256. <a href="forum.php?mod=viewthread&amp;tid={$thread['tThreadId']}" target="_blank" class="xst">{$thread['pSubject']}</a>
  257. EOF;
  258. } else {
  259. $return .= <<<EOF
  260. <a href="{$thread['mTargetUrl']}" target="_blank" class="xst">{$thread['mTitle']}</a>
  261. EOF;
  262. }
  263. $return .= <<<EOF
  264. </th>
  265. <td class="forum">
  266. EOF;
  267. if(!isset($thread['icon'])) {
  268. $return .= <<<EOF
  269. <a href="forum.php?mod=forumdisplay&amp;fid={$thread['pForumId']}">{$thread['pForumName']}</a>
  270. EOF;
  271. } else {
  272. $return .= <<<EOF
  273. {$thread['mShowUrl']}
  274. EOF;
  275. }
  276. $return .= <<<EOF
  277. </td>
  278. <td class="by">
  279. <cite>
  280. EOF;
  281. if($thread['pAuthorId'] && $thread['pAuthorName']) {
  282. $return .= <<<EOF
  283. <a href="home.php?mod=space&amp;uid={$thread['pAuthorId']}">{$thread['pAuthorName']}</a>
  284. EOF;
  285. } else {
  286. $return .= <<<EOF
  287. 匿名
  288. EOF;
  289. }
  290. $return .= <<<EOF
  291. </cite>
  292. EOF;
  293. if(!isset($thread['icon'])) {
  294. $return .= <<<EOF
  295. <em class="xi1">{$thread['dateline']}</em>
  296. EOF;
  297. }
  298. $return .= <<<EOF
  299. </td>
  300. </tr>
  301. EOF;
  302. }
  303. $return .= <<<EOF
  304. </table>
  305. </div>
  306. <div class="bm_c cl">
  307. <input type="hidden" value="{$_G['collection']['ctid']}" name="ctid" />
  308. <input type="hidden" name="formhash" id="formhash" value="{$__FORMHASH}" />
  309. <input type="hidden" name="addthread" id="addthread" value="1" />
  310. <button type="submit" class="pn pnc"><span>添加到淘专辑</span></button>
  311. </div>
  312. </form>
  313. EOF;
  314. } else {
  315. $return .= <<<EOF
  316. <p class="emp">
  317. 暂时还没有内容
  318. </p>
  319. EOF;
  320. }
  321. $return .= <<<EOF
  322. </div>
  323. EOF;
  324. if($multipage) {
  325. $return .= <<<EOF
  326. <div class="pgs mtm cl">{$multipage}</div>
  327. EOF;
  328. }
  329. $return .= <<<EOF
  330. EOF;
  331. ?><?php return $return;?><?php }
  332. function tpl_cloudsearch_relate_threadlist_output($kw) {
  333. global $_G;?><?php
  334. $__IMGDIR = IMGDIR;$return = <<<EOF
  335. <div id="cloudsearch_relate"><img src="{$__IMGDIR}/loading.gif" alt="loading..." class="vm" /> 正在加载……</div>
  336. <script>
  337. ajaxget('plugin.php?id=cloudsearch:forumdisplay&cloudop=relatelist&fid={$_G['fid']}&keyword={$kw}&page={$_G['page']}', 'cloudsearch_relate');
  338. </script>
  339. EOF;
  340. ?><?php return $return;?><?php }
  341. function tpl_cloudsearch_relate_threadlist_js_output($relatethreadlist, $urlkw, $searchparams, $srchotquery) {
  342. global $_G;?><?php
  343. $__IMGDIR = IMGDIR;$return = <<<EOF
  344. EOF;
  345. if($relatethreadlist) {
  346. $return .= <<<EOF
  347. <div class="th">
  348. <table cellspacing="0" cellpadding="0">
  349. <tr>
  350. <td class="icn"></td>
  351. <td class="common">相关主题</td>
  352. <td class="by">版块</td>
  353. <td class="by">作者</td>
  354. </tr>
  355. </table>
  356. </div>
  357. <div class="bm_c">
  358. <table cellspacing="0" cellpadding="0">
  359. EOF;
  360. if(is_array($relatethreadlist)) foreach($relatethreadlist as $thread) {
  361. $return .= <<<EOF
  362. <tbody id="{$thread['id']}">
  363. <tr>
  364. <td class="icn">
  365. EOF;
  366. if($thread['icon']) {
  367. $return .= <<<EOF
  368. <img src="{$thread['icon']}" />
  369. EOF;
  370. } else {
  371. $return .= <<<EOF
  372. <img src="{$__IMGDIR}/folder_common.gif" />
  373. EOF;
  374. }
  375. $return .= <<<EOF
  376. </td>
  377. <th>
  378. EOF;
  379. if(!isset($thread['icon'])) {
  380. $return .= <<<EOF
  381. <a href="forum.php?mod=viewthread&amp;tid={$thread['tThreadId']}" target="_blank" class="xst">{$thread['pSubject']}</a>
  382. EOF;
  383. } else {
  384. $return .= <<<EOF
  385. <a href="{$thread['mTargetUrl']}" target="_blank" class="xst">{$thread['mTitle']}</a>
  386. EOF;
  387. }
  388. $return .= <<<EOF
  389. </th>
  390. <td class="by">
  391. EOF;
  392. if(!isset($thread['icon'])) {
  393. $return .= <<<EOF
  394. <a href="forum.php?mod=forumdisplay&amp;fid={$thread['pForumId']}">{$thread['pForumName']}</a>
  395. EOF;
  396. } else {
  397. $return .= <<<EOF
  398. {$thread['mShowUrl']}
  399. EOF;
  400. }
  401. $return .= <<<EOF
  402. </td>
  403. <td class="by">
  404. <cite>
  405. EOF;
  406. if($thread['pAuthorId'] && $thread['pAuthorName']) {
  407. $return .= <<<EOF
  408. <a href="home.php?mod=space&amp;uid={$thread['pAuthorId']}">{$thread['pAuthorName']}</a>
  409. EOF;
  410. } else {
  411. $return .= <<<EOF
  412. 匿名
  413. EOF;
  414. }
  415. $return .= <<<EOF
  416. </cite>
  417. EOF;
  418. if(!isset($thread['icon'])) {
  419. $return .= <<<EOF
  420. <em class="xi1">{$thread['dateline']}</em>
  421. EOF;
  422. }
  423. $return .= <<<EOF
  424. </td>
  425. </tr>
  426. </tbody>
  427. EOF;
  428. }
  429. $return .= <<<EOF
  430. <tr>
  431. <td colspan="4" align="center" style="line-height:25px;">
  432. <a href="{$searchparams['url']}?q={$urlkw}&source=word.tao_more.a{$srchotquery}">查看更多</a>
  433. </td>
  434. </tr>
  435. </table>
  436. </div>
  437. EOF;
  438. }
  439. $return .= <<<EOF
  440. EOF;
  441. ?><?php return $return;?><?php }
  442. function tpl_cloudsearch_global_footer_related() {
  443. global $_G;
  444. $rel_title = urlencode($_G['forum_thread']['subject']);
  445. $widthauto = widthauto();
  446. $get_reltid = dintval($_GET[reltid]);
  447. $get_pre_pos = dhtmlspecialchars(trim($_GET[pre_pos]));?><?php
  448. $return = <<<EOF
  449. EOF;
  450. if(empty($_G['inajax'])) {
  451. $return .= <<<EOF
  452. <script type="text/javascript">
  453. var rel_tid = "{$_G['tid']}";
  454. var rel_title = "{$rel_title}";
  455. var rel_reltid = "{$get_reltid}";
  456. var rel_prepos = "{$get_pre_pos}";
  457. var my_siteid = "{$_G['setting']['my_siteid']}";
  458. var rel_uid = "{$_G['uid']}";
  459. var rel_views = "{$_G['forum_thread']['views']}";
  460. var rel_replies = "{$_G['forum_thread']['replies']}";
  461. var rel_page = "{$_G['page']}";
  462. var rel_show = "{$widthauto}";
  463. </script>
  464. <script src="http://cache.soso.com/30d/js/discuz/relate_subject.js" type="text/javascript" charset="GBK"></script>
  465. EOF;
  466. }
  467. $return .= <<<EOF
  468. EOF;
  469. ?><?php return $return;?><?php }
  470. function tpl_cloudsearch_global_footer_mini() {
  471. global $_G;
  472. $utilService = Cloud::loadClass('Service_Util');
  473. $params = array(
  474. 's_site_gid' => $_G['groupid'],
  475. 'response_type' => 'JSONP',
  476. );
  477. $params = $utilService->generateSiteSignUrl($params, false, true);
  478. $signUrlParams = json_encode($params);
  479. $discuz_mini_js_url = 'http://discuz.gtimg.cn/search/scripts/discuz_mini.js';
  480. $referer = htmlspecialchars($_SERVER['HTTP_REFERER']);?><?php
  481. $return = <<<EOF
  482. EOF;
  483. if(empty($_GET['inajax'])) {
  484. $return .= <<<EOF
  485. <script src="{$discuz_mini_js_url}" type="text/javascript"></script>
  486. <script type="text/javascript" charset="utf-8">
  487. if (typeof DiscuzMini != 'undefined' && typeof DiscuzMini == 'object') {
  488. DiscuzMini.showMini('{$referer}', {$signUrlParams});
  489. }
  490. </script>
  491. EOF;
  492. }
  493. $return .= <<<EOF
  494. EOF;
  495. ?><?php return $return;?><?php }
  496. function tpl_index_forum_extra_output($forum_recwords) {
  497. global $_G;?><?php
  498. $return = <<<EOF
  499. EOF;
  500. if($forum_recwords) {
  501. $return .= <<<EOF
  502. <dd class="fl_g_hot">
  503. <strong>热点: </strong>
  504. EOF;
  505. if(is_array($forum_recwords)) foreach($forum_recwords as $k => $frecword) {
  506. $return .= <<<EOF
  507. <a class="xi2" href="{$frecword['url']}" target="_blank">{$frecword['word']}</a>
  508. EOF;
  509. }
  510. $return .= <<<EOF
  511. </dd>
  512. EOF;
  513. }
  514. $return .= <<<EOF
  515. EOF;
  516. ?><?php return $return;?><?php }
  517. function tpl_cloudsearch_global_footer_suggest($queryString) {
  518. global $_G;?><?php
  519. $return = <<<EOF
  520. <script type="text/javascript">
  521. var cloudsearch_suggest = {};
  522. cloudsearch_suggest.cache = {}; // 缓存
  523. cloudsearch_suggest.sId = "{$_G['setting']['my_siteid']}";
  524. cloudsearch_suggest.keyInterval = null; // 按住上下键时的setTimeout时间值
  525. cloudsearch_suggest.requestTimeout = null; // 发送jsonp请求时的setTimeout时间值
  526. cloudsearch_suggest.responseTimeout = null; // jsonp请求超时时的setTimeout时间值
  527. cloudsearch_suggest.slideSpeed = 700; // 按住上下键时的滚动速度
  528. cloudsearch_suggest.linenow = 0; // 当前所在行
  529. cloudsearch_suggest.queryString = "{$queryString}"; // 当前所在行
  530. function cloudsearch_suggest_preventEnter(oEvent) {
  531. var code = oEvent.keyCode;
  532. var lines = $('sg').getElementsByTagName('li');
  533. if ((38 == code || 40 == code) && !cloudsearch_suggest.keyInterval) {
  534. cloudsearch_suggest_moveOneStep(code, lines);
  535. }
  536. }
  537. function cloudsearch_suggest_moveOneStep(code, lines) {
  538. if (38 == code || 40 == code) {
  539. var panel = $('sg');
  540. if ('block' == panel.style.display) {
  541. cloudsearch_suggest_clearStyle(); // 清掉所有li的选中状态
  542. var suggestNum = lines.length;
  543. if (38 == code) {
  544. if (cloudsearch_suggest.linenow > 1) {
  545. cloudsearch_suggest.linenow--;
  546. } else {
  547. cloudsearch_suggest.linenow = suggestNum;
  548. }
  549. }
  550. if (40 == code) {
  551. cloudsearch_suggest.linenow = (cloudsearch_suggest.linenow == suggestNum) ? 1 : (cloudsearch_suggest.linenow + 1);
  552. }
  553. lines[cloudsearch_suggest.linenow - 1].className = 'smo';
  554. }
  555. cloudsearch_suggest.keyInterval = setTimeout(function() {cloudsearch_suggest_moveOneStep(code, lines);}, cloudsearch_suggest.slideSpeed);
  556. cloudsearch_suggest.slideSpeed = 80;
  557. }
  558. }
  559. function cloudsearch_suggest_suggest(oEvent) {
  560. var q = trim($('scbar_txt').value); // 输入框的输入
  561. var code = oEvent.keyCode; // 键盘按键值
  562. var lines = $('sg').getElementsByTagName('li');
  563. if (38 == code || 40 == code) { // up down
  564. if (null != cloudsearch_suggest.keyInterval) {
  565. clearTimeout(cloudsearch_suggest.keyInterval);
  566. cloudsearch_suggest.keyInterval = null;
  567. cloudsearch_suggest.slideSpeed = 700;
  568. }
  569. // 把所选值放入输入框(去除html标签)
  570. $('scbar_txt').value = lines[cloudsearch_suggest.linenow - 1].innerHTML.replace(/<\s*(\/)?\s*[0-9a-zA-Z]+\s*>/g, '');
  571. } else if (27 == code) { // ESC
  572. if (null != cloudsearch_suggest.requestTimeout) {
  573. clearTimeout(cloudsearch_suggest.requestTimeout);
  574. }
  575. cloudsearch_suggest_hide();
  576. } else {
  577. if ('' != q) {
  578. var data = cloudsearch_suggest_getCache(q);
  579. if (data) {
  580. cloudsearch_suggest_menuMaker(data);
  581. } else {
  582. if (null != cloudsearch_suggest.requestTimeout) {
  583. clearTimeout(cloudsearch_suggest.requestTimeout);
  584. }
  585. // 请求延时0.3秒执行,因为有可能用户是在持续输入
  586. cloudsearch_suggest.requestTimeout = setTimeout(function() {cloudsearch_suggest_sendRequest(q);}, 500);
  587. }
  588. } else {
  589. if (null != cloudsearch_suggest.requestTimeout) {
  590. clearTimeout(cloudsearch_suggest.requestTimeout);
  591. }
  592. cloudsearch_suggest_hide();
  593. }
  594. }
  595. }
  596. function cloudsearch_suggest_sendRequest(q) {
  597. // 删掉之前的请求(包括超时处理)
  598. if ($('cloudsearch_suggest') != null) {
  599. document.getElementsByTagName('head')[0].removeChild($('cloudsearch_suggest'));
  600. if (null != cloudsearch_suggest.responseTimeout) {
  601. clearTimeout(cloudsearch_suggest.responseTimeout);
  602. }
  603. }
  604. var script = document.createElement('script');
  605. with (script) {
  606. src = 'http://search.discuz.qq.com/api/suggest?q=' + encodeURIComponent(q) + '&' + cloudsearch_suggest.queryString;
  607. id = 'cloudsearch_suggest';
  608. charset = 'utf-8';
  609. }
  610. document.getElementsByTagName('head')[0].appendChild(script); // jsonp加载外域接口数据
  611. cloudsearch_suggest.responseTimeout = setTimeout(function() {cloudsearch_suggest_clearRequest();}, 1000); // 0.5秒后没返回就抛弃
  612. }
  613. function cloudsearch_suggest_clearRequest() {
  614. // 删掉之前的请求(包括超时处理)
  615. if ($('cloudsearch_suggest') != null) {
  616. document.getElementsByTagName('head')[0].removeChild($('cloudsearch_suggest'));
  617. }
  618. }
  619. function cloudsearch_suggest_callback(data) {
  620. if (typeof data != undefined && 0 == data.status) {
  621. cloudsearch_suggest_menuMaker(data.result);
  622. cloudsearch_suggest_setCache(data.q, data.result);
  623. }
  624. }
  625. function cloudsearch_suggest_menuMaker(data) {
  626. if (data.length > 0) {
  627. var list = '<ul>';
  628. for (var i = 0; i < data.length; i++) {
  629. list += '<li class="sml" onmouseover="cloudsearch_suggest_mouseOver(this);" onclick="cloudsearch_suggest_mouseClick(this);">' + data[i] + '</li>';
  630. }
  631. list += '</ul>';
  632. $('st_box').innerHTML = list;
  633. cloudsearch_suggest_show();
  634. }
  635. }
  636. function cloudsearch_suggest_mouseClick(obj) {
  637. $('scbar_txt').value = obj.innerHTML.replace(/<\s*(\/)?\s*[0-9a-zA-Z]+\s*>/g, '');
  638. $('scbar_btn').click();
  639. }
  640. function cloudsearch_suggest_mouseOver(obj) {
  641. cloudsearch_suggest_clearStyle(); // 清掉之前的选中状态
  642. obj.className = "smo"; // 当前的li设置为选中状态
  643. // 把linenow设置为当前悬停的值
  644. var lis = $('st_box').getElementsByTagName('li');
  645. if (typeof lis != undefined && lis.length > 0) {
  646. for (var i = 0; i < lis.length; i++) {
  647. if (lis[i] == obj) {
  648. cloudsearch_suggest.linenow = i + 1;
  649. break;
  650. }
  651. }
  652. }
  653. }
  654. function cloudsearch_suggest_show(oEvent) {
  655. cloudsearch_suggest.linenow = 0;
  656. cloudsearch_suggest.slideSpeed = 700;
  657. $('sg').style.display = 'block';
  658. $('scbar_txt').focus();
  659. }
  660. function cloudsearch_suggest_hide() {
  661. $('sg').style.display = 'none';
  662. }
  663. function cloudsearch_suggest_setCache(key, data) {
  664. cloudsearch_suggest.cache[key] = data;
  665. }
  666. function cloudsearch_suggest_getCache(key) {
  667. return cloudsearch_suggest.cache[key];
  668. }
  669. function cloudsearch_suggest_clearStyle() {
  670. var lis = $('st_box').getElementsByTagName('li');
  671. if (typeof lis != undefined && lis.length > 0) {
  672. for (var i = 0; i < lis.length; i++) {
  673. lis[i].className = 'sml';
  674. }
  675. }
  676. }
  677. function cloudsearch_suggest_sgMouseOver() {
  678. $('scbar_txt').focus();
  679. _detachEvent($('scbar_txt'), 'blur', cloudsearch_suggest_hide);
  680. }
  681. function cloudsearch_suggest_sgMouseOut() {
  682. cloudsearch_suggest_clearStyle();
  683. _attachEvent($('scbar_txt'), 'blur', cloudsearch_suggest_hide);
  684. }
  685. if (!BROWSER.ie || BROWSER.ie > 6) {
  686. // 输入框绑定onkeydown和onkeyup事件
  687. _attachEvent($('scbar_txt'), 'keydown', cloudsearch_suggest_preventEnter);
  688. _attachEvent($('scbar_txt'), 'keyup', cloudsearch_suggest_suggest);
  689. _attachEvent($('scbar_txt'), 'blur', cloudsearch_suggest_hide);
  690. _attachEvent($('sg'), 'mouseover', cloudsearch_suggest_sgMouseOver);
  691. _attachEvent($('sg'), 'mouseout', cloudsearch_suggest_sgMouseOut);
  692. }
  693. </script>
  694. EOF;
  695. ?><?php return $return;?><?php }?>