Subversion Repositories ZenDark

Rev

Rev 24 | Go to most recent revision | Details | 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 '&hellip;<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) {
104
        // Craft a potential url and test its headers
105
        $hash = md5($email);
106
        $uri = 'http://www.gravatar.com/avatar/'.$hash.'?d=404';
107
        $headers = @get_headers($uri);
108
        if (!preg_match("|200|", $headers[0])) {
109
                $has_valid_avatar = false;
110
        }
111
  else {
112
                $has_valid_avatar = true;
113
        }
114
        return $has_valid_avatar;
115
}
116
 
117
/* Function to generate comments, I believe it's
118
 * necessary if you want paged comments.
119
 */
120
 function sdt_comment($comment, $args, $depth) {
121
        $GLOBALS['comment'] = $comment;
122
 
123
  if ($comment->comment_type != "trackback" && $comment->comment_type != "pingback") : ?>
124
  <div id="comment-<?php comment_ID() ?>" <?php comment_class(); ?>>
125
    <header class="comment-header">
126
      <?php
127
        if (validate_gravatar(get_comment_author_email()))
128
          echo '<div class="comment-avatar">'.get_avatar($comment, 40).'</div>';
129
      ?>
130
      <div>
131
        <div class="comment-meta">
132
          <span class="comment-author"><?php comment_author_link() ?></span> <?php edit_comment_link( __( 'Edit', 'sdt' ), ' &bull; ', '' ); ?><br />
133
          <?php printf('<span class="comment-datetime"><a href="%1$s"><time pubdate datetime="%2$s">%3$s</time></a></span>',
134
                        esc_url(get_comment_link($comment->comment_ID)),
135
                        get_comment_time('c'),
136
                        /* translators: 1: date, 2: time */
137
                        sprintf(__('%1$s %2$s', 'sdt'), get_comment_date(), get_comment_time())
138
                ); ?>
139
        </div>
140
        <?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']))); ?>
141
      </div>
142
    </header>
143
    <div class="comment-content">
144
      <?php if ($comment->comment_approved == '0') : ?>
145
        <div class="comment-awaiting-moderation"><?php _e('Your comment is awaiting moderation', 'sdt'); ?></div>
146
                        <?php endif; ?>
147
      <?php comment_text(); ?>
148
    </div>
149
  </div>
150
  <?php
151
  endif;
152
}
153
 
154
// Function to generate trackback/pingback
155
function sdt_trackback($comment, $args, $depth) {
156
        $GLOBALS['comment'] = $comment;
157
 
158
  if ($comment->comment_type == "trackback" || $comment->comment_type == "pingback") : ?>
159
    <div id="comment-<?php comment_ID() ?>" <?php comment_class(); ?>>
160
      <span class="comment-author"><?php comment_author_link() ?></span><br />
161
      <?php comment_excerpt(); ?>
162
    </div>
163
  <?php
164
        endif;
165
}
166
 
167
// Function to count trackback/pingback
168
function sdt_trackback_number($comments) {
169
  $numero_trackback = 0;
170
        foreach ($comments as $comment) :
171
    if ($comment->comment_type == "trackback" || $comment->comment_type == "pingback") $numero_trackback++;
172
  endforeach;
173
        return $numero_trackback;
174
}
175
 
176
/* Function to generate both comments and trackbacks/pingbacks together,
177
 * in case of paged comments. If you find a way to nicely separate comments
178
 * and pingbacks/trackbacks in paged comments, please tell me.
179
 */
180
function sdt_all_comment($comment, $args, $depth) {
181
        $GLOBALS['comment'] = $comment;
182
 
183
  if ($comment->comment_type != "trackback" && $comment->comment_type != "pingback") : ?>
184
  <div id="comment-<?php comment_ID() ?>" <?php comment_class(); ?>>
185
    <header class="comment-header">
186
      <?php
187
        if (validate_gravatar(get_comment_author_email()))
188
          echo '<div class="comment-avatar">'.get_avatar($comment, 40).'</div>';
189
      ?>
190
      <div>
191
        <div class="comment-meta">
192
          <span class="comment-author"><?php comment_author_link() ?></span> <?php edit_comment_link( __( 'Edit', 'sdt' ), ' &bull; ', '' ); ?><br />
193
          <?php printf('<span class="comment-datetime"><a href="%1$s"><time pubdate datetime="%2$s">%3$s</time></a></span>',
194
                        esc_url(get_comment_link($comment->comment_ID)),
195
                        get_comment_time('c'),
196
                        /* translators: 1: date, 2: time */
197
                        sprintf(__('%1$s %2$s', 'sdt'), get_comment_date(), get_comment_time())
198
                ); ?>
199
        </div>
200
        <?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']))); ?>
201
      </div>
202
    </header>
203
    <div class="comment-content">
204
      <?php if ($comment->comment_approved == '0') : ?>
205
        <div class="comment-awaiting-moderation"><?php _e('Your comment is awaiting moderation', 'sdt'); ?></div>
206
                        <?php endif; ?>
207
      <?php comment_text(); ?>
208
    </div>
209
  </div>
210
  <?php
211
  endif;
212
  if ($comment->comment_type == "trackback" || $comment->comment_type == "pingback") : ?>
213
    <div id="comment-<?php comment_ID() ?>" <?php comment_class(); ?>>
214
      <span class="comment-author"><?php comment_author_link() ?></span><br />
215
      <?php comment_excerpt(); ?>
216
    </div>
217
  <?php
218
        endif;
219
}
220
?>