frontier_prefilter_template

Processes template code within an each command from the base template.

Description

(null) frontier_prefilter_template( (array) $code, (string) $template, $pod ); 

Returns (null)

Parameters (3)

0. $code (array)
Attributes from template
1. $template (string)
Template to be processed
2. $pod
The pod.

Usage

  1. if ( !function_exists( 'frontier_prefilter_template' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'pods-custom-content-types-and-fields/components/Templates/includes/functions-view_template.php'; 
  3.  
  4. // attributes from template 
  5. $code = array(); 
  6.  
  7. // template to be processed 
  8. $template = ''; 
  9.  
  10. // The pod. 
  11. $pod = null; 
  12.  
  13. // NOTICE! Understand what this does before running. 
  14. $result = frontier_prefilter_template($code, $template, $pod); 
  15.  

Defined (1)

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

/components/Templates/includes/functions-view_template.php  
  1. function frontier_prefilter_template( $code, $template, $pod ) { 
  2.  
  3. global $frontier_once_tags; 
  4.  
  5. $commands = array( 
  6. 'each' => 'pod_sub_template',  
  7. 'once' => 'pod_once_template',  
  8. 'before' => 'pod_before_template',  
  9. 'after' => 'pod_after_template',  
  10. 'if' => 'pod_if_field',  
  11. ); 
  12.  
  13. $commands = array_merge( $commands, get_option( 'pods_frontier_extra_commands', array() ) ); 
  14.  
  15. /** 
  16. * Add additional control blocks to Pods templates 
  17. * Can also be use to remove each/once/before/after/if functionality from Pods Templates 
  18. * @param array $commands The control blocks in the form of 'tag' => 'shortcode' 
  19. * @return array An array of control blocks, and shortcodes used to power them. 
  20. * @since 1.0.0 
  21. */ 
  22. $commands = apply_filters( 'pods_frontier_template_commands', $commands ); 
  23.  
  24. $aliases = array(); 
  25. foreach ( $commands as $command => $shortcode ) { 
  26. preg_match_all( "/(\[" . $command . "(.*?)]|\[\/" . $command . "\])/m", $code, $matches ); 
  27. if ( !empty( $matches[ 0 ] ) ) { 
  28. // holder for found blocks. 
  29. $blocks = array(); 
  30. $indexCount = 0; 
  31. foreach ( $matches[ 0 ] as $key => $tag ) { 
  32. if ( false === strpos( $tag, '[/' ) ) { 
  33. // open tag 
  34. $field = null; 
  35. $value = null; 
  36. $ID = '{@EntryID}'; 
  37. $atts = ' pod="@pod" id="' . $ID . '"'; 
  38. if ( !empty( $matches[ 2 ][ $key ] ) ) { 
  39. // get atts if any 
  40. //$atts = shortcode_parse_atts(str_replace('.', '____', $matches[2][$key])); 
  41. $atts = array(); 
  42. $pattern = '/(\w.+)\s*=\s*"([^"]*)"(?:\s|$)/'; 
  43. $text = preg_replace( "/[\x{00a0}\x{200b}]+/u", " ", $matches[ 2 ][ $key ] ); 
  44. if ( preg_match_all( $pattern, $text, $match, PREG_SET_ORDER ) ) { 
  45. $field = $match[ 0 ][ 1 ]; 
  46. $value = $match[ 0 ][ 2 ]; 
  47. else { 
  48. $field = trim( $matches[ 2 ][ $key ] ); 
  49. if ( false !== strpos( $field, '.' ) ) { 
  50. $path = explode( '.', $field ); 
  51. $field = array_pop( $path ); 
  52. $ID = '{@' . implode( '.', $path ) . '.' . $pod->api->pod_data[ 'field_id' ] . '}'; 
  53. $atts = ' id="' . $ID . '" pod="@pod" field="' . $field . '"'; 
  54. if ( !empty( $value ) ) { 
  55. $atts .= ' value="' . $value . '"'; 
  56.  
  57. $newtag = $shortcode . '__' . $key; 
  58. $tags[ $indexCount ] = $newtag; 
  59. $aliases[ ] = $newtag; 
  60. $code = preg_replace( "/(" . preg_quote( $tag ) . ")/m", "[" . $newtag . $atts . " index=\"{_index}\"]", $code, 1 ); 
  61. $indexCount++; 
  62. else { 
  63. // close tag 
  64. $indexCount--; 
  65. $newclose = $tags[ $indexCount ]; 
  66. $code = preg_replace( "/(" . preg_quote( $tag, '/' ) . ")/m", "[/" . $newclose . "]", $code, 1 ); 
  67.  
  68. if ( $command == 'if' ) { 
  69. //dump($pod); 
  70. // get new aliased shotcodes 
  71.  
  72. if ( !empty( $aliases ) ) { 
  73. $code = frontier_backtrack_template( $code, $aliases ); 
  74. $code = str_replace( '@pod', $pod->pod, $code ); 
  75. $code = str_replace( '@EntryID', '@' . $pod->api->pod_data[ 'field_id' ], $code ); 
  76.  
  77. return $code;