PluginProbe
wpForo Forum / 1.0.2
wpForo Forum v1.0.2
3.1.6 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 All 138 releases
wpforo / wpf-includes / class-subscribes.php

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

178 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 = substr(md5(rand().time()), 0, 32);
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 }
48 else{
49 $this->wpforo->notice->add('Success! Thank you. Please check your email and click confirmation link below to complete this step.', 'success');
50 }
51 return $confirmkey;
52 }
53
54 $this->wpforo->notice->add('Can\'t subscribe to this item', 'error');
55 return FALSE;
56 }
57
58 function edit( $confirmkey = '' ){
59 if( !$confirmkey && isset($_REQUEST['key']) && $_REQUEST['key'] ) $confirmkey = $_REQUEST['key'];
60 if( !$confirmkey ){
61 $this->wpforo->notice->add('Invalid request!', 'error');
62 return FALSE;
63 }
64
65 if( $this->wpforo->db->update(
66 $this->wpforo->db->prefix . 'wpforo_subscribes',
67 array( 'active' => 1 ),
68 array( 'confirmkey' => sanitize_text_field($confirmkey) ),
69 array( '%d' ),
70 array( '%s' )
71 ) ){
72 $this->wpforo->notice->add('You have been successfully subscribed', 'success');
73 return TRUE;
74 }
75
76 $this->wpforo->notice->add('Your subscription for this item could not be confirmed', 'error');
77 return FALSE;
78 }
79
80 function delete( $confirmkey = '' ){
81 if( !$confirmkey && isset($_REQUEST['confirmkey']) && $_REQUEST['confirmkey'] ) $confirmkey = $_REQUEST['confirmkey'];
82 if( !$confirmkey ){
83 $this->wpforo->notice->add('Invalid request!', 'error');
84 return FALSE;
85 }
86 if( $this->wpforo->db->delete( $this->wpforo->db->prefix.'wpforo_subscribes', array( 'confirmkey' => sanitize_text_field($confirmkey) ), array( '%s' ) ) ){
87 $this->wpforo->notice->add('You have been successfully unsubscribed', 'success');
88 return TRUE;
89 }
90
91 $this->wpforo->notice->add('Could not be unsubscribe from this item', 'error');
92 return FALSE;
93 }
94
95 function get_subscribe( $args = array() ){
96 if( is_string($args) ) $args = array("confirmkey" => sanitize_text_field($args));
97 if( empty($args) && !empty($_REQUEST['sbscrb']) ) $args = $_REQUEST['sbscrb'];
98 if( empty($args) ) return FALSE;
99
100 extract( $args, EXTR_OVERWRITE );
101 if( (!isset($itemid) || !$itemid || !isset($userid) || !$userid || !isset($type) || !$type) && (!isset($confirmkey) || !$confirmkey) ) return FALSE;
102
103 if( isset($confirmkey) && $confirmkey){
104 $where = " `confirmkey` = '".esc_sql(sanitize_text_field($confirmkey))."'";
105 }elseif( isset($itemid) && $itemid && isset($userid) && $userid && isset($type) && $type ){
106 $where = " `itemid` = ".intval($itemid)." AND `userid` = ".intval($userid)." AND `type` = '".esc_sql(sanitize_text_field($type))."'";
107 }else{
108 return FALSE;
109 }
110
111 $sql = "SELECT * FROM `".$this->wpforo->db->prefix."wpforo_subscribes` WHERE " . $where;
112 return $this->wpforo->db->get_row($sql, ARRAY_A);
113 }
114
115 function get_subscribes( $args = array(), &$items_count = 0 ){
116
117 $default = array(
118 'itemid' => NULL,
119 'type' => '', // topic | forum
120 'userid' => NULL, //
121 'active' => 1,
122 'orderby' => 'subid', // order by `field`
123 'order' => 'DESC', // ASC DESC
124 'offset' => NULL, // OFFSET
125 'row_count' => NULL, // ROW COUNT
126 );
127
128 $args = wpforo_parse_args( $args, $default );
129 if(!empty($args)){
130 extract($args, EXTR_OVERWRITE);
131
132 $sql = "SELECT * FROM `".$this->wpforo->db->prefix."wpforo_subscribes`";
133 $wheres = array();
134
135 if( $type ) $wheres[] = " `type` = '" . esc_sql(sanitize_text_field($type)) . "'";
136 $wheres[] = " `active` = " . intval($active);
137 if($itemid != NULL) $wheres[] = " `itemid` = " . intval($itemid);
138 if($userid != NULL) $wheres[] = " `userid` = " . intval($userid);
139
140 if(!empty($wheres)) $sql .= " WHERE " . implode( " AND ", $wheres );
141
142 $item_count_sql = preg_replace('#SELECT.+?FROM#isu', 'SELECT count(*) FROM', $sql);
143 if( $item_count_sql ) $items_count = $this->wpforo->db->get_var($item_count_sql);
144
145 $sql .= " ORDER BY `$orderby` " . $order;
146
147 if($row_count != NULL){
148 if($offset != NULL){
149 $sql .= esc_sql(" LIMIT $offset,$row_count");
150 }else{
151 $sql .= esc_sql(" LIMIT $row_count");
152 }
153 }
154 return $this->wpforo->db->get_results($sql, ARRAY_A);
155
156 }
157 }
158
159 function get_confirm_link($args){
160 if(is_string($args)) return WPFORO_BASE_URL . "?wpforo=sbscrbconfirm&key=" . sanitize_text_field($args);
161
162 if($args['type'] == 'forum'){
163 $url = $this->wpforo->forum->get_forum_url($args['itemid']) . '/';
164 }elseif($args['type'] == 'topic'){
165 $url = $this->wpforo->topic->get_topic_url($args['itemid']) . '/';
166 }else{
167 $url = WPFORO_BASE_URL;
168 }
169 return $url . "?wpforo=sbscrbconfirm&key=" . sanitize_text_field($args['confirmkey']);
170 }
171
172 function get_unsubscribe_link($confirmkey){
173 return WPFORO_BASE_URL . "?wpforo=unsbscrb&key=" . sanitize_text_field($confirmkey);
174 }
175
176 }
177
178 ?>