function axiom_get_post_data(&$opt, $post_obj = null) { $opt = axiom_get_post_data_options($opt); global $post, $wp_query; $old_post = null; if (!empty($post) && is_object($post)) { $old_post = clone $post; } if ($post_obj != null) { $post = $post_obj; setup_postdata($post); } $cur_post = clone $post; $post_id = get_the_ID(); $post_parent_id = wp_get_post_parent_id($post_id); if (!$post_parent_id) { $post_parent_id = 0; } $post_type = get_post_type(); $post_protected = post_password_required(); $post_format = get_post_format(); if (empty($post_format)) { $post_format = 'standard'; } $post_icon = axiom_get_custom_option('icon', axiom_get_post_format_icon($post_format), $post_id, $post_type); //!!!!! Get option from specified post $post_flags = array('sticky' => is_sticky()); $post_link = get_permalink(); $post_comments_link = get_comments_link(); $post_date_sql = get_the_date('Y-m-d H:i:s'); $post_date_stamp = get_the_date('U'); $post_date = axiom_get_date_or_difference($post_date_sql); if (!empty($opt['date_format'])) { $parts = explode('+', $opt['date_format']); $post_date_part1 = empty($parts[0]) ? '' : date($parts[0], $post_date_stamp); $post_date_part2 = empty($parts[1]) ? '' : date($parts[1], $post_date_stamp); if ($post_date_part1 . $post_date_part2 != '') { $post_date = $post_date_part1 . ($post_date_part2 != '' ? ' ' . $post_date_part2 : ''); } } $post_comments = $post_views = $post_likes = 0; if ($opt['counters'] != '') { $post_comments = get_comments_number(); $post_views = axiom_get_post_views($post_id); $post_likes = axiom_get_post_likes($post_id); } $post_reviews_author = $post_reviews_users = 0; if ($opt['reviews']) { $post_reviews_author = axiom_reviews_marks_to_display(get_post_meta($post_id, 'reviews_avg', true)); $post_reviews_users = axiom_reviews_marks_to_display(get_post_meta($post_id, 'reviews_avg2', true)); } $post_author = get_the_author(); $post_author_id = get_the_author_meta('ID'); $post_author_url = get_author_posts_url($post_author_id, ''); // Is user can edit and/or delete this post? $allow_editor = axiom_get_theme_option("allow_editor") == 'yes'; $post_edit_enable = $allow_editor && ($post_type == 'post' && current_user_can('edit_posts', $post_id) || $post_type == 'page' && current_user_can('edit_pages', $post_id)); $post_delete_enable = $allow_editor && ($post_type == 'post' && current_user_can('delete_posts', $post_id) || $post_type == 'page' && current_user_can('delete_pages', $post_id)); // Post content global $more; $old_more = $more; $more = -1; $post_content_original = trim(chop($post->post_content)); $post_content_plain = trim(chop(get_the_content())); $more = $old_more; $post_content = trim(chop(get_the_content($opt['more_tag'], $opt['strip_teaser']))); // Substitute WP [gallery] shortcode $thumb_sizes = axiom_get_thumb_sizes(array('layout' => $opt['layout'])); if ($opt['content']) { if ($opt['substitute_gallery']) { $post_content = axiom_substitute_gallery($post_content, $post_id, $thumb_sizes['w'], $thumb_sizes['h_crop'], 'none', true); } $post_content = apply_filters('the_content', $post_content); if ($post_id != get_the_ID()) { // Fix bug in the WPML $post = $cur_post; setup_postdata($post); } if ($opt['substitute_video']) { $post_content = axiom_substitute_video($post_content, $thumb_sizes['w'], $thumb_sizes['h_crop']); } if ($opt['substitute_audio']) { $post_content = axiom_substitute_audio($post_content); } } // Post excerpt $post_excerpt_original = $post->post_excerpt; $post_excerpt = has_excerpt() || $post_protected ? get_the_excerpt() : ''; if (empty($post_excerpt)) { if (($more_pos = axiom_strpos($post_content_plain, '<span id="more-')) !== false) { $post_excerpt = axiom_substr($post_content_plain, 0, $more_pos); } else { $post_excerpt = in_array($post_format, array('quote', 'link')) ? $post_content : strip_shortcodes(strip_tags(get_the_excerpt())); } } if ($opt['substitute_gallery']) { $post_excerpt = axiom_substitute_gallery($post_excerpt, $post_id, $thumb_sizes['w'], $thumb_sizes['h_crop']); } $post_excerpt = apply_filters('axiom_filter_sc_clear_around', $post_excerpt); $post_excerpt = apply_filters('the_excerpt', $post_excerpt); $post_excerpt = apply_filters('axiom_filter_p_clear_around', $post_excerpt); if ($post_id != get_the_ID()) { // Fix bug in the WPML $post = $cur_post; setup_postdata($post); } if ($opt['substitute_video']) { $post_excerpt = axiom_substitute_video($post_excerpt, $thumb_sizes['w'], $thumb_sizes['h_crop']); } if ($opt['substitute_audio']) { $post_excerpt = axiom_substitute_audio($post_excerpt); } $post_excerpt = trim(chop(str_replace(array('[...]', '[…]'), array('', ''), $post_excerpt))); // Post Title $post_title = $post_title_plain = trim(chop(get_the_title())); $post_title = apply_filters('the_title', $post_title); if ($post_id != get_the_ID()) { // Fix bug in the WPML $post = $cur_post; setup_postdata($post); } // Prepare dedicated content $opt['dedicated'] = axiom_sc_get_dedicated_content(); $opt['location'] = !empty($opt['location']) ? $opt['location'] : axiom_get_custom_option('dedicated_location'); if (empty($opt['location']) || $opt['location'] == 'default') { $opt['location'] = axiom_get_custom_option('dedicated_location', '', $post_id, $post_type); } //!!!!! Get option from specified post if ($opt['location'] == 'alter' && !is_single() && (!is_page() || isset($wp_query->is_posts_page) && $wp_query->is_posts_page == 1)) { $loc = array('center', 'right', 'left'); $opt['location'] = $loc[($opt['number'] - 1) % count($loc)]; } if (!empty($opt['dedicated'])) { $class = axiom_get_tag_attrib($opt['dedicated'], '<div class="sc_section>', 'class'); if ($opt['location'] == 'default') { if (($pos = axiom_strpos($class, 'sc_align')) !== false) { $pos += 8; $pos2 = axiom_strpos($class, ' ', $pos); $opt['location'] = $pos2 === false ? axiom_substr($class, $pos) : axiom_substr($class, $pos, $pos2 - $pos); } if ($opt['location'] == '' || $opt['location'] == 'default') { $opt['location'] = 'center'; } } if (!is_singular() || axiom_get_global('blog_streampage') || axiom_sc_in_shortcode_blogger(true) || axiom_strpos($class, 'sc_align') !== false && axiom_strpos($class, 'columns') === false) { $class = str_replace(array('sc_alignright', 'sc_alignleft', 'sc_aligncenter'), array('', '', ''), $class) . ' sc_align' . esc_attr($opt['location']); //if ($opt['location'] == 'center' && axiom_strpos($class, 'column-2_3')===false && $opt['sidebar']) // $class = str_replace('columns', '_columns', $class) . ' column-2_3'; //else if (($opt['location'] == 'left' || $opt['location'] == 'right') && axiom_strpos($class, 'column-1_2')===false)// && $opt['sidebar']) // $class = str_replace('columns', '_columns', $class) . ' column-1_2'; $opt['dedicated'] = axiom_set_tag_attrib($opt['dedicated'], '<div class="sc_section>', 'class', $class); } } //else if ($opt['location']=='' || $opt['location']=='default') //$opt['location'] = 'center'; //if ($opt['location']=='default') $opt['location']='center'; $opt['post_class'] = $opt['location']; // Substitute <video> tags to <iframe> in dedicated content if ($opt['substitute_video']) { $opt['dedicated'] = axiom_substitute_video($opt['dedicated'], $thumb_sizes['w'], $thumb_sizes['h_crop']); } // Substitute <audio> tags with src from soundcloud to <iframe> if ($opt['substitute_audio']) { $opt['dedicated'] = axiom_substitute_audio($opt['dedicated']); } // Extract gallery, video and audio from full post content $post_thumb = $post_thumb_url = $post_attachment = $post_gallery = $post_video = $post_video_image = $post_audio = $post_audio_image = $post_url = $post_url_target = ''; $post_attachment = wp_get_attachment_url(get_post_thumbnail_id($post_id)); if (axiom_substr($opt['layout'], 0, 6) == 'single') { $post_thumb = axiom_get_resized_image_tag($post_id, $thumb_sizes['w'], $thumb_sizes['h'], null, false, false, true); } else { if (axiom_substr($opt['layout'], 0, 10) == 'attachment') { $post_thumb = axiom_get_resized_image_tag($post_attachment, $thumb_sizes['w'], $thumb_sizes['h'], null, false, false, true); } else { $post_thumb = axiom_get_resized_image_tag($post_id, $thumb_sizes['w'], $post_type == 'product' && axiom_get_theme_option('crop_product_thumb') == 'no' ? null : $thumb_sizes['h']); } } $post_thumb_url = axiom_get_tag_attrib($post_thumb, '<img>', 'src'); if ($post_format == 'gallery') { $post_gallery = axiom_build_gallery_tag(axiom_get_post_gallery($post_content_plain, $post_id, max(2, axiom_get_custom_option('gallery_max_slides'))), $thumb_sizes['w'], $thumb_sizes['h_crop'], false, $post_link); } else { if ($post_format == 'video') { $src = ''; $post_video = axiom_get_post_video($post_content_original, false); if ($post_video == '') { $src = axiom_get_post_video($post_content_original, true); if (!axiom_is_youtube_url($src) && !axiom_is_vimeo_url($src)) { $src = ''; } } else { if (axiom_substr($post_video, 0, 1) == '[') { $src = axiom_get_tag_attrib($post_video, '[trx_video]', 'src'); if (empty($src)) { $src = axiom_get_tag_attrib($post_video, '[trx_video]', 'url'); } if (empty($src)) { $src = axiom_get_post_video($post_video, true); } $post_video_image = axiom_get_tag_attrib($post_video, '[trx_video]', 'image'); if ($post_video_image > 0) { $attach = wp_get_attachment_image_src($post_video_image, 'full'); if (isset($attach[0]) && $attach[0] != '') { $post_video_image = $attach[0]; } } if (empty($post_video_image)) { $post_video_image = axiom_get_video_cover_image($src); } if (empty($post_video_image)) { $post_video_image = $post_thumb; } $post_video_image = axiom_get_resized_image_tag($post_video_image, $thumb_sizes['w'], $thumb_sizes['h']); } else { $src = axiom_get_post_video($post_video, true); } } if ($src) { $src = axiom_get_video_player_url($src, $post_thumb != '' || $post_video_image != ''); $post_video = '<video src="' . esc_url($src) . '" width="' . esc_attr($thumb_sizes['w']) . '" height="' . round($thumb_sizes['w'] / 16 * 9) . '"></video>'; } if ($post_video != '' && $opt['substitute_video']) { $post_video = axiom_substitute_video($post_video, $thumb_sizes['w'], round($thumb_sizes['w'] / 16 * 9), false); //$thumb_sizes['h_crop']); } } else { if ($post_format == 'audio') { $src = $data = ''; $post_audio = axiom_get_post_audio($post_content_original, false); if ($post_audio == '') { $src = axiom_get_post_audio($post_content_original, true); } else { if (axiom_substr($post_audio, 0, 1) == '[') { $src = axiom_get_tag_attrib($post_audio, '[trx_audio]', 'src'); if (empty($src)) { $src = axiom_get_tag_attrib($post_audio, '[trx_audio]', 'url'); } if (empty($src)) { $src = axiom_get_post_audio($post_audio, true); } $post_audio_image = axiom_get_tag_attrib($post_audio, '[trx_audio]', 'image'); if ($post_audio_image > 0) { $attach = wp_get_attachment_image_src($post_audio_image, 'full'); if (isset($attach[0]) && $attach[0] != '') { $post_audio_image = $attach[0]; } } if (empty($post_audio_image)) { $post_audio_image = $post_thumb; } if ($post_audio_image) { $post_audio_image = axiom_get_resized_image_url($post_audio_image, $thumb_sizes['w'], $thumb_sizes['h']); } $post_audio_title = axiom_get_tag_attrib($post_audio, '[trx_audio]', 'title'); $post_audio_author = axiom_get_tag_attrib($post_audio, '[trx_audio]', 'author'); $data = ($post_audio_title != '' ? ' data-title="' . esc_attr($post_audio_title) . '"' : '') . ($post_audio_author != '' ? ' data-author="' . esc_attr($post_audio_author) . '"' : '') . ($post_audio_image != '' ? ' data-image="' . esc_attr($post_audio_image) . '"' : ''); } else { $src = axiom_get_post_audio($post_audio, true); } } if ($src) { $post_audio = '<audio class="sc_audio" src="' . esc_url($src) . '"' . $data . '></audio>'; } if ($post_audio != '' && $opt['substitute_audio'] == 'yes') { $post_audio = axiom_substitute_audio($post_audio, false); } } } } if ($post_format == 'image' && !$post_thumb && !is_single()) { if (($src = axiom_get_post_image($post_content_original, $post_id)) != '') { $post_thumb = axiom_get_resized_image_tag($src, $thumb_sizes['w'], $thumb_sizes['h_crop']); } } if ($post_format == 'link') { $post_url_data = axiom_get_post_link($post_content_original, false); $post_link = $post_url = $post_url_data['url']; $post_url_target = $post_url_data['target']; } // Get all post's terms $post_taxonomy = axiom_get_taxonomy_categories_by_post_type($post_type); $post_taxonomy_tags = axiom_get_taxonomy_tags_by_post_type($post_type); $post_terms = array(); if ($opt['terms_list']) { $post_terms = axiom_get_terms_by_post_id(array('post_id' => $post_id, 'parent_id' => $post_type == 'post' ? $opt['parent_tax_id'] : 0, 'exclude' => $post_type == 'post' ? explode(',', axiom_get_theme_option('exclude_cats')) : array())); } if ($old_post != null) { $post = $old_post; setup_postdata($post); } $post_data = compact('post_id', 'post_parent_id', 'post_protected', 'post_type', 'post_taxonomy', 'post_taxonomy_tags', 'post_format', 'post_flags', 'post_icon', 'post_link', 'post_comments_link', 'post_date_sql', 'post_date_stamp', 'post_date', 'post_date_part1', 'post_date_part2', 'post_comments', 'post_views', 'post_likes', 'post_reviews_author', 'post_reviews_users', 'post_author', 'post_author_id', 'post_author_url', 'post_title', 'post_title_plain', 'post_content_plain', 'post_content_original', 'post_content', 'post_excerpt_original', 'post_excerpt', 'post_thumb', 'post_thumb_url', 'post_attachment', 'post_gallery', 'post_video', 'post_video_image', 'post_audio', 'post_audio_image', 'post_url', 'post_url_target', 'post_terms', 'post_edit_enable', 'post_delete_enable'); return apply_filters('axiom_filter_get_post_data', $post_data, $opt, $post_obj); }
function axiom_sc_video($atts, $content = null) { if (axiom_sc_in_shortcode_blogger()) { return ''; } extract(axiom_sc_html_decode(shortcode_atts(array("url" => '', "src" => '', "image" => '', "ratio" => '16:9', "autoplay" => 'off', "align" => '', "bg_image" => '', "bg_top" => '', "bg_bottom" => '', "bg_left" => '', "bg_right" => '', "frame" => "on", "id" => "", "class" => "", "animation" => "", "css" => "", "width" => '', "height" => '', "top" => "", "bottom" => "", "left" => "", "right" => ""), $atts))); $ratio = empty($ratio) ? "16:9" : str_replace(array('/', '\\', '-'), ':', $ratio); $ratio_parts = explode(':', $ratio); if (empty($height) && empty($width)) { $width = '100%'; } $ed = axiom_substr($width, -1); if (empty($height) && !empty($width) && $ed != '%') { $height = round($width / $ratio_parts[0] * $ratio_parts[1]); } if (!empty($height) && empty($width)) { $width = round($height * $ratio_parts[0] / $ratio_parts[1]); } $css .= axiom_get_css_position_from_values($top, $right, $bottom, $left); $css_dim = axiom_get_css_position_from_values('', '', '', '', $width, $height); $css_bg = axiom_get_css_paddings_from_values($bg_top, $bg_right, $bg_bottom, $bg_left); if ($src == '' && $url == '' && isset($atts[0])) { $src = $atts[0]; } $url = $src != '' ? $src : $url; if ($image != '' && axiom_sc_param_is_off($image)) { $image = ''; } else { if (axiom_sc_param_is_on($autoplay) && is_single()) { $image = ''; } else { if ($image > 0) { $attach = wp_get_attachment_image_src($image, 'full'); if (isset($attach[0]) && $attach[0] != '') { $image = $attach[0]; } } if ($bg_image) { $thumb_sizes = axiom_get_thumb_sizes(array('layout' => 'grid_3')); $image = axiom_get_resized_image_url(empty($image) ? get_the_ID() : $image, $thumb_sizes['w'], $thumb_sizes['h'], null, false, false, false); } else { $image = axiom_get_resized_image_url(empty($image) ? get_the_ID() : $image, $ed != '%' ? $width : null, $height); } if (empty($image)) { $image = axiom_get_video_cover_image($url); } } } if ($bg_image > 0) { $attach = wp_get_attachment_image_src($bg_image, 'full'); if (isset($attach[0]) && $attach[0] != '') { $bg_image = $attach[0]; } } if ($bg_image) { $css_bg .= $css . 'background-image: url(' . esc_url($bg_image) . ');'; $css = $css_dim; } else { $css .= $css_dim; } $url = axiom_get_video_player_url($src != '' ? $src : $url); $video = '<video' . ($id ? ' id="' . esc_attr($id) . '"' : '') . ' class="sc_video' . (!empty($class) ? ' ' . esc_attr($class) : '') . '"' . ' src="' . esc_url($url) . '"' . ' width="' . esc_attr($width) . '" height="' . esc_attr($height) . '"' . ' data-width="' . esc_attr($width) . '" data-height="' . esc_attr($height) . '"' . ' data-ratio="' . esc_attr($ratio) . '"' . ($image ? ' poster="' . esc_attr($image) . '" data-image="' . esc_attr($image) . '"' : '') . (!axiom_sc_param_is_off($animation) ? ' data-animation="' . esc_attr(axiom_sc_get_animation_classes($animation)) . '"' : '') . ($align && $align != 'none' ? ' data-align="' . esc_attr($align) . '"' : '') . ($bg_image ? ' data-bg-image="' . esc_attr($bg_image) . '"' : '') . ($css_bg != '' ? ' data-style="' . esc_attr($css_bg) . '"' : '') . ($css != '' ? ' style="' . esc_attr($css) . '"' : '') . ($image && axiom_get_theme_option('substitute_video') == 'yes' || axiom_sc_param_is_on($autoplay) && is_single() ? ' autoplay="autoplay"' : '') . ' controls="controls" loop="loop"' . '>' . '</video>'; if (axiom_get_custom_option('substitute_video') == 'no') { if (axiom_sc_param_is_on($frame)) { $video = axiom_get_video_frame($video, $image, $css, $css_bg); } } else { if (isset($_GET['vc_editable']) && $_GET['vc_editable'] == 'true' && (isset($_POST['action']) && $_POST['action'] == 'vc_load_shortcode')) { $video = axiom_substitute_video($video, $width, $height, false); } } if (axiom_get_theme_option('use_mediaelement') == 'yes') { axiom_enqueue_script('wp-mediaelement'); } return apply_filters('axiom_shortcode_output', $video, 'trx_video', $atts, $content); }
function axiom_substitute_video($post_text, $w, $h, $in_frame = true) { $tag = '<video>'; $tag_end = '</video>'; $pos_start = -1; while (($pos_start = axiom_strpos($post_text, axiom_substr($tag, 0, -1) . ' ', $pos_start + 1)) !== false) { $pos_end = axiom_strpos($post_text, axiom_substr($tag, -1), $pos_start); $pos_end2 = axiom_strpos($post_text, $tag_end, $pos_end); $tag_text = axiom_substr($post_text, $pos_start, ($pos_end2 !== false ? $pos_end2 + axiom_strlen($tag_end) - 1 : $pos_end) - $pos_start + 1); if (axiom_get_tag_attrib($tag_text, $tag, 'data-frame') == 'no') { continue; } if (($src = axiom_get_tag_attrib($tag_text, $tag, 'src')) == '') { $src = axiom_get_tag_attrib($tag_text, $tag, 'url'); } if ($src != '') { $auto = axiom_get_tag_attrib($tag_text, $tag, 'autoplay'); $src = axiom_get_video_player_url($src, $auto != ''); // && is_single()); $id = axiom_get_tag_attrib($tag_text, $tag, 'id'); $tag_w = axiom_get_tag_attrib($tag_text, $tag, 'width'); $tag_h = axiom_get_tag_attrib($tag_text, $tag, 'height'); $tag_a = axiom_get_tag_attrib($tag_text, $tag, 'align'); if (!$tag_a) { $tag_a = axiom_get_tag_attrib($tag_text, $tag, 'data-align'); } $tag_s = axiom_get_tag_attrib($tag_text, $tag, 'style'); $tag_s2 = axiom_get_tag_attrib($tag_text, $tag, 'data-style'); $tag_c = axiom_get_tag_attrib($tag_text, $tag, 'controls'); $tag_l = axiom_get_tag_attrib($tag_text, $tag, 'loop'); $video = '<iframe' . ($id ? ' id="' . esc_attr($id) . '"' : '') . ' class="video_frame' . (!$in_frame && $tag_a ? ' align' . esc_attr($tag_a) : '') . '"' . ' src="' . esc_url($src) . '"' . ' width="' . esc_attr($tag_w ? $tag_w : $w) . '"' . ' height="' . esc_attr($tag_h ? $tag_h : $h) . '"' . ($tag_a ? ' data-align="' . esc_attr($tag_a) . '"' : '') . ' frameborder="0" webkitAllowFullScreen="webkitAllowFullScreen" mozallowfullscreen="mozallowfullscreen" allowFullScreen="allowFullScreen"></iframe>'; if ($in_frame) { $tag_image = axiom_get_tag_attrib($tag_text, $tag, 'data-image'); $video = axiom_get_video_frame($video, $tag_image, $tag_s, $tag_s2); } $pos_end = $pos_end2 !== false ? $pos_end2 + 8 : $pos_end + 1; $post_text = axiom_substr($post_text, 0, axiom_substr($post_text, $pos_start - 3, 3) == '<p>' ? $pos_start - 3 : $pos_start) . $video . axiom_substr($post_text, axiom_substr($post_text, $pos_end, 4) == '</p>' ? $pos_end + 4 : $pos_end); } } return $post_text; }