function _b_wp_archives_monthly_show($options, $wp_num = '')
 {
     $block_style = $options[0] ? $options[0] : 0;
     $with_count = $options[1] == 0 ? false : true;
     $tpl_file = empty($options[2]) ? 'wp_archives_monthly.html' : $options[2];
     $sel_value = '';
     if (current_wp()) {
         if (!empty($_SERVER['PATH_INFO'])) {
             permlink_to_param();
         }
         init_param('GET', 'm', 'string', '');
         init_param('GET', 'year', 'integer', '');
         init_param('GET', 'monthnum', 'integer', '');
         init_param('GET', 'day', 'integer', '');
         if (strlen(get_param('m')) == 6) {
             $sel_value = get_param('m');
         } else {
             if (test_param('year') && test_param('monthnum') && !test_param('day')) {
                 $sel_value = get_param('year') . zeroise(get_param('monthnum'), 2);
             }
         }
     }
     $block['wp_num'] = $wp_num;
     $block['divid'] = 'wpArchive' . $wp_num;
     $block['siteurl'] = wp_siteurl();
     $block['style'] = block_style_get(false);
     $block['block_style'] = $block_style;
     $block['with_count'] = $with_count;
     $now = current_time('mysql');
     $postHandler =& wp_handler('Post');
     $criteria =& new CriteriaCompo(new Criteria('post_date', $now, '<'));
     $criteria->add(new Criteria('post_status', 'publish'));
     $criteria->setSort('post_date');
     $criteria->setOrder('DESC');
     $criteria->setGroupby('YEAR(post_date), MONTH(post_date)');
     $postObjects =& $postHandler->getObjects($criteria, false, 'DISTINCT YEAR(post_date) AS `year`, MONTH(post_date) AS `month`, count(ID) as posts');
     $block['records'] = array();
     if ($postObjects) {
         foreach ($postObjects as $postObject) {
             $this_year = $postObject->getExtraVar('year');
             $this_month = $postObject->getExtraVar('month');
             $_record['url'] = get_month_link($this_year, $this_month);
             $_record['text'] = format_month($this_year, $GLOBALS['month'][zeroise($this_month, 2)]);
             if ($with_count) {
                 $_record['count'] = '&nbsp;(' . $postObject->getExtraVar('posts') . ')';
             } else {
                 $_record['count'] = '';
             }
             $_record['select'] = $sel_value == $this_year . zeroise($this_month, 2) ? 'selected="selected"' : '';
             $block['records'][] = $_record;
         }
     }
     $_wpTpl =& new WordPresTpl('theme');
     $_wpTpl->assign('block', $block);
     if (!$_wpTpl->tpl_exists($tpl_file)) {
         $tpl_file = 'wp_archives_monthly.html';
     }
     $block['content'] = $_wpTpl->fetch($tpl_file);
     return $block;
 }
    function wp_dropdown_month($current)
    {
        $arc_result = $GLOBALS['wpdb']->get_results("SELECT DISTINCT YEAR(post_date), MONTH(post_date) FROM " . wp_table('posts') . " ORDER BY post_date DESC", ARRAY_A);
        foreach ($arc_result as $arc_row) {
            $arc_year = $arc_row["YEAR(post_date)"];
            $arc_month = $arc_row["MONTH(post_date)"];
            $arc_ym = $arc_year . zeroise($arc_month, 2);
            $month_str = format_month($arc_year, $GLOBALS['month'][zeroise($arc_month, 2)]);
            ?>
 
		<option value="<?php 
            echo $arc_ym;
            ?>
"<?php 
            selected($current, $arc_ym);
            ?>
><?php 
            echo $month_str;
            ?>
</option>
<?php 
        }
    }
 function get_calendar($daylength = 1, $echo = true)
 {
     $postHandler =& wp_handler('Post');
     // Quick check. If we have no posts at all, abort!
     if (empty($GLOBALS['posts'])) {
         $criteria =& new Criteria('post_status', 'publish');
         if (!$postHandler->getCount($criteria)) {
             return _echo('', $echo);
         }
     }
     // Let's figure out when we are
     if (!empty($GLOBALS['monthnum']) && !empty($GLOBALS['year'])) {
         $thismonth = '' . intval($GLOBALS['monthnum']);
         $thisyear = '' . intval($GLOBALS['year']);
     } elseif (!empty($GLOBALS['w'])) {
         $thisyear = '' . intval(substr($GLOBALS['m'], 0, 4));
         $wst = 8 - intval(date('w', mktime(0, 0, 0, 1, 1, $thisyear)));
         $d = ($GLOBALS['w'] - 1) * 7 + $wst;
         $thismonth = intval(date('m', mktime(0, 0, 0, 1, $d, $thisyear)));
     } elseif (!empty($GLOBALS['m'])) {
         $calendar = substr($GLOBALS['m'], 0, 6);
         $thisyear = '' . intval(substr($GLOBALS['m'], 0, 4));
         if (strlen($GLOBALS['m']) < 6) {
             $thismonth = '01';
         } else {
             $thismonth = '' . intval(substr($GLOBALS['m'], 4, 2));
         }
     } else {
         $thisyear = intval(date('Y', current_time('timestamp', 0)));
         $thismonth = intval(date('m', current_time('timestamp', 0)));
     }
     $unixmonth = mktime(0, 0, 0, $thismonth, 1, $thisyear);
     // Get the next and previous month and year with at least one post
     $criteria =& new CriteriaCompo(new Criteria('post_date', "{$thisyear}-{$thismonth}-01", '<'));
     $criteria->add(new Criteria('post_status', 'publish'));
     $criteria->setSort('post_date');
     $criteria->setOrder('DESC');
     $criteria->setLimit(1);
     $prevPostObjects =& $postHandler->getObjects($criteria, false, 'post_date');
     $nextyear = date('Y', mktime(0, 0, 0, $thismonth + 1, 1, $thisyear));
     $nextmonth = date('m', mktime(0, 0, 0, $thismonth + 1, 1, $thisyear));
     // this means year of next month.
     $criteria =& new CriteriaCompo(new Criteria('post_date', "{$nextyear}-{$nextmonth}-01", '>='));
     $criteria->add(new Criteria('post_status', 'publish'));
     $criteria->setSort('post_date');
     $criteria->setOrder('ASC');
     $criteria->setLimit(1);
     $nextPostObjects =& $postHandler->getObjects($criteria, false, 'post_date');
     $month_str = format_month(date('Y', $unixmonth), $GLOBALS['month'][zeroise($thismonth, 2)]);
     $get_calendar = "<table id='wp-calendar' summary='wp-calendar'>\n<caption>{$month_str}</caption>\n<thead>\n\t<tr>";
     foreach ($GLOBALS['weekday'] as $wd) {
         if (function_exists('mb_substr')) {
             $get_calendar .= "\n\t\t<th abbr='{$wd}' scope='col' title='{$wd}'>" . mb_substr($wd, 0, $daylength, $GLOBALS['blog_charset']) . '</th>';
         } else {
             $get_calendar .= "\n\t\t<th abbr='{$wd}' scope='col' title='{$wd}'>" . substr($wd, 0, $daylength) . '</th>';
         }
     }
     $get_calendar .= "\n\t</tr>\n</thead>\n<tfoot>\n\t<tr>";
     if ($prevPostObjects) {
         $prev_year = substr($prevPostObjects[0]->getVar('post_date'), 0, 4);
         $prev_month = substr($prevPostObjects[0]->getVar('post_date'), 5, 2);
         if (function_exists('mb_convert_encoding')) {
             $smonth_name = mb_substr($GLOBALS['month'][zeroise($prev_month, 2)], 0, 3, $GLOBALS['blog_charset']);
         } else {
             $smonth_name = substr($GLOBALS['month'][zeroise($prev_month, 2)], 0, 3);
         }
         $month_str = format_month(date('Y', mktime(0, 0, 0, $prev_month, 1, $prev_year)), $GLOBALS['month'][zeroise($prev_month, 2)]);
         $get_calendar .= "\n\t\t" . '<td abbr="' . $GLOBALS['month'][zeroise($prev_month, 2)] . '" colspan="3" id="prev"><a href="' . get_month_link($prev_year, $prev_month) . '" title="View posts for ' . $month_str . '">&laquo; ' . $smonth_name . '</a></td>';
     } else {
         $get_calendar .= "\n\t\t" . '<td colspan="3" id="prev" class="pad">&nbsp;</td>';
     }
     $get_calendar .= "\n\t\t" . '<td class="pad">&nbsp;</td>';
     if ($nextPostObjects) {
         $next_year = substr($nextPostObjects[0]->getVar('post_date'), 0, 4);
         $next_month = substr($nextPostObjects[0]->getVar('post_date'), 5, 2);
         if (function_exists('mb_substr')) {
             $smonth_name = mb_substr($GLOBALS['month'][zeroise($next_month, 2)], 0, 3, $GLOBALS['blog_charset']);
         } else {
             $smonth_name = substr($GLOBALS['month'][zeroise($next_month, 2)], 0, 3);
         }
         $month_str = format_month(date('Y', mktime(0, 0, 0, $next_month, 1, $next_year)), $GLOBALS['month'][zeroise($next_month, 2)]);
         $get_calendar .= "\n\t\t" . '<td abbr="' . $GLOBALS['month'][zeroise($next_month, 2)] . '" colspan="3" id="next"><a href="' . get_month_link($next_year, $next_month) . '" title="View posts for ' . $month_str . '">' . $smonth_name . ' &raquo;</a></td>';
     } else {
         $get_calendar .= "\n\t\t" . '<td colspan="3" id="next" class="pad">&nbsp;</td>';
     }
     $get_calendar .= "\n\t</tr>\n</tfoot>\n<tbody>\n\t<tr>";
     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 = ", ";
     }
     // Get days with posts
     $criteria =& new CriteriaCompo(new Criteria('MONTH(post_date)', $thismonth));
     $criteria->add(new Criteria('YEAR(post_date)', $thisyear));
     $criteria->add(new Criteria('post_date', current_time('mysql'), '<'));
     $criteria->add(new Criteria('post_status', 'publish'));
     $monthlyPostObjects =& $postHandler->getObjects($criteria, false, 'post_title, post_date');
     if ($monthlyPostObjects) {
         foreach ($monthlyPostObjects as $postObject) {
             $d = intval(substr($postObject->getVar('post_date'), 8, 2));
             $daywithpost[] = $d;
             if (empty($ak_titles_for_day["day_" . $d])) {
                 $ak_titles_for_day["day_" . $d] = '';
             }
             if (empty($ak_titles_for_day["{$d}"])) {
                 // first one
                 $ak_titles_for_day["{$d}"] = htmlspecialchars($postObject->getVar('post_title'));
             } else {
                 $ak_titles_for_day["{$d}"] .= $ak_title_separator . htmlspecialchars($postObject->getVar('post_title'));
             }
         }
         $daywithpost = array_unique($daywithpost);
     } else {
         $daywithpost = array();
     }
     // See how much we should pad in the beginning
     $pad = intval(date('w', $unixmonth));
     if ($pad) {
         $get_calendar .= "\n\t\t<td colspan='{$pad}' class='pad'>&nbsp;</td>";
     }
     $daysinmonth = intval(date('t', $unixmonth));
     for ($day = 1; $day <= $daysinmonth; ++$day) {
         if (!empty($newrow)) {
             $get_calendar .= "\n\t</tr>\n\t<tr>\n\t\t";
         }
         $newrow = false;
         if ($day == date('j', current_time('timestamp', 0)) && $thismonth == date('m', current_time('timestamp', 0))) {
             $get_calendar .= '<td id="today">';
         } else {
             $get_calendar .= "<td>";
         }
         if (in_array($day, $daywithpost)) {
             // any posts today?
             $get_calendar .= '<a href="' . get_day_link($thisyear, $thismonth, $day) . "\" title=\"{$ak_titles_for_day[$day]}\">{$day}</a>";
         } else {
             $get_calendar .= $day;
         }
         $get_calendar .= '</td>';
         if (6 == date('w', mktime(0, 0, 0, $thismonth, $day, $thisyear))) {
             $newrow = true;
         }
     }
     $pad = 7 - date('w', mktime(0, 0, 0, $thismonth, $day, $thisyear));
     if ($pad != 0 && $pad != 7) {
         $get_calendar .= "\n\t\t<td class='pad' colspan='{$pad}'>&nbsp;</td>";
     }
     $get_calendar .= "\n\t</tr>\n\t</tbody>\n\t</table>";
     return _echo($get_calendar, $echo);
 }
