Rev 25 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
3 | iacchi | 1 | <?php |
2 | // Add localisation support |
||
27 | iacchi | 3 | load_theme_textdomain( 'zendark', TEMPLATEPATH . '/languages' ); |
3 | iacchi | 4 | $locale = get_locale(); |
5 | $locale_file = TEMPLATEPATH ."/languages/$locale.php"; |
||
6 | if (is_readable($locale_file)) require_once($locale_file); |
||
7 | |||
8 | // Register theme options page |
||
9 | require_once(get_template_directory().'/theme-options.php'); |
||
10 | |||
11 | // Add default posts and comments RSS feed links to <head>. |
||
12 | add_theme_support('automatic-feed-links'); |
||
13 | |||
25 | iacchi | 14 | // Set the content width based on the theme's design and stylesheet. |
15 | if (!isset($content_width)) $content_width = 700; |
||
16 | |||
3 | iacchi | 17 | // This theme uses wp_nav_menu() in one location. |
27 | iacchi | 18 | function zendark_register_nav_menu() { |
19 | register_nav_menu('primary', __('Primary Menu', 'zendark')); |
||
3 | iacchi | 20 | } |
27 | iacchi | 21 | add_action('init', 'zendark_register_nav_menu'); |
3 | iacchi | 22 | |
23 | // Sets the post excerpt length to 40 words. |
||
27 | iacchi | 24 | function zendark_excerpt_length($length) { |
3 | iacchi | 25 | return 40; |
26 | } |
||
27 | iacchi | 27 | add_filter('excerpt_length', 'zendark_excerpt_length'); |
3 | iacchi | 28 | |
29 | // Returns a "Continue Reading" link for excerpts |
||
27 | iacchi | 30 | function zendark_continue_reading_link() { |
31 | return '<a href="'.esc_url(get_permalink()).'">'.__('Continue reading ⇾', 'zendark').'</a>'; |
||
3 | iacchi | 32 | } |
33 | |||
27 | iacchi | 34 | // Replaces "[...]" (appended to automatically generated excerpts) with an ellipsis and zendark_continue_reading_link(). |
35 | function zendark_auto_excerpt_more($more) { |
||
36 | return '…<br />'.zendark_continue_reading_link(); |
||
3 | iacchi | 37 | } |
27 | iacchi | 38 | add_filter('excerpt_more', 'zendark_auto_excerpt_more'); |
3 | iacchi | 39 | |
40 | // Display navigation to next/previous pages when applicable |
||
27 | iacchi | 41 | function zendark_content_nav( $nav_id ) { |
3 | iacchi | 42 | global $wp_query; |
43 | |||
44 | if ( $wp_query->max_num_pages > 1 ) : ?> |
||
45 | <nav id="<?php echo $nav_id; ?>"> |
||
27 | iacchi | 46 | <div class="nav-next"><?php previous_posts_link( __('⇽ Newer posts', 'zendark')); ?></div> |
47 | <div class="nav-previous"><?php next_posts_link( __('Older posts ⇾', 'zendark')); ?></div> |
||
3 | iacchi | 48 | </nav><!-- #<?php echo $nav_id; ?> --> |
49 | <?php endif; |
||
50 | } |
||
51 | |||
52 | // Count authors number (users with writing rights) |
||
27 | iacchi | 53 | function zendark_count_authors(){ |
3 | iacchi | 54 | $number = 0; |
55 | $result = count_users(); |
||
56 | foreach($result['avail_roles'] as $role => $count) |
||
57 | if($role != "subscriber") { $number = $number + $count; } |
||
58 | return $number; |
||
59 | } |
||
60 | |||
61 | // Register sidebars |
||
27 | iacchi | 62 | function zendark_widgets_init() { |
3 | iacchi | 63 | |
64 | register_sidebar( array( |
||
27 | iacchi | 65 | 'name' => __( 'Main Sidebar', 'zendark' ), |
3 | iacchi | 66 | 'id' => 'sidebar-1', |
67 | 'before_widget' => '<aside id="%1$s" class="widget %2$s">', |
||
68 | 'after_widget' => "</aside>", |
||
69 | 'before_title' => '<h3 class="widget-title">', |
||
70 | 'after_title' => '</h3>', |
||
71 | ) ); |
||
72 | } |
||
27 | iacchi | 73 | add_action('widgets_init', 'zendark_widgets_init'); |
3 | iacchi | 74 | |
75 | /* |
||
76 | * Adds two classes to the array of body classes. |
||
77 | * The first is if the site has only had one author with published posts. |
||
78 | * The second is if a singular post being displayed |
||
79 | */ |
||
27 | iacchi | 80 | function zendark_body_classes($classes) { |
3 | iacchi | 81 | if (!is_multi_author()) { $classes[] = 'single-author'; } |
82 | if (is_singular() && !is_home()) $classes[] = 'singular'; |
||
83 | return $classes; |
||
84 | } |
||
27 | iacchi | 85 | add_filter('body_class', 'zendark_body_classes'); |
3 | iacchi | 86 | |
87 | // Get the first parent of a page |
||
27 | iacchi | 88 | function zendark_get_root_parent($page_id) { |
3 | iacchi | 89 | global $wpdb; |
90 | $parent = $wpdb->get_var("SELECT post_parent FROM $wpdb->posts WHERE post_type='page' AND ID = '$page_id'"); |
||
91 | if ($parent == 0) return $page_id; |
||
27 | iacchi | 92 | else return zendark_get_root_parent($parent); |
3 | iacchi | 93 | } |
94 | |||
95 | |||
96 | // Add class to menu <li> for first parent page |
||
27 | iacchi | 97 | add_filter('nav_menu_css_class', 'zendark_special_nav_class', 10, 2); |
98 | function zendark_special_nav_class($classes, $item){ |
||
99 | if($item->object_id == zendark_get_root_parent(get_the_ID())){ |
||
3 | iacchi | 100 | $classes[] = "current_page_parent_function"; |
101 | } |
||
102 | return $classes; |
||
103 | } |
||
104 | |||
105 | // This check if a gravatar exists for a user, and if not return false |
||
106 | function validate_gravatar($email) { |
||
24 | iacchi | 107 | /* first of all, we want to do the check only if it's needed, so |
108 | * we check that gravatars are actually enabled in settings, and |
||
109 | * that you want to display a blank avatar (no avatar) as default. |
||
110 | */ |
||
111 | if (get_option('show_avatars') && get_option('avatar_default') == 'blank') { |
||
112 | // Craft a potential url and test its headers |
||
113 | $hash = md5($email); |
||
114 | $uri = 'http://www.gravatar.com/avatar/'.$hash.'?d=404'; |
||
115 | $headers = @get_headers($uri); |
||
116 | if (!preg_match("|200|", $headers[0])) $has_valid_avatar = false; |
||
117 | else $has_valid_avatar = true; |
||
118 | } |
||
119 | elseif (!get_option('show_avatars')) $has_valid_avatar = false; |
||
120 | else $has_valid_avatar = true; |
||
3 | iacchi | 121 | return $has_valid_avatar; |
122 | } |
||
123 | |||
124 | /* Function to generate comments, I believe it's |
||
125 | * necessary if you want paged comments. |
||
126 | */ |
||
27 | iacchi | 127 | function zendark_comment($comment, $args, $depth) { |
3 | iacchi | 128 | $GLOBALS['comment'] = $comment; |
129 | |||
130 | if ($comment->comment_type != "trackback" && $comment->comment_type != "pingback") : ?> |
||
131 | <div id="comment-<?php comment_ID() ?>" <?php comment_class(); ?>> |
||
132 | <header class="comment-header"> |
||
133 | <?php |
||
134 | if (validate_gravatar(get_comment_author_email())) |
||
135 | echo '<div class="comment-avatar">'.get_avatar($comment, 40).'</div>'; |
||
136 | ?> |
||
137 | <div> |
||
138 | <div class="comment-meta"> |
||
27 | iacchi | 139 | <span class="comment-author"><?php comment_author_link() ?></span> <?php edit_comment_link( __( 'Edit', 'zendark' ), ' • ', '' ); ?><br /> |
3 | iacchi | 140 | <?php printf('<span class="comment-datetime"><a href="%1$s"><time pubdate datetime="%2$s">%3$s</time></a></span>', |
141 | esc_url(get_comment_link($comment->comment_ID)), |
||
142 | get_comment_time('c'), |
||
143 | /* translators: 1: date, 2: time */ |
||
27 | iacchi | 144 | sprintf(__('%1$s %2$s', 'zendark'), get_comment_date(), get_comment_time()) |
3 | iacchi | 145 | ); ?> |
146 | </div> |
||
27 | iacchi | 147 | <?php comment_reply_link(array_merge($args, array('reply_text' => __( 'reply', 'zendark'), 'login_text' => __( 'login to reply', 'zendark'), 'depth' => $depth, 'max_depth' => $args['max_depth']))); ?> |
3 | iacchi | 148 | </div> |
149 | </header> |
||
150 | <div class="comment-content"> |
||
151 | <?php if ($comment->comment_approved == '0') : ?> |
||
27 | iacchi | 152 | <div class="comment-awaiting-moderation"><?php _e('Your comment is awaiting moderation', 'zendark'); ?></div> |
3 | iacchi | 153 | <?php endif; ?> |
154 | <?php comment_text(); ?> |
||
155 | </div> |
||
156 | </div> |
||
157 | <?php |
||
158 | endif; |
||
159 | } |
||
160 | |||
161 | // Function to generate trackback/pingback |
||
27 | iacchi | 162 | function zendark_trackback($comment, $args, $depth) { |
3 | iacchi | 163 | $GLOBALS['comment'] = $comment; |
164 | |||
165 | if ($comment->comment_type == "trackback" || $comment->comment_type == "pingback") : ?> |
||
166 | <div id="comment-<?php comment_ID() ?>" <?php comment_class(); ?>> |
||
167 | <span class="comment-author"><?php comment_author_link() ?></span><br /> |
||
168 | <?php comment_excerpt(); ?> |
||
169 | </div> |
||
170 | <?php |
||
171 | endif; |
||
172 | } |
||
173 | |||
174 | // Function to count trackback/pingback |
||
27 | iacchi | 175 | function zendark_trackback_number($comments) { |
3 | iacchi | 176 | $numero_trackback = 0; |
177 | foreach ($comments as $comment) : |
||
178 | if ($comment->comment_type == "trackback" || $comment->comment_type == "pingback") $numero_trackback++; |
||
179 | endforeach; |
||
180 | return $numero_trackback; |
||
181 | } |
||
182 | |||
183 | /* Function to generate both comments and trackbacks/pingbacks together, |
||
184 | * in case of paged comments. If you find a way to nicely separate comments |
||
185 | * and pingbacks/trackbacks in paged comments, please tell me. |
||
186 | */ |
||
27 | iacchi | 187 | function zendark_all_comment($comment, $args, $depth) { |
3 | iacchi | 188 | $GLOBALS['comment'] = $comment; |
189 | |||
190 | if ($comment->comment_type != "trackback" && $comment->comment_type != "pingback") : ?> |
||
191 | <div id="comment-<?php comment_ID() ?>" <?php comment_class(); ?>> |
||
192 | <header class="comment-header"> |
||
193 | <?php |
||
194 | if (validate_gravatar(get_comment_author_email())) |
||
195 | echo '<div class="comment-avatar">'.get_avatar($comment, 40).'</div>'; |
||
196 | ?> |
||
197 | <div> |
||
198 | <div class="comment-meta"> |
||
27 | iacchi | 199 | <span class="comment-author"><?php comment_author_link() ?></span> <?php edit_comment_link( __( 'Edit', 'zendark' ), ' • ', '' ); ?><br /> |
3 | iacchi | 200 | <?php printf('<span class="comment-datetime"><a href="%1$s"><time pubdate datetime="%2$s">%3$s</time></a></span>', |
201 | esc_url(get_comment_link($comment->comment_ID)), |
||
202 | get_comment_time('c'), |
||
203 | /* translators: 1: date, 2: time */ |
||
27 | iacchi | 204 | sprintf(__('%1$s %2$s', 'zendark'), get_comment_date(), get_comment_time()) |
3 | iacchi | 205 | ); ?> |
206 | </div> |
||
27 | iacchi | 207 | <?php comment_reply_link(array_merge($args, array('reply_text' => __( 'reply', 'zendark'), 'login_text' => __( 'login to reply', 'zendark'), 'depth' => $depth, 'max_depth' => $args['max_depth']))); ?> |
3 | iacchi | 208 | </div> |
209 | </header> |
||
210 | <div class="comment-content"> |
||
211 | <?php if ($comment->comment_approved == '0') : ?> |
||
27 | iacchi | 212 | <div class="comment-awaiting-moderation"><?php _e('Your comment is awaiting moderation', 'zendark'); ?></div> |
3 | iacchi | 213 | <?php endif; ?> |
214 | <?php comment_text(); ?> |
||
215 | </div> |
||
216 | </div> |
||
217 | <?php |
||
218 | endif; |
||
219 | if ($comment->comment_type == "trackback" || $comment->comment_type == "pingback") : ?> |
||
220 | <div id="comment-<?php comment_ID() ?>" <?php comment_class(); ?>> |
||
221 | <span class="comment-author"><?php comment_author_link() ?></span><br /> |
||
222 | <?php comment_excerpt(); ?> |
||
223 | </div> |
||
224 | <?php |
||
225 | endif; |
||
226 | } |
||
227 | ?> |