Пример #1
0
 public function saveData($aLinkData)
 {
     if ($this->iLinkId === null) {
         $oLink = new Link();
     } else {
         $oLink = LinkQuery::create()->findPk($this->iLinkId);
     }
     $oLink->setUrl(LinkUtil::getUrlWithProtocolIfNotSet($aLinkData['url']));
     $oLink->setName($aLinkData['name']);
     $oLink->setLinkCategoryId($aLinkData['link_category_id'] == null ? null : $aLinkData['link_category_id']);
     $oLink->setDescription($aLinkData['description']);
     if (isset($aLinkData['language_id'])) {
         $oLink->setLanguageId($aLinkData['language_id'] != null ? $aLinkData['language_id'] : null);
     }
     $this->validate($aLinkData);
     if (!Flash::noErrors()) {
         throw new ValidationException();
     }
     if ($oLink->getLinkCategoryId() != null) {
         if ($oLink->isNew() || $oLink->isColumnModified(LinkPeer::LINK_CATEGORY_ID)) {
             $oLink->setSort(LinkQuery::create()->filterByLinkCategoryId($oLink->getLinkCategoryId())->count() + 1);
         }
     }
     $oLink->save();
     return $oLink->getId();
 }
 public function saveData($aDocumentationData)
 {
     if ($this->iDocumentationId === null) {
         $oDocumentation = new Documentation();
     } else {
         $oDocumentation = DocumentationQuery::create()->findPk($this->iDocumentationId);
     }
     $oRichtextUtil = new RichtextUtil();
     $oRichtextUtil->setTrackReferences($oDocumentation);
     $oDocumentation->setDescription($oRichtextUtil->parseInputFromEditor($aDocumentationData['description']));
     $oDocumentation->setName($aDocumentationData['name']);
     $oDocumentation->setTitle($aDocumentationData['title']);
     $oDocumentation->setKey($aDocumentationData['key']);
     if (isset($aDocumentationData['name_space'])) {
         $oDocumentation->setNameSpace($aDocumentationData['name_space']);
     }
     $oDocumentation->setVersion($aDocumentationData['version']);
     $oDocumentation->setTitle($aDocumentationData['title']);
     $oDocumentation->setIsPublished($aDocumentationData['is_published']);
     $oDocumentation->setYoutubeUrl($aDocumentationData['youtube_url']);
     if ($oDocumentation->getYoutubeUrl() == null) {
         $oDocumentation->setYoutubeUrl(null);
     }
     $this->validate($aDocumentationData, $oDocumentation);
     if (!Flash::noErrors()) {
         throw new ValidationException();
     }
     return $oDocumentation->save();
 }
Пример #3
0
 public function saveData($aTagData)
 {
     $aTagData['name'] = StringUtil::normalize($aTagData['name']);
     if ($this->iTagId === null) {
         $oTag = new Tag();
     } else {
         $oTag = TagQuery::create()->findPk($this->iTagId);
     }
     $this->validate($aTagData);
     if (!Flash::noErrors()) {
         throw new ValidationException();
     }
     $sStringName = "tag.{$aTagData['name']}";
     if ($oTag->getName() !== $aTagData['name']) {
         //Rename Strings for the tag
         $sOldStringName = "tag.{$oTag->getName()}";
         foreach (TranslationQuery::create()->filterByStringKey($sOldStringName)->find() as $oString) {
             $sLanguageId = $oString->getLanguageId();
             //You can’t technically rename strings because string_key is the PKEY so we delete it and re-generate
             $oString->delete();
             $oString = new Translation();
             $oString->setStringKey($sStringName);
             $oString->setLanguageId($sLanguageId);
             $oString->save();
         }
         $oTag->setName($aTagData['name']);
     }
     foreach ($aTagData['edited_languages'] as $iIndex => $sLanguageId) {
         TranslationPeer::addOrUpdateString($sStringName, $aTagData['text'][$iIndex], $sLanguageId);
     }
     $oTag->save();
 }
 public function saveData($aSubscriberData)
 {
     $oSubscriber = SubscriberQuery::create()->findPk($this->iSubscriberId);
     if ($oSubscriber === null) {
         $oSubscriber = new Subscriber();
         $oSubscriber->setCreatedBy(Session::getSession()->getUserId());
         $oSubscriber->setCreatedAt(date('c'));
     }
     $oSubscriber->setPreferredLanguageId($aSubscriberData['preferred_language_id']);
     $oSubscriber->setName($aSubscriberData['name']);
     $oSubscriber->setEmail($aSubscriberData['email']);
     $this->validate($aSubscriberData, $oSubscriber);
     if (!Flash::noErrors()) {
         throw new ValidationException();
     }
     // Subscriptions
     foreach ($oSubscriber->getSubscriberGroupMemberships() as $oSubscriberGroupMembership) {
         $oSubscriberGroupMembership->delete();
     }
     $aSubscriptions = isset($aSubscriberData['subscriber_group_ids']) ? $aSubscriberData['subscriber_group_ids'] : array();
     foreach ($aSubscriptions as $iSubscriberGroupId) {
         $oSubscriberGroupMembership = new SubscriberGroupMembership();
         $oSubscriberGroupMembership->setSubscriberGroupId($iSubscriberGroupId);
         $oSubscriber->addSubscriberGroupMembership($oSubscriberGroupMembership);
     }
     return $oSubscriber->save();
 }
 public function saveData($aSubscriberGroupData)
 {
     if ($this->iSubscriberGroupId) {
         $oSubscriberGroup = SubscriberGroupQuery::create()->findPk($this->iSubscriberGroupId);
     } else {
         $oSubscriberGroup = new SubscriberGroup();
         $oSubscriberGroup->setCreatedBy(Session::getSession()->getUserId());
         $oSubscriberGroup->setCreatedAt(date('c'));
     }
     $oSubscriberGroup->setName($aSubscriberGroupData['name']);
     $oSubscriberGroup->setDisplayName($aSubscriberGroupData['display_name'] == null ? null : $aSubscriberGroupData['display_name']);
     $this->validate($aSubscriberGroupData);
     if (!Flash::noErrors()) {
         throw new ValidationException();
     }
     $oSubscriberGroup->save();
     $oResult = new stdClass();
     $oResult->id = $oSubscriberGroup->getId();
     if ($this->iSubscriberGroupId === null) {
         $oResult->inserted = true;
     } else {
         $oResult->updated = true;
     }
     $this->iSubscriberGroupId = $oResult->id;
     return $oResult;
 }
