Exemple #1
0
/**
 * Renders default/core config form.
 * 
 * The page is rendered in wp-admin / Classifieds / Options / Core 
 * 
 * @since 0.1
 * @return void
 */
function adext_core_page_options()
{
    $page_title = __("Core Options", "adverts");
    $button_text = __("Update Options", "adverts");
    wp_enqueue_style('adverts-admin');
    $flash = Adverts_Flash::instance();
    $error = array();
    $scheme = Adverts::instance()->get("form_core_config");
    $form = new Adverts_Form($scheme);
    if (isset($_POST) && !empty($_POST)) {
        $form->bind(stripslashes_deep($_POST));
        $valid = $form->validate();
        if ($valid) {
            $data = $form->get_values();
            $data["module"] = adverts_config('config.module');
            update_option("adverts_config", $data);
            $flash->add_info(__("Settings updated.", "adverts"));
        } else {
            $flash->add_error(__("There are errors in your form.", "adverts"));
        }
    } else {
        $form->bind(adverts_config("config.ALL"));
    }
    include ADVERTS_PATH . 'addons/core/admin/options.php';
}
Exemple #2
0
 /**
  * Singleton Returns Adverts Flash Instance
  * 
  * Flash object is used to store messages (info and warnings) which will
  * be displayed to user once.
  * 
  * @since 1.0
  * @return Adverts_Flash
  */
 public static function instance()
 {
     if (self::$_instance === null) {
         self::$_instance = new self();
     }
     return self::$_instance;
 }
Exemple #3
0
/**
 * Renders config Featured Ads config form.
 * 
 * The page is rendered in wp-admin / Classifieds / Options / Featured Ads 
 * 
 * @since 1.0.3
 * @return void
 */
function adext_featured_page_options()
{
    wp_enqueue_style('adverts-admin');
    $flash = Adverts_Flash::instance();
    $error = array();
    include ADVERTS_PATH . 'addons/featured/admin/options.php';
}
Exemple #4
0
/**
 * Renders config Bank Transfer config form.
 * 
 * The page is rendered in wp-admin / Classifieds / Options / Bank Transfer 
 * 
 * @since 0.1
 * @return void
 */
function adext_bank_transfer_page_options()
{
    wp_enqueue_style('adverts-admin');
    $flash = Adverts_Flash::instance();
    $error = array();
    $scheme = Adverts::instance()->get("form_bank_transfer_config");
    $form = new Adverts_Form($scheme);
    $button_text = __("Update Options", "adverts");
    if (isset($_POST) && !empty($_POST)) {
        $form->bind(stripslashes_deep($_POST));
        $valid = $form->validate();
        if ($valid) {
            update_option("adext_bank_transfer_config", $form->get_values());
            $flash->add_info(__("Settings updated.", "adverts"));
        } else {
            $flash->add_error(__("There are errors in your form.", "adverts"));
        }
    } else {
        $form->bind(get_option("adext_bank_transfer_config", array()));
    }
    include ADVERTS_PATH . 'addons/bank-transfer/admin/options.php';
}
Exemple #5
0
/**
 * Install Modules 
 * 
 * Run module installation functions (if any) on modules that were "just" activated. 
 * This function is executed in "init" filter with low priority so all the modules 
 * are initiated before it is run.
 * 
 * @since 0.2
 * @return void
 */
function adverts_install_modules()
{
    $module = adverts_config('config.module');
    $install = array();
    foreach ((array) $module as $mod => $status) {
        if (!is_file(ADVERTS_PATH . "addons/{$mod}/{$mod}.php")) {
            continue;
        }
        if ($status > 0) {
            include_once ADVERTS_PATH . "addons/{$mod}/{$mod}.php";
        }
        if ($status == 0.5) {
            add_action("init", "adverts_install_modules");
            Adverts_Flash::instance()->add_info(__("Module activated successfully.", "adverts"));
            $module[$mod] = 1;
            adverts_config_set('config.module', $module);
            adverts_config_save('config');
            do_action("adverts_install_module_{$mod}");
        }
    }
}
Exemple #6
0
/**
 * Renders Payments History List and Edit Page.
 * 
 * The page is rendered in wp-admin / Classifieds / Payments History panel
 * 
 * @global wpdb $wpdb
 * @global wp_locale $wp_locale
 * 
 * @since 0.1
 * @return void
 */
