ma38su / wp.vicuna.ext

This URL has Read+Write access

ma38su (author)
Thu Dec 11 08:55:33 -0800 2008
wp.vicuna.ext / functions.php
833b10df » ma38su 2008-12-11 ver.1.58 1 <?php
2 /**
3 * function.php for wp.Vicuna
4 * author: ma38su
5 *
6 * If you want to get the latest feature,
7 * you should connect to http://ma38su.org/.
8 */
9
10 $vicuna_mofile = dirname(__FILE__). '/languages/' . get_vicuna_language() . '.mo';
11 if ($vicuna_mofile) {
12 load_textdomain('vicuna', $vicuna_mofile);
13 }
14
15 require_once(dirname(__FILE__).'/script/config.php');
16
17 require_once(dirname(__FILE__).'/script/layout.php');
18
19 if ( function_exists('register_sidebar') ) {
20 require_once(dirname(__FILE__).'/script/widgets.php');
21 }
22 if (function_exists('get_tags')) {
23 require_once(dirname(__FILE__).'/script/tag.php');
24 }
25
26
27 /**
28 * display vicuna footer link
29 */
30 function vicuna_link() {
31 $locale = get_locale();
32 if ($locale == "ja") {
33 echo 'http://wp.vicuna.jp/';
34 } else if ($locale == "zh_TW" || $locale == "zh_CN") {
35 echo 'http://cn.wp.vicuna.jp/';
36 } else {
37 echo 'http://en.wp.vicuna.jp/';
38 }
39 }
40
41 /**
42 * get current language.
43 */
44 function get_vicuna_language() {
45 $options = get_option('vicuna_config');
46 return $options['language'];
47 }
48
49 /**
50 * display header for vicuna.
51 */
52 function vicuna_head() {
53 $options = get_option('vicuna_config');
54 if ($options['feed_url'] && $options['feed_type']) {
55 ?>
56 <link rel="alternate" type="application/<?php echo $options['feed_type']; ?>" href="<?php bloginfo('atom_url'); ?>" title="Atom cite contents" />
57 <?php } else { ?>
58 <link rel="alternate" type="application/rss+xml" href="<?php bloginfo('rss2_url'); ?>" title="RSS 2.0" />
59 <link rel="alternate" type="application/atom+xml" href="<?php bloginfo('atom_url'); ?>" title="Atom cite contents" />
60 <?php }
61 }
62
63 add_action('wp_head', 'vicuna_head');
64
65 function is_widget($index, $widget_id) {
66 global $wp_registered_sidebars;
67 $index = sanitize_title($index);
68 foreach ( $wp_registered_sidebars as $key => $value ) {
69 if ( sanitize_title($value['name']) == $index ) {
70 $index = $key;
71 break;
72 }
73 }
74 $sidebars_widgets = wp_get_sidebars_widgets();
75
76 if ( !is_array($sidebars_widgets[$index]) || empty($sidebars_widgets[$index])) {
77 return false;
78 }
79
80 foreach ($sidebars_widgets[$index] as $id) {
81 if ($id == $widget_id) {
82 return true;
83 }
84 }
85 return false;
86 }
87
88 /**
89 * Display calendar for Vicuna.
90 */
91 function vicuna_calendar($initial = true) {
92 $weekday = array('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday');
93 global $wpdb, $m, $monthnum, $year, $timedifference, $wp_locale, $posts;
94
95 $key = md5( $m . $monthnum . $year );
96
97 // get cache
98 if ( $cache = wp_cache_get( 'vicuna_calendar', 'calendar' ) ) {
99 if ( isset( $cache[ $key ] ) ) {
100 echo $cache[ $key ];
101 return;
102 }
103 }
104
105 ob_start();
106 // Quick check. If we have no posts at all, abort!
107 if ( !$posts ) {
108 $gotsome = $wpdb->get_var("SELECT ID from $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish' ORDER BY post_date DESC LIMIT 1");
109 if ( !$gotsome )
110 return;
111 }
112
113 if ( isset($_GET['w']) )
114 $w = ''.intval($_GET['w']);
115
116 // week_begins = 0 stands for Sunday
117 $week_begins = intval(get_option('start_of_week'));
118 $add_hours = intval(get_option('gmt_offset'));
119 $add_minutes = intval(60 * (get_option('gmt_offset') - $add_hours));
120
121 // Let's figure out when we are
122 if ( !empty($monthnum) && !empty($year) ) {
123 $thismonth = ''.zeroise(intval($monthnum), 2);
124 $thisyear = ''.intval($year);
125 } elseif ( !empty($w) ) {
126 // We need to get the month from MySQL
127 $thisyear = ''.intval(substr($m, 0, 4));
128 $d = (($w - 1) * 7) + 6; //it seems MySQL's weeks disagree with PHP's
129 $thismonth = $wpdb->get_var("SELECT DATE_FORMAT((DATE_ADD('${thisyear}0101', INTERVAL $d DAY) ), '%m')");
130 } elseif ( !empty($m) ) {
131 $calendar = substr($m, 0, 6);
132 $thisyear = ''.intval(substr($m, 0, 4));
133 if ( strlen($m) < 6 )
134 $thismonth = '01';
135 else
136 $thismonth = ''.zeroise(intval(substr($m, 4, 2)), 2);
137 } else {
138 $thisyear = gmdate('Y', current_time('timestamp'));
139 $thismonth = gmdate('m', current_time('timestamp'));
140 }
141
142 $unixmonth = mktime(0, 0 , 0, $thismonth, 1, $thisyear);
143
144 // Get the next and previous month and year with at least one post
145 $previous = $wpdb->get_row("SELECT DISTINCT MONTH(post_date) AS month, YEAR(post_date) AS year
146 FROM $wpdb->posts
147 WHERE post_date < '$thisyear-$thismonth-01'
148 AND post_type = 'post' AND post_status = 'publish'
149 ORDER BY post_date DESC
150 LIMIT 1");
151 $next = $wpdb->get_row("SELECT DISTINCT MONTH(post_date) AS month, YEAR(post_date) AS year
152 FROM $wpdb->posts
153 WHERE post_date > '$thisyear-$thismonth-01'
154 AND MONTH( post_date ) != MONTH( '$thisyear-$thismonth-01' )
155 AND post_type = 'post' AND post_status = 'publish'
156 ORDER BY post_date ASC
157 LIMIT 1");
158 ?>
159 <table class="calendar" cellpadding="0" cellspacing="0" summary="Monthly calendar">
160 <caption><?php
161 if ( $previous ) {
162 echo '<a href="' . get_month_link($previous->year, $previous->month) . '" title="Older" rel="nofollow">&laquo;</a>';
163 } else {
164 echo '&laquo;';
165 }
166 printf(__(' %1$s %2$s ', 'vicuna'), $wp_locale->get_month($thismonth), date('Y', $unixmonth));
167 if ( $next ) {
168 echo '<a href="' . get_month_link($next->year, $next->month) . '" title="Newer">&raquo;</a>';
169 } else {
170 echo '&raquo;';
171 }
172
173 $myweek = array();
174
175 for ( $wdcount=0; $wdcount<=6; $wdcount++ ) {
176 $myweek[] = $weekday[ ($wdcount + $week_begins) % 7];
177 }
178 ?></caption>
179 <tr>
180 <?php
181 foreach ( $myweek as $wd ) {
182 // $day_name = (true == $initial) ? $wp_locale->get_weekday_initial($wd) : $wp_locale->get_weekday_abbrev($wd);
183 $day_name = mb_substr( $wd, 0, 1 );
184 if ($day_name == "S") {
185 echo "\t\t\t\t\t<th class=\"". strtolower(substr( $wd, 0, 3)) ."\" title=\"".__($wd, 'vicuna')."\">$day_name</th>\n";
186 } else {
187 echo "\t\t\t\t\t<th title=\"".__($wd, 'vicuna')."\">$day_name</th>\n";
188 }
189 }
190 ?>
191 </tr>
192 <tr>
193 <?php
194 // Get days with posts
195 $dayswithposts = $wpdb->get_results("SELECT DISTINCT DAYOFMONTH(post_date)
196 FROM $wpdb->posts WHERE MONTH(post_date) = '$thismonth'
197 AND YEAR(post_date) = '$thisyear'
198 AND post_type = 'post' AND post_status = 'publish'
199 AND post_date < '" . current_time('mysql') . '\'', ARRAY_N);
200 if ( $dayswithposts ) {
201 foreach ( $dayswithposts as $daywith ) {
202 $daywithpost[] = $daywith[0];
203 }
204 } else {
205 $daywithpost = array();
206 }
207
208 if ( strstr($_SERVER['HTTP_USER_AGENT'], 'MSIE') || strstr(strtolower($_SERVER['HTTP_USER_AGENT']), 'camino') || strstr(strtolower($_SERVER['HTTP_USER_AGENT']), 'safari') )
209 $ak_title_separator = "\n";
210 else
211 $ak_title_separator = ', ';
212
213 $ak_titles_for_day = array();
214 $ak_post_titles = $wpdb->get_results("SELECT post_title, DAYOFMONTH(post_date) as dom "
215 ."FROM $wpdb->posts "
216 ."WHERE YEAR(post_date) = '$thisyear' "
217 ."AND MONTH(post_date) = '$thismonth' "
218 ."AND post_date < '".current_time('mysql')."' "
219 ."AND post_type = 'post' AND post_status = 'publish'"
220 );
221 if ( $ak_post_titles ) {
222 foreach ( $ak_post_titles as $ak_post_title ) {
223 if ( empty($ak_titles_for_day['day_'.$ak_post_title->dom]) )
224 $ak_titles_for_day['day_'.$ak_post_title->dom] = '';
225 if ( empty($ak_titles_for_day["$ak_post_title->dom"]) ) // first one
226 $ak_titles_for_day["$ak_post_title->dom"] = str_replace('"', '&quot;', wptexturize($ak_post_title->post_title));
227 else
228 $ak_titles_for_day["$ak_post_title->dom"] .= $ak_title_separator . str_replace('"', '&quot;', wptexturize($ak_post_title->post_title));
229 }
230 }
231
232 // See how much we should pad in the beginning
233 $pad = calendar_week_mod(date('w', $unixmonth)-$week_begins);
234 if ( 0 != $pad ) {
235 for ($i = 0; $i < $pad; $i++)
236 echo "\t\t\t\t\t<td>&nbsp;</td>\n";
237 }
238
239 $daysinmonth = intval(date('t', $unixmonth));
240 for ( $day = 1; $day <= $daysinmonth; ++$day ) {
241 if ( isset($newrow) && $newrow )
242 echo "\n\t\t\t\t</tr>\n\t\t\t\t<tr>\n";
243 $newrow = false;
244
245 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)) )
246 echo "\t\t\t\t\t<td class=\"today\">";
247 else
248 echo "\t\t\t\t\t<td>";
249
250 if ( in_array($day, $daywithpost) ) // any posts today?
251 echo '<a href="' . get_day_link($thisyear, $thismonth, $day) . "\" title=\"$ak_titles_for_day[$day]\">$day</a>";
252 else
253 echo $day;
254 echo "</td>\n";
255
256 if ( 6 == calendar_week_mod(date('w', mktime(0, 0 , 0, $thismonth, $day, $thisyear))-$week_begins) )
257 $newrow = true;
258 }
259
260 $pad = 7 - calendar_week_mod(date('w', mktime(0, 0 , 0, $thismonth, $day, $thisyear))-$week_begins);
261 if ( $pad != 0 && $pad != 7 ) {
262 for ($i = 0; $i < $pad; $i++)
263 echo "\t\t\t\t\t<td>&nbsp;</td>\n";
264 }
265
266 echo "\t\t\t\t</tr>\n\t\t\t</table>\n";
267
268 $output = ob_get_contents();
269 ob_end_clean();
270 echo $output;
271 $cache[ $key ] = $output;
272 wp_cache_set( 'vicuna_calendar', $cache, 'calendar' );
273 }
274
275 /**
276 * Delete cache of calendar
277 */
278 function delete_vicuna_calendar_cache() {
279 wp_cache_delete( 'vicuna_calendar', 'calendar' );
280 }
281 add_action( 'save_post', 'delete_vicuna_calendar_cache' );
282 add_action( 'delete_post', 'delete_vicuna_calendar_cache' );
283 add_action( 'update_option_start_of_week', 'delete_vicuna_calendar_cache' );
284 add_action( 'update_option_gmt_offset', 'delete_vicuna_calendar_cache' );
285
286 /**
287 * Display a description for the blog.
288 */
289 function vicuna_description() {
290 $description = get_bloginfo('description');
291 if ( !empty($description) ) {
292 echo '<p class="description">' . $description . "</p>\n";
293 }
294 }
295
296 /**
297 * Display a pager(Newer | Older).
298 */
299 function vicuna_paging_link($args = '') {
300 global $paged, $wpdb, $wp_query;
301
302 if (is_array($args))
303 $r = &$args;
304 else
305 parse_str($args, $r);
306
307 $defaults = array('next_label' => __('Older Entries', 'vicuna'), 'prev_label' => __('Newer Entries', 'vicuna'), 'indent' => '');
308 $r = array_merge($defaults, $r);
309 extract($r);
310
311 if ($indent != '') {
312 $indent = (int) $indent;
313
314 for ($i = 0; $i < $indent; $i ++)
315 $indentText .= "\t";
316 }
317
318 // get max_page
319 if (!$max_page)
320 $max_page = $wp_query->max_num_pages;
321
322 // get paged
323 if (!$paged)
324 $paged = 1;
325
326 // set next page number
327 $nextpage = intval($paged) + 1;
328
329 if(!is_single()) {
330 if ($max_page > 1)
331 echo "$indentText<ul class=\"flip pager\" id=\"flip2\">\n";
332 if ($paged > 1) {
333 echo "$indentText\t<li class=\"newer\"><a href=\"";
334 previous_posts();
335 echo '">'. preg_replace('/&([^#])(?![a-z]{1,8};)/', '&#038;$1', $prev_label) ."</a></li>\n";
336 }
337 if (empty($paged) || $nextpage <= $max_page) {
338 echo "$indentText\t<li class=\"older\"><a href=\"";
339 next_posts($max_page);
340 echo '">'. preg_replace('/&([^#])(?![a-z]{1,8};)/', '&#038;$1', $next_label) ."</a></li>\n";
341 }
342
343 if ($max_page > 1)
344 echo $indentText . '</ul>' . "\n";
345 }
346 }
347
348 /**
349 * Indent the body text.
350 */
351 function indent_entry_body($content) {
352 // indent depth (from div.textBody p)
353 $indent = 4;
354 for ($i = 0; $i < $indent; $i ++)
355 $indentText .= "\t";
356
357 $pre_flag = false;
358 $arr_content = split("\n", $content);
359
360 foreach ($arr_content as $line) {
361 if(!$pre_flag) {
362 if (strpos($line, "<pre") !== false)
363 $pre_flag = true;
364
365 $mes .= $indentText . $line . "\n";
366 }
367 else {
368 if (strpos($line, "</pre>") !== false)
369 $pre_flag = false;
370
371 $mes .= $line . "\n";
372 }
373 }
374
375 return rtrim($mes) . "\n";
376 }
377
378 add_action('the_content', indent_entry_body, 99);
379
380
381 /**
382 * Replace the body text with some vicuna style.
383 */
384 function replace_entry_body($content) {
385 // indent depth (from div.textBody p)
386 $indent = 3;
387 for ($i = 0; $i < $indent; $i ++)
388 $indentText .= "\t";
389
390 // get the title of entry.
391 $entry_title = get_the_title();
392
393 // [for ver.2.2]
394 // $content = preg_replace('/\s*<p><span id="more-([0-9]+?)"><\/span>(.*?)<\/p>/', "\n\t\t\t</div>\n$indentText<div class=\"textBody\" id=\"extended\">\n$indentText\t<p>\\2</p>", $content);
395
396 // [for ver.2.2]
397 // $content = preg_replace('/\s*<span id="more-([0-9]+?)"><\/span>(.*?)<\/p>/', "\t</p>\n\t\t\t</div>\n$indentText<div class=\"textBody\" id=\"extended\">\n$indentText\t<p>\\2</p>", $content);
398
399 // [for ver.2.2]
400 // $content = preg_replace('/\s*<p><span id="more-([0-9]+?)"><\/span>(.*?)<br\s*\/>/', "\n\t\t\t</div>\n$indentText<div class=\"textBody\" id=\"extended\">\n<p>$indentText\t<p>\\2</p>", $content);
401
402 if (is_page() || is_single()) {
403 // Replace '<p><a id="more-**"></p>' by '<div class="textBody" id="extended">'.
404 // $content = preg_replace('/\t<p(\s.+?=".+?">|>)<a id="more-([0-9]+?)"><\/a>(.*?)<\/p>/', "</div>\n$indentText<div class=\"textBody\" id=\"extended\">\n$indentText\t<p\\1\\3</p>", $content);
405
406 // if <a class="more-link"> is without <p>, replace <a id="more-**"> to <div class="textBody" id="extended">
407 // $content = preg_replace('/<a id="more-([0-9]+?)"><\/a>(.*?)<\/p>/', "</p>\n\t\t\t</div>\n$indentText<div class=\"textBody\" id=\"extended\">\n$indentText\t<p>\\2</p>", $content);
408
409 $content = preg_replace('/\s*<p><span id="more-([0-9]+?)"><\/span>(.*?)<\/p>/', "\n\t\t\t</div>\n$indentText<div class=\"textBody\" id=\"extended\">\n$indentText\t<p>\\2</p>", $content);
410
411 $content = preg_replace('/\s*<span id="more-([0-9]+?)"><\/span>(.*?)<\/p>/', "\t</p>\n\t\t\t</div>\n$indentText<div class=\"textBody\" id=\"extended\">\n$indentText\t<p>\\2</p>", $content);
412
413 $content = preg_replace('/\s*<p><span id="more-([0-9]+?)"><\/span>(.*?)<br\s*\/>/', "\n\t\t\t</div>\n$indentText<div class=\"textBody\" id=\"extended\">\n<p>$indentText\t<p>\\2</p>", $content);
414
415 } else {
416 // Replace '<p><a class="more-link">' by '<p class="continue"><a>'.
417 // (replace 'href="hoge#more-**"' to 'href="hoge#extended"')
418 $content = preg_replace('/<p(\s.+?=".+?">|>)\s?<a href="(.+?)#more-([0-9]+?)" class="more-link">(.+?)<\/a><\/p>/', '<p class="continue"><a href="\2#extended" title="'. sprintf("Read the full text of %s", $entry_title) . '" rel="nofollow">\4</a></p>', $content);
419
420 // if <a class="more-link"> is without <p>, replace to '<p class="continue"><a>'.
421 $content = preg_replace('/\s*<a href="(.+?)#more-([0-9]+?)" class="more-link">(.+?)<\/a><\/p>/', "</p>\n\t\t\t\t".'<p class="continue"><a href="\1#extended" title="'. sprintf("Read the full text of %s", $entry_title) . '" rel="nofollow">\3</a></p>', $content);
422
423 }
424 // Delete the tags '<p></p>', '<p class="hoge"></p>', '<p>&nbsp;</p>' and '<p class="hoge">&nbsp;</p>'
425 $content = preg_replace('/\t*<p(\s.+?=".+?">|>)\s*?<\/p>\n/', '', $content);
426
427 // Delete the tag "<br /></p>".
428 $content = preg_replace("/<br \/>\s*<\/p>/", "</p>", $content);
429
430 return $content;
431 }
432
433
434 add_action('the_content', replace_entry_body, 100);
435
436 /**
437 * Indent the comment body.
438 */
439 function indent_comment_body($content) {
440 // indent depth (from div.textBody p)
441 $indent = 7;
442 for ($i = 0; $i < $indent; $i ++)
443 $indentText .= "\t";
444
445 $pre_flag = false;
446 $arr_content = split("\n", $content);
447
448 foreach ($arr_content as $line) {
449 if(!$pre_flag) {
450 if (strpos($line, "<pre") !== false)
451 $pre_flag = true;
452
453 $mes .= $indentText . $line . "\n";
454 }
455 else {
456 if (strpos($line, "</pre>") !== false)
457 $pre_flag = false;
458
459 $mes .= $line . "\n";
460 }
461 }
462
463 return rtrim($mes) . "\n";
464 }
465
466 add_filter('comment_text', indent_comment_body, 100);
467
468 /**
469 * Return a URI of the javascript for VICUNA.
470 */
471 function get_vicuna_javascript_uri() {
472 $javascript_uri = get_stylesheet_directory_uri() . "/script.js";
473 return $javascript_uri;
474 }
475
476 /**
477 * Return a title of Archive page.
478 */
479 function get_vicuna_archive_title() {
480 if ( is_day() ) /* If this is a daily archive */
481 return get_the_time('Y-m-d');
482 elseif ( is_month() ) /* If this is a monthly archive */
483 return get_the_time('Y-m');
484 elseif ( is_year() ) /* If this is a yearly archive */
485 return get_the_time('Y');
486 elseif ( is_author() )
487 return 'Author';
488 }
489
490 /**
491 * Return a page navigation.
492 */
493 function get_vicuna_page_navigation($args = '') {
494 if ( is_array($args) )
495 $r = &$args;
496 else
497 parse_str($args, $r);
498
499 $defaults = array('depth' => 0, 'show_date' => '', 'date_format' => get_option('date_format'),
500 'child_of' => 0, 'exclude' => '', 'echo' => 1, 'authors' => '', 'separator' => ' | ');
501 $r = array_merge($defaults, $r);
502
503 $output = '';
504 $current_page = 0;
505
506 // sanitize, mostly to keep spaces out
507 $r['exclude'] = preg_replace('[^0-9,]', '', $r['exclude']);
508
509 // Allow plugins to filter an array of excluded pages
510 $r['exclude'] = implode(',', apply_filters('wp_list_pages_excludes', explode(',', $r['exclude'])));
511 $separator = $r['separator'];
512 // Query pages.
513 $pages = get_pages($r);
514 if ( !empty($pages) ) {
515 global $wp_query;
516 if ( is_page() ) {
517 $current_page = $wp_query->get_queried_object_id();
518 $flag = false;
519 $output = '';
520 $family = get_vicuna_upper_page($pages, array(), $current_page);
521 array_shift($family);
522 foreach ($family as $page) {
523 if ( $flag ) {
524 $output = $separator . $output;
525 } else {
526 $flag = true;
527 }
528 $output = '<a href="' .get_permalink($page->ID). "\">$page->post_title</a>". $output;
529 }
530 return $output;
531 }
532 }
533 }
534
535 /**
536 * Return a page upper the page.
537 */
538 function get_vicuna_upper_page($pages, $family, $page_id) {
539 foreach ($pages as $page) {
540 if ($page_id == $page->ID) {
541 if (array_push($family, $page)) {
542 $family = get_vicuna_upper_page($pages, $family, $page->post_parent);
543 break;
544 }
545 }
546 }
547 return $family;
548 }
549
550 /**
551 * Return a link for archives.
552 */
553 function vicuna_archives_link($limit = '') {
554 global $wp_locale, $wpdb;
555
556 if ( '' != $limit ) {
557 $limit = (int) $limit;
558 $limit = ' LIMIT '.$limit;
559 }
560
561 $arcresults = $wpdb->get_results("SELECT DISTINCT YEAR(post_date) AS `year`, MONTH(post_date) AS `month`, count(ID) as posts FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish' GROUP BY YEAR(post_date), MONTH(post_date) ORDER BY post_date DESC" . $limit);
562 if ( $arcresults ) {
563 foreach ( $arcresults as $arcresult ) {
564 $url = get_month_link($arcresult->year, $arcresult->month);
565 $text = sprintf("%04d-%02d", $arcresult->year, $arcresult->month);
566 echo "\t<li><a href=\"$url\" title=\"$arcresult->posts\" rel=\"nofollow\">$text</a></li>\n";
567 }
568 }
569 }
570
571 /**
572 * Return the upper category.
573 */
574 function get_vicuna_upper_category($cat_id, $category_split = ' | ') {
575 $parent = &get_category($cat_id);
576 $name = $parent->cat_name;
577 $flag = true;
578 $parent_category = '';
579 while ( $parent->category_parent ) {
580 $tmp = '';
581 $parent = &get_category($parent->category_parent);
582 $tmp .= '<a href="'. get_category_link($parent->cat_ID).'">'.$parent->cat_name.'</a>';
583 if ($flag) {
584 $flag = false;
585 } else {
586 $tmp .= $category_split;
587 }
588 $parent_category = $tmp.$output;
589 }
590 return $parent_category;
591 }
592
593 /**
594 * Return the total amount of pings.
595 */
596 function get_vicuna_pings_count() {
597 global $post, $wpdb, $id;
598 $comments = $wpdb->get_results("SELECT * FROM $wpdb->comments WHERE comment_post_ID = '$post->ID' AND comment_approved = '1' AND comment_type != '' ORDER BY comment_date");
599 return count($comments);
600 }
601
602 /**
603 * Return all the posts.
604 */
605 function get_all_posts() {
606 global $wpdb;
607 $posts = $wpdb->get_results("SELECT * FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish' ORDER BY ID DESC");
608 return $posts;
609 }
610
611 /**
612 * Return all the comments.
613 */
614 function get_all_comments() {
615 global $wpdb;
616 $comments = $wpdb->get_results("SELECT * FROM $wpdb->comments WHERE comment_approved = '1' AND comment_type = '' ORDER BY comment_date");
617 // $comments = apply_filters( 'comments_array', $comments, $post->ID );
618 return $comments;
619 }
620
621 /**
622 * Display a link to edit the comments for every posts.
623 * (unsupported in page)
624 */
625 function vicuna_edit_comments_link($link = 'Edit This Comments.', $before = '', $after = '') {
626 global $post;
627 if ( is_attachment() )
628 return;
629
630 if( $post->post_type == 'page' ) {
631 return;
632 } else {
633 if ( ! current_user_can('edit_post', $post->ID) )
634 return;
635 $file = 'post';
636 }
637 $location = get_option('siteurl') . "/wp-admin/edit.php?p=$post->ID&amp;c=1";
638 echo $before . "<a href=\"$location\">$link</a>" . $after;
639 }
640
641 add_action('entries_footer', vicuna_paging_link);
642 ?>