PluginProbe
wpForo Forum / 1.1.1
wpForo Forum v1.1.1
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 / wpf-includes / class-subscribes.php

class-subscribes.php in wpForo Forum 1.1.1, at wpf-includes/class-subscribes.php

177 lines 5.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 // Exit if accessed directly
3 if( !defined( 'ABSPATH' ) ) exit;
4
5
6 class wpForoSubscribe{
7
8 private $wpforo;
9
10 function __construct( $wpForo ){
11 if(!isset($this->wpforo)) $this->wpforo = $wpForo;
12 }
13
14 function get_confirm_key(){
15 return substr(md5(rand().time()), 0, 32);
16 }
17
18 function add( $args = array() ){
19 if( empty($args) && empty($_REQUEST['sbscrb']) ) return FALSE;
20 if( empty($args) && !empty($_REQUEST['sbscrb']) ) $args = $_REQUEST['sbscrb'];
21 if( !isset($args['active']) || !$args['active'] ) $args['active'] = 0;
22
23 extract( $args, EXTR_OVERWRITE );
24 if( !isset($itemid) || !$itemid || !isset($userid) || !$userid || !isset($type) || !$type ) return FALSE;
25
26 if( !isset($confirmkey) || (isset($confirmkey) && !$confirmkey ) ) $confirmkey = $this->get_confirm_key();
27
28 if($this->wpforo->db->insert(
29 $this->wpforo->db->prefix . 'wpforo_subscribes',
30 array(
31 'itemid' => intval($itemid),
32 'type' => sanitize_text_field($type),
33 'confirmkey' => sanitize_text_field($confirmkey),
34 'userid' => intval($userid),
35 'active' => $active
36 ),
37 array(
38 '%d',
39 '%s',
40 '%s',
41 '%d',
42 '%d'
43 )
44 )){
45 if( isset($active) && $active == 1 ){
46 $this->wpforo->notice->add('You have been successfully subscribed', 'success');
47 }else{
48 $this->wpforo->notice->add('Success! Thank you. Please check your email and click confirmation link below to complete this step.', 'success');
49 }
50 return $confirmkey;
51 }
52
53 $this->wpforo->notice->add('Can\'t subscribe to this item', 'error');
54 return FALSE;
55 }
56
57 function edit( $confirmkey = '' ){
58 if( !$confirmkey && isset($_REQUEST['key']) && $_REQUEST['key'] ) $confirmkey = $_REQUEST['key'];
59 if( !$confirmkey ){
60 $this->wpforo->notice->add('Invalid request!', 'error');
61 return FALSE;
62 }
63
64 if( $this->wpforo->db->update(
65 $this->wpforo->db->prefix . 'wpforo_subscribes',
66 array( 'active' => 1 ),
67 array( 'confirmkey' => sanitize_text_field($confirmkey) ),
68 array( '%d' ),
69 array( '%s' )
70 ) ){
71 $this->wpforo->notice->add('You have been successfully subscribed', 'success');
72 return TRUE;
73 }
74
75 $this->wpforo->notice->add('Your subscription for this item could not be confirmed', 'error');
76 return FALSE;
77 }
78
79 function delete( $confirmkey = '' ){
80 if( !$confirmkey && isset($_REQUEST['confirmkey']) && $_REQUEST['confirmkey'] ) $confirmkey = $_REQUEST['confirmkey'];
81 if( !$confirmkey ){
82 $this->wpforo->notice->add('Invalid request!', 'error');
83 return FALSE;
84 }
85 if( $this->wpforo->db->delete( $this->wpforo->db->prefix.'wpforo_subscribes', array( 'confirmkey' => sanitize_text_field($confirmkey) ), array( '%s' ) ) ){
86 $this->wpforo->notice->add('You have been successfully unsubscribed', 'success');
87 return TRUE;
88 }
89
90 $this->wpforo->notice->add('Could not be unsubscribe from this item', 'error');
91 return FALSE;
92 }
93
94 function get_subscribe( $args = array() ){
95 if( is_string($args) ) $args = array("confirmkey" => sanitize_text_field($args));
96 if( empty($args) && !empty($_REQUEST['sbscrb']) ) $args = $_REQUEST['sbscrb'];
97 if( empty($args) ) return FALSE;
98
99 extract( $args, EXTR_OVERWRITE );
100 if( (!isset($itemid) || !$itemid || !isset($userid) || !$userid || !isset($type) || !$type) && (!isset($confirmkey) || !$confirmkey) ) return FALSE;
101
102 if( isset($confirmkey) && $confirmkey){
103 $where = " `confirmkey` = '".esc_sql(sanitize_text_field($confirmkey))."'";
104 }elseif( isset($itemid) && $itemid && isset($userid) && $userid && isset($type) && $type ){
105 $where = " `itemid` = ".intval($itemid)." AND `userid` = ".intval($userid)." AND `type` = '".esc_sql(sanitize_text_field($type))."'";
106 }else{
107 return FALSE;
108 }
109
110 $sql = "SELECT * FROM `".$this->wpforo->db->prefix."wpforo_subscribes` WHERE " . $where;
111 return $this->wpforo->db->get_row($sql, ARRAY_A);
112 }
113
114 function get_subscribes( $args = array(), &$items_count = 0 ){
115
116 $default = array(
117 'itemid' => NULL,
118 'type' => '', // topic | forum
119 'userid' => NULL, //
120 'active' => 1,
121 'orderby' => 'subid', // order by `field`
122 'order' => 'DESC', // ASC DESC
123 'offset' => NULL, // OFFSET
124 'row_count' => NULL, // ROW COUNT
125 );
126
127 $args = wpforo_parse_args( $args, $default );
128 if(!empty($args)){
129 extract($args, EXTR_OVERWRITE);
130
131 $sql = "SELECT * FROM `".$this->wpforo->db->prefix."wpforo_subscribes`";
132 $wheres = array();
133
134 if( $type ) $wheres[] = " `type` = '" . esc_sql(sanitize_text_field($type)) . "'";
135 $wheres[] = " `active` = " . intval($active);
136 if($itemid != NULL) $wheres[] = " `itemid` = " . intval($itemid);
137 if($userid != NULL) $wheres[] = " `userid` = " . intval($userid);
138
139 if(!empty($wheres)) $sql .= " WHERE " . implode( " AND ", $wheres );
140
141 $item_count_sql = preg_replace('#SELECT.+?FROM#isu', 'SELECT count(*) FROM', $sql);
142 if( $item_count_sql ) $items_count = $this->wpforo->db->get_var($item_count_sql);
143
144 $sql .= " ORDER BY `$orderby` " . $order;
145
146 if($row_count != NULL){
147 if($offset != NULL){
148 $sql .= esc_sql(" LIMIT $offset,$row_count");
149 }else{
150 $sql .= esc_sql(" LIMIT $row_count");
151 }
152 }
153 return $this->wpforo->db->get_results($sql, ARRAY_A);
154
155 }
156 }
157
158 function get_confirm_link($args){
159 if(is_string($args)) return WPFORO_BASE_URL . "?wpforo=sbscrbconfirm&key=" . sanitize_text_field($args);
160
161 if($args['type'] == 'forum'){
162 $url = $this->wpforo->forum->get_forum_url($args['itemid']) . '/';
163 }elseif($args['type'] == 'topic'){
164 $url = $this->wpforo->topic->get_topic_url($args['itemid']) . '/';
165 }else{
166 $url = WPFORO_BASE_URL;
167 }
168 return $url . "?wpforo=sbscrbconfirm&key=" . sanitize_text_field($args['confirmkey']);
169 }
170
171 function get_unsubscribe_link($confirmkey){
172 return WPFORO_BASE_URL . "?wpforo=unsbscrb&key=" . sanitize_text_field($confirmkey);
173 }
174
175 }
176
177 ?>