Plugin Directory

Changeset 821860


Ignore:
Timestamp:
12/14/2013 01:38:46 PM (12 years ago)
Author:
jankarres
Message:

update to version 1.7

Location:
wp-stacker
Files:
10 edited
1 copied

Legend:

Unmodified
Added
Removed
  • wp-stacker/tags/1.7/css/support.css

    r751169 r821860  
    77    padding: 10px;
    88   
    9     background: #FEFEDB;
    10     border: 1px solid #2D2D2D;
     9    background: #FFFFFF;
     10    border-left: 4px solid #DD3D36;
     11
     12    webkit-box-shadow: 0 1px 1px 0 rgba(0,0,0,.1);
     13    box-shadow: 0 1px 1px 0 rgba(0,0,0,.1);
    1114   
    1215    text-align: center;
  • wp-stacker/tags/1.7/readme.txt

    r751169 r821860  
    33Tags: wp stacker, wordpress, pocket, post, automaticly, wp, links, linklist
    44Requires at least: 3.4
    5 Tested up to: 3.6
    6 Stable tag: 1.6
     5Tested up to: 3.8
     6Stable tag: 1.7
    77License: GPLv2 or later
    88License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    5050
    5151== Changelog ==
     52
     53
     54= 1.7 =
     55* Fixed compatibility with WordPress 3.8
     56* Changed design elements for WordPress 3.8
     57* Reduced PHP notices
    5258
    5359= 1.6 =
  • wp-stacker/tags/1.7/wp-stacker.php

    r751169 r821860  
    66    Author: Jan Karres
    77    Author URI: http://jankarres.de/
    8     Version: 1.6
     8    Version: 1.7
    99*/
    1010
     
    1919        function __construct() {
    2020            global $wpdb;
    21            
     21
    2222            // Set database
    2323            $this->wpdb = $wpdb;
    2424           
    2525            // Set plugin version
    26             $this->version = '1.6';
     26            $this->version = '1.7';
    2727       
    2828            // Check WP version
    2929            add_action('init', array(&$this, 'requires_versions'));
    30        
     30           
    3131            // Change plugin status hooks
    3232            register_activation_hook(__FILE__, array(&$this, 'activate'));
     
    4040           
    4141            // Add javascripts of the plugin in the system
    42             wp_register_script('wpstacker_main', plugins_url('js/main.js', __FILE__), array('jquery', 'jquery-ui-core', 'jquery-ui-draggable', 'jquery-ui-droppable'));
     42            @wp_register_script('wpstacker_main', plugins_url('js/main.js', __FILE__), array('jquery', 'jquery-ui-core', 'jquery-ui-draggable', 'jquery-ui-droppable'));
    4343           
    4444            // Pocket default Consumer-Key by developer
     
    181181             
    182182            $characters = '0123456789qwertzuiopasdfghjklyxcvbnmQWERTZUIOPASDFGHJKLYXCVBNM';
    183            
     183            $key = '';
    184184            for ($i = 0; $i < $length; $i++) {
    185185                $key .= $characters[mt_rand(0, strlen($characters) - 1)];
     
    198198           
    199199            // Get crypt keys, if should
     200            $key = array();
     201            $keys = array();
     202            $key['a'] = '';
     203            $key['b'] = '';
     204            $keys['a'] = '';
     205            $keys['b'] = '';
    200206            if (!$nosalt) {
    201207                $keys['a'] = get_option('wpstacker_key_a');
     
    231237            // Save POST parameter in one string
    232238            if (count($post) != 0) {
     239                $postAsString = '';
    233240                $i = 0;
    234241                foreach ($post as $key => $value) {
     
    334341            // Filter $_GET[p], falls vorhanden, aus link
    335342            preg_match('/p=(.*)/', $url, $matches);
    336             $matches = explode('&', $matches[0]);
     343            if (count($matches) != 0) {
     344                $matches = explode('&', $matches[0]);
     345            }   
    337346           
    338347            // Clean url
     
    669678                <h3>support me</h3>
    670679               
    671                 <p>If you use the plugin and like it, you can say thanks and support me. How?</p>
     680                <p>If you use the plugin and like it, you can say thanks and support me.</p>
    672681               
    673682                <h3>follow me on twitter</h3>
     
    696705        function options_link() {
    697706            // Start the view of the options page
    698             add_options_page('WP Stacker Settings', 'WP Stacker', 5, 'settings_pocket_poster', array($this, 'options_page_view'));
     707            add_options_page('WP Stacker Settings', 'WP Stacker', 'edit_pages', 'settings_pocket_poster', array($this, 'options_page_view'));
    699708           
    700709            // Setzte Link
     
    10061015        function options_page_controller() {
    10071016            // Solve escape errors
    1008             $_POST['wpstacker_title'] = stripslashes_deep($_POST['wpstacker_title']);
    1009             $_POST['wpstacker_entry_building'] = stripslashes_deep($_POST['wpstacker_entry_building']);
    1010             $_POST['wpstacker_introduction_text'] = stripslashes_deep($_POST['wpstacker_introduction_text']);
    1011             $_POST['wpstacker_statements_text'] = stripslashes_deep($_POST['wpstacker_statements_text']);
     1017            if (isset($_POST['wpstacker_title'] )) { $_POST['wpstacker_title'] = stripslashes_deep($_POST['wpstacker_title']); }
     1018            if (isset($_POST['wpstacker_entry_building'])) { $_POST['wpstacker_entry_building'] = stripslashes_deep($_POST['wpstacker_entry_building']); }
     1019            if (isset($_POST['wpstacker_introduction_text'])) { $_POST['wpstacker_introduction_text'] = stripslashes_deep($_POST['wpstacker_introduction_text']); }
     1020            if (isset($_POST['wpstacker_statements_text'])) { $_POST['wpstacker_statements_text'] = stripslashes_deep($_POST['wpstacker_statements_text']); }
    10121021       
    10131022            // Check if should start Pocket auth process
     
    10321041           
    10331042            // Check if setting sended
    1034             if ($_POST['wpstacker_edit']) {
     1043            if (isset($_POST['wpstacker_edit'])
     1044                && $_POST['wpstacker_edit']
     1045                ) {
    10351046                // Error Array
    10361047                $error = array();
     
    10441055           
    10451056                // Update "Pocket Login"
    1046                
    1047                 if ($_POST['wpstacker_pocket_consumer_key_custom_remove'] == 1) {
     1057                $changeConsumerKey = false;
     1058                if (isset($_POST['wpstacker_pocket_consumer_key_custom_remove'])
     1059                    && $_POST['wpstacker_pocket_consumer_key_custom_remove'] == 1) {
    10481060                    // Set default key
    10491061                    update_option('wpstacker_pocket_consumer_key_custom', 0);
     
    11891201        // Function to set the main page
    11901202        function main_link() {
     1203            global $wp_version;
     1204
     1205            if (version_compare($wp_version, '3.7', '<')) {
     1206                $iconPng = 'images/icons/16_upto_wp37.png';
     1207            }else {
     1208                $iconPng = 'images/icons/16.png';
     1209            }
    11911210            // Start the view of the main page
    1192             add_menu_page('WP Stacker', 'WP Stacker', 5, 'pocket_poster', array($this, 'main_page_view'), plugin_dir_url(__FILE__) . 'images/icons/16.png', 32);
     1211            add_menu_page('WP Stacker', 'WP Stacker', 'edit_pages', 'pocket_poster', array($this, 'main_page_view'), plugin_dir_url(__FILE__) . $iconPng, 32);
    11931212        }
    11941213       
     
    12001219
    12011220            // Add JavaScript functions
    1202             wp_enqueue_script('jquery-ui-draggable');
    1203             wp_enqueue_script('jquery-ui-droppable');
     1221            wp_enqueue_script('droppable');
    12041222            wp_enqueue_script('nav-menu');
    1205             wp_enqueue_script('postbox');
    12061223            wp_enqueue_script('wpstacker_main');
    12071224            ?>
     
    12221239                <?php
    12231240                // Check if only elements with a tag shoul loaded (pre-check)
    1224                 if ($_POST['mode'] == 'get' && $_POST['onlyWithTag']) { // Get Elements
    1225                     // Check if tag is not empty
    1226                     if ($_POST['tag'] == '') {
    1227                         // Redict to main start page with error
    1228                         unset($_POST['mode']);
     1241                if (isset($_POST['mode'])) {
     1242                    if ($_POST['mode'] == 'get' && isset($_POST['onlyWithTag']) && $_POST['onlyWithTag']) { // Get Elements
     1243                        // Check if tag is not empty
     1244                        if (isset($_POST['tag'])) {
     1245                            if ($_POST['tag'] == '') {
     1246                                // Redict to main start page with error
     1247                                unset($_POST['mode']);
     1248                            }
     1249                        }
    12291250                    }
    12301251                }
     
    12321253               
    12331254                <?php
    1234                 if ($_POST['mode'] != 'get') {
    1235                     $this->support_div();
     1255                if (isset($_POST['mode'])) {
     1256                    if ($_POST['mode'] != 'get') {
     1257                        $this->support_div();
     1258                    }
    12361259                }
    12371260                ?>
     
    12411264                <?php
    12421265                // Check if should get Pocket elements or save as post
    1243                 if ($_POST['mode'] == 'get') { // Get Elements
    1244                     // Check Pocket Access
    1245                     $checkPocketAccess = $this->checkPocketAccess();
    1246                    
    1247                     // Check if access is valid
    1248                     if ($checkPocketAccess) {               
    1249                         // Get links from the user
    1250                         $getLinksPost = array();
     1266                if (
     1267                    isset($_POST['mode'])
     1268                    && $_POST['mode'] != ''
     1269                    ) {
     1270                    if ($_POST['mode'] == 'get') { // Get Elements
     1271                        // Check Pocket Access
     1272                        $checkPocketAccess = $this->checkPocketAccess();
    12511273                       
    1252                         $getLinksPost['consumer_key'] = $this->xcrypt(1, get_option('wpstacker_pocket_consumer_key'));
    1253                         $getLinksPost['access_token'] = $this->xcrypt(1, get_option('wpstacker_pocket_access_key'));
    1254                         $getLinksPost['detailType'] = 'complete';
    1255                        
    1256                         // Should get Readed, unreaded or all links?
    1257                         if (get_option('wpstacker_links_to_use') == 0 || get_option('wpstacker_links_to_use') == 3) { // Unreaded
    1258                             $getLinksPost['state'] = 'unread';
    1259                         }elseif (get_option('wpstacker_links_to_use') == 1 || get_option('wpstacker_links_to_use') == 4) { // Readed / Archived
    1260                             $getLinksPost['state'] = 'archive';
    1261                         }else { // All
    1262                             $getLinksPost['state'] = 'all';
    1263                         }
    1264                        
    1265                         // Check if only faved or unfaved links should use
    1266                         if (get_option('wpstacker_faved') == 1) { // only faved
    1267                             $getLinksPost['favorite'] = '1';
    1268                         }else if (get_option('wpstacker_faved') == 2) { // only unfaved
    1269                             $getLinksPost['favorite'] = '0';
    1270                         } // All
    1271                        
    1272                         // Check if order should be oldest to newest or newest to oldest
    1273                         if (get_option('wpstacker_order')) { // oldest to newest
    1274                             $getLinksPost['sort'] = 'oldest';
    1275                         }else { // newest to oldest
    1276                             $getLinksPost['sort'] = 'newest';
    1277                         }
    1278                        
    1279                         // Check if only links with a tag should load
    1280                         if ($_POST['onlyWithTag']) {
    1281                             $getLinksPost['tag'] = stripslashes_deep($_POST['tag']);
    1282                         }
    1283                        
    1284                         $getLinks = $this->cURL(
    1285                             'https://getpocket.com/v3/get',
    1286                             $getLinksPost
    1287                         );
    1288                        
    1289                         // Decode JSON to Object
    1290                         $getLinks = json_decode($getLinks);
    1291                        
    1292                         // Check if only not posted links should post
    1293                         if (get_option('wpstacker_links_to_use') == 0 || get_option('wpstacker_links_to_use') == 1 || get_option('wpstacker_links_to_use') == 2) {
    1294                             // Remove all already posted links
    1295                             foreach ($getLinks->list as $key => $value) {
    1296                                 // Check if aleady posted. If true, remove it
    1297                                 $sql = 'SELECT `id` FROM `' . $this->wpdb->prefix . 'wpstacker_posted_links` WHERE `url`="' . $value->given_url . '"';
    1298                                 $row = $this->wpdb->get_results($sql);
    1299                                
    1300                                 if ($row[0]->id != '') {
    1301                                     unset($getLinks->list->$key);
     1274                        // Check if access is valid
     1275                        if ($checkPocketAccess) {               
     1276                            // Get links from the user
     1277                            $getLinksPost = array();
     1278                           
     1279                            $getLinksPost['consumer_key'] = $this->xcrypt(1, get_option('wpstacker_pocket_consumer_key'));
     1280                            $getLinksPost['access_token'] = $this->xcrypt(1, get_option('wpstacker_pocket_access_key'));
     1281                            $getLinksPost['detailType'] = 'complete';
     1282                           
     1283                            // Should get Readed, unreaded or all links?
     1284                            if (get_option('wpstacker_links_to_use') == 0 || get_option('wpstacker_links_to_use') == 3) { // Unreaded
     1285                                $getLinksPost['state'] = 'unread';
     1286                            }elseif (get_option('wpstacker_links_to_use') == 1 || get_option('wpstacker_links_to_use') == 4) { // Readed / Archived
     1287                                $getLinksPost['state'] = 'archive';
     1288                            }else { // All
     1289                                $getLinksPost['state'] = 'all';
     1290                            }
     1291                           
     1292                            // Check if only faved or unfaved links should use
     1293                            if (get_option('wpstacker_faved') == 1) { // only faved
     1294                                $getLinksPost['favorite'] = '1';
     1295                            }else if (get_option('wpstacker_faved') == 2) { // only unfaved
     1296                                $getLinksPost['favorite'] = '0';
     1297                            } // All
     1298                           
     1299                            // Check if order should be oldest to newest or newest to oldest
     1300                            if (get_option('wpstacker_order')) { // oldest to newest
     1301                                $getLinksPost['sort'] = 'oldest';
     1302                            }else { // newest to oldest
     1303                                $getLinksPost['sort'] = 'newest';
     1304                            }
     1305                           
     1306                            // Check if only links with a tag should load
     1307                            if (isset($_POST['onlyWithTag']) && $_POST['onlyWithTag']) {
     1308                                $getLinksPost['tag'] = stripslashes_deep($_POST['tag']);
     1309                            }
     1310                           
     1311                            $getLinks = $this->cURL(
     1312                                'https://getpocket.com/v3/get',
     1313                                $getLinksPost
     1314                            );
     1315                           
     1316                            // Decode JSON to Object
     1317                            $getLinks = json_decode($getLinks);
     1318                           
     1319                            // Check if only not posted links should post
     1320                            if (get_option('wpstacker_links_to_use') == 0 || get_option('wpstacker_links_to_use') == 1 || get_option('wpstacker_links_to_use') == 2) {
     1321                                // Remove all already posted links
     1322                                foreach ($getLinks->list as $key => $value) {
     1323                                    // Check if aleady posted. If true, remove it
     1324                                    $sql = 'SELECT `id` FROM `' . $this->wpdb->prefix . 'wpstacker_posted_links` WHERE `url`="' . $value->given_url . '"';
     1325                                    $row = $this->wpdb->get_results($sql);
     1326                                   
     1327                                    if (isset($row[0]->id) && $row[0]->id != '') {
     1328                                        unset($getLinks->list->$key);
     1329                                    }
    13021330                                }
    13031331                            }
    1304                         }
    1305                        
    1306                         if (count((array)$getLinks->list) == 0) { // No elements
    1307                             ?>
    1308                             <?php $this->support_div(); ?>
    1309                            
    1310                             <p><strong>You do not have usable elements<?php
    1311                             if ($_POST['onlyWithTag'] && $_POST['tag'] != '') {
    1312                                 echo ' with the tag <i>' . stripslashes_deep($_POST['tag']) . '</i>';
    1313                             }
    1314                             ?> in your Pocket account! Is the <i>Links to use</i> setting correct?</strong></p>
    1315                             <p>You have to look for interesting links, before you can post them ;-)</p>
    1316                             <?php
    1317                         }else {
    1318                             ?>
    1319                             <?php $this->support_div(false); ?>
    1320                            
    1321                             <p class="wpstacker_loader" style="width: 308px; margin: 15px 0 0 0; text-align: center;">
    1322                                 <img src="<?php echo plugins_url('images/loading.gif', __FILE__) ?>" alt="loading" /><br />
    1323                                 <strong>Please wait while loading...</strong>
    1324                             </p>
    1325                            
    1326                             <form id="update-nav-menu" action="" method="post" enctype="multipart/form-data" style="display: none;">
    1327                                 <p><br /><strong>Please edit, sort and associate the links. If you finished, please click on the <i>Generate post</i> button at the end of the list!</strong></p>
    1328                                 <?php echo '<p>Number of links: <span class="number-links">' . count((array)$getLinks->list) . '</span></p>'; ?>
     1332                           
     1333                            if (count((array)$getLinks->list) == 0) { // No elements
     1334                                ?>
     1335                                <?php $this->support_div(); ?>
    13291336                               
    1330                                 <ul class="menu ui-sortable" id="menu-to-edit">
    1331                                     <?php
    1332                                     // Gennerate output of each link
    1333                                     foreach ($getLinks->list as $key => $value) {
    1334                                         // Rewirte Tags Array as Tags string
    1335                                         if (count($value->tags) != 0) {
    1336                                             $tagsAsString = '';
    1337                                             $i2 = 0;
    1338                                             foreach ($value->tags as $tag) {
    1339                                                 if ($i2 != 0) {
    1340                                                     $tagsAsString .= ', ';
     1337                                <p><strong>You do not have usable elements<?php
     1338                                if (isset($_POST['onlyWithTag']) && $_POST['onlyWithTag'] && $_POST['tag'] != '') {
     1339                                    echo ' with the tag <i>' . stripslashes_deep($_POST['tag']) . '</i>';
     1340                                }
     1341                                ?> in your Pocket account! Is the <i>Links to use</i> setting correct?</strong></p>
     1342                                <p>You have to look for interesting links, before you can post them ;-)</p>
     1343                                <?php
     1344                            }else {
     1345                                ?>
     1346                                <?php $this->support_div(false); ?>
     1347                               
     1348                                <p class="wpstacker_loader" style="width: 308px; margin: 15px 0 0 0; text-align: center;">
     1349                                    <img src="<?php echo plugins_url('images/loading.gif', __FILE__) ?>" alt="loading" /><br />
     1350                                    <strong>Please wait while loading...</strong>
     1351                                </p>
     1352                               
     1353                                <form id="update-nav-menu" action="" method="post" enctype="multipart/form-data" style="display: none;">
     1354                                    <p><br /><strong>Please edit, sort and associate the links. If you finished, please click on the <i>Generate post</i> button at the end of the list!</strong></p>
     1355                                    <?php echo '<p>Number of links: <span class="number-links">' . count((array)$getLinks->list) . '</span></p>'; ?>
     1356                                   
     1357                                    <ul class="menu ui-sortable" id="menu-to-edit">
     1358                                        <?php
     1359                                        // Gennerate output of each link
     1360                                        foreach ($getLinks->list as $key => $value) {
     1361                                            // Rewirte Tags Array as Tags string
     1362                                            if (isset($value->tags) && count($value->tags) != 0) {
     1363                                                $tagsAsString = '';
     1364                                                $i2 = 0;
     1365                                                foreach ($value->tags as $tag) {
     1366                                                    if ($i2 != 0) {
     1367                                                        $tagsAsString .= ', ';
     1368                                                    }
     1369                                                   
     1370                                                    $tagsAsString .= $tag->tag;
     1371                                                   
     1372                                                    $i2++;
    13411373                                                }
    13421374                                               
    1343                                                 $tagsAsString .= $tag->tag;
    1344                                                
    1345                                                 $i2++;
     1375                                                $value->tags = $tagsAsString;
     1376                                                unset($tagsAsString);
     1377                                            }else { // Not tags yet
     1378                                                $value->tags = '';
    13461379                                            }
    13471380                                           
    1348                                             $value->tags = $tagsAsString;
    1349                                             unset($tagsAsString);
    1350                                         }else { // Not tags yet
    1351                                             $value->tags = '';
    1352                                         }
    1353                                        
    1354                                         // Get data from the meta tags, if necessary
    1355                                         if ($value->resolved_title == '' || $value->excerpt == '' || (get_option('wpstacker_meta_keyword_as_tags') == 1 && $value->tags == '')) {
    1356                                             $urlHtml = $this->cURL($value->given_url, array());
    1357                                            
    1358                                             $doc = new DOMDocument();
    1359                                             @$doc->loadHTML($urlHtml);
    1360                                            
    1361                                             if ($value->resolved_title == '') {
    1362                                                 $nodes = $doc->getElementsByTagName('title');
    1363                                                 $value->title = utf8_decode($nodes->item(0)->nodeValue);
     1381                                            // Get data from the meta tags, if necessary
     1382                                            if ($value->resolved_title == '' || $value->excerpt == '' || (get_option('wpstacker_meta_keyword_as_tags') == 1 && $value->tags == '')) {
     1383                                                $urlHtml = $this->cURL($value->given_url, array());
    13641384                                               
    1365                                                 if (!$this->is_utf8($value->title)) {
    1366                                                     $value->title = utf8_encode($value->title);
    1367                                                 }
    1368                                             }
    1369                                            
    1370                                             $metas = $doc->getElementsByTagName('meta');
    1371                                            
    1372                                             for ($i = 0; $i < $metas->length; $i++) {
    1373                                                 $meta = $metas->item($i);
     1385                                                $doc = new DOMDocument();
     1386                                                @$doc->loadHTML($urlHtml);
    13741387                                               
    1375                                                 if ($value->excerpt == '') {
    1376                                                     if($meta->getAttribute('name') == 'description') {
    1377                                                         $value->excerpt = utf8_decode($meta->getAttribute('content'));
    1378                                                         if (!$this->is_utf8($value->excerpt)) {
    1379                                                             $value->excerpt = utf8_encode($value->excerpt);
    1380                                                         }
     1388                                                if ($value->resolved_title == '') {
     1389                                                    $nodes = $doc->getElementsByTagName('title');
     1390                                                    $value->title = utf8_decode($nodes->item(0)->nodeValue);
     1391                                                   
     1392                                                    if (!$this->is_utf8($value->title)) {
     1393                                                        $value->title = utf8_encode($value->title);
    13811394                                                    }
    13821395                                                }
    13831396                                               
    1384                                                 if (get_option('wpstacker_meta_keyword_as_tags') == 1 && $value->tags == '') {
    1385                                                     if ($meta->getAttribute('name') == 'keywords') {
    1386                                                         $value->tags = utf8_decode($meta->getAttribute('content'));
    1387                                                         if (!$this->is_utf8($value->tags)) {
    1388                                                             $value->tags = utf8_encode($value->tags);
     1397                                                $metas = $doc->getElementsByTagName('meta');
     1398                                               
     1399                                                for ($i = 0; $i < $metas->length; $i++) {
     1400                                                    $meta = $metas->item($i);
     1401                                                   
     1402                                                    if ($value->excerpt == '') {
     1403                                                        if($meta->getAttribute('name') == 'description') {
     1404                                                            $value->excerpt = utf8_decode($meta->getAttribute('content'));
     1405                                                            if (!$this->is_utf8($value->excerpt)) {
     1406                                                                $value->excerpt = utf8_encode($value->excerpt);
     1407                                                            }
     1408                                                        }
     1409                                                    }
     1410                                                   
     1411                                                    if (get_option('wpstacker_meta_keyword_as_tags') == 1 && $value->tags == '') {
     1412                                                        if ($meta->getAttribute('name') == 'keywords') {
     1413                                                            $value->tags = utf8_decode($meta->getAttribute('content'));
     1414                                                            if (!$this->is_utf8($value->tags)) {
     1415                                                                $value->tags = utf8_encode($value->tags);
     1416                                                            }
    13891417                                                        }
    13901418                                                    }
    13911419                                                }
    13921420                                            }
    1393                                         }
    1394                                         ?>
    1395                                         <li class="menu-item-edit-inactive">
    1396                                             <dl class="menu-item-bar">
    1397                                                 <dt class="menu-item-handle">
    1398                                                     <div class="left">
    1399                                                         <?php echo $value->resolved_title; ?>
    1400                                                     </div>
    1401                                                     <div class="right">
    1402                                                         <a class="item-remove" href="#item-remove-<?php echo $key; ?>">Remove element</a>
    1403                                                         <a class="item-edit" href="#item-<?php echo $key; ?>">Edit element</a>
    1404                                                     </div>
    1405                                                 </dt>
    1406                                             </dl>
     1421                                            ?>
     1422                                            <li class="menu-item-edit-inactive">
     1423                                                <dl class="menu-item-bar">
     1424                                                    <dt class="menu-item-handle">
     1425                                                        <div class="left">
     1426                                                            <?php echo $value->resolved_title; ?>
     1427                                                        </div>
     1428                                                        <div class="right">
     1429                                                            <a class="item-remove" href="#item-remove-<?php echo $key; ?>">Remove element</a>
     1430                                                            <a class="item-edit" href="#item-<?php echo $key; ?>">Edit element</a>
     1431                                                        </div>
     1432                                                    </dt>
     1433                                                </dl>
    14071434
    1408                                             <div class="menu-item-settings" id="item-<?php echo $key; ?>">
    1409                                                 <p class="description description-thin description-two-thirds">
    1410                                                     <label for="item-<?php echo $key; ?>-input-title">
    1411                                                         Title<br />
    1412                                                         <input type="text" id="item-<?php echo $key; ?>-input-title" class="widefat input-title" name="element[][title]" value="<?php echo $value->resolved_title; ?>" />
    1413                                                     </label>
    1414                                                 </p>
    1415                                                 <p class="description description-thin description-one-thirds">
    1416                                                     <label for="item-<?php echo $key; ?>-input-author">
    1417                                                         Author<br />
    1418                                                         <input type="text" id="item-<?php echo $key; ?>-input-author" class="widefat" name="element[][author]" value="<?php
    1419                                                             if (count($value->authors) != 0) {
    1420                                                                 $i2 = 0;
    1421                                                                 foreach($value->authors as $author) {
    1422                                                                     if ($i2 != 0) {
    1423                                                                         echo ', ';
     1435                                                <div class="menu-item-settings" id="item-<?php echo $key; ?>">
     1436                                                    <p class="description description-thin description-two-thirds">
     1437                                                        <label for="item-<?php echo $key; ?>-input-title">
     1438                                                            Title<br />
     1439                                                            <input type="text" id="item-<?php echo $key; ?>-input-title" class="widefat input-title" name="element[][title]" value="<?php echo $value->resolved_title; ?>" />
     1440                                                        </label>
     1441                                                    </p>
     1442                                                    <p class="description description-thin description-one-thirds">
     1443                                                        <label for="item-<?php echo $key; ?>-input-author">
     1444                                                            Author<br />
     1445                                                            <input type="text" id="item-<?php echo $key; ?>-input-author" class="widefat" name="element[][author]" value="<?php
     1446                                                                if (isset($value->authors) && count($value->authors) != 0) {
     1447                                                                    $i2 = 0;
     1448                                                                    foreach($value->authors as $author) {
     1449                                                                        if ($i2 != 0) {
     1450                                                                            echo ', ';
     1451                                                                        }
     1452                                                                       
     1453                                                                        echo $author->name;
     1454                                                                       
     1455                                                                        $i2++;
    14241456                                                                    }
    1425                                                                    
    1426                                                                     echo $author->name;
    1427                                                                    
    1428                                                                     $i2++;
    14291457                                                                }
    1430                                                             }
    1431                                                         ?>" />
    1432                                                     </label>
    1433                                                 </p>
    1434                                                 <p class="description description-thin description-two-thirds">
    1435                                                     <label for="item-<?php echo $key; ?>-input-url">
    1436                                                         URL<br />
    1437                                                         <input type="text" id="item-<?php echo $key; ?>-input-url" class="widefat" name="element[][url]" value="<?php if (get_option('wpstacker_clean_url') == 1) { echo $this->cleanUpURL($value->resolved_url); }else { echo $value->given_url; } ?>" />
    1438                                                         <input type="hidden" id="item-<?php echo $key; ?>-input-url" class="widefat" name="element[][url_uncleaned]" value="<?php echo $value->given_url; ?>" />
    1439                                                     </label>
    1440                                                 </p>
    1441                                                 <p class="description description-thin description-one-thirds">
    1442                                                     <label for="item-<?php echo $key; ?>-input-tags">
    1443                                                         Tags<br />
    1444                                                         <input type="text" id="item-<?php echo $key; ?>-input-tags" class="widefat" name="element[][tags]" value="<?php echo $value->tags; ?>" />
    1445                                                     </label>
    1446                                                 </p>
    1447                                                 <p class="description">
    1448                                                     <label for="item-<?php echo $key; ?>-input-description">
    1449                                                         Description (optional)<br />
    1450                                                         <textarea name="element[][description]" rows="4" id="item-<?php echo $key; ?>-input-description" class="widefat" type="textarea"><?php echo $value->excerpt; ?></textarea>
    1451                                                     </label>
    1452                                                 </p>
    1453                                                
    1454                                                
    1455                                                 <input type="hidden" name="element[][id]" value="<?php echo $value->item_id; ?>" />
    1456                                                 <input type="hidden" name="element[][countwords]" value="<?php echo $value->word_count; ?>" />
    1457                                                 <input type="hidden" name="element[][associate]" class="associate" value="0" />
    1458                                             </div>
    1459                                         </li>
    1460                                     <?php } ?>
    1461                                 </ul>
    1462                                
    1463                                 <p class="submit">
    1464                                     <input type="hidden" name="mode" value="save" />
    1465                                     <input type="submit" name="save_menu" class="button-primary" value="Gennerate post" />
    1466                                     <strong>This can take up to 30 seconds!</strong>
    1467                                 </p>
    1468                             </form>
     1458                                                            ?>" />
     1459                                                        </label>
     1460                                                    </p>
     1461                                                    <p class="description description-thin description-two-thirds">
     1462                                                        <label for="item-<?php echo $key; ?>-input-url">
     1463                                                            URL<br />
     1464                                                            <input type="text" id="item-<?php echo $key; ?>-input-url" class="widefat" name="element[][url]" value="<?php if (get_option('wpstacker_clean_url') == 1) { echo $this->cleanUpURL($value->resolved_url); }else { echo $value->given_url; } ?>" />
     1465                                                            <input type="hidden" id="item-<?php echo $key; ?>-input-url" class="widefat" name="element[][url_uncleaned]" value="<?php echo $value->given_url; ?>" />
     1466                                                        </label>
     1467                                                    </p>
     1468                                                    <p class="description description-thin description-one-thirds">
     1469                                                        <label for="item-<?php echo $key; ?>-input-tags">
     1470                                                            Tags<br />
     1471                                                            <input type="text" id="item-<?php echo $key; ?>-input-tags" class="widefat" name="element[][tags]" value="<?php echo $value->tags; ?>" />
     1472                                                        </label>
     1473                                                    </p>
     1474                                                    <p class="description">
     1475                                                        <label for="item-<?php echo $key; ?>-input-description">
     1476                                                            Description (optional)<br />
     1477                                                            <textarea name="element[][description]" rows="4" id="item-<?php echo $key; ?>-input-description" class="widefat" type="textarea"><?php if (isset($value->excerpt)) { echo $value->excerpt; } ?></textarea>
     1478                                                        </label>
     1479                                                    </p>
     1480                                                   
     1481                                                   
     1482                                                    <input type="hidden" name="element[][id]" value="<?php echo $value->item_id; ?>" />
     1483                                                    <input type="hidden" name="element[][countwords]" value="<?php echo $value->word_count; ?>" />
     1484                                                    <input type="hidden" name="element[][associate]" class="associate" value="0" />
     1485                                                </div>
     1486                                            </li>
     1487                                        <?php } ?>
     1488                                    </ul>
     1489                                   
     1490                                    <p class="submit">
     1491                                        <input type="hidden" name="mode" value="save" />
     1492                                        <input type="submit" name="save_menu" class="button-primary" value="Gennerate post" />
     1493                                        <strong>This can take up to 30 seconds!</strong>
     1494                                    </p>
     1495                                </form>
     1496                                <?php
     1497                            }
     1498                        }
     1499                    }elseif ($_POST['mode'] == 'save') { // Save post
     1500                        // Check if elements was lposted
     1501                        if ($_POST['count_elements'] == 0) { // No elements
     1502                            ?>
     1503                            <p><strong>No elements to post were found. Is the <i>Links to use</i> setting correct?</strong></strong></p>
     1504                            <p>You have to look for interesting links, before you can post them ;-)</p>
     1505                            <?php
     1506                        }else { // Success
     1507                            ?>
     1508                            <p class="short"><strong>Great! You posted <?php echo $_POST['count_elements']; ?> links from your Pocket account into your blog. <?php if (isset($_POST['wpstacker_mark_as_readed']) && $_POST['wpstacker_mark_as_readed']) { ?>They are now marked as read in your pocket account!<?php } ?></strong></p>
     1509                            <p class="short">If you like WP Stacker, I would be pleased, if you supported me. How to? Look in the yellow box on the right!</p>
    14691510                            <?php
    14701511                        }
    14711512                    }
    1472                 }elseif ($_POST['mode'] == 'save') { // Save post
    1473                     // Check if elements was lposted
    1474                     if ($_POST['count_elements'] == 0) { // No elements
    1475                         ?>
    1476                         <p><strong>No elements to post were found. Is the <i>Links to use</i> setting correct?</strong></strong></p>
    1477                         <p>You have to look for interesting links, before you can post them ;-)</p>
    1478                         <?php
    1479                     }else { // Success
    1480                         ?>
    1481                         <p class="short"><strong>Great! You posted <?php echo $_POST['count_elements']; ?> links from your Pocket account into your blog. <?php if ($_POST['wpstacker_mark_as_readed']) { ?>[18:56:01] Elias: They are now marked as read in your pocket account!<?php } ?></strong></p>
    1482                         <p class="short">If you like WP Stacker, I would be pleased, if you supported me. How to? Look in the yellow box on the right!</p>
    1483                         <?php
    1484                     }
    14851513                }else { // Print introduction
    14861514                    // Check if form already sent, tag requied and not set
    1487                     if ($_POST['onlyWithTag']) {
     1515                    if (
     1516                        isset($_POST['onlyWithTag'])
     1517                        && $_POST['onlyWithTag']
     1518                        ) {
    14881519                        ?>
    14891520                        <div id="message" class="error">
     
    15411572           
    15421573            // Check if the post sould save
    1543             if ($_POST['mode'] == 'save') { // Save post
    1544                 ########################
    1545                 ## SET ENTRY BUILDING ##
    1546                 ########################
    1547                
    1548                 // Set en empty example for entry building with replace
    1549                 $replaceEntryBuilding = $this->replaceEntryBuilding(false, false, false, false, false, false);
    1550                
    1551                 // Set en empty example for entry building without replace
    1552                 $noReplaceEntryBuilding = $this->replaceEntryBuilding(false, false, false, false, false, false, false);
    1553                
    1554                 // Check, which Array elements are dynamic. Set empy replace and flag in new array
    1555                 $i = 0;
    1556                 $exampleReplaceEntryBuilding = array();
    1557                 while($i < count($replaceEntryBuilding)) {
    1558                     if ($replaceEntryBuilding[$i] == $noReplaceEntryBuilding[$i]) {
    1559                         $exampleReplaceEntryBuilding[$i] = array(
    1560                             'example' => $replaceEntryBuilding[$i],
    1561                             'dynamic' => false
    1562                         );
    1563                     }else {
    1564                         $exampleReplaceEntryBuilding[$i] = array(
    1565                             'example' => $replaceEntryBuilding[$i],
    1566                             'dynamic' => true
    1567                         );
    1568                     }
    1569                    
    1570                     $i++;
    1571                 }
    1572                
    1573                 // Unset not longer needed vars
    1574                 unset($replaceEntryBuilding);
    1575                 unset($noReplaceEntryBuilding);
    1576                
    1577                 #####################################
    1578                 ## COMBINE URL, URL CLEANED AND ID ##
    1579                 #####################################
    1580                
    1581                 $i = 0;
    1582                 while ($i < (count($_POST['element']) / 9)) {
    1583                     $url = $_POST['element'][(($i * 9) + 2)]['url'];
    1584                     $urlUncleaned = $_POST['element'][(($i * 9) + 3)]['url_uncleaned'];
    1585                     $id = $_POST['element'][(($i * 9) + 6)]['id'];
    1586                    
    1587                     $_POST['element'][(($i * 9) + 2)] = array(
    1588                         array(
    1589                             $url,
    1590                             $urlUncleaned,
    1591                             $id
    1592                         )
    1593                     );
    1594                    
    1595                    
    1596                     $i++;
    1597                 }
    1598                
    1599                 #########################
    1600                 ## SET ASSOCIATE LINKS ##
    1601                 #########################
    1602                 $i = 0;
    1603                 while ($i < (count($_POST['element']) / 9)) {
    1604                     // Check if this it not a associate link
    1605                     if (!$_POST['element'][($i * 9) + 6]['associate']) {
    1606                         // Search for associate links in the following
    1607                         $associateLinks = array();
    1608                         $i2 = 1;
    1609                         while(true) {
    1610                             // If this is an associate links, add this to the array, else break the while-loop
    1611                             if ($_POST['element'][($i * 9) + 8 + ($i2 * 9)]['associate']) {
    1612                                 $_POST['element'][($i * 9) + 2][] = $_POST['element'][(($i * 9) + 2 + ($i2 * 9))][0];
    1613                             }else {
    1614                                 break;
    1615                             }
    1616                            
    1617                             $i2++;
    1618                         }
    1619                     }
    1620                    
    1621                     $i++;
    1622                 }
    1623                
    1624                 ####################
    1625                 ## GENNERATE POST ##
    1626                 ####################
    1627                
    1628                 // Set posted elements in $_POST for view
    1629                 $_POST['count_elements'] = round((count($_POST['element']) / 9));
    1630                
    1631                 // Array for all posted links
    1632                 $allPostedLinks = array();
    1633                
    1634                 $post_content = '';
    1635                
    1636                 // Gennerate all links in text
    1637                 $i = 0;
    1638                 while ($i < (count($_POST['element']) / 9)) {
    1639                     // Check if only not posted links should post
    1640                     if (get_option('wpstacker_links_to_use') == 0 || get_option('wpstacker_links_to_use') == 1 || get_option('wpstacker_links_to_use') == 2) {
    1641                         // Check if aleady posted. If true, confine to the next loop
    1642                         $sql = 'SELECT `id` FROM `' . $this->wpdb->prefix . 'wpstacker_posted_links` WHERE `url`="' . $_POST['element'][($i * 9) + 2]['url'] . '"';
    1643                         $row = $this->wpdb->get_results($sql);
    1644                        
    1645                         if ($row[0]->id != '') {
    1646                             $_POST['count_elements'] -= count($_POST['element'][($i * 9) + 2]); // - this and associated elements
    1647                             $i++;
    1648                             continue;
    1649                         }
    1650                     }
    1651                    
    1652                     // Check if this it not a associate link
    1653                     if (!$_POST['element'][($i * 9) + 8]['associate']) {
    1654                         // Gennerate url array in url string
    1655                         $url = '';
    1656                        
    1657                         $i2 = 0;
    1658                         foreach ($_POST['element'][($i * 9) + 2] as $value) {
    1659                             if ($i2 != 0) {
    1660                                 $url .= '; ';
    1661                             }
    1662                            
    1663                             $url .= '<a href="' . $value[0] . '" target="_blank">' . $value[0] . '</a>';
    1664                            
    1665                             // Fill array for all posted links
    1666                             $allPostedLinks[] = $value;
    1667                            
    1668                             $i2++;
    1669                         }
    1670                        
    1671                         // Set element in entry building
    1672                         $element = $this->replaceEntryBuilding(
    1673                             $_POST['element'][($i * 9)]['title'],
    1674                             $_POST['element'][($i * 9) + 5]['description'],
    1675                             $url,
    1676                             $_POST['element'][($i * 9) + 4]['tags'],
    1677                             $_POST['element'][($i * 9) + 1]['author'],
    1678                             $_POST['element'][($i * 9) + 7]['countwords']
    1679                         );
    1680                        
    1681                         // Check if a dynamic element is not in use an delete it
    1682                         $i2 = 0;
    1683                         while ($i2 < count($element)) {
    1684                             if ($element[$i2] == $exampleReplaceEntryBuilding[$i2]['example'] && $exampleReplaceEntryBuilding[$i2]['dynamic']) {
    1685                                 unset($element[$i2]);
    1686                             }
    1687 
    1688                             $i2++;
    1689                         }
    1690                        
    1691                         // Set element array as string for the post content
    1692                         $post_content .= '<p>';
    1693                        
    1694                         foreach ($element as $value) {
    1695                             $post_content .= $value;
    1696                         }
    1697                        
    1698                         $post_content .= '</p>';
    1699                     }
    1700                    
    1701                     $i++;
    1702                 }
    1703                
    1704                 $post_content_final = '';
    1705                
    1706                 // Set introduction text if not empty
    1707                 if (trim(get_option('wpstacker_introduction_text')) != '') {
    1708                     $post_content_final .= $this->getReplacedIntroductionText($_POST['count_elements']);
    1709                 }
    1710                
    1711                 // Set links content
    1712                 $post_content_final .= $post_content;
    1713                
    1714                 // Set statements text if not empty
    1715                 if (trim(get_option('wpstacker_statements_text')) != '') {
    1716                     $post_content_final .= $this->getReplacedStatementsText($_POST['count_elements']);
    1717                 }
    1718                
    1719                 // Chech if reference to WP Stacker shot print
    1720                 if (get_option('wpstacker_reference_wpstacker')) {
    1721                     $post_content_final .= '<p><i>This post was automatically created by WP Stacker. If you look for this WordPress plugin, check out <a href="http://wp-stacker.com/" target="_blank">WP-Stacker.com</a> now!</i></p>';
    1722                 }
    1723                
    1724                 ###############
    1725                 ## SAVE POST ##
    1726                 ###############
    1727                
    1728                 // Save only, if one or more elements are valid
    1729                 if ($_POST['count_elements'] != 0) {
    1730                     // Set settings array
    1731                     $post = array(
    1732                         'comment_status' => get_option('wpstacker_comment_status'),
    1733                         'ping_status' => get_option('wpstacker_ping_status'),
    1734                         'post_author' => $current_user->ID,
    1735                         'post_category' => array(get_option('wpstacker_post_category')),
    1736                         'post_content' => $post_content_final,
    1737                         'post_date' => date('Y-m-d H:i:s'),
    1738                         'post_date_gmt' => gmdate('Y-m-d H:i:s'),
    1739                         'post_status' => get_option('wpstacker_post_status'),
    1740                         'post_title' => $this->getReplacedTitle($_POST['count_elements']),
    1741                         'post_type' => 'post'
    1742                     );
    1743                    
    1744                     // Insert the post
    1745                     $postId = wp_insert_post($post);
    1746                    
    1747                     // Set post format
    1748                     set_post_format($postId, get_option('wpstacker_post_format'));
    1749                 }
    1750                
    1751                 ##########################
    1752                 ## SAVE LINKS AS POSTED ##
    1753                 ##########################
    1754                
    1755                 // Save only, if one or more elements are valid
    1756                 if ($_POST['count_elements'] != 0) {
    1757                     // Set currently time
    1758                     $time = time();
    1759                    
     1574            if (isset($_POST['mode'])) {
     1575                if ($_POST['mode'] == 'save') { // Save post
     1576                    ########################
     1577                    ## SET ENTRY BUILDING ##
     1578                    ########################
     1579                   
     1580                    // Set en empty example for entry building with replace
     1581                    $replaceEntryBuilding = $this->replaceEntryBuilding(false, false, false, false, false, false);
     1582                   
     1583                    // Set en empty example for entry building without replace
     1584                    $noReplaceEntryBuilding = $this->replaceEntryBuilding(false, false, false, false, false, false, false);
     1585                   
     1586                    // Check, which Array elements are dynamic. Set empy replace and flag in new array
    17601587                    $i = 0;
    1761                     while ($i < count($allPostedLinks)) {
    1762                         $sql = 'SELECT `id` FROM `' . $this->wpdb->prefix . 'wpstacker_posted_links` WHERE `url`="' . $allPostedLinks[$i][1] . '"';
    1763                         $row = $this->wpdb->get_results($sql);
    1764                        
    1765                         // Save only it already not saved
    1766                         if ($row[0]->id == '') {
    1767                             $sql = '
    1768                             INSERT IGNORE INTO `' . $this->wpdb->prefix . 'wpstacker_posted_links` (
    1769                                 `url`,
    1770                                 `timestamp`
    1771                             )
    1772                             VALUES
    1773                                 (%s, %s)
    1774                             ';
    1775                            
    1776                             // Save link as posted
    1777                             $this->wpdb->query(
    1778                                 $this->wpdb->prepare(
    1779                                     $sql,
    1780                                     $allPostedLinks[$i][1],
    1781                                     $time
    1782                                 )
     1588                    $exampleReplaceEntryBuilding = array();
     1589                    while($i < count($replaceEntryBuilding)) {
     1590                        if ($replaceEntryBuilding[$i] == $noReplaceEntryBuilding[$i]) {
     1591                            $exampleReplaceEntryBuilding[$i] = array(
     1592                                'example' => $replaceEntryBuilding[$i],
     1593                                'dynamic' => false
     1594                            );
     1595                        }else {
     1596                            $exampleReplaceEntryBuilding[$i] = array(
     1597                                'example' => $replaceEntryBuilding[$i],
     1598                                'dynamic' => true
    17831599                            );
    17841600                        }
     
    17861602                        $i++;
    17871603                    }
    1788                 }
    1789                
    1790                 #################################
    1791                 ## SET STATUS READED IN POCKET ##
    1792                 #################################
    1793                
    1794                 // Check if link should marke as readed
    1795                 if (get_option('wpstacker_mark_as_readed')) {
    1796                     $markAsReaded = array();
    1797                    
    1798                     // Fill JSON as Array
     1604                   
     1605                    // Unset not longer needed vars
     1606                    unset($replaceEntryBuilding);
     1607                    unset($noReplaceEntryBuilding);
     1608                   
     1609                    #####################################
     1610                    ## COMBINE URL, URL CLEANED AND ID ##
     1611                    #####################################
     1612                   
    17991613                    $i = 0;
    1800                     while ($i < count($allPostedLinks)) {
    1801                         $markAsReaded[] = array(
    1802                             'action' => 'archive',
    1803                             'item_id' => $allPostedLinks[$i][2]
     1614                    while ($i < (count($_POST['element']) / 9)) {
     1615                        $url = $_POST['element'][(($i * 9) + 2)]['url'];
     1616                        $urlUncleaned = $_POST['element'][(($i * 9) + 3)]['url_uncleaned'];
     1617                        $id = $_POST['element'][(($i * 9) + 6)]['id'];
     1618                       
     1619                        $_POST['element'][(($i * 9) + 2)] = array(
     1620                            array(
     1621                                $url,
     1622                                $urlUncleaned,
     1623                                $id
     1624                            )
    18041625                        );
    18051626                       
    1806                         $i++;
    1807                        
    1808                         // Chech if limit of links reached. If yes, send request and start new sends array
    1809                         if (($i / 100) == round($i / 100)) {
    1810                             // Send request
    1811                             $this->cURL(
    1812                                 'https://getpocket.com/v3/send',
    1813                                 array(
    1814                                     'consumer_key' => $this->xcrypt(1, get_option('wpstacker_pocket_consumer_key')),
    1815                                     'access_token' => $this->xcrypt(1, get_option('wpstacker_pocket_access_key')),
    1816                                     'actions' => json_encode($markAsReaded)
    1817                                 )
    1818                             );
    1819                            
    1820                             // Clean up array
    1821                             $markAsReaded = array();
    1822                         }
    1823                     }
    1824                    
    1825                     // Send request
    1826                     $this->cURL(
    1827                         'https://getpocket.com/v3/send',
    1828                         array(
    1829                             'consumer_key' => $this->xcrypt(1, get_option('wpstacker_pocket_consumer_key')),
    1830                             'access_token' => $this->xcrypt(1, get_option('wpstacker_pocket_access_key')),
    1831                             'actions' => json_encode($markAsReaded)
    1832                         )
    1833                     );
    1834                 }
    1835                
    1836                 // Send statistics, if allowed
    1837                 if (get_option('wpstacker_statistics') == 1) {
    1838                     $allLinksForStatisics = array();
    1839                     $i = 0;
    1840                     while ($i < count($allPostedLinks)) {
    1841                         $allLinksForStatisics[] = $allPostedLinks[$i][0];
    18421627                       
    18431628                        $i++;
    18441629                    }
    18451630                   
    1846                     $this->statisticsPublishPost($allLinksForStatisics);
     1631                    #########################
     1632                    ## SET ASSOCIATE LINKS ##
     1633                    #########################
     1634                    $i = 0;
     1635                    while ($i < (count($_POST['element']) / 9)) {
     1636                        // Check if this it not a associate link
     1637                        if (isset($_POST['element'][($i * 9) + 6]['associate']) && !$_POST['element'][($i * 9) + 6]['associate']) {
     1638                            // Search for associate links in the following
     1639                            $associateLinks = array();
     1640                            $i2 = 1;
     1641                            while(true) {
     1642                                // If this is an associate links, add this to the array, else break the while-loop
     1643                                if ($_POST['element'][($i * 9) + 8 + ($i2 * 9)]['associate']) {
     1644                                    $_POST['element'][($i * 9) + 2][] = $_POST['element'][(($i * 9) + 2 + ($i2 * 9))][0];
     1645                                }else {
     1646                                    break;
     1647                                }
     1648                               
     1649                                $i2++;
     1650                            }
     1651                        }
     1652                       
     1653                        $i++;
     1654                    }
     1655                   
     1656                    ####################
     1657                    ## GENNERATE POST ##
     1658                    ####################
     1659                   
     1660                    // Set posted elements in $_POST for view
     1661                    $_POST['count_elements'] = round((count($_POST['element']) / 9));
     1662                   
     1663                    // Array for all posted links
     1664                    $allPostedLinks = array();
     1665                   
     1666                    $post_content = '';
     1667                   
     1668                    // Gennerate all links in text
     1669                    $i = 0;
     1670                    while ($i < (count($_POST['element']) / 9)) {
     1671                        // Check if only not posted links should post
     1672                        if (get_option('wpstacker_links_to_use') == 0 || get_option('wpstacker_links_to_use') == 1 || get_option('wpstacker_links_to_use') == 2) {
     1673                            // Check if aleady posted. If true, confine to the next loop
     1674                            if (isset($_POST['element'][($i * 9) + 2]['url'])) {
     1675                                $url = $_POST['element'][($i * 9) + 2]['url'];
     1676                            }else {
     1677                                $url = '';
     1678                            }
     1679
     1680                            $sql = 'SELECT `id` FROM `' . $this->wpdb->prefix . 'wpstacker_posted_links` WHERE `url`="' . $url . '"';
     1681                            $row = $this->wpdb->get_results($sql);
     1682                           
     1683                            if (isset($row[0]->id) && $row[0]->id != '') {
     1684                                $_POST['count_elements'] -= count($_POST['element'][($i * 9) + 2]); // - this and associated elements
     1685                                $i++;
     1686                                continue;
     1687                            }
     1688                        }
     1689                       
     1690                        // Check if this it not a associate link
     1691                        if (!$_POST['element'][($i * 9) + 8]['associate']) {
     1692                            // Gennerate url array in url string
     1693                            $url = '';
     1694                           
     1695                            $i2 = 0;
     1696                            foreach ($_POST['element'][($i * 9) + 2] as $value) {
     1697                                if ($i2 != 0) {
     1698                                    $url .= '; ';
     1699                                }
     1700                               
     1701                                $url .= '<a href="' . $value[0] . '" target="_blank">' . $value[0] . '</a>';
     1702                               
     1703                                // Fill array for all posted links
     1704                                $allPostedLinks[] = $value;
     1705                               
     1706                                $i2++;
     1707                            }
     1708                           
     1709                            // Set element in entry building
     1710                            $element = $this->replaceEntryBuilding(
     1711                                $_POST['element'][($i * 9)]['title'],
     1712                                $_POST['element'][($i * 9) + 5]['description'],
     1713                                $url,
     1714                                $_POST['element'][($i * 9) + 4]['tags'],
     1715                                $_POST['element'][($i * 9) + 1]['author'],
     1716                                $_POST['element'][($i * 9) + 7]['countwords']
     1717                            );
     1718                           
     1719                            // Check if a dynamic element is not in use an delete it
     1720                            $i2 = 0;
     1721                            while ($i2 < count($element)) {
     1722                                if ($element[$i2] == $exampleReplaceEntryBuilding[$i2]['example'] && $exampleReplaceEntryBuilding[$i2]['dynamic']) {
     1723                                    unset($element[$i2]);
     1724                                }
     1725
     1726                                $i2++;
     1727                            }
     1728                           
     1729                            // Set element array as string for the post content
     1730                            $post_content .= '<p>';
     1731                           
     1732                            foreach ($element as $value) {
     1733                                $post_content .= $value;
     1734                            }
     1735                           
     1736                            $post_content .= '</p>';
     1737                        }
     1738                       
     1739                        $i++;
     1740                    }
     1741                   
     1742                    $post_content_final = '';
     1743                   
     1744                    // Set introduction text if not empty
     1745                    if (trim(get_option('wpstacker_introduction_text')) != '') {
     1746                        $post_content_final .= $this->getReplacedIntroductionText($_POST['count_elements']);
     1747                    }
     1748                   
     1749                    // Set links content
     1750                    $post_content_final .= $post_content;
     1751                   
     1752                    // Set statements text if not empty
     1753                    if (trim(get_option('wpstacker_statements_text')) != '') {
     1754                        $post_content_final .= $this->getReplacedStatementsText($_POST['count_elements']);
     1755                    }
     1756                   
     1757                    // Chech if reference to WP Stacker shot print
     1758                    if (get_option('wpstacker_reference_wpstacker')) {
     1759                        $post_content_final .= '<p><i>This post was automatically created by WP Stacker. If you look for this WordPress plugin, check out <a href="http://wp-stacker.com/" target="_blank">WP-Stacker.com</a> now!</i></p>';
     1760                    }
     1761                   
     1762                    ###############
     1763                    ## SAVE POST ##
     1764                    ###############
     1765                   
     1766                    // Save only, if one or more elements are valid
     1767                    if ($_POST['count_elements'] != 0) {
     1768                        // Set settings array
     1769                        $post = array(
     1770                            'comment_status' => get_option('wpstacker_comment_status'),
     1771                            'ping_status' => get_option('wpstacker_ping_status'),
     1772                            'post_author' => $current_user->ID,
     1773                            'post_category' => array(get_option('wpstacker_post_category')),
     1774                            'post_content' => $post_content_final,
     1775                            'post_date' => date('Y-m-d H:i:s'),
     1776                            'post_date_gmt' => gmdate('Y-m-d H:i:s'),
     1777                            'post_status' => get_option('wpstacker_post_status'),
     1778                            'post_title' => $this->getReplacedTitle($_POST['count_elements']),
     1779                            'post_type' => 'post'
     1780                        );
     1781                       
     1782                        // Insert the post
     1783                        $postId = wp_insert_post($post);
     1784                       
     1785                        // Set post format
     1786                        set_post_format($postId, get_option('wpstacker_post_format'));
     1787                    }
     1788                   
     1789                    ##########################
     1790                    ## SAVE LINKS AS POSTED ##
     1791                    ##########################
     1792                   
     1793                    // Save only, if one or more elements are valid
     1794                    if ($_POST['count_elements'] != 0) {
     1795                        // Set currently time
     1796                        $time = time();
     1797                       
     1798                        $i = 0;
     1799                        while ($i < count($allPostedLinks)) {
     1800                            $sql = 'SELECT `id` FROM `' . $this->wpdb->prefix . 'wpstacker_posted_links` WHERE `url`="' . $allPostedLinks[$i][1] . '"';
     1801                            $row = $this->wpdb->get_results($sql);
     1802                           
     1803                            // Save only it already not saved
     1804                            if ($row[0]->id == '') {
     1805                                $sql = '
     1806                                INSERT IGNORE INTO `' . $this->wpdb->prefix . 'wpstacker_posted_links` (
     1807                                    `url`,
     1808                                    `timestamp`
     1809                                )
     1810                                VALUES
     1811                                    (%s, %s)
     1812                                ';
     1813                               
     1814                                // Save link as posted
     1815                                $this->wpdb->query(
     1816                                    $this->wpdb->prepare(
     1817                                        $sql,
     1818                                        $allPostedLinks[$i][1],
     1819                                        $time
     1820                                    )
     1821                                );
     1822                            }
     1823                           
     1824                            $i++;
     1825                        }
     1826                    }
     1827                   
     1828                    #################################
     1829                    ## SET STATUS READED IN POCKET ##
     1830                    #################################
     1831                   
     1832                    // Check if link should marke as readed
     1833                    if (get_option('wpstacker_mark_as_readed')) {
     1834                        $markAsReaded = array();
     1835                       
     1836                        // Fill JSON as Array
     1837                        $i = 0;
     1838                        while ($i < count($allPostedLinks)) {
     1839                            $markAsReaded[] = array(
     1840                                'action' => 'archive',
     1841                                'item_id' => $allPostedLinks[$i][2]
     1842                            );
     1843                           
     1844                            $i++;
     1845                           
     1846                            // Chech if limit of links reached. If yes, send request and start new sends array
     1847                            if (($i / 100) == round($i / 100)) {
     1848                                // Send request
     1849                                $this->cURL(
     1850                                    'https://getpocket.com/v3/send',
     1851                                    array(
     1852                                        'consumer_key' => $this->xcrypt(1, get_option('wpstacker_pocket_consumer_key')),
     1853                                        'access_token' => $this->xcrypt(1, get_option('wpstacker_pocket_access_key')),
     1854                                        'actions' => json_encode($markAsReaded)
     1855                                    )
     1856                                );
     1857                               
     1858                                // Clean up array
     1859                                $markAsReaded = array();
     1860                            }
     1861                        }
     1862                       
     1863                        // Send request
     1864                        $this->cURL(
     1865                            'https://getpocket.com/v3/send',
     1866                            array(
     1867                                'consumer_key' => $this->xcrypt(1, get_option('wpstacker_pocket_consumer_key')),
     1868                                'access_token' => $this->xcrypt(1, get_option('wpstacker_pocket_access_key')),
     1869                                'actions' => json_encode($markAsReaded)
     1870                            )
     1871                        );
     1872                    }
     1873                   
     1874                    // Send statistics, if allowed
     1875                    if (get_option('wpstacker_statistics') == 1) {
     1876                        $allLinksForStatisics = array();
     1877                        $i = 0;
     1878                        while ($i < count($allPostedLinks)) {
     1879                            $allLinksForStatisics[] = $allPostedLinks[$i][0];
     1880                           
     1881                            $i++;
     1882                        }
     1883                       
     1884                        $this->statisticsPublishPost($allLinksForStatisics);
     1885                    }
    18471886                }
    18481887            }
  • wp-stacker/trunk/css/support.css

    r751169 r821860  
    77    padding: 10px;
    88   
    9     background: #FEFEDB;
    10     border: 1px solid #2D2D2D;
     9    background: #FFFFFF;
     10    border-left: 4px solid #DD3D36;
     11
     12    webkit-box-shadow: 0 1px 1px 0 rgba(0,0,0,.1);
     13    box-shadow: 0 1px 1px 0 rgba(0,0,0,.1);
    1114   
    1215    text-align: center;
  • wp-stacker/trunk/readme.txt

    r751169 r821860  
    33Tags: wp stacker, wordpress, pocket, post, automaticly, wp, links, linklist
    44Requires at least: 3.4
    5 Tested up to: 3.6
    6 Stable tag: 1.6
     5Tested up to: 3.8
     6Stable tag: 1.7
    77License: GPLv2 or later
    88License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    5050
    5151== Changelog ==
     52
     53
     54= 1.7 =
     55* Fixed compatibility with WordPress 3.8
     56* Changed design elements for WordPress 3.8
     57* Reduced PHP notices
    5258
    5359= 1.6 =
  • wp-stacker/trunk/wp-stacker.php

    r751169 r821860  
    66    Author: Jan Karres
    77    Author URI: http://jankarres.de/
    8     Version: 1.6
     8    Version: 1.7
    99*/
    1010
     
    1919        function __construct() {
    2020            global $wpdb;
    21            
     21
    2222            // Set database
    2323            $this->wpdb = $wpdb;
    2424           
    2525            // Set plugin version
    26             $this->version = '1.6';
     26            $this->version = '1.7';
    2727       
    2828            // Check WP version
    2929            add_action('init', array(&$this, 'requires_versions'));
    30        
     30           
    3131            // Change plugin status hooks
    3232            register_activation_hook(__FILE__, array(&$this, 'activate'));
     
    4040           
    4141            // Add javascripts of the plugin in the system
    42             wp_register_script('wpstacker_main', plugins_url('js/main.js', __FILE__), array('jquery', 'jquery-ui-core', 'jquery-ui-draggable', 'jquery-ui-droppable'));
     42            @wp_register_script('wpstacker_main', plugins_url('js/main.js', __FILE__), array('jquery', 'jquery-ui-core', 'jquery-ui-draggable', 'jquery-ui-droppable'));
    4343           
    4444            // Pocket default Consumer-Key by developer
     
    181181             
    182182            $characters = '0123456789qwertzuiopasdfghjklyxcvbnmQWERTZUIOPASDFGHJKLYXCVBNM';
    183            
     183            $key = '';
    184184            for ($i = 0; $i < $length; $i++) {
    185185                $key .= $characters[mt_rand(0, strlen($characters) - 1)];
     
    198198           
    199199            // Get crypt keys, if should
     200            $key = array();
     201            $keys = array();
     202            $key['a'] = '';
     203            $key['b'] = '';
     204            $keys['a'] = '';
     205            $keys['b'] = '';
    200206            if (!$nosalt) {
    201207                $keys['a'] = get_option('wpstacker_key_a');
     
    231237            // Save POST parameter in one string
    232238            if (count($post) != 0) {
     239                $postAsString = '';
    233240                $i = 0;
    234241                foreach ($post as $key => $value) {
     
    334341            // Filter $_GET[p], falls vorhanden, aus link
    335342            preg_match('/p=(.*)/', $url, $matches);
    336             $matches = explode('&', $matches[0]);
     343            if (count($matches) != 0) {
     344                $matches = explode('&', $matches[0]);
     345            }   
    337346           
    338347            // Clean url
     
    669678                <h3>support me</h3>
    670679               
    671                 <p>If you use the plugin and like it, you can say thanks and support me. How?</p>
     680                <p>If you use the plugin and like it, you can say thanks and support me.</p>
    672681               
    673682                <h3>follow me on twitter</h3>
     
    696705        function options_link() {
    697706            // Start the view of the options page
    698             add_options_page('WP Stacker Settings', 'WP Stacker', 5, 'settings_pocket_poster', array($this, 'options_page_view'));
     707            add_options_page('WP Stacker Settings', 'WP Stacker', 'edit_pages', 'settings_pocket_poster', array($this, 'options_page_view'));
    699708           
    700709            // Setzte Link
     
    10061015        function options_page_controller() {
    10071016            // Solve escape errors
    1008             $_POST['wpstacker_title'] = stripslashes_deep($_POST['wpstacker_title']);
    1009             $_POST['wpstacker_entry_building'] = stripslashes_deep($_POST['wpstacker_entry_building']);
    1010             $_POST['wpstacker_introduction_text'] = stripslashes_deep($_POST['wpstacker_introduction_text']);
    1011             $_POST['wpstacker_statements_text'] = stripslashes_deep($_POST['wpstacker_statements_text']);
     1017            if (isset($_POST['wpstacker_title'] )) { $_POST['wpstacker_title'] = stripslashes_deep($_POST['wpstacker_title']); }
     1018            if (isset($_POST['wpstacker_entry_building'])) { $_POST['wpstacker_entry_building'] = stripslashes_deep($_POST['wpstacker_entry_building']); }
     1019            if (isset($_POST['wpstacker_introduction_text'])) { $_POST['wpstacker_introduction_text'] = stripslashes_deep($_POST['wpstacker_introduction_text']); }
     1020            if (isset($_POST['wpstacker_statements_text'])) { $_POST['wpstacker_statements_text'] = stripslashes_deep($_POST['wpstacker_statements_text']); }
    10121021       
    10131022            // Check if should start Pocket auth process
     
    10321041           
    10331042            // Check if setting sended
    1034             if ($_POST['wpstacker_edit']) {
     1043            if (isset($_POST['wpstacker_edit'])
     1044                && $_POST['wpstacker_edit']
     1045                ) {
    10351046                // Error Array
    10361047                $error = array();
     
    10441055           
    10451056                // Update "Pocket Login"
    1046                
    1047                 if ($_POST['wpstacker_pocket_consumer_key_custom_remove'] == 1) {
     1057                $changeConsumerKey = false;
     1058                if (isset($_POST['wpstacker_pocket_consumer_key_custom_remove'])
     1059                    && $_POST['wpstacker_pocket_consumer_key_custom_remove'] == 1) {
    10481060                    // Set default key
    10491061                    update_option('wpstacker_pocket_consumer_key_custom', 0);
     
    11891201        // Function to set the main page
    11901202        function main_link() {
     1203            global $wp_version;
     1204
     1205            if (version_compare($wp_version, '3.7', '<')) {
     1206                $iconPng = 'images/icons/16_upto_wp37.png';
     1207            }else {
     1208                $iconPng = 'images/icons/16.png';
     1209            }
    11911210            // Start the view of the main page
    1192             add_menu_page('WP Stacker', 'WP Stacker', 5, 'pocket_poster', array($this, 'main_page_view'), plugin_dir_url(__FILE__) . 'images/icons/16.png', 32);
     1211            add_menu_page('WP Stacker', 'WP Stacker', 'edit_pages', 'pocket_poster', array($this, 'main_page_view'), plugin_dir_url(__FILE__) . $iconPng, 32);
    11931212        }
    11941213       
     
    12001219
    12011220            // Add JavaScript functions
    1202             wp_enqueue_script('jquery-ui-draggable');
    1203             wp_enqueue_script('jquery-ui-droppable');
     1221            wp_enqueue_script('droppable');
    12041222            wp_enqueue_script('nav-menu');
    1205             wp_enqueue_script('postbox');
    12061223            wp_enqueue_script('wpstacker_main');
    12071224            ?>
     
    12221239                <?php
    12231240                // Check if only elements with a tag shoul loaded (pre-check)
    1224                 if ($_POST['mode'] == 'get' && $_POST['onlyWithTag']) { // Get Elements
    1225                     // Check if tag is not empty
    1226                     if ($_POST['tag'] == '') {
    1227                         // Redict to main start page with error
    1228                         unset($_POST['mode']);
     1241                if (isset($_POST['mode'])) {
     1242                    if ($_POST['mode'] == 'get' && isset($_POST['onlyWithTag']) && $_POST['onlyWithTag']) { // Get Elements
     1243                        // Check if tag is not empty
     1244                        if (isset($_POST['tag'])) {
     1245                            if ($_POST['tag'] == '') {
     1246                                // Redict to main start page with error
     1247                                unset($_POST['mode']);
     1248                            }
     1249                        }
    12291250                    }
    12301251                }
     
    12321253               
    12331254                <?php
    1234                 if ($_POST['mode'] != 'get') {
    1235                     $this->support_div();
     1255                if (isset($_POST['mode'])) {
     1256                    if ($_POST['mode'] != 'get') {
     1257                        $this->support_div();
     1258                    }
    12361259                }
    12371260                ?>
     
    12411264                <?php
    12421265                // Check if should get Pocket elements or save as post
    1243                 if ($_POST['mode'] == 'get') { // Get Elements
    1244                     // Check Pocket Access
    1245                     $checkPocketAccess = $this->checkPocketAccess();
    1246                    
    1247                     // Check if access is valid
    1248                     if ($checkPocketAccess) {               
    1249                         // Get links from the user
    1250                         $getLinksPost = array();
     1266                if (
     1267                    isset($_POST['mode'])
     1268                    && $_POST['mode'] != ''
     1269                    ) {
     1270                    if ($_POST['mode'] == 'get') { // Get Elements
     1271                        // Check Pocket Access
     1272                        $checkPocketAccess = $this->checkPocketAccess();
    12511273                       
    1252                         $getLinksPost['consumer_key'] = $this->xcrypt(1, get_option('wpstacker_pocket_consumer_key'));
    1253                         $getLinksPost['access_token'] = $this->xcrypt(1, get_option('wpstacker_pocket_access_key'));
    1254                         $getLinksPost['detailType'] = 'complete';
    1255                        
    1256                         // Should get Readed, unreaded or all links?
    1257                         if (get_option('wpstacker_links_to_use') == 0 || get_option('wpstacker_links_to_use') == 3) { // Unreaded
    1258                             $getLinksPost['state'] = 'unread';
    1259                         }elseif (get_option('wpstacker_links_to_use') == 1 || get_option('wpstacker_links_to_use') == 4) { // Readed / Archived
    1260                             $getLinksPost['state'] = 'archive';
    1261                         }else { // All
    1262                             $getLinksPost['state'] = 'all';
    1263                         }
    1264                        
    1265                         // Check if only faved or unfaved links should use
    1266                         if (get_option('wpstacker_faved') == 1) { // only faved
    1267                             $getLinksPost['favorite'] = '1';
    1268                         }else if (get_option('wpstacker_faved') == 2) { // only unfaved
    1269                             $getLinksPost['favorite'] = '0';
    1270                         } // All
    1271                        
    1272                         // Check if order should be oldest to newest or newest to oldest
    1273                         if (get_option('wpstacker_order')) { // oldest to newest
    1274                             $getLinksPost['sort'] = 'oldest';
    1275                         }else { // newest to oldest
    1276                             $getLinksPost['sort'] = 'newest';
    1277                         }
    1278                        
    1279                         // Check if only links with a tag should load
    1280                         if ($_POST['onlyWithTag']) {
    1281                             $getLinksPost['tag'] = stripslashes_deep($_POST['tag']);
    1282                         }
    1283                        
    1284                         $getLinks = $this->cURL(
    1285                             'https://getpocket.com/v3/get',
    1286                             $getLinksPost
    1287                         );
    1288                        
    1289                         // Decode JSON to Object
    1290                         $getLinks = json_decode($getLinks);
    1291                        
    1292                         // Check if only not posted links should post
    1293                         if (get_option('wpstacker_links_to_use') == 0 || get_option('wpstacker_links_to_use') == 1 || get_option('wpstacker_links_to_use') == 2) {
    1294                             // Remove all already posted links
    1295                             foreach ($getLinks->list as $key => $value) {
    1296                                 // Check if aleady posted. If true, remove it
    1297                                 $sql = 'SELECT `id` FROM `' . $this->wpdb->prefix . 'wpstacker_posted_links` WHERE `url`="' . $value->given_url . '"';
    1298                                 $row = $this->wpdb->get_results($sql);
    1299                                
    1300                                 if ($row[0]->id != '') {
    1301                                     unset($getLinks->list->$key);
     1274                        // Check if access is valid
     1275                        if ($checkPocketAccess) {               
     1276                            // Get links from the user
     1277                            $getLinksPost = array();
     1278                           
     1279                            $getLinksPost['consumer_key'] = $this->xcrypt(1, get_option('wpstacker_pocket_consumer_key'));
     1280                            $getLinksPost['access_token'] = $this->xcrypt(1, get_option('wpstacker_pocket_access_key'));
     1281                            $getLinksPost['detailType'] = 'complete';
     1282                           
     1283                            // Should get Readed, unreaded or all links?
     1284                            if (get_option('wpstacker_links_to_use') == 0 || get_option('wpstacker_links_to_use') == 3) { // Unreaded
     1285                                $getLinksPost['state'] = 'unread';
     1286                            }elseif (get_option('wpstacker_links_to_use') == 1 || get_option('wpstacker_links_to_use') == 4) { // Readed / Archived
     1287                                $getLinksPost['state'] = 'archive';
     1288                            }else { // All
     1289                                $getLinksPost['state'] = 'all';
     1290                            }
     1291                           
     1292                            // Check if only faved or unfaved links should use
     1293                            if (get_option('wpstacker_faved') == 1) { // only faved
     1294                                $getLinksPost['favorite'] = '1';
     1295                            }else if (get_option('wpstacker_faved') == 2) { // only unfaved
     1296                                $getLinksPost['favorite'] = '0';
     1297                            } // All
     1298                           
     1299                            // Check if order should be oldest to newest or newest to oldest
     1300                            if (get_option('wpstacker_order')) { // oldest to newest
     1301                                $getLinksPost['sort'] = 'oldest';
     1302                            }else { // newest to oldest
     1303                                $getLinksPost['sort'] = 'newest';
     1304                            }
     1305                           
     1306                            // Check if only links with a tag should load
     1307                            if (isset($_POST['onlyWithTag']) && $_POST['onlyWithTag']) {
     1308                                $getLinksPost['tag'] = stripslashes_deep($_POST['tag']);
     1309                            }
     1310                           
     1311                            $getLinks = $this->cURL(
     1312                                'https://getpocket.com/v3/get',
     1313                                $getLinksPost
     1314                            );
     1315                           
     1316                            // Decode JSON to Object
     1317                            $getLinks = json_decode($getLinks);
     1318                           
     1319                            // Check if only not posted links should post
     1320                            if (get_option('wpstacker_links_to_use') == 0 || get_option('wpstacker_links_to_use') == 1 || get_option('wpstacker_links_to_use') == 2) {
     1321                                // Remove all already posted links
     1322                                foreach ($getLinks->list as $key => $value) {
     1323                                    // Check if aleady posted. If true, remove it
     1324                                    $sql = 'SELECT `id` FROM `' . $this->wpdb->prefix . 'wpstacker_posted_links` WHERE `url`="' . $value->given_url . '"';
     1325                                    $row = $this->wpdb->get_results($sql);
     1326                                   
     1327                                    if (isset($row[0]->id) && $row[0]->id != '') {
     1328                                        unset($getLinks->list->$key);
     1329                                    }
    13021330                                }
    13031331                            }
    1304                         }
    1305                        
    1306                         if (count((array)$getLinks->list) == 0) { // No elements
    1307                             ?>
    1308                             <?php $this->support_div(); ?>
    1309                            
    1310                             <p><strong>You do not have usable elements<?php
    1311                             if ($_POST['onlyWithTag'] && $_POST['tag'] != '') {
    1312                                 echo ' with the tag <i>' . stripslashes_deep($_POST['tag']) . '</i>';
    1313                             }
    1314                             ?> in your Pocket account! Is the <i>Links to use</i> setting correct?</strong></p>
    1315                             <p>You have to look for interesting links, before you can post them ;-)</p>
    1316                             <?php
    1317                         }else {
    1318                             ?>
    1319                             <?php $this->support_div(false); ?>
    1320                            
    1321                             <p class="wpstacker_loader" style="width: 308px; margin: 15px 0 0 0; text-align: center;">
    1322                                 <img src="<?php echo plugins_url('images/loading.gif', __FILE__) ?>" alt="loading" /><br />
    1323                                 <strong>Please wait while loading...</strong>
    1324                             </p>
    1325                            
    1326                             <form id="update-nav-menu" action="" method="post" enctype="multipart/form-data" style="display: none;">
    1327                                 <p><br /><strong>Please edit, sort and associate the links. If you finished, please click on the <i>Generate post</i> button at the end of the list!</strong></p>
    1328                                 <?php echo '<p>Number of links: <span class="number-links">' . count((array)$getLinks->list) . '</span></p>'; ?>
     1332                           
     1333                            if (count((array)$getLinks->list) == 0) { // No elements
     1334                                ?>
     1335                                <?php $this->support_div(); ?>
    13291336                               
    1330                                 <ul class="menu ui-sortable" id="menu-to-edit">
    1331                                     <?php
    1332                                     // Gennerate output of each link
    1333                                     foreach ($getLinks->list as $key => $value) {
    1334                                         // Rewirte Tags Array as Tags string
    1335                                         if (count($value->tags) != 0) {
    1336                                             $tagsAsString = '';
    1337                                             $i2 = 0;
    1338                                             foreach ($value->tags as $tag) {
    1339                                                 if ($i2 != 0) {
    1340                                                     $tagsAsString .= ', ';
     1337                                <p><strong>You do not have usable elements<?php
     1338                                if (isset($_POST['onlyWithTag']) && $_POST['onlyWithTag'] && $_POST['tag'] != '') {
     1339                                    echo ' with the tag <i>' . stripslashes_deep($_POST['tag']) . '</i>';
     1340                                }
     1341                                ?> in your Pocket account! Is the <i>Links to use</i> setting correct?</strong></p>
     1342                                <p>You have to look for interesting links, before you can post them ;-)</p>
     1343                                <?php
     1344                            }else {
     1345                                ?>
     1346                                <?php $this->support_div(false); ?>
     1347                               
     1348                                <p class="wpstacker_loader" style="width: 308px; margin: 15px 0 0 0; text-align: center;">
     1349                                    <img src="<?php echo plugins_url('images/loading.gif', __FILE__) ?>" alt="loading" /><br />
     1350                                    <strong>Please wait while loading...</strong>
     1351                                </p>
     1352                               
     1353                                <form id="update-nav-menu" action="" method="post" enctype="multipart/form-data" style="display: none;">
     1354                                    <p><br /><strong>Please edit, sort and associate the links. If you finished, please click on the <i>Generate post</i> button at the end of the list!</strong></p>
     1355                                    <?php echo '<p>Number of links: <span class="number-links">' . count((array)$getLinks->list) . '</span></p>'; ?>
     1356                                   
     1357                                    <ul class="menu ui-sortable" id="menu-to-edit">
     1358                                        <?php
     1359                                        // Gennerate output of each link
     1360                                        foreach ($getLinks->list as $key => $value) {
     1361                                            // Rewirte Tags Array as Tags string
     1362                                            if (isset($value->tags) && count($value->tags) != 0) {
     1363                                                $tagsAsString = '';
     1364                                                $i2 = 0;
     1365                                                foreach ($value->tags as $tag) {
     1366                                                    if ($i2 != 0) {
     1367                                                        $tagsAsString .= ', ';
     1368                                                    }
     1369                                                   
     1370                                                    $tagsAsString .= $tag->tag;
     1371                                                   
     1372                                                    $i2++;
    13411373                                                }
    13421374                                               
    1343                                                 $tagsAsString .= $tag->tag;
    1344                                                
    1345                                                 $i2++;
     1375                                                $value->tags = $tagsAsString;
     1376                                                unset($tagsAsString);
     1377                                            }else { // Not tags yet
     1378                                                $value->tags = '';
    13461379                                            }
    13471380                                           
    1348                                             $value->tags = $tagsAsString;
    1349                                             unset($tagsAsString);
    1350                                         }else { // Not tags yet
    1351                                             $value->tags = '';
    1352                                         }
    1353                                        
    1354                                         // Get data from the meta tags, if necessary
    1355                                         if ($value->resolved_title == '' || $value->excerpt == '' || (get_option('wpstacker_meta_keyword_as_tags') == 1 && $value->tags == '')) {
    1356                                             $urlHtml = $this->cURL($value->given_url, array());
    1357                                            
    1358                                             $doc = new DOMDocument();
    1359                                             @$doc->loadHTML($urlHtml);
    1360                                            
    1361                                             if ($value->resolved_title == '') {
    1362                                                 $nodes = $doc->getElementsByTagName('title');
    1363                                                 $value->title = utf8_decode($nodes->item(0)->nodeValue);
     1381                                            // Get data from the meta tags, if necessary
     1382                                            if ($value->resolved_title == '' || $value->excerpt == '' || (get_option('wpstacker_meta_keyword_as_tags') == 1 && $value->tags == '')) {
     1383                                                $urlHtml = $this->cURL($value->given_url, array());
    13641384                                               
    1365                                                 if (!$this->is_utf8($value->title)) {
    1366                                                     $value->title = utf8_encode($value->title);
    1367                                                 }
    1368                                             }
    1369                                            
    1370                                             $metas = $doc->getElementsByTagName('meta');
    1371                                            
    1372                                             for ($i = 0; $i < $metas->length; $i++) {
    1373                                                 $meta = $metas->item($i);
     1385                                                $doc = new DOMDocument();
     1386                                                @$doc->loadHTML($urlHtml);
    13741387                                               
    1375                                                 if ($value->excerpt == '') {
    1376                                                     if($meta->getAttribute('name') == 'description') {
    1377                                                         $value->excerpt = utf8_decode($meta->getAttribute('content'));
    1378                                                         if (!$this->is_utf8($value->excerpt)) {
    1379                                                             $value->excerpt = utf8_encode($value->excerpt);
    1380                                                         }
     1388                                                if ($value->resolved_title == '') {
     1389                                                    $nodes = $doc->getElementsByTagName('title');
     1390                                                    $value->title = utf8_decode($nodes->item(0)->nodeValue);
     1391                                                   
     1392                                                    if (!$this->is_utf8($value->title)) {
     1393                                                        $value->title = utf8_encode($value->title);
    13811394                                                    }
    13821395                                                }
    13831396                                               
    1384                                                 if (get_option('wpstacker_meta_keyword_as_tags') == 1 && $value->tags == '') {
    1385                                                     if ($meta->getAttribute('name') == 'keywords') {
    1386                                                         $value->tags = utf8_decode($meta->getAttribute('content'));
    1387                                                         if (!$this->is_utf8($value->tags)) {
    1388                                                             $value->tags = utf8_encode($value->tags);
     1397                                                $metas = $doc->getElementsByTagName('meta');
     1398                                               
     1399                                                for ($i = 0; $i < $metas->length; $i++) {
     1400                                                    $meta = $metas->item($i);
     1401                                                   
     1402                                                    if ($value->excerpt == '') {
     1403                                                        if($meta->getAttribute('name') == 'description') {
     1404                                                            $value->excerpt = utf8_decode($meta->getAttribute('content'));
     1405                                                            if (!$this->is_utf8($value->excerpt)) {
     1406                                                                $value->excerpt = utf8_encode($value->excerpt);
     1407                                                            }
     1408                                                        }
     1409                                                    }
     1410                                                   
     1411                                                    if (get_option('wpstacker_meta_keyword_as_tags') == 1 && $value->tags == '') {
     1412                                                        if ($meta->getAttribute('name') == 'keywords') {
     1413                                                            $value->tags = utf8_decode($meta->getAttribute('content'));
     1414                                                            if (!$this->is_utf8($value->tags)) {
     1415                                                                $value->tags = utf8_encode($value->tags);
     1416                                                            }
    13891417                                                        }
    13901418                                                    }
    13911419                                                }
    13921420                                            }
    1393                                         }
    1394                                         ?>
    1395                                         <li class="menu-item-edit-inactive">
    1396                                             <dl class="menu-item-bar">
    1397                                                 <dt class="menu-item-handle">
    1398                                                     <div class="left">
    1399                                                         <?php echo $value->resolved_title; ?>
    1400                                                     </div>
    1401                                                     <div class="right">
    1402                                                         <a class="item-remove" href="#item-remove-<?php echo $key; ?>">Remove element</a>
    1403                                                         <a class="item-edit" href="#item-<?php echo $key; ?>">Edit element</a>
    1404                                                     </div>
    1405                                                 </dt>
    1406                                             </dl>
     1421                                            ?>
     1422                                            <li class="menu-item-edit-inactive">
     1423                                                <dl class="menu-item-bar">
     1424                                                    <dt class="menu-item-handle">
     1425                                                        <div class="left">
     1426                                                            <?php echo $value->resolved_title; ?>
     1427                                                        </div>
     1428                                                        <div class="right">
     1429                                                            <a class="item-remove" href="#item-remove-<?php echo $key; ?>">Remove element</a>
     1430                                                            <a class="item-edit" href="#item-<?php echo $key; ?>">Edit element</a>
     1431                                                        </div>
     1432                                                    </dt>
     1433                                                </dl>
    14071434
    1408                                             <div class="menu-item-settings" id="item-<?php echo $key; ?>">
    1409                                                 <p class="description description-thin description-two-thirds">
    1410                                                     <label for="item-<?php echo $key; ?>-input-title">
    1411                                                         Title<br />
    1412                                                         <input type="text" id="item-<?php echo $key; ?>-input-title" class="widefat input-title" name="element[][title]" value="<?php echo $value->resolved_title; ?>" />
    1413                                                     </label>
    1414                                                 </p>
    1415                                                 <p class="description description-thin description-one-thirds">
    1416                                                     <label for="item-<?php echo $key; ?>-input-author">
    1417                                                         Author<br />
    1418                                                         <input type="text" id="item-<?php echo $key; ?>-input-author" class="widefat" name="element[][author]" value="<?php
    1419                                                             if (count($value->authors) != 0) {
    1420                                                                 $i2 = 0;
    1421                                                                 foreach($value->authors as $author) {
    1422                                                                     if ($i2 != 0) {
    1423                                                                         echo ', ';
     1435                                                <div class="menu-item-settings" id="item-<?php echo $key; ?>">
     1436                                                    <p class="description description-thin description-two-thirds">
     1437                                                        <label for="item-<?php echo $key; ?>-input-title">
     1438                                                            Title<br />
     1439                                                            <input type="text" id="item-<?php echo $key; ?>-input-title" class="widefat input-title" name="element[][title]" value="<?php echo $value->resolved_title; ?>" />
     1440                                                        </label>
     1441                                                    </p>
     1442                                                    <p class="description description-thin description-one-thirds">
     1443                                                        <label for="item-<?php echo $key; ?>-input-author">
     1444                                                            Author<br />
     1445                                                            <input type="text" id="item-<?php echo $key; ?>-input-author" class="widefat" name="element[][author]" value="<?php
     1446                                                                if (isset($value->authors) && count($value->authors) != 0) {
     1447                                                                    $i2 = 0;
     1448                                                                    foreach($value->authors as $author) {
     1449                                                                        if ($i2 != 0) {
     1450                                                                            echo ', ';
     1451                                                                        }
     1452                                                                       
     1453                                                                        echo $author->name;
     1454                                                                       
     1455                                                                        $i2++;
    14241456                                                                    }
    1425                                                                    
    1426                                                                     echo $author->name;
    1427                                                                    
    1428                                                                     $i2++;
    14291457                                                                }
    1430                                                             }
    1431                                                         ?>" />
    1432                                                     </label>
    1433                                                 </p>
    1434                                                 <p class="description description-thin description-two-thirds">
    1435                                                     <label for="item-<?php echo $key; ?>-input-url">
    1436                                                         URL<br />
    1437                                                         <input type="text" id="item-<?php echo $key; ?>-input-url" class="widefat" name="element[][url]" value="<?php if (get_option('wpstacker_clean_url') == 1) { echo $this->cleanUpURL($value->resolved_url); }else { echo $value->given_url; } ?>" />
    1438                                                         <input type="hidden" id="item-<?php echo $key; ?>-input-url" class="widefat" name="element[][url_uncleaned]" value="<?php echo $value->given_url; ?>" />
    1439                                                     </label>
    1440                                                 </p>
    1441                                                 <p class="description description-thin description-one-thirds">
    1442                                                     <label for="item-<?php echo $key; ?>-input-tags">
    1443                                                         Tags<br />
    1444                                                         <input type="text" id="item-<?php echo $key; ?>-input-tags" class="widefat" name="element[][tags]" value="<?php echo $value->tags; ?>" />
    1445                                                     </label>
    1446                                                 </p>
    1447                                                 <p class="description">
    1448                                                     <label for="item-<?php echo $key; ?>-input-description">
    1449                                                         Description (optional)<br />
    1450                                                         <textarea name="element[][description]" rows="4" id="item-<?php echo $key; ?>-input-description" class="widefat" type="textarea"><?php echo $value->excerpt; ?></textarea>
    1451                                                     </label>
    1452                                                 </p>
    1453                                                
    1454                                                
    1455                                                 <input type="hidden" name="element[][id]" value="<?php echo $value->item_id; ?>" />
    1456                                                 <input type="hidden" name="element[][countwords]" value="<?php echo $value->word_count; ?>" />
    1457                                                 <input type="hidden" name="element[][associate]" class="associate" value="0" />
    1458                                             </div>
    1459                                         </li>
    1460                                     <?php } ?>
    1461                                 </ul>
    1462                                
    1463                                 <p class="submit">
    1464                                     <input type="hidden" name="mode" value="save" />
    1465                                     <input type="submit" name="save_menu" class="button-primary" value="Gennerate post" />
    1466                                     <strong>This can take up to 30 seconds!</strong>
    1467                                 </p>
    1468                             </form>
     1458                                                            ?>" />
     1459                                                        </label>
     1460                                                    </p>
     1461                                                    <p class="description description-thin description-two-thirds">
     1462                                                        <label for="item-<?php echo $key; ?>-input-url">
     1463                                                            URL<br />
     1464                                                            <input type="text" id="item-<?php echo $key; ?>-input-url" class="widefat" name="element[][url]" value="<?php if (get_option('wpstacker_clean_url') == 1) { echo $this->cleanUpURL($value->resolved_url); }else { echo $value->given_url; } ?>" />
     1465                                                            <input type="hidden" id="item-<?php echo $key; ?>-input-url" class="widefat" name="element[][url_uncleaned]" value="<?php echo $value->given_url; ?>" />
     1466                                                        </label>
     1467                                                    </p>
     1468                                                    <p class="description description-thin description-one-thirds">
     1469                                                        <label for="item-<?php echo $key; ?>-input-tags">
     1470                                                            Tags<br />
     1471                                                            <input type="text" id="item-<?php echo $key; ?>-input-tags" class="widefat" name="element[][tags]" value="<?php echo $value->tags; ?>" />
     1472                                                        </label>
     1473                                                    </p>
     1474                                                    <p class="description">
     1475                                                        <label for="item-<?php echo $key; ?>-input-description">
     1476                                                            Description (optional)<br />
     1477                                                            <textarea name="element[][description]" rows="4" id="item-<?php echo $key; ?>-input-description" class="widefat" type="textarea"><?php if (isset($value->excerpt)) { echo $value->excerpt; } ?></textarea>
     1478                                                        </label>
     1479                                                    </p>
     1480                                                   
     1481                                                   
     1482                                                    <input type="hidden" name="element[][id]" value="<?php echo $value->item_id; ?>" />
     1483                                                    <input type="hidden" name="element[][countwords]" value="<?php echo $value->word_count; ?>" />
     1484                                                    <input type="hidden" name="element[][associate]" class="associate" value="0" />
     1485                                                </div>
     1486                                            </li>
     1487                                        <?php } ?>
     1488                                    </ul>
     1489                                   
     1490                                    <p class="submit">
     1491                                        <input type="hidden" name="mode" value="save" />
     1492                                        <input type="submit" name="save_menu" class="button-primary" value="Gennerate post" />
     1493                                        <strong>This can take up to 30 seconds!</strong>
     1494                                    </p>
     1495                                </form>
     1496                                <?php
     1497                            }
     1498                        }
     1499                    }elseif ($_POST['mode'] == 'save') { // Save post
     1500                        // Check if elements was lposted
     1501                        if ($_POST['count_elements'] == 0) { // No elements
     1502                            ?>
     1503                            <p><strong>No elements to post were found. Is the <i>Links to use</i> setting correct?</strong></strong></p>
     1504                            <p>You have to look for interesting links, before you can post them ;-)</p>
     1505                            <?php
     1506                        }else { // Success
     1507                            ?>
     1508                            <p class="short"><strong>Great! You posted <?php echo $_POST['count_elements']; ?> links from your Pocket account into your blog. <?php if (isset($_POST['wpstacker_mark_as_readed']) && $_POST['wpstacker_mark_as_readed']) { ?>They are now marked as read in your pocket account!<?php } ?></strong></p>
     1509                            <p class="short">If you like WP Stacker, I would be pleased, if you supported me. How to? Look in the yellow box on the right!</p>
    14691510                            <?php
    14701511                        }
    14711512                    }
    1472                 }elseif ($_POST['mode'] == 'save') { // Save post
    1473                     // Check if elements was lposted
    1474                     if ($_POST['count_elements'] == 0) { // No elements
    1475                         ?>
    1476                         <p><strong>No elements to post were found. Is the <i>Links to use</i> setting correct?</strong></strong></p>
    1477                         <p>You have to look for interesting links, before you can post them ;-)</p>
    1478                         <?php
    1479                     }else { // Success
    1480                         ?>
    1481                         <p class="short"><strong>Great! You posted <?php echo $_POST['count_elements']; ?> links from your Pocket account into your blog. <?php if ($_POST['wpstacker_mark_as_readed']) { ?>[18:56:01] Elias: They are now marked as read in your pocket account!<?php } ?></strong></p>
    1482                         <p class="short">If you like WP Stacker, I would be pleased, if you supported me. How to? Look in the yellow box on the right!</p>
    1483                         <?php
    1484                     }
    14851513                }else { // Print introduction
    14861514                    // Check if form already sent, tag requied and not set
    1487                     if ($_POST['onlyWithTag']) {
     1515                    if (
     1516                        isset($_POST['onlyWithTag'])
     1517                        && $_POST['onlyWithTag']
     1518                        ) {
    14881519                        ?>
    14891520                        <div id="message" class="error">
     
    15411572           
    15421573            // Check if the post sould save
    1543             if ($_POST['mode'] == 'save') { // Save post
    1544                 ########################
    1545                 ## SET ENTRY BUILDING ##
    1546                 ########################
    1547                
    1548                 // Set en empty example for entry building with replace
    1549                 $replaceEntryBuilding = $this->replaceEntryBuilding(false, false, false, false, false, false);
    1550                
    1551                 // Set en empty example for entry building without replace
    1552                 $noReplaceEntryBuilding = $this->replaceEntryBuilding(false, false, false, false, false, false, false);
    1553                
    1554                 // Check, which Array elements are dynamic. Set empy replace and flag in new array
    1555                 $i = 0;
    1556                 $exampleReplaceEntryBuilding = array();
    1557                 while($i < count($replaceEntryBuilding)) {
    1558                     if ($replaceEntryBuilding[$i] == $noReplaceEntryBuilding[$i]) {
    1559                         $exampleReplaceEntryBuilding[$i] = array(
    1560                             'example' => $replaceEntryBuilding[$i],
    1561                             'dynamic' => false
    1562                         );
    1563                     }else {
    1564                         $exampleReplaceEntryBuilding[$i] = array(
    1565                             'example' => $replaceEntryBuilding[$i],
    1566                             'dynamic' => true
    1567                         );
    1568                     }
    1569                    
    1570                     $i++;
    1571                 }
    1572                
    1573                 // Unset not longer needed vars
    1574                 unset($replaceEntryBuilding);
    1575                 unset($noReplaceEntryBuilding);
    1576                
    1577                 #####################################
    1578                 ## COMBINE URL, URL CLEANED AND ID ##
    1579                 #####################################
    1580                
    1581                 $i = 0;
    1582                 while ($i < (count($_POST['element']) / 9)) {
    1583                     $url = $_POST['element'][(($i * 9) + 2)]['url'];
    1584                     $urlUncleaned = $_POST['element'][(($i * 9) + 3)]['url_uncleaned'];
    1585                     $id = $_POST['element'][(($i * 9) + 6)]['id'];
    1586                    
    1587                     $_POST['element'][(($i * 9) + 2)] = array(
    1588                         array(
    1589                             $url,
    1590                             $urlUncleaned,
    1591                             $id
    1592                         )
    1593                     );
    1594                    
    1595                    
    1596                     $i++;
    1597                 }
    1598                
    1599                 #########################
    1600                 ## SET ASSOCIATE LINKS ##
    1601                 #########################
    1602                 $i = 0;
    1603                 while ($i < (count($_POST['element']) / 9)) {
    1604                     // Check if this it not a associate link
    1605                     if (!$_POST['element'][($i * 9) + 6]['associate']) {
    1606                         // Search for associate links in the following
    1607                         $associateLinks = array();
    1608                         $i2 = 1;
    1609                         while(true) {
    1610                             // If this is an associate links, add this to the array, else break the while-loop
    1611                             if ($_POST['element'][($i * 9) + 8 + ($i2 * 9)]['associate']) {
    1612                                 $_POST['element'][($i * 9) + 2][] = $_POST['element'][(($i * 9) + 2 + ($i2 * 9))][0];
    1613                             }else {
    1614                                 break;
    1615                             }
    1616                            
    1617                             $i2++;
    1618                         }
    1619                     }
    1620                    
    1621                     $i++;
    1622                 }
    1623                
    1624                 ####################
    1625                 ## GENNERATE POST ##
    1626                 ####################
    1627                
    1628                 // Set posted elements in $_POST for view
    1629                 $_POST['count_elements'] = round((count($_POST['element']) / 9));
    1630                
    1631                 // Array for all posted links
    1632                 $allPostedLinks = array();
    1633                
    1634                 $post_content = '';
    1635                
    1636                 // Gennerate all links in text
    1637                 $i = 0;
    1638                 while ($i < (count($_POST['element']) / 9)) {
    1639                     // Check if only not posted links should post
    1640                     if (get_option('wpstacker_links_to_use') == 0 || get_option('wpstacker_links_to_use') == 1 || get_option('wpstacker_links_to_use') == 2) {
    1641                         // Check if aleady posted. If true, confine to the next loop
    1642                         $sql = 'SELECT `id` FROM `' . $this->wpdb->prefix . 'wpstacker_posted_links` WHERE `url`="' . $_POST['element'][($i * 9) + 2]['url'] . '"';
    1643                         $row = $this->wpdb->get_results($sql);
    1644                        
    1645                         if ($row[0]->id != '') {
    1646                             $_POST['count_elements'] -= count($_POST['element'][($i * 9) + 2]); // - this and associated elements
    1647                             $i++;
    1648                             continue;
    1649                         }
    1650                     }
    1651                    
    1652                     // Check if this it not a associate link
    1653                     if (!$_POST['element'][($i * 9) + 8]['associate']) {
    1654                         // Gennerate url array in url string
    1655                         $url = '';
    1656                        
    1657                         $i2 = 0;
    1658                         foreach ($_POST['element'][($i * 9) + 2] as $value) {
    1659                             if ($i2 != 0) {
    1660                                 $url .= '; ';
    1661                             }
    1662                            
    1663                             $url .= '<a href="' . $value[0] . '" target="_blank">' . $value[0] . '</a>';
    1664                            
    1665                             // Fill array for all posted links
    1666                             $allPostedLinks[] = $value;
    1667                            
    1668                             $i2++;
    1669                         }
    1670                        
    1671                         // Set element in entry building
    1672                         $element = $this->replaceEntryBuilding(
    1673                             $_POST['element'][($i * 9)]['title'],
    1674                             $_POST['element'][($i * 9) + 5]['description'],
    1675                             $url,
    1676                             $_POST['element'][($i * 9) + 4]['tags'],
    1677                             $_POST['element'][($i * 9) + 1]['author'],
    1678                             $_POST['element'][($i * 9) + 7]['countwords']
    1679                         );
    1680                        
    1681                         // Check if a dynamic element is not in use an delete it
    1682                         $i2 = 0;
    1683                         while ($i2 < count($element)) {
    1684                             if ($element[$i2] == $exampleReplaceEntryBuilding[$i2]['example'] && $exampleReplaceEntryBuilding[$i2]['dynamic']) {
    1685                                 unset($element[$i2]);
    1686                             }
    1687 
    1688                             $i2++;
    1689                         }
    1690                        
    1691                         // Set element array as string for the post content
    1692                         $post_content .= '<p>';
    1693                        
    1694                         foreach ($element as $value) {
    1695                             $post_content .= $value;
    1696                         }
    1697                        
    1698                         $post_content .= '</p>';
    1699                     }
    1700                    
    1701                     $i++;
    1702                 }
    1703                
    1704                 $post_content_final = '';
    1705                
    1706                 // Set introduction text if not empty
    1707                 if (trim(get_option('wpstacker_introduction_text')) != '') {
    1708                     $post_content_final .= $this->getReplacedIntroductionText($_POST['count_elements']);
    1709                 }
    1710                
    1711                 // Set links content
    1712                 $post_content_final .= $post_content;
    1713                
    1714                 // Set statements text if not empty
    1715                 if (trim(get_option('wpstacker_statements_text')) != '') {
    1716                     $post_content_final .= $this->getReplacedStatementsText($_POST['count_elements']);
    1717                 }
    1718                
    1719                 // Chech if reference to WP Stacker shot print
    1720                 if (get_option('wpstacker_reference_wpstacker')) {
    1721                     $post_content_final .= '<p><i>This post was automatically created by WP Stacker. If you look for this WordPress plugin, check out <a href="http://wp-stacker.com/" target="_blank">WP-Stacker.com</a> now!</i></p>';
    1722                 }
    1723                
    1724                 ###############
    1725                 ## SAVE POST ##
    1726                 ###############
    1727                
    1728                 // Save only, if one or more elements are valid
    1729                 if ($_POST['count_elements'] != 0) {
    1730                     // Set settings array
    1731                     $post = array(
    1732                         'comment_status' => get_option('wpstacker_comment_status'),
    1733                         'ping_status' => get_option('wpstacker_ping_status'),
    1734                         'post_author' => $current_user->ID,
    1735                         'post_category' => array(get_option('wpstacker_post_category')),
    1736                         'post_content' => $post_content_final,
    1737                         'post_date' => date('Y-m-d H:i:s'),
    1738                         'post_date_gmt' => gmdate('Y-m-d H:i:s'),
    1739                         'post_status' => get_option('wpstacker_post_status'),
    1740                         'post_title' => $this->getReplacedTitle($_POST['count_elements']),
    1741                         'post_type' => 'post'
    1742                     );
    1743                    
    1744                     // Insert the post
    1745                     $postId = wp_insert_post($post);
    1746                    
    1747                     // Set post format
    1748                     set_post_format($postId, get_option('wpstacker_post_format'));
    1749                 }
    1750                
    1751                 ##########################
    1752                 ## SAVE LINKS AS POSTED ##
    1753                 ##########################
    1754                
    1755                 // Save only, if one or more elements are valid
    1756                 if ($_POST['count_elements'] != 0) {
    1757                     // Set currently time
    1758                     $time = time();
    1759                    
     1574            if (isset($_POST['mode'])) {
     1575                if ($_POST['mode'] == 'save') { // Save post
     1576                    ########################
     1577                    ## SET ENTRY BUILDING ##
     1578                    ########################
     1579                   
     1580                    // Set en empty example for entry building with replace
     1581                    $replaceEntryBuilding = $this->replaceEntryBuilding(false, false, false, false, false, false);
     1582                   
     1583                    // Set en empty example for entry building without replace
     1584                    $noReplaceEntryBuilding = $this->replaceEntryBuilding(false, false, false, false, false, false, false);
     1585                   
     1586                    // Check, which Array elements are dynamic. Set empy replace and flag in new array
    17601587                    $i = 0;
    1761                     while ($i < count($allPostedLinks)) {
    1762                         $sql = 'SELECT `id` FROM `' . $this->wpdb->prefix . 'wpstacker_posted_links` WHERE `url`="' . $allPostedLinks[$i][1] . '"';
    1763                         $row = $this->wpdb->get_results($sql);
    1764                        
    1765                         // Save only it already not saved
    1766                         if ($row[0]->id == '') {
    1767                             $sql = '
    1768                             INSERT IGNORE INTO `' . $this->wpdb->prefix . 'wpstacker_posted_links` (
    1769                                 `url`,
    1770                                 `timestamp`
    1771                             )
    1772                             VALUES
    1773                                 (%s, %s)
    1774                             ';
    1775                            
    1776                             // Save link as posted
    1777                             $this->wpdb->query(
    1778                                 $this->wpdb->prepare(
    1779                                     $sql,
    1780                                     $allPostedLinks[$i][1],
    1781                                     $time
    1782                                 )
     1588                    $exampleReplaceEntryBuilding = array();
     1589                    while($i < count($replaceEntryBuilding)) {
     1590                        if ($replaceEntryBuilding[$i] == $noReplaceEntryBuilding[$i]) {
     1591                            $exampleReplaceEntryBuilding[$i] = array(
     1592                                'example' => $replaceEntryBuilding[$i],
     1593                                'dynamic' => false
     1594                            );
     1595                        }else {
     1596                            $exampleReplaceEntryBuilding[$i] = array(
     1597                                'example' => $replaceEntryBuilding[$i],
     1598                                'dynamic' => true
    17831599                            );
    17841600                        }
     
    17861602                        $i++;
    17871603                    }
    1788                 }
    1789                
    1790                 #################################
    1791                 ## SET STATUS READED IN POCKET ##
    1792                 #################################
    1793                
    1794                 // Check if link should marke as readed
    1795                 if (get_option('wpstacker_mark_as_readed')) {
    1796                     $markAsReaded = array();
    1797                    
    1798                     // Fill JSON as Array
     1604                   
     1605                    // Unset not longer needed vars
     1606                    unset($replaceEntryBuilding);
     1607                    unset($noReplaceEntryBuilding);
     1608                   
     1609                    #####################################
     1610                    ## COMBINE URL, URL CLEANED AND ID ##
     1611                    #####################################
     1612                   
    17991613                    $i = 0;
    1800                     while ($i < count($allPostedLinks)) {
    1801                         $markAsReaded[] = array(
    1802                             'action' => 'archive',
    1803                             'item_id' => $allPostedLinks[$i][2]
     1614                    while ($i < (count($_POST['element']) / 9)) {
     1615                        $url = $_POST['element'][(($i * 9) + 2)]['url'];
     1616                        $urlUncleaned = $_POST['element'][(($i * 9) + 3)]['url_uncleaned'];
     1617                        $id = $_POST['element'][(($i * 9) + 6)]['id'];
     1618                       
     1619                        $_POST['element'][(($i * 9) + 2)] = array(
     1620                            array(
     1621                                $url,
     1622                                $urlUncleaned,
     1623                                $id
     1624                            )
    18041625                        );
    18051626                       
    1806                         $i++;
    1807                        
    1808                         // Chech if limit of links reached. If yes, send request and start new sends array
    1809                         if (($i / 100) == round($i / 100)) {
    1810                             // Send request
    1811                             $this->cURL(
    1812                                 'https://getpocket.com/v3/send',
    1813                                 array(
    1814                                     'consumer_key' => $this->xcrypt(1, get_option('wpstacker_pocket_consumer_key')),
    1815                                     'access_token' => $this->xcrypt(1, get_option('wpstacker_pocket_access_key')),
    1816                                     'actions' => json_encode($markAsReaded)
    1817                                 )
    1818                             );
    1819                            
    1820                             // Clean up array
    1821                             $markAsReaded = array();
    1822                         }
    1823                     }
    1824                    
    1825                     // Send request
    1826                     $this->cURL(
    1827                         'https://getpocket.com/v3/send',
    1828                         array(
    1829                             'consumer_key' => $this->xcrypt(1, get_option('wpstacker_pocket_consumer_key')),
    1830                             'access_token' => $this->xcrypt(1, get_option('wpstacker_pocket_access_key')),
    1831                             'actions' => json_encode($markAsReaded)
    1832                         )
    1833                     );
    1834                 }
    1835                
    1836                 // Send statistics, if allowed
    1837                 if (get_option('wpstacker_statistics') == 1) {
    1838                     $allLinksForStatisics = array();
    1839                     $i = 0;
    1840                     while ($i < count($allPostedLinks)) {
    1841                         $allLinksForStatisics[] = $allPostedLinks[$i][0];
    18421627                       
    18431628                        $i++;
    18441629                    }
    18451630                   
    1846                     $this->statisticsPublishPost($allLinksForStatisics);
     1631                    #########################
     1632                    ## SET ASSOCIATE LINKS ##
     1633                    #########################
     1634                    $i = 0;
     1635                    while ($i < (count($_POST['element']) / 9)) {
     1636                        // Check if this it not a associate link
     1637                        if (isset($_POST['element'][($i * 9) + 6]['associate']) && !$_POST['element'][($i * 9) + 6]['associate']) {
     1638                            // Search for associate links in the following
     1639                            $associateLinks = array();
     1640                            $i2 = 1;
     1641                            while(true) {
     1642                                // If this is an associate links, add this to the array, else break the while-loop
     1643                                if ($_POST['element'][($i * 9) + 8 + ($i2 * 9)]['associate']) {
     1644                                    $_POST['element'][($i * 9) + 2][] = $_POST['element'][(($i * 9) + 2 + ($i2 * 9))][0];
     1645                                }else {
     1646                                    break;
     1647                                }
     1648                               
     1649                                $i2++;
     1650                            }
     1651                        }
     1652                       
     1653                        $i++;
     1654                    }
     1655                   
     1656                    ####################
     1657                    ## GENNERATE POST ##
     1658                    ####################
     1659                   
     1660                    // Set posted elements in $_POST for view
     1661                    $_POST['count_elements'] = round((count($_POST['element']) / 9));
     1662                   
     1663                    // Array for all posted links
     1664                    $allPostedLinks = array();
     1665                   
     1666                    $post_content = '';
     1667                   
     1668                    // Gennerate all links in text
     1669                    $i = 0;
     1670                    while ($i < (count($_POST['element']) / 9)) {
     1671                        // Check if only not posted links should post
     1672                        if (get_option('wpstacker_links_to_use') == 0 || get_option('wpstacker_links_to_use') == 1 || get_option('wpstacker_links_to_use') == 2) {
     1673                            // Check if aleady posted. If true, confine to the next loop
     1674                            if (isset($_POST['element'][($i * 9) + 2]['url'])) {
     1675                                $url = $_POST['element'][($i * 9) + 2]['url'];
     1676                            }else {
     1677                                $url = '';
     1678                            }
     1679
     1680                            $sql = 'SELECT `id` FROM `' . $this->wpdb->prefix . 'wpstacker_posted_links` WHERE `url`="' . $url . '"';
     1681                            $row = $this->wpdb->get_results($sql);
     1682                           
     1683                            if (isset($row[0]->id) && $row[0]->id != '') {
     1684                                $_POST['count_elements'] -= count($_POST['element'][($i * 9) + 2]); // - this and associated elements
     1685                                $i++;
     1686                                continue;
     1687                            }
     1688                        }
     1689                       
     1690                        // Check if this it not a associate link
     1691                        if (!$_POST['element'][($i * 9) + 8]['associate']) {
     1692                            // Gennerate url array in url string
     1693                            $url = '';
     1694                           
     1695                            $i2 = 0;
     1696                            foreach ($_POST['element'][($i * 9) + 2] as $value) {
     1697                                if ($i2 != 0) {
     1698                                    $url .= '; ';
     1699                                }
     1700                               
     1701                                $url .= '<a href="' . $value[0] . '" target="_blank">' . $value[0] . '</a>';
     1702                               
     1703                                // Fill array for all posted links
     1704                                $allPostedLinks[] = $value;
     1705                               
     1706                                $i2++;
     1707                            }
     1708                           
     1709                            // Set element in entry building
     1710                            $element = $this->replaceEntryBuilding(
     1711                                $_POST['element'][($i * 9)]['title'],
     1712                                $_POST['element'][($i * 9) + 5]['description'],
     1713                                $url,
     1714                                $_POST['element'][($i * 9) + 4]['tags'],
     1715                                $_POST['element'][($i * 9) + 1]['author'],
     1716                                $_POST['element'][($i * 9) + 7]['countwords']
     1717                            );
     1718                           
     1719                            // Check if a dynamic element is not in use an delete it
     1720                            $i2 = 0;
     1721                            while ($i2 < count($element)) {
     1722                                if ($element[$i2] == $exampleReplaceEntryBuilding[$i2]['example'] && $exampleReplaceEntryBuilding[$i2]['dynamic']) {
     1723                                    unset($element[$i2]);
     1724                                }
     1725
     1726                                $i2++;
     1727                            }
     1728                           
     1729                            // Set element array as string for the post content
     1730                            $post_content .= '<p>';
     1731                           
     1732                            foreach ($element as $value) {
     1733                                $post_content .= $value;
     1734                            }
     1735                           
     1736                            $post_content .= '</p>';
     1737                        }
     1738                       
     1739                        $i++;
     1740                    }
     1741                   
     1742                    $post_content_final = '';
     1743                   
     1744                    // Set introduction text if not empty
     1745                    if (trim(get_option('wpstacker_introduction_text')) != '') {
     1746                        $post_content_final .= $this->getReplacedIntroductionText($_POST['count_elements']);
     1747                    }
     1748                   
     1749                    // Set links content
     1750                    $post_content_final .= $post_content;
     1751                   
     1752                    // Set statements text if not empty
     1753                    if (trim(get_option('wpstacker_statements_text')) != '') {
     1754                        $post_content_final .= $this->getReplacedStatementsText($_POST['count_elements']);
     1755                    }
     1756                   
     1757                    // Chech if reference to WP Stacker shot print
     1758                    if (get_option('wpstacker_reference_wpstacker')) {
     1759                        $post_content_final .= '<p><i>This post was automatically created by WP Stacker. If you look for this WordPress plugin, check out <a href="http://wp-stacker.com/" target="_blank">WP-Stacker.com</a> now!</i></p>';
     1760                    }
     1761                   
     1762                    ###############
     1763                    ## SAVE POST ##
     1764                    ###############
     1765                   
     1766                    // Save only, if one or more elements are valid
     1767                    if ($_POST['count_elements'] != 0) {
     1768                        // Set settings array
     1769                        $post = array(
     1770                            'comment_status' => get_option('wpstacker_comment_status'),
     1771                            'ping_status' => get_option('wpstacker_ping_status'),
     1772                            'post_author' => $current_user->ID,
     1773                            'post_category' => array(get_option('wpstacker_post_category')),
     1774                            'post_content' => $post_content_final,
     1775                            'post_date' => date('Y-m-d H:i:s'),
     1776                            'post_date_gmt' => gmdate('Y-m-d H:i:s'),
     1777                            'post_status' => get_option('wpstacker_post_status'),
     1778                            'post_title' => $this->getReplacedTitle($_POST['count_elements']),
     1779                            'post_type' => 'post'
     1780                        );
     1781                       
     1782                        // Insert the post
     1783                        $postId = wp_insert_post($post);
     1784                       
     1785                        // Set post format
     1786                        set_post_format($postId, get_option('wpstacker_post_format'));
     1787                    }
     1788                   
     1789                    ##########################
     1790                    ## SAVE LINKS AS POSTED ##
     1791                    ##########################
     1792                   
     1793                    // Save only, if one or more elements are valid
     1794                    if ($_POST['count_elements'] != 0) {
     1795                        // Set currently time
     1796                        $time = time();
     1797                       
     1798                        $i = 0;
     1799                        while ($i < count($allPostedLinks)) {
     1800                            $sql = 'SELECT `id` FROM `' . $this->wpdb->prefix . 'wpstacker_posted_links` WHERE `url`="' . $allPostedLinks[$i][1] . '"';
     1801                            $row = $this->wpdb->get_results($sql);
     1802                           
     1803                            // Save only it already not saved
     1804                            if ($row[0]->id == '') {
     1805                                $sql = '
     1806                                INSERT IGNORE INTO `' . $this->wpdb->prefix . 'wpstacker_posted_links` (
     1807                                    `url`,
     1808                                    `timestamp`
     1809                                )
     1810                                VALUES
     1811                                    (%s, %s)
     1812                                ';
     1813                               
     1814                                // Save link as posted
     1815                                $this->wpdb->query(
     1816                                    $this->wpdb->prepare(
     1817                                        $sql,
     1818                                        $allPostedLinks[$i][1],
     1819                                        $time
     1820                                    )
     1821                                );
     1822                            }
     1823                           
     1824                            $i++;
     1825                        }
     1826                    }
     1827                   
     1828                    #################################
     1829                    ## SET STATUS READED IN POCKET ##
     1830                    #################################
     1831                   
     1832                    // Check if link should marke as readed
     1833                    if (get_option('wpstacker_mark_as_readed')) {
     1834                        $markAsReaded = array();
     1835                       
     1836                        // Fill JSON as Array
     1837                        $i = 0;
     1838                        while ($i < count($allPostedLinks)) {
     1839                            $markAsReaded[] = array(
     1840                                'action' => 'archive',
     1841                                'item_id' => $allPostedLinks[$i][2]
     1842                            );
     1843                           
     1844                            $i++;
     1845                           
     1846                            // Chech if limit of links reached. If yes, send request and start new sends array
     1847                            if (($i / 100) == round($i / 100)) {
     1848                                // Send request
     1849                                $this->cURL(
     1850                                    'https://getpocket.com/v3/send',
     1851                                    array(
     1852                                        'consumer_key' => $this->xcrypt(1, get_option('wpstacker_pocket_consumer_key')),
     1853                                        'access_token' => $this->xcrypt(1, get_option('wpstacker_pocket_access_key')),
     1854                                        'actions' => json_encode($markAsReaded)
     1855                                    )
     1856                                );
     1857                               
     1858                                // Clean up array
     1859                                $markAsReaded = array();
     1860                            }
     1861                        }
     1862                       
     1863                        // Send request
     1864                        $this->cURL(
     1865                            'https://getpocket.com/v3/send',
     1866                            array(
     1867                                'consumer_key' => $this->xcrypt(1, get_option('wpstacker_pocket_consumer_key')),
     1868                                'access_token' => $this->xcrypt(1, get_option('wpstacker_pocket_access_key')),
     1869                                'actions' => json_encode($markAsReaded)
     1870                            )
     1871                        );
     1872                    }
     1873                   
     1874                    // Send statistics, if allowed
     1875                    if (get_option('wpstacker_statistics') == 1) {
     1876                        $allLinksForStatisics = array();
     1877                        $i = 0;
     1878                        while ($i < count($allPostedLinks)) {
     1879                            $allLinksForStatisics[] = $allPostedLinks[$i][0];
     1880                           
     1881                            $i++;
     1882                        }
     1883                       
     1884                        $this->statisticsPublishPost($allLinksForStatisics);
     1885                    }
    18471886                }
    18481887            }
Note: See TracChangeset for help on using the changeset viewer.