Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancements to CoreBlock Monthly Archives and Tag Archives #53

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions plugins/coreblocks/block.cloud.tag_archives.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php if ( !defined( 'HABARI_PATH' ) ) { die( 'No direct access' ); } ?>
<?php $tags = $content->tags; ?>
<div id="tag_archives">
<?php $tags = $content->tags; foreach( $tags as $tag ): ?>
<span style="font-size: <?php echo ($content->cloud_min + round((($tag['count'] - $content->min_post_count) * $content->size_increment),1)); ?>em;" class="cloud-tag">
<a href="<?php echo $tag[ 'url' ]; ?>"
title="View entries tagged '<?php echo $tag[ 'tag' ]; ?>'">
<?php echo $tag[ 'tag' ]; ?>
<?php if ($content->show_counts) { ?>(<?php echo $tag['count']; ?>)<?php } ?>
</a>
</span>
<?php endforeach; ?>
</div>
2 changes: 1 addition & 1 deletion plugins/coreblocks/block.dropdown.tag_archives.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

<option value=''>by tag</option>
<?php $tags = $content->tags; foreach( $tags as $tag ): ?>
<option value="<?php echo $tag[ 'url' ]; ?>"><?php echo $tag[ 'tag' ] . $tag[ 'count' ];
<option value="<?php echo $tag[ 'url' ]; ?>"><?php echo $tag[ 'tag' ] . ' ('. $tag[ 'count' ] . ')';
?></option>
<?php endforeach; ?>
</select>
Expand Down
2 changes: 1 addition & 1 deletion plugins/coreblocks/block.tag_archives.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<a href="<?php echo $tag[ 'url' ]; ?>" title="View entries tagged '<?php
echo $tag[ 'tag' ];
?>'"><?php
echo $tag[ 'tag' ] . $tag[ 'count' ];
echo $tag[ 'tag' ] . ' ('. $tag[ 'count' ] . ')';
?></a>
</li>
<?php endforeach; ?>
Expand Down
37 changes: 31 additions & 6 deletions plugins/coreblocks/coreblocks.plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ function action_init()
}
$this->add_template( "block.dropdown.tag_archives", dirname( __FILE__ ) . "/block.dropdown.tag_archives.php" );
$this->add_template( "block.dropdown.monthly_archives", dirname( __FILE__ ) . "/block.dropdown.monthly_archives.php" );
$this->add_template( "block.cloud.tag_archives", dirname( __FILE__ ) . "/block.cloud.tag_archives.php");
}

/**
Expand Down Expand Up @@ -188,7 +189,10 @@ public function action_block_content_recent_posts( $block, $theme )
*/
public function action_block_form_monthly_archives( $form, $block )
{
$form->append( FormControlLabel::wrap( _t( 'Display full month names:' ),
$form->append( FormControlLabel::wrap( _t( 'Archive ordering:' ),
FormControlSelect::create( 'order', $block )->set_options( array('ASC' => _t( 'Oldest to Newest' ), 'DESC' => _t( 'Newest to Oldest' ) ) )
));
$form->append( FormControlLabel::wrap( _t( 'Display full month names:' ),
FormControlCheckbox::create( 'full_names', $block )
));
$form->append( FormControlLabel::wrap( _t( 'Append post count:' ),
Expand All @@ -213,7 +217,8 @@ public function action_block_content_monthly_archives( $block, $theme )
$results = Posts::get( array(
'content_type' => 'entry',
'status' => 'published',
'month_cts' => 1 )
'month_cts' => 1,
'orderby' => 'pubdate '.$block->order)
);

foreach ( $results as $result ) {
Expand Down Expand Up @@ -271,8 +276,16 @@ public function action_block_form_tag_archives( $form, $block )
FormControlCheckbox::create( 'show_counts', $block )
));
$form->append( FormControlLabel::wrap( _t( 'Preferred Output Style:' ),
FormControlSelect::create( 'style', $block )->set_options( array('dropdown' => _t( 'Dropdown' ), 'list' => _t( 'List' ) ) )
FormControlSelect::create( 'style', $block )->set_options( array( 'dropdown' => _t( 'Dropdown' ),
'list' => _t( 'List' ),
'cloud' => _t( 'Cloud' )) )
));
$form->append( FormControlLabel::wrap( _t( 'Cloud tag max font size (em):' ),
FormControlText::create('cloud_max',$block)
));
$form->append( FormControlLabel::wrap( _t( 'Cloud tag min font size (em):' ),
FormControlText::create('cloud_min',$block)
));
}

/**
Expand All @@ -287,22 +300,34 @@ public function action_block_content_tag_archives( $block, $theme )
{
$tags = array();
$results = Tags::vocabulary()->get_tree();
$minCount = 1000000;
$maxCount = 1;
if ($block->cloud_max == '') { $block->cloud_max = 3; }
if ($block->cloud_min == '') { $block->cloud_min = 0.8; }
$sizeIncrement = 0;

foreach( $results as $result ) {

$count = '';
if ( $block->show_counts ) {
$count = " (" . Posts::count_by_tag( $result->term_display, "published") . ")";
}
if ( $block->show_counts) {
$count = Posts::count_by_tag( $result->term_display, "published");
}

$url = URL::get( 'display_entries_by_tag', array( 'tag' => $result->term ) );
$tags[] = array(
'tag' => $result->term_display,
'count' => $count,
'url' => $url,
);

if ($count > $maxCount) { $maxCount = $count; }
if ($count < $minCount) { $minCount = $count; }
}

$sizeIncrement = round(($block->cloud_max - $block->cloud_min) / ($maxCount - $minCount),1);
$block->size_increment = $sizeIncrement;
$block->min_post_count = $minCount;

$block->tags = $tags;
}

Expand Down