$value ) { if ( sanitize_title($value['name']) == $index ) { $index = $key; break; } } $sidebars_widgets = wp_get_sidebars_widgets(); if ( !is_array($sidebars_widgets[$index]) || empty($sidebars_widgets[$index])) { return false; } foreach ($sidebars_widgets[$index] as $id) { if ($id == $widget_id) { return true; } } return false; } /** * Display calendar for Vicuna. */ function vicuna_calendar($initial = true) { $weekday = array('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'); global $wpdb, $m, $monthnum, $year, $timedifference, $wp_locale, $posts; $key = md5( $m . $monthnum . $year ); // get cache if ( $cache = wp_cache_get( 'vicuna_calendar', 'calendar' ) ) { if ( isset( $cache[ $key ] ) ) { echo $cache[ $key ]; return; } } ob_start(); // Quick check. If we have no posts at all, abort! if ( !$posts ) { $gotsome = $wpdb->get_var("SELECT ID from $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish' ORDER BY post_date DESC LIMIT 1"); if ( !$gotsome ) return; } if ( isset($_GET['w']) ) $w = ''.intval($_GET['w']); // week_begins = 0 stands for Sunday $week_begins = intval(get_option('start_of_week')); $add_hours = intval(get_option('gmt_offset')); $add_minutes = intval(60 * (get_option('gmt_offset') - $add_hours)); // Let's figure out when we are if ( !empty($monthnum) && !empty($year) ) { $thismonth = ''.zeroise(intval($monthnum), 2); $thisyear = ''.intval($year); } elseif ( !empty($w) ) { // We need to get the month from MySQL $thisyear = ''.intval(substr($m, 0, 4)); $d = (($w - 1) * 7) + 6; //it seems MySQL's weeks disagree with PHP's $thismonth = $wpdb->get_var("SELECT DATE_FORMAT((DATE_ADD('${thisyear}0101', INTERVAL $d DAY) ), '%m')"); } elseif ( !empty($m) ) { $calendar = substr($m, 0, 6); $thisyear = ''.intval(substr($m, 0, 4)); if ( strlen($m) < 6 ) $thismonth = '01'; else $thismonth = ''.zeroise(intval(substr($m, 4, 2)), 2); } else { $thisyear = gmdate('Y', current_time('timestamp')); $thismonth = gmdate('m', current_time('timestamp')); } $unixmonth = mktime(0, 0 , 0, $thismonth, 1, $thisyear); // Get the next and previous month and year with at least one post $previous = $wpdb->get_row("SELECT DISTINCT MONTH(post_date) AS month, YEAR(post_date) AS year FROM $wpdb->posts WHERE post_date < '$thisyear-$thismonth-01' AND post_type = 'post' AND post_status = 'publish' ORDER BY post_date DESC LIMIT 1"); $next = $wpdb->get_row("SELECT DISTINCT MONTH(post_date) AS month, YEAR(post_date) AS year FROM $wpdb->posts WHERE post_date > '$thisyear-$thismonth-01' AND MONTH( post_date ) != MONTH( '$thisyear-$thismonth-01' ) AND post_type = 'post' AND post_status = 'publish' ORDER BY post_date ASC LIMIT 1"); ?> get_weekday_initial($wd) : $wp_locale->get_weekday_abbrev($wd); $day_name = mb_substr( $wd, 0, 1 ); if ($day_name == "S") { echo "\t\t\t\t\t\n"; } else { echo "\t\t\t\t\t\n"; } } ?> get_results("SELECT DISTINCT DAYOFMONTH(post_date) FROM $wpdb->posts WHERE MONTH(post_date) = '$thismonth' AND YEAR(post_date) = '$thisyear' AND post_type = 'post' AND post_status = 'publish' AND post_date < '" . current_time('mysql') . '\'', ARRAY_N); if ( $dayswithposts ) { foreach ( $dayswithposts as $daywith ) { $daywithpost[] = $daywith[0]; } } else { $daywithpost = array(); } if ( strstr($_SERVER['HTTP_USER_AGENT'], 'MSIE') || strstr(strtolower($_SERVER['HTTP_USER_AGENT']), 'camino') || strstr(strtolower($_SERVER['HTTP_USER_AGENT']), 'safari') ) $ak_title_separator = "\n"; else $ak_title_separator = ', '; $ak_titles_for_day = array(); $ak_post_titles = $wpdb->get_results("SELECT post_title, DAYOFMONTH(post_date) as dom " ."FROM $wpdb->posts " ."WHERE YEAR(post_date) = '$thisyear' " ."AND MONTH(post_date) = '$thismonth' " ."AND post_date < '".current_time('mysql')."' " ."AND post_type = 'post' AND post_status = 'publish'" ); if ( $ak_post_titles ) { foreach ( $ak_post_titles as $ak_post_title ) { if ( empty($ak_titles_for_day['day_'.$ak_post_title->dom]) ) $ak_titles_for_day['day_'.$ak_post_title->dom] = ''; if ( empty($ak_titles_for_day["$ak_post_title->dom"]) ) // first one $ak_titles_for_day["$ak_post_title->dom"] = str_replace('"', '"', wptexturize($ak_post_title->post_title)); else $ak_titles_for_day["$ak_post_title->dom"] .= $ak_title_separator . str_replace('"', '"', wptexturize($ak_post_title->post_title)); } } // See how much we should pad in the beginning $pad = calendar_week_mod(date('w', $unixmonth)-$week_begins); if ( 0 != $pad ) { for ($i = 0; $i < $pad; $i++) echo "\t\t\t\t\t\n"; } $daysinmonth = intval(date('t', $unixmonth)); for ( $day = 1; $day <= $daysinmonth; ++$day ) { if ( isset($newrow) && $newrow ) echo "\n\t\t\t\t\n\t\t\t\t\n"; $newrow = false; 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)) ) echo "\t\t\t\t\t\n"; if ( 6 == calendar_week_mod(date('w', mktime(0, 0 , 0, $thismonth, $day, $thisyear))-$week_begins) ) $newrow = true; } $pad = 7 - calendar_week_mod(date('w', mktime(0, 0 , 0, $thismonth, $day, $thisyear))-$week_begins); if ( $pad != 0 && $pad != 7 ) { for ($i = 0; $i < $pad; $i++) echo "\t\t\t\t\t\n"; } echo "\t\t\t\t\n\t\t\t
year, $previous->month) . '" title="Older" rel="nofollow">«'; } else { echo '«'; } printf(__(' %1$s %2$s ', 'vicuna'), $wp_locale->get_month($thismonth), date('Y', $unixmonth)); if ( $next ) { echo '»'; } else { echo '»'; } $myweek = array(); for ( $wdcount=0; $wdcount<=6; $wdcount++ ) { $myweek[] = $weekday[ ($wdcount + $week_begins) % 7]; } ?>
$day_name$day_name
 
"; else echo "\t\t\t\t\t"; if ( in_array($day, $daywithpost) ) // any posts today? echo '$day"; else echo $day; echo " 
\n"; $output = ob_get_contents(); ob_end_clean(); echo $output; $cache[ $key ] = $output; wp_cache_set( 'vicuna_calendar', $cache, 'calendar' ); } /** * Delete cache of calendar */ function delete_vicuna_calendar_cache() { wp_cache_delete( 'vicuna_calendar', 'calendar' ); } add_action( 'save_post', 'delete_vicuna_calendar_cache' ); add_action( 'delete_post', 'delete_vicuna_calendar_cache' ); add_action( 'update_option_start_of_week', 'delete_vicuna_calendar_cache' ); add_action( 'update_option_gmt_offset', 'delete_vicuna_calendar_cache' ); /** * Display a description for the blog. */ function vicuna_description() { $description = get_bloginfo('description'); if ( !empty($description) ) { echo '

' . $description . "

\n"; } } /** * Display a pager(Newer | Older). */ function vicuna_paging_link($args = '') { global $paged, $wpdb, $wp_query; if (is_array($args)) $r = &$args; else parse_str($args, $r); $defaults = array('next_label' => __('Older Entries', 'vicuna'), 'prev_label' => __('Newer Entries', 'vicuna'), 'indent' => ''); $r = array_merge($defaults, $r); extract($r); if ($indent != '') { $indent = (int) $indent; for ($i = 0; $i < $indent; $i ++) $indentText .= "\t"; } // get max_page if (!$max_page) $max_page = $wp_query->max_num_pages; // get paged if (!$paged) $paged = 1; // set next page number $nextpage = intval($paged) + 1; if(!is_single()) { if ($max_page > 1) echo "$indentText' . "\n"; } } /** * Indent the body text. */ function indent_entry_body($content) { // indent depth (from div.textBody p) $indent = 4; for ($i = 0; $i < $indent; $i ++) $indentText .= "\t"; $pre_flag = false; $arr_content = split("\n", $content); foreach ($arr_content as $line) { if(!$pre_flag) { if (strpos($line, "") !== false) $pre_flag = false; $mes .= $line . "\n"; } } return rtrim($mes) . "\n"; } add_action('the_content', indent_entry_body, 99); /** * Replace the body text with some vicuna style. */ function replace_entry_body($content) { // indent depth (from div.textBody p) $indent = 3; for ($i = 0; $i < $indent; $i ++) $indentText .= "\t"; // get the title of entry. $entry_title = get_the_title(); // [for ver.2.2] // $content = preg_replace('/\s*

