示例#1
0
 /**
  * Set fields values
  * 
  * @param array $data
  */
 public function bind($data)
 {
     $fields = Adverts::instance()->get("form_field");
     foreach ($this->_scheme["field"] as $field) {
         $key = $field["name"];
         $type = $field["type"];
         $exploded = explode("[", $key);
         $key_arr = array_map("rtrim", $exploded, array_fill(0, count($exploded), "]"));
         $value = null;
         $drill = $data;
         foreach ($key_arr as $k) {
             if (isset($drill[$k])) {
                 $value = $drill[$k];
                 $drill = $drill[$k];
             } else {
                 $value = null;
             }
         }
         if (!isset($this->_form[$key])) {
             $this->_form[$key] = array();
         }
         if (isset($fields[$type]) && is_callable($fields[$type]["callback_bind"])) {
             $this->_form[$key]["value"] = call_user_func($fields[$type]["callback_bind"], $field, $value);
         }
     }
     do_action("adverts_form_bind", $this, $data);
 }
示例#2
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';
}
示例#3
0
 /**
  * Singleton, returns Adverts instance
  * 
  * @return Adverts
  */
 public static function instance()
 {
     if (self::$_instance === NULL) {
         self::$_instance = new self();
     }
     return self::$_instance;
 }
示例#4
0
/**
 * Main Adverts Init Function
 * 
 * Registers: custom post types, additional post statuses, taxonomies, image sizes
 * and Adverts scripts.
 * 
 * @global WP_Rewrite $wp_rewrite
 * @since 0.1
 * @return void
 */
function adverts_init()
{
    wp_register_style('adverts-icons', ADVERTS_URL . '/assets/css/adverts-glyphs.css');
    wp_register_style('adverts-icons-animate', ADVERTS_URL . '/assets/css/animation.css');
    load_plugin_textdomain("adverts", false, dirname(plugin_basename(__FILE__)) . "/languages/");
    register_post_status('expired', array('label' => _x('Expired', 'post'), 'public' => is_admin(), 'internal' => false, 'label_count' => _n_noop('Expired <span class="count">(%s)</span>', 'Expired <span class="count">(%s)</span>')));
    register_post_status('advert_tmp', array('label' => _x('Temporary', 'post'), 'public' => false, 'internal' => true, 'label_count' => _n_noop('Temporary <span class="count">(%s)</span>', 'Temporary <span class="count">(%s)</span>')));
    $labels = array('name' => _x('Classifieds', 'post type general name', 'adverts'), 'singular_name' => _x('Classified', 'post type singular name', 'adverts'), 'add_new' => _x('Add New', 'classified', 'adverts'), 'add_new_item' => __('Add New Classified', 'adverts'), 'edit_item' => __('Edit Classified', 'adverts'), 'new_item' => __('New Classified', 'adverts'), 'all_items' => __('All Classifieds', 'adverts'), 'view_item' => __('View Classified', 'adverts'), 'search_items' => __('Search Classifieds', 'adverts'), 'not_found' => __('No Classifieds found', 'adverts'), 'not_found_in_trash' => __('No Classifieds found in the Trash', 'adverts'), 'parent_item_colon' => '', 'menu_name' => __('Classifieds', 'adverts'));
    $args = array('labels' => $labels, 'description' => 'Holds our products and product specific data', 'public' => true, 'menu_icon' => 'dashicons-megaphone', 'menu_position' => 5, 'supports' => array('title', 'editor', 'author'), 'taxonomies' => array('advert_category'), 'has_archive' => true);
    register_post_type('advert', apply_filters('adverts_post_type', $args, 'advert'));
    $args = array('hierarchical' => true, 'query_var' => true, 'rewrite' => array('slug' => 'advert-category'));
    register_taxonomy('advert_category', 'advert', apply_filters('adverts_register_taxonomy', $args, 'advert_category'));
    add_image_size("adverts-upload-thumbnail", 150, 105, true);
    add_image_size("adverts-list", 310, 190, true);
    include_once ADVERTS_PATH . 'includes/class-adverts.php';
    include_once ADVERTS_PATH . 'includes/class-flash.php';
    include_once ADVERTS_PATH . 'includes/class-post.php';
    include_once ADVERTS_PATH . 'includes/events.php';
    include_once ADVERTS_PATH . 'includes/functions.php';
    include_once ADVERTS_PATH . 'includes/defaults.php';
    $currency = Adverts::instance()->get("currency");
    wp_register_script('adverts-auto-numeric', ADVERTS_URL . '/assets/js/auto-numeric.js', array(), false, true);
    wp_register_script('adverts-multiselect', ADVERTS_URL . '/assets/js/adverts-multiselect.js', array(), false, true);
    wp_register_script('adverts-gallery', ADVERTS_URL . '/assets/js/adverts-gallery.js', array('plupload-all'), false, true);
    wp_localize_script('adverts-auto-numeric', 'adverts_currency', array("aSign" => $currency["sign"], "pSign" => $currency["sign_type"], "aSep" => $currency["char_thousand"], "aDec" => $currency["char_decimal"]));
    wp_localize_script('adverts-multiselect', 'adverts_multiselect_lang', array("hint" => __("Select options ...", "adverts")));
    wp_localize_script('adverts-gallery', 'adverts_gallery_lang', array("edit_image" => __("Edit Image", "adverts"), "delete_image" => __("Delete Image", "adverts"), "view_image" => __("View Full Image", "adverts"), "featured" => __("Main", "adverts")));
    $module = adverts_config('config.module');
    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", 1000);
        }
    }
    if (get_option("adverts_delayed_install") == "yes") {
        global $wp_rewrite;
        $wp_rewrite->flush_rules();
        delete_option("adverts_delayed_install");
    }
    do_action("adverts_core_initiated");
}
示例#5
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';
}
示例#6
0
 static function getCategories()
 {
     // поставить кэширование запроса и обработку fields
     $categories = Yii::app()->db->createCommand('SELECT * FROM category')->queryAll();
     $ret_cat = array();
     foreach ($categories as $n => $cat) {
         $ret_cat[$cat['id']] = $cat;
         $ret_cat[$cat['id']]['fields'] = json_decode($cat['fields'], true);
         if (is_array($ret_cat[$cat['id']]['fields'])) {
             foreach ($ret_cat[$cat['id']]['fields'] as $f_n => $field) {
                 if ($field['type'] == 2) {
                     $ret_cat[$cat['id']]['fields'][$f_n]['atr'] = explode(",", $field['atr']);
                 }
             }
         }
     }
     $cat_count = Yii::app()->db->createCommand()->select('category_id, COUNT(*) count')->from(Adverts::model()->tableName())->group('category_id')->query();
     foreach ($cat_count as $row) {
         $ret_cat[$row['category_id']]['count'] = $row['count'];
     }
     return $ret_cat;
 }
