Beispiel #1
0
 static function XMLToClass($xml, $class = null)
 {
     if ($class) {
         $obj = new $class();
     } else {
         $obj = new stdClass();
     }
     if (!$xml) {
         return (string) $xml;
     }
     if (count($xml->attributes()) == 0 && count($xml->children()) == 0) {
         return (string) $xml;
     }
     foreach ($xml->attributes() as $id => $value) {
         $value = trim((string) $value);
         if ($value == "") {
             continue;
         }
         $obj->{$id} = (string) $value;
     }
     foreach ($xml->children() as $child) {
         $name = $child->getName();
         if (property_exists($obj, $name)) {
             if (!is_array($obj->{$name})) {
                 $t = $obj->{$name};
                 $obj->{$name} = array();
                 array_push($obj->{$name}, $t);
             }
             array_push($obj->{$name}, FSJ_XML::XMLToClass($child));
         } else {
             $obj->{$name} = FSJ_XML::XMLToClass($child);
         }
     }
     return $obj;
 }
Beispiel #2
0
 function TrimMessage()
 {
     $lines = explode("\n", $this->plainmsg);
     $this->plainmsg = array();
     require_once JPATH_SITE . DS . 'components' . DS . 'com_fss' . DS . 'helper' . DS . 'xml.php';
     $path = JPATH_ROOT . DS . 'components' . DS . 'com_fss' . DS . 'plugins' . DS . 'emailcheck' . DS . 'trim' . DS;
     $files = JFolder::files($path, '(.xml$)');
     $matches = array();
     foreach ($files as $file) {
         $xml = simplexml_load_file($path . $file);
         foreach ($xml->trimmatch as $match) {
             $matches[] = FSJ_XML::XMLToClass($match, "TrimMatch");
         }
     }
     $found_trim = false;
     foreach ($lines as $offset => $line) {
         $start_trim = false;
         foreach ($matches as $match) {
             if ($match->Match($line, $lines, $offset)) {
                 $start_trim = true;
                 break;
             }
         }
         if ($start_trim && !$found_trim) {
             while (true) {
                 $last = end($this->plainmsg);
                 $last = trim($last);
                 if ($last == "") {
                     array_pop($this->plainmsg);
                 } else {
                     break;
                 }
             }
             $this->plainmsg[] = "[quoted]";
             $found_trim = true;
         }
         $this->plainmsg[] = $line;
     }
     if ($found_trim) {
         $this->plainmsg[] = "[/quoted]";
     }
     for ($i = count($this->plainmsg) - 1; $i > 0; $i--) {
         if (trim($this->plainmsg[$i]) == "") {
             unset($this->plainmsg[$i]);
         } else {
             break;
         }
     }
     $this->plainmsg = implode("\n", $this->plainmsg);
 }