~canonical-sysadmins/wordpress/wp-theme-thematic

« back to all changes in this revision

Viewing changes to library/extensions/comments-extensions.php

  • Committer: Haw Loeung
  • Date: 2016-04-27 04:57:21 UTC
  • Revision ID: haw.loeung@canonical.com-20160427045721-k7ql8li9wdvhi81q
[trivial] Updated to 1.0.4 (bzr import thematic.1.0.4.zip).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
<?php
2
 
 
3
 
 
4
 
// Located in comments.php
5
 
// Just before #comments
 
2
/**
 
3
 * Comments Extensions
 
4
 *
 
5
 * @package ThematicCoreLibrary
 
6
 * @subpackage CommentsExtensions
 
7
 */
 
8
 
 
9
/**
 
10
 * Action Hook: thematic_abovecomments
 
11
 * 
 
12
 * Located in comments.php
 
13
 * Just before #comments
 
14
 */
6
15
function thematic_abovecomments() {
7
16
    do_action('thematic_abovecomments');
8
17
}
9
18
 
10
 
 
11
 
// Located in comments.php
12
 
// Just before #comments-list
 
19
/**
 
20
 * Action Hook: thematic_abovecommentslist
 
21
 * 
 
22
 * Located in comments.php
 
23
 * Just before #comments-list
 
24
 */
13
25
function thematic_abovecommentslist() {
14
26
    do_action('thematic_abovecommentslist');
15
27
}
16
28
 
17
 
 
18
 
// Located in comments.php
19
 
// Just after #comments-list
 
29
/**
 
30
 * Action Hook: thematic_belowcommentslist
 
31
 * 
 
32
 * Located in comments.php
 
33
 * Just after #comments-list
 
34
 */
20
35
function thematic_belowcommentslist() {
21
36
    do_action('thematic_belowcommentslist');
22
37
}
23
38
 
24
 
 
25
 
// Located in comments.php
26
 
// Just before #trackbacks-list
 
39
/**
 
40
 * Action Hook: thematic_abovetrackbackslist
 
41
 * 
 
42
 * Located in comments.php
 
43
 * Just before #trackbacks-list
 
44
 */
27
45
function thematic_abovetrackbackslist() {
28
46
    do_action('thematic_abovetrackbackslist');
29
47
}
30
48
 
31
 
 
32
 
// Located in comments.php
33
 
// Just after #trackbacks-list
 
49
/**
 
50
 * Action Hook: thematic_belowtrackbackslist
 
51
 * 
 
52
 * Located in comments.php
 
53
 * Just after #trackbacks-list
 
54
 */
34
55
function thematic_belowtrackbackslist() {
35
56
    do_action('thematic_belowtrackbackslist');
36
57
}
37
58
 
38
 
 
39
 
// Located in comments.php
40
 
// Just before the comments form
 
59
/**
 
60
 * Action Hook: thematic_abovecommentsform
 
61
 * 
 
62
 * Located in comments.php
 
63
 * Just before the comments form
 
64
 */
41
65
function thematic_abovecommentsform() {
42
66
    do_action('thematic_abovecommentsform');
43
67
}
44
68
 
45
 
 
46
 
// Adds the Subscribe to comments button
 
69
/**
 
70
 * Provides Plugin Compatibility: Subscribe to Comments
 
71
 *
 
72
 * Adds the subscribe to comments button.
 
73
 *
 
74
 * @link http://wordpress.org/extend/plugins/subscribe-to-comments/ Subscribe to Comments Plugin Page
 
75
 */
47
76
function thematic_show_subscription_checkbox() {
48
77
    if(function_exists('show_subscription_checkbox')) { show_subscription_checkbox(); }
49
78
}
50
79
add_action('comment_form', 'thematic_show_subscription_checkbox', 98);
51
80
 
52
 
 
53
 
// Located in comments.php
54
 
// Just after the comments form
 
81
/**
 
82
 * Action Hook: thematic_belowcommentsform
 
83
 * 
 
84
 * Located in comments.php
 
85
 * Just after the comments form
 
86
 */
55
87
function thematic_belowcommentsform() {
56
88
    do_action('thematic_belowcommentsform');
57
89
}
58
90
 
59
 
 
60
 
// Adds the Subscribe without commenting button
 
91
/**
 
92
 * Provides Plugin Compatibility: Subscribe to Comments
 
93
 *
 
94
 * Adds the subscribe without commenting button
 
95
 *
 
96
 * @link http://wordpress.org/extend/plugins/subscribe-to-comments/ Subscribe to Comments Plugin Page
 
97
 */
61
98
function thematic_show_manual_subscription_form() {
62
99
    if(function_exists('show_manual_subscription_form')) { show_manual_subscription_form(); }
63
100
}
64
101
add_action('thematic_belowcommentsform', 'thematic_show_manual_subscription_form', 5);
65
102
 
