コード例 #1
0
 protected function init($panel_name, $method = 'L', $id = 0)
 {
     $panel = new Panel();
     $this->id = $id;
     $this->name = $panel_name;
     $this->app_config = StationConfig::app();
     $this->user_scope = $panel->user_scope($this->name, $method, $this->subpanel_parent);
     // temp handling if someone is trying to access something they shouldn't
     if (!$this->user_scope) {
         dd('You do not have access to this');
     }
     // TODO: change handling. log it??
     $this->panel_config = $this->user_scope['config'];
     $this->single_item_name = $this->panel_config['panel_options']['single_item_name'];
     $this->user_data = Session::get('user_data');
     $this->assets = isset($this->assets) ? $this->assets : [];
     $this->base_uri = StationConfig::app('root_uri_segment') . '/';
     $this->foreign_data = $panel->foreign_data_for($this->user_scope, $method);
     $this->foreign_panels = $panel->foreign_panels_for($this->user_scope, $method);
     $this->array_img_size = $panel->img_sizes_for($this->user_scope, $this->app_config);
     $this->curr_panel = $this->subpanel_parent ?: $this->name;
     $this->panel_config['relative_uri'] = $this->base_uri . 'panel/' . $this->name;
     $this->panel_config['relative_uri'] = URL::to($this->panel_config['relative_uri']);
     View::share('base_uri', $this->base_uri);
     View::share('base_img_uri', 'http://' . $this->app_config['media_options']['AWS']['bucket'] . '.s3.amazonaws.com/');
     View::share('curr_panel', $this->curr_panel);
     View::share('curr_method', $method);
     View::share('single_item_name', $this->single_item_name);
     View::share('app_data', $this->app_config);
     View::share('panel_data', $this->panel_config);
     View::share('panel_name', $this->name);
     View::share('foreign_data', $this->foreign_data);
     View::share('foreign_panels', $this->foreign_panels);
     View::share('user_data', $this->user_data);
     View::share('base_uri', $this->base_uri);
     View::share('img_size_data', $this->array_img_size);
     View::share('sidenav_data', $panel->user_panel_access_list());
 }
コード例 #2
0
 public function upload()
 {
     if (!Input::hasFile('uploaded_file')) {
         echo json_encode(['success' => FALSE, 'reason' => 'no file uploaded']);
     }
     $file = Input::file('uploaded_file');
     $original_file_name = $file->getClientOriginalName();
     $size = $file->getSize();
     $mime = $file->getMimeType();
     $this->mime = $mime;
     $extension = $file->getClientOriginalExtension();
     $path = pathinfo($original_file_name);
     $orig_name_wo_ext = $path['filename'];
     $new_file_name = $orig_name_wo_ext . '_' . date('Y-m-d-H-i-s') . '.' . $extension;
     $panel = new Panel();
     $panel_name = Input::get('panel_name');
     $parent_panel_name = Input::get('parent_panel_name');
     $element_name = Input::get('upload_element_name');
     $method = Input::get('method');
     $user_scope = $panel->user_scope($panel_name, $method, $parent_panel_name);
     $element = $user_scope['config']['elements'][$element_name];
     $app_config = StationConfig::app();
     $success = FALSE;
     $message = '';
     $field_is_uploadable = $element['type'] == 'image' || isset($element['embeddable']) && $element['embeddable'];
     Input::file('uploaded_file')->move($this->tmp_dir, $new_file_name);
     if ($field_is_uploadable) {
         $allowed_image_extensions = ['png', 'gif', 'jpg', 'jpeg', 'PNG', 'GIF', 'JPG', 'JPEG'];
         $bad_image = strpos($mime, 'image') === FALSE || !in_array($extension, $allowed_image_extensions);
         if ($bad_image) {
             return Response::json(['success' => FALSE, 'reason' => 'not a proper image']);
         }
         $allow_upsize = isset($element['allow_upsize']) && $element['allow_upsize'];
         $all_sizes = $panel->img_sizes_for($user_scope, $app_config);
         $sizes_needed = isset($all_sizes[$element_name]) ? $all_sizes[$element_name] : $all_sizes['standard'];
         $manipulations = $this->manipulate_sizes_and_send_each($new_file_name, $sizes_needed, $app_config, $allow_upsize);
         $success = $manipulations['n_sent'] > 0;
         $message = $manipulations['n_sent'] . ' manipulations made and sent to S3';
     } else {
         // file?
         // TODO: deal with non-images here. check for allowed types. then just move and send to S3.
     }
     $response = ['success' => $success, 'message' => $message, 'insert_id' => isset($medium->id) ? $medium->id : FALSE, 'file_uri_stub' => 'http://' . $app_config['media_options']['AWS']['bucket'] . '.s3.amazonaws.com/', 'file_uri' => isset($manipulations['file_name']) ? 'http://' . $app_config['media_options']['AWS']['bucket'] . '.s3.amazonaws.com/' . 'station_thumbs_lg/' . $manipulations['file_name'] : FALSE, 'file_name' => isset($manipulations['file_name']) ? $manipulations['file_name'] : FALSE];
     //return Response::json($response); // was erroring with Resource interpreted as Document but transferred with MIME type application/json: "/station/file/upload".
     echo json_encode($response);
 }