Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- Plugin Name: Bidoo
- Plugin URI: none
- Description: Bidoo Bid management
- Version: 1.0 (Cooper)
- Author: Alex F
- Author URI: alexf.com
- */
- class aidee_bidoo {
- function __construct () {
- $this->self_define();
- $this->load_dependencies();
- $this->register_shortcodes();
- $this->action_hooks(); // add action hooks.
- }
- function register_shortcodes () {
- add_shortcode('generate_form_code', array($this, 'generate_form_code'));
- add_shortcode('nohost_landing_page', array($this, 'nohost_landing_page'));
- add_shortcode('account_interface', array($this, 'account_interface'));
- }
- function add_rewrite_rules($aRules) {
- $aNewRules = array('cid/([^/]+)/?$' => 'index.php?pagename=cid&cid=$matches[1]');
- $aRules = $aNewRules + $aRules;
- return $aRules;
- }
- function add_query_vars($aVars) {
- $aVars[] = "cid"; // represents the name of the product category as shown in the URL
- return $aVars;
- }
- function plugin_install () {
- $db = new aidee_bidoo_db();
- $db->db_install();
- }
- /**
- *
- * function get_single_company_by_cid
- *
- * @param $cid = company id. Stored in aidee_company_id meta_data
- *
- * Does double duty. Checks to see if Company with CID exists via post query
- *
- * Since we're already invoking a query anyways, might as well pass back the post object for iteration as well.
- *
- * @return array('has_posts'=>bool, 'post_obj'=>post_object if found, if not null.)
- */
- function get_single_company_by_cid($cid) {
- $meta_query = array();
- $meta_query[] = array(
- 'key' => 'aidee_company_id',
- 'value' => $cid,
- 'compare' => '=',
- );
- $posts = new wp_query(array(
- 'posts_per_page' => 1,
- 'post_type' => 'company',
- 'post_status'=>'any',
- 'meta_key'=>'aidee_company_id',
- 'meta_query'=>$meta_query,
- 'orderby' => 'ASC'
- ));
- if($posts->have_posts()){
- return array('has_posts'=>true, 'post_obj'=>$posts);
- }
- return array('has_posts'=>false, 'post_obj'=>null);
- }
- function register_post_types () {
- require_once($this->plugin_base_dir.'/classes/register_post_types.php');
- new aidee_register_cpt('Company', 'Companies');
- }
- function action_hooks () {
- add_action('wp_ajax_bid_board', array($this, 'get_bid_board'));
- add_action( 'init', array($this, 'register_post_types'));
- add_filter('query_vars', array($this, 'add_query_vars')); // hooks in and adds cid to query var for grabbing for form.
- add_filter('rewrite_rules_array', array($this, 'add_rewrite_rules')); // hooks in and adds cid to query var for grabbing for form.
- register_activation_hook( __FILE__, array( $this, 'plugin_install' ) );
- if(is_admin()) {
- add_action('admin_enqueue_scripts', array($this, 'register_scripts_back' ));
- add_action('admin_enqueue_scripts', array($this, 'register_styles_back' ));
- }
- if(!is_admin()) {
- add_action('wp_enqueue_scripts', array($this, 'register_styles_front'));
- add_action('wp_enqueue_scripts', array($this, 'register_scripts_front'));
- }
- }
- function build_form ($cid='', $no_host=false) {
- $site_url = get_site_url();
- $form.="<form action='{$site_url}' id='bidoo_bidding_form' method='post'>";
- $form.="<input type='hidden' id='' name='cid' value='{$cid}'>";
- $form.="<div id='load_number'>";
- $form.="<input required type='text' name='load_number' placeholder='Load Number'>";
- $form.="</div>";
- $form.="<div id='company_name'>";
- $form.="<input required type='text' name='company_name' placeholder='Company Name'>";
- $form.="</div>";
- $form.="<div id='company_base_city'>";
- $form.="<input required type='text' name='company_base_city' placeholder='City Company is located in'>";
- $form.="</div>";
- $form.="<div id='load_date'>";
- $form.="<input required type='text' class='datepicker' data-select='datepicker' name='load_date' placeholder='Load Date'>";
- $form.="</div>";
- $form.="<div id='delivery_date'>";
- $form.="<input required type='text' data-select='datepicker' name='delivery_date' placeholder='Delivery Date'>";
- $form.="</div>";
- $form.="<div id='contact_first_name'>";
- $form.="<input required type='text' name='contact_first_name' placeholder='Contact person (First Name)'>";
- $form.="</div>";
- $form.="<div id='contact_last_name'>";
- $form.="<input required type='text' name='contact_last_name' placeholder='Contact person (Last Name)'>";
- $form.="</div>";
- $form.="<div id='company_contact_number'>";
- $form.="<input required type='text' name='company_contact_number' placeholder='Callback Phone Number'>";
- $form.="</div>";
- $form.="<div id='company_contact_email'>";
- $form.="<input required type='text' name='company_contact_email' placeholder='Contact Email'>";
- $form.="</div>";
- $form.="<div id='company_contact_number'>";
- $form.="<textarea name='comments' id='comments' placeholder='Questions/Comments'></textarea>";
- $form.="</div>";
- $form.="<input type='submit' name='submit'>";
- $form.="</form>";
- return $form;
- }
- /**
- *
- * function generate_form_code
- *
- * @param null
- *
- * used to generate embed code.
- *
- */
- function generate_form_code() {
- $customer_id = 'generic_customer_id';
- $string.="<div id='bidoo_form_wrapper' data-title='{$customer_id}'></div>";
- $string.="<script type='text/javascript'>";
- $string.="var script = document.createElement('script');";
- $string.= "script.src = '{$this->plugin_base_url}assets/js/payload.min.js';";
- $string.="var head = document.getElementsByTagName('head')[0];";
- $string.="script.type = 'text/javascript';";
- $string.="head.appendChild(script);";
- $string.="</script>";
- return apply_filters('the_content', "[sourcecode language='plain']{$string}[/sourcecode]");
- }
- function load_dependencies() {
- require_once($this->plugin_base_dir.'/classes/filters.php');
- $this->filters = new aidee_bidoo_filters();
- require_once($this->plugin_base_dir.'/classes/api.php');
- require_once($this->plugin_base_dir.'/classes/aidee_db.php');
- }
- function self_define () {
- $this->plugin_base_dir = plugin_dir_path(__FILE__);
- $this->plugin_base_url = plugin_dir_url(__FILE__);
- $this->parent_theme_dir = get_template_directory();
- $this->parent_theme_url = get_template_directory_uri();
- $this->child_theme_dir = get_stylesheet_directory();
- $this->child_theme_url = get_stylesheet_directory_uri();
- }
- function register_scripts_back () {
- }
- function register_styles_back () {
- }
- function register_scripts_front () {
- wp_register_script('bidoo_local_form', $this->plugin_base_url. '/assets/js/form.js', null, null, true);
- wp_register_script('bidoo_form_base', $this->plugin_base_url. '/assets/js/form-base.js', null, null, true);
- wp_register_script('bidoo_tabify', $this->plugin_base_url. '/assets/js/tabify.js', null, null, true);
- wp_register_script('bidoo_bid_board', $this->plugin_base_url. '/assets/js/bid_board.js', null, null, true);
- }
- function register_styles_front () {
- wp_register_style('bidoo_css', $this->plugin_base_url . '/assets/css/bidoo.css');
- }
- /**
- *
- * function nohost_landing_page
- *
- * This builds content for the companies that do not self host.
- *
- * We use the same method for populating the form remotely, as we do here. We add a simple <div> to the markup, and then call our script
- * which makes the same ajax cb, loads the form and calls everything else. Voila. We do this for the sake of consistency.
- *
- * we also load a template for displaying company logo, title etc. The company ID will be grabbed from query param
- * cid eg: ?cid=12345. Of course. validation is done before hand to ensure the company id is valid.
- *
- *
- */
- function nohost_landing_page() {
- wp_enqueue_script('bidoo_local_form');
- global $wp_query;
- $cid = $this->filters->filter_customer_id($wp_query->query_vars['cid']);
- $has_company = $this->get_single_company_by_cid($cid);
- if($has_company['has_posts']) {
- $content.="<div id='bidoo_form_wrapper' data-title='{$cid}'></div>";
- return $content;
- } else {
- return "Sorry, we could not find that company.";
- }
- }
- function get_bid_board() {
- $db = new aidee_bidoo_db();
- require_once($this->plugin_base_dir.'/templates/account/bid_board.php');
- wp_send_json( array('error'=>false, 'results'=>$layout));
- die;
- }
- function account_interface () {
- $db = new aidee_bidoo_db();
- wp_enqueue_style('bidoo_css');
- wp_enqueue_script('bidoo_tabify');
- wp_enqueue_script('bidoo_form_base');
- wp_enqueue_script('bidoo_bid_board');
- wp_localize_script('bidoo_bid_board', 'core_obj', array('ajax_url'=>admin_url('admin-ajax.php')));
- require_once($this->plugin_base_dir.'/templates/account/head.php');
- require_once($this->plugin_base_dir.'/templates/account/bid_board.php');
- return $layout;
- }
- }
- new aidee_bidoo();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement