skipv1_0_0Form_Element

The Facebook Fanpage Import skip v1 0 Form Element class.

Defined (1)

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

/includes/skip/elements/forms/form-element.php  
  1. abstract class Form_Element extends HTML_Element{ 
  2. public $form_name; 
  3. public $name; 
  4. public $value; 
  5. public $save; 
  6. protected $errors = array(); 
  7. protected $error_msgs = array(); 
  8. protected $array; 
  9.  
  10. /** 
  11. * Constructor 
  12. * @package Skip 
  13. * @since 1.0 
  14. * @param string $tag The HTML Tag to use for element 
  15. * @param string $name The name of the element where to save data 
  16. * @param array $args Arguments 
  17. */ 
  18. function __construct( $tag, $name, $args = array() ) { 
  19. global $skip_form_name; 
  20.  
  21. /** 
  22. * Additional parent args: 
  23. * 'id' 
  24. * 'classes' 
  25. * 'before_element' 
  26. * 'after_element' 
  27. * 'params' 
  28. */ 
  29. $defaults = array( 
  30. 'label' => '',  
  31. 'description' => '',  
  32. 'default' => FALSE,  
  33. 'value' => '',  
  34. 'array' => '',  
  35. 'save' => TRUE,  
  36. 'disabled' => FALSE,  
  37. 'form_name' => $skip_form_name,  
  38. 'errors' => array(  
  39. 1 => __( 'Form could not be verified. Field could not be saved.', 'skip_framework' ),  
  40. 2 => sprintf( __( 'Upload limit exceeded. %s Bytes uploaded, %s Bytes allowed. Please try to upload one file after another or choose a smaller file.', 'skip_framework' ), array_key_exists( 'CONTENT_LENGTH', $_SERVER ) ? $_SERVER['CONTENT_LENGTH'] : 0, max_upload() ) 
  41. ); 
  42.  
  43. $args = wp_parse_args( $args, $defaults ); 
  44. extract( $args , EXTR_SKIP ); 
  45.  
  46. parent::__construct( $tag, $args ); 
  47.  
  48. $this->form_name = $form_name; 
  49. $this->name = $name; 
  50. $this->save = $save; 
  51. $this->default = $default; 
  52.  
  53. // Setting up Array 
  54. if( !is_array( $array ) ): 
  55. $this->array = explode( ', ', $array ); // For Values by param String 
  56.  
  57. if( count( $this->array ) == 1 ): 
  58. $this->array = $this->array[ 0 ]; 
  59. endif; 
  60.  
  61. // If array is given 
  62. else: 
  63. $this->array = $array; 
  64. endif; 
  65.  
  66. $this->errors = $errors; 
  67.  
  68. $this->field_name = $this->field_name(); // Name of HTML Field  
  69. $this->option_name = $this->option_name(); // Name of WP Option Field 
  70.  
  71. if( $save ) 
  72. $this->save(); // Register for saving 
  73.  
  74. if( '' == $value ) 
  75. $this->value = $this->value(); 
  76. else  
  77. $this->value = $value; 
  78.  
  79. // Setting up Tag 
  80. $this->add_param( 'name', $this->field_name ); 
  81. $this->add_param( 'value', $this->value ); 
  82.  
  83. if( TRUE == $disabled ) 
  84. $this->add_param( 'disabled', 'disabled' ); 
  85.  
  86. $this->before( '<div class="skip_field">' ); 
  87.  
  88. if( '' != $label ) 
  89. $this->before( '<div class="skip_field_row skip_field_row_' . $this->params[ 'id' ] . '"><label for="' . $this->params[ 'id' ] . '">' . $label . '</label><div class="skip_row_content">' ); 
  90.  
  91. if( '' != $description ) 
  92. $this->after( '<div class="skip_field_description skip_field_description_' . $this->params[ 'id' ] . '">' . $description . '</div>' ); 
  93.  
  94. if( '' != $label ) 
  95. $this->after( '</div><div class="clear"></div></div>' ); 
  96.  
  97. $this->after( '</div>' ); 
  98.  
  99. /** 
  100. * Value 
  101. *  
  102. * Gets the value type and returns the value from the field 
  103. * @package Skip 
  104. * @since 1.0 
  105. * @return string $value The Value of the field 
  106. */ 
  107. protected final function value() { 
  108. $value = $this->option_value(); 
  109.  
  110. if( !$value && $this->default !== FALSE ): 
  111. return $this->default; // If there has been no value before use default 
  112. else: 
  113. return $value; 
  114. endif; 
  115.  
  116. /** 
  117. * Gets the value from option field type 
  118. * @package Skip 
  119. * @since 1.0 
  120. * @return string $value The Value of the field 
  121. */ 
  122. private final function option_value() { 
  123. return get_option( $this->option_name ); 
  124.  
  125. /** 
  126. * Gets the value from post field type 
  127. * @package Skip 
  128. * @since 1.0 
  129. * @return string $value The Value of the field 
  130. */ 
  131. private final function post_type_value() { 
  132.  
  133.  
  134. /** 
  135. * Gets the value from taxonomy field type 
  136. * @package Skip 
  137. * @since 1.0 
  138. * @return string $value The Value of the field 
  139. */ 
  140. private final function taxonmy_value() { 
  141.  
  142.  
  143. /** 
  144. * Gets the name of the element in options table 
  145. * @package Skip 
  146. * @since 1.0 
  147. * @return string $option_name The Name of the element 
  148. */ 
  149. private final function option_name() { 
  150.  
  151. // Normal field 
  152. if( '' == $this->array ): 
  153. $option_name = $this->form_name . '_' . $this->name; 
  154. // Multidimensional Array field 
  155. elseif( is_array( $this->array ) ): 
  156. $option_name = $this->form_name . '_' . $this->name; 
  157.  
  158. foreach ( $this->array as $key ) 
  159. $option_name .= SKIP_DELIMITER . $key; 
  160.  
  161. // Array field 
  162. else: 
  163. $option_name = $this->form_name . '_' . $this->name . SKIP_DELIMITER . $this->array; 
  164. endif; 
  165.  
  166. return 'skip_framework_value_' . $option_name; 
  167.  
  168. /** 
  169. * Gets the HTML name of the element 
  170. * @package Skip 
  171. * @since 1.0 
  172. * @return string $field_name The HTML name of the element 
  173. */ 
  174. private final function field_name() { 
  175.  
  176. // Normal field 
  177. if( '' == $this->array ): 
  178. $field_name = $this->form_name . '_value[' . $this->name . ']'; 
  179. // Multidimensional Array field 
  180. elseif( is_array( $this->array ) ): 
  181. $field_name = $this->form_name . '_value[' . $this->name . ']'; 
  182.  
  183. foreach ( $this->array as $key ) 
  184. $field_name .= '[' . $key . ']'; 
  185. // Array field  
  186. else: 
  187. $field_name = $this->form_name . '_value[' . $this->name . '][' . $this->array . ']'; 
  188. endif; 
  189.  
  190. return $field_name; 
  191.  
  192. /** 
  193. * Gets the posted value From an Element 
  194. * @package Skip 
  195. * @since 1.0 
  196. * @return string $value The value of the element which was posted by a form 
  197. */ 
  198. private final function posted_value() { 
  199. $fields = $_POST[ $this->form_name . '_value' ]; 
  200.  
  201. if( !array_key_exists( $this->name, $fields ) ) 
  202. return; 
  203.  
  204. $field = $fields[ $this->name ]; 
  205.  
  206. // Normal field 
  207. if( !$this->array ) 
  208. return $field; 
  209.  
  210. // Multidimensional Array field 
  211. elseif( is_array( $this->array ) ) 
  212. return $this->array_value( $field, $this->array ); 
  213.  
  214. // Array field 
  215. else 
  216. return $field[ $this->array ]; 
  217.  
  218. /** 
  219. * Helper function to get an array value from a multidimesional Array 
  220. * @package Skip 
  221. * @since 1.0 
  222. * @return string $value The value of the array Element 
  223. */ 
  224. private final function array_value( $value, $array, $i = 0 ) { 
  225. if( $i < count( $array ) ) 
  226. return $this->array_value( $value[ $array[ $i ] ], $array, ++$i ); 
  227. else 
  228. return $value; 
  229.  
  230. /** 
  231. * Saveing posted Values 
  232. * @package Skip 
  233. * @since 1.0 
  234. */ 
  235. protected function save() { 
  236. global $skip_form_name, $skip_form_save_fields; 
  237. $skip_form_save_fields[ $skip_form_name ][] = array( 'name' => $this->name, 'option_name' => $this->option_name, 'array' => $this->array ); // Saving field names for later saving 
  238.  
  239. /** 
  240. * Rendering element 
  241. * @package Skip 
  242. * @since 1.0 
  243. * @return string $content The content of the element as HTML 
  244. */ 
  245. public function render() { 
  246. if( count( $this->error_msgs ) > 0 ) 
  247. foreach( $this->error_msgs AS $message ) 
  248. $this->after( '<div class="skip_error ui-state-error ui-corner-all"><p><span class="ui-icon ui-icon-alert" style="float: left; margin-right: .3em;"></span>' . $message . '</p></div>' ); 
  249.  
  250. return parent::render();