66
 
 
67
 
// Located in comments.php
68
 
// Just after #comments
 
103
/**
 
104
 * Action Hook: thematic_belowcomments
 
105
 * 
 
106
 * Located in comments.php
 
107
 * Just after #comments
 
108
 */
69
109
function thematic_belowcomments() {
70
110
    do_action('thematic_belowcomments');
71
111
}
72
112
 
73
 
// Located in comments.php
74
 
// Creates the standard text for one comment
 
113
/**
 
114
 * Filter: thematic_singlecomment_text
 
115
 *
 
116
 * Creates the standard text for one comment
 
117
 * Located in comments.php
 
118
 */
75
119
function thematic_singlecomment_text() {
76
 
    $content = __('<span>One</span> Comment', 'thematic');
77
 
    return apply_filters(thematic_singlecomment_text, $content);
 
120
    $content = sprintf( _x( '%1$sOne%2$s Comment' , 'One Comment, where %$1s and %$2s are <span> tags', 'thematic' ), '<span>' , '</span>' );
 
121
    return apply_filters( 'thematic_singlecomment_text', $content );
78
122
}
79
123
 
80
 
// Located in comments.php
81
 
// Creates the standard text for more than one comment
 
124
/**
 
125
 * Filter: thematic_multiplecomments_text
 
126
 *
 
127
 * Creates the standard text for more than one comment
 
128
 * Located in comments.php
 
129
 */
82
130
function thematic_multiplecomments_text() {
83
 
    $content = __('<span>%d</span> Comments', 'thematic');
84
 
    return apply_filters(thematic_multiplecomments_text, $content);
 
131
    $content = '<span>%d</span> ' . __('Comments', 'thematic');
 
132
    return apply_filters( 'thematic_multiplecomments_text', $content );
85
133
}
86
134
 
87
 
// creates the list comments arguments
88
 
function list_comments_arg() {
 
135
 
 
136
/**
 
137
 * Filter: list_comments_arg
 
138
 * 
 
139
 * Creates the list comments arguments
 
140
 */
 
141
function thematic_list_comments_arg() {
89
142
        $content = 'type=comment&callback=thematic_comments';
90
143
        return apply_filters('list_comments_arg', $content);
91
144
}
92
145
 
93
 
// Located in comments.php
94
 
// Creates the standard text 'Post a Comment'
 
146
 
 
147
/**
 
148
 * Filter: thematic_postcomment_text
 
149
 * 
 
150
 * Creates the standard text 'Post a Comment'
 
151
 * Located in comments.php
 
152
 */
95
153
function thematic_postcomment_text() {
 
154
        /* translators: comment form title */
96
155
    $content = __('Post a Comment', 'thematic');
97
 
    return apply_filters(thematic_postcomment_text, $content);
 
156
    return apply_filters( 'thematic_postcomment_text', $content );
98
157
}
99
158
 
100
 
// Located in comments.php
101
 
// Creates the standard text 'Post a Reply to %s'
 
159
/**
 
160
 * Filter: thematic_postreply_text
 
161
 * 
 
162
 * Creates the standard text 'Post a Reply to %s'
 
163
 * Located in comments.php
 
164
 */
102
165
function thematic_postreply_text() {
 
166
        /* translators: comment reply form title, %s is author of comment */
103
167
    $content = __('Post a Reply to %s', 'thematic');
104
 
    return apply_filters(thematic_postreply_text, $content);
 
168
    return apply_filters( 'thematic_postreply_text', $content );
105
169
}
106
170
 
107
 
// Located in comments.php
108
 
// Creates the standard text 'Comment' for the text box
 
171
/**
 
172
 * Filter: thematic_commentbox_text
 
173
 * 
 
174
 * Creates the standard text 'Comment' for the text box
 
175
 * Located in comments.php
 
176
 */
109
177
function thematic_commentbox_text() {
110
 
    $content = __('Comment', 'thematic');
111
 
    return apply_filters(thematic_commentbox_text, $content);
112
 
}
113
 
 
114
 
// Located in comments.php
115
 
// Creates the standard text 'Post Comment' for the send button
 
178
        /* translators: label for comment form textarea */
 
179
        $content = _x('Comment', 'noun', 'thematic');
 
180
    return apply_filters( 'thematic_commentbox_text', $content );
 
181
}
 
182
 
 
183
/**
 
184
 * Filter: thematic_cancelreply_text function.
 
185
 * 
 
186
 * Creates the standard text 'Cancel reply'
 
187
 * Located in comments-extensions.php
 
188
 */
 
189
function thematic_cancelreply_text() {
 
190
    $content = __('Cancel reply', 'thematic');
 
191
    return apply_filters( 'thematic_cancelreply_text', $content );
 
192
}
 
