[44] | 1 | <?php
|
---|
| 2 |
|
---|
| 3 | // This file is part of the Carrington Theme Framework for WordPress
|
---|
| 4 | // http://carringtontheme.com
|
---|
| 5 | //
|
---|
| 6 | // Copyright (c) 2008-2009 Crowd Favorite, Ltd. All rights reserved.
|
---|
| 7 | // http://crowdfavorite.com
|
---|
| 8 | //
|
---|
| 9 | // Released under the GPL license
|
---|
| 10 | // http://www.opensource.org/licenses/gpl-license.php
|
---|
| 11 | //
|
---|
| 12 | // **********************************************************************
|
---|
| 13 | // This program is distributed in the hope that it will be useful, but
|
---|
| 14 | // WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 15 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
---|
| 16 | // **********************************************************************
|
---|
| 17 | //
|
---|
| 18 | // Functions here without the cfct_ prefix are taken from WordPress 2.7 under the GPL
|
---|
| 19 |
|
---|
| 20 | if (!function_exists('is_sticky')) {
|
---|
| 21 | function is_sticky() {
|
---|
| 22 | return false;
|
---|
| 23 | }
|
---|
| 24 | }
|
---|
| 25 |
|
---|
| 26 | /**
|
---|
| 27 | * Displays classes for post div
|
---|
| 28 | *
|
---|
| 29 | * @param string|array $class One or more classes to add to the class list.
|
---|
| 30 | * @param int $post_id An optional post ID.
|
---|
| 31 | */
|
---|
| 32 |
|
---|
| 33 | if (!function_exists('post_class')) {
|
---|
| 34 | function post_class( $class = '', $post_id = null ) {
|
---|
| 35 | // Separates classes with a single space, collates classes for post DIV
|
---|
| 36 | echo 'class="' . join( ' ', get_post_class( $class, $post_id ) ) . '"';
|
---|
| 37 | }
|
---|
| 38 | }
|
---|
| 39 |
|
---|
| 40 | /**
|
---|
| 41 | * Retrieve the classes for the post div as an array.
|
---|
| 42 | *
|
---|
| 43 | * The class names are add are many. If the post is a sticky, then the 'sticky'
|
---|
| 44 | * class name. The class 'hentry' is always added to each post. For each
|
---|
| 45 | * category, the class will be added with 'category-' with category slug is
|
---|
| 46 | * added. The tags are the same way as the categories with 'tag-' before the tag
|
---|
| 47 | * slug. All classes are passed through the filter, 'post_class' with the list
|
---|
| 48 | * of classes, followed by $class parameter value, with the post ID as the last
|
---|
| 49 | * parameter.
|
---|
| 50 | *
|
---|
| 51 | * @param string|array $class One or more classes to add to the class list.
|
---|
| 52 | * @param int $post_id An optional post ID.
|
---|
| 53 | * @return array Array of classes.
|
---|
| 54 | */
|
---|
| 55 | if (!function_exists('get_post_class')) {
|
---|
| 56 | function get_post_class( $class = '', $post_id = null ) {
|
---|
| 57 | $post = get_post($post_id);
|
---|
| 58 |
|
---|
| 59 | $classes = array();
|
---|
| 60 |
|
---|
| 61 | $classes[] = $post->post_type;
|
---|
| 62 |
|
---|
| 63 | // sticky for Sticky Posts
|
---|
| 64 | if ( is_sticky($post->ID) && is_home())
|
---|
| 65 | $classes[] = 'sticky';
|
---|
| 66 |
|
---|
| 67 | // hentry for hAtom compliace
|
---|
| 68 | $classes[] = 'hentry';
|
---|
| 69 |
|
---|
| 70 | // Categories
|
---|
| 71 | foreach ( (array) get_the_category($post->ID) as $cat ) {
|
---|
| 72 | if ( empty($cat->slug ) )
|
---|
| 73 | continue;
|
---|
| 74 | $classes[] = 'category-' . $cat->slug;
|
---|
| 75 | }
|
---|
| 76 |
|
---|
| 77 | // Tags
|
---|
| 78 | foreach ( (array) get_the_tags($post->ID) as $tag ) {
|
---|
| 79 | if ( empty($tag->slug ) )
|
---|
| 80 | continue;
|
---|
| 81 | $classes[] = 'tag-' . $tag->slug;
|
---|
| 82 | }
|
---|
| 83 |
|
---|
| 84 | if ( !empty($class) ) {
|
---|
| 85 | if ( !is_array( $class ) )
|
---|
| 86 | $class = preg_split('#\s+#', $class);
|
---|
| 87 | $classes = array_merge($classes, $class);
|
---|
| 88 | }
|
---|
| 89 |
|
---|
| 90 | return apply_filters('post_class', $classes, $class, $post_id);
|
---|
| 91 | }
|
---|
| 92 | }
|
---|
| 93 |
|
---|
| 94 | /**
|
---|
| 95 | * Display "sticky" CSS class, if a post is sticky.
|
---|
| 96 | *
|
---|
| 97 | * @param int $post_id An optional post ID.
|
---|
| 98 | */
|
---|
| 99 | if (!function_exists('sticky_class')) {
|
---|
| 100 | function sticky_class( $post_id = null ) {
|
---|
| 101 | if ( !is_sticky($post_id) )
|
---|
| 102 | return;
|
---|
| 103 |
|
---|
| 104 | echo " sticky";
|
---|
| 105 | }
|
---|
| 106 | }
|
---|
| 107 |
|
---|
| 108 | /**
|
---|
| 109 | * Generates semantic classes for each comment element
|
---|
| 110 | *
|
---|
| 111 | * @param string|array $class One or more classes to add to the class list
|
---|
| 112 | * @param int $comment_id An optional comment ID
|
---|
| 113 | * @param int $post_id An optional post ID
|
---|
| 114 | * @param bool $echo Whether comment_class should echo or return
|
---|
| 115 | */
|
---|
| 116 | if (!function_exists('comment_class')) {
|
---|
| 117 | function comment_class( $class = '', $comment_id = null, $post_id = null, $echo = true ) {
|
---|
| 118 | // Separates classes with a single space, collates classes for comment DIV
|
---|
| 119 | $class = 'class="' . join( ' ', get_comment_class( $class, $comment_id, $post_id ) ) . '"';
|
---|
| 120 | if ( $echo)
|
---|
| 121 | echo $class;
|
---|
| 122 | else
|
---|
| 123 | return $class;
|
---|
| 124 | }
|
---|
| 125 | }
|
---|
| 126 |
|
---|
| 127 | /**
|
---|
| 128 | * Returns the classes for the comment div as an array
|
---|
| 129 | *
|
---|
| 130 | * @param string|array $class One or more classes to add to the class list
|
---|
| 131 | * @param int $comment_id An optional comment ID
|
---|
| 132 | * @param int $post_id An optional post ID
|
---|
| 133 | * @return array Array of classes
|
---|
| 134 | */
|
---|
| 135 | if (!function_exists('get_comment_class')) {
|
---|
| 136 | function get_comment_class( $class = '', $comment_id = null, $post_id = null ) {
|
---|
| 137 | global $comment_alt, $comment_depth, $comment_thread_alt;
|
---|
| 138 |
|
---|
| 139 | $comment = get_comment($comment_id);
|
---|
| 140 |
|
---|
| 141 | $classes = array();
|
---|
| 142 |
|
---|
| 143 | // Get the comment type (comment, trackback),
|
---|
| 144 | $classes[] = ( empty( $comment->comment_type ) ) ? 'comment' : $comment->comment_type;
|
---|
| 145 |
|
---|
| 146 | // If the comment author has an id (registered), then print the log in name
|
---|
| 147 | if ( $comment->user_id > 0 && $user = get_userdata($comment->user_id) ) {
|
---|
| 148 | // For all registered users, 'byuser'
|
---|
| 149 | $classes[] = 'byuser comment-author-' . $user->user_nicename;
|
---|
| 150 | // For comment authors who are the author of the post
|
---|
| 151 | if ( $post = get_post($post_id) ) {
|
---|
| 152 | if ( $comment->user_id === $post->post_author )
|
---|
| 153 | $classes[] = 'bypostauthor';
|
---|
| 154 | }
|
---|
| 155 | }
|
---|
| 156 |
|
---|
| 157 | if ( empty($comment_alt) )
|
---|
| 158 | $comment_alt = 0;
|
---|
| 159 | if ( empty($comment_depth) )
|
---|
| 160 | $comment_depth = 1;
|
---|
| 161 | if ( empty($comment_thread_alt) )
|
---|
| 162 | $comment_thread_alt = 0;
|
---|
| 163 |
|
---|
| 164 | if ( $comment_alt % 2 ) {
|
---|
| 165 | $classes[] = 'odd';
|
---|
| 166 | $classes[] = 'alt';
|
---|
| 167 | } else {
|
---|
| 168 | $classes[] = 'even';
|
---|
| 169 | }
|
---|
| 170 |
|
---|
| 171 | $comment_alt++;
|
---|
| 172 |
|
---|
| 173 | // Alt for top-level comments
|
---|
| 174 | if ( 1 == $comment_depth ) {
|
---|
| 175 | if ( $comment_thread_alt % 2 ) {
|
---|
| 176 | $classes[] = 'thread-odd';
|
---|
| 177 | $classes[] = 'thread-alt';
|
---|
| 178 | } else {
|
---|
| 179 | $classes[] = 'thread-even';
|
---|
| 180 | }
|
---|
| 181 | $comment_thread_alt++;
|
---|
| 182 | }
|
---|
| 183 |
|
---|
| 184 | $classes[] = "depth-$comment_depth";
|
---|
| 185 |
|
---|
| 186 | if ( !empty($class) ) {
|
---|
| 187 | if ( !is_array( $class ) )
|
---|
| 188 | $class = preg_split('#\s+#', $class);
|
---|
| 189 | $classes = array_merge($classes, $class);
|
---|
| 190 | }
|
---|
| 191 |
|
---|
| 192 | return apply_filters('comment_class', $classes, $class, $comment_id, $post_id);
|
---|
| 193 | }
|
---|
| 194 | }
|
---|
| 195 |
|
---|
| 196 | /**
|
---|
| 197 | * Outputs hidden fields for comment form with unique IDs, based on post ID, making it safe for AJAX pull.
|
---|
| 198 | */
|
---|
| 199 | function cfct_comment_id_fields() {
|
---|
| 200 | global $id;
|
---|
| 201 |
|
---|
| 202 | $replytoid = isset($_GET['replytocom']) ? (int) $_GET['replytocom'] : 0;
|
---|
| 203 | echo "<input type='hidden' name='comment_post_ID' value='$id' id='comment_post_ID_p$id' />\n";
|
---|
| 204 | echo "<input type='hidden' name='comment_parent' id='comment_parent_p$id' value='$replytoid' />\n";
|
---|
| 205 | }
|
---|
| 206 |
|
---|
| 207 | /**
|
---|
| 208 | * Filter the comment reply link to add a unique unique ID, based on post ID, making it safe for AJAX pull.
|
---|
| 209 | */
|
---|
| 210 | function cfct_get_cancel_comment_reply_link($reply_link, $link, $text) {
|
---|
| 211 | global $post;
|
---|
| 212 |
|
---|
| 213 | if ( !empty($text) ) { $text = __('Cancel', 'carrington'); }
|
---|
| 214 |
|
---|
| 215 | $style = '';
|
---|
| 216 | if (!isset($_GET['replytocom'])) {
|
---|
| 217 | $style = ' style="display:none;"';
|
---|
| 218 | }
|
---|
| 219 |
|
---|
| 220 | $reply_link = '<a rel="nofollow" id="cancel-comment-reply-link-p' . $post->ID . '" href="' . $link . '-p' . $post->ID . '"' . $style . '>' . $text . '</a>';
|
---|
| 221 | return $reply_link;
|
---|
| 222 | }
|
---|
| 223 |
|
---|
| 224 | // For meeting wordpress.org requirements
|
---|
| 225 | /*
|
---|
| 226 | get_avatar();
|
---|
| 227 | the_tags();
|
---|
| 228 | register_sidebar('none');
|
---|
| 229 | bloginfo('description');
|
---|
| 230 | wp_head();
|
---|
| 231 | wp_footer();
|
---|
| 232 | */
|
---|
| 233 |
|
---|
| 234 | ?> |
---|