template-helpers.php 0000644 00000005163 14720702042 0010533 0 ustar 00 ';
$output .= '';
$output .= '';
$output .= '';
return $output;
}
}
if ( ! function_exists( 'foxiz_get_wologin_bookmark' ) ) {
/**
* @param string $post_id
* @param string $redirect
*
* @return false|string
* without login bookmark
*/
function foxiz_get_wologin_bookmark( $post_id = '', $redirect = '' ) {
if ( function_exists( 'foxiz_is_amp' ) && foxiz_is_amp() ) {
return false;
}
if ( empty( $redirect ) ) {
$redirect = home_url( '/' );
}
$output = '';
$output .= '';
$output .= '';
$output .= '';
$output .= '';
return $output;
}
}
if ( ! function_exists( 'foxiz_bookmark_trigger' ) ) {
/**
* @param string $post_id
*/
function foxiz_bookmark_trigger( $post_id = '' ) {
echo foxiz_get_bookmark_trigger( $post_id );
}
}
if ( ! function_exists( 'foxiz_get_bookmark_trigger' ) ) {
/**
* @param string $post_id
*
* @return false|string
*/
function foxiz_get_bookmark_trigger( $post_id = '' ) {
if ( foxiz_is_amp() || ! class_exists( 'Foxiz_Bookmark' ) ) {
return false;
}
$settings = Foxiz_Bookmark::get_instance()->settings;
if ( empty( $settings['bookmark'] ) ) {
return false;
}
if ( ! isset( $settings['logged_redirect'] ) ) {
$redirect = $settings['logged_redirect'];
} else {
$redirect = get_home_url();
}
if ( empty( $settings['enable_when'] ) || is_user_logged_in() ) {
return foxiz_get_bookmark( $post_id );
}
if ( 'ask_login' === $settings['enable_when'] && ! is_user_logged_in() ) {
return foxiz_get_wologin_bookmark( $post_id, esc_url( $redirect ) );
}
}
}
bookmark.php 0000644 00000022565 14720702042 0007072 0 ustar 00 get_settings();
add_action( 'wp_ajax_nopriv_rb_bookmark', array( $this, 'add_bookmark' ) );
add_action( 'wp_ajax_rb_bookmark', array( $this, 'add_bookmark' ) );
add_action( 'wp_ajax_nopriv_rb_follow', array( $this, 'follow_toggle' ) );
add_action( 'wp_ajax_rb_follow', array( $this, 'follow_toggle' ) );
add_action( 'wp_ajax_nopriv_sync_bookmarks', array( $this, 'sync_bookmarks' ) );
add_action( 'wp_ajax_sync_bookmarks', array( $this, 'sync_bookmarks' ) );
add_filter( 'body_class', array( $this, 'add_classes' ), 99 );
add_action( 'wp_footer', array( $this, 'bookmark_info_template' ) );
add_action( 'wp_footer', array( $this, 'bookmark_remove_info' ) );
add_action( 'transition_post_status', array( $this, 'push_notification' ), 10, 3 );
}
function bookmark_remove_info() {
$settings = $this->settings;
if ( empty( $settings['bookmark'] ) ) {
return;
} ?>
settings;
if ( empty( $settings['bookmark'] ) || empty( $settings['notification'] ) ) {
return;
} ?>
settings['bookmark'] ) ) {
$classes[] = 'sync-bookmarks';
}
return $classes;
}
/**
* @param $name
*
* @return false|mixed
* get setting by name
*/
public function get_setting( $name ) {
if ( function_exists( 'foxiz_get_option' ) ) {
return foxiz_get_option( $name );
}
return false;
}
/**
* get settings
*/
public function get_settings() {
$settings = array(
'bookmark' => $this->get_setting( 'bookmark_system' ),
'enable_when' => $this->get_setting( 'bookmark_enable_when' ),
'logged_redirect' => $this->get_setting( 'bookmark_logged_redirect' ),
'expiration' => intval( $this->get_setting( 'bookmark_expiration' ) ) * 86400,
'notification' => $this->get_setting( 'bookmark_notification' )
);
$this->settings = wp_parse_args( $settings, array(
'bookmark' => '',
'enable_when' => '',
'logged_redirect' => '',
'expiration' => '5076000'
) );
}
/**
* @return string|string[]|null
* get user IP
*/
public function get_ip() {
if ( function_exists( 'foxiz_get_user_ip' ) ) {
$ip = foxiz_get_user_ip();
return foxiz_convert_to_id( $ip );
}
return '127_0_0_1';
}
/**
* @param $post_id
*
* @return bool
* check bookmark
*/
public function is_bookmarked( $post_id ) {
if ( is_user_logged_in() ) {
$data = get_user_meta( get_current_user_id(), $this->meta_ID, true );
} else {
$data = get_transient( 'rb_bookmark_' . $this->get_ip() );
}
if ( empty( $data ) || ! is_array( $data ) ) {
return false;
} else {
return in_array( $post_id, $data );
}
}
/**
* add bookmark
*/
public function add_bookmark() {
if ( empty( $_POST['pid'] ) ) {
wp_send_json( '', null );
}
$post_id = intval( $_POST['pid'] );
$response = array(
'action' => 'added',
'description' => foxiz_html__( 'This article has been added to reading list', 'foxiz' )
);
if ( is_user_logged_in() ) {
$user_id = get_current_user_id();
$bookmarked = get_user_meta( $user_id, $this->meta_ID, true );
if ( empty( $bookmarked ) || ! is_array( $bookmarked ) ) {
$bookmarked = array();
}
$key = array_search( $post_id, $bookmarked );
if ( false === $key ) {
array_push( $bookmarked, $post_id );
} else {
unset( $bookmarked[ $key ] );
$response['action'] = 'removed';
$response['description'] = foxiz_html__( 'This article was removed from reading list', 'foxiz' );
}
update_user_meta( $user_id, $this->meta_ID, array_unique( $bookmarked ) );
} else {
$transient_ID = 'rb_bookmark_' . $this->get_ip();
$bookmarked = get_transient( $transient_ID );
if ( empty( $bookmarked ) || ! is_array( $bookmarked ) ) {
$bookmarked = array();
}
$key = array_search( $post_id, $bookmarked );
if ( false === $key ) {
array_push( $bookmarked, $post_id );
} else {
unset( $bookmarked[ $key ] );
$response['action'] = 'removed';
$response['description'] = foxiz_html__( 'This article was removed from your bookmark', 'foxiz' );
}
set_transient( $transient_ID, array_unique( $bookmarked ), $this->settings['expiration'] );
}
if ( ! empty( $this->settings['notification'] ) ) {
$response['title'] = get_the_title( $post_id );
$response['image'] = '';
}
wp_send_json( $response, null );
}
/**
* get bookmarks
*/
public function get_bookmarks() {
if ( is_user_logged_in() ) {
$bookmarked = get_user_meta( get_current_user_id(), $this->meta_ID, true );
} else {
$bookmarked = get_transient( 'rb_bookmark_' . $this->get_ip() );
}
return $bookmarked;
}
public function sync_bookmarks() {
wp_send_json( $this->get_bookmarks(), null );
}
/**
* @return false|WP_Query
*/
public function get_query() {
$data = $this->get_bookmarks();
if ( is_array( $data ) && count( $data ) ) {
return new WP_Query( array(
'post_type' => 'post',
'post__in' => $data,
'ignore_sticky_posts' => 1,
'duplicate_allowed' => 1
) );
} else {
return false;
}
}
/**
* @param $new_status
* @param $old_status
* @param $post
*/
public function push_notification( $new_status, $old_status, $post ) {
if ( ( 'publish' === $new_status && 'publish' !== $old_status ) && 'post' === $post->post_type ) {
update_option( 'rb_push_notification', $post->ID );
}
}
/**
* @return array|mixed
*/
public function get_user_categories() {
if ( is_user_logged_in() ) {
$ids = get_user_meta( get_current_user_id(), $this->meta_category_ID, true );
if ( ! empty( $ids ) && is_array( $ids ) && count( $ids ) ) {
return $ids;
}
}
$data = array();
$counter = 1;
$categories = get_categories( array(
'orderby' => 'count',
'order' => 'DESC'
) );
foreach ( $categories as $category ) {
array_push( $data, $category->term_id );
if ( $counter >= 4 ) {
break;
}
$counter ++;
}
return $data;
}
/** follow toggle */
public function follow_toggle() {
if ( empty( $_POST['cid'] ) && ! is_user_logged_in() ) {
wp_send_json( '', null );
}
$category_id = intval( $_POST['cid'] );
$response = array(
'action' => 'added',
);
if ( is_user_logged_in() ) {
$user_id = get_current_user_id();
$followed = get_user_meta( $user_id, $this->meta_category_ID, true );
if ( empty( $followed ) || ! is_array( $followed ) ) {
$followed = array();
}
$key = array_search( $category_id, $followed );
if ( false === $key ) {
array_push( $followed, $category_id );
} else {
unset( $followed[ $key ] );
$response['action'] = 'removed';
}
update_user_meta( $user_id, $this->meta_category_ID, array_unique( $followed ) );
}
wp_send_json( $response, null );
}
/**
* @param $category_id
*
* @return bool
*/
public function is_followed( $category_id ) {
if ( ! is_user_logged_in() ) {
return false;
}
$data = get_user_meta( get_current_user_id(), $this->meta_category_ID, true );
if ( empty( $data ) || ! is_array( $data ) ) {
return false;
} else {
return in_array( $category_id, $data );
}
}
}
}
templates.php 0000644 00000020442 14720702042 0007253 0 ustar 00 'uid_saved',
'bookmark_action' => true,
'classes' => 'saved-content',
) );
unset( $settings['pagination'] );
$image_description = foxiz_get_option( 'saved_image' );
$image_description_dark = foxiz_get_option( 'saved_image_dark' );
$heading_classes = 'bookmark-section-header';
if ( ! empty( $settings['pattern'] ) && '-1' !== (string) $settings['pattern'] ) {
$heading_classes .= ' is-pattern pattern-' . esc_attr( $settings['pattern'] );
} else {
$heading_classes .= ' solid-bg';
}
$_query = Foxiz_Bookmark::get_instance()->get_query();
?>
' ); ?>