示例#1
0
 if (!empty($_POST['app_attach_id'])) {
     $postvals['app_attach_id'] = $_POST['app_attach_id'];
 }
 if (!empty($_POST['app_attach_title'])) {
     $postvals['app_attach_title'] = $_POST['app_attach_title'];
 }
 // put all the posted form values into an array
 foreach ($_POST as $key => $value) {
     if (!is_array($_POST[$key])) {
         $postvals[$key] = appthemes_clean($value);
     } else {
         $postvals[$key] = array_map('appthemes_clean', $value);
     }
 }
 // keep only numeric, commas or decimal values
 $postvals['cp_price'] = empty($_POST['cp_price']) ? '' : appthemes_clean_price($_POST['cp_price']);
 if (isset($postvals['cp_currency']) && !empty($postvals['cp_currency'])) {
     $price_curr = $postvals['cp_currency'];
 } else {
     $price_curr = $cp_options->curr_symbol;
 }
 // keep only values and insert/strip commas if needed
 if (!empty($_POST['tags_input'])) {
     $postvals['tags_input'] = appthemes_clean_tags($_POST['tags_input']);
     $_POST['tags_input'] = $postvals['tags_input'];
 }
 // store the user IP address, ID for later
 $postvals['cp_sys_userIP'] = appthemes_get_ip();
 $postvals['user_id'] = $current_user->ID;
 $ad_pack_id = isset($_POST['ad_pack_id']) ? appthemes_numbers_only($_POST['ad_pack_id']) : false;
 if ($ad_pack_id) {
function cp_update_listing()
{
    global $wpdb, $cp_options;
    // check to see if html is allowed
    if (!$cp_options->allow_html) {
        $post_content = appthemes_filter($_POST['post_content']);
    } else {
        $post_content = wp_kses_post($_POST['post_content']);
    }
    // keep only numeric, commas or decimal values
    if (!empty($_POST['cp_price'])) {
        $_POST['cp_price'] = appthemes_clean_price($_POST['cp_price']);
    }
    // keep only values and insert/strip commas if needed and put into an array
    if (!empty($_POST['tags_input'])) {
        $_POST['tags_input'] = appthemes_clean_tags($_POST['tags_input']);
        $new_tags = explode(',', $_POST['tags_input']);
    }
    // put all the ad elements into an array
    // these are the minimum required fields for WP (except tags)
    $update_ad = array();
    $update_ad['ID'] = trim($_POST['ad_id']);
    $update_ad['post_title'] = appthemes_filter($_POST['post_title']);
    $update_ad['post_content'] = trim($post_content);
    if ($cp_options->moderate_edited_ads) {
        $update_ad['post_status'] = 'pending';
    }
    // update the ad and return the ad id
    $post_id = wp_update_post($update_ad);
    if (!$post_id) {
        return false;
    }
    //update post custom taxonomy "ad_tags"
    // keep only values and insert/strip commas if needed and put into an array
    if (!empty($_POST['tags_input'])) {
        $_POST['tags_input'] = appthemes_clean_tags($_POST['tags_input']);
        $new_tags = explode(',', $_POST['tags_input']);
        $settags = wp_set_object_terms($post_id, $new_tags, APP_TAX_TAG);
    }
    // assemble the comma separated hidden fields back into an array so we can save them.
    $metafields = explode(',', $_POST['custom_fields_vals']);
    // loop through all custom meta fields and update values
    foreach ($metafields as $name) {
        if (!isset($_POST[$name])) {
            delete_post_meta($post_id, $name);
        } else {
            if (is_array($_POST[$name])) {
                delete_post_meta($post_id, $name);
                foreach ($_POST[$name] as $checkbox_value) {
                    add_post_meta($post_id, $name, wp_kses_post($checkbox_value));
                }
            } else {
                update_post_meta($post_id, $name, wp_kses_post($_POST[$name]));
            }
        }
    }
    cp_action_update_listing($post_id);
    return $post_id;
}
function cp_ad_listing_fee($catid, $ad_pack_id, $cp_price, $price_curr)
{
    global $wpdb;
    // make sure we are charging for ads
    if (get_option('cp_charge_ads') == 'yes') {
        // now figure out which pricing scheme is set
        switch (get_option('cp_price_scheme')) {
            case 'category':
                // then lookup the price for this catid
                $cat_price = get_option('cp_cat_price_' . $catid);
                // 0
                // if cat price is blank then assign it default price
                if (isset($cat_price)) {
                    $adlistingfee = $cat_price;
                } else {
                    // set the price to the default ad value
                    $adlistingfee = get_option('cp_price_per_ad');
                }
                break;
            case 'percentage':
                // grab the % and then put it into a workable number
                $ad_percentage = get_option('cp_percent_per_ad') * 0.01;
                // calculate the ad cost. Ad listing price x percentage.
                $adlistingfee = appthemes_clean_price($cp_price, 'float') * trim($ad_percentage);
                // can modify listing fee. example: apply currency conversion
                $adlistingfee = apply_filters('cp_percentage_listing_fee', $adlistingfee, $cp_price, $ad_percentage, $price_curr);
                break;
            case 'featured':
                // listing price is always free in this pricing schema
                $adlistingfee = 0;
                break;
            default:
                // pricing model must be single ad packs
                // make sure we have something if ad_pack_id is empty so no db error
                if (empty($ad_pack_id)) {
                    $ad_pack_id = 1;
                }
                // go get all the active ad packs and create a drop-down of options
                $sql = "SELECT pack_price, pack_duration " . "FROM {$wpdb->cp_ad_packs} " . "WHERE pack_id = '{$ad_pack_id}' " . "LIMIT 1";
                $results = $wpdb->get_row($sql);
                // now return the price and put the duration variable into an array
                if ($results) {
                    $adlistingfee = $results->pack_price;
                    // $postvals['pack_duration'] = $results->pack_duration;
                } else {
                    sprintf(__('ERROR: no ad packs found for ID %s.', 'appthemes'), $ad_pack_id);
                }
                // then cost per ad must be set to a flat fee
                //$adlistingfee = get_option('cp_price_per_ad');
        }
    }
    // return the ad listing fee
    return $adlistingfee;
}
示例#4
0
function cp_update_listing()
{
    global $wpdb;
    // check to see if html is allowed
    if (get_option('cp_allow_html') != 'yes') {
        $post_content = appthemes_filter($_POST['post_content']);
    } else {
        $post_content = $_POST['post_content'];
    }
    // keep only numeric, commas or decimal values
    if (!empty($_POST['cp_price'])) {
        $_POST['cp_price'] = appthemes_clean_price($_POST['cp_price']);
    }
    // keep only values and insert/strip commas if needed and put into an array
    if (!empty($_POST['tags_input'])) {
        $_POST['tags_input'] = appthemes_clean_tags($_POST['tags_input']);
        $new_tags = explode(',', $_POST['tags_input']);
    }
    // put all the ad elements into an array
    // these are the minimum required fields for WP (except tags)
    $update_ad = array();
    $update_ad['ID'] = trim($_POST['ad_id']);
    $update_ad['post_title'] = appthemes_filter($_POST['post_title']);
    $update_ad['post_content'] = trim($post_content);
    //$update_ad['post_category']   = array((int)appthemes_filter($_POST['cat'])); // maybe use later if we decide to let users change categories
    //print_r($update_ad).' <- new ad array<br>'; // for debugging
    // update the ad and return the ad id
    $post_id = wp_update_post($update_ad);
    if ($post_id) {
        //update post custom taxonomy "ad_tags"
        // keep only values and insert/strip commas if needed and put into an array
        if (!empty($_POST['tags_input'])) {
            $_POST['tags_input'] = appthemes_clean_tags($_POST['tags_input']);
            $new_tags = explode(',', $_POST['tags_input']);
            $settags = wp_set_object_terms($post_id, $new_tags, APP_TAX_TAG);
            //echo 'Update Tags or Erro:'.print_r($settags, true);
        }
        // assemble the comma separated hidden fields back into an array so we can save them.
        $metafields = explode(',', $_POST['custom_fields_vals']);
        // loop through all custom meta fields and update values
        foreach ($metafields as $name) {
            if (!isset($_POST[$name])) {
                delete_post_meta($post_id, $name);
            } else {
                if (is_array($_POST[$name])) {
                    delete_post_meta($post_id, $name);
                    foreach ($_POST[$name] as $checkbox_value) {
                        add_post_meta($post_id, $name, $checkbox_value);
                    }
                } else {
                    update_post_meta($post_id, $name, $_POST[$name]);
                }
            }
        }
        $result = $post_id;
        cp_action_update_listing($post_id);
    } else {
        // the ad wasn't updated
        $result = false;
    }
    return $result;
}
示例#5
0
文件: step2.php 项目: kalushta/darom
     $postvals['app_attach_id'] = $_POST['app_attach_id'];
 }
 if (!empty($_POST['app_attach_title'])) {
     $postvals['app_attach_title'] = $_POST['app_attach_title'];
 }
 // put all the posted form values into an array
 foreach ($_POST as $key => $value) {
     if (!is_array($_POST[$key])) {
         $postvals[$key] = appthemes_clean($value);
     } else {
         $postvals[$key] = $value;
     }
 }
 // keep only numeric, commas or decimal values
 if (!empty($_POST['cp_price'])) {
     $postvals['cp_price'] = appthemes_clean_price($_POST['cp_price']);
     $_POST['cp_price'] = $postvals['cp_price'];
 }
 if (isset($postvals['cp_currency']) && !empty($postvals['cp_currency'])) {
     $price_curr = $postvals['cp_currency'];
 } else {
     $price_curr = get_option('cp_curr_symbol');
 }
 // keep only values and insert/strip commas if needed
 if (!empty($_POST['tags_input'])) {
     $postvals['tags_input'] = appthemes_clean_tags($_POST['tags_input']);
     $_POST['tags_input'] = $postvals['tags_input'];
 }
 // store the user IP address, ID for later
 $postvals['cp_sys_userIP'] = appthemes_get_ip();
 $postvals['user_id'] = $current_user->ID;
