コード例 #1
0
 public function render()
 {
     if (!isset($this->_attributes['title'])) {
         $this->_attributes['title'] = ConfigHandler::Get('/captcha/formtext');
     }
     return parent::render();
 }
コード例 #2
0
 public function render()
 {
     if (!$this->get('basedir')) {
         throw new Exception('MultiFileInput cannot be rendered without a basedir attribute!');
     }
     // Make sure it ends with a trailing slash.
     if (substr($this->get('basedir'), -1) != '/') {
         $this->_attributes['basedir'] .= '/';
     }
     //var_dump($_SESSION['multifileinputobjects'], serialize($this->_attributes)); die();
     // This is a slightly different element than the traditional form system, as it must be able to be called without
     // the rest of the form system on submit.
     // This is because this system will do an ajax submit to do the actual upload.
     if (!is_array(\Core\Session::Get('multifileinputobjects'))) {
         \Core\Session::Set('multifileinputobjects', []);
     }
     // I don't need this key to be cryptographically secure, just generally unique.
     $key = md5(serialize($this->_attributes));
     foreach (\Core\Session::Get('multifileinputobjects') as $obj) {
         if (!isset($obj['key'])) {
             continue;
         }
         if ($obj['key'] == $key) {
             $this->set('id', $obj['id']);
         }
     }
     if (!isset($this->_attributes['id'])) {
         // This system requires a valid id.
         $this->set('id', 'multifileinput-' . Core::RandomHex('2'));
     }
     $this->set('key', $key);
     $this->set('uploadkey', $key);
     // Convert the string representation of a filesize to the raw bytes.
     $size = strtoupper(str_replace(' ', '', ini_get('upload_max_filesize')));
     if (strpos($size, 'G') !== false) {
         $size = preg_replace('/[^0-9]/', '', $size);
         $size = $size * (1024 * 1024 * 1024);
     } elseif (strpos($size, 'M') !== false) {
         $size = preg_replace('/[^0-9]/', '', $size);
         $size = $size * (1024 * 1024);
     } elseif (strpos($size, 'K') !== false) {
         $size = preg_replace('/[^0-9]/', '', $size);
         $size = $size * 1024;
     }
     $this->set('maxsize', $size);
     // Now that the session variable has been initialized, the traditional session variable is reliable.
     $_SESSION['multifileinputobjects'][$key] = array('obj' => serialize($this), 'key' => $key, 'id' => $this->_attributes['id']);
     return parent::render();
 }