<\/span>(.*?)<\/p>/', "\n\t\t\t\n$indentText

\n$indentText\t

\\2

", $content); // [for ver.2.2] // $content = preg_replace('/\s*<\/span>(.*?)<\/p>/', "\t

\n\t\t\t
\n$indentText
\n$indentText\t

\\2

", $content); // [for ver.2.2] // $content = preg_replace('/\s*

<\/span>(.*?)/', "\n\t\t\t

\n$indentText
\n

$indentText\t

\\2

", $content); if (is_page() || is_single()) { // Replace '

' by '\n$indentText
\n$indentText\t", $content); // if is without

, replace to

\n$indentText
\n$indentText\t

\\2

", $content); $content = preg_replace('/\s*

<\/span>(.*?)<\/p>/', "\n\t\t\t

\n$indentText
\n$indentText\t

\\2

", $content); $content = preg_replace('/\s*<\/span>(.*?)<\/p>/', "\t

\n\t\t\t
\n$indentText
\n$indentText\t

\\2

", $content); $content = preg_replace('/\s*

<\/span>(.*?)/', "\n\t\t\t

\n$indentText
\n

$indentText\t

\\2

", $content); } else { // Replace '

' by '

'. // (replace 'href="hoge#more-**"' to 'href="hoge#extended"') $content = preg_replace('/|>)\s?(.+?)<\/a><\/p>/', '

\4

', $content); // if is without

, replace to '

'. $content = preg_replace('/\s*(.+?)<\/a><\/p>/', "

\n\t\t\t\t".'

\3

', $content); } // Delete the tags '

', '

', '

 

' and '

 

' $content = preg_replace('/\t*|>)\s*?<\/p>\n/', '', $content); // Delete the tag "

". $content = preg_replace("/
\s*<\/p>/", "

