PluginProbe
Taboola / 2.0.1
Taboola v2.0.1
1.0.4 1.0.5 1.0.6 1.0.8 2.0.1 2.0.2 2.1.0 2.1.1 2.2.2 2.2.3 3.0.0 3.0.1 3.0.2 3.1.0 trunk 1.0 1.0.1 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.15 1.0.2 1.0.3
← All changes | taboola_widget.php +38 -124 2.2.22.0.1 View file →
@@ -1,18 +1,18 @@
1 1 <?php
2 2 /**
3 3 * Plugin Name: Taboola
4 - * Plugin URI: https://developers.taboola.com/web-integrations/docs/wordpress-plugin
4 + * Plugin URI: https://developers.taboola.com/web-integrations/discuss
5 5 * Description: Taboola
6 - * Version: 2.2.2
6 + * Version: 2.0.1
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*
12 -define ("TABOOLA_DEBUG_MODE", false); // => SET THIS TO 'FALSE' FOR *EVERY* RELEASE (USED TO SUPRESS DEBUGGING LOGS)
10 +define ("TABOOLA_PLUGIN_VERSION","2.0.1"); // => UPDATE FOR *EVERY* RELEASE (USED FOR TRACKING)
11 +define ("TABOOLA_MIN_VER","2.0.1"); // => UPDATE *ONLY* IF THIS RELEASE HAS *DB CHANGES*
12 +define ("TABOOLA_DEBUG_MODE", false); // => SET TO 'FALSE' FOR *EVERY* RELEASE (USED TO SUPRESS DEBUGGING LOGS)
13 13
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'.
14 +define ("TABOOLA_OPTION_NAME","taboola_plugin_version"); // *If* this release has DB changes, then the min version will be saved under 'taboola_plugin_version' in 'wp_options'.
15 15
16 16 define ("TABOOLA_XPATH_MARKER","/");
17 17 define ("TABOOLA_JS_INDICATOR","{JS}");
18 18 define ("TABOOLA_JS_MARKER","{");
@@ -23,9 +23,8 @@
23 23
24 24 include_once('widget.php');
25 25 require_once('JavaScriptWrapper.php');
26 26
27 -
28 27 if (!class_exists('TaboolaWP')) {
29 28 class TaboolaWP
30 29 {
31 30 //save internal data
@@ -31,28 +30,10 @@
31 30 //save internal data
32 31 public $data = array();
33 32 public $_is_widget_on_page;
34 33 public $_is_head_script_loaded = false;
35 - private $tpl_sw = 'importScripts("https://cdn.taboola.com/webpush/tsw.js");';
36 34
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()
35 + function __construct()
55 36 {
56 37 global $wpdb;
57 38
58 39 //initialize plugin constant
@@ -87,33 +68,15 @@
87 68 if (is_admin()) {
88 69 //add menu for plugin
89 70 add_action( 'admin_menu', array(&$this, 'admin_generate_menu') );
90 71 add_filter('plugin_action_links', array(&$this, 'plugin_action_links'), 10, 2 );
91 - }elseif ($this->settings != NULL){
72 + }else if ($this->settings != NULL){
92 73 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 74 add_action('wp_footer', array(&$this, 'taboola_footer_loader_js'));
112 75 add_filter('the_content', array(&$this, 'load_taboola_content'));
113 76 add_filter('the_content', array(&$this, 'load_taboola_content_mid'));
114 77 add_filter('the_content', array(&$this, 'load_taboola_content_home'));
115 - }
78 + }
116 79 }
117 80
118 81 function plugin_action_links($links, $file) {
119 82 static $this_plugin;
@@ -146,9 +109,9 @@
146 109 private function should_show_content_widget_home(){
147 110 // PC - only if v2 was installed:
148 111 if (!$this->is_db_updated_for_min_ver("2.0.0"))
149 112 return false;
150 - $retVal2 = ((trim($this->settings->publisher_id) != '') && (is_front_page() || is_home()) && $this->settings->home_enabled && trim($this->settings->home_widget_id) != '');
113 + $retVal2 = ((trim($this->settings->publisher_id) != '') && is_front_page() && $this->settings->home_enabled && trim($this->settings->home_widget_id) != '');
151 114 return $retVal2;
152 115 }
153 116
154 117 private function should_show_sidebar_widget(){
@@ -176,10 +139,9 @@
176 139 $head_string = "";
177 140
178 141 // Only adding the loader if a widget is going to be placed on the page.
179 142 if ($this->is_widget_on_page()){
180 - // PC - since these params will be inserted in 'loaderInjectionScript.js' via search and replace,
181 - // double brackets are used to ensure that each key is a unique string.
143 +
182 144 $stringParams = array(
183 145 '{{PUBLISHER_ID}}' => $this->settings->publisher_id,
184 146 '{{PAGE_TYPE}}' => $this->get_page_type(),
185 147 '{{WORDPRESS_VERSION}}' => get_bloginfo('version'),
@@ -191,8 +153,9 @@
191 153
192 154 $scriptWrapper = new JavaScriptWrapper("loaderInjectionScript.js",$stringParams);
193 155 $head_string = $scriptWrapper->getScriptMarkupString();
194 156 }
157 +
195 158 return $head_string;
196 159 }
197 160
198 161
@@ -200,23 +163,13 @@
200 163 function taboola_header_loader_inject(){
201 164 echo $this->taboola_header_loader_js();
202 165 }
203 166
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 167
215 168 function taboola_footer_loader_js() {
216 169
217 170 // Only adding flush script if a widget is going to be placed on the page.
218 - if ($this->is_widget_on_page()){
171 + if ( $this->is_widget_on_page() ){
219 172 $flushInjectionScript = new JavaScriptWrapper('flushInjectionScript.js',array());
220 173 echo $flushInjectionScript->getScriptMarkupString();
221 174 }
222 175 }
@@ -482,9 +435,9 @@
482 435 }
483 436
484 437 function admin_generate_menu(){
485 438 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);
439 + add_menu_page('Taboola', 'Taboola', 'manage_options', 'taboola_widget', array(&$this, 'admin_taboola_settings'), $this->plugin_url.'img/taboola_icon.png', 110);
487 440 }
488 441
489 442 function admin_taboola_settings(){
490 443 global $wpdb;
@@ -491,35 +444,29 @@
491 444 $settings = $wpdb->get_row("select * from ".$wpdb->prefix."_taboola_settings limit 1");
492 445 $taboola_errors = array();
493 446 if($_SERVER['REQUEST_METHOD'] == 'POST'){
494 447
495 - if(trim(strip_tags($_POST['publisher_id'])) == ''){
448 + if(trim($_POST['publisher_id']) == ''){
496 449 $taboola_errors[] = "Publisher ID";
497 450 }
498 451
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 452 if(isset($_POST['first_bc_enabled'])) {
506 - if (trim(strip_tags($_POST['first_bc_widget_id'])) == '') {
453 + if (trim($_POST['first_bc_widget_id']) == '') {
507 454 $taboola_errors[] = "Below-article > Widget ID";
508 455 }
509 - if (trim(strip_tags($_POST['first_bc_placement'])) == '') {
456 + if (trim($_POST['first_bc_placement']) == '') {
510 457 $taboola_errors[] = "Below-article > Placement Name";
511 458 }
512 459 }
513 460
514 461 if(isset($_POST['mid_enabled'])) {
515 - if (trim(strip_tags($_POST['mid_widget_id'])) == '') {
462 + if (trim($_POST['mid_widget_id']) == '') {
516 463 $taboola_errors[] = "Mid-article > Widget ID";
517 464 }
518 - if (trim(strip_tags($_POST['mid_placement'])) == '') {
465 + if (trim($_POST['mid_placement']) == '') {
519 466 $taboola_errors[] = "Mid-article > Placement Name";
520 467 }
521 - if (trim(strip_tags($_POST['mid_location_string'])) == '') {
468 + if (trim($_POST['mid_location_string']) == '') {
522 469 $taboola_errors[] = "Mid-article > CSS selector";
523 470 }
524 471 else {
525 472 // If the 'location' WAS filled in, then...
@@ -539,16 +486,16 @@
539 486
540 487 }
541 488
542 489 if(isset($_POST['home_enabled'])) {
543 - if (trim(strip_tags($_POST['home_widget_id'])) == '') {
490 + if (trim($_POST['home_widget_id']) == '') {
544 491 $taboola_errors[] = "Homepage > Widget ID";
545 492 }
546 - if (trim(strip_tags($_POST['home_placement'])) == '') {
493 + if (trim($_POST['home_placement']) == '') {
547 494 $taboola_errors[] = "Homepage > Placement Name";
548 495 }
549 496
550 - if (trim(strip_tags($_POST['home_location_string'])) == '') {
497 + if (trim($_POST['home_location_string']) == '') {
551 498 $taboola_errors[] = "Homepage > CSS selector";
552 499 }
553 500 else {
554 501 // If the 'location' WAS filled in, then...
@@ -567,14 +514,12 @@
567 514 }
568 515 }
569 516
570 517 if(count($taboola_errors) == 0){
518 +
571 519 $data = array(
572 520 "publisher_id" => trim($_POST['publisher_id']),
573 521
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 522 "first_bc_enabled" => isset($_POST['first_bc_enabled']) ? true : false,
578 523 "first_bc_widget_id" => !empty($_POST['first_bc_widget_id']) ? trim($_POST['first_bc_widget_id']) : '',
579 524 "first_bc_placement" => !empty($_POST['first_bc_placement']) ? trim($_POST['first_bc_placement']) : '',
580 525
@@ -596,28 +541,20 @@
596 541 "home_location_string" => !empty($_POST['home_location_string']) ? trim($_POST['home_location_string']) : ''
597 542 );
598 543
599 544 //var_dump($settings);
600 -
601 - $is_valid_nonce = false;
602 -
603 - if (isset( $_POST['my_plugin_nonce']) && wp_verify_nonce( $_POST['my_plugin_nonce'], 'my_plugin_update_field_action' ) ) {
604 - $is_valid_nonce = true;
545 + if($settings == NULL){
546 + $wpdb->insert($this->tbl_taboola_settings, $data, null, null);
547 + } else {
548 + $wpdb->update($this->tbl_taboola_settings, $data, array('id' => $settings->id));
605 549 }
606 -
607 - if ($is_valid_nonce) {
608 - if($settings == NULL){
609 - $wpdb->insert($this->tbl_taboola_settings, $data, null, null);
610 - } else {
611 - $wpdb->update($this->tbl_taboola_settings, $data, array('id' => $settings->id));
612 - }
613 - }
614 550 }
615 551 $settings = $wpdb->get_row("select * from ".$wpdb->prefix."_taboola_settings limit 1");
616 552 }
553 +
617 554 include_once('settings.php');
618 555 }
619 -
556 +
620 557 function is_mid_location_string_valid($mid_location_string){
621 558 // TODO:: validate the location string
622 559 return true;
623 560 }
@@ -641,9 +578,8 @@
641 578 return true;
642 579 }
643 580 return false;
644 581 }
645 -
646 582 function columnExists($column_name) {
647 583 global $wpdb;
648 584 $table_name = $wpdb->prefix . "_taboola_settings";
649 585 tb_write_log("table name : " . $table_name);
@@ -669,8 +605,9 @@
669 605 else {
670 606 tb_write_log("This is NOT a v1 upgrade!"); //PC
671 607 return false;
672 608 }
609 +
673 610 }
674 611
675 612 function is_db_updated_for_min_ver($min_ver) {
676 613 /**
@@ -676,28 +613,10 @@
676 613 /**
677 614 * Checks if the DB was *previously* updated for the minimum version specified.
678 615 * $min_ver should be passed in a format like this: "2.1.0"
679 616 */
680 -
681 617 global $wpdb;
682 618
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 619 // Check the saved version in wp_options. Default to '1.0.0' if the option is not found.
701 620 $saved_version = get_option(TABOOLA_OPTION_NAME, '1.0.0');
702 621
703 622 $db_is_up_to_date = version_compare($saved_version, $min_ver, '>=');
@@ -707,9 +626,8 @@
707 626 }
708 627
709 628 function is_db_updated_for_current_ver() {
710 629 /**
711 - * DEPRECATED
712 630 * Checks if the DB was *previously* updated for the version currently loaded.
713 631 */
714 632 global $wpdb;
715 633
@@ -715,9 +633,9 @@
715 633
716 634 // Check the saved version in wp_options. Default to '1.0.0' if the option is not found.
717 635 $saved_version = get_option(TABOOLA_OPTION_NAME, '1.0.0');
718 636
719 - // Get the currently loaded plugin version.
637 + // Get the currently loaded plugin version from wp_options.
720 638 $plugin_version = $this->get_loaded_plugin_version();
721 639
722 640 $db_is_up_to_date = version_compare($saved_version, $plugin_version, '>=');
723 641 //tb_write_log($db_is_up_to_date);
@@ -733,16 +651,14 @@
733 651
734 652 }
735 653
736 654 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 -
655 + // Get the currently loaded plugin version
656 + // $plugin_version = $this->get_loaded_plugin_version();
742 657
743 658 tb_write_log("SAVING NEW MIN VERSION: " . $min_ver); // PC
744 659
660 + // Check the saved version in wp_options. Default to '' if the option is not found.
745 661 $saved_version = get_option(TABOOLA_OPTION_NAME, '');
746 662 if ($saved_version == '') {
747 663 add_option(TABOOLA_OPTION_NAME, $min_ver);
748 664 }
@@ -751,12 +667,12 @@
751 667 }
752 668 }
753 669
754 670 function update_db(){
755 -
671 +
756 672 // If we are up to date, then skip this method...
757 673 if ($this->is_db_updated_for_min_ver(TABOOLA_MIN_VER)) {
758 - //tb_write_log("All up to date!");
674 + //tb_write_log("All up to date!");
759 675 return;
760 676 }
761 677
762 678 $this->save_taboola_version(TABOOLA_MIN_VER);
@@ -764,9 +680,9 @@
764 680 global $wpdb;
765 681 require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
766 682
767 683
768 - // Handling for older MySQL versions
684 + //check mysql version
769 685 if (function_exists('mysql_get_server_info') && version_compare(mysql_get_server_info(), '4.1.0', '>=')) {
770 686 if (!empty($wpdb->charset))
771 687 $charset_collate = "DEFAULT CHARACTER SET $wpdb->charset";
772 688 if (!empty($wpdb->collate))
@@ -783,10 +699,8 @@
783 699 $sql_table_settings = "
784 700 CREATE TABLE `" . $wpdb->prefix . "_taboola_settings` (
785 701 `id` INT NOT NULL AUTO_INCREMENT ,
786 702 `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 703 `first_bc_enabled` TINYINT(1) NOT NULL DEFAULT FALSE,
790 704 `first_bc_widget_id` VARCHAR(255) DEFAULT NULL,
791 705 `first_bc_placement` VARCHAR(255) DEFAULT " . ($is_upgrade_from_v1 ? "'below-article'" : "NULL") .",
792 706 `first_bc_custom_css` TEXT DEFAULT NULL,