prefix."activity"; $structure = "CREATE TABLE `".$table."` ( `id` int(9) NOT NULL auto_increment, `user_id` bigint(20) NOT NULL, `act_type` varchar(20) NOT NULL, `act_date` datetime default NULL, `act_params` text, UNIQUE KEY `id` (`id`), KEY `user_id` (`user_id`), KEY `act_date` (`act_date`) );"; dbDelta($structure); $options['act_prune'] = '500'; $options['act_feed_display'] = false; $options['act_date_format'] = 'yyyy/mm/dd'; $options['act_date_relative']= true; $options['act_connect']= true; $options['act_profiles']= true; $options['act_posts']= true; $options['act_comments']= true; $options['act_feed_connect']= false; $options['act_feed_profiles']= true; $options['act_feed_posts']= true; $options['act_feed_comments']= true; $options['act_icons']= 'g'; add_option('act_settings', $options); wp_schedule_event(time(), 'daily', 'act_cron_install'); } register_activation_hook( __FILE__, 'act_install' ); //we add actions to hooks to log their events add_action('send_headers', 'act_session'); add_action('profile_update', 'act_profile_edit'); add_action('publish_post', 'act_post_add'); add_action('comment_post', 'act_comment_add'); add_action('add_link', 'act_link_add'); function act_cron(){ global $wpdb, $options, $plugin_page; $wpdb->query("DELETE FROM ".$wpdb->prefix."activity ORDER BY id ASC LIMIT ".$options['act_prune']); } add_action('act_cron_install','act_cron'); function act_header(){ echo '' . "\n"; } add_action('wp_head', 'act_header'); function act_profile_option(){ global $wpdb, $user_ID; $act_private = get_usermeta($user_ID, 'act_private'); ?>

