123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337 |
- <?php
- if (!defined('IN_DISCUZ')) {
- exit('Access Denied');
- }
- class base_baidusubmit
- {
- function __construct()
- {
- define('__BDS_ROOT__', dirname(__FILE__) . DIRECTORY_SEPARATOR);
- include_once (__BDS_ROOT__ . 'function/function_baidu.php');
- include_once (__BDS_ROOT__ . 'class_schema.php');
- $opencse = baidu_get_plugin_setting('baiducse');
- $openTime = baidu_get_plugin_setting('auto_time');
- $auto = baidu_get_plugin_setting('auto');
- if ($opencse == 2 && (time() >= $openTime || $auto == 0)) {
- $this->value['header'] = $this->getHeaderHtml();
- $this->value['footer'] = $this->getFooterHtml_V2();
- } else if ($opencse == 1 && (time() >= $openTime || $auto == 0)) {
- $this->value['footer'] = $this->getFooterHtml_V1();
- }
- }
- function common()
- {
- $opencse = baidu_get_plugin_setting('baiducse');
- $openTime = baidu_get_plugin_setting('auto_time');
- $auto = baidu_get_plugin_setting('auto');
- if (CURSCRIPT == 'search' && $opencse > 0 && (time() >= $openTime || $auto == 0)) {
- $sid = baidu_get_plugin_setting('engine');
- $searchUser = baidu_get_plugin_setting('user_sitemap');
- $config = baidu_get_plugin_config();
- if (isset($_GET['mod']) && $_GET['mod']) {
- $mod = $_GET['mod'];
- } else if (isset($_POST['mod']) && $_POST['mod']) {
- $mod = $_POST['mod'];
- } else {
- $mod = '';
- }
- if (isset($_GET['kw']) && $_GET['kw']) {
- $query = trim($_GET['kw']);
- } else if (isset($_POST['srchtxt']) && $_POST['srchtxt']) {
- $query = trim($_POST['srchtxt']);
- } else if (isset($_GET['srchtxt']) && $_GET['srchtxt']) {
- $query = trim($_GET['srchtxt']);
- } else {
- $query = '';
- }
- $zn = sprintf($config['zhannei'], $sid) . "&q=" . urlencode($query) . "&partner=discuz";
- switch ($mod) {
- case 'forum':
- header("Location:" . $zn);
- exit;
- break;
- case 'user':
- if ($searchUser) {
- header("Location:" . $zn . "&fst=2");
- exit;
- }
- break;
- default :
- break;
- }
- }
- }
- }
- class plugin_baidusubmit extends base_baidusubmit
- {
- public $value = array();
- function deletethread($value)
- {
- if (!baidu_get_plugin_setting('openping'))
- return;
- if (baidu_senddata_error())
- return;
- $tidlist = $value['param'][0];
- $tidstr = join('_', $tidlist);
- if (defined("_bds_wew_{$tidstr}"))
- return;
- define("_bds_wew_{$tidstr}", true);
- if (!empty($tidlist)) {
- foreach ($tidlist as $tid) {
- $schema = new BaiduThreadSchema();
- $url = baidu_gen_thread_url($tid, 1, 1);
- $schema->setThreadUrl($url);
- baidu_send_data($schema, 2);
- }
- }
- }
- function __destruct()
- {
- //flush(); //个别web配置下会出错
- if (!empty($_GET['inajax']))
- return;
- if (empty($_GET['action']) || 'newthread' !== $_GET['action'])
- return;
- if ('yes' !== $_GET['topicsubmit'])
- return;
- if ($_POST['formhash'] != FORMHASH)
- return;
- global $tid;
- if (empty($tid))
- return;
- if (defined("_bds_w9x_{$tid}"))
- return;
- define("_bds_w9x_{$tid}", true);
- if (!baidu_get_plugin_setting('openping'))
- return;
- if (baidu_senddata_error())
- return;
- //发新帖
- $thread = get_thread_by_tid($tid);
- if ($thread) {
- $url = baidu_gen_thread_url($tid, 1, 1, $thread['fid']);
- $schema = new BaiduThreadSchema();
- $schema->setThreadUrl($url);
- baidu_send_data($schema, 1);
- }
- }
- function getHeaderHtml()
- {
- return <<<EOF
- <style>
- #bdcs{width: 630px}
- #zn_baidu {width: 100%;margin:5px 0}
- .ct {margin: 0 auto;min-width: 960px;width: 98%}
- </style>
- <div id="zn_baidu">
- <div class='ct' id="baidu_ct">
- <div id="bdcs"></div>
- </div>
- </div>
- <script type="text/javascript">
- hideDzSearchBar();
- function hideDzSearchBar(){
- var scbar = $('scbar');
- var hd = $('hd');
- var form = document.getElementsByTagName("form")[0];
- if (scbar) {
- scbar.style.display = 'none';
- } else if (form && form.action.indexOf('search.php?searchsubmit=yes') != -1){
- form.style.display = 'none';
- }
- if (hd && hd.getElementsByTagName('div')[0]){
- $('baidu_ct').style.width = getStyle(hd.getElementsByTagName('div')[0],'width');
- }
- }
- function getStyle(elem, name) {
- var inlineName = name ;
- var oriName = name;
- if(elem.style.inlineName) {
- return elem.style[inlineName];
- } else if(document.defaultView && document.defaultView.getComputedStyle) {
- return document.defaultView.getComputedStyle(elem, null).getPropertyValue(oriName);
- } else if(elem.currentStyle) {
- return elem.currentStyle[inlineName];
- } else {
- return null;
- }
- }
- </script>
- EOF;
- }
- function global_header()
- {
- return isset($this->value['header']) ? $this->value['header'] : array();
- }
- function getFooterHtml_V1()
- {
- $config = baidu_get_plugin_config();
- $sid = baidu_get_plugin_setting('engine');
- $searchUser = baidu_get_plugin_setting('user_sitemap');
- $zn = sprintf($config['zhannei'], $sid);
- return <<<EOF
- <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>
- <script src="source/plugin/baidusubmit/template/jquery-1.8.3.min.js"></script>
- <script type="text/javascript">
- var bdjq = jQuery.noConflict(true);
- function znForDz(siteConfig){
- bdjq(function(){
- var zn = '{$zn}';
- if (siteConfig && siteConfig.resultUrl){
- zn = 'http://' + siteConfig.resultUrl + '/cse/search?s={$sid}'
- }
- var btn = bdjq("#scbar_btn");
- if (btn.length == 0) {
- btn = bdjq('button[name="searchsubmit"]');
- }
- if (btn.length == 0) {
- btn = bdjq('input[name="searchsubmit"]');
- }
- if (btn.length == 0) {
- btn = bdjq('#scbar_form input[type="submit"]');
- }
- if (btn.length == 0) {
- btn = bdjq('#scbar_form button');
- }
- if (btn.length > 0) {
- btn.click(function(event){
- var mod = bdjq('#scbar_mod').val() || bdjq('form input[name="mod"]').val()
- var st = '';
- var txt = bdjq('#scbar_txt').val() || bdjq('form input[name="srchtxt"]').val();
- var user = '$searchUser';
- if (mod === 'user' && user === '1'){
- st = 2;
- window.open(zn + "&q=" + encodeURIComponent(txt) + "&fst=" + st + "&partner=discuz");
- event.preventDefault();
- } else if (mod === 'forum'){
- window.open(zn + "&q=" + encodeURIComponent(txt) + "&partner=discuz");
- event.preventDefault();
- }
- });
- }
- var hot = bdjq('#scbar_hot a')
- if (hot.length > 0){
- hot.click(function(event){
- var txt = bdjq(this).text();
- window.open(zn + "&q=" + encodeURIComponent(txt) + "&partner=discuz");
- event.preventDefault();
- });
- }
- });
- }
- </script>
- EOF;
- }
- function global_footer()
- {
- return isset($this->value['footer']) ? $this->value['footer'] : array();
- }
- function getFooterHtml_V2()
- {
- $config = baidu_get_plugin_config();
- $sid = baidu_get_plugin_setting('engine');
- return <<<EOF
- <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>
- EOF;
- }
- }
- class mobileplugin_baidusubmit extends base_baidusubmit
- {
- function getHeaderHtml()
- {
- return <<<EOF
- <div style="clear:both"></div>
- <div id='bdcs' style="margin:5px 0"></div>
- EOF;
- }
- function global_footer_mobile()
- {
- return isset($this->value['footer']) ? $this->value['footer'] : array();
- }
- function getFooterHtml_V1()
- {
- $config = baidu_get_plugin_config();
- $sid = baidu_get_plugin_setting('engine');
- $zn = sprintf($config['zhannei'], $sid);
- return <<<EOF
- <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>
- <script src="source/plugin/baidusubmit/template/jquery-1.8.3.min.js"></script>
- <script type="text/javascript">
- var bdjq = jQuery.noConflict(true);
- function znForDz(siteConfig){
- bdjq(function(){
- var zn = '{$zn}';
- if (siteConfig && siteConfig.resultUrl){
- zn = 'http://' + siteConfig.resultUrl + '/cse/search?s={$sid}'
- }
- var btn = bdjq("a[href^='search.php?mod']");
- if (btn.length > 0) {
- btn.click(function(event){
- window.location.href = zn+ '&q=&partner=discuz';
- event.preventDefault();
- });
- }
- });
- }
- </script>
- EOF;
- }
- function getFooterHtml_V2()
- {
- $config = baidu_get_plugin_config();
- $sid = baidu_get_plugin_setting('engine');
- return <<<EOF
- <script src="source/plugin/baidusubmit/template/jquery-1.8.3.min.js"></script>
- <script type="text/javascript">
- var bdjq = jQuery.noConflict(true);
- bdjq("a[href^='search.php?mod']").hide();
- </script>
- <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>
- EOF;
- }
- }
- class mobileplugin_baidusubmit_forum extends mobileplugin_baidusubmit
- {
- function index_top_mobile()
- {
- return isset($this->value['header']) ? $this->value['header'] : array();
- }
- function forumdisplay_top_mobile()
- {
- return isset($this->value['header']) ? $this->value['header'] : array();
- }
- }
|