193
 
 
194
/**
 
195
 * Filter: thematic_commentbutton_text
 
196
 * 
 
197
 * Creates the standard text 'Post Comment' for the send button
 
198
 * Located in comments.php
 
199
 */
116
200
function thematic_commentbutton_text() {
117
 
    $content = __('Post Comment', 'thematic');
118
 
    return apply_filters(thematic_commentbutton_text, $content);
119
 
}
120
 
 
121
 
// Produces an avatar image with the hCard-compliant photo class
 
201
        /* translators: text of comment button */
 
202
    $content = esc_attr( __('Post Comment', 'thematic') );
 
203
    return apply_filters( 'thematic_commentbutton_text', $content );
 
204
}
 
205
 
 
206
/**
 
207
 * Function: thematic_comment_form_args
 
208
 * Filter: comment_form_default_fields
 
209
 * 
 
210
 * Creates the standard arguments for comment_form()
 
211
 * Located in comments.php
 
212
 */
 
213
function thematic_comment_form_args( $post_id = null ) {
 
214
        global $user_identity, $id;
 
215
        
 
216
        if ( null === $post_id )
 
217
          $post_id = $id;
 
218
      else
 
219
          $id = $post_id;
 
220
        
 
221
        $req = get_option( 'require_name_email' );
 
222
        
 
223
        $commenter = wp_get_current_commenter();
 
224
        
 
225
        $aria_req = ( $req ? " aria-required='true'" : '' );
 
226
        
 
227
        $fields =  array(
 
228
                'author' => '<div id="form-section-author" class="form-section"><div class="form-label">' . '<label for="author">' . __( 'Name', 'thematic' ) . '</label> ' . ( $req ? '<span class="required">' . _x( '*', 'denotes required field', 'thematic' ) . '</span>' : '' ) . '</div>' . '<div class="form-input">' . '<input id="author" name="author" type="text" value="' . esc_attr( $commenter['comment_author'] ) . '" size="30"' .  ' maxlength="20" tabindex="3"' . $aria_req . ' /></div></div><!-- #form-section-author .form-section -->',
 
229
                'email'  => '<div id="form-section-email" class="form-section"><div class="form-label"><label for="email">' . __( 'Email', 'thematic' ) . '</label> ' . ( $req ? '<span class="required">' . _x( '*', 'denotes required field', 'thematic' ) . '</span>' : '' ) . '</div><div class="form-input">' . '<input id="email" name="email" type="email" value="' . esc_attr(  $commenter['comment_author_email'] ) . '" size="30" maxlength="50" tabindex="4"' . $aria_req . ' /></div></div><!-- #form-section-email .form-section -->',
 
230
                'url'    => '<div id="form-section-url" class="form-section"><div class="form-label"><label for="url">' . __( 'Website', 'thematic' ) . '</label></div>' . '<div class="form-input"><input id="url" name="url" type="url" value="' . esc_attr( $commenter['comment_author_url'] ) . '" size="30" maxlength="50" tabindex="5" /></div></div><!-- #form-section-url .form-section -->',
 
231
        );
 
232
 
 
233
        
 
234
        $args = array(
 
235
                'fields'               => apply_filters( 'comment_form_default_fields', $fields ),
 
236
                'comment_field'        => '<div id="form-section-comment" class="form-section"><div class="form-label"><label for="comment">' . __(thematic_commentbox_text(), 'thematic') . '</label></div><div class="form-textarea"><textarea id="comment" name="comment" cols="45" rows="8" tabindex="6" aria-required="true"></textarea></div></div><!-- #form-section-comment .form-section -->',
 
237
 
 
238
                'comment_notes_before' => '<p class="comment-notes">' . sprintf( _x( 'Your email is %1$snever%2$s published nor shared.' , '%$1s and %$2s are <em> tags for emphasis on never', 'thematic' ), '<em>' , '</em>' ) . ( $req ? ' ' . sprintf( _x('Required fields are marked %1$s*%2$s', '%$1s and %$2s are <span> tags', 'thematic'), '<span class="required">', '</span>' ) : '' ) . '</p>',
 
239
 
 
240
                'must_log_in'          => '<p id="login-req">' .  sprintf( __('You must be %1$slogged in%2$s to post a comment.', 'thematic'), sprintf('<a href="%s" title ="%s">', esc_attr( wp_login_url( apply_filters( 'the_permalink', get_permalink() ) ) ), esc_attr__( 'Log in', 'thematic' ) ), '</a>' ). '</p>',
 
241
 
 
242
                'logged_in_as'         => '<p id="login"><span class="loggedin">' . sprintf( __('Logged in as %s', 'thematic' ), sprintf( ' <a href="%1$s" title="%2$s">%3$s</a>', admin_url( 'profile.php' ), sprintf( esc_attr__('Logged in as %s', 'thematic'), $user_identity ) , $user_identity ) ) .'</span> <span class="logout">' . sprintf('<a href="%s" title="%s">%s</a>' , esc_attr( wp_logout_url( apply_filters( 'the_permalink', get_permalink( $post_id ) ) ) ), esc_attr__('Log out of this account', 'thematic' ) , __('Log out?', 'thematic' ) ) . '</span></p>',
 
243
                
 
244
                'comment_notes_after'  => '<div id="form-allowed-tags" class="form-section"><p><span>' . sprintf( _x('You may use these %1$sHTML%2$s tags and attributes', '%$1s and %$2s are <abbr> tags', 'thematic'), '<abbr title="HyperText Markup Language">', '</abbr>' ) . '</span> <code>' . allowed_tags() . '</code></p></div>',
 
245
 
 
246
                'id_form'              => 'commentform',
 
247
                'id_submit'            => 'submit',
 
248
                'title_reply'          => thematic_postcomment_text(),
 
249
                'title_reply_to'       => thematic_postreply_text(),
 
250
                'cancel_reply_link'    => thematic_cancelreply_text(),
 
251
                'label_submit'         => thematic_commentbutton_text(),
 
252
 
 
253
        );
 
254
        return apply_filters( 'thematic_comment_form_args', $args );    
 
255
}
 
