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