Exemplo n.º 1
0
 public function isValid($value)
 {
     $this->_setValue($value);
     $valueString = (string) $value;
     $people = Ml_Model_People::getInstance();
     if (mb_strstr($value, "@")) {
         $getUserByEmail = $people->getByEmail($value);
         if (empty($getUserByEmail)) {
             $this->_error(self::MSG_EMAIL_NOT_FOUND);
             return false;
         }
         Zend_Registry::getInstance()->set("loginUserInfo", $getUserByEmail);
         return true;
     }
     if (mb_strlen($value) == 0) {
         return false;
     }
     if (mb_strlen($value) > 20) {
         $this->_error(self::MSG_USERNAME_NOT_FOUND);
         return false;
     }
     if (preg_match('#([^a-z0-9_-]+)#is', $value) || $value == '0') {
         $this->_error(self::MSG_USERNAME_NOT_FOUND);
         return false;
     }
     $getUserByUsername = $people->getByUsername($value);
     if (empty($getUserByUsername)) {
         $this->_error(self::MSG_USERNAME_NOT_FOUND);
         return false;
     }
     Zend_Registry::getInstance()->set("loginUserInfo", $getUserByUsername);
     return true;
 }
Exemplo n.º 2
0
 public function init()
 {
     $registry = Zend_Registry::getInstance();
     $auth = Zend_Auth::getInstance();
     $config = $registry->get("config");
     $sessionConfig = $config['resources']['session'];
     $cookieLifetime = $sessionConfig['cookie_lifetime'];
     /* @todo fix issue of system with incoherent behavior when the session
        system has a issue, such as when the savehandler doesn't work as
        expected when it's off-line which results in differents
        catched / uncatched exception when the resource (page) loads
        */
     $saveHandler = new Ml_Session_SaveHandler_PlusCache($registry->get("memCache"), $config['session']['prefix'], $config['lastActivity']['prefix']);
     Zend_Session::setSaveHandler($saveHandler);
     Zend_Session::getSaveHandler()->setLifetime($cookieLifetime, true);
     Zend_Session::start();
     $defaultNamespace = new Zend_Session_Namespace();
     if (!isset($defaultNamespace->initialized)) {
         Zend_Session::regenerateId();
         $defaultNamespace->initialized = true;
     }
     if ($auth->hasIdentity()) {
         $people = Ml_Model_People::getInstance();
         $signedUserInfo = $people->getById($auth->getIdentity());
         $registry->set('signedUserInfo', $signedUserInfo);
     }
     $globalHash = Ml_Model_MagicCookies::getInstance()->getLast(true);
     $registry->set("globalHash", $globalHash);
 }
Exemplo n.º 3
0
 public function deleteAccount($userInfo, $userInfoSerializedHashed)
 {
     $registry = Zend_Registry::getInstance();
     $people = Ml_Model_People::getInstance();
     $share = Ml_Model_Share::getInstance();
     $removeFiles = Ml_Model_RemoveFiles::getInstance();
     $picture = Ml_Model_Picture::getInstance();
     if (!is_array($userInfo) || !isset($userInfo['alias'])) {
         throw new Exception("Invalid userInfo data.");
     }
     //flag set to true when authorized to do so, least security resource
     if (!$registry->isRegistered("canDeleteAccount")) {
         throw new Exception("Not authorized to delete account.");
     }
     if (sha1(serialize($userInfo)) != $userInfoSerializedHashed) {
         throw new Exception("userInfo and serialized data doesn't match.");
     }
     $this->_dbAdapter->beginTransaction();
     try {
         $picture->deleteFiles($userInfo);
         $removeFiles->addFilesGc($userInfo['id'], $userInfo['alias']);
         $this->_dbAdapter->query("INSERT INTO " . $this->_dbAdapter->quoteTableAs($this->_dbTable->getTableName()) . " SELECT id, alias, email, membershipdate, name, private_email, CURRENT_TIMESTAMP as delete_timestamp from people where " . $this->_dbAdapter->quoteInto("id = ?", $userInfo['id']));
         $people->delete($userInfo['id']);
         $this->_dbAdapter->commit();
     } catch (Exception $e) {
         $this->_dbAdapter->rollBack();
         throw $e;
     }
     return true;
 }
