From d22944a9546e66e2ceb13aa4b579b3af909f919c Mon Sep 17 00:00:00 2001 From: gordielachance Date: Thu, 15 Sep 2016 01:18:10 +0200 Subject: [PATCH] bookmarks ! --- _inc/css/bbppu.css | 22 +++++++----- _inc/scss/bbppu.scss | 6 ++++ bbppu-bookmarks.php | 76 +++++++++++++++++++++++++++++++++++++++ bbppu-settings.php | 20 +++++++++++ bbpress-pencil-unread.php | 12 +++++-- 5 files changed, 125 insertions(+), 11 deletions(-) create mode 100644 bbppu-bookmarks.php diff --git a/_inc/css/bbppu.css b/_inc/css/bbppu.css index 6a238fb..8ba413c 100644 --- a/_inc/css/bbppu.css +++ b/_inc/css/bbppu.css @@ -5,45 +5,49 @@ body a.bbppu-hentry, body ul.bbppu-hentry > li:first-child { -webkit-transition: border 500ms ease-out; transition: border 500ms ease-out; } -/* line 13, ../scss/bbppu.scss */ +/* line 14, ../scss/bbppu.scss */ +body .bbppu-bookmark .dashicons { + font-size: 1.5em; +} +/* line 19, ../scss/bbppu.scss */ body .bbppu-mark-as-read { margin-bottom: 15px; text-align: right; } -/* line 17, ../scss/bbppu.scss */ +/* line 23, ../scss/bbppu.scss */ body .bbppu-mark-as-read a .bbppu-loading { filter: progid:DXImageTransform.Microsoft.Alpha(Opacity=0); opacity: 0; } -/* line 21, ../scss/bbppu.scss */ +/* line 27, ../scss/bbppu.scss */ body .bbppu-mark-as-read a.loading .bbppu-loading { filter: progid:DXImageTransform.Microsoft.Alpha(enabled=false); opacity: 1; } -/* line 28, ../scss/bbppu.scss */ +/* line 34, ../scss/bbppu.scss */ body:not(.rtl) a.bbppu-hentry, body:not(.rtl) ul.bbppu-hentry > li:first-child { padding-left: 5px; } -/* line 32, ../scss/bbppu.scss */ +/* line 38, ../scss/bbppu.scss */ body:not(.rtl) a.bbppu-hentry.bbppu-read, body:not(.rtl) ul.bbppu-hentry.bbppu-read > li:first-child { border-left: 5px solid #EAEAEA; } -/* line 37, ../scss/bbppu.scss */ +/* line 43, ../scss/bbppu.scss */ body:not(.rtl) a.bbppu-hentry.bbppu-unread, body:not(.rtl) ul.bbppu-hentry.bbppu-unread > li:first-child { border-left: 5px solid #21759B; } -/* line 44, ../scss/bbppu.scss */ +/* line 50, ../scss/bbppu.scss */ body.rtl a.bbppu-hentry, body.rtl ul.bbppu-hentry > li:first-child { padding-right: 5px; } -/* line 48, ../scss/bbppu.scss */ +/* line 54, ../scss/bbppu.scss */ body.rtl a.bbppu-hentry.bbppu-read, body.rtl ul.bbppu-hentry.bbppu-read > li:first-child { border-right: 5px solid #EAEAEA; } -/* line 53, ../scss/bbppu.scss */ +/* line 59, ../scss/bbppu.scss */ body.rtl a.bbppu-hentry.bbppu-unread, body.rtl ul.bbppu-hentry.bbppu-unread > li:first-child { border-right: 5px solid #21759B; diff --git a/_inc/scss/bbppu.scss b/_inc/scss/bbppu.scss index bcf2e2c..cdb9ce1 100644 --- a/_inc/scss/bbppu.scss +++ b/_inc/scss/bbppu.scss @@ -9,6 +9,12 @@ body{ a.bbppu-hentry, ul.bbppu-hentry > li:first-child { @include transition(border 500ms ease-out); } + + .bbppu-bookmark{ + .dashicons{ + font-size: 1.5em; + } + } .bbppu-mark-as-read { margin-bottom: 15px; diff --git a/bbppu-bookmarks.php b/bbppu-bookmarks.php new file mode 100644 index 0000000..43bc578 --- /dev/null +++ b/bbppu-bookmarks.php @@ -0,0 +1,76 @@ +bookmark_id = bbp_get_reply_id(); //last reply viewed + } + + function bookmark_get($parent_id) { + $user_id = get_current_user_id(); + $metakey_name = 'bookmark_id_'.$parent_id; + return get_user_meta( $user_id, $metakey_name, true ); + } + + function bookmark_save() { + global $post; + + $bookmark_id = $this->bookmark_id; + + $parent_id = wp_get_post_parent_id( $bookmark_id ); //topic id + + $user_id = get_current_user_id(); + + $metakey_name = 'bookmark_id_'.$parent_id; + + $debug_message = sprintf('save bookmark: %s ("%s") for user #%s',$metakey_name,$bookmark_id,$user_id); + bbppu()->debug_log($debug_message); + + return update_user_meta( $user_id, $metakey_name, $bookmark_id ); + } + + function bookmark_get_url($post_id){ + + //$parent_id = wp_get_post_parent_id( $post_id ); + //$url = sprintf('%s#%s',get_permalink($post_id),'post-'.$post_id); + + $url = bbp_get_reply_url($post_id); + + return $url; + } + + function bookmark_embed_link(){ + global $post; + $bookmark_id = $this->bookmark_get($post->ID); + $last_chilren_id = bbp_get_topic_last_reply_id( $post->ID ); + + // Abord if the user has not read any posts in the topic + if (!$bookmark_id) return; + + // Skip if user as read the last post + //if ($bookmark_id == $last_chilren_id) return; + + $bookmark_url = $this->bookmark_get_url($bookmark_id); + $title = __('Go to bookmark','bbppu'); + $icon = ''; + printf('%s',$title,$bookmark_url,$icon); + } + + +} + +new bbP_Pencil_Unread_Bookmarks; \ No newline at end of file diff --git a/bbppu-settings.php b/bbppu-settings.php index a06b552..df96995 100644 --- a/bbppu-settings.php +++ b/bbppu-settings.php @@ -38,6 +38,7 @@ function settings_sanitize( $input ){ //test registration time $new_input['test_registration_time'] = ( isset($input['test_registration_time']) ) ? 'on' : 'off'; + $new_input['bookmarks'] = ( isset($input['bookmarks']) ) ? 'on' : 'off'; } @@ -76,6 +77,14 @@ function settings_init(){ 'bbppu-settings-page', // Page 'settings_general'//section ); + + add_settings_field( + 'bookmarks', + __('Enable bookmarks','bbppu'), + array( $this, 'enable_bookmark_callback' ), + 'bbppu-settings-page', // Page + 'settings_general'//section + ); @@ -110,6 +119,17 @@ function test_registration_time_callback(){ __("Items older than the registration date of the user should be marked as read.","bbppu") ); } + + function enable_bookmark_callback(){ + $option = bbppu()->get_options('bookmarks'); + + printf( + ' %s', + bbppu()->options_metaname, + checked( $option, 'on', false ), + sprintf(__("Add bookmarks links %s after the topic title; to jump to the last read reply","bbppu"),'') + ); + } function bbppu_settings_system_desc(){ diff --git a/bbpress-pencil-unread.php b/bbpress-pencil-unread.php index 2130ce8..fc29499 100644 --- a/bbpress-pencil-unread.php +++ b/bbpress-pencil-unread.php @@ -88,7 +88,9 @@ function setup_globals() { $this->options_default = array( 'test_registration_time' => 'on', //all items dated befoe user's first visit - 'count_topics_transient_duration' => 5 + 'bookmarks' => 'on', + 'count_topics_transient_duration' => 5, + ); $this->options = wp_parse_args(get_option( $this->options_metaname), $this->options_default); @@ -101,6 +103,11 @@ function includes(){ require( $this->plugin_dir . 'bbppu-settings.php'); require( $this->plugin_dir . 'bbppu-template.php'); require( $this->plugin_dir . 'bbppu-ajax.php'); + + if ( $this->get_options('bookmarks') == 'on' ){ + require( $this->plugin_dir . 'bbppu-bookmarks.php'); + } + if (is_admin()){ } } @@ -242,13 +249,14 @@ function logged_in_user_actions(){ //queries add_filter('query_vars', array(&$this,'register_query_vars' )); add_action( 'pre_get_posts', array($this, 'filter_query')); + } function register_query_vars($vars) { $vars[] = $this->qvar; return $vars; } - + // Filter a query for read/unread posts if the 'bbppu' var is set function filter_query( $query ){