load(); $this->addHooks(); } public function addHooks() { if(!is_admin()) return; add_action('admin_menu', array($this, 'Author_Progress_Bar_Create_Menu'), 10); global $wp_version; if ( version_compare($wp_version, '2.7', '>=' ) ) { add_filter( 'plugin_action_links', array($this, 'add_filter_plugin_action_links'), 10, 2 ); } } function add_filter_plugin_action_links( $links, $file ) { if ( $file == AUTHOR_PROGRESS_BAR_PLUGIN_BASENAME ) { $links[] = '' . __('Settings') . ''; } return $links; } function GetPluginOptionsURL() { if (function_exists('admin_url')) { // since WP 2.6.0 $adminurl = trailingslashit(admin_url()); } else { $adminurl = trailingslashit(get_settings('siteurl')).'wp-admin/'; } return $adminurl.'options-general.php'.'?page=' . AUTHOR_PROGRESS_BAR_PLUGIN_NAME; } function Author_Progress_Bar_Create_Menu() { add_options_page('Author Progress Bar', 'Author Progress Bar', 10, AUTHOR_PROGRESS_BAR_PLUGIN_NAME, array($this, 'Author_Progress_Bar_Options_Page')); } function Author_Progress_Bar_Options_Page() { global $pb_PluginName; if(isset($_POST['updateSettings'])) { if(is_numeric($_POST['width']) || is_numeric($_POST['height'])) { echo "

Specify units! Settings were not saved.

"; } else { $settings['width'] = $_POST['width']; $settings['height'] = $_POST['height']; $settings['bg_color'] = $_POST['bg_color']; $settings['border_color'] = $_POST['border_color']; $settings['author_progress_bar_color'] = $_POST['author_progress_bar_color']; $settings['precision'] = $_POST['precision']; $this->settings = $settings; $this->save(); echo "

Settings have been saved.

"; } } extract($this->settings); require('frontend_style.php'); ?>

The _config.php file is no longer needed since version 0.4. Since there are no write permissions on this file or the plugin directory, delete the file manually or assign the appropriate rights!



Settings › Author Progress Bar

Height x
Background color
Color of the progress bar
Color of the frame
Number of decimal places


Progress Bar Design :


settings = get_option($this->optionName); if(is_null($this->settings) || empty($this->settings)) { $this->loadDefaults(); } } public function save() { update_option($this->optionName, $this->settings); } public function loadDefaults() { $settings['width'] = '100%'; $settings['height'] = '12px'; $settings['bg_color'] = '#f3f3f3'; $settings['author_progress_bar_color'] = '#247102'; $settings['border_color'] = '#000000'; $settings['precision'] = 0; // legacy (<= 0.4): load all _config settings if the file is existing. $configFile = plugin_dir_path(__FILE__) . '_config.php'; if(is_readable($configFile)) { include($configFile); $settings['width'] = $width; $settings['height'] = $height; $settings['bg_color'] = $bg_color; $settings['border_color'] = $border_color; $settings['author_progress_bar_color'] = $author_progress_bar_color; if(is_writable($configFile) && is_writable(plugin_dir_path(__FILE__))) { unlink($configFile); } } $this->settings = $settings; } } /******************************************************************************* ====================== Progress Bar Management ================================= ********************************************************************************/ class Author_Progress_BarWidgetManager { public function __construct() { add_action('widgets_init',create_function('','register_widget("Author_Progress_BarWidget");')); } } /******************************************************************************* ======================== Progress Bar Widget =================================== ********************************************************************************/ class Author_Progress_BarWidget extends WP_Widget { public $id_base = 'author_progress_bar'; public $name = 'Author Progress Bar'; public $description = 'Author Progress Bar displays the progress of your book in a sidebar widget. Allowing for greater audience engagement & to motivate you the writer.'; public $progressTitle = array('No words', 'One word', ' words'); public $progressLabel = 'word'; public $widgetTitle = 'I am writing'; public $progressTitleAudio = array('No minute', 'One Minute', ' Minutes'); public $progressLabelAudio = 'Minute'; public $widgetTitleAudio = 'I am working on'; function singularPlural($amount, $list) { if($amount > 1) { return $amount . ' ' . $list[2]; } elseif($amount == 1) { return $list[1]; } return $list[0]; } function __construct() { parent::WP_Widget($this->id_base, $this->name, array('description' => $this->description)); } function widget($args,$instance) { global $author_progress_bar_settings; extract($args); $title = apply_filters('widget_title', $instance['title'] ); $author = apply_filters('widget_author',$instance['author']); $book = apply_filters('widget_book',$instance['book']); $progress = apply_filters('widget_progress',$instance['progress']); $max = apply_filters('widget_max',$instance['max']); $progress_bar_type = apply_filters('widget_progress_bar_type',$instance['progress_bar_type']); $cover = apply_filters('widget_cover',$instance['cover']); $info = apply_filters('widget_info',$instance['info']); if(strcmp($progress_bar_type,"book")==0){ $before_title = '

'; $after_title = '

'; } elseif(strcmp($progress_bar_type,"ebook")==0){ $before_title = '

'; $after_title = '

'; } elseif(strcmp($progress_bar_type,"kindle")==0) { $before_title = '

'; $after_title = '

'; } elseif(strcmp($progress_bar_type,"audio")==0) { $before_title = '

'; $after_title = '

'; } echo $before_widget; if ($title){ echo $before_title . $title . $after_title; } extract($author_progress_bar_settings->settings); include('frontend_style.php'); if($cover) { ?>


()

currentProgress($progress, $max, $precision); ?>%

currentPage($progress, $max); ?> of singularPlural($max, $this->progressTitleAudio);} else {echo $this->singularPlural($max, $this->progressTitle);} ?>

Sponsored by Featured Fiction

0) { return round(($progress/$max)*100, $precision); } return 0; } function update( $new_instance, $old_instance ) { $instance = $old_instance; $instance['title'] = strip_tags($new_instance['title']); $instance['author']= strip_tags($new_instance['author']); $instance['book'] = strip_tags($new_instance['book']); $instance['progress'] = strip_tags($new_instance['progress']); $instance['max'] = strip_tags($new_instance['max']); $instance['progress_bar_type'] = strip_tags($new_instance['progress_bar_type']); $instance['cover'] = strip_tags($new_instance['cover']); $instance['info'] = $new_instance['info']; return $instance; } function form( $instance ) { if ( $instance ) { $title = esc_attr($instance['title']); $author = esc_attr($instance['author']); $book = esc_attr($instance['book']); $progress = esc_attr($instance['progress']); $max = esc_attr($instance['max']); $progress_bar_type = esc_attr($instance['progress_bar_type']); $cover = esc_attr($instance['cover']); $info = esc_attr($instance['info']); } else { $title = __( $this->widgetTitle, 'title' ); $author = __('','author'); $book = __('','book'); $progress = __('','progress'); $max = __('','max'); $progress_bar_type = __('','progress_bar_type'); $cover = __('','cover'); $info = __('','info'); } // load the script to use the media upload dialog. wp_enqueue_script( 'author_progress_barMediaUpload' ); ?>

of

Type of progress bar:

Add Media'; echo ''; } else { echo 'Upload/Insert '; } } } // Initialize the widget manager. new Author_Progress_BarWidgetManager(); ?>