[ Index ] |
MailPress 544 |
[ Index ] [ Classes ] [ Functions ] [ Variables ] [ Constants ] [ Statistics ] |
[Summary view] [Print] [Text view]
1 <?php 2 abstract class MP_form_field_type_ 3 { 4 var $field = null; 5 var $prefix = MailPress_form::prefix; 6 7 function __construct($desc) 8 { 9 $this->desc = $desc; 10 $this->settings = dirname($this->file) . '/settings.xml'; 11 12 add_filter('MailPress_form_field_types_register', array($this, 'register'), 8, 1); 13 add_filter('MailPress_form_field_type_' . $this->id . '_have_file', array($this, 'have_file'), 8, 1); 14 15 add_filter('MailPress_form_field_type_' . $this->id . '_submitted', array($this, 'submitted'), 8, 1); 16 17 add_filter('MailPress_form_field_type_' . $this->id . '_get_tag', array($this, 'get_tag'), 8, 2); 18 add_filter('MailPress_form_field_type_' . $this->id . '_get_id', array($this, 'get_id'), 8, 1); 19 add_filter('MailPress_form_field_type_' . $this->id . '_get_name', array($this, 'get_name'), 8, 1); 20 21 add_action('MailPress_form_field_type_' . $this->id . '_settings_form', array($this, 'settings_form'), 8, 1); 22 } 23 24 function register($field_types) { $field_types[$this->id] = array( 'desc' => $this->desc, 'order' => $this->order ); return $field_types; } 25 function have_file($have_file) { return $have_file; } 26 27 function submitted($field) 28 { 29 if (!isset($_POST[$this->prefix][$field->form_id][$field->id])) return $field; 30 31 $field->submitted['value'] = $_POST[$this->prefix][$field->form_id][$field->id]; 32 $field->submitted['text'] = stripslashes($_POST[$this->prefix][$field->form_id][$field->id]); 33 return $field; 34 } 35 36 function get_tag($field, $no_reset) 37 { 38 unset($this->field); 39 40 $this->field = $field; 41 42 $this->attributes_filter($no_reset); 43 44 return $this->build_tag(); 45 } 46 47 function get_formats($default = '') 48 { 49 $form_template = MP_Form::get_template($this->field->form_id); 50 if (!$form_template) return $default; 51 52 $form_templates = new MP_Form_templates(); 53 $f = $form_templates->get_composite_template($form_template, $this->id); 54 return (is_array($f)) ? array_merge($default, $f) : ((!empty($f)) ? $f : $default); 55 } 56 57 function attributes_filter($no_reset) 58 { 59 if ($no_reset) $this->field->settings['attributes']['value'] = esc_attr(stripslashes($_POST[$this->prefix][$this->field->form_id][$this->field->id])); 60 61 $this->attributes_filter_css(); 62 } 63 64 function attributes_filter_css() 65 { 66 if (!isset($this->field->submitted['on_error'])) return; 67 $_classes = (isset($this->field->settings['controls']['class'])) ? trim($this->field->settings['controls']['class']) : ''; 68 if ( !empty($_classes) ) 69 { 70 $add = $remove = array(); 71 $error_classes = explode(' ', $_classes); 72 $classes = explode(' ', $this->field->settings['attributes']['class']); 73 foreach ($classes as $k => $v) $classes[$k] = trim($v); 74 foreach ($error_classes as $k => $v) { $v = trim($v); switch ($v[0]) { case '+' : $add[] = substr($v, 1); break; case '-' : $remove[] = substr($v, 1); break; default : $add[] = $v; break; } } 75 $this->field->settings['attributes']['class'] = implode(' ', array_merge(array_diff($classes, $remove), $add) ); 76 } 77 $_style = (isset($this->field->settings['controls']['style'])) ? trim($this->field->settings['controls']['style']) : ''; 78 if (!empty($_style)) $this->field->settings['attributes']['style'] .= $_style; 79 } 80 81 function build_tag() 82 { 83 $tag_content = $misc = ''; 84 // opening tag 85 $tag = '<'; 86 $tag .= (isset($this->field_not_input)) ? $this->field->type : 'input'; 87 // id 88 $this->field->settings['attributes']['id'] = $this->get_id($this->field); 89 // name 90 $this->field->settings['attributes']['name'] = $this->get_name($this->field); 91 // other attributes 92 foreach ($this->field->settings['attributes'] as $attribute => $value) 93 { 94 if ('tag_content' == $attribute) { $tag_content = $value; continue; } 95 if ('misc' == $attribute) { $misc = trim($value); if ('' != $misc) $misc = " $misc"; continue; } 96 if ('' != trim($value)) $tag .= $this->get_attribute($attribute, trim($value)); 97 } 98 // closing tag 99 return $tag . ( (isset($this->field_not_input)) ? "$misc >$tag_content</" . $this->field->type . '>' : "$misc />" ); 100 } 101 function get_attribute($attr, $value) { if ('value' == $attr) $value = esc_attr($value); $quote = (false !== strpos($value, '"')) ? "'" : '"'; return " $attr=$quote$value$quote"; } 102 function get_name($field) { return (isset($field->settings['attributes']['name'])) ? $this->prefix.'['.$field->form_id.']['.$this->prefix.$field->settings['attributes']['name'].']' : $this->prefix.'['.$field->form_id . ']['. $field->id . ']'; } 103 function get_id($field) { return (isset($field->settings['attributes']['id'])) ? $this->prefix . $field->form_id.'_'. $field->settings['attributes']['id'] : $this->prefix . $field->form_id . '_' . $field->id; } 104 105 106 107 function settings_form($field) 108 { 109 $this->field = $field; 110 $this->type_ok = ($this->id == $this->field->type); 111 $protected = ( isset($this->field->settings['options']['protected']) && $this->field->settings['options']['protected'] ); 112 $has_controls = $has_controls_checked = false; 113 if (method_exists($this, 'build_settings_form')) return $this->build_settings_form(); 114 115 ob_start(); 116 include($this->settings); 117 $xml = trim(ob_get_contents()); 118 ob_end_clean(); 119 $xml = '<?xml version="1.0" ?>' . $xml; 120 $xml = simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA); 121 foreach ($xml->tabs->children() as $child) $tabs[$child->getName()] = (string) $child; 122 if (isset($_GET['action']) && ('edit' == $_GET['action']) && $this->type_ok) { $tabs['html'] = __('Html', MP_TXTDOM); } 123 124 if (empty($tabs)) return; 125 ?> 126 <div id='field_type_<?php echo $this->id; ?>_settings' class='field_type_settings' <?php echo ( ($this->type_ok) ? '' : "style='display:none;'" ); ?>> 127 <ul> 128 <?php foreach ($tabs as $tab_type => $tab) echo "<li><a href='#settings_tab_" . $this->id . '_' . $tab_type . "'><span>$tab</span></a></li>\n"; ?> 129 </ul> 130 <div style='clear:both;' > 131 <?php 132 foreach ($tabs as $tab_type => $tab) 133 { 134 echo "\n<div id='settings_tab_" . $this->id . '_' . $tab_type . "' class='ui-tabs settings_form_tabs settings_$tab_type'>\n"; 135 switch ($tab_type) 136 { 137 case 'html' : 138 $form = MP_Form::get($this->field->form_id); 139 echo "<textarea rows='5' cols='40' disabled='disabled'>" . htmlspecialchars(MP_Form::get_field($this->field, false, $form->template), ENT_QUOTES) . '</textarea>'; 140 echo '<p><small>' . sprintf(__('Templates : %1$s/%2$s', MP_TXTDOM), $form->template, $field->template) . '</small></p>'; 141 break; 142 default : 143 foreach ($xml->{$tab_type}->items as $items) 144 { 145 foreach ($items->children() as $child) 146 { 147 $attribute = $child->getName(); 148 foreach ($child->children() as $tags) 149 { 150 switch ($tags->getName()) 151 { 152 case 'checkbox' : 153 $checked = $this->settings_checkbox($tab_type, $attribute, $tags->value, (int) $tags->disabled, ( (isset($tags->class)) ? $tags->class : false), ( (isset($tags->forced)) ? $tags->forced : false) ); 154 if ( isset($tags->class) && ('controls' == (string) $tags->class) ) $has_controls = true; 155 if ($checked) $has_controls_checked = true; 156 echo "<label for='" . $this->prefix . $this->id . '_settings_' . $tab_type . '_' . $attribute . '_' . $tags->value . "' class='inline' ><span class='description'><small>" . $tags->text . "</small></span></label> \n"; 157 break; 158 case 'hidden' : 159 $this->settings_hidden_value($tab_type, $attribute, $tags->value); 160 break; 161 case 'is' : 162 $this->settings_description(__('initial state : ', MP_TXTDOM)); 163 $values = unserialize($tags->values); 164 $disabled = unserialize($tags->disabled); 165 foreach ($values as $attribute) 166 { 167 $this->settings_checkbox( $tab_type, $attribute, $attribute, (in_array($attribute, $disabled)) ); 168 echo "<label for='" . $this->prefix . $this->id . '_settings_' . $tab_type . '_' . $attribute . '_' . $attribute . "' class='inline' ><span class='description'><small>$attribute</small></span></label> \n"; 169 } 170 break; 171 case 'misc' : 172 $this->settings_text('attributes', 'misc', false, '', 39); 173 echo "\n<br /><span class='description'><i style='color:#666;font-size:8px;'>" . ( (string) $tags ) . "</i></span><br />\n"; 174 break; 175 case 'only_text' : 176 echo "<span class='description'>" . (string) $tags . '</span>'; 177 break; 178 case 'radio' : 179 $this->settings_description($tags->text); 180 $values = unserialize($tags->values); 181 $disabled = unserialize($tags->disabled); 182 foreach ($values as $value => $value_text) $this->settings_radio($tab_type, $attribute, $value, $value_text, $tags->default, in_array($value, $disabled) ); 183 break; 184 case 'select_num' : 185 echo "<span class='description'><small>" . $tags->text; 186 if ('attributes' == $tab_type) echo '"'; 187 $this->settings_select_num($tab_type, $attribute, (int) $tags->min, (int) $tags->max, (int) $tags->default); 188 if ('attributes' == $tab_type) echo '"'; 189 echo "</small></span> \n"; 190 break; 191 case 'select_opt' : 192 $values = unserialize($tags->values); 193 echo "<span class='description'><small>" . $tags->text; 194 $this->settings_select_opt($tab_type, $attribute, $values, $tags->default); 195 echo "</small></span> \n"; 196 break; 197 case 'text' : 198 echo "<span class='description'><small>"; 199 if (isset($tags->text)) echo $tags->text; else echo $attribute; 200 if ('attributes' == $tab_type) echo '="'; 201 echo "</small></span>"; 202 $this->settings_text($tab_type, $attribute, (isset($tags->disabled)) ? (string) $tags->disabled : false, (isset($tags->default)) ? $tags->default : '', (isset($tags->size)) ? (string) $tags->size : 32); 203 if ('attributes' == $tab_type) echo "<span class='description'><small>\"</small></span>\n"; 204 break; 205 case 'textarea' : 206 $this->settings_attributes_textarea($tags->text, $attribute); 207 if (isset($tags->desc)) echo "<br /><span class='description'><small style='color:#666;'>" . $tags->desc . '</small></span>'; 208 break; 209 } 210 } 211 } 212 echo "<br />\n"; 213 } 214 if ( ($has_controls) && ('controls' == $tab_type) ) 215 { 216 echo "<div id='field_type_controls_" . $this->id . "'" . ( ($has_controls_checked) ? '' : " style='display:none;'" ) . " class='field_type_controls'>\n"; 217 echo "<hr style='border: 0pt none ; margin: 1px 5px 5px 1px; color: rgb(223, 223, 223); background-color: rgb(223, 223, 223); height: 1px;' />"; 218 _e('On error <small>(to remove a class : -name_of_class)</small>', MP_TXTDOM); 219 echo '<br />'; 220 echo "<div>"; 221 foreach (array('class', 'style') as $attribute) 222 { 223 echo "<span class='description'><small>$attribute=\"</small></span>"; 224 $this->settings_text($tab_type, $attribute); 225 echo "<span class='description'><small>\"</small></span><br />\n"; 226 } 227 echo '</div>'; 228 echo "</div>\n"; 229 } 230 break; 231 } 232 echo "\n</div>\n"; 233 } 234 if (isset($xml->hiddens)) 235 { 236 foreach ($xml->hiddens->children() as $child) 237 { 238 $tab_type = $child->getName(); 239 foreach($child->children() as $child2) 240 { 241 $attribute = $child2->getName(); 242 if (isset($child2->value)) $this->settings_hidden_value($tab_type, $attribute, $child2->value); 243 else $this->settings_hidden($tab_type, $attribute); 244 } 245 } 246 } 247 ?> 248 </div> 249 </div> 250 <?php 251 } 252 function settings_description($text) { echo "<span class='description'><small>$text</small></span>"; } 253 function settings_hidden($setting, $attribute) { ?><input type='hidden' name='<?php echo $this->prefix . $this->id . "[settings][$setting][$attribute]"; ?>' value="<?php if ($this->type_ok && isset($this->field->settings[$setting][$attribute])) echo esc_attr($this->field->settings[$setting][$attribute]); ?>" /><?php } 254 function settings_hidden_value($setting, $attribute, $value) { ?><input type='hidden' name='<?php echo $this->prefix . $this->id . "[settings][$setting][$attribute]"; ?>' value="<?php echo esc_attr($value); ?>" /><?php } 255 function settings_text($setting, $attribute, $disabled = false, $default = '', $size = 32) { ?><input type='text' name='<?php echo $this->prefix . $this->id . "[settings][$setting][$attribute]"; ?>' id='<?php echo $this->prefix . $this->id . '_settings_' . $setting . '_' . $attribute; ?>' value="<?php echo ( ($this->type_ok && isset($this->field->settings[$setting][$attribute])) ? esc_attr($this->field->settings[$setting][$attribute]) : esc_attr($default) ); ?>" size='<?php echo $size; ?>' /><?php } 256 function settings_checkbox($setting, $attribute, $value, $disabled = false, $class = false, $forced = false) { ?><input type='checkbox' name='<?php echo $this->prefix . $this->id . "[settings][$setting][$attribute]"; ?>' id='<?php echo $this->prefix . $this->id . '_settings_' . $setting . '_' . $attribute . '_' . $value; ?>' value="<?php echo esc_attr($value); ?>" style='width:auto;'<?php if ($disabled) echo " disabled='disabled'"; ?><?php if ($class) echo " class='$class'"; ?><?php if ($forced !== false) checked(true); else checked( $value, ( ($this->type_ok && isset($this->field->settings[$setting][$attribute])) ? $this->field->settings[$setting][$attribute] : null ) ); ?> /><?php if ($forced !== false) return true; return ($this->type_ok && isset($this->field->settings[$setting][$attribute]) && ($value == $this->field->settings[$setting][$attribute]) );} 257 function settings_radio($setting, $attribute, $value, $value_text, $default, $disabled = false) { ?><input type='radio' name='<?php echo $this->prefix . $this->id . "[settings][$setting][$attribute]"; ?>' id='<?php echo $this->prefix . $this->id .'_settings_' . $setting . '_' . $attribute . '_' . $value; ?>' value="<?php echo esc_attr($value); ?>" style='width:auto;'<?php checked($value, ( ($this->type_ok && isset($this->field->settings[$setting][$attribute])) ? $this->field->settings[$setting][$attribute] : $default) ); ?><?php if ($disabled) echo " disabled='disabled'"; ?> /><label class='inline' for='<?php echo $this->prefix . $this->id .'_settings_' . $setting . '_' . $attribute . '_' . $value; ?>' ><span class='description'><small<?php if ($disabled) echo " style='color:#888'";?>><?php echo $value_text; ?></small></span></label> <?php } 258 function settings_select_num($setting, $attribute, $min, $max, $default) { ?><select name='<?php echo $this->prefix . $this->id . "[settings][$setting][$attribute]"; ?>' id='<?php echo $this->prefix . $this->id . '_settings_' . $setting . '_' . $attribute; ?>' ><?php MP_AdminPage::select_number($min, $max, ( ($this->type_ok && isset($this->field->settings[$setting][$attribute])) ? $this->field->settings[$setting][$attribute] : $default) ); ?></select><?php } 259 function settings_select_opt($setting, $attribute, $values, $default) { ?><select name='<?php echo $this->prefix . $this->id . "[settings][$setting][$attribute]"; ?>' id='<?php echo $this->prefix . $this->id . '_settings_' . $setting . '_' . $attribute; ?>' ><?php MP_AdminPage::select_option($values, ( ($this->type_ok && isset($this->field->settings[$setting][$attribute])) ? $this->field->settings[$setting][$attribute] : $default) ); ?></select><?php } 260 function settings_attributes_textarea($text, $option) { ?><input type='hidden' name='<?php echo $this->prefix . $this->id . '[textareas][]'; ?>' value='<?php echo esc_attr($option); ?>' /><?php $this->settings_description($text); ?><br /><textarea name='<?php echo $this->prefix . $this->id . "[settings][attributes][$option]"; ?>' id='<?php echo $this->prefix . $this->id . '_settings_attributes_' . $option; ?>' cols='40' rows='4'><?php if ($this->type_ok && isset($this->field->settings['attributes']['tag_content'])) echo esc_attr(trim(base64_decode($this->field->settings['attributes']['tag_content']))); ?></textarea><?php } 261 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Apr 28 18:38:52 2016 | Cross-referenced by PHPXref 0.7.1 |