1 | <?php |
---|
2 | |
---|
3 | /* Note: these tags go anywhere in the template */ |
---|
4 | |
---|
5 | function get_header() { |
---|
6 | do_action( 'get_header' ); |
---|
7 | if ( TEMPLATEPATH !== STYLESHEETPATH && file_exists( STYLESHEETPATH . '/header.php') ) |
---|
8 | load_template( STYLESHEETPATH . '/header.php'); |
---|
9 | elseif ( file_exists( TEMPLATEPATH . '/header.php') ) |
---|
10 | load_template( TEMPLATEPATH . '/header.php'); |
---|
11 | else |
---|
12 | load_template( WP_CONTENT_DIR . '/themes/default/header.php'); |
---|
13 | } |
---|
14 | |
---|
15 | |
---|
16 | function get_footer() { |
---|
17 | do_action( 'get_footer' ); |
---|
18 | if ( TEMPLATEPATH !== STYLESHEETPATH && file_exists( STYLESHEETPATH . '/footer.php') ) |
---|
19 | load_template( STYLESHEETPATH . '/footer.php'); |
---|
20 | elseif ( file_exists( TEMPLATEPATH . '/footer.php') ) |
---|
21 | load_template( TEMPLATEPATH . '/footer.php'); |
---|
22 | else |
---|
23 | load_template( WP_CONTENT_DIR . '/themes/default/footer.php'); |
---|
24 | } |
---|
25 | |
---|
26 | |
---|
27 | function get_sidebar( $name = null ) { |
---|
28 | do_action( 'get_sidebar' ); |
---|
29 | if ( TEMPLATEPATH !== STYLESHEETPATH && ( isset($name) && file_exists( STYLESHEETPATH . "/sidebar-{$name}.php") ) ) |
---|
30 | load_template( STYLESHEETPATH . "/sidebar-{$name}.php"); |
---|
31 | elseif ( isset($name) && file_exists( TEMPLATEPATH . "/sidebar-{$name}.php") ) |
---|
32 | load_template( TEMPLATEPATH . "/sidebar-{$name}.php"); |
---|
33 | |
---|
34 | elseif ( TEMPLATEPATH !== STYLESHEETPATH && file_exists( STYLESHEETPATH . '/sidebar.php') ) |
---|
35 | load_template( STYLESHEETPATH . '/sidebar.php'); |
---|
36 | elseif ( file_exists( TEMPLATEPATH . '/sidebar.php') ) |
---|
37 | load_template( TEMPLATEPATH . '/sidebar.php'); |
---|
38 | else |
---|
39 | load_template( WP_CONTENT_DIR . '/themes/default/sidebar.php'); |
---|
40 | } |
---|
41 | |
---|
42 | |
---|
43 | function wp_loginout() { |
---|
44 | if ( ! is_user_logged_in() ) |
---|
45 | $link = '<a href="' . get_option('siteurl') . '/wp-login.php">' . __('Log in') . '</a>'; |
---|
46 | else |
---|
47 | $link = '<a href="' . get_option('siteurl') . '/wp-login.php?action=logout">' . __('Log out') . '</a>'; |
---|
48 | |
---|
49 | echo apply_filters('loginout', $link); |
---|
50 | } |
---|
51 | |
---|
52 | |
---|
53 | function wp_register( $before = '<li>', $after = '</li>' ) { |
---|
54 | |
---|
55 | if ( ! is_user_logged_in() ) { |
---|
56 | if ( get_option('users_can_register') ) |
---|
57 | $link = $before . '<a href="' . get_option('siteurl') . '/wp-login.php?action=register">' . __('Register') . '</a>' . $after; |
---|
58 | else |
---|
59 | $link = ''; |
---|
60 | } else { |
---|
61 | $link = $before . '<a href="' . get_option('siteurl') . '/wp-admin/">' . __('Site Admin') . '</a>' . $after; |
---|
62 | } |
---|
63 | |
---|
64 | echo apply_filters('register', $link); |
---|
65 | } |
---|
66 | |
---|
67 | |
---|
68 | function wp_meta() { |
---|
69 | do_action('wp_meta'); |
---|
70 | } |
---|
71 | |
---|
72 | |
---|
73 | function bloginfo($show='') { |
---|
74 | echo get_bloginfo($show, 'display'); |
---|
75 | } |
---|
76 | |
---|
77 | /** |
---|
78 | * Note: some of these values are DEPRECATED. Meaning they could be |
---|
79 | * taken out at any time and shouldn't be relied upon. Options |
---|
80 | * without "// DEPRECATED" are the preferred and recommended ways |
---|
81 | * to get the information. |
---|
82 | */ |
---|
83 | function get_bloginfo($show = '', $filter = 'raw') { |
---|
84 | |
---|
85 | switch($show) { |
---|
86 | case 'url' : |
---|
87 | case 'home' : // DEPRECATED |
---|
88 | case 'siteurl' : // DEPRECATED |
---|
89 | $output = get_option('home'); |
---|
90 | break; |
---|
91 | case 'wpurl' : |
---|
92 | $output = get_option('siteurl'); |
---|
93 | break; |
---|
94 | case 'description': |
---|
95 | $output = get_option('blogdescription'); |
---|
96 | break; |
---|
97 | case 'rdf_url': |
---|
98 | $output = get_feed_link('rdf'); |
---|
99 | break; |
---|
100 | case 'rss_url': |
---|
101 | $output = get_feed_link('rss'); |
---|
102 | break; |
---|
103 | case 'rss2_url': |
---|
104 | $output = get_feed_link('rss2'); |
---|
105 | break; |
---|
106 | case 'atom_url': |
---|
107 | $output = get_feed_link('atom'); |
---|
108 | break; |
---|
109 | case 'comments_atom_url': |
---|
110 | $output = get_feed_link('comments_atom'); |
---|
111 | break; |
---|
112 | case 'comments_rss2_url': |
---|
113 | $output = get_feed_link('comments_rss2'); |
---|
114 | break; |
---|
115 | case 'pingback_url': |
---|
116 | $output = get_option('siteurl') .'/xmlrpc.php'; |
---|
117 | break; |
---|
118 | case 'stylesheet_url': |
---|
119 | $output = get_stylesheet_uri(); |
---|
120 | break; |
---|
121 | case 'stylesheet_directory': |
---|
122 | $output = get_stylesheet_directory_uri(); |
---|
123 | break; |
---|
124 | case 'template_directory': |
---|
125 | case 'template_url': |
---|
126 | $output = get_template_directory_uri(); |
---|
127 | break; |
---|
128 | case 'admin_email': |
---|
129 | $output = get_option('admin_email'); |
---|
130 | break; |
---|
131 | case 'charset': |
---|
132 | $output = get_option('blog_charset'); |
---|
133 | if ('' == $output) $output = 'UTF-8'; |
---|
134 | break; |
---|
135 | case 'html_type' : |
---|
136 | $output = get_option('html_type'); |
---|
137 | break; |
---|
138 | case 'version': |
---|
139 | global $wp_version; |
---|
140 | $output = $wp_version; |
---|
141 | break; |
---|
142 | case 'language': |
---|
143 | $output = get_locale(); |
---|
144 | $output = str_replace('_', '-', $output); |
---|
145 | break; |
---|
146 | case 'text_direction': |
---|
147 | global $wp_locale; |
---|
148 | $output = $wp_locale->text_direction; |
---|
149 | break; |
---|
150 | case 'name': |
---|
151 | default: |
---|
152 | $output = get_option('blogname'); |
---|
153 | break; |
---|
154 | } |
---|
155 | |
---|
156 | $url = true; |
---|
157 | if (strpos($show, 'url') === false && |
---|
158 | strpos($show, 'directory') === false && |
---|
159 | strpos($show, 'home') === false) |
---|
160 | $url = false; |
---|
161 | |
---|
162 | if ( 'display' == $filter ) { |
---|
163 | if ( $url ) |
---|
164 | $output = apply_filters('bloginfo_url', $output, $show); |
---|
165 | else |
---|
166 | $output = apply_filters('bloginfo', $output, $show); |
---|
167 | } |
---|
168 | |
---|
169 | return $output; |
---|
170 | } |
---|
171 | |
---|
172 | |
---|
173 | function wp_title($sep = '»', $display = true, $seplocation = '') { |
---|
174 | global $wpdb, $wp_locale, $wp_query; |
---|
175 | |
---|
176 | $cat = get_query_var('cat'); |
---|
177 | $tag = get_query_var('tag_id'); |
---|
178 | $category_name = get_query_var('category_name'); |
---|
179 | $author = get_query_var('author'); |
---|
180 | $author_name = get_query_var('author_name'); |
---|
181 | $m = get_query_var('m'); |
---|
182 | $year = get_query_var('year'); |
---|
183 | $monthnum = get_query_var('monthnum'); |
---|
184 | $day = get_query_var('day'); |
---|
185 | $title = ''; |
---|
186 | |
---|
187 | // If there's a category |
---|
188 | if ( !empty($cat) ) { |
---|
189 | // category exclusion |
---|
190 | if ( !stristr($cat,'-') ) |
---|
191 | $title = apply_filters('single_cat_title', get_the_category_by_ID($cat)); |
---|
192 | } elseif ( !empty($category_name) ) { |
---|
193 | if ( stristr($category_name,'/') ) { |
---|
194 | $category_name = explode('/',$category_name); |
---|
195 | if ( $category_name[count($category_name)-1] ) |
---|
196 | $category_name = $category_name[count($category_name)-1]; // no trailing slash |
---|
197 | else |
---|
198 | $category_name = $category_name[count($category_name)-2]; // there was a trailling slash |
---|
199 | } |
---|
200 | $cat = get_term_by('slug', $category_name, 'category', OBJECT, 'display'); |
---|
201 | if ( $cat ) |
---|
202 | $title = apply_filters('single_cat_title', $cat->name); |
---|
203 | } |
---|
204 | |
---|
205 | if ( !empty($tag) ) { |
---|
206 | $tag = get_term($tag, 'post_tag', OBJECT, 'display'); |
---|
207 | if ( is_wp_error( $tag ) ) |
---|
208 | return $tag; |
---|
209 | if ( ! empty($tag->name) ) |
---|
210 | $title = apply_filters('single_tag_title', $tag->name); |
---|
211 | } |
---|
212 | |
---|
213 | // If there's an author |
---|
214 | if ( !empty($author) ) { |
---|
215 | $title = get_userdata($author); |
---|
216 | $title = $title->display_name; |
---|
217 | } |
---|
218 | if ( !empty($author_name) ) { |
---|
219 | // We do a direct query here because we don't cache by nicename. |
---|
220 | $title = $wpdb->get_var($wpdb->prepare("SELECT display_name FROM $wpdb->users WHERE user_nicename = %s", $author_name)); |
---|
221 | } |
---|
222 | |
---|
223 | // If there's a month |
---|
224 | if ( !empty($m) ) { |
---|
225 | $my_year = substr($m, 0, 4); |
---|
226 | $my_month = $wp_locale->get_month(substr($m, 4, 2)); |
---|
227 | $my_day = intval(substr($m, 6, 2)); |
---|
228 | $title = "$my_year" . ($my_month ? "$sep $my_month" : "") . ($my_day ? "$sep $my_day" : ""); |
---|
229 | } |
---|
230 | |
---|
231 | if ( !empty($year) ) { |
---|
232 | $title = $year; |
---|
233 | if ( !empty($monthnum) ) |
---|
234 | $title .= " $sep " . $wp_locale->get_month($monthnum); |
---|
235 | if ( !empty($day) ) |
---|
236 | $title .= " $sep " . zeroise($day, 2); |
---|
237 | } |
---|
238 | |
---|
239 | // If there is a post |
---|
240 | if ( is_single() || is_page() ) { |
---|
241 | $post = $wp_query->get_queried_object(); |
---|
242 | $title = strip_tags( apply_filters( 'single_post_title', $post->post_title ) ); |
---|
243 | } |
---|
244 | |
---|
245 | // If there's a taxonomy |
---|
246 | if ( is_tax() ) { |
---|
247 | $taxonomy = get_query_var( 'taxonomy' ); |
---|
248 | $tax = get_taxonomy( $taxonomy ); |
---|
249 | $tax = $tax->label; |
---|
250 | $term = $wp_query->get_queried_object(); |
---|
251 | $term = $term->name; |
---|
252 | if ( 'right' == $seplocation ) |
---|
253 | $title = "$term $sep $tax"; |
---|
254 | else |
---|
255 | $title = "$tax $sep $term"; |
---|
256 | } |
---|
257 | |
---|
258 | $prefix = ''; |
---|
259 | if ( !empty($title) ) |
---|
260 | $prefix = " $sep "; |
---|
261 | |
---|
262 | // Determines position of the separator |
---|
263 | if ( 'right' == $seplocation ) |
---|
264 | $title = $title . $prefix; |
---|
265 | else |
---|
266 | $title = $prefix . $title; |
---|
267 | |
---|
268 | $title = apply_filters('wp_title', $title, $sep); |
---|
269 | |
---|
270 | // Send it out |
---|
271 | if ( $display ) |
---|
272 | echo $title; |
---|
273 | else |
---|
274 | return $title; |
---|
275 | |
---|
276 | } |
---|
277 | |
---|
278 | |
---|
279 | function single_post_title($prefix = '', $display = true) { |
---|
280 | global $wpdb; |
---|
281 | $p = get_query_var('p'); |
---|
282 | $name = get_query_var('name'); |
---|
283 | |
---|
284 | if ( intval($p) || '' != $name ) { |
---|
285 | if ( !$p ) |
---|
286 | $p = $wpdb->get_var($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_name = %s", $name)); |
---|
287 | $post = & get_post($p); |
---|
288 | $title = $post->post_title; |
---|
289 | $title = apply_filters('single_post_title', $title); |
---|
290 | if ( $display ) |
---|
291 | echo $prefix.strip_tags($title); |
---|
292 | else |
---|
293 | return strip_tags($title); |
---|
294 | } |
---|
295 | } |
---|
296 | |
---|
297 | |
---|
298 | function single_cat_title($prefix = '', $display = true ) { |
---|
299 | $cat = intval( get_query_var('cat') ); |
---|
300 | if ( !empty($cat) && !(strtoupper($cat) == 'ALL') ) { |
---|
301 | $my_cat_name = apply_filters('single_cat_title', get_the_category_by_ID($cat)); |
---|
302 | if ( !empty($my_cat_name) ) { |
---|
303 | if ( $display ) |
---|
304 | echo $prefix.strip_tags($my_cat_name); |
---|
305 | else |
---|
306 | return strip_tags($my_cat_name); |
---|
307 | } |
---|
308 | } else if ( is_tag() ) { |
---|
309 | return single_tag_title($prefix, $display); |
---|
310 | } |
---|
311 | } |
---|
312 | |
---|
313 | |
---|
314 | function single_tag_title($prefix = '', $display = true ) { |
---|
315 | if ( !is_tag() ) |
---|
316 | return; |
---|
317 | |
---|
318 | $tag_id = intval( get_query_var('tag_id') ); |
---|
319 | |
---|
320 | if ( !empty($tag_id) ) { |
---|
321 | $my_tag = &get_term($tag_id, 'post_tag', OBJECT, 'display'); |
---|
322 | if ( is_wp_error( $my_tag ) ) |
---|
323 | return false; |
---|
324 | $my_tag_name = apply_filters('single_tag_title', $my_tag->name); |
---|
325 | if ( !empty($my_tag_name) ) { |
---|
326 | if ( $display ) |
---|
327 | echo $prefix . $my_tag_name; |
---|
328 | else |
---|
329 | return $my_tag_name; |
---|
330 | } |
---|
331 | } |
---|
332 | } |
---|
333 | |
---|
334 | |
---|
335 | function single_month_title($prefix = '', $display = true ) { |
---|
336 | global $wp_locale; |
---|
337 | |
---|
338 | $m = get_query_var('m'); |
---|
339 | $year = get_query_var('year'); |
---|
340 | $monthnum = get_query_var('monthnum'); |
---|
341 | |
---|
342 | if ( !empty($monthnum) && !empty($year) ) { |
---|
343 | $my_year = $year; |
---|
344 | $my_month = $wp_locale->get_month($monthnum); |
---|
345 | } elseif ( !empty($m) ) { |
---|
346 | $my_year = substr($m, 0, 4); |
---|
347 | $my_month = $wp_locale->get_month(substr($m, 4, 2)); |
---|
348 | } |
---|
349 | |
---|
350 | if ( empty($my_month) ) |
---|
351 | return false; |
---|
352 | |
---|
353 | $result = $prefix . $my_month . $prefix . $my_year; |
---|
354 | |
---|
355 | if ( !$display ) |
---|
356 | return $result; |
---|
357 | echo $result; |
---|
358 | } |
---|
359 | |
---|
360 | |
---|
361 | /* link navigation hack by Orien http://icecode.com/ */ |
---|
362 | function get_archives_link($url, $text, $format = 'html', $before = '', $after = '') { |
---|
363 | $text = wptexturize($text); |
---|
364 | $title_text = attribute_escape($text); |
---|
365 | $url = clean_url($url); |
---|
366 | |
---|
367 | if ('link' == $format) |
---|
368 | $link_html = "\t<link rel='archives' title='$title_text' href='$url' />\n"; |
---|
369 | elseif ('option' == $format) |
---|
370 | $link_html = "\t<option value='$url'>$before $text $after</option>\n"; |
---|
371 | elseif ('html' == $format) |
---|
372 | $link_html = "\t<li>$before<a href='$url' title='$title_text'>$text</a>$after</li>\n"; |
---|
373 | else // custom |
---|
374 | $link_html = "\t$before<a href='$url' title='$title_text'>$text</a>$after\n"; |
---|
375 | |
---|
376 | $link_html = apply_filters( "get_archives_link", $link_html ); |
---|
377 | |
---|
378 | return $link_html; |
---|
379 | } |
---|
380 | |
---|
381 | |
---|
382 | function wp_get_archives($args = '') { |
---|
383 | global $wpdb, $wp_locale; |
---|
384 | |
---|
385 | $defaults = array( |
---|
386 | 'type' => 'monthly', 'limit' => '', |
---|
387 | 'format' => 'html', 'before' => '', |
---|
388 | 'after' => '', 'show_post_count' => false |
---|
389 | ); |
---|
390 | |
---|
391 | $r = wp_parse_args( $args, $defaults ); |
---|
392 | extract( $r, EXTR_SKIP ); |
---|
393 | |
---|
394 | if ( '' == $type ) |
---|
395 | $type = 'monthly'; |
---|
396 | |
---|
397 | if ( '' != $limit ) { |
---|
398 | $limit = absint($limit); |
---|
399 | $limit = ' LIMIT '.$limit; |
---|
400 | } |
---|
401 | |
---|
402 | // this is what will separate dates on weekly archive links |
---|
403 | $archive_week_separator = '–'; |
---|
404 | |
---|
405 | // over-ride general date format ? 0 = no: use the date format set in Options, 1 = yes: over-ride |
---|
406 | $archive_date_format_over_ride = 0; |
---|
407 | |
---|
408 | // options for daily archive (only if you over-ride the general date format) |
---|
409 | $archive_day_date_format = 'Y/m/d'; |
---|
410 | |
---|
411 | // options for weekly archive (only if you over-ride the general date format) |
---|
412 | $archive_week_start_date_format = 'Y/m/d'; |
---|
413 | $archive_week_end_date_format = 'Y/m/d'; |
---|
414 | |
---|
415 | if ( !$archive_date_format_over_ride ) { |
---|
416 | $archive_day_date_format = get_option('date_format'); |
---|
417 | $archive_week_start_date_format = get_option('date_format'); |
---|
418 | $archive_week_end_date_format = get_option('date_format'); |
---|
419 | } |
---|
420 | |
---|
421 | //filters |
---|
422 | $where = apply_filters('getarchives_where', "WHERE post_type = 'post' AND post_status = 'publish'", $r ); |
---|
423 | $join = apply_filters('getarchives_join', "", $r); |
---|
424 | |
---|
425 | if ( 'monthly' == $type ) { |
---|
426 | $query = "SELECT DISTINCT YEAR(post_date) AS `year`, MONTH(post_date) AS `month`, count(ID) as posts FROM $wpdb->posts $join $where GROUP BY YEAR(post_date), MONTH(post_date) ORDER BY post_date DESC $limit"; |
---|
427 | $key = md5($query); |
---|
428 | $cache = wp_cache_get( 'wp_get_archives' , 'general'); |
---|
429 | if ( !isset( $cache[ $key ] ) ) { |
---|
430 | $arcresults = $wpdb->get_results($query); |
---|
431 | $cache[ $key ] = $arcresults; |
---|
432 | wp_cache_add( 'wp_get_archives', $cache, 'general' ); |
---|
433 | } else { |
---|
434 | $arcresults = $cache[ $key ]; |
---|
435 | } |
---|
436 | if ( $arcresults ) { |
---|
437 | $afterafter = $after; |
---|
438 | foreach ( $arcresults as $arcresult ) { |
---|
439 | $url = get_month_link($arcresult->year, $arcresult->month); |
---|
440 | $text = sprintf(__('%1$s %2$d'), $wp_locale->get_month($arcresult->month), $arcresult->year); |
---|
441 | if ( $show_post_count ) |
---|
442 | $after = ' ('.$arcresult->posts.')' . $afterafter; |
---|
443 | echo get_archives_link($url, $text, $format, $before, $after); |
---|
444 | } |
---|
445 | } |
---|
446 | } elseif ('yearly' == $type) { |
---|
447 | $query = "SELECT DISTINCT YEAR(post_date) AS `year`, count(ID) as posts FROM $wpdb->posts $join $where GROUP BY YEAR(post_date) ORDER BY post_date DESC $limit"; |
---|
448 | $key = md5($query); |
---|
449 | $cache = wp_cache_get( 'wp_get_archives' , 'general'); |
---|
450 | if ( !isset( $cache[ $key ] ) ) { |
---|
451 | $arcresults = $wpdb->get_results($query); |
---|
452 | $cache[ $key ] = $arcresults; |
---|
453 | wp_cache_add( 'wp_get_archives', $cache, 'general' ); |
---|
454 | } else { |
---|
455 | $arcresults = $cache[ $key ]; |
---|
456 | } |
---|
457 | if ($arcresults) { |
---|
458 | $afterafter = $after; |
---|
459 | foreach ($arcresults as $arcresult) { |
---|
460 | $url = get_year_link($arcresult->year); |
---|
461 | $text = sprintf('%d', $arcresult->year); |
---|
462 | if ($show_post_count) |
---|
463 | $after = ' ('.$arcresult->posts.')' . $afterafter; |
---|
464 | echo get_archives_link($url, $text, $format, $before, $after); |
---|
465 | } |
---|
466 | } |
---|
467 | } elseif ( 'daily' == $type ) { |
---|
468 | $query = "SELECT DISTINCT YEAR(post_date) AS `year`, MONTH(post_date) AS `month`, DAYOFMONTH(post_date) AS `dayofmonth`, count(ID) as posts FROM $wpdb->posts $join $where GROUP BY YEAR(post_date), MONTH(post_date), DAYOFMONTH(post_date) ORDER BY post_date DESC $limit"; |
---|
469 | $key = md5($query); |
---|
470 | $cache = wp_cache_get( 'wp_get_archives' , 'general'); |
---|
471 | if ( !isset( $cache[ $key ] ) ) { |
---|
472 | $arcresults = $wpdb->get_results($query); |
---|
473 | $cache[ $key ] = $arcresults; |
---|
474 | wp_cache_add( 'wp_get_archives', $cache, 'general' ); |
---|
475 | } else { |
---|
476 | $arcresults = $cache[ $key ]; |
---|
477 | } |
---|
478 | if ( $arcresults ) { |
---|
479 | $afterafter = $after; |
---|
480 | foreach ( $arcresults as $arcresult ) { |
---|
481 | $url = get_day_link($arcresult->year, $arcresult->month, $arcresult->dayofmonth); |
---|
482 | $date = sprintf('%1$d-%2$02d-%3$02d 00:00:00', $arcresult->year, $arcresult->month, $arcresult->dayofmonth); |
---|
483 | $text = mysql2date($archive_day_date_format, $date); |
---|
484 | if ($show_post_count) |
---|
485 | $after = ' ('.$arcresult->posts.')'.$afterafter; |
---|
486 | echo get_archives_link($url, $text, $format, $before, $after); |
---|
487 | } |
---|
488 | } |
---|
489 | } elseif ( 'weekly' == $type ) { |
---|
490 | $start_of_week = get_option('start_of_week'); |
---|
491 | $query = "SELECT DISTINCT WEEK(post_date, $start_of_week) AS `week`, YEAR(post_date) AS yr, DATE_FORMAT(post_date, '%Y-%m-%d') AS yyyymmdd, count(ID) as posts FROM $wpdb->posts $join $where GROUP BY WEEK(post_date, $start_of_week), YEAR(post_date) ORDER BY post_date DESC $limit"; |
---|
492 | $key = md5($query); |
---|
493 | $cache = wp_cache_get( 'wp_get_archives' , 'general'); |
---|
494 | if ( !isset( $cache[ $key ] ) ) { |
---|
495 | $arcresults = $wpdb->get_results($query); |
---|
496 | $cache[ $key ] = $arcresults; |
---|
497 | wp_cache_add( 'wp_get_archives', $cache, 'general' ); |
---|
498 | } else { |
---|
499 | $arcresults = $cache[ $key ]; |
---|
500 | } |
---|
501 | $arc_w_last = ''; |
---|
502 | $afterafter = $after; |
---|
503 | if ( $arcresults ) { |
---|
504 | foreach ( $arcresults as $arcresult ) { |
---|
505 | if ( $arcresult->week != $arc_w_last ) { |
---|
506 | $arc_year = $arcresult->yr; |
---|
507 | $arc_w_last = $arcresult->week; |
---|
508 | $arc_week = get_weekstartend($arcresult->yyyymmdd, get_option('start_of_week')); |
---|
509 | $arc_week_start = date_i18n($archive_week_start_date_format, $arc_week['start']); |
---|
510 | $arc_week_end = date_i18n($archive_week_end_date_format, $arc_week['end']); |
---|
511 | $url = sprintf('%1$s/%2$s%3$sm%4$s%5$s%6$sw%7$s%8$d', get_option('home'), '', '?', '=', $arc_year, '&', '=', $arcresult->week); |
---|
512 | $text = $arc_week_start . $archive_week_separator . $arc_week_end; |
---|
513 | if ($show_post_count) |
---|
514 | $after = ' ('.$arcresult->posts.')'.$afterafter; |
---|
515 | echo get_archives_link($url, $text, $format, $before, $after); |
---|
516 | } |
---|
517 | } |
---|
518 | } |
---|
519 | } elseif ( ( 'postbypost' == $type ) || ('alpha' == $type) ) { |
---|
520 | ('alpha' == $type) ? $orderby = "post_title ASC " : $orderby = "post_date DESC "; |
---|
521 | $query = "SELECT * FROM $wpdb->posts $join $where ORDER BY $orderby $limit"; |
---|
522 | $key = md5($query); |
---|
523 | $cache = wp_cache_get( 'wp_get_archives' , 'general'); |
---|
524 | if ( !isset( $cache[ $key ] ) ) { |
---|
525 | $arcresults = $wpdb->get_results($query); |
---|
526 | $cache[ $key ] = $arcresults; |
---|
527 | wp_cache_add( 'wp_get_archives', $cache, 'general' ); |
---|
528 | } else { |
---|
529 | $arcresults = $cache[ $key ]; |
---|
530 | } |
---|
531 | if ( $arcresults ) { |
---|
532 | foreach ( $arcresults as $arcresult ) { |
---|
533 | if ( $arcresult->post_date != '0000-00-00 00:00:00' ) { |
---|
534 | $url = get_permalink($arcresult); |
---|
535 | $arc_title = $arcresult->post_title; |
---|
536 | if ( $arc_title ) |
---|
537 | $text = strip_tags(apply_filters('the_title', $arc_title)); |
---|
538 | else |
---|
539 | $text = $arcresult->ID; |
---|
540 | echo get_archives_link($url, $text, $format, $before, $after); |
---|
541 | } |
---|
542 | } |
---|
543 | } |
---|
544 | } |
---|
545 | } |
---|
546 | |
---|
547 | |
---|
548 | // Used in get_calendar |
---|
549 | function calendar_week_mod($num) { |
---|
550 | $base = 7; |
---|
551 | return ($num - $base*floor($num/$base)); |
---|
552 | } |
---|
553 | |
---|
554 | |
---|
555 | function get_calendar($initial = true) { |
---|
556 | global $wpdb, $m, $monthnum, $year, $wp_locale, $posts; |
---|
557 | |
---|
558 | $key = md5( $m . $monthnum . $year ); |
---|
559 | if ( $cache = wp_cache_get( 'get_calendar', 'calendar' ) ) { |
---|
560 | if ( isset( $cache[ $key ] ) ) { |
---|
561 | echo $cache[ $key ]; |
---|
562 | return; |
---|
563 | } |
---|
564 | } |
---|
565 | |
---|
566 | ob_start(); |
---|
567 | // Quick check. If we have no posts at all, abort! |
---|
568 | if ( !$posts ) { |
---|
569 | $gotsome = $wpdb->get_var("SELECT ID from $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish' ORDER BY post_date DESC LIMIT 1"); |
---|
570 | if ( !$gotsome ) |
---|
571 | return; |
---|
572 | } |
---|
573 | |
---|
574 | if ( isset($_GET['w']) ) |
---|
575 | $w = ''.intval($_GET['w']); |
---|
576 | |
---|
577 | // week_begins = 0 stands for Sunday |
---|
578 | $week_begins = intval(get_option('start_of_week')); |
---|
579 | |
---|
580 | // Let's figure out when we are |
---|
581 | if ( !empty($monthnum) && !empty($year) ) { |
---|
582 | $thismonth = ''.zeroise(intval($monthnum), 2); |
---|
583 | $thisyear = ''.intval($year); |
---|
584 | } elseif ( !empty($w) ) { |
---|
585 | // We need to get the month from MySQL |
---|
586 | $thisyear = ''.intval(substr($m, 0, 4)); |
---|
587 | $d = (($w - 1) * 7) + 6; //it seems MySQL's weeks disagree with PHP's |
---|
588 | $thismonth = $wpdb->get_var("SELECT DATE_FORMAT((DATE_ADD('${thisyear}0101', INTERVAL $d DAY) ), '%m')"); |
---|
589 | } elseif ( !empty($m) ) { |
---|
590 | $thisyear = ''.intval(substr($m, 0, 4)); |
---|
591 | if ( strlen($m) < 6 ) |
---|
592 | $thismonth = '01'; |
---|
593 | else |
---|
594 | $thismonth = ''.zeroise(intval(substr($m, 4, 2)), 2); |
---|
595 | } else { |
---|
596 | $thisyear = gmdate('Y', current_time('timestamp')); |
---|
597 | $thismonth = gmdate('m', current_time('timestamp')); |
---|
598 | } |
---|
599 | |
---|
600 | $unixmonth = mktime(0, 0 , 0, $thismonth, 1, $thisyear); |
---|
601 | |
---|
602 | // Get the next and previous month and year with at least one post |
---|
603 | $previous = $wpdb->get_row("SELECT DISTINCT MONTH(post_date) AS month, YEAR(post_date) AS year |
---|
604 | FROM $wpdb->posts |
---|
605 | WHERE post_date < '$thisyear-$thismonth-01' |
---|
606 | AND post_type = 'post' AND post_status = 'publish' |
---|
607 | ORDER BY post_date DESC |
---|
608 | LIMIT 1"); |
---|
609 | $next = $wpdb->get_row("SELECT DISTINCT MONTH(post_date) AS month, YEAR(post_date) AS year |
---|
610 | FROM $wpdb->posts |
---|
611 | WHERE post_date > '$thisyear-$thismonth-01' |
---|
612 | AND MONTH( post_date ) != MONTH( '$thisyear-$thismonth-01' ) |
---|
613 | AND post_type = 'post' AND post_status = 'publish' |
---|
614 | ORDER BY post_date ASC |
---|
615 | LIMIT 1"); |
---|
616 | |
---|
617 | echo '<table id="wp-calendar" summary="' . __('Calendar') . '"> |
---|
618 | <caption>' . sprintf(_c('%1$s %2$s|Used as a calendar caption'), $wp_locale->get_month($thismonth), date('Y', $unixmonth)) . '</caption> |
---|
619 | <thead> |
---|
620 | <tr>'; |
---|
621 | |
---|
622 | $myweek = array(); |
---|
623 | |
---|
624 | for ( $wdcount=0; $wdcount<=6; $wdcount++ ) { |
---|
625 | $myweek[] = $wp_locale->get_weekday(($wdcount+$week_begins)%7); |
---|
626 | } |
---|
627 | |
---|
628 | foreach ( $myweek as $wd ) { |
---|
629 | $day_name = (true == $initial) ? $wp_locale->get_weekday_initial($wd) : $wp_locale->get_weekday_abbrev($wd); |
---|
630 | echo "\n\t\t<th abbr=\"$wd\" scope=\"col\" title=\"$wd\">$day_name</th>"; |
---|
631 | } |
---|
632 | |
---|
633 | echo ' |
---|
634 | </tr> |
---|
635 | </thead> |
---|
636 | |
---|
637 | <tfoot> |
---|
638 | <tr>'; |
---|
639 | |
---|
640 | if ( $previous ) { |
---|
641 | echo "\n\t\t".'<td abbr="' . $wp_locale->get_month($previous->month) . '" colspan="3" id="prev"><a href="' . |
---|
642 | get_month_link($previous->year, $previous->month) . '" title="' . sprintf(__('View posts for %1$s %2$s'), $wp_locale->get_month($previous->month), |
---|
643 | date('Y', mktime(0, 0 , 0, $previous->month, 1, $previous->year))) . '">« ' . $wp_locale->get_month_abbrev($wp_locale->get_month($previous->month)) . '</a></td>'; |
---|
644 | } else { |
---|
645 | echo "\n\t\t".'<td colspan="3" id="prev" class="pad"> </td>'; |
---|
646 | } |
---|
647 | |
---|
648 | echo "\n\t\t".'<td class="pad"> </td>'; |
---|
649 | |
---|
650 | if ( $next ) { |
---|
651 | echo "\n\t\t".'<td abbr="' . $wp_locale->get_month($next->month) . '" colspan="3" id="next"><a href="' . |
---|
652 | get_month_link($next->year, $next->month) . '" title="' . sprintf(__('View posts for %1$s %2$s'), $wp_locale->get_month($next->month), |
---|
653 | date('Y', mktime(0, 0 , 0, $next->month, 1, $next->year))) . '">' . $wp_locale->get_month_abbrev($wp_locale->get_month($next->month)) . ' »</a></td>'; |
---|
654 | } else { |
---|
655 | echo "\n\t\t".'<td colspan="3" id="next" class="pad"> </td>'; |
---|
656 | } |
---|
657 | |
---|
658 | echo ' |
---|
659 | </tr> |
---|
660 | </tfoot> |
---|
661 | |
---|
662 | <tbody> |
---|
663 | <tr>'; |
---|
664 | |
---|
665 | // Get days with posts |
---|
666 | $dayswithposts = $wpdb->get_results("SELECT DISTINCT DAYOFMONTH(post_date) |
---|
667 | FROM $wpdb->posts WHERE MONTH(post_date) = '$thismonth' |
---|
668 | AND YEAR(post_date) = '$thisyear' |
---|
669 | AND post_type = 'post' AND post_status = 'publish' |
---|
670 | AND post_date < '" . current_time('mysql') . '\'', ARRAY_N); |
---|
671 | if ( $dayswithposts ) { |
---|
672 | foreach ( $dayswithposts as $daywith ) { |
---|
673 | $daywithpost[] = $daywith[0]; |
---|
674 | } |
---|
675 | } else { |
---|
676 | $daywithpost = array(); |
---|
677 | } |
---|
678 | |
---|
679 | if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false || strpos(strtolower($_SERVER['HTTP_USER_AGENT']), 'camino') !== false || strpos(strtolower($_SERVER['HTTP_USER_AGENT']), 'safari') !== false) |
---|
680 | $ak_title_separator = "\n"; |
---|
681 | else |
---|
682 | $ak_title_separator = ', '; |
---|
683 | |
---|
684 | $ak_titles_for_day = array(); |
---|
685 | $ak_post_titles = $wpdb->get_results("SELECT post_title, DAYOFMONTH(post_date) as dom " |
---|
686 | ."FROM $wpdb->posts " |
---|
687 | ."WHERE YEAR(post_date) = '$thisyear' " |
---|
688 | ."AND MONTH(post_date) = '$thismonth' " |
---|
689 | ."AND post_date < '".current_time('mysql')."' " |
---|
690 | ."AND post_type = 'post' AND post_status = 'publish'" |
---|
691 | ); |
---|
692 | if ( $ak_post_titles ) { |
---|
693 | foreach ( $ak_post_titles as $ak_post_title ) { |
---|
694 | |
---|
695 | $post_title = apply_filters( "the_title", $ak_post_title->post_title ); |
---|
696 | $post_title = str_replace('"', '"', wptexturize( $post_title )); |
---|
697 | |
---|
698 | if ( empty($ak_titles_for_day['day_'.$ak_post_title->dom]) ) |
---|
699 | $ak_titles_for_day['day_'.$ak_post_title->dom] = ''; |
---|
700 | if ( empty($ak_titles_for_day["$ak_post_title->dom"]) ) // first one |
---|
701 | $ak_titles_for_day["$ak_post_title->dom"] = $post_title; |
---|
702 | else |
---|
703 | $ak_titles_for_day["$ak_post_title->dom"] .= $ak_title_separator . $post_title; |
---|
704 | } |
---|
705 | } |
---|
706 | |
---|
707 | |
---|
708 | // See how much we should pad in the beginning |
---|
709 | $pad = calendar_week_mod(date('w', $unixmonth)-$week_begins); |
---|
710 | if ( 0 != $pad ) |
---|
711 | echo "\n\t\t".'<td colspan="'.$pad.'" class="pad"> </td>'; |
---|
712 | |
---|
713 | $daysinmonth = intval(date('t', $unixmonth)); |
---|
714 | for ( $day = 1; $day <= $daysinmonth; ++$day ) { |
---|
715 | if ( isset($newrow) && $newrow ) |
---|
716 | echo "\n\t</tr>\n\t<tr>\n\t\t"; |
---|
717 | $newrow = false; |
---|
718 | |
---|
719 | if ( $day == gmdate('j', (time() + (get_option('gmt_offset') * 3600))) && $thismonth == gmdate('m', time()+(get_option('gmt_offset') * 3600)) && $thisyear == gmdate('Y', time()+(get_option('gmt_offset') * 3600)) ) |
---|
720 | echo '<td id="today">'; |
---|
721 | else |
---|
722 | echo '<td>'; |
---|
723 | |
---|
724 | if ( in_array($day, $daywithpost) ) // any posts today? |
---|
725 | echo '<a href="' . get_day_link($thisyear, $thismonth, $day) . "\" title=\"$ak_titles_for_day[$day]\">$day</a>"; |
---|
726 | else |
---|
727 | echo $day; |
---|
728 | echo '</td>'; |
---|
729 | |
---|
730 | if ( 6 == calendar_week_mod(date('w', mktime(0, 0 , 0, $thismonth, $day, $thisyear))-$week_begins) ) |
---|
731 | $newrow = true; |
---|
732 | } |
---|
733 | |
---|
734 | $pad = 7 - calendar_week_mod(date('w', mktime(0, 0 , 0, $thismonth, $day, $thisyear))-$week_begins); |
---|
735 | if ( $pad != 0 && $pad != 7 ) |
---|
736 | echo "\n\t\t".'<td class="pad" colspan="'.$pad.'"> </td>'; |
---|
737 | |
---|
738 | echo "\n\t</tr>\n\t</tbody>\n\t</table>"; |
---|
739 | |
---|
740 | $output = ob_get_contents(); |
---|
741 | ob_end_clean(); |
---|
742 | echo $output; |
---|
743 | $cache[ $key ] = $output; |
---|
744 | wp_cache_set( 'get_calendar', $cache, 'calendar' ); |
---|
745 | } |
---|
746 | |
---|
747 | function delete_get_calendar_cache() { |
---|
748 | wp_cache_delete( 'get_calendar', 'calendar' ); |
---|
749 | } |
---|
750 | add_action( 'save_post', 'delete_get_calendar_cache' ); |
---|
751 | add_action( 'delete_post', 'delete_get_calendar_cache' ); |
---|
752 | add_action( 'update_option_start_of_week', 'delete_get_calendar_cache' ); |
---|
753 | add_action( 'update_option_gmt_offset', 'delete_get_calendar_cache' ); |
---|
754 | add_action( 'update_option_start_of_week', 'delete_get_calendar_cache' ); |
---|
755 | |
---|
756 | |
---|
757 | function allowed_tags() { |
---|
758 | global $allowedtags; |
---|
759 | $allowed = ''; |
---|
760 | foreach ( $allowedtags as $tag => $attributes ) { |
---|
761 | $allowed .= '<'.$tag; |
---|
762 | if ( 0 < count($attributes) ) { |
---|
763 | foreach ( $attributes as $attribute => $limits ) { |
---|
764 | $allowed .= ' '.$attribute.'=""'; |
---|
765 | } |
---|
766 | } |
---|
767 | $allowed .= '> '; |
---|
768 | } |
---|
769 | return htmlentities($allowed); |
---|
770 | } |
---|
771 | |
---|
772 | |
---|
773 | /***** Date/Time tags *****/ |
---|
774 | |
---|
775 | |
---|
776 | function the_date_xml() { |
---|
777 | global $post; |
---|
778 | echo mysql2date('Y-m-d', $post->post_date); |
---|
779 | //echo ""+$post->post_date; |
---|
780 | } |
---|
781 | |
---|
782 | |
---|
783 | function the_date($d='', $before='', $after='', $echo = true) { |
---|
784 | global $post, $day, $previousday; |
---|
785 | $the_date = ''; |
---|
786 | if ( $day != $previousday ) { |
---|
787 | $the_date .= $before; |
---|
788 | if ( $d=='' ) |
---|
789 | $the_date .= mysql2date(get_option('date_format'), $post->post_date); |
---|
790 | else |
---|
791 | $the_date .= mysql2date($d, $post->post_date); |
---|
792 | $the_date .= $after; |
---|
793 | $previousday = $day; |
---|
794 | } |
---|
795 | $the_date = apply_filters('the_date', $the_date, $d, $before, $after); |
---|
796 | if ( $echo ) |
---|
797 | echo $the_date; |
---|
798 | else |
---|
799 | return $the_date; |
---|
800 | } |
---|
801 | |
---|
802 | |
---|
803 | function the_modified_date($d = '') { |
---|
804 | echo apply_filters('the_modified_date', get_the_modified_date($d), $d); |
---|
805 | } |
---|
806 | |
---|
807 | |
---|
808 | function get_the_modified_date($d = '') { |
---|
809 | if ( '' == $d ) |
---|
810 | $the_time = get_post_modified_time(get_option('date_format')); |
---|
811 | else |
---|
812 | $the_time = get_post_modified_time($d); |
---|
813 | return apply_filters('get_the_modified_date', $the_time, $d); |
---|
814 | } |
---|
815 | |
---|
816 | |
---|
817 | function the_time( $d = '' ) { |
---|
818 | echo apply_filters('the_time', get_the_time( $d ), $d); |
---|
819 | } |
---|
820 | |
---|
821 | |
---|
822 | function get_the_time( $d = '' ) { |
---|
823 | if ( '' == $d ) |
---|
824 | $the_time = get_post_time(get_option('time_format')); |
---|
825 | else |
---|
826 | $the_time = get_post_time($d); |
---|
827 | return apply_filters('get_the_time', $the_time, $d); |
---|
828 | } |
---|
829 | |
---|
830 | |
---|
831 | function get_post_time( $d = 'U', $gmt = false ) { // returns timestamp |
---|
832 | global $post; |
---|
833 | if ( $gmt ) |
---|
834 | $time = $post->post_date_gmt; |
---|
835 | else |
---|
836 | $time = $post->post_date; |
---|
837 | |
---|
838 | $time = mysql2date($d, $time); |
---|
839 | return apply_filters('get_post_time', $time, $d, $gmt); |
---|
840 | } |
---|
841 | |
---|
842 | |
---|
843 | function the_modified_time($d = '') { |
---|
844 | echo apply_filters('the_modified_time', get_the_modified_time($d), $d); |
---|
845 | } |
---|
846 | |
---|
847 | |
---|
848 | function get_the_modified_time($d = '') { |
---|
849 | if ( '' == $d ) |
---|
850 | $the_time = get_post_modified_time(get_option('time_format')); |
---|
851 | else |
---|
852 | $the_time = get_post_modified_time($d); |
---|
853 | return apply_filters('get_the_modified_time', $the_time, $d); |
---|
854 | } |
---|
855 | |
---|
856 | |
---|
857 | function get_post_modified_time( $d = 'U', $gmt = false ) { // returns timestamp |
---|
858 | global $post; |
---|
859 | |
---|
860 | if ( $gmt ) |
---|
861 | $time = $post->post_modified_gmt; |
---|
862 | else |
---|
863 | $time = $post->post_modified; |
---|
864 | $time = mysql2date($d, $time); |
---|
865 | |
---|
866 | return apply_filters('get_the_modified_time', $time, $d, $gmt); |
---|
867 | } |
---|
868 | |
---|
869 | |
---|
870 | function the_weekday() { |
---|
871 | global $wp_locale, $post; |
---|
872 | $the_weekday = $wp_locale->get_weekday(mysql2date('w', $post->post_date)); |
---|
873 | $the_weekday = apply_filters('the_weekday', $the_weekday); |
---|
874 | echo $the_weekday; |
---|
875 | } |
---|
876 | |
---|
877 | |
---|
878 | function the_weekday_date($before='',$after='') { |
---|
879 | global $wp_locale, $post, $day, $previousweekday; |
---|
880 | $the_weekday_date = ''; |
---|
881 | if ( $day != $previousweekday ) { |
---|
882 | $the_weekday_date .= $before; |
---|
883 | $the_weekday_date .= $wp_locale->get_weekday(mysql2date('w', $post->post_date)); |
---|
884 | $the_weekday_date .= $after; |
---|
885 | $previousweekday = $day; |
---|
886 | } |
---|
887 | $the_weekday_date = apply_filters('the_weekday_date', $the_weekday_date, $before, $after); |
---|
888 | echo $the_weekday_date; |
---|
889 | } |
---|
890 | |
---|
891 | function wp_head() { |
---|
892 | do_action('wp_head'); |
---|
893 | } |
---|
894 | |
---|
895 | function wp_footer() { |
---|
896 | do_action('wp_footer'); |
---|
897 | } |
---|
898 | |
---|
899 | function rsd_link() { |
---|
900 | echo '<link rel="EditURI" type="application/rsd+xml" title="RSD" href="' . get_bloginfo('wpurl') . "/xmlrpc.php?rsd\" />\n"; |
---|
901 | } |
---|
902 | |
---|
903 | function wlwmanifest_link() { |
---|
904 | echo '<link rel="wlwmanifest" type="application/wlwmanifest+xml" href="' |
---|
905 | . get_bloginfo('wpurl') . '/wp-includes/wlwmanifest.xml" /> ' . "\n"; |
---|
906 | } |
---|
907 | |
---|
908 | function noindex() { |
---|
909 | // If the blog is not public, tell robots to go away. |
---|
910 | if ( '0' == get_option('blog_public') ) |
---|
911 | echo "<meta name='robots' content='noindex,nofollow' />\n"; |
---|
912 | } |
---|
913 | |
---|
914 | function rich_edit_exists() { |
---|
915 | global $wp_rich_edit_exists; |
---|
916 | if ( !isset($wp_rich_edit_exists) ) |
---|
917 | $wp_rich_edit_exists = file_exists(ABSPATH . WPINC . '/js/tinymce/tiny_mce.js'); |
---|
918 | return $wp_rich_edit_exists; |
---|
919 | } |
---|
920 | |
---|
921 | function user_can_richedit() { |
---|
922 | global $wp_rich_edit, $pagenow; |
---|
923 | |
---|
924 | if ( !isset( $wp_rich_edit) ) { |
---|
925 | if ( get_user_option( 'rich_editing' ) == 'true' && |
---|
926 | ( ( preg_match( '!AppleWebKit/(\d+)!', $_SERVER['HTTP_USER_AGENT'], $match ) && intval($match[1]) >= 420 ) || |
---|
927 | !preg_match( '!opera[ /][2-8]|konqueror|safari!i', $_SERVER['HTTP_USER_AGENT'] ) ) |
---|
928 | && 'comment.php' != $pagenow ) { |
---|
929 | $wp_rich_edit = true; |
---|
930 | } else { |
---|
931 | $wp_rich_edit = false; |
---|
932 | } |
---|
933 | } |
---|
934 | |
---|
935 | return apply_filters('user_can_richedit', $wp_rich_edit); |
---|
936 | } |
---|
937 | |
---|
938 | function wp_default_editor() { |
---|
939 | $r = user_can_richedit() ? 'tinymce' : 'html'; // defaults |
---|
940 | if ( $user = wp_get_current_user() ) { // look for cookie |
---|
941 | if ( isset($_COOKIE['wordpress_editor_' . $user->ID]) && in_array($_COOKIE['wordpress_editor_' . $user->ID], array('tinymce', 'html', 'test') ) ) |
---|
942 | $r = $_COOKIE['wordpress_editor_' . $user->ID]; |
---|
943 | } |
---|
944 | return apply_filters( 'wp_default_editor', $r ); // filter |
---|
945 | } |
---|
946 | |
---|
947 | function the_editor($content, $id = 'content', $prev_id = 'title', $media_buttons = true, $tab_index = 2) { |
---|
948 | $rows = get_option('default_post_edit_rows'); |
---|
949 | if (($rows < 3) || ($rows > 100)) |
---|
950 | $rows = 12; |
---|
951 | |
---|
952 | $rows = "rows='$rows'"; ?> |
---|
953 | <div id="editor-toolbar"> |
---|
954 | <?php if ( user_can_richedit() ) { |
---|
955 | $wp_default_editor = wp_default_editor(); ?> |
---|
956 | <div class="zerosize"><input accesskey="e" type="button" onclick="switchEditors.go('<?php echo $id; ?>')" /></div> |
---|
957 | <?php if ( 'tinymce' == $wp_default_editor ) { |
---|
958 | add_filter('the_editor_content', 'wp_richedit_pre'); ?> |
---|
959 | <a id="edButtonHTML" onclick="switchEditors.go('<?php echo $id; ?>');"><?php _e('HTML'); ?></a> |
---|
960 | <a id="edButtonPreview" class="active"><?php _e('Visual'); ?></a> |
---|
961 | <?php } elseif ( 'html' == $wp_default_editor ) { |
---|
962 | add_filter('the_editor_content', 'wp_htmledit_pre'); ?> |
---|
963 | <a id="edButtonHTML" class="active"><?php _e('HTML'); ?></a> |
---|
964 | <a id="edButtonPreview" onclick="switchEditors.go('<?php echo $id; ?>');"><?php _e('Visual'); ?></a> |
---|
965 | <?php } |
---|
966 | } |
---|
967 | |
---|
968 | if ( $media_buttons ) { ?> |
---|
969 | <div id="media-buttons" class="hide-if-no-js"> |
---|
970 | <?php do_action( 'media_buttons' ); ?> |
---|
971 | </div> |
---|
972 | <?php } ?> |
---|
973 | </div> |
---|
974 | |
---|
975 | <div id="quicktags"> |
---|
976 | <?php wp_print_scripts( 'quicktags' ); ?> |
---|
977 | <script type="text/javascript">edToolbar()</script> |
---|
978 | </div> |
---|
979 | |
---|
980 | <?php if ( 'html' != $wp_default_editor ) : ?> |
---|
981 | <script type="text/javascript"> |
---|
982 | // <![CDATA[ |
---|
983 | if ( typeof tinyMCE != "undefined" ) |
---|
984 | document.getElementById("quicktags").style.display="none"; |
---|
985 | // ]]> |
---|
986 | </script> |
---|
987 | <?php endif; // 'html' != $wp_default_editor |
---|
988 | |
---|
989 | $the_editor = apply_filters('the_editor', "<div id='editorcontainer'><textarea class='' $rows cols='40' name='$id' tabindex='$tab_index' id='$id'>%s</textarea></div>\n"); |
---|
990 | $the_editor_content = apply_filters('the_editor_content', $content); |
---|
991 | |
---|
992 | printf($the_editor, $the_editor_content); |
---|
993 | |
---|
994 | ?> |
---|
995 | <script type="text/javascript"> |
---|
996 | // <![CDATA[ |
---|
997 | edCanvas = document.getElementById('<?php echo $id; ?>'); |
---|
998 | <?php if ( $prev_id && user_can_richedit() ) : ?> |
---|
999 | // If tinyMCE is defined. |
---|
1000 | if ( typeof tinyMCE != 'undefined' ) { |
---|
1001 | // This code is meant to allow tabbing from Title to Post (TinyMCE). |
---|
1002 | document.getElementById('<?php echo $prev_id; ?>').onkeydown = function (e) { |
---|
1003 | e = e || window.event; |
---|
1004 | if (e.keyCode == 9 && !e.shiftKey && !e.controlKey && !e.altKey) { |
---|
1005 | if ( tinyMCE.activeEditor ) { |
---|
1006 | if ( (jQuery("#post_ID").val() < 1) && (jQuery("#title").val().length > 0) ) { autosave(); } |
---|
1007 | e = null; |
---|
1008 | if ( tinyMCE.activeEditor.isHidden() ) return true; |
---|
1009 | tinyMCE.activeEditor.focus(); |
---|
1010 | return false; |
---|
1011 | } |
---|
1012 | return true; |
---|
1013 | } |
---|
1014 | } |
---|
1015 | } |
---|
1016 | <?php endif; ?> |
---|
1017 | // ]]> |
---|
1018 | </script> |
---|
1019 | <?php |
---|
1020 | } |
---|
1021 | |
---|
1022 | function get_search_query() { |
---|
1023 | return apply_filters( 'get_search_query', stripslashes( get_query_var( 's' ) ) ); |
---|
1024 | } |
---|
1025 | |
---|
1026 | function the_search_query() { |
---|
1027 | echo attribute_escape( apply_filters( 'the_search_query', get_search_query() ) ); |
---|
1028 | } |
---|
1029 | |
---|
1030 | function language_attributes($doctype = 'html') { |
---|
1031 | $attributes = array(); |
---|
1032 | $output = ''; |
---|
1033 | |
---|
1034 | if ( $dir = get_bloginfo('text_direction') ) |
---|
1035 | $attributes[] = "dir=\"$dir\""; |
---|
1036 | |
---|
1037 | if ( $lang = get_bloginfo('language') ) { |
---|
1038 | if ( get_option('html_type') == 'text/html' || $doctype == 'xhtml' ) |
---|
1039 | $attributes[] = "lang=\"$lang\""; |
---|
1040 | |
---|
1041 | if ( get_option('html_type') != 'text/html' || $doctype == 'xhtml' ) |
---|
1042 | $attributes[] = "xml:lang=\"$lang\""; |
---|
1043 | } |
---|
1044 | |
---|
1045 | $output = implode(' ', $attributes); |
---|
1046 | $output = apply_filters('language_attributes', $output); |
---|
1047 | echo $output; |
---|
1048 | } |
---|
1049 | |
---|
1050 | function paginate_links( $args = '' ) { |
---|
1051 | $defaults = array( |
---|
1052 | 'base' => '%_%', // http://example.com/all_posts.php%_% : %_% is replaced by format (below) |
---|
1053 | 'format' => '?page=%#%', // ?page=%#% : %#% is replaced by the page number |
---|
1054 | 'total' => 1, |
---|
1055 | 'current' => 0, |
---|
1056 | 'show_all' => false, |
---|
1057 | 'prev_next' => true, |
---|
1058 | 'prev_text' => __('« Previous'), |
---|
1059 | 'next_text' => __('Next »'), |
---|
1060 | 'end_size' => 1, // How many numbers on either end including the end |
---|
1061 | 'mid_size' => 2, // How many numbers to either side of current not including current |
---|
1062 | 'type' => 'plain', |
---|
1063 | 'add_args' => false // array of query args to aadd |
---|
1064 | ); |
---|
1065 | |
---|
1066 | $args = wp_parse_args( $args, $defaults ); |
---|
1067 | extract($args, EXTR_SKIP); |
---|
1068 | |
---|
1069 | // Who knows what else people pass in $args |
---|
1070 | $total = (int) $total; |
---|
1071 | if ( $total < 2 ) |
---|
1072 | return; |
---|
1073 | $current = (int) $current; |
---|
1074 | $end_size = 0 < (int) $end_size ? (int) $end_size : 1; // Out of bounds? Make it the default. |
---|
1075 | $mid_size = 0 <= (int) $mid_size ? (int) $mid_size : 2; |
---|
1076 | $add_args = is_array($add_args) ? $add_args : false; |
---|
1077 | $r = ''; |
---|
1078 | $page_links = array(); |
---|
1079 | $n = 0; |
---|
1080 | $dots = false; |
---|
1081 | |
---|
1082 | if ( $prev_next && $current && 1 < $current ) : |
---|
1083 | $link = str_replace('%_%', 2 == $current ? '' : $format, $base); |
---|
1084 | $link = str_replace('%#%', $current - 1, $link); |
---|
1085 | if ( $add_args ) |
---|
1086 | $link = add_query_arg( $add_args, $link ); |
---|
1087 | $page_links[] = "<a class='prev page-numbers' href='" . clean_url($link) . "'>$prev_text</a>"; |
---|
1088 | endif; |
---|
1089 | for ( $n = 1; $n <= $total; $n++ ) : |
---|
1090 | if ( $n == $current ) : |
---|
1091 | $page_links[] = "<span class='page-numbers current'>$n</span>"; |
---|
1092 | $dots = true; |
---|
1093 | else : |
---|
1094 | if ( $show_all || ( $n <= $end_size || ( $current && $n >= $current - $mid_size && $n <= $current + $mid_size ) || $n > $total - $end_size ) ) : |
---|
1095 | $link = str_replace('%_%', 1 == $n ? '' : $format, $base); |
---|
1096 | $link = str_replace('%#%', $n, $link); |
---|
1097 | if ( $add_args ) |
---|
1098 | $link = add_query_arg( $add_args, $link ); |
---|
1099 | $page_links[] = "<a class='page-numbers' href='" . clean_url($link) . "'>$n</a>"; |
---|
1100 | $dots = true; |
---|
1101 | elseif ( $dots && !$show_all ) : |
---|
1102 | $page_links[] = "<span class='page-numbers dots'>...</span>"; |
---|
1103 | $dots = false; |
---|
1104 | endif; |
---|
1105 | endif; |
---|
1106 | endfor; |
---|
1107 | if ( $prev_next && $current && ( $current < $total || -1 == $total ) ) : |
---|
1108 | $link = str_replace('%_%', $format, $base); |
---|
1109 | $link = str_replace('%#%', $current + 1, $link); |
---|
1110 | if ( $add_args ) |
---|
1111 | $link = add_query_arg( $add_args, $link ); |
---|
1112 | $page_links[] = "<a class='next page-numbers' href='" . clean_url($link) . "'>$next_text</a>"; |
---|
1113 | endif; |
---|
1114 | switch ( $type ) : |
---|
1115 | case 'array' : |
---|
1116 | return $page_links; |
---|
1117 | break; |
---|
1118 | case 'list' : |
---|
1119 | $r .= "<ul class='page-numbers'>\n\t<li>"; |
---|
1120 | $r .= join("</li>\n\t<li>", $page_links); |
---|
1121 | $r .= "</li>\n</ul>\n"; |
---|
1122 | break; |
---|
1123 | default : |
---|
1124 | $r = join("\n", $page_links); |
---|
1125 | break; |
---|
1126 | endswitch; |
---|
1127 | return $r; |
---|
1128 | } |
---|
1129 | |
---|
1130 | function wp_admin_css_color($key, $name, $url, $colors = array()) { |
---|
1131 | global $_wp_admin_css_colors; |
---|
1132 | |
---|
1133 | if ( !isset($_wp_admin_css_colors) ) |
---|
1134 | $_wp_admin_css_colors = array(); |
---|
1135 | |
---|
1136 | $_wp_admin_css_colors[$key] = (object) array('name' => $name, 'url' => $url, 'colors' => $colors); |
---|
1137 | } |
---|
1138 | |
---|
1139 | /** |
---|
1140 | * wp_admin_css_uri() - Outputs the URL of a WordPress admin CSS file |
---|
1141 | * |
---|
1142 | * @see WP_Styles::_css_href and its style_loader_src filter. |
---|
1143 | * |
---|
1144 | * @param string $file file relative to wp-admin/ without its ".css" extension. |
---|
1145 | */ |
---|
1146 | |
---|
1147 | function wp_admin_css_uri( $file = 'wp-admin' ) { |
---|
1148 | if ( defined('WP_INSTALLING') ) { |
---|
1149 | $_file = "./$file.css"; |
---|
1150 | } else { |
---|
1151 | $_file = admin_url("$file.css"); |
---|
1152 | } |
---|
1153 | $_file = add_query_arg( 'version', get_bloginfo( 'version' ), $_file ); |
---|
1154 | |
---|
1155 | return apply_filters( 'wp_admin_css_uri', $_file, $file ); |
---|
1156 | } |
---|
1157 | |
---|
1158 | /** |
---|
1159 | * wp_admin_css() - Enqueues or directly prints a stylesheet link to the specified CSS file. |
---|
1160 | * |
---|
1161 | * "Intelligently" decides to enqueue or to print the CSS file. |
---|
1162 | * If the wp_print_styles action has *not* yet been called, the CSS file will be enqueued. |
---|
1163 | * If the wp_print_styles action *has* been called, the CSS link will be printed. |
---|
1164 | * Printing may be forced by passing TRUE as the $force_echo (second) parameter. |
---|
1165 | * |
---|
1166 | * For backward compatibility with WordPress 2.3 calling method: |
---|
1167 | * If the $file (first) parameter does not correspond to a registered CSS file, we assume $file is a |
---|
1168 | * file relative to wp-admin/ without its ".css" extension. A stylesheet link to that generated URL is printed. |
---|
1169 | * |
---|
1170 | * @package WordPress |
---|
1171 | * @since 2.3 |
---|
1172 | * |
---|
1173 | * @uses $wp_styles WordPress Styles Object |
---|
1174 | * |
---|
1175 | * @param string $file Style handle name or file name (without ".css" extension) relative to wp-admin/ |
---|
1176 | * @param bool $force_echo Optional. Force the stylesheet link to be printed rather than enqueued. |
---|
1177 | */ |
---|
1178 | |
---|
1179 | function wp_admin_css( $file = 'wp-admin', $force_echo = false ) { |
---|
1180 | global $wp_styles; |
---|
1181 | if ( !is_a($wp_styles, 'WP_Styles') ) |
---|
1182 | $wp_styles = new WP_Styles(); |
---|
1183 | |
---|
1184 | // For backward compatibility |
---|
1185 | $handle = 0 === strpos( $file, 'css/' ) ? substr( $file, 4 ) : $file; |
---|
1186 | |
---|
1187 | if ( $wp_styles->query( $handle ) ) { |
---|
1188 | if ( $force_echo || did_action( 'wp_print_styles' ) ) // we already printed the style queue. Print this one immediately |
---|
1189 | wp_print_styles( $handle ); |
---|
1190 | else // Add to style queue |
---|
1191 | wp_enqueue_style( $handle ); |
---|
1192 | return; |
---|
1193 | } |
---|
1194 | |
---|
1195 | echo apply_filters( 'wp_admin_css', "<link rel='stylesheet' href='" . clean_url( wp_admin_css_uri( $file ) ) . "' type='text/css' />\n", $file ); |
---|
1196 | if ( 'rtl' == get_bloginfo( 'text_direction' ) ) |
---|
1197 | echo apply_filters( 'wp_admin_css', "<link rel='stylesheet' href='" . clean_url( wp_admin_css_uri( "$file-rtl" ) ) . "' type='text/css' />\n", "$file-rtl" ); |
---|
1198 | } |
---|
1199 | |
---|
1200 | /** |
---|
1201 | * Enqueues the default ThickBox js and css. |
---|
1202 | * If any of the settings need to be changed, this can be done with another js file |
---|
1203 | * similar to media-upload.js and theme-preview.js. That file should require array('thickbox') |
---|
1204 | * to ensure it is loaded after. |
---|
1205 | */ |
---|
1206 | function add_thickbox() { |
---|
1207 | wp_enqueue_script( 'thickbox' ); |
---|
1208 | wp_enqueue_style( 'thickbox' ); |
---|
1209 | } |
---|
1210 | |
---|
1211 | /** |
---|
1212 | * Outputs the XHTML generator that is generated on the wp_head hook. |
---|
1213 | */ |
---|
1214 | function wp_generator() |
---|
1215 | { |
---|
1216 | the_generator( apply_filters( 'wp_generator_type', 'xhtml' ) ); |
---|
1217 | } |
---|
1218 | |
---|
1219 | /** |
---|
1220 | * Outputs the generator XML or Comment for RSS, ATOM, etc. |
---|
1221 | * @param {String} $type The type of generator to return. |
---|
1222 | */ |
---|
1223 | function the_generator ( $type ) { |
---|
1224 | echo apply_filters('the_generator',get_the_generator($type),$type) . "\n"; |
---|
1225 | } |
---|
1226 | |
---|
1227 | /** |
---|
1228 | * Creates the generator XML or Comment for RSS, ATOM, etc. |
---|
1229 | * @param {String} $type The type of generator to return. |
---|
1230 | */ |
---|
1231 | function get_the_generator ( $type ) { |
---|
1232 | switch ($type) { |
---|
1233 | case 'html': |
---|
1234 | $gen = '<meta name="generator" content="WordPress ' . get_bloginfo( 'version' ) . '">' . "\n"; |
---|
1235 | break; |
---|
1236 | case 'xhtml': |
---|
1237 | $gen = '<meta name="generator" content="WordPress ' . get_bloginfo( 'version' ) . '" />' . "\n"; |
---|
1238 | break; |
---|
1239 | case 'atom': |
---|
1240 | $gen = '<generator uri="http://wordpress.org/" version="' . get_bloginfo_rss( 'version' ) . '">WordPress</generator>'; |
---|
1241 | break; |
---|
1242 | case 'rss2': |
---|
1243 | $gen = '<generator>http://wordpress.org/?v=' . get_bloginfo_rss( 'version' ) . '</generator>'; |
---|
1244 | break; |
---|
1245 | case 'rdf': |
---|
1246 | $gen = '<admin:generatorAgent rdf:resource="http://wordpress.org/?v=' . get_bloginfo_rss( 'version' ) . '" />'; |
---|
1247 | break; |
---|
1248 | case 'comment': |
---|
1249 | $gen = '<!-- generator="WordPress/' . get_bloginfo( 'version' ) . '" -->'; |
---|
1250 | break; |
---|
1251 | case 'export': |
---|
1252 | $gen = '<!-- generator="WordPress/' . get_bloginfo_rss('version') . '" created="'. date('Y-m-d H:i') . '"-->'; |
---|
1253 | break; |
---|
1254 | } |
---|
1255 | return apply_filters( "get_the_generator_{$type}", $gen, $type ); |
---|
1256 | } |
---|
1257 | ?> |
---|