コード例 #1
0
 /**
  * Hooks into save_post function and saves additional property data
  *
  * @todo Add some sort of custom capability so not only admins can make properties as featured. i.e. Agents can make their own properties featured.
  * @since 1.04
  * @param null $post_id
  * @return null
  */
 function save_property($post_id = null)
 {
     global $wp_properties, $wp_version;
     $_wpnonce = (version_compare($wp_version, '3.5', '>=') ? 'update-post_' : 'update-property_') . $post_id;
     if (!isset($_POST['_wpnonce']) || !wp_verify_nonce($_POST['_wpnonce'], $_wpnonce) || $_POST['post_type'] !== 'property') {
         return $post_id;
     }
     if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
         return $post_id;
     }
     $update_data = $_REQUEST['wpp_data']['meta'];
     //** Neccessary meta data which is required by Supermap Premium Feature. Should be always set even the Supermap disabled. peshkov@UD */
     if (empty($_REQUEST['exclude_from_supermap'])) {
         if (!metadata_exists('post', $post_id, 'exclude_from_supermap')) {
             $update_data['exclude_from_supermap'] = 'false';
         }
     }
     if (!isset($update_data['latitude']) || (double) $update_data['latitude'] == 0) {
         $update_data['latitude'] = '';
     }
     if (!isset($update_data['longitude']) || (double) $update_data['longitude'] == 0) {
         $update_data['longitude'] = '';
     }
     /* get old coordinates and location */
     $old_lat = get_post_meta($post_id, 'latitude', true);
     $old_lng = get_post_meta($post_id, 'longitude', true);
     $geo_data = array('old_coordinates' => empty($old_lat) || empty($old_lng) ? "" : array('lat' => $old_lat, 'lng' => $old_lng), 'old_location' => !empty($wp_properties['configuration']['address_attribute']) ? get_post_meta($post_id, $wp_properties['configuration']['address_attribute'], true) : '');
     //    die( '<pre>' . $post_id . print_r( $update_data, true ) . '</pre>' );
     foreach ($update_data as $meta_key => $meta_value) {
         $attribute_data = UsabilityDynamics\WPP\Attributes::get_attribute_data($meta_key);
         $meta_value = html_entity_decode($meta_value);
         $meta_value = stripslashes($meta_value);
         /* Handle logic for featured property. */
         if ($meta_key == 'featured') {
             //* Only admins can mark properties as featured. */
             if (!current_user_can('manage_options')) {
                 //** But be sure that meta 'featured' exists at all */
                 if (!metadata_exists('post', $post_id, $meta_key)) {
                     $meta_value = 'false';
                 } else {
                     continue;
                 }
             }
             do_action('wpp::toggle_featured', $meta_value, $post_id);
         }
         //* Remove certain characters */
         if (isset($attribute_data['currency']) || isset($attribute_data['numeric'])) {
             $meta_value = str_replace(array("\$", ","), '', $meta_value);
         }
         //* Overwrite old post meta allowing only one value */
         delete_post_meta($post_id, $meta_key);
         add_post_meta($post_id, $meta_key, $meta_value);
     }
     //* Check if property has children */
     $children = get_children(array('post_parent' => $post_id, 'post_type' => 'property'));
     //* Write any data to children properties that are supposed to inherit things */
     //* 1) Go through all children */
     foreach ((array) $children as $child_id => $child_data) {
         //* Determine child property_type */
         $child_property_type = get_post_meta($child_id, 'property_type', true);
         //* Check if child's property type has inheritence rules, and if meta_key exists in inheritance array */
         if (isset($wp_properties['property_inheritance'][$child_property_type]) && is_array($wp_properties['property_inheritance'][$child_property_type])) {
             foreach ($wp_properties['property_inheritance'][$child_property_type] as $i_meta_key) {
                 $parent_meta_value = get_post_meta($post_id, $i_meta_key, true);
                 //* inheritance rule exists for this property_type for this meta_key */
                 update_post_meta($child_id, $i_meta_key, $parent_meta_value);
             }
         }
     }
     $_gpid = WPP_F::maybe_set_gpid($post_id);
     do_action('save_property', $post_id, array('children' => $children, 'gpid' => $_gpid, 'update_data' => $update_data, 'geo_data' => $geo_data));
     /**
      * Flush all object caches related to current property
      */
     \UsabilityDynamics\WPP\Property_Factory::flush_cache($post_id);
     /**
      * Flush WP-Property caches
      */
     \WPP_F::clear_cache();
 }
