[ Index ]

MailPress 7.1

[ Index ]     [ Classes ]     [ Functions ]     [ Variables ]     [ Constants ]     [ Statistics ]    

title

Body

[close]

/mp-includes/class/ -> MP_Form_templates.class.php (source)

   1  <?php
   2  class MP_Form_templates
   3  {
   4      var $templates = null;
   5  
   6  	function __construct()
   7      {
   8             // Load all templates.
   9          $advanced_path = 'advanced/' . get_current_blog_id() . '/forms';
  10  
  11          $root  = MP_UPL_ABSPATH . $advanced_path;
  12          $root  = apply_filters( 'MailPress_advanced_forms_root', $root );
  13          $root .= '/templates';
  14          $dir  = @opendir( $root );
  15          if ( $dir ) 
  16              while ( ( $file = readdir( $dir ) ) !== false ) if ( ( $file{0} != '.' ) && ( substr( $file, -4 ) == '.xml' ) ) 
  17              {
  18                  $f = file_get_contents( "$root/$file" );
  19                  if ( simplexml_load_string( $f ) )
  20                  {
  21                      $xml = new MP_Xml( $f );
  22                      $this->templates[substr( $file, 0, -4 )] = self::xml_clean_up( $xml->object->children );
  23                  }
  24              }
  25          @closedir( $dir );
  26      }
  27  
  28  // xml 
  29  	function xml_clean_up( $items )
  30      {
  31          switch ( true )
  32          {
  33              case ( isset( $items->children ) ) :
  34                  $tab[$items->name] = self::xml_clean_up( $items->children );
  35              break;
  36              case ( is_array( $items ) ) :
  37                  foreach( $items as $item ) $tab[$item->name] = ( isset( $item->children ) ) ? self::xml_clean_up( $item->children ) : self::xml_clean_up( $item );
  38              break;
  39              default :
  40                  if ( !empty( $items->textValue ) ) $tab = $items->textValue;
  41              break;
  42          }
  43          if ( isset( $tab ) ) return $tab;
  44      }
  45  
  46  // templates
  47  	function get_all()
  48      {
  49          foreach( $this->templates as $k => $v ) $templates[$k] = $k;
  50          return $templates;
  51      }
  52  
  53  	function get( $id )
  54      {
  55          return ( isset( $this->templates[$id] ) ) ? $this->templates[$id] : $this->templates['default'];
  56      }
  57  
  58  	function get_sub( $id, $sub )
  59      {
  60          if ( isset( $this->templates[$id][$sub] ) )                 return $this->templates[$id][$sub];
  61          if ( isset( $this->templates['default'][$sub] ) )             return $this->templates['default'][$sub];
  62          return false;
  63      }
  64  
  65  	function get_template_sub( $id, $sub, $field_template )
  66      {
  67          if ( isset( $this->templates[$id][$sub][$field_template] ) )         return $this->templates[$id][$sub][$field_template];
  68          if ( isset( $this->templates[$id][$sub]['standard'] ) )              return $this->templates[$id][$sub]['standard'];
  69          if ( isset( $this->templates['default'][$sub][$field_template] ) )     return $this->templates['default'][$sub][$field_template];
  70          if ( isset( $this->templates['default'][$sub]['standard'] ) )         return $this->templates['default'][$sub]['standard'];
  71          return false;
  72      }
  73  
  74      // field
  75  	function get_field( $id ) { return $this->get_sub( $id, 'fields' ); }
  76  	function get_field_template( $id, $field_template ) { return $this->get_template_sub( $id, 'fields', $field_template ); }
  77  	function get_all_fields( $id )
  78      {
  79          foreach( $this->get_field( $id ) as $k => $v ) $subtemplates[$k] = $k;
  80          return $subtemplates;
  81      }
  82  
  83      // field_on_error
  84  	function get_field_on_error_template( $id, $field_template ) { return $this->get_template_sub( $id, 'fields_on_error', $field_template ); }
  85  
  86      // groups
  87  	function get_group( $id ) { return $this->get_sub( $id, 'groups' ); }
  88  	function get_group_template( $id, $fields_template ) { return $this->get_template_sub( $id, 'groups', $fields_template ); }
  89  
  90      // composite field_types
  91  	function get_composite_template( $id, $field_type )
  92      { 
  93          if ( isset( $this->templates[$id]['composite'][$field_type] ) )    return $this->templates[$id]['composite'][$field_type];
  94          return false;
  95      }
  96  
  97      // message
  98  	function get_message_template( $id, $ret )  //$ret->( ok/ko )
  99      { 
 100          if ( isset( $this->templates[$id]['message'][$ret] ) )         return $this->templates[$id]['message'][$ret];
 101          if ( isset( $this->templates[$id]['message'] ) )              return $this->templates[$id]['message'];
 102          return false;
 103      }
 104  
 105      // form
 106  	function get_form_template( $id ) { return $this->get_sub( $id, 'form' ); }
 107  }


Generated: Mon Mar 11 18:33:33 2019 Cross-referenced by PHPXref 0.7.1