示例#7
0
 public static function get_by_md5($md5)
 {
     $type = DigiplayDB::select("type FROM audio WHERE md5 = '" . $md5 . "'");
     if ($type) {
         if ($type == 1) {
             return Tracks::get_by_md5($md5);
         } else {
             if ($type == 2) {
                 return Jingles::get_by_md5($md5);
             } else {
                 if ($type == 3) {
                     return Adverts::get_by_md5($md5);
                 } else {
                     if ($type == 4) {
                         return Prerecs::get_by_md5($md5);
                     }
                 }
             }
         }
     }
 }
示例#8
0
<?php

Output::set_title("Advert Manager");
Output::add_script(LINK_ABS . "js/jquery-ui-1.10.3.custom.min.js");
Output::add_stylesheet(LINK_ABS . "css/select2.min.css");
Output::add_script(LINK_ABS . "js/select2.min.js");
Output::require_group("Sustainer Admin");
MainTemplate::set_subtitle("Change the adverts on the sustainer service");
$adverts = Adverts::get_all();
echo "<div class=\"list-group\">";
foreach ($adverts as $advert) {
    if ($advert->get_sustainer() == 't') {
        echo "<div class=\"list-group-item active\" data-advert=\"" . $advert->get_id() . "\">" . $advert->get_title() . "</div>";
    } else {
        echo "<div class=\"list-group-item\" data-advert=\"" . $advert->get_id() . "\">" . $advert->get_title() . "</div>";
    }
}
echo "</div>";
echo "<p></p>";
echo "<script>\r\n  \$('.list-group-item').click(function(){\r\n    \$(this).toggleClass(\"active\");\r\n    \$.ajax({\r\n      url: '" . LINK_ABS . "ajax/update-sustainer-advert.php',\r\n      data: {advertid: \$(this).data(\"advert\")},\r\n      type: 'POST',\r\n      error: function(xhr, text, error) {\r\n        value = \$.parseJSON(xhr.responseText);\r\n        alert(value.error);\r\n      },\r\n      success: function(data, text, xhr) {\r\n        window.location.reload(true);\r\n      }\r\n    });\r\n  });\r\n  </script>";
示例#9
0
 /**
  * Saves data in DB
  * 
  * @param Adverts_Form $form
  * @param WP_Post $post
  * @param array $defaults
  */
 public static function save(Adverts_Form $form, $post = null, $init = array())
 {
     if (is_numeric($post)) {
         $post = get_post($post);
     }
     // Change Post GUID using post_guid filter if the post is already saved in DB
     // (otherwise guid will be set automatically)
     if (isset($init["post"]["ID"]) && isset($init["post"]["guid"]) && $init["post"]["guid"] == "") {
         self::$_tmp_guid = get_post_permalink($init["post"]["ID"]);
         add_filter("post_guid", array(__CLASS__, "tmp_guid"));
     }
     $data = array();
     $meta = array();
     $taxo = array();
     // Set default values
     if (isset($init["post"]) && is_array($init["post"])) {
         $data = $init["post"];
     }
     if (isset($init["meta"]) && is_array($init["meta"])) {
         $meta = $init["meta"];
     }
     if (isset($init["taxo"]) && is_array($init["taxo"])) {
         $taxo = $init["taxo"];
     }
     // Merge defaults with data from the Adverts_Form
     foreach ($form->get_fields() as $field) {
         if (property_exists("WP_Post", $field["name"])) {
             $data[$field["name"]] = $field["value"];
         } elseif (taxonomy_exists($field["name"])) {
             $taxo[$field["name"]] = $field["value"];
         } elseif (isset($field["value"])) {
             $meta[$field["name"]] = array("field" => $field, "value" => $field["value"]);
         }
     }
     if ($post && $post->ID > 0) {
         // Post already exists, update only.
         $data["ID"] = $post->ID;
         $post_id = wp_update_post(apply_filters("adverts_update_post", $data));
     } else {
         // Post does not exist, insert it.
         $data["comment_status"] = "closed";
         $post_id = wp_insert_post(apply_filters("adverts_insert_post", $data));
     }
     if (is_wp_error($post_id)) {
         return $post_id;
     }
     // Save meta data values
     $fields = Adverts::instance()->get("form_field");
     foreach ($meta as $key => $data) {
         $field = $data["field"];
         $field_type = $field["type"];
         $value = $data["value"];
         $callback_save = $fields[$field_type]["callback_save"];
         if (is_callable($callback_save)) {
             call_user_func($callback_save, $post_id, $key, $value);
         }
     }
     // Save taxonomies
     foreach ($taxo as $key => $tax) {
         wp_set_post_terms($post_id, $tax, $key);
     }
     if (self::$_tmp_guid) {
         // After save tmp_guid filter is no longer needed, remove it.
         self::$_tmp_guid = null;
         remove_filter("post_guid", array(__CLASS__, "tmp_guid"));
     }
     return $post_id;
 }