Пример #6
0
 public function saveData($aRoleData)
 {
     $oRole = null;
     if ($this->sRoleId === null) {
         $oRole = new Role();
     } else {
         $oRole = RoleQuery::create()->findPk($this->sRoleId);
         // If the role_key has changed and the new key does not exist yet, delete the current role and create a new one
         if ($oRole->getRoleKey() !== $aRoleData['role_key']) {
             if (RoleQuery::create()->filterByRoleKey($aRoleData['role_key'])->count() === 0) {
                 $oRole->delete();
                 $oRole = new Role();
             }
         }
     }
     $this->validate($aRoleData, $oRole);
     if (!Flash::noErrors()) {
         throw new ValidationException();
     }
     $oRole->setRoleKey($aRoleData['role_key']);
     $oRole->setDescription($aRoleData['description']);
     if (isset($aRoleData['page_id'])) {
         if (!$oRole->isNew()) {
             RightQuery::create()->filterByRole($oRole)->delete();
         }
         $aRights = array();
         foreach ($aRoleData['page_id'] as $iCounter => $sPageId) {
             $sRightKey = $sPageId . ($aRoleData['is_inherited'][$iCounter] ? "_inherited" : "_uninherited");
             if (isset($aRights[$sRightKey])) {
                 $oRight = $aRights[$sRightKey];
                 $oRight->setMayEditPageContents($oRight->getMayEditPageContents() || $aRoleData['may_edit_page_contents'][$iCounter]);
                 $oRight->setMayEditPageDetails($oRight->getMayEditPageDetails() || $aRoleData['may_edit_page_details'][$iCounter]);
                 $oRight->setMayDelete($oRight->getMayDelete() || $aRoleData['may_delete'][$iCounter]);
                 $oRight->setMayCreateChildren($oRight->getMayCreateChildren() || $aRoleData['may_create_children'][$iCounter]);
                 $oRight->setMayViewPage($oRight->getMayViewPage() || $aRoleData['may_view_page'][$iCounter]);
             } else {
                 $oRight = new Right();
                 $oRight->setPageId($sPageId);
                 $oRight->setRole($oRole);
                 $oRight->setIsInherited($aRoleData['is_inherited'][$iCounter]);
                 $oRight->setMayEditPageContents($aRoleData['may_edit_page_contents'][$iCounter]);
                 $oRight->setMayEditPageDetails($aRoleData['may_edit_page_details'][$iCounter]);
                 $oRight->setMayDelete($aRoleData['may_delete'][$iCounter]);
                 $oRight->setMayCreateChildren($aRoleData['may_create_children'][$iCounter]);
                 $oRight->setMayViewPage($aRoleData['may_view_page'][$iCounter]);
                 $aRights[$sRightKey] = $oRight;
             }
         }
         foreach ($aRights as $oRight) {
             $oRight->save();
         }
     }
     $oRole->save();
     return array('id' => $oRole->getRoleKey());
 }