Exemplo n.º 4
0
 public function pseudoshareSetUp()
 {
     $registry = Zend_Registry::getInstance();
     $request = $this->getRequest();
     if ($request->getUserParam('username') && !$registry->isRegistered("userInfo")) {
         //avoid calling the DB again for nothing
         if (isset($registry['signedUserInfo']) && $registry['signedUserInfo']['alias'] == $request->getUserParam('username')) {
             $userInfo = $registry['signedUserInfo'];
         } else {
             $people = Ml_Model_People::getInstance();
             $userInfo = $people->getByUsername($request->getUserParam('username'));
         }
         if (!$userInfo) {
             $registry->set("notfound", true);
             throw new Exception("User does not exists.");
         }
         $registry->set("userInfo", $userInfo);
         $registry->set("requestUserParams", $this->getRequest()->getUserParams());
         if ($this->getRequest()->getUserParam("share_id")) {
             $share = Ml_Model_Share::getInstance();
             $shareInfo = $share->getById($this->getRequest()->getUserParam("share_id"));
             if (!$shareInfo) {
                 $registry->set("notfound", true);
                 throw new Exception("Share does not exists.");
             } else {
                 if ($shareInfo['byUid'] != $userInfo['id']) {
                     $registry->set("notfound", true);
                     throw new Exception("Share owned by another user.");
                 }
             }
             $registry->set("shareInfo", $shareInfo);
         }
     }
 }
Exemplo n.º 5
0
 public function isValid($value)
 {
     $registry = Zend_Registry::getInstance();
     $this->_setValue($value);
     $valueString = (string) $value;
     if (mb_strlen($value) < 1 || mb_strlen($value) > 100) {
         return false;
     }
     $method = strpos($value, '@') === FALSE ? "alias" : "email";
     $people = Ml_Model_People::getInstance();
     if ($method == "alias") {
         $getUser = $people->getByUsername($value);
     } else {
         $getUser = $people->getByEmail($value);
     }
     if (empty($getUser)) {
         if ($method == "alias") {
             $this->_error(self::MSG_USERNAME_NOT_FOUND);
         } else {
             $this->_error(self::MSG_EMAIL_NOT_FOUND);
         }
         return false;
     }
     $registry->set("accountRecover", $getUser);
     return true;
 }
Exemplo n.º 6
0
 public function passwordAction()
 {
     $request = $this->getRequest();
     $auth = Zend_Auth::getInstance();
     $registry = Zend_Registry::getInstance();
     $router = Zend_Controller_Front::getInstance()->getRouter();
     $people = Ml_Model_People::getInstance();
     $credential = Ml_Model_Credential::getInstance();
     $recover = Ml_Model_Recover::getInstance();
     $params = $request->getParams();
     $this->view->request = $request;
     if ($auth->hasIdentity()) {
         if (isset($params['confirm_uid'])) {
             $this->_redirect($router->assemble(array(), "logout") . "?please", array("exit"));
         }
         $form = $credential->newPasswordForm();
         $uid = $auth->getIdentity();
         $registry->set("changeUserProperPassword", true);
         $signedUserInfo = $registry->get("signedUserInfo");
     } else {
         if (isset($params['confirm_uid']) && isset($params['security_code'])) {
             $recoverInfo = $recover->getAuthorization($params["confirm_uid"], $params["security_code"]);
             if (!$recoverInfo) {
                 return $this->_forward("unavailable");
             }
             $form = $credential->newPasswordForm($params["confirm_uid"], $params["security_code"]);
             $uid = $recoverInfo['uid'];
         } else {
             return $this->_forward("redirect", "login");
         }
     }
     if ($auth->hasIdentity()) {
         $this->view->userInfoDataForPasswordChange = $signedUserInfo;
     } else {
         $userInfo = $people->getById($request->getParam("confirm_uid"));
         $this->view->userInfoDataForPasswordChange = $userInfo;
     }
     if ($request->isPost()) {
         $credentialInfo = $credential->getByUid($uid);
         if (!$credentialInfo) {
             $this->_redirect($router->assemble(array(), "index"), array("exit"));
         }
         $registry->set('credentialInfoDataForPasswordChange', $credentialInfo);
         if ($form->isValid($request->getPost())) {
             $password = $form->getValue("password");
             if (isset($recoverInfo)) {
                 $recover->closeCase($uid);
             }
             $credential->setCredential($uid, $password);
             $this->view->passwordReset = true;
         }
     }
     if (!isset($this->view->passwordReset)) {
         $this->view->passwordForm = $form;
     }
 }
Exemplo n.º 7
0
 public function getCommentsPages($shareId, $perPage, $page)
 {
     $people = Ml_Model_People::getInstance();
     $select = $this->_dbTable->select();
     $select->where($this->_dbTable->getTableName() . ".share = ?", $shareId)->order("timestamp ASC");
     $people->joinDbTableInfo($select, $this->_dbTable->getTableName(), "uid");
     $paginator = Zend_Paginator::factory($select);
     $paginator->setCurrentPageNumber($page);
     $paginator->setItemCountPerPage($perPage);
     return $paginator;
 }
