PluginProbe
Taboola / 1.0.15
Taboola v1.0.15
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 +155 -764 3.0.11.0.15 View file →
@@ -1,216 +1,83 @@
1 1 <?php
2 2 /**
3 - * Plugin Name: Taboola
4 - * Plugin URI: https://developers.taboola.com/web-integrations/docs/wordpress-plugin
5 - * Description: Taboola
6 - * Version: 3.0.1
7 - * Author: Taboola
3 + * Plugin Name: Taboola
4 + * Plugin URI: https://developers.taboola.com/web-integrations/discuss
5 + * Description: Taboola
6 + * Version: 1.0.15
7 + * Author: Taboola
8 8 */
9 9
10 -define( 'TABOOLA_PLUGIN_VERSION', '3.0.1' ); // track every release
11 -define( 'TABOOLA_MIN_VER', '3.0' ); // bump only when DB changes
12 -define( 'TABOOLA_DEBUG_MODE', false );
10 +define ("XPATH_MARKER","/");
11 +define ("JS_INDICATOR","{JS}");
12 +define ("JS_MARKER","{");
13 +define ("TABOOLA_CONTENT_FORMAT_STRING",'string');
14 +define ("TABOOLA_CONTENT_FORMAT_SCRIPT",'script');
15 +define ("TABOOLA_CONTENT_FORMAT_HTML",'html');
16 +define ("TABOOLA_PLUGIN_VERSION","1.0.15");
13 17
14 -define( 'TABOOLA_OPTION_NAME', 'taboola_plugin_version' );
15 18
16 -define( 'TABOOLA_XPATH_MARKER', '/' );
17 -define( 'TABOOLA_JS_INDICATOR', '{JS}' );
18 -define( 'TABOOLA_JS_MARKER', '{' );
19 -define( 'TABOOLA_CONTENT_FORMAT_STRING', 'string' );
20 -define( 'TABOOLA_CONTENT_FORMAT_SCRIPT', 'script' );
21 -define( 'TABOOLA_CONTENT_FORMAT_HTML', 'html' );
19 +include_once('widget.php');
20 +require_once('JavaScriptWrapper.php');
22 21
23 -include_once 'widget.php';
24 -require_once 'JavaScriptWrapper.php';
25 -require_once plugin_dir_path( __FILE__ ) . 'simple_html_dom.php'; // ← NEW
22 +if (!class_exists('TaboolaWP')) {
23 + class TaboolaWP
24 + {
25 + //save internal data
26 + public $data = array();
27 + public $_is_widget_on_page;
28 + public $_is_head_script_loaded = false;
26 29
27 -if ( ! class_exists( 'TaboolaWP' ) ) {
28 -class TaboolaWP {
29 30
30 - /* ─────────────────────────── properties ─────────────────────────── */
31 - public $data = [];
32 - public $_is_widget_on_page;
33 - public $_is_head_script_loaded = false;
31 + function __construct()
32 + {
33 + global $wpdb;
34 34
35 - private $tpl_sw = 'importScripts("https://cdn.taboola.com/webpush/tsw.js");';
36 - private $msg_sw_error = <<<SWE
37 - <p>The file <code>sw.js</code> in the WP root is not writable.
38 - Please change its permissions or paste the code below manually:</p>
39 - <pre><code>{{SW}}</code></pre>
40 - <p>Also make sure it's reachable at <code>{{DOMAIN}}/sw.js</code></p>
41 -SWE;
35 + //initialize plugin constant
36 + DEFINE('TaboolaWP', true);
42 37
43 - public $plugin_name;
44 - public $plugin_directory;
45 - public $plugin_url;
46 - public $settings;
47 - public $tbl_taboola_settings;
38 + $this->_is_widget_on_page = false;
39 + $this->_is_head_script_loaded = false;
48 40
49 - /* ─────────────────────────── constructor ─────────────────────────── */
50 - public function __construct() {
51 - global $wpdb;
52 - //initialize plugin constant
53 - define( 'TaboolaWP', true );
41 + $this->plugin_name = plugin_basename(__FILE__);
42 + $this->plugin_directory = plugin_dir_path(__FILE__);
43 + $this->plugin_url = trailingslashit(WP_PLUGIN_URL . '/' . dirname(plugin_basename(__FILE__)));
44 + $this->settings = $wpdb->get_row("select * from ".$wpdb->prefix."_taboola_settings limit 1");
54 45
55 - $this->_is_widget_on_page = false;
56 - $this->_is_head_script_loaded = false;
46 + $this->tbl_taboola_settings = $wpdb->prefix . '_taboola_settings';
57 47
58 - $this->plugin_name = plugin_basename( __FILE__ );
59 - $this->plugin_directory = plugin_dir_path( __FILE__ );
60 - $this->plugin_url = trailingslashit(
61 - WP_PLUGIN_URL . '/' . dirname( plugin_basename( __FILE__ ) )
62 - );
63 - $this->tbl_taboola_settings = $wpdb->prefix . '_taboola_settings';
64 - $this->settings = $wpdb->get_row(
65 - "SELECT * FROM {$this->tbl_taboola_settings} LIMIT 1"
66 - );
48 + //activation function
49 + register_activation_hook($this->plugin_name, array(&$this, 'activate'));
67 50
68 - /* activation / upgrade */
69 - register_activation_hook( $this->plugin_name, [ $this, 'update_db' ] );
70 - add_action( 'admin_init', [ $this, 'update_db' ] );
71 -
72 - /* widgets */
73 - if ( $this->settings && ! empty( $this->settings->publisher_id ) ) {
74 - add_action(
75 - 'widgets_init',
76 - static fn() => register_widget( 'WP_Widget_Taboola' )
77 - );
78 - }
79 -
80 - /* admin vs front-end hooks */
81 - if ( is_admin() ) {
82 - add_action( 'admin_menu', [ $this, 'admin_generate_menu' ] );
83 - add_filter( 'plugin_action_links',
84 - [ $this, 'plugin_action_links' ], 10, 2 );
85 - }
86 -
87 -
88 -
89 -
90 - elseif ( $this->settings ) {
91 - /* loader & flush */
92 - add_action( 'wp_head', [ $this, 'taboola_header_loader_inject' ] );
93 - if ( ! empty( $this->settings->publisher_id_push ) ) {
94 - add_action( 'wp_head', [ $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 - }
51 + // Enable sidebar widgets
52 + if($this->settings != NULL && !empty($this->settings->publisher_id)){
53 + //register Taboola widget
54 + add_action('widgets_init',
55 + function(){
56 + return register_widget("WP_Widget_Taboola");
110 57 }
111 - add_action( 'wp_footer', [ $this, 'taboola_footer_loader_js' ] );
58 + );
59 + }
112 60
113 - /* content widgets */
114 - add_filter( 'the_content', [ $this, 'load_taboola_content' ] );
115 - add_filter( 'the_content', [ $this, 'load_taboola_content_mid' ] );
61 + //$this->should_place_tag_outside_of_content = $this->settings->out_of_content_enabled;
116 62
117 - /* full-page buffer – home & category */
118 - add_action( 'template_redirect', [ $this, 'tb_home_buffer_start' ], 0 );
119 - add_action( 'shutdown', [ $this, 'tb_home_buffer_flush' ], PHP_INT_MAX );
120 -
121 - add_action( 'template_redirect', [ $this, 'tb_cat_buffer_start' ], 0 );
122 - add_action( 'shutdown', [ $this, 'tb_cat_buffer_flush' ], PHP_INT_MAX );
63 + if (is_admin()) {
64 + //add menu for plugin
65 + add_action( 'admin_menu', array(&$this, 'admin_generate_menu') );
66 + add_filter('plugin_action_links', array(&$this, 'plugin_action_links'), 10, 2 );
67 + } else {
68 + if($this->settings != NULL){
69 + add_action('wp_head', array(&$this, 'taboola_header_loader_inject'));
70 + add_action('wp_footer', array(&$this, 'taboola_footer_loader_js'));
71 + add_filter('the_content', array(&$this, 'load_taboola_content'));
72 + }
73 + }
123 74 }
124 - } // __construct
125 75
126 76
127 -/* ======================================================================
128 - CATEGORY ▸ should we show the widget?
129 - ====================================================================== */
130 -private function should_show_content_widget_category(): bool {
131 - return (
132 - trim( $this->settings->publisher_id ) !== '' &&
133 - ( is_category() || is_archive() || is_search() ) &&
134 - $this->settings->category_enabled &&
135 - trim( $this->settings->category_widget_id ) !== ''
136 - );
137 -}
138 77
139 -/* ----------------------------------------------------------------------
140 - HOMEPAGE ▸ full-page buffer
141 - -------------------------------------------------------------------- */
142 -public function tb_home_buffer_start() {
143 - if ( $this->should_show_content_widget_home() ) {
144 - ob_start( [ $this, 'tb_home_buffer_inject' ] );
145 - }
146 -}
147 -public function tb_home_buffer_inject( $html ) {
148 - return $this->load_taboola_content_home( $html );
149 -}
150 78
151 -/* ----------------------------------------------------------------------
152 - CATEGORY ▸ buffer hooks
153 - -------------------------------------------------------------------- */
154 -public function tb_cat_buffer_start() {
155 - if ( $this->should_show_content_widget_category() ) {
156 - ob_start( [ $this, 'tb_cat_buffer_inject' ] );
157 - }
158 -}
159 -public function tb_cat_buffer_inject( $html ) {
160 - return $this->load_taboola_content_category( $html );
161 -}
162 -public function tb_cat_buffer_flush() {
163 - if ( ob_get_length() ) {
164 - echo ob_get_clean();
165 - }
166 -}
167 -
168 -/* ----------------------------------------------------------------------
169 - CATEGORY ▸ choose where to inject
170 - -------------------------------------------------------------------- */
171 -private function embed_taboola_content_location_category(
172 - string $html,
173 - array $taboola_content,
174 - string $selector ) : string {
175 -
176 - $formatted = $this->format_taboola_content_category( $taboola_content );
177 -
178 - /* A. no selector → bottom of page */
179 - if ( $selector === '' ) {
180 - return str_ireplace( '</body>', $formatted . '</body>', $html );
181 - }
182 -
183 - /* B. selector given → try server-side injection */
184 - $doc = str_get_html( $html );
185 - if ( ! $doc ) {
186 - // parser failed → graceful fallback
187 - return str_ireplace( '</body>', $formatted . '</body>', $html );
188 - }
189 -
190 - $occurrence = max( 0, $this->settings->category_location_string_occurrence - 1 );
191 - $target = $doc->find( $selector, $occurrence );
192 -
193 - if ( $target ) { // selector found
194 - $target->outertext .= $formatted;
195 - return (string) $doc; // done – no duplicate
196 - }
197 -
198 - /* C. selector not found → bottom of page */
199 - return str_ireplace( '</body>', $formatted . '</body>', $html );
200 -}
201 -
202 -/* ------------------------------------------------------------------ */
203 -public function tb_home_buffer_flush() {
204 - if ( ob_get_length() ) {
205 - echo ob_get_clean();
206 - }
207 -}
208 -
209 -
210 -
211 -
212 -function plugin_action_links($links, $file) {
79 + function plugin_action_links($links, $file) {
213 80 static $this_plugin;
214 81
215 82 if (!$this_plugin) {
216 83 $this_plugin = plugin_basename(__FILE__);
@@ -228,27 +95,8 @@
228 95 $retVal = ((trim($this->settings->publisher_id) != '') && is_single() && $this->settings->first_bc_enabled && trim($this->settings->first_bc_widget_id) != '');
229 96 return $retVal;
230 97 }
231 98
232 - private function should_show_content_widget_mid(){
233 - // PC - only if v2 was installed:
234 - if (!$this->is_db_updated_for_min_ver("2.0.0"))
235 - return false;
236 - $retVal1 = ((trim($this->settings->publisher_id) != '') && is_single() && !empty($this->settings->mid_enabled));
237 - return $retVal1;
238 - }
239 -
240 - private function should_show_content_widget_home(){
241 - // PC - only if v2 was installed:
242 -
243 - //error_log( print_r( $this->settings, true ) ); // TEMP line
244 -
245 - if (!$this->is_db_updated_for_min_ver("2.0.0"))
246 - return false;
247 - $retVal2 = ((trim($this->settings->publisher_id) != '') && (is_front_page() || is_home()) && $this->settings->home_enabled && trim($this->settings->home_widget_id) != '');
248 - return $retVal2;
249 - }
250 -
251 99 private function should_show_sidebar_widget(){
252 100 $retVal = ((trim($this->settings->publisher_id) != '') && is_active_widget( false, false, TABOOLA_WIDGET_BASE_ID, true ));
253 101 return $retVal;
254 102 }
@@ -254,15 +102,16 @@
254 102 }
255 103
256 104 // Determine if a taboola widget should be added somewhere on the current page (content or sidebar)
257 105 function is_widget_on_page(){
258 - return $this->should_show_content_widget() || $this->should_show_content_widget_mid() || $this->should_show_content_widget_home() || $this->should_show_sidebar_widget() || $this->should_show_content_widget_category() ;
106 + return $this->should_show_content_widget() || $this->should_show_sidebar_widget();
259 107 }
260 108
261 109 function get_page_type(){
110 +
262 111 $page_type='article';
263 112 if (is_front_page()){
264 - $page_type='home';
113 + $page_type='home';
265 114 }else if (is_category() || is_archive() || is_search()){
266 115 $page_type='category';
267 116 }
268 117 return $page_type;
@@ -268,20 +117,13 @@
268 117 return $page_type;
269 118 }
270 119
271 120 // return the head loader script
272 - function taboola_header_loader_js() {
121 + function taboola_header_loader_js() {
122 + $head_string = "";
123 +
124 + // Only adding the loader if a widget is going to be placed on the page.
273 125 if ($this->is_widget_on_page()){
274 -
275 - // New logic to get all mid-article locations
276 - $mid_locations_string = '';
277 - if (!empty($this->settings->mid_widgets)) {
278 - $mid_widgets_array = json_decode($this->settings->mid_widgets, true);
279 - if (is_array($mid_widgets_array)) {
280 - $locations = array_column($mid_widgets_array, 'location_string');
281 - $mid_locations_string = implode(', ', $locations);
282 - }
283 - }
284 126
285 127 $stringParams = array(
286 128 '{{PUBLISHER_ID}}' => $this->settings->publisher_id,
287 129 '{{PAGE_TYPE}}' => $this->get_page_type(),
@@ -287,146 +129,67 @@
287 129 '{{PAGE_TYPE}}' => $this->get_page_type(),
288 130 '{{WORDPRESS_VERSION}}' => get_bloginfo('version'),
289 131 '{{PHP_VERSION}}' => phpversion(),
290 132 '{{PLUGIN_VERSION}}' => TABOOLA_PLUGIN_VERSION,
291 - '{{LOC_MID}}' => $mid_locations_string,
292 - '{{LOC_HOME}}' => $this->settings->home_location_string ?? ''
133 + '{{LOCATION}}' => $this->settings->location_string
293 134 );
294 135
295 136 $scriptWrapper = new JavaScriptWrapper("loaderInjectionScript.js",$stringParams);
296 - return $scriptWrapper->getScriptMarkupString();
137 + $head_string = $scriptWrapper->getScripMarkupString();
297 138 }
298 - return "";
139 +
140 + return $head_string;
299 141 }
300 142
143 +
301 144 // This function is used for the hook action, injects the header content to the <head> tag.
302 145 function taboola_header_loader_inject(){
146 +
303 147 echo $this->taboola_header_loader_js();
304 148 }
305 149
306 - // adding webpush loader
307 - function taboola_webpush_loader_js() {
308 - if(is_single() || is_home() || is_category() || is_front_page()){
309 - $stringParamsWeb = array(
310 - '{{PUBLISHER_ID}}' => $this->settings->publisher_id_push
311 - );
312 - $webpushInjectionScript = new JavaScriptWrapper("webPush.js",$stringParamsWeb);
313 - echo $webpushInjectionScript;
314 - }
315 - }
316 150
317 151 function taboola_footer_loader_js() {
318 152
319 153 // Only adding flush script if a widget is going to be placed on the page.
320 - if ($this->is_widget_on_page()){
154 + if ( $this->is_widget_on_page() ){
321 155 $flushInjectionScript = new JavaScriptWrapper('flushInjectionScript.js',array());
322 - echo $flushInjectionScript->getScriptMarkupString();
156 + echo $flushInjectionScript->getScripMarkupString();
323 157 }
324 158 }
325 159
326 - // Below-article widget
327 160 function load_taboola_content($content)
328 161 {
329 162 $taboola_content = array();
330 163 if ($this->should_show_content_widget()){
331 164
332 - $firstWidgetParams = array(
333 - '{{WIDGET_ID}}' => $this->settings->first_bc_widget_id,
334 - '{{CONTAINER}}' => 'taboola-below-article-thumbnails',
335 - // PC - If v2 was not installed, then use v1 logic
336 - '{{PLACEMENT}}' => (!empty($this->settings->first_bc_placement)) ? $this->settings->first_bc_placement : 'below-article' // In case v1 upgrade has not run yet
337 - );
165 + $firstWidgetParams = array('{{WIDGET_ID}}' => $this->settings->first_bc_widget_id,
166 + '{{CONTAINER}}' => 'taboola-below-article',
167 + '{{PLACEMENT}}' => 'below-article');
338 168
339 169 $firstWidgetScript = new JavaScriptWrapper("widgetInjectionScript.js",$firstWidgetParams);
340 - $taboola_content[TABOOLA_CONTENT_FORMAT_HTML][] = "<div id='taboola-below-article-thumbnails'></div>";
170 + $taboola_content[TABOOLA_CONTENT_FORMAT_HTML][] = "<div id='taboola-below-article'></div>";
341 171 $taboola_content[TABOOLA_CONTENT_FORMAT_SCRIPT][] = $firstWidgetScript;
342 172
343 - $content = $this->embed_taboola_content_location($content,$taboola_content);
344 - }
173 + // Adding the 2nd widget if needed
174 + if($this->settings->second_bc_enabled && trim($this->settings->second_bc_widget_id) != ''){
345 175
346 - return $content;
347 - }
176 + $secondWidgetParams = array('{{WIDGET_ID}}' => $this->settings->second_bc_widget_id,
177 + '{{CONTAINER}}' => 'taboola-below-article-second',
178 + '{{PLACEMENT}}' => 'below-article-2nd');
179 + $secondWidgetScript = new JavaScriptWrapper("widgetInjectionScript.js",$secondWidgetParams);
348 180
349 - // Mid-article-widget
350 - function load_taboola_content_mid($content) {
351 - if ($this->should_show_content_widget_mid()){
352 - $mid_widgets = json_decode($this->settings->mid_widgets ?? '[]');
181 + $taboola_content[TABOOLA_CONTENT_FORMAT_HTML][] = "<div id='taboola-below-article-second'></div>";
182 + $taboola_content[TABOOLA_CONTENT_FORMAT_SCRIPT][] = $secondWidgetScript;
183 + }
353 184
354 - if (is_array($mid_widgets) && !empty($mid_widgets)) {
355 - foreach ($mid_widgets as $index => $widget) {
356 - $container_id = 'taboola-mid-article-thumbnails-' . $index;
357 -
358 - $widgetParams = array(
359 - '{{WIDGET_ID}}' => $widget->widget_id,
360 - '{{CONTAINER}}' => $container_id,
361 - '{{PLACEMENT}}' => $widget->placement
362 - );
363 -
364 - $widgetScript = new JavaScriptWrapper("widgetInjectionScript.js", $widgetParams);
365 - $taboola_content_mid = array(
366 - TABOOLA_CONTENT_FORMAT_HTML => array("<div id='{$container_id}'></div>"),
367 - TABOOLA_CONTENT_FORMAT_SCRIPT => array($widgetScript),
368 - );
369 -
370 - $content = $this->embed_taboola_content_location_mid(
371 - $content,
372 - $taboola_content_mid,
373 - $widget->location_string,
374 - $widget->occurrence
375 - );
376 - }
377 - }
185 + $content = $this->embed_taboola_content_location($content,$taboola_content,trim($this->settings->location_string));
378 186 }
379 - return $content;
380 - }
381 187
382 - // Homepage widget
383 - function load_taboola_content_home($content)
384 - {
385 - //error_log( 'TB-DEBUG ② entered load_taboola_content_home' );
386 - $taboola_content_home = array();
387 - if ($this->should_show_content_widget_home()){
388 -
389 - $homeWidgetParams = array('{{WIDGET_ID}}' => $this->settings->home_widget_id,
390 - '{{CONTAINER}}' => 'taboola-homepage-thumbnails',
391 - '{{PLACEMENT}}' => $this->settings->home_placement);
392 -
393 - $homeWidgetScript = new JavaScriptWrapper("widgetInjectionScript.js",$homeWidgetParams);
394 - $taboola_content_home[TABOOLA_CONTENT_FORMAT_HTML][] = "<div id='taboola-homepage-thumbnails'></div>";
395 - $taboola_content_home[TABOOLA_CONTENT_FORMAT_SCRIPT][] = $homeWidgetScript;
396 -
397 - $content = $this->embed_taboola_content_location_home($content,$taboola_content_home,trim($this->settings->home_location_string));
398 - }
399 188 return $content;
400 -
401 189 }
402 - /* ------------------------------------------------------------------
403 - * CATEGORY ▸ build widget & inject
404 - * ------------------------------------------------------------------*/
405 -public function load_taboola_content_category( $content ) {
406 190
407 - // 1) Build the DIV that Taboola will fill
408 - $taboola[TABOOLA_CONTENT_FORMAT_HTML][] =
409 - "<div id='taboola-category-thumbnails'></div>";
410 191
411 - // 2) Build the JS that loads the feed (reuse the wrapper)
412 - $taboola[TABOOLA_CONTENT_FORMAT_SCRIPT][] =
413 - new JavaScriptWrapper( 'widgetInjectionScript.js', [
414 - '{{WIDGET_ID}}' => $this->settings->category_widget_id,
415 - '{{CONTAINER}}' => 'taboola-category-thumbnails',
416 - '{{PLACEMENT}}' => $this->settings->category_placement,
417 - ]);
418 -
419 - // 3) Decide where to insert (selector or end of <body>)
420 - return $this->embed_taboola_content_location_category(
421 - $content,
422 - $taboola,
423 - trim( $this->settings->category_location_string )
424 - );
425 -}
426 -
427 - // Below-article widget
428 -
429 192 // Extract the taboola content in the required format:
430 193 // String - for injecting on the servr side
431 194 // Script or HTML - for injecting on the client side
432 195 function format_taboola_content($taboola_content,$format){
@@ -448,105 +211,26 @@
448 211 return $ret_val;
449 212 }
450 213
451 214
452 - // Mid-article widget
453 - function format_taboola_content_mid($taboola_content_mid,$format){
454 - $ret_val = null;
455 -
456 - switch($format){
457 - case TABOOLA_CONTENT_FORMAT_STRING:
458 - $result_string = join("",$taboola_content_mid[TABOOLA_CONTENT_FORMAT_HTML]).
459 - "<script type='text/javascript'>".join("\n",$taboola_content_mid[TABOOLA_CONTENT_FORMAT_SCRIPT])."</script>";
460 - $ret_val = $result_string;
461 - break;
462 -
463 - // script or html
464 - default:
465 - $ret_val = str_replace("\n","",join("",$taboola_content_mid[$format]));
466 - break;
467 - }
468 -
469 - return $ret_val;
470 - }
471 -
472 -
473 - // Homepage widget
474 - function format_taboola_content_home($taboola_content_home,$format){
475 -
476 - $ret_val = null;
477 -
478 - switch($format){
479 - case TABOOLA_CONTENT_FORMAT_STRING:
480 - $result_string = join("",$taboola_content_home[TABOOLA_CONTENT_FORMAT_HTML]).
481 - "<script type='text/javascript'>".join("\n",$taboola_content_home[TABOOLA_CONTENT_FORMAT_SCRIPT])."</script>";
482 - $ret_val = $result_string;
483 - break;
484 -
485 - // script or html
486 - default:
487 - $ret_val = str_replace("\n","",join("",$taboola_content_home[$format]));
488 - break;
489 - }
490 -
491 - return $ret_val;
492 -
493 - }
494 -
495 -
496 - // ► CATEGORY formatter ◄
497 -private function format_taboola_content_category( $arr ) {
498 - return implode( "\n", [
499 - implode( "\n", $arr[TABOOLA_CONTENT_FORMAT_HTML] ?? [] ),
500 - '<script type="text/javascript">' .
501 - implode( "\n", $arr[TABOOLA_CONTENT_FORMAT_SCRIPT] ?? [] ) .
502 - '</script>',
503 - ]);
504 -}
505 - // Below-article widget
506 - // Do the actual logic of choosing where to place the taboola content.
507 - function embed_taboola_content_location($content, $taboola_content){
215 + // Do the actual logic of choosing where to place the taboola content based on the "location" attribute
216 + function embed_taboola_content_location($content, $taboola_content, $location){
508 217 $do_default = true;
509 218
510 - // tag is placed outside of content in order to allow "read more" functionality.
511 - if ($this->settings->out_of_content_enabled){
512 -
513 - $scriptWrapper = new JavaScriptWrapper("js_inject.min.js",array(
514 - "{{HTML}}" => $this->format_taboola_content($taboola_content,TABOOLA_CONTENT_FORMAT_HTML),
515 - "{{SCRIPT}}" => $this->format_taboola_content($taboola_content,TABOOLA_CONTENT_FORMAT_SCRIPT))
516 - );
517 - $scriptWrapper->appendScript("injectWidgetByMarker('tbmarker');");
518 - $content = $content."<span id='tbmarker'></span><script type='text/javascript'>".$scriptWrapper."</script>";
519 - $do_default = false;
520 - }
521 -
522 - // Default for below-article widget - add to the end of the content
523 - if ($do_default){
524 - $content = $content.$this->format_taboola_content($taboola_content,TABOOLA_CONTENT_FORMAT_STRING);
525 - }
526 -
527 - return $content;
528 - }
529 -
530 - // Mid-article widget
531 - // Do the actual logic of choosing where to place the taboola content based on the "location" attribute
532 - function embed_taboola_content_location_mid($content, $taboola_content_mid, $location, $occurrence = 1){
533 - $do_default = true;
534 -
535 219 if (isset($location) && $location != ''){
536 220 $first_char = substr($location,0,1);
537 221
538 222 // DIV/XPATH provided for JS handling
539 - if ($first_char == TABOOLA_JS_MARKER){
540 - $full_indicator = substr($location,0,strlen(TABOOLA_JS_INDICATOR));
223 + if ($first_char == JS_MARKER){
224 + $full_indicator = substr($location,0,strlen(JS_INDICATOR));
541 225
542 - if ($full_indicator == TABOOLA_JS_INDICATOR){
226 + if ($full_indicator == JS_INDICATOR){
543 227
544 - $xpath = substr($location,strlen(TABOOLA_JS_INDICATOR));
545 - $scriptWrapper = new JavaScriptWrapper("js_inject.min.js",array(
546 - "{{HTML}}" => $this->format_taboola_content_mid($taboola_content_mid,TABOOLA_CONTENT_FORMAT_HTML),
547 - "{{SCRIPT}}" => $this->format_taboola_content_mid($taboola_content_mid,TABOOLA_CONTENT_FORMAT_SCRIPT))
548 - );
228 + $xpath = substr($location,strlen(JS_INDICATOR));
229 + $scriptWrapper = new JavaScriptWrapper("js_inject.min.js",array(
230 + "{{HTML}}" => $this->format_taboola_content($taboola_content,TABOOLA_CONTENT_FORMAT_HTML),
231 + "{{SCRIPT}}" => $this->format_taboola_content($taboola_content,TABOOLA_CONTENT_FORMAT_SCRIPT))
232 + );
549 233 $scriptWrapper->appendScript("injectWidgetByXpath('".$xpath."');");
550 234 $content = $content."<span id='tbdefault'></span><script type='text/javascript'>".$scriptWrapper."</script>";
551 235
552 236 $do_default = false;
@@ -551,100 +235,51 @@
551 235
552 236 $do_default = false;
553 237 }
554 238
555 - // server side selector provided (see simple_html_dom selectors http://simplehtmldom.sourceforge.net/manual.htm)
239 + // server side selector provided (see simple_html_dom selectors https://simplehtmldom.sourceforge.net/manual.htm)
556 240 // basically it's CSS selectors like in jQuery
557 241 } else{
242 +
558 243 require_once('simple_html_dom.php');
559 244
560 245 $html_doc = str_get_html($content);
561 - $target_location = $html_doc->find($location, ($occurrence) - 1);
246 + $target_location = $html_doc->find($location,0);
562 247
563 248 // if the location was found within the html content
564 249 if (isset($target_location) && is_object($target_location)){
565 250
566 251 // adding taboola content AFTER the target location
567 - $target_location->outertext = $target_location->outertext.$this->format_taboola_content_mid($taboola_content_mid,TABOOLA_CONTENT_FORMAT_STRING);
252 + $target_location->outertext = $target_location->outertext.$this->format_taboola_content($taboola_content,TABOOLA_CONTENT_FORMAT_STRING);
568 253 $content = $html_doc;
569 254 $do_default = false;
570 255 }
571 256 }
257 +
258 + // tag is placed outside of content in order to allow "read more" functionality.
259 + }elseif ($this->settings->out_of_content_enabled){
260 +
261 + $scriptWrapper = new JavaScriptWrapper("js_inject.min.js",array(
262 + "{{HTML}}" => $this->format_taboola_content($taboola_content,TABOOLA_CONTENT_FORMAT_HTML),
263 + "{{SCRIPT}}" => $this->format_taboola_content($taboola_content,TABOOLA_CONTENT_FORMAT_SCRIPT))
264 + );
265 + $scriptWrapper->appendScript("injectWidgetByMarker('tbmarker');");
266 + $content = $content."<span id='tbmarker'></span><script type='text/javascript'>".$scriptWrapper."</script>";
267 + $do_default = false;
572 268 }
573 269
270 + // Default - add to the end of the content
271 + if ($do_default){
272 + $content = $content.$this->format_taboola_content($taboola_content,TABOOLA_CONTENT_FORMAT_STRING);
273 + }
274 +
574 275 return $content;
575 276 }
576 277
577 - // Homepage widget
578 - // Do the actual logic of choosing where to place the taboola content based on the "location" attribute
579 - function embed_taboola_content_location_home($content, $taboola_content_home, $location){
580 278
581 -
582 - // error_log( 'TB-DEBUG ③ raw selector string: [' . $location . ']' );
583 -
584 - // load parser
585 - //require_once plugin_dir_path( __FILE__ ) . 'simple_html_dom.php';
586 - // $html_doc = str_get_html( $content );
587 -
588 - // occurrence: settings is 1-based, find() wants 0-based
589 - // $occurrence = max( 1, intval( $this->settings->home_location_string_occurrence ) );
590 - // $node = $html_doc->find( $location, $occurrence - 1 );
591 - // $found = is_object( $node ) ? 1 : 0;
592 -
593 - // error_log( "TB-DEBUG ③ found {$found} matching node(s) for selector [{$location}]" );
594 - // ────────────────────────────
595 - $do_default = true;
596 -
597 - if (isset($location) && $location != ''){
598 - $first_char = substr($location,0,1);
599 -
600 - // DIV/XPATH provided for JS handling
601 - if ($first_char == TABOOLA_JS_MARKER){
602 - $full_indicator = substr($location,0,strlen(TABOOLA_JS_INDICATOR));
603 -
604 - if ($full_indicator == TABOOLA_JS_INDICATOR){
605 -
606 - $xpath = substr($location,strlen(TABOOLA_JS_INDICATOR));
607 - $scriptWrapper = new JavaScriptWrapper("js_inject.min.js",array(
608 - "{{HTML}}" => $this->format_taboola_content_home($taboola_content_home,TABOOLA_CONTENT_FORMAT_HTML),
609 - "{{SCRIPT}}" => $this->format_taboola_content_home($taboola_content_home,TABOOLA_CONTENT_FORMAT_SCRIPT))
610 - );
611 - $scriptWrapper->appendScript("injectWidgetByXpath('".$xpath."');");
612 - $content = $content."<span id='tbdefault'></span><script type='text/javascript'>".$scriptWrapper."</script>";
613 -
614 - $do_default = false;
615 - }
616 -
617 - // server side selector provided (see simple_html_dom selectors http://simplehtmldom.sourceforge.net/manual.htm)
618 - // basically it's CSS selectors like in jQuery
619 - } else{
620 - require_once('simple_html_dom.php');
621 -
622 - $html_doc = str_get_html($content);
623 - $target_location = $html_doc->find($location,($this->settings->home_location_string_occurrence)-1);
624 -
625 - // if the location was found within the html content
626 - if (isset($target_location) && is_object($target_location)){
627 -
628 - // adding taboola content AFTER the target location
629 - $target_location->outertext = $target_location->outertext.$this->format_taboola_content_home($taboola_content_home,TABOOLA_CONTENT_FORMAT_STRING);
630 - $content = $html_doc;
631 - $do_default = false;
632 - }
633 - }
634 - }
635 - // Default for below-article widget - add to the end of the content
636 - if ($do_default){
637 - $content = $content.$this->format_taboola_content_home($taboola_content_home,TABOOLA_CONTENT_FORMAT_STRING);
638 - }
639 - return $content;
640 -
641 -
642 - }
643 -
644 279 function admin_generate_menu(){
645 280 global $current_user;
646 - 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);
281 + add_menu_page('Taboola', 'Taboola', 'manage_options', 'taboola_widget', array(&$this, 'admin_taboola_settings'), $this->plugin_url.'img/taboola_icon.png', 110);
647 282 }
648 283
649 284 function admin_taboola_settings(){
650 285 global $wpdb;
@@ -651,278 +286,81 @@
651 286 $settings = $wpdb->get_row("select * from ".$wpdb->prefix."_taboola_settings limit 1");
652 287 $taboola_errors = array();
653 288 if($_SERVER['REQUEST_METHOD'] == 'POST'){
654 289
655 - if(trim(strip_tags($_POST['publisher_id'])) == ''){
656 - $taboola_errors[] = "Publisher ID";
290 + if(trim($_POST['publisher_id']) == ''){
291 + $taboola_errors[] = "Please add a 'Publisher ID' in order to apply changes to your widgets";
657 292 }
658 -
659 - if(isset($_POST['web_push_enabled'])) {
660 - if (trim(strip_tags($_POST['publisher_id_push'])) == '') {
661 - $taboola_errors[] = "Publisher Push ID";
662 - }
293 + if((isset($_POST['first_bc_enabled']) && trim($_POST['first_bc_widget_id']) == '') ||
294 + (isset($_POST['second_bc_enabled']) && trim($_POST['second_bc_widget_id']) == '')
295 + ){
296 + $taboola_errors[] = "Please add a 'Widget ID' in order to apply changes to your widgets";
663 297 }
664 -
665 - if(isset($_POST['first_bc_enabled'])) {
666 - if (trim(strip_tags($_POST['first_bc_widget_id'])) == '') {
667 - $taboola_errors[] = "Below-article > Widget ID";
668 - }
669 - if (trim(strip_tags($_POST['first_bc_placement'])) == '') {
670 - $taboola_errors[] = "Below-article > Placement Name";
671 - }
298 + if (trim($_POST['location_string']) != '' && !$this->is_location_string_valid($_POST['location_string'])){
299 + $taboola_errors[] = "Location string not valid, please contact your Taboola account manager to get a valid location string";
672 300 }
673 -
674 - if(isset($_POST['mid_enabled'])) {
675 - if(isset($_POST['mid_widget_id']) && is_array($_POST['mid_widget_id'])) {
676 - foreach ($_POST['mid_widget_id'] as $index => $widget_id) {
677 - if(trim($widget_id) == '') {
678 - $taboola_errors[] = "Mid-article Widget #".($index + 1)." > Widget ID";
679 - }
680 - if(trim($_POST['mid_placement'][$index]) == '') {
681 - $taboola_errors[] = "Mid-article Widget #".($index + 1)." > Placement Name";
682 - }
683 - }
684 - }
685 - }
686 -
687 - if(isset($_POST['home_enabled'])) {
688 - if (trim(strip_tags($_POST['home_widget_id'])) == '') {
689 - $taboola_errors[] = "Homepage > Widget ID";
690 - }
691 - if (trim(strip_tags($_POST['home_placement'])) == '') {
692 - $taboola_errors[] = "Homepage > Placement Name";
693 - }
694 -
695 - if (trim(strip_tags($_POST['home_location_string'])) == '') {
696 - $taboola_errors[] = "Homepage > CSS selector";
697 - }
698 - else {
699 - if (!empty($_POST['home_location_string']) && !$this->is_home_location_string_occurrence_valid($_POST['home_location_string_occurrence'])) {
700 - $taboola_errors[] = "Homepage > Occurance (must be >= 1)";
701 - }
702 - }
703 - }
704 - if ( isset($_POST['category_enabled']) ) {
705 - if ( trim(strip_tags($_POST['category_widget_id'])) == '' )
706 - $taboola_errors[] = "Category > Widget ID";
707 - if ( trim(strip_tags($_POST['category_placement'])) == '' )
708 - $taboola_errors[] = "Category > Placement Name";
709 - }
710 -
711 301 if(count($taboola_errors) == 0){
712 -
713 - $mid_widgets_data = array();
714 - if (isset($_POST['mid_widget_id']) && is_array($_POST['mid_widget_id'])) {
715 - foreach ($_POST['mid_widget_id'] as $index => $widget_id) {
716 - if (!empty(trim($widget_id))) {
717 -
718 - $location_string = 'p';
719 - if (isset($_POST['mid_paragraph_ui_mode'][$index]) && $_POST['mid_paragraph_ui_mode'][$index] === 'Other') {
720 - if (isset($_POST['mid_location_string'][$index])) {
721 - $location_string = sanitize_text_field($_POST['mid_location_string'][$index]);
722 - }
723 - }
724 302
725 - $mid_widgets_data[] = array(
726 - 'widget_id' => sanitize_text_field($widget_id),
727 - 'placement' => sanitize_text_field($_POST['mid_placement'][$index]),
728 - 'location_string' => $location_string,
729 - 'occurrence' => intval($_POST['mid_location_string_occurrence'][$index]),
730 - );
731 - }
732 - }
733 - }
734 - $mid_widgets_json = json_encode($mid_widgets_data);
735 -
736 303 $data = array(
737 304 "publisher_id" => trim($_POST['publisher_id']),
738 -
739 - "web_push_enabled" => isset($_POST['web_push_enabled']) ? true : false,
740 - "publisher_id_push" => !empty($_POST['publisher_id_push']) ? trim($_POST['publisher_id_push']) : '',
741 -
742 305 "first_bc_enabled" => isset($_POST['first_bc_enabled']) ? true : false,
743 - "first_bc_widget_id" => !empty($_POST['first_bc_widget_id']) ? trim($_POST['first_bc_widget_id']) : '',
744 - "first_bc_placement" => !empty($_POST['first_bc_placement']) ? trim($_POST['first_bc_placement']) : '',
745 -
746 - "out_of_content_enabled" => isset($_POST['out_of_content_enabled']) ? true : false,
747 -
748 - "mid_enabled" => isset($_POST['mid_enabled']) ? true : false,
749 - "mid_widgets" => $mid_widgets_json,
750 -
751 - "home_enabled" => isset($_POST['home_enabled']) ? true : false,
752 - "home_widget_id" => !empty($_POST['home_widget_id']) ? trim($_POST['home_widget_id']) : '',
753 - "home_placement" => !empty($_POST['home_placement']) ? trim($_POST['home_placement']) : '',
754 -
755 - "home_location_string_occurrence" => !empty($_POST['home_location_string_occurrence']) ? $_POST['home_location_string_occurrence'] : '',
756 - "home_location_string" => !empty($_POST['home_location_string']) ? trim($_POST['home_location_string']) : '',
757 - "category_enabled" => isset($_POST['category_enabled']) ? true : false,
758 - "category_widget_id" => !empty($_POST['category_widget_id']) ? trim($_POST['category_widget_id']) : '',
759 - "category_placement" => !empty($_POST['category_placement']) ? trim($_POST['category_placement']) : '',
760 - "category_location_string_occurrence" => !empty($_POST['category_location_string_occurrence']) ? $_POST['category_location_string_occurrence'] : '',
761 - "category_location_string" => !empty($_POST['category_location_string']) ? trim($_POST['category_location_string']) : '',
762 -
306 + "first_bc_widget_id" => trim($_POST['first_bc_widget_id']),
307 + "second_bc_enabled" => isset($_POST['second_bc_enabled']) ? true : false,
308 + "second_bc_widget_id" => trim($_POST['second_bc_widget_id']),
309 + "location_string" => trim($_POST['location_string']),
310 + "out_of_content_enabled" => isset($_POST['out_of_content_enabled']) ? true : false
763 311 );
764 312
765 - $is_valid_nonce = false;
766 -
767 - if (isset( $_POST['my_plugin_nonce']) && wp_verify_nonce( $_POST['my_plugin_nonce'], 'my_plugin_update_field_action' ) ) {
768 - $is_valid_nonce = true;
313 + //var_dump($settings);
314 + if($settings == NULL){
315 + $wpdb->insert($this->tbl_taboola_settings, $data, null, null);
316 + } else {
317 + $wpdb->update($this->tbl_taboola_settings, $data, array('id' => $settings->id));
769 318 }
770 -
771 - if ($is_valid_nonce) {
772 - if($settings == NULL){
773 - $wpdb->insert($this->tbl_taboola_settings, $data);
774 - } else {
775 - $wpdb->update($this->tbl_taboola_settings, $data, array('id' => $settings->id));
776 - }
777 - }
778 319 }
779 320 $settings = $wpdb->get_row("select * from ".$wpdb->prefix."_taboola_settings limit 1");
780 321 }
781 - include_once('settings.php');
782 - }
783 -
784 - function is_mid_location_string_valid($mid_location_string){
785 - // TODO:: validate the location string
786 - return true;
787 - }
788 322
789 - function is_mid_location_string_occurrence_valid($mid_location_string_occurrence){
790 323
791 - if ((int)$mid_location_string_occurrence >= 1) {
792 - return true;
793 - }
794 - return false;
324 + include_once('settings.php');
795 325 }
796 326
797 - function is_home_location_string_valid($home_location_string){
327 + function is_location_string_valid($location_string){
798 328 // TODO:: validate the location string
799 329 return true;
800 330 }
801 -
802 - function is_home_location_string_occurrence_valid($home_location_string_occurrence){
803 -
804 - if ((int)$home_location_string_occurrence >= 1) {
805 - return true;
806 - }
807 - return false;
808 - }
809 -
810 - function columnExists($column_name) {
331 + function activate(){
811 332 global $wpdb;
812 - $table_name = $wpdb->prefix . "_taboola_settings";
813 - tb_write_log("table name : " . $table_name);
814 - tb_write_log("column name : " . $column_name);
815 333
816 - $column_exists = $wpdb->get_var("SHOW COLUMNS FROM $table_name LIKE '$column_name'") !== null;
334 + require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
817 335
818 - if ($column_exists) {
819 - tb_write_log("Yes - column " . $column_name . " DOES exist!"); //PC
820 - return true;
821 - } else {
822 - tb_write_log("No - column " . $column_name . " does NOT exist!"); //PC
823 - return false;
824 - }
825 - }
336 + $settings_table = $this->tbl_taboola_settings;
826 337
827 - function is_upgrade_from_v1() {
828 -
829 - if($this->columnExists("first_bc_widget_id") && !$this->columnExists("first_bc_placement")){
830 - tb_write_log("This IS a v1 upgrade!"); //PC
831 - return true;
832 - }
833 - else {
834 - tb_write_log("This is NOT a v1 upgrade!"); //PC
835 - return false;
338 + //check mysql version
339 + if (function_exists('mysql_get_server_info') && version_compare(mysql_get_server_info(), '4.1.0', '>=')) {
340 + if (!empty($wpdb->charset))
341 + $charset_collate = "DEFAULT CHARACTER SET $wpdb->charset";
342 + if (!empty($wpdb->collate))
343 + $charset_collate .= " COLLATE $wpdb->collate";
836 344 }
837 - }
838 345
839 - function is_db_updated_for_min_ver($min_ver) {
840 - global $wpdb;
841 - $table_name = $wpdb->prefix . "_taboola_settings";
842 -
843 - if($wpdb->get_var("SHOW TABLES LIKE '$table_name'") != $table_name) {
844 - tb_write_log("Table NOT FOUND");
845 - return false;
846 - }
847 - else {
848 - tb_write_log("Table EXISTS");
849 - }
850 - $saved_version = get_option(TABOOLA_OPTION_NAME, '1.0.0');
851 -
852 - $db_is_up_to_date = version_compare($saved_version, $min_ver, '>=');
853 - return $db_is_up_to_date;
854 -
855 - }
856 -
857 - function is_db_updated_for_current_ver() {
858 - global $wpdb;
859 - $saved_version = get_option(TABOOLA_OPTION_NAME, '1.0.0');
860 - $plugin_version = $this->get_loaded_plugin_version();
861 - $db_is_up_to_date = version_compare($saved_version, $plugin_version, '>=');
862 - return $db_is_up_to_date;
863 - }
864 -
865 - function get_loaded_plugin_version() {
866 - $plugin_data = get_plugin_data( __FILE__ );
867 - $loaded_plugin_version = $plugin_data['Version'];
868 - return $loaded_plugin_version;
869 - }
870 -
871 - function save_taboola_version($min_ver) {
872 - tb_write_log("SAVING NEW MIN VERSION: " . $min_ver); // PC
873 - $saved_version = get_option(TABOOLA_OPTION_NAME, '');
874 - if ($saved_version == '') {
875 - add_option(TABOOLA_OPTION_NAME, $min_ver);
876 - }
877 - else {
878 - update_option(TABOOLA_OPTION_NAME, $min_ver);
879 - }
880 - }
881 -
882 - function update_db(){
883 - if ($this->is_db_updated_for_min_ver(TABOOLA_MIN_VER)) {
884 - return;
885 - }
886 -
887 - $this->save_taboola_version(TABOOLA_MIN_VER);
888 -
889 - global $wpdb;
890 - require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
891 -
892 - $charset_collate = '';
893 - if ( ! empty( $wpdb->charset ) ) {
894 - $charset_collate = "DEFAULT CHARACTER SET {$wpdb->charset}";
895 - }
896 - if ( ! empty( $wpdb->collate ) ) {
897 - $charset_collate .= " COLLATE {$wpdb->collate}";
898 - }
899 -
900 - $is_upgrade_from_v1 = $this->is_upgrade_from_v1();
346 + //settings table structure
901 347 $sql_table_settings = "
902 348 CREATE TABLE `" . $wpdb->prefix . "_taboola_settings` (
903 349 `id` INT NOT NULL AUTO_INCREMENT ,
904 350 `publisher_id` VARCHAR(255) DEFAULT NULL,
905 - `web_push_enabled` TINYINT(1) NOT NULL DEFAULT FALSE,
906 - `publisher_id_push` INT(15) DEFAULT NULL,
907 351 `first_bc_enabled` TINYINT(1) NOT NULL DEFAULT FALSE,
908 352 `first_bc_widget_id` VARCHAR(255) DEFAULT NULL,
909 - `first_bc_placement` VARCHAR(255) DEFAULT " . ($is_upgrade_from_v1 ? "'below-article'" : "NULL") .",
353 + `first_bc_custom_css` TEXT DEFAULT NULL,
354 + `second_bc_enabled` TINYINT(1) NOT NULL DEFAULT FALSE,
355 + `second_bc_widget_id` VARCHAR(255) DEFAULT NULL,
356 + `second_bc_custom_css` TEXT DEFAULT NULL,
357 + `location_string` TEXT DEFAULT NULL,
910 358 `out_of_content_enabled` TINYINT(1) NOT NULL DEFAULT TRUE,
911 - `mid_enabled` TINYINT(1) NOT NULL DEFAULT FALSE,
912 - `mid_widgets` TEXT DEFAULT NULL,
913 - `home_enabled` TINYINT(1) NOT NULL DEFAULT FALSE,
914 - `home_widget_id` VARCHAR(255) DEFAULT NULL,
915 - `home_placement` VARCHAR(255) DEFAULT NULL,
916 - `home_location_string` TEXT DEFAULT NULL,
917 - `home_location_string_occurrence` SMALLINT DEFAULT NULL,
918 - `category_enabled` TINYINT(1) NOT NULL DEFAULT FALSE,
919 - `category_widget_id` VARCHAR(255) DEFAULT NULL,
920 - `category_placement` VARCHAR(255) DEFAULT NULL,
921 - `category_location_string` TEXT DEFAULT NULL,
922 - `category_location_string_occurrence` SMALLINT DEFAULT NULL,
923 359 PRIMARY KEY (`id`)
924 - ) $charset_collate;";
360 + )" . $charset_collate . ";";
361 +
362 + // create/update the table
925 363 dbDelta($sql_table_settings);
926 364 }
927 365 }
928 366 }
@@ -929,52 +367,5 @@
929 367
930 368 global $taboolaWP;
931 369 $taboolaWP = new TaboolaWP();
932 370
933 -function tb_write_log($log_msg)
934 -{
935 - if (!TABOOLA_DEBUG_MODE)
936 - return;
937 -
938 - $log_filename = "logs";
939 - if (!file_exists($log_filename))
940 - {
941 - mkdir($log_filename, 0777, true);
942 - }
943 - $log_file_data = $log_filename.'/debug.log';
944 -
945 - $date = date('Y-m-d H:i:s');
946 - $log_msg_with_date = $date." : ".$log_msg;
947 -
948 - file_put_contents($log_file_data, $log_msg_with_date . "\n", FILE_APPEND);
949 -}
950 -
951 -function tb_console_log( $data ){
952 -
953 - If(wp_get_environment_type() === 'development') {
954 -
955 - echo '<script>';
956 - echo 'console.log('. json_encode( $data ) .')';
957 - echo '</script>';
958 -
959 - }
960 -}
961 -
962 -function tb_print_to_page($data) {
963 - If(wp_get_environment_type() === 'development') {
964 - print_r($data);
965 - die;
966 - }
967 -}
968 -
969 -function enqueue_taboola_scripts() {
970 - wp_register_script(
971 - 'taboola-injector',
972 - plugins_url('js/js_inject.min.js', __FILE__),
973 - array(),
974 - null,
975 - true
976 - );
977 -
978 - wp_enqueue_script('taboola-injector');
979 -}
980 -add_action('wp_enqueue_scripts', 'enqueue_taboola_scripts');
371 +//