diff options
Diffstat (limited to 'themes/mantra/includes/theme-loop.php')
-rw-r--r-- | themes/mantra/includes/theme-loop.php | 169 |
1 files changed, 76 insertions, 93 deletions
diff --git a/themes/mantra/includes/theme-loop.php b/themes/mantra/includes/theme-loop.php index 479d172f..d2a6b8e9 100644 --- a/themes/mantra/includes/theme-loop.php +++ b/themes/mantra/includes/theme-loop.php @@ -17,7 +17,7 @@ */ function mantra_excerpt_length( $length ) { global $mantra_excerptwords; - return $mantra_excerptwords; + return absint( $mantra_excerptwords ); } add_filter( 'excerpt_length', 'mantra_excerpt_length' ); @@ -29,7 +29,7 @@ add_filter( 'excerpt_length', 'mantra_excerpt_length' ); */ function mantra_continue_reading_link() { global $mantra_excerptcont; - return ' <a class="continue-reading-link" href="'. get_permalink() . '">' .$mantra_excerptcont.' <span class="meta-nav">→ </span>' . '</a>'; + return ' <a class="continue-reading-link" href="' . esc_url( get_permalink() ) . '">' . wp_kses_post( $mantra_excerptcont ).' <span class="meta-nav">→ </span>' . '</a>'; } /** @@ -43,7 +43,7 @@ function mantra_continue_reading_link() { */ function mantra_auto_excerpt_more( $more ) { global $mantra_excerptdots; - return $mantra_excerptdots. mantra_continue_reading_link(); + return wp_kses_post( $mantra_excerptdots ). mantra_continue_reading_link(); } add_filter( 'excerpt_more', 'mantra_auto_excerpt_more' ); @@ -77,7 +77,7 @@ add_filter( 'get_the_excerpt', 'mantra_custom_excerpt_more' ); */ function mantra_more_link($more_link, $more_link_text) { global $mantra_excerptcont; - $new_link_text = $mantra_excerptcont; + $new_link_text = wp_kses_post( $mantra_excerptcont ); if (preg_match("/custom=(.*)/",$more_link_text,$m) ) { $new_link_text = $m[1]; }; @@ -94,44 +94,40 @@ add_filter('the_content_more_link', 'mantra_more_link',10,2); */ function mantra_trim_excerpt($text) { -global $mantra_excerptwords; -global $mantra_excerptcont; -global $mantra_excerptdots; -$raw_excerpt = $text; -if ( '' == $text ) { - //Retrieve the post content. - $text = get_the_content(''); - - //Delete all shortcode tags from the content. - $text = strip_shortcodes( $text ); - - $text = apply_filters('the_content', $text); - $text = str_replace(']]>', ']]>', $text); - - $allowed_tags = '<a>,<img>,<b>,<strong>,<ul>,<li>,<i>,<h1>,<h2>,<h3>,<h4>,<h5>,<h6>,<pre>,<code>,<em>,<u>,<br>,<p>'; - $text = strip_tags($text, $allowed_tags); - - $words = preg_split("/[\n\r\t ]+/", $text, $mantra_excerptwords + 1, PREG_SPLIT_NO_EMPTY); - if ( count($words) > $mantra_excerptwords ) { - array_pop($words); - $text = implode(' ', $words); - $text = $text .' '.$mantra_excerptdots. ' <a href="'. get_permalink() . '">' .$mantra_excerptcont.' <span class="meta-nav">→ </span>' . '</a>'; - } else { - $text = implode(' ', $words); - } -} -return apply_filters('wp_trim_excerpt', $text, $raw_excerpt); + global $mantra_excerptwords; + global $mantra_excerptcont; + global $mantra_excerptdots; + $raw_excerpt = $text; + if ( '' == $text ) { + //Retrieve the post content. + $text = get_the_content(''); + + //Delete all shortcode tags from the content. + $text = strip_shortcodes( $text ); + + $text = apply_filters('the_content', $text); + $text = str_replace(']]>', ']]>', $text); + + $allowed_tags = '<a>,<img>,<b>,<strong>,<ul>,<li>,<i>,<h1>,<h2>,<h3>,<h4>,<h5>,<h6>,<pre>,<code>,<em>,<u>,<br>,<p>'; + $text = strip_tags($text, $allowed_tags); + + $words = preg_split("/[\n\r\t ]+/", $text, $mantra_excerptwords + 1, PREG_SPLIT_NO_EMPTY); + if ( count($words) > $mantra_excerptwords ) { + array_pop($words); + $text = implode(' ', $words); + $text = $text .' '.$mantra_excerptdots. ' <a href="' . esc_url( get_permalink() ) . '">' .$mantra_excerptcont.' <span class="meta-nav">→ </span>' . '</a>'; + } else { + $text = implode(' ', $words); + } + } + return apply_filters('wp_trim_excerpt', $text, $raw_excerpt); } - - - if ($mantra_excerpttags=='Enable') { -remove_filter('get_the_excerpt', 'wp_trim_excerpt'); -add_filter('get_the_excerpt', 'mantra_trim_excerpt'); + remove_filter('get_the_excerpt', 'wp_trim_excerpt'); + add_filter('get_the_excerpt', 'mantra_trim_excerpt'); } - /** * Remove inline styles printed when the gallery shortcode is used. * @@ -153,28 +149,24 @@ if ( ! function_exists( 'mantra_posted_on' ) ) : * @since mantra 0.5 */ function mantra_posted_on() { -global $mantra_options; -foreach ($mantra_options as $key => $value) { - ${"$key"} = $value ; -} - -$date_string = '<time class="onDate date published" datetime="' . get_the_time( 'c' ) . '"> %3$s </time><span class="bl_sep">|</span>'; -$date_string .= '<time class="updated" datetime="' . get_the_modified_date( 'c' ) . '">' . get_the_modified_date() . '</time>'; + $date_string = '<time class="onDate date published" datetime="' . get_the_time( 'c' ) . '"> %3$s </time><span class="bl_sep">|</span>'; + $date_string .= '<time class="updated" datetime="' . get_the_modified_date( 'c' ) . '">' . get_the_modified_date() . '</time>'; -// If author is hidden don't give it a value -$author_string = sprintf( '<span class="author vcard" >'.__( 'By ','mantra'). ' <a class="url fn n" rel="author" href="%1$s" title="%2$s">%3$s</a> <span class="bl_sep">|</span></span>', - get_author_posts_url( get_the_author_meta( 'ID' ) ), - sprintf( esc_attr__( 'View all posts by %s', 'mantra' ), get_the_author() ), - get_the_author() - ); + // If author is hidden don't give it a value + $author_string = sprintf( '<span class="author vcard" > %4$s <a class="url fn n" rel="author" href="%1$s" title="%2$s">%3$s</a> <span class="bl_sep">|</span></span>', + esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ), + sprintf( esc_attr__( 'View all posts by %s', 'mantra' ), get_the_author() ), + get_the_author(), + __('By ', 'mantra') + ); -// Print the meta data - printf( ' %4$s '.$date_string.' <span class="bl_categ"> %2$s </span> ', + // Print the meta data + printf( ' %4$s '.$date_string.' <span class="bl_categ"> %2$s </span> ', 'meta-prep meta-prep-author', get_the_category_list( ', ' ), sprintf( '<a href="%1$s" title="%2$s" rel="bookmark"><span class="entry-date">%3$s</span> <span class="entry-time"> - %2$s</span></a>', - get_permalink(), + esc_url( get_permalink() ), esc_attr( get_the_time() ), get_the_date() ), $author_string @@ -183,13 +175,13 @@ $author_string = sprintf( '<span class="author vcard" >'.__( 'By ','mantra'). ' } endif; -// Remove category from rel in categry tags. -add_filter( 'the_category', 'mantra_remove_category_tag' ); -add_filter( 'get_the_category_list', 'mantra_remove_category_tag' ); +// Remove category from rel in category tags. function mantra_remove_category_tag( $text ) { -$text = str_replace('rel="category tag"', 'rel="tag"', $text); return $text; + return str_replace('rel="category tag"', 'rel="tag"', $text); } +add_filter( 'the_category', 'mantra_remove_category_tag' ); +add_filter( 'get_the_category_list', 'mantra_remove_category_tag' ); if ( ! function_exists( 'mantra_posted_in' ) ) : @@ -213,7 +205,7 @@ function mantra_posted_in() { $posted_in, get_the_category_list( ', ' ), $tag_list, - get_permalink(), + esc_url( get_permalink() ), the_title_attribute( 'echo=0' ) ); } @@ -235,32 +227,26 @@ function mantra_content_nav( $nav_id ) { } endif; // mantra_content_nav -// Custom image size for use with post thumbnails -if($mantra_fcrop) -add_image_size( 'custom', $mantra_fwidth, $mantra_fheight, true ); -else -add_image_size( 'custom', $mantra_fwidth, $mantra_fheight ); - - -function cryout_echo_first_image ($postID) -{ +/** + * Returns src of image first attached to the post + */ +function cryout_echo_first_image( $postID ) { $args = array( - 'numberposts' => 1, - 'order'=> 'ASC', - 'post_mime_type' => 'image', - 'post_parent' => $postID, - 'post_status' => 'any', - 'post_type' => 'any' + 'numberposts' => 1, + 'order'=> 'ASC', + 'post_mime_type' => 'image', + 'post_parent' => $postID, + 'post_status' => 'any', + 'post_type' => 'any', ); $attachments = get_children( $args ); - //print_r($attachments); if ($attachments) { foreach($attachments as $attachment) { $image_attributes = wp_get_attachment_image_src( $attachment->ID, 'custom' ) ? wp_get_attachment_image_src( $attachment->ID, 'custom' ) : wp_get_attachment_image_src( $attachment->ID, 'custom' ); - return $image_attributes[0]; + return esc_url( $image_attributes[0] ); } } @@ -273,29 +259,26 @@ if ( ! function_exists( 'mantra_set_featured_thumb' ) ) : function mantra_set_featured_thumb() { global $mantra_options; - foreach ($mantra_options as $key => $value) { - ${"$key"} = $value ; + extract($mantra_options); + global $post; + $image_src = cryout_echo_first_image($post->ID); + + if ( function_exists("has_post_thumbnail") && has_post_thumbnail() && $mantra_fpost=='Enable') { + the_post_thumbnail( 'custom', array( "class" => "align" . strtolower($mantra_falign) . " post-thumbnail" ) ); + } elseif ($mantra_fpost=='Enable' && $mantra_fauto=="Enable" && $image_src && ($mantra_excerptarchive != "Full Post" || $mantra_excerpthome != "Full Post")) { ?> + <a class="post-thumbnail-link" title="<?php echo the_title_attribute('echo=0') ?>" href="<?php echo esc_url( get_permalink() ) ?>" > + <img width="<?php echo $mantra_fwidth ?>" title="" alt="<?php echo the_title_attribute('echo=0') ?>" class="align<?php echo strtolower($mantra_falign) ?> post_thumbnail" src="<?php echo $image_src ?>"> + </a> + <?php } } -global $post; -$image_src = cryout_echo_first_image($post->ID); - - if ( function_exists("has_post_thumbnail") && has_post_thumbnail() && $mantra_fpost=='Enable') - the_post_thumbnail( 'custom', array("class" => "align".strtolower($mantra_falign)." post_thumbnail" ) ); - - else if ($mantra_fpost=='Enable' && $mantra_fauto=="Enable" && $image_src && ($mantra_excerptarchive != "Full Post" || $mantra_excerpthome != "Full Post")) - echo '<a title="'.the_title_attribute('echo=0').'" href="'.get_permalink().'" ><img width="'.$mantra_fwidth.'" title="" alt="" class="align'.strtolower($mantra_falign).' post_thumbnail" src="'.$image_src.'"></a>' ; - - } endif; // mantra_set_featured_thumb -if ($mantra_fpost=='Enable' && $mantra_fpostlink) add_filter( 'post_thumbnail_html', 'mantra_thumbnail_link', 10, 2 ); - /** * The thumbnail gets a link to the post's page */ - function mantra_thumbnail_link( $html, $post_id ) { - $html = '<a href="' . get_permalink( $post_id ) . '" title="' . esc_attr( get_post_field( 'post_title', $post_id ) ) . '">' . $html . '</a>'; - return $html; + return '<a class="post-thumbnail-link" href="' . esc_url( get_permalink( $post_id ) ) . '" title="' . esc_attr( get_post_field( 'post_title', $post_id ) ) . '">' . $html . '</a>'; } -?> +if ($mantra_fpost=='Enable' && $mantra_fpostlink) add_filter( 'post_thumbnail_html', 'mantra_thumbnail_link', 10, 2 ); + +// FIN
\ No newline at end of file |