コード例 #1
0
ファイル: controller.statique.php プロジェクト: arno06/Savely
 /**
  * @return void
  */
 public function captcha()
 {
     if (!Core::checkRequiredGetVars("form", "input")) {
         Go::to404();
     }
     $form = $_GET["form"];
     $input = $_GET["input"];
     if (isset($_GET["backoffice"]) && $_GET["backoffice"] == 1) {
         Core::$isBackoffice = true;
     }
     $form = new Form($form);
     $captcha = $form->getInput($input);
     if (empty($captcha) || $captcha["tag"] != Form::TAG_CAPTCHA) {
         Go::to404();
     }
     $avaibles = array("backgroundColor", "fontSizeMax", "fontSizeMin", "width", "height", "rotation", "transparent");
     if (!isset($captcha["length"]) || empty($captcha["length"]) || $captcha["length"] == 0) {
         $captcha["length"] = 5;
     }
     $c = new Captcha($captcha["length"], $input);
     if (isset($captcha["fontColors"]) && is_array($captcha["fontColors"])) {
         $a = $captcha["fontColors"];
         for ($i = 0, $max = count($a); $i < $max; $i++) {
             $c->addFontColor($a[$i]);
         }
     }
     if (isset($captcha["fontFace"]) && is_array($captcha["fontFace"])) {
         $a = $captcha["fontFace"];
         for ($i = 0, $max = count($a); $i < $max; $i++) {
             $c->addFontFace($a[$i]);
         }
     }
     for ($i = 0, $max = count($avaibles); $i < $max; $i++) {
         if (isset($captcha[$avaibles[$i]]) && !empty($captcha[$avaibles[$i]])) {
             $c->{$avaibles}[$i] = $captcha[$avaibles[$i]];
         }
     }
     $c->render();
     exit;
 }
コード例 #2
0
ファイル: class.Form.php プロジェクト: arno06/Savely
 /**
  * Méthode de traitement du formulaire si les données $this->post existantes
  * @return void
  */
 private function checkInputs()
 {
     $this->isValid = true;
     $this->inputsWithAlternative = array();
     $this->inputsWithConfirm = array();
     $this->inputsRequire = array();
     $this->inputsIncorrect = array();
     foreach ($this->data as $name => &$data) {
         if ($data["tag"] == Form::TAG_CAPTCHA) {
             $data["label"] = "Captcha";
             $c = new Captcha($data["length"], $name);
             if (!isset($this->post[$name]) || empty($this->post[$name])) {
                 unset($this->post[$name]);
                 $this->inputsRequire[] = $name;
                 $this->isValid = false;
             } else {
                 if ($c->getValue() != $this->post[$name]) {
                     unset($this->post[$name]);
                     $this->inputsIncorrect[] = $name;
                     $this->isValid = false;
                 } else {
                     unset($this->post[$name]);
                     $c->unsetSessionVar();
                 }
             }
             continue;
         }
         if (is_array($data["inputModifiers"])) {
             $this->applyModifiers($data["inputModifiers"], $name);
         }
         if (isset($data["attributes"]["type"])) {
             switch ($data["attributes"]["type"]) {
                 case "submit":
                     unset($this->post[$name]);
                     continue;
                     break;
                 case "checkbox":
                     if (!isset($this->post[$name]) || $this->post[$name] != $data["attributes"]["value"]) {
                         $this->post[$name] = $data["attributes"]["valueOff"];
                     }
                     break;
             }
         }
         if ($data["tag"] == self::TAG_CHECKBOXGROUP) {
             if (!isset($this->post[$name])) {
                 $this->post[$name] = array();
             }
         }
         if ($data["tag"] == self::TAG_UPLOAD && $data["require"]) {
             if (!isset($data["isUpload"]) && !$data["attributes"]["value"] && !$this->post[$name]) {
                 $this->inputsRequire[] = $name;
                 $this->isValid = false;
             }
             continue;
         }
         if (isset($data["isAlternativeFor"]) && isset($this->data[$data["isAlternativeFor"]])) {
             if ((!isset($this->post[$data["isAlternativeFor"]]) || empty($this->post[$data["isAlternativeFor"]])) && (!isset($this->post[$name]) || empty($this->post[$name]))) {
                 $this->inputsWithAlternative[] = array($name, $data["isAlternativeFor"]);
                 $this->isValid = false;
                 continue;
             }
         }
         if (isset($data["isConfirmFor"]) && isset($this->data[$data["isConfirmFor"]])) {
             if (!isset($this->post[$data["isConfirmFor"]])) {
                 unset($this->post[$name]);
                 continue;
             }
             if ($this->post[$name] != $this->post[$data["isConfirmFor"]]) {
                 $this->inputsWithConfirm[] = array($name, $data["isConfirmFor"]);
                 $this->isValid = false;
             } else {
                 unset($this->post[$name]);
             }
             continue;
         }
         if ($data["require"]) {
             if (is_string($this->post[$name])) {
                 $this->post[$name] = trim($this->post[$name]);
             } elseif (is_array($this->post[$name])) {
                 foreach ($this->post[$name] as &$p) {
                     if (is_string($p)) {
                         $p = trim($p);
                     }
                 }
             }
             if ($this->post[$name] !== 0 && $this->post[$name] !== '0' && empty($this->post[$name])) {
                 if (isset($data["isAlternativeFor"]) && isset($this->data[$data["isAlternativeFor"]]) && !empty($this->post[$data["isAlternativeFor"]])) {
                     continue;
                 }
                 $this->inputsRequire[] = $name;
                 $this->isValid = false;
                 continue;
             }
         }
         if ($data["require"] == false && empty($this->post[$name])) {
             $this->applyModifiers($data["outputModifiers"], $name);
             continue;
         }
         if ($data["require"] == true && empty($data["regExp"])) {
             trigger_error("Les champs obligatoires doivent nécessairement renseigner une expression régulière &agrave; respecter !<br/>Formulaire <b>" . $this->name . "</b> champ <b>" . $name . "</b>", E_USER_ERROR);
         }
         if (empty($data["regExp"])) {
             $this->applyModifiers($data["outputModifiers"], $name);
             continue;
         }
         $regExp = $this->getRegExp($data["regExp"]);
         if ($data["tag"] == self::TAG_SELECT && isset($data["attributes"]["multiple"]) && $data["attributes"]["multiple"] == "multiple") {
             if ($data["require"] == false) {
                 array_shift($this->post[$name]);
             }
         }
         $valid = false;
         if (is_array($this->post[$name])) {
             $valid = true;
             foreach ($this->post[$name] as $v) {
                 $valid = $valid && preg_match($regExp, $v, $extract, PREG_OFFSET_CAPTURE);
             }
         } else {
             if (is_string($this->post[$name])) {
                 $valid = preg_match($regExp, $this->post[$name], $extract, PREG_OFFSET_CAPTURE);
             }
         }
         if (!$valid) {
             $this->inputsIncorrect[] = $name;
             unset($this->post[$name]);
             $this->isValid = false;
             continue;
         }
         $this->applyModifiers($data["outputModifiers"], $name);
     }
 }