| @@ -1,18 +1,18 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | 3 | * Plugin Name: Taboola |
| 4 | - * Plugin URI: https://developers.taboola.com/web-integrations/docs/wordpress-plugin | |
| 4 | + * Plugin URI: https://developers.taboola.com/web-integrations/discuss | |
| 5 | 5 | * Description: Taboola |
| 6 | - * Version: 2.2.3 | |
| 6 | + * Version: 2.0.2 | |
| 7 | 7 | * Author: Taboola |
| 8 | 8 | */ |
| 9 | 9 | |
| 10 | -define ("TABOOLA_PLUGIN_VERSION","2.2.3"); // => UPDATE THIS FOR *EVERY* RELEASE (USED FOR TRACKING) | |
| 11 | -define ("TABOOLA_MIN_VER","2.2.2"); // => UPDATE THIS *ONLY* IF THIS RELEASE HAS *DB CHANGES* | |
| 12 | -define ("TABOOLA_DEBUG_MODE", false); // => SET THIS TO 'FALSE' FOR *EVERY* RELEASE (USED TO SUPRESS DEBUGGING LOGS) | |
| 10 | +define ("TABOOLA_PLUGIN_VERSION","2.0.2"); // => UPDATE FOR *EVERY* RELEASE (USED FOR TRACKING) | |
| 11 | +define ("TABOOLA_MIN_VER","2.0.1"); // => UPDATE *ONLY* IF THIS RELEASE HAS *DB CHANGES* | |
| 12 | +define ("TABOOLA_DEBUG_MODE", false); // => SET TO 'FALSE' FOR *EVERY* RELEASE (USED TO SUPRESS DEBUGGING LOGS) | |
| 13 | 13 | |
| 14 | -define ("TABOOLA_OPTION_NAME","taboola_plugin_version"); // Note: if this release has DB changes, then the min version will be saved under 'taboola_plugin_version' in 'wp_options'. | |
| 14 | +define ("TABOOLA_OPTION_NAME","taboola_plugin_version"); // *If* this release has DB changes, then the min version will be saved under 'taboola_plugin_version' in 'wp_options'. | |
| 15 | 15 | |
| 16 | 16 | define ("TABOOLA_XPATH_MARKER","/"); |
| 17 | 17 | define ("TABOOLA_JS_INDICATOR","{JS}"); |
| 18 | 18 | define ("TABOOLA_JS_MARKER","{"); |
| @@ -31,28 +31,10 @@ | ||
| 31 | 31 | //save internal data |
| 32 | 32 | public $data = array(); |
| 33 | 33 | public $_is_widget_on_page; |
| 34 | 34 | public $_is_head_script_loaded = false; |
| 35 | - private $tpl_sw = 'importScripts("https://cdn.taboola.com/webpush/tsw.js");'; | |
| 36 | 35 | |
| 37 | - private $msg_sw_error = <<<SWE | |
| 38 | - <p> | |
| 39 | - The file sw.js in the root directory of Wordpress is not writable. | |
| 40 | - Please change its permissions and try again. Otherwise replace its contents manually: | |
| 41 | - </p> | |
| 42 | - <pre><code>{{SW}}</code></pre> | |
| 43 | - <p> | |
| 44 | - Also make sure that the file is accessible at {{DOMAIN}}/sw.js | |
| 45 | - </p> | |
| 46 | - SWE; | |
| 47 | - | |
| 48 | - public $plugin_name; | |
| 49 | - public $plugin_directory; | |
| 50 | - public $plugin_url; | |
| 51 | - public $settings; | |
| 52 | - public $tbl_taboola_settings; | |
| 53 | - | |
| 54 | - public function __construct() | |
| 36 | + function __construct() | |
| 55 | 37 | { |
| 56 | 38 | global $wpdb; |
| 57 | 39 | |
| 58 | 40 | //initialize plugin constant |
| @@ -87,75 +69,17 @@ | ||
| 87 | 69 | if (is_admin()) { |
| 88 | 70 | //add menu for plugin |
| 89 | 71 | add_action( 'admin_menu', array(&$this, 'admin_generate_menu') ); |
| 90 | 72 | add_filter('plugin_action_links', array(&$this, 'plugin_action_links'), 10, 2 ); |
| 91 | - }elseif ($this->settings != NULL){ | |
| 73 | + }else if ($this->settings != NULL){ | |
| 92 | 74 | add_action('wp_head', array(&$this, 'taboola_header_loader_inject')); |
| 93 | - if (!empty($this->settings->publisher_id_push)) { | |
| 94 | - add_action('wp_head', array(&$this, 'taboola_webpush_loader_js')); | |
| 95 | - | |
| 96 | - $sw = 'sw.js'; | |
| 97 | - $sw_path = ABSPATH . $sw; | |
| 98 | - | |
| 99 | - $content = file_exists($sw_path) ? file_get_contents($sw_path) : ''; | |
| 100 | - | |
| 101 | - if (strpos($content, $this->tpl_sw) === false) { | |
| 102 | - if (!is_writable(ABSPATH) || (file_exists($sw_path) && !is_writable($sw_path))) { | |
| 103 | - return $this->notice($this->msg_sw_error); | |
| 104 | - } | |
| 105 | - $content = $this->tpl_sw . PHP_EOL . $content; | |
| 106 | - if (file_put_contents($sw_path, $content) === false) { | |
| 107 | - return $this->notice($this->msg_sw_error); | |
| 108 | - } | |
| 109 | - } | |
| 110 | - } | |
| 111 | 75 | add_action('wp_footer', array(&$this, 'taboola_footer_loader_js')); |
| 112 | 76 | add_filter('the_content', array(&$this, 'load_taboola_content')); |
| 113 | 77 | add_filter('the_content', array(&$this, 'load_taboola_content_mid')); |
| 114 | - //add_filter('the_content', array(&$this, 'load_taboola_content_home')); | |
| 115 | - // add_filter('the_excerpt', array(&$this, 'load_taboola_content_home')); | |
| 116 | - // Homepage widget – capture the full page, inject once. | |
| 117 | - // Homepage widget – start buffering *before* anything else renders | |
| 118 | - add_action( 'template_redirect', [ $this, 'tb_home_buffer_start' ], 0 ); | |
| 119 | - | |
| 120 | - // Homepage widget – flush the buffer *after* literally everything else | |
| 121 | - add_action( 'shutdown', [ $this, 'tb_home_buffer_flush' ], PHP_INT_MAX ); | |
| 122 | - | |
| 123 | - | |
| 124 | - } | |
| 125 | - | |
| 78 | + add_filter('the_content', array(&$this, 'load_taboola_content_home')); | |
| 79 | + } | |
| 126 | 80 | } |
| 127 | - | |
| 128 | - /* ------------------------------------------------------------------ | |
| 129 | - * HOMEPAGE WIDGET – full-page buffer | |
| 130 | - * ----------------------------------------------------------------*/ | |
| 131 | -public function tb_home_buffer_start() { | |
| 132 | - | |
| 133 | - // Use the plug-in’s own logic to decide if the home widget is enabled | |
| 134 | - if ( $this->should_show_content_widget_home() ) { | |
| 135 | - ob_start( [ $this, 'tb_home_buffer_inject' ] ); | |
| 136 | - } | |
| 137 | -} | |
| 138 | 81 | |
| 139 | -public function tb_home_buffer_inject( $html ) { | |
| 140 | - //error_log( '🟢 Taboola buffer inject ran. HTML length = ' . strlen( $html ) ); // LOG #1 | |
| 141 | - // error_log( 'TB-DEBUG â‘ buffer inject, html len='.strlen($html) ); | |
| 142 | - | |
| 143 | - /* | |
| 144 | - * load_taboola_content_home() already: | |
| 145 | - * – reads your saved widget-ID, placement, selector & occurrence | |
| 146 | - * – builds the HTML + JS | |
| 147 | - * – calls embed_taboola_content_location_home() to place it | |
| 148 | - */ | |
| 149 | - return $this->load_taboola_content_home( $html ); | |
| 150 | -} | |
| 151 | - | |
| 152 | -public function tb_home_buffer_flush() { | |
| 153 | - if ( ob_get_length() ) { | |
| 154 | - echo ob_get_clean(); | |
| 155 | - } | |
| 156 | -} | |
| 157 | - | |
| 158 | 82 | function plugin_action_links($links, $file) { |
| 159 | 83 | static $this_plugin; |
| 160 | 84 | |
| 161 | 85 | if (!$this_plugin) { |
| @@ -184,14 +108,11 @@ | ||
| 184 | 108 | } |
| 185 | 109 | |
| 186 | 110 | private function should_show_content_widget_home(){ |
| 187 | 111 | // PC - only if v2 was installed: |
| 188 | - | |
| 189 | - //error_log( print_r( $this->settings, true ) ); // TEMP line | |
| 190 | - | |
| 191 | 112 | if (!$this->is_db_updated_for_min_ver("2.0.0")) |
| 192 | 113 | return false; |
| 193 | - $retVal2 = ((trim($this->settings->publisher_id) != '') && (is_front_page() || is_home()) && $this->settings->home_enabled && trim($this->settings->home_widget_id) != ''); | |
| 114 | + $retVal2 = ((trim($this->settings->publisher_id) != '') && is_front_page() && $this->settings->home_enabled && trim($this->settings->home_widget_id) != ''); | |
| 194 | 115 | return $retVal2; |
| 195 | 116 | } |
| 196 | 117 | |
| 197 | 118 | private function should_show_sidebar_widget(){ |
| @@ -220,9 +141,9 @@ | ||
| 220 | 141 | |
| 221 | 142 | // Only adding the loader if a widget is going to be placed on the page. |
| 222 | 143 | if ($this->is_widget_on_page()){ |
| 223 | 144 | // PC - since these params will be inserted in 'loaderInjectionScript.js' via search and replace, |
| 224 | - // double brackets are used to ensure that each key is a unique string. | |
| 145 | + // double brackets are used to ensure that each key is a unique string. | |
| 225 | 146 | $stringParams = array( |
| 226 | 147 | '{{PUBLISHER_ID}}' => $this->settings->publisher_id, |
| 227 | 148 | '{{PAGE_TYPE}}' => $this->get_page_type(), |
| 228 | 149 | '{{WORDPRESS_VERSION}}' => get_bloginfo('version'), |
| @@ -234,8 +155,9 @@ | ||
| 234 | 155 | |
| 235 | 156 | $scriptWrapper = new JavaScriptWrapper("loaderInjectionScript.js",$stringParams); |
| 236 | 157 | $head_string = $scriptWrapper->getScriptMarkupString(); |
| 237 | 158 | } |
| 159 | + | |
| 238 | 160 | return $head_string; |
| 239 | 161 | } |
| 240 | 162 | |
| 241 | 163 | |
| @@ -243,23 +165,13 @@ | ||
| 243 | 165 | function taboola_header_loader_inject(){ |
| 244 | 166 | echo $this->taboola_header_loader_js(); |
| 245 | 167 | } |
| 246 | 168 | |
| 247 | - // adding webpush loader | |
| 248 | - function taboola_webpush_loader_js() { | |
| 249 | - if(is_single() || is_home() || is_category() || is_front_page()){ | |
| 250 | - $stringParamsWeb = array( | |
| 251 | - '{{PUBLISHER_ID}}' => $this->settings->publisher_id_push | |
| 252 | - ); | |
| 253 | - $webpushInjectionScript = new JavaScriptWrapper("webPush.js",$stringParamsWeb); | |
| 254 | - echo $webpushInjectionScript; | |
| 255 | - } | |
| 256 | - } | |
| 257 | 169 | |
| 258 | 170 | function taboola_footer_loader_js() { |
| 259 | 171 | |
| 260 | 172 | // Only adding flush script if a widget is going to be placed on the page. |
| 261 | - if ($this->is_widget_on_page()){ | |
| 173 | + if ( $this->is_widget_on_page() ){ | |
| 262 | 174 | $flushInjectionScript = new JavaScriptWrapper('flushInjectionScript.js',array()); |
| 263 | 175 | echo $flushInjectionScript->getScriptMarkupString(); |
| 264 | 176 | } |
| 265 | 177 | } |
| @@ -309,9 +221,9 @@ | ||
| 309 | 221 | |
| 310 | 222 | // Homepage widget |
| 311 | 223 | function load_taboola_content_home($content) |
| 312 | 224 | { |
| 313 | - //error_log( 'TB-DEBUG â‘¡ entered load_taboola_content_home' ); | |
| 225 | + | |
| 314 | 226 | $taboola_content_home = array(); |
| 315 | 227 | if ($this->should_show_content_widget_home()){ |
| 316 | 228 | |
| 317 | 229 | $homeWidgetParams = array('{{WIDGET_ID}}' => $this->settings->home_widget_id, |
| @@ -475,22 +387,8 @@ | ||
| 475 | 387 | // Homepage widget |
| 476 | 388 | // Do the actual logic of choosing where to place the taboola content based on the "location" attribute |
| 477 | 389 | function embed_taboola_content_location_home($content, $taboola_content_home, $location){ |
| 478 | 390 | |
| 479 | - | |
| 480 | - // error_log( 'TB-DEBUG â‘¢ raw selector string: [' . $location . ']' ); | |
| 481 | - | |
| 482 | - // load parser | |
| 483 | - //require_once plugin_dir_path( __FILE__ ) . 'simple_html_dom.php'; | |
| 484 | - // $html_doc = str_get_html( $content ); | |
| 485 | - | |
| 486 | - // occurrence: settings is 1-based, find() wants 0-based | |
| 487 | - // $occurrence = max( 1, intval( $this->settings->home_location_string_occurrence ) ); | |
| 488 | - // $node = $html_doc->find( $location, $occurrence - 1 ); | |
| 489 | - // $found = is_object( $node ) ? 1 : 0; | |
| 490 | - | |
| 491 | - // error_log( "TB-DEBUG â‘¢ found {$found} matching node(s) for selector [{$location}]" ); | |
| 492 | - // ──────────────────────────── | |
| 493 | 391 | $do_default = true; |
| 494 | 392 | |
| 495 | 393 | if (isset($location) && $location != ''){ |
| 496 | 394 | $first_char = substr($location,0,1); |
| @@ -530,54 +428,48 @@ | ||
| 530 | 428 | } |
| 531 | 429 | } |
| 532 | 430 | } |
| 533 | 431 | // Default for below-article widget - add to the end of the content |
| 534 | - if ($do_default){ | |
| 535 | - $content = $content.$this->format_taboola_content_home($taboola_content_home,TABOOLA_CONTENT_FORMAT_STRING); | |
| 536 | - } | |
| 432 | + // if ($do_default){ | |
| 433 | + // $content = $content.$this->format_taboola_content_home($taboola_content_home,TABOOLA_CONTENT_FORMAT_STRING); | |
| 434 | + // } | |
| 537 | 435 | return $content; |
| 538 | - | |
| 539 | 436 | |
| 540 | 437 | } |
| 541 | 438 | |
| 542 | 439 | function admin_generate_menu(){ |
| 543 | 440 | global $current_user; |
| 544 | - 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); | |
| 441 | + add_menu_page('Taboola', 'Taboola', 'manage_options', 'taboola_widget', array(&$this, 'admin_taboola_settings'), $this->plugin_url.'img/taboola_icon.png', 110); | |
| 545 | 442 | } |
| 546 | 443 | |
| 547 | 444 | function admin_taboola_settings(){ |
| 445 | + | |
| 548 | 446 | global $wpdb; |
| 549 | 447 | $settings = $wpdb->get_row("select * from ".$wpdb->prefix."_taboola_settings limit 1"); |
| 550 | 448 | $taboola_errors = array(); |
| 551 | 449 | if($_SERVER['REQUEST_METHOD'] == 'POST'){ |
| 552 | 450 | |
| 553 | - if(trim(strip_tags($_POST['publisher_id'])) == ''){ | |
| 451 | + if(trim($_POST['publisher_id']) == ''){ | |
| 554 | 452 | $taboola_errors[] = "Publisher ID"; |
| 555 | 453 | } |
| 556 | 454 | |
| 557 | - if(isset($_POST['web_push_enabled'])) { | |
| 558 | - if (trim(strip_tags($_POST['publisher_id_push'])) == '') { | |
| 559 | - $taboola_errors[] = "Publisher Push ID"; | |
| 560 | - } | |
| 561 | - } | |
| 562 | - | |
| 563 | 455 | if(isset($_POST['first_bc_enabled'])) { |
| 564 | - if (trim(strip_tags($_POST['first_bc_widget_id'])) == '') { | |
| 456 | + if (trim($_POST['first_bc_widget_id']) == '') { | |
| 565 | 457 | $taboola_errors[] = "Below-article > Widget ID"; |
| 566 | 458 | } |
| 567 | - if (trim(strip_tags($_POST['first_bc_placement'])) == '') { | |
| 459 | + if (trim($_POST['first_bc_placement']) == '') { | |
| 568 | 460 | $taboola_errors[] = "Below-article > Placement Name"; |
| 569 | 461 | } |
| 570 | 462 | } |
| 571 | 463 | |
| 572 | 464 | if(isset($_POST['mid_enabled'])) { |
| 573 | - if (trim(strip_tags($_POST['mid_widget_id'])) == '') { | |
| 465 | + if (trim($_POST['mid_widget_id']) == '') { | |
| 574 | 466 | $taboola_errors[] = "Mid-article > Widget ID"; |
| 575 | 467 | } |
| 576 | - if (trim(strip_tags($_POST['mid_placement'])) == '') { | |
| 468 | + if (trim($_POST['mid_placement']) == '') { | |
| 577 | 469 | $taboola_errors[] = "Mid-article > Placement Name"; |
| 578 | 470 | } |
| 579 | - if (trim(strip_tags($_POST['mid_location_string'])) == '') { | |
| 471 | + if (trim($_POST['mid_location_string']) == '') { | |
| 580 | 472 | $taboola_errors[] = "Mid-article > CSS selector"; |
| 581 | 473 | } |
| 582 | 474 | else { |
| 583 | 475 | // If the 'location' WAS filled in, then... |
| @@ -597,16 +489,16 @@ | ||
| 597 | 489 | |
| 598 | 490 | } |
| 599 | 491 | |
| 600 | 492 | if(isset($_POST['home_enabled'])) { |
| 601 | - if (trim(strip_tags($_POST['home_widget_id'])) == '') { | |
| 493 | + if (trim($_POST['home_widget_id']) == '') { | |
| 602 | 494 | $taboola_errors[] = "Homepage > Widget ID"; |
| 603 | 495 | } |
| 604 | - if (trim(strip_tags($_POST['home_placement'])) == '') { | |
| 496 | + if (trim($_POST['home_placement']) == '') { | |
| 605 | 497 | $taboola_errors[] = "Homepage > Placement Name"; |
| 606 | 498 | } |
| 607 | 499 | |
| 608 | - if (trim(strip_tags($_POST['home_location_string'])) == '') { | |
| 500 | + if (trim($_POST['home_location_string']) == '') { | |
| 609 | 501 | $taboola_errors[] = "Homepage > CSS selector"; |
| 610 | 502 | } |
| 611 | 503 | else { |
| 612 | 504 | // If the 'location' WAS filled in, then... |
| @@ -625,14 +517,12 @@ | ||
| 625 | 517 | } |
| 626 | 518 | } |
| 627 | 519 | |
| 628 | 520 | if(count($taboola_errors) == 0){ |
| 521 | + | |
| 629 | 522 | $data = array( |
| 630 | 523 | "publisher_id" => trim($_POST['publisher_id']), |
| 631 | 524 | |
| 632 | - "web_push_enabled" => isset($_POST['web_push_enabled']) ? true : false, | |
| 633 | - "publisher_id_push" => !empty($_POST['publisher_id_push']) ? trim($_POST['publisher_id_push']) : '', | |
| 634 | - | |
| 635 | 525 | "first_bc_enabled" => isset($_POST['first_bc_enabled']) ? true : false, |
| 636 | 526 | "first_bc_widget_id" => !empty($_POST['first_bc_widget_id']) ? trim($_POST['first_bc_widget_id']) : '', |
| 637 | 527 | "first_bc_placement" => !empty($_POST['first_bc_placement']) ? trim($_POST['first_bc_placement']) : '', |
| 638 | 528 | |
| @@ -668,14 +558,16 @@ | ||
| 668 | 558 | } else { |
| 669 | 559 | $wpdb->update($this->tbl_taboola_settings, $data, array('id' => $settings->id)); |
| 670 | 560 | } |
| 671 | 561 | } |
| 562 | + | |
| 672 | 563 | } |
| 673 | 564 | $settings = $wpdb->get_row("select * from ".$wpdb->prefix."_taboola_settings limit 1"); |
| 674 | 565 | } |
| 566 | + | |
| 675 | 567 | include_once('settings.php'); |
| 676 | 568 | } |
| 677 | - | |
| 569 | + | |
| 678 | 570 | function is_mid_location_string_valid($mid_location_string){ |
| 679 | 571 | // TODO:: validate the location string |
| 680 | 572 | return true; |
| 681 | 573 | } |
| @@ -699,9 +591,8 @@ | ||
| 699 | 591 | return true; |
| 700 | 592 | } |
| 701 | 593 | return false; |
| 702 | 594 | } |
| 703 | - | |
| 704 | 595 | function columnExists($column_name) { |
| 705 | 596 | global $wpdb; |
| 706 | 597 | $table_name = $wpdb->prefix . "_taboola_settings"; |
| 707 | 598 | tb_write_log("table name : " . $table_name); |
| @@ -727,8 +618,9 @@ | ||
| 727 | 618 | else { |
| 728 | 619 | tb_write_log("This is NOT a v1 upgrade!"); //PC |
| 729 | 620 | return false; |
| 730 | 621 | } |
| 622 | + | |
| 731 | 623 | } |
| 732 | 624 | |
| 733 | 625 | function is_db_updated_for_min_ver($min_ver) { |
| 734 | 626 | /** |
| @@ -734,28 +626,10 @@ | ||
| 734 | 626 | /** |
| 735 | 627 | * Checks if the DB was *previously* updated for the minimum version specified. |
| 736 | 628 | * $min_ver should be passed in a format like this: "2.1.0" |
| 737 | 629 | */ |
| 738 | - | |
| 739 | 630 | global $wpdb; |
| 740 | 631 | |
| 741 | - // PC - Temporary patch for v2.1.0 | |
| 742 | - | |
| 743 | - // START patch =============================================== | |
| 744 | - // Check if the `_taboola` table exists. | |
| 745 | - // If not, then return false. | |
| 746 | - | |
| 747 | - $table_name = $wpdb->prefix . "_taboola_settings"; | |
| 748 | - | |
| 749 | - if($wpdb->get_var("SHOW TABLES LIKE '$table_name'") != $table_name) { | |
| 750 | - tb_write_log("Table NOT FOUND"); | |
| 751 | - return false; | |
| 752 | - } | |
| 753 | - else { | |
| 754 | - tb_write_log("Table EXISTS"); | |
| 755 | - } | |
| 756 | - // END patch ================================================= | |
| 757 | - | |
| 758 | 632 | // Check the saved version in wp_options. Default to '1.0.0' if the option is not found. |
| 759 | 633 | $saved_version = get_option(TABOOLA_OPTION_NAME, '1.0.0'); |
| 760 | 634 | |
| 761 | 635 | $db_is_up_to_date = version_compare($saved_version, $min_ver, '>='); |
| @@ -765,9 +639,8 @@ | ||
| 765 | 639 | } |
| 766 | 640 | |
| 767 | 641 | function is_db_updated_for_current_ver() { |
| 768 | 642 | /** |
| 769 | - * DEPRECATED | |
| 770 | 643 | * Checks if the DB was *previously* updated for the version currently loaded. |
| 771 | 644 | */ |
| 772 | 645 | global $wpdb; |
| 773 | 646 | |
| @@ -773,9 +646,9 @@ | ||
| 773 | 646 | |
| 774 | 647 | // Check the saved version in wp_options. Default to '1.0.0' if the option is not found. |
| 775 | 648 | $saved_version = get_option(TABOOLA_OPTION_NAME, '1.0.0'); |
| 776 | 649 | |
| 777 | - // Get the currently loaded plugin version. | |
| 650 | + // Get the currently loaded plugin version from wp_options. | |
| 778 | 651 | $plugin_version = $this->get_loaded_plugin_version(); |
| 779 | 652 | |
| 780 | 653 | $db_is_up_to_date = version_compare($saved_version, $plugin_version, '>='); |
| 781 | 654 | //tb_write_log($db_is_up_to_date); |
| @@ -791,16 +664,14 @@ | ||
| 791 | 664 | |
| 792 | 665 | } |
| 793 | 666 | |
| 794 | 667 | function save_taboola_version($min_ver) { |
| 795 | - /** | |
| 796 | - * Checks for the saved version in wp_options. | |
| 797 | - * If not found - adds it. Else - updates it. | |
| 798 | - */ | |
| 799 | - | |
| 668 | + // Get the currently loaded plugin version | |
| 669 | + // $plugin_version = $this->get_loaded_plugin_version(); | |
| 800 | 670 | |
| 801 | 671 | tb_write_log("SAVING NEW MIN VERSION: " . $min_ver); // PC |
| 802 | 672 | |
| 673 | + // Check the saved version in wp_options. Default to '' if the option is not found. | |
| 803 | 674 | $saved_version = get_option(TABOOLA_OPTION_NAME, ''); |
| 804 | 675 | if ($saved_version == '') { |
| 805 | 676 | add_option(TABOOLA_OPTION_NAME, $min_ver); |
| 806 | 677 | } |
| @@ -812,9 +683,9 @@ | ||
| 812 | 683 | function update_db(){ |
| 813 | 684 | |
| 814 | 685 | // If we are up to date, then skip this method... |
| 815 | 686 | if ($this->is_db_updated_for_min_ver(TABOOLA_MIN_VER)) { |
| 816 | - //tb_write_log("All up to date!"); | |
| 687 | + //tb_write_log("All up to date!"); | |
| 817 | 688 | return; |
| 818 | 689 | } |
| 819 | 690 | |
| 820 | 691 | $this->save_taboola_version(TABOOLA_MIN_VER); |
| @@ -822,9 +693,9 @@ | ||
| 822 | 693 | global $wpdb; |
| 823 | 694 | require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); |
| 824 | 695 | |
| 825 | 696 | |
| 826 | - // Handling for older MySQL versions | |
| 697 | + //check mysql version | |
| 827 | 698 | if (function_exists('mysql_get_server_info') && version_compare(mysql_get_server_info(), '4.1.0', '>=')) { |
| 828 | 699 | if (!empty($wpdb->charset)) |
| 829 | 700 | $charset_collate = "DEFAULT CHARACTER SET $wpdb->charset"; |
| 830 | 701 | if (!empty($wpdb->collate)) |
| @@ -841,10 +712,8 @@ | ||
| 841 | 712 | $sql_table_settings = " |
| 842 | 713 | CREATE TABLE `" . $wpdb->prefix . "_taboola_settings` ( |
| 843 | 714 | `id` INT NOT NULL AUTO_INCREMENT , |
| 844 | 715 | `publisher_id` VARCHAR(255) DEFAULT NULL, |
| 845 | - `web_push_enabled` TINYINT(1) NOT NULL DEFAULT FALSE, | |
| 846 | - `publisher_id_push` INT(15) DEFAULT NULL, | |
| 847 | 716 | `first_bc_enabled` TINYINT(1) NOT NULL DEFAULT FALSE, |
| 848 | 717 | `first_bc_widget_id` VARCHAR(255) DEFAULT NULL, |
| 849 | 718 | `first_bc_placement` VARCHAR(255) DEFAULT " . ($is_upgrade_from_v1 ? "'below-article'" : "NULL") .", |
| 850 | 719 | `first_bc_custom_css` TEXT DEFAULT NULL, |
| @@ -887,11 +756,8 @@ | ||
| 887 | 756 | // In this script, we trigger the function from the admin dashboard. |
| 888 | 757 | // So the log file is located under 'wp-admin/logs'. |
| 889 | 758 | function tb_write_log($log_msg) |
| 890 | 759 | { |
| 891 | - if (!TABOOLA_DEBUG_MODE) // If not debug mode, do nothing | |
| 892 | - return; | |
| 893 | - | |
| 894 | 760 | $log_filename = "logs"; |
| 895 | 761 | if (!file_exists($log_filename)) |
| 896 | 762 | { |
| 897 | 763 | mkdir($log_filename, 0777, true); |
| @@ -900,10 +766,12 @@ | ||
| 900 | 766 | |
| 901 | 767 | // Add date/time |
| 902 | 768 | $date = date('Y-m-d H:i:s'); |
| 903 | 769 | $log_msg_with_date = $date." : ".$log_msg; |
| 904 | - | |
| 905 | - file_put_contents($log_file_data, $log_msg_with_date . "\n", FILE_APPEND); | |
| 770 | + | |
| 771 | + if (TABOOLA_DEBUG_MODE) | |
| 772 | + file_put_contents($log_file_data, $log_msg_with_date . "\n", FILE_APPEND); | |
| 773 | + | |
| 906 | 774 | } |
| 907 | 775 | |
| 908 | 776 | // Write to console |
| 909 | 777 | function tb_console_log( $data ){ |
| @@ -923,19 +791,6 @@ | ||
| 923 | 791 | print_r($data); |
| 924 | 792 | die; |
| 925 | 793 | } |
| 926 | 794 | } |
| 795 | + | |
| 927 | 796 | // |
| 928 | - | |
| 929 | -// Enqueue js_inject.min.js script for XPath injection | |
| 930 | -function enqueue_taboola_scripts() { | |
| 931 | - wp_register_script( | |
| 932 | - 'taboola-injector', | |
| 933 | - plugins_url('js/js_inject.min.js', __FILE__), | |
| 934 | - array(), // No dependencies | |
| 935 | - null, // No version specified | |
| 936 | - true // Load in footer | |
| 937 | - ); | |
| 938 | - | |
| 939 | - wp_enqueue_script('taboola-injector'); | |
| 940 | -} | |
| 941 | -add_action('wp_enqueue_scripts', 'enqueue_taboola_scripts'); | |