示例#10
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';
    }
}
示例#11
0
 public function actionBan($id)
 {
     $model = $this->loadModel($id);
     $model->status = USER::STATUS_BANNED;
     $model->update(array('status'));
     //$adv_model = new Adverts();
     $adv_model = Adverts::model()->find("user_id = :id ", array(':id' => intval($id)));
     if ($adv_model) {
         $adv_model->delete();
     }
     $this->redirect(array('/'));
 }
示例#12
0
文件: defaults.php 项目: hemangsk/TCB
 * @uses Adverts
 * @uses adverts_config
 * 
 * @package     Adverts
 * @copyright   Copyright (c) 2015, Grzegorz Winiarski
 * @license     http://opensource.org/licenses/gpl-2.0.php GNU Public License
 * @since       0.1
 */
// Exit if accessed directly
if (!defined('ABSPATH')) {
    exit;
}
// Set default "Post Ad" form structure and save it in Adverts Singleton
Adverts::instance()->set("form", array("name" => "advert", "action" => "", "field" => array(array("name" => "_post_id", "type" => "adverts_field_hidden", "order" => 10, "label" => ""), array("name" => "_adverts_action", "type" => "adverts_field_hidden", "order" => 10, "label" => ""), array("name" => "_contact_information", "type" => "adverts_field_header", "order" => 10, "label" => __('Contact Information', 'adverts')), array("name" => "_adverts_account", "type" => "adverts_field_account", "order" => 10, "label" => __("Account", "adverts")), array("name" => "adverts_person", "type" => "adverts_field_text", "order" => 10, "label" => __("Contact Person", "adverts"), "is_required" => true, "validator" => array(array("name" => "is_required"))), array("name" => "adverts_email", "type" => "adverts_field_text", "order" => 10, "label" => __("Email", "adverts"), "is_required" => true, "validator" => array(array("name" => "is_required"), array("name" => "is_email"))), array("name" => "adverts_phone", "type" => "adverts_field_text", "order" => 10, "label" => __("Phone Number", "adverts"), "validator" => array(array("name" => "string_length", "params" => array("min" => 5)))), array("name" => "_item_information", "type" => "adverts_field_header", "order" => 20, "label" => __('Item Information', 'adverts')), array("name" => "post_title", "type" => "adverts_field_text", "order" => 20, "label" => __("Title", "adverts"), "validator" => array(array("name" => "is_required"))), array("name" => "advert_category", "type" => "adverts_field_select", "order" => 20, "label" => __("Category", "adverts"), "max_choices" => 10, "options" => array(), "options_callback" => "adverts_taxonomies"), array("name" => "gallery", "type" => "adverts_field_gallery", "order" => 20, "label" => __("Gallery", "adverts")), array("name" => "post_content", "type" => "adverts_field_textarea", "order" => 20, "label" => __("Description", "adverts"), "validator" => array(array("name" => "is_required")), "mode" => "tinymce-mini"), array("name" => "adverts_price", "type" => "adverts_field_text", "order" => 20, "label" => __("Price", "adverts"), "description" => "", "attr" => array("key" => "value"), "filter" => array(array("name" => "money"))), array("name" => "adverts_location", "type" => "adverts_field_text", "order" => 20, "label" => __("Location", "adverts")))));
// Set default currency and save it in Adverts Singleton
Adverts::instance()->set("currency", array('code' => adverts_config("config.currency_code"), 'sign' => adverts_currency_list(adverts_config("config.currency_code"), 'sign'), 'sign_type' => adverts_config("config.currency_sign_type"), 'decimals' => adverts_config("config.currency_decimals"), 'char_decimal' => adverts_config("config.currency_char_decimal"), 'char_thousand' => adverts_config("config.currency_char_thousand")));
/** REGISTER FORM FIELDS */
// Register <span> input
/** @see adverts_field_label() */
adverts_form_add_field("adverts_field_label", array("renderer" => "adverts_field_label", "callback_save" => null, "callback_bind" => null));
// Register <input type="hidden" /> input
/** @see adverts_field_hidden() */
adverts_form_add_field("adverts_field_hidden", array("renderer" => "adverts_field_hidden", "callback_save" => "adverts_save_single", "callback_bind" => "adverts_bind_single"));
// Register <input type="text" /> input
/** @see adverts_field_text() */
adverts_form_add_field("adverts_field_text", array("renderer" => "adverts_field_text", "callback_save" => "adverts_save_single", "callback_bind" => "adverts_bind_single"));
// Register <textarea></textarea> input
/** @see adverts_field_textarea() */
adverts_form_add_field("adverts_field_textarea", array("renderer" => "adverts_field_textarea", "callback_save" => "adverts_save_single", "callback_bind" => "adverts_bind_single"));
// Register <select>...</select> input
/** @see adverts_field_select() */
示例#13
0
/**
 * Adds meta box with additional advert information
 * 
 * @uses Adverts
 * @uses Adverts_Form
 * @see add_meta_box()
 * 
 * @param WP_Post $post
 * @since 0.1
 * @return void
 */
