| @@ -1,11 +1,11 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | 3 | * Execute snippet |
| 4 | 4 | * |
| 5 | - * @author Artem Prihodko <webtemyk@yandex.ru> | |
| 6 | - * @copyright (c) 2020, CreativeMotion | |
| 7 | - * @version 2.4 | |
| 5 | + * @author Webcraftic <wordpress.webraftic@gmail.com> | |
| 6 | + * @copyright (c) 16.11.2018, Webcraftic | |
| 7 | + * @version 1.0 | |
| 8 | 8 | */ |
| 9 | 9 | |
| 10 | 10 | // Exit if accessed directly |
| 11 | 11 | if ( ! defined( 'ABSPATH' ) ) { |
| @@ -14,36 +14,11 @@ | ||
| 14 | 14 | |
| 15 | 15 | class WINP_Execute_Snippet { |
| 16 | 16 | |
| 17 | 17 | /** |
| 18 | - * @var self | |
| 19 | - */ | |
| 20 | - private static $instance; | |
| 21 | - | |
| 22 | - /** | |
| 23 | - * @var array | |
| 24 | - */ | |
| 25 | - public $snippets; | |
| 26 | - | |
| 27 | - /** | |
| 28 | - * @var WINP_Insertion_Locations | |
| 29 | - */ | |
| 30 | - public $snippets_locations; | |
| 31 | - | |
| 32 | - public static function app() { | |
| 33 | - if ( self::$instance === null ) { | |
| 34 | - self::$instance = new self(); | |
| 35 | - } | |
| 36 | - | |
| 37 | - return self::$instance; | |
| 38 | - } | |
| 39 | - | |
| 40 | - /** | |
| 41 | 18 | * WINP_Execute_Snippet constructor. |
| 42 | 19 | */ |
| 43 | 20 | public function __construct() { |
| 44 | - self::$instance = $this; | |
| 45 | - | |
| 46 | 21 | if ( ! defined( 'WINP_UPLOAD_DIR' ) ) { |
| 47 | 22 | $dir = wp_upload_dir(); |
| 48 | 23 | define( 'WINP_UPLOAD_DIR', $dir['basedir'] . '/winp-css-js' ); |
| 49 | 24 | } |
| @@ -51,28 +26,8 @@ | ||
| 51 | 26 | if ( ! defined( 'WINP_UPLOAD_URL' ) ) { |
| 52 | 27 | $dir = wp_upload_dir(); |
| 53 | 28 | define( 'WINP_UPLOAD_URL', $dir['baseurl'] . '/winp-css-js' ); |
| 54 | 29 | } |
| 55 | - global $wpdb; | |
| 56 | - | |
| 57 | - $sql = "SELECT {$wpdb->posts}.ID, {$wpdb->posts}.post_content, p2.meta_value as priority | |
| 58 | - FROM {$wpdb->posts} | |
| 59 | - INNER JOIN {$wpdb->postmeta} p1 ON ({$wpdb->posts}.ID = p1.post_id) | |
| 60 | - INNER JOIN {$wpdb->postmeta} p2 ON ({$wpdb->posts}.ID = p2.post_id) | |
| 61 | - INNER JOIN {$wpdb->postmeta} p3 ON ({$wpdb->posts}.ID = p3.post_id) | |
| 62 | - WHERE (( p1.meta_key = '" . WINP_Plugin::app()->getPrefix() . "snippet_scope' AND p1.meta_value = '%s') | |
| 63 | - AND | |
| 64 | - ( p3.meta_key = '" . WINP_Plugin::app()->getPrefix() . "snippet_activate' AND p3.meta_value = '1') | |
| 65 | - AND p2.meta_key = '" . WINP_Plugin::app()->getPrefix() . "snippet_priority' ) | |
| 66 | - AND {$wpdb->posts}.post_type = '" . WINP_SNIPPETS_POST_TYPE . "' | |
| 67 | - AND ({$wpdb->posts}.post_status = 'publish') | |
| 68 | - ORDER BY CAST(priority AS UNSIGNED) %s"; | |
| 69 | - | |
| 70 | - $this->snippets['evrywhere'] = $wpdb->get_results( sprintf( $sql, 'evrywhere', 'DESC' ) ); | |
| 71 | - $this->snippets['auto'] = $wpdb->get_results( sprintf( $sql, 'auto', 'ASC' ) ); | |
| 72 | - | |
| 73 | - global $winp_snippets_locations; | |
| 74 | - $this->snippets_locations = new WINP_Insertion_Locations(); | |
| 75 | 30 | } |
| 76 | 31 | |
| 77 | 32 | /** |
| 78 | 33 | * Register hooks |
| @@ -85,22 +40,14 @@ | ||
| 85 | 40 | add_action( 'wp_footer', [ $this, 'executeFooterSnippets' ] ); |
| 86 | 41 | add_filter( 'the_post', [ $this, 'executePostSnippets' ], 10, 2 ); |
| 87 | 42 | add_filter( 'the_content', [ $this, 'executeContentSnippets' ] ); |
| 88 | 43 | add_filter( 'the_excerpt', [ $this, 'executeExcerptSnippets' ] ); |
| 89 | - // Бесполезный хук, который вызывается на каждый комментарий. Если их много, увеличивается нагрузка | |
| 90 | - //add_filter( 'wp_list_comments_args', [ $this, 'executeListCommentsSnippets' ] ); | |
| 91 | - | |
| 92 | - //add_action( 'wp_head', [ $this, 'executeWoocommerceSnippets' ] ); | |
| 93 | - | |
| 94 | - if ( ! empty( $this->snippets_locations->getInsertion( 'custom' ) ) ) { | |
| 95 | - add_action( 'wp_head', [ $this, 'executeCustomSnippets' ] ); | |
| 96 | - } | |
| 97 | - | |
| 44 | + add_filter( 'wp_list_comments_args', [ $this, 'executeListCommentsSnippets' ] ); | |
| 98 | 45 | } |
| 99 | 46 | } |
| 100 | 47 | |
| 101 | 48 | /** |
| 102 | - * Execute the everywhere snippets once the plugins are loaded | |
| 49 | + * Execute the evrywhere snippets once the plugins are loaded | |
| 103 | 50 | */ |
| 104 | 51 | public function executeEverywhereSnippets() { |
| 105 | 52 | echo $this->executeActiveSnippets( 'evrywhere' ); |
| 106 | 53 | } |
| @@ -108,9 +55,9 @@ | ||
| 108 | 55 | /** |
| 109 | 56 | * Execute the snippets in header of page once the plugins are loaded |
| 110 | 57 | */ |
| 111 | 58 | public function executeHeaderSnippets() { |
| 112 | - echo $this->executeActiveSnippets( 'auto', 'header' ); | |
| 59 | + echo $this->executeActiveSnippets( 'auto', WINP_SNIPPET_AUTO_HEADER ); | |
| 113 | 60 | } |
| 114 | 61 | |
| 115 | 62 | /** |
| 116 | 63 | * Execute the snippets in footer of page once the plugins are loaded |
| @@ -115,9 +62,9 @@ | ||
| 115 | 62 | /** |
| 116 | 63 | * Execute the snippets in footer of page once the plugins are loaded |
| 117 | 64 | */ |
| 118 | 65 | public function executeFooterSnippets() { |
| 119 | - echo $this->executeActiveSnippets( 'auto', 'footer' ); | |
| 66 | + echo $this->executeActiveSnippets( 'auto', WINP_SNIPPET_AUTO_FOOTER ); | |
| 120 | 67 | } |
| 121 | 68 | |
| 122 | 69 | /** |
| 123 | 70 | * Execute the snippets before post |
| @@ -133,21 +80,21 @@ | ||
| 133 | 80 | $post_type = ! empty( $post ) ? $post->post_type : get_post( $data->ID )->post_type; |
| 134 | 81 | if ( is_singular( [ $post_type ] ) && $post->ID == $data->ID ) { |
| 135 | 82 | if ( did_action( 'get_header' ) ) { |
| 136 | 83 | // Перед заголовком |
| 137 | - $content = $this->executeActiveSnippets( 'auto', 'before_post' ); | |
| 84 | + $content = $this->executeActiveSnippets( 'auto', WINP_SNIPPET_AUTO_BEFORE_POST ); | |
| 138 | 85 | } |
| 139 | 86 | } else { |
| 140 | 87 | if ( $query->post_count > 0 ) { |
| 141 | 88 | if ( $query->post_count > 1 && $query->current_post > 0 && $query->post_count > $query->current_post ) { |
| 142 | 89 | // Между записями |
| 143 | - $content = $this->executeActiveSnippets( 'auto', 'between_posts' ); | |
| 90 | + $content = $this->executeActiveSnippets( 'auto', WINP_SNIPPET_AUTO_BETWEEN_POSTS ); | |
| 144 | 91 | } |
| 145 | 92 | // Перед записью |
| 146 | - $content .= $this->executeActiveSnippets( 'auto', 'before_posts', '', $query ); | |
| 93 | + $content .= $this->executeActiveSnippets( 'auto', WINP_SNIPPET_AUTO_BEFORE_POSTS, '', $query ); | |
| 147 | 94 | |
| 148 | 95 | // После записи |
| 149 | - $content .= $this->executeActiveSnippets( 'auto', 'after_posts', '', $query ); | |
| 96 | + $content .= $this->executeActiveSnippets( 'auto', WINP_SNIPPET_AUTO_AFTER_POSTS, '', $query ); | |
| 150 | 97 | } |
| 151 | 98 | } |
| 152 | 99 | |
| 153 | 100 | echo $content; |
| @@ -198,13 +145,13 @@ | ||
| 198 | 145 | |
| 199 | 146 | /** |
| 200 | 147 | * Handle posts content |
| 201 | 148 | * |
| 202 | - * @param string $content | |
| 203 | - * @param string $snippet_content | |
| 149 | + * @param string $content | |
| 150 | + * @param string $snippet_content | |
| 204 | 151 | * @param integer $post_number |
| 205 | - * @param string $type | |
| 206 | - * @param object $query | |
| 152 | + * @param string $type | |
| 153 | + * @param object $query | |
| 207 | 154 | * |
| 208 | 155 | * @return mixed |
| 209 | 156 | */ |
| 210 | 157 | private function handlePostsContent( $content, $snippet_content, $post_number, $type, $query ) { |
| @@ -244,29 +191,29 @@ | ||
| 244 | 191 | $post_type = ! empty( $post ) ? $post->post_type : false; |
| 245 | 192 | |
| 246 | 193 | if ( is_category() || is_archive() || is_tag() || is_tax() || is_search() ) { |
| 247 | 194 | // Перед коротким описанием |
| 248 | - $content = $this->executeActiveSnippets( 'auto', 'before_excerpt' ) . $content; | |
| 195 | + $content = $this->executeActiveSnippets( 'auto', WINP_SNIPPET_AUTO_BEFORE_EXCERPT ) . $content; | |
| 249 | 196 | |
| 250 | 197 | // После короткого описания |
| 251 | - $content .= $this->executeActiveSnippets( 'auto', 'after_excerpt' ); | |
| 198 | + $content .= $this->executeActiveSnippets( 'auto', WINP_SNIPPET_AUTO_AFTER_EXCERPT ); | |
| 252 | 199 | } |
| 253 | 200 | |
| 254 | 201 | if ( is_singular( [ $post_type ] ) ) { |
| 255 | 202 | // Перед параграфом |
| 256 | - $content = $this->executeActiveSnippets( 'auto', 'before_paragraph', $content ); | |
| 203 | + $content = $this->executeActiveSnippets( 'auto', WINP_SNIPPET_AUTO_BEFORE_PARAGRAPH, $content ); | |
| 257 | 204 | |
| 258 | 205 | // После параграфа |
| 259 | - $content = $this->executeActiveSnippets( 'auto', 'after_paragraph', $content ); | |
| 206 | + $content = $this->executeActiveSnippets( 'auto', WINP_SNIPPET_AUTO_AFTER_PARAGRAPH, $content ); | |
| 260 | 207 | |
| 261 | 208 | // После заголовка |
| 262 | - $content = $this->executeActiveSnippets( 'auto', 'before_content' ) . $content; | |
| 209 | + $content = $this->executeActiveSnippets( 'auto', WINP_SNIPPET_AUTO_BEFORE_CONTENT ) . $content; | |
| 263 | 210 | |
| 264 | 211 | // После текста |
| 265 | - $content .= $this->executeActiveSnippets( 'auto', 'after_content' ); | |
| 212 | + $content .= $this->executeActiveSnippets( 'auto', WINP_SNIPPET_AUTO_AFTER_CONTENT ); | |
| 266 | 213 | |
| 267 | 214 | // После поста |
| 268 | - $content .= $this->executeActiveSnippets( 'auto', 'after_post' ); | |
| 215 | + $content .= $this->executeActiveSnippets( 'auto', WINP_SNIPPET_AUTO_AFTER_POST ); | |
| 269 | 216 | |
| 270 | 217 | if ( ! comments_open( $post->ID ) && ! get_comments_number( $post->ID ) ) { |
| 271 | 218 | remove_filter( 'wp_list_comments_args', [ $this, 'executeListCommentsSnippets' ] ); |
| 272 | 219 | } |
| @@ -288,12 +235,12 @@ | ||
| 288 | 235 | */ |
| 289 | 236 | public function executeExcerptSnippets( $excerpt ) { |
| 290 | 237 | if ( is_category() || is_archive() || is_tag() || is_tax() || is_search() ) { |
| 291 | 238 | // Перед коротким описанием |
| 292 | - $excerpt = $this->executeActiveSnippets( 'auto', 'before_excerpt' ) . $excerpt; | |
| 239 | + $excerpt = $this->executeActiveSnippets( 'auto', WINP_SNIPPET_AUTO_BEFORE_EXCERPT ) . $excerpt; | |
| 293 | 240 | |
| 294 | 241 | // После короткого описания |
| 295 | - $excerpt .= $this->executeActiveSnippets( 'auto', 'after_excerpt' ); | |
| 242 | + $excerpt .= $this->executeActiveSnippets( 'auto', WINP_SNIPPET_AUTO_AFTER_EXCERPT ); | |
| 296 | 243 | } |
| 297 | 244 | |
| 298 | 245 | return $excerpt; |
| 299 | 246 | } |
| @@ -332,9 +279,9 @@ | ||
| 332 | 279 | |
| 333 | 280 | $post_type = ! empty( $post ) ? $post->post_type : false; |
| 334 | 281 | if ( is_singular( [ $post_type ] ) ) { |
| 335 | 282 | // После комментариев |
| 336 | - $content = $this->executeActiveSnippets( 'auto', 'after_post' ); | |
| 283 | + $content = $this->executeActiveSnippets( 'auto', WINP_SNIPPET_AUTO_AFTER_POST ); | |
| 337 | 284 | } |
| 338 | 285 | |
| 339 | 286 | echo $content; |
| 340 | 287 | } |
| @@ -339,124 +286,24 @@ | ||
| 339 | 286 | echo $content; |
| 340 | 287 | } |
| 341 | 288 | |
| 342 | 289 | /** |
| 343 | - * Execute the custom snippets | |
| 344 | - * | |
| 345 | - * @since 2.4 | |
| 346 | - */ | |
| 347 | - public function executeCustomSnippets() { | |
| 348 | - $locations = $this->snippets_locations->getInsertion( 'custom' ); | |
| 349 | - foreach ( $locations as $location => $data ) { | |
| 350 | - $this->executeActiveSnippets( 'auto', $location ); | |
| 351 | - } | |
| 352 | - } | |
| 353 | - | |
| 354 | - /** | |
| 355 | - * Execute Woocommerce actions/hooks | |
| 356 | - * | |
| 357 | - * @param $location | |
| 358 | - * @param $snippet_content | |
| 359 | - * | |
| 360 | - * @since 2.4 | |
| 361 | - */ | |
| 362 | - public function woocommerce_actions( $location, $snippet_content = '' ) { | |
| 363 | - $action = function () use ( $location, $snippet_content ) { | |
| 364 | - echo $snippet_content; | |
| 365 | - }; | |
| 366 | - | |
| 367 | - switch ( $location ) { | |
| 368 | - case 'woo_before_shop_loop': | |
| 369 | - add_filter( 'woocommerce_product_loop_start', function ( $content ) use ( $snippet_content ) { | |
| 370 | - return $snippet_content . $content; | |
| 371 | - } ); | |
| 372 | - break; | |
| 373 | - case 'woo_after_shop_loop': | |
| 374 | - add_filter( 'woocommerce_product_loop_end', function ( $content ) use ( $snippet_content ) { | |
| 375 | - return $content . $snippet_content; | |
| 376 | - } ); | |
| 377 | - break; | |
| 378 | - case 'woo_before_single_product': | |
| 379 | - add_action( 'woocommerce_before_single_product', $action, 10, 2 ); | |
| 380 | - break; | |
| 381 | - case 'woo_after_single_product': | |
| 382 | - add_action( 'woocommerce_after_single_product', $action, 10, 2 ); | |
| 383 | - break; | |
| 384 | - case 'woo_before_single_product_summary': | |
| 385 | - add_action( 'woocommerce_before_single_product_summary', $action, 10, 2 ); | |
| 386 | - break; | |
| 387 | - case 'woo_after_single_product_summary': | |
| 388 | - add_action( 'woocommerce_after_single_product_summary', $action, 10, 2 ); | |
| 389 | - break; | |
| 390 | - case 'woo_single_product_summary_title': | |
| 391 | - add_action( 'woocommerce_single_product_summary', $action, 6, 2 ); | |
| 392 | - break; | |
| 393 | - case 'woo_single_product_summary_price': | |
| 394 | - add_action( 'woocommerce_single_product_summary', $action, 15, 2 ); | |
| 395 | - break; | |
| 396 | - case 'woo_single_product_summary_excerpt': | |
| 397 | - add_action( 'woocommerce_single_product_summary', $action, 25, 2 ); | |
| 398 | - break; | |
| 399 | - default: | |
| 400 | - break; | |
| 401 | - } | |
| 402 | - } | |
| 403 | - | |
| 404 | - /** | |
| 405 | - * Execute Woocommerce actions/hooks | |
| 406 | - * | |
| 407 | - * @param $location | |
| 408 | - * @param $snippet_content | |
| 409 | - * | |
| 410 | - * @since 2.4 | |
| 411 | - */ | |
| 412 | - public function custom_actions( $location, $snippet_content = '' ) { | |
| 413 | - if ( ! empty( $this->snippets_locations->getLocation( $location ) ) ) { | |
| 414 | - /** | |
| 415 | - * Action for a custom location applied in 'wbcr/woody/add_custom_location' filter | |
| 416 | - * | |
| 417 | - * @param array $location Slug of the location. | |
| 418 | - * @param string $snippet_content Rendered snippet content | |
| 419 | - * | |
| 420 | - * @since 2.4 | |
| 421 | - */ | |
| 422 | - do_action( "wbcr/woody/do_custom_location/{$location}", $snippet_content ); | |
| 423 | - } | |
| 424 | - } | |
| 425 | - | |
| 426 | - /** | |
| 427 | 290 | * Execute the snippets once the plugins are loaded |
| 428 | 291 | * |
| 429 | 292 | * @param string $scope |
| 430 | - * @param string $location | |
| 293 | + * @param string $auto | |
| 431 | 294 | * @param string $content |
| 432 | - * @param array $custom_params | |
| 295 | + * @param array $custom_params | |
| 433 | 296 | * |
| 434 | 297 | * @return string |
| 435 | 298 | */ |
| 436 | - public function executeActiveSnippets( $scope = 'evrywhere', $location = '', $content = '', $custom_params = [] ) { | |
| 437 | - /* | |
| 299 | + public function executeActiveSnippets( $scope = 'evrywhere', $auto = '', $content = '', $custom_params = [] ) { | |
| 438 | 300 | global $wpdb; |
| 439 | 301 | |
| 440 | - if ( $scope == 'evrywhere' ) { | |
| 441 | - $sort = 'DESC'; | |
| 442 | - } else { | |
| 443 | - $sort = 'ASC'; | |
| 444 | - } | |
| 445 | - $snippets = $wpdb->get_results( "SELECT {$wpdb->posts}.ID, {$wpdb->posts}.post_content, p2.meta_value as priority | |
| 302 | + $snippets = $wpdb->get_results( "SELECT {$wpdb->posts}.ID, {$wpdb->posts}.post_content | |
| 446 | 303 | FROM {$wpdb->posts} |
| 447 | - INNER JOIN {$wpdb->postmeta} p1 ON ({$wpdb->posts}.ID = p1.post_id) | |
| 448 | - INNER JOIN {$wpdb->postmeta} p2 ON ({$wpdb->posts}.ID = p2.post_id) | |
| 449 | - INNER JOIN {$wpdb->postmeta} p3 ON ({$wpdb->posts}.ID = p3.post_id) | |
| 450 | - WHERE (( p1.meta_key = '" . WINP_Plugin::app()->getPrefix() . "snippet_scope' AND p1.meta_value = '{$scope}') | |
| 451 | - AND | |
| 452 | - ( p3.meta_key = '" . WINP_Plugin::app()->getPrefix() . "snippet_activate' AND p3.meta_value = '1') | |
| 453 | - AND p2.meta_key = '" . WINP_Plugin::app()->getPrefix() . "snippet_priority' ) | |
| 454 | - AND {$wpdb->posts}.post_type = '" . WINP_SNIPPETS_POST_TYPE . "' | |
| 455 | - AND ({$wpdb->posts}.post_status = 'publish') | |
| 456 | - ORDER BY CAST(priority AS UNSIGNED) {$sort}" ); | |
| 457 | - */ | |
| 458 | - $snippets = $this->snippets[ $scope ] ?? []; | |
| 304 | + INNER JOIN {$wpdb->postmeta} ON ( {$wpdb->posts}.ID = {$wpdb->postmeta}.post_id ) | |
| 305 | + WHERE ( ( {$wpdb->postmeta}.meta_key = '" . WINP_Plugin::app()->getPrefix() . "snippet_scope' AND {$wpdb->postmeta}.meta_value = '{$scope}' ) ) AND {$wpdb->posts}.post_type = '" . WINP_SNIPPETS_POST_TYPE . "' AND ( ({$wpdb->posts}.post_status = 'publish') )" ); | |
| 459 | 306 | |
| 460 | 307 | if ( empty( $snippets ) ) { |
| 461 | 308 | return $content; |
| 462 | 309 | } |
| @@ -462,16 +309,17 @@ | ||
| 462 | 309 | } |
| 463 | 310 | |
| 464 | 311 | foreach ( (array) $snippets as $snippet ) { |
| 465 | 312 | $id = (int) $snippet->ID; |
| 466 | - //$is_active = (int) WINP_Helper::getMetaOption( $id, 'snippet_activate', 0 ); | |
| 313 | + | |
| 314 | + $is_active = (int) WINP_Helper::getMetaOption( $id, 'snippet_activate', 0 ); | |
| 467 | 315 | // Если это сниппет с автовставкой и выбранное место подходит под активный action |
| 468 | - $avail_place = ( 'auto' == $scope ? $location == WINP_Helper::getMetaOption( $id, 'snippet_location', '' ) : true ); | |
| 469 | - // Если условие отображения сниппета выполняется | |
| 316 | + $avail_place = ( 'auto' == $scope ? $auto == WINP_Helper::getMetaOption( $id, 'snippet_location', '' ) : true ); | |
| 317 | + // Если условие отображения сниппена выполняется | |
| 470 | 318 | $snippet_type = WINP_Helper::getMetaOption( $id, 'snippet_type', WINP_SNIPPET_TYPE_PHP ); |
| 471 | 319 | $is_condition = $snippet_type != WINP_SNIPPET_TYPE_PHP ? $this->checkCondition( $id ) : true; |
| 472 | 320 | |
| 473 | - if ( $avail_place && $is_condition ) { | |
| 321 | + if ( $is_active && $avail_place && $is_condition ) { | |
| 474 | 322 | $post_id = (int) WINP_Plugin::app()->request->post( 'post_ID', 0 ); |
| 475 | 323 | |
| 476 | 324 | if ( isset( $_POST['wbcr_inp_snippet_scope'] ) && $post_id === $id && WINP_Plugin::app()->currentUserCan() ) { |
| 477 | 325 | return $content; |
| @@ -480,26 +328,12 @@ | ||
| 480 | 328 | if ( WINP_Helper::is_safe_mode() ) { |
| 481 | 329 | return $content; |
| 482 | 330 | } |
| 483 | 331 | |
| 484 | - // WPML Compatibility | |
| 485 | - if ( defined( 'WPML_PLUGIN_FILE' ) ) { | |
| 486 | - $wpml_langs = WINP_Helper::getMetaOption( $id, 'snippet_wpml_lang', '' ); | |
| 487 | - if ( $wpml_langs !== '' && defined( 'ICL_LANGUAGE_CODE' ) ) { | |
| 488 | - if ( ! in_array( ICL_LANGUAGE_CODE, explode( ',', $wpml_langs ) ) ) { | |
| 489 | - continue; | |
| 490 | - } | |
| 491 | - } | |
| 492 | - } | |
| 493 | - | |
| 494 | 332 | $snippet_code = WINP_Helper::get_snippet_code( $snippet ); |
| 495 | 333 | |
| 496 | - if ( WINP_Plugin::app()->getOption( 'execute_shortcode' ) ) { | |
| 497 | - $snippet_code = do_shortcode( $snippet_code ); | |
| 498 | - } | |
| 499 | - | |
| 500 | - if ( $snippet_type === WINP_SNIPPET_TYPE_TEXT || $snippet_type === WINP_SNIPPET_TYPE_AD ) { | |
| 501 | - $snippet_content = '<div class="winp-text-snippet-container">' . $snippet_code . '</div>'; | |
| 334 | + if ( $snippet_type === WINP_SNIPPET_TYPE_TEXT ) { | |
| 335 | + $snippet_content = '<div class="winp-text-snippet-contanier">' . $snippet_code . '</div>'; | |
| 502 | 336 | } else if ( $snippet_type === WINP_SNIPPET_TYPE_CSS || $snippet_type === WINP_SNIPPET_TYPE_JS ) { |
| 503 | 337 | $snippet_content = self::getJsCssSnippetData( $id ); |
| 504 | 338 | } else if ( $snippet_type === WINP_SNIPPET_TYPE_HTML ) { |
| 505 | 339 | $snippet_content = $snippet_code; |
| @@ -511,22 +345,22 @@ | ||
| 511 | 345 | ob_end_clean(); |
| 512 | 346 | } |
| 513 | 347 | |
| 514 | 348 | if ( 'auto' == $scope ) { |
| 515 | - switch ( $location ) { | |
| 516 | - case 'before_paragraph': // Перед параграфом | |
| 349 | + switch ( $auto ) { | |
| 350 | + case WINP_SNIPPET_AUTO_BEFORE_PARAGRAPH: // Перед параграфом | |
| 517 | 351 | $location_number = WINP_Helper::getMetaOption( $id, 'snippet_p_number', 0 ); |
| 518 | 352 | $content = $this->handleParagraphContent( $content, $snippet_content, $location_number ); |
| 519 | 353 | break; |
| 520 | - case 'after_paragraph': // После параграфа | |
| 354 | + case WINP_SNIPPET_AUTO_AFTER_PARAGRAPH: // После параграфа | |
| 521 | 355 | $location_number = WINP_Helper::getMetaOption( $id, 'snippet_p_number', 0 ); |
| 522 | 356 | $content = $this->handleParagraphContent( $content, $snippet_content, $location_number, 'after' ); |
| 523 | 357 | break; |
| 524 | - case 'before_posts': // Перед записью | |
| 358 | + case WINP_SNIPPET_AUTO_BEFORE_POSTS: // Перед записью | |
| 525 | 359 | $location_number = WINP_Helper::getMetaOption( $id, 'snippet_p_number', 0 ); |
| 526 | 360 | $content = $this->handlePostsContent( $content, $snippet_content, $location_number, 'before', $custom_params ); |
| 527 | 361 | break; |
| 528 | - case 'after_posts': // После записи | |
| 362 | + case WINP_SNIPPET_AUTO_AFTER_POSTS: // После записи | |
| 529 | 363 | $location_number = WINP_Helper::getMetaOption( $id, 'snippet_p_number', 0 ); |
| 530 | 364 | $content = $this->handlePostsContent( $content, $snippet_content, $location_number, 'after', $custom_params ); |
| 531 | 365 | break; |
| 532 | 366 | default: |
| @@ -531,22 +365,8 @@ | ||
| 531 | 365 | break; |
| 532 | 366 | default: |
| 533 | 367 | $content = $snippet_content . $content; |
| 534 | 368 | } |
| 535 | - | |
| 536 | - /** | |
| 537 | - * Action for woo actions | |
| 538 | - * | |
| 539 | - * @param array $location Slug of the location. | |
| 540 | - * @param string $snippet_content Rendered snippet content | |
| 541 | - * | |
| 542 | - * @since 2.4 | |
| 543 | - */ | |
| 544 | - do_action( "wbcr/woody/do_woocommerce_actions", $location, $snippet_content ); | |
| 545 | - | |
| 546 | - //$this->woocommerce_actions( $location, $snippet_content ); | |
| 547 | - $this->custom_actions( $location, $snippet_content ); | |
| 548 | - | |
| 549 | 369 | } else { |
| 550 | 370 | $content = $snippet_content . $content; |
| 551 | 371 | } |
| 552 | 372 | } |
| @@ -602,11 +422,11 @@ | ||
| 602 | 422 | * |
| 603 | 423 | * Code must NOT be escaped, as |
| 604 | 424 | * it will be executed directly |
| 605 | 425 | * |
| 606 | - * @param string $code The snippet code to execute | |
| 607 | - * @param int $id The snippet ID | |
| 608 | - * @param bool $catch_output Whether to attempt to suppress the output of execution using buffers | |
| 426 | + * @param string $code The snippet code to execute | |
| 427 | + * @param int $id The snippet ID | |
| 428 | + * @param bool $catch_output Whether to attempt to suppress the output of execution using buffers | |
| 609 | 429 | * |
| 610 | 430 | * @return mixed The result of the code execution |
| 611 | 431 | */ |
| 612 | 432 | public function executeSnippet( $code, $id = 0, $catch_output = true ) { |
| @@ -766,9 +586,9 @@ | ||
| 766 | 586 | |
| 767 | 587 | /** |
| 768 | 588 | * Prepare the code by removing php tags from beginning and end |
| 769 | 589 | * |
| 770 | - * @param string $code | |
| 590 | + * @param string $code | |
| 771 | 591 | * @param integer $snippet_id |
| 772 | 592 | * |
| 773 | 593 | * @return string |
| 774 | 594 | */ |
| @@ -827,19 +647,11 @@ | ||
| 827 | 647 | */ |
| 828 | 648 | public function checkByOperator( $operation, $first, $second, $third = false ) { |
| 829 | 649 | switch ( $operation ) { |
| 830 | 650 | case 'equals': |
| 831 | - if ( is_array( $second ) ) { | |
| 832 | - return in_array( $first, $second ); | |
| 833 | - } else { | |
| 834 | - return $first === $second; | |
| 835 | - } | |
| 651 | + return $first === $second; | |
| 836 | 652 | case 'notequal': |
| 837 | - if ( is_array( $second ) ) { | |
| 838 | - return ! in_array( $first, $second ); | |
| 839 | - } else { | |
| 840 | - return $first !== $second; | |
| 841 | - } | |
| 653 | + return $first !== $second; | |
| 842 | 654 | case 'less': |
| 843 | 655 | case 'older': |
| 844 | 656 | return $first > $second; |
| 845 | 657 | case 'greater': |
| @@ -1063,40 +875,14 @@ | ||
| 1063 | 875 | if ( $current_taxonomy == $taxonomy ) { |
| 1064 | 876 | $result = true; |
| 1065 | 877 | } |
| 1066 | 878 | } |
| 1067 | - break; | |
| 879 | + break; | |
| 1068 | 880 | |
| 1069 | 881 | default: |
| 1070 | - $result = false; | |
| 882 | + $result = true; | |
| 1071 | 883 | } |
| 1072 | 884 | |
| 1073 | - if ( WINP_Helper::is_woo_active() ) { | |
| 1074 | - switch ( $value ) { | |
| 1075 | - case 'woo_product': | |
| 1076 | - $result = is_product(); | |
| 1077 | - break; | |
| 1078 | - case 'woo_arch': | |
| 1079 | - $result = is_shop(); | |
| 1080 | - break; | |
| 1081 | - case 'woo_cart': | |
| 1082 | - $result = is_cart(); | |
| 1083 | - break; | |
| 1084 | - case 'woo_checkout': | |
| 1085 | - $result = is_checkout(); | |
| 1086 | - break; | |
| 1087 | - case 'woo_checkout_pay': | |
| 1088 | - $result = is_checkout_pay_page(); | |
| 1089 | - break; | |
| 1090 | - case 'woo_cat': | |
| 1091 | - $result = is_product_category(); | |
| 1092 | - break; | |
| 1093 | - case 'woo_tag': | |
| 1094 | - $result = is_product_tag(); | |
| 1095 | - break; | |
| 1096 | - } | |
| 1097 | - } | |
| 1098 | - | |
| 1099 | 885 | return $this->checkByOperator( $operator, $result, true ); |
| 1100 | 886 | } |
| 1101 | 887 | |
| 1102 | 888 | /** |
| @@ -1143,56 +929,23 @@ | ||
| 1143 | 929 | return false; |
| 1144 | 930 | } |
| 1145 | 931 | |
| 1146 | 932 | /** |
| 1147 | - * A taxonomy page | |
| 933 | + * A taxonomy of the current page | |
| 1148 | 934 | * |
| 1149 | 935 | * @param $operator |
| 1150 | 936 | * @param $value |
| 1151 | 937 | * |
| 1152 | 938 | * @return boolean |
| 1153 | - * @since 2.2.8 The bug is fixed, the condition was not checked | |
| 1154 | - * for tachonomies, only posts. | |
| 1155 | - * | |
| 1156 | 939 | */ |
| 1157 | 940 | private function location_taxonomy( $operator, $value ) { |
| 1158 | - $term_id = null; | |
| 941 | + global $post; | |
| 1159 | 942 | |
| 1160 | - if ( is_tax() || is_tag() || is_category() ) { | |
| 1161 | - $term_id = get_queried_object()->term_id; | |
| 1162 | - | |
| 1163 | - if ( $term_id ) { | |
| 1164 | - return $this->checkByOperator( $operator, intval( $value ), $term_id ); | |
| 1165 | - } | |
| 943 | + $post_cat = get_the_category( $post->ID ); | |
| 944 | + if ( isset( $post_cat[0] ) ) { | |
| 945 | + return $this->checkByOperator( $operator, intval( $value ), $post_cat[0]->term_id ); | |
| 1166 | 946 | } |
| 1167 | 947 | |
| 1168 | 948 | return false; |
| 1169 | 949 | } |
| 1170 | 950 | |
| 1171 | - /** | |
| 1172 | - * A taxonomy of the current page | |
| 1173 | - * | |
| 1174 | - * @param $operator | |
| 1175 | - * @param $value | |
| 1176 | - * | |
| 1177 | - * @return boolean | |
| 1178 | - * @since 2.4.0 | |
| 1179 | - */ | |
| 1180 | - private function page_taxonomy( $operator, $value ) { | |
| 1181 | - $term_id = null; | |
| 1182 | - | |
| 1183 | - if ( is_singular() ) { | |
| 1184 | - $post_cat = get_the_category( get_the_ID() ); | |
| 1185 | - if ( is_array( $post_cat ) ) { | |
| 1186 | - foreach ( $post_cat as $item ) { | |
| 1187 | - $term_id[] = $item->term_id; | |
| 1188 | - } | |
| 1189 | - } | |
| 1190 | - } | |
| 1191 | - | |
| 1192 | - if ( $term_id ) { | |
| 1193 | - return $this->checkByOperator( $operator, intval( $value ), $term_id ); | |
| 1194 | - } | |
| 1195 | - | |
| 1196 | - return false; | |
| 1197 | - } | |
| 1198 | 951 | } |