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