| 1 |
<?php |
| 2 |
|
| 3 |
if ( ! defined( 'ABSPATH' ) ) { |
| 4 |
exit; // Exit if accessed directly. |
| 5 |
} |
| 6 |
|
| 7 |
/* |
| 8 |
* Widget [wdk-listing-fields-section], show latest listings in list view |
| 9 |
* atts list: |
| 10 |
* |
| 11 |
* section_id (int) - section id |
| 12 |
* post_id (int) - post_id |
| 13 |
* field_label_hide (string) - yes|no, default no, hide labels |
| 14 |
* field_group_icon_enable (string) - yes|no, default yes, show labels |
| 15 |
* label_suffix (string) - text after label, can be ":" |
| 16 |
* label_prefix (string) - text before label, can be ":" |
| 17 |
* hide_onempty_complete (string) - yes|no, default yes, hide section if all fields empty |
| 18 |
* custom_class (string) - custom css class |
| 19 |
* |
| 20 |
* Layout path : |
| 21 |
* get_template_directory().'/wpdirectorykit/shortcodes/views/shortcode-wdk-listing-fields-section.php' |
| 22 |
* WPDIRECTORYKIT_PATH.'shortcodes/views/shortcode-wdk-listing-fields-section.php' |
| 23 |
*/ |
| 24 |
|
| 25 |
add_shortcode('wdk-listing-fields-section', 'shortcode_wdk_listing_fields_section'); |
| 26 |
function shortcode_wdk_listing_fields_section($atts, $content){ |
| 27 |
$atts = shortcode_atts(array( |
| 28 |
'id'=>NULL, |
| 29 |
'section_id'=>'', |
| 30 |
'post_id'=>'', |
| 31 |
'field_label_hide'=>'', |
| 32 |
'label_suffix'=>':', |
| 33 |
'label_prefix'=>'', |
| 34 |
'field_group_icon_enable'=>'no', |
| 35 |
'hide_onempty_complete'=>'yes', |
| 36 |
'custom_class'=>'', |
| 37 |
), $atts); |
| 38 |
$data = array(); |
| 39 |
|
| 40 |
/* settings from atts */ |
| 41 |
$data['settings'] = $atts; |
| 42 |
$data['id_element'] = ''; |
| 43 |
|
| 44 |
/* load css/js */ |
| 45 |
|
| 46 |
$WMVC = &wdk_get_instance(); |
| 47 |
$WMVC->model('listingfield_m'); |
| 48 |
$WMVC->model('field_m'); |
| 49 |
$WMVC->model('listing_m'); |
| 50 |
$WMVC->load_helper('listing'); |
| 51 |
|
| 52 |
global $wdk_listing_id; |
| 53 |
$post_id = $wdk_listing_id; |
| 54 |
if (!empty($data['settings']['post_id'])) { |
| 55 |
$post_id = $data['settings']['post_id']; |
| 56 |
} |
| 57 |
|
| 58 |
$data['post_id'] = $post_id; |
| 59 |
|
| 60 |
$data['section_label'] = 'Example Section'; |
| 61 |
$data['sections_data'] = $WMVC->field_m->get_fields_section(); |
| 62 |
$data['section_data'] = array(); |
| 63 |
|
| 64 |
if(!empty($data['settings']['section_id'])){ |
| 65 |
$data['section_label'] = wdk_field_label($data['settings']['section_id']); |
| 66 |
if(isset($data['sections_data'][$data['settings']['section_id']])) |
| 67 |
$data['section_data'] = $data['sections_data'][$data['settings']['section_id']]; |
| 68 |
} |
| 69 |
|
| 70 |
if(!empty($data['settings']['field_id'])) |
| 71 |
$data['field_label'] = wdk_field_label($data['settings']['field_id']); |
| 72 |
|
| 73 |
if(empty($data['section_data'])){ |
| 74 |
return false; |
| 75 |
} |
| 76 |
|
| 77 |
/* return false if no content */ |
| 78 |
if($data['settings']['hide_onempty_complete'] == 'yes') { |
| 79 |
$complete_empty = true; |
| 80 |
foreach($data['section_data']['fields'] as $field) { |
| 81 |
|
| 82 |
if(wdk_field_value('category_id', $post_id) && wdk_depend_is_hidden_field(wmvc_show_data('idfield', $field), wdk_field_value('category_id', $post_id))) { |
| 83 |
continue; |
| 84 |
} |
| 85 |
|
| 86 |
if(!empty(wdk_field_value (wmvc_show_data('idfield', $field), $post_id))){ |
| 87 |
$complete_empty = false; |
| 88 |
break; |
| 89 |
} |
| 90 |
} |
| 91 |
|
| 92 |
if($complete_empty) |
| 93 |
return false; |
| 94 |
} |
| 95 |
|
| 96 |
return wdk_shortcodes_view('shortcode-wdk-listing-fields-section', $data); |
| 97 |
} |
| 98 |
|
| 99 |
?> |