Plugin Directory

Changeset 2166257


Ignore:
Timestamp:
10/01/2019 09:35:23 AM (6 years ago)
Author:
wallkit
Message:

version 1.1.36

  • fix auto sync posts
Location:
wallkit/trunk
Files:
1 added
4 edited

Legend:

Unmodified
Added
Removed
  • wallkit/trunk/includes/class-wallkit-wp-access.php

    r2112945 r2166257  
    4040        return self::$instance;
    4141    }
     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    }
    4249
    4350    /**
     
    5057     */
    5158    private function __wakeup () {}
    52 
     59   
    5360    /**
    54      * @param WP_Post|NULL $WP_Post
     61     * @param \WP_Post|null $WP_Post
     62     * @param bool $autoCreate
    5563     * @return bool
    5664     */
    57     public function check_post_access(WP_Post $WP_Post = null) {
     65    public function check_post_access(WP_Post $WP_Post = null, $autoCreate = true) {
    5866
    5967        if(!$WP_Post instanceof WP_Post || !isset($WP_Post->ID))
     
    113121            }
    114122        }
     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        }
    115143        catch (\Exception $exception)
    116144        {
  • wallkit/trunk/vendor/wallkit-php-sdk/src/WallkitClient.php

    r2109517 r2166257  
    55use WallkitSDK\Exceptions\WallkitApiException;
    66use WallkitSDK\Exceptions\WallkitException;
     7use WallkitSDK\Exceptions\WallkitNotFoundException;
    78
    89class WallkitClient
    910{
     11   
    1012    /**
    1113     * @var WallkitToken $token
    1214     */
    1315    protected $token;
    14 
    1516    protected $host;
    1617    protected $api_version;
    1718    protected $resource;
    18 
     19   
    1920    /**
    2021     * WallkitClient constructor.
     
    2425     * @param String $resource
    2526     */
    26     function __construct($token,$host,$api_version,$resource)
     27    function __construct($token, $host, $api_version, $resource)
    2728    {
    2829        $this->token = $token;
     
    3132        $this->resource = $resource;
    3233    }
    33 
     34   
    3435    /**
    3536     * @param WallkitToken $token
     
    3839    function setToken($token)
    3940    {
    40         if (!$token instanceof WallkitToken)
     41        if(!$token instanceof WallkitToken)
    4142            throw new WallkitException('Invalid Token');
    42 
     43       
    4344        $this->token = $token;
    4445    }
    45 
     46   
    4647    /**
    4748     * @return bool|String
    4849     */
    49     public function getTokenValue() {
    50         if ($this->token)
     50    public function getTokenValue()
     51    {
     52        if($this->token)
    5153            return $this->token->getValue();
     54       
    5255        return false;
    5356    }
    54 
     57   
    5558    /**
    5659     * @param $headers
    5760     * @return array
    5861     */
    59     function compileHeaders($headers) {
     62    function compileHeaders($headers)
     63    {
    6064        $headers = array_merge([
    6165            '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()) {
    6770            $headers["session"] = session_id();
    6871        }
    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));
    7376    }
    74 
     77   
    7578    /**
    7679     * @param $method
    77      * @param array $headers
     80     * @param $headers
    7881     * @param $url
    7982     * @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
    8387     */
    84     function sendRequest($method,$headers,$url,$body) {
    85 
     88    function sendRequest($method, $headers, $url, $body)
     89    {
     90       
    8691        $info = "";
    87 
     92       
    8893        $url = "https://$this->host/api/$this->api_version$url";
    89 
    90         if(defined("WPWKP_VERSION"))
    91         {
     94       
     95        if(defined("WPWKP_VERSION")) {
    9296            $info .= " WPWKP v".WPWKP_VERSION;
    9397        }
    94 
    95         if(function_exists("phpversion"))
    96         {
     98       
     99        if(function_exists("phpversion")) {
    97100            $info .= " php v".phpversion();
    98101        }
    99 
     102       
    100103        $headers["Wallkit-Client"] = "PhpSDK v0.1.3".$info;
    101 
     104       
    102105        $body = $this->utf8ize($body);
    103 
    104         if($method === "GET")
    105         {
     106       
     107        if($method === "GET") {
    106108            $url .= "?".http_build_query($body);
    107109        }
    108 
     110       
    109111        $options = [
    110112            CURLOPT_CUSTOMREQUEST => $method,
     
    117119            CURLOPT_SSL_VERIFYHOST => false,
    118120        ];
    119 
    120         if ($method !== "GET")
    121         {
     121       
     122        if($method !== "GET") {
    122123           try {
    123124               $options[CURLOPT_POSTFIELDS] = json_encode($body, JSON_UNESCAPED_UNICODE);
    124            }
    125            catch (\Exception $exception)
    126            {
     125            } catch(\Exception $exception) {
    127126               throw new WallkitException("Json encode is failed");
    128127           }
    129128        }
    130 
     129       
    131130        $curl = curl_init();
    132131        curl_setopt_array($curl, $options);
    133132        $response = curl_exec($curl);
    134 
    135         if ($curlErrorCode = curl_errno($curl)) {
     133       
     134        if($curlErrorCode = curl_errno($curl)) {
    136135            throw new WallkitException(curl_error($curl), $curlErrorCode);
    137136        }
    138 
     137       
    139138        $info = curl_getinfo($curl);
    140 
     139       
    141140        curl_close($curl);
    142 
    143         if (!($info['http_code'] <= 226 && $info['http_code'] >= 200 )) {
    144             throw new WallkitApiException($info,$response);
     141       
     142        if($info['http_code'] === 404) {
     143            throw new WallkitNotFoundException($info, $response);
    145144        }
    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);
    148151    }
    149 
     152   
    150153    /**
    151154     * @param $mixed
    152155     * @return array|string
    153156     */
    154     private function utf8ize($mixed) {
    155 
    156         if(!function_exists("mb_convert_encoding"))
     157    private function utf8ize($mixed)
    157158        {
     159       
     160        if(!function_exists("mb_convert_encoding")) {
    158161            return $mixed;
    159162        }
    160 
    161         if (is_array($mixed)) {
    162             foreach ($mixed as $key => $value) {
     163       
     164        if(is_array($mixed)) {
     165            foreach($mixed as $key => $value) {
    163166                $mixed[$key] = $this->utf8ize($value);
    164167            }
    165         } else if (is_string ($mixed)) {
     168        } else if(is_string($mixed)) {
    166169            return mb_convert_encoding($mixed, "UTF-8", "auto");
    167170        }
     171       
    168172        return $mixed;
    169173    }
  • wallkit/trunk/vendor/wallkit-php-sdk/src/WallkitSDK.php

    r2109517 r2166257  
    150150        return (bool) $this->token && self::$instance->user && self::$instance->user->isAuth();
    151151    }
    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
    160161     */
    161162    function get($url,$params = [],$asAdmin = false) {
     
    166167        return $this->client->sendRequest("GET",$headers, $url, $params);
    167168    }
    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
    176178     */
    177179    function post($url,$params = [],$asAdmin = false) {
  • wallkit/trunk/wallkit-wp.php

    r2157879 r2166257  
    1010 * Plugin URI:        https://wallkit.net
    1111 * Description:       A Plug & Play paid-content system to manage subscribers, gather fees and drive additional content sales.
    12  * Version:           1.1.35
     12 * Version:           1.1.36
    1313 * Author:            Wallkit <dev@wallkit.net>
    1414 * Author URI:        https://wallkit.net/
     
    2727 * Rename this for your plugin and update it as you release new versions.
    2828 */
    29 define( 'WPWKP_VERSION', '1.1.35' );
     29define( 'WPWKP_VERSION', '1.1.36' );
    3030
    3131/**
Note: See TracChangeset for help on using the changeset viewer.