ILIAS  Release_4_2_x_branch Revision 61807
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilSoapMailXmlParser.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 
5 include_once './classes/class.ilSaxParser.php';
6 include_once './Services/User/classes/class.ilObjUser.php';
7 
17 {
21  public function __construct($a_xml)
22  {
23  parent::__construct('',true);
24  $this->setThrowException(true);
25  $this->setXMLContent($a_xml);
26  }
27 
32  public function getMails()
33  {
34  return (array) $this->mails;
35  }
36 
44  public function start ()
45  {
46  $this->startParsing();
47  return true;
48  }
49 
50 
57  public function setHandlers($a_xml_parser)
58  {
59  xml_set_object($a_xml_parser,$this);
60  xml_set_element_handler($a_xml_parser,'handlerBeginTag','handlerEndTag');
61  xml_set_character_data_handler($a_xml_parser,'handlerCharacterData');
62  }
63 
71  public function handlerBeginTag($a_xml_parser,$a_name,$a_attribs)
72  {
73  switch($a_name)
74  {
75  case 'Mail':
76  $this->mail = array();
77  $this->mail['usePlaceholders'] = $a_attribs['usePlaceholders'] ? true : false;
78  $this->mail['type'] = $a_attribs['type'] == 'System' ? 'system' : 'normal';
79  break;
80 
81  case 'To':
82  $this->mail['to'] = $this->parseName($a_attribs);
83  break;
84 
85  case 'Cc':
86  $this->mail['cc'] = $this->parseName($a_attribs);
87  break;
88 
89  case 'Bcc':
90  $this->mail['bcc'] = $this->parseName($a_attribs);
91  break;
92 
93  case 'Subject':
94  break;
95 
96  case 'Message':
97  $this->lines = array();
98  break;
99 
100  case 'Attachment':
101  $this->attachment = array();
102  $this->attachment['name'] = $a_attribs['name'];
103  break;
104 
105  }
106  }
107 
114  public function handlerEndTag($a_xml_parser,$a_name)
115  {
116  switch($a_name)
117  {
118  case 'Mail':
119  $this->mails[] = $this->mail;
120  break;
121 
122  case 'Subject':
123  $this->mail['subject'] = $this->cdata;
124  break;
125 
126  case 'Message':
127  $this->mail['body'] = (array) $this->lines;
128  break;
129 
130  case 'P':
131  $this->lines[] = trim($this->cdata);
132  break;
133 
134  case 'Attachment':
135  $this->attachment['content'] = base64_decode(trim($this->cdata));
136  $this->mail['attachments'][] = $this->attachment;
137  break;
138  }
139 
140  $this->cdata = '';
141  }
142 
149  public function handlerCharacterData($a_xml_parser,$a_data)
150  {
151  if($this->in_metadata)
152  {
153  parent::handlerCharacterData($a_xml_parser,$a_data);
154  }
155 
156  if($a_data != "\n")
157  {
158  // Replace multiple tabs with one space
159  $a_data = preg_replace("/\t+/"," ",$a_data);
160  $this->cdata .= $a_data;
161  }
162  }
163 
170  protected function parseName($a_attribs)
171  {
172  include_once './classes/class.ilObjectFactory.php';
173 
174  if($a_attribs['obj_id'])
175  {
176  $il_id = explode('_',$a_attribs['obj_id']);
177  $GLOBALS['ilLog']->write('il ID:'.print_r($il_id,true));
178  if(!$user = ilObjectFactory::getInstanceByObjId($il_id[3],false))
179  {
180  throw new InvalidArgumentException("Invalid user id given: obj_id => ".$a_attribs['obj_id']);
181  }
182  return $user->getLogin();
183  }
184  else
185  {
186  return $a_attribs['name'];
187  }
188  }
189 }
190 ?>