Plugin Directory

Changeset 647244


Ignore:
Timestamp:
01/02/2013 10:09:27 PM (13 years ago)
Author:
jankarres
Message:

tagging version 1.2

Location:
wp-pocket
Files:
6 edited
1 copied

Legend:

Unmodified
Added
Removed
  • wp-pocket/tags/1.2/css/main.css

    r598433 r647244  
    1010.wppocket p.description {
    1111    margin: 2px 10px 5px 0;
     12}
     13
     14.wppocket p.description textarea {
     15    resize: vertical;
    1216}
    1317
     
    6266}
    6367
     68.wppocket .description-thin.description-two-thirds {
     69    width: 400px;
     70}
     71
     72.wppocket .description-thin.description-one-thirds {
     73    width: 180px;
     74}
     75
    6476.wppocket .menu-item-settings {
    6577    width: 600px;
  • wp-pocket/tags/1.2/readme.txt

    r618439 r647244  
    44Tags: wp pocket, wordpress, pocket, post, automaticly, wp, links, linklist
    55Requires at least: 3.4
    6 Tested up to: 3.4
    7 Stable tag: 1.1.1
     6Tested up to: 3.5
     7Stable tag: 1.2
    88License: GPLv2 or later
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    5252== Changelog ==
    5353
     54= 1.2 =
     55Rewrite to Pocket API v3 with oAuth
     56Check required PHP version
     57Added names of months in English, German or French language
     58Improved quality of link title and description
     59Implemented function to publish only links, that are marked as favorites in pocket
     60Implemented function to show the author of the article in the linklist
     61More variables possible in entry building, introduction text and statement text
     62Sends, if user allowed it, anonymous statistics to WP-Pocket.com
     63Solved coding problems of titles and descriptions
     64Solved the problem of marking more than 100 links as read
     65Improved performance
     66Improved commenting of the code
     67Other minor bugfixes
     68Removed Flattr button
     69
    5470= 1.1.1 =
    5571Fix link to options in installed plugins overview
     
    8096== ToDo ==
    8197
    82 Nothing. If you have requests, please tell me via the contact form on http://wp-pocket.com
     98Solve all links option in <i>Links to use</i> (possible, if Pocket save the bug in the API)
     99
     100If 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  
    66    Author: Jan Karres
    77    Author URI: http://www.jankarres.de/
    8     Version: 1.1.1
     8    Version: 1.2
    99*/
    10 
    1110if(!class_exists('wppocketer')) {
    1211    class wppocketer {
     
    1413        private $version;
    1514       
    16         // Pocket default API-Key by developer
    17         private $global_pocket_api_key;
     15        // Pocket default Consumer-Key by developer
     16        private $global_pocket_consumer_key;
    1817   
    1918        function __construct() {
     
    2423           
    2524            // Set plugin version
    26             $this->version = '1.1.1';
     25            $this->version = '1.2';
    2726       
    2827            // Check WP version
    29             add_action('init', array(&$this, 'requires_wordpress_version'));
     28            add_action('init', array(&$this, 'requires_versions'));
    3029       
    3130            // Change plugin status hooks
     
    4241            wp_register_script('wppocket_main', plugins_url('js/main.js', __FILE__), array('jquery', 'jquery-ui-core', 'jquery-ui-draggable', 'jquery-ui-droppable'));
    4342           
    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() {
    4949            global $wp_version;
    5050           
     
    5858                    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>.');
    5959                }
     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>.');
    6066            }
    6167           
     
    9096                ("wppocket_version", "' . $this->version . '", "yes"),
    9197                ("wppocket_links_to_use", "0", "yes"),
     98                ("wppocket_faved", "0", "yes"),
    9299                ("wppocket_order", "0", "yes"),
    93100                ("wppocket_mark_as_readed", "0", "yes"),
     
    100107                ("wppocket_post_category", "1", "yes"),
    101108                ("wppocket_pocket_username", "", "yes"),
    102                 ("wppocket_pocket_password", "", "yes"),
     109                ("wppocket_pocket_access_key", "", "yes"),
    103110                ("wppocket_title", "WP Pocket link collection: %%month%% with %%count%% links", "yes"),
    104111                ("wppocket_introduction_text", "", "yes"),
    105112                ("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"),
    107116                ("wppocket_key_a", "' . $this->keygen(128) . '", "yes"),
    108117                ("wppocket_key_b", "' . $this->keygen(128) . '", "yes")
    109118            ';
    110119            $this->wpdb->query($sql);
    111 
     120           
    112121            // 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', '>=')) {
    118123                // Update Pocket username, password and api-key
    119124                update_option('wppocket_pocket_username', $this->xcrypt(0, $this->xcrypt(1, get_option('wppocket_pocket_username'), true)));
     
    122127            }
    123128           
    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
    125141            $sql = '
    126142            INSERT IGNORE INTO `' . $this->wpdb->prefix . 'options` (
     
    129145                `autoload`
    130146            ) 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")
    133149            ';
    134150            $this->wpdb->query($sql);
     
    136152            // Check if plugin version number up to date
    137153            if (get_option('wppocket_version') != $this->version) {
     154                // Send statistics, if allowed
     155                if (get_option('wppocket_statistics') == 1) {
     156                    $this->statisticsUpdateVersion();
     157                }
     158               
    138159                // Update version number
    139160                update_option('wppocket_version', $this->version);
     
    142163
    143164        function deactivate() {
    144             // nothing to do, because user cam reactivate
     165            // nothing to do, because user can reactivate the plugin
    145166        }
    146167       
     
    197218        }
    198219       
    199         private function cURL($url, $timeout = 5) {
     220        // Easy cURL function
     221        private function cURL($url, $post, $timeout = 5) {
    200222            // Init cURL
    201223            $cURL = curl_init();
     224           
     225            // Define HTTP-Header
     226            $httpheader = array();
     227            $httpheader[] = 'Content-type: application/x-www-form-urlencoded;charset=UTF-8';
    202228           
    203229            // Settings
    204230            curl_setopt($cURL, CURLOPT_URL, $url);
    205231            curl_setopt($cURL, CURLOPT_HEADER, 0);
     232            curl_setopt($cURL, CURLOPT_HTTPHEADER, $httpheader);
    206233            curl_setopt($cURL, CURLOPT_RETURNTRANSFER, true);
    207234            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);
    208253           
    209254            // Download
     
    232277        }
    233278       
     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
    234338        function cleanUpURL($url) {
    235339            // Filter $_GET[p], falls vorhanden, aus link
     
    249353        }
    250354       
    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) {
    252357            $wppocket_entry_building = get_option('wppocket_entry_building');
    253358           
     
    258363                $wppocket_entry_building = str_replace('%%url%%', $url, $wppocket_entry_building);
    259364                $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);
    260367            }
    261368           
     
    267374        }
    268375       
     376        // Function to replace variables in the title of the post
    269377        function getReplacedTitle($countLinks, $replace = true) {
    270378            $wppocket_title = get_option('wppocket_title');
     
    272380            // Set the variables, if should do this
    273381            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);
    276384                $wppocket_title = str_replace('%%year%%', date('Y'), $wppocket_title);
    277385                $wppocket_title = str_replace('%%count%%', $countLinks, $wppocket_title);
     
    281389        }
    282390       
    283         function getReplacedIntroductionText($replace = true) {
     391        // Function to replace variables in the introduction text
     392        function getReplacedIntroductionText($countLinks, $replace = true) {
    284393            $wppocket_introduction_text = get_option('wppocket_introduction_text');
    285394           
    286395            // Set the variables, if should do this
    287396            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);
    290399                $wppocket_introduction_text = str_replace('%%year%%', date('Y'), $wppocket_introduction_text);         
     400                $wppocket_introduction_text = str_replace('%%count%%', $countLinks, $wppocket_introduction_text);
    291401            }
    292402           
     
    294404        }
    295405       
    296         function getReplacedStatementsText($replace = true) {
     406        // Function to replace variables in the statements text
     407        function getReplacedStatementsText($countLinks, $replace = true) {
    297408            $wppocket_statements_text = get_option('wppocket_statements_text');
    298409           
    299410            // Set the variables, if should do this
    300411            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);
    304416            }
    305417           
     
    307419        }
    308420       
     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
    309614        function checkPocketAccess() {
    310             // Check if username, password and api-key is set, if not, print error
    311             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') == '') {
    312617                ?>
    313618                <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>
    315620                </div>
    316621                <?php
     
    318623            }else { // Test the settings
    319624                // 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
    323635                if ($getAuth == '400 Bad Request') {
    324636                    ?>
    325637                    <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>
    327639                    </div>
    328640                    <?php
     
    331643                    ?>
    332644                    <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>
    334646                    </div>
    335647                    <?php
     
    341653        }
    342654       
     655        // Support box on the right side of each WP Pocket page
    343656        function support_div($display = true) {
    344657            ?>
     
    346659                <h3>support me</h3>
    347660               
    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>
    349662               
    350663                <h3>follow me on twitter</h3>
    351664               
    352665                <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>
    354667                    <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>
    355668                </p>
    356669               
    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>
    362675            </div>
    363676            <?php
    364677        }
    365678       
     679        // Function to set options page
    366680        function options_link() {
    367681            // Start the view of the options page
     
    372686        }
    373687       
     688        // Options page view
    374689        function options_page_view() {
    375690            // Add option page style
     
    388703                <?php $this->support_div(); ?>
    389704               
    390                 <form method="post" action="<?php echo $_SERVER['REQUEST_URI']; ?>">
    391705                    <h3>Pocket Login</h3>
    392706                    <table class="form-table">
    393707                        <tr>
    394                             <th>Pocket Username</th>
     708                            <th>Pocket Auth</th>
    395709                            <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>
    397743                            </td>
    398744                        </tr>
    399745                        <tr>
    400                             <th>Pocket Password</th>
     746                            <th>Statistics</th>
    401747                            <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>
    417753                            </td>
    418754                        </tr>
     
    426762                                <select name="wppocket_links_to_use">
    427763                                    <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>
    430766                                    <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>
    433769                                </select>
    434770                                <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>
    435782                            </td>
    436783                        </tr>
     
    446793                        </tr>
    447794                        <tr>
    448                             <th>Mark as readed</th>
     795                            <th>Mark as readed/archived</th>
    449796                            <td>
    450797                                <select name="wppocket_mark_as_readed">
     
    565912                                    write the text and the variable in double square brackets. For example: %%title%%[[ - Tags: %%tags%%]]<br />
    566913                                    <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>
    568916                                </p>
    569917                            </td>
     
    581929                                <p class="description">
    582930                                    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>
    584932                                </p>
    585933                            </td>
     
    597945                                <p class="description">
    598946                                    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>
    600948                                </p>
    601949                            </td>
     
    613961        }
    614962       
     963        // Options page controller
    615964        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           
    616985            // Check if setting sended
    617986            if ($_POST['wppocket_edit']) {
     
    621990                // Error Text Array
    622991                $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.'
    628995                );
    629996           
    630997                // Update "Pocket Login"
    631998               
    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'] == '') {
    6411009                    $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'] != '') {
    6531011                    // 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;
    6591027                }
    6601028               
     
    6651033               
    6661034                update_option('wppocket_links_to_use', $_POST['wppocket_links_to_use']);
     1035                update_option('wppocket_faved', $_POST['wppocket_faved']);
    6671036                update_option('wppocket_order', $_POST['wppocket_order']);
    6681037                update_option('wppocket_mark_as_readed', $_POST['wppocket_mark_as_readed']);
     
    7151084                // Check if title is not set
    7161085                if ($_POST['wppocket_title'] == '') {
    717                     $error[] = 3;
     1086                    $error[] = 2;
    7181087                }else {
    7191088                    update_option('wppocket_title', $_POST['wppocket_title']);
     
    7221091                // Chech if entry building is not set
    7231092                if ($_POST['wppocket_entry_building'] == '') {
    724                     $error[] = 4;
     1093                    $error[] = 3;
    7251094                }else {
    7261095                    update_option('wppocket_entry_building', $_POST['wppocket_entry_building']);
     
    7301099                update_option('wppocket_introduction_text', $_POST['wppocket_introduction_text']);
    7311100                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']);
    7321105               
    7331106                // Output all errors
     
    7501123                    <?php
    7511124                }
     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                }
    7521134            }
    7531135           
     
    7561138        }
    7571139       
     1140        // Function to set the main page
    7581141        function main_link() {     
    7591142            // Start the view of the main page
     
    7611144        }
    7621145       
     1146        // Main page view
    7631147        function main_page_view() {
    7641148            // Add option page style
     
    7811165                    <div class="nav-tabs-arrow nav-tabs-arrow-left" style="display: none; "><a>«</a></div>
    7821166                    <div class="nav-tabs-wrapper">
    783                         <div class="nav-tabs" style="padding: 0px; margin-right: -110px; margin-left: 0px; ">
     1167                        <div class="nav-tabs">
    7841168                            <span class="nav-tab nav-tab-active"></span><a href="#" class="nav-tab menu-add-new"></a>   
    7851169                        </div>
     
    8041188                    if ($checkPocketAccess) {               
    8051189                        // 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?
    8081197                        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';
    8121201                        } // All
    8131202                       
    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                        );
    8151221                       
    8161222                        // Decode JSON to Object
     
    8221228                            foreach ($getLinks->list as $key => $value) {
    8231229                                // 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 . '"';
    8251231                                $row = $this->wpdb->get_results($sql);
    8261232                               
     
    8291235                                }
    8301236                            }
    831                         }
    832                        
    833                         // Check if order should be oldest to newest
    834                         if (get_option('wppocket_order')) {
    835                             // Turn around the json object
    836                             $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;
    8421237                        }
    8431238                       
     
    8641259                                    <?php
    8651260                                    // 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                                            }
    8761275                                           
    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 = '';
    8801280                                        }
    8811281                                       
    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());
    8861285                                           
    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);
    8911295                                                }
    8921296                                            }
    8931297                                           
    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                                                        }
    8991318                                                    }
    9001319                                                }
     
    9061325                                                <dt class="menu-item-handle">
    9071326                                                    <div class="left">
    908                                                         <?php echo $value->title; ?>
     1327                                                        <?php echo $value->resolved_title; ?>
    9091328                                                    </div>
    9101329                                                    <div class="right">
     
    9161335
    9171336                                            <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">
    9191338                                                    <label for="item-<?php echo $key; ?>-input-title">
    9201339                                                        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; ?>" />
    9221341                                                    </label>
    9231342                                                </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">
    9251370                                                    <label for="item-<?php echo $key; ?>-input-tags">
    926                                                         Tags (optional)<br />
     1371                                                        Tags<br />
    9271372                                                        <input type="text" id="item-<?php echo $key; ?>-input-tags" class="widefat" name="element[][tags]" value="<?php echo $value->tags; ?>" />
    9281373                                                    </label>
     
    9311376                                                    <label for="item-<?php echo $key; ?>-input-description">
    9321377                                                        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>
    9411379                                                    </label>
    9421380                                                </p>
    9431381                                               
    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; ?>" />
    9451385                                                <input type="hidden" name="element[][associate]" class="associate" value="0" />
    9461386                                            </div>
     
    9591399                    }
    9601400                }elseif ($_POST['mode'] == 'save') { // Save post
    961                     // Check if elements was posted
     1401                    // Check if elements was lposted
    9621402                    if ($_POST['count_elements'] == 0) { // No elements
    9631403                        ?>
     
    9991439        }
    10001440       
     1441        // Options page controller
    10011442        function main_page_controller() {
    10021443            global $current_user;
     
    10091450               
    10101451                // 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);
    10121453               
    10131454                // 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);
    10151456               
    10161457                // Check, which Array elements are dynamic. Set empy replace and flag in new array
     
    10371478                unset($noReplaceEntryBuilding);
    10381479               
     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               
    10391502                #########################
    10401503                ## SET ASSOCIATE LINKS ##
    10411504                #########################
    10421505                $i = 0;
    1043                 while ($i < (count($_POST['element']) / 7)) {
     1506                while ($i < (count($_POST['element']) / 9)) {
    10441507                    // Check if this it not a associate link
    1045                     if (!$_POST['element'][($i * 7) + 5]['associate']) {
     1508                    if (!$_POST['element'][($i * 9) + 6]['associate']) {
    10461509                        // Search for associate links in the following
    10471510                        $associateLinks = array();
     
    10491512                        while(true) {
    10501513                            // 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];
    10541516                            }else {
    10551517                                break;
     
    10681530               
    10691531                // 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));
    10711533               
    10721534                // Array for all posted links
     
    10751537                $post_content = '';
    10761538               
    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
    10831540                $i = 0;
    1084                 while ($i < (count($_POST['element']) / 7)) {
     1541                while ($i < (count($_POST['element']) / 9)) {
    10851542                    // Check if only not posted links should post
    10861543                    if (get_option('wppocket_links_to_use') == 0 || get_option('wppocket_links_to_use') == 1 || get_option('wppocket_links_to_use') == 2) {
    10871544                        // 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'] . '"';
    10891546                        $row = $this->wpdb->get_results($sql);
    10901547                       
    10911548                        if ($row[0]->id != '') {
    1092                             $_POST['count_elements'] -= count($_POST['element'][($i * 7) + 3]); // - this and associated elements
     1549                            $_POST['count_elements'] -= count($_POST['element'][($i * 9) + 2]); // - this and associated elements
    10931550                            $i++;
    10941551                            continue;
     
    10971554                   
    10981555                    // Check if this it not a associate link
    1099                     if (!$_POST['element'][($i * 7) + 6]['associate']) {                   
     1556                    if (!$_POST['element'][($i * 9) + 8]['associate']) {
    11001557                        // Gennerate url array in url string
    11011558                        $url = '';
    11021559                       
    11031560                        $i2 = 0;
    1104                         foreach ($_POST['element'][($i * 7) + 3] as $value) {
     1561                        foreach ($_POST['element'][($i * 9) + 2] as $value) {
    11051562                            if ($i2 != 0) {
    11061563                                $url .= '; ';
    11071564                            }
    11081565                           
    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;
    11101570                           
    11111571                            $i2++;
    11121572                        }
    11131573                       
    1114                         // Fill array for all posted links
    1115                         foreach ($_POST['element'][($i * 7) + 4] as $value) {
    1116                             $allPostedLinks[] = $value;
    1117                         }
    1118                        
    11191574                        // 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                        );
    11211583                       
    11221584                        // Check if a dynamic element is not in use an delete it
     
    11431605                }
    11441606               
     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               
    11451617                // Set statements text if not empty
    11461618                if (trim(get_option('wppocket_statements_text')) != '') {
    1147                     $post_content .= $this->getReplacedStatementsText();
     1619                    $post_content_final .= $this->getReplacedStatementsText($_POST['count_elements']);
    11481620                }
    11491621               
    11501622                // Chech if reference to WP Pocket shot print
    11511623                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>';
    11531625                }
    11541626               
     
    11651637                        'post_author' => $current_user->ID,
    11661638                        'post_category' => array(get_option('wppocket_post_category')),
    1167                         'post_content' => $post_content,
     1639                        'post_content' => $post_content_final,
    11681640                        'post_date' => date('Y-m-d H:i:s'),
    11691641                        'post_date_gmt' => gmdate('Y-m-d H:i:s'),
     
    11881660                    $i = 0;
    11891661                    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] . '"';
    11911663                        $row = $this->wpdb->get_results($sql);
    11921664                       
     
    12061678                                $this->wpdb->prepare(
    12071679                                    $sql,
    1208                                     $allPostedLinks[$i],
     1680                                    $allPostedLinks[$i][1],
    12091681                                    $time
    12101682                                )
     
    12221694                // Check if link should marke as readed
    12231695                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
    12281699                    $i = 0;
    12291700                    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();
    12321722                        }
    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];
    12351742                       
    12361743                        $i++;
    12371744                    }
    12381745                   
    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            );
    12461796        }
    12471797    }
  • wp-pocket/trunk/css/main.css

    r598433 r647244  
    1010.wppocket p.description {
    1111    margin: 2px 10px 5px 0;
     12}
     13
     14.wppocket p.description textarea {
     15    resize: vertical;
    1216}
    1317
     
    6266}
    6367
     68.wppocket .description-thin.description-two-thirds {
     69    width: 400px;
     70}
     71
     72.wppocket .description-thin.description-one-thirds {
     73    width: 180px;
     74}
     75
    6476.wppocket .menu-item-settings {
    6577    width: 600px;
  • wp-pocket/trunk/readme.txt

    r618439 r647244  
    44Tags: wp pocket, wordpress, pocket, post, automaticly, wp, links, linklist
    55Requires at least: 3.4
    6 Tested up to: 3.4
    7 Stable tag: 1.1.1
     6Tested up to: 3.5
     7Stable tag: 1.2
    88License: GPLv2 or later
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    5252== Changelog ==
    5353
     54= 1.2 =
     55Rewrite to Pocket API v3 with oAuth
     56Check required PHP version
     57Added names of months in English, German or French language
     58Improved quality of link title and description
     59Implemented function to publish only links, that are marked as favorites in pocket
     60Implemented function to show the author of the article in the linklist
     61More variables possible in entry building, introduction text and statement text
     62Sends, if user allowed it, anonymous statistics to WP-Pocket.com
     63Solved coding problems of titles and descriptions
     64Solved the problem of marking more than 100 links as read
     65Improved performance
     66Improved commenting of the code
     67Other minor bugfixes
     68Removed Flattr button
     69
    5470= 1.1.1 =
    5571Fix link to options in installed plugins overview
     
    8096== ToDo ==
    8197
    82 Nothing. If you have requests, please tell me via the contact form on http://wp-pocket.com
     98Solve all links option in <i>Links to use</i> (possible, if Pocket save the bug in the API)
     99
     100If you have requests, please tell me via the contact form on http://wp-pocket.com
  • wp-pocket/trunk/wp-pocket.php

    r618439 r647244  
    66    Author: Jan Karres
    77    Author URI: http://www.jankarres.de/
    8     Version: 1.1.1
     8    Version: 1.2
    99*/
    10 
    1110if(!class_exists('wppocketer')) {
    1211    class wppocketer {
     
    1413        private $version;
    1514       
    16         // Pocket default API-Key by developer
    17         private $global_pocket_api_key;
     15        // Pocket default Consumer-Key by developer
     16        private $global_pocket_consumer_key;
    1817   
    1918        function __construct() {
     
    2423           
    2524            // Set plugin version
    26             $this->version = '1.1.1';
     25            $this->version = '1.2';
    2726       
    2827            // Check WP version
    29             add_action('init', array(&$this, 'requires_wordpress_version'));
     28            add_action('init', array(&$this, 'requires_versions'));
    3029       
    3130            // Change plugin status hooks
     
    4241            wp_register_script('wppocket_main', plugins_url('js/main.js', __FILE__), array('jquery', 'jquery-ui-core', 'jquery-ui-draggable', 'jquery-ui-droppable'));
    4342           
    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() {
    4949            global $wp_version;
    5050           
     
    5858                    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>.');
    5959                }
     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>.');
    6066            }
    6167           
     
    9096                ("wppocket_version", "' . $this->version . '", "yes"),
    9197                ("wppocket_links_to_use", "0", "yes"),
     98                ("wppocket_faved", "0", "yes"),
    9299                ("wppocket_order", "0", "yes"),
    93100                ("wppocket_mark_as_readed", "0", "yes"),
     
    100107                ("wppocket_post_category", "1", "yes"),
    101108                ("wppocket_pocket_username", "", "yes"),
    102                 ("wppocket_pocket_password", "", "yes"),
     109                ("wppocket_pocket_access_key", "", "yes"),
    103110                ("wppocket_title", "WP Pocket link collection: %%month%% with %%count%% links", "yes"),
    104111                ("wppocket_introduction_text", "", "yes"),
    105112                ("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"),
    107116                ("wppocket_key_a", "' . $this->keygen(128) . '", "yes"),
    108117                ("wppocket_key_b", "' . $this->keygen(128) . '", "yes")
    109118            ';
    110119            $this->wpdb->query($sql);
    111 
     120           
    112121            // 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', '>=')) {
    118123                // Update Pocket username, password and api-key
    119124                update_option('wppocket_pocket_username', $this->xcrypt(0, $this->xcrypt(1, get_option('wppocket_pocket_username'), true)));
     
    122127            }
    123128           
    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
    125141            $sql = '
    126142            INSERT IGNORE INTO `' . $this->wpdb->prefix . 'options` (
     
    129145                `autoload`
    130146            ) 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")
    133149            ';
    134150            $this->wpdb->query($sql);
     
    136152            // Check if plugin version number up to date
    137153            if (get_option('wppocket_version') != $this->version) {
     154                // Send statistics, if allowed
     155                if (get_option('wppocket_statistics') == 1) {
     156                    $this->statisticsUpdateVersion();
     157                }
     158               
    138159                // Update version number
    139160                update_option('wppocket_version', $this->version);
     
    142163
    143164        function deactivate() {
    144             // nothing to do, because user cam reactivate
     165            // nothing to do, because user can reactivate the plugin
    145166        }
    146167       
     
    197218        }
    198219       
    199         private function cURL($url, $timeout = 5) {
     220        // Easy cURL function
     221        private function cURL($url, $post, $timeout = 5) {
    200222            // Init cURL
    201223            $cURL = curl_init();
     224           
     225            // Define HTTP-Header
     226            $httpheader = array();
     227            $httpheader[] = 'Content-type: application/x-www-form-urlencoded;charset=UTF-8';
    202228           
    203229            // Settings
    204230            curl_setopt($cURL, CURLOPT_URL, $url);
    205231            curl_setopt($cURL, CURLOPT_HEADER, 0);
     232            curl_setopt($cURL, CURLOPT_HTTPHEADER, $httpheader);
    206233            curl_setopt($cURL, CURLOPT_RETURNTRANSFER, true);
    207234            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);
    208253           
    209254            // Download
     
    232277        }
    233278       
     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
    234338        function cleanUpURL($url) {
    235339            // Filter $_GET[p], falls vorhanden, aus link
     
    249353        }
    250354       
    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) {
    252357            $wppocket_entry_building = get_option('wppocket_entry_building');
    253358           
     
    258363                $wppocket_entry_building = str_replace('%%url%%', $url, $wppocket_entry_building);
    259364                $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);
    260367            }
    261368           
     
    267374        }
    268375       
     376        // Function to replace variables in the title of the post
    269377        function getReplacedTitle($countLinks, $replace = true) {
    270378            $wppocket_title = get_option('wppocket_title');
     
    272380            // Set the variables, if should do this
    273381            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);
    276384                $wppocket_title = str_replace('%%year%%', date('Y'), $wppocket_title);
    277385                $wppocket_title = str_replace('%%count%%', $countLinks, $wppocket_title);
     
    281389        }
    282390       
    283         function getReplacedIntroductionText($replace = true) {
     391        // Function to replace variables in the introduction text
     392        function getReplacedIntroductionText($countLinks, $replace = true) {
    284393            $wppocket_introduction_text = get_option('wppocket_introduction_text');
    285394           
    286395            // Set the variables, if should do this
    287396            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);
    290399                $wppocket_introduction_text = str_replace('%%year%%', date('Y'), $wppocket_introduction_text);         
     400                $wppocket_introduction_text = str_replace('%%count%%', $countLinks, $wppocket_introduction_text);
    291401            }
    292402           
     
    294404        }
    295405       
    296         function getReplacedStatementsText($replace = true) {
     406        // Function to replace variables in the statements text
     407        function getReplacedStatementsText($countLinks, $replace = true) {
    297408            $wppocket_statements_text = get_option('wppocket_statements_text');
    298409           
    299410            // Set the variables, if should do this
    300411            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);
    304416            }
    305417           
     
    307419        }
    308420       
     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
    309614        function checkPocketAccess() {
    310             // Check if username, password and api-key is set, if not, print error
    311             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') == '') {
    312617                ?>
    313618                <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>
    315620                </div>
    316621                <?php
     
    318623            }else { // Test the settings
    319624                // 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
    323635                if ($getAuth == '400 Bad Request') {
    324636                    ?>
    325637                    <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>
    327639                    </div>
    328640                    <?php
     
    331643                    ?>
    332644                    <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>
    334646                    </div>
    335647                    <?php
     
    341653        }
    342654       
     655        // Support box on the right side of each WP Pocket page
    343656        function support_div($display = true) {
    344657            ?>
     
    346659                <h3>support me</h3>
    347660               
    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>
    349662               
    350663                <h3>follow me on twitter</h3>
    351664               
    352665                <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>
    354667                    <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>
    355668                </p>
    356669               
    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>
    362675            </div>
    363676            <?php
    364677        }
    365678       
     679        // Function to set options page
    366680        function options_link() {
    367681            // Start the view of the options page
     
    372686        }
    373687       
     688        // Options page view
    374689        function options_page_view() {
    375690            // Add option page style
     
    388703                <?php $this->support_div(); ?>
    389704               
    390                 <form method="post" action="<?php echo $_SERVER['REQUEST_URI']; ?>">
    391705                    <h3>Pocket Login</h3>
    392706                    <table class="form-table">
    393707                        <tr>
    394                             <th>Pocket Username</th>
     708                            <th>Pocket Auth</th>
    395709                            <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>
    397743                            </td>
    398744                        </tr>
    399745                        <tr>
    400                             <th>Pocket Password</th>
     746                            <th>Statistics</th>
    401747                            <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>
    417753                            </td>
    418754                        </tr>
     
    426762                                <select name="wppocket_links_to_use">
    427763                                    <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>
    430766                                    <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>
    433769                                </select>
    434770                                <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>
    435782                            </td>
    436783                        </tr>
     
    446793                        </tr>
    447794                        <tr>
    448                             <th>Mark as readed</th>
     795                            <th>Mark as readed/archived</th>
    449796                            <td>
    450797                                <select name="wppocket_mark_as_readed">
     
    565912                                    write the text and the variable in double square brackets. For example: %%title%%[[ - Tags: %%tags%%]]<br />
    566913                                    <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>
    568916                                </p>
    569917                            </td>
     
    581929                                <p class="description">
    582930                                    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>
    584932                                </p>
    585933                            </td>
     
    597945                                <p class="description">
    598946                                    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>
    600948                                </p>
    601949                            </td>
     
    613961        }
    614962       
     963        // Options page controller
    615964        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           
    616985            // Check if setting sended
    617986            if ($_POST['wppocket_edit']) {
     
    621990                // Error Text Array
    622991                $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.'
    628995                );
    629996           
    630997                // Update "Pocket Login"
    631998               
    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'] == '') {
    6411009                    $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'] != '') {
    6531011                    // 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;
    6591027                }
    6601028               
     
    6651033               
    6661034                update_option('wppocket_links_to_use', $_POST['wppocket_links_to_use']);
     1035                update_option('wppocket_faved', $_POST['wppocket_faved']);
    6671036                update_option('wppocket_order', $_POST['wppocket_order']);
    6681037                update_option('wppocket_mark_as_readed', $_POST['wppocket_mark_as_readed']);
     
    7151084                // Check if title is not set
    7161085                if ($_POST['wppocket_title'] == '') {
    717                     $error[] = 3;
     1086                    $error[] = 2;
    7181087                }else {
    7191088                    update_option('wppocket_title', $_POST['wppocket_title']);
     
    7221091                // Chech if entry building is not set
    7231092                if ($_POST['wppocket_entry_building'] == '') {
    724                     $error[] = 4;
     1093                    $error[] = 3;
    7251094                }else {
    7261095                    update_option('wppocket_entry_building', $_POST['wppocket_entry_building']);
     
    7301099                update_option('wppocket_introduction_text', $_POST['wppocket_introduction_text']);
    7311100                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']);
    7321105               
    7331106                // Output all errors
     
    7501123                    <?php
    7511124                }
     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                }
    7521134            }
    7531135           
     
    7561138        }
    7571139       
     1140        // Function to set the main page
    7581141        function main_link() {     
    7591142            // Start the view of the main page
     
    7611144        }
    7621145       
     1146        // Main page view
    7631147        function main_page_view() {
    7641148            // Add option page style
     
    7811165                    <div class="nav-tabs-arrow nav-tabs-arrow-left" style="display: none; "><a>«</a></div>
    7821166                    <div class="nav-tabs-wrapper">
    783                         <div class="nav-tabs" style="padding: 0px; margin-right: -110px; margin-left: 0px; ">
     1167                        <div class="nav-tabs">
    7841168                            <span class="nav-tab nav-tab-active"></span><a href="#" class="nav-tab menu-add-new"></a>   
    7851169                        </div>
     
    8041188                    if ($checkPocketAccess) {               
    8051189                        // 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?
    8081197                        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';
    8121201                        } // All
    8131202                       
    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                        );
    8151221                       
    8161222                        // Decode JSON to Object
     
    8221228                            foreach ($getLinks->list as $key => $value) {
    8231229                                // 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 . '"';
    8251231                                $row = $this->wpdb->get_results($sql);
    8261232                               
     
    8291235                                }
    8301236                            }
    831                         }
    832                        
    833                         // Check if order should be oldest to newest
    834                         if (get_option('wppocket_order')) {
    835                             // Turn around the json object
    836                             $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;
    8421237                        }
    8431238                       
     
    8641259                                    <?php
    8651260                                    // 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                                            }
    8761275                                           
    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 = '';
    8801280                                        }
    8811281                                       
    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());
    8861285                                           
    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);
    8911295                                                }
    8921296                                            }
    8931297                                           
    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                                                        }
    8991318                                                    }
    9001319                                                }
     
    9061325                                                <dt class="menu-item-handle">
    9071326                                                    <div class="left">
    908                                                         <?php echo $value->title; ?>
     1327                                                        <?php echo $value->resolved_title; ?>
    9091328                                                    </div>
    9101329                                                    <div class="right">
     
    9161335
    9171336                                            <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">
    9191338                                                    <label for="item-<?php echo $key; ?>-input-title">
    9201339                                                        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; ?>" />
    9221341                                                    </label>
    9231342                                                </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">
    9251370                                                    <label for="item-<?php echo $key; ?>-input-tags">
    926                                                         Tags (optional)<br />
     1371                                                        Tags<br />
    9271372                                                        <input type="text" id="item-<?php echo $key; ?>-input-tags" class="widefat" name="element[][tags]" value="<?php echo $value->tags; ?>" />
    9281373                                                    </label>
     
    9311376                                                    <label for="item-<?php echo $key; ?>-input-description">
    9321377                                                        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>
    9411379                                                    </label>
    9421380                                                </p>
    9431381                                               
    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; ?>" />
    9451385                                                <input type="hidden" name="element[][associate]" class="associate" value="0" />
    9461386                                            </div>
     
    9591399                    }
    9601400                }elseif ($_POST['mode'] == 'save') { // Save post
    961                     // Check if elements was posted
     1401                    // Check if elements was lposted
    9621402                    if ($_POST['count_elements'] == 0) { // No elements
    9631403                        ?>
     
    9991439        }
    10001440       
     1441        // Options page controller
    10011442        function main_page_controller() {
    10021443            global $current_user;
     
    10091450               
    10101451                // 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);
    10121453               
    10131454                // 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);
    10151456               
    10161457                // Check, which Array elements are dynamic. Set empy replace and flag in new array
     
    10371478                unset($noReplaceEntryBuilding);
    10381479               
     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               
    10391502                #########################
    10401503                ## SET ASSOCIATE LINKS ##
    10411504                #########################
    10421505                $i = 0;
    1043                 while ($i < (count($_POST['element']) / 7)) {
     1506                while ($i < (count($_POST['element']) / 9)) {
    10441507                    // Check if this it not a associate link
    1045                     if (!$_POST['element'][($i * 7) + 5]['associate']) {
     1508                    if (!$_POST['element'][($i * 9) + 6]['associate']) {
    10461509                        // Search for associate links in the following
    10471510                        $associateLinks = array();
     
    10491512                        while(true) {
    10501513                            // 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];
    10541516                            }else {
    10551517                                break;
     
    10681530               
    10691531                // 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));
    10711533               
    10721534                // Array for all posted links
     
    10751537                $post_content = '';
    10761538               
    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
    10831540                $i = 0;
    1084                 while ($i < (count($_POST['element']) / 7)) {
     1541                while ($i < (count($_POST['element']) / 9)) {
    10851542                    // Check if only not posted links should post
    10861543                    if (get_option('wppocket_links_to_use') == 0 || get_option('wppocket_links_to_use') == 1 || get_option('wppocket_links_to_use') == 2) {
    10871544                        // 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'] . '"';
    10891546                        $row = $this->wpdb->get_results($sql);
    10901547                       
    10911548                        if ($row[0]->id != '') {
    1092                             $_POST['count_elements'] -= count($_POST['element'][($i * 7) + 3]); // - this and associated elements
     1549                            $_POST['count_elements'] -= count($_POST['element'][($i * 9) + 2]); // - this and associated elements
    10931550                            $i++;
    10941551                            continue;
     
    10971554                   
    10981555                    // Check if this it not a associate link
    1099                     if (!$_POST['element'][($i * 7) + 6]['associate']) {                   
     1556                    if (!$_POST['element'][($i * 9) + 8]['associate']) {
    11001557                        // Gennerate url array in url string
    11011558                        $url = '';
    11021559                       
    11031560                        $i2 = 0;
    1104                         foreach ($_POST['element'][($i * 7) + 3] as $value) {
     1561                        foreach ($_POST['element'][($i * 9) + 2] as $value) {
    11051562                            if ($i2 != 0) {
    11061563                                $url .= '; ';
    11071564                            }
    11081565                           
    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;
    11101570                           
    11111571                            $i2++;
    11121572                        }
    11131573                       
    1114                         // Fill array for all posted links
    1115                         foreach ($_POST['element'][($i * 7) + 4] as $value) {
    1116                             $allPostedLinks[] = $value;
    1117                         }
    1118                        
    11191574                        // 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                        );
    11211583                       
    11221584                        // Check if a dynamic element is not in use an delete it
     
    11431605                }
    11441606               
     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               
    11451617                // Set statements text if not empty
    11461618                if (trim(get_option('wppocket_statements_text')) != '') {
    1147                     $post_content .= $this->getReplacedStatementsText();
     1619                    $post_content_final .= $this->getReplacedStatementsText($_POST['count_elements']);
    11481620                }
    11491621               
    11501622                // Chech if reference to WP Pocket shot print
    11511623                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>';
    11531625                }
    11541626               
     
    11651637                        'post_author' => $current_user->ID,
    11661638                        'post_category' => array(get_option('wppocket_post_category')),
    1167                         'post_content' => $post_content,
     1639                        'post_content' => $post_content_final,
    11681640                        'post_date' => date('Y-m-d H:i:s'),
    11691641                        'post_date_gmt' => gmdate('Y-m-d H:i:s'),
     
    11881660                    $i = 0;
    11891661                    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] . '"';
    11911663                        $row = $this->wpdb->get_results($sql);
    11921664                       
     
    12061678                                $this->wpdb->prepare(
    12071679                                    $sql,
    1208                                     $allPostedLinks[$i],
     1680                                    $allPostedLinks[$i][1],
    12091681                                    $time
    12101682                                )
     
    12221694                // Check if link should marke as readed
    12231695                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
    12281699                    $i = 0;
    12291700                    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();
    12321722                        }
    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];
    12351742                       
    12361743                        $i++;
    12371744                    }
    12381745                   
    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            );
    12461796        }
    12471797    }
Note: See TracChangeset for help on using the changeset viewer.