Forum Replies Created

Viewing 15 replies - 1 through 15 (of 22 total)
  • Thread Starter Blindacme

    (@blindacme)

    Apologies, I just read the rules after posting. I will ask via your support system.

    Thread Starter Blindacme

    (@blindacme)

    Got it, so I changed the name of the file input from thumbnail to thumbnail[]. Then I wrapped the above paste in a function and added this part at the top of the file and it works perfectly:

    if ( $_FILES ) {
        	$files = $_FILES['thumbnail'];
        		foreach ($files['name'] as $key => $value) {
        		  if ($files['name'][$key]) {
        		  $file = array(
        		  'name' => $files['name'][$key],
        		  'type' => $files['type'][$key],
        		  'tmp_name' => $files['tmp_name'][$key],
        		  'error' => $files['error'][$key],
        		  'size' => $files['size'][$key]
        		  );
    
        			  $_FILES = array("" => $file);
    
        			  foreach ($_FILES as $file => $array) {
        			          //call my function
        				  create_var_product($file, $post_id);
        			  }
        		  }
        	}
        }
    Thread Starter Blindacme

    (@blindacme)

    Got it if anyone needs something similar, I set mine to add 40 points to a transaction. Prob not the best approach but will suffice for now.

    <?php
    
    /** Donate Module */
    
    cp_module_register(__('Donate', 'cp') , 'donate' , '1.2', 'CubePoints', 'http://cubepoints.com', 'http://cubepoints.com' , __('This module allows your users to donate points to each other.', 'cp'), 1);
    
    if(cp_module_activated('donate')){
    
    	add_action( 'wp_ajax_cp_donate_search', 'cp_module_donate_ajax_search' );
    
    	function cp_module_donate_ajax_search() {
    
    		header( "Content-Type: application/json" );
    
    		if( $_REQUEST['q']=='' ){
    
    			$response = json_encode( array() );
    
    			echo $response;
    
    			exit;
    
    		}
    
    		global $wpdb;
    
    		$users = $wpdb->get_results('SELECT ID, user_login, first_name, last_name, md5(user_email) as email_hash FROM <code>' . $wpdb->prefix . 'users</code>
    
    										LEFT JOIN (
    
    											SELECT
    
    												user_id,
    
    												meta_value as first_name
    
    											FROM <code>' . $wpdb->prefix . 'usermeta</code>
    
    											WHERE (	meta_key =  \'first_name\' )
    
    										) AS A
    
    										ON id = A.user_id
    
    										LEFT JOIN (
    
    											SELECT
    
    												user_id,
    
    												meta_value as last_name
    
    											FROM <code>' . $wpdb->prefix . 'usermeta</code>
    
    											WHERE (	meta_key =  \'last_name\' )
    
    										) AS B
    
    										ON id = B.user_id
    
    										WHERE
    
    											user_login  LIKE \''. $wpdb->escape($_REQUEST['q']) .'%\'
    
    											OR CONCAT_WS(\' \', first_name, last_name) LIKE \''. $wpdb->escape($_REQUEST['q']) .'%\'
    
    											OR CONCAT_WS(\' \', last_name, first_name) LIKE \''. $wpdb->escape($_REQUEST['q']) .'%\'
    
    											OR CONCAT_WS(\' \', first_name, last_name) LIKE \'% '. $wpdb->escape($_REQUEST['q']) .'%\'
    
    											OR CONCAT_WS(\' \', last_name, last_name) LIKE \'% '. $wpdb->escape($_REQUEST['q']) .'%\'
    
    										ORDER BY CASE
    
    											WHEN user_login  LIKE \''. $wpdb->escape($_REQUEST['q']) .'%\' THEN 1 ELSE 2 END 
    
    										LIMIT 30');
    
    		$response = array();
    
    		foreach($users as $u){
    
    			$response[] = array(
    
    							'id' => $u->ID,
    
    							'ul' => $u->user_login,
    
    							'fn' => $u->first_name,
    
    							'ln' => $u->last_name,
    
    							'eh' => $u->email_hash
    
    							);
    
    		}
    
    		$response = json_encode($response);
    
    		echo $response;
    
    		exit;
    
    	}
    
    	function cp_module_donate_scripts(){
    
    		wp_register_script('impromptu',
    
    		   CP_PATH . 'modules/donate/jquery-impromptu.4.0.min.js',
    
    		   array('jquery'),
    
    		   '4.0' );
    
    		wp_register_style('cp_donate', CP_PATH . 'modules/donate/donate.css');
    
    		wp_enqueue_script('impromptu');
    
    		wp_enqueue_style('cp_donate');
    
    	}
    
    	add_action('init', 'cp_module_donate_scripts');
    
    	function cp_module_donate_do(){
    
    		$recipient = $_POST['recipient'];
    
    		$points = $_POST['points'];
    
    		$points_fee = 40;
    
    		$points_sum = $points + $points_fee;
    
    		$message = htmlentities(stripslashes($_POST['message']), ENT_QUOTES, 'UTF-8');
    
    		$user =  get_user_by('id', $recipient);
    
    		if(!is_user_logged_in()){
    
    			$r['success'] = false;
    
    			$r['message'] = __('You must be logged in to make a donation!', 'cp');
    
    		}
    
    		else if($recipient==''){
    
    			$r['success'] = false;
    
    			$r['message'] = __('Please enter the username of the recipient!', 'cp');
    
    		}
    
    		else if($user->ID==''){
    
    			$r['success'] = false;
    
    			$r['message'] = __('You have entered an invalid recipient!', 'cp');
    
    		}
    
    		else if($user->ID==cp_currentUser()){
    
    			$r['success'] = false;
    
    			$r['message'] = __('You cannot donate to yourself!', 'cp');
    
    		}
    
    		else if(!is_numeric($points)){
    
    			$r['success'] = false;
    
    			$r['message'] = __('You have entered an invalid number of points!', 'cp');
    
    		}
    
    		else if((int)$points<1){
    
    			$r['success'] = false;
    
    			$r['message'] = __('You have to donate at least one point!', 'cp');
    
    		}
    
    		else if((int)$points != (float) $points){
    
    			$r['success'] = false;
    
    			$r['message'] = __('You have entered an invalid number of points!', 'cp');
    
    		}
    
    		else if((int)$points_sum>(int)cp_getPoints(cp_currentUser())){
    
    			$r['success'] = false;
    
    			$r['message'] = __('You do not have that many points to donate!', 'cp');
    
    		}
    
    		else if(strlen($message)>160){
    
    			$r['success'] = false;
    
    			$r['message'] = __('The message you have entered is too long!', 'cp');
    
    		}
    
    		else{
    
    			$message = mb_convert_encoding($message, 'HTML-ENTITIES', 'UTF-8');
    
    			$r['success'] = true;
    
    			$r['message'] = __('Your donation is successful!', 'cp');
    
    			cp_points('donate_from', $user->ID, $points_sum, serialize(array("from"=>cp_currentUser(),"message"=>$message)));
    
    			cp_points('donate_to', cp_currentUser(), -$points_sum, serialize(array("to"=>$user->ID,"message"=>$message)));
    
    			$r['pointsd'] = cp_displayPoints(0, 1, 1);
    
    			$r['points'] = cp_displayPoints(0, 1, 0);
    
    		}
    
    		echo json_encode($r);
    
    		die();
    
    	}
    
    	add_action('wp_ajax_cp_module_donate_do', 'cp_module_donate_do');
    
    	add_action('wp_ajax_nopriv_cp_module_donate_do', 'cp_module_donate_do');
    
    	// Handle JS
    
    	function cp_module_donate_script(){
    
    		wp_register_script('cp_donate_script', WP_PLUGIN_URL.'/'.str_replace(basename( __FILE__),"",plugin_basename(__FILE__)). 'donate.js', array('jquery'));
    
    		wp_enqueue_script('cp_donate_script');
    
    		wp_localize_script( 'cp_donate_script', 'cp_donate', array(
    
    			'logged_in' =>  is_user_logged_in() ? '1' : '0',
    
    			'ajax_url' =>  admin_url( 'admin-ajax.php' ),
    
    			'title' => __('Points Transfer', 'cp'),
    
    			'searchText' => __('Type a username and press Enter to search... <br /><strong>(NOTE: a 40 Point transaction fee will be added to your transaction)</strong>', 'cp'),
    
    			'searchingText' => __('Searching, please wait...', 'cp'),
    
    			'searchPlaceholder' => __('Search...', 'cp'),
    
    			'nothingFound' => __('Nothing Found', 'cp'),
    
    			'amountToDonate' => __('Enter amount of points to transfer...', 'cp'),
    
    			'donateAmountPlaceholder' => __('Amount to transfer...', 'cp'),
    
    			'donateComment' => __('Leave feedback (to be displayed on recipient\'s profile)', 'cp'),
    
    			'donateCommentPlaceholder' => __('Enter a message...', 'cp'),
    
    			'notLoggedInText' => __('You must be logged in to make a transfer!', 'cp'),
    
    			'somethingWentWrongText' => __('Oops, something went wrong! Please try again later.', 'cp')
    
    		) );
    
    	}
    
    	add_action('init', 'cp_module_donate_script');
    
    	function cp_module_donate_widget(){
    
    		if(is_user_logged_in()){
    
    			?>
    
    				<li><a href="javascript:void(0);" onclick="cp_module_donate();"><?php _e('Donate', 'cp'); ?></a></li>
    
    			<?php
    
    		}
    
    	}
    
    	add_action('cp_pointsWidget', 'cp_module_donate_widget',1000);
    
    	/** Donations log hook */
    
    	add_action('cp_logs_description','cp_admin_logs_desc_donate', 10, 4);
    
    	function cp_admin_logs_desc_donate($type,$uid,$points,$data){
    
    		if($type!='donate_to'&&$type!='donate_from') { return; }
    
    		$data = unserialize($data);
    
    		$user = get_userdata($data['to']+$data['from']);
    
    		if($type=='donate_to'){ 
    
    			echo __('Donation to', 'cp') . ' "' . $user->user_login . '" (includes transaction fee)';
    
    		}
    
    		if($type=='donate_from'){ 
    
    			echo __('Donation from', 'cp') . ' "' . $user->user_login . '"';
    
    		}
    
    		if($data['message']!=''){
    
    			echo ' <a href="javascript:void(0);" onclick="jQuery.prompt(\'MESSAGE: '.htmlspecialchars($data['message']).'\')">[' . __('Message', 'cp') . ']</a>';
    
    		}
    
    	}
    
    }
    
    ?>
    Thread Starter Blindacme

    (@blindacme)

    Hey Lex, thanks so much for your willingness to help correct this problem.. Actually the only place this install is active is on the link above. I can give you login credintials for that if that is ok because it has yet to “go live”. Let me know if that would work and how I can PM you the details.

    Thanks again for the help and support!

    Thread Starter Blindacme

    (@blindacme)

    oh well it wont post the link but </a href=/"javascript:void(0);"/ onclick=/"cp_module_donate();"/>

    just remove the slashes

    Thread Starter Blindacme

    (@blindacme)

    Sweet! Thanks man, I did not see the widget but luckily I have an anchor button in my template and just replaced the anchor with this:<a href="void(0);">

    now all works perfectly!

    Thread Starter Blindacme

    (@blindacme)

    Ahh, thank you so much for replying.. Unfortunately that is not working for me.. I have put the shortcode on my page (in text mode) like this: [cp_donate] and when I view the page I just see the shortcode. I look and double check that the module is activated and it says it is. Could it be something else or am I missing something else?

    Thanks for your help.

    Thread Starter Blindacme

    (@blindacme)

    Just a standard page I guess, it is using a custom post type that came with the theme but no modifications have been made to it… Theme is Sopastore I believe..

    Thread Starter Blindacme

    (@blindacme)

    Any other suggestions? I would appreciate the help getting your plugin to work on my install. Thx

    Thread Starter Blindacme

    (@blindacme)

    Can anyone tell me how to display the donate module on front end? is it via shortcode or template files? Cant seem to find out where or how I use this, would appreciate any help.

    Thread Starter Blindacme

    (@blindacme)

    Anyone able to help with this? Their site seems to be down and Im not quite grasping how to do this yet.

    Thread Starter Blindacme

    (@blindacme)

    Thanks for the quick reply, that unfortunately did not do it.. The link is: http://secondtimedress.com/ and when I did comment that out it made the slider and thumbnail images stop working and not display..

    Gabriel, may I pick your brain for just one more thing? I was told I should use the em_booking_get_price filter similar to the one below.. I just dont know how I could easily incorporate this into the module so that I dont have to use custom fields but things are kind of automatic.

    I figured with your experience with cubepoints this could be an easy question for you to answer and I really, really appreciate all the help your giving as I start to understand things.

    Here is a sample filter –

    function my_em_booking_get_price($content){
                    $content .= "Hello!";
            return $content;
    }
    add_filter('em_booking_get_price','my_em_booking_get_price');

    Here is another example of the filter I found online just in case it helps –

    function my_em_booking_price($format = false, $EM_Booking){
     $discount = 1; //no discount
     if( $EM_Booking->booking_spaces > 2 ){
            $discount = 0.75; //25% discount
     }
     $price = $EM_Ticket->price * $discount;
     if($format){
            return em_get_currency_symbol().number_format($price,2);
     }
     return $price;
    }
    add_action('em_booking_get_price', 'my_em_booking_price', 10, 2);

    Thanks, I just noticed you were not the original developer, which makes you even more awesome for helping so many people out with this, but yes – their site has been down for awhile and I just got cubepoints and was not able to find anything on deducting points.

    Thanks for your help I will work with it and see if I get it working for my needs..

    BTW kudos on your site man, Looks great! love the design

    Hi Gabriel, you are a saint for going out of your way to provide the snippet above.

    I would like to modify your snippet above so that if someone says they are attending the event then they would be deducted the amount of points for attending an event (could vary)..

    Im stuck because it seems your website has been down and I have been continuously trying it for the past week, although I know what happened to it, I hope you get back online soon but with all of that being said I cant find anything anywhere on how to actually “spend” your points because it all takes me to your forum which is currently down.

    How can I set up the above to deduct points if a user decides to attend an event and where could I define the amount of points it costs for each event?

    I am fairly comfortable with PHP so any direction would be nice since I cant seem to get on your site to find out how the spending mechanism works.

    Thanks in advance

Viewing 15 replies - 1 through 15 (of 22 total)