Exemplo n.º 8
0
 public function isValid($value)
 {
     $people = Ml_Model_People::getInstance();
     $this->_setValue($value);
     $valueString = (string) $value;
     if (mb_strlen($value) < 3 || mb_strlen($value) > 60) {
         return false;
     }
     $getUserByMail = $people->getByEmail($value);
     if (!empty($getUserByMail)) {
         $this->_error(self::MSG_EMAIL_EXISTS);
         return false;
     }
     return true;
 }
Exemplo n.º 9
0
 /**
  * 
  * Change user's e-mail
  * @param big int $uid
  * @param string $email
  * @param bool $removeTicket removes update request ticket
  */
 public function setChange($uid, $email, $removeTicket = true)
 {
     $people = Ml_Model_People::getInstance();
     if ($removeTicket) {
         $rename = $people->update($uid, array("email" => $email));
         if (!$rename) {
             return false;
         }
     }
     $deleteRequest = $this->_dbTable->delete($this->_dbAdapter->quoteInto('uid = ?', $uid));
     if (!$deleteRequest) {
         return false;
     }
     return true;
 }
Exemplo n.º 10
0
 public function user()
 {
     $registry = Zend_Registry::getInstance();
     $request = $this->getRequest();
     $params = $request->getParams();
     $people = Ml_Model_People::getInstance();
     if (!isset($params['user_id'])) {
         throw new Exception("User param not given.");
     }
     $userInfo = $people->getById($params['user_id']);
     if (empty($userInfo)) {
         $registry->set("notfound", true);
         throw new Exception("User not found.");
     }
     $registry->set("userInfo", $userInfo);
 }
Exemplo n.º 11
0
 public function userAction()
 {
     $registry = Zend_Registry::getInstance();
     $router = Zend_Controller_Front::getInstance()->getRouter();
     $favorites = Ml_Model_Favorites::getInstance();
     $share = Ml_Model_Share::getInstance();
     $people = Ml_Model_People::getInstance();
     $request = $this->getRequest();
     $userInfo = $registry->get('userInfo');
     $page = $request->getUserParam("page");
     $paginator = $favorites->getUserPage($userInfo['id'], 25, $page);
     //Test if there is enough pages or not
     if (!$paginator->count() && $page != 1 || $paginator->getCurrentPageNumber() != $page) {
         $this->_redirect($router->assemble(array("username" => $userInfo['alias']), "userfav_1stpage"), array("exit"));
     }
     $this->view->paginator = $paginator;
 }
Exemplo n.º 12
0
 public function getContactsPage($uid, $perPage, $page, $reverse = false)
 {
     $people = Ml_Model_People::getInstance();
     if ($reverse) {
         $uidF = 'has';
         $hasF = 'uid';
     } else {
         $uidF = 'uid';
         $hasF = 'has';
     }
     $select = $this->_dbTable->select();
     $select->where($this->_dbTable->getTableName() . "." . $uidF . " = ?", $uid)->order($this->_dbTable->getTableName() . ".since DESC");
     $people->joinDbTableInfo($select, $this->_dbTable->getTableName(), $hasF);
     $paginator = Zend_Paginator::factory($select);
     $paginator->setCurrentPageNumber($page);
     $paginator->setItemCountPerPage($perPage);
     return $paginator;
 }
Exemplo n.º 13
0
 public function confirmAction()
 {
     $auth = Zend_Auth::getInstance();
     $request = $this->getRequest();
     $registry = Zend_Registry::getInstance();
     $router = Zend_Controller_Front::getInstance()->getRouter();
     $config = $registry->get("config");
     if ($auth->hasIdentity()) {
         $registry->set("pleaseSignout", true);
         return $this->_forward("index", "logout");
     }
     $signUp = Ml_Model_SignUp::getInstance();
     $credential = Ml_Model_Credential::getInstance();
     $people = Ml_Model_People::getInstance();
     $profile = Ml_Model_Profile::getInstance();
     if ($config['ssl'] && (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != "on")) {
         $this->_redirect("https://" . $config['webhostssl'] . $router->assemble(array($request->getUserParams()), "join_emailconfirm"), array("exit"));
     }
     $securityCode = $request->getParam("security_code");
     $confirmationInfo = $signUp->getByHash($securityCode);
     if (!$confirmationInfo) {
         $this->getResponse()->setHttpResponseCode(404);
         return $this->_forward("unavailable");
     }
     $form = $signUp->newIdentityForm($securityCode);
     if ($request->isPost() && $form->isValid($request->getPost())) {
         $newUsername = $form->getValue("newusername");
         $password = $form->getValue("password");
         $preUserInfo = array("alias" => $newUsername, "membershipdate" => $confirmationInfo['timestamp'], "name" => $confirmationInfo['name'], "email" => $confirmationInfo['email']);
         $uid = $people->create($newUsername, $password, $preUserInfo, $confirmationInfo);
         $getUserByUsername = $people->getByUsername($preUserInfo['alias']);
         $adapter = $credential->getAuthAdapter($getUserByUsername['id'], $password);
         if ($adapter) {
             $result = $auth->authenticate($adapter);
             if ($result->getCode() != Zend_Auth_Result::SUCCESS) {
                 throw new Exception("Could not authenticate 'just created' user");
             }
         }
         Zend_Session::regenerateId();
         $this->_redirect($router->assemble(array(), "join_welcome"), array("exit"));
     }
     $this->view->entry = $confirmationInfo;
     $this->view->confirmForm = $form;
 }
Exemplo n.º 14
0
 public function direct()
 {
     if (OAuthRequestVerifier::requestIsSigned()) {
         try {
             $req = new OAuthRequestVerifier();
             $authUid = $req->verify();
             if ($authUid) {
                 $registry = Zend_Registry::getInstance();
                 $people = Ml_Model_People::getInstance();
                 $authedUserInfo = $people->getById($authUid);
                 $registry->set("authedUserInfo", $authedUserInfo);
             }
         } catch (OAuthException $e) {
             //If user authentication fails
             header('HTTP/1.1 401 Unauthorized');
             header('WWW-Authenticate: OAuth realm=""');
             header('Content-Type: text/plain; charset=utf8');
             throw $e;
         }
     }
 }
Exemplo n.º 15
0
 public function deleteAction()
 {
     $registry = Zend_Registry::getInstance();
     $service = new Ml_Model_Service();
     $timecheck = new Ml_Model_Timecheck();
     $people = Ml_Model_People::getInstance();
     $peopleDelete = Ml_Model_PeopleDelete::getInstance();
     $service->putString("WARNING!\n========\n");
     $service->putString("DON'T type the user data. Use COPY/PASTE.\n");
     $service->requestConfirmAction("Delete user");
     $timecheck->reset();
     $enteredUserId = $service->getInput("Delete User of id: ");
     $timecheck->check(60);
     $timecheck->reset();
     $enteredUserAlias = $service->getInput("Delete User of alias: ");
     $timecheck->check(40);
     $userInfo = $people->getById($enteredUserId);
     if (!is_array($userInfo)) {
         die("User Not Found by ID.\n");
     }
     if ($userInfo['id'] != $enteredUserId) {
         throw new Exception("Wrong ID retrieved?");
     }
     if ($userInfo['alias'] != $enteredUserAlias) {
         die("Alias does NOT match user id. Please, be careful.\n");
     }
     $service->putString("USER INFORMATION\n=================\n");
     $service->putString(print_r($userInfo, true));
     $timecheck->reset();
     $service->requestConfirmAction("Please DO confirm alias, email, name and id.\n\nDelete this user");
     $service->requestConfirmAction("Confirm");
     $timecheck->check(180);
     $service->putString("Sleeping for three seconds.\nAfter that, deleting the user. Use ^C to cancel\n");
     sleep(3);
     $registry->set("canDeleteAccount", true);
     $peopleDelete->deleteAccount($userInfo, sha1(serialize($userInfo)));
     echo "User account deleted.\n";
 }
Exemplo n.º 16
0
 public function shortLink()
 {
     $registry = Zend_Registry::getInstance();
     $config = $registry->get("config");
     $uri = $_SERVER['REQUEST_URI'];
     if ($uri == '/') {
         header("HTTP/1.1 301 Moved Permanently");
         header("Location: http://" . $config['webhost'] . "/");
         exit;
     }
     //clear the first and the last '/'
     if (mb_substr($uri, -1) == '/') {
         $uri = mb_substr($uri, 1, -1);
     } else {
         $uri = mb_substr($uri, 1);
     }
     $numbers = new Ml_Model_Numbers();
     $id = $numbers->base58Decode($uri);
     if ($id) {
         //Is it a valid share ID?
         $share = Ml_Model_Share::getInstance();
         $people = Ml_Model_People::getInstance();
         $shareInfo = $share->getById($id);
         if ($shareInfo) {
             $userInfo = $people->getById($shareInfo['byUid']);
             $link = "http://" . $config['webhost'] . "/" . urlencode($userInfo['alias']) . "/" . $shareInfo['id'];
             header("HTTP/1.1 301 Moved Permanently");
             header("Location: " . $link);
             exit;
             //nothing more to do
         }
     }
     //If nothing matches
     $link = "http://" . $config['webhost'] . "/not-found/" . urlencode(utf8_encode($uri));
     header("Location: " . $link);
     //the redirector stops the default bootstrap, always
     exit;
 }
Exemplo n.º 17
0
 public function confirmAction()
 {
     $auth = Zend_Auth::getInstance();
     $router = Zend_Controller_Front::getInstance()->getRouter();
     $request = $this->getRequest();
     $people = Ml_Model_People::getInstance();
     $emailChange = Ml_Model_EmailChange::getInstance();
     $confirmUid = $request->getParam("confirm_uid");
     $securityCode = $request->getParam("security_code");
     $changeInfo = $emailChange->get($confirmUid, $securityCode);
     if (!$changeInfo) {
         $this->_redirect("/email/unconfirmed", array("exit"));
     }
     if ($auth->hasIdentity() && $changeInfo['uid'] != $auth->getIdentity()) {
         $this->_redirect($router->assemble(array(), "logout") . "?please", array("exit"));
     }
     $confirm = $emailChange->setChange($confirmUid, $changeInfo['email']);
     if ($confirm) {
         $this->_redirect($this->view->StaticUrl("/email/confirmed"), array("exit"));
     } else {
         throw new Exception("Couldn't confirm new e-mail.");
     }
 }
Exemplo n.º 18
0
 public function isValid($value)
 {
     $this->_setValue($value);
     $valueString = (string) $value;
     if (preg_match('#([^a-z0-9_-]+)#is', $value) || $value == '0') {
         $this->_error(self::MSG_USERNAME_INVALID);
         return false;
     }
     $reservedUsernames = (require APPLICATION_PATH . "/configs/ReservedUsernames.php");
     if (in_array($value, $reservedUsernames)) {
         $this->_error(self::MSG_USERNAME_RESERVED);
         return false;
     }
     if (mb_strlen($value) < 1 || mb_strlen($value) > 15) {
         return false;
     }
     $people = Ml_Model_People::getInstance();
     $getUserByUsername = $people->getByUsername($value);
     if (!empty($getUserByUsername)) {
         $this->_error(self::MSG_USERNAME_EXISTS);
         return false;
     }
     return true;
 }
Exemplo n.º 19
0
 public function deleteAction()
 {
     $registry = Zend_Registry::getInstance();
     $service = new Ml_Model_Service();
     $timecheck = new Ml_Model_Timecheck();
     $share = Ml_Model_Share::getInstance();
     $people = Ml_Model_People::getInstance();
     $service->putString("WARNING!\n========\n");
     $service->requestConfirmAction("Delete share");
     $timecheck->reset();
     $shareId = $service->getInput("Delete share of ID?");
     $timecheck->check(60);
     $timecheck->reset();
     $shareInfo = $share->getById($shareId);
     if (!is_array($shareInfo)) {
         die("Share not found.\n");
     }
     $service->putString(print_r($shareInfo, true));
     $userInfo = $people->getById($shareInfo['byUid']);
     $service->putString("By user alias: " . $userInfo['alias'] . "\n");
     $service->requestConfirmAction("Delete this share");
     $share->deleteShare($shareInfo, $userInfo);
     echo "Share deleted!\n";
 }
Exemplo n.º 20
0
 public function setAvatar($userInfo, $source)
 {
     $registry = Zend_Registry::getInstance();
     $config = $registry->get("config");
     $people = Ml_Model_People::getInstance();
     $s3config = $config['services']['S3'];
     $s3 = new Zend_Service_Amazon_S3($s3config['key'], $s3config['secret']);
     try {
         $im = new Imagick($source);
         $im->setimagecompressionquality(self::$_imageQuality);
         $dim = $im->getimagegeometry();
         if (!$dim) {
             return false;
         }
     } catch (Exception $e) {
         return false;
     }
     $sizesInfo = array();
     $tmpFilenames = array();
     $im->unsharpMaskImage(0, 0.5, 1, 0.05);
     foreach ($this->_sizes as $sizeInfo) {
         $tmpFilenames[$sizeInfo[1]] = tempnam(sys_get_temp_dir(), 'HEADSHOT');
         if ($sizeInfo[0] == "sq") {
             if ($dim['height'] < $dim['width']) {
                 $size = $dim['height'];
             } else {
                 $size = $dim['width'];
             }
             //@todo let the user crop using Javascript, so he/she can set the offsets (default 0,0)
             $im->cropThumbnailImage($sizeInfo[3], $sizeInfo[3]);
         } else {
             if ($dim['width'] < $sizeInfo[3] && $dim['height'] < $sizeInfo[3] && $sizeInfo[2] != 'huge') {
                 copy($source, $tmpFilenames[$sizeInfo[1]]);
             } else {
                 if ($dim['width'] > $dim['height']) {
                     $im->resizeimage($sizeInfo[3], 0, Imagick::FILTER_LANCZOS, 1);
                 } else {
                     $im->resize(0, $sizeInfo[3], Imagick::FILTER_LANCZOS, 1);
                 }
             }
         }
         $im->writeimage($tmpFilenames[$sizeInfo[1]]);
         $imGeometry = $im->getimagegeometry();
         $sizesInfo[$sizeInfo[0]] = array("w" => $imGeometry['width'], "h" => $imGeometry['height']);
     }
     $oldData = unserialize($userInfo['avatarInfo']);
     //get the max value of mt_getrandmax() or the max value of the unsigned int type
     if (mt_getrandmax() < 4294967295.0) {
         $maxRand = mt_getrandmax();
     } else {
         $maxRand = 4294967295.0;
     }
     $newSecret = mt_rand(0, $maxRand);
     if (isset($oldData['secret'])) {
         while ($oldData['secret'] == $newSecret) {
             $newSecret = mt_rand(0, $maxRand);
         }
     }
     foreach ($tmpFilenames as $size => $file) {
         if ($size == '_h') {
             $privacy = Zend_Service_Amazon_S3::S3_ACL_PRIVATE;
         } else {
             $privacy = Zend_Service_Amazon_S3::S3_ACL_PUBLIC_READ;
         }
         $picAddr = $s3config['headshotsBucket'] . "/" . $userInfo['id'] . '-' . $newSecret . $size . '.jpg';
         $meta = array(Zend_Service_Amazon_S3::S3_ACL_HEADER => $privacy, "Content-Type" => Zend_Service_Amazon_S3::getMimeType($picAddr), "Cache-Control" => "max-age=37580000, public", "Expires" => "Thu, 10 May 2029 00:00:00 GMT");
         $s3->putFile($file, $picAddr, $meta);
         unlink($file);
     }
     $newAvatarInfo = serialize(array("sizes" => $sizesInfo, "secret" => $newSecret));
     $people->update($userInfo['id'], array("avatarInfo" => $newAvatarInfo));
     //delete the old files
     $this->deleteFiles($userInfo);
     return true;
 }
Exemplo n.º 21
0
 public function filepageAction()
 {
     $registry = Zend_Registry::getInstance();
     $auth = Zend_Auth::getInstance();
     $request = $this->getRequest();
     $config = $registry->get('config');
     $params = $request->getParams();
     $keys = array("deletetag" => array("tags" => "delete"), "addtags" => array("tags" => "add"), "favorite" => array("favorites" => "switch"), "unfavorite" => array("favorites" => "switch"), "tweet" => array("twitter" => "tweet"));
     $this->_helper->loadResource->pseudoshareSetUp();
     foreach ($keys as $key => $where) {
         if (array_key_exists($key, $params)) {
             return $this->_forward(current($where), key($where));
         }
     }
     $userInfo = $registry->get('userInfo');
     $shareInfo = $registry->get("shareInfo");
     if ($registry->isRegistered("signedUserInfo")) {
         $signedUserInfo = $registry->get("signedUserInfo");
     }
     $page = $request->getUserParam("page");
     $share = Ml_Model_Share::getInstance();
     $tags = Ml_Model_Tags::getInstance();
     $people = Ml_Model_People::getInstance();
     $comments = Ml_Model_Comments::getInstance();
     $twitter = Ml_Model_Twitter::getInstance();
     $ignore = Ml_Model_Ignore::getInstance();
     $paginator = $comments->getCommentsPages($shareInfo['id'], $config['share']['commentsPerPage'], $page);
     //Test if there is enough pages or not
     if (!$paginator->count() && $page != 1 || $paginator->getCurrentPageNumber() != $page) {
         $this->_redirect(Zend_Controller_Front::getInstance()->getRouter()->assemble(array("username" => $userInfo['alias'], "share_id" => $shareInfo['id']), "sharepage_1stpage"), array("exit"));
     }
     $tagsList = $tags->getShareTags($shareInfo['id']);
     if ($auth->hasIdentity()) {
         $ignore = Ml_Model_Ignore::getInstance();
         if ($auth->getIdentity() == $userInfo['id'] || !$ignore->status($userInfo['id'], $auth->getIdentity())) {
             $commentForm = $comments->addForm();
             //should The comment form processing should be in the CommentsController?
             if ($request->isPost() && $commentForm->isValid($request->getPost())) {
                 $newCommentMsg = $commentForm->getValue('commentMsg');
                 $previewFlag = $commentForm->getValue('getCommentPreview');
                 //check if it is a post or preview
                 if (!empty($previewFlag)) {
                     $this->view->commentPreview = $newCommentMsg;
                 } else {
                     $newComment = $comments->add($newCommentMsg, $auth->getIdentity(), $shareInfo);
                     if (!$newComment) {
                         $newComment = "#commentPreview";
                         $this->view->commentPreview = $newCommentMsg;
                     } else {
                         $request->setParam("comment_id", $newComment);
                         return $this->_forward("commentpermalink", "comments");
                     }
                 }
             }
             $this->view->commentForm = $commentForm;
             if ($twitter->getSignedUserTwitterAccount()) {
                 $this->view->twitterForm = $twitter->form();
             }
         }
     }
     $this->view->tagsList = $tagsList;
     $this->view->paginator = $paginator;
 }
Exemplo n.º 22
0
 public function infoAction()
 {
     //@todo route: do it the right way!
     $router = new Zend_Controller_Router_Rewrite();
     $routeConfig = new Zend_Config_Ini(APPLICATION_PATH . '/configs/defaultRoutes.ini');
     $router->addConfig($routeConfig, 'routes');
     $registry = Zend_Registry::getInstance();
     $config = $registry->get("config");
     $request = $this->getRequest();
     $params = $request->getParams();
     $people = Ml_Model_People::getInstance();
     $profile = Ml_Model_Profile::getInstance();
     $share = Ml_Model_Share::getInstance();
     if (isset($params['username'])) {
         $userInfo = $people->getByUsername($params['username']);
     } else {
         if (isset($params['user_id'])) {
             $userInfo = $people->getById($params['user_id']);
         } else {
             if (isset($params['email'])) {
                 $userInfo = $people->getByEmail($params['email']);
                 if (!empty($userInfo) && $userInfo['private_email'] == true) {
                     $registry->set("notfound", true);
                     throw new Exception("User not found.");
                 }
             } else {
                 throw new Exception("No user params were given.");
             }
         }
     }
     if (empty($userInfo)) {
         $registry->set("notfound", true);
         throw new Exception("User not found.");
     }
     $profileInfo = $profile->getById($userInfo['id']);
     $doc = new Ml_Model_Dom();
     $doc->formatOutput = true;
     $rootElement = $doc->createElement("person");
     $doc->appendChild($rootElement);
     $rootElement->appendChild($doc->newTextAttribute('id', $userInfo['id']));
     $avatarInfo = unserialize($userInfo['avatarInfo']);
     if (isset($avatarInfo['secret'])) {
         $iconSecret = $avatarInfo['secret'];
     } else {
         $iconSecret = '';
     }
     $rootElement->appendChild($doc->newTextAttribute('iconsecret', $iconSecret));
     $userData = array("username" => $userInfo['alias'], "realname" => $userInfo['name']);
     if (!$userInfo['private_email']) {
         $userData["mbox_sha1sum"] = sha1("mailto:" . $userInfo['email']);
     }
     $userData["location"] = $profileInfo['location'];
     $userData["url"] = "http://" . $config['webhost'] . $router->assemble(array("username" => $userInfo['alias']), "filestream_1stpage");
     foreach ($userData as $field => $data) {
         $rootElement->appendChild($doc->newTextElement($field, $data));
     }
     $sharesCounter = $share->countOfUser($userInfo['id']);
     $sharesElement = $doc->createElement("files");
     $sharesCounterElement = $doc->createElement("count");
     $sharesCounterElement->appendChild($doc->createTextNode($sharesCounter));
     $sharesElement->appendChild($sharesCounterElement);
     $rootElement->appendChild($sharesElement);
     $this->_helper->printResponse($doc);
 }
Exemplo n.º 23
0
 public function pictureAction()
 {
     $registry = Zend_Registry::getInstance();
     $request = $this->getRequest();
     $signedUserInfo = $registry->get("signedUserInfo");
     $picture = Ml_Model_Picture::getInstance();
     $people = Ml_Model_People::getInstance();
     $form = $picture->pictureForm();
     if ($request->isPost() && $form->isValid($request->getPost())) {
         if ($form->getValue("delete")) {
             $change = $picture->deleteAvatar($signedUserInfo);
         } else {
             if ($form->Image->isUploaded()) {
                 $fileInfo = $form->Image->getFileInfo();
                 $change = $picture->setAvatar($signedUserInfo, $fileInfo['Image']['tmp_name']);
             }
         }
         if (isset($change) && $change) {
             //refresh
             $signedUserInfo = $people->getById($signedUserInfo['id']);
             $registry->set("signedUserInfo", $signedUserInfo);
         }
         $form->getValues();
     }
     $this->view->submitPictureForm = $form;
 }
Exemplo n.º 24
0
 public function infoAction()
 {
     //@todo route: do it the right way!
     $router = new Zend_Controller_Router_Rewrite();
     $routeConfig = new Zend_Config_Ini(APPLICATION_PATH . '/configs/defaultRoutes.ini');
     $router->addConfig($routeConfig, 'routes');
     $registry = Zend_Registry::getInstance();
     $config = $registry->get("config");
     $request = $this->getRequest();
     $params = $request->getParams();
     $people = Ml_Model_People::getInstance();
     $favorites = Ml_Model_Favorites::getInstance();
     $comments = Ml_Model_Comments::getInstance();
     $tags = Ml_Model_Tags::getInstance();
     $numbers = new Ml_Model_Numbers();
     $this->_helper->loadApiresource->share();
     $shareInfo = $registry->get("shareInfo");
     $userInfo = $people->getById($shareInfo['byUid']);
     $tagsList = $tags->getShareTags($shareInfo['id']);
     $countFavs = $favorites->count($shareInfo['id']);
     $countComments = $comments->count($shareInfo['id']);
     //begin of response
     $doc = new Ml_Model_Dom();
     $doc->formatOutput = true;
     $rootElement = $doc->createElement("file");
     $doc->appendChild($rootElement);
     $rootElement->appendChild($doc->newTextAttribute('id', $shareInfo['id']));
     $rootElement->appendChild($doc->newTextAttribute('secret', $shareInfo['secret']));
     $rootElement->appendChild($doc->newTextAttribute('download_secret', $shareInfo['download_secret']));
     $ownerElement = $doc->createElement("owner");
     $ownerData = array("id" => $userInfo['id'], "username" => $userInfo['alias'], "realname" => $userInfo['name']);
     foreach ($ownerData as $field => $data) {
         $ownerElement->appendChild($doc->newTextAttribute($field, $data));
     }
     $rootElement->appendChild($ownerElement);
     $shareData = array("title" => $shareInfo['title'], "filename" => $shareInfo['filename'], "filetype" => $shareInfo['type'], "short" => $shareInfo['short'], "description" => $shareInfo['description_filtered'], "url" => "http://" . $config['webhost'] . $router->assemble(array("username" => $userInfo['alias'], "share_id" => $shareInfo['id']), "sharepage_1stpage"), "dataurl" => $config['services']['S3']['sharesBucketAddress'] . $userInfo['alias'] . "/" . $shareInfo['id'] . "-" . $shareInfo['download_secret'] . "/" . $shareInfo['filename'], "shorturl" => $config['URLshortening']['addr'] . $numbers->base58Encode($shareInfo['id']), "comments" => $countComments, "favorites" => $countFavs);
     foreach ($shareData as $field => $data) {
         $rootElement->appendChild($doc->newTextElement($field, $data));
     }
     $filesizeElement = $doc->createElement("filesize");
     $filesizeElement->appendChild($doc->newTextAttribute("bits", $shareInfo['fileSize']));
     $filesizeElement->appendChild($doc->newTextAttribute("kbytes", ceil($shareInfo['fileSize'] / (1024 * 8))));
     $rootElement->appendChild($filesizeElement);
     $checksumElement = $doc->createElement("checksum");
     $checksumElement->appendChild($doc->newTextAttribute("hash", "md5"));
     $checksumElement->appendChild($doc->newTextAttribute("value", $shareInfo['md5']));
     $rootElement->appendChild($checksumElement);
     $visibilityElement = $doc->createElement("visibility");
     $visibilityElement->appendChild($doc->newTextAttribute("ispublic", "1"));
     $rootElement->appendChild($visibilityElement);
     $datesData = array("posted" => $shareInfo['uploadedTime'], "lastupdate" => $shareInfo['lastChange']);
     $datesElement = $doc->createElement("dates");
     foreach ($datesData as $field => $data) {
         $datesElement->appendChild($doc->newTextAttribute($field, $data));
     }
     $rootElement->appendChild($datesElement);
     $tagsElement = $doc->createElement("tags");
     foreach ($tagsList as $tag) {
         $tagElement = $doc->createElement("tag");
         $tagElement->appendChild($doc->newTextAttribute("id", $tag['id']));
         $tagElement->appendChild($doc->newTextAttribute("raw", $tag['raw']));
         $tagElement->appendChild($doc->createTextNode($tag['clean']));
         $tagsElement->appendChild($tagElement);
     }
     $rootElement->appendChild($tagsElement);
     $this->_helper->printResponse($doc);
 }