Plugin Directory

Changeset 1890443


Ignore:
Timestamp:
06/10/2018 12:36:30 PM (8 years ago)
Author:
semantify
Message:

New api version

Location:
semantify-it/trunk
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • semantify-it/trunk/admin/partials/meta_boxes_notices.php

    r1654116 r1890443  
    22
    33$admin_url = admin_url( 'admin.php?page=' . $this->plugin_name );
    4 
    5 
    6 
    74
    85
     
    1310    die();
    1411}
    15 
    1612
    1713
     
    3026        }
    3127    }
    32 
    33 
    34 
    35 
    3628}
  • semantify-it/trunk/admin/partials/semantify_it-admin-display.php

    r1654116 r1890443  
    1818
    1919$apikey = $this->h->loadContent('api_key');
    20 $Semantify = new SemantifyItWrapperController($apikey);
     20$apisecret = $this->h->loadContent('api_secret');
     21$Semantify = new SemantifyItWrapperController($apikey, $apisecret);
    2122
    2223$admin = 1;
     
    5556            </p>
    5657            <input type="text" name="data[api_key]" class="code large-text" value="<?php echo $this->h->loadContent('api_key'); ?>"><br/>
     58
     59            <h4><span><?php esc_attr_e( 'Website API Secret', $this->plugin_name ); ?></span></h4>
     60            <p>
     61                <?php esc_attr_e( 'Please input your Website API secret'); ?>
     62            </p>
     63            <input type="text" name="data[api_secret]" class="code large-text" value="<?php echo $this->h->loadContent('api_secret'); ?>"><br/>
    5764            <br/>
    5865            <h4><span><?php esc_attr_e( 'Automatic Annotation search by URL', $this->plugin_name ); ?></span></h4>
  • semantify-it/trunk/includes/class-semantify_it.php

    r1776822 r1890443  
    7272
    7373        $this->plugin_name = 'semantify_it';
    74         $this->version = '0.1.4';
     74        $this->version = '0.1.5';
    7575
    7676        $this->load_dependencies();
  • semantify-it/trunk/includes/controller/SemantifyItWrapperController.php

    r1776822 r1890443  
    3232     * @param string $key
    3333     */
    34     function __construct($key="")
    35     {
    36 
    37         if($key!=""){
    38             $this->model = new SemantifyItWrapper($key);
    39         }else{
    40             $this->model = new SemantifyItWrapper();
    41         }
     34    function __construct($key="", $secret="")
     35    {
     36         $this->model = new SemantifyItWrapper($key, $secret);
    4237    }
    4338
  • semantify-it/trunk/includes/model/domain/SemantifyItWrapper.php

    r1683505 r1890443  
    1717     * @param string $key
    1818     */
    19     public function __construct($key = "")
     19    public function __construct($key = "", $secret = "")
    2020    {
    2121
     
    2929        }
    3030
    31 
    3231        if ($key != "") {
    3332            $this->setWebsiteApiKey($key);
     33        }
     34
     35        if ($secret != "") {
     36            $this->setWebsiteApiSecret($secret);
    3437        }
    3538
  • semantify-it/trunk/public/partials/deploy_annotation.php

    r1683281 r1890443  
    2727
    2828    $apiKey = $this->h->loadContent('api_key');
     29    $apiSecret = $this->h->loadContent('api_secret');
     30
    2931
    3032    if(!$apiKey){
     
    3234    }
    3335
    34     $Semantify = new SemantifyItWrapperController($apiKey);
     36    $Semantify = new SemantifyItWrapperController($apiKey, $apiSecret);
    3537
    3638    $annotationByURL = $this->h->loadContent('annotationByURL');
  • semantify-it/trunk/readme.txt

    r1776822 r1890443  
    33Tags: annotations, schema.org, semantify
    44Plugin Name:       semantify.it
    5 Version:           0.1.4
     5Version:           0.1.5
    66Author:            semantify.it
    77Author URI:        semantify.it
     
    5151= 1.4 =
    5252* Updated API to new version
     53= 1.5 =
     54* Support for websites api secret
    5355
    5456== Upgrade Notice ==
    5557
    56 = 1.4 =
    57 * Update recommend for all users, because of new api version
     58= 1.5 =
     59* Update recommend for all users, because of new api version. Otherwise post Annotations will not work.
  • semantify-it/trunk/semantify_it.php

    r1776822 r1890443  
    1616 * Plugin Name:       semantify.it
    1717 * Description:       Deploy your annotations from semantify.it to your wordpress website.
    18  * Version:           0.1.4
     18 * Version:           0.1.5
    1919 * Author:            semantify.it
    2020 * Author URI:        www.semantify.it
  • semantify-it/trunk/vendor/semantify-api-php/SemantifyIt.php

    r1776822 r1890443  
    2020
    2121    /**
     22     * website secret
     23     */
     24    private $websiteApiSecret;
     25
     26
     27    /**
    2228     * variable for Url
    2329     *
     
    8591
    8692    /**
     93     * @return mixed
     94     */
     95    public function getWebsiteApiSecret()
     96    {
     97        if($this->websiteApiSecret==""){
     98            throw new Exception("Caught problem: no API secret saved!");
     99        }
     100
     101        return $this->websiteApiSecret;
     102    }
     103
     104    /**
     105     * @param mixed $websiteApiSecret
     106     */
     107    public function setWebsiteApiSecret($websiteApiSecret)
     108    {
     109        $this->websiteApiSecret = $websiteApiSecret;
     110    }
     111
     112    /**
     113     * getter for websiteApiKey
     114     *
     115     * @return string
     116     */
     117    public function getWebsiteApiKey()
     118    {
     119        //return ""
     120        if (($this->error) && (($this->websiteApiKey=="") || ($this->websiteApiKey=="0"))){
     121            throw new Exception("Caught problem: no API key saved!");
     122            echo "Caught problem: no API key saved!<br>";
     123        }
     124        return $this->websiteApiKey;
     125    }
     126
     127    /**
     128     * setter for websiteApiKey
     129     *
     130     * @param string $websiteApiKey
     131     */
     132    public function setWebsiteApiKey($websiteApiKey)
     133    {
     134        $this->websiteApiKey = $websiteApiKey;
     135    }
     136
     137
     138    /**
    87139     * SemantifyIt constructor.
    88140     *
    89141     * @param string $key
    90142     */
    91     public function __construct($key = "")
     143    public function __construct($key = "", $secret = "")
    92144    {
    93145        if ($key != "") {
     
    95147        }
    96148
    97         if($this->error){
    98             if(!function_exists('curl_version')) {
     149        if ($secret != "") {
     150            $this->setWebsiteApiSecret($secret);
     151        }
     152
     153        if(!function_exists('curl_version')) {
    99154                die("No curl library installed! API will not work.");
    100             }
    101         }
    102 
    103 
    104     }
     155        }
     156
     157    }
     158
     159
     160    /**
     161     *
     162     * transport layer for api
     163     *
     164     * @param       $type
     165     * @param       path
     166     * @param array $params
     167     * @return string
     168     */
     169    private function transport($type, $path, $params = array(), $settings = array())
     170    {
     171
     172        $headers = array();
     173
     174        /** url with server and path */
     175        $url = $this->live_server . '/' . $path;
     176        //if it is in staging server than switch to staging api
     177        if ($this->live == false) {
     178            $url = $this->staging_server . '/' . $path;
     179        }
     180
     181        /** add support for headers */
     182        if(!empty($settings["headers"])){
     183            $headers = $settings["headers"];
     184        }
     185
     186
     187        switch ($type) {
     188
     189            case "GET":
     190                try {
     191                    $fullurl = $url . (count($params) == 0 ? '' : '?' . http_build_query($params));
     192
     193                    return $this->get($fullurl, $headers);
     194                } catch (Exception $e) {
     195                    if ($this->error) {
     196                        echo 'Caught exception: ' . $e->getMessage() . "<br>";
     197                    }
     198
     199                    return false;
     200                }
     201                break;
     202
     203            case "POST":
     204            case "PATCH":
     205                try {
     206                    $fullurl = $url;
     207
     208                    //call the class method
     209                    return call_user_func_array(array($this, strtolower($type)), array($fullurl, $params, $headers));
     210
     211                } catch (Exception $e) {
     212                    if ($this->error) {
     213                        echo 'Caught exception: ' . $e->getMessage() . "<br>";
     214                    }
     215
     216                    return false;
     217                }
     218
     219                break;
     220
     221
     222        }
     223    }
     224
    105225
    106226
     
    113233     * @throws Exception
    114234     */
    115     private function get($url)
     235    private function get($url, $headers)
    116236    {
    117237
    118238        //if allow url fopen is allowed we will use file_get_contents otherwise curl
    119         $content = $this->curl("GET", $url);
     239        $content = $this->curl("GET", $url, "", $headers);
    120240
    121241        if ($content === false) {
     
    131251    }
    132252
    133     private function post($url, $params)
     253    private function post($url, $params, $headers)
    134254    {
    135255        $action = "POST";
    136         $content = $this->curl($action, $url, $params);
     256        $content = $this->curl($action, $url, $params, $headers);
    137257
    138258        if ($content === false) {
     
    148268    }
    149269
    150     private function patch($url, $params)
     270    private function patch($url, $params, $headers)
    151271    {
    152272        $action = "PATCH";
    153         $content = $this->curl($action, $url, $params);
     273        $content = $this->curl($action, $url, $params, $headers);
    154274
    155275        if ($content === false) {
     
    170290
    171291
    172     private function curl($type, $url, $params="")
    173     {
    174 
    175         $params_string = json_encode($params);
    176 
    177         //var_dump($params_string);
     292    private function curl($type, $url, $params="", $headers)
     293    {
     294
     295        //echo $url;
    178296
    179297        $ch = curl_init();
     
    185303
    186304        if($type!="GET"){
     305
     306            $params_string = $params; //because it is already in json
    187307            curl_setopt($ch, CURLOPT_POSTFIELDS, $params_string);
    188             curl_setopt($ch, CURLOPT_HTTPHEADER,
    189                         array('Content-Type: application/json', 'Content-Length: ' . strlen($params_string)));
     308
     309
     310            $Headers = array_merge(array('Content-Type: application/json', 'Content-Length: ' . strlen($params_string)), $headers);
     311
     312            //var_dump($Headers);
     313            curl_setopt($ch, CURLOPT_HTTPHEADER,$Headers);
    190314        }
    191315
     
    213337    }
    214338
    215     /**
    216      *
    217      * transport layer for api
    218      *
    219      * @param       $type
    220      * @param       path
    221      * @param array $params
    222      * @return string
    223      */
    224     private function transport($type, $path, $params = array())
    225     {
    226 
    227         /** url with server and path */
    228         $url = $this->live_server . '/' . $path;
    229         //if it is in staging server than switch to staging api
    230         if ($this->live == false) {
    231             $url = $this->staging_server . '/' . $path;
    232         }
    233 
    234 
    235         switch ($type) {
    236 
    237             case "GET":
    238                 try {
    239                     $fullurl = $url . (count($params) == 0 ? '' : '?' . http_build_query($params));
    240 
    241                     return $this->get($fullurl);
    242                 } catch (Exception $e) {
    243                     if ($this->error) {
    244                         echo 'Caught exception: ' . $e->getMessage() . "<br>";
    245                     }
    246 
    247                     return false;
    248                 }
    249                 break;
    250 
    251             case "POST":
    252             case "PATCH":
    253                 try {
    254                     $fullurl = $url;
    255 
    256                     //call the class method
    257                     return call_user_func_array(array($this, strtolower($type)), array($fullurl, $params));
    258 
    259                 } catch (Exception $e) {
    260                     if ($this->error) {
    261                         echo 'Caught exception: ' . $e->getMessage() . "<br>";
    262                     }
    263 
    264                     return false;
    265                 }
    266 
    267                 break;
    268 
    269 
    270         }
    271     }
    272339
    273340    /**
     
    284351
    285352
    286     /**
    287      * getter for websiteApiKey
    288      *
    289      * @return string
    290      */
    291     public function getWebsiteApiKey()
    292     {
    293         //return ""
    294         if (($this->error) && (($this->websiteApiKey=="") || ($this->websiteApiKey=="0"))){
    295             echo "Caught problem: no API key saved!<br>";
    296         }
    297         return $this->websiteApiKey;
    298     }
    299 
    300     /**
    301      * setter for websiteApiKey
    302      *
    303      * @param string $websiteApiKey
    304      */
    305     public function setWebsiteApiKey($websiteApiKey)
    306     {
    307         $this->websiteApiKey = $websiteApiKey;
    308     }
     353
    309354
    310355    /**
     
    334379    public function postAnnotation($json)
    335380    {
    336 
    337         $params["content"] = $json;
    338         $json = $this->transport("POST", "annotation/" . $this->getWebsiteApiKey(), $params);
    339 
     381        $settings["headers"] = array('website-secret:'." ".$this->getWebsiteApiSecret());
     382        $json = $this->transport("POST", "annotation/" . $this->getWebsiteApiKey(), $json, $settings);
    340383
    341384        return $json;
     
    344387    /**
    345388     *
    346      * update an annotation by uid
     389     * update an annotation by uid to website
    347390     *
    348391     * @param $json
     
    350393     * @return string
    351394     */
    352     public function updateAnnotation($json, $uid)
    353     {
    354 
    355         $params["content"] = $json;
    356         $json = $this->transport("PATCH", "annotation/".$uid."/" . $this->getWebsiteApiKey(), $params);
    357 
     395    public function updateAnnotation($json, $uid, $secret)
     396    {
     397
     398        $settings["headers"] = array('website-secret:'." ".$secret);
     399        $json = $this->transport("PATCH", "annotation/".$uid."/" . $this->getWebsiteApiKey(), $json, $settings);
    358400
    359401        return $json;
Note: See TracChangeset for help on using the changeset viewer.