Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class fire_island {
- function __construct () {
- $this->acf_required_fields = array('field_554add0107fe4', 'field_554adcf607fe3', 'field_554add9245c94', 'field_554ae220ba906', 'field_554ae2cfba907');
- if(is_admin()) {
- require_once (plugin_dir_path(__FILE__).'/include/Aidee-Optionz/options_class.php');
- require_once (plugin_dir_path(__FILE__).'/include/Aidee-Formz/form_class.php');
- require_once (plugin_dir_path(__FILE__).'include/Aidee-Optionz/options.php');
- require_once(plugin_dir_path( __FILE__ ).'/include/Aidee-Upload-Class/basic_upload.php');
- new uploader('upload_manager',
- array(
- 'upload_size_limit'=>'99999999999999',
- 'uploader_type'=>'upload',
- 'parent_class'=>'fire_island'
- ),
- array('xlsx'), array('application'));
- }
- add_action( 'wp_enqueue_scripts', array(&$this, 'enqueue_styles' ),15);
- add_action( 'admin_enqueue_scripts', array(&$this, 'backend_enqueue_styles' ),15);
- add_action('init', array(&$this, 'register_taxonomies'));
- add_action ('init', array(&$this, 'register_post_types'));
- add_action('admin_menu',array(&$this, 'cleanup_post_editor'));
- // we're over-riding the parents property listing class with our own.
- require_once( get_stylesheet_directory( __FILE__ ) . '/framework/admin/noo-property.php');
- require_once( get_stylesheet_directory( __FILE__ ) . '/framework/admin/noo-agent.php');
- require_once( plugin_dir_path( __FILE__ ) . '/framework/admin/meta-boxes/post-meta-boxes.php');
- require_once( plugin_dir_path( __FILE__ ) . '/include/date_time.php');
- add_action('add_meta_boxes', array(&$this, 'add_more_meta_boxes'));
- add_action('add_meta_boxes', array(&$this, 'register_meta_boxes'), 1);
- add_action( 'save_post', array(&$this, 'save_book_meta'), 10, 3 );
- add_action('add_meta_boxes', array(&$this, 'register_quick_menu'), 1);
- add_action( 'edit_form_after_title', array(&$this, 'cleanify_wp_editor' ));
- add_action( 'edit_form_after_editor', array(&$this, 'cleanify_wp_editor_after' ));
- add_filter( 'wp_mail_content_type', array(&$this, 'set_html_content_type'));
- add_action('wp_ajax_event_calendar_change', array(&$this, 'update_side_bar_calendar'));
- add_action('wp_ajax_nopriv_event_calendar_change', array(&$this, 'update_side_bar_calendar'));
- add_action('wp_ajax_nopriv_xls_parser', array(&$this, 'xls_parser'));
- add_action('wp_ajax_xls_parser', array(&$this, 'xls_parser'));
- add_action('wp_ajax_show_cons_single_item', array(&$this, 'show_cons_single_item'));
- add_action('wp_ajax_nopriv_show_cons_single_item', array(&$this, 'show_cons_single_item'));
- add_filter( 'pre_get_posts', array(&$this, 'filter_pre_get_posts'));
- add_filter('posts_where', array(&$this, 'no_privates'));
- add_filter( 'wp_nav_menu_items', array(&$this, 'add_search_to_nav'));
- /*
- $page = acf_add_options_page(array(
- 'page_title' => 'Fire Island Extra Options',
- 'menu_title' => 'Fire Island Command Center',
- 'menu_slug' => 'theme-general-settings',
- 'capability' => 'administrator',
- 'redirect' => false
- ));*/
- add_shortcode('home_page_testimonials', array(&$this, 'home_page_testimonials'));
- // adds lot # col sortable to post list.
- add_filter('manage_edit-noo_property_columns', array(&$this, 'add_extra_column'));
- add_action( 'manage_noo_property_posts_custom_column', array(&$this, 'add_column_content'), 10, 2 );
- add_filter( 'manage_edit-noo_property_sortable_columns', array(&$this, 'resort_col' ));
- add_action( 'pre_get_posts', array(&$this, 'resort_colums_filter' ));
- // adds lot # col sortable to post list.
- add_filter('manage_edit-noo_property_columns', array(&$this, 'add_post_status_extra_column'));
- add_action( 'manage_noo_property_posts_custom_column', array(&$this, 'add_post_status_column_content'), 10, 2 );
- foreach ($this->acf_required_fields as $field ) {
- add_filter("acf/load_field/key={$field}", array(&$this, 'my_acf_load_field'));
- }
- // these 6, yes count them 6 fucking filters/actions are ALL required to make our auto-emailer
- // work. We need to use the update_ hooks to store the updated data that we then use
- // to cross reference against our hidden data array to check if anythings change in the
- // wp_insert_post hook. Do not mess with these. Seriously, the kitten gets it if you do.
- //
- // This is the culmination of a 12 hour coding session, a lot of coffee and 1 step closer
- // to me going bald. FML.
- if(is_admin() && $this->is_edit_page()) {
- add_action( 'wp_insert_post', array(&$this, 'auto_emailer_on_post_update'), 99999, 3 );
- add_filter( "get_post_metadata", array(&$this, 'filter_get_post_meta'), true, 4);
- add_action("update_post_metadata", array(&$this, 'filter_update_post_meta'), 10, 5);
- add_action("update_post_meta", array(&$this, 'filter_update_post_meta'), 10, 5);
- add_action("updated_postmeta", array(&$this, 'filter_update_post_meta'), 10, 5);
- add_action("updated_post_meta", array(&$this, 'filter_update_post_meta'), 10, 5);
- add_action('added_post_meta', array(&$this, 'filter_update_post_meta'), 10, 4 );
- }
- add_action( 'admin_menu', array(&$this, 'remove_default_metaboxes' ));
- add_action( 'post_submitbox_misc_actions', array(&$this, 'show_modified_date' ));
- require_once( get_stylesheet_directory( __FILE__ ) . '/include/acf-field-date-time-picker-master/acf-date_time_picker.php');
- }
- function show_modified_date() {
- if ( ! is_admin() )
- return;
- global $post_ID;
- $post = get_post( $post_ID );
- ?>
- <div id="author" class="misc-pub-section" style="border-top-style:solid; border-top-width:1px; border-top-color:#EEEEEE; border-bottom-width:0px;">
- Last Modified:
- <?php the_modified_time('D M d Y g:i a');?>
- </div>
- <?php
- }
- function remove_default_metaboxes() {
- // Remove 'Keywords' (like tags) metabox
- remove_meta_box( 'tagsdiv-keyword', 'my-custom-post-type-slug', 'side' );
- // Remove 'Groups' (like categories) metabox
- remove_meta_box( 'groupdiv', 'my-custom-post-type-slug', 'side' );
- }
- function cleanup_post_editor() {
- foreach (array('noo_property','Testimonial','Event', 'concierge_service') as $post_type) {
- remove_meta_box( 'authordiv',$post_type,'normal' );
- remove_meta_box( 'commentstatusdiv',$post_type,'normal' );
- remove_meta_box( 'commentsdiv',$post_type,'normal' );
- remove_meta_box( 'postcustom',$post_type,'normal' );
- if($post_type!='concierge_service') remove_meta_box( 'postexcerpt',$post_type,'normal' );
- remove_meta_box( 'revisionsdiv',$post_type,'normal' );
- remove_meta_box( 'slugdiv',$post_type,'normal' );
- remove_meta_box( 'tagsdiv-post_tag',$post_type,'normal' );
- remove_meta_box( 'pageparentdiv',$post_type,'normal' );
- remove_meta_box( 'trackbacksdiv',$post_type,'normal' );
- remove_meta_box('categorydiv', $post_type, 'normal');
- }
- }
- function add_more_meta_boxes () { // hooks the noo featured image gallery to our post type for events
- $helper = new NOO_Meta_Boxes_Helper($prefix, array('page' => 'event'));
- $meta_box = array(
- 'id' => "{$prefix}_meta_box_gallery",
- 'title' => __('Gallery Settings', NOO_TEXT_DOMAIN),
- 'fields' => array(
- array(
- 'id' => "{$prefix}_gallery",
- // 'label' => __( 'Your Gallery', NOO_TEXT_DOMAIN ),
- 'type' => 'gallery',
- ),
- array(
- 'type' => 'divider',
- ),
- )
- );
- $helper->add_meta_box($meta_box);
- }
- function list_all_sheets () {
- global $wp_styles;
- foreach ($wp_styles as $style) {
- foreach ($style as $s) {
- echo "<li>Source:$s->src</li>";
- echo "<li>Handle:$s->handle</li>";
- }
- }
- }
- function register_post_types () {
- include_once (get_stylesheet_directory(__FILE__) . '/include/register_post_types.php'); // Handles the vim section. Modifying vims, membership renewal etc.
- new aidee_register_cpt('Testimonial');
- new aidee_register_cpt('Event');
- new aidee_register_cpt('Concierge Service');
- }
- function register_taxonomies () {
- include_once (get_stylesheet_directory(__FILE__) . '/include/taxon_register.php'); // Handles the vim section. Modifying vims, membership renewal etc.
- new taxonomy_register("market_availability", 'noo_property');
- new taxonomy_register("property_features", 'noo_property');
- }
- function is_edit_page($new_edit = null){
- global $pagenow;
- if (!is_admin()) return false;
- if($new_edit == "edit")
- return in_array( $pagenow, array( 'post.php', ) );
- elseif($new_edit == "new") //check for new post page
- return in_array( $pagenow, array( 'post-new.php' ) );
- else //check for either new or edit
- return in_array( $pagenow, array( 'post.php', 'post-new.php' ) );
- }
- function filter_get_post_meta ($metadata, $object_id, $meta_key, $single) {
- // we use this function to build and hide an array of fields propogated on post load in the editor.
- // we will be using these in conjuction with the wp_insert_post hook above, and the updated_post
- global $post;
- remove_filter( "get_post_metadata", array(&$this, 'filter_get_post_meta'), true, 4);
- $current_meta = urlencode(serialize(get_post_meta($post->ID , $meta_key)));
- add_filter( "get_post_metadata", array(&$this, 'filter_get_post_meta'), true, 4);
- echo "<input type='hidden' class='hide_me_away' value='{$current_meta}' name='check_sum[$meta_key]'>";
- }
- function filter_update_post_meta ( $null, $object_id, $meta_key, $meta_value, $nah='') {
- $this->changed_values[$meta_key] = $meta_value;
- }
- function resort_colums_filter( $query ) {
- if( ! is_admin() )
- return;
- $orderby = $query->get( 'orderby');
- if( 'lot_nmb' == $orderby ) {
- $query->set('meta_key','lot_nmb');
- $query->set('orderby','meta_value_num');
- }
- }
- function resort_col( $columns ) {
- $columns['lot_nmb'] = 'lot_nmb';
- return $columns;
- }
- function add_post_status_column_content( $column_name, $post_id ) {
- if ( 'lot_nmb' != $column_name )
- return;
- $slices = get_post_meta($post_id, 'lot_nmb', true);
- if($slices==0) {echo "Not Set";return;}
- echo intval($slices);
- }
- function add_post_status_extra_column($columns) {
- $columns['property_status'] = 'Property Status';
- return $columns;
- }
- function add_column_content( $column_name, $post_id ) {
- if ( 'property_status' != $column_name )
- return;
- $terms = wp_get_post_terms($post_id, 'property_category');
- if($terms) foreach($terms as $term) {
- echo $term->name." ";
- }
- }
- function add_extra_column($columns) {
- $columns['lot_nmb'] = 'Lot Number';
- return $columns;
- }
- function add_search_to_nav($menu) {
- if (!is_user_logged_in()) {
- return $menu;
- } else {
- $profilelink = "<li class='nav_bar_search fa_awesome fa_awesome-search'></li>";
- $menu = $menu . $profilelink;
- return $menu;
- }
- }
- function no_privates($where) { // hides/filters posts marked private from the front end.
- if( is_admin() ) return $where;
- global $wpdb;
- return " $where AND {$wpdb->posts}.post_status != 'private' ";
- }
- function filter_pre_get_posts( $query ) { // changes PPP for concierge CPT
- if(is_post_type_archive('concierge_service')) {
- $query->set( 'posts_per_page',99 );
- }
- }
- function noo_social_icons($position = 'topbar', $direction = '') {
- if ($position == 'topbar') {
- // Top Bar social
- } else {
- // Bottom Bar social
- }
- $class = isset($direction) ? $direction : '';
- $html = array();
- $html[] = '<div class="noo-social social-icons ' . $class . '">';
- $social_list = array(
- 'facebook' => __('Facebook', NOO_TEXT_DOMAIN) ,
- 'twitter' => __('Twitter', NOO_TEXT_DOMAIN) ,
- 'google' => __('Google+', NOO_TEXT_DOMAIN) ,
- 'pinterest' => __('Pinterest', NOO_TEXT_DOMAIN) ,
- 'linkedin' => __('LinkedIn', NOO_TEXT_DOMAIN) ,
- 'rss' => __('RSS', NOO_TEXT_DOMAIN) ,
- 'youtube' => __('YouTube', NOO_TEXT_DOMAIN) ,
- 'instagram' => __('Instagram', NOO_TEXT_DOMAIN) ,
- );
- $social_html = array();
- foreach ($social_list as $key => $title) {
- $social = noo_get_option("noo_social_{$key}", '');
- if ($social) {
- $social_html[] = '<a href="' . $social . '" title="' . $title . '" target="_blank">';
- $social_html[] = '<div class="nav_share fa_awesome fa_awesome-' . $key . '-square"></div>';
- $social_html[] = '</a>';
- }
- }
- if(empty($social_html)) {
- $social_html[] = __('No Social Media Link',NOO_TEXT_DOMAIN);
- }
- $html[] = implode($social_html, "\n");
- $html[] = '</div>';
- echo implode($html, "\n");
- }
- function render_menu_search_form () {
- echo "<div id='menu_foldout_search' class='animoot menu_search_form_outter_wrapper minimized'>";
- NooProperty::advanced_map( false, '', true, '', false, $no_search_container,
- $source,!!$disable_search_form,$show_advanced_search_field, $map_height);
- echo "</div>";
- }
- function show_cons_single_item () {
- if (is_numeric($_POST['post_id'])) {
- $post = get_post($_POST['post_id'], ARRAY_A);
- include_once (get_stylesheet_directory(__FILE__) . '/templates/concierge/single_item.php'); // Handles the vim section. Modifying vims, membership renewal etc.
- } else {
- $content.='Sorry, nothing found';
- }
- echo $content;
- die;
- }
- function update_side_bar_calendar() {
- $the_date = (Aidee_date::validateDate($_POST['variables']['date'], 'Y-m-d') && $_POST['variables']['type']='date_change')
- ? $_POST['variables']['date']
- : "";
- $what_date_are_we_showing = Aidee_date::flip_around_dates ($from_format = 'Y-m-d', $to_format = 'D M j', $the_date);
- $query_args = array(
- 'post_type' => 'event',
- 'paged' => 0,
- 'posts_per_page' => -1,
- 'post_status' => 'publish',
- 'meta_key' => 'latest_date',
- 'orderby' => 'meta_value_num',
- 'meta_query' => array(
- 'relation' => 'AND',
- array(
- 'key' => 'booked_dates',
- 'value' => $the_date,
- 'compare' => 'LIKE',
- ),
- ),
- );
- $side_bar_posts = new WP_Query($query_args);
- include(plugin_dir_path(__FILE__)."/templates/event/build_side_bar.php");
- echo $string;
- exit;
- }
- function get_all_attached_images ($post_id) {
- $images = array();
- foreach (get_attached_media( 'image', $post_id ) as $image) {
- $get_image = wp_get_attachment_image_src( $image->ID, 'large' );
- $images[] = array(
- 'url'=>$get_image[0],
- 'title'=>$image->post_title,
- 'caption'=>$image->post_excerpt
- );
- }
- return $images;
- }
- function get_featured_image ($post_id, $size='size') { //used to get first/featured post attached to post. If none found, we check for ANY attached picture. Failing that
- // we return a placeholder image.
- $first_image = wp_get_attachment_image_src( get_post_thumbnail_id($post_id), ($size) ? $size : 'large' );
- if(!$first_image) {
- foreach (get_attached_media( 'image',$post_id ) as $image) {
- $get_image = wp_get_attachment_image_src( $image->ID, ($size) ? $size : 'large' );
- $first_image[] = $get_image[0];
- }
- }
- if (!$first_image)
- $first_image[0] = 'http://placehold.it/350x155';
- return $first_image[0];
- }
- function home_page_testimonials() {
- $posts = new wp_query( array('posts_per_page' => 3, 'post_type' => 'testimonial'));
- if($posts->have_posts()) {
- while($posts->have_posts()) {
- $string = '';
- $posts->the_post();
- $post_content = apply_filters('the_content', get_post_field('post_content', $posts->id));
- $img = $this->get_featured_image($posts->id);
- $header = get_field('name_of_person', $posts->id);
- $sub_header = get_field('small_quote', $posts->id);
- $string.="<div class='testimonial-desc'>";
- $string.=$post_content;
- $string.="</div>";
- $string.="<div class='our-customer-info col-md-4 col-md-offset-4'>";
- $string.="<a class='col-sm-6' href='#'><img class='alignnone size-full wp-image-6501' src='{$img}' alt='customer' width='70' height='70' /></a>";
- $string.="<div class='custom-desc col-sm-6'>";
- $string.="<h4>{$header}</h4>";
- $string.=$sub_header;
- $string.="</div>";
- $string.="</div>";
- $content.=do_shortcode("[slide type='content']" . $string . "[/slide]");
- }
- return do_shortcode("[slider animation='slide' slider_time='3000' slider_speed='600' indicator_position='top' visibility='all' indicator='true' class=' testimonial-slide']".$content."[/slider]");
- }
- }
- function set_html_content_type() {
- return 'text/html';
- }
- function send_email ($email='pcmagician@hotmail.com', $title = 'Test', $template='property_update_notice', $post=false) {
- if(!$post) global $post;
- $site_name = get_bloginfo('name');
- $admin_email = get_bloginfo('admin_email');
- $email = array();
- $email = 'pcmagician@hotmail.com';
- //$email[] = 'jessica@fireislandpines.com';
- $email[] = 'justin_a_lindsay@hotmail.com';
- $headers[] = "From: $site_name <$admin_email>";
- //$headers[] = 'Cc: Jessica K <jessica@fireislandpines.com>;';
- //$headers[] = 'Cc: Justin L <justin_a_lindsay@hotmail.com>;';
- require_once( plugin_dir_path( __FILE__ ) . '/include/css-inline-class/CssToInlineStyles.php');
- $css = file_get_contents(plugin_dir_path( __FILE__ ). 'c_assets/css/emailers.css'); // pulls in stylesheet and does its thing.
- $message.= "<div class='email_body'>";
- include_once(plugin_dir_path(__FILE__)."/templates/email/header.php");
- if($template && file_exists(plugin_dir_path(__FILE__)."/templates/email/$template")) {
- include_once(plugin_dir_path(__FILE__)."/templates/email/$template");
- } else {
- //$message.="no $template";
- }
- ob_start();
- $message.=ob_get_contents();
- $message.= "</div>";
- $emogrifier = new \Pelago\Emogrifier($message, $css);
- $message = $emogrifier->emogrify();
- echo($message);
- wp_mail($email, $title, $message, $headers);
- }
- function searchArrayValueByKey(array $array, $search) {
- foreach (new RecursiveIteratorIterator(new RecursiveArrayIterator($array)) as $key => $value) {
- if ($search === $key)
- return $value;
- }
- return false;
- }
- function get_agent_email_list () {
- $query_args = array(
- 'post_type' => 'event',
- 'paged' => 0,
- 'posts_per_page' => -1,
- );
- $agents = new WP_Query($query_args);
- if($agents->have_posts()) while($agents->have_posts()) {
- $agents->the_post();
- echo the_title();
- }
- die;
- }
- function auto_emailer_on_post_update($post_id, $post, $updated) {
- global $post;
- //$agent_email_list = $this->get_agent_email_list();
- if(!$post->type == 'noo_property') return;
- die;
- $title = get_the_title($post->ID);
- $user = wp_get_current_user();
- $post_link = get_the_permalink($post->ID);
- $name = $user->user_firstname . " " . $user->user_lastname;
- $name = ($name) ? $name : $user->display_name;
- foreach ($_POST['check_sum'] as $data=>$value){
- if (!in_array($data,array('_thumbnail_id', '_edit_last'))) {
- $conv_data = unserialize(urldecode($value));
- $check_array[$data] = $conv_data[0] ;
- }
- }
- $result = array_diff($check_array, $this->changed_values);
- if($result) {
- $this->email_body.="<div class='main_message'>This email is to inform you that {$name} updated {$title}</div>";
- $this->email_body.="<ul class='changes_list'>";
- foreach ($result as $key=>$v) {
- $this->email_body.="<li class='changes_made'>" . ucwords(str_replace(array('_'), array(' '), $key))."</li>";
- }
- $this->email_body.="</ul>";
- $this->email_body.="<div class='main_message'>You can view this listing <a href='{$post_link}'>here</a></div>";
- $this->send_email('pcmagician@hotmail.com', "{$title} has been updated by {$name}", 'property_update_notice.php');
- }
- }
- function cleanify_wp_editor_after() {
- global $post;
- if($post->post_type=='noo_property' || $post->post_type=='event') {
- echo "</div>";
- }
- }
- function resort_meta_boxes ($custom_post_name='post') {
- global $wp_meta_boxes;
- $resorted = array(
- 'Rental Description'=>'0',
- 'Property Details'=>'1',
- 'Dates Booked'=>'2',
- 'Extra Property Info'=>'3',
- 'Property Media'=>'4',
- 'Contact Information'=>'5',
- 'Property Notes'=>'6',
- 'Place in Map'=>'7',
- );
- foreach($wp_meta_boxes[$custom_post_name]['normal']['high'] as $k=>$v) {
- if (key_exists($v['title'], $resorted)) {
- $key = $resorted[$v['title']];
- $array[$key] = $wp_meta_boxes[$custom_post_name]['normal']['high'][$k];
- } else {
- $after_array[$k] = $v;
- }
- }
- ksort($array);
- $wp_meta_boxes['noo_property']['normal']['high'] = array_merge($array, $after_array );
- }
- function sort_rental_pricing_keys ($prices){
- $rent_order = array("Weekly"=>'0', 'Monthly'=>'1');
- $shares_order = array("Quarter Share"=>'0', "Half Share"=>'1', "Full Season"=>'2', );
- if(is_array($prices)) {
- foreach($prices as $key=>$v) {
- if(key_exists('share_type', $v)) { // Share handling
- if(key_exists($v['share_type'], $shares_order)) {
- $share_arrays[$shares_order[$v['share_type']]][] = $v;
- }
- }
- if(key_exists('price_per', $v)) { // Share handling
- if(key_exists($v['price_per'], $rent_order)) {
- $share_arrays[$rent_order[$v['price_per']]][] = $v;
- }
- }
- }
- if (is_array($share_arrays)) ksort($share_arrays);
- if(is_array($share_arrays)) $share_arrays = call_user_func_array('array_merge', $share_arrays);
- return $share_arrays;
- }
- }
- function cleanify_wp_editor() { // we're appending some things, and also changing the priority of a few things to achieve a nice
- // clean backend aesthetic.
- global $post;
- if($post->post_type=='noo_property') {
- $post_type = NooProperty::check_prop_for_type($post->ID);
- $class = ($post_type=='Both' || $post_type== 'Sale') ? '': "hide_post_editor";
- echo "<div class='faux_post_editor_wrapper {$class}' id='main_post_editor'>";
- echo '<h2 class="property_editor_first_editor">Sales Description</h2>';
- $this->resort_meta_boxes('noo_property');
- }
- if($post->post_type=='event') {
- echo "<div class='faux_post_editor_wrapper'>";
- echo '<h2 class="property_editor_first_editor">Event Description</h2>';
- }
- }
- function find_parent($array, $needle, $parent = null) {
- foreach ($array as $key => $value) {
- if (is_array($value)) {
- $pass = $parent;
- if (is_string($key)) {
- $pass = $key;
- }
- $found = $this->find_parent($value, $needle, $pass);
- if ($found !== false) {
- return $found;
- }
- } else if ($key === 'id' && $value === $needle) {
- return $parent;
- }
- }
- return false;
- }
- function show_template() {
- global $template;
- print_r($template);
- }
- function add_quick_menu () {
- echo "<div>";
- echo "<li><a href='#titlediv'>Top</a></li>";
- echo "<li><a href='#property_detail'>Property Details</a></li>";
- echo "<li><a href='#property_video'>Media</a></li>";
- echo "<li><a href='#acf-group_555035ed212aa'>Contact Info</a></li>";
- echo "<li><a href='#acf-group_555035ed30e34'>Extra Info</a></li>";
- echo "<li><a href='#acf-group_555035ed43e76'>Notes</a></li>";
- echo "<li><a href='#datepicker'>Booking Dates</a></li>";
- echo "<li><a href='#property_map'>Property Map</a></li>";
- echo "</div>";
- }
- function register_quick_menu () {
- remove_filter( 'user_can_richedit' , array(&$this, 'remove_advanced_edit'));
- add_meta_box( 'quick_menu', 'Quick Nav', array( $this, 'add_quick_menu' ), 'noo_property', 'normal', 'low');
- }
- function my_acf_load_field($field) {
- $field['required'] = true;
- return $field;
- }
- function save_book_meta ($post_id) {
- if($_POST['booked_dates']) $dates = explode(", ", $_POST['booked_dates']);
- if(is_array($dates)) {
- foreach ($dates as $date) {
- if(Aidee_date::validateDate($date, 'Y-m-d')) {
- $valid_dates[] = $date;
- }
- }
- reset($valid_dates); // we're grabbing the first date and storing it separately for queries
- $first_date = str_replace('-', '', $valid_dates[key($valid_dates)]);
- end($valid_dates); // we're also grabbing the last date and storing it separately for queries
- $last_date = str_replace('-', '', $valid_dates[key($valid_dates)]);
- update_post_meta($post_id, 'booked_dates', $valid_dates);//$valid_dates);
- update_post_meta($post_id, 'earliest_date', $first_date);
- update_post_meta($post_id, 'latest_date', $last_date);
- } else {
- update_post_meta($post_id, 'booked_dates', null);
- update_post_meta($post_id, 'earliest_date', null);
- update_post_meta($post_id, 'latest_date', null);
- }
- }
- function register_meta_boxes () {
- foreach (array('noo_property'=>'Dates Booked','Event'=>'Dates of Event') as $post_type=>$title) {
- add_meta_box( 'datepicker', $title, array( $this, 'add_date_picker' ), $post_type, 'normal', 'high');
- }
- }
- function add_date_picker ($post, $args) {
- $meta_values = get_post_meta( $post->ID, 'booked_dates', true);
- wp_localize_script('fi_back_end_scripts', 'data_obj', array('dates_booked'=>$meta_values));
- if ($post->post_type == 'noo_property') {
- echo "<span class='meta_helper'>";
- echo "<p>To mark a date as booked, just click the date. Highlighted dates indicate they are booked. Clicking a date a second time";
- echo "will remove the booking for that date.</p>";
- echo "</span>";
- }
- if ($post->post_type == 'event') {
- echo "<span class='meta_helper'>";
- echo "<p>To setup dates an event is available, merely click on dates in the calendar to highlight them. If an event spans multiple dates,";
- echo "then it will show up throughout dates in that range.</p>";
- echo "<p>When a user is viewing the events on the front end, events marked with dates that are expired (Past the current date vs the dates";
- echo "it's available), it will automaticall hide the event.</p>";
- echo "</span>";
- }
- echo "<div id='datepicker'></div>";
- echo "<input type='hidden' id='booked_dates' name='booked_dates'>";
- }
- function backend_enqueue_styles ($hook) { // teh backends
- wp_enqueue_script('jquery-ui-core');
- wp_register_style('back_end_css', get_stylesheet_directory_uri() . '/c_assets/css/back_end.css');
- wp_register_style('emailer_style', get_stylesheet_directory_uri() . '/c_assets/css/emailers.css');
- wp_enqueue_style('emailer_style');
- wp_enqueue_style('back_end_css');
- if($hook=='post.php') {
- $this->date_picker();
- wp_enqueue_script('date_picker_extension');
- }
- wp_register_script('fi_back_end_scripts', get_stylesheet_directory_uri() . '/c_assets/js/back_end.js', null, null, true);
- wp_enqueue_script('fi_back_end_scripts');
- }
- function enqueue_styles ($hook) { // for front end
- wp_dequeue_style( 'noo-main-style' );
- wp_register_style('noo-main-style-child', get_stylesheet_directory_uri() . '/assets/css/noo.css');
- wp_enqueue_style('noo-main-style-child');
- wp_register_style('unified', get_stylesheet_directory_uri() . '/assets/css/unified.css');
- wp_enqueue_style('unified');
- wp_register_style('font-awesome2', get_stylesheet_directory_uri() . '/assets/font-awesome/css/font-awesome.css');
- wp_enqueue_style('font-awesome2');
- wp_register_script('equalizer', get_stylesheet_directory_uri() . '/c_assets/js/equalize.js', null, null, true);
- wp_enqueue_script('equalizer');
- wp_register_script('concierge', get_stylesheet_directory_uri() . '/c_assets/js/concierge.js', null, null, true);
- wp_register_script('property_script', get_stylesheet_directory_uri() . '/c_assets/js/property_script.js', null, null, true);
- wp_register_script('property_calendar', get_stylesheet_directory_uri() . '/c_assets/js/property_calendar.js', null, null, true);
- $this->date_picker();
- $this->magnificent();
- $this->simple_slider();
- $this->front_end_calendar_js_hook();
- $this->jssor_slider();
- }
- function date_picker () {
- wp_register_style('date_picker_css', get_stylesheet_directory_uri() . '/c_assets/css/jquery-date-picker.css');
- wp_enqueue_style('date_picker_css');
- wp_register_script('date_picker_extension', get_stylesheet_directory_uri() . '/c_assets/js/date-picker-extension.js', null, null, true);
- }
- function magnificent () {
- wp_register_script('magnificent', get_stylesheet_directory_uri() . '/c_assets/magnificent/magnific-popup.js', null, null, true);
- wp_register_script('magnificent_trigger', get_stylesheet_directory_uri() . '/c_assets/magnificent/trigger.js', null, null, true);
- wp_enqueue_script('jQuery');
- wp_enqueue_script('magnificent');
- wp_enqueue_script('magnificent_trigger');
- wp_register_style('magnificent_css', get_stylesheet_directory_uri() . '/c_assets/magnificent/magnific-popup.css');
- wp_enqueue_style('magnificent_css');
- }
- function simple_slider () {
- wp_register_script('simple_slider', get_stylesheet_directory_uri() . '/c_assets/js/simple_slide.js', null, null, true);
- wp_register_style('simple_slider', get_stylesheet_directory_uri() . '/c_assets/css/simple_slide.css');
- wp_enqueue_style('simple_slider');
- }
- function upload_manager ($uploaded_file) {
- return wp_send_json(array('error'=>$uploaded_file['error'], 'results'=>$uploaded_file['message'], 'file_path'=>$uploaded_file['file']));
- }
- function merge_row_and_columns ($spread_sheet, $sheet_were_on, $row_were_on) {
- $data_heads = $spread_sheet->rows($sheet_were_on)[0];
- $data = $spread_sheet->rows($sheet_were_on)[$row_were_on];
- foreach($data_heads as $k=>$v)
- $array[str_replace(array(' ', '#', "$"), array('_','nmb', ''), $v)] = $data[$k];
- return $array;
- }
- function get_row_and_colum_count ($spread_sheet, $sheet_were_on=1) {
- $sheet_count = count($spread_sheet->sheetNames());
- $columns_count = count($spread_sheet->rows($sheet_were_on));
- return array('cols'=>$columns_count, 'sheets'=>$sheet_count);
- }
- function just_add_a_term($taxonomy, $term, $post_id) {
- $term_id = term_exists( $term, $taxonomy);
- if($term_id!=null) {
- wp_set_post_terms( $post_id, $term_id, $taxonomy, true );
- }
- }
- function create_imported_property_add_terms_compared($data_merged, $post_id, $array=array(), $taxonomy='', $compare_key) {
- // checks to see if a specfic imported data array key is set again an array, and adds it to the term list if it is.
- foreach($array as $k=>$v) {
- if($data_merged[$compare_key]==$k) {
- $term_id = term_exists( $v, $taxonomy);
- if($term_id!=null) {
- $term_id_array[] = $term_id['term_id'];
- }
- }
- }
- wp_set_post_terms( $post_id, $term_id_array, $taxonomy, FALSE );
- }
- function create_imported_property_add_terms($data_merged, $post_id, $array=array(), $taxonomy='') {
- // This function just checks to see if the imported data is set within the array, and then sets the tax term if it does.
- // useful for importing multiple taxonomies.
- foreach($array as $k=>$v) {
- if($data_merged[$k]!='') {
- $term_id = term_exists( $v, $taxonomy);
- if($term_id!=null) {
- $term_id_array[] = $term_id['term_id'];
- }
- }
- }
- wp_set_post_terms( $post_id, $term_id_array, $taxonomy, FALSE );
- }
- function create_imported_property_create_data ($data_merged, $post_id, $title, $already_exists) {
- /////////////////////////////////////// Tagging Features ///.//////////////////////////////////////////////////
- $features_array = array('Fpl'=>'Fire Place (Gas)',
- 'Pool'=>'Pool',
- 'H/T'=>'Hot Tub',
- 'A/C'=>'AC'
- );
- /////////////////////////////////////// Rental Information ///.//////////////////////////////////////////////////
- if($data_merged['Rent_']!='' || $data_merged['Rent']!='') {
- $old_pricing_info = get_field('field_55504b2c23183', $post_id); // contact_info
- if(!$old_pricing_info) {
- $old_pricing_info = array();
- }
- $old_pricing_info[] = array('price'=>($data_merged['Rent_']!='') ? $data_merged['Rent_'] : $data_merged['Rent'], // number_type
- 'price_per'=>$data_merged['Term'] // number_number
- );
- update_field( 'field_55504b2c23183', $old_pricing_info, $post_id );
- }
- ///////////////////////////////// Contact Information section ///.//////////////////////////////////////////////////
- $old_contact_info = get_field('field_554adcd507fe2', $post_id); // contact_info
- if(!$old_contact_info)
- $old_contact_info = array();
- if($data_merged['Rent_'] || $data_merged['Rent']) {
- $name = ($data_merged['Landlord']) ? explode(" ", $data_merged['Landlord']) : explode(" ", "None Entered") ;
- } else {
- $name = ($data_merged['Seller']) ? explode(" ", $data_merged['Seller']) : explode(" ", "None Entered") ;
- }
- $old_contact_info[] = array('field_554adcf607fe3' => $name[0], // first name
- 'field_554add0107fe4' => $name[1],//last_name
- 'field_554ae203ba905'=>array( // contact_numbers
- array('number_type'=>'Phone', // number_type
- 'number_number'=>($data_merged['Phone_nmb']) ? $data_merged['Phone_nmb'] : '000-000-0000' // number_number
- )),
- 'field_554add0707fe5'=> array( // email_address
- array('email_addy'=>($data_merged['Email_']) ? $data_merged['Email_'] : "none@entered.com"
- )), // email
- 'field_55831cead156f' => ($data_merged['Listing_Price']!='') ? "Seller" : "Landlord",
- );
- /////////////////////////////////////// Address ///.//////////////////////////////////////////////////
- update_field( 'field_554adcd507fe2', $old_contact_info, $post_id );
- /////////////////////////////////////// Tagging ///.//////////////////////////////////////////////////
- $status_array = array('OTM'=>'Off the Market', 'SOLD'=>'Sold');
- $this->create_imported_property_add_terms($data_merged, $post_id, $features_array, 'property_features');
- if($data_merged['Listing_Price'])
- $this->just_add_a_term('property_category', 'Sale', $post_id);
- if($data_merged['Rent_'] || $data_merged['Rent'])
- $this->just_add_a_term('property_category', 'Rental', $post_id);
- $this->create_imported_property_add_terms_compared($data_merged, $post_id, $status_array, 'market_availability', 'Status');
- /////////////////////////////////////// Misc Data /////////////////////////////////////////////////////
- $correlated_post_array = array('Listing_Price'=>'_price',
- 'nmbBR'=>'_bedrooms',
- 'nmbBTH'=>'_bathrooms',
- 'Lot_Sz'=>'_area',
- );
- foreach($correlated_post_array as $key=>$value) {
- if($key=='Listing_Price' && (!$data_merged['Listing_Price'])) continue; // because we dont want to override pricing
- update_post_meta($post_id, $value, $data_merged[$key], true);
- }
- update_post_meta($post_id, '_address', $title, true);
- $correlated_acf_array = array('Key_nmb'=>'field_554f041f53a00',
- 'Pines_nmb'=>'field_55827f8769cb0',
- 'Lot_nmb'=>'field_558271aa2e755',
- 'Taxes'=>'field_55511f6faf880',
- 'Keynmb'=>'field_554f041f53a00',
- 'Notes'=>'agent_notes',
- 'Walk'=>'walk');
- foreach($correlated_acf_array as $key=>$value) {
- if($value=='') continue; // so we dont overwrite values with blank data.
- update_field( $value, $data_merged[$key], $post_id );
- }
- }
- function create_imported_property ($data_merged, $title) {
- remove_action( 'save_post_noo_property', array(&$this, 'auto_emailer_on_post_update'), 10, 3 ); // because yeah, we dont want to spam.
- $already_exists = $this->wp_exist_post_by_title($title);
- if($already_exists==null) {
- $new_post = array(
- 'post_title' => wp_strip_all_tags( $title ),
- 'post_content' => 'Lorem Ipsum Lorem Ipsum Lorem Ipsum Lorem Ipsum Lorem Ipsum Lorem Ipsum Lorem Ipsum Lorem Ipsum Lorem Ipsum Lorem
- Ipsum Lorem Ipsum Lorem Ipsum Lorem Ipsum Lorem Ipsum ',
- 'post_status' => 'publish',
- 'post_author' => 1,
- 'post_type'=>'noo_property',
- );
- $post_id = wp_insert_post( $new_post );
- $this->create_imported_property_create_data($data_merged, $post_id, $title, $already_exists);
- return array('status'=>true, 'message'=>"{$title} Successfully Imported. ");
- } else {
- $post_id = $already_exists['ID'];
- $this->create_imported_property_create_data($data_merged, $post_id, $title, $already_exists);
- return array('status'=>false, 'message'=>"{$title} Already exists. Data appended instead. ");
- }
- }
- function wp_exist_post_by_title($title_str) {
- global $wpdb;
- return $wpdb->get_row("SELECT ID FROM wp_posts WHERE post_type = 'noo_property' AND (post_title = '{$title_str}')", 'ARRAY_A');
- }
- function xls_parser ($sheet_were_on=1, $row_were_on=1) {
- require_once (plugin_dir_path(__FILE__).'include/Excell_Parser/simplexlsx.class.php');
- if (!file_exists($_POST['file_path'])) // checks to ensure we're parsing a file.
- wp_send_json(array('results'=>$_POST['file_path'].'Not found, please try uploading a new file.'));
- $sheet_were_on = (is_numeric($_POST['sheet_were_on'])) ? $_POST['sheet_were_on'] : $sheet_were_on;
- $row_were_on = (is_numeric($_POST['row_were_on'])) ? $_POST['row_were_on'] : $row_were_on;
- //if ($row_were_on>40) die;
- $spread_sheet = new SimpleXLSX($_POST['file_path']);
- $row_and_sheet_count = $this->get_row_and_colum_count($spread_sheet, $sheet_were_on);
- $data_merged = $this->merge_row_and_columns($spread_sheet, $sheet_were_on, $row_were_on);
- $results.="<h3 class='import_header'>Sheet Name: " . $spread_sheet->sheetNames()[$sheet_were_on] ."</h3>";
- $results.="<li class='imported_row'><span class='field'>Sheet</span><span class='data'>{$sheet_were_on} of {$row_and_sheet_count['sheets']}</span></li> ";
- $results.= "<li class='imported_row'><span class='field'>Row</span><span class='data'>{$row_were_on} of ".($row_and_sheet_count['cols']-1)."</span></li>";
- foreach($data_merged as $k=>$v)
- $results.="<li class='imported_row'><span class='field'>".str_replace(array('_','nmb', ''), array(' ', '#', "$"), $k)."</span> <span class='data'>$v</span></li>";
- $title = ($data_merged['Lot_nmb']) ? $data_merged['Lot_nmb'] : "";
- $title.= ($data_merged['Lot_nmb']) ? " " :"";
- $title.= $data_merged['Walk'];
- $title.= ($data_merged['Walk']) ? " Walk" : "";
- $imported = $this->create_imported_property($data_merged, $title);
- $results.= $imported['message'];
- $done = false;
- // do stuff here.
- $row_were_on ++;
- if ($row_were_on > $row_and_sheet_count['cols']) {
- $sheet_were_on++;
- $row_were_on = 1;
- }
- if ($sheet_were_on > $row_and_sheet_count['sheets']) {
- $done = true;
- }
- wp_send_json(array('results'=>$results, 'sheet_were_on'=>$sheet_were_on, 'row_were_on'=>$row_were_on,'done'=>$done));
- }
- function jssor_slider ($hook='register') {
- if($hook=='register') {
- wp_register_script('jssor_1', get_stylesheet_directory_uri() . '/c_assets/jssor/js/jssor.js', null, null, true);
- wp_register_script('jssor_2', get_stylesheet_directory_uri() . '/c_assets/jssor/js/jssor.slider.js', null, null, true);
- wp_register_script('jssor_trigger', get_stylesheet_directory_uri() . '/c_assets/js/jssor-trigger.js', null, null, true);
- wp_register_style('jssor-css', get_stylesheet_directory_uri() . '/c_assets/css/jssor.css');
- }
- if($hook=='queue') {
- wp_enqueue_script('jssor_1');
- wp_enqueue_script('jssor_2');
- wp_enqueue_script('jssor_trigger');
- wp_enqueue_style('jssor-css');
- }
- }
- function front_end_calendar_js_hook () {
- wp_register_style('front_end_event_calendar_style', get_stylesheet_directory_uri() . '/c_assets/fullcalendar/fullcalendar.min.css');
- wp_register_script('front_end_event_calendar_moment', get_stylesheet_directory_uri() . '/c_assets/fullcalendar/lib/moment.min.js', null, null, true);
- wp_register_script('front_end_event_calendar_base', get_stylesheet_directory_uri() . '/c_assets/fullcalendar/fullcalendar.js', null, null, true);
- wp_register_script('front_end_event_calendar', get_stylesheet_directory_uri() . '/c_assets/js/event_calendar.js', null, null, true);
- }
- }
- new fire_island();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement