Exemplo n.º 1
0
 public function render_search_fields($instance, $widget_id, $finds = array())
 {
     /** first validation **/
     if (!$instance) {
         return array();
     }
     $path = WPL_ABSPATH . DS . 'libraries' . DS . 'widget_search' . DS . 'frontend';
     $files = array();
     if (wpl_folder::exists($path)) {
         $files = wpl_folder::files($path, '.php$');
     }
     $fields = $instance['data'];
     uasort($fields, array('wpl_global', 'wpl_array_sort'));
     $rendered = array();
     foreach ($fields as $key => $field) {
         /** proceed to next field if field is not enabled **/
         if (!isset($field['enable']) or isset($field['enable']) and $field['enable'] != 'enable') {
             continue;
         }
         /** Fix empty id issue **/
         if ((!isset($field['id']) or isset($field['id']) and !$field['id']) and $key) {
             $field['id'] = $key;
         }
         $field_data = (array) wpl_flex::get_field($field['id']);
         if (!$field_data) {
             continue;
         }
         $field['name'] = $field_data['name'];
         $type = $field_data['type'];
         $field_id = $field['id'];
         $options = json_decode($field_data['options'], true);
         $display = '';
         $done_this = false;
         $html = '';
         /** listing and property type specific **/
         if (trim($field_data['listing_specific']) != '') {
             $specified_listings = explode(',', trim($field_data['listing_specific'], ', '));
             $this->listing_specific_array[$field_data['id']] = $specified_listings;
         } elseif (trim($field_data['property_type_specific']) != '') {
             $specified_property_types = explode(',', trim($field_data['property_type_specific'], ', '));
             $this->property_type_specific_array[$field_data['id']] = $specified_property_types;
         }
         /** Accesses **/
         if (trim($field_data['accesses']) != '') {
             $accesses = explode(',', trim($field_data['accesses'], ', '));
             $cur_membership_id = wpl_users::get_user_membership();
             if (!in_array($cur_membership_id, $accesses)) {
                 continue;
             }
         }
         if (isset($finds[$type])) {
             $html .= '<div class="wpl_search_field_container ' . (isset($field['type']) ? $field['type'] . '_type' : '') . ' ' . ((isset($field['type']) and $field['type'] == 'predefined') ? 'wpl_hidden' : '') . '" id="wpl' . $widget_id . '_search_field_container_' . $field['id'] . '">';
             include $path . DS . $finds[$type];
             $html .= '</div>';
             $rendered[$field_id]['id'] = $field_id;
             $rendered[$field_id]['field_data'] = $field_data;
             $rendered[$field_id]['field_options'] = json_decode($field_data['options'], true);
             $rendered[$field_id]['search_options'] = isset($field['extoption']) ? $field['extoption'] : NULL;
             $rendered[$field_id]['html'] = $html;
             $rendered[$field_id]['current_value'] = isset($current_value) ? $current_value : NULL;
             $rendered[$field_id]['display'] = $display;
             continue;
         }
         $html .= '<div class="wpl_search_field_container ' . (isset($field['type']) ? $field['type'] . '_type' : '') . ' ' . ((isset($field['type']) and $field['type'] == 'predefined') ? 'wpl_hidden' : '') . '" id="wpl' . $widget_id . '_search_field_container_' . $field['id'] . '" style="' . $display . '">';
         foreach ($files as $file) {
             include $path . DS . $file;
             /** proceed to next field **/
             if ($done_this) {
                 $finds[$type] = $file;
                 break;
             }
         }
         $html .= '</div>';
         $rendered[$field_id]['id'] = $field_id;
         $rendered[$field_id]['field_data'] = $field_data;
         $rendered[$field_id]['field_options'] = json_decode($field_data['options'], true);
         $rendered[$field_id]['search_options'] = isset($field['extoption']) ? $field['extoption'] : NULL;
         $rendered[$field_id]['html'] = $html;
         $rendered[$field_id]['current_value'] = isset($current_value) ? $current_value : NULL;
         $rendered[$field_id]['display'] = $display;
     }
     return $rendered;
 }