function archive_header(&$post, $before = '', $after = '')
{
    static $previous = '';
    if (test_param('orderby')) {
        $orderby = explode(' ', get_param('orderby'));
        $orderby = $orderby[0];
    } else {
        $orderby = '';
    }
    switch ($orderby) {
        case 'title':
            if (_LANGCODE == 'ja') {
                $thisletter = ucfirst(mb_substring($post->yomi, 0, 1, $GLOBALS['blog_charset']));
                if ($thisletter > "¤ó") {
                    $thisletter = "´Á»ú";
                }
            } else {
                $thisletter = ucfirst(substr($post->yomi, 0, 1));
            }
            if ($thisletter == "") {
                $thisletter = _WP_POST_NOTITLE;
            }
            if ($previous === '' || $thisletter !== $previous) {
                $output = "<br/>" . $thisletter;
            }
            $previous = $thisletter;
            break;
        case 'category':
            $thiscategory = $post->cat_ID;
            if ($thiscategory != $previous) {
                $output = '<br/><strong><a href="' . get_category_link(false, $thiscategory) . '">' . get_catname($thiscategory) . '</a></strong>';
            }
            $previous = $thiscategory;
            break;
        case 'author':
            $thisauthor = $post->post_author;
            if ($thisauthor != $previous) {
                $output = '<br/><strong><a href="' . get_author_link(false, $thisauthor) . '">' . the_author('', false) . '</a></strong>';
            }
            $previous = $thisauthor;
            break;
        case 'date':
        case '':
            $thismonth = mysql2date('m', $post->post_date);
            $thisyear = mysql2date('Y', $post->post_date);
            $thisdate = $thisyear . $thismonth;
            if ($thisdate != $previous) {
                $monthstr = format_month(sprintf("%d", $thisyear), $GLOBALS['month'][zeroise($thismonth, 2)]);
                $output = '<strong><br/><a href="' . get_month_link($thisyear, $thismonth) . '">' . $monthstr . '</a></strong>';
            }
            $previous = $thisdate;
            break;
    }
    if (!empty($output)) {
        $output = $before . $output . $after . "\n";
        echo $output;
    }
}