baidusubmit.class.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  1. <?php
  2. if (!defined('IN_DISCUZ')) {
  3. exit('Access Denied');
  4. }
  5. class base_baidusubmit
  6. {
  7. function __construct()
  8. {
  9. define('__BDS_ROOT__', dirname(__FILE__) . DIRECTORY_SEPARATOR);
  10. include_once (__BDS_ROOT__ . 'function/function_baidu.php');
  11. include_once (__BDS_ROOT__ . 'class_schema.php');
  12. $opencse = baidu_get_plugin_setting('baiducse');
  13. $openTime = baidu_get_plugin_setting('auto_time');
  14. $auto = baidu_get_plugin_setting('auto');
  15. if ($opencse == 2 && (time() >= $openTime || $auto == 0)) {
  16. $this->value['header'] = $this->getHeaderHtml();
  17. $this->value['footer'] = $this->getFooterHtml_V2();
  18. } else if ($opencse == 1 && (time() >= $openTime || $auto == 0)) {
  19. $this->value['footer'] = $this->getFooterHtml_V1();
  20. }
  21. }
  22. function common()
  23. {
  24. $opencse = baidu_get_plugin_setting('baiducse');
  25. $openTime = baidu_get_plugin_setting('auto_time');
  26. $auto = baidu_get_plugin_setting('auto');
  27. if (CURSCRIPT == 'search' && $opencse > 0 && (time() >= $openTime || $auto == 0)) {
  28. $sid = baidu_get_plugin_setting('engine');
  29. $searchUser = baidu_get_plugin_setting('user_sitemap');
  30. $config = baidu_get_plugin_config();
  31. if (isset($_GET['mod']) && $_GET['mod']) {
  32. $mod = $_GET['mod'];
  33. } else if (isset($_POST['mod']) && $_POST['mod']) {
  34. $mod = $_POST['mod'];
  35. } else {
  36. $mod = '';
  37. }
  38. if (isset($_GET['kw']) && $_GET['kw']) {
  39. $query = trim($_GET['kw']);
  40. } else if (isset($_POST['srchtxt']) && $_POST['srchtxt']) {
  41. $query = trim($_POST['srchtxt']);
  42. } else if (isset($_GET['srchtxt']) && $_GET['srchtxt']) {
  43. $query = trim($_GET['srchtxt']);
  44. } else {
  45. $query = '';
  46. }
  47. $zn = sprintf($config['zhannei'], $sid) . "&q=" . urlencode($query) . "&partner=discuz";
  48. switch ($mod) {
  49. case 'forum':
  50. header("Location:" . $zn);
  51. exit;
  52. break;
  53. case 'user':
  54. if ($searchUser) {
  55. header("Location:" . $zn . "&fst=2");
  56. exit;
  57. }
  58. break;
  59. default :
  60. break;
  61. }
  62. }
  63. }
  64. }
  65. class plugin_baidusubmit extends base_baidusubmit
  66. {
  67. public $value = array();
  68. function deletethread($value)
  69. {
  70. if (!baidu_get_plugin_setting('openping'))
  71. return;
  72. if (baidu_senddata_error())
  73. return;
  74. $tidlist = $value['param'][0];
  75. $tidstr = join('_', $tidlist);
  76. if (defined("_bds_wew_{$tidstr}"))
  77. return;
  78. define("_bds_wew_{$tidstr}", true);
  79. if (!empty($tidlist)) {
  80. foreach ($tidlist as $tid) {
  81. $schema = new BaiduThreadSchema();
  82. $url = baidu_gen_thread_url($tid, 1, 1);
  83. $schema->setThreadUrl($url);
  84. baidu_send_data($schema, 2);
  85. }
  86. }
  87. }
  88. function __destruct()
  89. {
  90. //flush(); //个别web配置下会出错
  91. if (!empty($_GET['inajax']))
  92. return;
  93. if (empty($_GET['action']) || 'newthread' !== $_GET['action'])
  94. return;
  95. if ('yes' !== $_GET['topicsubmit'])
  96. return;
  97. if ($_POST['formhash'] != FORMHASH)
  98. return;
  99. global $tid;
  100. if (empty($tid))
  101. return;
  102. if (defined("_bds_w9x_{$tid}"))
  103. return;
  104. define("_bds_w9x_{$tid}", true);
  105. if (!baidu_get_plugin_setting('openping'))
  106. return;
  107. if (baidu_senddata_error())
  108. return;
  109. //发新帖
  110. $thread = get_thread_by_tid($tid);
  111. if ($thread) {
  112. $url = baidu_gen_thread_url($tid, 1, 1, $thread['fid']);
  113. $schema = new BaiduThreadSchema();
  114. $schema->setThreadUrl($url);
  115. baidu_send_data($schema, 1);
  116. }
  117. }
  118. function getHeaderHtml()
  119. {
  120. return <<<EOF
  121. <style>
  122. #bdcs{width: 630px}
  123. #zn_baidu {width: 100%;margin:5px 0}
  124. .ct {margin: 0 auto;min-width: 960px;width: 98%}
  125. </style>
  126. <div id="zn_baidu">
  127. <div class='ct' id="baidu_ct">
  128. <div id="bdcs"></div>
  129. </div>
  130. </div>
  131. <script type="text/javascript">
  132. hideDzSearchBar();
  133. function hideDzSearchBar(){
  134. var scbar = $('scbar');
  135. var hd = $('hd');
  136. var form = document.getElementsByTagName("form")[0];
  137. if (scbar) {
  138. scbar.style.display = 'none';
  139. } else if (form && form.action.indexOf('search.php?searchsubmit=yes') != -1){
  140. form.style.display = 'none';
  141. }
  142. if (hd && hd.getElementsByTagName('div')[0]){
  143. $('baidu_ct').style.width = getStyle(hd.getElementsByTagName('div')[0],'width');
  144. }
  145. }
  146. function getStyle(elem, name) {
  147. var inlineName = name ;
  148. var oriName = name;
  149. if(elem.style.inlineName) {
  150. return elem.style[inlineName];
  151. } else if(document.defaultView && document.defaultView.getComputedStyle) {
  152. return document.defaultView.getComputedStyle(elem, null).getPropertyValue(oriName);
  153. } else if(elem.currentStyle) {
  154. return elem.currentStyle[inlineName];
  155. } else {
  156. return null;
  157. }
  158. }
  159. </script>
  160. EOF;
  161. }
  162. function global_header()
  163. {
  164. return isset($this->value['header']) ? $this->value['header'] : array();
  165. }
  166. function getFooterHtml_V1()
  167. {
  168. $config = baidu_get_plugin_config();
  169. $sid = baidu_get_plugin_setting('engine');
  170. $searchUser = baidu_get_plugin_setting('user_sitemap');
  171. $zn = sprintf($config['zhannei'], $sid);
  172. return <<<EOF
  173. <script type="text/javascript">(function(){var bdcs = document.createElement('script');bdcs.type = 'text/javascript';bdcs.async = true;bdcs.src = "{$config['znsv']}/customer_search/api/js?sid={$sid}" + '&plate_url=' + encodeURIComponent(window.location.href) + '&t=' + Math.ceil(new Date()/3600000) + '&callback=znForDz';var s = document.getElementsByTagName('script')[0];s.parentNode.insertBefore(bdcs, s);})();</script>
  174. <script src="source/plugin/baidusubmit/template/jquery-1.8.3.min.js"></script>
  175. <script type="text/javascript">
  176. var bdjq = jQuery.noConflict(true);
  177. function znForDz(siteConfig){
  178. bdjq(function(){
  179. var zn = '{$zn}';
  180. if (siteConfig && siteConfig.resultUrl){
  181. zn = 'http://' + siteConfig.resultUrl + '/cse/search?s={$sid}'
  182. }
  183. var btn = bdjq("#scbar_btn");
  184. if (btn.length == 0) {
  185. btn = bdjq('button[name="searchsubmit"]');
  186. }
  187. if (btn.length == 0) {
  188. btn = bdjq('input[name="searchsubmit"]');
  189. }
  190. if (btn.length == 0) {
  191. btn = bdjq('#scbar_form input[type="submit"]');
  192. }
  193. if (btn.length == 0) {
  194. btn = bdjq('#scbar_form button');
  195. }
  196. if (btn.length > 0) {
  197. btn.click(function(event){
  198. var mod = bdjq('#scbar_mod').val() || bdjq('form input[name="mod"]').val()
  199. var st = '';
  200. var txt = bdjq('#scbar_txt').val() || bdjq('form input[name="srchtxt"]').val();
  201. var user = '$searchUser';
  202. if (mod === 'user' && user === '1'){
  203. st = 2;
  204. window.open(zn + "&q=" + encodeURIComponent(txt) + "&fst=" + st + "&partner=discuz");
  205. event.preventDefault();
  206. } else if (mod === 'forum'){
  207. window.open(zn + "&q=" + encodeURIComponent(txt) + "&partner=discuz");
  208. event.preventDefault();
  209. }
  210. });
  211. }
  212. var hot = bdjq('#scbar_hot a')
  213. if (hot.length > 0){
  214. hot.click(function(event){
  215. var txt = bdjq(this).text();
  216. window.open(zn + "&q=" + encodeURIComponent(txt) + "&partner=discuz");
  217. event.preventDefault();
  218. });
  219. }
  220. });
  221. }
  222. </script>
  223. EOF;
  224. }
  225. function global_footer()
  226. {
  227. return isset($this->value['footer']) ? $this->value['footer'] : array();
  228. }
  229. function getFooterHtml_V2()
  230. {
  231. $config = baidu_get_plugin_config();
  232. $sid = baidu_get_plugin_setting('engine');
  233. return <<<EOF
  234. <script type="text/javascript">(function(){hideDzSearchBar();var bdcs = document.createElement('script');bdcs.type = 'text/javascript';bdcs.async = true;bdcs.src = "{$config['znsv']}/customer_search/api/js?sid={$sid}" + '&plate_url=' + encodeURIComponent(window.location.href) + '&t=' + Math.ceil(new Date()/3600000);var s = document.getElementsByTagName('script')[0];s.parentNode.insertBefore(bdcs, s);})();</script>
  235. EOF;
  236. }
  237. }
  238. class mobileplugin_baidusubmit extends base_baidusubmit
  239. {
  240. function getHeaderHtml()
  241. {
  242. return <<<EOF
  243. <div style="clear:both"></div>
  244. <div id='bdcs' style="margin:5px 0"></div>
  245. EOF;
  246. }
  247. function global_footer_mobile()
  248. {
  249. return isset($this->value['footer']) ? $this->value['footer'] : array();
  250. }
  251. function getFooterHtml_V1()
  252. {
  253. $config = baidu_get_plugin_config();
  254. $sid = baidu_get_plugin_setting('engine');
  255. $zn = sprintf($config['zhannei'], $sid);
  256. return <<<EOF
  257. <script type="text/javascript">(function(){var bdcs = document.createElement('script');bdcs.type = 'text/javascript';bdcs.async = true;bdcs.src = "{$config['znsv']}/customer_search/api/js?sid={$sid}" + '&plate_url=' + encodeURIComponent(window.location.href) + '&t=' + Math.ceil(new Date()/3600000) + '&callback=znForDz';var s = document.getElementsByTagName('script')[0];s.parentNode.insertBefore(bdcs, s);})();</script>
  258. <script src="source/plugin/baidusubmit/template/jquery-1.8.3.min.js"></script>
  259. <script type="text/javascript">
  260. var bdjq = jQuery.noConflict(true);
  261. function znForDz(siteConfig){
  262. bdjq(function(){
  263. var zn = '{$zn}';
  264. if (siteConfig && siteConfig.resultUrl){
  265. zn = 'http://' + siteConfig.resultUrl + '/cse/search?s={$sid}'
  266. }
  267. var btn = bdjq("a[href^='search.php?mod']");
  268. if (btn.length > 0) {
  269. btn.click(function(event){
  270. window.location.href = zn+ '&q=&partner=discuz';
  271. event.preventDefault();
  272. });
  273. }
  274. });
  275. }
  276. </script>
  277. EOF;
  278. }
  279. function getFooterHtml_V2()
  280. {
  281. $config = baidu_get_plugin_config();
  282. $sid = baidu_get_plugin_setting('engine');
  283. return <<<EOF
  284. <script src="source/plugin/baidusubmit/template/jquery-1.8.3.min.js"></script>
  285. <script type="text/javascript">
  286. var bdjq = jQuery.noConflict(true);
  287. bdjq("a[href^='search.php?mod']").hide();
  288. </script>
  289. <script type="text/javascript">(function(){var bdcs = document.createElement('script');bdcs.type = 'text/javascript';bdcs.async = true;bdcs.src = "{$config['znsv']}/customer_search/api/js?sid={$sid}" + '&plate_url=' + encodeURIComponent(window.location.href) + '&t=' + Math.ceil(new Date()/3600000);var s = document.getElementsByTagName('script')[0];s.parentNode.insertBefore(bdcs, s);})();</script>
  290. EOF;
  291. }
  292. }
  293. class mobileplugin_baidusubmit_forum extends mobileplugin_baidusubmit
  294. {
  295. function index_top_mobile()
  296. {
  297. return isset($this->value['header']) ? $this->value['header'] : array();
  298. }
  299. function forumdisplay_top_mobile()
  300. {
  301. return isset($this->value['header']) ? $this->value['header'] : array();
  302. }
  303. }