コード例 #2
0
 /**
  *
  * Extends get_post by dumping all metadata into array
  *
  * @param $id
  * @param string $args
  *
  * @return bool|mixed|object|stdClass|void
  */
 function get_property($id, $args = "")
 {
     return \UsabilityDynamics\WPP\Property_Factory::get($id, $args);
 }
コード例 #3
0
ファイル: class-export.php プロジェクト: Juni4567/mycashflow
 /**
  * Exports all properties to CSV file
  */
 public function maybe_export_properties_to_scv()
 {
     if (!empty($_REQUEST['action']) && $_REQUEST['action'] == 'wpp_export_to_scv' && !empty($_REQUEST['nonce']) && wp_verify_nonce($_REQUEST['nonce'], 'export_properties_to_scv')) {
         // output headers so that the file is downloaded rather than displayed
         header('Content-Type: text/csv; charset=utf-8');
         header('Content-Disposition: attachment; filename=properties.csv');
         $headings = array('ID' => __('ID', ud_get_wp_property('domain')), 'post_title' => __('Title', ud_get_wp_property('domain')), 'post_content' => __('Content', ud_get_wp_property('domain')), 'post_date' => __('Date', ud_get_wp_property('domain')), 'post_modified' => __('Modified Date', ud_get_wp_property('domain')), 'post_parent' => __('Falls Under', ud_get_wp_property('domain')), 'menu_order' => __('Menu Order', ud_get_wp_property('domain')), 'post_author' => __('Author', ud_get_wp_property('domain')), 'property_type_label' => __('Property Type', ud_get_wp_property('domain')));
         $headings = array_merge($headings, (array) ud_get_wp_property('property_stats', array()));
         $headings = array_merge($headings, (array) ud_get_wp_property('property_meta', array()));
         foreach ((array) ud_get_wp_property('geo_type_attributes', array()) as $k) {
             $headings[$k] = \WPP_F::de_slug($k);
         }
         $headings['latitude'] = __('Latitude', ud_get_wp_property('domain'));
         $headings['longitude'] = __('Longitude', ud_get_wp_property('domain'));
         $headings['permalink'] = __('Permalink', ud_get_wp_property('domain'));
         // create a file pointer connected to the output stream
         $output = fopen('php://output', 'w');
         // output the column headings
         fputcsv($output, array_values($headings));
         $ids = \WPP_F::get_properties();
         $keys = array_keys($headings);
         foreach ($ids as $id) {
             $property = Property_Factory::get($id, array('get_children' => 'false', 'load_gallery' => 'false', 'load_thumbnail' => 'true', 'load_parent' => 'false'));
             $data = array();
             foreach ($keys as $k) {
                 $v = isset($property[$k]) ? $property[$k] : '';
                 if (is_array($v)) {
                     $v = implode(',', $v);
                 }
                 switch ($k) {
                     case 'post_content':
                         $v = strip_shortcodes($v);
                         $v = apply_filters('the_content', $v);
                         $v = str_replace(']]>', ']]&gt;', $v);
                         $v = wp_trim_words($v, 55, '...');
                         break;
                     case 'author':
                         $v = get_the_author_meta('display_name', $v);
                         break;
                 }
                 $data[$k] = $v;
             }
             fputcsv($output, $data);
         }
         exit;
     }
 }
コード例 #4
0
 /**
  * Load property information into an array or an object
  * Deprecated since 2.1.1
  *
  * @param mix ID or post object
  * @param array $args
  * @return mix array or object
  */
 public static function get_property($id, $args = array())
 {
     return \UsabilityDynamics\WPP\Property_Factory::get($id, $args);
 }