From d55d06507c5f19e9b6fa895f8ce5db1a62827040 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=91=E8=90=BD?= Date: Wed, 6 Oct 2021 21:44:41 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8E=A8=E9=80=81=E4=B8=80=E4=BA=9B=E6=96=87?= =?UTF-8?q?=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 9 +- assets/js/gdk.js | 2 +- class/ai.php | 45 ++++ class/ai/AipContentCensor.php | 25 +++ class/ai/AipNlp.php | 197 +++++++++++++++++ class/ai/lib/AipBCEUtil.php | 345 +++++++++++++++++++++++++++++ class/ai/lib/AipBase.php | 394 +++++++++++++++++++++++++++++++++ class/ai/lib/AipHttpClient.php | 214 ++++++++++++++++++ class/class_load.php | 2 +- framework/options-config.php | 12 + framework/plugin-options.php | 56 ++--- functions/Ajax.php | 8 +- functions/Common.php | 36 +-- functions/advanced.php | 42 +++- functions/optimization.php | 3 + functions/rewrite.php | 1 - functions/security.php | 2 +- functions/server.php | 121 ++++++++-- functions/shortcode.php | 68 +++++- gdk.php | 14 +- public/daohang.php | 64 +++++- public/sitemap-xml.php | 2 +- 22 files changed, 1531 insertions(+), 131 deletions(-) create mode 100644 class/ai.php create mode 100644 class/ai/AipContentCensor.php create mode 100644 class/ai/AipNlp.php create mode 100644 class/ai/lib/AipBCEUtil.php create mode 100644 class/ai/lib/AipBase.php create mode 100644 class/ai/lib/AipHttpClient.php diff --git a/.gitignore b/.gitignore index cbaadde..ceae2f8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,7 @@ -desktop.ini +cache/*.txt +.coding-ide/* .ecloud/* -.git/ -public/cache/*.txt +*.ini +.vscode/* +.SynologyWorkingDirectory/* +*/cache/* diff --git a/assets/js/gdk.js b/assets/js/gdk.js index e4daa1c..ed482a3 100644 --- a/assets/js/gdk.js +++ b/assets/js/gdk.js @@ -64,7 +64,7 @@ jQuery(function($) { /**澹版槑鍔犺浇jQuery */ */ function setCookie(e, t, o) { var i = new Date; - i.setDate(i.getDate() + o), document.cookie = e + "=" + escape(t) + (null == o ? "" : ";expires=" + i.toGMTString()) + i.setDate(i.getDate() + o), document.cookie = e + "=" + escape(t) + (null == o ? "" : ";expires=" + i.toGMTString()) + ";Secure" }; /** * diff --git a/class/ai.php b/class/ai.php new file mode 100644 index 0000000..b822b6a --- /dev/null +++ b/class/ai.php @@ -0,0 +1,45 @@ +newsSummary($content, $maxSummaryLen); + +var_dump($result); + + +$my_post = array( + 'ID' => $post_ID, +'post_excerpt' => $result //摘要信息 + +); + + +//入库 + +//wp_insert_post( $my_post ); + +} +add_action('publish_post', 'gdk_newsSummary', 0); +add_action('update_post', 'gdk_newsSummary', 0); \ No newline at end of file diff --git a/class/ai/AipContentCensor.php b/class/ai/AipContentCensor.php new file mode 100644 index 0000000..34c3651 --- /dev/null +++ b/class/ai/AipContentCensor.php @@ -0,0 +1,25 @@ +request($this->commentTagUrl, $data); + } + + /** + * 鎯呮劅鍊惧悜鍒嗘瀽鎺ュ彛 + * + * @param string $text - 鏂囨湰鍐呭锛圙BK缂栫爜锛夛紝鏈澶102400瀛楄妭 + * @param array $options - 鍙夊弬鏁板璞★紝key: value閮戒负string绫诲瀷 + * @description options鍒楄〃: + * @return array + */ + public function sentimentClassify($text, $options=array()){ + + $data = array(); + + $data['text'] = $text; + + $data = array_merge($data, $options); + $data = mb_convert_encoding(json_encode($data), 'GBK', 'UTF8'); + + return $this->request($this->sentimentClassifyUrl, $data); + } + + /** + * 鏂囩珷鏍囩鎺ュ彛 + * + * @param string $title - 绡囩珷鐨勬爣棰橈紝鏈澶80瀛楄妭 + * @param string $content - 绡囩珷鐨勬鏂囷紝鏈澶65535瀛楄妭 + * @param array $options - 鍙夊弬鏁板璞★紝key: value閮戒负string绫诲瀷 + * @description options鍒楄〃: + * @return array + */ + public function keyword($title, $content, $options=array()){ + + $data = array(); + + $data['title'] = $title; + $data['content'] = $content; + + $data = array_merge($data, $options); + $data = mb_convert_encoding(json_encode($data), 'GBK', 'UTF8'); + + return $this->request($this->keywordUrl, $data); + } + + /** + * 鏂囩珷鍒嗙被鎺ュ彛 + * + * @param string $title - 绡囩珷鐨勬爣棰橈紝鏈澶80瀛楄妭 + * @param string $content - 绡囩珷鐨勬鏂囷紝鏈澶65535瀛楄妭 + * @param array $options - 鍙夊弬鏁板璞★紝key: value閮戒负string绫诲瀷 + * @description options鍒楄〃: + * @return array + */ + public function topic($title, $content, $options=array()){ + + $data = array(); + + $data['title'] = $title; + $data['content'] = $content; + + $data = array_merge($data, $options); + $data = mb_convert_encoding(json_encode($data), 'GBK', 'UTF8'); + + return $this->request($this->topicUrl, $data); + } + + /** + * 鏂囨湰绾犻敊鎺ュ彛 + * + * @param string $text - 寰呯籂閿欐枃鏈紝杈撳叆闄愬埗511瀛楄妭 + * @param array $options - 鍙夊弬鏁板璞★紝key: value閮戒负string绫诲瀷 + * @description options鍒楄〃: + * @return array + */ + public function ecnet($text, $options=array()){ + + $data = array(); + + $data['text'] = $text; + + $data = array_merge($data, $options); + $data = mb_convert_encoding(json_encode($data), 'GBK', 'UTF8'); + + return $this->request($this->ecnetUrl, $data); + } + + /** + * 鏂伴椈鎽樿鎺ュ彛鎺ュ彛 + * + * @param string $content - 瀛楃涓诧紙闄3000瀛楃鏁颁互鍐咃級瀛楃涓蹭粎鏀寔GBK缂栫爜锛岄暱搴﹂渶灏忎簬3000瀛楃鏁帮紙鍗6000瀛楄妭锛夛紝璇疯緭鍏ュ墠纭瀛楃鏁版病鏈夎秴闄愶紝鑻ュ瓧绗︽暟瓒呴暱浼氳繑鍥為敊璇傛鏂囦腑濡傛灉鍖呭惈娈佃惤淇℃伅锛岃浣跨敤"\n"鍒嗛殧锛屾钀戒俊鎭畻娉曚腑鏈夐噸瑕佺殑浣滅敤锛岃灏介噺淇濈暀 + * @param integer $maxSummaryLen - 姝ゆ暟鍊煎皢浣滀负鎽樿缁撴灉鐨勬渶澶ч暱搴︺備緥濡傦細鍘熸枃闀垮害1000瀛楋紝鏈弬鏁拌缃负150锛屽垯鎽樿缁撴灉鐨勬渶澶ч暱搴︽槸150瀛楋紱鎺ㄨ崘鏈浼樺尯闂达細200-500瀛 + * @param array $options - 鍙夊弬鏁板璞★紝key: value閮戒负string绫诲瀷 + * @description options鍒楄〃: + * title 瀛楃涓诧紙闄200瀛楃鏁帮級瀛楃涓蹭粎鏀寔GBK缂栫爜锛岄暱搴﹂渶灏忎簬200瀛楃鏁帮紙鍗400瀛楄妭锛夛紝璇疯緭鍏ュ墠纭瀛楃鏁版病鏈夎秴闄愶紝鑻ュ瓧绗︽暟瓒呴暱浼氳繑鍥為敊璇傛爣棰樺湪绠楁硶涓叿鏈夐噸瑕佺殑浣滅敤锛岃嫢鏂囩珷纭棤鏍囬锛岃緭鍏ュ弬鏁扮殑鈥滄爣棰樷濆瓧娈典负绌哄嵆鍙 + * @return array + */ + public function newsSummary($content, $maxSummaryLen, $options=array()){ + + $data = array(); + + $data['content'] = $content; + $data['max_summary_len'] = $maxSummaryLen; + + $data = array_merge($data, $options); + $data = mb_convert_encoding(json_encode($data), 'GBK', 'UTF8'); + + return $this->request($this->newsSummaryUrl, $data); + } + + +} \ No newline at end of file diff --git a/class/ai/lib/AipBCEUtil.php b/class/ai/lib/AipBCEUtil.php new file mode 100644 index 0000000..84b79d2 --- /dev/null +++ b/class/ai/lib/AipBCEUtil.php @@ -0,0 +1,345 @@ + $v) { + //璺宠繃Authorization瀛楁 + if (strcasecmp('Authorization', $k) == 0) { + continue; + } + if (!isset($k)) { + throw new \InvalidArgumentException( + "parameter key should not be null" + ); + } + if (isset($v)) { + //瀵逛簬鏈夊肩殑锛岀紪鐮佸悗鏀惧湪=鍙蜂袱杈 + $parameterStrings[] = AipHttpUtil::urlEncode($k) + . '=' . AipHttpUtil::urlEncode((string) $v); + } else { + //瀵逛簬娌℃湁鍊肩殑锛屽彧灏唊ey缂栫爜鍚庢斁鍦=鍙风殑宸﹁竟锛屽彸杈圭暀绌 + $parameterStrings[] = AipHttpUtil::urlEncode($k) . '='; + } + } + //鎸夌収瀛楀吀搴忔帓搴 + sort($parameterStrings); + + //浣跨敤'&'绗﹀彿杩炴帴瀹冧滑 + return implode('&', $parameterStrings); + } + + /** + * 鐢熸垚鏍囧噯鍖杣ri + * @param string $path + * @return string + */ + public static function getCanonicalURIPath($path) + { + //绌鸿矾寰勮缃负'/' + if (empty($path)) { + return '/'; + } else { + //鎵鏈夌殑uri蹇呴』浠'/'寮澶 + if ($path[0] == '/') { + return AipHttpUtil::urlEncodeExceptSlash($path); + } else { + return '/' . AipHttpUtil::urlEncodeExceptSlash($path); + } + } + } + + /** + * 鐢熸垚鏍囧噯鍖杊ttp璇锋眰澶翠覆 + * @param array $headers + * @return array + */ + public static function getCanonicalHeaders($headers) + { + //濡傛灉娌℃湁headers锛屽垯杩斿洖绌轰覆 + if (count($headers) == 0) { + return ''; + } + + $headerStrings = array(); + foreach ($headers as $k => $v) { + //璺宠繃key涓簄ull鐨 + if ($k === null) { + continue; + } + //濡傛灉value涓簄ull锛屽垯璧嬪间负绌轰覆 + if ($v === null) { + $v = ''; + } + //trim鍚庡啀encode锛屼箣鍚庝娇鐢':'鍙疯繛鎺ヨ捣鏉 + $headerStrings[] = AipHttpUtil::urlEncode(strtolower(trim($k))) . ':' . AipHttpUtil::urlEncode(trim($v)); + } + //瀛楀吀搴忔帓搴 + sort($headerStrings); + + //鐢'\n'鎶婂畠浠繛鎺ヨ捣鏉 + return implode("\n", $headerStrings); + } +} +AipHttpUtil::__init(); + + +class AipSignOption +{ + const EXPIRATION_IN_SECONDS = 'expirationInSeconds'; + + const HEADERS_TO_SIGN = 'headersToSign'; + + const TIMESTAMP = 'timestamp'; + + const DEFAULT_EXPIRATION_IN_SECONDS = 1800; + + const MIN_EXPIRATION_IN_SECONDS = 300; + + const MAX_EXPIRATION_IN_SECONDS = 129600; +} + + +class AipSampleSigner +{ + + const BCE_AUTH_VERSION = "bce-auth-v1"; + const BCE_PREFIX = 'x-bce-'; + + //涓嶆寚瀹歨eadersToSign鎯呭喌涓嬶紝榛樿绛惧悕http澶达紝鍖呮嫭锛 + // 1.host + // 2.content-length + // 3.content-type + // 4.content-md5 + public static $defaultHeadersToSign; + + public static function __init() + { + AipSampleSigner::$defaultHeadersToSign = array( + "host", + "content-length", + "content-type", + "content-md5", + ); + } + + /** + * 绛惧悕 + * @param array $credentials + * @param string $httpMethod + * @param string $path + * @param array $headers + * @param string $params + * @param array $options + * @return string + */ + public static function sign( + array $credentials, + $httpMethod, + $path, + $headers, + $params, + $options = array() + ) { + //璁惧畾绛惧悕鏈夋晥鏃堕棿 + if (!isset($options[AipSignOption::EXPIRATION_IN_SECONDS])) { + //榛樿鍊1800绉 + $expirationInSeconds = AipSignOption::DEFAULT_EXPIRATION_IN_SECONDS; + } else { + $expirationInSeconds = $options[AipSignOption::EXPIRATION_IN_SECONDS]; + } + + //瑙f瀽ak sk + $accessKeyId = $credentials['ak']; + $secretAccessKey = $credentials['sk']; + + //璁惧畾鏃堕棿鎴筹紝娉ㄦ剰锛氬鏋滆嚜琛屾寚瀹氭椂闂存埑闇瑕佷负UTC鏃堕棿 + if (!isset($options[AipSignOption::TIMESTAMP])) { + //榛樿鍊煎綋鍓嶆椂闂 + $timestamp = gmdate('Y-m-d\TH:i:s\Z'); + } else { + $timestamp = $options[AipSignOption::TIMESTAMP]; + } + + //鐢熸垚authString + $authString = AipSampleSigner::BCE_AUTH_VERSION . '/' . $accessKeyId . '/' + . $timestamp . '/' . $expirationInSeconds; + + //浣跨敤sk鍜宎uthString鐢熸垚signKey + $signingKey = hash_hmac('sha256', $authString, $secretAccessKey); + + //鐢熸垚鏍囧噯鍖朥RI + $canonicalURI = AipHttpUtil::getCanonicalURIPath($path); + + //鐢熸垚鏍囧噯鍖朡ueryString + $canonicalQueryString = AipHttpUtil::getCanonicalQueryString($params); + + //濉厖headersToSign锛屼篃灏辨槸鎸囨槑鍝簺header鍙備笌绛惧悕 + $headersToSign = null; + if (isset($options[AipSignOption::HEADERS_TO_SIGN])) { + $headersToSign = $options[AipSignOption::HEADERS_TO_SIGN]; + } + + //鐢熸垚鏍囧噯鍖杊eader + $canonicalHeader = AipHttpUtil::getCanonicalHeaders( + AipSampleSigner::getHeadersToSign($headers, $headersToSign) + ); + + //鏁寸悊headersToSign锛屼互';'鍙疯繛鎺 + $signedHeaders = ''; + if ($headersToSign !== null) { + $signedHeaders = strtolower( + trim(implode(";", $headersToSign)) + ); + } + + //缁勬垚鏍囧噯璇锋眰涓 + $canonicalRequest = "$httpMethod\n$canonicalURI\n" + . "$canonicalQueryString\n$canonicalHeader"; + + //浣跨敤signKey鍜屾爣鍑嗚姹備覆瀹屾垚绛惧悕 + $signature = hash_hmac('sha256', $canonicalRequest, $signingKey); + + //缁勬垚鏈缁堢鍚嶄覆 + $authorizationHeader = "$authString/$signedHeaders/$signature"; + + return $authorizationHeader; + } + + /** + * 鏍规嵁headsToSign杩囨护搴旇鍙備笌绛惧悕鐨刪eader + * @param array $headers + * @param array $headersToSign + * @return array + */ + public static function getHeadersToSign($headers, $headersToSign) + { + + $arr = array(); + foreach ($headersToSign as $value) { + $arr[] = strtolower(trim($value)); + } + + //value琚玹rim鍚庝负绌轰覆鐨刪eader涓嶅弬涓庣鍚 + $result = array(); + foreach ($headers as $key => $value) { + if (trim($value) !== '') { + $key = strtolower(trim($key)); + if (in_array($key, $arr)) { + $result[$key] = $value; + } + } + } + + //杩斿洖闇瑕佸弬涓庣鍚嶇殑header + return $result; + } + + /** + * 妫鏌eader鏄笉鏄粯璁ゅ弬鍔犵鍚嶇殑锛 + * 1.鏄痟ost銆乧ontent-type銆乧ontent-md5銆乧ontent-length涔嬩竴 + * 2.浠-bce寮澶 + * @param array $header + * @return boolean + */ + public static function isDefaultHeaderToSign($header) + { + $header = strtolower(trim($header)); + if (in_array($header, AipSampleSigner::$defaultHeadersToSign)) { + return true; + } + return substr_compare($header, AipSampleSigner::BCE_PREFIX, 0, strlen(AipSampleSigner::BCE_PREFIX)) == 0; + } +} +AipSampleSigner::__init(); diff --git a/class/ai/lib/AipBase.php b/class/ai/lib/AipBase.php new file mode 100644 index 0000000..6a54145 --- /dev/null +++ b/class/ai/lib/AipBase.php @@ -0,0 +1,394 @@ +appId = trim($appId); + $this->apiKey = trim($apiKey); + $this->secretKey = trim($secretKey); + $this->isCloudUser = null; + $this->client = new AipHttpClient(); + $this->version = '2_2_19'; + $this->proxies = array(); + } + + /** + * 鏌ョ湅鐗堟湰 + * @return string + * + */ + public function getVersion(){ + return $this->version; + } + + /** + * 杩炴帴瓒呮椂 + * @param int $ms 姣 + */ + public function setConnectionTimeoutInMillis($ms){ + $this->client->setConnectionTimeoutInMillis($ms); + } + + /** + * 鍝嶅簲瓒呮椂 + * @param int $ms 姣 + */ + public function setSocketTimeoutInMillis($ms){ + $this->client->setSocketTimeoutInMillis($ms); + } + + /** + * 浠g悊 + * @param array $proxy + * @return string + * + */ + public function setProxies($proxies){ + $this->client->setConf($proxies); + } + + /** + * 澶勭悊璇锋眰鍙傛暟 + * @param string $url + * @param array $params + * @param array $data + * @param array $headers + */ + protected function proccessRequest($url, &$params, &$data, $headers){ + $params['aipSdk'] = 'php'; + $params['aipSdkVersion'] = $this->version; + } + + /** + * Api 璇锋眰 + * @param string $url + * @param mixed $data + * @return mixed + */ + protected function request($url, $data, $headers=array()){ + try{ + $result = $this->validate($url, $data); + if($result !== true){ + return $result; + } + + $params = array(); + $authObj = $this->auth(); + + if($this->isCloudUser === false){ + $params['access_token'] = $authObj['access_token']; + } + + // 鐗规畩澶勭悊 + $this->proccessRequest($url, $params, $data, $headers); + + $headers = $this->getAuthHeaders('POST', $url, $params, $headers); + $response = $this->client->post($url, $data, $params, $headers); + + $obj = $this->proccessResult($response['content']); + + if(!$this->isCloudUser && isset($obj['error_code']) && $obj['error_code'] == 110){ + $authObj = $this->auth(true); + $params['access_token'] = $authObj['access_token']; + $response = $this->client->post($url, $data, $params, $headers); + $obj = $this->proccessResult($response['content']); + } + + if(empty($obj) || !isset($obj['error_code'])){ + $this->writeAuthObj($authObj); + } + }catch(Exception $e){ + return array( + 'error_code' => 'SDK108', + 'error_msg' => 'connection or read data timeout', + ); + } + + return $obj; + } + + /** + * Api 澶氫釜骞跺彂璇锋眰 + * @param string $url + * @param mixed $data + * @return mixed + */ + protected function multi_request($url, $data){ + try{ + $params = array(); + $authObj = $this->auth(); + $headers = $this->getAuthHeaders('POST', $url); + + if($this->isCloudUser === false){ + $params['access_token'] = $authObj['access_token']; + } + + $responses = $this->client->multi_post($url, $data, $params, $headers); + + $is_success = false; + foreach($responses as $response){ + $obj = $this->proccessResult($response['content']); + + if(empty($obj) || !isset($obj['error_code'])){ + $is_success = true; + } + + if(!$this->isCloudUser && isset($obj['error_code']) && $obj['error_code'] == 110){ + $authObj = $this->auth(true); + $params['access_token'] = $authObj['access_token']; + $responses = $this->client->post($url, $data, $params, $headers); + break; + } + } + + if($is_success){ + $this->writeAuthObj($authObj); + } + + $objs = array(); + foreach($responses as $response){ + $objs[] = $this->proccessResult($response['content']); + } + + }catch(Exception $e){ + return array( + 'error_code' => 'SDK108', + 'error_msg' => 'connection or read data timeout', + ); + } + + return $objs; + } + + /** + * 鏍煎紡妫鏌 + * @param string $url + * @param array $data + * @return mix + */ + protected function validate($url, &$data){ + return true; + } + + /** + * 鏍煎紡鍖栫粨鏋 + * @param $content string + * @return mixed + */ + protected function proccessResult($content){ + return json_decode($content, true); + } + + /** + * 杩斿洖 access token 璺緞 + * @return string + */ + private function getAuthFilePath(){ + return dirname(__FILE__) . DIRECTORY_SEPARATOR . md5($this->apiKey); + } + + /** + * 鍐欏叆鏈湴鏂囦欢 + * @param array $obj + * @return void + */ + private function writeAuthObj($obj){ + if($obj === null || (isset($obj['is_read']) && $obj['is_read'] === true)){ + return; + } + + $obj['time'] = time(); + $obj['is_cloud_user'] = $this->isCloudUser; + @file_put_contents($this->getAuthFilePath(), json_encode($obj)); + } + + /** + * 璇诲彇鏈湴缂撳瓨 + * @return array + */ + private function readAuthObj(){ + $content = @file_get_contents($this->getAuthFilePath()); + if($content !== false){ + $obj = json_decode($content, true); + $this->isCloudUser = $obj['is_cloud_user']; + $obj['is_read'] = true; + if($this->isCloudUser || $obj['time'] + $obj['expires_in'] - 30 > time()){ + return $obj; + } + } + + return null; + } + + /** + * 璁よ瘉 + * @param bool $refresh 鏄惁鍒锋柊 + * @return array + */ + private function auth($refresh=false){ + + //闈炶繃鏈熷埛鏂 + if(!$refresh){ + $obj = $this->readAuthObj(); + if(!empty($obj)){ + return $obj; + } + } + + $response = $this->client->get($this->accessTokenUrl, array( + 'grant_type' => 'client_credentials', + 'client_id' => $this->apiKey, + 'client_secret' => $this->secretKey, + )); + + $obj = json_decode($response['content'], true); + + $this->isCloudUser = !$this->isPermission($obj); + return $obj; + } + + /** + * 鍒ゆ柇璁よ瘉鏄惁鏈夋潈闄 + * @param array $authObj + * @return boolean + */ + protected function isPermission($authObj) + { + if(empty($authObj) || !isset($authObj['scope'])){ + return false; + } + + $scopes = explode(' ', $authObj['scope']); + + return in_array($this->scope, $scopes); + } + + /** + * @param string $method HTTP method + * @param string $url + * @param array $param 鍙傛暟 + * @return array + */ + private function getAuthHeaders($method, $url, $params=array(), $headers=array()){ + + //涓嶆槸浜戠殑鑰佺敤鎴峰垯涓嶇敤鍦╤eader涓鍚 璁よ瘉 + if($this->isCloudUser === false){ + return $headers; + } + + $obj = parse_url($url); + if(!empty($obj['query'])){ + foreach(explode('&', $obj['query']) as $kv){ + if(!empty($kv)){ + list($k, $v) = explode('=', $kv, 2); + $params[$k] = $v; + } + } + } + + //UTC 鏃堕棿鎴 + $timestamp = gmdate('Y-m-d\TH:i:s\Z'); + $headers['Host'] = isset($obj['port']) ? sprintf('%s:%s', $obj['host'], $obj['port']) : $obj['host']; + $headers['x-bce-date'] = $timestamp; + + //绛惧悕 + $headers['authorization'] = AipSampleSigner::sign(array( + 'ak' => $this->apiKey, + 'sk' => $this->secretKey, + ), $method, $obj['path'], $headers, $params, array( + 'timestamp' => $timestamp, + 'headersToSign' => array_keys($headers), + )); + + return $headers; + } + + /** + * 鍙嶉 + * + * @param array $feedbacks + * @return array + */ + public function report($feedback){ + + $data = array(); + + $data['feedback'] = $feedback; + + return $this->request($this->reportUrl, $data); + } + + /** + * 閫氱敤鎺ュ彛 + * @param string $url + * @param array $data + * @param array header + * @return array + */ + public function post($url, $data, $headers=array()){ + return $this->request($url, $data, $headers); + } + +} diff --git a/class/ai/lib/AipHttpClient.php b/class/ai/lib/AipHttpClient.php new file mode 100644 index 0000000..4518d19 --- /dev/null +++ b/class/ai/lib/AipHttpClient.php @@ -0,0 +1,214 @@ +headers = $this->buildHeaders($headers); + $this->connectTimeout = 60000; + $this->socketTimeout = 60000; + $this->conf = array(); + } + + /** + * 杩炴帴瓒呮椂 + * @param int $ms 姣 + */ + public function setConnectionTimeoutInMillis($ms){ + $this->connectTimeout = $ms; + } + + /** + * 鍝嶅簲瓒呮椂 + * @param int $ms 姣 + */ + public function setSocketTimeoutInMillis($ms){ + $this->socketTimeout = $ms; + } + + /** + * 閰嶇疆 + * @param array $conf + */ + public function setConf($conf){ + $this->conf = $conf; + } + + /** + * 璇锋眰棰勫鐞 + * @param resource $ch + */ + public function prepare($ch){ + foreach($this->conf as $key => $value){ + curl_setopt($ch, $key, $value); + } + } + + /** + * @param string $url + * @param array $data HTTP POST BODY + * @param array $param HTTP URL + * @param array $headers HTTP header + * @return array + */ + public function post($url, $data=array(), $params=array(), $headers=array()){ + $url = $this->buildUrl($url, $params); + $headers = array_merge($this->headers, $this->buildHeaders($headers)); + + $ch = curl_init(); + $this->prepare($ch); + curl_setopt($ch, CURLOPT_URL, $url); + curl_setopt($ch, CURLOPT_POST, 1); + curl_setopt($ch, CURLOPT_HEADER, false); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); + curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); + curl_setopt($ch, CURLOPT_POSTFIELDS, is_array($data) ? http_build_query($data) : $data); + curl_setopt($ch, CURLOPT_TIMEOUT_MS, $this->socketTimeout); + curl_setopt($ch, CURLOPT_CONNECTTIMEOUT_MS, $this->connectTimeout); + $content = curl_exec($ch); + $code = curl_getinfo($ch, CURLINFO_HTTP_CODE); + + if($code === 0){ + throw new Exception(curl_error($ch)); + } + + curl_close($ch); + return array( + 'code' => $code, + 'content' => $content, + ); + } + + /** + * @param string $url + * @param array $datas HTTP POST BODY + * @param array $param HTTP URL + * @param array $headers HTTP header + * @return array + */ + public function multi_post($url, $datas=array(), $params=array(), $headers=array()){ + $url = $this->buildUrl($url, $params); + $headers = array_merge($this->headers, $this->buildHeaders($headers)); + + $chs = array(); + $result = array(); + $mh = curl_multi_init(); + foreach($datas as $data){ + $ch = curl_init(); + $chs[] = $ch; + $this->prepare($ch); + curl_setopt($ch, CURLOPT_URL, $url); + curl_setopt($ch, CURLOPT_POST, 1); + curl_setopt($ch, CURLOPT_HEADER, false); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); + curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); + curl_setopt($ch, CURLOPT_POSTFIELDS, is_array($data) ? http_build_query($data) : $data); + curl_setopt($ch, CURLOPT_TIMEOUT_MS, $this->socketTimeout); + curl_setopt($ch, CURLOPT_CONNECTTIMEOUT_MS, $this->connectTimeout); + curl_multi_add_handle($mh, $ch); + } + + $running = null; + do{ + curl_multi_exec($mh, $running); + usleep(100); + }while($running); + + foreach($chs as $ch){ + $content = curl_multi_getcontent($ch); + $code = curl_getinfo($ch, CURLINFO_HTTP_CODE); + $result[] = array( + 'code' => $code, + 'content' => $content, + ); + curl_multi_remove_handle($mh, $ch); + } + curl_multi_close($mh); + + return $result; + } + + /** + * @param string $url + * @param array $param HTTP URL + * @param array $headers HTTP header + * @return array + */ + public function get($url, $params=array(), $headers=array()){ + $url = $this->buildUrl($url, $params); + $headers = array_merge($this->headers, $this->buildHeaders($headers)); + + $ch = curl_init(); + $this->prepare($ch); + curl_setopt($ch, CURLOPT_URL, $url); + curl_setopt($ch, CURLOPT_HEADER, false); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); + curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); + curl_setopt($ch, CURLOPT_TIMEOUT_MS, $this->socketTimeout); + curl_setopt($ch, CURLOPT_CONNECTTIMEOUT_MS, $this->connectTimeout); + $content = curl_exec($ch); + $code = curl_getinfo($ch, CURLINFO_HTTP_CODE); + + if($code === 0){ + throw new Exception(curl_error($ch)); + } + + curl_close($ch); + return array( + 'code' => $code, + 'content' => $content, + ); + } + + /** + * 鏋勯 header + * @param array $headers + * @return array + */ + private function buildHeaders($headers){ + $result = array(); + foreach($headers as $k => $v){ + $result[] = sprintf('%s:%s', $k, $v); + } + return $result; + } + + /** + * + * @param string $url + * @param array $params 鍙傛暟 + * @return string + */ + private function buildUrl($url, $params){ + if(!empty($params)){ + $str = http_build_query($params); + return $url . (strpos($url, '?') === false ? '?' : '&') . $str; + }else{ + return $url; + } + } +} diff --git a/class/class_load.php b/class/class_load.php index ec93bda..af8cd98 100644 --- a/class/class_load.php +++ b/class/class_load.php @@ -12,4 +12,4 @@ include 'points/points.php'; //绉垎鍔熻兘 include 'aq_resizer.php'; //缂╃暐鍥惧姛鑳 include 'wechat.php'; //寰俊鍔熻兘 - +//include 'ai.php'; //AI鍔熻兘 diff --git a/framework/options-config.php b/framework/options-config.php index aca1873..121ef3e 100644 --- a/framework/options-config.php +++ b/framework/options-config.php @@ -16,6 +16,17 @@ $gdk_options = [ ], 'std' => '1', ], + [ + 'name' => '绂佺敤鏂扮増灏忓伐鍏', + 'desc' => '鏂扮増灏忓伐鍏峰皻涓嶆垚鐔燂紝寰堝涓婚涓嶅吋瀹癸紝寤鸿寮鍚', + 'id' => 'gdk_diasble_widgets_block', + 'type' => 'radio', + 'options' => [ + '0' => '绂佺敤', + '1' => '寮鍚', + ], + 'std' => '1', + ], [ 'name' => '绂佺敤澶撮儴鍐椾綑浠g爜', 'desc' => 'WordPress澶撮儴鑷甫寰堝鏃犵敤浠g爜锛屼笉瀹夊叏涓旀氮璐癸紝寤鸿寮鍚', @@ -130,6 +141,7 @@ $gdk_options = [ '1' => '闅忔満澶村儚', '2' => 'V2EX澶村儚闀滃儚', '3' => '涓冪墰澶村儚闀滃儚', + '4' => 'Cravatar', ], 'std' => '3', ], diff --git a/framework/plugin-options.php b/framework/plugin-options.php index 6661a97..39710f1 100644 --- a/framework/plugin-options.php +++ b/framework/plugin-options.php @@ -7,15 +7,14 @@ if (!defined('WPINC')) { die; } -$current_theme = wp_get_theme(); -$gdk_default_options = []; -$gdk_options = array(); +$gdk_default = []; +$gdk_options = []; include 'options-config.php'; -$gdk_current_options = get_option('gdk_options_setup'); +$gdk_config = get_option('gdk_options_setup'); function gdk_update_options() { - global $gdk_default_options, $gdk_options, $gdk_current_options; + global $gdk_default, $gdk_options, $gdk_config; foreach ($gdk_options as $panel) { foreach ($panel as $option) { $id = $option['id'] ?? ''; @@ -25,22 +24,23 @@ function gdk_update_options() continue; } - $gdk_default_options[$id] = $std; - if (isset($gdk_current_options[$id])) { + $gdk_default[$id] = $std; + if (isset($gdk_config[$id])) { continue; } - $gdk_current_options[$id] = $std; + $gdk_config[$id] = $std; + } } } -gdk_update_options(); +//gdk_update_options(); //鑾峰彇璁剧疆閫夐」 -function gdk_option($id, $returnDefault = false) +function gdk_option($id, $Default = false) { - global $gdk_default_options, $gdk_current_options; - return stripslashes($returnDefault ? $gdk_default_options[$id] : $gdk_current_options[$id]); + global $gdk_default, $gdk_config; + return stripslashes($Default ? $gdk_default[$id] : $gdk_config[$id]); } //璁剧疆椤甸潰妯℃澘 @@ -66,7 +66,7 @@ if (isset($_GET['update'])) {
- -

鐩稿叧閾炬帴

- - - - - -

绗笁鏂规敮鎸

- - - -

鎰忚鍙嶉

@@ -406,7 +382,7 @@ jQuery(function ($) { $.get(ajaxurl, ajax_data, function() { $(".g-load").hide(); - window.location.reload(); + //window.location.reload(); }); }); diff --git a/functions/Ajax.php b/functions/Ajax.php index e58186c..0bf969e 100644 --- a/functions/Ajax.php +++ b/functions/Ajax.php @@ -65,7 +65,7 @@ function gdk_pasteup_imag() $wp_upload_dir = wp_upload_dir(); $file = $_FILES['imageFile']; $result = array('success' => false, 'message' => 'Null'); - if (in_array($file['type'], array('image/gif', 'image/jpeg', 'image/jpg', 'image/png'))) { + if (in_array($file['type'], array('image/gif', 'image/jpeg', 'image/pjpeg', 'image/png'))) { if ($file['error'] > 0) { $result['message'] = 'error'; } else { @@ -335,7 +335,7 @@ add_action('wp_ajax_gdk_auto_login', 'gdk_auto_login'); add_action('wp_ajax_nopriv_gdk_auto_login', 'gdk_auto_login'); //閭缁戝畾 -function bind_email_check() +function gdk_bind_email_check() { $mail = isset($_POST['email']) ? $_POST['email'] : false; if ($mail && $_POST['action'] == 'bind_email_check') { @@ -345,8 +345,8 @@ function bind_email_check() } } } -add_action('wp_ajax_bind_email_check', 'bind_email_check'); -add_action('wp_ajax_nopriv_bind_email_check', 'bind_email_check'); +add_action('wp_ajax_bind_email_check', 'gdk_bind_email_check'); +add_action('wp_ajax_nopriv_bind_email_check', 'gdk_bind_email_check'); //绉垎鏀粯 function point_buy() diff --git a/functions/Common.php b/functions/Common.php index 0b312b7..6e3e95f 100644 --- a/functions/Common.php +++ b/functions/Common.php @@ -1,5 +1,5 @@ 1鍧囦负寮傚父閲嶅鍏ュ簱鏁版嵁 } -//瀵艰埅鍗曢〉鍑芥暟 -function gdk_get_the_link_items($id = null) -{ - $bookmarks = get_bookmarks('orderby=date&category=' . $id); - $output = ''; - if (!empty($bookmarks)) { - foreach ($bookmarks as $bookmark) { - $output .= '
-
' . $bookmark->link_name . '
' . $bookmark->link_description . ' : ' . $bookmark->link_notes . '
'; - } - } - return $output; -} - -function gdk_get_link_items() -{ - $linkcats = get_terms('link_category', 'orderby=count&hide_empty=1&exclude=' . gdk_option('gdk_link_id')); - $result = ''; - foreach ($linkcats as $linkcat) { - $result .= '
-
' . $linkcat->name . '
-
-
'; - $result .= gdk_get_the_link_items($linkcat->term_id); - $result .= '
'; - } - return $result; -} - function gdk_get_Version() { echo ''; @@ -1157,11 +1128,6 @@ function gdk_weauth_qr() return $qr64; } -//寰俊鐧婚檰椤甸潰鎸夐挳 -function weixin_login_button(){ - echo '

寰俊鐧诲綍


'; -} - /** * 寰俊鐧婚檰鎸夐挳 */ diff --git a/functions/advanced.php b/functions/advanced.php index e7f7188..c74cd50 100644 --- a/functions/advanced.php +++ b/functions/advanced.php @@ -1,5 +1,5 @@ /i', "\n", $content); } @@ -321,8 +345,7 @@ if (gdk_option('gdk_article_list')) { add_filter('the_content', 'article_index'); } -//鎻掍欢瀹夎鑷姩婵娲婚〉闈 -function gdk_page_activate() +function weauth_page_activate() { $awesome_page_id = get_option('weixin_page_id'); if (!$awesome_page_id) { @@ -339,7 +362,7 @@ function gdk_page_activate() } } -add_action('admin_init', 'gdk_page_activate'); +add_action('admin_init', 'weauth_page_activate'); //寮哄埗寰俊鐧诲綍 function force_weauth_login_url($login_url, $redirect, $force_reauth) @@ -354,7 +377,6 @@ function force_weauth_login_url($login_url, $redirect, $force_reauth) return $login_url; } -//淇敼娉ㄥ唽椤甸潰 function change_my_register_url($url) { if (is_admin()) { diff --git a/functions/optimization.php b/functions/optimization.php index 9b209a5..0565bd7 100644 --- a/functions/optimization.php +++ b/functions/optimization.php @@ -119,6 +119,9 @@ function gdk_after_init_theme() if (get_option('permalink_structure') == '' || define('GDK_HTML_LINK', true)) { //濡傛灉鏄粯璁よ繛鎺ユ牸寮忔垨鑰呬富棰樺0鏄 define( 'GDK_HTML_LINK', true ); update_option('permalink_structure', '/archives/%post_id%.html'); //鍥哄畾閾炬帴鏍煎紡 } + if (gdk_option('gdk_diasble_widgets_block')){ //濡傛灉 + remove_theme_support( 'widgets-block-editor' ); //绂佺敤鏂扮増灏忓伐鍏 + } update_option('posts_per_page', '30'); //姣忛〉鏂囩珷鏁扮洰 } add_action('after_setup_theme', 'gdk_after_init_theme'); diff --git a/functions/rewrite.php b/functions/rewrite.php index 1393921..5ac842b 100644 --- a/functions/rewrite.php +++ b/functions/rewrite.php @@ -1,5 +1,4 @@ 寰俊鐧诲綍


'; +}if (gdk_option('gdk_weauth_oauth')) { + add_action('login_form', 'weixin_login_button'); +} + //璇勮寰俊鎺ㄩ if (gdk_option('gdk_Server') && !is_admin()) { function sc_send($comment_id) @@ -103,7 +110,7 @@ if (gdk_option('gdk_Server') && !is_admin()) { ), ); $context = stream_context_create($opts); - return $result = file_get_contents('https://sctapi.ftqq.com/' . $key . '.send', false, $context); + return $result = file_get_contents('http://sc.ftqq.com/' . $key . '.send', false, $context); } add_action('comment_post', 'sc_send', 19, 2); } @@ -157,24 +164,100 @@ wp_embed_register_handler('youku_iframe', '#http://v.youku.com/v_show/id_(.*?).h wp_embed_unregister_handler('youku'); ////////////////weauth////////////// -//鎺ュ彈濂跺瓙寰俊鐨勮处鍙蜂俊鎭 -function get_weauth_oauth() +/* +function weauth_oauth_redirect() { - if (in_string($_SERVER['REQUEST_URI'], 'weauth')) { - $weauth_user = isset($_GET['user']) ? sanitize_text_field($_GET['user']) : false; //weauth鍙戞潵鐢ㄦ埛淇℃伅 - $weauth_sk = isset($_GET['sk']) ? sanitize_text_field($_GET['sk']) : false; //weauth杩斿洖鐨12浣峴k淇℃伅 - $weauth_res = get_transient($weauth_sk . '-OK'); - if (empty($weauth_res) && $weauth_res !== 1) { - return; - } + wp_redirect(home_url()); + exit; +} - $weauth_user = stripslashes($weauth_user); - $weauth_user = json_decode($weauth_user, true); - $oauth_result = implode('|', $weauth_user); - set_transient($weauth_sk . '-info', $oauth_result, 60); //1鍒嗛挓缂撳瓨 - header('goauth: ok'); - echo 'success'; //缁欏鏂规湇鍔″櫒鎵撲釜鎷涘懠 - exit; +function get_weauth_token() +{ + $sk = date("YmdHis") . mt_rand(10, 99); + set_transient($sk, 1, 60 * 6); + $key = $_SERVER['HTTP_HOST'] . '@' . $sk; + return $key; +} + +function get_weauth_qr() +{ + $qr64 = []; + $qr64['key'] = get_weauth_token(); + $qr64['qrcode'] = json_decode(file_get_contents('https://wa.isdot.net/qrcode?str=' . $qr64['key']), true)['qrcode']; + return $qr64; +} + +function weauth_rewrite_rules($wp_rewrite) +{ + if ($ps = get_option('permalink_structure')) { + $new_rules['^weauth'] = 'index.php?user=$matches[1]&sk=$matches[2]'; + $wp_rewrite->rules = $new_rules + $wp_rewrite->rules; } } -add_action('parse_request', 'get_weauth_oauth'); \ No newline at end of file +add_action('generate_rewrite_rules', 'weauth_rewrite_rules'); + +function weauth_oauth() +{ + $weauth_user = $_GET['user']; + $weauth_sk = esc_attr($_GET['sk']); + $weauth_res = get_transient($weauth_sk); + if (empty($weauth_res)) { + return; + } + $weauth_user = stripslashes($weauth_user); + $weauth_user = json_decode($weauth_user, true); + $nickname = $weauth_user['nickName']; + $wxavatar = $weauth_user['avatarUrl']; + $openid = $weauth_user['openid']; + $login_name = 'wx_' . wp_create_nonce($openid); + if (is_user_logged_in()) { + $user_id = get_current_user_id(); + update_user_meta($user_id, 'wx_openid', $openid); + update_user_meta($user_id, 'simple_local_avatar', $wxavatar); + } else { + $weauth_user = get_users(array( + 'meta_key ' => 'wx_openid', + 'meta_value' => $openid, + ) + ); + if (is_wp_error($weauth_user) || !count($weauth_user)) { + $random_password = wp_generate_password(12, false); + $userdata = array( + 'user_login' => $login_name, + 'display_name' => $nickname, + 'user_pass' => $random_password, + 'nickname' => $nickname, + ); + $user_id = wp_insert_user($userdata); + update_user_meta($user_id, 'wx_openid', $openid); + update_user_meta($user_id, 'simple_local_avatar', $wxavatar); + } else { + $user_id = $weauth_user[0]->ID; + } + } + set_transient($weauth_sk . 'ok', $user_id, 60); //鐢ㄤ簬鐧诲綍鐨勯殢鏈烘暟锛屾湁鏁堟湡涓轰竴鍒嗛挓 + weauth_oauth_redirect(); +} +//鍒濆鍖 +/* +function weauth_oauth_init() +{ + if (isset($_GET['user']) && isset($_GET['sk'])) { + weauth_oauth(); + } +} +add_action('init', 'weauth_oauth_init'); + +/* +//GET鑷姩鐧诲綍 +function gdk_weauth_oauth_login() +{ + $key = isset($_GET['spam']) ? $_GET['spam'] : false; + if ($key) { + $user_id = get_transient($key . 'ok'); + if ($user_id != 0) { + wp_set_auth_cookie($user_id); + } + } +} +add_action('init', 'gdk_weauth_oauth_login'); diff --git a/functions/shortcode.php b/functions/shortcode.php index de5521f..7da0544 100644 --- a/functions/shortcode.php +++ b/functions/shortcode.php @@ -50,7 +50,6 @@ add_shortcode('dm', 'gdk_DemoUrl'); //浣跨敤鐭唬鐮佹坊鍔犲洖澶嶅悗鍙鍐呭寮濮 function gdk_reply_to_read($atts, $content = null) { - $content = do_shortcode($content); extract(shortcode_atts(array( 'notice' => '

娉ㄦ剰锛氭湰娈靛唴瀹归』鎴愬姛鈥鍥炲鏈枃鈥濆悗鈥鍒锋柊鏈〉鈥濇柟鍙煡鐪嬶紒

', ), $atts)); @@ -204,7 +203,6 @@ add_shortcode('netmusic', 'gdk_music163'); //鐧诲綍鍙 function gdk_login_to_read($atts, $content = null) { - $content = do_shortcode($content); $logina = '鐧诲綍'; extract(shortcode_atts(array( 'notice' => '

娉ㄦ剰锛氭湰娈靛唴瀹归』鈥' . $logina . '鈥濆悗鏂瑰彲鏌ョ湅锛

', @@ -219,7 +217,6 @@ add_shortcode('vip', 'gdk_login_to_read'); // 閮ㄥ垎鍐呭杈撳叆瀵嗙爜鍙 function gdk_secret_view($atts, $content = null) { - $content = do_shortcode($content); $pid = get_the_ID(); add_post_meta($pid, '_pass_content', $content, true) or update_post_meta($pid, '_pass_content', $content); if (current_user_can('administrator')) { @@ -429,6 +426,71 @@ function gdk_pay_nologin($atts, $content = '') } add_shortcode('pax', 'gdk_pay_nologin'); + +function box_shortcode( $atts, $content = null ) { + extract( + shortcode_atts(array( + 's' => '1' + ), $atts)); + + if($s == '1') { $box_classes = 'c1_4 aside'; } + if($s == '2') { $box_classes = 'c2_4 main'; } + if($s == '3') { $box_classes = 'c3_4'; } + if($s == '4') { $box_classes = 'c4_4'; } + + return '
' . $content . '
'; +} +add_shortcode( 'b', 'box_shortcode' ); + +function contentblock_shortcode( $atts, $content = null ) { + return '
' . do_shortcode($content) . '
'; +} +add_shortcode( 'cb', 'contentblock_shortcode' ); + + + +// +function points_view($content){ + $cookie_name = 'huoduan_wechat_fans'; + + if (preg_match_all('/([\s\S]*?)/i', $content, $hide_words)) + { + $re = '/銆(.*)銆/i'; +$str = '鎴戝湪杩欓噷锛岃繖閲屼笉鏄粯璐瑰唴瀹 +銆10銆慸ssdssdfs鎴戝湪杩欓噷锛岃繖閲屾槸浠樿垂鍐呭 +绗簩琛 +'; + +preg_match($re, $str, $matches, PREG_OFFSET_CAPTURE, 0); +$points = $matches[1][0]; + $wechatfans = get_option('huoduan_wechatfans'); + $cv = md5($wechatfans['wechat_key'].$cookie_name.'huoduan.com'); + $vtips=''; + if(isset($_POST['huoduan_verifycode'])){ + if($_POST['huoduan_verifycode']==$wechatfans['wechat_code']){ + setcookie($cookie_name, $cv ,time()+(int)$wechatfans['wechat_day']*86400, "/"); + $_COOKIE[$cookie_name] = $cv; + }else{ + $vtips=''; + } + } + $cookievalue = isset($_COOKIE[$cookie_name])?$_COOKIE[$cookie_name]:''; + + if($cookievalue==$cv){ + $content = str_replace($hide_words[0], '
'.$hide_words[0][0].'
', $content); + }else{ + + $hide_notice = '
'.$wechatfans['wechat_name'].'姝ゅ鍐呭宸茬粡琚綔鑰呴殣钘忥紝璇疯緭鍏ラ獙璇佺爜鏌ョ湅鍐呭
楠岃瘉鐮侊細
璇峰叧娉ㄦ湰绔欏井淇″叕浼楀彿锛屽洖澶嶁'.$wechatfans['wechat_keyword'].'鈥濓紝鑾峰彇楠岃瘉鐮併傚湪寰俊閲屾悳绱⑩'.$wechatfans['wechat_name'].'鈥濇垨鑰呪'.$wechatfans['wechat_account'].'鈥濇垨鑰呭井淇℃壂鎻忓彸渚т簩缁寸爜閮藉彲浠ュ叧娉ㄦ湰绔欏井淇″叕浼楀彿銆
'.$vtips; + + $content = str_replace($hide_words[0], $hide_notice, $content); + } + + } + return $content; +} + +add_filter('the_content', 'points_view'); + //WordPress 娈典唬鐮佹寜閽泦鍚 function gdk_shortcode_list() { diff --git a/gdk.php b/gdk.php index dc49ecd..5f83178 100644 --- a/gdk.php +++ b/gdk.php @@ -3,10 +3,10 @@ Plugin Name: GitCafe Development Kit 鏋佸鍏洯寮鍙戝浠 Plugin URI: https://gitcafe.net/ Description: 涓篧ordPress涓婚寮鍙戞彁渚涘簳灞傛敮鎸 -Version: 1.1 +Version: 0.0.3 Author: 浜戣惤 Author URI: https://gitcafe.net/ -Compatible:5.7.1 +Compatible:5.3.2 */ //涓囪兘鐨勫紑澶 @@ -16,19 +16,19 @@ if (!defined('ABSPATH')) {exit;} function deactivate_myself() { deactivate_plugins(plugin_basename(__FILE__)); - wp_die('鍚姩澶辫触锛孏DK鎻掍欢涓嶅吋瀹笹it涓婚涓旈渶瑕佽繍琛屽湪 PHP 7.3 鐗堟湰鍙婃洿楂樼殑鐜涓嬨'); + wp_die('鍚姩澶辫触锛孏DK鎻掍欢涓嶅吋瀹笹it涓婚涓旈渶瑕佽繍琛屽湪 PHP 7.2 鐗堟湰鍙婃洿楂樼殑鐜涓嬨'); } if (defined('GIT_URL')) { add_action('update_option_active_plugins', 'deactivate_myself'); } -if (!version_compare(PHP_VERSION, '7.3', '>=')) { +if (!version_compare(PHP_VERSION, '7.2', '>=')) { add_action('update_option_active_plugins', 'deactivate_myself'); } //瀹氫箟鍚勭甯搁噺 -define('GDK_PLUGIN_VER', '1.0'); +define('GDK_PLUGIN_VER', '0.0.3'); define('GDK_PLUGIN_FILE', __FILE__); //鎻掍欢鍏ュ彛鏂囦欢 define('GDK_BASE_URL', plugin_dir_url(__FILE__)); //鎻掍欢鐩綍url define('GDK_ROOT_PATH', plugin_dir_path(__FILE__)); //鎻掍欢鐩綍璺緞 @@ -37,4 +37,6 @@ define('GDK_ROOT_PATH', plugin_dir_path(__FILE__)); //鎻掍欢鐩綍璺緞 include 'framework/frame_load.php'; //鍔犺浇鍚庡彴妗嗘灦 include 'class/class_load.php'; //鍔犺浇鍚勭绫 include 'functions/func_load.php'; //鍔犺浇鍑芥暟 -include 'assets/assets_load.php'; //鍔犺浇闈欐佽祫婧 \ No newline at end of file +include 'assets/assets_load.php'; //鍔犺浇闈欐佽祫婧 + + diff --git a/public/daohang.php b/public/daohang.php index 959b8f8..cc242e9 100644 --- a/public/daohang.php +++ b/public/daohang.php @@ -30,6 +30,40 @@ function gdk_daohang_html_api_handlers($template) add_filter('template_include', 'gdk_daohang_html_api_handlers', 99); +//瀵艰埅鍗曢〉鍑芥暟 +function gdk_get_the_link_items($id = null) +{ + $bookmarks = get_bookmarks('orderby=date&category=' . $id); + $output = ''; + if (!empty($bookmarks)) { + foreach ($bookmarks as $bookmark) {/* $bookmark->link_description */ + if(empty($bookmark->link_image)){ + $icon = 'https://img12.360buyimg.com/ddimg/jfs/t1/130599/4/13000/527/5f8ef17aE60de6b3e/4da08e59f8e12dec.png'; + }else{ + $icon = $bookmark->link_image; + } + $output .= '
+
' . $bookmark->link_name . '
' . $bookmark->link_notes . '
'; + } + } + return $output; +} + +function gdk_get_link_items() +{ + $linkcats = get_terms('link_category', 'orderby=count&hide_empty=1&exclude=' . gdk_option('gdk_link_id')); + $result = ''; + foreach ($linkcats as $linkcat) { + $result .= '
+
' . $linkcat->name . '
+
+
'; + $result .= gdk_get_the_link_items($linkcat->term_id); + $result .= '
'; + } + return $result; +} + function gdk_create_html_daohang() { ?> @@ -41,8 +75,25 @@ function gdk_create_html_daohang() @@ -61,6 +112,7 @@ function gdk_create_html_daohang() +
@@ -81,13 +133,13 @@ $linkcats1 = get_terms('link_category', 'orderby=count&hide_empty=1&exclude=7'); ?> diff --git a/public/sitemap-xml.php b/public/sitemap-xml.php index f285887..5597f8d 100644 --- a/public/sitemap-xml.php +++ b/public/sitemap-xml.php @@ -75,4 +75,4 @@ function gdk_clear_sitemap_cache() } add_action('publish_post', 'gdk_clear_sitemap_cache'); add_action('publish_page', 'gdk_clear_sitemap_cache'); -add_action('save_post', 'gdk_clear_sitemap_cache'); \ No newline at end of file +add_action('save_post', 'gdk_clear_sitemap_cache');