| @@ -2,14 +2,14 @@ | ||
| 2 | 2 | /** |
| 3 | 3 | * Plugin Name: Taboola |
| 4 | 4 | * Plugin URI: https://developers.taboola.com/web-integrations/docs/wordpress-plugin |
| 5 | 5 | * Description: Taboola |
| 6 | - * Version: 2.2.2 | |
| 6 | + * Version: 2.1.0 | |
| 7 | 7 | * Author: Taboola |
| 8 | 8 | */ |
| 9 | 9 | |
| 10 | -define ("TABOOLA_PLUGIN_VERSION","2.2.2"); // => UPDATE THIS FOR *EVERY* RELEASE (USED FOR TRACKING) | |
| 11 | -define ("TABOOLA_MIN_VER","2.2.2"); // => UPDATE THIS *ONLY* IF THIS RELEASE HAS *DB CHANGES* | |
| 10 | +define ("TABOOLA_PLUGIN_VERSION","2.1.0"); // => UPDATE THIS FOR *EVERY* RELEASE (USED FOR TRACKING) | |
| 11 | +define ("TABOOLA_MIN_VER","2.0.1"); // => UPDATE THIS *ONLY* IF THIS RELEASE HAS *DB CHANGES* | |
| 12 | 12 | define ("TABOOLA_DEBUG_MODE", false); // => SET THIS TO 'FALSE' FOR *EVERY* RELEASE (USED TO SUPRESS DEBUGGING LOGS) |
| 13 | 13 | |
| 14 | 14 | define ("TABOOLA_OPTION_NAME","taboola_plugin_version"); // Note: if this release has DB changes, then the min version will be saved under 'taboola_plugin_version' in 'wp_options'. |
| 15 | 15 | |
| @@ -31,28 +31,10 @@ | ||
| 31 | 31 | //save internal data |
| 32 | 32 | public $data = array(); |
| 33 | 33 | public $_is_widget_on_page; |
| 34 | 34 | public $_is_head_script_loaded = false; |
| 35 | - private $tpl_sw = 'importScripts("https://cdn.taboola.com/webpush/tsw.js");'; | |
| 36 | 35 | |
| 37 | - private $msg_sw_error = <<<SWE | |
| 38 | - <p> | |
| 39 | - The file sw.js in the root directory of Wordpress is not writable. | |
| 40 | - Please change its permissions and try again. Otherwise replace its contents manually: | |
| 41 | - </p> | |
| 42 | - <pre><code>{{SW}}</code></pre> | |
| 43 | - <p> | |
| 44 | - Also make sure that the file is accessible at {{DOMAIN}}/sw.js | |
| 45 | - </p> | |
| 46 | - SWE; | |
| 47 | - | |
| 48 | - public $plugin_name; | |
| 49 | - public $plugin_directory; | |
| 50 | - public $plugin_url; | |
| 51 | - public $settings; | |
| 52 | - public $tbl_taboola_settings; | |
| 53 | - | |
| 54 | - public function __construct() | |
| 36 | + function __construct() | |
| 55 | 37 | { |
| 56 | 38 | global $wpdb; |
| 57 | 39 | |
| 58 | 40 | //initialize plugin constant |
| @@ -87,33 +69,15 @@ | ||
| 87 | 69 | if (is_admin()) { |
| 88 | 70 | //add menu for plugin |
| 89 | 71 | add_action( 'admin_menu', array(&$this, 'admin_generate_menu') ); |
| 90 | 72 | add_filter('plugin_action_links', array(&$this, 'plugin_action_links'), 10, 2 ); |
| 91 | - }elseif ($this->settings != NULL){ | |
| 73 | + }else if ($this->settings != NULL){ | |
| 92 | 74 | add_action('wp_head', array(&$this, 'taboola_header_loader_inject')); |
| 93 | - if (!empty($this->settings->publisher_id_push)) { | |
| 94 | - add_action('wp_head', array(&$this, 'taboola_webpush_loader_js')); | |
| 95 | - | |
| 96 | - $sw = 'sw.js'; | |
| 97 | - $sw_path = ABSPATH . $sw; | |
| 98 | - | |
| 99 | - $content = file_exists($sw_path) ? file_get_contents($sw_path) : ''; | |
| 100 | - | |
| 101 | - if (strpos($content, $this->tpl_sw) === false) { | |
| 102 | - if (!is_writable(ABSPATH) || (file_exists($sw_path) && !is_writable($sw_path))) { | |
| 103 | - return $this->notice($this->msg_sw_error); | |
| 104 | - } | |
| 105 | - $content = $this->tpl_sw . PHP_EOL . $content; | |
| 106 | - if (file_put_contents($sw_path, $content) === false) { | |
| 107 | - return $this->notice($this->msg_sw_error); | |
| 108 | - } | |
| 109 | - } | |
| 110 | - } | |
| 111 | 75 | add_action('wp_footer', array(&$this, 'taboola_footer_loader_js')); |
| 112 | 76 | add_filter('the_content', array(&$this, 'load_taboola_content')); |
| 113 | 77 | add_filter('the_content', array(&$this, 'load_taboola_content_mid')); |
| 114 | 78 | add_filter('the_content', array(&$this, 'load_taboola_content_home')); |
| 115 | - } | |
| 79 | + } | |
| 116 | 80 | } |
| 117 | 81 | |
| 118 | 82 | function plugin_action_links($links, $file) { |
| 119 | 83 | static $this_plugin; |
| @@ -146,9 +110,9 @@ | ||
| 146 | 110 | private function should_show_content_widget_home(){ |
| 147 | 111 | // PC - only if v2 was installed: |
| 148 | 112 | if (!$this->is_db_updated_for_min_ver("2.0.0")) |
| 149 | 113 | return false; |
| 150 | - $retVal2 = ((trim($this->settings->publisher_id) != '') && (is_front_page() || is_home()) && $this->settings->home_enabled && trim($this->settings->home_widget_id) != ''); | |
| 114 | + $retVal2 = ((trim($this->settings->publisher_id) != '') && is_front_page() && $this->settings->home_enabled && trim($this->settings->home_widget_id) != ''); | |
| 151 | 115 | return $retVal2; |
| 152 | 116 | } |
| 153 | 117 | |
| 154 | 118 | private function should_show_sidebar_widget(){ |
| @@ -191,8 +155,9 @@ | ||
| 191 | 155 | |
| 192 | 156 | $scriptWrapper = new JavaScriptWrapper("loaderInjectionScript.js",$stringParams); |
| 193 | 157 | $head_string = $scriptWrapper->getScriptMarkupString(); |
| 194 | 158 | } |
| 159 | + | |
| 195 | 160 | return $head_string; |
| 196 | 161 | } |
| 197 | 162 | |
| 198 | 163 | |
| @@ -200,23 +165,13 @@ | ||
| 200 | 165 | function taboola_header_loader_inject(){ |
| 201 | 166 | echo $this->taboola_header_loader_js(); |
| 202 | 167 | } |
| 203 | 168 | |
| 204 | - // adding webpush loader | |
| 205 | - function taboola_webpush_loader_js() { | |
| 206 | - if(is_single() || is_home() || is_category() || is_front_page()){ | |
| 207 | - $stringParamsWeb = array( | |
| 208 | - '{{PUBLISHER_ID}}' => $this->settings->publisher_id_push | |
| 209 | - ); | |
| 210 | - $webpushInjectionScript = new JavaScriptWrapper("webPush.js",$stringParamsWeb); | |
| 211 | - echo $webpushInjectionScript; | |
| 212 | - } | |
| 213 | - } | |
| 214 | 169 | |
| 215 | 170 | function taboola_footer_loader_js() { |
| 216 | 171 | |
| 217 | 172 | // Only adding flush script if a widget is going to be placed on the page. |
| 218 | - if ($this->is_widget_on_page()){ | |
| 173 | + if ( $this->is_widget_on_page() ){ | |
| 219 | 174 | $flushInjectionScript = new JavaScriptWrapper('flushInjectionScript.js',array()); |
| 220 | 175 | echo $flushInjectionScript->getScriptMarkupString(); |
| 221 | 176 | } |
| 222 | 177 | } |
| @@ -482,12 +437,13 @@ | ||
| 482 | 437 | } |
| 483 | 438 | |
| 484 | 439 | function admin_generate_menu(){ |
| 485 | 440 | global $current_user; |
| 486 | - add_menu_page(__('Taboola','taboola_widget'), __('Taboola','taboola_widget'), 'manage_options', 'taboola_widget', array(&$this, 'admin_taboola_settings'), $this->plugin_url.'img/taboola_icon.png', 110); | |
| 441 | + add_menu_page('Taboola', 'Taboola', 'manage_options', 'taboola_widget', array(&$this, 'admin_taboola_settings'), $this->plugin_url.'img/taboola_icon.png', 110); | |
| 487 | 442 | } |
| 488 | 443 | |
| 489 | 444 | function admin_taboola_settings(){ |
| 445 | + | |
| 490 | 446 | global $wpdb; |
| 491 | 447 | $settings = $wpdb->get_row("select * from ".$wpdb->prefix."_taboola_settings limit 1"); |
| 492 | 448 | $taboola_errors = array(); |
| 493 | 449 | if($_SERVER['REQUEST_METHOD'] == 'POST'){ |
| @@ -495,14 +451,8 @@ | ||
| 495 | 451 | if(trim(strip_tags($_POST['publisher_id'])) == ''){ |
| 496 | 452 | $taboola_errors[] = "Publisher ID"; |
| 497 | 453 | } |
| 498 | 454 | |
| 499 | - if(isset($_POST['web_push_enabled'])) { | |
| 500 | - if (trim(strip_tags($_POST['publisher_id_push'])) == '') { | |
| 501 | - $taboola_errors[] = "Publisher Push ID"; | |
| 502 | - } | |
| 503 | - } | |
| 504 | - | |
| 505 | 455 | if(isset($_POST['first_bc_enabled'])) { |
| 506 | 456 | if (trim(strip_tags($_POST['first_bc_widget_id'])) == '') { |
| 507 | 457 | $taboola_errors[] = "Below-article > Widget ID"; |
| 508 | 458 | } |
| @@ -567,14 +517,12 @@ | ||
| 567 | 517 | } |
| 568 | 518 | } |
| 569 | 519 | |
| 570 | 520 | if(count($taboola_errors) == 0){ |
| 521 | + | |
| 571 | 522 | $data = array( |
| 572 | 523 | "publisher_id" => trim($_POST['publisher_id']), |
| 573 | 524 | |
| 574 | - "web_push_enabled" => isset($_POST['web_push_enabled']) ? true : false, | |
| 575 | - "publisher_id_push" => !empty($_POST['publisher_id_push']) ? trim($_POST['publisher_id_push']) : '', | |
| 576 | - | |
| 577 | 525 | "first_bc_enabled" => isset($_POST['first_bc_enabled']) ? true : false, |
| 578 | 526 | "first_bc_widget_id" => !empty($_POST['first_bc_widget_id']) ? trim($_POST['first_bc_widget_id']) : '', |
| 579 | 527 | "first_bc_placement" => !empty($_POST['first_bc_placement']) ? trim($_POST['first_bc_placement']) : '', |
| 580 | 528 | |
| @@ -610,14 +558,16 @@ | ||
| 610 | 558 | } else { |
| 611 | 559 | $wpdb->update($this->tbl_taboola_settings, $data, array('id' => $settings->id)); |
| 612 | 560 | } |
| 613 | 561 | } |
| 562 | + | |
| 614 | 563 | } |
| 615 | 564 | $settings = $wpdb->get_row("select * from ".$wpdb->prefix."_taboola_settings limit 1"); |
| 616 | 565 | } |
| 566 | + | |
| 617 | 567 | include_once('settings.php'); |
| 618 | 568 | } |
| 619 | - | |
| 569 | + | |
| 620 | 570 | function is_mid_location_string_valid($mid_location_string){ |
| 621 | 571 | // TODO:: validate the location string |
| 622 | 572 | return true; |
| 623 | 573 | } |
| @@ -641,9 +591,8 @@ | ||
| 641 | 591 | return true; |
| 642 | 592 | } |
| 643 | 593 | return false; |
| 644 | 594 | } |
| 645 | - | |
| 646 | 595 | function columnExists($column_name) { |
| 647 | 596 | global $wpdb; |
| 648 | 597 | $table_name = $wpdb->prefix . "_taboola_settings"; |
| 649 | 598 | tb_write_log("table name : " . $table_name); |
| @@ -669,8 +618,9 @@ | ||
| 669 | 618 | else { |
| 670 | 619 | tb_write_log("This is NOT a v1 upgrade!"); //PC |
| 671 | 620 | return false; |
| 672 | 621 | } |
| 622 | + | |
| 673 | 623 | } |
| 674 | 624 | |
| 675 | 625 | function is_db_updated_for_min_ver($min_ver) { |
| 676 | 626 | /** |
| @@ -676,28 +626,10 @@ | ||
| 676 | 626 | /** |
| 677 | 627 | * Checks if the DB was *previously* updated for the minimum version specified. |
| 678 | 628 | * $min_ver should be passed in a format like this: "2.1.0" |
| 679 | 629 | */ |
| 680 | - | |
| 681 | 630 | global $wpdb; |
| 682 | 631 | |
| 683 | - // PC - Temporary patch for v2.1.0 | |
| 684 | - | |
| 685 | - // START patch =============================================== | |
| 686 | - // Check if the `_taboola` table exists. | |
| 687 | - // If not, then return false. | |
| 688 | - | |
| 689 | - $table_name = $wpdb->prefix . "_taboola_settings"; | |
| 690 | - | |
| 691 | - if($wpdb->get_var("SHOW TABLES LIKE '$table_name'") != $table_name) { | |
| 692 | - tb_write_log("Table NOT FOUND"); | |
| 693 | - return false; | |
| 694 | - } | |
| 695 | - else { | |
| 696 | - tb_write_log("Table EXISTS"); | |
| 697 | - } | |
| 698 | - // END patch ================================================= | |
| 699 | - | |
| 700 | 632 | // Check the saved version in wp_options. Default to '1.0.0' if the option is not found. |
| 701 | 633 | $saved_version = get_option(TABOOLA_OPTION_NAME, '1.0.0'); |
| 702 | 634 | |
| 703 | 635 | $db_is_up_to_date = version_compare($saved_version, $min_ver, '>='); |
| @@ -707,9 +639,8 @@ | ||
| 707 | 639 | } |
| 708 | 640 | |
| 709 | 641 | function is_db_updated_for_current_ver() { |
| 710 | 642 | /** |
| 711 | - * DEPRECATED | |
| 712 | 643 | * Checks if the DB was *previously* updated for the version currently loaded. |
| 713 | 644 | */ |
| 714 | 645 | global $wpdb; |
| 715 | 646 | |
| @@ -715,9 +646,9 @@ | ||
| 715 | 646 | |
| 716 | 647 | // Check the saved version in wp_options. Default to '1.0.0' if the option is not found. |
| 717 | 648 | $saved_version = get_option(TABOOLA_OPTION_NAME, '1.0.0'); |
| 718 | 649 | |
| 719 | - // Get the currently loaded plugin version. | |
| 650 | + // Get the currently loaded plugin version from wp_options. | |
| 720 | 651 | $plugin_version = $this->get_loaded_plugin_version(); |
| 721 | 652 | |
| 722 | 653 | $db_is_up_to_date = version_compare($saved_version, $plugin_version, '>='); |
| 723 | 654 | //tb_write_log($db_is_up_to_date); |
| @@ -733,16 +664,14 @@ | ||
| 733 | 664 | |
| 734 | 665 | } |
| 735 | 666 | |
| 736 | 667 | function save_taboola_version($min_ver) { |
| 737 | - /** | |
| 738 | - * Checks for the saved version in wp_options. | |
| 739 | - * If not found - adds it. Else - updates it. | |
| 740 | - */ | |
| 741 | - | |
| 668 | + // Get the currently loaded plugin version | |
| 669 | + // $plugin_version = $this->get_loaded_plugin_version(); | |
| 742 | 670 | |
| 743 | 671 | tb_write_log("SAVING NEW MIN VERSION: " . $min_ver); // PC |
| 744 | 672 | |
| 673 | + // Check the saved version in wp_options. Default to '' if the option is not found. | |
| 745 | 674 | $saved_version = get_option(TABOOLA_OPTION_NAME, ''); |
| 746 | 675 | if ($saved_version == '') { |
| 747 | 676 | add_option(TABOOLA_OPTION_NAME, $min_ver); |
| 748 | 677 | } |
| @@ -754,9 +683,9 @@ | ||
| 754 | 683 | function update_db(){ |
| 755 | 684 | |
| 756 | 685 | // If we are up to date, then skip this method... |
| 757 | 686 | if ($this->is_db_updated_for_min_ver(TABOOLA_MIN_VER)) { |
| 758 | - //tb_write_log("All up to date!"); | |
| 687 | + //tb_write_log("All up to date!"); | |
| 759 | 688 | return; |
| 760 | 689 | } |
| 761 | 690 | |
| 762 | 691 | $this->save_taboola_version(TABOOLA_MIN_VER); |
| @@ -764,10 +693,10 @@ | ||
| 764 | 693 | global $wpdb; |
| 765 | 694 | require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); |
| 766 | 695 | |
| 767 | 696 | |
| 768 | - // Handling for older MySQL versions | |
| 769 | - if (function_exists('mysql_get_server_info') && version_compare(mysql_get_server_info(), '4.1.0', '>=')) { | |
| 697 | + //check mysql version | |
| 698 | + if (function_exists('mysqli_get_server_info') && version_compare(mysqli_get_server_info(), '4.1.0', '>=')) { | |
| 770 | 699 | if (!empty($wpdb->charset)) |
| 771 | 700 | $charset_collate = "DEFAULT CHARACTER SET $wpdb->charset"; |
| 772 | 701 | if (!empty($wpdb->collate)) |
| 773 | 702 | $charset_collate .= " COLLATE $wpdb->collate"; |
| @@ -783,10 +712,8 @@ | ||
| 783 | 712 | $sql_table_settings = " |
| 784 | 713 | CREATE TABLE `" . $wpdb->prefix . "_taboola_settings` ( |
| 785 | 714 | `id` INT NOT NULL AUTO_INCREMENT , |
| 786 | 715 | `publisher_id` VARCHAR(255) DEFAULT NULL, |
| 787 | - `web_push_enabled` TINYINT(1) NOT NULL DEFAULT FALSE, | |
| 788 | - `publisher_id_push` INT(15) DEFAULT NULL, | |
| 789 | 716 | `first_bc_enabled` TINYINT(1) NOT NULL DEFAULT FALSE, |
| 790 | 717 | `first_bc_widget_id` VARCHAR(255) DEFAULT NULL, |
| 791 | 718 | `first_bc_placement` VARCHAR(255) DEFAULT " . ($is_upgrade_from_v1 ? "'below-article'" : "NULL") .", |
| 792 | 719 | `first_bc_custom_css` TEXT DEFAULT NULL, |