function adext_payments_page_history()
{
    global $wpdb, $wp_locale;
    wp_enqueue_style('adverts-admin');
    $flash = Adverts_Flash::instance();
    if (adverts_request("add")) {
        // Do nothing currently users cannot add pricing manually.
    } elseif (adverts_request("edit")) {
        // Display payment edit page.
        $payment = get_post(adverts_request("edit"));
        $form = new Adverts_Form();
        $form->load(Adverts::instance()->get("form_payments_history"));
        $form->bind(Adverts_Post::to_array($payment));
        $gateway_name = get_post_meta($payment->ID, '_adverts_payment_gateway', true);
        $gateway = adext_payment_gateway_get($gateway_name);
        if (!$gateway) {
            $msg = sprintf(__("Payment Method [%s] assigned to this Payment does not exist or was disabled.", "adverts"), $gateway_name);
            $flash->add_error($msg);
        }
        if (isset($_POST) && !empty($_POST)) {
            $form->bind(stripslashes_deep($_POST));
            $valid = $form->validate();
            if ($valid) {
                $status_new = $form->get_value("post_status");
                $status_old = $payment->post_status;
                $post_id = Adverts_Post::save($form, $payment);
                if (is_numeric($post_id) && $post_id > 0 && $status_old != $status_new) {
                    do_action("adverts_payment_" . $status_new, $payment);
                    $text = __('<strong>%1$s</strong> changed payment status to <strong>%2$s</strong>', 'adverts');
                    $message = sprintf($text, wp_get_current_user()->user_login, $status_new);
                    adext_payments_log($post_id, $message);
                    $payment = get_post($post_id);
                }
                if (is_wp_error($post_id)) {
                    $flash->add_error($post_id->get_error_message());
                } elseif ($post_id === 0) {
                    $flash->add_error(__("There was an error while saving pricing in database.", "adverts"));
                } else {
                    $flash->add_info(__("Payment updated.", "adverts"));
                }
            } else {
                $flash->add_error(__("There are errors in your form.", "adverts"));
            }
        }
        include ADVERTS_PATH . 'addons/payments/admin/payment-history-edit.php';
    } elseif (adverts_request('delete')) {
        // Delete Payment
        $post = get_post(adverts_request('delete'));
        $i = 0;
        if (!$post || $post->post_type != 'adverts-payment') {
            wp_die(__('Adverts Payment with given ID does not exist.', 'adverts'));
        }
        foreach (get_children($post) as $child) {
            wp_delete_attachment($child->ID, true);
            $i++;
        }
        $flash->add_info(sprintf(_n("1 Payment deleted.", "%s Payments deleted.", $i, "adverts"), $i));
        wp_delete_post($post->ID, true);
        wp_redirect(remove_query_arg(array('delete', 'noheader', 'pg')));
        exit;
    } elseif (adverts_request('filter_action')) {
        // Apply filters and return to payments history list
        $url = remove_query_arg(array('delete', 'noheader', 'pg'));
        $url = add_query_arg(array('month' => adverts_request('month')), $url);
        wp_redirect($url);
        exit;
    } elseif (adverts_request('action') || adverts_request('action2')) {
        // Apply bulk actions and return to payments history list
        $action = adverts_request('action');
        if (empty($action)) {
            $action = adverts_request('action2');
        }
        $item = adverts_request('item');
        foreach ($item as $id) {
            if ($action == "delete") {
                foreach (get_children($id) as $child) {
                    wp_delete_attachment($child->ID, true);
                }
                wp_delete_post($id, true);
                $flash->add_info(__("Payments deleted.", "adverts"));
            } elseif (stripos($action, "set-status-") === 0) {
                $status_old = get_post_status($id);
                $status_new = str_replace("set-status-", "", $action);
                $status_obj = get_post_status_object($status_new);
                if ($status_old != $status_new) {
                    wp_update_post(array("ID" => $id, "post_status" => $status_new));
                    do_action("adverts_payment_" . $status_new, $payment);
                }
                $flash->add_info(sprintf(__("Status for selected Payments was changed to: %s"), $status_obj->label));
            }
        }
        wp_redirect(remove_query_arg(array('delete', 'noheader', 'pg')));
        exit;
    } else {
        // Display Payments History
        $status_list = array("pending" => 0, "completed" => 0, "failed" => 0, "refunded" => 0);
        foreach ($status_list as $k => $v) {
            $sql = "SELECT COUNT(*) FROM {$wpdb->posts} WHERE post_status = %s AND post_type = 'adverts-payment'";
            $status_list[$k] = (int) $wpdb->get_var($wpdb->prepare($sql, $k));
        }
        $sql = "SELECT DISTINCT YEAR( post_date ) AS year, MONTH( post_date ) AS month FROM {$wpdb->posts} WHERE post_type = %s ORDER BY post_date DESC";
        $months_list = $wpdb->get_results($wpdb->prepare($sql, 'adverts-payment'));
        $months = array();
        foreach ($months_list as $m) {
            $months[] = array("value" => $m->year . "-" . $m->month, "label" => sprintf(__('%1$s %2$d'), $wp_locale->get_month($m->month), $m->year));
        }
        $month = adverts_request("month", "");
        $filter = adverts_request("status", "");
        $loop_params = array('post_type' => 'adverts-payment', 'posts_per_page' => 20, 'paged' => adverts_request('pg', 1));
        if ($filter) {
            $loop_params['post_status'] = $filter;
        }
        if ($month == "this-month") {
            $before = date('Y-m-d H:i:s', strtotime('last day of this month', current_time('timestamp')));
            $after = date('Y-m-d H:i:s', strtotime('first day of this month', current_time('timestamp')));
            $loop_params['date_query'] = array(array('before' => $before, 'after' => $after, 'inclusive' => true));
        } elseif ($month == "last-month") {
            $before = date('Y-m-d H:i:s', strtotime('last day of last month', current_time('timestamp')));
            $after = date('Y-m-d H:i:s', strtotime('first day of last month', current_time('timestamp')));
            $loop_params['date_query'] = array(array('before' => $before, 'after' => $after, 'inclusive' => true));
        } elseif (!empty($month)) {
            $time = strtotime($month . "-10");
            $before = date('Y-m-d', strtotime('last day of this month', $time));
            $after = date('Y-m-d H:i:s', strtotime('first day of this month', $time));
            $loop_params['date_query'] = array(array('before' => '', 'after' => '', 'inclusive' => true));
        }
        $loop = new WP_Query($loop_params);
        include ADVERTS_PATH . 'addons/payments/admin/payment-history-list.php';
    }
}
Exemple #7
0
/**
 * Display flash messages in wp-admin
 * 
 * This function is being used mainly in Adverts wp-admin template files
 * 
 * @since 0.1
 * @return void
 */
function adverts_admin_flash()
{
    $flash = Adverts_Flash::instance();
    ?>

    <?php 
    foreach ($flash->get_info() as $info) {
        ?>
    <div class="updated fade">
        <p><?php 
        echo $info;
        ?>
</p>
    </div>
    <?php 
    }
    ?>

    <?php 
    foreach ($flash->get_error() as $error) {
        ?>
    <div class="error">
        <p><?php 
        echo $error;
        ?>
</p>
    </div>
    <?php 
    }
    ?>

    <?php 
    $flash->dispose();
    ?>
    <?php 
    $flash->save();
}