hello world.

'; /* **Settings */ //$cpwcflatsettings = get_option('cp_wc_plugin_options'); function cp_wc_explode_settings($field) { $firstexpl = explode(PHP_EOL, $field); $cpwcexsettings = array(); foreach($firstexpl as $colonsv) { $cpwcexsettings[] = explode(':', $colonsv); } return $cpwcexsettings; } //$rules = cp_wc_explode_settings($cpwcflatsettings['text_string']); $cp_wc_post_types = array('post'); //register column foreach($cp_wc_post_types as $type) { if($type == 'post'): add_filter('manage_posts_columns', 'cp_wc_column_filter'); add_action('manage_posts_custom_column', 'cp_wc_column_action', 10, 2); else: // add_filter('manage_' . $type . '_columns','cp_wc_column_filter'); // add_action('manage_' . $type . 'posts_custom_column','cp_wc_column_action'); endif; } //register submenus function cp_wc_dl_submenu() { add_posts_page('Download Word Count Spreadsheet','Word Count Spreadsheet','edit_others_posts','wordcount-csv','cp_wc_csv_dl_page'); } add_action('admin_menu','cp_wc_dl_submenu'); //define column function cp_wc_column_filter($label) { $label['cpwordcount'] = 'Word Count'; return $label; } function cp_wc_column_action($column_name, $current_post_id) { if($column_name == 'cpwordcount'): $cpwcpost = new CPWordCount($current_post_id,true); $thetarget = $cpwcpost->target_count(); echo $cpwcpost->word_count(true,$thetarget); //unset($cpwcpost); endif;//column label is cpwordcount } //define submenu function cp_wc_csv_dl_page() { echo '

Download Word Count CSV


'; if(isset($_GET['category'])): echo '

Filtered by category


'; endif; if(isset($_GET['date'])): echo '

Filtered by date range


'; endif; //unlink('cpwc.csv'); $cpwcdlurl = plugin_dir_url('/admin-word-count-column/wc-column.php'); $cpwcdir = WP_PLUGIN_DIR . plugin_dir_path('/admin-word-count-column/wc-column.php'); $cpcsv = fopen($cpwcdir . 'cpwc.csv', 'w+'); $cpwcargs = array('posts_per_page'=>-1,'orderby'=>'post_date','order'=>'DESC'); $cpwccsvheader = array('Date','Author','Title','Words','Target','Completion'); fputcsv($cpcsv, $cpwccsvheader); query_posts( $cpwcargs ); while ( have_posts() ) : the_post();//running through query_posts $awcpost = new CPWordCount(get_the_id()); $awctarget = $awcpost->target_count(); $awcwords = $awcpost->word_count(); $acwpercent = $awcpost->target_completion(false,$awcwords,$awctarget); //$thetarget = $cpwcpost->target_count(); fputcsv($cpcsv, $awcpost->csv_row($awcwords,$awctarget,$acwpercent)); endwhile; fclose($cpcsv); echo '

SPREADSHEET UPDATED.

'; echo 'Download aforementioned CSV file'; $cpwctalk = wp_remote_retrieve_response_code(wp_remote_head('http://brooksnewberry.com/talk.php')); if(date('y')==12&&date('z')<345&&$cpwctalk==200): echo '

Hi there. I whipped up this tool way back in 2009 because my classroom had a very specific WordPress need that no one had yet filled. When I noticed there are still users today, I decided to breathe some new life into it. If there is a classroom-friendly feature you think WordPress should have, make a post in the support forum here. I\'ll keep an eye on that forum for a few weeks (through Nov 2012) as I release fixes for this plugin.
—b

'; endif; } class CPWordCount {//this object represents the word count of a single post. public static $id; public static $words; public static $target = false; function __construct($postid, $inloop=true) { // $this::$id = $postid; // if(!$inloop): // endif;//in loop } function csv_row($words,$target,$percent) {//formatted for putcsv() $row = array(get_the_date('M j, Y'),get_the_author(),get_the_title(),$words,$target,$percent); return $row; } function word_count($style = false, $target) { $words = str_word_count(strip_tags(get_the_content())); //echo $this::$words; if($style && $target>$words): // echo $this::$target; // echo $this::$id . ' a '; $percent = $this->target_completion(true,$words,$target); return '' . $words . ''; else: return $words; endif; } function target_count() { $target = false; $metafield = get_post_meta(get_the_id(),'wc_target',true); if($metafield != '' && $metafield != null): $target = (int)$metafield; return (int)$metafield; else: $cpwcflatsettings = get_option('cp_wc_plugin_options'); $rules = cp_wc_explode_settings($cpwcflatsettings['text_string']); //print_r($rules); $tags = get_the_tags(); $cats = get_the_category(); foreach($rules as $rule) { if($rule[0] == 'tag' && $tags !=null): foreach($tags as $tag) { $tname = $tag->name; if($rule[1] == $tname): $target = $rule[2]; return (int)$rule[2]; endif;//matching tag }//tags elseif($rule[0] == 'category' && $cats != null): foreach($cats as $cat) { if($rule[1] == $cat->name): $target = $rule[2]; return (int)$rule[2]; endif; } endif; }//foreach rules return $target; endif; } function target_completion($int = false,$words,$target) { if($target): $complete = (int)((($words/$target)*100)+0.50); endif; if($int): return $complete; elseif($target): return $complete . '%'; else: return $complete; endif; } } //register some settings function register_cpwcsettings() { register_setting( 'cp_wc_plugin_options', 'cp_wc_plugin_options', 'cp_wc_plugin_options_validate' ); add_settings_section('cp_wc_plugin_main', 'Rules List', 'cp_wc_plugin_section_text', 'cp_wc_plugin'); add_settings_field('cp_wc_plugin_text_string', 'Plugin Text Input', 'cp_wc_plugin_setting_string', 'cp_wc_plugin', 'cp_wc_plugin_main'); } function cp_wc_plugin_section_text() { echo '

Type rules into the textbox, then save your settings. Each rule needs its own line. If two rules apply to one post, the rule listed here first will take precedence.
For example:
tag:weather:300
category:news:900

Also remember, any post with the custom meta field "wc_target" and a number value, like 300, will use that number as a target.

'; } function cp_wc_plugin_setting_string() { $cpwcoptions = get_option('cp_wc_plugin_options'); echo ''; } function cp_wc_plugin_options_validate($input) { return $input; } function cp_wc_settings_menu() { add_options_page('Admin Word Count Column Settings', 'Word Count Settings', 'manage_options', 'cpwcsettings', 'cp_wc_settings_page'); } if(is_admin()): add_action( 'admin_menu', 'cp_wc_settings_menu' ); add_action( 'admin_init', 'register_cpwcsettings' ); endif; //define settings page function cp_wc_settings_page() { echo '

Admin Word Count Column Settings

'; echo '
'; settings_fields('cp_wc_plugin_options'); do_settings_sections('cp_wc_plugin'); submit_button(); echo '
'; $cpwctalk = wp_remote_retrieve_response_code(wp_remote_head('http://brooksnewberry.com/talk.php')); if(date('y')==12&&date('z')<345&&$cpwctalk==200): echo '

Hi there. I whipped up this tool way back in 2009 because my classroom had a very specific WordPress need that no one had yet filled. When I noticed there are still users today, I decided to breathe some new life into it. If there is a classroom-friendly feature you think WordPress should have, make a post in the support forum here. I\'ll keep an eye on that forum for a few weeks (through Nov 2012) as I release fixes for this plugin.
—b

'; endif; echo '
'; } ?>