Пример #1
0
            echo $img_handle;
            ?>
')">{{featured_image_<?php 
            echo $img_handle;
            ?>
}}</a></td><td><?php 
            _e("Featured Image &lt;img /&gt;", REVSLIDER_TEXTDOMAIN);
            echo ' ' . $img_name;
            ?>
</td></tr>
							<?php 
        }
        ?>
					</table>
					<?php 
        if (RevSliderWooCommerce::isWooCommerceExists()) {
            ?>
						<table class="table_template_help" id="slide-woocommerce-template-entry" style="display: none;">
							<tr><td><a href="javascript:UniteLayersRev.insertTemplate('wc_sku')">{{wc_sku}}</a></td><td><?php 
            _e("SKU", REVSLIDER_TEXTDOMAIN);
            ?>
</td></tr>
							<tr><td><a href="javascript:UniteLayersRev.insertTemplate('wc_full_price')">{{wc_full_price}}</a></td><td><?php 
            _e("Full Price", REVSLIDER_TEXTDOMAIN);
            ?>
</td></tr>
							<tr><td><a href="javascript:UniteLayersRev.insertTemplate('wc_price')">{{wc_price}}</a></td><td><?php 
            _e("Single Price", REVSLIDER_TEXTDOMAIN);
            ?>
</td></tr>
							<tr><td><a href="javascript:UniteLayersRev.insertTemplate('wc_price_no_cur')">{{wc_price_no_cur}}</a></td><td><?php 
Пример #2
0
 public function set_post_data($text, $attr, $post_id)
 {
     $img_sizes = RevSliderBase::get_all_image_sizes();
     $title = isset($attr['title']) ? $attr['title'] : '';
     $excerpt = isset($attr['excerpt']) ? $attr['excerpt'] : '';
     $alias = isset($attr['alias']) ? $attr['alias'] : '';
     $content = isset($attr['content']) ? $attr['content'] : '';
     $link = isset($attr['link']) ? $attr['link'] : '';
     $postDate = isset($attr['postDate']) ? $attr['postDate'] : '';
     $dateModified = isset($attr['dateModified']) ? $attr['dateModified'] : '';
     $authorName = isset($attr['authorName']) ? $attr['authorName'] : '';
     $numComments = isset($attr['numComments']) ? $attr['numComments'] : '';
     $catlist = isset($attr['catlist']) ? $attr['catlist'] : '';
     $catlist_raw = isset($attr['catlist_raw']) ? $attr['catlist_raw'] : '';
     $taglist = isset($attr['taglist']) ? $attr['taglist'] : '';
     //add filter for addon metas
     $text = apply_filters('rev_slider_insert_meta', $text, $post_id);
     $text = str_replace(array('%title%', '{{title}}'), $title, $text);
     $text = str_replace(array('%excerpt%', '{{excerpt}}'), $excerpt, $text);
     $text = str_replace(array('%alias%', '{{alias}}'), $alias, $text);
     $text = str_replace(array('%content%', '{{content}}'), $content, $text);
     $text = str_replace(array('%link%', '{{link}}'), $link, $text);
     $text = str_replace(array('%date%', '{{date}}'), $postDate, $text);
     $text = str_replace(array('%date_modified%', '{{date_modified}}'), $dateModified, $text);
     $text = str_replace(array('%author_name%', '{{author_name}}'), $authorName, $text);
     $text = str_replace(array('%num_comments%', '{{num_comments}}'), $numComments, $text);
     $text = str_replace(array('%catlist%', '{{catlist}}'), $catlist, $text);
     $text = str_replace(array('%catlist_raw%', '{{catlist_raw}}'), $catlist_raw, $text);
     $text = str_replace(array('%taglist%', '{{taglist}}'), $taglist, $text);
     foreach ($img_sizes as $img_handle => $img_name) {
         $url = isset($attr['img_urls']) && isset($attr['img_urls'][$img_handle]) && isset($attr['img_urls'][$img_handle]['url']) ? $attr['img_urls'][$img_handle]['url'] : '';
         $tag = isset($attr['img_urls']) && isset($attr['img_urls'][$img_handle]) && isset($attr['img_urls'][$img_handle]['tag']) ? $attr['img_urls'][$img_handle]['tag'] : '';
         $text = str_replace(array('%featured_image_url_' . $img_handle . '%', '{{featured_image_url_' . $img_handle . '}}'), $url, $text);
         $text = str_replace(array('%featured_image_' . $img_handle . '%', '{{featured_image_' . $img_handle . '}}'), $tag, $text);
     }
     //process meta tags:
     $text = str_replace('-', '_REVSLIDER_', $text);
     $arrMatches = array();
     preg_match_all('/%meta:\\w+%/', $text, $arrMatches);
     foreach ($arrMatches as $matched) {
         foreach ($matched as $match) {
             $meta = str_replace("%meta:", "", $match);
             $meta = str_replace("%", "", $meta);
             $meta = str_replace('_REVSLIDER_', '-', $meta);
             $metaValue = get_post_meta($post_id, $meta, true);
             $text = str_replace($match, $metaValue, $text);
         }
     }
     $arrMatches = array();
     preg_match_all('/{{meta:\\w+}}/', $text, $arrMatches);
     foreach ($arrMatches as $matched) {
         foreach ($matched as $match) {
             $meta = str_replace("{{meta:", "", $match);
             $meta = str_replace("}}", "", $meta);
             $meta = str_replace('_REVSLIDER_', '-', $meta);
             $metaValue = get_post_meta($post_id, $meta, true);
             $text = str_replace($match, $metaValue, $text);
         }
     }
     $arrMatches = array();
     preg_match_all("/{{content:\\w+[\\:]\\w+}}/", $text, $arrMatches);
     foreach ($arrMatches as $matched) {
         foreach ($matched as $match) {
             //now check length and type
             $meta = str_replace("{{content:", "", $match);
             $meta = str_replace("}}", "", $meta);
             $meta = str_replace('_REVSLIDER_', '-', $meta);
             $vals = explode(':', $meta);
             if (count($vals) !== 2) {
                 continue;
             }
             //not correct values
             $vals[1] = intval($vals[1]);
             //get real number
             if ($vals[1] === 0 || $vals[1] < 0) {
                 continue;
             }
             //needs to be at least 1
             if ($vals[0] == 'words') {
                 $metaValue = explode(' ', strip_tags($content), $vals[1] + 1);
                 if (is_array($metaValue) && count($metaValue) > $vals[1]) {
                     array_pop($metaValue);
                 }
                 $metaValue = implode(' ', $metaValue);
             } elseif ($vals[0] == 'chars') {
                 $metaValue = substr(strip_tags($content), 0, $vals[1]);
             } else {
                 continue;
             }
             $text = str_replace($match, $metaValue, $text);
         }
     }
     $text = str_replace('_REVSLIDER_', '-', $text);
     //replace event's template
     if (RevSliderEventsManager::isEventsExists()) {
         $eventData = RevSliderEventsManager::getEventPostData($post_id);
         if (!empty($eventData)) {
             foreach ($eventData as $eventKey => $eventValue) {
                 $eventPlaceholder = "%event_" . $eventKey . "%";
                 $eventPlaceholderNew = "{{event_" . $eventKey . "}}";
                 if ($eventKey == 'start_date' || $eventKey == 'end_date') {
                     $eventValue = RevSliderFunctionsWP::convertPostDate($eventValue);
                 }
                 $text = str_replace(array($eventPlaceholder, $eventPlaceholderNew), $eventValue, $text);
             }
         }
     }
     if (RevSliderWooCommerce::isWooCommerceExists()) {
         $product = get_product($post_id);
         $wc_full_price = $product->get_price_html();
         $wc_price = wc_price($product->get_price());
         $wc_price_no_cur = $product->get_price();
         $wc_stock = $product->get_total_stock();
         $wc_rating = $product->get_rating_html();
         $wc_star_rating = '<div class="rs-starring">';
         preg_match_all('#<strong class="rating">.*?</span>#', $wc_rating, $match);
         if (!empty($match) && isset($match[0]) && isset($match[0][0])) {
             $wc_star_rating .= str_replace($match[0][0], '', $wc_rating);
         }
         $wc_star_rating .= '</div>';
         $wc_categories = $product->get_categories(',');
         $wc_add_to_cart = $product->add_to_cart_url();
         $wc_add_to_cart_button = '';
         $wc_sku = $product->get_sku();
         $wc_stock_quantity = $product->get_stock_quantity();
         $wc_rating_count = $product->get_rating_count();
         $wc_review_count = $product->get_review_count();
         $wc_tags = $product->get_tags();
         if (strpos($text, 'wc_add_to_cart_button') !== false) {
             $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
             $ajax_cart_en = get_option('woocommerce_enable_ajax_add_to_cart') == 'yes' ? true : false;
             $assets_path = str_replace(array('http:', 'https:'), '', WC()->plugin_url()) . '/assets/';
             $frontend_script_path = $assets_path . 'js/frontend/';
             if ($ajax_cart_en) {
                 wp_enqueue_script('wc-add-to-cart', $frontend_script_path . 'add-to-cart' . $suffix . '.js', array('jquery'), WC_VERSION, true);
                 global $wc_is_localized;
                 if ($wc_is_localized === false) {
                     //load it only one time
                     wp_localize_script('wc-add-to-cart', 'wc_add_to_cart_params', apply_filters('wc_add_to_cart_params', array('ajax_url' => WC()->ajax_url(), 'ajax_loader_url' => apply_filters('woocommerce_ajax_loader_url', $assets_path . 'images/ajax-loader@2x.gif'), 'i18n_view_cart' => esc_attr__('View Cart', 'woocommerce'), 'cart_url' => get_permalink(wc_get_page_id('cart')), 'is_cart' => is_cart(), 'cart_redirect_after_add' => get_option('woocommerce_cart_redirect_after_add'))));
                     $wc_is_localized = true;
                 }
             }
             $wc_add_to_cart_button = apply_filters('woocommerce_loop_add_to_cart_link', sprintf('<a href="%s" rel="nofollow" data-product_id="%s" data-product_sku="%s" class="button %s product_type_%s">%s</a>', esc_url($product->add_to_cart_url()), esc_attr($product->id), esc_attr($product->get_sku()), $product->is_purchasable() ? 'add_to_cart_button' : '', esc_attr($product->product_type), esc_html($product->add_to_cart_text())), $product);
         }
         $text = str_replace(array('%wc_full_price%', '{{wc_full_price}}'), $wc_full_price, $text);
         $text = str_replace(array('%wc_price%', '{{wc_price}}'), $wc_price, $text);
         $text = str_replace(array('%wc_price_no_cur%', '{{wc_price_no_cur}}'), $wc_price_no_cur, $text);
         $text = str_replace(array('%wc_stock%', '{{wc_stock}}'), $wc_stock, $text);
         $text = str_replace(array('%wc_rating%', '{{wc_rating}}'), $wc_rating, $text);
         $text = str_replace(array('%wc_star_rating%', '{{wc_star_rating}}'), $wc_star_rating, $text);
         $text = str_replace(array('%wc_categories%', '{{wc_categories}}'), $wc_categories, $text);
         $text = str_replace(array('%wc_add_to_cart%', '{{wc_add_to_cart}}'), $wc_add_to_cart, $text);
         $text = str_replace(array('%wc_add_to_cart_button%', '{{wc_add_to_cart_button}}'), $wc_add_to_cart_button, $text);
         $text = str_replace(array('%wc_sku%', '{{wc_sku}}'), $wc_sku, $text);
         $text = str_replace(array('%wc_stock_quantity%', '{{wc_stock_quantity}}'), $wc_stock_quantity, $text);
         $text = str_replace(array('%wc_rating_count%', '{{wc_rating_count}}'), $wc_rating_count, $text);
         $text = str_replace(array('%wc_review_count%', '{{wc_review_count}}'), $wc_review_count, $text);
         $text = str_replace(array('%wc_tags%', '{{wc_tags}}'), $wc_tags, $text);
     }
     return $text;
 }