PluginProbe
Taboola / 3.0.0
Taboola v3.0.0
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 +18 -52 3.0.23.0.0 View file →
@@ -2,13 +2,13 @@
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: 3.0.2
6 + * Version: 3.0.0
7 7 * Author: Taboola
8 8 */
9 9
10 -define( 'TABOOLA_PLUGIN_VERSION', '3.0.2' ); // track every release
10 +define( 'TABOOLA_PLUGIN_VERSION', '3.0' ); // track every release
11 11 define( 'TABOOLA_MIN_VER', '3.0' ); // bump only when DB changes
12 12 define( 'TABOOLA_DEBUG_MODE', false );
13 13
14 14 define( 'TABOOLA_OPTION_NAME', 'taboola_plugin_version' );
@@ -21,11 +21,9 @@
21 21 define( 'TABOOLA_CONTENT_FORMAT_HTML', 'html' );
22 22
23 23 include_once 'widget.php';
24 24 require_once 'JavaScriptWrapper.php';
25 -if ( ! class_exists( 'simple_html_dom' ) ) {
26 - require_once plugin_dir_path( __FILE__ ) . 'simple_html_dom.php'; // ← NEW
27 -}
25 +require_once plugin_dir_path( __FILE__ ) . 'simple_html_dom.php'; // ← NEW
28 26
29 27 if ( ! class_exists( 'TaboolaWP' ) ) {
30 28 class TaboolaWP {
31 29
@@ -50,9 +48,9 @@
50 48
51 49 /* ─────────────────────────── constructor ─────────────────────────── */
52 50 public function __construct() {
53 51 global $wpdb;
54 - //initialize plugin constant
52 +
55 53 define( 'TaboolaWP', true );
56 54
57 55 $this->_is_widget_on_page = false;
58 56 $this->_is_head_script_loaded = false;
@@ -83,34 +81,11 @@
83 81 if ( is_admin() ) {
84 82 add_action( 'admin_menu', [ $this, 'admin_generate_menu' ] );
85 83 add_filter( 'plugin_action_links',
86 84 [ $this, 'plugin_action_links' ], 10, 2 );
87 - }
88 -
89 -
90 -
91 -
92 - elseif ( $this->settings ) {
85 + } elseif ( $this->settings ) {
93 86 /* loader & flush */
94 87 add_action( 'wp_head', [ $this, 'taboola_header_loader_inject' ] );
95 - if ( ! empty( $this->settings->publisher_id_push ) ) {
96 - add_action( 'wp_head', [ $this, 'taboola_webpush_loader_js' ] );
97 -
98 - $sw = 'sw.js';
99 - $sw_path = ABSPATH . $sw;
100 -
101 - $content = file_exists( $sw_path ) ? file_get_contents( $sw_path ) : '';
102 -
103 - if ( strpos( $content, $this->tpl_sw ) === false ) {
104 - if ( ! is_writable( ABSPATH ) || ( file_exists( $sw_path ) && ! is_writable( $sw_path ) ) ) {
105 - return $this->notice( $this->msg_sw_error );
106 - }
107 - $content = $this->tpl_sw . PHP_EOL . $content;
108 - if ( file_put_contents( $sw_path, $content ) === false ) {
109 - return $this->notice( $this->msg_sw_error );
110 - }
111 - }
112 - }
113 88 add_action( 'wp_footer', [ $this, 'taboola_footer_loader_js' ] );
114 89
115 90 /* content widgets */
116 91 add_filter( 'the_content', [ $this, 'load_taboola_content' ] );
@@ -270,21 +245,15 @@
270 245 return $page_type;
271 246 }
272 247
273 248 // return the head loader script
274 - function taboola_header_loader_js() {
249 + function taboola_header_loader_js() {
250 + $head_string = "";
251 +
252 + // Only adding the loader if a widget is going to be placed on the page.
275 253 if ($this->is_widget_on_page()){
276 -
277 - // New logic to get all mid-article locations
278 - $mid_locations_string = '';
279 - if (!empty($this->settings->mid_widgets)) {
280 - $mid_widgets_array = json_decode($this->settings->mid_widgets, true);
281 - if (is_array($mid_widgets_array)) {
282 - $locations = array_column($mid_widgets_array, 'location_string');
283 - $mid_locations_string = implode(', ', $locations);
284 - }
285 - }
286 -
254 + // PC - since these params will be inserted in 'loaderInjectionScript.js' via search and replace,
255 + // double brackets are used to ensure that each key is a unique string.
287 256 $stringParams = array(
288 257 '{{PUBLISHER_ID}}' => $this->settings->publisher_id,
289 258 '{{PAGE_TYPE}}' => $this->get_page_type(),
290 259 '{{WORDPRESS_VERSION}}' => get_bloginfo('version'),
@@ -289,18 +258,19 @@
289 258 '{{PAGE_TYPE}}' => $this->get_page_type(),
290 259 '{{WORDPRESS_VERSION}}' => get_bloginfo('version'),
291 260 '{{PHP_VERSION}}' => phpversion(),
292 261 '{{PLUGIN_VERSION}}' => TABOOLA_PLUGIN_VERSION,
293 - '{{LOC_MID}}' => $mid_locations_string,
294 - '{{LOC_HOME}}' => $this->settings->home_location_string ?? ''
262 + '{{LOC_MID}}' => $this->settings->mid_location_string,
263 + '{{LOC_HOME}}' => $this->settings->home_location_string
295 264 );
296 265
297 266 $scriptWrapper = new JavaScriptWrapper("loaderInjectionScript.js",$stringParams);
298 - return $scriptWrapper->getScriptMarkupString();
267 + $head_string = $scriptWrapper->getScriptMarkupString();
299 268 }
300 - return "";
269 + return $head_string;
301 270 }
302 271
272 +
303 273 // This function is used for the hook action, injects the header content to the <head> tag.
304 274 function taboola_header_loader_inject(){
305 275 echo $this->taboola_header_loader_js();
306 276 }
@@ -556,11 +526,9 @@
556 526
557 527 // server side selector provided (see simple_html_dom selectors http://simplehtmldom.sourceforge.net/manual.htm)
558 528 // basically it's CSS selectors like in jQuery
559 529 } else{
560 - if ( ! class_exists( 'simple_html_dom' ) ) {
561 - require_once('simple_html_dom.php');
562 - }
530 + require_once('simple_html_dom.php');
563 531
564 532 $html_doc = str_get_html($content);
565 533 $target_location = $html_doc->find($location, ($occurrence) - 1);
566 534
@@ -619,12 +587,10 @@
619 587 }
620 588
621 589 // server side selector provided (see simple_html_dom selectors http://simplehtmldom.sourceforge.net/manual.htm)
622 590 // basically it's CSS selectors like in jQuery
623 - } else{
624 - if ( ! class_exists( 'simple_html_dom' ) ) {
591 + } else{
625 592 require_once('simple_html_dom.php');
626 - }
627 593
628 594 $html_doc = str_get_html($content);
629 595 $target_location = $html_doc->find($location,($this->settings->home_location_string_occurrence)-1);
630 596