EditProfile
5 years ago
Login
5 years ago
MemberDirectory
5 years ago
PasswordReset
5 years ago
Registration
5 years ago
UserProfile
5 years ago
AbstractBuildScratch.php
5 years ago
AbstractMemberDirectoryTheme.php
5 years ago
AbstractTheme.php
5 years ago
FieldListing.php
5 years ago
MemberDirectoryListing.php
5 years ago
ProfileFieldListing.php
5 years ago
ThemeInterface.php
5 years ago
ThemesRepository.php
5 years ago
index.php
5 years ago
ProfileFieldListing.php
169 lines
| 1 | <?php |
| 2 | |
| 3 | namespace ProfilePress\Core\Themes\DragDrop; |
| 4 | |
| 5 | use ProfilePress\Core\Base; |
| 6 | use ProfilePress\Core\Classes\FormRepository as FR; |
| 7 | use ProfilePress\Core\Classes\PROFILEPRESS_sql; |
| 8 | |
| 9 | class ProfileFieldListing |
| 10 | { |
| 11 | private $form_id; |
| 12 | private $field_settings = []; |
| 13 | |
| 14 | private $has_field_data = false; |
| 15 | |
| 16 | private $item_wrap_start_tag = ''; |
| 17 | private $item_wrap_end_tag = ''; |
| 18 | private $title_start_tag = ''; |
| 19 | private $title_end_tag = ''; |
| 20 | private $info_start_tag = ''; |
| 21 | private $info_end_tag = ''; |
| 22 | |
| 23 | private $output = ''; |
| 24 | |
| 25 | private $defaults; |
| 26 | |
| 27 | public function __construct($form_id) |
| 28 | { |
| 29 | $this->form_id = $form_id; |
| 30 | |
| 31 | $this->field_settings = FR::form_builder_fields_settings($form_id, FR::USER_PROFILE_TYPE); |
| 32 | } |
| 33 | |
| 34 | public function defaults($defaults) |
| 35 | { |
| 36 | $this->defaults = $defaults; |
| 37 | |
| 38 | return $this; |
| 39 | } |
| 40 | |
| 41 | public function item_wrap_start_tag($tag) |
| 42 | { |
| 43 | $this->item_wrap_start_tag = $tag; |
| 44 | |
| 45 | return $this; |
| 46 | } |
| 47 | |
| 48 | public function item_wrap_end_tag($tag) |
| 49 | { |
| 50 | $this->item_wrap_end_tag = $tag; |
| 51 | |
| 52 | return $this; |
| 53 | } |
| 54 | |
| 55 | public function title_start_tag($tag) |
| 56 | { |
| 57 | $this->title_start_tag = $tag; |
| 58 | |
| 59 | return $this; |
| 60 | } |
| 61 | |
| 62 | public function title_end_tag($tag) |
| 63 | { |
| 64 | $this->title_end_tag = $tag; |
| 65 | |
| 66 | return $this; |
| 67 | } |
| 68 | |
| 69 | public function info_start_tag($tag) |
| 70 | { |
| 71 | $this->info_start_tag = $tag; |
| 72 | |
| 73 | return $this; |
| 74 | } |
| 75 | |
| 76 | public function info_end_tag($tag) |
| 77 | { |
| 78 | $this->info_end_tag = $tag; |
| 79 | |
| 80 | return $this; |
| 81 | } |
| 82 | |
| 83 | public function has_field_data() |
| 84 | { |
| 85 | return $this->has_field_data; |
| 86 | } |
| 87 | |
| 88 | public function forge() |
| 89 | { |
| 90 | $output = ''; |
| 91 | |
| 92 | foreach ($this->field_settings as $field_setting) { |
| 93 | |
| 94 | $field_type = $field_setting['fieldType']; |
| 95 | |
| 96 | if (isset($this->defaults, $this->defaults[$field_type])) { |
| 97 | $field_setting = wp_parse_args($field_setting, $this->defaults[$field_type]); |
| 98 | } |
| 99 | |
| 100 | $field_title = isset($field_setting['label']) ? $field_setting['label'] : ''; |
| 101 | |
| 102 | if ($field_type == 'profile-cpf') { |
| 103 | |
| 104 | $field_key = ''; |
| 105 | |
| 106 | if ( ! empty($field_setting['field_key']) && ! empty($field_setting['label'])) { |
| 107 | $field_key = $field_setting['field_key']; |
| 108 | |
| 109 | $field_type = $field_type . ' key="' . $field_key . '"'; |
| 110 | |
| 111 | } elseif ( ! empty($field_setting['custom_field'])) { |
| 112 | |
| 113 | $field_key = $field_setting['custom_field']; |
| 114 | |
| 115 | $field_title = PROFILEPRESS_sql::get_field_label($field_key); |
| 116 | |
| 117 | if ( ! $field_title) { |
| 118 | $field_title = PROFILEPRESS_sql::get_contact_info_field_label($field_key); |
| 119 | } |
| 120 | |
| 121 | $field_type = $field_type . ' key="' . $field_key . '"'; |
| 122 | } |
| 123 | } |
| 124 | |
| 125 | if ($field_type == 'profile-display-name') { |
| 126 | |
| 127 | if ( ! empty($field_setting['format'])) { |
| 128 | |
| 129 | $field_type = $field_type . ' format="' . $field_setting['format'] . '"'; |
| 130 | } |
| 131 | } |
| 132 | |
| 133 | if ($field_type == 'pp-custom-html') { |
| 134 | |
| 135 | if ( ! empty($field_setting['custom_html'])) { |
| 136 | |
| 137 | $field_type = $field_type . ' custom_html="' . $field_setting['custom_html'] . '"'; |
| 138 | } |
| 139 | } |
| 140 | |
| 141 | $parsed_shortcode = do_shortcode('[' . $field_type . ']', true); |
| 142 | |
| 143 | if ( ! empty($parsed_shortcode)) { |
| 144 | |
| 145 | $this->has_field_data = true; |
| 146 | |
| 147 | if ( ! empty($field_key) && strpos($field_type, 'profile-cpf') !== false && in_array($field_key, array_keys(ppress_social_network_fields()))) { |
| 148 | $parsed_shortcode = sprintf('<a href="%s">%s</a>', $parsed_shortcode, ppress_var(ppress_social_network_fields(), $field_key)); |
| 149 | } |
| 150 | |
| 151 | $output .= $this->item_wrap_start_tag; |
| 152 | if ( ! empty($field_title)) { |
| 153 | $output .= $this->title_start_tag . $field_title . $this->title_end_tag; |
| 154 | } |
| 155 | $output .= $this->info_start_tag . $parsed_shortcode . $this->info_end_tag; |
| 156 | $output .= $this->item_wrap_end_tag; |
| 157 | } |
| 158 | } |
| 159 | |
| 160 | $this->output = $output; |
| 161 | |
| 162 | return $this; |
| 163 | } |
| 164 | |
| 165 | public function output() |
| 166 | { |
| 167 | return $this->output; |
| 168 | } |
| 169 | } |