256
 
 
257
/**
 
258
 * Produces an avatar image with the hCard-compliant photo class
 
259
 */
122
260
function thematic_commenter_link() {
123
261
        $commenter = get_comment_author_link();
124
262
        if ( ereg( '<a[^>]* class=[^>]+>', $commenter ) ) {
130
268
        $avatar_size = apply_filters( 'avatar_size', '80' ); // Available filter: avatar_size
131
269
        $avatar = str_replace( "class='avatar", "class='photo avatar", get_avatar( $avatar_email, $avatar_size ) );
132
270
        echo $avatar . ' <span class="fn n">' . $commenter . '</span>';
133
 
} // end thematic_commenter_link
134
 
 
135
 
 
136
 
// A hook for the standard comments template
 
271
 
272
 
 
273
/**
 
274
 * ActionHook: thematic_comments_template
 
275
 */
137
276
function thematic_comments_template() {
138
277
        do_action('thematic_comments_template');
139
 
} // end thematic_comments
140
 
 
141
 
 
142
 
        // The standard comments template is injected into thematic_comments_template() by default
143
 
        function thematic_include_comments() {
 
278
}
 
279
 
 
280
/**
 
281
 *  Outputs the standard comments template
 
282
 */
 
283
function thematic_include_comments() {
 
284
        // Checking for defined constant to enable conditional comment display for Pages
 
285
    if (  current_theme_supports( 'thematic_legacy_comment_handling' ) && is_page() ) {
 
286
        // Needs post-meta key/value of "comments" to call comments template on Pages!
 
287
        if ( get_post_custom_values('comments') )
 
288
                        comments_template('', true);            
 
289
        // WordPress standard comment handling is the default if constant is not set
 
290
        } else {
144
291
                comments_template('', true);
145
 
        } // end thematic_include_comments
146
 
        
147
 
        add_action('thematic_comments_template','thematic_include_comments',5);
148
 
        
149
 
        
 
 
b'\\ No newline at end of file'
 
292
        }
 
293
}
 
294
 
 
295
add_action('thematic_comments_template','thematic_include_comments', 5);
 
296
 
 
297
function thematic_get_comment_link( $link , $comment, $args ) {
 
298
        global  $wp_rewrite; 
 
299
 
 
300
        $args['type'] = 'comment';
 
301
        $args['page'] = get_page_of_comment( $comment->comment_ID, $args );
 
302
        
 
303
        if ( $args['per_page'] ) {
 
304
                if ( '' == $args['page'] )
 
305
                        $args['page'] = ( !empty($in_comment_loop) ) ? get_query_var('cpage') : get_page_of_comment( $comment->comment_ID, $args );
 
306
 
 
307
                if ( $wp_rewrite->using_permalinks() )
 
308
                        $link = user_trailingslashit( trailingslashit( get_permalink( $comment->comment_post_ID ) ) . 'comment-page-' . $args['page'], 'comment' );
 
309
                else
 
310
                        $link = add_query_arg( 'cpage', $args['page'], get_permalink( $comment->comment_post_ID ) );
 
311
        } else {
 
312
                $link = get_permalink( $comment->comment_post_ID );
 
313
        }
 
314
 
 
315
        return $link . '#comment-' . $comment->comment_ID; 
 
316
}
 
317
add_filter( 'get_comment_link', 'thematic_get_comment_link', 10, 3 );
 
318
 
 
319
?>
 
 
b'\\ No newline at end of file'