public static function create(&$state)
 {
     $title = 'Untitled Listing';
     if (isset($state->title)) {
         $title = $state->title;
     } else {
         $title_field = wpbdp_get_form_fields(array('association' => 'title', 'unique' => true));
         if (isset($state->fields[$title_field->get_id()])) {
             $title = $state->fields[$title_field->get_id()];
         }
     }
     $title = trim(strip_tags($title));
     $post_data = array('post_title' => $title, 'post_status' => 'pending', 'post_type' => WPBDP_POST_TYPE);
     $post_id = wp_insert_post($post_data);
     // Create author user if needed.
     $current_user = wp_get_current_user();
     if ($current_user->ID == 0) {
         if (wpbdp_get_option('require-login')) {
             throw new Exception('Login required.');
         }
         // Create user.
         if ($email_field = wpbdp_get_form_fields(array('validators' => 'email', 'unique' => 1))) {
             $email = $state->fields[$email_field->get_id()];
             if (email_exists($email)) {
                 $post_author = get_user_by('email', $email);
                 $post_author = $post_author->ID;
             } else {
                 $post_author = wp_insert_user(array('user_login' => 'guest_' . wp_generate_password(5, false, false), 'user_email' => $email, 'user_pass' => wp_generate_password()));
             }
             wp_update_post(array('ID' => $post_id, 'post_author' => $post_author));
         }
     }
     return new self($post_id);
 }
 /**
  * Tries to delete this field from the database.
  * @return mixed True if successfully deleted, WP_Error in the other case
  */
 public function delete()
 {
     if (!$this->id) {
         return new WP_Error('wpbdp-delete-error', _x('Invalid field ID', 'form-fields-api', 'WPBDM'));
     }
     global $wpbdp;
     $flags = $wpbdp->formfields->get_association_flags($this->association);
     if (in_array('required', $flags)) {
         $otherfields = wpbdp_get_form_fields(array('association' => $this->association));
         if (!$otherfields || $otherfields[0]->get_id() == $this->id) {
             return new WP_Error('wpbdp-delete-error', _x("This form field can't be deleted because it is required for the plugin to work.", 'form-fields api', 'WPBDM'));
         }
     }
     global $wpdb;
     if ($wpdb->query($wpdb->prepare("DELETE FROM  {$wpdb->prefix}wpbdp_form_fields WHERE id = %d", $this->id)) !== false) {
         $this->type->cleanup($this);
         wp_cache_delete($this->id, 'wpbdp formfields');
         $this->id = 0;
     } else {
         return new WP_Error('wpbdp-delete-error', _x('An error occurred while trying to delete this field.', 'form-fields-api', 'WPBDM'));
     }
     $api = wpbdp_formfields_api();
     $api->_calculate_short_names();
     return true;
 }
 public function __construct($listing_id = 0)
 {
     $this->editing = $listing_id > 0 ? true : false;
     if ($listing_id > 0) {
         $listing = WPBDP_Listing::get($listing_id);
         if (!$listing || !$listing->is_published()) {
             throw new Exception('You can not edit this listing.');
         }
         $this->listing_id = $listing_id;
         $categories = $listing->get_categories('all');
         foreach ($categories as &$category) {
             $this->categories[$category->id] = $category->fee_id;
         }
         // Image information.
         $this->images = $listing->get_images('ids');
         $this->thumbnail_id = $listing->get_thumbnail_id();
         // Fields.
         $fields = wpbdp_get_form_fields(array('association' => '-category'));
         foreach ($fields as &$f) {
             $this->fields[$f->get_id()] = $f->value($this->listing_id);
         }
         // Recover additional information.
         do_action_ref_array('wpbdp_submit_state_init', array(&$this));
     }
 }
?>
</th>
            <th class="field-is-required"><?php 
_ex('Required?', 'admin csv-import', 'WPBDM');
?>
</th>
            <th class="field-is-multivalued"><?php 
_ex('Multivalued?', 'admin csv-import', 'WPBDM');
?>
</th>
        </tr>
    </thead>
    <tbody>
    <?php 
$i = 0;
foreach (wpbdp_get_form_fields() as $field) {
    ?>
        <?php 
    if ('custom' == $field->get_association()) {
        continue;
    }
    ?>
        <tr class="<?php 
    echo $i % 2 == 0 ? 'alt' : '';
    ?>
">
            <td class="header-name"><?php 
    echo $field->get_short_name();
    ?>
</td>
            <td class="field-label"><?php 
 public static function prepare_set($listing_id, $display)
 {
     $res = (object) array('fields' => array(), 'social' => array());
     $form_fields = wpbdp_get_form_fields();
     $form_fields = apply_filters_ref_array('wpbdp_render_listing_fields', array(&$form_fields, $listing_id));
     foreach ($form_fields as &$f) {
         if (!$f->display_in($display)) {
             continue;
         }
         if ($f->display_in('social')) {
             $res->social[$f->get_id()] = new self($f, $listing_id, 'social');
         } else {
             $res->fields[$f->get_id()] = new self($f, $listing_id, $display);
         }
     }
     return $res;
 }
Beispiel #6
0
 public function search()
 {
     $_REQUEST = stripslashes_deep($_REQUEST);
     $search_args = array();
     $results = array();
     if (isset($_GET['dosrch'])) {
         $search_args['q'] = wpbdp_getv($_GET, 'q', null);
         $search_args['fields'] = array();
         // standard search fields
         $search_args['extra'] = array();
         // search fields added by plugins
         foreach (wpbdp_getv($_GET, 'listingfields', array()) as $field_id => $field_search) {
             $search_args['fields'][] = array('field_id' => $field_id, 'q' => $field_search);
         }
         foreach (wpbdp_getv($_GET, '_x', array()) as $label => $field) {
             $search_args['extra'][$label] = $field;
         }
         $listings_api = wpbdp_listings_api();
         if ($search_args['q'] && !$search_args['fields'] && !$search_args['extra']) {
             $results = $listings_api->quick_search($search_args['q']);
         } else {
             $results = $listings_api->search($search_args);
         }
     }
     $form_fields = wpbdp_get_form_fields(array('display_flags' => 'search', 'validators' => '-email'));
     $fields = '';
     foreach ($form_fields as &$field) {
         $field_value = isset($_REQUEST['listingfields']) && isset($_REQUEST['listingfields'][$field->get_id()]) ? $field->convert_input($_REQUEST['listingfields'][$field->get_id()]) : $field->convert_input(null);
         $fields .= $field->render($field_value, 'search');
     }
     $args = array('post_type' => WPBDP_POST_TYPE, 'posts_per_page' => wpbdp_get_option('listings-per-page') > 0 ? wpbdp_get_option('listings-per-page') : -1, 'paged' => get_query_var('paged') ? get_query_var('paged') : 1, 'post__in' => $results ? $results : array(0), 'orderby' => wpbdp_get_option('listings-order-by', 'date'), 'order' => wpbdp_get_option('listings-sort', 'ASC'));
     $args = apply_filters('wpbdp_search_query_posts_args', $args, $search_args);
     query_posts($args);
     wpbdp_push_query($GLOBALS['wp_query']);
     $html = wpbdp_render('search', array('fields' => $fields, 'searching' => isset($_GET['dosrch']) ? true : false, 'show_form' => !isset($_GET['dosrch']) || wpbdp_get_option('show-search-form-in-results')), false);
     wp_reset_query();
     wpbdp_pop_query();
     return $html;
 }
Beispiel #7
0
/**
 * @deprecated
 * @since 2.3
 */
function wpbusdirman_get_the_business_email($post_id)
{
    $email_mode = wpbdp_get_option('listing-email-mode');
    $email_field_value = '';
    if ($email_field = wpbdp_get_form_fields('validators=email&unique=1')) {
        $email_field_value = trim($email_field->plain_value($post_id));
    }
    if ($email_mode == 'field' && !empty($email_field_value)) {
        return $email_field_value;
    }
    $author_email = '';
    $post = get_post($post_id);
    $author_email = trim(get_the_author_meta('user_email', $post->post_author));
    if (empty($author_email) && !empty($email_field_value)) {
        return $email_field_value;
    }
    return $author_email ? $author_email : '';
}
 private function set_header($header)
 {
     if (!$header || count($header) == 1 && is_null($header[0])) {
         throw new Exception('Invalid header');
     }
     $required_fields = wpbdp_get_form_fields('validators=required');
     $fields_in_header = array_map('trim', $header);
     foreach ($required_fields as $rf) {
         if (!in_array($rf->get_short_name(), $fields_in_header, true)) {
             throw new Exception(sprintf('Required header column "%s" missing', $rf->get_short_name()));
         }
     }
     $this->header = array();
     $short_names = get_option('wpbdp-field-short-names', array());
     foreach ($fields_in_header as $short_name) {
         $field_id = 0;
         $key = array_search($short_name, $short_names, true);
         if (false === $key) {
             $field_id = 0;
         }
         if ($f = wpbdp_get_form_field($key)) {
             $field_id = $f->get_id();
         }
         $this->header[] = array('short_name' => $short_name, 'field_id' => $field_id);
     }
 }
Beispiel #9
0
 public function __construct($settings, $workingdir = null, $listings = array())
 {
     global $wpdb;
     $this->settings = array_merge($this->settings, $settings);
     // Setup columns.
     if ($this->settings['generate-sequence-ids']) {
         $this->columns['sequence_id'] = 'sequence_id';
     }
     $fields = wpbdp_get_form_fields();
     foreach ($fields as &$f) {
         $this->columns[$f->get_short_name()] = $f;
     }
     if ($this->settings['export-images']) {
         $this->columns['images'] = 'images';
     }
     if ($this->settings['include-users']) {
         $this->columns['username'] = '******';
     }
     if ($this->settings['include-sticky-status']) {
         $this->columns['featured_level'] = 'featured_level';
     }
     if ($this->settings['include-expiration-date']) {
         $this->columns['expires_on'] = 'expires_on';
     }
     // Setup working directory.
     if (!$workingdir) {
         $direrror = '';
         $upload_dir = wp_upload_dir();
         if (!$upload_dir['error']) {
             $csvexportsdir = rtrim($upload_dir['basedir'], DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . 'wpbdp-csv-exports';
             if (is_dir($csvexportsdir) || mkdir($csvexportsdir)) {
                 $this->workingdir = rtrim($csvexportsdir . DIRECTORY_SEPARATOR . uniqid(), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
                 if (!mkdir($this->workingdir, 0777)) {
                     $direrror = _x('Could not create a temporary directory for handling this CSV export.', 'admin csv-export', 'WPBDM');
                 }
             } else {
                 $direrror = _x('Could not create wpbdp-csv-exports directory.', 'admin csv-export', 'WPBDM');
             }
         }
         if ($direrror) {
             throw new Exception(sprintf(_x('Error while creating a temporary directory for CSV export: %s', 'admin csv-export', 'WPBDM'), $direrror));
         }
     } else {
         $this->workingdir = $workingdir;
     }
     if ($listings) {
         $this->listings = $listings;
     } else {
         switch ($this->settings['listing_status']) {
             case 'publish+draft':
                 $post_status = array('publish', 'draft', 'pending');
                 break;
             case 'publish':
                 $post_status = 'publish';
                 break;
             case 'all':
             default:
                 $post_status = array('publish', 'draft', 'pending', 'future', 'trash');
                 break;
         }
         $this->listings = get_posts(array('post_status' => $post_status, 'posts_per_page' => -1, 'post_type' => WPBDP_POST_TYPE, 'fields' => 'ids'));
     }
 }
 function register_form_fields_strings()
 {
     if (isset($_GET['action']) || !function_exists('icl_register_string')) {
         return;
     }
     $fields = wpbdp_get_form_fields();
     foreach ($fields as &$f) {
         icl_register_string('Business Directory Plugin', sprintf('Field #%d - label', $f->get_id()), $f->get_label());
         if ($f->get_description()) {
             icl_register_string('Business Directory Plugin', sprintf('Field #%d - description', $f->get_id()), $f->get_description());
         }
     }
 }