Пример #7
0
 public function uploadFile($sFileKey = 'file', $aOptions = null, $bCreateType = false)
 {
     $oFlash = Flash::getFlash();
     $oFlash->checkForFileUpload($sFileKey);
     $oFlash->finishReporting();
     if (!Flash::noErrors()) {
         throw new ValidationException();
     }
     $aFileInfo = $_FILES[$sFileKey];
     if ($aOptions['document_id']) {
         $oDocument = DocumentQuery::create()->findPk($aOptions['document_id']);
     } else {
         $oDocument = new Document();
     }
     if ($oDocument === null) {
         throw new LocalizedException("wns.file_upload.document_not_found");
     }
     $sFileName = $aOptions['name'];
     $aName = explode('.', $sFileName);
     if (count($aName) > 1) {
         array_pop($aName);
     }
     $sFileName = implode('.', $aName);
     $iDocumentTypeId = null;
     try {
         $iDocumentTypeId = $this->accepts($aOptions['name'], $aOptions['type']);
     } catch (Exception $e) {
         if ($bCreateType) {
             $aName = explode('.', $aOptions['name']);
             $sExtension = null;
             if (count($aName) > 1) {
                 $sExtension = array_pop($aName);
             }
             $aMimeType = explode('/', $aOptions['type']);
             if ($sExtension === null) {
                 $sExtension = $aMimeType[1];
             }
             if ($sExtension === null) {
                 throw new LocalizedException("wns.file_upload.unknown_document_type");
             }
             $oDocumentType = new DocumentType();
             $oDocumentType->setExtension($sExtension);
             $oDocumentType->setMimetype(implode('/', $aMimeType));
             $oDocumentType->save();
             $iDocumentTypeId = $oDocumentType->getId();
         } else {
             throw $e;
         }
     }
     $oDocument->setData(fopen($aFileInfo['tmp_name'], "r"));
     $this->updateDocument($oDocument, $aOptions, $sFileName, $iDocumentTypeId);
     $oDocument->save();
     return $oDocument->getId();
 }
 public function saveData($aDocumentTypeData)
 {
     if ($this->iTypeId === null) {
         $oType = new DocumentType();
     } else {
         $oType = DocumentTypeQuery::create()->findPk($this->iTypeId);
     }
     $this->validate($aDocumentTypeData, $oType);
     if (!Flash::noErrors()) {
         throw new ValidationException();
     }
     $oType->setExtension($aDocumentTypeData['extension']);
     $oType->setMimetype($aDocumentTypeData['mimetype']);
     return $oType->save();
 }
 public function saveData($aLanguageData)
 {
     // string key is changed if a existing Language string_key is changed
     if ($aLanguageData['language_id'] !== $this->sLanguageId) {
         $this->sLanguageId = $aLanguageData['language_id'];
     }
     $oLanguage = LanguageQuery::create()->findPk($this->sLanguageId);
     if ($oLanguage === null) {
         $oLanguage = new Language();
         $oLanguage->setId($aLanguageData['language_id']);
     }
     $this->validate($aLanguageData, $oLanguage);
     if (!Flash::noErrors()) {
         throw new ValidationException();
     }
     $oLanguage->setIsActive($aLanguageData['is_active']);
     $oLanguage->setPathPrefix($aLanguageData['path_prefix']);
     return $oLanguage->save();
 }
 public function saveData($aJournalData)
 {
     if ($this->iJournalId === null) {
         $oJournal = new Journal();
     } else {
         $oJournal = JournalQuery::create()->findPk($this->iJournalId);
     }
     $this->validate($aJournalData);
     $oJournal->setName($aJournalData['name']);
     $oJournal->setDescription($aJournalData['description']);
     $oJournal->setUseCaptcha($aJournalData['use_captcha']);
     $sCommentMode = $aJournalData['comment_mode'];
     $oJournal->setEnableComments($sCommentMode === 'on' || $sCommentMode === 'notified');
     $oJournal->setNotifyComments($sCommentMode === 'moderated' || $sCommentMode === 'notified');
     if (!Flash::noErrors()) {
         throw new ValidationException();
     }
     $oJournal->save();
     return $oJournal->getId();
 }
 public function saveData($aDocumentationPartData)
 {
     if ($this->iDocumentationPartId === null) {
         $oDocumentationPart = new DocumentationPart();
     } else {
         $oDocumentationPart = DocumentationPartQuery::create()->findPk($this->iDocumentationPartId);
     }
     $this->validate($aDocumentationPartData);
     $oDocumentationPart->setName($aDocumentationPartData['name']);
     $oDocumentationPart->setKey($aDocumentationPartData['key']);
     $oDocumentationPart->setIsOverview($aDocumentationPartData['is_overview']);
     $oDocumentationPart->setIsPublished($aDocumentationPartData['is_published']);
     $oDocumentationPart->setDocumentationId($aDocumentationPartData['documentation_id']);
     $oDocumentationPart->setLanguageId($oDocumentationPart->getDocumentation()->getLanguageId());
     $oDocumentationPart->setImageId($aDocumentationPartData['image_id'] != null ? $aDocumentationPartData['image_id'] : null);
     if ($oDocumentationPart->getTitle() == null) {
         $oDocumentationPart->setTitle(null);
     }
     $oRichtextUtil = new RichtextUtil();
     $oRichtextUtil->setTrackReferences($oDocumentationPart);
     $oDocumentationPart->setBody($oRichtextUtil->parseInputFromEditor($aDocumentationPartData['body']));
     if ($oDocumentationPart->isNew() && is_numeric($oDocumentationPart->getDocumentationId())) {
         $oDocumentationPart->setSort(DocumentationPartQuery::create()->filterByDocumentationId($oDocumentationPart->getDocumentationId())->count() + 1);
     }
     if ($aDocumentationPartData['image_id'] == null && $oDocumentationPart->getDocument()) {
         $oDocumentationPart->getDocument()->delete();
     }
     if (!Flash::noErrors()) {
         // Don't validate on file upload but set is_published to false if there are errors
         if ($aDocumentationPartData['documentation_id'] != null && $aDocumentationPartData['is_file_upload']) {
             $oDocumentationPart->setIsPublished(false);
         } else {
             throw new ValidationException();
         }
     }
     $oDocumentationPart->save();
     return $oDocumentationPart->getId();
 }
 public function saveData($aLinkCategoryData)
 {
     if ($this->iLinkCategoryId === null) {
         $oLinkCategory = new LinkCategory();
     } else {
         $oLinkCategory = LinkCategoryQuery::create()->findPk($this->iLinkCategoryId);
     }
     $this->validate($aLinkCategoryData);
     if (!Flash::noErrors()) {
         throw new ValidationException();
     }
     $oLinkCategory->setName($aLinkCategoryData['name']);
     $oLinkCategory->setIsExternallyManaged($aLinkCategoryData['is_externally_managed']);
     $oLinkCategory->save();
     $oResult = new stdClass();
     if ($this->iLinkCategoryId === null) {
         $oResult->inserted = true;
     } else {
         $oResult->updated = true;
     }
     $oResult->id = $this->iLinkCategoryId = $oLinkCategory->getId();
     return $oResult;
 }
Пример #13
0
 public function renderFile()
 {
     $aCurrentValues = $this->oFormStorage->saveCurrentValuesToSession();
     $oFlash = Flash::getFlash();
     $oFlash->setArrayToCheck($aCurrentValues);
     $bHasCaptcha = false;
     foreach ($this->oFormStorage->getFormObjects() as $oFormObject) {
         if ($oFormObject instanceof CaptchaObject) {
             $bHasCaptcha = true;
         }
         if ($oFormObject->shouldExcludeFromReport()) {
             continue;
         }
         if ($oFormObject->isRequired()) {
             $oFlash->checkForValue($oFormObject->getName());
         }
         $oEmailItemTemplateInstance = clone $this->oEmailItemTemplate;
         $oEmailItemTemplateInstance->replaceIdentifier('name', $oFormObject->getName());
         $oEmailItemTemplateInstance->replaceIdentifier('label', $oFormObject->getLabel());
         $oEmailItemTemplateInstance->replaceIdentifier('value', $oFormObject->getCurrentValue());
         $this->oEmailTemplate->replaceIdentifierMultiple('form_content', $oEmailItemTemplateInstance);
     }
     if ($bHasCaptcha && !FormFrontendModule::validateRecaptchaInput()) {
         $oFlash->addMessage('captcha_code_required');
     }
     $oFlash->finishReporting();
     if (Flash::noErrors()) {
         $oEmail = new EMail(TranslationPeer::getString('wns.form_module.email_subject', null, null, array('page' => $this->sPageName)), $this->oEmailTemplate);
         $oEmail->addRecipient($this->sEmailAddress);
         $oEmail->send();
         $this->oFormStorage->deleteCurrentValuesFromSession();
         LinkUtil::redirect($_REQUEST['origin'] . '?form_success=true');
     } else {
         $oFlash->stick();
         LinkUtil::redirect($_REQUEST['origin']);
     }
 }
Пример #14
0
 public static function loginNewPassword($sReferrer = '')
 {
     $oFlash = Flash::getFlash();
     $oUser = UserQuery::create()->filterByUsername(trim($_REQUEST['recover_username']))->isActive()->findOne();
     if ($oUser === null || md5($oUser->getPasswordRecoverHint()) !== $_REQUEST['recover_hint']) {
         $oFlash->addMessage('login.recovery.invalid');
         return 'login';
     }
     if ($_POST['new_password'] === '') {
         $oFlash->addMessage('login.empty_fields');
     }
     PasswordHash::checkPasswordValidity($_POST['new_password'], $oFlash);
     if ($_POST['new_password'] !== $_POST['new_password_retype']) {
         $oFlash->addMessage('password_confirm');
     }
     $oFlash->finishReporting();
     if (!Flash::noErrors()) {
         return 'password_reset';
     }
     //No errors – set new password, login and redirect
     UserPeer::ignoreRights(true);
     $oUser->setPassword($_POST['new_password']);
     $oUser->setPasswordRecoverHint(null);
     $oUser->save();
     self::login($_POST['recover_username'], $_POST['new_password'], $sReferrer);
     return 'login';
 }
Пример #15
0
 public function saveData($aUserData)
 {
     if ($this->iUserId === null) {
         $oUser = new User();
     } else {
         $oUser = UserQuery::create()->findPk($this->iUserId);
     }
     $this->validate($aUserData, $oUser);
     if (!Flash::noErrors()) {
         throw new ValidationException();
     }
     $oUser->setUsername($aUserData['username']);
     $oUser->setFirstName($aUserData['first_name']);
     $oUser->setLastName($aUserData['last_name']);
     $oUser->setEmail($aUserData['email']);
     $oUser->setLanguageId($aUserData['language_id']);
     $oUser->setTimezone($aUserData['timezone']);
     //Password
     if ($aUserData['force_password_reset']) {
         $oUser->forcePasswordReset();
     } else {
         if ($aUserData['password'] !== '') {
             $oUser->setPassword($aUserData['password']);
             $oUser->setPasswordRecoverHint(null);
         }
     }
     //This also means the user’s an admin (or has the role “users”) because non-admins can only edit themselves
     if (!$oUser->isSessionUser()) {
         //Only admins may give or take admin rights, having the role “users” does not suffice
         if (Session::user()->getIsAdmin()) {
             $oUser->setIsAdmin($aUserData['is_admin']);
         }
         //Admin & inactive flags
         $oUser->setIsBackendLoginEnabled($oUser->getIsAdmin() || $aUserData['is_admin_login_enabled'] || $aUserData['is_backend_login_enabled']);
         $oUser->setIsAdminLoginEnabled($oUser->getIsAdmin() || $aUserData['is_admin_login_enabled']);
         $oUser->setIsInactive($aUserData['is_inactive']);
         //Groups
         foreach ($oUser->getUserGroupsRelatedByUserId() as $oUserGroup) {
             $oUserGroup->delete();
         }
         $aRequestedGroups = isset($aUserData['group_ids']) ? $aUserData['group_ids'] : array();
         foreach ($aRequestedGroups as $iGroupId) {
             if ($iGroupId === false) {
                 continue;
             }
             $oUserGroup = new UserGroup();
             $oUserGroup->setGroupId($iGroupId);
             $oUser->addUserGroupRelatedByUserId($oUserGroup);
         }
         //Roles
         foreach ($oUser->getUserRolesRelatedByUserId() as $oUserRole) {
             $oUserRole->delete();
         }
         $aRequestedRoles = isset($aUserData['role_keys']) ? !is_array($aUserData['role_keys']) ? array($aUserData['role_keys']) : $aUserData['role_keys'] : array();
         foreach ($aRequestedRoles as $sRoleKey) {
             if ($sRoleKey === false) {
                 continue;
             }
             $oUserRole = new UserRole();
             $oUserRole->setRoleKey($sRoleKey);
             $oUser->addUserRoleRelatedByUserId($oUserRole);
         }
     } else {
         //Set the new session language for the currently logged-in user
         Session::getSession()->setLanguage($oUser->getLanguageId());
     }
     return $oUser->save();
 }
 public function saveData($aData)
 {
     $oJournalEntry = JournalEntryPeer::retrieveByPK($this->iJournalEntryId);
     if ($oJournalEntry === null) {
         $oJournalEntry = new JournalEntry();
         $oJournalEntry->setJournalId($this->iJournalId);
     }
     $this->validate($aData);
     if (!Flash::noErrors()) {
         throw new ValidationException();
     }
     $oJournalEntry->setJournalId($aData['journal_id']);
     $oJournalEntry->setTitle($aData['title']);
     $oJournalEntry->setIsPublished($aData['is_published']);
     $oJournalEntry->setPublishAt($aData['publish_at'] == null ? date('c') : $aData['publish_at']);
     $oRichtextUtil = new RichtextUtil();
     $oRichtextUtil->setTrackReferences($oJournalEntry);
     $oJournalEntry->setText($oRichtextUtil->getTagParser($aData['text']));
     $oJournalEntry->save();
     $oResult = new StdClass();
     if ($this->iJournalEntryId === null) {
         $oResult->inserted = true;
     } else {
         $oResult->updated = true;
     }
     $oResult->id = $this->iCategoryId = $oJournalEntry->getId();
     return $oResult;
 }
Пример #17
0
 public function save()
 {
     if (Flash::noErrors()) {
         $this->sFilePath = self::normalize($_POST['file_path']);
         if ($_POST['file_path_old'] == self::NEW_DIR_IDENTIFIER) {
             mkdir("{$this->sWebdavBaseDirPath}/{$this->sFilePath}");
         } else {
             if ($this->sFilePath !== $_POST['file_path_old']) {
                 rename($this->sWebdavBaseDirPath . "/" . $_POST['file_path_old'], "{$this->sWebdavBaseDirPath}/{$this->sFilePath}");
             }
         }
         // delete all old groups
         foreach (DirectoryPermissionPeer::getPermissionsByFileName($this->sFilePath) as $oPermission) {
             $oPermission->delete();
         }
         if (isset($_POST['group_ids'])) {
             foreach ($_POST['group_ids'] as $sGroupId) {
                 $oDirectoryPermisson = new DirectoryPermission();
                 $oDirectoryPermisson->setFileName($this->sFilePath);
                 $oDirectoryPermisson->setGroupId($sGroupId);
                 $oDirectoryPermisson->setCreatedBy(Session::getSession()->getUserId());
                 $oDirectoryPermisson->setCreatedAt(date('c'));
                 $oDirectoryPermisson->save();
             }
         }
         LinkUtil::redirect($this->link($this->sFilePath));
     }
 }
Пример #18
0
 public function saveData($aStringData)
 {
     $this->validate($aStringData);
     if (!Flash::noErrors()) {
         throw new ValidationException();
     }
     $oConnection = Propel::getConnection();
     foreach (LanguageQuery::create()->orderById()->find() as $oLanguage) {
         $oUpdateCriteria = new Criteria();
         $oUpdateCriteria->add(TranslationPeer::LANGUAGE_ID, $oLanguage->getId());
         $oUpdateCriteria->add(TranslationPeer::STRING_KEY, $this->sStringId);
         if (isset($aStringData['text_' . $oLanguage->getId()])) {
             $sText = trim($aStringData['text_' . $oLanguage->getId()]);
             $oString = TranslationQuery::create()->findPk(array($oLanguage->getId(), $this->sStringId));
             if ($sText === '') {
                 if ($oString !== null) {
                     $oString->delete();
                 }
                 continue;
             }
             if ($oString === null) {
                 $oString = new Translation();
                 $oString->setLanguageId($oLanguage->getId());
                 $oString->setStringKey($aStringData['string_key']);
             } else {
                 if ($this->sStringId !== null && $this->sStringId !== $aStringData['string_key']) {
                     $oString->setStringKey($aStringData['string_key']);
                     BasePeer::doUpdate($oUpdateCriteria, $oString->buildCriteria(), $oConnection);
                 }
             }
             $oString->setText($sText);
             $oString->save();
         } else {
             $oString = TranslationQuery::create()->findPk(array($oLanguage->getId(), $this->sStringId));
             if ($oString === null) {
                 continue;
             }
             if ($this->sStringId !== null && $this->sStringId !== $aStringData['string_key']) {
                 $oString->setStringKey($aStringData['string_key']);
                 BasePeer::doUpdate($oUpdateCriteria, $oString->buildCriteria(), $oConnection);
             }
         }
     }
     // check sidebar reload criteria
     $sNameSpaceOld = TranslationPeer::getNameSpaceFromStringKey($this->sStringId);
     $sNameSpaceNew = TranslationPeer::getNameSpaceFromStringKey($aStringData['string_key']);
     // if both are the same the sidebar is not effected
     $bSidebarHasChanged = false;
     if ($sNameSpaceOld !== $sNameSpaceNew) {
         // if there was an old name space then we have to check whether it was the last string with this namespace
         if ($sNameSpaceOld !== null && !TranslationPeer::nameSpaceExists($sNameSpaceOld)) {
             $bSidebarHasChanged = true;
         }
         // if the new exits only once it has been created and the sidebar needs to be relaoded
         if ($sNameSpaceNew !== null && TranslationPeer::countNameSpaceByName($sNameSpaceNew) === 1) {
             $bSidebarHasChanged = true;
         }
     }
     $this->sStringId = $aStringData['string_key'];
     return array('id' => $this->sStringId, self::SIDEBAR_CHANGED => $bSidebarHasChanged);
 }
 /**
  * processSubscribe()
  *
  * @param int/array subscriber group
  * @param Template object
  *
  * Description
  * • validate subscriber
  * • create/update subscriber and subscriptions
  * • notify subscriber in case it is a new subscription
  * • display confirm message independent the success of the action (previous existence of subscriber is not disclosed)
  * @return void
  */
 private function processSubscribe($iSubscriberGroupId, $oTemplate)
 {
     $oFlash = Flash::getFlash();
     $oFlash->checkForEmail('subscriber_email', 'email_required_for_subscription');
     $oFlash->finishReporting();
     if (Flash::noErrors()) {
         $this->oSubscriber = SubscriberQuery::create()->filterByEmail($_POST['subscriber_email'])->findOne();
         // Create new subscriber if it does not exist yet
         if ($this->oSubscriber === null) {
             $this->oSubscriber = new Subscriber();
             $this->oSubscriber->setEmail($_POST['subscriber_email']);
             $this->oSubscriber->setPreferredLanguageId(isset($_REQUEST['preferred_language_id']) ? $_REQUEST['preferred_language_id'] : Session::language());
             $this->oSubscriber->setName(isset($_POST['name']) ? $_POST['name'] : $this->oSubscriber->getEmail());
             $this->oSubscriber->setCreatedAt(date('c'));
         }
         // Add newsletter subscription if it does not exist yet
         $bHasNewSubscription = false;
         if ($iSubscriberGroupId && !$this->oSubscriber->hasSubscriberGroupMembership($iSubscriberGroupId)) {
             $bHasNewSubscription = $this->oSubscriber->addSubscriberGroupMembershipBySubscriberGroupId($iSubscriberGroupId) !== null;
         }
         SubscriberGroupMembershipPeer::ignoreRights(true);
         SubscriberPeer::ignoreRights(true);
         $this->oSubscriber->save();
         $sConfirmMessage = TranslationPeer::getString('wns.newsletter.subscribe.success');
         // Notifiy only if a new subscription has been added, otherwise ignore
         if ($bHasNewSubscription) {
             if (Settings::getSetting('newsletter', 'optin_confirmation_required', true)) {
                 $sConfirmMessage = TranslationPeer::getString('wns.newsletter.subscribe_opt_in.success');
                 $this->notifySubscriberOptIn($iSubscriberGroupId);
             } else {
                 $this->notifySubscriber();
             }
         }
         $oTemplate->replaceIdentifier('message', $sConfirmMessage);
     }
 }
