Advertisement
Crecket

Untitled

Aug 3rd, 2015
312
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 28.70 KB | None | 0 0
  1. <?php
  2. class customList {
  3.  
  4. private $db_connection = null;
  5. private $db_connectionSecond = null;
  6.  
  7. public $auctionmessages = array();
  8. public $donationmessages = array();
  9. public $formDebugMessages = array();
  10.  
  11. public $formDebugList = array();
  12.  
  13. public $metalist = array();
  14.  
  15. public $debugging = 0;
  16.  
  17.  
  18.  
  19. public function __construct(){
  20. $this->databaseConnection();
  21. $this->databaseConnectionSecond();
  22. $checkListResult = $this->checkList();
  23. if($checkListResult == false){
  24. $this->auctionmessages[] = 'There already are active auctions';
  25. }else{
  26. $this->auctionmessages[] = 'No more auctions, adding new auctions';
  27. $this->setNewPost();
  28. }
  29. $this->checkDonations();
  30. }
  31.  
  32. private function databaseConnection(){ //database connection
  33. if ($this->db_connection != null) {
  34. return true;
  35. } else {
  36. try {
  37. $this->db_connection = new PDO('mysql:host='. DB_HOST .';dbname='. DB_NAME . ';charset=utf8', DB_USER, DB_PASSWORD);
  38. if($this->debugging == 1){
  39. $this->db_connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  40. $this->db_connection->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); //debugging
  41. }
  42. return true;
  43. } catch (PDOException $e) {
  44. $this->auctionmessages[] = $e->getMessage();
  45. }
  46. }
  47. return false;
  48. }
  49.  
  50. private function databaseConnectionSecond(){ //database connection
  51. if ($this->db_connectionSecond != null) {
  52. return true;
  53. } else {
  54. try {
  55. $this->db_connectionSecond = new PDO('mysql:host='. DB_HOST2 .';dbname='. DB_NAME2 . ';charset=utf8', DB_USER2, DB_PASSWORD2);
  56. if($this->debugging == 1){
  57. $this->db_connectionSecond->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  58. $this->db_connectionSecond->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); //debugging
  59. }
  60. return true;
  61. } catch (PDOException $e) {
  62. $this->auctionmessages[] = $e->getMessage();
  63. }
  64. }
  65. return false;
  66. }
  67.  
  68. public function AuthFunction(){
  69. if(1 == 1){
  70. return true; //if user is logged in/admin return true
  71. }
  72. return false;
  73. }
  74.  
  75. private function checkDonations(){
  76. if($this->AuthFunction() == true){
  77. $full_insert_data = array();
  78. $data = $this->getSoldDonations();
  79. $this->donationmessages[] = "Found ".count($data)." finished auctions";
  80.  
  81. foreach($data as $auction){
  82. $check_donation_list = $this->db_connection->prepare("SELECT *
  83. FROM auction WHERE auctionid = :id");
  84. $check_donation_list->bindValue(':id', $auction, PDO::PARAM_INT);
  85. $check_donation_list->execute();
  86.  
  87. if($check_donation_list->rowcount() == 0){
  88. $get_postMeta = $this->db_connection->prepare("SELECT post_id, meta_key, meta_value FROM wp_postmeta
  89. WHERE post_id = :id AND meta_value = 'added' AND meta_key = 'auction_added_status'");
  90. $get_postMeta->bindValue(':id', $auction, PDO::PARAM_INT);
  91. $get_postMeta->execute();
  92. if($get_postMeta->rowcount() == 0){
  93. $this->donationmessages[] = "Found a new auction with auction id: ".$auction;
  94. $get_bid = $this->db_connection->prepare("SELECT bid, name, email, auction_id FROM wp_wdm_bidders
  95. WHERE auction_id = :id ORDER BY bid DESC");
  96. $get_bid->bindValue(':id', $auction, PDO::PARAM_INT);
  97. $get_bid->execute();
  98. if($get_bid->rowcount() > 0){
  99. $biddata = $get_bid->fetch(PDO::FETCH_ASSOC);
  100. $auctionpost = $this->getSettings($auction, "gettitle");
  101.  
  102. $get_userip = $this->db_connection->prepare("SELECT ip FROM wp_user_login_log WHERE user_login = :id");
  103. $get_userip->bindValue(':id', $biddata['name'], PDO::PARAM_STR);
  104. $get_userip->execute();
  105. if($get_userip->rowcount() > 0){
  106. $userip = $get_userip->fetchAll(PDO::FETCH_ASSOC);
  107. $userip = $userip[0]["ip"];
  108. }else{
  109. $userip = "NOIP";
  110. }
  111. $full_insert_data[$auction]['bid'] = $biddata['bid'];
  112. $full_insert_data[$auction]['itemname'] = $auctionpost;
  113. $full_insert_data[$auction]['username'] = $biddata['name'];
  114. $full_insert_data[$auction]['email'] = $biddata['email'];
  115. $full_insert_data[$auction]['ip'] = $userip;
  116.  
  117. $this->donationmessages[] = "The highest bid for this auction was: ".$full_insert_data[$auction]['bid'];
  118. $set_new_donation = $this->db_connectionSecond->prepare("INSERT INTO
  119. auction (itemname, price, username, email, ip)
  120. VALUES (:itemname, :price, :username, :email, :ip)");
  121. $set_new_donation->bindValue(':itemname', $full_insert_data[$auction]['itemname'], PDO::PARAM_STR);
  122. $set_new_donation->bindValue(':price', $full_insert_data[$auction]['bid'], PDO::PARAM_INT);
  123. $set_new_donation->bindValue(':username', $full_insert_data[$auction]['username'], PDO::PARAM_STR);
  124. $set_new_donation->bindValue(':email', $full_insert_data[$auction]['email'], PDO::PARAM_STR);
  125. $set_new_donation->bindValue(':ip', $full_insert_data[$auction]['ip'], PDO::PARAM_STR);
  126. $set_new_donation->execute();
  127. if($set_new_donation->rowcount() > 0){
  128. $this->donationmessages[] = "A new donation has been added. Auction number: ".$auction;
  129. $this->create_post_meta($auction, "auction_added_status", "added", true);
  130. }else{
  131. $this->donationmessages[] = "A new donation has NOT been added. Auction number: ".$auction;
  132. }
  133. }else{
  134. $payamount = 0;
  135. $this->donationmessages[] = "There were no bids for this auction.";
  136. }
  137. }
  138. }
  139. }
  140. }
  141. }
  142.  
  143. private function checkBoughtPayment(){
  144. $check_payment = $this->db_connection->prepare("SELECT post_id FROM auction WHERE meta_key = 'auction_bought_status' AND meta_value = 'bought' GROUP BY post_id");
  145. $check_payment->execute();
  146. if($check_payment->rowcount() == 0){
  147. return true; //there are NO active auctions, return false
  148. }
  149. return false; //there are activeauctions, return false
  150. }
  151.  
  152. private function checkList(){ //check if there are any active auctions
  153. $check_list = $this->db_connection->prepare("SELECT ID FROM wp_posts INNER JOIN wp_postmeta ON wp_posts.ID = wp_postmeta.post_id WHERE meta_key = 'wdm_listing_ends' AND meta_value > NOW()");
  154. $check_list->execute();
  155. if($check_list->rowcount() == 0){
  156. return true; //there are NO active auctions, return false
  157. }
  158. return false; //there are activeauctions, return false
  159. }
  160.  
  161. private function getNewPostMeta(){
  162. if($this->AuthFunction() == true){
  163. //retrieve the post meta from the list of new auctions
  164. $getauction = $this->db_connection->prepare('SELECT * FROM wp_wdm_newlist WHERE status = 0 AND listingstarts < now()');
  165. $getauction->execute();
  166. if($getauction->rowcount() > 0){
  167. $this->auctionmessages[] = "A new auction has been retrieved";
  168. return $getauction->fetch(PDO::FETCH_ASSOC);
  169. }else{
  170. $this->auctionmessages[] = "There are no new auctions on the list";
  171. return false;
  172. }
  173. }
  174. }
  175.  
  176. private function setNewPost(){ //create new auction
  177. if($this->AuthFunction() === true){
  178. $newdata = $this->getNewPostMeta();
  179. if($newdata != false){
  180. $set_new_post = $this->db_connection->prepare("INSERT INTO wp_posts
  181. (post_title, post_content, post_type, post_status, post_excerpt, post_date, post_date_gmt, post_modified, post_modified_gmt)
  182. VALUES(:title, :content, 'ultimate-auction', 'publish', :excerpt, now(), now(), now(), now())");
  183. $set_new_post->bindValue(':title', $newdata['title'], PDO::PARAM_STR);
  184. $set_new_post->bindValue(':content', $newdata['description'], PDO::PARAM_STR);
  185. $set_new_post->bindValue(':excerpt', $newdata['description_small'], PDO::PARAM_STR);
  186. $set_new_post->execute();
  187. $postid = $this->db_connection->lastInsertId();
  188.  
  189. if($set_new_post->rowcount()>0){
  190. $this->auctionmessages[] = "New auction post has been added to the list";
  191. $this->setNewPostMeta($postid, $newdata);
  192. }else{
  193. $this->auctionmessages[] = "New auction post has NOT been added to the list";
  194. }
  195. }
  196. }
  197. }
  198. private function setNewPostMeta($post_id, $newdata){
  199.  
  200. if($this->AuthFunction() === true){
  201. $salt = $this->createUID();
  202. $salt2 = $salt . $this->createUID();
  203. $authkey = array('wdm-auth-key',md5($salt2)); //create random auth key
  204. $wdmimage1 = array('wdm-image-1', $newdata['image1']);
  205. $wdmimage2 = array('wdm-image-2', $newdata['image2']);
  206. $wdmimage3 = array('wdm-image-3', $newdata['image3']);
  207. $wdmimage4 = array('wdm-image-4', $newdata['image4']);
  208. $mainimage = array('wdm-main-image', $newdata['mainimage']);
  209. $listingends = array('wdm_listing_ends',date('Y-m-d H:i:s',(time() +$newdata['listingends'] * 60 * 60 * 24)));
  210. $openingbid = array('wdm_opening_bid',$newdata['openingbid']);
  211. $lowestbid = array('wdm_lowest_bid',$newdata['lowestbid']);
  212. $incremental = array('wdm_incremental_val', $newdata['incrementval']);
  213. $paymentmethod = array('wdm_payment_method', $newdata['paymentmethod']);
  214. $biddingengine = array('wdm_bidding_engine', $newdata['biddingengine']);
  215. $auctionthumb = array('wdm_auction_thumb', $newdata['auctionthumb']);
  216. $currentauclink = array('current_auction_permalink', $_SERVER['HTTP_HOST'].'/?ult_auc_id='.$post_id);
  217.  
  218. $fulldata = array($authkey,$wdmimage1,$wdmimage2,$wdmimage3,$wdmimage4,$lowestbid,$mainimage,$listingends,$openingbid,$incremental,$paymentmethod,$biddingengine,$auctionthumb,$currentauclink);
  219. $successcounter = 0;
  220. $totalcounter = count($fulldata) + 1;
  221. //add post meta
  222.  
  223. $new_post_meta = $this->db_connection->prepare("INSERT INTO wp_postmeta
  224. (post_id, meta_key, meta_value)
  225. VALUES(:idvar, 'wdm_creation_time', now())");
  226. $new_post_meta->bindValue(':idvar', $post_id, PDO::PARAM_INT);
  227. $new_post_meta->execute();
  228. if($new_post_meta->rowcount()>0){
  229. $this->metalist[] = "New auction postmeta has been added to the list: creationtime ".date('Y-m-d H:i:s',(time() +$newdata['listingends'] * 60 * 60 * 24));
  230. $successcounter++;
  231. }else{
  232. $this->metalist[] = "New auction postmeta has NOT been added to the list: creationtime ".date('Y-m-d H:i:s',(time() +$newdata['listingends'] * 60 * 60 * 24));
  233. }
  234.  
  235. foreach($fulldata as $singledata){
  236. $new_post_meta = $this->db_connection->prepare('INSERT INTO wp_postmeta
  237. (post_id, meta_key, meta_value)
  238. VALUES(:idvar, :firstvar, :secvar)');
  239. $new_post_meta->bindValue(':idvar', $post_id, PDO::PARAM_INT);
  240. $new_post_meta->bindValue(':firstvar', $singledata[0], PDO::PARAM_STR);
  241. $new_post_meta->bindValue(':secvar', $singledata[1], PDO::PARAM_STR);
  242. $new_post_meta->execute();
  243. if($new_post_meta->rowcount()>0){
  244. $this->metalist[] = "New auction postmeta has been added to the list: ". $singledata[0]. " value: ". $singledata[1];
  245. $successcounter++;
  246. }else{
  247. $this->metalist[] = "New auction postmeta has NOT been added to the list: ". $singledata[0]. " value: ". $singledata[1];
  248. }
  249. }
  250. $this->handleNewAuction($successcounter, $totalcounter, $post_id, $newdata['auction_id']);
  251. }
  252. }
  253.  
  254. private function handleNewAuction($successcounter, $totalcounter, $post_id, $auction_id){
  255. if($successcounter != $totalcounter){
  256. //delete all post meta
  257. $delete_post_meta = $this->db_connection->prepare('DELETE FROM wp_postmeta WHERE post_id = :id)');
  258. $delete_post_meta->bindValue(':id', $post_id, PDO::PARAM_INT);
  259. $delete_post_meta->execute();
  260. if($delete_post_meta->rowcount() > 0){
  261. $this->auctionmessages[] = "The post meta has been deleted";
  262. }else{
  263. $this->auctionmessages[] = "The post meta has NOT been deleted";
  264. }
  265. //delete the post
  266. $delete_post = $this->db_connection->prepare('DELETE FROM wp_post WHERE ID = :id)');
  267. $delete_post->bindValue(':id', $post_id, PDO::PARAM_INT);
  268. $delete_post->execute();
  269. if($delete_post->rowcount() > 0){
  270. $this->auctionmessages[] = "The post has been deleted";
  271. }else{
  272. $this->auctionmessages[] = "The post has NOT been deleted";
  273. }
  274. }else{
  275. //update the list with new auctions
  276. $update_new_list = $this->db_connection->prepare('UPDATE wp_wdm_newlist SET status = 1 WHERE auction_id = :id');
  277. $update_new_list->bindValue(':id', $auction_id, PDO::PARAM_INT);
  278. $update_new_list->execute();
  279. if($update_new_list->rowcount() > 0){
  280. $this->auctionmessages[] = "The list with new auctions has been updated, status was changed";
  281. }else{
  282. $this->auctionmessages[] = "The list with new auctions has NOT been updated, status was NOT changed";
  283. }
  284.  
  285. //insert new term relationship
  286. $new_relation = $this->db_connection->prepare("INSERT INTO wp_term_relationships
  287. (object_id, term_taxonomy_id, term_order)
  288. VALUES(:idvar, 2, 0)");
  289. $new_relation->bindValue(':idvar', $post_id, PDO::PARAM_INT);
  290. $new_relation->execute();
  291. if($new_relation->rowcount() > 0){
  292. $this->auctionmessages[] = "New term relation has been added to the list";
  293. }else{
  294. $this->auctionmessages[] = "New term relation has NOT been added to the list";
  295. }
  296. }
  297. }
  298.  
  299. public function createForm($auctionid, $uid, $debug){
  300. return false;
  301. //outdated, requires some work on the paypal functions
  302. if(isset($auctionid, $uid)){
  303. $auctionauthkey = $this->getSettings($auctionid, 'authkey');
  304. if($auctionauthkey == $uid){
  305. if($this->debugging == 1){ //set debugging to 0 to use the online version
  306. $pp_link = "https://www.sandbox.paypal.com/cgi-bin/webscr";
  307. }else{
  308. $pp_link = "https://www.paypal.com/cgi-bin/webscr";
  309. }
  310. $wdm_paypal_address = $this->getSettings($auctionid, 'getaddress');
  311. $buy_now_price = $this->getSettings($auctionid, 'buyprice');
  312. $permalink = 'http://localhost/?ult_auc_id='.$auctionid;
  313. $buymessage = 'Buy it now for $'. number_format($buy_now_price, 2, '.', ',');
  314. $post_title = $this->getSettings($auctionid, 'gettitle');
  315. $currency_code = 'USD';
  316. }else{
  317. $this->formDebugMessages[] = 'Unverified params<br>';
  318. }
  319.  
  320. if($debug == 1){
  321. $this->formDebugList[] = "Retrieved key: ".$auctionauthkey."<br>";
  322. $this->formDebugList[] = "PP link: ".$pp_link."<br>";
  323. $this->formDebugList[] = "Paypal address: ".$wdm_paypal_address."<br>";
  324. $this->formDebugList[] = "Post title: ".$post_title."<br>";
  325. $this->formDebugList[] = "Buynow: ".$buy_now_price."<br>";
  326. $this->formDebugList[] = "Permalink: ".$permalink."<br>";
  327. $this->formDebugList[] = "Buymessage: ".$buymessage."<br>";
  328. }
  329.  
  330. if(isset($pp_link, $wdm_paypal_address, $post_title, $buy_now_price, $currency_code, $permalink, $buymessage)){
  331. $formdata = '<form action="'. $pp_link. '" method="post" target="_top">';
  332. $formdata .= '<input type="hidden" name="business" value="'. $wdm_paypal_address.'">';
  333. $formdata .= '<input type="hidden" name="item_name" value="'. $post_title.'">';
  334. $formdata .= '<input type="hidden" name="amount" value="'. $buy_now_price.'">';
  335. $formdata .= '<input type="hidden" name="currency_code" value="'. $currency_code.'">';
  336. $formdata .= '<input type="hidden" name="return" value="'. $permalink.'">';
  337. $formdata .= '<input type="submit" value="'. $buymessage.'" id="wdm-buy-now-button">'; //change this button looks
  338. $formdata .= '<input type="hidden" name="button_subtype" value="services">';
  339. $formdata .= '<input type="hidden" name="no_note" value="0">';
  340. $formdata .= '<input type="hidden" name="bn" value="PP-BuyNowBF:btn_buynowCC_LG.gif:NonHostedGuest">';
  341. $formdata .= '<input type="hidden" name="cmd" value="_xclick">';
  342. $formdata .= '<input type="hidden" name="charset" value="utf-8">';
  343. $formdata .= '</form>';
  344. return $formdata;
  345. }else{
  346. $this->formDebugMessages[] = 'All data not set<br>';
  347. }
  348.  
  349. }else{
  350. $this->formDebugMessages[] = "Params data not set<br>";
  351. }
  352. return FALSE;
  353. }
  354.  
  355. public function checkPaymentParams($uid = NULL){
  356. if($uid == NULL){
  357. if(isset($_GET['auctionid'], $_GET['uid'])){
  358. $auctionid = $_GET['auctionid'];
  359. $auctionauthkey = $this->getSettings($auctionid, 'authkey');
  360. if($auctionauthkey != false && $auctionauthkey == $_GET['uid']){
  361. $post_title = $this->getSettings($auctionid, 'gettitle');
  362. $image1 = $this->get_post_meta($auctionid, 'wdm-image-1', true);
  363. $description = $this->getSettings($auctionid, 'getpost2');
  364.  
  365. $getlastbid = $this->db_connection->prepare("SELECT bid, name FROM wp_wdm_bidders WHERE auction_id = :idvar ORDER BY bid DESC");
  366. $getlastbid->bindValue(':idvar', $auctionid, PDO::PARAM_INT);
  367. $getlastbid->execute();
  368. $result = $getlastbid->fetch(PDO::FETCH_ASSOC);
  369. if($getlastbid->rowcount() == 1){
  370. $formdata = array("title" => $post_title
  371. , "auctionid" => $auctionid
  372. , "price" => $result['bid']
  373. , "image" => $image1
  374. , "description" => $description
  375. , "username" => $result['name']);
  376. return $formdata;
  377. }
  378. }
  379. }
  380. if(isset($_POST['auctionid'], $_POST['uid'])){
  381. $auctionid = $_POST['auctionid'];
  382. $auctionauthkey = $this->getSettings($auctionid, 'authkey');
  383. if($auctionauthkey != false && $auctionauthkey == $_POST['uid']){
  384. $getlastbid = $this->db_connection->prepare("SELECT bid, name FROM wp_wdm_bidders WHERE auction_id = :idvar ORDER BY bid DESC");
  385. $getlastbid->bindValue(':idvar', $auctionid, PDO::PARAM_INT);
  386. $getlastbid->execute();
  387. $result = $getlastbid->fetch(PDO::FETCH_ASSOC);
  388. if($getlastbid->rowcount() == 1){
  389. return $result = array("price" => $result['bid'], "name" => $result['name']);
  390. }
  391. }
  392. }
  393. if(isset($_GET['uid'], $_GET['prod'])){
  394. $auctionid = $_GET['prod'];
  395. $auctionauthkey = $this->getSettings($auctionid, 'authkey');
  396. if($auctionauthkey != false && $auctionauthkey == $_GET['uid']){
  397. $getlastbid = $this->db_connection->prepare("SELECT bid, name FROM wp_wdm_bidders WHERE auction_id = :idvar ORDER BY bid DESC");
  398. $getlastbid->bindValue(':idvar', $auctionid, PDO::PARAM_INT);
  399. $getlastbid->execute();
  400. $result = $getlastbid->fetch(PDO::FETCH_ASSOC);
  401. if($getlastbid->rowcount() == 1){
  402. $itemname = $this->getSettings($auctionid, 'gettitle');
  403. return $result = array("price" => $result['bid'], "name" => $result['name'], 'itemname' => $itemname);
  404. }
  405. }
  406. }
  407. }else{
  408. $auctionauthkey = $this->getSettings($uid, 'authkey');
  409. if($auctionauthkey != false){
  410. return "auctionpayment.php?auctionid=".$uid."&uid=".$auctionauthkey;
  411. }
  412. }
  413. return false;
  414. }
  415.  
  416. public function getSoldDonations(){ //returns all auctions with a status: 'bought'
  417. $get_bought_auctions = $this->db_connection->prepare("SELECT post_id FROM wp_postmeta
  418. WHERE meta_key = 'wdm_listing_ends'
  419. AND meta_value < now()");
  420. $get_bought_auctions->execute();
  421. $data = $get_bought_auctions->fetchAll(PDO::FETCH_ASSOC);
  422. $returndata = array();
  423. foreach($data as $postid){
  424. $get_bids = $this->db_connection->prepare("SELECT post_id FROM wp_postmeta
  425. WHERE meta_key = 'wdm_listing_ends'
  426. AND meta_value < now()");
  427. $get_bids->bindparam(':id', $postid['post_id'], PDO::PARAM_INT);
  428. $get_bids->execute();
  429. if($get_bids->rowcount() > 0){
  430. $returndata[$postid['post_id']] = $postid['post_id'];
  431. }
  432.  
  433. }
  434. return $returndata;
  435. }
  436.  
  437. private function createUID($length = 100) { //random generator
  438. $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ#$%^&';
  439. $charactersLength = strlen($characters);
  440. $randomString = '';
  441. for ($i = 0; $i < $length; $i++) {
  442. $randomString .= $characters[rand(0, $charactersLength - 1)];
  443. }
  444. return $randomString;
  445. }
  446.  
  447. private function switchArray($i, $field1, $field2) { //reformats the arrays
  448. $returndata = array();
  449. foreach ($i as $z){
  450. $returndata[$z[$field1]] = $z[$field2];
  451. }
  452. return $returndata;
  453. }
  454.  
  455. public function get_post_meta($param, $key, $boolean){
  456. $get_postmeta = $this->db_connection->prepare("SELECT meta_key, meta_value FROM wp_postmeta
  457. WHERE meta_key = :inputkey AND post_id = :param");
  458. $get_postmeta->bindparam(":inputkey", $key, PDO::PARAM_STR);
  459. $get_postmeta->bindparam(":param", $param, PDO::PARAM_STR);
  460. $get_postmeta->execute();
  461. $data = $get_postmeta->fetch(PDO::FETCH_ASSOC);
  462. return $data['meta_value'];
  463. }
  464.  
  465. public function create_post_meta($param, $metakey, $metavalue,$boolean){
  466. if($boolean == true){
  467. $check_postmeta = $this->db_connection->prepare("SELECT * FROM wp_postmeta WHERE post_id = :post_id AND meta_key = :metakey");
  468. $check_postmeta->bindparam(":post_id", $param, PDO::PARAM_STR);
  469. $check_postmeta->bindparam(":metakey", $metakey, PDO::PARAM_STR);
  470. $check_postmeta->execute();
  471. if($check_postmeta->rowcount() > 0){
  472. return false;
  473. }
  474. }
  475. $create_postmeta = $this->db_connection->prepare("INSERT INTO wp_postmeta (post_id, meta_key, meta_value) VALUES (:post_id, :metakey, :metavalue)");
  476. $create_postmeta->bindparam(":post_id", $param, PDO::PARAM_STR);
  477. $create_postmeta->bindparam(":metakey", $metakey, PDO::PARAM_STR);
  478. $create_postmeta->bindparam(":metavalue", $metavalue, PDO::PARAM_STR);
  479. $create_postmeta->execute();
  480. if($create_postmeta->rowcount() > 0){
  481. return true;
  482. }
  483. return false;
  484. }
  485.  
  486. public function getSettings($param, $type){ //getparams for the buy form
  487. switch ($type){
  488. case 'authkey' :
  489. $data = $this->get_post_meta($param, 'wdm-auth-key', true);
  490. break;
  491. case 'buyprice' :
  492. $data = $this->get_post_meta($param, 'wdm_buy_it_now', true);
  493. break;
  494. case 'gettitle' :
  495. $get_postmeta = $this->db_connection->prepare("SELECT post_title FROM wp_posts
  496. WHERE ID = :inputkey");
  497. $get_postmeta->bindparam(":inputkey", $param, PDO::PARAM_STR);
  498. $get_postmeta->execute();
  499. $data = $get_postmeta->fetch(PDO::FETCH_ASSOC);
  500. return $data['post_title'];
  501. break;
  502. case 'getpost':
  503. $get_postmeta = $this->db_connection->prepare("SELECT post_content FROM wp_posts
  504. WHERE ID = :inputkey");
  505. $get_postmeta->bindparam(":inputkey", $param, PDO::PARAM_STR);
  506. $get_postmeta->execute();
  507. $data = $get_postmeta->fetch(PDO::FETCH_ASSOC);
  508. return $data['post_content'];
  509. break;
  510. case 'getpost2':
  511. $get_postmeta = $this->db_connection->prepare("SELECT post_excerpt FROM wp_posts
  512. WHERE ID = :inputkey");
  513. $get_postmeta->bindparam(":inputkey", $param, PDO::PARAM_STR);
  514. $get_postmeta->execute();
  515. $data = $get_postmeta->fetch(PDO::FETCH_ASSOC);
  516. return $data['post_excerpt'];
  517. break;
  518. default :
  519. $data = false;
  520. break;
  521. }
  522. return $data;
  523. }
  524.  
  525. //messages, call any of these to show them in a list
  526. public function showAuctionMessages(){
  527. echo "<h3>Auction Messages</h3>
  528. <ul>";
  529. foreach($this->auctionmessages as $message){
  530. echo "<li>".$message."</li>";
  531. }
  532. echo "</ul>";
  533.  
  534. echo "<h3>Auction Meta list</h3>
  535. <ul>";
  536. foreach($this->metalist as $meta){
  537. echo "<li>".$meta."</li>";
  538. }
  539. echo "</ul>";
  540. }
  541. public function showDonationMessages(){
  542. echo "<h3>Donation Messages</h3>
  543. <ul>";
  544. foreach($this->donationmessages as $message){
  545. echo "<li>".$message."</li>";
  546. }
  547. echo "</ul>";
  548. }
  549. public function showFormMessages(){
  550. echo "<h3>Form debug messages</h3>
  551. <ul>";
  552. foreach($this->formDebugMessages as $meta){
  553. echo "<li>".$meta."</li>";
  554. }
  555. echo "</ul>";
  556.  
  557. echo "<h3>Form debug list</h3>
  558. <ul>";
  559. foreach($this->formDebugList as $meta){
  560. echo "<li>".$meta."</li>";
  561. }
  562. echo "</ul>";
  563. }
  564. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement