public function setMeta($userInfo, $shareInfo, $metaData, $errorHandle = false) { $config = self::$_registry->get("config"); if ($userInfo['id'] != $shareInfo['byUid']) { throw new Exception("User is not the owner of the share."); } $changeData = array(); if ($errorHandle) { foreach (self::$_editableMetadata as $what) { if (empty($errorHandle[$what]) && $metaData[$what] != $shareInfo[$what]) { $changeData[$what] = $metaData[$what]; } } } else { $changeData = $metaData; } if (empty($changeData)) { return false; } if (isset($changeData['filename'])) { $s3 = new Zend_Service_Amazon_S3($config['services']['S3']['key'], $config['services']['S3']['secret']); $bucketPlusObjectKeyPrefix = $config['services']['S3']['sharesBucket'] . "/" . $userInfo['alias'] . "/" . $shareInfo['id'] . "-" . $shareInfo['download_secret'] . "/"; $source = $bucketPlusObjectKeyPrefix . $shareInfo['filename']; $destination = $bucketPlusObjectKeyPrefix . $changeData['filename']; $meta = array(Zend_Service_Amazon_S3::S3_ACL_HEADER => Zend_Service_Amazon_S3::S3_ACL_PUBLIC_READ, "x-amz-copy-source" => $source, "x-amz-metadata-directive" => "COPY"); $request = $s3->_makeRequest("PUT", $destination, null, $meta); if ($request->getStatus() == 200) { $filenameChanged = true; } } if (isset($filenameChanged) && $filenameChanged) { $removeFiles = Ml_Model_RemoveFiles::getInstance(); $removeFiles->addFileGc(array("share" => $shareInfo['id'], "byUid" => $shareInfo['byUid'], "download_secret" => $shareInfo['download_secret'], "filename" => $shareInfo['filename'], "alias" => $userInfo['alias'])); //Using delete from the S3 Zend class here doesn't work because of a bug //is not working for some reason after the _makeRequest or other things I tried to COPY... } else { unset($changeData['filename']); } if (empty($changeData)) { return false; } if (isset($changeData['description'])) { $purifier = Ml_Model_HtmlPurifier::getInstance(); $changeData['description_filtered'] = $purifier->purify($changeData['description']); } $date = new Zend_Date(); $changeData['lastChange'] = $date->get("yyyy-MM-dd HH:mm:ss"); $this->_dbTable->update($changeData, $this->_dbAdapter->quoteInto("id = ?", $shareInfo['id'])); return array_merge($shareInfo, $changeData); }
public function indexAction() { $request = $this->getRequest(); $registry = Zend_Registry::getInstance(); $router = Zend_Controller_Front::getInstance()->getRouter(); $config = $registry->get("config"); $people = Ml_Model_People::getInstance(); $profile = Ml_Model_Profile::getInstance(); $form = Ml_Model_Account::settingsForm(); $signedUserInfo = $registry->get("signedUserInfo"); $profileInfo = $profile->getById($signedUserInfo['id']); //only data that can be changed can be here $listOfData = array("name" => $signedUserInfo['name'], "email" => $signedUserInfo['email'], "private_email" => $signedUserInfo['private_email'], "about" => $profileInfo['about'], "website" => $profileInfo['website'], "location" => $profileInfo['location']); $form->setDefaults($listOfData); if ($request->isPost()) { $form->isValid($request->getPost()); $errors = $form->getErrors(); $changeData = array(); $rec = $form->getValues(); //update foreach ($listOfData as $key => $value) { if (empty($errors[$key]) && $rec[$key] != $value) { $changeData[$key] = $rec[$key]; } } if (!empty($changeData)) { $changeDataLessEmail = $changeData; if (isset($changeData['email'])) { unset($changeDataLessEmail['email']); } if (!empty($changeDataLessEmail)) { //just a small state protection if (isset($changeDataLessEmail['private_email'])) { $changeDataLessEmail['private_email'] = 1; } $profileFields = array("website", "location", "about"); $changeProfileData = array(); foreach ($profileFields as $field) { if (isset($changeDataLessEmail[$field])) { $changeProfileData[$field] = $changeDataLessEmail[$field]; unset($changeDataLessEmail[$field]); } } if (!empty($changeDataLessEmail)) { $people->update($signedUserInfo['id'], $changeDataLessEmail); } if (!empty($changeProfileData)) { if (isset($changeProfileData['about'])) { $purifier = Ml_Model_HtmlPurifier::getInstance(); $changeProfileData['about_filtered'] = $purifier->purify($changeProfileData['about']); } $profile->update($signedUserInfo['id'], $changeProfileData); } $signedUserInfo = array_merge($signedUserInfo, $changeDataLessEmail); $registry->set("signedUserInfo", $signedUserInfo); } if (isset($changeData['about']) && sizeof($changeData) == 1) { $redirectToProfile = true; } } if (isset($changeData['email'])) { $emailChange = Ml_Model_EmailChange::getInstance(); $securitycode = $emailChange->newChange($signedUserInfo['id'], $changeData['email'], $signedUserInfo['name']); $mail = new Zend_Mail(); $this->view->securitycode = $securitycode; $mail->setBodyText($this->view->render("account/emailChange.phtml"))->setFrom($config['robotEmail']['addr'], $config['robotEmail']['name'])->addTo($changeData['email'], $signedUserInfo['name'])->setSubject('Changing your ' . $config['applicationname'] . ' email')->send(); $this->view->changeEmail = true; } else { if (isset($redirectToProfile)) { $this->_redirect($router->assemble(array("username" => $signedUserInfo['alias']), "profile") . "?about_check=true", array("exit")); } } } $this->view->accountForm = $form; }
public function update($id, $comments) { $purifier = Ml_Model_HtmlPurifier::getInstance(); $commentsFiltered = $purifier->purify($comments); return $this->_dbTable->update(array("comments" => $comments, "comments_filtered" => $commentsFiltered), $this->_dbAdapter->quoteInto("id = ?", $id)); }