function adverts_data_box_content($post)
{
    wp_nonce_field(plugin_basename(__FILE__), 'product_price_box_content_nonce');
    $exclude = array("_adverts_account", "advert_category", "post_title", "gallery", "post_content");
    // Load form data
    $form = new Adverts_Form();
    $form->load(Adverts::instance()->get("form"));
    // Get list of fields from post meta table
    $bind = array();
    foreach ($form->get_fields(array("exclude" => $exclude)) as $f) {
        $bind[$f["name"]] = get_post_meta($post->ID, $f["name"], true);
    }
    // Bind data
    $form->bind($bind);
    // Validate if message 21 will be displayed, that is if form already failed
    // validation in adverts_save_post_validator() function
    if (isset($_GET['message']) && $_GET['message'] == 21) {
        $form->validate();
    }
    ?>

    <style type="text/css">
        .adverts-data-table th.adverts-data-header {
            font-size:1.4em; 
            font-weight: normal; 
            font-variant: small-caps; 
            padding: 20px 10px 0px 0px
        }
        
        .adverts-data-table input[type="text"],
        .adverts-data-table textarea {
            width: 99%;
        }
    </style>
    
    <table class="form-table adverts-data-table">
	<tbody>
        <?php 
    foreach ($form->get_fields(array("exclude" => $exclude)) as $field) {
        ?>
            <tr class="<?php 
        if (isset($field["error"]) && !empty($field["error"])) {
            ?>
form-invalid<?php 
        }
        ?>
">
            <?php 
        if ($field["type"] == "adverts_field_header") {
            ?>
                <th scope="row" colspan="2" class="adverts-data-header">
                    <?php 
            esc_html_e($field["label"]);
            ?>
                </th>
            <?php 
        } else {
            ?>
                <th scope="row">
                    <label for="<?php 
            esc_attr_e($field["name"]);
            ?>
"><?php 
            esc_html_e($field["label"]);
            ?>
</label></th>
                <td>
                    <?php 
            call_user_func(adverts_field_get_renderer($field), $field);
            ?>
                    <?php 
            if (isset($field["error"]) && !empty($field["error"])) {
                ?>
                    <ul>
                        <?php 
                foreach ($field["error"] as $error) {
                    ?>
                        <li><?php 
                    esc_html_e($error);
                    ?>
</li>
                        <?php 
                }
                ?>
                    </ul>
                    <?php 
            }
            ?>
                </td>
            <?php 
        }
        ?>
            </tr>
        <?php 
    }
    ?>
			
        </tbody>
    </table>
  
  <?php 
}
示例#14
0
/**
 * Binding function for array values
 * 
 * This function is used in Adverts_Form class filter and set values
 * for form fields which are using this function for binding (by default 
 * <select> and <input type="checkbox" /> are using it).
 * 
 * @see Adverts_Form
 * @see adverts_form_add_field()
 * @see includes/default.php
 * 
 * @since 1.0
 * @access public
 * @param array $field Information about form field
 * @param mixed $value Array or NULL value submitted via form
 * @return mixed
 */
function adverts_bind_multi($field, $value)
{
    $filters = Adverts::instance()->get("field_filter", array());
    $key = $field["name"];
    if ($value === NULL) {
        $value = array();
    } elseif (!is_array($value)) {
        $value = array($value);
    }
    $result = array();
    foreach ($value as $v) {
        $result[] = adverts_bind_single($field, $v);
    }
    if (!isset($field["max_choices"]) || $field["max_choices"] == 1) {
        if (isset($result[0])) {
            return $result[0];
        } else {
            return "";
        }
    } else {
        return $result;
    }
}
<?php

if (Session::is_group_user('Sustainer Admin')) {
    if (!($advert = Adverts::get_by_id((int) $_REQUEST["advertid"]))) {
        exit(json_encode(array('error' => 'Invalid advert ID.')));
    }
    if ($advert->get_sustainer() == 't') {
        $advert->set_sustainer('f');
    } else {
        $advert->set_sustainer('t');
    }
    $advert->save();
    if (Errors::occured()) {
        http_response_code(400);
        exit(json_encode(array("error" => "Something went wrong. You may have discovered a bug!", "detail" => Errors::report("array"))));
        Errors::clear();
    } else {
        exit(json_encode(array('response' => 'success', 'id' => $playlist->get_id())));
    }
} else {
    http_response_code(403);
    exit(json_encode(array('error' => 'Permission denied.')));
}
示例#16
0
 function __construct()
 {
     parent::__construct();
     $this->table = 'adverts';
 }
示例#17
0
/**
 * Generates HTML for ad edit form (in [adverts_manage] shortcode)
 * 
 * @param array $atts Shortcode attributes
 * @since 0.1
 * @return void 
 * @access private
 */
