function awpcp_listing_upload_limits() { if (!isset($GLOBALS['awpcp-listing-upload-limits'])) { $GLOBALS['awpcp-listing-upload-limits'] = new AWPCP_ListingUploadLimits(awpcp_file_types(), awpcp_payments_api(), awpcp()->settings); } return $GLOBALS['awpcp-listing-upload-limits']; }
public function ajax_edit_balance($user_id, $action) { $user = get_user_by('id', $user_id); if (is_null($user)) { $message = __("The specified User doesn't exists.", 'AWPCP'); $response = array('status' => 'error', 'message' => $message); } if (isset($_POST['save'])) { $payments = awpcp_payments_api(); $amount = (int) awpcp_post_param('amount', 0); if ($action == 'debit') { $payments->remove_credit($user->ID, $amount); } else { $payments->add_credit($user->ID, $amount); } $balance = $payments->format_account_balance($user->ID); $response = array('status' => 'success', 'balance' => $balance); } else { // load the table so the get_columns methods is properly called // when attempt to find out the number of columns in the table $table = $this->get_table(); $columns = $_POST['columns']; ob_start(); include AWPCP_DIR . '/admin/templates/admin-panel-users-balance-form.tpl.php'; $html = ob_get_contents(); ob_end_clean(); $response = array('html' => $html); } return $response; }
/** * Register Ad Management Panel menu */ public function menu() { /* Profile Menu */ // We are using read as an alias for edit_classifieds_listings. If a user can `read`, // he or she can `edit_classifieds_listings`. $capability = 'read'; // Account Balance if (awpcp_payments_api()->credit_system_enabled() && !awpcp_current_user_is_admin()) { $parts = array($this->account->title, $this->account->menu, $this->account->page); $hook = add_users_page($parts[0], $parts[1], $capability, $parts[2], array($this->account, 'dispatch')); add_action("admin_print_styles-{$hook}", array($this->account, 'scripts')); } $current_user_is_non_admin_moderator = awpcp_current_user_is_moderator() && !awpcp_current_user_is_admin(); if (get_awpcp_option('enable-user-panel') != 1 || $current_user_is_non_admin_moderator) { return; } /* Ad Management Menu */ $slug = 'awpcp-panel'; $title = sprintf(__('%s Ad Management Panel', 'AWPCP'), get_bloginfo()); $menu = __('Ad Management', 'AWPCP'); $hook = add_menu_page($title, $menu, $capability, $slug, array($this->listings, 'dispatch'), MENUICO); // Listings $title = __('Manage Ad Listings', 'AWPCP'); $menu = __('Listings', 'AWPCP'); $hook = add_submenu_page($slug, $title, $menu, $capability, $slug, array($this->listings, 'dispatch')); add_action("admin_print_styles-{$hook}", array($this->listings, 'scripts')); do_action('awpcp_panel_add_submenu_page', $slug, $capability); }
function awpcp_listing_updated_user_message($listing, $messages) { $admin_email = awpcp_admin_recipient_email_address(); $payments_api = awpcp_payments_api(); $show_total_amount = $payments_api->payments_enabled(); $show_total_credits = $payments_api->credit_system_enabled(); $currency_code = awpcp_get_currency_code(); $blog_name = awpcp_get_blog_name(); if (!is_null($transaction)) { $transaction_totals = $transaction->get_totals(); $total_amount = $transaction_totals['money']; $total_credits = $transaction_totals['credits']; } else { $total_amount = 0; $total_credits = 0; } if (get_awpcp_option('requireuserregistration')) { $include_listing_access_key = false; $include_edit_listing_url = true; } else { $include_listing_access_key = get_awpcp_option('include-ad-access-key'); $include_edit_listing_url = false; } $params = compact('ad', 'admin_email', 'transaction', 'currency_code', 'show_total_amount', 'show_total_credits', 'include_listing_access_key', 'include_edit_listing_url', 'total_amount', 'total_credits', 'message', 'blog_name'); $email = new AWPCP_Email(); $email->to[] = "{$ad->ad_contact_name} <{$ad->ad_contact_email}>"; $email->subject = get_awpcp_option('listingaddedsubject'); $email->prepare(AWPCP_DIR . '/frontend/templates/email-place-ad-success-user.tpl.php', $params); return $email; }
public function get_payment_terms() { global $wpdb; if (!awpcp_payments_api()->payments_enabled()) { return array($this->get_free_payment_term()); } $order = get_awpcp_option('fee-order'); $direction = get_awpcp_option('fee-order-direction'); switch ($order) { case 1: $orderby = array('adterm_name', $direction); break; case 2: $orderby = array("amount {$direction}, adterm_name", $direction); break; case 3: $orderby = array("imagesallowed {$direction}, adterm_name", $direction); break; case 5: $orderby = array("_duration_interval {$direction}, rec_period {$direction}, adterm_name", $direction); break; } if (awpcp_current_user_is_admin()) { $args = array('orderby' => $orderby[0], 'order' => $orderby[1]); } else { $args = array('where' => 'private = 0', 'orderby' => $orderby[0], 'order' => $orderby[1]); } return AWPCP_Fee::query($args); }
private function render_payment_button($transaction) { global $awpcp_imagesurl; // no current support for multiple items $item = $transaction->get_item(0); $is_recurring = get_awpcp_option('twocheckoutpaymentsrecurring'); $is_test_mode_enabled = get_awpcp_option('paylivetestmode') == 1; $custom = $transaction->id; $totals = $transaction->get_totals(); $amount = $totals['money']; $x_login = get_awpcp_option('2checkout'); $currency = get_awpcp_option('2checkoutcurrencycode'); $payments = awpcp_payments_api(); $return_url = $payments->get_return_url($transaction); $notify_url = $payments->get_notify_url($transaction); $cancel_url = $payments->get_cancel_url($transaction); ob_start(); include AWPCP_DIR . '/frontend/templates/payments-2checkout-payment-button.tpl.php'; $html = ob_get_contents(); ob_end_clean(); return $html; }
function awpcp_account_balance_page() { $request = new AWPCP_Request(); $steps = awpcp_account_balance_page_steps(awpcp_payments_api()); return new AWPCP_AccountBalancePage($steps, $request); }
function awpcp_credit_plans_notices() { return new AWPCP_CreditPlansNotices(awpcp()->settings, awpcp_payments_api()); }
public function finish_step() { $transaction = $this->get_transaction(); $messages = $this->messages; $send_email = false; if (is_null($transaction)) { $message = __('We were unable to find a Payment Transaction assigned to this operation.', 'AWPCP'); return $this->render('content', awpcp_print_error($message)); } $ad = AWPCP_Ad::find_by_id($transaction->get('ad-id', 0)); if (is_null($ad)) { $message = __('The Ad associated with this transaction doesn\'t exists.', 'AWPCP'); return $this->render('content', awpcp_print_error($message)); } if (!$transaction->is_completed()) { awpcp_payments_api()->set_transaction_status_to_completed($transaction, $errors); if (!empty($errors)) { return $this->render('content', join(',', array_map('awpcp_print_error', $errors))); } $transaction->save(); } // reload Ad, since modifications were probably made as part of the // transaction handling workflow $ad = AWPCP_Ad::find_by_id($transaction->get('ad-id', 0)); $params = array('edit' => false, 'ad' => $ad, 'messages' => array_merge($messages, awpcp_listings_api()->get_ad_alerts($ad)), 'transaction' => $transaction, 'transaction_id' => $transaction->id); $template = AWPCP_DIR . '/frontend/templates/page-place-ad-finish-step.tpl.php'; return $this->render($template, $params); }
function awpcp_renew_listings_admin_page() { return new AWPCP_RenewListingsAdminPage(awpcp_listings_collection(), awpcp_payments_api(), awpcp_request()); }
/** * Returns information about the number of files uplaoded to an Ad, and * the number of files that can still be added to that same Ad. * * @since 3.0.2 * @deprecated 3.4 */ function awpcp_get_ad_uploaded_files_stats($ad) { $payment_term = awpcp_payments_api()->get_ad_payment_term($ad); $images_allowed = get_awpcp_option('imagesallowedfree', 0); $images_allowed = awpcp_get_property($payment_term, 'images', $images_allowed); $images_uploaded = $ad->count_image_files(); $images_left = max($images_allowed - $images_uploaded, 0); return apply_filters('awpcp-ad-uploaded-files-stats', array('images_allowed' => $images_allowed, 'images_uploaded' => $images_uploaded, 'images_left' => $images_left), $ad); }
function awpcp_listing_form_steps_componponent() { return new AWPCP_ListingFormStepsComponent(awpcp_payments_api(), awpcp_listing_upload_limits(), awpcp()->settings); }
function awpcp_users_collection() { global $wpdb; return new AWPCP_UsersCollection($wpdb, awpcp_payments_api()); }
public function user_has_enough_credit(&$balance = null) { if (awpcp_current_user_is_admin()) { return true; } if (awpcp_user_is_admin($this->user_id)) { return true; } $totals = $this->get_totals(); $credits = $totals['credits']; // no need for credits if ($credits === 0) { return true; } $payments = awpcp_payments_api(); if (!$payments->is_credit_accepted()) { return false; } $balance = $payments->get_account_balance($this->user_id); $plan = $payments->get_credit_plan($this->get('credit-plan')); $balance = $balance - $credits; if ($balance < 0) { if (is_null($plan)) { return false; } $balance = $balance + $plan->credits; if ($balance < 0) { return false; } } return true; }
function awpcp_listing_title_form_field($slug) { return new AWPCP_ListingTitleFormField($slug, awpcp_payments_api()); }
/** * Single entry point for AWPCP plugin. * * This is functional but still a work in progress... */ public function setup() { global $wpdb; if (!$this->is_up_to_date()) { $this->installer->install_or_upgrade(); // we can't call flush_rewrite_rules() because // $wp_rewrite is not available yet. It is initialized // after plugins_load hook is executed. $this->flush_rewrite_rules = true; } if (!$this->is_up_to_date()) { return; } $this->setup_register_settings_handlers(); // Ad metadata integration. $wpdb->awpcp_admeta = AWPCP_TABLE_AD_META; $this->settings->setup(); $this->modules_manager = awpcp_modules_manager(); $this->modules_updater = awpcp_modules_updater(); $this->payments = awpcp_payments_api(); $this->listings = awpcp_listings_api(); $this->admin = new AWPCP_Admin(); $this->panel = new AWPCP_User_Panel(); $this->compatibility = new AWPCP_Compatibility(); $this->compatibility->load_plugin_integrations(); add_action('generate_rewrite_rules', array($this, 'clear_categories_list_cache')); add_action('init', array($this, 'init')); add_action('init', array($this, 'register_custom_style'), 1000000); add_action('admin_init', array($this, 'check_compatibility_with_premium_modules')); add_action('admin_notices', array($this, 'admin_notices')); add_action('admin_notices', array($this->modules_manager, 'show_admin_notices')); add_action('awpcp_register_settings', array($this, 'register_settings')); add_action('awpcp-register-payment-term-types', array($this, 'register_payment_term_types')); add_action('awpcp-register-payment-methods', array($this, 'register_payment_methods')); add_filter('pre_set_site_transient_update_plugins', array($this->modules_updater, 'filter_plugins_version_information')); add_filter('plugins_api', array($this->modules_updater, 'filter_detailed_plugin_information'), 10, 3); add_filter('http_request_args', array($this->modules_updater, 'filter_http_request_args'), 10, 2); add_action('wp_enqueue_scripts', array($this, 'enqueue_scripts'), 1000); add_action('admin_enqueue_scripts', array($this, 'enqueue_scripts'), 1000); add_action('wp_footer', array($this, 'localize_scripts'), 15000); add_action('admin_footer', array($this, 'localize_scripts'), 15000); // some upgrade operations can't be done in background. // if one those is pending, we will disable all other features // until the user executes the upgrade operaton if (!get_option('awpcp-pending-manual-upgrade')) { $this->pages = new AWPCP_Pages(); add_action('awpcp-process-payment-transaction', array($this, 'process_transaction_update_payment_status')); add_action('awpcp-process-payment-transaction', array($this, 'process_transaction_notify_wp_affiliate_platform')); add_action('wp_ajax_awpcp-get-regions-options', array($this, 'get_regions_options')); add_action('wp_ajax_nopriv_awpcp-get-regions-options', array($this, 'get_regions_options')); // actions and filters from functions_awpcp.php add_action('phpmailer_init', 'awpcp_phpmailer_init_smtp'); add_action('widgets_init', array($this, 'register_widgets')); if (get_awpcp_option('awpcppagefilterswitch') == 1) { add_filter('wp_list_pages_excludes', 'exclude_awpcp_child_pages'); } awpcp_schedule_activation(); $this->modules_manager->load_modules(); } }
public function finish_step() { $transaction = $this->page->get_transaction(); if (is_null($transaction)) { $message = $this->page->transaction_error(); return $this->page->render('content', awpcp_print_error($message)); } $ad = $this->page->get_ad(); if (is_null($ad)) { $message = __('The Ad associated with this transaction doesn\'t exists.', 'AWPCP'); return $this->page->render('content', awpcp_print_error($message)); } if (!$transaction->is_completed()) { $payments = awpcp_payments_api(); $payments->set_transaction_status_to_completed($transaction, $errors); if (!empty($errors)) { return $this->page->render('content', join(',', array_map($errors, 'awpcp_print_error'))); } $ad->renew(); $ad->save(); awpcp_send_ad_renewed_email($ad); // MOVE inside Ad::renew() ? do_action('awpcp-renew-ad', $ad->ad_id, $transaction); } return $this->page->render_finish_step($ad); }
function get_payment_term() { return awpcp_payments_api()->get_payment_term($this->adterm_id, $this->payment_term_type); }
function awpcp_listing_regions_form_field($slug) { return new AWPCP_ListingRegionsFormField($slug, awpcp_payments_api(), awpcp()->settings); }
/** * @param transaction unused but required to match method * signature in parent class. */ public function save_details_step($transaction = null, $errors = array()) { global $wpdb, $hasextrafieldsmodule; $ad = $this->get_ad(); if (is_null($ad)) { $message = __('The specified Ad doesn\'t exists.', 'AWPCP'); return $this->render('content', awpcp_print_error($message)); } $data = $this->get_posted_details($_POST); $characters = $this->get_characters_allowed($ad->ad_id); $errors = array(); $payment_term = awpcp_payments_api()->get_ad_payment_term($ad); if (!$this->validate_details($data, true, $payment_term, $errors)) { return $this->details_step_form($ad, $data, $errors); } do_action('awpcp_before_edit_ad', $ad); // only admins can change the owner of an Ad if (!awpcp_current_user_is_moderator() || empty($data['user_id'])) { $data['user_id'] = $ad->user_id; } $ad->user_id = $data['user_id']; $ad->ad_title = $this->prepare_ad_title($data['ad_title'], $characters['characters_allowed_in_title']); $ad->ad_details = $this->prepare_ad_details($data['ad_details'], $characters['characters_allowed']); $ad->ad_contact_name = $data['ad_contact_name']; $ad->ad_contact_phone = $data['ad_contact_phone']; $ad->ad_contact_email = $data['ad_contact_email']; $ad->websiteurl = $data['websiteurl']; $ad->ad_item_price = $data['ad_item_price'] * 100; $ad->ad_last_updated = current_time('mysql'); if (awpcp_current_user_is_moderator()) { $ad->ad_startdate = awpcp_set_datetime_date($ad->ad_startdate, $data['start_date']); $ad->ad_enddate = awpcp_set_datetime_date($ad->ad_enddate, $data['end_date']); } if (awpcp_current_user_is_moderator() && !empty($data['ad_category'])) { $category = AWPCP_Category::find_by_id($data['ad_category']); if (!is_null($category)) { $ad->ad_category_id = $category->id; $ad->ad_category_parent_id = $category->parent; } } if (!$ad->save()) { $errors[] = __('There was an unexpected error trying to save your Ad details. Please try again or contact an administrator.', 'AWPCP'); return $this->details_step_form($ad, $data, $errors); } if (awpcp_current_user_is_moderator() || get_awpcp_option('allow-regions-modification')) { $regions_allowed = $this->get_regions_allowed($ad->ad_id); awpcp_basic_regions_api()->update_ad_regions($ad, $data['regions'], $regions_allowed); } do_action('awpcp_edit_ad', $ad); if (is_admin() || !awpcp_are_images_allowed()) { return $this->finish_step(); } else { return $this->upload_images_step(); } }
function awpcp_buy_credits_page() { $request = new AWPCP_Request(); $steps = awpcp_buy_credit_page_steps(awpcp_payments_api()); return new AWPCP_BuyCreditsPage($steps, $request); }
public function set_transaction_item($transaction, $term = null, $payment_type = null) { if (is_null($term)) { $term = $this->get_payment_term($payment_type, $selected); } else { if (is_null($payment_type)) { $payment_type = AWPCP_Payment_Transaction::PAYMENT_TYPE_MONEY; } $selected = $this->item_id($term, $payment_type); } if (!in_array($payment_type, awpcp_payments_api()->get_accepted_payment_types())) { awpcp_flash(__("The selected payment type can't be used in this kind of transaction.", 'AWPCP'), 'error'); return; } if (!$term->is_suitable_for_transaction($transaction)) { awpcp_flash(__("The selected payment term can't be used in this kind of transaction.", 'AWPCP'), 'error'); return; } $amount = $payment_type == 'credits' ? $term->credits : $term->price; $transaction->add_item($selected, $term->get_name(), $term->description, $payment_type, $amount); }
function awpcp_fee_payment_terms_notices() { return new AWPCP_FeePaymentTermsNotices(awpcp()->settings, awpcp_payments_api()); }
function awpcp_listing_details_form_field($slug) { return new AWPCP_ListingDetailsFormField($slug, awpcp_payments_api()); }