PluginProbe
Taboola / 2.2.2
Taboola v2.2.2
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 +69 -17 2.1.12.2.2 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.1.1
6 + * Version: 2.2.2
7 7 * Author: Taboola
8 8 */
9 9
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*
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 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,10 +31,28 @@
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");';
35 36
36 - function __construct()
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()
37 55 {
38 56 global $wpdb;
39 57
40 58 //initialize plugin constant
@@ -69,15 +87,33 @@
69 87 if (is_admin()) {
70 88 //add menu for plugin
71 89 add_action( 'admin_menu', array(&$this, 'admin_generate_menu') );
72 90 add_filter('plugin_action_links', array(&$this, 'plugin_action_links'), 10, 2 );
73 - }else if ($this->settings != NULL){
91 + }elseif ($this->settings != NULL){
74 92 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 + }
75 111 add_action('wp_footer', array(&$this, 'taboola_footer_loader_js'));
76 112 add_filter('the_content', array(&$this, 'load_taboola_content'));
77 113 add_filter('the_content', array(&$this, 'load_taboola_content_mid'));
78 114 add_filter('the_content', array(&$this, 'load_taboola_content_home'));
79 - }
115 + }
80 116 }
81 117
82 118 function plugin_action_links($links, $file) {
83 119 static $this_plugin;
@@ -110,9 +146,9 @@
110 146 private function should_show_content_widget_home(){
111 147 // PC - only if v2 was installed:
112 148 if (!$this->is_db_updated_for_min_ver("2.0.0"))
113 149 return false;
114 - $retVal2 = ((trim($this->settings->publisher_id) != '') && is_front_page() && $this->settings->home_enabled && trim($this->settings->home_widget_id) != '');
150 + $retVal2 = ((trim($this->settings->publisher_id) != '') && (is_front_page() || is_home()) && $this->settings->home_enabled && trim($this->settings->home_widget_id) != '');
115 151 return $retVal2;
116 152 }
117 153
118 154 private function should_show_sidebar_widget(){
@@ -155,9 +191,8 @@
155 191
156 192 $scriptWrapper = new JavaScriptWrapper("loaderInjectionScript.js",$stringParams);
157 193 $head_string = $scriptWrapper->getScriptMarkupString();
158 194 }
159 -
160 195 return $head_string;
161 196 }
162 197
163 198
@@ -165,13 +200,23 @@
165 200 function taboola_header_loader_inject(){
166 201 echo $this->taboola_header_loader_js();
167 202 }
168 203
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 + }
169 214
170 215 function taboola_footer_loader_js() {
171 216
172 217 // Only adding flush script if a widget is going to be placed on the page.
173 - if ( $this->is_widget_on_page() ){
218 + if ($this->is_widget_on_page()){
174 219 $flushInjectionScript = new JavaScriptWrapper('flushInjectionScript.js',array());
175 220 echo $flushInjectionScript->getScriptMarkupString();
176 221 }
177 222 }
@@ -437,13 +482,12 @@
437 482 }
438 483
439 484 function admin_generate_menu(){
440 485 global $current_user;
441 - add_menu_page('Taboola', 'Taboola', 'manage_options', 'taboola_widget', array(&$this, 'admin_taboola_settings'), $this->plugin_url.'img/taboola_icon.png', 110);
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);
442 487 }
443 488
444 489 function admin_taboola_settings(){
445 -
446 490 global $wpdb;
447 491 $settings = $wpdb->get_row("select * from ".$wpdb->prefix."_taboola_settings limit 1");
448 492 $taboola_errors = array();
449 493 if($_SERVER['REQUEST_METHOD'] == 'POST'){
@@ -451,8 +495,14 @@
451 495 if(trim(strip_tags($_POST['publisher_id'])) == ''){
452 496 $taboola_errors[] = "Publisher ID";
453 497 }
454 498
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 +
455 505 if(isset($_POST['first_bc_enabled'])) {
456 506 if (trim(strip_tags($_POST['first_bc_widget_id'])) == '') {
457 507 $taboola_errors[] = "Below-article > Widget ID";
458 508 }
@@ -517,12 +567,14 @@
517 567 }
518 568 }
519 569
520 570 if(count($taboola_errors) == 0){
521 -
522 571 $data = array(
523 572 "publisher_id" => trim($_POST['publisher_id']),
524 573
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 +
525 577 "first_bc_enabled" => isset($_POST['first_bc_enabled']) ? true : false,
526 578 "first_bc_widget_id" => !empty($_POST['first_bc_widget_id']) ? trim($_POST['first_bc_widget_id']) : '',
527 579 "first_bc_placement" => !empty($_POST['first_bc_placement']) ? trim($_POST['first_bc_placement']) : '',
528 580
@@ -558,16 +610,14 @@
558 610 } else {
559 611 $wpdb->update($this->tbl_taboola_settings, $data, array('id' => $settings->id));
560 612 }
561 613 }
562 -
563 614 }
564 615 $settings = $wpdb->get_row("select * from ".$wpdb->prefix."_taboola_settings limit 1");
565 616 }
566 -
567 617 include_once('settings.php');
568 618 }
569 -
619 +
570 620 function is_mid_location_string_valid($mid_location_string){
571 621 // TODO:: validate the location string
572 622 return true;
573 623 }
@@ -591,8 +641,9 @@
591 641 return true;
592 642 }
593 643 return false;
594 644 }
645 +
595 646 function columnExists($column_name) {
596 647 global $wpdb;
597 648 $table_name = $wpdb->prefix . "_taboola_settings";
598 649 tb_write_log("table name : " . $table_name);
@@ -618,9 +669,8 @@
618 669 else {
619 670 tb_write_log("This is NOT a v1 upgrade!"); //PC
620 671 return false;
621 672 }
622 -
623 673 }
624 674
625 675 function is_db_updated_for_min_ver($min_ver) {
626 676 /**
@@ -704,9 +754,9 @@
704 754 function update_db(){
705 755
706 756 // If we are up to date, then skip this method...
707 757 if ($this->is_db_updated_for_min_ver(TABOOLA_MIN_VER)) {
708 - //tb_write_log("All up to date!");
758 + //tb_write_log("All up to date!");
709 759 return;
710 760 }
711 761
712 762 $this->save_taboola_version(TABOOLA_MIN_VER);
@@ -733,8 +783,10 @@
733 783 $sql_table_settings = "
734 784 CREATE TABLE `" . $wpdb->prefix . "_taboola_settings` (
735 785 `id` INT NOT NULL AUTO_INCREMENT ,
736 786 `publisher_id` VARCHAR(255) DEFAULT NULL,
787 + `web_push_enabled` TINYINT(1) NOT NULL DEFAULT FALSE,
788 + `publisher_id_push` INT(15) DEFAULT NULL,
737 789 `first_bc_enabled` TINYINT(1) NOT NULL DEFAULT FALSE,
738 790 `first_bc_widget_id` VARCHAR(255) DEFAULT NULL,
739 791 `first_bc_placement` VARCHAR(255) DEFAULT " . ($is_upgrade_from_v1 ? "'below-article'" : "NULL") .",
740 792 `first_bc_custom_css` TEXT DEFAULT NULL,