Changeset 1890443
- Timestamp:
- 06/10/2018 12:36:30 PM (8 years ago)
- Location:
- semantify-it/trunk
- Files:
-
- 9 edited
-
admin/partials/meta_boxes_notices.php (modified) (3 diffs)
-
admin/partials/semantify_it-admin-display.php (modified) (2 diffs)
-
includes/class-semantify_it.php (modified) (1 diff)
-
includes/controller/SemantifyItWrapperController.php (modified) (1 diff)
-
includes/model/domain/SemantifyItWrapper.php (modified) (2 diffs)
-
public/partials/deploy_annotation.php (modified) (2 diffs)
-
readme.txt (modified) (2 diffs)
-
semantify_it.php (modified) (1 diff)
-
vendor/semantify-api-php/SemantifyIt.php (modified) (13 diffs)
Legend:
- Unmodified
- Added
- Removed
-
semantify-it/trunk/admin/partials/meta_boxes_notices.php
r1654116 r1890443 2 2 3 3 $admin_url = admin_url( 'admin.php?page=' . $this->plugin_name ); 4 5 6 7 4 8 5 … … 13 10 die(); 14 11 } 15 16 12 17 13 … … 30 26 } 31 27 } 32 33 34 35 36 28 } -
semantify-it/trunk/admin/partials/semantify_it-admin-display.php
r1654116 r1890443 18 18 19 19 $apikey = $this->h->loadContent('api_key'); 20 $Semantify = new SemantifyItWrapperController($apikey); 20 $apisecret = $this->h->loadContent('api_secret'); 21 $Semantify = new SemantifyItWrapperController($apikey, $apisecret); 21 22 22 23 $admin = 1; … … 55 56 </p> 56 57 <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/> 57 64 <br/> 58 65 <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 72 72 73 73 $this->plugin_name = 'semantify_it'; 74 $this->version = '0.1. 4';74 $this->version = '0.1.5'; 75 75 76 76 $this->load_dependencies(); -
semantify-it/trunk/includes/controller/SemantifyItWrapperController.php
r1776822 r1890443 32 32 * @param string $key 33 33 */ 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); 42 37 } 43 38 -
semantify-it/trunk/includes/model/domain/SemantifyItWrapper.php
r1683505 r1890443 17 17 * @param string $key 18 18 */ 19 public function __construct($key = "" )19 public function __construct($key = "", $secret = "") 20 20 { 21 21 … … 29 29 } 30 30 31 32 31 if ($key != "") { 33 32 $this->setWebsiteApiKey($key); 33 } 34 35 if ($secret != "") { 36 $this->setWebsiteApiSecret($secret); 34 37 } 35 38 -
semantify-it/trunk/public/partials/deploy_annotation.php
r1683281 r1890443 27 27 28 28 $apiKey = $this->h->loadContent('api_key'); 29 $apiSecret = $this->h->loadContent('api_secret'); 30 29 31 30 32 if(!$apiKey){ … … 32 34 } 33 35 34 $Semantify = new SemantifyItWrapperController($apiKey );36 $Semantify = new SemantifyItWrapperController($apiKey, $apiSecret); 35 37 36 38 $annotationByURL = $this->h->loadContent('annotationByURL'); -
semantify-it/trunk/readme.txt
r1776822 r1890443 3 3 Tags: annotations, schema.org, semantify 4 4 Plugin Name: semantify.it 5 Version: 0.1. 45 Version: 0.1.5 6 6 Author: semantify.it 7 7 Author URI: semantify.it … … 51 51 = 1.4 = 52 52 * Updated API to new version 53 = 1.5 = 54 * Support for websites api secret 53 55 54 56 == Upgrade Notice == 55 57 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 16 16 * Plugin Name: semantify.it 17 17 * Description: Deploy your annotations from semantify.it to your wordpress website. 18 * Version: 0.1. 418 * Version: 0.1.5 19 19 * Author: semantify.it 20 20 * Author URI: www.semantify.it -
semantify-it/trunk/vendor/semantify-api-php/SemantifyIt.php
r1776822 r1890443 20 20 21 21 /** 22 * website secret 23 */ 24 private $websiteApiSecret; 25 26 27 /** 22 28 * variable for Url 23 29 * … … 85 91 86 92 /** 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 /** 87 139 * SemantifyIt constructor. 88 140 * 89 141 * @param string $key 90 142 */ 91 public function __construct($key = "" )143 public function __construct($key = "", $secret = "") 92 144 { 93 145 if ($key != "") { … … 95 147 } 96 148 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')) { 99 154 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 105 225 106 226 … … 113 233 * @throws Exception 114 234 */ 115 private function get($url )235 private function get($url, $headers) 116 236 { 117 237 118 238 //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); 120 240 121 241 if ($content === false) { … … 131 251 } 132 252 133 private function post($url, $params )253 private function post($url, $params, $headers) 134 254 { 135 255 $action = "POST"; 136 $content = $this->curl($action, $url, $params );256 $content = $this->curl($action, $url, $params, $headers); 137 257 138 258 if ($content === false) { … … 148 268 } 149 269 150 private function patch($url, $params )270 private function patch($url, $params, $headers) 151 271 { 152 272 $action = "PATCH"; 153 $content = $this->curl($action, $url, $params );273 $content = $this->curl($action, $url, $params, $headers); 154 274 155 275 if ($content === false) { … … 170 290 171 291 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; 178 296 179 297 $ch = curl_init(); … … 185 303 186 304 if($type!="GET"){ 305 306 $params_string = $params; //because it is already in json 187 307 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); 190 314 } 191 315 … … 213 337 } 214 338 215 /**216 *217 * transport layer for api218 *219 * @param $type220 * @param path221 * @param array $params222 * @return string223 */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 api230 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 method257 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 }272 339 273 340 /** … … 284 351 285 352 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 309 354 310 355 /** … … 334 379 public function postAnnotation($json) 335 380 { 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); 340 383 341 384 return $json; … … 344 387 /** 345 388 * 346 * update an annotation by uid 389 * update an annotation by uid to website 347 390 * 348 391 * @param $json … … 350 393 * @return string 351 394 */ 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); 358 400 359 401 return $json;
Note: See TracChangeset
for help on using the changeset viewer.