value="true" />
query("INSERT INTO ".$wpdb->prefix."activity (user_id, act_type, act_date, act_params) VALUES($user_ID,'CONNECT', '".$time."', '')"); $url = parse_url(get_option('home')); $_SESSION['act_logged']= time(); } } } function act_reinit(){ if ($_SESSION['act_logged']){ unset($_SESSION['act_logged']);} } add_action('wp_login', 'act_reinit'); add_action('wp_logout', 'act_reinit'); function act_profile_edit($user){ global $wpdb, $user_ID, $options; if ($options['act_profiles'] and !get_usermeta($user_ID, 'act_private')){ $time=mysql2date("Y-m-d H:i:s", time()); $wpdb->query("INSERT INTO ".$wpdb->prefix."activity (user_id, act_type, act_date, act_params) VALUES($user_ID, 'PROFILE_EDIT', '".$time."', $user)"); } } function act_post_add($post){ global $wpdb, $user_ID, $options; if ($options['act_posts'] and !get_usermeta($user_ID, 'act_private')){ $time=mysql2date("Y-m-d H:i:s", time()); if ($wpdb->get_var("SELECT COUNT(*) FROM ".$wpdb->prefix."activity WHERE act_params=$post AND act_type='POST_ADD'") > 0){ $type='POST_EDIT'; }else{ $type='POST_ADD'; } $wpdb->query("INSERT INTO ".$wpdb->prefix."activity (user_id, act_type, act_date, act_params) VALUES($user_ID, '".$type."', '".$time."', $post)"); } } function act_comment_add($comment){ global $wpdb, $user_ID, $options; if ($options['act_comments'] and !get_usermeta($user_ID, 'act_private')){ $time=mysql2date("Y-m-d H:i:s", time()); $wpdb->query("INSERT INTO ".$wpdb->prefix."activity (user_id, act_type, act_date, act_params) VALUES($user_ID,'COMMENT_ADD', '".$time."', $comment)"); } } function act_link_add($link){ global $wpdb, $user_ID, $options; if ($options['act_links'] and !get_usermeta($user_ID, 'act_private')){ $time=mysql2date("Y-m-d H:i:s", time()); $wpdb->query("INSERT INTO ".$wpdb->prefix."activity (user_id, act_type, act_date, act_params) VALUES($user_ID, 'LINK_ADD', '".$time."', $link)"); } } function act_last_connect($user=''){ global $wpdb, $options, $user_ID; if (!$user){ $user = $user_ID; } if ($options['act_connect'] and !get_usermeta($user_ID, 'act_private')){ $last_connect = $wpdb->get_var("SELECT MAX(act_date) FROM ".$wpdb->prefix."activity WHERE user_id = '".$user."'"); echo __("Last logon :", 'wp-activity')." ".nicetime($last_connect); } } function act_stream($number='30', $title=''){ global $wpdb, $options; if ($title == ''){ $title= __("Recent Activity", 'wp-activity'); } if ($options['act_feed_display']){ $title .= ' '; } $wp_url = get_bloginfo('wpurl'); echo '

'.$title.'

'; } function nicetime($posted_date, $admin=false) { $act_opt=get_option('act_settings'); $date_relative = $act_opt['act_date_relative']; $date_format = $act_opt['act_date_format']; $in_seconds = strtotime($posted_date); $relative_date = ''; $diff = time()-$in_seconds; $months = floor($diff/2592000); $diff -= $months*2419200; $weeks = floor($diff/604800); $diff -= $weeks*604800; $days = floor($diff/86400); $diff -= $days*86400; $hours = floor($diff/3600); $diff -= $hours*3600; $minutes = floor($diff/60); $diff -= $minutes*60; $seconds = $diff; if ($months>0 or !$date_relative or $admin) { // over a month old, just show date if (!$date_relative or $admin){ $h = substr($posted_date,10); } else { $h = ''; } switch ($date_format){ case 'dd/mm/yyyy': return substr($posted_date,8,2).'/'.substr($posted_date,5,2).'/'.substr($posted_date,0,4).$h; break; case 'mm/dd/yyyy': return substr($posted_date,5,2).'/'.substr($posted_date,8,2).'/'.substr($posted_date,0,4).$h; break; case 'yyyy/mm/dd': default: return substr($posted_date,0,4).'/'.substr($posted_date,5,2).'/'.substr($posted_date,8,2).$h; break; } } else { if ($weeks>0) { // weeks and days $relative_date .= ($relative_date?', ':'').$weeks.' '.($weeks>1? __('weeks', 'wp-activity'):__('week', 'wp-activity')); $relative_date .= $days>0?($relative_date?', ':'').$days.' '.($days>1? __('days', 'wp-activity'):__('day', 'wp-activity')):''; } elseif ($days>0) { // days and hours $relative_date .= ($relative_date?', ':'').$days.' '.($days>1? __('days', 'wp-activity'):__('day', 'wp-activity')); $relative_date .= $hours>0?($relative_date?', ':'').$hours.' '.($hours>1? __('hours', 'wp-activity'):__('hour', 'wp-activity')):''; } elseif ($hours>0) { // hours and minutes $relative_date .= ($relative_date?', ':'').$hours.' '.($hours>1? __('hours', 'wp-activity'):__('hour', 'wp-activity')); $relative_date .= $minutes>0?($relative_date?', ':'').$minutes.' '.($minutes>1? __('minutes', 'wp-activity'):__('minute', 'wp-activity')):''; } elseif ($minutes>0) { // minutes only $relative_date .= ($relative_date?', ':'').$minutes.' '.($minutes>1? __('minutes', 'wp-activity'):__('minute', 'wp-activity')); } else { // seconds only $relative_date .= ($relative_date?', ':'').$seconds.' '.($seconds>1? __('seconds', 'wp-activity'):__('second', 'wp-activity')); } } // show relative date and add proper verbiage return sprintf(__('%s ago', 'wp-activity'), $relative_date); } function act_admin_menu(){ $plugin_page = add_options_page('WP-Activity', 'WP-Activity', 8, 'wp-activity', 'act_admin'); add_action( 'admin_head-'. $plugin_page, 'act_header' ); } add_action('admin_menu', 'act_admin_menu'); function act_admin(){ global $wpdb, $act_version; $count = $wpdb->get_var("SELECT count(ID) FROM ".$wpdb->prefix."activity"); ?>

WP-Activity

()
- prefix."activity"; if ( $results = $wpdb->query( $sql ) ){ echo '

'.__('Activity logs deleted.', 'wp-activity').'

'; } break; default: $options['act_connect']=$_POST['act_connect']; $options['act_profiles']=$_POST['act_profiles']; $options['act_posts']=$_POST['act_posts']; $options['act_comments']=$_POST['act_comments']; $options['act_links']=$_POST['act_links']; $options['act_feed_connect']=$_POST['act_feed_connect']; $options['act_feed_profiles']=$_POST['act_feed_profiles']; $options['act_feed_posts']=$_POST['act_feed_posts']; $options['act_feed_comments']=$_POST['act_feed_comments']; $options['act_feed_links']=$_POST['act_feed_links']; $options['act_feed_display']=$_POST['act_feed_display']; $options['act_prune']=$_POST['act_prune']; $options['act_date_format']=$_POST['act_date_format']; $options['act_date_relative']=$_POST['act_date_relative']; $options['act_icons']=$_POST['act_icons']; update_option('act_settings', $options); break; } } $act_opt=get_option('act_settings'); extract($act_opt); ?>


name="act_date_relative" />

name="act_icons" value="g" />
name="act_icons" value="a" />
name="act_icons" value="n" />

name="act_feed_display" />
name="act_connect" /> name="act_feed_connect" />
name="act_profiles" /> name="act_feed_profiles" />
name="act_posts" /> name="act_feed_posts" />
name="act_comments" /> name="act_feed_comments" />
name="act_links" /> name="act_feed_links" />

' />

0){ $nbpages++; } echo __("Page", 'wp-activity').' '.$page.'/'.$nbpages; ?> get_results("SELECT ID, display_name FROM $wpdb->users"); foreach ($users as $user) { $users_display[$user->ID]=$user->display_name; } $sql = "SELECT * FROM ".$wpdb->prefix."activity ORDER BY id DESC LIMIT ".$start.",50"; if ( $logins = $wpdb->get_results( $sql)){ foreach ( (array) $logins as $act ){ $user_display = $users_display[$act->user_id]; echo ''; switch ($act->act_type){ case 'CONNECT': echo ''; break; case 'COMMENT_ADD': $act_comment=get_comment($act->act_params); $act_post=get_post($act_comment->comment_post_ID); echo ''; break; case 'POST_ADD': case 'POST_EDIT': $act_post=get_post($act->act_params); echo ''; break; case 'PROFILE_EDIT': echo ''; break; case 'LINK_ADD': $link = get_bookmark($act->act_params); if ($link->link_visible == 'Y'){ echo ''; } break; default: break; } echo ''; } } ?>
1){ echo ''.__("« Previous Page").''; } ?> '.__("Next Page »").''; } ?>
'.nicetime($act->act_date, true).''.$user_display.''.$act->act_type.''.$user_display.''.$act->act_type.''.$act_post->post_title.''.$user_display.''.$act->act_type.''.$act_post->post_title.''.$user_display.''.$act->act_type.''.$user_display.''.$act->act_type.''.$link->link_name.'
1){ echo ''.__("« Previous Page").''; } ?> '.__("Next Page »").''; } ?>

Dric. Version %s.', 'wp-activity'), $act_version) ?>

'wp-activity', 'description' => __('Display a stream of registered users events', 'wp-activity') ); /* Widget control settings. */ $control_ops = array( 'height' => 350, 'id_base' => 'wp-activity' ); /* Create the widget. */ $this->WP_Widget( 'wp-activity', __('Wp-Activity Widget', 'wp-activity'), $widget_ops, $control_ops ); } function widget( $args, $instance ) { extract( $args ); $title = apply_filters('widget_title', $instance['title'] ); $number = $instance['number']; echo $before_widget; if ( $title ) $title = $before_title . $title . $after_title; act_stream($number, $title); echo $after_widget; } function update( $new_instance, $old_instance ) { $instance = $old_instance; $instance['title'] = strip_tags( $new_instance['title'] ); $instance['number'] = $new_instance['number']; return $instance; } function form( $instance ) { $defaults = array( 'title' => __('Recent Activity', 'wp-activity'), 'number' => '30'); $instance = wp_parse_args( (array) $instance, $defaults ); ?>