示例#1
0
 public static function uploadEventImage1($avatar, $user_id = 0)
 {
     try {
         $added_date = time();
         if (is_array($user_info = Model_Users::getUser($user_id))) {
             $added_date = $user_info['date_added'];
         }
         $date_added = WM_Date::format($added_date, 'yy-mm-dd H:i:s');
         $s3 = new JO_Api_Amazon(JO_Registry::get('awsAccessKey'), JO_Registry::get('awsSecretKey'));
         $s3->putBucket(JO_Registry::get('bucklet'), JO_Api_Amazon::ACL_PUBLIC_READ);
         if ($s3->getBucketLogging(JO_Registry::get('bucklet'))) {
             if (($imageinfo = @getimagesize($avatar)) !== false) {
                 $ext = strtolower(strrchr($avatar, "."));
                 $name = $user_id . $ext;
                 $image_path = 'events/' . WM_Date::format($date_added, 'yy/mm/');
                 if (!file_exists(BASE_PATH . '/uploads/cache_events/' . $image_path) || !is_dir(BASE_PATH . '/uploads/cache_events/' . $image_path)) {
                     @mkdir(BASE_PATH . '/uploads/cache_events/' . $image_path, 0777, true);
                 }
                 @copy($avatar, BASE_PATH . '/uploads/cache_events/' . $image_path . $name);
                 if (self::uploatToServer(BASE_PATH . '/uploads/cache_events/' . $image_path . $name, $image_path . $name)) {
                     $model_images = new Helper_Images();
                     $temp_width = 0;
                     $temp_height = 0;
                     $sizes = self::userThumbSizes();
                     if ($sizes) {
                         foreach ($sizes as $size => $prefix) {
                             $sizes = explode('x', $size);
                             $width = (int) isset($sizes[0]) ? $sizes[0] : 0;
                             $height = (int) isset($sizes[1]) ? $sizes[1] : 0;
                             $name_pref = basename($name, $ext) . $prefix . $ext;
                             if ($width && $height) {
                                 $thumb_a = $model_images->resize('/cache_events/' . $image_path . $name, $width, $height, true);
                             } else {
                                 if ($width && !$height) {
                                     $thumb_a = $model_images->resizeWidth('/cache_events/' . $image_path . $name, $width);
                                 } else {
                                     if ($height && !$width) {
                                         $thumb_a = $model_images->resizeHeight('/cache_events/' . $image_path . $name, $height);
                                     }
                                 }
                             }
                             if ($prefix == '_B') {
                                 $temp_width = $model_images->getSizes('width');
                                 $temp_height = $model_images->getSizes('height');
                             }
                             $thumb_a1 = explode('/uploads/', $thumb_a);
                             if ($thumb_a1 && isset($thumb_a1[1])) {
                                 if (!self::uploatToServer(BASE_PATH . '/uploads/' . $thumb_a1[1], $image_path . $name_pref)) {
                                 }
                             }
                         }
                     }
                     //$model_images->deleteImages('/cache_events/' . $image_path . $name);
                     if ($temp_width) {
                         return array('store' => 'amazons3', 'image' => $image_path . $name, 'width' => $temp_width, 'height' => $temp_height);
                     } else {
                         return false;
                     }
                 } else {
                     return false;
                 }
             } else {
                 return false;
             }
         }
     } catch (JO_Exception $e) {
         return false;
     }
     return false;
 }
示例#2
0
文件: Users.php 项目: noikiy/amatteur
 public static function deleteFromServer($image)
 {
     if (JO_Registry::get('enable_amazon')) {
         $s3 = new JO_Api_Amazon(JO_Registry::get('awsAccessKey'), JO_Registry::get('awsSecretKey'));
         $s3->putBucket(JO_Registry::get('bucklet'), JO_Api_Amazon::ACL_PUBLIC_READ);
         if ($s3->getBucketLogging(JO_Registry::get('bucklet'))) {
             $s3->deleteObject(JO_Registry::get('bucklet'), $image);
         }
     }
 }
 public function indexAction()
 {
     if (!WM_Users::allow('edit', 'modules')) {
         JO_Session::set('error_permision', $this->translate('You do not have permission to this action'));
         $this->redirect($this->getRequest()->getBaseUrl() . $this->getRequest()->getModule() . '/modules_storage/');
     }
     $request = $this->getRequest();
     if (JO_Session::get('successfu_edite')) {
         $this->view->successfu_edite = true;
         JO_Session::clear('successfu_edite');
     }
     if ($request->isPost()) {
         //validate app id
         $this->view->error = false;
         try {
             $s3 = new JO_Api_Amazon($request->getPost('amazons3[amazons3_access_key]'), $request->getPost('amazons3[amazons3_secret_key]'));
             //$s3->putBucket($request->getPost('amazons3[amazons3_bucklet]'), JO_Api_Amazon::ACL_PUBLIC_READ);
             $loged = $s3->getBucketLogging($request->getPost('amazons3[amazons3_bucklet]'));
             if ($loged) {
                 $upload = $s3->putObjectString('test', $request->getPost('amazons3[amazons3_bucklet]'), 'test_upload.txt', JO_Api_Amazon::ACL_PUBLIC_READ);
                 if (!$upload) {
                     $this->view->error = sprintf($this->translate('Unable to upload to Bucklet "%s"'), $request->getPost('amazons3[amazons3_bucklet]'));
                     $loged = false;
                 } else {
                     $is_file = @file_get_contents(trim($request->getPost('amazons3[amazons3_bucklet_location]'), '/') . '/test_upload.txt');
                     if ($is_file != 'test') {
                         $this->view->error = sprintf($this->translate('Unable to read test file "%s"'), trim($request->getPost('amazons3[amazons3_bucklet_location]'), '/') . '/test_upload.txt');
                         $loged = false;
                     }
                 }
             } else {
                 $this->view->error = sprintf($this->translate('Bucklet "%s" not found'), $request->getPost('amazons3[amazons3_bucklet]'));
                 $loged = false;
             }
         } catch (JO_Exception $e) {
             $this->view->error = $e->getMessage();
             $loged = false;
         }
         if ($loged) {
             Model_Settings::updateAll(array('amazons3' => $request->getPost('amazons3')));
             JO_Session::set('successfu_edite', true);
             $this->redirect($this->getRequest()->getBaseUrl() . $this->getRequest()->getModule() . '/modules_storage_amazons3/');
         } else {
             if (!$this->view->error) {
                 $this->view->error = $this->translate('Invalid App configuration');
             }
         }
     }
     $this->view->modules_url = $this->getRequest()->getModule() . '/modules';
     $this->view->modules_storage_url = $this->getRequest()->getModule() . '/modules_storage';
     $store_config = Model_Settings::getSettingsPairs(array('filter_group' => 'amazons3'));
     if (!isset($store_config['amazons3_access_key'])) {
         $store_config['amazons3_access_key'] = '';
     }
     if (!isset($store_config['amazons3_secret_key'])) {
         $store_config['amazons3_secret_key'] = '';
     }
     if (!isset($store_config['amazons3_bucklet'])) {
         $store_config['amazons3_bucklet'] = '';
     }
     if (!isset($store_config['amazons3_bucklet_location'])) {
         $store_config['amazons3_bucklet_location'] = '';
     }
     foreach ($store_config as $key => $data) {
         if ($request->issetPost('amazons3[' . $key . ']')) {
             $this->view->{$key} = $request->getPost('amazons3[' . $key . ']');
         } else {
             $this->view->{$key} = $data;
         }
     }
 }