Changeset 647244
- Timestamp:
- 01/02/2013 10:09:27 PM (13 years ago)
- Location:
- wp-pocket
- Files:
-
- 6 edited
- 1 copied
-
tags/1.2 (copied) (copied from wp-pocket/trunk)
-
tags/1.2/css/main.css (modified) (2 diffs)
-
tags/1.2/readme.txt (modified) (3 diffs)
-
tags/1.2/wp-pocket.php (modified) (61 diffs)
-
trunk/css/main.css (modified) (2 diffs)
-
trunk/readme.txt (modified) (3 diffs)
-
trunk/wp-pocket.php (modified) (61 diffs)
Legend:
- Unmodified
- Added
- Removed
-
wp-pocket/tags/1.2/css/main.css
r598433 r647244 10 10 .wppocket p.description { 11 11 margin: 2px 10px 5px 0; 12 } 13 14 .wppocket p.description textarea { 15 resize: vertical; 12 16 } 13 17 … … 62 66 } 63 67 68 .wppocket .description-thin.description-two-thirds { 69 width: 400px; 70 } 71 72 .wppocket .description-thin.description-one-thirds { 73 width: 180px; 74 } 75 64 76 .wppocket .menu-item-settings { 65 77 width: 600px; -
wp-pocket/tags/1.2/readme.txt
r618439 r647244 4 4 Tags: wp pocket, wordpress, pocket, post, automaticly, wp, links, linklist 5 5 Requires at least: 3.4 6 Tested up to: 3. 47 Stable tag: 1. 1.16 Tested up to: 3.5 7 Stable tag: 1.2 8 8 License: GPLv2 or later 9 9 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 52 52 == Changelog == 53 53 54 = 1.2 = 55 Rewrite to Pocket API v3 with oAuth 56 Check required PHP version 57 Added names of months in English, German or French language 58 Improved quality of link title and description 59 Implemented function to publish only links, that are marked as favorites in pocket 60 Implemented function to show the author of the article in the linklist 61 More variables possible in entry building, introduction text and statement text 62 Sends, if user allowed it, anonymous statistics to WP-Pocket.com 63 Solved coding problems of titles and descriptions 64 Solved the problem of marking more than 100 links as read 65 Improved performance 66 Improved commenting of the code 67 Other minor bugfixes 68 Removed Flattr button 69 54 70 = 1.1.1 = 55 71 Fix link to options in installed plugins overview … … 80 96 == ToDo == 81 97 82 Nothing. If you have requests, please tell me via the contact form on http://wp-pocket.com 98 Solve all links option in <i>Links to use</i> (possible, if Pocket save the bug in the API) 99 100 If you have requests, please tell me via the contact form on http://wp-pocket.com -
wp-pocket/tags/1.2/wp-pocket.php
r618439 r647244 6 6 Author: Jan Karres 7 7 Author URI: http://www.jankarres.de/ 8 Version: 1. 1.18 Version: 1.2 9 9 */ 10 11 10 if(!class_exists('wppocketer')) { 12 11 class wppocketer { … … 14 13 private $version; 15 14 16 // Pocket default API-Key by developer17 private $global_pocket_ api_key;15 // Pocket default Consumer-Key by developer 16 private $global_pocket_consumer_key; 18 17 19 18 function __construct() { … … 24 23 25 24 // Set plugin version 26 $this->version = '1. 1.1';25 $this->version = '1.2'; 27 26 28 27 // Check WP version 29 add_action('init', array(&$this, 'requires_ wordpress_version'));28 add_action('init', array(&$this, 'requires_versions')); 30 29 31 30 // Change plugin status hooks … … 42 41 wp_register_script('wppocket_main', plugins_url('js/main.js', __FILE__), array('jquery', 'jquery-ui-core', 'jquery-ui-draggable', 'jquery-ui-droppable')); 43 42 44 // Pocket default API-Key by developer 45 $this->global_pocket_api_key = '074A0c78dTi1bI26f2pU4b0X9dTbe798'; 46 } 47 48 function requires_wordpress_version() { 43 // Pocket default Consumer-Key by developer 44 $this->global_pocket_consumer_key = '10481-1069ebc911a9483c145d3d92'; 45 } 46 47 // Check if requied versions are supported 48 function requires_versions() { 49 49 global $wp_version; 50 50 … … 58 58 wp_die('<i>WP Pocket</i> requires WordPress 3.4 or higher. The plugin has been deactivated! Please update WordPress and try again.<br /><br />Back to <a href="' . admin_url() . '">WordPress Dashboard</a>.'); 59 59 } 60 } 61 62 // Check PHP Version 63 if (!version_compare(PHP_VERSION, '5.2', '>=')) { 64 deactivate_plugins($plugin); 65 wp_die('<i>WP Pocket</i> requires PHP 5.2 or higher. The plugin has been deactivated! Please update your PHP and try again.<br /><br />Back to <a href="' . admin_url() . '">WordPress Dashboard</a>.'); 60 66 } 61 67 … … 90 96 ("wppocket_version", "' . $this->version . '", "yes"), 91 97 ("wppocket_links_to_use", "0", "yes"), 98 ("wppocket_faved", "0", "yes"), 92 99 ("wppocket_order", "0", "yes"), 93 100 ("wppocket_mark_as_readed", "0", "yes"), … … 100 107 ("wppocket_post_category", "1", "yes"), 101 108 ("wppocket_pocket_username", "", "yes"), 102 ("wppocket_pocket_ password", "", "yes"),109 ("wppocket_pocket_access_key", "", "yes"), 103 110 ("wppocket_title", "WP Pocket link collection: %%month%% with %%count%% links", "yes"), 104 111 ("wppocket_introduction_text", "", "yes"), 105 112 ("wppocket_statements_text", "", "yes"), 106 ("wppocket_entry_building", "<strong>%%title%%</strong>[[: %%description%%]][[ - Tags: %%tags%%]] - %%url%%", "yes"), 113 ("wppocket_entry_building", "<strong>%%title%%</strong>[[: %%description%%]][[ - by %%author%%]][[ - Tags: %%tags%%]] - %%url%%", "yes"), 114 ("wppocket_language", "en", "yes"), 115 ("wppocket_statistics", "1", "yes"), 107 116 ("wppocket_key_a", "' . $this->keygen(128) . '", "yes"), 108 117 ("wppocket_key_b", "' . $this->keygen(128) . '", "yes") 109 118 '; 110 119 $this->wpdb->query($sql); 111 120 112 121 // Check if version under 1.0.2, if true, replace Pocket username, password and api-key 113 $version = explode('.', get_option('wppocket_version')); 114 if ( 115 ($version[0] == 1 && $version[1] == 0 && $version[2] < 2) || 116 ($version[0] == '' && $version[1] == '' && $version[2] == '') 117 ) { 122 if (!version_compare(get_option('wppocket_version'), '1.0.2', '>=')) { 118 123 // Update Pocket username, password and api-key 119 124 update_option('wppocket_pocket_username', $this->xcrypt(0, $this->xcrypt(1, get_option('wppocket_pocket_username'), true))); … … 122 127 } 123 128 124 // Save API Key 129 // Check if version under 1.2, if true, remove api-key for consumer-key, remove password, api custom key and reset username 130 if (!version_compare(get_option('wppocket_version'), '1.2', '>=')) { 131 // Remove api key 132 $sql = 'DELETE FROM `wp_options` WHERE `option_name`="wppocket_pocket_api_key" OR `option_name`="wppocket_pocket_password" OR `option_name`="wppocket_pocket_api_key_custom"'; 133 $this->wpdb->query($sql); 134 135 // Reset username 136 $sql = 'UPDATE `wp_options` SET `option_value` = "" WHERE `option_name`="wppocket_pocket_username";'; 137 $this->wpdb->query($sql); 138 } 139 140 // Create Customer Key in database 125 141 $sql = ' 126 142 INSERT IGNORE INTO `' . $this->wpdb->prefix . 'options` ( … … 129 145 `autoload` 130 146 ) VALUES 131 ("wppocket_pocket_ api_key_custom", "0", "yes"),132 ("wppocket_pocket_ api_key", "' . $this->xcrypt(0, $this->global_pocket_api_key) . '", "yes")147 ("wppocket_pocket_consumer_key_custom", "0", "yes"), 148 ("wppocket_pocket_consumer_key", "' . $this->xcrypt(0, $this->global_pocket_consumer_key) . '", "yes") 133 149 '; 134 150 $this->wpdb->query($sql); … … 136 152 // Check if plugin version number up to date 137 153 if (get_option('wppocket_version') != $this->version) { 154 // Send statistics, if allowed 155 if (get_option('wppocket_statistics') == 1) { 156 $this->statisticsUpdateVersion(); 157 } 158 138 159 // Update version number 139 160 update_option('wppocket_version', $this->version); … … 142 163 143 164 function deactivate() { 144 // nothing to do, because user ca m reactivate165 // nothing to do, because user can reactivate the plugin 145 166 } 146 167 … … 197 218 } 198 219 199 private function cURL($url, $timeout = 5) { 220 // Easy cURL function 221 private function cURL($url, $post, $timeout = 5) { 200 222 // Init cURL 201 223 $cURL = curl_init(); 224 225 // Define HTTP-Header 226 $httpheader = array(); 227 $httpheader[] = 'Content-type: application/x-www-form-urlencoded;charset=UTF-8'; 202 228 203 229 // Settings 204 230 curl_setopt($cURL, CURLOPT_URL, $url); 205 231 curl_setopt($cURL, CURLOPT_HEADER, 0); 232 curl_setopt($cURL, CURLOPT_HTTPHEADER, $httpheader); 206 233 curl_setopt($cURL, CURLOPT_RETURNTRANSFER, true); 207 234 curl_setopt($cURL, CURLOPT_TIMEOUT, $timeout); 235 236 // Save POST parameter in one string 237 if (count($post) != 0) { 238 $i = 0; 239 foreach ($post as $key => $value) { 240 if ($i != 0) { 241 $postAsString .= '&'; 242 } 243 244 $postAsString .= $key . '=' . $value; 245 246 $i++; 247 } 248 } 249 250 // Set POST parameters 251 curl_setopt($cURL, CURLOPT_POST, count($post)); 252 curl_setopt($cURL, CURLOPT_POSTFIELDS, $postAsString); 208 253 209 254 // Download … … 232 277 } 233 278 279 // Function to get Pocket user auth after OAuth 2.0 280 function authPocketAccountGetRequest() { 281 // Define current URL as return URL with GET parameter auth 282 $returnUrl = (isset($_SERVER['HTTPS'])?'https':'http') . '://' . $_SERVER['HTTP_HOST'] . str_replace('auth-get', 'auth', $_SERVER['REQUEST_URI']); 283 284 // Request authe 285 $oAuthRequest = $this->cURL( 286 'https://getpocket.com/v3/oauth/request', 287 array( 288 'consumer_key' => $this->xcrypt(1, get_option('wppocket_pocket_consumer_key')), 289 'redirect_uri' => $returnUrl 290 ) 291 ); 292 293 // Split return, to have [1] the needed request token 294 $oAuthRequestToken = explode('=', $oAuthRequest); 295 296 // Redirect user to Pocket auth form (via meta, because wp hadalready sent header) 297 echo '<meta http-equiv="refresh" content="0;url=' . 'https://getpocket.com/auth/authorize?request_token=' . urlencode($oAuthRequestToken[1]) . '&redirect_uri=' . urlencode($returnUrl . '&token=' . $oAuthRequestToken[1]) . '" />'; 298 exit; 299 } 300 301 // Function to save access token of a user 302 function authPocketAccountSaveAccessToken() { 303 // Define access token by GET 304 $oAuthRequestToken = $_GET['token']; 305 306 // Request authe 307 $oAuthAccess = $this->cURL( 308 'https://getpocket.com/v3/oauth/authorize', 309 array( 310 'consumer_key' => $this->xcrypt(1, get_option('wppocket_pocket_consumer_key')), 311 'code' => $oAuthRequestToken 312 ) 313 ); 314 315 // Split return to have access token and username seperated ([0][1] = access_key; [1][1] = username) 316 $oAuthAccess = explode('&', $oAuthAccess); 317 $oAuthAccess[0] = explode('=', $oAuthAccess[0]); 318 $oAuthAccess[1] = explode('=', $oAuthAccess[1]); 319 320 // Check if access key and username are set 321 if ($oAuthAccess[0][1] != '' && $oAuthAccess[1][1] != '') { 322 // Save auth key and username 323 update_option('wppocket_pocket_access_key', $this->xcrypt(0, $oAuthAccess[0][1])); 324 update_option('wppocket_pocket_username', $this->xcrypt(0, $oAuthAccess[1][1])); 325 326 // Redirect user to success page. Print not here, because if the user refresh, the auth would fail. 327 echo '<meta http-equiv="refresh" content="0;url=' . 'options-general.php?page=settings_pocket_poster&auth-success" />'; 328 exit; 329 }else { 330 // Print, the auth faild 331 echo '<div id="message" class="error">'; 332 echo '<p><strong>The authentication of your Pocket account failed. Please try again!</strong></p>'; 333 echo '</div>'; 334 } 335 } 336 337 // Function to clean links of unneeded shares 234 338 function cleanUpURL($url) { 235 339 // Filter $_GET[p], falls vorhanden, aus link … … 249 353 } 250 354 251 function replaceEntryBuilding($title, $description, $url, $tags, $replace = true) { 355 // Function to replace variables in the entry building 356 function replaceEntryBuilding($title, $description, $url, $tags, $author, $countwords, $replace = true) { 252 357 $wppocket_entry_building = get_option('wppocket_entry_building'); 253 358 … … 258 363 $wppocket_entry_building = str_replace('%%url%%', $url, $wppocket_entry_building); 259 364 $wppocket_entry_building = str_replace('%%tags%%', $tags, $wppocket_entry_building); 365 $wppocket_entry_building = str_replace('%%author%%', $author, $wppocket_entry_building); 366 $wppocket_entry_building = str_replace('%%countwords%%', $countwords, $wppocket_entry_building); 260 367 } 261 368 … … 267 374 } 268 375 376 // Function to replace variables in the title of the post 269 377 function getReplacedTitle($countLinks, $replace = true) { 270 378 $wppocket_title = get_option('wppocket_title'); … … 272 380 // Set the variables, if should do this 273 381 if ($replace) { 274 $wppocket_title = str_replace('%%day%%', date('l'), $wppocket_title);275 $wppocket_title = str_replace('%%month%%', date('F'), $wppocket_title);382 $wppocket_title = str_replace('%%day%%', $this->getReplaceLanguageDependentStrings(date('l')), $wppocket_title); 383 $wppocket_title = str_replace('%%month%%', $this->getReplaceLanguageDependentStrings(date('F')), $wppocket_title); 276 384 $wppocket_title = str_replace('%%year%%', date('Y'), $wppocket_title); 277 385 $wppocket_title = str_replace('%%count%%', $countLinks, $wppocket_title); … … 281 389 } 282 390 283 function getReplacedIntroductionText($replace = true) { 391 // Function to replace variables in the introduction text 392 function getReplacedIntroductionText($countLinks, $replace = true) { 284 393 $wppocket_introduction_text = get_option('wppocket_introduction_text'); 285 394 286 395 // Set the variables, if should do this 287 396 if ($replace) { 288 $wppocket_introduction_text = str_replace('%%day%%', date('l'), $wppocket_introduction_text);289 $wppocket_introduction_text = str_replace('%%month%%', date('F'), $wppocket_introduction_text);397 $wppocket_introduction_text = str_replace('%%day%%', $this->getReplaceLanguageDependentStrings(date('l')), $wppocket_introduction_text); 398 $wppocket_introduction_text = str_replace('%%month%%', $this->getReplaceLanguageDependentStrings(date('F')), $wppocket_introduction_text); 290 399 $wppocket_introduction_text = str_replace('%%year%%', date('Y'), $wppocket_introduction_text); 400 $wppocket_introduction_text = str_replace('%%count%%', $countLinks, $wppocket_introduction_text); 291 401 } 292 402 … … 294 404 } 295 405 296 function getReplacedStatementsText($replace = true) { 406 // Function to replace variables in the statements text 407 function getReplacedStatementsText($countLinks, $replace = true) { 297 408 $wppocket_statements_text = get_option('wppocket_statements_text'); 298 409 299 410 // Set the variables, if should do this 300 411 if ($replace) { 301 $wppocket_statements_text = str_replace('%%day%%', date('l'), $wppocket_statements_text); 302 $wppocket_statements_text = str_replace('%%month%%', date('F'), $wppocket_statements_text); 303 $wppocket_statements_text = str_replace('%%year%%', date('Y'), $wppocket_statements_text); 412 $wppocket_statements_text = str_replace('%%day%%', $this->getReplaceLanguageDependentStrings(date('l')), $wppocket_statements_text); 413 $wppocket_statements_text = str_replace('%%month%%', $this->getReplaceLanguageDependentStrings(date('F')), $wppocket_statements_text); 414 $wppocket_statements_text = str_replace('%%year%%', date('Y'), $wppocket_statements_text); 415 $wppocket_statements_text = str_replace('%%count%%', $countLinks, $wppocket_statements_text); 304 416 } 305 417 … … 307 419 } 308 420 421 // Function to replace language-dependent strings 422 function getReplaceLanguageDependentStrings($string) { 423 // Check with language is selected 424 if (get_option('wppocket_language') == 'de') { // German 425 // Return replaced strings 426 switch($string) { 427 case ('January'): 428 return 'Januar'; 429 break; 430 case ('February'): 431 return 'Februar'; 432 break; 433 case ('March'): 434 return 'März'; 435 break; 436 case ('April'): 437 return 'April'; 438 break; 439 case ('May'): 440 return 'Mai'; 441 break; 442 case ('June'): 443 return 'Juni'; 444 break; 445 case ('July'): 446 return 'July'; 447 break; 448 case ('August'): 449 return 'August'; 450 break; 451 case ('September'): 452 return 'Steptember'; 453 break; 454 case ('October'): 455 return 'Oktober'; 456 break; 457 case ('November'): 458 return 'November'; 459 break; 460 case ('December'): 461 return 'Dezember'; 462 break; 463 464 case ('Monday'): 465 return 'Montag'; 466 break; 467 case ('Tuesday'): 468 return 'Dienstag'; 469 break; 470 case ('Wednesday'): 471 return 'Mittwoch'; 472 break; 473 case ('Thursday'): 474 return 'Donnerstag'; 475 break; 476 case ('Friday'): 477 return 'Freitag'; 478 break; 479 case ('Saturday'): 480 return 'Samstag'; 481 break; 482 case ('Sunday'): 483 return 'Sonntag'; 484 break; 485 } 486 }else if (get_option('wppocket_language') == 'fr') { // French 487 // Return replaced strings 488 switch($string) { 489 case ('January'): 490 return 'janvier'; 491 break; 492 case ('February'): 493 return 'février'; 494 break; 495 case ('March'): 496 return 'mars'; 497 break; 498 case ('April'): 499 return 'avril'; 500 break; 501 case ('May'): 502 return 'mai'; 503 break; 504 case ('June'): 505 return 'juin'; 506 break; 507 case ('July'): 508 return 'juillet'; 509 break; 510 case ('August'): 511 return 'août'; 512 break; 513 case ('September'): 514 return 'septembre'; 515 break; 516 case ('October'): 517 return 'octobre'; 518 break; 519 case ('November'): 520 return 'novembre'; 521 break; 522 case ('December'): 523 return 'décembre'; 524 break; 525 526 case ('Monday'): 527 return 'lundi'; 528 break; 529 case ('Tuesday'): 530 return 'mardi'; 531 break; 532 case ('Wednesday'): 533 return 'mercredi'; 534 break; 535 case ('Thursday'): 536 return 'jeudi'; 537 break; 538 case ('Friday'): 539 return 'vendredi'; 540 break; 541 case ('Saturday'): 542 return 'samedi'; 543 break; 544 case ('Sunday'): 545 return 'dimanche'; 546 break; 547 } 548 }else { // English by default 549 // Return replaced strings 550 switch($string) { 551 case ('January'): 552 return 'January'; 553 break; 554 case ('February'): 555 return 'February'; 556 break; 557 case ('March'): 558 return 'March'; 559 break; 560 case ('April'): 561 return 'April'; 562 break; 563 case ('May'): 564 return 'May'; 565 break; 566 case ('June'): 567 return 'June'; 568 break; 569 case ('July'): 570 return 'July'; 571 break; 572 case ('August'): 573 return 'August'; 574 break; 575 case ('September'): 576 return 'September'; 577 break; 578 case ('October'): 579 return 'October'; 580 break; 581 case ('November'): 582 return 'November'; 583 break; 584 case ('December'): 585 return 'December'; 586 break; 587 588 case ('Monday'): 589 return 'Monday'; 590 break; 591 case ('Tuesday'): 592 return 'Tuesday'; 593 break; 594 case ('Wednesday'): 595 return 'Wednesday'; 596 break; 597 case ('Thursday'): 598 return 'Thursday'; 599 break; 600 case ('Friday'): 601 return 'Friday'; 602 break; 603 case ('Saturday'): 604 return 'Saturday'; 605 break; 606 case ('Sunday'): 607 return 'Sunday'; 608 break; 609 } 610 } 611 } 612 613 // Function to check if the plugin have access to a Pocket account 309 614 function checkPocketAccess() { 310 // Check if username, password and api-key is set, if not, print error311 if (get_option('wppocket_pocket_username') == '' || get_option('wppocket_pocket_ password') == '' || get_option('wppocket_pocket_api_key') == '') {615 // Check if username, password and consumer-key is set, if not, print error 616 if (get_option('wppocket_pocket_username') == '' || get_option('wppocket_pocket_access_key') == '' || get_option('wppocket_pocket_consumer_key') == '') { 312 617 ?> 313 618 <div id="message" class="error"> 314 <p><strong>WP Pocket can NOT work. Please save your Pocket username, password and API-Key (optional)!</strong></p>619 <p><strong>WP Pocket can NOT work. Please authenticate your Pocket account in the WP Pocket options!</strong></p> 315 620 </div> 316 621 <?php … … 318 623 }else { // Test the settings 319 624 // Init cURL 320 $getAuth = $this->cURL('https://readitlaterlist.com/v2/auth?username=' . $this->xcrypt(1, get_option('wppocket_pocket_username')) . '&password=' . $this->xcrypt(1, get_option('wppocket_pocket_password')) . '&apikey=' . $this->xcrypt(1, get_option('wppocket_pocket_api_key'))); 321 322 // Check if, user data ad api key correct 625 $getAuth = $this->cURL( 626 'https://getpocket.com/v3/send', 627 array( 628 'consumer_key' => $this->xcrypt(1, get_option('wppocket_pocket_consumer_key')), 629 'access_token' => $this->xcrypt(1, get_option('wppocket_pocket_access_key')), 630 'actions' => '[{}]' 631 ) 632 ); 633 634 // Check if, user data and consumer-key correct 323 635 if ($getAuth == '400 Bad Request') { 324 636 ?> 325 637 <div id="message" class="error"> 326 <p><strong>Your API-Key it not valid. Please correct it, else WP Pocket can NOT work.</strong></p>638 <p><strong>Your Consumer-Key it not valid. Please correct it, else WP Pocket can NOT work.</strong></p> 327 639 </div> 328 640 <?php … … 331 643 ?> 332 644 <div id="message" class="error"> 333 <p><strong> Your Pocket username and/or password it not valid. Please correct that, else WP Pocket can NOT work.</strong></p>645 <p><strong>The authentication of you Pocket account is expired. Please reauthenticate it, else WP Pocket can NOT work.</strong></p> 334 646 </div> 335 647 <?php … … 341 653 } 342 654 655 // Support box on the right side of each WP Pocket page 343 656 function support_div($display = true) { 344 657 ?> … … 346 659 <h3>support me</h3> 347 660 348 <p>If you use the plugin and like it, you can say thanks and support me. </p>661 <p>If you use the plugin and like it, you can say thanks and support me. How?</p> 349 662 350 663 <h3>follow me on twitter</h3> 351 664 352 665 <p> 353 <a href="https://twitter.com/jankarres" class="twitter-follow-button" data-show-count="false" data- lang="en" data-size="large">Follow @jankarres</a>666 <a href="https://twitter.com/jankarres" class="twitter-follow-button" data-show-count="false" data-size="large" data-dnt="true">Follow @jankarres</a> 354 667 <script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="https://plugins.trac.wordpress.org//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script> 355 668 </p> 356 669 357 <h3> donate on flattr</h3>358 359 < a href="http://flattr.com/thing/881252/WP-Pocket" target="_blank">360 <img src="http://api.flattr.com/button/flattr-badge-large.png" alt="Flattr this" title="Flattr this" border="0" />361 </ a>670 <h3>report bugs</h3> 671 672 <p> 673 You found a bug? You have an idea for a feature? Then let me know and send a request on <a href="http://wp-pocket.com/" target="_blank">WP-Pocket.com</a>! 674 </p> 362 675 </div> 363 676 <?php 364 677 } 365 678 679 // Function to set options page 366 680 function options_link() { 367 681 // Start the view of the options page … … 372 686 } 373 687 688 // Options page view 374 689 function options_page_view() { 375 690 // Add option page style … … 388 703 <?php $this->support_div(); ?> 389 704 390 <form method="post" action="<?php echo $_SERVER['REQUEST_URI']; ?>">391 705 <h3>Pocket Login</h3> 392 706 <table class="form-table"> 393 707 <tr> 394 <th>Pocket Username</th>708 <th>Pocket Auth</th> 395 709 <td> 396 <input type="text" size="57" name="wppocket_pocket_username" value="<?php if (get_option('wppocket_pocket_username') != '') { echo $this->xcrypt(1, get_option('wppocket_pocket_username')); } ?>" /> 710 <?php if (get_option('wppocket_pocket_username') != '') { echo $this->xcrypt(1, get_option('wppocket_pocket_username')) . ' authenticated.'; } ?> 711 <?php if (get_option('wppocket_pocket_username') == '') { echo '<a href="?page=settings_pocket_poster&auth-get"><input type="button" class="button-primary" value="Authenticate account" /></a>'; }else { echo '<a href="?page=settings_pocket_poster&auth-get"><input type="button" class="button-primary" value="Authenticate other account" /></a>'; } ?> 712 </td> 713 </tr> 714 715 <form method="post" action="<?php echo $_SERVER['REQUEST_URI']; ?>"> 716 717 <tr> 718 <th>Pocket Consumer-Key</th> 719 <td> 720 <input type="text" size="57" name="wppocket_pocket_consumer_key" value="<?php if(get_option('wppocket_pocket_consumer_key_custom') == 1) { echo $this->xcrypt(1, get_option('wppocket_pocket_consumer_key')); } ?>" /> 721 722 <?php if(get_option('wppocket_pocket_consumer_key_custom') == 1) { ?> 723 <label><input name="wppocket_pocket_consumer_key_custom_remove" type="checkbox" value="1" /> Use the default Consumer-Key</label> 724 <?php } ?> 725 726 <p class="description">If you wish to use a private Consumer-Key, please enter one. <strong>It is not necessary!</strong><br /> 727 You can get one on <a href="http://getpocket.com/developer/apps/new" target="_blank">http://getpocket.com/developer/apps/new</a>.</p> 728 </td> 729 </tr> 730 </table> 731 732 <h3>WP Pocket Settings</h3> 733 <table class="form-table"> 734 <tr> 735 <th>Language</th> 736 <td> 737 <select name="wppocket_language"> 738 <option value="en" <?php selected('en', get_option('wppocket_language')); ?>>English</option> 739 <option value="de" <?php selected('de', get_option('wppocket_language')); ?>>German</option> 740 <option value="fr" <?php selected('fr', get_option('wppocket_language')); ?>>French</option> 741 </select> 742 <p class="description">A few variables you can set are language-dependent. Which language should WP Pocket use? <strong>This setting does not change the language of complete WP Pocket (currently only English supported)!</strong></p> 397 743 </td> 398 744 </tr> 399 745 <tr> 400 <th> Pocket Password</th>746 <th>Statistics</th> 401 747 <td> 402 <input type="password" size="57" name="wppocket_pocket_password" value="" /> 403 <p class="description">If you do not wish to edit something, leave it blank.</p> 404 </td> 405 </tr> 406 <tr> 407 <th>Pocket API-Key</th> 408 <td> 409 <input type="text" size="57" name="wppocket_pocket_api_key" value="<?php if(get_option('wppocket_pocket_api_key_custom') == 1) { echo $this->xcrypt(1, get_option('wppocket_pocket_api_key')); } ?>" /> 410 411 <?php if(get_option('wppocket_pocket_api_key_custom') == 1) { ?> 412 <label><input name="wppocket_pocket_api_key_custom_remove" type="checkbox" value="1" /> Use the default API-Key</label> 413 <?php } ?> 414 415 <p class="description">If you wish to use a private API-Key, please enter one. <strong>It is not necessary!</strong><br /> 416 You can get one on <a href="http://getpocket.com/api/signup/" target="_blank">http://getpocket.com/api/signup/</a>.</p> 748 <select name="wppocket_statistics"> 749 <option value="1" <?php selected('1', get_option('wppocket_statistics')); ?>>Yes</option> 750 <option value="0" <?php selected('0', get_option('wppocket_statistics')); ?>>No</option> 751 </select> 752 <p class="description">Do you allow WP Pocket to collect anonymous statistics about published links and updates and send them to WP-Pocket.com? These statistics will only be used to improve WP Pocket.</p> 417 753 </td> 418 754 </tr> … … 426 762 <select name="wppocket_links_to_use"> 427 763 <option value="0" <?php selected('0', get_option('wppocket_links_to_use')); ?>>Only unread links, which are unposted</option> 428 <option value="1" <?php selected('1', get_option('wppocket_links_to_use')); ?>>Only read links, which are unposted</option>429 <option value="2" <?php selected('2', get_option('wppocket_links_to_use')); ?> >All links, which are unposted</option>764 <option value="1" <?php selected('1', get_option('wppocket_links_to_use')); ?>>Only read/archived links, which are unposted</option> 765 <option value="2" <?php selected('2', get_option('wppocket_links_to_use')); ?> disabled><s>All links, which are unposted</s> (Currently impossible due to a bug in Pocket API)</option> 430 766 <option value="3" <?php selected('3', get_option('wppocket_links_to_use')); ?>>All unread links, also already posted ones</option> 431 <option value="4" <?php selected('4', get_option('wppocket_links_to_use')); ?>>All read links, also already posted ones</option>432 <option value="5" <?php selected('5', get_option('wppocket_links_to_use')); ?> >All links, also already posted ones</option>767 <option value="4" <?php selected('4', get_option('wppocket_links_to_use')); ?>>All read/archived links, also already posted ones</option> 768 <option value="5" <?php selected('5', get_option('wppocket_links_to_use')); ?> disabled><s>All links, also already posted ones</s> (Currently impossible due to a bug in Pocket API)</option> 433 769 </select> 434 770 <p class="description">Which links should be used for the new post?</p> 771 </td> 772 </tr> 773 <tr> 774 <th>Favorites</th> 775 <td> 776 <select name="wppocket_faved"> 777 <option value="0" <?php selected('0', get_option('wppocket_faved')); ?>>All links</option> 778 <option value="1" <?php selected('1', get_option('wppocket_faved')); ?>>Only faved links</option> 779 <option value="2" <?php selected('2', get_option('wppocket_faved')); ?>>Only unfaved links</option> 780 </select> 781 <p class="description">Should only faved or unfaved links be used in a new post?</p> 435 782 </td> 436 783 </tr> … … 446 793 </tr> 447 794 <tr> 448 <th>Mark as readed </th>795 <th>Mark as readed/archived</th> 449 796 <td> 450 797 <select name="wppocket_mark_as_readed"> … … 565 912 write the text and the variable in double square brackets. For example: %%title%%[[ - Tags: %%tags%%]]<br /> 566 913 <strong>Use <i>%%title%%</i> for title of the link in pocket; <i>%%description%%</i> for the meta description of the link; 567 <i>%%url%%</i> for the link itself; <i>%%tags%%</i> for added tags in pocket.</strong> 914 <i>%%url%%</i> for the link itself; <i>%%tags%%</i> for added tags in pocket/metatags; <i>%%author%%</i> for the name 915 of the author who wrote the article; <i>%%countwords%%</i> for the number of words, which the article has</strong> 568 916 </p> 569 917 </td> … … 581 929 <p class="description"> 582 930 At the beginning of the post, before the links, this text will be shown.<br /> 583 <strong>Use <i>%%day%%</i> for day, on which the post is being generated; <i>%%month%%</i> for the month; <i>%%year%%</i> for the year .</strong>931 <strong>Use <i>%%day%%</i> for day, on which the post is being generated; <i>%%month%%</i> for the month; <i>%%year%%</i> for the year; %%count%% to get the number of posted links.</strong> 584 932 </p> 585 933 </td> … … 597 945 <p class="description"> 598 946 At the end of the post, after the links, this text will be shown.<br /> 599 <strong>Use <i>%%day%%</i> for day, on which the post is being generated; <i>%%month%%</i> for the month; <i>%%year%%</i> for the year .</strong>947 <strong>Use <i>%%day%%</i> for day, on which the post is being generated; <i>%%month%%</i> for the month; <i>%%year%%</i> for the year; %%count%% to get the number of posted links.</strong> 600 948 </p> 601 949 </td> … … 613 961 } 614 962 963 // Options page controller 615 964 function options_page_controller() { 965 // Check if should start Pocket auth process 966 if (isset($_GET['auth-get'])) { 967 // Start Pocket auth process 968 $this->authPocketAccountGetRequest(); 969 } 970 971 // Check if should save Pocket access token 972 if (isset($_GET['auth'])) { 973 // Save Pocket access token 974 $this->authPocketAccountSaveAccessToken(); 975 } 976 977 // Check if Pocket account auth saved successfull 978 if (isset($_GET['auth-success'])) { 979 // Print, the auth succeed 980 echo '<div id="message" class="updated">'; 981 echo '<p><strong>You have successfully authenticated your Pocket Account!</strong></p>'; 982 echo '</div>'; 983 } 984 616 985 // Check if setting sended 617 986 if ($_POST['wppocket_edit']) { … … 621 990 // Error Text Array 622 991 $errorLang = array( 623 '0' => 'Please enter your Pocket username.', 624 '1' => 'Please enter your Pocket password.', 625 '2' => 'Please enter your Pocket API-Key or reset it to use the default key.', 626 '3' => 'Please enter a title for the posts.', 627 '4' => 'Please enter a building for each link which will be posted.' 992 '1' => 'Please enter your Pocket Consumer-Key or reset it to use the default key (recommend).', 993 '2' => 'Please enter a title for the posts.', 994 '3' => 'Please enter a building for each link which will be posted.' 628 995 ); 629 996 630 997 // Update "Pocket Login" 631 998 632 // Check if Pocket username is isset 633 if ($_POST['wppocket_pocket_username'] == '') { 634 $error[] = 0; 635 }else { 636 update_option('wppocket_pocket_username', $this->xcrypt(0, $_POST['wppocket_pocket_username'])); 637 } 638 639 // Check if Pocket one password is isset 640 if (get_option('wppocket_pocket_password') == '' && $_POST['wppocket_pocket_password'] == '') { 999 if ($_POST['wppocket_pocket_consumer_key_custom_remove'] == 1) { 1000 // Set default key 1001 update_option('wppocket_pocket_consumer_key_custom', 0); 1002 update_option('wppocket_pocket_consumer_key', $this->xcrypt(0, $this->global_pocket_consumer_key)); 1003 1004 // Reset authed Pocket account 1005 update_option('wppocket_pocket_access_key', ''); 1006 update_option('wppocket_pocket_username', ''); 1007 $changeConsumerKey = true; 1008 }elseif(get_option('wppocket_pocket_consumer_key_custom') == 1 && $_POST['wppocket_pocket_consumer_key'] == '') { 641 1009 $error[] = 1; 642 }elseif ($_POST['wppocket_pocket_password'] != '') { 643 update_option('wppocket_pocket_password', $this->xcrypt(0, $_POST['wppocket_pocket_password'])); 644 } 645 646 if ($_POST['wppocket_pocket_api_key_custom_remove'] == 1) { 647 // Set default key 648 update_option('wppocket_pocket_api_key_custom', 0); 649 update_option('wppocket_pocket_api_key', $this->xcrypt(0, $this->global_pocket_api_key)); 650 }elseif(get_option('wppocket_pocket_api_key_custom') == 1 && $_POST['wppocket_pocket_api_key'] == '') { 651 $error[] = 2; 652 }elseif(get_option('wppocket_pocket_api_key_custom') == 1 && $_POST['wppocket_pocket_api_key'] != '') { 1010 }elseif(get_option('wppocket_pocket_consumer_key_custom') == 1 && $_POST['wppocket_pocket_consumer_key'] != '') { 653 1011 // Set new key 654 update_option('wppocket_pocket_api_key', $this->xcrypt(0, $_POST['wppocket_pocket_api_key'])); 655 }elseif (get_option('wppocket_pocket_api_key_custom') == 0 && $_POST['wppocket_pocket_api_key'] != '') { 656 // Set custom API-Key first time 657 update_option('wppocket_pocket_api_key_custom', 1); 658 update_option('wppocket_pocket_api_key', $this->xcrypt(0, $_POST['wppocket_pocket_api_key'])); 1012 update_option('wppocket_pocket_consumer_key', $this->xcrypt(0, $_POST['wppocket_pocket_consumer_key'])); 1013 1014 // Reset authed Pocket account 1015 update_option('wppocket_pocket_access_key', ''); 1016 update_option('wppocket_pocket_username', ''); 1017 $changeConsumerKey = true; 1018 }elseif (get_option('wppocket_pocket_consumer_key_custom') == 0 && $_POST['wppocket_pocket_consumer_key'] != '') { 1019 // Set custom Consumer-Key first time 1020 update_option('wppocket_pocket_consumer_key_custom', 1); 1021 update_option('wppocket_pocket_consumer_key', $this->xcrypt(0, $_POST['wppocket_pocket_consumer_key'])); 1022 1023 // Reset authed Pocket account 1024 update_option('wppocket_pocket_access_key', ''); 1025 update_option('wppocket_pocket_username', ''); 1026 $changeConsumerKey = true; 659 1027 } 660 1028 … … 665 1033 666 1034 update_option('wppocket_links_to_use', $_POST['wppocket_links_to_use']); 1035 update_option('wppocket_faved', $_POST['wppocket_faved']); 667 1036 update_option('wppocket_order', $_POST['wppocket_order']); 668 1037 update_option('wppocket_mark_as_readed', $_POST['wppocket_mark_as_readed']); … … 715 1084 // Check if title is not set 716 1085 if ($_POST['wppocket_title'] == '') { 717 $error[] = 3;1086 $error[] = 2; 718 1087 }else { 719 1088 update_option('wppocket_title', $_POST['wppocket_title']); … … 722 1091 // Chech if entry building is not set 723 1092 if ($_POST['wppocket_entry_building'] == '') { 724 $error[] = 4;1093 $error[] = 3; 725 1094 }else { 726 1095 update_option('wppocket_entry_building', $_POST['wppocket_entry_building']); … … 730 1099 update_option('wppocket_introduction_text', $_POST['wppocket_introduction_text']); 731 1100 update_option('wppocket_statements_text', $_POST['wppocket_statements_text']); 1101 1102 // WP Pocket settings 1103 update_option('wppocket_language', $_POST['wppocket_language']); 1104 update_option('wppocket_statistics', $_POST['wppocket_statistics']); 732 1105 733 1106 // Output all errors … … 750 1123 <?php 751 1124 } 1125 1126 // Check if Consumer-Key was changed. If yes, azth was reseted. 1127 if ($changeConsumerKey) { 1128 ?> 1129 <div id="message" class="updated"> 1130 <p><strong>You changed the Consumer-Key. Because of, the authentication of your WP Pocket account was removed. Please reauthenticate!</strong></p> 1131 </div> 1132 <?php 1133 } 752 1134 } 753 1135 … … 756 1138 } 757 1139 1140 // Function to set the main page 758 1141 function main_link() { 759 1142 // Start the view of the main page … … 761 1144 } 762 1145 1146 // Main page view 763 1147 function main_page_view() { 764 1148 // Add option page style … … 781 1165 <div class="nav-tabs-arrow nav-tabs-arrow-left" style="display: none; "><a>«</a></div> 782 1166 <div class="nav-tabs-wrapper"> 783 <div class="nav-tabs" style="padding: 0px; margin-right: -110px; margin-left: 0px; ">1167 <div class="nav-tabs"> 784 1168 <span class="nav-tab nav-tab-active"></span><a href="#" class="nav-tab menu-add-new"></a> 785 1169 </div> … … 804 1188 if ($checkPocketAccess) { 805 1189 // Get links from the user 806 807 // Should get Readed, onreaded or all links? 1190 $getLinksPost = array(); 1191 1192 $getLinksPost['consumer_key'] = $this->xcrypt(1, get_option('wppocket_pocket_consumer_key')); 1193 $getLinksPost['access_token'] = $this->xcrypt(1, get_option('wppocket_pocket_access_key')); 1194 $getLinksPost['detailType'] = 'complete'; 1195 1196 // Should get Readed, unreaded or all links? 808 1197 if (get_option('wppocket_links_to_use') == 0 || get_option('wppocket_links_to_use') == 3) { // Unreaded 809 $ state = '&state=unread';810 }elseif (get_option('wppocket_links_to_use') == 1 || get_option('wppocket_links_to_use') == 4) { // Readed 811 $ state = '&state=read';1198 $getLinksPost['state'] = 'unread'; 1199 }elseif (get_option('wppocket_links_to_use') == 1 || get_option('wppocket_links_to_use') == 4) { // Readed / Archived 1200 $getLinksPost['state'] = 'archive'; 812 1201 } // All 813 1202 814 $getLinks = $this->cURL('https://readitlaterlist.com/v2/get?username=' . $this->xcrypt(1, get_option('wppocket_pocket_username')) . '&password=' . $this->xcrypt(1, get_option('wppocket_pocket_password')) . '&apikey=' . $this->xcrypt(1, get_option('wppocket_pocket_api_key')) . $state . '&tags=1', 30); 1203 // Check if only faved or unfaved links should use 1204 if (get_option('wppocket_faved') == 1) { // only faved 1205 $getLinksPost['favorite'] = '1'; 1206 }else if (get_option('wppocket_faved') == 2) { // only unfaved 1207 $getLinksPost['favorite'] = '0'; 1208 } // All 1209 1210 // Check if order should be oldest to newest or newest to oldest 1211 if (get_option('wppocket_order')) { // oldest to newest 1212 $getLinksPost['sort'] = 'oldest'; 1213 }else { // newest to oldest 1214 $getLinksPost['sort'] = 'newest'; 1215 } 1216 1217 $getLinks = $this->cURL( 1218 'https://getpocket.com/v3/get', 1219 $getLinksPost 1220 ); 815 1221 816 1222 // Decode JSON to Object … … 822 1228 foreach ($getLinks->list as $key => $value) { 823 1229 // Check if aleady posted. If true, remove it 824 $sql = 'SELECT `id` FROM `' . $this->wpdb->prefix . 'wppocket_posted_links` WHERE `url`="' . $value-> url . '"';1230 $sql = 'SELECT `id` FROM `' . $this->wpdb->prefix . 'wppocket_posted_links` WHERE `url`="' . $value->given_url . '"'; 825 1231 $row = $this->wpdb->get_results($sql); 826 1232 … … 829 1235 } 830 1236 } 831 }832 833 // Check if order should be oldest to newest834 if (get_option('wppocket_order')) {835 // Turn around the json object836 $tmp = json_encode($getLinks, true);837 $tmp = json_decode($tmp, true);838 $tmp['list'] = array_reverse($tmp['list']);839 $tmp = json_encode($tmp, true);840 $tmp = json_decode($tmp);841 $getLinks = $tmp;842 1237 } 843 1238 … … 864 1259 <?php 865 1260 // Gennerate output of each link 866 foreach ($getLinks->list as $key => $value) { 867 // Get description 868 $urlHtml = $this->cURL($value->url); 869 870 $doc = new DOMDocument(); 871 @$doc->loadHTML($urlHtml); 872 873 if ($value->title == '') { 874 $nodes = $doc->getElementsByTagName('title'); 875 $value->title = utf8_decode($nodes->item(0)->nodeValue); 1261 foreach ($getLinks->list as $key => $value) { 1262 // Rewirte Tags Array as Tags string 1263 if (count($value->tags) != 0) { 1264 $tagsAsString = ''; 1265 $i2 = 0; 1266 foreach ($value->tags as $tag) { 1267 if ($i2 != 0) { 1268 $tagsAsString .= ', '; 1269 } 1270 1271 $tagsAsString .= $tag->tag; 1272 1273 $i2++; 1274 } 876 1275 877 if (!$this->is_utf8($value->title)) { 878 $value->title = utf8_encode($value->title); 879 } 1276 $value->tags = $tagsAsString; 1277 unset($tagsAsString); 1278 }else { // Not tags yet 1279 $value->tags = ''; 880 1280 } 881 1281 882 $metas = $doc->getElementsByTagName('meta'); 883 884 for ($i = 0; $i < $metas->length; $i++) { 885 $meta = $metas->item($i); 1282 // Get data from the meta tags, if necessary 1283 if ($value->resolved_title == '' || $value->excerpt == '' || (get_option('wppocket_meta_keyword_as_tags') == 1 && $value->tags == '')) { 1284 $urlHtml = $this->cURL($value->given_url, array()); 886 1285 887 if($meta->getAttribute('name') == 'description') { 888 $value->description = utf8_decode($meta->getAttribute('content')); 889 if (!$this->is_utf8($value->description)) { 890 $value->description = utf8_encode($value->description); 1286 $doc = new DOMDocument(); 1287 @$doc->loadHTML($urlHtml); 1288 1289 if ($value->resolved_title == '') { 1290 $nodes = $doc->getElementsByTagName('title'); 1291 $value->title = utf8_decode($nodes->item(0)->nodeValue); 1292 1293 if (!$this->is_utf8($value->title)) { 1294 $value->title = utf8_encode($value->title); 891 1295 } 892 1296 } 893 1297 894 if (get_option('wppocket_meta_keyword_as_tags') == 1) { 895 if ($meta->getAttribute('name') == 'keywords') { 896 $value->tags = utf8_decode($meta->getAttribute('content')); 897 if (!$this->is_utf8($value->tags)) { 898 $value->tags = utf8_encode($value->tags); 1298 $metas = $doc->getElementsByTagName('meta'); 1299 1300 for ($i = 0; $i < $metas->length; $i++) { 1301 $meta = $metas->item($i); 1302 1303 if ($value->excerpt == '') { 1304 if($meta->getAttribute('name') == 'description') { 1305 $value->excerpt = utf8_decode($meta->getAttribute('content')); 1306 if (!$this->is_utf8($value->excerpt)) { 1307 $value->excerpt = utf8_encode($value->excerpt); 1308 } 1309 } 1310 } 1311 1312 if (get_option('wppocket_meta_keyword_as_tags') == 1 && $value->tags == '') { 1313 if ($meta->getAttribute('name') == 'keywords') { 1314 $value->tags = utf8_decode($meta->getAttribute('content')); 1315 if (!$this->is_utf8($value->tags)) { 1316 $value->tags = utf8_encode($value->tags); 1317 } 899 1318 } 900 1319 } … … 906 1325 <dt class="menu-item-handle"> 907 1326 <div class="left"> 908 <?php echo $value-> title; ?>1327 <?php echo $value->resolved_title; ?> 909 1328 </div> 910 1329 <div class="right"> … … 916 1335 917 1336 <div class="menu-item-settings" id="item-<?php echo $key; ?>"> 918 <p class="description description-thin ">1337 <p class="description description-thin description-two-thirds"> 919 1338 <label for="item-<?php echo $key; ?>-input-title"> 920 1339 Title<br /> 921 <input type="text" id="item-<?php echo $key; ?>-input-title" class="widefat input-title" name="element[][title]" value="<?php echo $value-> title; ?>" />1340 <input type="text" id="item-<?php echo $key; ?>-input-title" class="widefat input-title" name="element[][title]" value="<?php echo $value->resolved_title; ?>" /> 922 1341 </label> 923 1342 </p> 924 <p class="description description-thin"> 1343 <p class="description description-thin description-one-thirds"> 1344 <label for="item-<?php echo $key; ?>-input-author"> 1345 Author<br /> 1346 <input type="text" id="item-<?php echo $key; ?>-input-author" class="widefat input-title" name="element[][author]" value="<?php 1347 if (count($value->authors) != 0) { 1348 $i2 = 0; 1349 foreach($value->authors as $author) { 1350 if ($i2 != 0) { 1351 echo ', '; 1352 } 1353 1354 echo $author->name; 1355 1356 $i2++; 1357 } 1358 } 1359 ?>" /> 1360 </label> 1361 </p> 1362 <p class="description description-thin description-two-thirds"> 1363 <label for="item-<?php echo $key; ?>-input-url"> 1364 URL<br /> 1365 <input type="text" id="item-<?php echo $key; ?>-input-url" class="widefat" name="element[][url]" value="<?php if (get_option('wppocket_clean_url') == 1) { echo $this->cleanUpURL($value->resolved_url); }else { echo $value->given_url; } ?>" /> 1366 <input type="hidden" id="item-<?php echo $key; ?>-input-url" class="widefat" name="element[][url_uncleaned]" value="<?php echo $value->given_url; ?>" /> 1367 </label> 1368 </p> 1369 <p class="description description-thin description-one-thirds"> 925 1370 <label for="item-<?php echo $key; ?>-input-tags"> 926 Tags (optional)<br />1371 Tags<br /> 927 1372 <input type="text" id="item-<?php echo $key; ?>-input-tags" class="widefat" name="element[][tags]" value="<?php echo $value->tags; ?>" /> 928 1373 </label> … … 931 1376 <label for="item-<?php echo $key; ?>-input-description"> 932 1377 Description (optional)<br /> 933 <textarea name="element[][description]" rows="4" id="item-<?php echo $key; ?>-input-description" class="widefat" type="textarea"><?php echo $value->description; ?></textarea> 934 </label> 935 </p> 936 <p class="description"> 937 <label for="item-<?php echo $key; ?>-input-url"> 938 URL<br /> 939 <input type="text" id="item-<?php echo $key; ?>-input-url" class="widefat" name="element[][url]" value="<?php if (get_option('wppocket_clean_url') == 1) { echo $this->cleanUpURL($value->url); }else { echo $value->url; } ?>" /> 940 <input type="hidden" id="item-<?php echo $key; ?>-input-url" class="widefat" name="element[][url_uncleaned]" value="<?php echo $value->url; ?>" /> 1378 <textarea name="element[][description]" rows="4" id="item-<?php echo $key; ?>-input-description" class="widefat" type="textarea"><?php echo $value->excerpt; ?></textarea> 941 1379 </label> 942 1380 </p> 943 1381 944 <input type="hidden" name="element[][id]" value="<?php echo $key; ?>" /> 1382 1383 <input type="hidden" name="element[][id]" value="<?php echo $value->item_id; ?>" /> 1384 <input type="hidden" name="element[][countwords]" value="<?php echo $value->word_count; ?>" /> 945 1385 <input type="hidden" name="element[][associate]" class="associate" value="0" /> 946 1386 </div> … … 959 1399 } 960 1400 }elseif ($_POST['mode'] == 'save') { // Save post 961 // Check if elements was posted1401 // Check if elements was lposted 962 1402 if ($_POST['count_elements'] == 0) { // No elements 963 1403 ?> … … 999 1439 } 1000 1440 1441 // Options page controller 1001 1442 function main_page_controller() { 1002 1443 global $current_user; … … 1009 1450 1010 1451 // Set en empty example for entry building with replace 1011 $replaceEntryBuilding = $this->replaceEntryBuilding(false, false, false, false );1452 $replaceEntryBuilding = $this->replaceEntryBuilding(false, false, false, false, false, false); 1012 1453 1013 1454 // Set en empty example for entry building without replace 1014 $noReplaceEntryBuilding = $this->replaceEntryBuilding(false, false, false, false, false );1455 $noReplaceEntryBuilding = $this->replaceEntryBuilding(false, false, false, false, false, false, false); 1015 1456 1016 1457 // Check, which Array elements are dynamic. Set empy replace and flag in new array … … 1037 1478 unset($noReplaceEntryBuilding); 1038 1479 1480 ##################################### 1481 ## COMBINE URL, URL CLEANED AND ID ## 1482 ##################################### 1483 1484 $i = 0; 1485 while ($i < (count($_POST['element']) / 9)) { 1486 $url = $_POST['element'][(($i * 9) + 2)]['url']; 1487 $urlUncleaned = $_POST['element'][(($i * 9) + 3)]['url_uncleaned']; 1488 $id = $_POST['element'][(($i * 9) + 6)]['id']; 1489 1490 $_POST['element'][(($i * 9) + 2)] = array( 1491 array( 1492 $url, 1493 $urlUncleaned, 1494 $id 1495 ) 1496 ); 1497 1498 1499 $i++; 1500 } 1501 1039 1502 ######################### 1040 1503 ## SET ASSOCIATE LINKS ## 1041 1504 ######################### 1042 1505 $i = 0; 1043 while ($i < (count($_POST['element']) / 7)) {1506 while ($i < (count($_POST['element']) / 9)) { 1044 1507 // Check if this it not a associate link 1045 if (!$_POST['element'][($i * 7) + 5]['associate']) {1508 if (!$_POST['element'][($i * 9) + 6]['associate']) { 1046 1509 // Search for associate links in the following 1047 1510 $associateLinks = array(); … … 1049 1512 while(true) { 1050 1513 // If this is an associate links, add this to the array, else break the while-loop 1051 if ($_POST['element'][($i * 7) + 6 + ($i2 * 7)]['associate']) { 1052 $_POST['element'][($i * 7) + 3][] = $_POST['element'][(($i * 7) + 3 + ($i2 * 7))]['url']; 1053 $_POST['element'][($i * 7) + 4][] = $_POST['element'][(($i * 7) + 4 + ($i2 * 7))]['url_uncleaned']; 1514 if ($_POST['element'][($i * 9) + 8 + ($i2 * 9)]['associate']) { 1515 $_POST['element'][($i * 9) + 2][] = $_POST['element'][(($i * 9) + 2 + ($i2 * 9))][0]; 1054 1516 }else { 1055 1517 break; … … 1068 1530 1069 1531 // Set posted elements in $_POST for view 1070 $_POST['count_elements'] = round((count($_POST['element']) / 7));1532 $_POST['count_elements'] = round((count($_POST['element']) / 9)); 1071 1533 1072 1534 // Array for all posted links … … 1075 1537 $post_content = ''; 1076 1538 1077 // Set introduction text if not empty 1078 if (trim(get_option('wppocket_introduction_text')) != '') { 1079 $post_content .= $this->getReplacedIntroductionText(); 1080 } 1081 1082 // Gennerate all links intro text 1539 // Gennerate all links in text 1083 1540 $i = 0; 1084 while ($i < (count($_POST['element']) / 7)) {1541 while ($i < (count($_POST['element']) / 9)) { 1085 1542 // Check if only not posted links should post 1086 1543 if (get_option('wppocket_links_to_use') == 0 || get_option('wppocket_links_to_use') == 1 || get_option('wppocket_links_to_use') == 2) { 1087 1544 // Check if aleady posted. If true, confine to the next loop 1088 $sql = 'SELECT `id` FROM `' . $this->wpdb->prefix . 'wppocket_posted_links` WHERE `url`="' . $_POST['element'][($i * 7) + 3]['url'] . '"';1545 $sql = 'SELECT `id` FROM `' . $this->wpdb->prefix . 'wppocket_posted_links` WHERE `url`="' . $_POST['element'][($i * 9) + 2]['url'] . '"'; 1089 1546 $row = $this->wpdb->get_results($sql); 1090 1547 1091 1548 if ($row[0]->id != '') { 1092 $_POST['count_elements'] -= count($_POST['element'][($i * 7) + 3]); // - this and associated elements1549 $_POST['count_elements'] -= count($_POST['element'][($i * 9) + 2]); // - this and associated elements 1093 1550 $i++; 1094 1551 continue; … … 1097 1554 1098 1555 // Check if this it not a associate link 1099 if (!$_POST['element'][($i * 7) + 6]['associate']) {1556 if (!$_POST['element'][($i * 9) + 8]['associate']) { 1100 1557 // Gennerate url array in url string 1101 1558 $url = ''; 1102 1559 1103 1560 $i2 = 0; 1104 foreach ($_POST['element'][($i * 7) + 3] as $value) {1561 foreach ($_POST['element'][($i * 9) + 2] as $value) { 1105 1562 if ($i2 != 0) { 1106 1563 $url .= '; '; 1107 1564 } 1108 1565 1109 $url .= '<a href="' . $value . '" target="_blank">' . $value . '</a>'; 1566 $url .= '<a href="' . $value[0] . '" target="_blank">' . $value[0] . '</a>'; 1567 1568 // Fill array for all posted links 1569 $allPostedLinks[] = $value; 1110 1570 1111 1571 $i2++; 1112 1572 } 1113 1573 1114 // Fill array for all posted links1115 foreach ($_POST['element'][($i * 7) + 4] as $value) {1116 $allPostedLinks[] = $value;1117 }1118 1119 1574 // Set element in entry building 1120 $element = $this->replaceEntryBuilding($_POST['element'][($i * 7)]['title'], $_POST['element'][($i * 7) + 2]['description'], $url, $_POST['element'][($i * 7) + 1]['tags']); 1575 $element = $this->replaceEntryBuilding( 1576 $_POST['element'][($i * 9)]['title'], 1577 $_POST['element'][($i * 9) + 5]['description'], 1578 $url, 1579 $_POST['element'][($i * 9) + 4]['tags'], 1580 $_POST['element'][($i * 9) + 1]['author'], 1581 $_POST['element'][($i * 9) + 7]['countwords'] 1582 ); 1121 1583 1122 1584 // Check if a dynamic element is not in use an delete it … … 1143 1605 } 1144 1606 1607 $post_content_final = ''; 1608 1609 // Set introduction text if not empty 1610 if (trim(get_option('wppocket_introduction_text')) != '') { 1611 $post_content_final .= $this->getReplacedIntroductionText($_POST['count_elements']); 1612 } 1613 1614 // Set links content 1615 $post_content_final .= $post_content; 1616 1145 1617 // Set statements text if not empty 1146 1618 if (trim(get_option('wppocket_statements_text')) != '') { 1147 $post_content .= $this->getReplacedStatementsText();1619 $post_content_final .= $this->getReplacedStatementsText($_POST['count_elements']); 1148 1620 } 1149 1621 1150 1622 // Chech if reference to WP Pocket shot print 1151 1623 if (get_option('wppocket_reference_wppocket')) { 1152 $post_content .= '<p><i>This post was automatically created by WP Pocket. If you look for this WordPress plugin, check out <a href="http://wp-pocket.com/" target="_blank">WP-Pocket.com</a> now!</i></p>';1624 $post_content_final .= '<p><i>This post was automatically created by WP Pocket. If you look for this WordPress plugin, check out <a href="http://wp-pocket.com/" target="_blank">WP-Pocket.com</a> now!</i></p>'; 1153 1625 } 1154 1626 … … 1165 1637 'post_author' => $current_user->ID, 1166 1638 'post_category' => array(get_option('wppocket_post_category')), 1167 'post_content' => $post_content ,1639 'post_content' => $post_content_final, 1168 1640 'post_date' => date('Y-m-d H:i:s'), 1169 1641 'post_date_gmt' => gmdate('Y-m-d H:i:s'), … … 1188 1660 $i = 0; 1189 1661 while ($i < count($allPostedLinks)) { 1190 $sql = 'SELECT `id` FROM `' . $this->wpdb->prefix . 'wppocket_posted_links` WHERE `url`="' . $allPostedLinks[$i] . '"';1662 $sql = 'SELECT `id` FROM `' . $this->wpdb->prefix . 'wppocket_posted_links` WHERE `url`="' . $allPostedLinks[$i][1] . '"'; 1191 1663 $row = $this->wpdb->get_results($sql); 1192 1664 … … 1206 1678 $this->wpdb->prepare( 1207 1679 $sql, 1208 $allPostedLinks[$i] ,1680 $allPostedLinks[$i][1], 1209 1681 $time 1210 1682 ) … … 1222 1694 // Check if link should marke as readed 1223 1695 if (get_option('wppocket_mark_as_readed')) { 1224 // JSON Start 1225 $markAsReaded = '{'; 1226 1227 // Fill JSON 1696 $markAsReaded = array(); 1697 1698 // Fill JSON as Array 1228 1699 $i = 0; 1229 1700 while ($i < count($allPostedLinks)) { 1230 if ($i != 0) { 1231 $markAsReaded .= ','; 1701 $markAsReaded[] = array( 1702 'action' => 'archive', 1703 'item_id' => $allPostedLinks[$i][2] 1704 ); 1705 1706 $i++; 1707 1708 // Chech if limit of links reached. If yes, send request and start new sends array 1709 if (($i / 100) == round($i / 100)) { 1710 // Send request 1711 $this->cURL( 1712 'https://getpocket.com/v3/send', 1713 array( 1714 'consumer_key' => $this->xcrypt(1, get_option('wppocket_pocket_consumer_key')), 1715 'access_token' => $this->xcrypt(1, get_option('wppocket_pocket_access_key')), 1716 'actions' => json_encode($markAsReaded) 1717 ) 1718 ); 1719 1720 // Clean up array 1721 $markAsReaded = array(); 1232 1722 } 1233 1234 $markAsReaded .= '"' . $i . '":{"url":"' . $allPostedLinks[$i] . '"}'; 1723 } 1724 1725 // Send request 1726 $this->cURL( 1727 'https://getpocket.com/v3/send', 1728 array( 1729 'consumer_key' => $this->xcrypt(1, get_option('wppocket_pocket_consumer_key')), 1730 'access_token' => $this->xcrypt(1, get_option('wppocket_pocket_access_key')), 1731 'actions' => json_encode($markAsReaded) 1732 ) 1733 ); 1734 } 1735 1736 // Send statistics, if allowed 1737 if (get_option('wppocket_statistics') == 1) { 1738 $allLinksForStatisics = array(); 1739 $i = 0; 1740 while ($i < count($allPostedLinks)) { 1741 $allLinksForStatisics[] = $allPostedLinks[$i][0]; 1235 1742 1236 1743 $i++; 1237 1744 } 1238 1745 1239 // JSON End 1240 $markAsReaded .= '}'; 1241 1242 // Send request 1243 $responses = $this->cURL('https://readitlaterlist.com/v2/send?username=' . $this->xcrypt(1, get_option('wppocket_pocket_username')) . '&password=' . $this->xcrypt(1, get_option('wppocket_pocket_password')) . '&apikey=' . $this->xcrypt(1, get_option('wppocket_pocket_api_key')) . '&read=' . urlencode($markAsReaded), 10); 1244 } 1245 } 1746 $this->statisticsPublishPost($allLinksForStatisics); 1747 } 1748 } 1749 } 1750 1751 // Statisics send to WP-Pocket.com: Update version 1752 private function statisticsUpdateVersion() { 1753 // Get Data 1754 $url = explode('?', ((empty($_SERVER['HTTPS'])) ? 'http' : 'https') . '://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']); 1755 $url = $url[0]; 1756 $type = 'update'; 1757 $versions = array('from' => get_option('wppocket_version'), 'to' => $this->version); 1758 1759 // Gennerate JSON Array 1760 $data = array( 1761 'url' => $url, 1762 'type' => $type, 1763 'update' => $versions 1764 ); 1765 1766 @$this->cURL( 1767 'http://pluginstats.wp-pocket.com/index.php', 1768 array( 1769 'data' => json_encode($data) 1770 ) 1771 ); 1772 } 1773 1774 // Statisics send to WP-Pocket.com: Publish post 1775 private function statisticsPublishPost($links) { 1776 echo 'HERO!'; 1777 1778 // Get Data 1779 $url = explode('?', ((empty($_SERVER['HTTPS'])) ? 'http' : 'https') . '://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']); 1780 $url = $url[0]; 1781 $type = 'publish'; 1782 1783 // Gennerate JSON Array 1784 $data = array( 1785 'url' => $url, 1786 'type' => $type, 1787 'links' => $links 1788 ); 1789 1790 echo $this->cURL( 1791 'http://pluginstats.wp-pocket.com/index.php', 1792 array( 1793 'data' => json_encode($data) 1794 ) 1795 ); 1246 1796 } 1247 1797 } -
wp-pocket/trunk/css/main.css
r598433 r647244 10 10 .wppocket p.description { 11 11 margin: 2px 10px 5px 0; 12 } 13 14 .wppocket p.description textarea { 15 resize: vertical; 12 16 } 13 17 … … 62 66 } 63 67 68 .wppocket .description-thin.description-two-thirds { 69 width: 400px; 70 } 71 72 .wppocket .description-thin.description-one-thirds { 73 width: 180px; 74 } 75 64 76 .wppocket .menu-item-settings { 65 77 width: 600px; -
wp-pocket/trunk/readme.txt
r618439 r647244 4 4 Tags: wp pocket, wordpress, pocket, post, automaticly, wp, links, linklist 5 5 Requires at least: 3.4 6 Tested up to: 3. 47 Stable tag: 1. 1.16 Tested up to: 3.5 7 Stable tag: 1.2 8 8 License: GPLv2 or later 9 9 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 52 52 == Changelog == 53 53 54 = 1.2 = 55 Rewrite to Pocket API v3 with oAuth 56 Check required PHP version 57 Added names of months in English, German or French language 58 Improved quality of link title and description 59 Implemented function to publish only links, that are marked as favorites in pocket 60 Implemented function to show the author of the article in the linklist 61 More variables possible in entry building, introduction text and statement text 62 Sends, if user allowed it, anonymous statistics to WP-Pocket.com 63 Solved coding problems of titles and descriptions 64 Solved the problem of marking more than 100 links as read 65 Improved performance 66 Improved commenting of the code 67 Other minor bugfixes 68 Removed Flattr button 69 54 70 = 1.1.1 = 55 71 Fix link to options in installed plugins overview … … 80 96 == ToDo == 81 97 82 Nothing. If you have requests, please tell me via the contact form on http://wp-pocket.com 98 Solve all links option in <i>Links to use</i> (possible, if Pocket save the bug in the API) 99 100 If you have requests, please tell me via the contact form on http://wp-pocket.com -
wp-pocket/trunk/wp-pocket.php
r618439 r647244 6 6 Author: Jan Karres 7 7 Author URI: http://www.jankarres.de/ 8 Version: 1. 1.18 Version: 1.2 9 9 */ 10 11 10 if(!class_exists('wppocketer')) { 12 11 class wppocketer { … … 14 13 private $version; 15 14 16 // Pocket default API-Key by developer17 private $global_pocket_ api_key;15 // Pocket default Consumer-Key by developer 16 private $global_pocket_consumer_key; 18 17 19 18 function __construct() { … … 24 23 25 24 // Set plugin version 26 $this->version = '1. 1.1';25 $this->version = '1.2'; 27 26 28 27 // Check WP version 29 add_action('init', array(&$this, 'requires_ wordpress_version'));28 add_action('init', array(&$this, 'requires_versions')); 30 29 31 30 // Change plugin status hooks … … 42 41 wp_register_script('wppocket_main', plugins_url('js/main.js', __FILE__), array('jquery', 'jquery-ui-core', 'jquery-ui-draggable', 'jquery-ui-droppable')); 43 42 44 // Pocket default API-Key by developer 45 $this->global_pocket_api_key = '074A0c78dTi1bI26f2pU4b0X9dTbe798'; 46 } 47 48 function requires_wordpress_version() { 43 // Pocket default Consumer-Key by developer 44 $this->global_pocket_consumer_key = '10481-1069ebc911a9483c145d3d92'; 45 } 46 47 // Check if requied versions are supported 48 function requires_versions() { 49 49 global $wp_version; 50 50 … … 58 58 wp_die('<i>WP Pocket</i> requires WordPress 3.4 or higher. The plugin has been deactivated! Please update WordPress and try again.<br /><br />Back to <a href="' . admin_url() . '">WordPress Dashboard</a>.'); 59 59 } 60 } 61 62 // Check PHP Version 63 if (!version_compare(PHP_VERSION, '5.2', '>=')) { 64 deactivate_plugins($plugin); 65 wp_die('<i>WP Pocket</i> requires PHP 5.2 or higher. The plugin has been deactivated! Please update your PHP and try again.<br /><br />Back to <a href="' . admin_url() . '">WordPress Dashboard</a>.'); 60 66 } 61 67 … … 90 96 ("wppocket_version", "' . $this->version . '", "yes"), 91 97 ("wppocket_links_to_use", "0", "yes"), 98 ("wppocket_faved", "0", "yes"), 92 99 ("wppocket_order", "0", "yes"), 93 100 ("wppocket_mark_as_readed", "0", "yes"), … … 100 107 ("wppocket_post_category", "1", "yes"), 101 108 ("wppocket_pocket_username", "", "yes"), 102 ("wppocket_pocket_ password", "", "yes"),109 ("wppocket_pocket_access_key", "", "yes"), 103 110 ("wppocket_title", "WP Pocket link collection: %%month%% with %%count%% links", "yes"), 104 111 ("wppocket_introduction_text", "", "yes"), 105 112 ("wppocket_statements_text", "", "yes"), 106 ("wppocket_entry_building", "<strong>%%title%%</strong>[[: %%description%%]][[ - Tags: %%tags%%]] - %%url%%", "yes"), 113 ("wppocket_entry_building", "<strong>%%title%%</strong>[[: %%description%%]][[ - by %%author%%]][[ - Tags: %%tags%%]] - %%url%%", "yes"), 114 ("wppocket_language", "en", "yes"), 115 ("wppocket_statistics", "1", "yes"), 107 116 ("wppocket_key_a", "' . $this->keygen(128) . '", "yes"), 108 117 ("wppocket_key_b", "' . $this->keygen(128) . '", "yes") 109 118 '; 110 119 $this->wpdb->query($sql); 111 120 112 121 // Check if version under 1.0.2, if true, replace Pocket username, password and api-key 113 $version = explode('.', get_option('wppocket_version')); 114 if ( 115 ($version[0] == 1 && $version[1] == 0 && $version[2] < 2) || 116 ($version[0] == '' && $version[1] == '' && $version[2] == '') 117 ) { 122 if (!version_compare(get_option('wppocket_version'), '1.0.2', '>=')) { 118 123 // Update Pocket username, password and api-key 119 124 update_option('wppocket_pocket_username', $this->xcrypt(0, $this->xcrypt(1, get_option('wppocket_pocket_username'), true))); … … 122 127 } 123 128 124 // Save API Key 129 // Check if version under 1.2, if true, remove api-key for consumer-key, remove password, api custom key and reset username 130 if (!version_compare(get_option('wppocket_version'), '1.2', '>=')) { 131 // Remove api key 132 $sql = 'DELETE FROM `wp_options` WHERE `option_name`="wppocket_pocket_api_key" OR `option_name`="wppocket_pocket_password" OR `option_name`="wppocket_pocket_api_key_custom"'; 133 $this->wpdb->query($sql); 134 135 // Reset username 136 $sql = 'UPDATE `wp_options` SET `option_value` = "" WHERE `option_name`="wppocket_pocket_username";'; 137 $this->wpdb->query($sql); 138 } 139 140 // Create Customer Key in database 125 141 $sql = ' 126 142 INSERT IGNORE INTO `' . $this->wpdb->prefix . 'options` ( … … 129 145 `autoload` 130 146 ) VALUES 131 ("wppocket_pocket_ api_key_custom", "0", "yes"),132 ("wppocket_pocket_ api_key", "' . $this->xcrypt(0, $this->global_pocket_api_key) . '", "yes")147 ("wppocket_pocket_consumer_key_custom", "0", "yes"), 148 ("wppocket_pocket_consumer_key", "' . $this->xcrypt(0, $this->global_pocket_consumer_key) . '", "yes") 133 149 '; 134 150 $this->wpdb->query($sql); … … 136 152 // Check if plugin version number up to date 137 153 if (get_option('wppocket_version') != $this->version) { 154 // Send statistics, if allowed 155 if (get_option('wppocket_statistics') == 1) { 156 $this->statisticsUpdateVersion(); 157 } 158 138 159 // Update version number 139 160 update_option('wppocket_version', $this->version); … … 142 163 143 164 function deactivate() { 144 // nothing to do, because user ca m reactivate165 // nothing to do, because user can reactivate the plugin 145 166 } 146 167 … … 197 218 } 198 219 199 private function cURL($url, $timeout = 5) { 220 // Easy cURL function 221 private function cURL($url, $post, $timeout = 5) { 200 222 // Init cURL 201 223 $cURL = curl_init(); 224 225 // Define HTTP-Header 226 $httpheader = array(); 227 $httpheader[] = 'Content-type: application/x-www-form-urlencoded;charset=UTF-8'; 202 228 203 229 // Settings 204 230 curl_setopt($cURL, CURLOPT_URL, $url); 205 231 curl_setopt($cURL, CURLOPT_HEADER, 0); 232 curl_setopt($cURL, CURLOPT_HTTPHEADER, $httpheader); 206 233 curl_setopt($cURL, CURLOPT_RETURNTRANSFER, true); 207 234 curl_setopt($cURL, CURLOPT_TIMEOUT, $timeout); 235 236 // Save POST parameter in one string 237 if (count($post) != 0) { 238 $i = 0; 239 foreach ($post as $key => $value) { 240 if ($i != 0) { 241 $postAsString .= '&'; 242 } 243 244 $postAsString .= $key . '=' . $value; 245 246 $i++; 247 } 248 } 249 250 // Set POST parameters 251 curl_setopt($cURL, CURLOPT_POST, count($post)); 252 curl_setopt($cURL, CURLOPT_POSTFIELDS, $postAsString); 208 253 209 254 // Download … … 232 277 } 233 278 279 // Function to get Pocket user auth after OAuth 2.0 280 function authPocketAccountGetRequest() { 281 // Define current URL as return URL with GET parameter auth 282 $returnUrl = (isset($_SERVER['HTTPS'])?'https':'http') . '://' . $_SERVER['HTTP_HOST'] . str_replace('auth-get', 'auth', $_SERVER['REQUEST_URI']); 283 284 // Request authe 285 $oAuthRequest = $this->cURL( 286 'https://getpocket.com/v3/oauth/request', 287 array( 288 'consumer_key' => $this->xcrypt(1, get_option('wppocket_pocket_consumer_key')), 289 'redirect_uri' => $returnUrl 290 ) 291 ); 292 293 // Split return, to have [1] the needed request token 294 $oAuthRequestToken = explode('=', $oAuthRequest); 295 296 // Redirect user to Pocket auth form (via meta, because wp hadalready sent header) 297 echo '<meta http-equiv="refresh" content="0;url=' . 'https://getpocket.com/auth/authorize?request_token=' . urlencode($oAuthRequestToken[1]) . '&redirect_uri=' . urlencode($returnUrl . '&token=' . $oAuthRequestToken[1]) . '" />'; 298 exit; 299 } 300 301 // Function to save access token of a user 302 function authPocketAccountSaveAccessToken() { 303 // Define access token by GET 304 $oAuthRequestToken = $_GET['token']; 305 306 // Request authe 307 $oAuthAccess = $this->cURL( 308 'https://getpocket.com/v3/oauth/authorize', 309 array( 310 'consumer_key' => $this->xcrypt(1, get_option('wppocket_pocket_consumer_key')), 311 'code' => $oAuthRequestToken 312 ) 313 ); 314 315 // Split return to have access token and username seperated ([0][1] = access_key; [1][1] = username) 316 $oAuthAccess = explode('&', $oAuthAccess); 317 $oAuthAccess[0] = explode('=', $oAuthAccess[0]); 318 $oAuthAccess[1] = explode('=', $oAuthAccess[1]); 319 320 // Check if access key and username are set 321 if ($oAuthAccess[0][1] != '' && $oAuthAccess[1][1] != '') { 322 // Save auth key and username 323 update_option('wppocket_pocket_access_key', $this->xcrypt(0, $oAuthAccess[0][1])); 324 update_option('wppocket_pocket_username', $this->xcrypt(0, $oAuthAccess[1][1])); 325 326 // Redirect user to success page. Print not here, because if the user refresh, the auth would fail. 327 echo '<meta http-equiv="refresh" content="0;url=' . 'options-general.php?page=settings_pocket_poster&auth-success" />'; 328 exit; 329 }else { 330 // Print, the auth faild 331 echo '<div id="message" class="error">'; 332 echo '<p><strong>The authentication of your Pocket account failed. Please try again!</strong></p>'; 333 echo '</div>'; 334 } 335 } 336 337 // Function to clean links of unneeded shares 234 338 function cleanUpURL($url) { 235 339 // Filter $_GET[p], falls vorhanden, aus link … … 249 353 } 250 354 251 function replaceEntryBuilding($title, $description, $url, $tags, $replace = true) { 355 // Function to replace variables in the entry building 356 function replaceEntryBuilding($title, $description, $url, $tags, $author, $countwords, $replace = true) { 252 357 $wppocket_entry_building = get_option('wppocket_entry_building'); 253 358 … … 258 363 $wppocket_entry_building = str_replace('%%url%%', $url, $wppocket_entry_building); 259 364 $wppocket_entry_building = str_replace('%%tags%%', $tags, $wppocket_entry_building); 365 $wppocket_entry_building = str_replace('%%author%%', $author, $wppocket_entry_building); 366 $wppocket_entry_building = str_replace('%%countwords%%', $countwords, $wppocket_entry_building); 260 367 } 261 368 … … 267 374 } 268 375 376 // Function to replace variables in the title of the post 269 377 function getReplacedTitle($countLinks, $replace = true) { 270 378 $wppocket_title = get_option('wppocket_title'); … … 272 380 // Set the variables, if should do this 273 381 if ($replace) { 274 $wppocket_title = str_replace('%%day%%', date('l'), $wppocket_title);275 $wppocket_title = str_replace('%%month%%', date('F'), $wppocket_title);382 $wppocket_title = str_replace('%%day%%', $this->getReplaceLanguageDependentStrings(date('l')), $wppocket_title); 383 $wppocket_title = str_replace('%%month%%', $this->getReplaceLanguageDependentStrings(date('F')), $wppocket_title); 276 384 $wppocket_title = str_replace('%%year%%', date('Y'), $wppocket_title); 277 385 $wppocket_title = str_replace('%%count%%', $countLinks, $wppocket_title); … … 281 389 } 282 390 283 function getReplacedIntroductionText($replace = true) { 391 // Function to replace variables in the introduction text 392 function getReplacedIntroductionText($countLinks, $replace = true) { 284 393 $wppocket_introduction_text = get_option('wppocket_introduction_text'); 285 394 286 395 // Set the variables, if should do this 287 396 if ($replace) { 288 $wppocket_introduction_text = str_replace('%%day%%', date('l'), $wppocket_introduction_text);289 $wppocket_introduction_text = str_replace('%%month%%', date('F'), $wppocket_introduction_text);397 $wppocket_introduction_text = str_replace('%%day%%', $this->getReplaceLanguageDependentStrings(date('l')), $wppocket_introduction_text); 398 $wppocket_introduction_text = str_replace('%%month%%', $this->getReplaceLanguageDependentStrings(date('F')), $wppocket_introduction_text); 290 399 $wppocket_introduction_text = str_replace('%%year%%', date('Y'), $wppocket_introduction_text); 400 $wppocket_introduction_text = str_replace('%%count%%', $countLinks, $wppocket_introduction_text); 291 401 } 292 402 … … 294 404 } 295 405 296 function getReplacedStatementsText($replace = true) { 406 // Function to replace variables in the statements text 407 function getReplacedStatementsText($countLinks, $replace = true) { 297 408 $wppocket_statements_text = get_option('wppocket_statements_text'); 298 409 299 410 // Set the variables, if should do this 300 411 if ($replace) { 301 $wppocket_statements_text = str_replace('%%day%%', date('l'), $wppocket_statements_text); 302 $wppocket_statements_text = str_replace('%%month%%', date('F'), $wppocket_statements_text); 303 $wppocket_statements_text = str_replace('%%year%%', date('Y'), $wppocket_statements_text); 412 $wppocket_statements_text = str_replace('%%day%%', $this->getReplaceLanguageDependentStrings(date('l')), $wppocket_statements_text); 413 $wppocket_statements_text = str_replace('%%month%%', $this->getReplaceLanguageDependentStrings(date('F')), $wppocket_statements_text); 414 $wppocket_statements_text = str_replace('%%year%%', date('Y'), $wppocket_statements_text); 415 $wppocket_statements_text = str_replace('%%count%%', $countLinks, $wppocket_statements_text); 304 416 } 305 417 … … 307 419 } 308 420 421 // Function to replace language-dependent strings 422 function getReplaceLanguageDependentStrings($string) { 423 // Check with language is selected 424 if (get_option('wppocket_language') == 'de') { // German 425 // Return replaced strings 426 switch($string) { 427 case ('January'): 428 return 'Januar'; 429 break; 430 case ('February'): 431 return 'Februar'; 432 break; 433 case ('March'): 434 return 'März'; 435 break; 436 case ('April'): 437 return 'April'; 438 break; 439 case ('May'): 440 return 'Mai'; 441 break; 442 case ('June'): 443 return 'Juni'; 444 break; 445 case ('July'): 446 return 'July'; 447 break; 448 case ('August'): 449 return 'August'; 450 break; 451 case ('September'): 452 return 'Steptember'; 453 break; 454 case ('October'): 455 return 'Oktober'; 456 break; 457 case ('November'): 458 return 'November'; 459 break; 460 case ('December'): 461 return 'Dezember'; 462 break; 463 464 case ('Monday'): 465 return 'Montag'; 466 break; 467 case ('Tuesday'): 468 return 'Dienstag'; 469 break; 470 case ('Wednesday'): 471 return 'Mittwoch'; 472 break; 473 case ('Thursday'): 474 return 'Donnerstag'; 475 break; 476 case ('Friday'): 477 return 'Freitag'; 478 break; 479 case ('Saturday'): 480 return 'Samstag'; 481 break; 482 case ('Sunday'): 483 return 'Sonntag'; 484 break; 485 } 486 }else if (get_option('wppocket_language') == 'fr') { // French 487 // Return replaced strings 488 switch($string) { 489 case ('January'): 490 return 'janvier'; 491 break; 492 case ('February'): 493 return 'février'; 494 break; 495 case ('March'): 496 return 'mars'; 497 break; 498 case ('April'): 499 return 'avril'; 500 break; 501 case ('May'): 502 return 'mai'; 503 break; 504 case ('June'): 505 return 'juin'; 506 break; 507 case ('July'): 508 return 'juillet'; 509 break; 510 case ('August'): 511 return 'août'; 512 break; 513 case ('September'): 514 return 'septembre'; 515 break; 516 case ('October'): 517 return 'octobre'; 518 break; 519 case ('November'): 520 return 'novembre'; 521 break; 522 case ('December'): 523 return 'décembre'; 524 break; 525 526 case ('Monday'): 527 return 'lundi'; 528 break; 529 case ('Tuesday'): 530 return 'mardi'; 531 break; 532 case ('Wednesday'): 533 return 'mercredi'; 534 break; 535 case ('Thursday'): 536 return 'jeudi'; 537 break; 538 case ('Friday'): 539 return 'vendredi'; 540 break; 541 case ('Saturday'): 542 return 'samedi'; 543 break; 544 case ('Sunday'): 545 return 'dimanche'; 546 break; 547 } 548 }else { // English by default 549 // Return replaced strings 550 switch($string) { 551 case ('January'): 552 return 'January'; 553 break; 554 case ('February'): 555 return 'February'; 556 break; 557 case ('March'): 558 return 'March'; 559 break; 560 case ('April'): 561 return 'April'; 562 break; 563 case ('May'): 564 return 'May'; 565 break; 566 case ('June'): 567 return 'June'; 568 break; 569 case ('July'): 570 return 'July'; 571 break; 572 case ('August'): 573 return 'August'; 574 break; 575 case ('September'): 576 return 'September'; 577 break; 578 case ('October'): 579 return 'October'; 580 break; 581 case ('November'): 582 return 'November'; 583 break; 584 case ('December'): 585 return 'December'; 586 break; 587 588 case ('Monday'): 589 return 'Monday'; 590 break; 591 case ('Tuesday'): 592 return 'Tuesday'; 593 break; 594 case ('Wednesday'): 595 return 'Wednesday'; 596 break; 597 case ('Thursday'): 598 return 'Thursday'; 599 break; 600 case ('Friday'): 601 return 'Friday'; 602 break; 603 case ('Saturday'): 604 return 'Saturday'; 605 break; 606 case ('Sunday'): 607 return 'Sunday'; 608 break; 609 } 610 } 611 } 612 613 // Function to check if the plugin have access to a Pocket account 309 614 function checkPocketAccess() { 310 // Check if username, password and api-key is set, if not, print error311 if (get_option('wppocket_pocket_username') == '' || get_option('wppocket_pocket_ password') == '' || get_option('wppocket_pocket_api_key') == '') {615 // Check if username, password and consumer-key is set, if not, print error 616 if (get_option('wppocket_pocket_username') == '' || get_option('wppocket_pocket_access_key') == '' || get_option('wppocket_pocket_consumer_key') == '') { 312 617 ?> 313 618 <div id="message" class="error"> 314 <p><strong>WP Pocket can NOT work. Please save your Pocket username, password and API-Key (optional)!</strong></p>619 <p><strong>WP Pocket can NOT work. Please authenticate your Pocket account in the WP Pocket options!</strong></p> 315 620 </div> 316 621 <?php … … 318 623 }else { // Test the settings 319 624 // Init cURL 320 $getAuth = $this->cURL('https://readitlaterlist.com/v2/auth?username=' . $this->xcrypt(1, get_option('wppocket_pocket_username')) . '&password=' . $this->xcrypt(1, get_option('wppocket_pocket_password')) . '&apikey=' . $this->xcrypt(1, get_option('wppocket_pocket_api_key'))); 321 322 // Check if, user data ad api key correct 625 $getAuth = $this->cURL( 626 'https://getpocket.com/v3/send', 627 array( 628 'consumer_key' => $this->xcrypt(1, get_option('wppocket_pocket_consumer_key')), 629 'access_token' => $this->xcrypt(1, get_option('wppocket_pocket_access_key')), 630 'actions' => '[{}]' 631 ) 632 ); 633 634 // Check if, user data and consumer-key correct 323 635 if ($getAuth == '400 Bad Request') { 324 636 ?> 325 637 <div id="message" class="error"> 326 <p><strong>Your API-Key it not valid. Please correct it, else WP Pocket can NOT work.</strong></p>638 <p><strong>Your Consumer-Key it not valid. Please correct it, else WP Pocket can NOT work.</strong></p> 327 639 </div> 328 640 <?php … … 331 643 ?> 332 644 <div id="message" class="error"> 333 <p><strong> Your Pocket username and/or password it not valid. Please correct that, else WP Pocket can NOT work.</strong></p>645 <p><strong>The authentication of you Pocket account is expired. Please reauthenticate it, else WP Pocket can NOT work.</strong></p> 334 646 </div> 335 647 <?php … … 341 653 } 342 654 655 // Support box on the right side of each WP Pocket page 343 656 function support_div($display = true) { 344 657 ?> … … 346 659 <h3>support me</h3> 347 660 348 <p>If you use the plugin and like it, you can say thanks and support me. </p>661 <p>If you use the plugin and like it, you can say thanks and support me. How?</p> 349 662 350 663 <h3>follow me on twitter</h3> 351 664 352 665 <p> 353 <a href="https://twitter.com/jankarres" class="twitter-follow-button" data-show-count="false" data- lang="en" data-size="large">Follow @jankarres</a>666 <a href="https://twitter.com/jankarres" class="twitter-follow-button" data-show-count="false" data-size="large" data-dnt="true">Follow @jankarres</a> 354 667 <script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="https://plugins.trac.wordpress.org//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script> 355 668 </p> 356 669 357 <h3> donate on flattr</h3>358 359 < a href="http://flattr.com/thing/881252/WP-Pocket" target="_blank">360 <img src="http://api.flattr.com/button/flattr-badge-large.png" alt="Flattr this" title="Flattr this" border="0" />361 </ a>670 <h3>report bugs</h3> 671 672 <p> 673 You found a bug? You have an idea for a feature? Then let me know and send a request on <a href="http://wp-pocket.com/" target="_blank">WP-Pocket.com</a>! 674 </p> 362 675 </div> 363 676 <?php 364 677 } 365 678 679 // Function to set options page 366 680 function options_link() { 367 681 // Start the view of the options page … … 372 686 } 373 687 688 // Options page view 374 689 function options_page_view() { 375 690 // Add option page style … … 388 703 <?php $this->support_div(); ?> 389 704 390 <form method="post" action="<?php echo $_SERVER['REQUEST_URI']; ?>">391 705 <h3>Pocket Login</h3> 392 706 <table class="form-table"> 393 707 <tr> 394 <th>Pocket Username</th>708 <th>Pocket Auth</th> 395 709 <td> 396 <input type="text" size="57" name="wppocket_pocket_username" value="<?php if (get_option('wppocket_pocket_username') != '') { echo $this->xcrypt(1, get_option('wppocket_pocket_username')); } ?>" /> 710 <?php if (get_option('wppocket_pocket_username') != '') { echo $this->xcrypt(1, get_option('wppocket_pocket_username')) . ' authenticated.'; } ?> 711 <?php if (get_option('wppocket_pocket_username') == '') { echo '<a href="?page=settings_pocket_poster&auth-get"><input type="button" class="button-primary" value="Authenticate account" /></a>'; }else { echo '<a href="?page=settings_pocket_poster&auth-get"><input type="button" class="button-primary" value="Authenticate other account" /></a>'; } ?> 712 </td> 713 </tr> 714 715 <form method="post" action="<?php echo $_SERVER['REQUEST_URI']; ?>"> 716 717 <tr> 718 <th>Pocket Consumer-Key</th> 719 <td> 720 <input type="text" size="57" name="wppocket_pocket_consumer_key" value="<?php if(get_option('wppocket_pocket_consumer_key_custom') == 1) { echo $this->xcrypt(1, get_option('wppocket_pocket_consumer_key')); } ?>" /> 721 722 <?php if(get_option('wppocket_pocket_consumer_key_custom') == 1) { ?> 723 <label><input name="wppocket_pocket_consumer_key_custom_remove" type="checkbox" value="1" /> Use the default Consumer-Key</label> 724 <?php } ?> 725 726 <p class="description">If you wish to use a private Consumer-Key, please enter one. <strong>It is not necessary!</strong><br /> 727 You can get one on <a href="http://getpocket.com/developer/apps/new" target="_blank">http://getpocket.com/developer/apps/new</a>.</p> 728 </td> 729 </tr> 730 </table> 731 732 <h3>WP Pocket Settings</h3> 733 <table class="form-table"> 734 <tr> 735 <th>Language</th> 736 <td> 737 <select name="wppocket_language"> 738 <option value="en" <?php selected('en', get_option('wppocket_language')); ?>>English</option> 739 <option value="de" <?php selected('de', get_option('wppocket_language')); ?>>German</option> 740 <option value="fr" <?php selected('fr', get_option('wppocket_language')); ?>>French</option> 741 </select> 742 <p class="description">A few variables you can set are language-dependent. Which language should WP Pocket use? <strong>This setting does not change the language of complete WP Pocket (currently only English supported)!</strong></p> 397 743 </td> 398 744 </tr> 399 745 <tr> 400 <th> Pocket Password</th>746 <th>Statistics</th> 401 747 <td> 402 <input type="password" size="57" name="wppocket_pocket_password" value="" /> 403 <p class="description">If you do not wish to edit something, leave it blank.</p> 404 </td> 405 </tr> 406 <tr> 407 <th>Pocket API-Key</th> 408 <td> 409 <input type="text" size="57" name="wppocket_pocket_api_key" value="<?php if(get_option('wppocket_pocket_api_key_custom') == 1) { echo $this->xcrypt(1, get_option('wppocket_pocket_api_key')); } ?>" /> 410 411 <?php if(get_option('wppocket_pocket_api_key_custom') == 1) { ?> 412 <label><input name="wppocket_pocket_api_key_custom_remove" type="checkbox" value="1" /> Use the default API-Key</label> 413 <?php } ?> 414 415 <p class="description">If you wish to use a private API-Key, please enter one. <strong>It is not necessary!</strong><br /> 416 You can get one on <a href="http://getpocket.com/api/signup/" target="_blank">http://getpocket.com/api/signup/</a>.</p> 748 <select name="wppocket_statistics"> 749 <option value="1" <?php selected('1', get_option('wppocket_statistics')); ?>>Yes</option> 750 <option value="0" <?php selected('0', get_option('wppocket_statistics')); ?>>No</option> 751 </select> 752 <p class="description">Do you allow WP Pocket to collect anonymous statistics about published links and updates and send them to WP-Pocket.com? These statistics will only be used to improve WP Pocket.</p> 417 753 </td> 418 754 </tr> … … 426 762 <select name="wppocket_links_to_use"> 427 763 <option value="0" <?php selected('0', get_option('wppocket_links_to_use')); ?>>Only unread links, which are unposted</option> 428 <option value="1" <?php selected('1', get_option('wppocket_links_to_use')); ?>>Only read links, which are unposted</option>429 <option value="2" <?php selected('2', get_option('wppocket_links_to_use')); ?> >All links, which are unposted</option>764 <option value="1" <?php selected('1', get_option('wppocket_links_to_use')); ?>>Only read/archived links, which are unposted</option> 765 <option value="2" <?php selected('2', get_option('wppocket_links_to_use')); ?> disabled><s>All links, which are unposted</s> (Currently impossible due to a bug in Pocket API)</option> 430 766 <option value="3" <?php selected('3', get_option('wppocket_links_to_use')); ?>>All unread links, also already posted ones</option> 431 <option value="4" <?php selected('4', get_option('wppocket_links_to_use')); ?>>All read links, also already posted ones</option>432 <option value="5" <?php selected('5', get_option('wppocket_links_to_use')); ?> >All links, also already posted ones</option>767 <option value="4" <?php selected('4', get_option('wppocket_links_to_use')); ?>>All read/archived links, also already posted ones</option> 768 <option value="5" <?php selected('5', get_option('wppocket_links_to_use')); ?> disabled><s>All links, also already posted ones</s> (Currently impossible due to a bug in Pocket API)</option> 433 769 </select> 434 770 <p class="description">Which links should be used for the new post?</p> 771 </td> 772 </tr> 773 <tr> 774 <th>Favorites</th> 775 <td> 776 <select name="wppocket_faved"> 777 <option value="0" <?php selected('0', get_option('wppocket_faved')); ?>>All links</option> 778 <option value="1" <?php selected('1', get_option('wppocket_faved')); ?>>Only faved links</option> 779 <option value="2" <?php selected('2', get_option('wppocket_faved')); ?>>Only unfaved links</option> 780 </select> 781 <p class="description">Should only faved or unfaved links be used in a new post?</p> 435 782 </td> 436 783 </tr> … … 446 793 </tr> 447 794 <tr> 448 <th>Mark as readed </th>795 <th>Mark as readed/archived</th> 449 796 <td> 450 797 <select name="wppocket_mark_as_readed"> … … 565 912 write the text and the variable in double square brackets. For example: %%title%%[[ - Tags: %%tags%%]]<br /> 566 913 <strong>Use <i>%%title%%</i> for title of the link in pocket; <i>%%description%%</i> for the meta description of the link; 567 <i>%%url%%</i> for the link itself; <i>%%tags%%</i> for added tags in pocket.</strong> 914 <i>%%url%%</i> for the link itself; <i>%%tags%%</i> for added tags in pocket/metatags; <i>%%author%%</i> for the name 915 of the author who wrote the article; <i>%%countwords%%</i> for the number of words, which the article has</strong> 568 916 </p> 569 917 </td> … … 581 929 <p class="description"> 582 930 At the beginning of the post, before the links, this text will be shown.<br /> 583 <strong>Use <i>%%day%%</i> for day, on which the post is being generated; <i>%%month%%</i> for the month; <i>%%year%%</i> for the year .</strong>931 <strong>Use <i>%%day%%</i> for day, on which the post is being generated; <i>%%month%%</i> for the month; <i>%%year%%</i> for the year; %%count%% to get the number of posted links.</strong> 584 932 </p> 585 933 </td> … … 597 945 <p class="description"> 598 946 At the end of the post, after the links, this text will be shown.<br /> 599 <strong>Use <i>%%day%%</i> for day, on which the post is being generated; <i>%%month%%</i> for the month; <i>%%year%%</i> for the year .</strong>947 <strong>Use <i>%%day%%</i> for day, on which the post is being generated; <i>%%month%%</i> for the month; <i>%%year%%</i> for the year; %%count%% to get the number of posted links.</strong> 600 948 </p> 601 949 </td> … … 613 961 } 614 962 963 // Options page controller 615 964 function options_page_controller() { 965 // Check if should start Pocket auth process 966 if (isset($_GET['auth-get'])) { 967 // Start Pocket auth process 968 $this->authPocketAccountGetRequest(); 969 } 970 971 // Check if should save Pocket access token 972 if (isset($_GET['auth'])) { 973 // Save Pocket access token 974 $this->authPocketAccountSaveAccessToken(); 975 } 976 977 // Check if Pocket account auth saved successfull 978 if (isset($_GET['auth-success'])) { 979 // Print, the auth succeed 980 echo '<div id="message" class="updated">'; 981 echo '<p><strong>You have successfully authenticated your Pocket Account!</strong></p>'; 982 echo '</div>'; 983 } 984 616 985 // Check if setting sended 617 986 if ($_POST['wppocket_edit']) { … … 621 990 // Error Text Array 622 991 $errorLang = array( 623 '0' => 'Please enter your Pocket username.', 624 '1' => 'Please enter your Pocket password.', 625 '2' => 'Please enter your Pocket API-Key or reset it to use the default key.', 626 '3' => 'Please enter a title for the posts.', 627 '4' => 'Please enter a building for each link which will be posted.' 992 '1' => 'Please enter your Pocket Consumer-Key or reset it to use the default key (recommend).', 993 '2' => 'Please enter a title for the posts.', 994 '3' => 'Please enter a building for each link which will be posted.' 628 995 ); 629 996 630 997 // Update "Pocket Login" 631 998 632 // Check if Pocket username is isset 633 if ($_POST['wppocket_pocket_username'] == '') { 634 $error[] = 0; 635 }else { 636 update_option('wppocket_pocket_username', $this->xcrypt(0, $_POST['wppocket_pocket_username'])); 637 } 638 639 // Check if Pocket one password is isset 640 if (get_option('wppocket_pocket_password') == '' && $_POST['wppocket_pocket_password'] == '') { 999 if ($_POST['wppocket_pocket_consumer_key_custom_remove'] == 1) { 1000 // Set default key 1001 update_option('wppocket_pocket_consumer_key_custom', 0); 1002 update_option('wppocket_pocket_consumer_key', $this->xcrypt(0, $this->global_pocket_consumer_key)); 1003 1004 // Reset authed Pocket account 1005 update_option('wppocket_pocket_access_key', ''); 1006 update_option('wppocket_pocket_username', ''); 1007 $changeConsumerKey = true; 1008 }elseif(get_option('wppocket_pocket_consumer_key_custom') == 1 && $_POST['wppocket_pocket_consumer_key'] == '') { 641 1009 $error[] = 1; 642 }elseif ($_POST['wppocket_pocket_password'] != '') { 643 update_option('wppocket_pocket_password', $this->xcrypt(0, $_POST['wppocket_pocket_password'])); 644 } 645 646 if ($_POST['wppocket_pocket_api_key_custom_remove'] == 1) { 647 // Set default key 648 update_option('wppocket_pocket_api_key_custom', 0); 649 update_option('wppocket_pocket_api_key', $this->xcrypt(0, $this->global_pocket_api_key)); 650 }elseif(get_option('wppocket_pocket_api_key_custom') == 1 && $_POST['wppocket_pocket_api_key'] == '') { 651 $error[] = 2; 652 }elseif(get_option('wppocket_pocket_api_key_custom') == 1 && $_POST['wppocket_pocket_api_key'] != '') { 1010 }elseif(get_option('wppocket_pocket_consumer_key_custom') == 1 && $_POST['wppocket_pocket_consumer_key'] != '') { 653 1011 // Set new key 654 update_option('wppocket_pocket_api_key', $this->xcrypt(0, $_POST['wppocket_pocket_api_key'])); 655 }elseif (get_option('wppocket_pocket_api_key_custom') == 0 && $_POST['wppocket_pocket_api_key'] != '') { 656 // Set custom API-Key first time 657 update_option('wppocket_pocket_api_key_custom', 1); 658 update_option('wppocket_pocket_api_key', $this->xcrypt(0, $_POST['wppocket_pocket_api_key'])); 1012 update_option('wppocket_pocket_consumer_key', $this->xcrypt(0, $_POST['wppocket_pocket_consumer_key'])); 1013 1014 // Reset authed Pocket account 1015 update_option('wppocket_pocket_access_key', ''); 1016 update_option('wppocket_pocket_username', ''); 1017 $changeConsumerKey = true; 1018 }elseif (get_option('wppocket_pocket_consumer_key_custom') == 0 && $_POST['wppocket_pocket_consumer_key'] != '') { 1019 // Set custom Consumer-Key first time 1020 update_option('wppocket_pocket_consumer_key_custom', 1); 1021 update_option('wppocket_pocket_consumer_key', $this->xcrypt(0, $_POST['wppocket_pocket_consumer_key'])); 1022 1023 // Reset authed Pocket account 1024 update_option('wppocket_pocket_access_key', ''); 1025 update_option('wppocket_pocket_username', ''); 1026 $changeConsumerKey = true; 659 1027 } 660 1028 … … 665 1033 666 1034 update_option('wppocket_links_to_use', $_POST['wppocket_links_to_use']); 1035 update_option('wppocket_faved', $_POST['wppocket_faved']); 667 1036 update_option('wppocket_order', $_POST['wppocket_order']); 668 1037 update_option('wppocket_mark_as_readed', $_POST['wppocket_mark_as_readed']); … … 715 1084 // Check if title is not set 716 1085 if ($_POST['wppocket_title'] == '') { 717 $error[] = 3;1086 $error[] = 2; 718 1087 }else { 719 1088 update_option('wppocket_title', $_POST['wppocket_title']); … … 722 1091 // Chech if entry building is not set 723 1092 if ($_POST['wppocket_entry_building'] == '') { 724 $error[] = 4;1093 $error[] = 3; 725 1094 }else { 726 1095 update_option('wppocket_entry_building', $_POST['wppocket_entry_building']); … … 730 1099 update_option('wppocket_introduction_text', $_POST['wppocket_introduction_text']); 731 1100 update_option('wppocket_statements_text', $_POST['wppocket_statements_text']); 1101 1102 // WP Pocket settings 1103 update_option('wppocket_language', $_POST['wppocket_language']); 1104 update_option('wppocket_statistics', $_POST['wppocket_statistics']); 732 1105 733 1106 // Output all errors … … 750 1123 <?php 751 1124 } 1125 1126 // Check if Consumer-Key was changed. If yes, azth was reseted. 1127 if ($changeConsumerKey) { 1128 ?> 1129 <div id="message" class="updated"> 1130 <p><strong>You changed the Consumer-Key. Because of, the authentication of your WP Pocket account was removed. Please reauthenticate!</strong></p> 1131 </div> 1132 <?php 1133 } 752 1134 } 753 1135 … … 756 1138 } 757 1139 1140 // Function to set the main page 758 1141 function main_link() { 759 1142 // Start the view of the main page … … 761 1144 } 762 1145 1146 // Main page view 763 1147 function main_page_view() { 764 1148 // Add option page style … … 781 1165 <div class="nav-tabs-arrow nav-tabs-arrow-left" style="display: none; "><a>«</a></div> 782 1166 <div class="nav-tabs-wrapper"> 783 <div class="nav-tabs" style="padding: 0px; margin-right: -110px; margin-left: 0px; ">1167 <div class="nav-tabs"> 784 1168 <span class="nav-tab nav-tab-active"></span><a href="#" class="nav-tab menu-add-new"></a> 785 1169 </div> … … 804 1188 if ($checkPocketAccess) { 805 1189 // Get links from the user 806 807 // Should get Readed, onreaded or all links? 1190 $getLinksPost = array(); 1191 1192 $getLinksPost['consumer_key'] = $this->xcrypt(1, get_option('wppocket_pocket_consumer_key')); 1193 $getLinksPost['access_token'] = $this->xcrypt(1, get_option('wppocket_pocket_access_key')); 1194 $getLinksPost['detailType'] = 'complete'; 1195 1196 // Should get Readed, unreaded or all links? 808 1197 if (get_option('wppocket_links_to_use') == 0 || get_option('wppocket_links_to_use') == 3) { // Unreaded 809 $ state = '&state=unread';810 }elseif (get_option('wppocket_links_to_use') == 1 || get_option('wppocket_links_to_use') == 4) { // Readed 811 $ state = '&state=read';1198 $getLinksPost['state'] = 'unread'; 1199 }elseif (get_option('wppocket_links_to_use') == 1 || get_option('wppocket_links_to_use') == 4) { // Readed / Archived 1200 $getLinksPost['state'] = 'archive'; 812 1201 } // All 813 1202 814 $getLinks = $this->cURL('https://readitlaterlist.com/v2/get?username=' . $this->xcrypt(1, get_option('wppocket_pocket_username')) . '&password=' . $this->xcrypt(1, get_option('wppocket_pocket_password')) . '&apikey=' . $this->xcrypt(1, get_option('wppocket_pocket_api_key')) . $state . '&tags=1', 30); 1203 // Check if only faved or unfaved links should use 1204 if (get_option('wppocket_faved') == 1) { // only faved 1205 $getLinksPost['favorite'] = '1'; 1206 }else if (get_option('wppocket_faved') == 2) { // only unfaved 1207 $getLinksPost['favorite'] = '0'; 1208 } // All 1209 1210 // Check if order should be oldest to newest or newest to oldest 1211 if (get_option('wppocket_order')) { // oldest to newest 1212 $getLinksPost['sort'] = 'oldest'; 1213 }else { // newest to oldest 1214 $getLinksPost['sort'] = 'newest'; 1215 } 1216 1217 $getLinks = $this->cURL( 1218 'https://getpocket.com/v3/get', 1219 $getLinksPost 1220 ); 815 1221 816 1222 // Decode JSON to Object … … 822 1228 foreach ($getLinks->list as $key => $value) { 823 1229 // Check if aleady posted. If true, remove it 824 $sql = 'SELECT `id` FROM `' . $this->wpdb->prefix . 'wppocket_posted_links` WHERE `url`="' . $value-> url . '"';1230 $sql = 'SELECT `id` FROM `' . $this->wpdb->prefix . 'wppocket_posted_links` WHERE `url`="' . $value->given_url . '"'; 825 1231 $row = $this->wpdb->get_results($sql); 826 1232 … … 829 1235 } 830 1236 } 831 }832 833 // Check if order should be oldest to newest834 if (get_option('wppocket_order')) {835 // Turn around the json object836 $tmp = json_encode($getLinks, true);837 $tmp = json_decode($tmp, true);838 $tmp['list'] = array_reverse($tmp['list']);839 $tmp = json_encode($tmp, true);840 $tmp = json_decode($tmp);841 $getLinks = $tmp;842 1237 } 843 1238 … … 864 1259 <?php 865 1260 // Gennerate output of each link 866 foreach ($getLinks->list as $key => $value) { 867 // Get description 868 $urlHtml = $this->cURL($value->url); 869 870 $doc = new DOMDocument(); 871 @$doc->loadHTML($urlHtml); 872 873 if ($value->title == '') { 874 $nodes = $doc->getElementsByTagName('title'); 875 $value->title = utf8_decode($nodes->item(0)->nodeValue); 1261 foreach ($getLinks->list as $key => $value) { 1262 // Rewirte Tags Array as Tags string 1263 if (count($value->tags) != 0) { 1264 $tagsAsString = ''; 1265 $i2 = 0; 1266 foreach ($value->tags as $tag) { 1267 if ($i2 != 0) { 1268 $tagsAsString .= ', '; 1269 } 1270 1271 $tagsAsString .= $tag->tag; 1272 1273 $i2++; 1274 } 876 1275 877 if (!$this->is_utf8($value->title)) { 878 $value->title = utf8_encode($value->title); 879 } 1276 $value->tags = $tagsAsString; 1277 unset($tagsAsString); 1278 }else { // Not tags yet 1279 $value->tags = ''; 880 1280 } 881 1281 882 $metas = $doc->getElementsByTagName('meta'); 883 884 for ($i = 0; $i < $metas->length; $i++) { 885 $meta = $metas->item($i); 1282 // Get data from the meta tags, if necessary 1283 if ($value->resolved_title == '' || $value->excerpt == '' || (get_option('wppocket_meta_keyword_as_tags') == 1 && $value->tags == '')) { 1284 $urlHtml = $this->cURL($value->given_url, array()); 886 1285 887 if($meta->getAttribute('name') == 'description') { 888 $value->description = utf8_decode($meta->getAttribute('content')); 889 if (!$this->is_utf8($value->description)) { 890 $value->description = utf8_encode($value->description); 1286 $doc = new DOMDocument(); 1287 @$doc->loadHTML($urlHtml); 1288 1289 if ($value->resolved_title == '') { 1290 $nodes = $doc->getElementsByTagName('title'); 1291 $value->title = utf8_decode($nodes->item(0)->nodeValue); 1292 1293 if (!$this->is_utf8($value->title)) { 1294 $value->title = utf8_encode($value->title); 891 1295 } 892 1296 } 893 1297 894 if (get_option('wppocket_meta_keyword_as_tags') == 1) { 895 if ($meta->getAttribute('name') == 'keywords') { 896 $value->tags = utf8_decode($meta->getAttribute('content')); 897 if (!$this->is_utf8($value->tags)) { 898 $value->tags = utf8_encode($value->tags); 1298 $metas = $doc->getElementsByTagName('meta'); 1299 1300 for ($i = 0; $i < $metas->length; $i++) { 1301 $meta = $metas->item($i); 1302 1303 if ($value->excerpt == '') { 1304 if($meta->getAttribute('name') == 'description') { 1305 $value->excerpt = utf8_decode($meta->getAttribute('content')); 1306 if (!$this->is_utf8($value->excerpt)) { 1307 $value->excerpt = utf8_encode($value->excerpt); 1308 } 1309 } 1310 } 1311 1312 if (get_option('wppocket_meta_keyword_as_tags') == 1 && $value->tags == '') { 1313 if ($meta->getAttribute('name') == 'keywords') { 1314 $value->tags = utf8_decode($meta->getAttribute('content')); 1315 if (!$this->is_utf8($value->tags)) { 1316 $value->tags = utf8_encode($value->tags); 1317 } 899 1318 } 900 1319 } … … 906 1325 <dt class="menu-item-handle"> 907 1326 <div class="left"> 908 <?php echo $value-> title; ?>1327 <?php echo $value->resolved_title; ?> 909 1328 </div> 910 1329 <div class="right"> … … 916 1335 917 1336 <div class="menu-item-settings" id="item-<?php echo $key; ?>"> 918 <p class="description description-thin ">1337 <p class="description description-thin description-two-thirds"> 919 1338 <label for="item-<?php echo $key; ?>-input-title"> 920 1339 Title<br /> 921 <input type="text" id="item-<?php echo $key; ?>-input-title" class="widefat input-title" name="element[][title]" value="<?php echo $value-> title; ?>" />1340 <input type="text" id="item-<?php echo $key; ?>-input-title" class="widefat input-title" name="element[][title]" value="<?php echo $value->resolved_title; ?>" /> 922 1341 </label> 923 1342 </p> 924 <p class="description description-thin"> 1343 <p class="description description-thin description-one-thirds"> 1344 <label for="item-<?php echo $key; ?>-input-author"> 1345 Author<br /> 1346 <input type="text" id="item-<?php echo $key; ?>-input-author" class="widefat input-title" name="element[][author]" value="<?php 1347 if (count($value->authors) != 0) { 1348 $i2 = 0; 1349 foreach($value->authors as $author) { 1350 if ($i2 != 0) { 1351 echo ', '; 1352 } 1353 1354 echo $author->name; 1355 1356 $i2++; 1357 } 1358 } 1359 ?>" /> 1360 </label> 1361 </p> 1362 <p class="description description-thin description-two-thirds"> 1363 <label for="item-<?php echo $key; ?>-input-url"> 1364 URL<br /> 1365 <input type="text" id="item-<?php echo $key; ?>-input-url" class="widefat" name="element[][url]" value="<?php if (get_option('wppocket_clean_url') == 1) { echo $this->cleanUpURL($value->resolved_url); }else { echo $value->given_url; } ?>" /> 1366 <input type="hidden" id="item-<?php echo $key; ?>-input-url" class="widefat" name="element[][url_uncleaned]" value="<?php echo $value->given_url; ?>" /> 1367 </label> 1368 </p> 1369 <p class="description description-thin description-one-thirds"> 925 1370 <label for="item-<?php echo $key; ?>-input-tags"> 926 Tags (optional)<br />1371 Tags<br /> 927 1372 <input type="text" id="item-<?php echo $key; ?>-input-tags" class="widefat" name="element[][tags]" value="<?php echo $value->tags; ?>" /> 928 1373 </label> … … 931 1376 <label for="item-<?php echo $key; ?>-input-description"> 932 1377 Description (optional)<br /> 933 <textarea name="element[][description]" rows="4" id="item-<?php echo $key; ?>-input-description" class="widefat" type="textarea"><?php echo $value->description; ?></textarea> 934 </label> 935 </p> 936 <p class="description"> 937 <label for="item-<?php echo $key; ?>-input-url"> 938 URL<br /> 939 <input type="text" id="item-<?php echo $key; ?>-input-url" class="widefat" name="element[][url]" value="<?php if (get_option('wppocket_clean_url') == 1) { echo $this->cleanUpURL($value->url); }else { echo $value->url; } ?>" /> 940 <input type="hidden" id="item-<?php echo $key; ?>-input-url" class="widefat" name="element[][url_uncleaned]" value="<?php echo $value->url; ?>" /> 1378 <textarea name="element[][description]" rows="4" id="item-<?php echo $key; ?>-input-description" class="widefat" type="textarea"><?php echo $value->excerpt; ?></textarea> 941 1379 </label> 942 1380 </p> 943 1381 944 <input type="hidden" name="element[][id]" value="<?php echo $key; ?>" /> 1382 1383 <input type="hidden" name="element[][id]" value="<?php echo $value->item_id; ?>" /> 1384 <input type="hidden" name="element[][countwords]" value="<?php echo $value->word_count; ?>" /> 945 1385 <input type="hidden" name="element[][associate]" class="associate" value="0" /> 946 1386 </div> … … 959 1399 } 960 1400 }elseif ($_POST['mode'] == 'save') { // Save post 961 // Check if elements was posted1401 // Check if elements was lposted 962 1402 if ($_POST['count_elements'] == 0) { // No elements 963 1403 ?> … … 999 1439 } 1000 1440 1441 // Options page controller 1001 1442 function main_page_controller() { 1002 1443 global $current_user; … … 1009 1450 1010 1451 // Set en empty example for entry building with replace 1011 $replaceEntryBuilding = $this->replaceEntryBuilding(false, false, false, false );1452 $replaceEntryBuilding = $this->replaceEntryBuilding(false, false, false, false, false, false); 1012 1453 1013 1454 // Set en empty example for entry building without replace 1014 $noReplaceEntryBuilding = $this->replaceEntryBuilding(false, false, false, false, false );1455 $noReplaceEntryBuilding = $this->replaceEntryBuilding(false, false, false, false, false, false, false); 1015 1456 1016 1457 // Check, which Array elements are dynamic. Set empy replace and flag in new array … … 1037 1478 unset($noReplaceEntryBuilding); 1038 1479 1480 ##################################### 1481 ## COMBINE URL, URL CLEANED AND ID ## 1482 ##################################### 1483 1484 $i = 0; 1485 while ($i < (count($_POST['element']) / 9)) { 1486 $url = $_POST['element'][(($i * 9) + 2)]['url']; 1487 $urlUncleaned = $_POST['element'][(($i * 9) + 3)]['url_uncleaned']; 1488 $id = $_POST['element'][(($i * 9) + 6)]['id']; 1489 1490 $_POST['element'][(($i * 9) + 2)] = array( 1491 array( 1492 $url, 1493 $urlUncleaned, 1494 $id 1495 ) 1496 ); 1497 1498 1499 $i++; 1500 } 1501 1039 1502 ######################### 1040 1503 ## SET ASSOCIATE LINKS ## 1041 1504 ######################### 1042 1505 $i = 0; 1043 while ($i < (count($_POST['element']) / 7)) {1506 while ($i < (count($_POST['element']) / 9)) { 1044 1507 // Check if this it not a associate link 1045 if (!$_POST['element'][($i * 7) + 5]['associate']) {1508 if (!$_POST['element'][($i * 9) + 6]['associate']) { 1046 1509 // Search for associate links in the following 1047 1510 $associateLinks = array(); … … 1049 1512 while(true) { 1050 1513 // If this is an associate links, add this to the array, else break the while-loop 1051 if ($_POST['element'][($i * 7) + 6 + ($i2 * 7)]['associate']) { 1052 $_POST['element'][($i * 7) + 3][] = $_POST['element'][(($i * 7) + 3 + ($i2 * 7))]['url']; 1053 $_POST['element'][($i * 7) + 4][] = $_POST['element'][(($i * 7) + 4 + ($i2 * 7))]['url_uncleaned']; 1514 if ($_POST['element'][($i * 9) + 8 + ($i2 * 9)]['associate']) { 1515 $_POST['element'][($i * 9) + 2][] = $_POST['element'][(($i * 9) + 2 + ($i2 * 9))][0]; 1054 1516 }else { 1055 1517 break; … … 1068 1530 1069 1531 // Set posted elements in $_POST for view 1070 $_POST['count_elements'] = round((count($_POST['element']) / 7));1532 $_POST['count_elements'] = round((count($_POST['element']) / 9)); 1071 1533 1072 1534 // Array for all posted links … … 1075 1537 $post_content = ''; 1076 1538 1077 // Set introduction text if not empty 1078 if (trim(get_option('wppocket_introduction_text')) != '') { 1079 $post_content .= $this->getReplacedIntroductionText(); 1080 } 1081 1082 // Gennerate all links intro text 1539 // Gennerate all links in text 1083 1540 $i = 0; 1084 while ($i < (count($_POST['element']) / 7)) {1541 while ($i < (count($_POST['element']) / 9)) { 1085 1542 // Check if only not posted links should post 1086 1543 if (get_option('wppocket_links_to_use') == 0 || get_option('wppocket_links_to_use') == 1 || get_option('wppocket_links_to_use') == 2) { 1087 1544 // Check if aleady posted. If true, confine to the next loop 1088 $sql = 'SELECT `id` FROM `' . $this->wpdb->prefix . 'wppocket_posted_links` WHERE `url`="' . $_POST['element'][($i * 7) + 3]['url'] . '"';1545 $sql = 'SELECT `id` FROM `' . $this->wpdb->prefix . 'wppocket_posted_links` WHERE `url`="' . $_POST['element'][($i * 9) + 2]['url'] . '"'; 1089 1546 $row = $this->wpdb->get_results($sql); 1090 1547 1091 1548 if ($row[0]->id != '') { 1092 $_POST['count_elements'] -= count($_POST['element'][($i * 7) + 3]); // - this and associated elements1549 $_POST['count_elements'] -= count($_POST['element'][($i * 9) + 2]); // - this and associated elements 1093 1550 $i++; 1094 1551 continue; … … 1097 1554 1098 1555 // Check if this it not a associate link 1099 if (!$_POST['element'][($i * 7) + 6]['associate']) {1556 if (!$_POST['element'][($i * 9) + 8]['associate']) { 1100 1557 // Gennerate url array in url string 1101 1558 $url = ''; 1102 1559 1103 1560 $i2 = 0; 1104 foreach ($_POST['element'][($i * 7) + 3] as $value) {1561 foreach ($_POST['element'][($i * 9) + 2] as $value) { 1105 1562 if ($i2 != 0) { 1106 1563 $url .= '; '; 1107 1564 } 1108 1565 1109 $url .= '<a href="' . $value . '" target="_blank">' . $value . '</a>'; 1566 $url .= '<a href="' . $value[0] . '" target="_blank">' . $value[0] . '</a>'; 1567 1568 // Fill array for all posted links 1569 $allPostedLinks[] = $value; 1110 1570 1111 1571 $i2++; 1112 1572 } 1113 1573 1114 // Fill array for all posted links1115 foreach ($_POST['element'][($i * 7) + 4] as $value) {1116 $allPostedLinks[] = $value;1117 }1118 1119 1574 // Set element in entry building 1120 $element = $this->replaceEntryBuilding($_POST['element'][($i * 7)]['title'], $_POST['element'][($i * 7) + 2]['description'], $url, $_POST['element'][($i * 7) + 1]['tags']); 1575 $element = $this->replaceEntryBuilding( 1576 $_POST['element'][($i * 9)]['title'], 1577 $_POST['element'][($i * 9) + 5]['description'], 1578 $url, 1579 $_POST['element'][($i * 9) + 4]['tags'], 1580 $_POST['element'][($i * 9) + 1]['author'], 1581 $_POST['element'][($i * 9) + 7]['countwords'] 1582 ); 1121 1583 1122 1584 // Check if a dynamic element is not in use an delete it … … 1143 1605 } 1144 1606 1607 $post_content_final = ''; 1608 1609 // Set introduction text if not empty 1610 if (trim(get_option('wppocket_introduction_text')) != '') { 1611 $post_content_final .= $this->getReplacedIntroductionText($_POST['count_elements']); 1612 } 1613 1614 // Set links content 1615 $post_content_final .= $post_content; 1616 1145 1617 // Set statements text if not empty 1146 1618 if (trim(get_option('wppocket_statements_text')) != '') { 1147 $post_content .= $this->getReplacedStatementsText();1619 $post_content_final .= $this->getReplacedStatementsText($_POST['count_elements']); 1148 1620 } 1149 1621 1150 1622 // Chech if reference to WP Pocket shot print 1151 1623 if (get_option('wppocket_reference_wppocket')) { 1152 $post_content .= '<p><i>This post was automatically created by WP Pocket. If you look for this WordPress plugin, check out <a href="http://wp-pocket.com/" target="_blank">WP-Pocket.com</a> now!</i></p>';1624 $post_content_final .= '<p><i>This post was automatically created by WP Pocket. If you look for this WordPress plugin, check out <a href="http://wp-pocket.com/" target="_blank">WP-Pocket.com</a> now!</i></p>'; 1153 1625 } 1154 1626 … … 1165 1637 'post_author' => $current_user->ID, 1166 1638 'post_category' => array(get_option('wppocket_post_category')), 1167 'post_content' => $post_content ,1639 'post_content' => $post_content_final, 1168 1640 'post_date' => date('Y-m-d H:i:s'), 1169 1641 'post_date_gmt' => gmdate('Y-m-d H:i:s'), … … 1188 1660 $i = 0; 1189 1661 while ($i < count($allPostedLinks)) { 1190 $sql = 'SELECT `id` FROM `' . $this->wpdb->prefix . 'wppocket_posted_links` WHERE `url`="' . $allPostedLinks[$i] . '"';1662 $sql = 'SELECT `id` FROM `' . $this->wpdb->prefix . 'wppocket_posted_links` WHERE `url`="' . $allPostedLinks[$i][1] . '"'; 1191 1663 $row = $this->wpdb->get_results($sql); 1192 1664 … … 1206 1678 $this->wpdb->prepare( 1207 1679 $sql, 1208 $allPostedLinks[$i] ,1680 $allPostedLinks[$i][1], 1209 1681 $time 1210 1682 ) … … 1222 1694 // Check if link should marke as readed 1223 1695 if (get_option('wppocket_mark_as_readed')) { 1224 // JSON Start 1225 $markAsReaded = '{'; 1226 1227 // Fill JSON 1696 $markAsReaded = array(); 1697 1698 // Fill JSON as Array 1228 1699 $i = 0; 1229 1700 while ($i < count($allPostedLinks)) { 1230 if ($i != 0) { 1231 $markAsReaded .= ','; 1701 $markAsReaded[] = array( 1702 'action' => 'archive', 1703 'item_id' => $allPostedLinks[$i][2] 1704 ); 1705 1706 $i++; 1707 1708 // Chech if limit of links reached. If yes, send request and start new sends array 1709 if (($i / 100) == round($i / 100)) { 1710 // Send request 1711 $this->cURL( 1712 'https://getpocket.com/v3/send', 1713 array( 1714 'consumer_key' => $this->xcrypt(1, get_option('wppocket_pocket_consumer_key')), 1715 'access_token' => $this->xcrypt(1, get_option('wppocket_pocket_access_key')), 1716 'actions' => json_encode($markAsReaded) 1717 ) 1718 ); 1719 1720 // Clean up array 1721 $markAsReaded = array(); 1232 1722 } 1233 1234 $markAsReaded .= '"' . $i . '":{"url":"' . $allPostedLinks[$i] . '"}'; 1723 } 1724 1725 // Send request 1726 $this->cURL( 1727 'https://getpocket.com/v3/send', 1728 array( 1729 'consumer_key' => $this->xcrypt(1, get_option('wppocket_pocket_consumer_key')), 1730 'access_token' => $this->xcrypt(1, get_option('wppocket_pocket_access_key')), 1731 'actions' => json_encode($markAsReaded) 1732 ) 1733 ); 1734 } 1735 1736 // Send statistics, if allowed 1737 if (get_option('wppocket_statistics') == 1) { 1738 $allLinksForStatisics = array(); 1739 $i = 0; 1740 while ($i < count($allPostedLinks)) { 1741 $allLinksForStatisics[] = $allPostedLinks[$i][0]; 1235 1742 1236 1743 $i++; 1237 1744 } 1238 1745 1239 // JSON End 1240 $markAsReaded .= '}'; 1241 1242 // Send request 1243 $responses = $this->cURL('https://readitlaterlist.com/v2/send?username=' . $this->xcrypt(1, get_option('wppocket_pocket_username')) . '&password=' . $this->xcrypt(1, get_option('wppocket_pocket_password')) . '&apikey=' . $this->xcrypt(1, get_option('wppocket_pocket_api_key')) . '&read=' . urlencode($markAsReaded), 10); 1244 } 1245 } 1746 $this->statisticsPublishPost($allLinksForStatisics); 1747 } 1748 } 1749 } 1750 1751 // Statisics send to WP-Pocket.com: Update version 1752 private function statisticsUpdateVersion() { 1753 // Get Data 1754 $url = explode('?', ((empty($_SERVER['HTTPS'])) ? 'http' : 'https') . '://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']); 1755 $url = $url[0]; 1756 $type = 'update'; 1757 $versions = array('from' => get_option('wppocket_version'), 'to' => $this->version); 1758 1759 // Gennerate JSON Array 1760 $data = array( 1761 'url' => $url, 1762 'type' => $type, 1763 'update' => $versions 1764 ); 1765 1766 @$this->cURL( 1767 'http://pluginstats.wp-pocket.com/index.php', 1768 array( 1769 'data' => json_encode($data) 1770 ) 1771 ); 1772 } 1773 1774 // Statisics send to WP-Pocket.com: Publish post 1775 private function statisticsPublishPost($links) { 1776 echo 'HERO!'; 1777 1778 // Get Data 1779 $url = explode('?', ((empty($_SERVER['HTTPS'])) ? 'http' : 'https') . '://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']); 1780 $url = $url[0]; 1781 $type = 'publish'; 1782 1783 // Gennerate JSON Array 1784 $data = array( 1785 'url' => $url, 1786 'type' => $type, 1787 'links' => $links 1788 ); 1789 1790 echo $this->cURL( 1791 'http://pluginstats.wp-pocket.com/index.php', 1792 array( 1793 'data' => json_encode($data) 1794 ) 1795 ); 1246 1796 } 1247 1797 }
Note: See TracChangeset
for help on using the changeset viewer.