Rev 24 | 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 | |||
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. |
18 | function sdt_register_nav_menu() { |
||
19 | register_nav_menu('primary', __('Primary Menu', 'sdt')); |
||
20 | } |
||
21 | add_action('init', 'sdt_register_nav_menu'); |
||
22 | |||
23 | // Sets the post excerpt length to 40 words. |
||
24 | function sdt_excerpt_length($length) { |
||
25 | return 40; |
||
26 | } |
||
27 | add_filter('excerpt_length', 'sdt_excerpt_length'); |
||
28 | |||
29 | // Returns a "Continue Reading" link for excerpts |
||
30 | function sdt_continue_reading_link() { |
||
31 | return '<a href="'.esc_url(get_permalink()).'">'.__('Continue reading ⇾', 'sdt').'</a>'; |
||
32 | } |
||
33 | |||
34 | // Replaces "[...]" (appended to automatically generated excerpts) with an ellipsis and sdt_continue_reading_link(). |
||
35 | function sdt_auto_excerpt_more($more) { |
||
36 | return '…<br />'.sdt_continue_reading_link(); |
||
37 | } |
||
38 | add_filter('excerpt_more', 'sdt_auto_excerpt_more'); |
||
39 | |||
40 | // Display navigation to next/previous pages when applicable |
||
41 | function sdt_content_nav( $nav_id ) { |
||
42 | global $wp_query; |
||
43 | |||
44 | if ( $wp_query->max_num_pages > 1 ) : ?> |
||
45 | <nav id="<?php echo $nav_id; ?>"> |
||
46 | <div class="nav-next"><?php previous_posts_link( __('⇽ Newer posts', 'sdt')); ?></div> |
||
47 | <div class="nav-previous"><?php next_posts_link( __('Older posts ⇾', 'sdt')); ?></div> |
||
48 | </nav><!-- #<?php echo $nav_id; ?> --> |
||
49 | <?php endif; |
||
50 | } |
||
51 | |||
52 | // Count authors number (users with writing rights) |
||
53 | function sdt_count_authors(){ |
||
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 |
||
62 | function sdt_widgets_init() { |
||
63 | |||
64 | register_sidebar( array( |
||
65 | 'name' => __( 'Main Sidebar', 'sdt' ), |
||
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 | } |
||
73 | add_action('widgets_init', 'sdt_widgets_init'); |
||
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 | */ |
||
80 | function sdt_body_classes($classes) { |
||
81 | if (!is_multi_author()) { $classes[] = 'single-author'; } |
||
82 | if (is_singular() && !is_home()) $classes[] = 'singular'; |
||
83 | return $classes; |
||
84 | } |
||
85 | add_filter('body_class', 'sdt_body_classes'); |
||
86 | |||
87 | // Get the first parent of a page |
||
88 | function sdt_get_root_parent($page_id) { |
||
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; |
||
92 | else return sdt_get_root_parent($parent); |
||
93 | } |
||
94 | |||
95 | |||
96 | // Add class to menu <li> for first parent page |
||
97 | add_filter('nav_menu_css_class', 'sdt_special_nav_class', 10, 2); |
||
98 | function sdt_special_nav_class($classes, $item){ |
||
99 | if($item->object_id == sdt_get_root_parent(get_the_ID())){ |
||
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 | */ |
||
127 | function sdt_comment($comment, $args, $depth) { |
||
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"> |
||
139 | <span class="comment-author"><?php comment_author_link() ?></span> <?php edit_comment_link( __( 'Edit', 'sdt' ), ' • ', '' ); ?><br /> |
||
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 */ |
||
144 | sprintf(__('%1$s %2$s', 'sdt'), get_comment_date(), get_comment_time()) |
||
145 | ); ?> |
||
146 | </div> |
||
147 | <?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']))); ?> |
||
148 | </div> |
||
149 | </header> |
||
150 | <div class="comment-content"> |
||
151 | <?php if ($comment->comment_approved == '0') : ?> |
||
152 | <div class="comment-awaiting-moderation"><?php _e('Your comment is awaiting moderation', 'sdt'); ?></div> |
||
153 | <?php endif; ?> |
||
154 | <?php comment_text(); ?> |
||
155 | </div> |
||
156 | </div> |
||
157 | <?php |
||
158 | endif; |
||
159 | } |
||
160 | |||
161 | // Function to generate trackback/pingback |
||
162 | function sdt_trackback($comment, $args, $depth) { |
||
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 |
||
175 | function sdt_trackback_number($comments) { |
||
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 | */ |
||
187 | function sdt_all_comment($comment, $args, $depth) { |
||
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"> |
||
199 | <span class="comment-author"><?php comment_author_link() ?></span> <?php edit_comment_link( __( 'Edit', 'sdt' ), ' • ', '' ); ?><br /> |
||
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 */ |
||
204 | sprintf(__('%1$s %2$s', 'sdt'), get_comment_date(), get_comment_time()) |
||
205 | ); ?> |
||
206 | </div> |
||
207 | <?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']))); ?> |
||
208 | </div> |
||
209 | </header> |
||
210 | <div class="comment-content"> |
||
211 | <?php if ($comment->comment_approved == '0') : ?> |
||
212 | <div class="comment-awaiting-moderation"><?php _e('Your comment is awaiting moderation', 'sdt'); ?></div> |
||
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 | ?> |