setEndpoint() public method

Set the service endpoint
public setEndpoint ( string $host ) : void
$host string Hostname
return void
Ejemplo n.º 1
0
 /**
  * Prepare the S3 connection for requests to this bucket.
  *
  * @param $settings
  */
 private function _prepareForRequests($settings = null)
 {
     if (is_null($settings)) {
         $settings = $this->getSettings();
     }
     if (is_null($this->_s3)) {
         $this->_s3 = new \S3($settings->keyId, $settings->secret);
     }
     \S3::setAuth($settings->keyId, $settings->secret);
     $this->_s3->setEndpoint(static::getEndpointByLocation($settings->location));
 }
Ejemplo n.º 2
0
 /**
  * Returns a fresh S3 instance
  */
 private function _getS3($cfg)
 {
     $s3 = new S3($cfg['accesskey'], $cfg['secretkey']);
     if (!empty($cfg['endpoint'])) {
         $s3->setEndpoint($cfg['endpoint']);
     }
     return $s3;
 }
 public static function updateUserImage($userId)
 {
     $result = new FunctionResult();
     $result->success = false;
     if (!empty($userId)) {
         $user = GameUsers::getGameUserById($userId);
         if (!empty($user)) {
             $tmpImgPath = UserProfileImageUtils::downloadFBProfileImage($user->facebookId);
             $profileImageUrl = null;
             if (!empty($tmpImgPath)) {
                 try {
                     $s3 = new S3(AWS_API_KEY, AWS_SECRET_KEY);
                     $s3->setEndpoint(AWS_S3_ENDPOINT);
                     $imageName = "pi_" . $userId . ".png";
                     $s3Name = "profile.images/" . $userId . "/" . $imageName;
                     $res = $s3->putObjectFile($tmpImgPath, AWS_S3_BUCKET, $s3Name, S3::ACL_PUBLIC_READ);
                     if ($res) {
                         $profileImageUrl = 'http://' . AWS_S3_BUCKET . '.s3.amazonaws.com/' . $s3Name;
                         try {
                             unlink($tmpImgPath);
                         } catch (Exception $exc) {
                             error_log($exc->getTraceAsString());
                         }
                     } else {
                         $result->result = json_encode($res);
                     }
                 } catch (Exception $exc) {
                     $result->result = $exc->getTraceAsString();
                 }
             } else {
                 $profileImageUrl = USER_DEFAULT_IMAGE_URL;
             }
             if (!empty($profileImageUrl)) {
                 $user->setProfilePicture($profileImageUrl);
                 try {
                     $user->updateToDatabase(DBUtils::getConnection());
                     $result->success = true;
                     $result->result = null;
                 } catch (Exception $exc) {
                     $result->result = $exc->getTraceAsString();
                 }
             }
         } else {
             $result->result = "user not found";
         }
     } else {
         $result->result = "user id empty";
     }
     return $result;
 }
