PluginProbe
wpForo Forum / beta-4
wpForo Forum vbeta-4
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 beta-4, at wpf-includes/class-subscribes.php

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