Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /** Items for Points Module */
- cp_module_register(__('Items for Points', 'cp') , 'items4points' , '1.0', 'sl21', '', '' , __('This module allows your members to buy virtual Items with points', 'cp'), 1);
- if(cp_module_activated('items4points')){
- /* Based on the Answer Question for Points Module by Tosh Hatch, http://www.SlySpyder.com */
- /* ****************** Shortcode for Items for Points ************ */
- function items4points($atts) {
- extract(shortcode_atts(array(
- 'item' => '',
- 'points' => '',
- 'limit' => '',
- 'limituser' => '',
- ), $atts));
- if (isset($_POST[$atts[item]])) {
- get_currentuserinfo();
- if ( !is_user_logged_in() ) {
- $output .= 'please login';
- return $output;
- }
- global $wpdb, $post;
- $multiple = $_POST['multiple'];
- $getitemno = strtolower($_POST[$atts[item]]);
- $item = strtolower($item);
- $neg = '-';
- $negpoints = str_replace( $neg , '' , ($points * $multiple));
- $current_user = wp_get_current_user();
- $allusers_times_bought = $wpdb->get_var("SELECT COUNT(*) FROM wp_cp WHERE type = 'shop_item' AND data = '".$item."'");
- $user_times_bought = $wpdb->get_var("SELECT COUNT(*) FROM wp_cp WHERE type = 'shop_item' AND uid = '".$current_user->ID."' AND data = '".$item."'");
- $pointsavailable = $wpdb->get_var("SELECT meta_value FROM wp_usermeta WHERE meta_key = 'cpoints' AND user_id = '".$current_user->ID."'");
- $wpdb->query("INSERT IGNORE INTO wp_cp_shop (user_id) VALUES (".$current_user->ID.")");
- if (($user_times_bought + $multiple) > ($atts[limituser])) { // In the short code userlimit="10" means user can buy this item 10 times
- $output .= '<p><strong>you reached your personal limit for this item!</strong></p><br />';
- } else {
- if ($pointsavailable + ($points * $multiple) < 0) // Check if user has enough coins to buy item
- {$output .= '<p><strong>not enough coins!</strong></p><br />';}
- else{
- if ($getitemno == $item) {
- if (($allusers_times_bought + $multiple) <= $limit and ($points * $multiple) < 0) { // limit="10" means only first 10 user can buy item
- // +check if coins reduced or awarded
- $output .= '<p><strong>you paid '.$negpoints.' coins for item: '.$item.' x'.$multiple.'</strong></p><br />';
- for($i=1;$i<=$multiple;$i++){ //multiple single entrys in db for correct limit check
- cp_points('shop_item', $current_user->ID, $points, $getitemno);
- }
- $wpdb->query("UPDATE wp_cp_shop SET $item = $item + $multiple WHERE user_id = '".$current_user->ID."'");
- }
- elseif (($allusers_times_bought + $multiple) <= $limit and ($points * $multiple) > 0) { // limit="10" means only first 10 user can buy item
- // +check if coins reduced or awarded
- $output .= '<p><strong>you got '.($points * $multiple).' coins and item: '.$item.' x'.$multiple.'</strong></p><br />';
- for($i=1;$i<=$multiple ;$i++){ //multiple single entrys in db for correct limit check
- cp_points('shop_item', $current_user->ID, $points, $getitemno);
- }
- $wpdb->query("UPDATE wp_cp_shop SET $item = $item + 1 WHERE user_id = '".$current_user->ID."'");
- } else {
- $output .= '<p><strong>item is no longer available!</strong></p>';
- }
- } else {
- $url = htmlspecialchars($_SERVER['HTTP_REFERER']);
- $output .= '';
- }
- }
- }
- return $output;
- }
- $output .= '<form name="question" method="post" action="">
- <img src="https://yourdomain.com/wp-content/uploads/images/'.$atts[item].'.png">
- <p><label><select name="multiple" onchange="showControls(this.value)">
- <option value="1">1x</option>
- <option value="2">2x</option>
- <option value="3">3x</option>
- <option value="4">4x</option>
- <option value="5">5x</option>
- </select>
- <input type="submit" name="button" id="button" value="Buy Now"></label></p>
- <p><label><input type="hidden" value="'.$atts[item].'" name="'.$atts[item].'" id="'.$atts[item].'" /></label></p>
- </form>';
- return $output;
- }
- add_shortcode('items4points', 'items4points');
- add_action('cp_logs_description','logit', 10, 4); // Log it
- function logit($type,$uid,$points,$data){
- if($type != 'shop_item') { return; }
- echo 'Shop Item: '.$data;
- }
- /* ****************** Shortcode for Items for Points ************ */
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement