Esempio n. 1
0
 function setMeta($name, $value, $readonly = false)
 {
     $e = $this->query('/*/meta[@name="' . htmlspecialchars($name) . '"]')->item(0);
     if (!$e) {
         $e = $this->de()->appendChild($this->createElement('meta', array('name' => $name)));
     }
     if ($e) {
         xml::setElementText($e, $value);
     }
     if ($readonly) {
         $e->setAttribute('readonly', 'readonly');
     } elseif ($e->hasAttribute('readonly')) {
         $e->removeAttribute('readonly');
     }
 }
Esempio n. 2
0
 function setValue($value)
 {
     if ($this->hasCheck('num')) {
         if (is_numeric($value)) {
             $value = str_replace('.', ',', floatval($value));
         } else {
             $value = null;
         }
     }
     xml::setElementText($this->e, $value);
 }
Esempio n. 3
0
 function __call($m, $a)
 {
     $xml = new xml($this->e);
     switch ($m) {
         case 'rewind':
         case 'current':
         case 'key':
         case 'next':
         case 'valid':
         case 'setButton':
         case 'getButtons':
             return call_user_func(array($this, $m), $a);
         default:
             if (preg_match('/^get(\\w+)$/', $m, $res)) {
                 $name = strtolower($res[1]);
                 if ($name == row::IDATTR) {
                     return $this->e->getAttribute('id');
                 } elseif ($this->hasColumn($name) && ($e = $xml->query($name, $this->e)->item(0))) {
                     return xml::getElementText($e);
                 }
             } elseif (preg_match('/^set(\\w+)$/', $m, $res)) {
                 switch ($name = strtolower($res[1])) {
                     case row::IDATTR:
                         if ($val = $a[0]) {
                             $this->e->setAttribute('id', $val);
                         } elseif ($this->e->hasAttribute('id')) {
                             $this->e->removeAttribute('id');
                         }
                         break;
                     default:
                         if ($this->hasColumn($name)) {
                             $e = null;
                             if ($e = $xml->query('cell[@name="' . htmlspecialchars($name) . '"]', $this->e)->item(0)) {
                             } else {
                                 $e = $this->e->appendChild($xml->createElement('cell', array('name' => $name)));
                             }
                             if ($e) {
                                 xml::setElementText($e, $a[0]);
                             }
                         }
                 }
             }
     }
 }
Esempio n. 4
0
 function run()
 {
     global $_out;
     $captcha = new captcha();
     $captcha->setParamName('captcha');
     if ($form = $this->query('form')->item(0)) {
         //нашли форму
         if (!$form->getAttribute('action')) {
             $form->setAttribute('action', $_SERVER['REQUEST_URI']);
         }
         if ($this->isSent($form)) {
             //форму отправили
             if (!$this->check($form) && ($res = $this->getSentData($form))) {
                 $e = $this->getSection()->getXML()->createElement('final', null);
                 $resultSQL = $resultMail = true;
                 if (count($res['mysql'])) {
                     $resultSQL = $this->insertDB($res['mysql'], $form);
                 }
                 if ($res['xml']) {
                     $resultMail = $this->sendEmail($res['xml'], $form);
                 }
                 if ($resultSQL && $resultMail) {
                     xml::setElementText($e, xml::getElementText($this->getSection()->getXML()->query('good', $form)->item(0)));
                 } else {
                     xml::setElementText($e, xml::getElementText($this->getSection()->getXML()->query('fail', $form)->item(0)));
                 }
                 $form->appendChild($e);
             } else {
                 // Ошибка - заполняем форму
                 $this->fillForm($form);
             }
         }
         $_out->addSectionContent($form);
         $captcha->setLanguage('en');
         $captcha->create('userfiles/cptch.jpg');
     }
 }
Esempio n. 5
0
 function save()
 {
     $files = array();
     foreach ($this->values as $fpath => $values) {
         if (!isset($files[$fpath])) {
             $files[$fpath] = $this->getXML($fpath, null, false);
         }
         $xml = $files[$fpath];
         foreach ($values as $xpath => $data) {
             //создаем недостающие элементы из xpath запроса
             $elemToCreate = array();
             $arQuery = explode('/', $xpath);
             $elem = null;
             while ($query = implode('/', $arQuery)) {
                 if ($elem = $xml->query($query)->item(0)) {
                     break;
                 } else {
                     array_unshift($elemToCreate, array_pop($arQuery));
                 }
             }
             if (!$elem) {
                 $elem = $xml->dd();
             }
             foreach ($elemToCreate as $str) {
                 if (preg_match('/^([\\w\\-]+)(?:\\[((?:@[\\w\\-]+|@[\\w\\-]+=["\'][\\w\\-]+["\']|\\s+|and|or|[0-9])+)\\]){0,1}$/', $str, $res)) {
                     $elem = $elem->appendChild($xml->createElement($res[1]));
                     if (isset($res[2])) {
                         $tmp = explode(' ', $res[2]);
                         //все атрибуты в условии запроса, у которых заданы значения, будут созданы
                         foreach ($tmp as $str) {
                             if (preg_match('/^@([\\w\\-]+)=["\']([\\w\\-]+)["\']$/', trim($str), $res)) {
                                 $elem->setAttribute($res[1], $res[2]);
                             }
                         }
                     }
                 } else {
                     break;
                 }
             }
             //Устанавливаем значения. Сначала получим целевой элемент
             if ($xpath == '/' && ($e = $xml->dd()) || ($e = $xml->query($xpath)->item(0)) || preg_match('/(.*)\\/@([\\w\\-]+)$/', $xpath, $matches) && ($tmp = $xml->query($matches[1])->item(0)) && ($e = $tmp->setAttribute($matches[2], null))) {
                 switch ($elementClass = get_class($e)) {
                     case 'DOMAttr':
                         if ($data['value']) {
                             if (!is_array($data['value'])) {
                                 $e->value = $data['value'];
                             }
                         } elseif ($e->ownerElement->hasAttribute($e->name)) {
                             $e->ownerElement->removeAttribute($e->name);
                         }
                         break;
                     case 'DOMDocument':
                     case 'DOMElement':
                         if ($data['hash']) {
                             if (preg_match('/^([\\w\\-]+)(?:\\[((?:@[\\w\\-]+|@[\\w\\-]+=["\'][\\w\\-]+["\']|\\s+|and)+)\\]){0,1}$/', $data['hash'] = trim($data['hash']), $res)) {
                                 $elem = null;
                                 if (!$elem) {
                                     $elem = $e->appendChild($xml->createElement($res[1], null, is_array($data['value']) ? null : $data['value']));
                                     if (isset($res[2])) {
                                         $tmp = explode('and', $res[2]);
                                         foreach ($tmp as $attr) {
                                             if (preg_match('/^@([\\w\\-]+)=["\']([\\w\\-]+)["\']$/', trim($attr), $res)) {
                                                 $elem->setAttribute($res[1], $res[2]);
                                             }
                                         }
                                     }
                                 }
                                 if (is_array($data['value'])) {
                                     foreach ($data['value'] as $name => $value) {
                                         if (!is_numeric($name)) {
                                             if ($value) {
                                                 $elem->setAttribute($name, $value);
                                             } elseif ($elem->hasAttribute($name)) {
                                                 $elem->removeAttribute($name);
                                             }
                                         }
                                     }
                                 }
                             }
                         } else {
                             if (is_array($data['value'])) {
                                 foreach ($data['value'] as $name => $value) {
                                     if (!is_numeric($name)) {
                                         if ($value) {
                                             $elem->setAttribute($name, $value);
                                         } elseif ($elem->hasAttribute($name)) {
                                             $elem->removeAttribute($name);
                                         }
                                     }
                                 }
                             } else {
                                 xml::setElementText($elem, $data['value']);
                             }
                         }
                         break;
                 }
             }
         }
         $xml->save();
     }
 }