collapsiblearchive_toggle = function(listelement,visible,listsign)
{
(visible == false ?
new Effect.(document.getElementById(listelement)) :
new Effect.(document.getElementById(listelement))
);
var sign = document.getElementById(listsign);
collapsiblearchive_togglesign(sign, visible);
visible = (visible == false ? true : false);
return visible;
}
collapsiblearchive_toggle = function(listelement, listsign)
{
var listobject = document.getElementById(listelement);
var sign = document.getElementById(listsign);
if(listobject.style.display == 'block')
{
listobject.style.display = 'none';
collapsiblearchive_togglesign(sign, true);
}
else
{
listobject.style.display = 'block';
collapsiblearchive_togglesign(sign, false);
}
}
collapsiblearchive_togglesign = function(element,visibility)
{
(visibility == false ? element.innerHTML = '' : element.innerHTML = '');
}
// -->
0 ) $string_to_echo .= $parentOpen;
$icon = ($defaultexpand || ($expandcurryear && date("Y") == $years[$x]->year)) ? $ara_collapsible_icons['minus'][$htmlarrows] : $ara_collapsible_icons['plus'][$htmlarrows];
$year_link = get_year_link($years[$x]->year);
if($scriptaculous > 0)
{
?>year} = collapsiblearchive_toggle('ara_ca_mo{$years[$x]->year}',visible_{$years[$x]->year},'ara_ca_mosign{$years[$x]->year}')">
EOB;
}
else
{
$string_to_echo .= <<
EOB;
}
$string_to_echo .= "year}\">$icon{$years[$x]->year}";
if($count > 0) $string_to_echo .= ' ('.$years[$x]->posts.')';
$string_to_echo .= $childOpen.' id="ara_ca_mo'.$years[$x]->year.'" style="display:'.(($defaultexpand || ($expandcurryear && date("Y") == $years[$x]->year)) ? 'block' : 'none').'">';
$string_to_echo .= ara_collapsiblearchive_get_archivesbymonth($years[$x]->year,$count,$lineStart.$preappend,$lineEnd,$abbr);
$string_to_echo .= $childClose;
if (strlen($parentClose) > 0) $string_to_echo .= $parentClose;
}
$string_to_echo .= $parentPreClose;
return $string_to_echo;
}
function ara_collapsiblearchive_get_archivesbymonth($year, $count, $before, $after, $abbr)
{
global $wpdb, $wp_locale, $ara_collapsible_icons;
$options = (array) get_option('widget_ara_collapsiblearchive');
$scriptaculous = $options['scriptaculous'] ? 1 : 0;
$defaultexpand = $options['defaultexpand'] ? 1 : 0;
$expandcurrmonth = $options['expandcurrmonth'] ? 1 : 0;
$show_individual_posts = $options['showposts'] ? 1 : 0;
$count = $options['count'] ? 1 : 0;
$mcount = $options['mcount'] ? 1 : 0;
$htmlarrows = $options['htmlarrows'] ? 1 : 0;
$highlightcurrmonth = $options['highlightcurrmonth'] ? 1 : 0;
$monthhideyear = $options['monthhideyear'] ? 1 : 0;
$monthresults = $wpdb->get_results("SELECT DISTINCT YEAR(post_date) AS `year`, MONTH(post_date) AS `month`, count(ID) as posts"
. " FROM $wpdb->posts"
. " WHERE $wpdb->posts.post_status = 'publish'"
. " AND $wpdb->posts.post_type = 'post'"
. " AND YEAR(post_date) = $year"
. " GROUP BY YEAR(post_date), MONTH(post_date) ORDER BY post_date DESC");
$result_string = '';
foreach ($monthresults as $month)
{
$url = get_month_link($year, $month->month);
if($show_individual_posts > 0)
{
$icon = ($defaultexpand || ($expandcurrmonth && date("Y") == $year && date("n") == $month->month)) ? $ara_collapsible_icons['minus'][$htmlarrows] : $ara_collapsible_icons['plus'][$htmlarrows];
if($scriptaculous > 0)
{
$add_before = '';
$add_before .= <<
EOB;
}
else
{
$add_before = <<
EOB;
}
$add_before .= "month}\">$icon";
}
else $add_before = '';
$monthname = ($abbr > 0 ? $wp_locale->get_month_abbrev($wp_locale->get_month($month->month)) : $wp_locale->get_month($month->month));
if($monthhideyear > 0)
$text = ($highlightcurrmonth > 0 ? '' : '') . sprintf(__('%1$s'), $monthname) . ($highlightcurrmonth > 0 ? '' : '');
else
$text = ($highlightcurrmonth > 0 ? '' : '') . sprintf(__('%1$s %2$d'), $monthname, $year) . ($highlightcurrmonth > 0 ? '' : '');
if ($mcount > 0) $aftertext = ' ('.$month->posts.')' . $after;
else $aftertext = $after;
$result_string .= get_archives_link($url, $text, 'custom', $before.$add_before, $aftertext);
if($show_individual_posts)
{
$result_string .= ara_collapsiblearchive_get_postsbymonth($year, $month->month, '', '');
$result_string .= $after;
}
}
return $result_string;
}
function ara_collapsiblearchive_get_postsbymonth($year, $month, $before, $after)
{
global $wpdb;
$options = (array) get_option('widget_ara_collapsiblearchive');
$defaultexpand = $options['defaultexpand'] ? 1 : 0;
$expandcurrmonth = $options['expandcurrmonth'] ? 1 : 0;
if (empty($year) || empty($month)) {
return null;
}
list($parentOpen, $parentClose, $lineStart, $lineEnd, $childOpen, $childClose, $preappend, $parentPreOpen, $parentPreClose) = ara_collapsiblearchive_getlisttype();
$postresults = $wpdb->get_results("SELECT ID, post_title, post_name"
. " FROM $wpdb->posts"
. " WHERE $wpdb->posts.post_status = 'publish' AND $wpdb->posts.post_type = 'post'"
. " AND YEAR(post_date) = $year AND MONTH(post_date) = $month"
. " ORDER BY post_date DESC");
$result_string = '';
$sectionstart = true;
foreach ($postresults as $post)
{
if($sectionstart)
{
$result_string .= $childOpen.' id="ara_ca_po'.$year.$month.'" style="display:'.(($defaultexpand || ($expandcurrmonth && date("Y") == $year && date("n") == $month)) ? 'block' : 'none').'">';
$sectionstart = false;
}
$url = get_permalink($post->ID);
$result_string .= $lineStart.''.$post->post_title.''.$lineEnd;
}
$result_string .= $childClose;
return $result_string;
}
function ara_collapsiblearchive_get_archivesbyyear() {
global $wpdb;
$yearresults = $wpdb->get_results("SELECT DISTINCT YEAR(post_date) AS `year`, count(ID) as posts"
. " FROM $wpdb->posts"
. " WHERE $wpdb->posts.post_status = 'publish'"
. " AND $wpdb->posts.post_type = 'post'"
. " GROUP BY YEAR(post_date) ORDER BY post_date DESC");
return $yearresults;
}
function widget_ara_collapsiblearchive_control() {
$options = $newoptions = get_option('widget_ara_collapsiblearchive');
if ( $_POST['collapsiblearchive-submit'] ) {
$newoptions['title'] = strip_tags(stripslashes($_POST['collapsiblearchive-title']));
$newoptions['count'] = isset($_POST['collapsiblearchive-count']);
$newoptions['mcount'] = isset($_POST['collapsiblearchive-mcount']);
$newoptions['abbr'] = isset($_POST['collapsiblearchive-monthabbr']);
$newoptions['scriptaculous'] = isset($_POST['collapsiblearchive-scriptaculous']);
$newoptions['effectexpand'] = $_POST['collapsiblearchive-effectexpand'];
$newoptions['effectcollapse'] = $_POST['collapsiblearchive-effectcollapse'];
$newoptions['showposts'] = $_POST['collapsiblearchive-showposts'];
$newoptions['defaultexpand'] = $_POST['collapsiblearchive-defaultexpand'];
$newoptions['expandcurryear'] = $_POST['collapsiblearchive-expandcurryear'];
$newoptions['expandcurrmonth'] = $_POST['collapsiblearchive-expandcurrmonth'];
$newoptions['linktoplugin'] = $_POST['collapsiblearchive-linktoplugin'];
$newoptions['htmlarrows'] = $_POST['collapsiblearchive-htmlarrows'];
$newoptions['highlightcurrmonth'] = $_POST['collapsiblearchive-highlightcurrmonth'];
$newoptions['monthhideyear'] = $_POST['collapsiblearchive-monthhideyear'];
}
if ( $options != $newoptions ) {
$options = $newoptions;
update_option('widget_ara_collapsiblearchive', $options);
}
$count = $options['count'] ? 'checked="checked"' : '';
$mcount = $options['mcount'] ? 'checked="checked"' : '';
$abbr = $options['abbr'] ? 'checked="checked"' : '';
$showposts = $options['showposts'] ? 'checked="checked"' : '';
$defaultexpand = $options['defaultexpand'] ? 'checked="checked"' : '';
$expandcurryear = $options['expandcurryear'] ? 'checked="checked"' : '';
$expandcurrmonth = $options['expandcurrmonth'] ? 'checked="checked"' : '';
$scriptaculous = $options['scriptaculous'] ? 'checked="checked"' : '';
$linktoplugin = $options['linktoplugin'] ? 'checked="checked"' : '';
$htmlarrows = $options['htmlarrows'] ? 'checked="checked"' : '';
$highlightcurrmonth = $options['highlightcurrmonth'] ? 'checked="checked"' : '';
$monthhideyear = $options['monthhideyear'] ? 'checked="checked"' : '';
?>
";
$parentClose= "\n\t";
$lineStart = "\n\t\t\t";
$lineEnd = "";
$childOpen = "\n\t\t";
$preappend = '';
$parentPreOpen = "\n";
return array($parentOpen, $parentClose, $lineStart, $lineEnd, $childOpen, $childClose, $preappend, $parentPreOpen, $parentPreClose);
}
function ara_collapsiblearchive_microtime_float()
{
list($usec, $sec) = explode(" ", microtime());
return ((float)$usec + (float)$sec);
}
function widget_ara_collapsiblearchive_init() {
global $ara_collapsible_icons;
$ara_collapsible_icons['plus'][0] = '
';
$ara_collapsible_icons['minus'][0] = '
';
$ara_collapsible_icons['plus'][1] = '► ';
$ara_collapsible_icons['minus'][1] = '▼ ';
// Check for the required API functions
if ( !function_exists('register_sidebar_widget') || !function_exists('register_widget_control') )
return;
// This prints the widget
function widget_ara_collapsiblearchive($args) {
$options = (array) get_option('widget_ara_collapsiblearchive');
$linktoplugin = $options['linktoplugin'] ? 1 : 0;
extract($args);
$start = ara_collapsiblearchive_microtime_float();
echo $before_widget;
echo "\n\t".''."\n";
echo ara_collapsiblearchive($before_title, $after_title);
if($linktoplugin)
{
print "\n\t".'';
}
echo $after_widget;
echo "\n\t".'';
$end = ara_collapsiblearchive_microtime_float();
echo "\n\t".''."\n";
}
// Tell Dynamic Sidebar about our new widget and its control
register_sidebar_widget(array('Collapsible Archive', 'widgets'), 'widget_ara_collapsiblearchive');
register_widget_control(array('Collapsible Archive', 'widgets'), 'widget_ara_collapsiblearchive_control', 300, 300);
}
function widget_ara_collapsiblearchive_enqueue()
{
$options = (array) get_option('widget_ara_collapsiblearchive');
$scriptaculous = $options['scriptaculous'] ? 1 : 0;
if(function_exists('wp_enqueue_script') && $scriptaculous > 0) wp_enqueue_script('scriptaculous-effects');
}
// Delay plugin execution to ensure Dynamic Sidebar has a chance to load first
add_action('widgets_init', 'widget_ara_collapsiblearchive_enqueue');
add_action('widgets_init', 'widget_ara_collapsiblearchive_init');
?>