", $content); return $content; } add_action('the_content', replace_entry_body, 100); /** * Indent the comment body. */ function indent_comment_body($content) { // indent depth (from div.textBody p) $indent = 7; for ($i = 0; $i < $indent; $i ++) $indentText .= "\t"; $pre_flag = false; $arr_content = split("\n", $content); foreach ($arr_content as $line) { if(!$pre_flag) { if (strpos($line, "") !== false) $pre_flag = false; $mes .= $line . "\n"; } } return rtrim($mes) . "\n"; } add_filter('comment_text', indent_comment_body, 100); /** * Return a URI of the javascript for VICUNA. */ function get_vicuna_javascript_uri() { $javascript_uri = get_stylesheet_directory_uri() . "/script.js"; return $javascript_uri; } /** * Return a title of Archive page. */ function get_vicuna_archive_title() { if ( is_day() ) /* If this is a daily archive */ return get_the_time('Y-m-d'); elseif ( is_month() ) /* If this is a monthly archive */ return get_the_time('Y-m'); elseif ( is_year() ) /* If this is a yearly archive */ return get_the_time('Y'); elseif ( is_author() ) return 'Author'; } /** * Return a page navigation. */ function get_vicuna_page_navigation($args = '') { if ( is_array($args) ) $r = &$args; else parse_str($args, $r); $defaults = array('depth' => 0, 'show_date' => '', 'date_format' => get_option('date_format'), 'child_of' => 0, 'exclude' => '', 'echo' => 1, 'authors' => '', 'separator' => ' | '); $r = array_merge($defaults, $r); $output = ''; $current_page = 0; // sanitize, mostly to keep spaces out $r['exclude'] = preg_replace('[^0-9,]', '', $r['exclude']); // Allow plugins to filter an array of excluded pages $r['exclude'] = implode(',', apply_filters('wp_list_pages_excludes', explode(',', $r['exclude']))); $separator = $r['separator']; // Query pages. $pages = get_pages($r); if ( !empty($pages) ) { global $wp_query; if ( is_page() ) { $current_page = $wp_query->get_queried_object_id(); $flag = false; $output = ''; $family = get_vicuna_upper_page($pages, array(), $current_page); array_shift($family); foreach ($family as $page) { if ( $flag ) { $output = $separator . $output; } else { $flag = true; } $output = '$page->post_title". $output; } return $output; } } } /** * Return a page upper the page. */ function get_vicuna_upper_page($pages, $family, $page_id) { foreach ($pages as $page) { if ($page_id == $page->ID) { if (array_push($family, $page)) { $family = get_vicuna_upper_page($pages, $family, $page->post_parent); break; } } } return $family; } /** * Return a link for archives. */ function vicuna_archives_link($limit = '') { global $wp_locale, $wpdb; if ( '' != $limit ) { $limit = (int) $limit; $limit = ' LIMIT '.$limit; } $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); if ( $arcresults ) { foreach ( $arcresults as $arcresult ) { $url = get_month_link($arcresult->year, $arcresult->month); $text = sprintf("%04d-%02d", $arcresult->year, $arcresult->month); echo "\t
  • posts\" rel=\"nofollow\">$text
  • \n"; } } } /** * Return the upper category. */ function get_vicuna_upper_category($cat_id, $category_split = ' | ') { $parent = &get_category($cat_id); $name = $parent->cat_name; $flag = true; $parent_category = ''; while ( $parent->category_parent ) { $tmp = ''; $parent = &get_category($parent->category_parent); $tmp .= ''.$parent->cat_name.''; if ($flag) { $flag = false; } else { $tmp .= $category_split; } $parent_category = $tmp.$output; } return $parent_category; } /** * Return the total amount of pings. */ function get_vicuna_pings_count() { global $post, $wpdb, $id; $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"); return count($comments); } /** * Return all the posts. */ function get_all_posts() { global $wpdb; $posts = $wpdb->get_results("SELECT * FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish' ORDER BY ID DESC"); return $posts; } /** * Return all the comments. */ function get_all_comments() { global $wpdb; $comments = $wpdb->get_results("SELECT * FROM $wpdb->comments WHERE comment_approved = '1' AND comment_type = '' ORDER BY comment_date"); // $comments = apply_filters( 'comments_array', $comments, $post->ID ); return $comments; } /** * Display a link to edit the comments for every posts. * (unsupported in page) */ function vicuna_edit_comments_link($link = 'Edit This Comments.', $before = '', $after = '') { global $post; if ( is_attachment() ) return; if( $post->post_type == 'page' ) { return; } else { if ( ! current_user_can('edit_post', $post->ID) ) return; $file = 'post'; } $location = get_option('siteurl') . "/wp-admin/edit.php?p=$post->ID&c=1"; echo $before . "$link" . $after; } add_action('entries_footer', vicuna_paging_link); ?>