PluginProbe
Taboola / 3.0.2
Taboola v3.0.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 +52 -18 3.0.03.0.2 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.0
6 + * Version: 3.0.2
7 7 * Author: Taboola
8 8 */
9 9
10 -define( 'TABOOLA_PLUGIN_VERSION', '3.0' ); // track every release
10 +define( 'TABOOLA_PLUGIN_VERSION', '3.0.2' ); // 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,9 +21,11 @@
21 21 define( 'TABOOLA_CONTENT_FORMAT_HTML', 'html' );
22 22
23 23 include_once 'widget.php';
24 24 require_once 'JavaScriptWrapper.php';
25 -require_once plugin_dir_path( __FILE__ ) . 'simple_html_dom.php'; // ← NEW
25 +if ( ! class_exists( 'simple_html_dom' ) ) {
26 + require_once plugin_dir_path( __FILE__ ) . 'simple_html_dom.php'; // ← NEW
27 +}
26 28
27 29 if ( ! class_exists( 'TaboolaWP' ) ) {
28 30 class TaboolaWP {
29 31
@@ -48,9 +50,9 @@
48 50
49 51 /* ─────────────────────────── constructor ─────────────────────────── */
50 52 public function __construct() {
51 53 global $wpdb;
52 -
54 + //initialize plugin constant
53 55 define( 'TaboolaWP', true );
54 56
55 57 $this->_is_widget_on_page = false;
56 58 $this->_is_head_script_loaded = false;
@@ -81,11 +83,34 @@
81 83 if ( is_admin() ) {
82 84 add_action( 'admin_menu', [ $this, 'admin_generate_menu' ] );
83 85 add_filter( 'plugin_action_links',
84 86 [ $this, 'plugin_action_links' ], 10, 2 );
85 - } elseif ( $this->settings ) {
87 + }
88 +
89 +
90 +
91 +
92 + elseif ( $this->settings ) {
86 93 /* loader & flush */
87 94 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 + }
88 113 add_action( 'wp_footer', [ $this, 'taboola_footer_loader_js' ] );
89 114
90 115 /* content widgets */
91 116 add_filter( 'the_content', [ $this, 'load_taboola_content' ] );
@@ -245,15 +270,21 @@
245 270 return $page_type;
246 271 }
247 272
248 273 // return the head loader script
249 - function taboola_header_loader_js() {
250 - $head_string = "";
274 + function taboola_header_loader_js() {
275 + 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 + }
251 286
252 - // Only adding the loader if a widget is going to be placed on the page.
253 - if ($this->is_widget_on_page()){
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.
256 287 $stringParams = array(
257 288 '{{PUBLISHER_ID}}' => $this->settings->publisher_id,
258 289 '{{PAGE_TYPE}}' => $this->get_page_type(),
259 290 '{{WORDPRESS_VERSION}}' => get_bloginfo('version'),
@@ -258,19 +289,18 @@
258 289 '{{PAGE_TYPE}}' => $this->get_page_type(),
259 290 '{{WORDPRESS_VERSION}}' => get_bloginfo('version'),
260 291 '{{PHP_VERSION}}' => phpversion(),
261 292 '{{PLUGIN_VERSION}}' => TABOOLA_PLUGIN_VERSION,
262 - '{{LOC_MID}}' => $this->settings->mid_location_string,
263 - '{{LOC_HOME}}' => $this->settings->home_location_string
293 + '{{LOC_MID}}' => $mid_locations_string,
294 + '{{LOC_HOME}}' => $this->settings->home_location_string ?? ''
264 295 );
265 296
266 297 $scriptWrapper = new JavaScriptWrapper("loaderInjectionScript.js",$stringParams);
267 - $head_string = $scriptWrapper->getScriptMarkupString();
298 + return $scriptWrapper->getScriptMarkupString();
268 299 }
269 - return $head_string;
300 + return "";
270 301 }
271 302
272 -
273 303 // This function is used for the hook action, injects the header content to the <head> tag.
274 304 function taboola_header_loader_inject(){
275 305 echo $this->taboola_header_loader_js();
276 306 }
@@ -526,9 +556,11 @@
526 556
527 557 // server side selector provided (see simple_html_dom selectors http://simplehtmldom.sourceforge.net/manual.htm)
528 558 // basically it's CSS selectors like in jQuery
529 559 } else{
530 - require_once('simple_html_dom.php');
560 + if ( ! class_exists( 'simple_html_dom' ) ) {
561 + require_once('simple_html_dom.php');
562 + }
531 563
532 564 $html_doc = str_get_html($content);
533 565 $target_location = $html_doc->find($location, ($occurrence) - 1);
534 566
@@ -587,10 +619,12 @@
587 619 }
588 620
589 621 // server side selector provided (see simple_html_dom selectors http://simplehtmldom.sourceforge.net/manual.htm)
590 622 // basically it's CSS selectors like in jQuery
591 - } else{
623 + } else{
624 + if ( ! class_exists( 'simple_html_dom' ) ) {
592 625 require_once('simple_html_dom.php');
626 + }
593 627
594 628 $html_doc = str_get_html($content);
595 629 $target_location = $html_doc->find($location,($this->settings->home_location_string_occurrence)-1);
596 630