Skip to content

Commit

Permalink
bookmarks !
Browse files Browse the repository at this point in the history
  • Loading branch information
gordielachance authored and gordielachance committed Sep 14, 2016
1 parent 2a0e0cb commit d22944a
Show file tree
Hide file tree
Showing 5 changed files with 125 additions and 11 deletions.
22 changes: 13 additions & 9 deletions _inc/css/bbppu.css
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 6 additions & 0 deletions _inc/scss/bbppu.scss
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
76 changes: 76 additions & 0 deletions bbppu-bookmarks.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?php

class bbP_Pencil_Unread_Bookmarks {

function __construct(){

add_action('bbp_init',array(&$this,"logged_in_user_actions")); //logged in users actions

}

function logged_in_user_actions(){
if(!is_user_logged_in()) return false;
//TO FIX reset bookmark_id when displaying a topic ?
add_action( 'bbp_theme_after_reply_content', array(&$this,'bookmark_resfresh'));
add_action( 'bbp_template_after_replies_loop', array(&$this,'bookmark_save'));
add_action( 'bbp_theme_after_topic_title', array(&$this,'bookmark_embed_link'));
}

function bookmark_resfresh(){
$this->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 = '<span class="bbppu-bookmark-icon dashicons dashicons-flag"></span>';
printf('<a class="bbppu-bookmark" title="%s" href="%s">%s</a>',$title,$bookmark_url,$icon);
}


}

new bbP_Pencil_Unread_Bookmarks;
20 changes: 20 additions & 0 deletions bbppu-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';

}

Expand Down Expand Up @@ -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
);



Expand Down Expand Up @@ -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(
'<input type="checkbox" name="%s[bookmarks]" value="on" %s /> %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"),'<code><span class="dashicons dashicons-flag"></span></code>')
);
}

function bbppu_settings_system_desc(){

Expand Down
12 changes: 10 additions & 2 deletions bbpress-pencil-unread.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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()){
}
}
Expand Down Expand Up @@ -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 ){

Expand Down

0 comments on commit d22944a

Please sign in to comment.