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

219 lines 9.2 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 private $wpforo;
8 public $default;
9 public $options;
10
11 static $cache = array( 'subscribe' => array() );
12
13 function __construct( $wpForo ){
14 if(!isset($this->wpforo)) $this->wpforo = $wpForo;
15
16 $this->init_defaults();
17 $this->init_options();
18 }
19
20 private function init_defaults(){
21 $blogname = get_option('blogname', '');
22 $adminemail = get_option('admin_email');
23
24 $this->default = new stdClass;
25
26 $this->default->options = array (
27 'from_name' => $blogname . ' - Forum',
28 'from_email' => $adminemail,
29 'admin_emails' => $adminemail,
30 'new_topic_notify' => 1,
31 'new_reply_notify' => 0,
32 'confirmation_email_subject' => "Please confirm subscription to [entry_title]",
33 'confirmation_email_message' => "Hello [member_name]!<br>\r\n Thank you for subscribing.<br>\r\n This is an automated response.<br>\r\n We are glad to inform you that after confirmation you will get updates from - [entry_title].<br>\r\n Please click on link below to complete this step.<br>\r\n [confirm_link]" ,
34 'new_topic_notification_email_subject' => "New Topic" ,
35 'new_topic_notification_email_message' => "Hello [member_name]!<br>\r\n New topic has been created on your subscribed forum - [forum].\r\n <br><br>\r\n <strong>[topic_title]</strong>\r\n <blockquote>\r\n [topic_desc]\r\n </blockquote>\r\n <br><hr>\r\n If you want to unsubscribe from this forum please use the link below.<br>\r\n [unsubscribe_link]" ,
36 'new_post_notification_email_subject' => "New Reply" ,
37 'new_post_notification_email_message' => "Hello [member_name]!<br>\r\n New reply has been posted on your subscribed topic - [topic].\r\n <br><br>\r\n <strong>[reply_title]</strong>\r\n <blockquote >\r\n [reply_desc]\r\n </blockquote>\r\n <br><hr>\r\n If you want to unsubscribe from this topic please use the link below.<br>\r\n [unsubscribe_link]" ,
38 'report_email_subject' => "Forum Post Report",
39 'report_email_message' => "<strong>Report details:</strong>\r\n Reporter: [reporter], <br>\r\n Message: [message],<br>\r\n <br>\r\n [post_url]",
40 'reset_password_email_message' => "Hello! <br>\r\n\r\n You asked us to reset your password for your account using the email address [user_login]. <br>\r\n\r\n If this was a mistake, or you didn't ask for a password reset, just ignore this email and nothing will happen. <br>\r\n\r\n To reset your password, visit the following address: <br>\r\n\r\n [reset_password_url] <br>\r\n\r\n Thanks!",
41 //'spam_notification_email_subject' => 'New Banned User',
42 //'spam_notification_email_message' => "Hello [member_name]!<br>\r\n Please check this user's topics/posts and consider to Delete or Unban.<br>\r\n User Activity: [profile_activity_url]",
43 'update' => '1'
44 );
45 }
46
47 private function init_options(){
48 $this->options = get_wpf_option('wpforo_subscribe_options', $this->default->options);
49 }
50
51 function get_confirm_key(){
52 return substr(md5(rand().time()), 0, 32);
53 }
54
55 function add( $args = array() ){
56 if( empty($args) && empty($_REQUEST['sbscrb']) ) return FALSE;
57 if( empty($args) && !empty($_REQUEST['sbscrb']) ) $args = $_REQUEST['sbscrb'];
58 if( !isset($args['active']) || !$args['active'] ) $args['active'] = 0;
59
60 extract( $args, EXTR_OVERWRITE );
61 if( !isset($itemid) || !$itemid || !isset($userid) || !$userid || !isset($type) || !$type ) return FALSE;
62
63 if( !isset($confirmkey) || (isset($confirmkey) && !$confirmkey ) ) $confirmkey = $this->get_confirm_key();
64
65 if($this->wpforo->db->insert(
66 $this->wpforo->db->prefix . 'wpforo_subscribes',
67 array(
68 'itemid' => intval($itemid),
69 'type' => sanitize_text_field($type),
70 'confirmkey' => sanitize_text_field($confirmkey),
71 'userid' => intval($userid),
72 'active' => $active
73 ),
74 array(
75 '%d',
76 '%s',
77 '%s',
78 '%d',
79 '%d'
80 )
81 )){
82 if( isset($active) && $active == 1 ){
83 $this->wpforo->notice->add('You have been successfully subscribed', 'success');
84 }else{
85 $this->wpforo->notice->add('Success! Thank you. Please check your email and click confirmation link below to complete this step.', 'success');
86 }
87 return $confirmkey;
88 }
89
90 $this->wpforo->notice->add('Can\'t subscribe to this item', 'error');
91 return FALSE;
92 }
93
94 function edit( $confirmkey = '' ){
95 if( !$confirmkey && isset($_REQUEST['key']) && $_REQUEST['key'] ) $confirmkey = $_REQUEST['key'];
96 if( !$confirmkey ){
97 $this->wpforo->notice->add('Invalid request!', 'error');
98 return FALSE;
99 }
100
101 if( $this->wpforo->db->update(
102 $this->wpforo->db->prefix . 'wpforo_subscribes',
103 array( 'active' => 1 ),
104 array( 'confirmkey' => sanitize_text_field($confirmkey) ),
105 array( '%d' ),
106 array( '%s' )
107 ) ){
108 $this->wpforo->notice->add('You have been successfully subscribed', 'success');
109 return TRUE;
110 }
111
112 $this->wpforo->notice->add('Your subscription for this item could not be confirmed', 'error');
113 return FALSE;
114 }
115
116 function delete( $confirmkey = '' ){
117 if( !$confirmkey && isset($_REQUEST['confirmkey']) && $_REQUEST['confirmkey'] ) $confirmkey = $_REQUEST['confirmkey'];
118 if( !$confirmkey ){
119 $this->wpforo->notice->add('Invalid request!', 'error');
120 return FALSE;
121 }
122 if( $this->wpforo->db->delete( $this->wpforo->db->prefix.'wpforo_subscribes', array( 'confirmkey' => sanitize_text_field($confirmkey) ), array( '%s' ) ) ){
123 $this->wpforo->notice->add('You have been successfully unsubscribed', 'success');
124 return TRUE;
125 }
126
127 $this->wpforo->notice->add('Could not be unsubscribe from this item', 'error');
128 return FALSE;
129 }
130
131 function get_subscribe( $args = array() ){
132
133 $cache = $this->wpforo->cache->on('memory_cashe');
134
135 if( is_string($args) ) $args = array("confirmkey" => sanitize_text_field($args));
136 if( empty($args) && !empty($_REQUEST['sbscrb']) ) $args = $_REQUEST['sbscrb'];
137 if( empty($args) ) return FALSE;
138 extract( $args, EXTR_OVERWRITE );
139 if( (!isset($itemid) || !$itemid || !isset($userid) || !$userid || !isset($type) || !$type) && (!isset($confirmkey) || !$confirmkey) ) return FALSE;
140 if( isset($confirmkey) && $confirmkey){
141 $where = " `confirmkey` = '".esc_sql(sanitize_text_field($confirmkey))."'";
142 }elseif( isset($itemid) && $itemid && isset($userid) && $userid && isset($type) && $type ){
143 $where = " `itemid` = ".intval($itemid)." AND `userid` = ".intval($userid)." AND `type` = '".esc_sql(sanitize_text_field($type))."'";
144 }else{
145 return FALSE;
146 }
147 if( $cache && isset(self::$cache['subscribe'][$itemid][$userid][$type]) ){
148 return self::$cache['subscribe'][$itemid][$userid][$type];
149 }
150 $sql = "SELECT * FROM `".$this->wpforo->db->prefix."wpforo_subscribes` WHERE " . $where;
151 $subscribe = $this->wpforo->db->get_row($sql, ARRAY_A);
152 if($cache && !empty($subscribe)){
153 self::$cache['subscribe'][$itemid][$userid][$type] = $subscribe;
154 }
155 return $subscribe;
156 }
157
158 function get_subscribes( $args = array(), &$items_count = 0 ){
159
160 $default = array(
161 'itemid' => NULL,
162 'type' => '', // topic | forum
163 'userid' => NULL, //
164 'active' => 1,
165 'orderby' => 'subid', // order by `field`
166 'order' => 'DESC', // ASC DESC
167 'offset' => NULL, // OFFSET
168 'row_count' => NULL, // ROW COUNT
169 );
170
171 $args = wpforo_parse_args( $args, $default );
172 if(!empty($args)){
173 extract($args, EXTR_OVERWRITE);
174
175 $sql = "SELECT * FROM `".$this->wpforo->db->prefix."wpforo_subscribes`";
176 $wheres = array();
177
178 if( $type ) $wheres[] = " `type` = '" . esc_sql(sanitize_text_field($type)) . "'";
179 $wheres[] = " `active` = " . intval($active);
180 if($itemid != NULL) $wheres[] = " `itemid` = " . intval($itemid);
181 if($userid != NULL) $wheres[] = " `userid` = " . intval($userid);
182
183 if(!empty($wheres)) $sql .= " WHERE " . implode( " AND ", $wheres );
184
185 $item_count_sql = preg_replace('#SELECT.+?FROM#isu', 'SELECT count(*) FROM', $sql);
186 if( $item_count_sql ) $items_count = $this->wpforo->db->get_var($item_count_sql);
187
188 $sql .= " ORDER BY `$orderby` " . $order;
189
190 if($row_count != NULL){
191 if($offset != NULL){
192 $sql .= esc_sql(" LIMIT $offset,$row_count");
193 }else{
194 $sql .= esc_sql(" LIMIT $row_count");
195 }
196 }
197 return $this->wpforo->db->get_results($sql, ARRAY_A);
198
199 }
200 }
201
202 function get_confirm_link($args){
203 if(is_string($args)) return wpforo_home_url( "?wpforo=sbscrbconfirm&key=" . sanitize_text_field($args) );
204
205 if($args['type'] == 'forum'){
206 $url = $this->wpforo->forum->get_forum_url($args['itemid']) . '/';
207 }elseif($args['type'] == 'topic'){
208 $url = $this->wpforo->topic->get_topic_url($args['itemid']) . '/';
209 }else{
210 $url = wpforo_home_url();
211 }
212 return wpforo_home_url( $url . "?wpforo=sbscrbconfirm&key=" . sanitize_text_field($args['confirmkey']) );
213 }
214
215 function get_unsubscribe_link($confirmkey){
216 return wpforo_home_url( "?wpforo=unsbscrb&key=" . sanitize_text_field($confirmkey) );
217 }
218
219 }