| @@ -2,13 +2,13 @@ | ||
| 2 | 2 | /** |
| 3 | 3 | * Plugin Name: Taboola |
| 4 | 4 | * Plugin URI: https://developers.taboola.com/web-integrations/docs/wordpress-plugin |
| 5 | 5 | * Description: Taboola |
| 6 | - * Version: 2.2.3 | |
| 6 | + * Version: 2.2.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) | |
| 10 | +define ("TABOOLA_PLUGIN_VERSION","2.2.2"); // => UPDATE THIS FOR *EVERY* RELEASE (USED FOR TRACKING) | |
| 11 | 11 | define ("TABOOLA_MIN_VER","2.2.2"); // => UPDATE THIS *ONLY* IF THIS RELEASE HAS *DB CHANGES* |
| 12 | 12 | define ("TABOOLA_DEBUG_MODE", false); // => SET THIS TO 'FALSE' FOR *EVERY* RELEASE (USED TO SUPRESS DEBUGGING LOGS) |
| 13 | 13 | |
| 14 | 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'. |
| @@ -110,52 +110,12 @@ | ||
| 110 | 110 | } |
| 111 | 111 | add_action('wp_footer', array(&$this, 'taboola_footer_loader_js')); |
| 112 | 112 | add_filter('the_content', array(&$this, 'load_taboola_content')); |
| 113 | 113 | 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 | - | |
| 114 | + add_filter('the_content', array(&$this, 'load_taboola_content_home')); | |
| 115 | + } | |
| 126 | 116 | } |
| 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 | 117 | |
| 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 | 118 | function plugin_action_links($links, $file) { |
| 159 | 119 | static $this_plugin; |
| 160 | 120 | |
| 161 | 121 | if (!$this_plugin) { |
| @@ -184,11 +144,8 @@ | ||
| 184 | 144 | } |
| 185 | 145 | |
| 186 | 146 | private function should_show_content_widget_home(){ |
| 187 | 147 | // PC - only if v2 was installed: |
| 188 | - | |
| 189 | - //error_log( print_r( $this->settings, true ) ); // TEMP line | |
| 190 | - | |
| 191 | 148 | if (!$this->is_db_updated_for_min_ver("2.0.0")) |
| 192 | 149 | return false; |
| 193 | 150 | $retVal2 = ((trim($this->settings->publisher_id) != '') && (is_front_page() || is_home()) && $this->settings->home_enabled && trim($this->settings->home_widget_id) != ''); |
| 194 | 151 | return $retVal2; |
| @@ -309,9 +266,9 @@ | ||
| 309 | 266 | |
| 310 | 267 | // Homepage widget |
| 311 | 268 | function load_taboola_content_home($content) |
| 312 | 269 | { |
| 313 | - //error_log( 'TB-DEBUG ② entered load_taboola_content_home' ); | |
| 270 | + | |
| 314 | 271 | $taboola_content_home = array(); |
| 315 | 272 | if ($this->should_show_content_widget_home()){ |
| 316 | 273 | |
| 317 | 274 | $homeWidgetParams = array('{{WIDGET_ID}}' => $this->settings->home_widget_id, |
| @@ -475,22 +432,8 @@ | ||
| 475 | 432 | // Homepage widget |
| 476 | 433 | // Do the actual logic of choosing where to place the taboola content based on the "location" attribute |
| 477 | 434 | function embed_taboola_content_location_home($content, $taboola_content_home, $location){ |
| 478 | 435 | |
| 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 | 436 | $do_default = true; |
| 494 | 437 | |
| 495 | 438 | if (isset($location) && $location != ''){ |
| 496 | 439 | $first_char = substr($location,0,1); |
| @@ -530,13 +473,12 @@ | ||
| 530 | 473 | } |
| 531 | 474 | } |
| 532 | 475 | } |
| 533 | 476 | // 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 | - } | |
| 477 | + // if ($do_default){ | |
| 478 | + // $content = $content.$this->format_taboola_content_home($taboola_content_home,TABOOLA_CONTENT_FORMAT_STRING); | |
| 479 | + // } | |
| 537 | 480 | return $content; |
| 538 | - | |
| 539 | 481 | |
| 540 | 482 | } |
| 541 | 483 | |
| 542 | 484 | function admin_generate_menu(){ |
| @@ -887,11 +829,8 @@ | ||
| 887 | 829 | // In this script, we trigger the function from the admin dashboard. |
| 888 | 830 | // So the log file is located under 'wp-admin/logs'. |
| 889 | 831 | function tb_write_log($log_msg) |
| 890 | 832 | { |
| 891 | - if (!TABOOLA_DEBUG_MODE) // If not debug mode, do nothing | |
| 892 | - return; | |
| 893 | - | |
| 894 | 833 | $log_filename = "logs"; |
| 895 | 834 | if (!file_exists($log_filename)) |
| 896 | 835 | { |
| 897 | 836 | mkdir($log_filename, 0777, true); |
| @@ -900,10 +839,12 @@ | ||
| 900 | 839 | |
| 901 | 840 | // Add date/time |
| 902 | 841 | $date = date('Y-m-d H:i:s'); |
| 903 | 842 | $log_msg_with_date = $date." : ".$log_msg; |
| 904 | - | |
| 905 | - file_put_contents($log_file_data, $log_msg_with_date . "\n", FILE_APPEND); | |
| 843 | + | |
| 844 | + if (TABOOLA_DEBUG_MODE) | |
| 845 | + file_put_contents($log_file_data, $log_msg_with_date . "\n", FILE_APPEND); | |
| 846 | + | |
| 906 | 847 | } |
| 907 | 848 | |
| 908 | 849 | // Write to console |
| 909 | 850 | function tb_console_log( $data ){ |
| @@ -923,19 +864,6 @@ | ||
| 923 | 864 | print_r($data); |
| 924 | 865 | die; |
| 925 | 866 | } |
| 926 | 867 | } |
| 868 | + | |
| 927 | 869 | // |
| 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'); | |