ass if you need to change this behaviour. * * @since 4.7.6.3 * @param string $shortcode * @return boolean */ public function is_nested_self_closing( $shortcode ) { if( in_array( $shortcode, $this->config['shortcode_nested'] ) ) { return true; } return false; } /** * Create custom stylings * * @since 4.8.4 * @param array $args * @return array */ protected function get_element_styles( array $args ) { $result = parent::get_element_styles( $args ); extract( $result ); $default = array( 'post_selected' => '', 'seperator' => '/', 'before_meta_content' => '', 'after_meta_content' => '', 'margin' => '', 'align' => 'left', 'custom_title' => '', 'size' => '', ); $default = $this->sync_sc_defaults_array( $default, 'no_modal_item', 'no_content' ); $locked = array(); Avia_Element_Templates()->set_locked_attributes( $atts, $this, $shortcodename, $default, $locked, $content ); Avia_Element_Templates()->add_template_class( $meta, $atts, $default ); $metadata = ShortcodeHelper::shortcode2array( $content, 1 ); $group_defaults = $this->sync_sc_defaults_array( $this->get_group_defaults(), 'modal_item', 'no_content' ); foreach( $metadata as &$meta_values ) { Avia_Element_Templates()->set_locked_attributes( $meta_values['attr'], $this, $this->config['shortcode_nested'][0], $group_defaults, $locked, $meta_values['content'] ); } unset( $meta_values ); $atts = shortcode_atts( $default, $atts, $this->config['shortcode'] ); $atts['metadata'] = $metadata; if( is_numeric( $atts['size'] ) ) { $atts['size'] .= 'px'; } $element_styling->create_callback_styles( $atts ); $classes = array( 'av-post-metadata-container', $element_id, 'av-metadata-container-align-' . $atts['align'], ); $element_styling->add_classes( 'container', $classes ); $element_styling->add_classes_from_array( 'container', $meta, 'el_class' ); $element_styling->add_styles( 'container', array( 'color' => $atts['custom_title'], 'font-size' => $atts['size'] ) ); if( ! empty( $atts['margin'] ) ) { $element_styling->add_callback_styles( 'container', array( 'margin' ) ); } $selectors = array( 'container' => "#top .av-post-metadata-container.{$element_id}" ); $element_styling->add_selectors( $selectors ); $result['default'] = $default; $result['atts'] = $atts; $result['content'] = $content; $result['element_styling'] = $element_styling; return $result; } /** * Frontend Shortcode Handler * * @since 4.7.6.3 * @param array $atts array of attributes * @param string $content text within enclosing form of shortcode element * @param string $shortcodename the shortcode found, when == callback name * @param array $meta * @return string the modified html string */ public function shortcode_handler( $atts, $content = '', $shortcodename = '', $meta = '' ) { $result = $this->get_element_styles( compact( array( 'atts', 'content', 'shortcodename', 'meta' ) ) ); extract( $result ); $this->screen_options = AviaHelper::av_mobile_sizes( $atts ); extract( $this->screen_options ); //return $av_font_classes, $av_title_font_classes and $av_display_classes $this->atts = $atts; avia_sc_post_metadata::$instance ++; extract( $this->atts ); global $post; $this->post_id = 0; unset( $this->post ); $this->post = null; /** * Initialise, as on ajax preview callback there is no connection to post */ if( isset( $_REQUEST['text_to_preview_post_id'] ) ) { $this->post_id = (int) $_REQUEST['text_to_preview_post_id']; } else if( $post instanceof WP_Post ) { $this->post_id = $post->ID; } if( $this->atts['post_selected'] != '' ) { $link = explode( ',', $this->atts['post_selected'], 2 ); if( isset( $link[1] ) && is_numeric( $link[1] ) ) { $this->post_id = (int) $link[1]; } } $this->post = get_post( $this->post_id ); if( ! $this->post instanceof WP_Post ) { unset( $this->post ); $this->post = null; return ''; } $metadata_content = $this->get_metadata_content( $metadata ); if( empty( $metadata_content ) ) { return ''; } $element_styling->add_classes( 'container', 'av-metadata-container-' . avia_sc_post_metadata::$instance ); $style_tag = $element_styling->get_style_tag( $element_id ); $container_class = $element_styling->get_class_string( 'container' ); $output = ''; $output .= $style_tag; $output .= "
"; $output .= "
"; if( ! empty( $before_meta_content ) ) { $output .= ''; } $output .= ''; if( ! empty( $after_meta_content ) ) { $output .= ''; } $output .= '
'; $output .= '
'; return $output; } /** * Returns the default array * * @since 4.8 * @return array */ protected function get_group_defaults() { $default = array( 'metadata' => 'author', 'before_meta' => '', 'after_meta' => '', 'link_meta' => 'default', 'link_target' => '', 'url' => '', // save url if link_meta != 'default' 'attributes' => '' // target="_blank" rel="nofollow" ); return $default; } /** * Returns all selected metadata in a HTML string * * @since 4.7.6.3 * @param array $content * @return string */ protected function get_metadata_content( $content = array() ) { $sep = '' . $this->atts['seperator'] . ''; $output = array(); foreach( $content as $meta_values ) { $meta = shortcode_atts( $this->get_group_defaults(), $meta_values['attr'], $this->config['shortcode_nested'][0] ); $rel_attr = array(); switch( $meta['metadata'] ) { case 'author': $rel_attr[] = 'author'; break; } $meta['attributes'] = AviaHelper::get_link_target( $meta['link_target'], $meta['link_meta'], $rel_attr ); $link = ( 'default' == $meta['link_meta'] ) ? '' : trim( AviaHelper::get_url( $meta['link_meta'] ) ); $meta['url'] = ( in_array( $link, array( 'http://', 'https://', 'manually' ) ) ) ? '' : $link; $out = ''; switch( $meta['metadata'] ) { case 'author': $out = $this->author( $meta ); break; case 'categories': $out = $this->taxonomies( $meta, 'categories' ); break; case 'tags': $out = $this->taxonomies( $meta, 'tags' ); break; case 'comments': $out = $this->comments( $meta ); break; case 'revisions': $out = $this->revisions( $meta ); break; case 'published': case 'published time': case 'modified': case 'modified time': $out = $this->date_time( $meta ); break; } if( ! empty( $out ) ) { $output[] = $out; } } $output = ! empty( $output ) ? implode( $sep, $output ) : ''; return $output; } /** * Return Metadata for author * * @since 4.7.6.3 * @param array $meta * @return string */ protected function author( array $meta ) { $output = ''; $output .= ' 'author_name', 'echo' => false ) ) . '>'; $output .= $this->html_before( $meta ); if( 'default' == $meta['link_meta'] ) { $output .= ''; $output .= '' . get_the_author_meta( 'display_name', $this->post->post_author ) . ''; $output .= ''; } else if( $meta['url'] != '' ) { $output .= ''; $output .= '' . get_the_author_meta( 'display_name', $this->post->post_author ) . ''; $output .= ''; } else { $output .= ''; $output .= get_the_author_meta( 'display_name', $this->post->post_author ); $output .= ''; } $output .= $this->html_after( $meta ); $output .= ''; return $output; } /** * Get taxonomies terms for post * * @since 4.7.6.3 * @param array $meta * @param string $which 'categories' | 'tags' * @return string */ protected function taxonomies( array $meta, $which ) { // Get post type taxonomies. $taxonomies = get_object_taxonomies( $this->post->post_type, 'objects' ); $names = array(); $links = array(); foreach ( $taxonomies as $taxonomy_slug => $taxonomy ) { if( $which == 'tags' ) { if( $taxonomy_slug != 'post_tag' ) { continue; } } else if( in_array( $taxonomy_slug, array( 'post_tag', 'post_format' ) ) ) { continue; } // Get the terms related to post. $terms = get_the_terms( $this->post->ID, $taxonomy_slug ); if( ! is_array( $terms ) ) { continue; } foreach ( $terms as $term ) { $names[ $term->slug ] = $term->name; if( 'no_link' != $meta['link_meta'] ) { $links[ $term->slug ] = esc_url( get_term_link( $term->slug, $taxonomy_slug ) ); } } } if( empty( $names ) ) { return ''; } asort( $names ); $output = ''; $output .= ''; $output .= $this->html_before( $meta ); $sep = ''; foreach( $names as $slug => $name ) { if( $sep != '' ) { $output .= $sep; } if( 'default' == $meta['link_meta'] ) { $output .= ''; $output .= '' . $name . ''; $output .= ''; } else if( $meta['url'] != '' ) { $output .= ''; $output .= '' . $name . ''; $output .= ''; } else { $output .= ''; $output .= $name; $output .= ''; } $sep = ', '; } $output .= $this->html_after( $meta ); $output .= ''; return $output; } /** * Get comments count for post * * @since 4.7.6.3 * @param array $meta * @return string */ protected function comments( array $meta ) { $count = get_comments_number( $this->post->ID ); $force_no_link = false; if ( 0 == $count && ! comments_open( $this->post->ID ) ) { $result = __( 'Comments Off', 'avia_framework' ); $force_no_link = true; } else if( post_password_required( $this->post->ID ) && ! is_admin() ) { $result = __( 'Enter your password to view comments', 'avia_framework' ); $force_no_link = true; } else if( post_password_required( $this->post->ID ) && is_admin() ) { $result = sprintf( __( 'Password protected - %s comment(s)', 'avia_framework' ), $count ); } else { if( $count == 0 ) { $result = __( 'No comments', 'avia_framework' ); } if( $count == 1 ) { $result = sprintf( __( '%s Comment', 'avia_framework' ), $count ); } else { $result = sprintf( __( '%s Comments', 'avia_framework' ), $count ); } } $result .= sprintf( __( ' on %s', 'avia_framework' ), esc_html( $this->post->post_title ) ); $output = ''; $output .= ''; $output .= $this->html_before( $meta ); if( 'default' == $meta['link_meta'] && ! $force_no_link ) { $output .= ''; $output .= '' . $result . ''; $output .= ''; } else if( $meta['url'] != '' && ! $force_no_link ) { $output .= ''; $output .= '' . $result . ''; $output .= ''; } else { $output .= ''; $output .= $result; $output .= ''; } $output .= $this->html_after( $meta ); $output .= ''; return $output; } /** * Get revisions count for post * * @since 4.7.6.3 * @param array $meta * @return string */ protected function revisions( array $meta ) { $revisions = wp_get_post_revisions( $this->post->ID ); $count = count( $revisions ); switch( $count ) { case 0: $result = __( 'No revisions', 'avia_framework' ); break; case 1: $result = sprintf( __( '%s revision', 'avia_framework' ), $count ); break; default: $result = sprintf( __( '%s revisions', 'avia_framework' ), $count ); break; } $result .= sprintf( __( ' on %s', 'avia_framework' ), esc_html( $this->post->post_title ) ); $output = ''; $output .= ''; $output .= $this->html_before( $meta ); if( $meta['url'] != '' ) { $output .= ''; $output .= '' . $result . ''; $output .= ''; } else { $output .= ''; $output .= $result; $output .= ''; } $output .= $this->html_after( $meta ); $output .= ''; return $output; } /** * Get published/modified date for post * * @since 4.7.6.3 * @param array $meta * @return string */ protected function date_time( array $meta ) { $what = explode( ' ', $meta['metadata'] ); $format = get_option( 'date_format' ); if( isset( $what[1] ) ) { $format .= ' ' . get_option( 'time_format' ); } $time = 'published' == $what[0] ? get_post_time( $format, false, $this->post->ID, true ) : get_post_modified_time( $format, false, $this->post->ID, true ); $output = ''; $output .= ''; $output .= $this->html_before( $meta ); if( $meta['url'] != '' ) { $output .= ''; $output .= '' . $time . ''; $output .= ''; } else { $output .= ''; $output .= $time; $output .= ''; } $output .= $this->html_after( $meta ); $output .= ''; return $output; } /** * Returns the "before" single meta string * * @since 4.7.6.3 * @param array $meta * @return string */ protected function html_before( array $meta ) { if( empty( $meta['before_meta'] ) ) { return ''; } return '' . esc_html( $meta['before_meta'] ) . ''; } /** * Returns the "after" single meta string * * @since 4.7.6.3 * @param array $meta * @return string */ protected function html_after( array $meta ) { if( empty( $meta['after_meta'] ) ) { return ''; } return '' . esc_html( $meta['after_meta'] ) . ''; } } }