Ejemplo n.º 4
0
 /**
  * component constructor - set up local vars based on settings array in controller
  */
 public function __construct(ComponentCollection $collection, $settings = array())
 {
     parent::__construct($collection, $settings);
     // setup the instance vars
     if (!empty($settings)) {
         foreach ($settings as $var => $val) {
             $this->{$var} = $val;
         }
     } else {
         if ($config = Configure::read('CakeS3')) {
             foreach ($config as $var => $val) {
                 $this->{$var} = $val;
             }
         }
     }
     if (empty($this->s3Key) || empty($this->s3Secret)) {
         throw new Exception('S3 Keys not set up. Unable to connect');
     }
     S3::setAuth($this->s3Key, $this->s3Secret);
     S3::setEndpoint($this->endpoint);
 }
 function _serve_file($link_id, $storage, $container, $endpoint, $url, $filename, $type, $file_id, $inline = false)
 {
     //echo $link_id.", <br />".$storage.", <br />".$container.", <br />".$endpoint.", <br />".$url.", <br />".$filename.",  <br />".$type.", <br />".$file_id.", <br />".$inline;
     if ($this->EE->session->userdata('group_id') != 1) {
         $this->EE->db->query("INSERT INTO exp_protected_links_stats (link_id, file_id, member_id, ip, dl_date) VALUES ('{$link_id}', '{$file_id}', '" . $this->EE->session->userdata('member_id') . "', '" . $this->EE->input->ip_address . "', '" . $this->EE->localize->now . "')");
         $this->EE->db->query("UPDATE exp_protected_links_files SET dl_count=dl_count+1, dl_date='" . $this->EE->localize->now . "' WHERE file_id={$file_id}");
         $this->EE->db->query("UPDATE exp_protected_links_links SET dl_count=dl_count+1 WHERE link_id={$link_id}");
     }
     $filename = strstr($_SERVER['HTTP_USER_AGENT'], 'MSIE') ? preg_replace('/\\./', '%2e', $filename, substr_count($filename, '.') - 1) : $filename;
     switch ($storage) {
         case 'local':
             $url = urldecode($url);
             if (!file_exists($url)) {
                 return $this->EE->output->show_user_error('general', array($this->EE->lang->line('file_not_exist')));
             }
             header("Pragma: public");
             header("Expires: 0");
             header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
             header("Cache-Control: public", FALSE);
             header("Content-Description: File Transfer");
             header("Content-Type: " . $type);
             header("Accept-Ranges: bytes");
             if ($inline == true) {
                 header("Content-Disposition: inline; filename=\"" . $filename . "\";");
             } else {
                 header("Content-Disposition: attachment; filename=\"" . $filename . "\";");
             }
             header("Content-Transfer-Encoding: binary");
             header('Content-Length: ' . filesize($url));
             @ob_clean();
             @flush();
             @readfile($url);
             break;
         case 'url':
             $use_curl = true;
             if (!function_exists('curl_init')) {
                 $use_curl = false;
                 //return $this->EE->output->show_user_error('general', array($this->EE->lang->line('curl_required')));
             } else {
                 $curl = curl_init();
                 curl_setopt($curl, CURLOPT_URL, str_replace('&#47;', '/', $url));
                 curl_setopt($curl, CURLOPT_HEADER, true);
                 curl_setopt($curl, CURLOPT_NOBODY, true);
                 curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
                 if (ini_get('open_basedir') == '' && ini_get('safe_mode' == 'Off')) {
                     curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
                 }
                 curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
                 curl_setopt($curl, CURLOPT_SSLVERSION, 3);
                 curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
                 curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 2);
                 curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.5) Gecko/20041107 Firefox/1.0');
                 $out = curl_exec($curl);
                 $error = curl_error($curl);
                 if ($error != '') {
                     return $this->EE->output->show_user_error('general', array($this->EE->lang->line('curl_error') . $error));
                 }
                 $size = curl_getinfo($curl, CURLINFO_CONTENT_LENGTH_DOWNLOAD);
                 curl_close($curl);
                 $memory = memory_get_usage(true);
                 if ($size > $memory * 3 / 4) {
                     $use_curl = false;
                 }
             }
             header("Pragma: public");
             header("Expires: 0");
             header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
             header("Cache-Control: public", FALSE);
             header("Content-Description: File Transfer");
             header("Content-Type: " . $type);
             header("Accept-Ranges: bytes");
             if ($inline == true) {
                 header("Content-Disposition: inline; filename=\"" . $filename . "\";");
             } else {
                 header("Content-Disposition: attachment; filename=\"" . $filename . "\";");
             }
             header("Content-Transfer-Encoding: binary");
             if ($use_curl == true) {
                 $curl = curl_init();
                 curl_setopt($curl, CURLOPT_URL, str_replace('&#47;', '/', $url));
                 curl_setopt($curl, CURLOPT_HEADER, false);
                 curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
                 if (ini_get('open_basedir') == '' && ini_get('safe_mode' == 'Off')) {
                     curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
                 }
                 curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
                 curl_setopt($curl, CURLOPT_SSLVERSION, 3);
                 curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
                 curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 2);
                 curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.5) Gecko/20041107 Firefox/1.0');
                 $out = curl_exec($curl);
                 curl_close($curl);
                 echo $out;
             } else {
                 $fp = fopen(str_replace('&#47;', '/', $url), "rb");
                 while (!feof($fp)) {
                     echo fread($fp, 4096);
                     flush();
                 }
                 fclose($fp);
             }
             break;
         case 's3':
         case 'S3':
             require_once PATH_THIRD . "protected_links/storage_api/amazon/S3.php";
             header("Pragma: public");
             header("Expires: 0");
             header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
             header("Cache-Control: public", FALSE);
             header("Content-Description: File Transfer");
             header("Content-Type: " . $type);
             header("Accept-Ranges: bytes");
             if ($inline == true) {
                 header("Content-Disposition: inline; filename=\"" . $filename . "\";");
             } else {
                 header("Content-Disposition: attachment; filename=\"" . $filename . "\";");
             }
             header("Content-Transfer-Encoding: binary");
             $s3 = new S3($this->settings['s3_key_id'], $this->settings['s3_key_value']);
             if ($endpoint != '') {
                 $s3->setEndpoint($endpoint);
             }
             $fp = fopen("php://output", "wb");
             $s3->getObject("{$container}", $url, $fp);
             fclose($fp);
             break;
         case 'rackspace':
             require_once PATH_THIRD . "protected_links/storage_api/rackspace/cloudfiles.php";
             header("Pragma: public");
             header("Expires: 0");
             header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
             header("Cache-Control: public", FALSE);
             header("Content-Description: File Transfer");
             header("Content-Type: " . $type);
             header("Accept-Ranges: bytes");
             if ($inline == true) {
                 header("Content-Disposition: inline; filename=\"" . $filename . "\";");
             } else {
                 header("Content-Disposition: attachment; filename=\"" . $filename . "\";");
             }
             header("Content-Transfer-Encoding: binary");
             $auth = new CF_Authentication($this->settings['rackspace_api_login'], $this->settings['rackspace_api_password']);
             $auth->authenticate();
             $conn = new CF_Connection($auth);
             $container = $conn->get_container("{$container}");
             $fp = fopen("php://output", "wb");
             $url->stream($fp);
             fclose($fp);
             break;
     }
     exit;
 }