diff --git a/wp-content/plugins/mark-as-read/includes/dashboard-widgets.php b/wp-content/plugins/mark-as-read/includes/dashboard-widgets.php new file mode 100644 index 0000000..c8c9bfd --- /dev/null +++ b/wp-content/plugins/mark-as-read/includes/dashboard-widgets.php @@ -0,0 +1,14 @@ +'; + } + if($read_text == '') { + if($mar_options['read_text'] != '') { + $read_text = $mar_options['read_text']; + } else { + $read_text = 'Mark as Read'; + } + } + if($unread_text == '') { + if($mar_options['unread_text'] != '') { + $unread_text = $mar_options['unread_text']; + } else { + $unread_text = 'Mark as Unread'; + } + } + + if(mar_check_post_is_read($post_id, mar_get_user_id())) { + $link .= '' . $unread_text . ''; + $link .= ''; + } else { + $link .= ''; + $link .= '' . $read_text . ''; + } + if($wrapper == true) { + $link .= ''; + } + return $link; + } +} + +// show mark as read / unread links automatically if enabled. Do not use this as a template tag +function mar_show_links($content) { + global $post; + global $mar_options; + + if(is_single() && get_post_type() == 'post' && $mar_options['show_links'] == true) { + + if($mar_options['post_position'] == 'Top') { + $content = mar_read_unread_links($mar_options['read_text'], $mar_options['unread_text']) . $content; + } else { + $content = $content . mar_read_unread_links($mar_options['read_text'], $mar_options['unread_text']); + } + } + return $content; +} +add_filter('the_content', 'mar_show_links'); + + +function mar_list_unread_posts($number = 5) { + if(is_user_logged_in()) { + $read_ids = mar_get_user_read_posts( mar_get_user_id() ); + $unread_posts = get_posts(array('exclude' => $read_ids, 'numberposts' => $number)); + ob_start(); ?> +
+ + +
++ + +
+ 'Show the number of posts the user has read, not read, etc')); + } + + /** @see WP_Widget::widget */ + function widget($args, $instance) { + extract( $args ); + + if(is_user_logged_in()) { + + $title = apply_filters('widget_title', $instance['title']); + $read_posts = (bool)$instance['read_posts']; + $read_label = $instance['read_label']; + $unread_posts = (bool)$instance['unread_posts']; + $unread_label = $instance['unread_label']; + $total_posts = (bool)$instance['total_posts']; + $total_label = $instance['total_label']; + $percentage = (bool)$instance['percentage']; + $percentage_label = $instance['percentage_label']; + + $labels = array( + 'read' => $read_label, + 'unread' => $unread_label, + 'total' => $total_label, + 'percentage' => $percentage_label + ); + + echo $before_widget; + if ( $title ) { + echo $before_title . $title . $after_title; + } + echo mar_list_user_report( + array( + 'read' => $read_posts, + 'unread' => $unread_posts, + 'total' => $total_posts, + 'percentage' => $percentage, + 'labels' => array( + 'read' => $read_label, + 'unread' => $unread_label, + 'total' => $total_label, + 'percentage' => $percentage_label + ) + ) + ); + echo $after_widget; + } + } + + /** @see WP_Widget::update */ + function update($new_instance, $old_instance) { + $instance = $old_instance; + $instance['title'] = strip_tags($new_instance['title']); + $instance['read_posts'] = strip_tags($new_instance['read_posts']); + $instance['read_label'] = strip_tags($new_instance['read_label']); + $instance['unread_posts'] = strip_tags($new_instance['unread_posts']); + $instance['unread_label'] = strip_tags($new_instance['unread_label']); + $instance['total_posts'] = strip_tags($new_instance['total_posts']); + $instance['total_label'] = strip_tags($new_instance['total_label']); + $instance['percentage'] = strip_tags($new_instance['percentage']); + $instance['percentage_label'] = strip_tags($new_instance['percentage_label']); + return $instance; + } + + /** @see WP_Widget::form */ + function form($instance) { + + $title = esc_attr($instance['title']); + $read_posts = esc_attr($instance['read_posts']); + $read_label = esc_attr($instance['read_label']); + $unread_posts = esc_attr($instance['unread_posts']); + $unread_label = esc_attr($instance['unread_label']); + $total_posts = esc_attr($instance['total_posts']); + $total_label = esc_attr($instance['total_label']); + $percentage = esc_attr($instance['percentage']); + $percentage_label = esc_attr($instance['percentage_label']); + ?> ++ + +
++ /> + +
++ + +
++ /> + +
++ + +
++ /> + +
++ + +
++ /> + +
++ + +
+ 'Show your most read posts')); + } + + /** @see WP_Widget::widget */ + function widget($args, $instance) { + extract( $args ); + + $title = apply_filters('widget_title', $instance['title']); + $number = (int)$instance['number']; + $read_count = (bool)$instance['read_count']; + if($number == '' || !isset($number)) { $number = 5; } + echo $before_widget; + if ( $title ) { + echo $before_title . $title . $after_title; + } + echo mar_most_read($number, $read_count); + echo $after_widget; + + } + + /** @see WP_Widget::update */ + function update($new_instance, $old_instance) { + $instance = $old_instance; + $instance['title'] = strip_tags($new_instance['title']); + $instance['number'] = strip_tags($new_instance['number']); + $instance['read_count'] = strip_tags($new_instance['read_count']); + return $instance; + } + + /** @see WP_Widget::form */ + function form($instance) { + + $title = esc_attr($instance['title']); + $number = esc_attr($instance['number']); + $read_count = esc_attr($instance['read_count']); + + ?> ++ + +
++ + +
++ /> + +
+ 'Show link to mark current post as read or unread')); + } + + /** @see WP_Widget::widget */ + function widget($args, $instance) { + extract( $args ); + $title = apply_filters('widget_title', $instance['title']); + $read = apply_filters('widget_title', $instance['read']); + $unread = apply_filters('widget_title', $instance['unread']); + + if(is_single() && is_user_logged_in()) { + + echo $before_widget; + if ( $title ) { + echo $before_title . $title . $after_title; + } + echo mar_read_unread_links($read, $unread); + echo $after_widget; + } + } + + /** @see WP_Widget::update */ + function update($new_instance, $old_instance) { + $instance = $old_instance; + $instance['title'] = strip_tags($new_instance['title']); + $instance['read'] = strip_tags($new_instance['read']); + $instance['unread'] = strip_tags($new_instance['unread']); + return $instance; + } + + /** @see WP_Widget::form */ + function form($instance) { + + $title = esc_attr($instance['title']); + $read = esc_attr($instance['read']); + $unread = esc_attr($instance['unread']); + + ?> ++ + +
++ + +
++ + +
+ ID; +} + +// adds a post to the user meta +function mar_add_to_usermeta($post_id) { + $user_id = mar_get_user_id(); + $mar_read = mar_get_user_read_posts($user_id); + // add out post id to the end of the array + $mar_read[] = $post_id; + mar_update_user_meta($mar_read, $user_id); +} + +// removes a post ID from the user meta +function mar_remove_from_usermeta($post_id) { + $user_id = mar_get_user_id(); + $mar_read = mar_get_user_read_posts($user_id); + foreach ($mar_read as $read_post => $id) { + if ($id == $post_id) { + unset($mar_read[$read_post]); + } + } + mar_update_user_meta($mar_read, $user_id); +} + +// updates the current users read IDs +function mar_update_user_meta($arr, $user_id) { + return update_user_meta($user_id,'mar_read_posts', $arr); +} + +// gets all read posts for the current user +function mar_get_user_read_posts($user_id) { + return get_user_meta($user_id, 'mar_read_posts', true); +} + +// processes the ajax mark as read request +function mar_post_mark_as_read() { + if ( isset( $_POST["post_read"] ) ) { + $post_id = intval($_POST["post_read"]); + + $mark_as_read = mar_add_to_usermeta($post_id); + $update_count = mar_increase_count($post_id); + + die(); + } +} +add_action('wp_ajax_mark_post_as_read', 'mar_post_mark_as_read'); + +// processes the ajax mark as unread request +function mar_post_mark_as_unread() { + if ( isset( $_POST["del_post_id"] ) ) { + $post_id = intval($_POST["del_post_id"]); + $mark_as_unread = mar_remove_from_usermeta($post_id); + $update_count = mar_decrease_count($post_id); + die(); + } +} +add_action('wp_ajax_mark_post_as_unread', 'mar_post_mark_as_unread'); + +// increases the read posts count for $post_id +function mar_increase_count($post_id) { + global $wpdb; + global $mar_db_table; + + // add the post ID to the count database if it doesn't already exist + if(!$wpdb->query("SELECT `read_count` FROM `" . $mar_db_table . "` WHERE id=" . $post_id . ";")) { + $add_post_id = $wpdb->insert( $mar_db_table, + array( + 'id' => $post_id, + 'read_count' => 1 + ) + ); + } else { + $count = $wpdb->query("UPDATE " . $mar_db_table . " SET read_count = read_count + 1 WHERE id=" . $post_id . ";"); + } +} + +// decreases the bookmark count for $post_id +function mar_decrease_count($post_id) { + global $wpdb; + global $mar_db_table; + + $count = $wpdb->query("UPDATE " . $mar_db_table . " SET read_count = read_count - 1 WHERE id=" . $post_id . ";"); +} + +// retrieves all report card data for the current user +// this includes unread / read posts with counts +function mar_get_user_report() { + $user_report = array(); + + // get all read posts for the current user + $read_posts = mar_get_user_read_posts( mar_get_user_id() ); + + // get all unread posts for the current user + $unread_posts = get_posts(array('exclude' => $read_posts, 'posts_per_page' => -1)); + + $total_posts = count($unread_posts) + count($read_posts); + // calculate the percentage of post sthat have been read + $read_percentage = round( ( count($read_posts) * 100 ) / $total_posts); + + $user_report['read_posts'] = $read_posts; + $user_report['read_posts_count'] = count($read_posts); + $user_report['unread_posts_count'] = count($unread_posts); + $user_report['total_posts'] = $total_posts; + $user_report['read_percentage'] = $read_percentage; + + return $user_report; +} + +// automarks a post as read after the user has been on the post for the designated length of time +function mar_auto_mark_as_read($content) { + global $mar_options, $post; + + // proceed if the auto option is enabled and we are on a single post + if($mar_options['auto'] && is_single()) { + // proceed if the post is not already marked as read + if(!mar_check_post_is_read($post->ID, mar_get_user_id())) { + mar_load_auto_scripts(); + } + } +} +add_action('template_redirect', 'mar_auto_mark_as_read'); \ No newline at end of file diff --git a/wp-content/plugins/mark-as-read/includes/mark-as-read.js b/wp-content/plugins/mark-as-read/includes/mark-as-read.js new file mode 100644 index 0000000..f3ef4f6 --- /dev/null +++ b/wp-content/plugins/mark-as-read/includes/mark-as-read.js @@ -0,0 +1,45 @@ +jQuery(document).ready( function($) { + + var read_message = mark_as_read_js.read_message; + var unread_message = mark_as_read_js.unread_message; + + $(".mar_mark_as_read").click( function() { + var post_id = $(this).attr('rel'); + var data = { + action: 'mark_post_as_read', + post_read: post_id + }; + $.post(mark_as_read_js.ajaxurl, data, function(response) { + if(mark_as_read_js.show_alerts == '1') { + alert(read_message); + } + $('.mar_read_control_'+post_id).toggle(); + }); + return false; + }); + $(".mar_mark_as_unread").click( function() { + + if(mark_as_read_js.show_alerts == '1') { + if(confirm(unread_message)) { + var post_id = $(this).attr('rel'); + var data = { + action: 'mark_post_as_unread', + del_post_id: post_id + }; + $.post(mark_as_read_js.ajaxurl, data, function(response) { + $('.mar_read_control_'+post_id).toggle(); + }); + } + } else { + var post_id = $(this).attr('rel'); + var data = { + action: 'mark_post_as_unread', + del_post_id: post_id + }; + $.post(mark_as_read_js.ajaxurl, data, function(response) { + $('.mar_read_control_'+post_id).toggle(); + }); + } + return false; + }); +}); \ No newline at end of file diff --git a/wp-content/plugins/mark-as-read/includes/profile-post-report.php b/wp-content/plugins/mark-as-read/includes/profile-post-report.php new file mode 100644 index 0000000..a1dd078 --- /dev/null +++ b/wp-content/plugins/mark-as-read/includes/profile-post-report.php @@ -0,0 +1,24 @@ + + +| + array( + 'read' => __('Posts Read: '), + 'unread' => __('Posts Unread: '), + 'total' => __('Total Posts on This Site: '), + 'percentage' => __('Percentage of Total Posts Read: '), + ) + ); + echo mar_list_user_report($args); + ?> + | +
The selectors below can be used in your CSS to customize the look of your bookmark links, the add / remove bookmark links, and more.
+ +Mark as Read / Unread Controls
+Most Read Posts List
+User Report
+