Changeset 2166257
- Timestamp:
- 10/01/2019 09:35:23 AM (6 years ago)
- Location:
- wallkit/trunk
- Files:
-
- 1 added
- 4 edited
-
includes/class-wallkit-wp-access.php (modified) (3 diffs)
-
vendor/wallkit-php-sdk/src/Exceptions/WallkitNotFoundException.php (added)
-
vendor/wallkit-php-sdk/src/WallkitClient.php (modified) (5 diffs)
-
vendor/wallkit-php-sdk/src/WallkitSDK.php (modified) (2 diffs)
-
wallkit-wp.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
wallkit/trunk/includes/class-wallkit-wp-access.php
r2112945 r2166257 40 40 return self::$instance; 41 41 } 42 43 /** 44 * @return \Wallkit_Wp_Admin_Posts 45 */ 46 public function get_wk_posts() { 47 return new Wallkit_Wp_Admin_Posts(static::$wallkit_Wp_Collection); 48 } 42 49 43 50 /** … … 50 57 */ 51 58 private function __wakeup () {} 52 59 53 60 /** 54 * @param WP_Post|NULL $WP_Post 61 * @param \WP_Post|null $WP_Post 62 * @param bool $autoCreate 55 63 * @return bool 56 64 */ 57 public function check_post_access(WP_Post $WP_Post = null ) {65 public function check_post_access(WP_Post $WP_Post = null, $autoCreate = true) { 58 66 59 67 if(!$WP_Post instanceof WP_Post || !isset($WP_Post->ID)) … … 113 121 } 114 122 } 123 catch(\WallkitSDK\Exceptions\WallkitNotFoundException $exception) 124 { 125 Wallkit_Wp_Logger::log("access false in check_post_access as Exception: ".$exception->getMessage(), "error"); 126 127 if(self::$wallkit_Wp_Collection->get_settings()->get_option("wk_is_auto_sync") && $autoCreate) { 128 129 Wallkit_Wp_Logger::log("post not found in wallkit contents. try create postID ".$WP_Post->ID, "info"); 130 131 try { 132 $this->get_wk_posts()->createPost($WP_Post->ID, $WP_Post); 133 134 return $this->check_post_access($WP_Post, false); 135 } 136 catch(\Exception $exception) { 137 Wallkit_Wp_Logger::log("create postID ".$WP_Post->ID." is failed by exception: ". $exception->getMessage(), "error"); 138 Wallkit_Wp_Logger::log("access false in check_post_access after created failed", "error"); 139 return false; 140 } 141 } 142 } 115 143 catch (\Exception $exception) 116 144 { -
wallkit/trunk/vendor/wallkit-php-sdk/src/WallkitClient.php
r2109517 r2166257 5 5 use WallkitSDK\Exceptions\WallkitApiException; 6 6 use WallkitSDK\Exceptions\WallkitException; 7 use WallkitSDK\Exceptions\WallkitNotFoundException; 7 8 8 9 class WallkitClient 9 10 { 11 10 12 /** 11 13 * @var WallkitToken $token 12 14 */ 13 15 protected $token; 14 15 16 protected $host; 16 17 protected $api_version; 17 18 protected $resource; 18 19 19 20 /** 20 21 * WallkitClient constructor. … … 24 25 * @param String $resource 25 26 */ 26 function __construct($token, $host,$api_version,$resource)27 function __construct($token, $host, $api_version, $resource) 27 28 { 28 29 $this->token = $token; … … 31 32 $this->resource = $resource; 32 33 } 33 34 34 35 /** 35 36 * @param WallkitToken $token … … 38 39 function setToken($token) 39 40 { 40 if (!$token instanceof WallkitToken)41 if(!$token instanceof WallkitToken) 41 42 throw new WallkitException('Invalid Token'); 42 43 43 44 $this->token = $token; 44 45 } 45 46 46 47 /** 47 48 * @return bool|String 48 49 */ 49 public function getTokenValue() { 50 if ($this->token) 50 public function getTokenValue() 51 { 52 if($this->token) 51 53 return $this->token->getValue(); 54 52 55 return false; 53 56 } 54 57 55 58 /** 56 59 * @param $headers 57 60 * @return array 58 61 */ 59 function compileHeaders($headers) { 62 function compileHeaders($headers) 63 { 60 64 $headers = array_merge([ 61 65 'token' => $this->getTokenValue(), 62 'resource' => $this->resource 63 ],$headers); 64 65 if(session_id()) 66 { 66 'resource' => $this->resource, 67 ], $headers); 68 69 if(session_id()) { 67 70 $headers["session"] = session_id(); 68 71 } 69 70 return array_map(function ($value, $key) {71 return $key . ': ' .$value;72 }, $headers,array_keys($headers));72 73 return array_map(function ($value, $key) { 74 return $key.': '.$value; 75 }, $headers, array_keys($headers)); 73 76 } 74 77 75 78 /** 76 79 * @param $method 77 * @param array$headers80 * @param $headers 78 81 * @param $url 79 82 * @param $body 80 * @return WallkitResponse 81 * @throws WallkitApiException 82 * @throws WallkitException 83 * @return \WallkitSDK\WallkitResponse 84 * @throws \WallkitSDK\Exceptions\WallkitApiException 85 * @throws \WallkitSDK\Exceptions\WallkitException 86 * @throws \WallkitSDK\Exceptions\WallkitNotFoundException 83 87 */ 84 function sendRequest($method,$headers,$url,$body) { 85 88 function sendRequest($method, $headers, $url, $body) 89 { 90 86 91 $info = ""; 87 92 88 93 $url = "https://$this->host/api/$this->api_version$url"; 89 90 if(defined("WPWKP_VERSION")) 91 { 94 95 if(defined("WPWKP_VERSION")) { 92 96 $info .= " WPWKP v".WPWKP_VERSION; 93 97 } 94 95 if(function_exists("phpversion")) 96 { 98 99 if(function_exists("phpversion")) { 97 100 $info .= " php v".phpversion(); 98 101 } 99 102 100 103 $headers["Wallkit-Client"] = "PhpSDK v0.1.3".$info; 101 104 102 105 $body = $this->utf8ize($body); 103 104 if($method === "GET") 105 { 106 107 if($method === "GET") { 106 108 $url .= "?".http_build_query($body); 107 109 } 108 110 109 111 $options = [ 110 112 CURLOPT_CUSTOMREQUEST => $method, … … 117 119 CURLOPT_SSL_VERIFYHOST => false, 118 120 ]; 119 120 if ($method !== "GET") 121 { 121 122 if($method !== "GET") { 122 123 try { 123 124 $options[CURLOPT_POSTFIELDS] = json_encode($body, JSON_UNESCAPED_UNICODE); 124 } 125 catch (\Exception $exception) 126 { 125 } catch(\Exception $exception) { 127 126 throw new WallkitException("Json encode is failed"); 128 127 } 129 128 } 130 129 131 130 $curl = curl_init(); 132 131 curl_setopt_array($curl, $options); 133 132 $response = curl_exec($curl); 134 135 if ($curlErrorCode = curl_errno($curl)) {133 134 if($curlErrorCode = curl_errno($curl)) { 136 135 throw new WallkitException(curl_error($curl), $curlErrorCode); 137 136 } 138 137 139 138 $info = curl_getinfo($curl); 140 139 141 140 curl_close($curl); 142 143 if (!($info['http_code'] <= 226 && $info['http_code'] >= 200 )) {144 throw new Wallkit ApiException($info,$response);141 142 if($info['http_code'] === 404) { 143 throw new WallkitNotFoundException($info, $response); 145 144 } 146 147 return new WallkitResponse($info,$response); 145 146 if(!($info['http_code'] <= 226 && $info['http_code'] >= 200)) { 147 throw new WallkitApiException($info, $response); 148 } 149 150 return new WallkitResponse($info, $response); 148 151 } 149 152 150 153 /** 151 154 * @param $mixed 152 155 * @return array|string 153 156 */ 154 private function utf8ize($mixed) { 155 156 if(!function_exists("mb_convert_encoding")) 157 private function utf8ize($mixed) 157 158 { 159 160 if(!function_exists("mb_convert_encoding")) { 158 161 return $mixed; 159 162 } 160 161 if (is_array($mixed)) {162 foreach ($mixed as $key => $value) {163 164 if(is_array($mixed)) { 165 foreach($mixed as $key => $value) { 163 166 $mixed[$key] = $this->utf8ize($value); 164 167 } 165 } else if (is_string($mixed)) {168 } else if(is_string($mixed)) { 166 169 return mb_convert_encoding($mixed, "UTF-8", "auto"); 167 170 } 171 168 172 return $mixed; 169 173 } -
wallkit/trunk/vendor/wallkit-php-sdk/src/WallkitSDK.php
r2109517 r2166257 150 150 return (bool) $this->token && self::$instance->user && self::$instance->user->isAuth(); 151 151 } 152 153 /** 154 * @param $url 155 * @param array $params 156 * @param bool $asAdmin 157 * @return WallkitResponse 158 * @throws Exceptions\WallkitApiException 159 * @throws WallkitException 152 153 /** 154 * @param $url 155 * @param array $params 156 * @param bool $asAdmin 157 * @return \WallkitSDK\WallkitResponse 158 * @throws \WallkitSDK\Exceptions\WallkitApiException 159 * @throws \WallkitSDK\Exceptions\WallkitException 160 * @throws \WallkitSDK\Exceptions\WallkitNotFoundException 160 161 */ 161 162 function get($url,$params = [],$asAdmin = false) { … … 166 167 return $this->client->sendRequest("GET",$headers, $url, $params); 167 168 } 168 169 /** 170 * @param $url 171 * @param array $params 172 * @param bool $asAdmin 173 * @return WallkitResponse 174 * @throws Exceptions\WallkitApiException 175 * @throws WallkitException 169 170 /** 171 * @param $url 172 * @param array $params 173 * @param bool $asAdmin 174 * @return \WallkitSDK\WallkitResponse 175 * @throws \WallkitSDK\Exceptions\WallkitApiException 176 * @throws \WallkitSDK\Exceptions\WallkitException 177 * @throws \WallkitSDK\Exceptions\WallkitNotFoundException 176 178 */ 177 179 function post($url,$params = [],$asAdmin = false) { -
wallkit/trunk/wallkit-wp.php
r2157879 r2166257 10 10 * Plugin URI: https://wallkit.net 11 11 * Description: A Plug & Play paid-content system to manage subscribers, gather fees and drive additional content sales. 12 * Version: 1.1.3 512 * Version: 1.1.36 13 13 * Author: Wallkit <dev@wallkit.net> 14 14 * Author URI: https://wallkit.net/ … … 27 27 * Rename this for your plugin and update it as you release new versions. 28 28 */ 29 define( 'WPWKP_VERSION', '1.1.3 5' );29 define( 'WPWKP_VERSION', '1.1.36' ); 30 30 31 31 /**
Note: See TracChangeset
for help on using the changeset viewer.