WYSIJA_help_forms

Some Functions are based on Codeigniter's Form Helper Class (http://www.codeigniter.com).

Defined (1)

The class is defined in the following location(s).

/helpers/forms.php  
  1. class WYSIJA_help_forms{ 
  2. var $eachValues = array(); 
  3. var $eachValuesSec = array(); 
  4.  
  5. function __construct() { 
  6. // I believe this is for translation purpose, making sure the correct language is loaded 
  7. add_action( 'init', array( $this, 'apply_filters' ), 20 ); 
  8.  
  9. $this->eachValues = array( 
  10. 'one_min' => __( 'every minute', WYSIJA ),  
  11. 'two_min' => __( 'every 2 minutes', WYSIJA ),  
  12. 'five_min' => __( 'every 5 minutes', WYSIJA ),  
  13. 'ten_min' => __( 'every 10 minutes', WYSIJA ),  
  14. 'fifteen_min' => __( 'every 15 minutes', WYSIJA ),  
  15. 'thirty_min' => __( 'every 30 minutes', WYSIJA ),  
  16. 'hourly' => __( 'every hour', WYSIJA ),  
  17. 'two_hours' => __( 'every 2 hours', WYSIJA ) 
  18. ); 
  19.  
  20. $this->eachValuesSec = array( 
  21. 'one_min' => '60',  
  22. 'two_min' => '120',  
  23. 'five_min' => '300',  
  24. 'ten_min' => '600',  
  25. 'fifteen_min' => '900',  
  26. 'thirty_min' => '1800',  
  27. 'hourly' => '3600',  
  28. 'two_hours' => '7200',  
  29. 'twicedaily' => '43200',  
  30. 'daily' => '86400',  
  31. ); 
  32.  
  33. function apply_filters() { 
  34. $this->eachValues = apply_filters( 'mpoet_sending_frequency', $this->eachValues ); 
  35. $this->eachValuesSec = apply_filters( 'mpoet_sending_frequency_sec', $this->eachValuesSec ); 
  36.  
  37. function input($data = '', $value = '', $extra = '') { 
  38. $defaults = array('type' => 'text', 'name' => (( ! is_array($data)) ? $data : ''), 'value' => $value); 
  39. $content="<input ".$this->setAttrib($data, $defaults).$extra." />"; 
  40. return $content; 
  41. function password($data = '', $value = '', $extra = '') { 
  42. $defaults = array('type' => 'password', 'name' => (( ! is_array($data)) ? $data : ''), 'value' => $value); 
  43. $content="<input ".$this->setAttrib($data, $defaults).$extra." />"; 
  44. return $content; 
  45.  
  46. function hidden($data = '', $value = '', $extra = '') { 
  47. $defaults = array('type' => 'hidden', 'name' => (( ! is_array($data)) ? $data : ''), 'value' => $value); 
  48. $content="<input ".$this->setAttrib($data, $defaults).$extra." />"; 
  49. return $content; 
  50.  
  51. function textarea($data = '', $value = '', $extra = '') { 
  52. $defaults = array('name' => (( ! is_array($data)) ? $data : ''), 'cols' => '90', 'rows' => '12'); 
  53.  
  54. if ( ! is_array($data) OR ! isset($data['value'])) { 
  55. $val = $value; 
  56. } else { 
  57. $val = $data['value']; 
  58. unset($data['value']); 
  59.  
  60. return '<textarea '.$this->setAttrib($data, $defaults).$extra.'>'.esc_textarea($val).'</textarea>'; 
  61.  
  62.  
  63. function tinymce($idName = '', $content = '') { 
  64. $this->the_editor(stripslashes($content), $idName, 'title', false); 
  65.  
  66. function checkbox($data = '', $value = '', $checked = FALSE, $extra = '') { 
  67. $defaults = array('type' => 'checkbox', 'name' => (( ! is_array($data)) ? $data : ''), 'value' => $value); 
  68.  
  69. if (is_array($data) AND array_key_exists('checked', $data)) { 
  70. $checked = $data['checked']; 
  71.  
  72. if ($checked == FALSE) unset($data['checked']); 
  73. else $data['checked'] = 'checked'; 
  74.  
  75. if ($checked == TRUE) $defaults['checked'] = 'checked'; 
  76. else unset($defaults['checked']); 
  77.  
  78. return "<input ".$this->setAttrib($data, $defaults).$extra." />"; 
  79.  
  80. function checkboxes($data = '', $values = array(), $value = '', $extra = '') { 
  81. $html=''; 
  82. foreach($values as $val => $valtitle) { 
  83. $checked=false; 
  84. $data2=$data; 
  85. $data2['id'].="-".$val; 
  86. if($val==$value)$checked=true; 
  87. $html.='<label for="'.$data2['id'].'">'.$this->checkbox($data2, $val, $checked, $extra).$valtitle."</label>"; 
  88.  
  89. return $html; 
  90.  
  91. function radios($data = '', $values = array(), $value = '', $extra = '') { 
  92. $html=''; 
  93. foreach($values as $val => $valtitle) { 
  94. $checked=false; 
  95. $data2=$data; 
  96. $data2['id'].="-".$val; 
  97. if($val==$value)$checked=true; 
  98. $html.='<label for="'.$data2['id'].'">'.$this->radio($data2, $val, $checked, $extra).$valtitle."</label>"; 
  99.  
  100. return $html; 
  101.  
  102. function radio($data = '', $value = '', $checked = FALSE, $extra = '') { 
  103. if ( ! is_array($data)) { 
  104. $data = array('name' => $data); 
  105.  
  106. $data['type'] = 'radio'; 
  107. return $this->checkbox($data, $value, $checked, $extra); 
  108.  
  109.  
  110. function the_editor($content, $id = 'content', $prev_id = 'title', $media_buttons = true, $tab_index = 2) { 
  111. $rows = get_option('default_post_edit_rows'); 
  112. if (($rows < 3) || ($rows > 100)) 
  113. $rows = 12; 
  114.  
  115. if ( !current_user_can( 'upload_files' ) ) 
  116. $media_buttons = false; 
  117.  
  118. $richedit = user_can_richedit(); 
  119. $class = ''; 
  120.  
  121. if ( $richedit || $media_buttons ) { ?> 
  122. <div id="editor-toolbar"> 
  123. <?php 
  124. if ( $richedit ) { 
  125. $wp_default_editor=tap_get_option("visual_ed_disable"); 
  126. ?> 
  127. <div class="zerosize"><input accesskey="e" type="button" onclick="switchEditors.go('<?php echo $id; ?>')" /></div> 
  128. <?php if ( $wp_default_editor ) { 
  129. add_filter('the_editor_content', 'wp_htmledit_pre'); ?> 
  130. <a id="edButtonHTML" class="edButtonHTML active hide-if-no-js" onclick="switchEditors.go('<?php echo $id; ?>', 'html');"><?php _e('HTML'); ?></a> 
  131. <a id="edButtonPreview" class="edButtonPreview hide-if-no-js" onclick="switchEditors.go('<?php echo $id; ?>', 'tinymce');"><?php _e('Visual'); ?></a> 
  132. <?php } else { 
  133. $class = " class='theEditor'"; 
  134. add_filter('the_editor_content', 'wp_richedit_pre'); ?> 
  135. <a id="edButtonHTML" class="edButtonHTML hide-if-no-js" onclick="switchEditors.go('<?php echo $id; ?>', 'html');"><?php _e('HTML'); ?></a> 
  136. <a id="edButtonPreview" class="edButtonPreview active hide-if-no-js" onclick="switchEditors.go('<?php echo $id; ?>', 'tinymce');"><?php _e('Visual'); ?></a> 
  137. <?php } 
  138. ?><div id="media-buttons" class="hide-if-no-js"><?php 
  139. if ( $media_buttons ) { ?> 
  140.  
  141. <?php do_action( 'media_buttons' ); ?> 
  142.  
  143. <?php 
  144. } ?> 
  145. </div> 
  146. </div> 
  147. <?php 
  148. ?> 
  149. <div id="quicktags"><?php 
  150. wp_print_scripts( 'quicktags' ); ?> 
  151. </div> 
  152.  
  153. <?php 
  154. $the_editor = apply_filters('the_editor', "<div id='editorcontainer'><textarea rows='$rows'$class cols='40' name='$id' tabindex='$tab_index' id='$id'>%s</textarea></div>\n"); 
  155. $the_editor_content = apply_filters('the_editor_content', $content); 
  156.  
  157. printf($the_editor, $the_editor_content); 
  158.  
  159.  
  160. function titleh($idName = '', $selected = '') { 
  161. $options=array("default"=>"default", "h2"=>"h2", "h3"=>"h3", "h4"=>"h4"); 
  162. echo $this->dropdown($idName, $options, $selected); 
  163.  
  164. function enabled($idName = '', $selected = '') { 
  165. $options=array(0=>"disabled", 1=>"enabled"); 
  166. echo $this->dropdown($idName, $options, $selected); 
  167.  
  168. function dropdown($data = '', $options = array(), $selected = array(), $extra = '') { 
  169. if ( ! is_array($selected)) { 
  170. $selected = array($selected); 
  171.  
  172. if ( empty($options) ) { 
  173. return false; 
  174.  
  175. $defaults = array('name' => (( ! is_array($data)) ? $data : '')); 
  176.  
  177. /** buggy lines 
  178. * if (count($selected) === 0) { 
  179. if (isset($_POST[$name])) $selected = array($_POST[$name]); 
  180. }*/ 
  181.  
  182. if ($extra != '') $extra = ' '.$extra; 
  183.  
  184. $multiple = (count($selected) > 1 && strpos($extra, 'multiple') === FALSE) ? ' multiple="multiple"' : ''; 
  185. $form = '<select '.$this->setAttrib($data, $defaults).$extra.$multiple.">\n"; 
  186.  
  187. foreach ($options as $key => $val) { 
  188. $key = (string) $key; 
  189. if (is_array($val)) { 
  190. $form .= '<optgroup label="'.$key.'">'."\n"; 
  191. foreach ($val as $optgroup_key => $optgroup_val) { 
  192. $sel = (in_array($optgroup_key, $selected)) ? ' selected="selected"' : ''; 
  193. $form .= '<option value="'.esc_attr($optgroup_key).'"'.$sel.'>'.(string) $optgroup_val."</option>\n"; 
  194. $form .= '</optgroup>'."\n"; 
  195. } else { 
  196. $sel = (in_array($key, $selected)) ? ' selected="selected"' : ''; 
  197. $form .= '<option value="'.esc_attr($key).'"'.$sel.'>'.(string) $val."</option>\n"; 
  198. $form .= '</select>'; 
  199. return $form; 
  200.  
  201.  
  202. function setAttrib($attributes, $default) { 
  203. if (is_array($attributes)) { 
  204. foreach ($default as $key => $val) { 
  205. if (isset($attributes[$key])) { 
  206. $default[$key] = $attributes[$key]; 
  207. unset($attributes[$key]); 
  208. if(isset($attributes["default"])) { 
  209.  
  210. $attributes["onBlur"]="if(this.value=='') {this.value='".$attributes["default"]."';this.style.color='#ccc';this.style.fontStyle='italic';}"; 
  211. $attributes["onFocus"]="if(this.value=='".$attributes["default"]."') {this.value='';this.style.color='#000';this.style.fontStyle='normal';}"; 
  212. if((!isset($default['value']) || !$default['value'])) { 
  213. $default['value']=$attributes["default"]; 
  214. $attributes["style"]="color:#ccc;font-style:italic;"; 
  215.  
  216. if (count($attributes) > 0) { 
  217. $default = array_merge($default, $attributes); 
  218.  
  219. $att = ''; 
  220.  
  221. foreach ($default as $key => $val) { 
  222. if($key=='value') $val=esc_attr($val); 
  223. $att .= $key . '="' . $val . '" '; 
  224.  
  225. return $att; 
  226.