Plugin Directory

Changeset 1921451


Ignore:
Timestamp:
08/08/2018 09:02:36 AM (8 years ago)
Author:
plenigo
Message:

Version 1.7.8

Location:
plenigo/trunk
Files:
14 edited

Legend:

Unmodified
Added
Removed
  • plenigo/trunk/plenigo_plugin/PlenigoContentManager.php

    r1920340 r1921451  
    368368        $typesPluginPaywall = function_exists('types_render_field') && types_render_field("paywall");
    369369        // Do not paywall if nothing is configured
     370
    370371        if (trim($plenigoTagDB) === '' && trim($plenigoCatTagDB) === '' && !$typesPluginPaywall) {
    371372            plenigo_log_message("NO TAGS CONFIGURED");
    372373            return FALSE;
    373374        }
     375
     376//        var_dump(PlenigoSDKManager::get()->isPayWallEnabled());
    374377
    375378        // If Paywall is disabled, we dont check anything
     
    431434    }
    432435
    433     /**
    434      * This method checks for category IDs that need to be added to the category list
    435      * so it can be checked for bought products. Returns FALSE if there is no tag
    436      * found on the article that reflects a tag in the plenigo settings
    437      *
    438      * @return bool Returns TRUE if a tag has been found and the category list is in the cache
    439      */
    440     public function hasAnyCategoryTag() {
    441         if (isset($this->reqCache["hasAnyCategoryTag"])) {
    442             $this->addDebugLine("[Cached] has Category Tag: " . $this->reqCache["hasAnyCategoryTag"]);
    443             return $this->reqCache["hasAnyCategoryTag"];
    444         }
    445         $catTagList = (isset($this->options['plenigo_cat_tag_db']) ? $this->options['plenigo_cat_tag_db'] : '');
    446         $res = FALSE;
    447         //TAGS WITH CATEGORY IDS
    448         $rowSplit = explode("\n", $catTagList);
     436    protected function postHasTerm($configRow) {
     437        $strTag = explode("->", $configRow);
     438        $arrToken = array();
     439        //Obtain the {slug} or {id}
     440        preg_match('/{(.*?)}/', $strTag[0], $arrToken);
     441
     442        if (is_numeric($arrToken[1])) {
     443            $categories = $this->getCategoryChildren(intval($arrToken[1]));
     444        } else {
     445            $categories = $arrToken[1];
     446        }
     447
     448        return ($strTag !== FALSE && count($strTag) == 2 && count($arrToken) == 2 && (has_tag($arrToken[1]) || has_category($categories)));
     449    }
     450
     451    /**
     452     * @param string $tagList
     453     * @param string $type
     454     * @return bool
     455     */
     456    protected function hasTerm($tagList, $type = 'Product') {
     457        $shortType = $type === 'Product' ? 'Prod' : 'Cat';
     458        $rowSplit = explode("\n", $tagList);
     459        $res = false;
    449460        if ($rowSplit === FALSE || count($rowSplit) == 0) {
    450             $rowSplit = array($catTagList);
    451         }
     461            $rowSplit = array($tagList);
     462        }
     463
    452464        foreach ($rowSplit as $tagRow) {
    453465            $strTag = explode("->", $tagRow);
    454466            $arrToken = array();
    455             //Obtain the {slug}
     467            //Obtain the {slug} or {id}
    456468            preg_match('/{(.*?)}/', $strTag[0], $arrToken);
    457             if ($strTag !== FALSE && count($strTag) == 2 && count($arrToken) == 2 && (has_tag($arrToken[1]) || has_category($arrToken[1]))) {
    458                 plenigo_log_message("Category TAG! TAG=" . $strTag[0] . " CategoryID(s):" . $strTag[1]);
    459                 $this->addDebugLine("Category match: " . $strTag[0]);
     469
     470            if (is_numeric($arrToken[1])) {
     471                $categories = $this->getCategoryChildren(intval($arrToken[1]));
     472            } else {
     473                $categories = $arrToken[1];
     474            }
     475
     476            if ($strTag !== FALSE && count($strTag) == 2 && count($arrToken) == 2 && (has_tag($arrToken[1]) || has_category($categories))) {
     477                plenigo_log_message("{$type} TAG! TAG=" . $strTag[0] . " {$type}ID(s):" . $strTag[1]);
     478                $this->addDebugLine("{$type} match: " . $strTag[0]);
    460479                $arrCats = array();
    461480                //Support for multiple ids in one tag
     
    466485                }
    467486                foreach ($arrCats as $cid) {
    468                     if (!isset($this->reqCache["lastCatId"])) {
    469                         $this->reqCache["lastCatId"] = trim($cid);
    470                         $this->reqCache["lastCatTag"] = trim($arrToken[1]);
     487                    if (!isset($this->reqCache["last{$shortType}Id"])) {
     488                        $this->reqCache["last{$shortType}Id"] = trim($cid);
     489                        $this->reqCache["last{$shortType}Tag"] = trim($arrToken[1]);
    471490                    }
    472                     array_push($this->reqCache["listCatId"], trim($cid));
    473                     array_push($this->reqCache["listCatTag"], trim($arrToken[1]));
     491                    array_push($this->reqCache["list{$shortType}Id"], trim($cid));
     492                    array_push($this->reqCache["list{$shortType}Tag"], trim($arrToken[1]));
    474493                    $res = TRUE;
    475494                }
    476495            }
    477496        }
     497        return $res;
     498    }
     499
     500    /**
     501     * This method checks for category IDs that need to be added to the category list
     502     * so it can be checked for bought products. Returns FALSE if there is no tag
     503     * found on the article that reflects a tag in the plenigo settings
     504     *
     505     * @return bool Returns TRUE if a tag has been found and the category list is in the cache
     506     */
     507    public function hasAnyCategoryTag() {
     508        if (isset($this->reqCache["hasAnyCategoryTag"])) {
     509            $this->addDebugLine("[Cached] has Category Tag: " . $this->reqCache["hasAnyCategoryTag"]);
     510            return $this->reqCache["hasAnyCategoryTag"];
     511        }
     512        $catTagList = (isset($this->options['plenigo_cat_tag_db']) ? $this->options['plenigo_cat_tag_db'] : '');
     513        $res = FALSE;
     514        //TAGS WITH CATEGORY IDS
     515
     516        if (!empty($catTagList)) {
     517            $res = $this->hasTerm($catTagList, 'Category');
     518        }
     519
    478520        if ($res === TRUE) {
    479521            $this->addDebugLine("Categories: " . var_export($this->reqCache["listCatId"], TRUE));
     
    497539        $arrToken = array();
    498540        preg_match('/{(.*?)}/', $prevTag, $arrToken);
    499         if (count($arrToken) == 2 && (has_tag($arrToken[1]) || has_category($arrToken[1]))) {
     541
     542        if (is_numeric($arrToken[1])) {
     543            $categories = $this->getCategoryChildren(intval($arrToken[1]));
     544        } else {
     545            $categories = $arrToken[1];
     546        }
     547
     548        if (count($arrToken) == 2 && (has_tag($arrToken[1]) || has_category($categories))) {
    500549            plenigo_log_message("Prevent TAG! TAG=" . $prevTag);
    501550            $this->addDebugLine("Prevent Tag: " . $prevTag);
     
    508557        }
    509558        $this->reqCache["hasPreventTag"] = $res;
     559
    510560        return $res;
     561    }
     562
     563    private function getCategoryChildren($id) {
     564
     565        $categories = array();
     566        $categories[$id] = $id;
     567
     568        $cats = get_categories( array( 'parent' => $id ));
     569
     570        if (empty($cats)) {
     571            return $categories;
     572        }
     573
     574        foreach ($cats as $category) {
     575            $categories[$category->term_id] = $category->term_id;
     576            $sub = $this->getCategoryChildren($category->term_id);
     577            if (!empty($sub)) {
     578                $categories = array_merge($categories, $sub);
     579            }
     580        }
     581
     582        return $categories;
    511583    }
    512584
     
    526598        $res = FALSE;
    527599        //TAGS WITH PRODUCT IDS
    528         $rowSplit = explode("\n", $prodTagList);
    529         if ($rowSplit == FALSE || count($rowSplit) == 0) {
    530             $rowSplit = array($prodTagList);
    531         }
    532 
    533         foreach ($rowSplit as $tagRow) {
    534             $strTag = explode("->", $tagRow);
    535             $arrToken = array();
    536             //Obtain the {slug}
    537             preg_match('/{(.*?)}/', $strTag[0], $arrToken);
    538 
    539             if ($strTag !== FALSE && count($strTag) == 2 && count($arrToken) == 2 && (has_tag($arrToken[1]) || has_category($arrToken[1]))) {
    540                 plenigo_log_message("Product TAG! TAG=" . $strTag[0] . " ProductID(s):" . $strTag[1]);
    541                 $this->addDebugLine("Product match: " . $strTag[0]);
    542                 $arrProds = array();
    543                 //Support for multiple ids in one tag
    544                 if (stristr($strTag[1], ',')) {
    545                     $arrProds = explode(',', $strTag[1]);
    546                 } else {
    547                     $arrProds = array($strTag[1]);
    548                 }
    549                 foreach ($arrProds as $pid) {
    550                     if (!isset($this->reqCache["lastProdId"])) {
    551                         $this->reqCache["lastProdId"] = trim($pid);
    552                         $this->reqCache["lastProdTag"] = trim($arrToken[1]);
    553                     }
    554                     array_push($this->reqCache["listProdId"], trim($pid));
    555                     array_push($this->reqCache["listProdTag"], trim($arrToken[1]));
    556 
    557                     $res = TRUE;
    558                 }
    559             }
    560         }
     600
     601        if (!empty($prodTagList)) {
     602
     603            $res = $this->hasTerm($prodTagList, 'Product');
     604
     605        }
     606
    561607        if ($res === TRUE) {
    562608            $this->addDebugLine("Products: " . var_export($this->reqCache["listProdId"], TRUE));
  • plenigo/trunk/plenigo_plugin/PlenigoSDKManager.php

    r1919357 r1921451  
    3535     * Holds values for the SDK requests, so they are made just once per request
    3636     */
    37     private $reqCache = array();
     37//    private $reqCache = array();
    3838
    3939    /**
  • plenigo/trunk/plenigo_plugin/settings/PlenigoWPSetting.php

    r1919357 r1921451  
    3838
    3939    private $store = array();
     40
     41    protected $reqCache = array();
    4042
    4143    public function __construct()
     
    118120    }
    119121
     122    final protected function getCategoryChildren($id) {
     123
     124        $categories = array();
     125        $categories[$id] = $id;
     126
     127        $cats = get_categories( array( 'parent' => $id ));
     128
     129        var_dump($cats);
     130        if (empty($cats)) {
     131            return implode('|', $categories);
     132        }
     133
     134        foreach ($cats as $category) {
     135            $categories[$category->term_id] = $category->term_id;
     136            $sub = $this->getCategoryChildren($category->term_id);
     137            if (!empty($sub)) {
     138                $categories = array_merge($categories, $sub);
     139            }
     140        }
     141
     142        return implode('|', $categories);
     143    }
     144
     145    /**
     146     * This method allows the autocomplete field to populate with all the current tag values
     147     *
     148     * @global type $wpdb The WordPress database object
     149     * @return string A comma separated list of all existing tags
     150     */
     151    final protected function get_term_data()
     152    {
     153        if (isset($this->reqCache['term-query'])) {
     154            return $this->reqCache['term-query'];
     155        }
     156        global $wpdb;
     157        $res = '';
     158        $type = '';
     159
     160        $search_tags = $wpdb->get_results("SELECT a.name,a.slug,a.term_id as id,b.taxonomy FROM " . $wpdb->terms
     161            . " a," . $wpdb->term_taxonomy . " b WHERE a.term_id=b.term_id "
     162            . " and (b.taxonomy='post_tag' or b.taxonomy='category') ");
     163        foreach ($search_tags as $mytag) {
     164            if (strlen($res) !== 0) {
     165                $res.=",";
     166            }
     167            $type = $mytag->taxonomy == 'category' ? 'Categories' : 'Tags';
     168            $res.= str_replace('"', '', $mytag->name) . " ({$type}) " . "{" . ($mytag->id) . "}";
     169        }
     170        $this->reqCache['term-query'] = $res;
     171        return $res;
     172    }
     173
     174
    120175}
  • plenigo/trunk/plenigo_plugin/settings/SettingCategoryTagDB.php

    r1920340 r1921451  
    3838     * Holds values for storing values, so they are generated just once per request
    3939     */
    40     private $reqCache = array();
     40//    private $reqCache = array();
    4141
    4242    /**
     
    148148    }
    149149
    150     /**
    151      * This method allows the autocomplete field to populate with all the current tag values
    152      *
    153      * @global type $wpdb The WordPress database object
    154      * @return string A comma separated list of all existing tags
    155      */
    156     private function get_term_data()
    157     {
    158         if (isset($this->reqCache['term-query'])) {
    159             return $this->reqCache['term-query'];
    160         }
    161         global $wpdb;
    162         $res = '';
    163         $type = '';
    164 
    165         $search_tags = $wpdb->get_results("SELECT a.name,a.slug,b.taxonomy FROM " . $wpdb->terms
    166             . " a," . $wpdb->term_taxonomy . " b WHERE a.term_id=b.term_id "
    167             . " and (b.taxonomy='post_tag' or b.taxonomy='category') ");
    168         foreach ($search_tags as $mytag) {
    169             if (strlen($res) !== 0) {
    170                 $res.=",";
    171             }
    172             $type = $mytag->taxonomy == 'category' ? 'Categories' : 'Tags';
    173             $res.= $mytag->name . " ({$type}) " . "{" . $mytag->slug . "}";
    174         }
    175         $this->reqCache['term-query'] = $res;
    176         return $res;
    177     }
    178 
    179150}
  • plenigo/trunk/plenigo_plugin/settings/SettingCurtainBuyTextDB.php

    r1920340 r1921451  
    3838     * Holds values for storing values, so they are generated just once per request
    3939     */
    40     private $reqCache = array();
     40//    private $reqCache = array();
    4141
    4242    /**
     
    8888        . 'jQuery(document).ready(function(){'
    8989        . 'var data = "' . $this->get_term_data() . '".split(",");'
    90         . 'jQuery("#tag_buy_text_adder").autocomplete({source:data,autoFocus:true});});'
     90        . 'jQuery("#tag_buy_text_adder").autocomplete({source:data,autoFocus:true});'
    9191        . 'function addValuesToBuyTextArea(){'
    9292        . 'var strPrev=jQuery("#' . static::SETTING_ID . '").val();'
     
    148148    }
    149149
    150     /**
    151      * This method allows the autocomplete field to populate with all the current tag values
    152      *
    153      * @global type $wpdb The WordPress database object
    154      * @return string A comma separated list of all existing tags
    155      */
    156     private function get_term_data()
    157     {
    158         if (isset($this->reqCache['term-query'])) {
    159             return $this->reqCache['term-query'];
    160         }
    161         global $wpdb;
    162         $res = '';
    163         $type = '';
    164 
    165         $search_tags = $wpdb->get_results("SELECT a.name,a.slug,b.taxonomy FROM " . $wpdb->terms
    166             . " a," . $wpdb->term_taxonomy . " b WHERE a.term_id=b.term_id "
    167             . " and (b.taxonomy='post_tag' or b.taxonomy='category') ");
    168         foreach ($search_tags as $mytag) {
    169             if (strlen($res) !== 0) {
    170                 $res.=",";
    171             }
    172             $type = $mytag->taxonomy == 'category' ? 'Categories' : 'Tags';
    173             $res.= $mytag->name . " ({$type}) " . "{" . $mytag->slug . "}";
    174         }
    175         $this->reqCache['term-query'] = $res;
    176         return $res;
    177     }
    178150}
  • plenigo/trunk/plenigo_plugin/settings/SettingCustomCurtainDB.php

    r1919357 r1921451  
    3939     * Holds values for the SQL requests, so they are made just once per request
    4040     */
    41     private $reqCache = array();
     41//    private $reqCache = array();
    4242
    4343    /**
  • plenigo/trunk/plenigo_plugin/settings/SettingPreventTag.php

    r1920340 r1921451  
    3838     * Holds values for the SQL requests, so they are made just once per request
    3939     */
    40     private $reqCache = array();
     40//    private $reqCache = array();
    4141
    4242    /**
     
    9999    }
    100100
    101     private function get_term_data()
    102     {
    103         if (isset($this->reqCache['term-query'])) {
    104             return $this->reqCache['term-query'];
    105         }
    106         global $wpdb;
    107         $res = '';
    108         $type = '';
    109 
    110         $search_tags = $wpdb->get_results("SELECT a.name,a.slug,b.taxonomy FROM " . $wpdb->terms
    111             . " a," . $wpdb->term_taxonomy . " b WHERE a.term_id=b.term_id "
    112             . " and (b.taxonomy='post_tag' or b.taxonomy='category') ");
    113         foreach ($search_tags as $mytag) {
    114             if (strlen($res) !== 0) {
    115                 $res.=",";
    116             }
    117             $type = $mytag->taxonomy == 'category' ? 'Categories' : 'Tags';
    118             $res.= $mytag->name . " ({$type}) " . "{" . $mytag->slug . "}";
    119         }
    120         $this->reqCache['term-query'] = $res;
    121         return $res;
    122     }
    123101
    124102}
  • plenigo/trunk/plenigo_plugin/settings/SettingProductGroupOneDB.php

    r1919357 r1921451  
    3737     * Holds values for the SQL requests, so they are made just once per request
    3838     */
    39     private $reqCache = array();
     39//  private $reqCache = array();
    4040
    4141    /**
  • plenigo/trunk/plenigo_plugin/settings/SettingProductGroupTwoDB.php

    r1919357 r1921451  
    3737     * Holds values for the SQL requests, so they are made just once per request
    3838     */
    39     private $reqCache = array();
     39//  private $reqCache = array();
    4040
    4141    /**
  • plenigo/trunk/plenigo_plugin/settings/SettingProductTagDB.php

    r1919357 r1921451  
    3838     * Holds values for the SQL requests, so they are made just once per request
    3939     */
    40     private $reqCache = array();
     40//    private $reqCache = array();
    4141   
    4242    /**
     
    148148    }
    149149
    150     private function get_term_data()
    151     {
    152         if (isset($this->reqCache['term-query'])) {
    153             return $this->reqCache['term-query'];
    154         }
    155         global $wpdb;
    156         $res = '';
    157         $type = '';
    158 
    159         $search_tags = $wpdb->get_results("SELECT a.name,a.slug,b.taxonomy FROM " . $wpdb->terms
    160             . " a," . $wpdb->term_taxonomy . " b WHERE a.term_id=b.term_id "
    161             . " and (b.taxonomy='post_tag' or b.taxonomy='category') ");
    162         foreach ($search_tags as $mytag) {
    163             if (strlen($res) !== 0) {
    164                 $res.=",";
    165             }
    166             $type = $mytag->taxonomy == 'category' ? 'Categories' : 'Tags';
    167             $res.= $mytag->name . " ({$type}) " . "{" . $mytag->slug . "}";
    168         }
    169         $this->reqCache['term-query'] = $res;
    170         return $res;
    171     }
    172 
    173150}
  • plenigo/trunk/plenigo_wordpress.php

    r1920340 r1921451  
    55  Plugin URI: http://wordpress.org/plugins/plenigo/
    66  Description: So far, the technical implementation of paid content has been time-consuming and costly for publishing houses and media companies. plenigo puts an end to this.
    7   Version: 1.7.7
     7  Version: 1.7.8
    88  Author: Plenigo
    99  Author URI: https://www.plenigo.com
     
    3030  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
    3131 */
    32 define('PLENIGO_VERSION', '1.7.7');
     32define('PLENIGO_VERSION', '1.7.8');
    3333
    3434// Plenigo JavaScript SDK / Services
  • plenigo/trunk/readme.txt

    r1920340 r1921451  
    44Requires at least: 4.0.0
    55Tested up to: 4.9.1
    6 Stable tag: 1.7.7
     6Stable tag: 1.7.8
    77License: GPLv2 or later
    88License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    299299
    300300== Changelog ==
     301= 1.7.8 - Fixed Displaying Categories with quotes
     302
    301303= 1.7.7 - Fixed Translations
    302304
Note: See TracChangeset for help on using the changeset viewer.