示例#6
0
function cp_ad_packs()
{
    global $app_abbr, $wpdb, $current_user, $options_new_ad_pack, $options_new_membership_pack;
    $current_user = wp_get_current_user();
    $theswitch = isset($_GET['action']) ? $_GET['action'] : '';
    ?>

	<script type="text/javascript">
	/* <![CDATA[ */
		/* initialize the form validation */
		jQuery(document).ready(function($) {
			$("#mainform").validate({errorClass: "invalid"});
		});
	/* ]]> */
	</script>

	<?php 
    $options_new_pack = isset($_GET['type']) && $_GET['type'] == 'membership' ? $options_new_membership_pack : $options_new_ad_pack;
    switch ($theswitch) {
        case 'addpack':
            ?>

			<div class="wrap">
				<div class="icon32" id="icon-themes"><br /></div>
				<h2><?php 
            if ($_GET['type'] == 'membership') {
                _e('New Membership Pack', APP_TD);
            } else {
                _e('New Ad Pack', APP_TD);
            }
            ?>
</h2>

				<?php 
            cp_admin_info_box();
            ?>

				<?php 
            // check and make sure the form was submitted
            if (isset($_POST['submitted'])) {
                //setup optional variables for the package
                $post_pack_satisfies_required = isset($_POST['pack_satisfies_required']) ? $_POST['pack_satisfies_required'] : '';
                $post_pack_type = isset($_POST['pack_type']) ? $post_pack_satisfies_required . $_POST['pack_type'] : '';
                $post_pack_membership_price = isset($_POST['pack_membership_price']) ? $_POST['pack_membership_price'] : 0;
                $data = array('pack_name' => appthemes_clean($_POST['pack_name']), 'pack_desc' => appthemes_clean($_POST['pack_desc']), 'pack_price' => appthemes_clean_price($_POST['pack_price'], 'float'), 'pack_duration' => appthemes_clean($_POST['pack_duration']), 'pack_status' => appthemes_clean($_POST['pack_status']), 'pack_type' => appthemes_clean($post_pack_type), 'pack_membership_price' => appthemes_clean_price($post_pack_membership_price, 'float'), 'pack_owner' => appthemes_clean($_POST['pack_owner']), 'pack_modified' => gmdate('Y-m-d H:i:s'));
                $insert = $wpdb->insert($wpdb->cp_ad_packs, $data);
                if ($insert) {
                    ?>

						<p style="text-align:center;padding-top:50px;font-size:22px;"><?php 
                    _e('Creating your ad package.....', APP_TD);
                    ?>
<br /><br /><img src="<?php 
                    bloginfo('template_directory');
                    ?>
/images/loader.gif" alt="" /></p>
						<meta http-equiv="refresh" content="0; URL=?page=packages">

					<?php 
                }
            } else {
                ?>

					<form method="post" id="mainform" action="">

						<?php 
                cp_admin_fields($options_new_pack);
                ?>

						<p class="submit">
							<input class="btn button-primary" name="save" type="submit" value="<?php 
                _e('Create New Ad Package', APP_TD);
                ?>
" />&nbsp;&nbsp;&nbsp;
							<input name="cancel" type="button" onClick="location.href='?page=packages'" value="<?php 
                _e('Cancel', APP_TD);
                ?>
" />
							<input name="submitted" type="hidden" value="yes" />
							<input name="pack_owner" type="hidden" value="<?php 
                echo $current_user->user_login;
                ?>
" />
						</p>

					</form>

				<?php 
            }
            ?>

			</div><!-- end wrap -->

		<?php 
            break;
        case 'editpack':
            ?>

			<div class="wrap">
				<div class="icon32" id="icon-themes"><br /></div>
				<h2><?php 
            _e('Edit Ad Package', APP_TD);
            ?>
</h2>

				<?php 
            cp_admin_info_box();
            ?>

				<?php 
            if (isset($_POST['submitted']) && $_POST['submitted'] == 'yes') {
                //setup optional variables for the package
                $post_pack_satisfies_required = isset($_POST['pack_satisfies_required']) ? $_POST['pack_satisfies_required'] : '';
                $post_pack_type = isset($_POST['pack_type']) ? $post_pack_satisfies_required . $_POST['pack_type'] : '';
                $post_pack_membership_price = isset($_POST['pack_membership_price']) ? $_POST['pack_membership_price'] : 0;
                $data = array('pack_name' => appthemes_clean($_POST['pack_name']), 'pack_desc' => appthemes_clean($_POST['pack_desc']), 'pack_price' => appthemes_clean_price($_POST['pack_price'], 'float'), 'pack_duration' => appthemes_clean($_POST['pack_duration']), 'pack_status' => appthemes_clean($_POST['pack_status']), 'pack_type' => appthemes_clean($post_pack_type), 'pack_membership_price' => appthemes_clean_price($post_pack_membership_price, 'float'), 'pack_owner' => appthemes_clean($_POST['pack_owner']), 'pack_modified' => gmdate('Y-m-d H:i:s'));
                $update = $wpdb->update($wpdb->cp_ad_packs, $data, array('pack_id' => $_GET['id']));
                ?>

						<p style="text-align:center;padding-top:50px;font-size:22px;"><?php 
                _e('Saving your changes.....', APP_TD);
                ?>
<br /><br /><img src="<?php 
                bloginfo('template_directory');
                ?>
/images/loader.gif" alt="" /></p>
						<meta http-equiv="refresh" content="0; URL=?page=packages">

				<?php 
            } else {
                ?>

					<form method="post" id="mainform" action="">

						<?php 
                cp_admin_db_fields($options_new_pack, 'cp_ad_packs', 'pack_id');
                ?>

						<p class="submit">
							<input class="btn button-primary" name="save" type="submit" value="<?php 
                _e('Save changes', APP_TD);
                ?>
" />&nbsp;&nbsp;&nbsp;
							<input name="cancel" type="button" onClick="location.href='?page=packages'" value="<?php 
                _e('Cancel', APP_TD);
                ?>
" />
							<input name="submitted" type="hidden" value="yes" />
							<input name="pack_owner" type="hidden" value="<?php 
                echo $current_user->user_login;
                ?>
" />
						</p>

					</form>

				<?php 
            }
            ?>

			</div><!-- end wrap -->

		<?php 
            break;
        case 'delete':
            $delete = $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->cp_ad_packs} WHERE pack_id = %d", $_GET['id']));
            ?>

				<p style="text-align:center;padding-top:50px;font-size:22px;"><?php 
            _e('Deleting ad package.....', APP_TD);
            ?>
<br /><br /><img src="<?php 
            bloginfo('template_directory');
            ?>
/images/loader.gif" alt="" /></p>
				<meta http-equiv="refresh" content="0; URL=?page=packages">

		<?php 
            break;
        default:
            $results = $wpdb->get_results("SELECT * FROM {$wpdb->cp_ad_packs} ORDER BY pack_id desc");
            ?>

			<div class="wrap">
				<div class="icon32" id="icon-themes"><br /></div>
				<h2><?php 
            _e('Ad Packs', APP_TD);
            ?>
&nbsp;<a class="button add-new-h2" href="?page=packages&amp;action=addpack&amp;type=ad"><?php 
            _e('Add New', APP_TD);
            ?>
</a></h2>

				<?php 
            cp_admin_info_box();
            ?>

				<?php 
            if (get_option($app_abbr . '_price_scheme') != 'single') {
                ?>
					<div class="error"><p><?php 
                printf(__('Ad Packs are disabled. Change the <a href="%1$s">pricing model</a> to enable Ad Packs.', APP_TD), 'admin.php?page=pricing#tab1');
                ?>
</p></div>
				<?php 
            }
            ?>

				<p class="admin-msg"><?php 
            _e('Ad Packs allow you to create bundled listing options for your customers to choose from. For example, instead of only offering a set price for xx days (30 days for $5), you could also offer discounts for longer terms (60 days for $7). These only work if you are selling ads and using the "Fixed Price Per Ad" price model.', APP_TD);
            ?>
</p>

				<table id="tblspacer" class="widefat fixed">

					<thead>
						<tr>
							<th scope="col" style="width:35px;">&nbsp;</th>
							<th scope="col"><?php 
            _e('Name', APP_TD);
            ?>
</th>
							<th scope="col"><?php 
            _e('Description', APP_TD);
            ?>
</th>
							<th scope="col"><?php 
            _e('Price Per Ad', APP_TD);
            ?>
</th>
							<th scope="col"><?php 
            _e('Duration', APP_TD);
            ?>
</th>
							<th scope="col" style="width:150px;"><?php 
            _e('Modified', APP_TD);
            ?>
</th>
							<th scope="col" style="width:75px;"><?php 
            _e('Status', APP_TD);
            ?>
</th>
							<th scope="col" style="text-align:center;width:100px;"><?php 
            _e('Actions', APP_TD);
            ?>
</th>
							</tr>
						</thead>

						<?php 
            if ($results) {
                $rowclass = '';
                $i = 1;
                ?>

							<tbody id="list">

								<?php 
                foreach ($results as $result) {
                    if ($result->pack_status == 'active' || $result->pack_status == 'inactive') {
                        $rowclass = 'even' == $rowclass ? 'alt' : 'even';
                        ?>

										<tr class="<?php 
                        echo $rowclass;
                        ?>
">
											<td style="padding-left:10px;"><?php 
                        echo $i++;
                        ?>
.</td>
											<td><a href="?page=packages&amp;action=editpack&amp;type=ad&amp;id=<?php 
                        echo $result->pack_id;
                        ?>
"><strong><?php 
                        echo stripslashes($result->pack_name);
                        ?>
</strong></a></td>
											<td><?php 
                        echo $result->pack_desc;
                        ?>
</td>
											<td><?php 
                        cp_display_price($result->pack_price);
                        ?>
</td>
											<td><?php 
                        echo $result->pack_duration;
                        ?>
&nbsp;<?php 
                        _e('days', APP_TD);
                        ?>
</td>
											<td><?php 
                        echo mysql2date(get_option('date_format') . ' ' . get_option('time_format'), $result->pack_modified);
                        ?>
 <?php 
                        _e('by', APP_TD);
                        ?>
 <?php 
                        echo $result->pack_owner;
                        ?>
</td>
											<td><?php 
                        echo cp_get_status_i18n($result->pack_status);
                        ?>
</td>
											<td style="text-align:center">
												<a href="?page=packages&amp;action=editpack&amp;type=ad&amp;id=<?php 
                        echo $result->pack_id;
                        ?>
"><img src="<?php 
                        bloginfo('template_directory');
                        ?>
/images/edit.png" alt="<?php 
                        _e('Edit ad package', APP_TD);
                        ?>
" title="<?php 
                        _e('Edit ad package', APP_TD);
                        ?>
" /></a>&nbsp;&nbsp;&nbsp;
												<a onclick="return confirmBeforeDelete();" href="?page=packages&amp;action=delete&amp;id=<?php 
                        echo $result->pack_id;
                        ?>
"><img src="<?php 
                        bloginfo('template_directory');
                        ?>
/images/cross.png" alt="<?php 
                        _e('Delete ad package', APP_TD);
                        ?>
" title="<?php 
                        _e('Delete ad package', APP_TD);
                        ?>
" /></a>
											</td>
										</tr>

								<?php 
                    }
                    //end if('active' || 'inactive')
                }
                // end foreach
                unset($i);
                ?>

							</tbody>

						<?php 
            } else {
                ?>

							<tr>
								<td colspan="7"><?php 
                _e('No ad packs found.', APP_TD);
                ?>
</td>
							</tr>

						<?php 
            }
            // end $results
            ?>

				</table>


			</div><!-- end wrap for ad packs -->

			<div id="membership-packs" class="wrap">
				<div class="icon32" id="icon-themes"><br /></div>
				<h2><?php 
            _e('Membership Packs', APP_TD);
            ?>
&nbsp;<a class="button add-new-h2" href="?page=packages&amp;action=addpack&amp;type=membership"><?php 
            _e('Add New', APP_TD);
            ?>
</a></h2>

				<?php 
            cp_admin_info_box();
            ?>

				<p class="admin-msg"><?php 
            printf(__('Membership Packs allow you to setup subscription-based pricing packages. This enables your customers to post unlimited ads for a set period of time or until the membership becomes inactive. These memberships affect pricing regardless of the ad packs or pricing model you have set as long as you have the <a href="%1$s">enable membership packs</a> option set to yes.', APP_TD), 'admin.php?page=pricing#tab2');
            ?>
</p>

				<table id="tblspacer" class="widefat fixed">

					<thead>
						<tr>
							<th scope="col" style="width:35px;">&nbsp;</th>
							<th scope="col"><?php 
            _e('Name', APP_TD);
            ?>
</th>
							<th scope="col"><?php 
            _e('Description', APP_TD);
            ?>
</th>
							<th scope="col"><?php 
            _e('Price Modifier', APP_TD);
            ?>
</th>
							<th scope="col"><?php 
            _e('Terms', APP_TD);
            ?>
</th>
							<th scope="col" style="width:150px;"><?php 
            _e('Modified', APP_TD);
            ?>
</th>
							<th scope="col" style="width:75px;"><?php 
            _e('Status', APP_TD);
            ?>
</th>
							<th scope="col" style="text-align:center;width:100px;"><?php 
            _e('Actions', APP_TD);
            ?>
</th>
						</tr>
					</thead>

					<?php 
            if ($results) {
                $rowclass = '';
                $i = 1;
                ?>

						<tbody id="list">

							<?php 
                foreach ($results as $result) {
                    if ($result->pack_status == 'active_membership' || $result->pack_status == 'inactive_membership') {
                        $rowclass = 'even' == $rowclass ? 'alt' : 'even';
                        ?>

									<tr class="<?php 
                        echo $rowclass;
                        ?>
">
										<td style="padding-left:10px;"><?php 
                        echo $i++;
                        ?>
.</td>
										<td><a href="?page=packages&amp;action=editpack&amp;type=membership&amp;id=<?php 
                        echo $result->pack_id;
                        ?>
"><strong><?php 
                        echo stripslashes($result->pack_name);
                        ?>
</strong></a></td>
										<td><?php 
                        echo $result->pack_desc;
                        ?>
</td>
										<td>
						<?php 
                        switch ($result->pack_type) {
                            case 'percentage':
                                echo preg_replace('/.00$/', '', $result->pack_price) . '% ' . __('of price', APP_TD);
                                //remove decimal when decimal is .00
                                break;
                            case 'discount':
                                printf(__('%s\'s less per ad', APP_TD), cp_display_price($result->pack_price, '', false));
                                break;
                            case 'required_static':
                                if ((double) $result->pack_price == 0) {
                                    _e('Free', APP_TD);
                                } else {
                                    printf(__('%s per ad', APP_TD), cp_display_price($result->pack_price, '', false));
                                }
                                echo ' (' . __('required to post', APP_TD) . ')';
                                break;
                            case 'required_discount':
                                printf(__('%s\'s less per ad', APP_TD), cp_display_price($result->pack_price, '', false));
                                echo ' (' . __('required to post', APP_TD) . ')';
                                break;
                            case 'required_percentage':
                                echo preg_replace('/.00$/', '', $result->pack_price) . '% ' . __('of price', APP_TD);
                                //remove decimal when decimal is .00
                                echo ' (' . __('required to post', APP_TD) . ')';
                                break;
                            default:
                                //likely 'static'
                                if ((double) $result->pack_price == 0) {
                                    _e('Free', APP_TD);
                                } else {
                                    printf(__('%s per ad', APP_TD), cp_display_price($result->pack_price, '', false));
                                }
                        }
                        ?>
										</td>
										<td><?php 
                        printf(__('%s / %s days', APP_TD), cp_display_price($result->pack_membership_price, '', false), $result->pack_duration);
                        ?>
</td>
										<td><?php 
                        echo mysql2date(get_option('date_format') . ' ' . get_option('time_format'), $result->pack_modified);
                        ?>
 <?php 
                        _e('by', APP_TD);
                        ?>
 <?php 
                        echo $result->pack_owner;
                        ?>
</td>
										<td><?php 
                        echo cp_get_status_i18n($result->pack_status);
                        ?>
</td>
										<td style="text-align:center">
											<a href="?page=packages&amp;action=editpack&amp;type=membership&amp;id=<?php 
                        echo $result->pack_id;
                        ?>
"><img src="<?php 
                        bloginfo('template_directory');
                        ?>
/images/edit.png" alt="<?php 
                        _e('Edit ad package', APP_TD);
                        ?>
" title="<?php 
                        _e('Edit ad package', APP_TD);
                        ?>
" /></a>&nbsp;&nbsp;&nbsp;
											<a onclick="return confirmBeforeDelete();" href="?page=packages&amp;action=delete&amp;id=<?php 
                        echo $result->pack_id;
                        ?>
"><img src="<?php 
                        bloginfo('template_directory');
                        ?>
/images/cross.png" alt="<?php 
                        _e('Delete ad package', APP_TD);
                        ?>
" title="<?php 
                        _e('Delete ad package', APP_TD);
                        ?>
" /></a>
										</td>
									</tr>

								<?php 
                    }
                    //end if('active_membership' || 'inactive_membership')
                }
                // end foreach
                unset($i);
                ?>

						</tbody>

					<?php 
            } else {
                ?>

						<tr>
							<td colspan="7"><?php 
                _e('No ad packs found.', APP_TD);
                ?>
</td>
						</tr>

					<?php 
            }
            // end $results
            ?>

				</table>


			</div><!-- end wrap for membership packs-->

	<?php 
    }
    // end switch
    ?>
	<script type="text/javascript">
	/* <![CDATA[ */
		function confirmBeforeDelete() { return confirm("<?php 
    _e('Are you sure you want to delete this ad package?', APP_TD);
    ?>
"); }
	/* ]]> */
	</script>

<?php 
}
function cp_ad_listing_fee($cat_id, $ad_pack_id, $cp_price, $price_curr)
{
    global $wpdb, $cp_options;
    // make sure we are charging for ads
    if (!cp_payments_is_enabled()) {
        return 0;
    }
    // now figure out which pricing scheme is set
    switch ($cp_options->price_scheme) {
        case 'category':
            $prices = $cp_options->price_per_cat;
            $adlistingfee = isset($prices[$cat_id]) ? (double) $prices[$cat_id] : 0;
            break;
        case 'percentage':
            // grab the % and then put it into a workable number
            $ad_percentage = $cp_options->percent_per_ad * 0.01;
            // calculate the ad cost. Ad listing price x percentage.
            $adlistingfee = appthemes_clean_price($cp_price, 'float') * $ad_percentage;
            // can modify listing fee. example: apply currency conversion
            $adlistingfee = apply_filters('cp_percentage_listing_fee', $adlistingfee, $cp_price, $ad_percentage, $price_curr);
            break;
        case 'featured':
            // listing price is always free in this pricing schema
            $adlistingfee = 0;
            break;
        default:
            // pricing model must be single ad packs
            // make sure we have something if ad_pack_id is empty so no db error
            if (empty($ad_pack_id)) {
                $ad_pack_id = 1;
            }
            // go get all the active ad packs and create a drop-down of options
            $sql = $wpdb->prepare("SELECT pack_price, pack_duration FROM {$wpdb->cp_ad_packs} WHERE pack_id = %d LIMIT 1", $ad_pack_id);
            $results = $wpdb->get_row($sql);
            // now return the price and put the duration variable into an array
            if ($results) {
                $adlistingfee = $results->pack_price;
            } else {
                sprintf(__('ERROR: no ad packs found for ID %s.', APP_TD), $ad_pack_id);
            }
            break;
    }
    // return the ad listing fee
    return $adlistingfee;
}
示例#8
0
function cp_update_listing()
{
    global $wpdb;
    // check to see if html is allowed
    if (get_option('cp_allow_html') != 'yes') {
        $post_content = appthemes_filter($_POST['post_content']);
    } else {
        $post_content = $_POST['post_content'];
    }
    // keep only numeric, commas or decimal values
    if (!empty($_POST['cp_price'])) {
        $_POST['cp_price'] = appthemes_clean_price($_POST['cp_price']);
    }
    // keep only values and insert/strip commas if needed and put into an array
    if (!empty($_POST['tags_input'])) {
        $_POST['tags_input'] = appthemes_clean_tags($_POST['tags_input']);
        $new_tags = explode(',', $_POST['tags_input']);
    }
    // put all the ad elements into an array
    // these are the minimum required fields for WP (except tags)
    $update_ad = array();
    $update_ad['ID'] = trim($_POST['ad_id']);
    $update_ad['post_title'] = appthemes_filter($_POST['post_title']);
    $update_ad['post_content'] = trim($post_content);
    //$update_ad['post_category']   = array((int)appthemes_filter($_POST['cat'])); // maybe use later if we decide to let users change categories
    // make sure the WP sanitize_post function doesn't strip out embed & other html
    if (get_option('cp_allow_html') == 'yes') {
        $update_ad['filter'] = true;
    }
    //print_r($update_ad).' <- new ad array<br>'; // for debugging
    // update the ad and return the ad id
    $post_id = wp_update_post($update_ad);
    if ($post_id) {
        //update post custom taxonomy "ad_tags"
        // keep only values and insert/strip commas if needed and put into an array
        if (!empty($_POST['tags_input'])) {
            $_POST['tags_input'] = appthemes_clean_tags($_POST['tags_input']);
            $new_tags = explode(',', $_POST['tags_input']);
            $settags = wp_set_object_terms($post_id, $new_tags, APP_TAX_TAG);
            //echo 'Update Tags or Erro:'.print_r($settags, true);
        }
        // assemble the comma separated hidden fields back into an array so we can save them.
        $metafields = explode(',', $_POST['custom_fields_vals']);
        // loop through all custom meta fields and update values
        foreach ($metafields as $name) {
            if (!isset($_POST[$name])) {
                delete_post_meta($post_id, $name);
            } else {
                if (is_array($_POST[$name])) {
                    delete_post_meta($post_id, $name);
                    foreach ($_POST[$name] as $checkbox_value) {
                        add_post_meta($post_id, $name, $checkbox_value);
                    }
                } else {
                    update_post_meta($post_id, $name, $_POST[$name]);
                }
            }
        }
        $errmsg = '<div class="box-yellow"><b>' . __('Your ad has been successfully updated.', 'appthemes') . '</b> <a href="' . CP_DASHBOARD_URL . '">' . __('Return to my dashboard', 'appthemes') . '</a></div>';
        // send out the email notifications
        cp_edited_ad_email($post_id);
    } else {
        // the ad wasn't updated so throw an error
        $errmsg = '<div class="box-red"><b>' . __('There was an error trying to update your ad.', 'appthemes') . '</b></div>';
    }
    return $errmsg;
}
示例#9
0
/**
 * Calculates the ad listing fee.
 *
 * @param int $category_id
 * @param int $package_id
 * @param float $cp_price
 * @param string $price_curr
 *
 * @return float
 */
function cp_ad_listing_fee($category_id, $package_id, $cp_price, $price_curr)
{
    global $cp_options;
    // make sure we are charging for ads
    if (!cp_payments_is_enabled()) {
        return 0;
    }
    // now figure out which pricing scheme is set
    switch ($cp_options->price_scheme) {
        case 'category':
            $prices = $cp_options->price_per_cat;
            $adlistingfee = isset($prices[$category_id]) ? (double) $prices[$category_id] : 0;
            break;
        case 'percentage':
            // grab the % and then put it into a workable number
            $ad_percentage = $cp_options->percent_per_ad * 0.01;
            // calculate the ad cost. Ad listing price x percentage.
            $adlistingfee = appthemes_clean_price($cp_price, 'float') * $ad_percentage;
            // can modify listing fee. example: apply currency conversion
            $adlistingfee = apply_filters('cp_percentage_listing_fee', $adlistingfee, $cp_price, $ad_percentage, $price_curr);
            break;
        case 'featured':
            // listing price is always free in this pricing schema
            $adlistingfee = 0;
            break;
        case 'single':
        default:
            // pricing model must be single ad packs
            $listing_package = cp_get_listing_package($package_id);
            if ($listing_package) {
                $adlistingfee = $listing_package->price;
            } else {
                $adlistingfee = 0;
                //sprintf( __( 'ERROR: no ad packs found for ID %s.', APP_TD ), $package_id );
            }
            break;
    }
    // return the ad listing fee
    return $adlistingfee;
}
示例#10
0
 /**
  * Returns cleaned fields that we expect.
  *
  * return array
  */
 protected function clean_expected_fields()
 {
     global $cp_options;
     $posted = array();
     foreach ($this->expected_fields() as $field) {
         $posted[$field] = isset($_POST[$field]) ? $_POST[$field] : '';
         if (!is_array($posted[$field])) {
             $posted[$field] = appthemes_clean($posted[$field]);
             if (appthemes_str_starts_with($field, 'cp_')) {
                 $posted[$field] = wp_kses_post($posted[$field]);
             }
         } else {
             $posted[$field] = array_map('appthemes_clean', $posted[$field]);
             if (appthemes_str_starts_with($field, 'cp_')) {
                 $posted[$field] = array_map('wp_kses_post', $posted[$field]);
             }
         }
         if ($field == 'cp_price') {
             $posted[$field] = appthemes_clean_price($posted[$field]);
         }
         if ($field == 'tags_input') {
             $posted[$field] = appthemes_clean_tags($posted[$field]);
             $posted[$field] = wp_kses_post($posted[$field]);
         }
         if ($field == 'post_content') {
             // check to see if html is allowed
             if (!$cp_options->allow_html) {
                 $posted[$field] = appthemes_filter($posted[$field]);
             } else {
                 $posted[$field] = wp_kses_post($posted[$field]);
             }
         }
         if ($field == 'post_title') {
             $posted[$field] = appthemes_filter($posted[$field]);
         }
     }
     return $posted;
 }