[ Index ]

MailPress 544

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


Generated: Thu Apr 28 18:38:52 2016 Cross-referenced by PHPXref 0.7.1