function _adverts_manage_edit($atts)
{
    wp_enqueue_style('adverts-frontend');
    wp_enqueue_style('adverts-icons');
    wp_enqueue_style('adverts-icons-animate');
    wp_enqueue_script('adverts-frontend');
    wp_enqueue_script('adverts-auto-numeric');
    extract(shortcode_atts(array('name' => 'default', 'moderate' => false), $atts));
    include_once ADVERTS_PATH . 'includes/class-html.php';
    include_once ADVERTS_PATH . 'includes/class-form.php';
    $form = new Adverts_Form(Adverts::instance()->get("form"));
    $valid = null;
    $error = array();
    $info = array();
    $bind = array();
    $action = apply_filters('adverts_action', adverts_request("_adverts_action", ""), __FUNCTION__);
    $post_id = adverts_request("advert_id", null);
    // $post_id hijack attempt protection here!
    $post = get_post($post_id);
    if ($post === null) {
        $error[] = __("Ad does not exist.", "adverts");
        adverts_flash(array("error" => $error));
        return;
    }
    if ($post->post_author != get_current_user_id()) {
        $error[] = __("You do not own this Ad.", "adverts");
        adverts_flash(array("error" => $error));
        return;
    }
    $slist = apply_filters("adverts_sh_manage_list_statuses", array('publish', 'expired', 'pending', 'draft'));
    if (!in_array($post->post_status, $slist)) {
        $error[] = sprintf(__("Incorrect post status [%s].", "adverts"), $post->post_status);
        adverts_flash(array("error" => $error));
        return;
    }
    foreach ($form->get_fields() as $f) {
        $bind[$f["name"]] = get_post_meta($post_id, $f["name"], true);
    }
    $bind["_adverts_action"] = "update";
    $bind["_post_id"] = $post_id;
    $bind["post_title"] = $post->post_title;
    $bind["post_content"] = $post->post_content;
    $bind["advert_category"] = array();
    $terms = get_the_terms($post_id, 'advert_category');
    if (is_array($terms)) {
        foreach ($terms as $term) {
            $bind["advert_category"][] = $term->term_id;
        }
    }
    $form->bind($bind);
    if ($action == "update") {
        $form->bind((array) stripslashes_deep($_POST));
        $valid = $form->validate();
        if ($valid) {
            $post_id = Adverts_Post::save($form, $post_id);
            if (is_wp_error($post_id)) {
                $error[] = $post_id->get_error_message();
            } else {
                $info[] = __("Post has been updated.", "adverts");
            }
        } else {
            $error[] = __("Cannot update. There are errors in your form.", "adverts");
        }
    }
    $adverts_flash = array("error" => $error, "info" => $info);
    // adverts/templates/manage-edit.php
    include apply_filters("adverts_template_load", ADVERTS_PATH . 'templates/manage-edit.php');
}
示例#18
0
 public function getUserId()
 {
     $id = $_GET['ads_id'];
     $ads = new Adverts();
     return $ads->UserId($id);
 }
示例#19
0
 /**
  * Вывод главной
  * отличается наличием виджета категорий вверху
  */
 public function actionIndex() {
     $roots = Category::model()->roots()->findAll();
     $criteria = new CDbCriteria();
     $criteria->limit = 10;
     $criteria->order = 'id desc';
     $IndexAdv = Adverts::model()->findAll($criteria);
     $this->render('index', array(
         'roots' => $roots,
         'IndexAdv' => $IndexAdv,
     ));
 }
示例#20
0
文件: payments.php 项目: hemangsk/TCB
/**
 * Returns payment gateway by $name, if $name is NULL then all payment
 * gateways are returned.
 * 
 * @see Adverts
 * @since 1.0
 * 
 * @param string $name
 * @return mixed
 */
function adext_payment_gateway_get($name = null)
{
    $pg = Adverts::instance()->get("payment_gateways");
    if ($name === null) {
        return $pg;
    } elseif (isset($pg[$name])) {
        return $pg[$name];
    } else {
        return null;
    }
}
示例#21
0
    public function actionSearch($searchStr = "") {
        $model = new Adverts('search');

        $model->unsetAttributes();  // clear any default values
        //$model->attributes=$_POST;

        if ($searchStr) {
            $model->name = $searchStr;
            $model->text = $searchStr;
        }
        $model->category_id = Yii::app()->request->getParam("cat_id");

        // Обработка дополнительных полей для поиска 
        $s_fields = $_GET['fields'];
        $txt_vld = new textValidator();

        if (is_array($s_fields)) {
            ksort($s_fields);
            foreach ($s_fields as $fn => $fv) {
                if ($fv!=="") {
                    if ($txt_vld->validate_str($fv) and $txt_vld->validate_str($fn)) {
                        if ($model->fields) {
                            $model->fields .= "%";
                        }
                        $model->fields .= '"' . $fn . '"[^"]+"' . $fv . '"';
                    } else {
                        throw new CHttpException(400, ' Bad Request ');
                    }
                }
            }
        }

        $dataProvider = $model->search();

        $this->render('index', array(
            'data' => $dataProvider,
        ));
    }
示例#22
0
 /**
  * Returns the data model based on the primary key given in the GET variable.
  * If the data model is not found, an HTTP exception will be raised.
  * @param integer $id the ID of the model to be loaded
  * @return Adverts the loaded model
  * @throws CHttpException
  */
 public function loadModel($id)
 {
     $model = Adverts::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }