public function insert() { try { $fields = $this->_getFields(); $input = $this->_controller->getRequest()->getPost(null); require_once 'Sitengine/String.php'; $id = Sitengine_String::createId(); $data = array(); $notifyNewUser = $this->_controller->getRequest()->getPost('notifyNewUser'); if ($notifyNewUser) { $password = Sitengine_String::createId(8); } else { $name = 'password'; $password = $this->_controller->getRequest()->getPost($name); if (Sitengine_Validator::nada($this->_controller->getRequest()->getPost($name))) { $message = $this->_controller->getTranslate()->translate('hintsPasswordRequired'); $this->_controller->getStatus()->addHint($name, $message); } } if (!$this->_controller->getPermiso()->getUsersTable()->checkUserModifyData($this->_controller->getStatus(), $this->_controller->getRequest(), $this->_controller->getTranslate())) { return null; } $this->_controller->getFrontController()->getPermiso()->getUsersTable()->handleInsertUploads($id); foreach ($fields as $k => $v) { $data[$k] = array_key_exists($k, $input) ? $input[$k] : $v; } require_once 'Zend/Date.php'; $date = new Zend_Date(); $date->setTimezone('UTC'); $data['cdate'] = $date->get('YYYY-MM-dd HH:mm:ss', Sitengine_Env::LANGUAGE_EN); $data['mdate'] = $data['cdate']; $data['id'] = $id; # make names lowercase $data['name'] = mb_strtolower($data['name']); # encrypt password $data['password'] = md5($password); $data = array_merge($data, $this->_controller->getFrontController()->getPermiso()->getUsersTable()->getFileData()); #Sitengine_Debug::print_r($data); $insertId = $this->_controller->getFrontController()->getPermiso()->getUsersTable()->insertOrRollback($data); if (!$insertId) { $error = $this->_controller->getFrontController()->getPermiso()->getUsersTable()->getError(); if ($error === null) { return null; } $message = $this->_controller->getTranslate()->translate('hints' . ucfirst($error)); $this->_controller->getStatus()->addHint('record', $message); return null; } if ($notifyNewUser) { $this->_sendNotifyNewUserMail($data, $password); } return $data; } catch (Exception $exception) { require_once 'Sitengine/Permiso/Backend/Users/Exception.php'; throw new Sitengine_Permiso_Backend_Users_Exception('insert error', $exception); } }
public function checkInput() { require_once 'Sitengine/Validator.php'; $name = 'firstname'; if (Sitengine_Validator::nada($this->_controller->getRequest()->getPost($name))) { $message = $this->_controller->getTranslate()->translate('hintFirstnameRequired'); $this->_controller->getStatus()->addHint($name, $message); } $name = 'lastname'; if (Sitengine_Validator::nada($this->_controller->getRequest()->getPost($name))) { $message = $this->_controller->getTranslate()->translate('hintLastnameRequired'); $this->_controller->getStatus()->addHint($name, $message); } $name = 'email'; if (!Sitengine_Validator::emailAddress($this->_controller->getRequest()->getPost($name))) { $message = $this->_controller->getTranslate()->translate('hintEmailRequired'); $this->_controller->getStatus()->addHint($name, $message); } return !$this->_controller->getStatus()->hasHints(); }
public function checkUserModifyData(Sitengine_Status $status, Sitengine_Controller_Request_Http $request, Sitengine_Translate $translate) { require_once 'Sitengine/Validator.php'; $name = 'name'; $val = $request->getPost($name); if (Sitengine_Validator::nada($val)) { $message = $translate->translate('hintsNameRequired'); $status->addHint($name, $message); } else { if (!Sitengine_Validator::emailAddress($val)) { $message = $translate->translate('hintsNameValidEmailRequired'); $status->addHint($name, $message); } } $name = 'nickname'; $val = $request->getPost($name); if (Sitengine_Validator::nada($val)) { $message = $translate->translate('hintsNicknameRequired'); $status->addHint($name, $message); } $name = 'firstname'; $val = $request->getPost($name); if (Sitengine_Validator::nada($val)) { $message = $translate->translate('hintsFirstnameRequired'); $status->addHint($name, $message); } $name = 'lastname'; $val = $request->getPost($name); if (Sitengine_Validator::nada($val)) { $message = $translate->translate('hintsLastnameRequired'); $status->addHint($name, $message); } $name = 'password'; $val = $request->getPost($name); if ($val != $request->getPost('passwordConfirm')) { $message = $translate->translate('hintsPasswordsDontMatch'); $status->addHint($name, $message); } if ($val != '') { require_once 'Zend/Validate/StringLength.php'; $validator = new Zend_Validate_StringLength($this->getPermiso()->getMinimalPasswordLength()); $validator->setMessage($translate->translate('hintsPasswordTooShort'), Zend_Validate_StringLength::TOO_SHORT); if (!$validator->isValid($val)) { $messages = $validator->getMessages(); $status->addHint($name, $messages); } } $name = 'country'; if (Sitengine_Validator::nada($request->getPost($name), 'noneSelected')) { $message = $translate->translate('hintsCountryRequired'); $status->addHint($name, $message); } $name = 'timezone'; if (Sitengine_Validator::nada($request->getPost($name), 'noneSelected')) { $message = $translate->translate('hintsTimezoneRequired'); #$status->addHint($name, $message); } $fileId = 'avatarOriginal'; require_once 'Sitengine/Upload.php'; $upload = new Sitengine_Upload($fileId); if ($upload->isFile()) { $messages = array(); if (!preg_match('/(gif|jpg|jpeg)/i', $upload->getMime())) { $messages[] = $translate->translate('hintsAvatarOriginalFiletype'); } if ($upload->getSize() > 1024 * 1024) { $messages[] = $translate->translate('hintsAvatarOriginalFilesize'); } if (sizeof($messages)) { $status->addHint($fileId, $messages); } } return !$status->hasHints(); }
protected function _checkInput() { /* $name = 'gid'; if($this->_controller->getRequest()->getPost($name)==Sitengine_Blog_Frontend_Blogs_Posts_Comments_Controller::VALUE_NONESELECTED) { $message = $this->_controller->getTranslate()->translate('hintsGidRequired'); $this->_controller->getStatus()->addHint($name, $message); } */ $name = 'comment'; $val = $this->_controller->getRequest()->getPost($name); if (Sitengine_Validator::nada($val, Sitengine_Blog_Frontend_Blogs_Posts_Comments_Controller::VALUE_NONESELECTED)) { $message = $this->_controller->getTranslate()->translate('hintsCommentRequired'); $this->_controller->getStatus()->addHint($name, $message); } if (strip_tags($val) != $val) { $message = $this->_controller->getTranslate()->translate('hintsCommentContainsHtml'); #$this->_controller->getStatus()->addHint($name, $message); } return !$this->_controller->getStatus()->hasHints(); }
protected function _checkInput() { if ($this->_payloads->isMain()) { $name = 'titleLang' . $this->_controller->getRecord()->getTranscripts()->getDefaultIndex(); if (Sitengine_Validator::nada($this->_controller->getRequest()->getPost($name))) { $message = $this->_controller->getTranslate()->translate('hintsTitleRequired'); $this->_controller->getStatus()->addHint($name, $message); } $name = 'gid'; if ($this->_controller->getRequest()->getPost($name) == Sitengine_Blog_Frontend_Blogs_Posts_Files_Controller::VALUE_NONESELECTED) { $message = $this->_controller->getTranslate()->translate('hintsGidRequired'); $this->_controller->getStatus()->addHint($name, $message); } $fileId = 'file1Original'; $upload = new Sitengine_Upload($fileId); if ($upload->isFile()) { $type = $this->_controller->getEntity()->getAncestorType(); if ($type == Sitengine_Blog_Posts_Table::TYPE_GALLERY) { $typesPattern = '/(gif|jpg|jpeg|png)/i'; } else { $typesPattern = '/(gif|jpg|jpeg|png|pdf|mpeg|quicktime|msword|excel)/i'; } $messages = array(); if (!preg_match($typesPattern, $upload->getMime())) { $messages[] = $this->_controller->getTranslate()->translate('hintsFile1OriginalFiletype'); } if ($upload->getSize() > 1024 * 1024 * 15) { $messages[] = $this->_controller->getTranslate()->translate('hintsFile1OriginalFilesize'); } if (sizeof($messages)) { $this->_controller->getStatus()->addHint($fileId, $messages); } } } return !$this->_controller->getStatus()->hasHints(); }
protected function _checkInput() { $table = $this->_controller->getFrontController()->getProtoPackage()->getGoodiesTable(); $transcripts = $table->getTranscripts(); /* require_once 'Zend/Validate/StringLength.php'; $validator = new Zend_Validate_StringLength(4); $val = $this->_controller->getRequest()->getPost($name); $validator->setMessage( $this->_controller->getTranslate()->translate('hintsTest'), Zend_Validate_StringLength::TOO_SHORT ); if(!$validator->isValid($val)) { $this->_controller->getStatus()->addHint($name, $validator->getMessages(), $validator->getErrors()); Sitengine_Debug::print_r($this->_controller->getStatus()); } exit; */ if ($this->_payloads->isMain() || $this->_payloads->isDefaultTranscript()) { $name = 'titleLang' . $transcripts->getDefaultIndex(); if (Sitengine_Validator::nada($this->_controller->getRequest()->getPost($name))) { $message = $this->_controller->getTranslate()->translate('hintsTitleRequired'); $this->_controller->getStatus()->addHint($name, $message); } } if ($this->_payloads->isMain()) { $name = 'gid'; if ($this->_controller->getRequest()->getPost($name) == Sitengine_Proto_Backend_Goodies_Controller::VALUE_NONESELECTED) { $message = $this->_controller->getTranslate()->translate('hintsGidRequired'); $this->_controller->getStatus()->addHint($name, $message); } $name = 'type'; if (Sitengine_Validator::nada($this->_controller->getRequest()->getPost($name), Sitengine_Proto_Backend_Goodies_Controller::VALUE_NONESELECTED)) { $message = $this->_controller->getTranslate()->translate('hintsTypeRequired'); $this->_controller->getStatus()->addHint($name, $message); } $fileId = 'file1Original'; $upload = new Sitengine_Upload($fileId); if ($upload->isFile()) { /* $name = 'transColor'; $val = $this->_controller->getRequest()->getPost($name); if($val && !Sitengine_Validator::rgbColor($val)) { $message = $this->_controller->getTranslate()->translate('hintsTransColorInvalid'); $this->_controller->getStatus()->addHint($name, $messages); } */ $messages = array(); if (!preg_match('/(gif|jpg|jpeg|png|pdf|mpeg|quicktime|msword|excel)/i', $upload->getMime())) { $messages[] = $this->_controller->getTranslate()->translate('hintsFile1OriginalFiletype'); } if ($upload->getSize() > '1048576') { # 1M $messages[] = $this->_controller->getTranslate()->translate('hintsFile1OriginalFilesize'); } if (sizeof($messages)) { $this->_controller->getStatus()->addHint($fileId, $messages); } } } return !$this->_controller->getStatus()->hasHints(); }
protected function _checkInput() { $name = 'gid'; if ($this->_controller->getRequest()->getPost($name) == Sitengine_Blog_Backend_Blogs_Posts_Comments_Controller::VALUE_NONESELECTED) { $message = $this->_controller->getTranslate()->translate('hintsGidRequired'); $this->_controller->getStatus()->addHint($name, $message); } $name = 'comment'; if (Sitengine_Validator::nada($this->_controller->getRequest()->getPost($name), Sitengine_Blog_Backend_Blogs_Posts_Comments_Controller::VALUE_NONESELECTED)) { $message = $this->_controller->getTranslate()->translate('hintsCommentRequired'); $this->_controller->getStatus()->addHint($name, $message); } return !$this->_controller->getStatus()->hasHints(); }
protected function _checkInput() { require_once 'Sitengine/Validator.php'; $name = 'name'; $val = $this->_controller->getRequest()->getPost($name); # name can't be empty if (Sitengine_Validator::nada($val)) { $message = $this->_controller->getTranslate()->translate('hintsNameRequired'); $this->_controller->getStatus()->addHint($name, $message); } else { if (!Sitengine_Validator::word($val)) { $message = $this->_controller->getTranslate()->translate('hintsNameInvalid'); $this->_controller->getStatus()->addHint($name, $message); } } return !$this->_controller->getStatus()->hasHints(); }
protected function _checkUpload($required = false) { $name = 'file1Original'; $upload = new Sitengine_Upload($name); if ($required && !$upload->isFile()) { $message = $this->_controller->getTranslate()->translate('hints' . ucfirst($name) . 'Required'); $this->_controller->getStatus()->addHint($name, $message); return null; } else { if ($upload->isFile()) { $n = 'transColor'; $v = $this->_controller->getRequest()->getPost($n); if ($v && !Sitengine_Validator::rgbColor($v)) { $message = $this->_controller->getTranslate()->translate('hints' . ucfirst($n) . 'Invalid'); $this->_controller->getStatus()->addHint($n, $message); } #print $upload->getMime(); if (!preg_match($this->_allowedTypes, $upload->getMime())) { $message = $this->_controller->getTranslate()->translate('hints' . ucfirst($name) . 'Filetype'); $this->_controller->getStatus()->addHint($name, $message); } if ($upload->getSize() > $this->_maxSize) { $message = $this->_controller->getTranslate()->translate('hints' . ucfirst($name) . 'Filesize'); $this->_controller->getStatus()->addHint($name, $message); } } } }
protected function _checkInput() { require_once 'Sitengine/Validator.php'; $name = 'userId'; $userId = $this->_controller->getRequest()->getPost($name); $groupId = $this->_controller->getEntity()->getAncestorId(); if (Sitengine_Validator::nada($userId, Sitengine_Permiso_Backend_Groups_Members_Controller::VALUE_NONESELECTED)) { $message = $this->_controller->getTranslate()->translate('hintsUserIdRequired'); $this->_controller->getStatus()->addHint($name, $message); } if ($userId == Sitengine_Permiso::UID_GUEST || $userId == Sitengine_Permiso::UID_LOSTFOUND) { # users guest and lostfound can't be made a member of any group $message = $this->_controller->getTranslate()->translate(Sitengine_Env::HINT_INVALID_ACTION); $this->_controller->getStatus()->addHint('modifier', $message); return false; } if ($groupId == Sitengine_Permiso::GID_ADMINISTRATORS && !$this->_controller->getPermiso()->getDirectory()->userIsMember($this->_controller->getPermiso()->getAuth()->getId(), Sitengine_Permiso::GID_ADMINISTRATORS)) { # only administrators can add users to the administrators group $message = $this->_controller->getTranslate()->translate(Sitengine_Env::HINT_INVALID_ACTION); $this->_controller->getStatus()->addHint('modifier', $message); return false; } if ($groupId == Sitengine_Permiso::UID_LOSTFOUND) { # no users can be added to the lostfound group $message = $this->_controller->getTranslate()->translate(Sitengine_Env::HINT_INVALID_ACTION); $this->_controller->getStatus()->addHint('modifier', $message); return false; } return !$this->_controller->getStatus()->hasHints(); }
/** * * @throws Sitengine_Exception * */ public static function resizePng($inFile, $outFile, $length, $method, $mode = 0644, $transColor = '') { $size = getimagesize($inFile); if (!$size) { throw new Sitengine_Exception('png could not be opened'); } if ($size[2] != 3) { throw new Sitengine_Exception('image is not a png'); } # not a png switch ($method) { case 'width': $width = $length; $height = self::calcHeight($size[0], $size[1], $length); break; case 'height': $width = self::calcWidth($size[0], $size[1], $length); $height = $length; break; default: if ($size[0] > $size[1]) { $width = $length; $height = self::calcHeight($size[0], $size[1], $length); } else { $width = self::calcWidth($size[0], $size[1], $length); $height = $length; } break; } $inRid = imagecreatefrompng($inFile); if (!$inRid) { throw new Sitengine_Exception('png processing error'); } $outRid = imagecreatetruecolor($width, $height); if (!$outRid) { throw new Sitengine_Exception('png processing error'); } $rgbColors = Sitengine_Validator::rgbColor($transColor); if ($rgbColors) { $color = imagecolorallocate($outRid, $rgbColors['red'], $rgbColors['green'], $rgbColors['blue']); $transparency = imagecolortransparent($outRid, $color); } $copy = imagecopyresized($outRid, $inRid, 0, 0, 0, 0, $width, $height, $size[0], $size[1]); if (!$copy) { throw new Sitengine_Exception('png processing error'); } $image = imagepng($outRid, $outFile); if (!$image) { throw new Sitengine_Exception('png processing error'); } chmod($outFile, $mode); $stats = stat($outFile); return array('mime' => 'image/png', 'size' => $stats['size'], 'width' => $width, 'height' => $height); }
protected function _checkVideoPostInput() { if ($this->_payloads->isMain()) { $name = 'gid'; if ($this->_controller->getRequest()->getPost($name) == Sitengine_Blog_Frontend_Blogs_Posts_Controller::VALUE_NONESELECTED) { $message = $this->_controller->getTranslate()->translate('videoposthintsGidRequired'); $this->_controller->getStatus()->addHint($name, $message); } $name = 'embedTag'; if (Sitengine_Validator::nada($this->_controller->getRequest()->getPost($name))) { $message = $this->_controller->getTranslate()->translate('videoposthintsEmbedTagRequired'); $this->_controller->getStatus()->addHint($name, $message); } } if ($this->_payloads->isMain() || $this->_payloads->isDefaultTranscript()) { $name = 'titleLang' . $this->_controller->getRecord()->getTranscripts()->getDefaultIndex(); if (Sitengine_Validator::nada($this->_controller->getRequest()->getPost($name))) { $message = $this->_controller->getTranslate()->translate('videoposthintsTitleRequired'); $this->_controller->getStatus()->addHint($name, $message); } } return !$this->_controller->getStatus()->hasHints(); }
protected function _checkInput() { if ($this->_payloads->isMain()) { $name = 'title'; if (Sitengine_Validator::nada($this->_controller->getRequest()->getPost($name))) { $message = $this->_controller->getTranslate()->translate('hintsTitleRequired'); $this->_controller->getStatus()->addHint($name, $message); } } return !$this->_controller->getStatus()->hasHints(); }
protected function _checkInput() { $name = 'title'; if (Sitengine_Validator::nada($this->_controller->getRequest()->getPost($name))) { $message = $this->_controller->getTranslate()->translate('hintsTitleRequired'); $this->_controller->getStatus()->addHint($name, $message); } $fileId = 'file1Original'; $upload = new Sitengine_Upload($fileId); if ($upload->isFile()) { $messages = array(); if (!preg_match('/(gif|jpg|jpeg|png|pdf|mpeg|mpg|quicktime|msword|excel)/i', $upload->getMime())) { $messages[] = $this->_controller->getTranslate()->translate('hintsFile1OriginalFiletype'); } if ($upload->getSize() > 1024 * 1024 * 5) { $messages[] = $this->_controller->getTranslate()->translate('hintsFile1OriginalFilesize'); } if (sizeof($messages)) { $this->_controller->getStatus()->addHint($fileId, $messages); } } return !$this->_controller->getStatus()->hasHints(); }
protected function _checkInput() { $table = $this->_controller->getFrontController()->getBlogPackage()->getBlogsTable(); $transcripts = $table->getTranscripts(); $name = 'titleLang' . $transcripts->getDefaultIndex(); if (Sitengine_Validator::nada($this->_controller->getRequest()->getPost($name))) { $message = $this->_controller->getTranslate()->translate('hintsTitleRequired'); $this->_controller->getStatus()->addHint($name, $message); } $name = 'gid'; if ($this->_controller->getRequest()->getPost($name) == Sitengine_Blog_Backend_Blogs_Controller::VALUE_NONESELECTED) { $message = $this->_controller->getTranslate()->translate('hintsGidRequired'); $this->_controller->getStatus()->addHint($name, $message); } $name = 'slug'; if (Sitengine_Validator::nada($this->_controller->getRequest()->getPost($name), Sitengine_Blog_Backend_Blogs_Controller::VALUE_NONESELECTED)) { $message = $this->_controller->getTranslate()->translate('hintsSlugRequired'); $this->_controller->getStatus()->addHint($name, $message); } $name = 'slug'; if (!Sitengine_Validator::word($this->_controller->getRequest()->getPost($name))) { $message = $this->_controller->getTranslate()->translate('hintsSlugInvalid'); $this->_controller->getStatus()->addHint($name, $message); } return !$this->_controller->getStatus()->hasHints(); }