Ejemplo n.º 1
0
 function testURLsAndContent()
 {
     if ($this->s3_key) {
         $s3 = new S3Seed($this->cash_user_id, $this->s3_connection_id);
         // check for the timestamp in the public link for the public test file
         $test_content = CASHSystem::getURLContents('http://' . $this->s3_bucket . '.s3.amazonaws.com/' . 'test' . $this->timestamp);
         $this->assertPattern('/' . $this->timestamp . '/', $test_content);
         // and in the private link generated for the private test file
         $test_content = CASHSystem::getURLContents($s3->getExpiryURL('test_private' . $this->timestamp, 20));
         $this->assertPattern('/' . $this->timestamp . '/', $test_content);
         // now test headers -- relies on fopen wrappers
         if (ini_get('allow_url_fopen')) {
             // first defaults, both present:
             file_get_contents($s3->getExpiryURL('test_private' . $this->timestamp, 20));
             $this->assertTrue(array_search('Content-Disposition: attachment', $http_response_header));
             $this->assertTrue(array_search('Cache-Control: no-cache', $http_response_header));
             // no-cache only:
             file_get_contents($s3->getExpiryURL('test_private' . $this->timestamp, 20, false, true));
             $this->assertFalse(array_search('Content-Disposition: attachment', $http_response_header));
             $this->assertTrue(array_search('Cache-Control: no-cache', $http_response_header));
             // attachment only:
             file_get_contents($s3->getExpiryURL('test_private' . $this->timestamp, 20, true, false));
             $this->assertTrue(array_search('Content-Disposition: attachment', $http_response_header));
             $this->assertFalse(array_search('Cache-Control: no-cache', $http_response_header));
         }
     }
 }
Ejemplo n.º 2
0
	/**
	 * Reads asset details and redirects to the file directly. The success 
	 * Response is set here rather than in processRequest(), allowing it to 
	 * exist in the session 
	 *
	 * @param {integer} $asset_id - the asset you are trying to retrieve
	 * @return string
	 */public function redirectToAsset($asset_id,$element_id=0) {
		if ($this->getUnlockedStatus($asset_id)) {
			$asset = $this->getAssetInfo($asset_id);
			switch ($asset['type']) {
				case 'com.amazon':
					include(CASH_PLATFORM_ROOT.'/classes/seeds/S3Seed.php');
					$s3 = new S3Seed($asset['user_id'],$asset['settings_id']);
					$this->pushSuccess(array('asset' => $asset_id),'redirect executed successfully');
					$this->recordAnalytics($asset_id,$element_id);
					header("Location: " . $s3->getExpiryURL($asset['location']));
					die();
					break; // I know this break will never be executed, but it makes me feel better seeing it here
			    default:
					if (parse_url($asset['location']) || strpos($asset['location'], '/') !== false) {
						$this->pushSuccess(array('asset' => $asset_id),'redirect executed successfully');
						$this->recordAnalytics($asset_id,$element_id);
						header("Location: " . $asset['location']);
						die();
						break; // This one won't get executed either ...sucker!
					} else {
						return $this->response->pushResponse(
							500,$this->request_type,$this->action,
							$this->request,
							'unknown asset type, please as an admin to check the asset type'
						);
					}
			}
		}
	}
Ejemplo n.º 3
0
 protected function getFinalAssetLocation($connection_id, $user_id, $asset_location)
 {
     $connection_type = $this->getConnectionType($connection_id);
     $final_asset_location = false;
     switch ($connection_type) {
         case 'com.amazon':
             $s3 = new S3Seed($user_id, $connection_id);
             $final_asset_location = $s3->getExpiryURL($asset_location);
             break;
         default:
             if (parse_url($asset_location) || strpos($asset_location, '/') !== false) {
                 $final_asset_location = $asset_location;
                 break;
             }
     }
     return $final_asset_location;
 }