示例#1
0
 /**
  * Default controller for image view page
  * @return boolean
  */
 public function indexAction()
 {
     // Hash (bababa)
     $hashString = $this->getParam('hash', false);
     if (!$hashString) {
         return $this->deletedAction();
     }
     // Get hash document
     $hashDoc = $this->hashDoc = new Unsee_Hash($hashString);
     $form = $this->form;
     $block = new Unsee_Block($hashDoc->key);
     $sessionId = Unsee_Session::getCurrent();
     /**
      * "Block" cookie detected. This means that viewer performed one of the restricred actions, like
      * opening a web developer tools (Firebug), pressed the print screen button, etc.
      */
     if (isset($_COOKIE['block'])) {
         // Remove the cookie
         setcookie('block', null, 1, '/' . $hashDoc->key . '/');
         // Register a block flag for current session
         $block->{$sessionId} = time();
         // Act as if the image was deleted
         return $this->deletedAction();
     }
     // The block flag was previously set for the current session
     if (isset($block->{$sessionId})) {
         return $this->deletedAction();
     }
     // It was already deleted/did not exist/expired
     if (!$hashDoc->exists() || !$hashDoc->isViewable($hashDoc)) {
         return $this->deletedAction();
     }
     // Handle image settings form submission
     if ($this->getRequest()->isPost()) {
         $this->handleSettingsFormSubmit($form, $hashDoc);
     }
     // Check again
     // It was already deleted/did not exist/expired
     if (!$hashDoc->exists() || !$hashDoc->isViewable($hashDoc)) {
         return $this->deletedAction();
     }
     // No use to do anything, page is not viewable for one of the reasons
     if (!$hashDoc->isViewable($hashDoc)) {
         $hashDoc->delete();
         return $this->deletedAction();
     }
     // Getting an array of hash settings
     $values = $hashDoc->export();
     // Populate form values
     $form->populate($values);
     // Disable image download by default
     $this->view->no_download = true;
     $images = $hashDoc->getImages();
     // Creating a set of "tickets" to view images related to current hash
     $ticket = new Unsee_Ticket();
     // Create a view "ticket" for every image of a hash
     foreach ($images as $image) {
         $ticket->issue($image);
     }
     // Handle current request based on what settins are set
     foreach ($values as $key => $value) {
         $key = explode('_', $key);
         foreach ($key as &$itemItem) {
             $itemItem = ucfirst($itemItem);
         }
         $method = 'process' . implode('', $key);
         if (method_exists($this, $method) && !$this->{$method}()) {
             return $this->deletedAction();
         }
     }
     $this->view->isOwner = Unsee_Session::isOwner($hashDoc);
     // If viewer is the creator - don't count their view
     if (!Unsee_Session::isOwner($hashDoc)) {
         $hashDoc->views++;
         // Reached max views for this hash
         if ($hashDoc->max_views && $hashDoc->views >= $hashDoc->max_views) {
             // Remove the hash in a while for the images to be displayed
             $hashDoc->expireAt(time() + 30);
         }
     } else {
         // Owner - include extra webpage assets
         $this->view->headScript()->appendFile('js/settings.js');
         $this->view->headLink()->appendStylesheet('css/settings.css');
     }
     // Don't show the 'other party' text for the 'other party'
     if (Unsee_Session::isOwner($hashDoc) || $hashDoc->ttl !== Unsee_Hash::$ttlTypes[0]) {
         if ($hashDoc->ttl === Unsee_Hash::$ttlTypes[0]) {
             $deleteTimeStr = '';
             $deleteMessageTemplate = 'delete_first';
         } else {
             $deleteTimeStr = $hashDoc->getTtlWords();
             $deleteMessageTemplate = 'delete_time';
         }
         $this->view->deleteTime = $this->view->translate($deleteMessageTemplate, array($deleteTimeStr));
     }
     // Cookie check vould be passed to the image view controller below to
     // make sure the page was opened in a browser
     $this->view->cookieCheck = md5(Unsee_Session::getCurrent() . $hashDoc->key);
     $this->view->images = $images;
     $this->view->groups = $form->getDisplayGroups();
     $message = '';
     if (Unsee_Session::isOwner($this->hashDoc)) {
         $message = $this->view->translate('upload_more_owner');
     } elseif ($hashDoc->allow_anonymous_images) {
         $message = $this->view->translate('upload_more_anonymous');
     }
     $this->view->welcomeMessage = $message;
     return true;
 }
示例#2
0
 /**
  * Controller to handle file upload form
  * @throws Exception
  */
 public function indexAction()
 {
     $response = new stdClass();
     try {
         $upload = new Zend_File_Transfer();
     } catch (Exception $e) {
         $response->error = $e->getMessage();
         $this->_helper->json->sendJson($response);
     }
     $upload->addValidator('Count', false, array('min' => 1, 'max' => 100));
     $upload->addValidator('IsImage', false);
     $upload->addValidator('Size', false, array('max' => '10MB', 'bytestring' => false));
     $translate = Zend_Registry::get('Zend_Translate');
     $updating = false;
     try {
         if (!$upload->receive()) {
             throw new Exception($translate->translate('error_uploading'));
         } else {
             $files = $upload->getFileInfo();
             // Updating hash with new images
             if (!empty($_POST['hash']) && Unsee_Hash::isValid($_POST['hash'])) {
                 $hashDoc = new Unsee_Hash($_POST['hash']);
                 $updating = true;
                 $response = array();
                 if (!Unsee_Session::isOwner($hashDoc) && !$hashDoc->allow_anonymous_images) {
                     die('[]');
                 }
             } else {
                 // Creating a new hash
                 $hashDoc = new Unsee_Hash();
                 $this->setExpiration($hashDoc);
                 $response->hash = $hashDoc->key;
             }
             $imageAdded = false;
             foreach ($files as $file => $info) {
                 if ($upload->isUploaded($file)) {
                     $imgDoc = new Unsee_Image($hashDoc);
                     $res = $imgDoc->setFile($info['tmp_name']);
                     $imgDoc->setSecureParams();
                     //hack to populate correct secureTtd
                     if ($updating) {
                         $ticket = new Unsee_Ticket();
                         $ticket->issue($imgDoc);
                         $newImg = new stdClass();
                         $newImg->hashKey = $hashDoc->key;
                         $newImg->key = $imgDoc->key;
                         $newImg->src = '/image/' . $imgDoc->key . '/' . $imgDoc->secureMd5 . '/' . $imgDoc->secureTtd . '/';
                         $newImg->width = $imgDoc->width;
                         $newImg->ticket = md5(Unsee_Session::getCurrent() . $hashDoc->key);
                         $response[] = $newImg;
                     }
                     if ($res) {
                         $imageAdded = true;
                     }
                     // Remove uploaded file from temporary dir if it wasn't removed
                     if (file_exists($info['tmp_name'])) {
                         @unlink($info['tmp_name']);
                     }
                 }
             }
             if (!$imageAdded) {
                 throw new Exception('No images were added');
             }
         }
     } catch (Exception $e) {
         $response->error = $e->getMessage();
     }
     $this->_helper->json->sendJson($response);
 }