Пример #20
0
 public function saveData($aDocumentData)
 {
     if ($this->iDocumentId === null) {
         $oDocument = new Document();
     } else {
         $oDocument = DocumentQuery::create()->findPk($this->iDocumentId);
     }
     if ($aDocumentData['name'] == null && $oDocument->getName()) {
         $aDocumentData['name'] = $oDocument->getName();
     }
     $this->validate($aDocumentData, $oDocument);
     if (!Flash::noErrors()) {
         throw new ValidationException();
     }
     $oDocument->setName($aDocumentData['name']);
     $oDocument->setLanguageId($aDocumentData['language_id']);
     $oDocument->setDocumentCategoryId(is_numeric($aDocumentData['document_category_id']) ? $aDocumentData['document_category_id'] : null);
     if (isset($aDocumentData['is_protected'])) {
         $oDocument->setIsProtected($aDocumentData['is_protected']);
     }
     $oDocument->setDescription($aDocumentData['description'] == null ? null : $aDocumentData['description']);
     $oDocument->setAuthor($aDocumentData['author']);
     $oDocument->setLicense($aDocumentData['license']);
     $oDocument->setContentCreatedAt($aDocumentData['content_created_at'] == '' ? null : $aDocumentData['content_created_at']);
     // Set/reset sort order
     if ($oDocument->getDocumentCategoryId() != null) {
         if ($oDocument->isNew() || $oDocument->isColumnModified(DocumentPeer::DOCUMENT_CATEGORY_ID)) {
             $oDocument->setSort(DocumentQuery::create()->filterByDocumentCategoryId($oDocument->getDocumentCategoryId())->count() + 1);
         }
     }
     $oDocument->save();
     return $oDocument->getId();
 }
 public function saveData($aNewsletterData)
 {
     $oNewsletter = NewsletterQuery::create()->findPk($this->iNewsletterId);
     if ($oNewsletter === null) {
         $oNewsletter = new Newsletter();
         $oNewsletter->setCreatedBy(Session::getSession()->getUserId());
         $oNewsletter->setCreatedAt(date('c'));
     }
     // If language is not set (not multilingual), write session language, since it is default language
     $sLanguageId = isset($aNewsletterData['language_id']) ? $aNewsletterData['language_id'] : Session::language();
     $oNewsletter->setLanguageId($sLanguageId);
     $oNewsletter->setTemplateName($aNewsletterData['template_name']);
     $oNewsletter->setSubject($aNewsletterData['subject']);
     $oRichtextUtil = new RichtextUtil();
     $oRichtextUtil->setTrackReferences($oNewsletter);
     $oNewsletter->setNewsletterBody($oRichtextUtil->parseInputFromEditor($aNewsletterData['newsletter_body']));
     $this->validate($aNewsletterData, $oNewsletter);
     if (!Flash::noErrors()) {
         throw new ValidationException();
     }
     if (isset($aNewsletterData['is_approved'])) {
         $oNewsletter->setIsApproved($aNewsletterData['is_approved']);
     }
     if (isset($aNewsletterData['template_name'])) {
         $oNewsletter->setTemplateName($aNewsletterData['template_name']);
     }
     return $oNewsletter->save();
 }
 public function saveJournalPageConfiguration($aData)
 {
     $this->validate($aData);
     if (!Flash::noErrors()) {
         throw new ValidationException();
     }
     if ($this->oJournalEntryList) {
         $this->oJournalEntryList->getDelegate()->setJournalId($aData['journal_ids']);
     }
     $this->oPage->updatePageProperty('journal:overview_action', $aData['mode']);
     $this->oPage->updatePageProperty('journal:journal_id', implode(',', array_filter($aData['journal_ids'])));
     // reset journal filter because a journal id that is not configured anymore might be in the session and take effect
     Session::getSession()->resetAttribute(self::SESSION_JOURNAL_FILTER);
     $this->oPage->updatePageProperty('journal:entries_per_page', $aData['entries_per_page'] == '' ? null : $aData['entries_per_page']);
     $this->oPage->updatePageProperty('journal:template_set', $aData['template_set']);
     $this->oPage->updatePageProperty('journal:container', $aData['container']);
     $this->oPage->updatePageProperty('journal:auxiliary_container', $aData['auxiliary_container']);
     $this->oPage->updatePageProperty('journal:date_navigation_items_visible', $aData['date_navigation_items_visible'] === '1' ? 1 : 0);
     $aWidgets = array();
     foreach ($aData['widgets'] as $sWidgetName) {
         if ($sWidgetName !== false) {
             $aWidgets[] = $sWidgetName;
         }
     }
     $this->oPage->updatePageProperty('journal:widgets', implode(',', $aWidgets));
     $this->updateFlagsFromProperties();
 }