Exemplo n.º 2
0
 /**
  * Generates wizard form using dbst fields
  * @author Howard R <*****@*****.**>
  * @param objects $fields
  * @param array $values
  * @param int $item_id
  * @param array $finds
  * @return void
  */
 public function generate_wizard_form($fields, $values, $item_id = 0, &$finds = array())
 {
     /** first validation **/
     if (!$fields) {
         return;
     }
     /** get files **/
     $path = WPL_ABSPATH . DS . 'libraries' . DS . 'dbst_wizard';
     $files = array();
     if (wpl_folder::exists($path)) {
         $files = wpl_folder::files($path, '.php$', false, false);
     }
     $wpllangs = wpl_global::check_multilingual_status() ? wpl_addon_pro::get_wpl_languages() : array();
     $has_more_details = false;
     foreach ($fields as $key => $field) {
         if (!$field) {
             return;
         }
         $done_this = false;
         $type = $field->type;
         $label = $field->name;
         $mandatory = $field->mandatory;
         $options = json_decode($field->options, true);
         $value = isset($values[$field->table_column]) ? stripslashes($values[$field->table_column]) : NULL;
         $kind = isset($values['kind']) ? $values['kind'] : NULL;
         $display = '';
         /** Specific **/
         if (trim($field->listing_specific) != '') {
             $specified_listings = explode(',', trim($field->listing_specific, ', '));
             self::$category_listing_specific_array[$field->id] = $specified_listings;
             if (!in_array($values['listing'], $specified_listings)) {
                 $display = 'display: none;';
             }
         } elseif (trim($field->property_type_specific) != '') {
             $specified_property_types = explode(',', trim($field->property_type_specific, ', '));
             self::$category_property_type_specific_array[$field->id] = $specified_property_types;
             if (!in_array($values['property_type'], $specified_property_types)) {
                 $display = 'display: none;';
             }
         } elseif (trim($field->user_specific) != '') {
             $specified_user_types = explode(',', trim($field->user_specific, ', '));
             self::$category_user_specific_array[$field->id] = $specified_user_types;
             if (!in_array($values['membership_type'], $specified_user_types)) {
                 $display = 'display: none;';
             }
         } elseif (isset($options['access'])) {
             foreach ($options['access'] as $access) {
                 if (!wpl_global::check_access($access)) {
                     $display = 'display: none;';
                     break;
                 }
             }
         }
         /** More Details **/
         if ($type == 'more_details' and !$has_more_details) {
             echo '<div class="wpl_listing_field_container wpl-pwizard-prow-' . $type . '" id="wpl_listing_field_container' . $field->id . '">';
             echo '<label for="wpl_c_' . $field->id . '"><span>' . __($label, WPL_TEXTDOMAIN) . '</span></label>';
             echo '<div id="wpl_more_details' . $field->id . '" style="display: none;" class="wpl-fields-more-details-block">';
             $has_more_details = true;
         } elseif ($type == 'more_details' and $has_more_details) {
             /** Only one details field is acceptable in each category **/
             continue;
         }
         /** Accesses **/
         if (isset($field->accesses) and trim($field->accesses) != '' and wpl_global::check_addon('membership')) {
             $accesses = explode(',', trim($field->accesses, ', '));
             $cur_membership_id = wpl_users::get_user_membership();
             if (!in_array($cur_membership_id, $accesses) and trim($field->accesses_message) == '') {
                 continue;
             } elseif (!in_array($cur_membership_id, $accesses) and trim($field->accesses_message) != '') {
                 echo '<div class="prow wpl_listing_field_container prow-' . $type . '" id="wpl_listing_field_container' . $field->id . '" style="' . $display . '">';
                 echo '<label for="wpl_c_' . $field->id . '">' . __($label, WPL_TEXTDOMAIN) . '</label>';
                 echo '<span class="wpl-access-blocked-message">' . __($field->accesses_message, WPL_TEXTDOMAIN) . '</span>';
                 echo '</div>';
                 continue;
             }
         }
         /** js validation **/
         self::$wizard_js_validation[$field->id] = self::generate_js_validation($field);
         if (isset($finds[$type])) {
             echo '<div class="prow wpl_listing_field_container prow-' . $type . '" id="wpl_listing_field_container' . $field->id . '" style="' . $display . '">';
             include $path . DS . $finds[$type];
             echo '</div>';
             continue;
         }
         echo '<div class="prow wpl_listing_field_container prow-' . $type . '" id="wpl_listing_field_container' . $field->id . '" style="' . $display . '">';
         foreach ($files as $file) {
             include $path . DS . $file;
             if ($done_this) {
                 $finds[$type] = $file;
                 break;
             }
         }
         echo '</div>';
     }
     if ($has_more_details) {
         echo '</div></div>';
     }
 }
Exemplo n.º 3
0
 /**
  * Renders one dbst field
  * @author Howard R <*****@*****.**>
  * @param string $value
  * @param int $dbst_id
  * @return array rendered field
  */
 public static function render_field($value, $dbst_id)
 {
     /** first validation **/
     if (!$dbst_id) {
         return array();
     }
     $done_this = false;
     $return = array();
     $path = WPL_ABSPATH . DS . 'libraries' . DS . 'dbst_show';
     $files = wpl_folder::files($path, '.php$', false, false);
     $field = wpl_flex::get_field($dbst_id);
     $value = stripslashes($value);
     $type = $field->type;
     $options = json_decode($field->options, true);
     foreach ($files as $file) {
         require $path . DS . $file;
         if ($done_this == true) {
             break;
         }
     }
     /** Accesses **/
     if (trim($field->accesses) != '') {
         $accesses = explode(',', trim($field->accesses, ', '));
         $cur_membership_id = wpl_users::get_user_membership();
         if (!in_array($cur_membership_id, $accesses) and trim($field->accesses_message) == '') {
             return array();
         } elseif (!in_array($cur_membership_id, $accesses) and trim($field->accesses_message) != '') {
             $return = array('field_id' => $field->id, 'type' => $field->type, 'name' => __($field->name, WPL_TEXTDOMAIN), 'value' => __($field->accesses_message, WPL_TEXTDOMAIN));
         }
     }
     return $return;
 }