PluginProbe
Ultimate WordPress Auction Plugin / 1.0.4
Ultimate WordPress Auction Plugin v1.0.4
4.3.4 trunk 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 4.0.2 4.0.3
ultimate-auction / ultimate-auction.php

ultimate-auction.php in Ultimate WordPress Auction Plugin 1.0.4, at ultimate-auction.php

471 lines 16.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 Plugin Name: Wordpress Auction Plugin
4 Plugin URI: http://auctionplugin.net
5 Description: Awesome plugin to host auctions on your wordpress site and sell anything you want.
6 Author: Nitesh Singh
7 Author URI: http://auctionplugin.net
8 Version: 1.0.4
9 License: GPLv2
10 Copyright 2013 Nitesh Singh
11 */
12
13 require_once('settings-page.php');
14 require_once('auction-shortcode.php');
15 require_once('send-auction-email.php');
16
17 //create a table for auction bidders on plugin activation
18 register_activation_hook(__FILE__,'wdm_create_bidders_table');
19
20 function wdm_create_bidders_table()
21 {
22 require(ABSPATH . 'wp-admin/includes/upgrade.php');
23 global $wpdb;
24
25 $data_table = $wpdb->prefix."wdm_bidders";
26 $sql = "CREATE TABLE IF NOT EXISTS $data_table
27 (
28 id MEDIUMINT(9) NOT NULL AUTO_INCREMENT,
29 name VARCHAR(45),
30 email VARCHAR(45),
31 auction_id MEDIUMINT(9),
32 bid DECIMAL(10,2),
33 date datetime,
34 PRIMARY KEY (id)
35 );";
36
37 dbDelta($sql);
38
39 //for old table (till 'Wordpress Auction Plugin' version 1.0.2) which had 'bid' column as integer(MEDIUMINT)
40 $alt_sql = "ALTER TABLE $data_table MODIFY bid DECIMAL(10,2);";
41
42 $wpdb->query($alt_sql);
43 }
44
45 //send email Ajax callback - An automatic activity once an auction has expired
46 function send_auction_email_callback()
47 {
48 require_once('email-template.php');
49
50 $sent_email = ultimate_auction_email_template($_POST['auc_title'], $_POST['auc_id'], $_POST['auc_cont'], $_POST['auc_bid'], $_POST['auc_email'], $_POST['auc_url']);
51
52 if(!$sent_email)
53 update_post_meta($_POST['auc_id'], 'wdm_to_be_sent', '');
54
55 die();
56 }
57
58 add_action('wp_ajax_send_auction_email', 'send_auction_email_callback');
59 add_action('wp_ajax_nopriv_send_auction_email', 'send_auction_email_callback');
60
61 //resend email Ajax callback - 'Resend' link on 'Manage Auctions' page
62 function resend_auction_email_callback()
63 {
64 require_once('email-template.php');
65
66 $res_email = ultimate_auction_email_template($_POST['a_title'], $_POST['a_id'], $_POST['a_cont'], $_POST['a_bid'], $_POST['a_em'], $_POST['a_url']);
67
68 if($res_email)
69 echo "Email sent successfully";
70 else
71 echo "Sorry, email cannot be sent";
72
73 die();
74 }
75
76 add_action('wp_ajax_resend_auction_email', 'resend_auction_email_callback');
77 add_action('wp_ajax_nopriv_resend_auction_email', 'resend_auction_email_callback');
78
79 //delete auction Ajax callback - 'Delete' link on 'Manage Auctions' page
80 function delete_auction_callback()
81 {
82 if($_POST["force_del"] === 'yes')
83 $force = true;
84 else
85 $force = false;
86 //echo $force;
87 if(current_user_can('delete_posts'))
88 {
89 $del_auc = wp_delete_post($_POST["del_id"], false);
90 }
91
92 if($del_auc)
93 {
94 echo "Auction '".$_POST['auc_title']."' deleted successfully";
95 }
96 else
97 echo "Sorry, this auction cannot be deleted";
98 die();
99 }
100
101 add_action('wp_ajax_delete_auction', 'delete_auction_callback');
102 add_action('wp_ajax_nopriv_delete_auction', 'delete_auction_callback');
103
104 //end auction Ajax callback - 'End Auction' link on 'Manage Auctions' page
105 function end_auction_callback()
106 {
107 $end_auc = update_post_meta($_POST['end_id'], 'wdm_listing_ends', date("Y-m-d H:i:s", time()));
108
109 $check_term = term_exists('expired', 'auction-status');
110 wp_set_post_terms($_POST['end_id'], $check_term["term_id"], 'auction-status');
111
112 if($end_auc)
113 echo "Auction '".$_POST['end_title']."' ended successfully";
114 else
115 echo "Sorry, this auction cannot be ended";
116 die();
117 }
118
119 add_action('wp_ajax_end_auction', 'end_auction_callback');
120 add_action('wp_ajax_nopriv_end_auction', 'end_auction_callback');
121
122 //cancel bid entry Ajax callback - 'Cancel Last Bid' link on 'Manage Auctions' page
123 function cancel_last_bid_callback()
124 {
125 global $wpdb;
126
127 $cancel_bid = $wpdb->query(
128 $wpdb->prepare(
129 "
130 DELETE FROM ".$wpdb->prefix."wdm_bidders
131 WHERE id = %d
132 ",
133 $_POST['cancel_id']
134 )
135 );
136
137 if($cancel_bid)
138 echo $_POST['bidder_name']."'s bid entry removed successfully";
139 else
140 echo "Sorry, bid entry cannot be removed";
141 die();
142 }
143
144 add_action('wp_ajax_cancel_last_bid', 'cancel_last_bid_callback');
145 add_action('wp_ajax_nopriv_cancel_last_bid', 'cancel_last_bid_callback');
146
147 //place bid Ajax callback - 'Place Bid' button on Single Auction page
148 function place_bid_now_callback()
149 {
150 if(is_user_logged_in()){
151 global $wpdb;
152 $wpdb->hide_errors();
153
154 $q="SELECT MAX(bid) FROM ".$wpdb->prefix."wdm_bidders WHERE auction_id =".$_POST['auction_id'];
155 $next_bid = $wpdb->get_var($q);
156
157 if(!empty($next_bid)){
158 update_post_meta($_POST['auction_id'], 'wdm_previous_bid_value', $next_bid); //store bid value of the most recent bidder
159 }
160
161 if(empty($next_bid))
162 $next_bid = get_post_meta($_POST['auction_id'], 'wdm_opening_bid', true);
163
164 $next_bid = $next_bid + get_post_meta($_POST['auction_id'],'wdm_incremental_val',true);
165
166 if($_POST['bid'] < $next_bid)
167 {
168 echo "inv_bid".$next_bid;
169 }
170 else
171 {
172 $palce_bid = $wpdb->insert(
173 $wpdb->prefix.'wdm_bidders',
174 array(
175 'name' => $_POST['name'],
176 'email' => $_POST['email'],
177 'auction_id' => $_POST['auction_id'],
178 'bid' => $_POST['bid'],
179 'date' => date("Y-m-d H:i:s", time())
180 ),
181 array(
182 '%s',
183 '%s',
184 '%d',
185 '%f',
186 '%s'
187 )
188 );
189
190 if($palce_bid)
191 {
192 $qry="SELECT COUNT(bid) FROM ".$wpdb->prefix."wdm_bidders WHERE auction_id =".$_POST['auction_id'];
193 $total_bids = $wpdb->get_var($qry);
194 $buy_price = get_post_meta($_POST['auction_id'], 'wdm_buy_it_now', true);
195
196 if(!empty($buy_price) && $_POST['bid'] >= $buy_price)
197 {
198 update_post_meta($_POST['auction_id'], 'wdm_listing_ends', date("Y-m-d H:i:s", time()));
199 $check_term = term_exists('expired', 'auction-status');
200 wp_set_post_terms($_POST['auction_id'], $check_term["term_id"], 'auction-status');
201 update_post_meta($_POST['auction_id'], 'email_sent_imd', 'sent_imd');
202 echo "Won";
203 }
204 else
205 echo "Placed";
206
207 }
208 }
209 }
210 else{
211 echo "Please log in to place bid";
212 }
213 die();
214 }
215
216 add_action('wp_ajax_place_bid_now', 'place_bid_now_callback');
217 add_action('wp_ajax_nopriv_place_bid_now', 'place_bid_now_callback');
218
219 //bid notification email Ajax callback - Single Auction page
220 function bid_notification_callback()
221 {
222
223 $c_code = substr(get_option('wdm_currency'), -3);
224
225 //$perma_type = get_option('permalink_structure');
226 //if(empty($perma_type))
227 // $char = "&";
228 //else
229 // $char = "?";
230 $char = $_POST['char'];
231
232 $ret_url = $_POST['auc_url'].$char."ult_auc_id=".$_POST['auction_id'];
233
234 $adm_email = get_option("wdm_auction_email");
235
236 $adm_sub = "[".get_bloginfo('name')."] A bidder has placed a bid on the product - ".$_POST['auc_name'];
237 $adm_msg = "";
238 $adm_msg = "<strong>Bidder Details - </strong>";
239 $adm_msg .= "<br /><br /> Bidder Name: ".$_POST['name'];
240 $adm_msg .= "<br /><br /> Bidder Email: ".$_POST['email'];
241 $adm_msg .= "<br /><br /> Bid Value: ".$c_code." ".round($_POST['bid'], 2);
242 $adm_msg .= "<br /><br /><strong>Product Details - </strong>";
243 $adm_msg .= "<br /><br /> Product URL: ".$ret_url;
244 $adm_msg .= "<br /><br /> Product Name: ".$_POST['auc_name'];
245 $adm_msg .= "<br /><br /> Description: <br />".$_POST['auc_desc']."<br />";
246
247 $hdr = "";
248 //$hdr = "From: ". get_bloginfo('name') ." <". $adm_email ."> \r\n";
249 $hdr .= "MIME-Version: 1.0\r\n";
250 $hdr .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
251
252 wp_mail($adm_email, $adm_sub, $adm_msg, $hdr, '');
253
254 $bid_sub = "[".get_bloginfo('name')."] You recently placed a bid on the product - ".$_POST['auc_name'];
255 $bid_msg = "";
256 $bid_msg = "Here are the details - ";
257 $bid_msg .= "<br /><br /> Product URL: ". $ret_url;
258 $bid_msg .= "<br /><br /> Product Name: ".$_POST['auc_name'];
259 $bid_msg .= "<br /><br /> Bid Value: ".$c_code." ".round($_POST['bid'], 2);
260 $bid_msg .= "<br /><br /> Description: <br />".$_POST['auc_desc']."<br />";
261
262 wp_mail($_POST['email'], $bid_sub, $bid_msg, $hdr, '');
263
264 //outbid email
265 global $wpdb;
266 $wpdb->hide_errors();
267
268 $prev_bid = get_post_meta($_POST['auction_id'], 'wdm_previous_bid_value', true);
269
270 if(!empty($prev_bid)){
271 $bidder_email = "";
272 $email_qry = "SELECT email FROM ".$wpdb->prefix."wdm_bidders WHERE bid =".$prev_bid." AND auction_id =".$_POST['auction_id'];
273 $bidder_email = $wpdb->get_var($email_qry);
274
275 if($bidder_email != $_POST['email']){
276 $outbid_sub = "[".get_bloginfo('name')."] You have been outbid on the product - ".$_POST['auc_name'];
277 wp_mail($bidder_email, $outbid_sub, $bid_msg, $hdr, '');
278 }
279 }
280
281 //auction won immediately
282 if(isset($_POST['email_type']) && $_POST['email_type'] === 'winner_email')
283 {
284 require_once('email-template.php');
285 ultimate_auction_email_template($_POST['auc_name'], $_POST['auction_id'], $_POST['auc_desc'], round($_POST['bid'], 2), $_POST['email'], $ret_url);
286 }
287
288 die();
289 }
290
291 add_action('wp_ajax_bid_notification', 'bid_notification_callback');
292 add_action('wp_ajax_nopriv_bid_notification', 'bid_notification_callback');
293
294 //private message Ajax callback - Single Auction page
295 function private_message_callback()
296 {
297 //$perma_type = get_option('permalink_structure');
298 //if(empty($perma_type))
299 // $char = "&";
300 //else
301 // $char = "?";
302
303 $char = $_POST['p_char'];
304
305 $auc_url = $_POST['p_url'].$char."ult_auc_id=".$_POST['p_auc_id'];
306
307 $adm_email = get_option('wdm_auction_email');
308
309 $p_sub = "[".get_bloginfo('name')."] You have a private message from a site visitor";
310
311 $msg = "";
312 $msg = "Name: ".$_POST['p_name']."<br /><br />";
313 $msg .= "Email: ".$_POST['p_email']."<br /><br />";
314 $msg .= "Message: <br />".$_POST['p_msg']."<br /><br />";
315 $msg .= "Product URL: ".$auc_url."<br />";
316
317 $hdr = "";
318 //$hdr = "From: ". get_bloginfo('name') ." <". $adm_email ."> \r\n";
319 $hdr .= "MIME-Version: 1.0\r\n";
320 $hdr .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
321
322 $sent = wp_mail($adm_email, $p_sub, $msg, $hdr, '');
323
324 if($sent)
325 echo "Email sent successfully";
326 else
327 echo "Sorry, email could not be sent";
328
329 die();
330 }
331
332 add_action('wp_ajax_private_message', 'private_message_callback');
333 add_action('wp_ajax_nopriv_private_message', 'private_message_callback');
334
335 //plugin credit link
336 add_action('wp_footer', 'wdm_plugin_credit_link');
337
338 function wdm_plugin_credit_link()
339 {
340 add_option('wdm_powered_by', "Yes");
341
342 $check_credit = get_option('wdm_powered_by');
343
344 if($check_credit == "Yes")
345 {
346 if(!is_admin())
347 echo "<center><div id='ult-auc-footer-credit'><a href='http://auctionplugin.net' target='_blank'>Powered By Ultimate Auction</a></div></center>";
348 }
349 }
350
351 add_action('init', 'wdm_set_auction_timezone');
352 function wdm_set_auction_timezone()
353 {
354 $get_default_timezone = get_option('wdm_time_zone');
355
356 if(!empty($get_default_timezone))
357 {
358 date_default_timezone_set($get_default_timezone);
359 }
360
361 if(isset($_GET["ult_auc_id"]) && $_GET["ult_auc_id"]){
362
363 $single_auction=get_post($_GET["ult_auc_id"]);
364
365 $auth_key = get_post_meta($single_auction->ID, 'wdm-auth-key', true);
366
367 if(isset($_GET['wdm']) && $_GET['wdm'] === $auth_key)
368 {
369 $terms = wp_get_post_terms($single_auction->ID, 'auction-status',array("fields" => "names"));
370 if(!in_array('expired',$terms))
371 {
372 $chck_term = term_exists('expired', 'auction-status');
373 wp_set_post_terms($single_auction->ID, $chck_term["term_id"], 'auction-status');
374 update_post_meta($single_auction->ID, 'wdm_listing_ends', date("Y-m-d H:i:s", time()));
375 }
376
377 update_post_meta($single_auction->ID, 'auction_bought_status', 'bought');
378 echo '<script type="text/javascript">
379 setTimeout(function() {
380 alert("Thank you for buying this product.");
381 }, 1000);
382 </script>';
383
384 //details of a product sold through buy now link
385 if(is_user_logged_in()){
386 $curr_user = wp_get_current_user();
387 $buyer_email = $curr_user->user_email;
388 $winner_name = $curr_user->user_login;
389 }
390
391 $auction_email = get_option('wdm_auction_email');
392 $site_name = get_bloginfo('name');
393 $site_url = get_bloginfo('url');
394 $c_code = substr(get_option('wdm_currency'), -3);
395 $rec_email = get_option('wdm_paypal_address');
396 $buy_now_price = get_post_meta($single_auction->ID, 'wdm_buy_it_now', true);
397
398 $headers = "";
399 //$headers = "From: ". $site_name ." <". $auction_email ."> \r\n";
400 $headers .= "MIME-Version: 1.0\r\n";
401 $headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
402
403 $return_url = "";
404 $return_url = strstr($_SERVER['REQUEST_URI'], 'ult_auc_id', true);
405 $return_url = $site_url.$return_url."ult_auc_id=".$_GET["ult_auc_id"];
406
407 $auction_data = array('auc_id' => $single_auction->ID,
408 'auc_name' => $single_auction->post_title,
409 'auc_desc' => $single_auction->post_content,
410 'auc_price' => $buy_now_price,
411 'auc_currency' => $c_code,
412 'seller_paypal_email' => $rec_email,
413 'winner_email' => $buyer_email,
414 'seller_email' => $auction_email,
415 'winner_name' => $winner_name,
416 'pay_method' => 'method_paypal',
417 'site_name' => $site_name,
418 'site_url' => $site_url,
419 'product_url' => $return_url,
420 'header' => $headers
421 );
422
423 do_action('ua_shipping_data_email', $auction_data);
424 }
425 }
426
427
428 }
429
430 function wdm_ending_time_calculator($seconds)
431 {
432 $days = floor($seconds / 86400);
433 $seconds %= 86400;
434
435 $hours = floor($seconds / 3600);
436 $seconds %= 3600;
437
438 $minutes = floor($seconds / 60);
439 $seconds %= 60;
440
441 $rem_tm = "";
442
443 if($days > 1)
444 $rem_tm = $days ." days ";
445 elseif($days == 1)
446 $rem_tm = $days ." day ";
447
448 if($hours > 1)
449 $rem_tm .= $hours ." hrs ";
450 elseif($hours == 1)
451 $rem_tm .= $hours ." hr ";
452
453 if($minutes > 1)
454 $rem_tm .= $minutes ." mins ";
455 elseif($minutes == 1)
456 $rem_tm .= $minutes ." min ";
457
458 if($seconds > 1)
459 $rem_tm .= $seconds ." secs";
460 elseif($seconds == 1)
461 $rem_tm .= $seconds ." sec";
462
463 return $rem_tm;
464 }
465 add_filter('comment_post_redirect', 'redirect_after_comment');
466 function redirect_after_comment($location)
467 {
468 return $_SERVER["HTTP_REFERER"];
469 }
470
471 ?>