Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added set truncation feature

  • Loading branch information...
commit 93868585bd52ec4e45df10059969c006832e1790 1 parent 402d0f7
Dan Crimmins dan-crimmins authored
Showing with 15 additions and 5 deletions.
  1. +12 −2 recent-activities-widget.php
  2. +3 −3 views/recent-activities.php
14 recent-activities-widget.php
View
@@ -93,7 +93,6 @@ public function widget( $args, $instance ){
->category($category)
->get_all_activities()
->activities;
-
include ('views/recent-activities.php');
@@ -141,7 +140,13 @@ public function update($new_instance, $old_instance){
if($value == 'on' && !isset($new_instance[$key])){
unset($instance[$key]);
}
-
+
+ }
+
+ //Default truncation to 80 chars if left blank
+ if((isset($instance['recent_trunc_chars']) && ! count(trim($instance['recent_trunc_chars']))) || (! isset($instance['recent_trunc_chars']))) {
+
+ $instance['recent_trunc_chars'] = 80;
}
return $instance;
@@ -205,6 +210,11 @@ public function form($instance){
'type' => 'select',
'label' => 'Show categories',
'options' => $category_terms
+ ),
+
+ array('field_id' => 'recent_trunc_chars',
+ 'type' => 'text',
+ 'label' => 'Truncate at (chars)'
)
);
6 views/recent-activities.php
View
@@ -31,7 +31,7 @@
$is_reply = true;
$act_type_text = ($activity->comment_parent_author[0]->comment_type == 'answer') ? 'answer' : 'comment';
$act_text = return_screenname_link($activity->author) . ' Replied to ' . return_screenname_link($activity->comment_parent_author[0]->user_id) .'\'s ' . $act_type_text . ':';
- $parent_excerpt = strlen($activity->comment_parent_author[0]->comment_content) > 200 ? substr( truncated_text(sanitize_text($activity->comment_parent_author[0]->comment_content)), 0, 200 ) . "…" : truncated_text(sanitize_text($activity->comment_parent_author[0]->comment_content));
+ $parent_excerpt = strlen($activity->comment_parent_author[0]->comment_content) > 200 ? truncated_text(sanitize_text($activity->comment_parent_author[0]->comment_content), $recent_trunc_chars) : truncated_text(sanitize_text($activity->comment_parent_author[0]->comment_content), $recent_trunc_chars);
} else {
@@ -42,7 +42,7 @@
}
- $excerpt = '<li class="recent-activity_excerpt">' . ( strlen( $activity->content ) > 200 ? substr( truncated_text(sanitize_text($activity->content)), 0, 200 ) . "&#8230;" : truncated_text(sanitize_text($activity->content))) . '</li>';
+ $excerpt = '<li class="recent-activity_excerpt">' . ( strlen( $activity->content ) > $recent_trunc_chars ? truncated_text(sanitize_text($activity->content), $recent_trunc_chars) : truncated_text(sanitize_text($activity->content), $recent_trunc_chars)) . '</li>';
$time_options = array(
"timestamp" => strtotime( $activity->date ),
@@ -63,7 +63,7 @@
<?php get_partial( 'parts/space_date_time', $time_options ); ?>
<a href="<?php echo (in_array($activity->type, $recent->comment_types)) ? ((count($activity->post->category)) ? get_term_link($activity->post->category[0]) : null) : ((count($activity->category)) ? get_term_link($activity->category[0]) : null) ;?>" class="category"><?php echo (in_array($activity->type, $recent->comment_types)) ? ((count($activity->post->category)) ? $activity->post->category[0]->cat_name : 'Uncategorized') : ((count($activity->category)) ? $activity->category[0]->cat_name : 'Uncategorized') ;?></a>
</li>
- <li class="recent-activity_title"><a href="<?php echo (in_array($activity->type, $recent->comment_types) || $activity->type == '') ? get_permalink($activity->post->ID) : get_permalink($activity->ID) ;?>"><?php echo (in_array($activity->type, $recent->comment_types) || $activity->type == '') ? (($is_reply) ? '"' . $parent_excerpt . '"' : truncated_text(sanitize_text($activity->post->post_title))) : truncated_text(sanitize_text($activity->title));?></a></li>
+ <li class="recent-activity_title"><a href="<?php echo (in_array($activity->type, $recent->comment_types) || $activity->type == '') ? get_permalink($activity->post->ID) : get_permalink($activity->ID) ;?>"><?php echo (in_array($activity->type, $recent->comment_types) || $activity->type == '') ? (($is_reply) ? '"' . $parent_excerpt . '"' : truncated_text(sanitize_text($activity->post->post_title), $recent_trunc_chars)) : truncated_text(sanitize_text($activity->title), $recent_trunc_chars);?></a></li>
<?php if (in_array($activity->type, $recent->comment_types) || $activity->type == '') {echo $excerpt;} ?>
</ul>
Please sign in to comment.
Something went wrong with that request. Please try again.