コード例 #1
0
 function bl_frontend_form_submit_check($post)
 {
     if (isset($post['post_id']) && is_numeric($post['post_id']) && $post['post_id'] != 0) {
         $data = get_option("bepro_listings");
         //check if in-sufficient funds
         $uid = get_current_user_id();
         $current_points = cp_getPoints($uid);
         //if insufficient funds then abort listing save altogether
         if ($current_points == 0) {
             header("Location: " . get_bloginfo("url") . "/?p=" . $data["redirect_need_funds"]);
         }
         //update cubepoint records
         $new_points = $current_points - $data["charge_amount"];
         cp_updatePoints($uid, $new_points);
         cp_log("listing", $uid, -$data["charge_amount"], "Listing payment");
     }
 }
コード例 #2
0
ファイル: cp_api.php プロジェクト: adisonc/MaineLearning
function cp_api_do()
{
    if (get_option('cp_auth_key') != $_REQUEST['cp_api_key']) {
        $r['error'] = 'Invalid API key';
        return $r;
    }
    $s = $_REQUEST['cp_api'];
    $q = explode('/', $s);
    switch ($q[0]) {
        case 'user':
            switch ($q[1]) {
                case 'login':
                    $user = get_userdatabylogin($q[2]);
                    break;
                case 'id':
                    $user = get_userdata($q[2]);
                    break;
                default:
                    $r['error'] = 'Method not implemented';
                    return $r;
            }
            if ($user->ID == '') {
                $r['error'] = 'Invalid user';
                return $r;
            }
            switch ($q[3]) {
                case '':
                    $r = $user;
                    return $r;
                    break;
                case 'points':
                    switch ($q[4]) {
                        case '':
                            $r['points'] = cp_getPoints($user->ID);
                            return $r;
                            break;
                        case 'get':
                            $r['points'] = cp_getPoints($user->ID);
                            return $r;
                            break;
                        case 'set':
                            if (!is_numeric($q[5])) {
                                $r['error'] = 'Points must be integers';
                                return $r;
                            } else {
                                cp_updatePoints($user->ID, (int) $q[5]);
                                $r['points'] = cp_getPoints($user->ID);
                                $r['message'] = 'Points updated';
                                return $r;
                            }
                            break;
                        case 'add':
                            if (!is_numeric($q[5])) {
                                $r['error'] = 'Points must be integers';
                                return $r;
                            } else {
                                switch ($q[6]) {
                                    case '':
                                        cp_alterPoints($user->ID, $q[5]);
                                        $r['points'] = cp_getPoints($user->ID);
                                        $r['message'] = 'Points updated';
                                        return $r;
                                        break;
                                    case 'log':
                                        if ($q[7] == '') {
                                            $r['error'] = 'Log item type must not be empty';
                                            return $r;
                                        }
                                        $data = explode('/', $s, 9);
                                        cp_points($q[7], $user->ID, $q[5], $data[8]);
                                        $r['points'] = cp_getPoints($user->ID);
                                        $r['message'] = 'Points updated';
                                        return $r;
                                        break;
                                    default:
                                        $r['error'] = 'Method not implemented';
                                        return $r;
                                }
                            }
                            break;
                        default:
                            $r['error'] = 'Method not implemented';
                            return $r;
                    }
                    break;
                default:
                    $r['error'] = 'Method not implemented';
                    return $r;
            }
            break;
        default:
            $r['error'] = 'Method not implemented';
            return $r;
    }
}
コード例 #3
0
ファイル: cp_core.php プロジェクト: adisonc/MaineLearning
/** Set points and add to logs */
function cp_points_set($type, $uid, $points, $data)
{
    $points = apply_filters('cp_points_set', $points, $type, $uid, $data);
    $difference = $points - cp_getPoints($uid);
    cp_updatePoints($uid, $points);
    cp_log($type, $uid, $difference, $data);
}
コード例 #4
0
ファイル: backup.php プロジェクト: alphaomegahost/FIN
    function cp_modules_backup_admin()
    {
        // handles form submissions
        if ($_POST['cp_module_backup_down_form_submit'] == 'Y') {
            update_option('cp_module_backup_lastbackup', time());
            echo '<div class="updated"><p><strong>' . __('Your backup has been generated', 'cp') . '...</strong></p></div>';
            echo '<script type="text/javascript">jQuery(document).ready(function() { location.href="' . get_bloginfo('url') . '/wp-admin/admin-ajax.php?action=cp_module_backup_down&fmt=' . $_POST['cp_module_backup_down_form_format'] . '"; });</script>';
        }
        if ($_POST['cp_module_backup_up_form_submit'] == 'Y') {
            switch ($_FILES['cp_module_backup_up_form_upload']['error']) {
                case 0:
                    $handle = fopen($_FILES['cp_module_backup_up_form_upload']['tmp_name'], "r");
                    $data = fread($handle, filesize($_FILES['cp_module_backup_up_form_upload']['tmp_name']));
                    fclose($handle);
                    // try json
                    $json = json_decode($data);
                    if ($json != null) {
                        $data = $json;
                    } else {
                        // try csv
                        $lines = explode("\n", str_replace("\r", "", $data));
                        foreach ($lines as $n => $line) {
                            $csv[] = explode(",", $line);
                        }
                        $data = $csv;
                    }
                    $datap = array();
                    foreach ($data as $d) {
                        if (is_numeric($d[0]) && validate_username($d[1]) && is_email($d[2]) && is_numeric($d[3]) && $d[3] >= 0) {
                            $datap[] = array($d[0], $d[1], $d[2], $d[3]);
                        }
                    }
                    if (count($datap) > 0) {
                        // valid data
                        $users_matched = 0;
                        $users_updated = 0;
                        foreach ($datap as $d) {
                            switch ($_POST['cp_module_backup_up_form_match']) {
                                default:
                                case 'id':
                                    $u = get_user_by('id', $d[0]);
                                    break;
                                case 'login':
                                    $u = get_user_by('login', $d[1]);
                                    break;
                                case 'email':
                                    $u = get_user_by('email', $d[2]);
                                    break;
                            }
                            if ($u) {
                                $uid = $u->ID;
                                $curr_points = $u->cpoints;
                                if ((int) $curr_points != $d[3]) {
                                    cp_updatePoints($uid, $d[3]);
                                    $users_updated++;
                                }
                                $users_matched++;
                            }
                        }
                        echo '<div class="updated"><p><strong>' . __('The backup file has been restored!', 'cp') . '</strong>';
                        echo '<div style="font-size:11px;">';
                        $users = count_users();
                        echo '<strong>' . __('Backup file', 'cp') . ':</strong> ' . basename($_FILES['cp_module_backup_up_form_upload']['name']);
                        echo '<br /><strong>' . __('Total users in blog', 'cp') . ':</strong> ' . $users['total_users'];
                        echo '<br /><strong>' . __('Users in backup file', 'cp') . ':</strong> ' . count($datap);
                        echo '<br /><strong>' . __('Users matched', 'cp') . ':</strong> ' . $users_matched;
                        echo '<br /><strong>' . __('Users altered', 'cp') . ':</strong> ' . $users_updated;
                        echo '</div>';
                        echo '</p></div>';
                        update_option('cp_module_backup_lastrestore', time());
                    } else {
                        echo '<div class="error"><p><strong>' . __('The file you have uploaded is not a valid backup file', 'cp') . '...</strong></p></div>';
                    }
                    break;
                case 1:
                case 2:
                    echo '<div class="error"><p><strong>' . __('The file you uploaded exceeds the maximum file size allowed', 'cp') . '...</strong></p></div>';
                    break;
                case 4:
                    echo '<div class="error"><p><strong>' . __('Please select a file to restore', 'cp') . '...</strong></p></div>';
                    break;
                default:
                    echo '<div class="error"><p><strong>' . __('An error occured while uploading the backup file', 'cp') . '...</strong></p></div>';
                    break;
            }
        }
        ?>
	
	<div class="wrap">
		<h2>CubePoints - <?php 
        _e('Backup &amp; Restore', 'cp');
        ?>
</h2>
		

		<h3><?php 
        _e('Backup Points', 'cp');
        ?>
</h3>		

		<form name="cp_module_backup_down_form" method="post">
			<input type="hidden" name="cp_module_backup_down_form_submit" value="Y" />
			
			<table class="form-table">
				<tr valign="top">
					<th scope="row"><?php 
        _e('Last backup');
        ?>
:</label></th>
					<td valign="middle"><?php 
        echo get_option('cp_module_backup_lastbackup') == null ? '<i>(' . __('none', 'cp') . ')</i>' : date_i18n("j F Y, h:i A", get_option('cp_module_backup_lastbackup') + get_option('gmt_offset') * 3600);
        ?>
</td>
				</tr>
				<tr valign="top">
					<th scope="row"><?php 
        _e('Number of users');
        ?>
:</label></th>
					<td valign="middle"><?php 
        $users = count_users();
        echo $users['total_users'];
        ?>
</td>
				</tr>
				<tr valign="top">
					<th scope="row"><label for="cp_module_backup_down_form_format"><?php 
        _e('Format', 'cp');
        ?>
:</label></th>
					<td valign="middle">
						<select id="cp_module_backup_down_form_format" name="cp_module_backup_down_form_format" style="width:200px;">
							<option value="json"<?php 
        echo $_POST['cp_module_backup_down_form_format'] == 'json' ? ' selected' : '';
        ?>
>JSON</option>
							<option value="csv"<?php 
        echo $_POST['cp_module_backup_down_form_format'] == 'csv' ? ' selected' : '';
        ?>
>CSV</option>
						</select>
					</td>
				</tr>
			</table>

			<p class="submit">
				<input type="submit" name="Submit" value="<?php 
        _e('Download Backup', 'cp');
        ?>
 &raquo;" />
			</p>

		</form>

		<h3><?php 
        _e('Restore Backup', 'cp');
        ?>
</h3>		

		<form name="cp_module_backup_up_form" method="post" enctype="multipart/form-data">
			<input type="hidden" name="cp_module_backup_up_form_submit" value="Y" />
			<table class="form-table">
				<tr valign="top">
					<th scope="row"><?php 
        _e('Last restore');
        ?>
:</label></th>
					<td valign="middle"><?php 
        echo get_option('cp_module_backup_lastrestore') == null ? '<i>(' . __('none', 'cp') . ')</i>' : date_i18n("j F Y, h:i A", get_option('cp_module_backup_lastrestore') + get_option('gmt_offset') * 3600);
        ?>
</td>
				</tr>
				<tr valign="top">
					<th scope="row"><label for="cp_module_backup_up_form_upload"><?php 
        _e('Upload', 'cp');
        ?>
:</label></th>
					<td valign="middle">
						<input type="file" id="cp_module_backup_up_form_upload" name="cp_module_backup_up_form_upload" />
					</td>
				</tr>
				<tr valign="top">
					<th scope="row"><label for="cp_module_backup_up_form_match"><?php 
        _e('Match', 'cp');
        ?>
:</label></th>
					<td valign="middle">
						<select id="cp_module_backup_up_form_match" name="cp_module_backup_up_form_match" style="width:200px;">
							<option value="id"<?php 
        echo $_POST['cp_module_backup_up_form_match'] == 'id' ? ' selected' : '';
        ?>
><?php 
        _e('User ID', 'cp');
        ?>
</option>
							<option value="login"<?php 
        echo $_POST['cp_module_backup_up_form_match'] == 'login' ? ' selected' : '';
        ?>
><?php 
        _e('Username', 'cp');
        ?>
</option>
							<option value="email"<?php 
        echo $_POST['cp_module_backup_up_form_match'] == 'email' ? ' selected' : '';
        ?>
><?php 
        _e('Email Address', 'cp');
        ?>
</option>
						</select>
					</td>
				</tr>
			</table>

			<p class="submit">
				<input type="submit" name="Submit" value="<?php 
        _e('Restore from Backup', 'cp');
        ?>
 &raquo;" />
			</p>

		</form>
		
	</div>
	<?php 
    }