PodsField_Paragraph

The Pods - Custom Content Types and Fields PodsField Paragraph class.

Defined (1)

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

/classes/fields/paragraph.php  
  1. class PodsField_Paragraph extends PodsField { 
  2.  
  3. /** 
  4. * Field Type Group 
  5. * @var string 
  6. * @since 2.0 
  7. */ 
  8. public static $group = 'Paragraph'; 
  9.  
  10. /** 
  11. * Field Type Identifier 
  12. * @var string 
  13. * @since 2.0 
  14. */ 
  15. public static $type = 'paragraph'; 
  16.  
  17. /** 
  18. * Field Type Label 
  19. * @var string 
  20. * @since 2.0 
  21. */ 
  22. public static $label = 'Plain Paragraph Text'; 
  23.  
  24. /** 
  25. * Field Type Preparation 
  26. * @var string 
  27. * @since 2.0 
  28. */ 
  29. public static $prepare = '%s'; 
  30.  
  31. /** 
  32. * Do things like register/enqueue scripts and stylesheets 
  33. * @since 2.0 
  34. */ 
  35. public function __construct () { 
  36.  
  37.  
  38. /** 
  39. * Add options and set defaults to 
  40. * @return array 
  41. * @since 2.0 
  42. */ 
  43. public function options () { 
  44. $options = array( 
  45. self::$type . '_repeatable' => array( 
  46. 'label' => __( 'Repeatable Field', 'pods' ),  
  47. 'default' => 0,  
  48. 'type' => 'boolean',  
  49. 'help' => __( 'Making a field repeatable will add controls next to the field which allows users to Add/Remove/Reorder additional values. These values are saved in the database as an array, so searching and filtering by them may require further adjustments".', 'pods' ),  
  50. 'boolean_yes_label' => '',  
  51. 'dependency' => true,  
  52. 'developer_mode' => true 
  53. ),  
  54. 'output_options' => array( 
  55. 'label' => __( 'Output Options', 'pods' ),  
  56. 'group' => array( 
  57. self::$type . '_allow_html' => array( 
  58. 'label' => __( 'Allow HTML?', 'pods' ),  
  59. 'default' => 1,  
  60. 'type' => 'boolean',  
  61. 'dependency' => true 
  62. ),  
  63. self::$type . '_oembed' => array( 
  64. 'label' => __( 'Enable oEmbed?', 'pods' ),  
  65. 'default' => 0,  
  66. 'type' => 'boolean',  
  67. 'help' => array( 
  68. __( 'Embed videos, images, tweets, and other content.', 'pods' ),  
  69. 'http://codex.wordpress.org/Embeds' 
  70. ),  
  71. self::$type . '_wptexturize' => array( 
  72. 'label' => __( 'Enable wptexturize?', 'pods' ),  
  73. 'default' => 1,  
  74. 'type' => 'boolean',  
  75. 'help' => array( 
  76. __( 'Transforms less-beautfiul text characters into stylized equivalents.', 'pods' ),  
  77. 'http://codex.wordpress.org/Function_Reference/wptexturize' 
  78. ),  
  79. self::$type . '_convert_chars' => array( 
  80. 'label' => __( 'Enable convert_chars?', 'pods' ),  
  81. 'default' => 1,  
  82. 'type' => 'boolean',  
  83. 'help' => array( 
  84. __( 'Converts text into valid XHTML and Unicode', 'pods' ),  
  85. 'http://codex.wordpress.org/Function_Reference/convert_chars' 
  86. ),  
  87. self::$type . '_wpautop' => array( 
  88. 'label' => __( 'Enable wpautop?', 'pods' ),  
  89. 'default' => 1,  
  90. 'type' => 'boolean',  
  91. 'help' => array( 
  92. __( 'Changes double line-breaks in the text into HTML paragraphs', 'pods' ),  
  93. 'http://codex.wordpress.org/Function_Reference/wpautop' 
  94. ),  
  95. self::$type . '_allow_shortcode' => array( 
  96. 'label' => __( 'Allow Shortcodes?', 'pods' ),  
  97. 'default' => 0,  
  98. 'type' => 'boolean',  
  99. 'dependency' => true,  
  100. 'help' => array( 
  101. __( 'Embed [shortcodes] that help transform your static content into dynamic content.', 'pods' ),  
  102. 'http://codex.wordpress.org/Shortcode_API' 
  103. ),  
  104. self::$type . '_allowed_html_tags' => array( 
  105. 'label' => __( 'Allowed HTML Tags', 'pods' ),  
  106. 'depends-on' => array( self::$type . '_allow_html' => true ),  
  107. 'default' => 'strong em a ul ol li b i',  
  108. 'type' => 'text',  
  109. 'help' => __( 'Format: strong em a ul ol li b i', 'pods' ) 
  110. ),  
  111. self::$type . '_max_length' => array( 
  112. 'label' => __( 'Maximum Length', 'pods' ),  
  113. 'default' => 0,  
  114. 'type' => 'number',  
  115. 'help' => __( 'Set to -1 for no limit', 'pods' ) 
  116. )/**,  
  117. self::$type . '_size' => array( 
  118. 'label' => __( 'Field Size', 'pods' ),  
  119. 'default' => 'medium',  
  120. 'type' => 'pick',  
  121. 'data' => array( 
  122. 'small' => __( 'Small', 'pods' ),  
  123. 'medium' => __( 'Medium', 'pods' ),  
  124. 'large' => __( 'Large', 'pods' ) 
  125. )*/ 
  126. ); 
  127.  
  128. if ( function_exists( 'Markdown' ) ) { 
  129. $options[ 'output_options' ][ 'group' ][ self::$type . '_allow_markdown' ] = array( 
  130. 'label' => __( 'Allow Markdown Syntax?', 'pods' ),  
  131. 'default' => 0,  
  132. 'type' => 'boolean' 
  133. ); 
  134.  
  135. return $options; 
  136.  
  137. /** 
  138. * Define the current field's schema for DB table storage 
  139. * @param array $options 
  140. * @return array 
  141. * @since 2.0 
  142. */ 
  143. public function schema ( $options = null ) { 
  144. $length = (int) pods_v( self::$type . '_max_length', $options, 0 ); 
  145.  
  146. $schema = 'LONGTEXT'; 
  147.  
  148. if ( 0 < $length ) { 
  149. $schema = 'VARCHAR(' . $length . ')'; 
  150.  
  151. return $schema; 
  152.  
  153. /** 
  154. * Change the way the value of the field is displayed with Pods::get 
  155. * @param mixed $value 
  156. * @param string $name 
  157. * @param array $options 
  158. * @param array $pod 
  159. * @param int $id 
  160. * @return mixed|null|string 
  161. * @since 2.0 
  162. */ 
  163. public function display ( $value = null, $name = null, $options = null, $pod = null, $id = null ) { 
  164. $value = $this->strip_html( $value, $options ); 
  165.  
  166. if ( 1 == pods_var( self::$type . '_oembed', $options, 0 ) ) { 
  167. $embed = $GLOBALS[ 'wp_embed' ]; 
  168. $value = $embed->run_shortcode( $value ); 
  169. $value = $embed->autoembed( $value ); 
  170.  
  171. if ( 1 == pods_var( self::$type . '_wptexturize', $options, 1 ) ) 
  172. $value = wptexturize( $value ); 
  173.  
  174. if ( 1 == pods_var( self::$type . '_convert_chars', $options, 1 ) ) 
  175. $value = convert_chars( $value ); 
  176.  
  177. if ( 1 == pods_var( self::$type . '_wpautop', $options, 1 ) ) 
  178. $value = wpautop( $value ); 
  179.  
  180. if ( 1 == pods_var( self::$type . '_allow_shortcode', $options, 0 ) ) { 
  181. if ( 1 == pods_var( self::$type . '_wpautop', $options, 1 ) ) 
  182. $value = shortcode_unautop( $value ); 
  183.  
  184. $value = do_shortcode( $value ); 
  185.  
  186. if ( function_exists( 'Markdown' ) && 1 == pods_v( self::$type . '_allow_markdown', $options ) ) { 
  187. $value = Markdown( $value ); 
  188.  
  189. return $value; 
  190.  
  191. /** 
  192. * Customize output of the form field 
  193. * @param string $name 
  194. * @param mixed $value 
  195. * @param array $options 
  196. * @param array $pod 
  197. * @param int $id 
  198. * @since 2.0 
  199. */ 
  200. public function input ( $name, $value = null, $options = null, $pod = null, $id = null ) { 
  201. $options = (array) $options; 
  202. $form_field_type = PodsForm::$field_type; 
  203.  
  204. if ( is_array( $value ) ) 
  205. $value = implode( "\n", $value ); 
  206.  
  207. if ( isset( $options[ 'name' ] ) && false === PodsForm::permission( self::$type, $options[ 'name' ], $options, null, $pod, $id ) ) { 
  208. if ( pods_var( 'read_only', $options, false ) ) 
  209. $options[ 'readonly' ] = true; 
  210. else 
  211. return; 
  212. elseif ( !pods_has_permissions( $options ) && pods_var( 'read_only', $options, false ) ) 
  213. $options[ 'readonly' ] = true; 
  214.  
  215. pods_view( PODS_DIR . 'ui/fields/textarea.php', compact( array_keys( get_defined_vars() ) ) ); 
  216.  
  217. /** 
  218. * Change the value or perform actions after validation but before saving to the DB 
  219. * @param mixed $value 
  220. * @param int $id 
  221. * @param string $name 
  222. * @param array $options 
  223. * @param array $fields 
  224. * @param array $pod 
  225. * @param object $params 
  226. * @return mixed|string 
  227. * @since 2.0 
  228. */ 
  229. public function pre_save ( $value, $id = null, $name = null, $options = null, $fields = null, $pod = null, $params = null ) { 
  230. $value = $this->strip_html( $value, $options ); 
  231.  
  232. $length = (int) pods_var( self::$type . '_max_length', $options, 0 ); 
  233.  
  234. if ( 0 < $length && $length < pods_mb_strlen( $value ) ) { 
  235. $value = pods_mb_substr( $value, 0, $length ); 
  236.  
  237. return $value; 
  238.  
  239. /** 
  240. * Customize the Pods UI manage table column output 
  241. * @param int $id 
  242. * @param mixed $value 
  243. * @param string $name 
  244. * @param array $options 
  245. * @param array $fields 
  246. * @param array $pod 
  247. * @return mixed|string 
  248. * @since 2.0 
  249. */ 
  250. public function ui ( $id, $value, $name = null, $options = null, $fields = null, $pod = null ) { 
  251. $value = $this->strip_html( $value, $options ); 
  252.  
  253. $value = wp_trim_words( $value ); 
  254.  
  255. return $value; 
  256.  
  257. /** 
  258. * Strip HTML based on options 
  259. * @param string $value 
  260. * @param array $options 
  261. * @return string 
  262. */ 
  263. public function strip_html ( $value, $options = null ) { 
  264. if ( is_array( $value ) ) 
  265. $value = @implode( ' ', $value ); 
  266.  
  267. $value = trim( $value ); 
  268.  
  269. if ( empty( $value ) ) 
  270. return $value; 
  271.  
  272. $options = (array) $options; 
  273.  
  274. if ( 1 == pods_var( self::$type . '_allow_html', $options ) ) { 
  275. $allowed_html_tags = ''; 
  276.  
  277. if ( 0 < strlen( pods_var( self::$type . '_allowed_html_tags', $options ) ) ) { 
  278. $allowed_tags = pods_var( self::$type . '_allowed_html_tags', $options ); 
  279. $allowed_tags = trim( str_replace( array( '<', '>', ', ' ), ' ', $allowed_tags ) ); 
  280. $allowed_tags = explode( ' ', $allowed_tags ); 
  281. $allowed_tags = array_unique( array_filter( $allowed_tags ) ); 
  282.  
  283. if ( !empty( $allowed_tags ) ) { 
  284. $allowed_html_tags = '<' . implode( '><', $allowed_tags ) . '>'; 
  285.  
  286. if ( !empty( $allowed_html_tags ) ) 
  287. $value = strip_tags( $value, $allowed_html_tags ); 
  288. else 
  289. $value = strip_tags( $value ); 
  290.  
  291. return $value;