PluginProbe
wpForo Forum / 3.0.9
wpForo Forum v3.0.9
3.1.5 3.1.4 3.1.2 3.1.1 3.1.0 3.0.9 3.0.8 3.0.7 trunk 1.0.0 1.0.1 1.0.2 1.1.0 1.1.1 1.1.2 1.2.0 1.3.0 1.3.1 1.4.0 1.4.1 1.4.10 1.4.11 1.4.12 1.4.13 1.4.2 All 137 releases
wpforo / modules / bookmarks / classes / Actions.php

Actions.php in wpForo Forum 3.0.9, at modules/bookmarks/classes/Actions.php

93 lines 2.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace wpforo\modules\bookmarks\classes;
4
5 class Actions {
6 public function __construct() {
7 $this->init_hooks();
8 }
9
10 private function init_hooks() {
11 add_action( 'wpforo_after_delete_user', [ $this, 'after_delete_user' ] );
12 add_action( 'wpforo_after_delete_board', [ $this, 'after_delete_board' ] );
13 add_action( 'wpforo_after_delete_post', [ $this, 'after_delete_post' ] );
14
15 #### -- AJAX ACTIONS -- ###
16 add_action( 'wp_ajax_wpforo_bookmark', [ $this, 'bookmark' ] );
17 add_action( 'wp_ajax_wpforo_unbookmark', [ $this, 'unbookmark' ] );
18 }
19
20 public function after_delete_user( $userid ){
21 WPF()->bookmark->delete( [ 'userid' => $userid ] );
22 }
23
24 public function after_delete_board( $boardid ) {
25 WPF()->bookmark->delete( [ 'boardid' => $boardid ] );
26 }
27
28 public function after_delete_post( $post ) {
29 $boardid = WPF()->board->get_current( 'boardid' );
30 WPF()->bookmark->delete( [ 'boardid' => $boardid, 'postid' => $post['postid'] ] );
31 }
32
33 public function bookmark() {
34 wpforo_verify_nonce( 'wpforo_bookmark' );
35 $r = false;
36 if( WPF()->current_userid && ( $postid = wpforo_bigintval( wpfval( $_POST, 'postid' ) ) ) ){
37 $boardid = WPF()->board->get_current( 'boardid' );
38
39 $bookmark = WPF()->bookmark->get_user_bookmark( $postid, WPF()->current_userid, $boardid );
40
41 if( $bookmark ){
42 if( ! $bookmark['status'] ){
43 $r = WPF()->bookmark->edit(
44 [
45 'status' => true,
46 'created' => time()
47 ],
48 $bookmark['bookmarkid']
49 );
50 }else{
51 $r = true;
52 }
53 }else{
54 $r = WPF()->bookmark->add(
55 [
56 'userid' => WPF()->current_userid,
57 'boardid' => $boardid,
58 'postid' => $postid,
59 ]
60 );
61 }
62 }
63
64 if( $r ){
65 wp_send_json_success( [ 'button' => WPF()->bookmark->Template->_button( false ) ] );
66 }else{
67 wp_send_json_error();
68 }
69 }
70
71 public function unbookmark() {
72 wpforo_verify_nonce( 'wpforo_unbookmark' );
73 $r = false;
74 if( WPF()->current_userid && ( $postid = wpforo_bigintval( wpfval( $_POST, 'postid' ) ) ) ){
75 $boardid = WPF()->board->get_current( 'boardid' );
76
77 $r = WPF()->bookmark->delete(
78 [
79 'userid' => WPF()->current_userid,
80 'boardid' => $boardid,
81 'postid' => $postid,
82 ]
83 );
84 }
85
86 if( $r ){
87 wp_send_json_success( [ 'button' => WPF()->bookmark->Template->_button( true ) ] );
88 }else{
89 wp_send_json_error();
90 }
91 }
92 }
93