PluginProbe
Taboola / 2.1.1
Taboola v2.1.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 +17 -69 2.2.22.1.1 View file →
@@ -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.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*
10 +define ("TABOOLA_PLUGIN_VERSION","2.1.1"); // => 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 /**
@@ -754,9 +704,9 @@
754 704 function update_db(){
755 705
756 706 // If we are up to date, then skip this method...
757 707 if ($this->is_db_updated_for_min_ver(TABOOLA_MIN_VER)) {
758 - //tb_write_log("All up to date!");
708 + //tb_write_log("All up to date!");
759 709 return;
760 710 }
761 711
762 712 $this->save_taboola_version(TABOOLA_MIN_VER);
@@ -783,10 +733,8 @@
783 733 $sql_table_settings = "
784 734 CREATE TABLE `" . $wpdb->prefix . "_taboola_settings` (
785 735 `id` INT NOT NULL AUTO_INCREMENT ,
786 736 `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 737 `first_bc_enabled` TINYINT(1) NOT NULL DEFAULT FALSE,
790 738 `first_bc_widget_id` VARCHAR(255) DEFAULT NULL,
791 739 `first_bc_placement` VARCHAR(255) DEFAULT " . ($is_upgrade_from_v1 ? "'below-article'" : "NULL") .",
792 740 `first_bc_custom_css` TEXT DEFAULT NULL,