Пример #23
0
 private function handleNewJournalComment($oPage, $oEntry)
 {
     $oFlash = Flash::getFlash();
     // Validate form and create new comment and
     $oComment = new JournalComment();
     $oComment->setUsername($_POST['comment_name']);
     $oFlash->checkForValue('comment_name', 'comment_name_required');
     $oComment->setEmail($_POST['comment_email']);
     $oFlash->checkForEmail('comment_email', 'comment_email_required');
     if ($oEntry->getJournal()->getUseCaptcha() && !Session::getSession()->isAuthenticated() && !FormFrontendModule::validateRecaptchaInput() && !isset($_POST['preview'])) {
         $oFlash->addMessage('captcha_required');
     }
     $oPurifierConfig = HTMLPurifier_Config::createDefault();
     $oPurifierConfig->set('Cache.SerializerPath', MAIN_DIR . '/' . DIRNAME_GENERATED . '/' . DIRNAME_CACHES . '/purifier');
     $oPurifierConfig->set('HTML.Doctype', 'XHTML 1.0 Transitional');
     $oPurifierConfig->set('AutoFormat.AutoParagraph', true);
     $oPurifier = new HTMLPurifier($oPurifierConfig);
     $_POST['comment_text'] = $oPurifier->purify($_POST['comment_text']);
     $oComment->setText($_POST['comment_text']);
     $oFlash->checkForValue('comment_text', 'comment_required');
     $oFlash->finishReporting();
     if (isset($_POST['preview'])) {
         $oComment->setCreatedAt(date('c'));
         $_POST['preview'] = $oComment;
     } else {
         if (Flash::noErrors()) {
             $oEntry->addJournalComment($oComment);
             // Post is considered as spam
             $bIsProblablySpam = isset($_POST['important_note']) && $_POST['important_note'] != null;
             $sCommentNotificationTemplate = 'e_mail_comment_notified';
             // Prevent publication if comments are not enabled or post is spam
             if (!$oEntry->getJournal()->getEnableComments() || $bIsProblablySpam) {
                 if (!Session::getSession()->isAuthenticated()) {
                     $oComment->setIsPublished(false);
                     $sCommentNotificationTemplate = 'e_mail_comment_moderated';
                 }
             }
             $oComment->save();
             // Notify new comment
             if ($oEntry->getJournal()->getNotifyComments()) {
                 $oEmailContent = JournalPageTypeModule::templateConstruct($sCommentNotificationTemplate, $oPage->getPagePropertyValue('journal:template_set', 'default'));
                 $oEmailContent->replaceIdentifier('email', $oComment->getEmail());
                 $oEmailContent->replaceIdentifier('user', $oComment->getUsername());
                 if ($bIsProblablySpam) {
                     $oEmailContent->replaceIdentifier('this_comment_is_spam_note', TranslationPeer::getString('journal.this_comment_is_spam_note', null, null, array('important_note_content' => $_POST['important_note'])));
                 }
                 $oEmailContent->replaceIdentifier('comment', $oComment->getText());
                 $oEmailContent->replaceIdentifier('entry', $oEntry->getTitle());
                 $oEmailContent->replaceIdentifier('journal', $oEntry->getJournal()->getName());
                 $oEmailContent->replaceIdentifier('entry_link', LinkUtil::absoluteLink(LinkUtil::link($oEntry->getLink($oPage))));
                 $oEmailContent->replaceIdentifier('deactivation_link', LinkUtil::absoluteLink(LinkUtil::link(array('journal_comment_moderation', $oComment->getActivationHash(), 'deactivate'), 'FileManager'), null, LinkUtil::isSSL()));
                 $oEmailContent->replaceIdentifier('activation_link', LinkUtil::absoluteLink(LinkUtil::link(array('journal_comment_moderation', $oComment->getActivationHash(), 'activate'), 'FileManager'), null, LinkUtil::isSSL()));
                 $oEmailContent->replaceIdentifier('deletion_link', LinkUtil::absoluteLink(LinkUtil::link(array('journal_comment_moderation', $oComment->getActivationHash(), 'delete'), 'FileManager'), null, LinkUtil::isSSL()));
                 $sSubject = TranslationPeer::getString('journal.notification_subject', null, null, array('entry' => $oEntry->getTitle()));
                 $oEmail = new EMail($sSubject, $oEmailContent);
                 $oSender = $oEntry->getUserRelatedByCreatedBy();
                 $oEmail->addRecipient($oSender->getEmail(), $oSender->getFullName());
                 $oEmail->send();
             }
             $oSession = Session::getSession();
             Flash::getFlash()->unfinishReporting()->addMessage('journal.has_new_comment', array(), "journal_entry.new_comment_thank_you" . ($oEntry->getJournal()->getEnableComments() || $oSession->isAuthenticated() ? '' : '.moderated'), 'new_comment_thank_you_message', 'p')->stick();
             LinkUtil::redirect(LinkUtil::link($oEntry->getLink($oPage)) . "#comments");
         }
     }
 }
Пример #24
0
 public function saveData($aPageData)
 {
     $this->oPage = PageQuery::create()->findPk($this->iPageId);
     if (!Session::getSession()->getUser()->mayEditPageDetails($this->oPage)) {
         throw new NotPermittedException('may_edit_page_details');
     }
     // validate post values / fetch most with js
     $this->validate($aPageData);
     if (!Flash::noErrors()) {
         throw new ValidationException();
     }
     $this->oPage->setName($aPageData['name']);
     $this->oPage->setIsInactive(!$aPageData['global_is_active']);
     $this->oPage->setIsHidden($aPageData['is_hidden']);
     $this->oPage->setIsFolder($aPageData['is_folder']);
     $this->oPage->setIsProtected($aPageData['is_protected']);
     $mCanonicalId = null;
     if ($aPageData['canonical_id'] !== '') {
         $mCanonicalId = $this->validateCanonicalId($aPageData['canonical_id']);
     }
     $this->oPage->setCanonicalId($mCanonicalId);
     if ($aPageData['template_name'] === "") {
         $this->oPage->setTemplateName(null);
     } else {
         $this->oPage->setTemplateName($aPageData['template_name']);
     }
     $this->oPage->setPageType($aPageData['page_type']);
     // handle related tables
     $this->handlePageStrings($aPageData);
     $this->handleLanguageObjects($aPageData);
     $this->handlePageProperties($aPageData);
     // save if no errors
     return $this->oPage->save();
 }