Esempio n. 1
0
 /**
  * populate the user_data
  *
  * @param  type  $param
  * @return void
  */
 static function hydrate()
 {
     $user_id = Auth::user()->id;
     $user = User::find($user_id);
     $group_names = $user->groups->lists('name');
     $primary_group = current($group_names);
     $app_groups = StationConfig::app('user_groups');
     $starting_panel = $app_groups[$primary_group]['starting_panel'];
     $starting_panel_uri = Panel::config_to_uri($starting_panel);
     Laravel_Session::put('user_data', array('id' => $user_id, 'groups' => $group_names, 'primary_group' => $primary_group, 'starting_panel' => $starting_panel, 'starting_panel_uri' => $starting_panel_uri, 'name' => $user['first_name'] . ' ' . $user['last_name'], 'email' => $user['email'], 'username' => $user['username'], 'gravatar_hash' => md5($user['email'])));
 }
 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());
 }
 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);
 }
Esempio n. 4
0
 private function model_code($is_new = FALSE, $modelName, $tableName, $panel_data)
 {
     $panel = new Panel();
     $code = "";
     $code .= $is_new ? "<?php namespace App\\Models; \n\n" . "class {$modelName} extends \\Eloquent {\n\t" : "";
     $code .= $this->gen_begin . "\n\n\t" . "protected \$table = '{$tableName}';\n\tprotected \$guarded = array('id');\n\n";
     $code .= !$panel_data['panel_options']['has_timestamps'] ? "\tpublic \$timestamps = false;\n\n" : "\n";
     if (isset($panel_data['elements'])) {
         foreach ($panel_data['elements'] as $elem_name => $elem_data) {
             if (isset($elem_data['data']['relation']) && in_array($elem_data['data']['relation'], $this->valid_relationships) && !isset($elem_data['data']['no_model'])) {
                 $is_subpanel = $elem_data['type'] == 'subpanel';
                 $order_by = '';
                 if ($is_subpanel) {
                     // check to see if we can apply order_by clause for foreign table relationship.
                     $subpanel_data = StationConfig::panel($elem_name, TRUE);
                     $order_by_column = isset($subpanel_data['panel_options']['default_order_by']) ? $subpanel_data['panel_options']['default_order_by'] : false;
                     $order_by = $order_by_column ? $this->order_by_clause($order_by_column) : "";
                 } else {
                     // TODO: add order_by for non sub panels. We will need this soon.
                 }
                 $pivot_table_name = $this->pivot_table_name(array('tableOne' => $tableName, 'tableTwo' => $elem_data['data']['table']), TRUE);
                 $pivot_table = strpos($elem_data['data']['relation'], 'ToMany') !== FALSE ? $pivot_table_name : '';
                 $pivot_table = $pivot_table == "" && $elem_data['data']['relation'] == 'belongsTo' ? ", '" . $elem_name . "'" : $pivot_table;
                 $pivot_table = $pivot_table == "" && $elem_data['data']['relation'] == 'hasMany' && isset($elem_data['data']['key']) ? ", '" . $elem_data['data']['key'] . "'" : $pivot_table;
                 $code .= "\tpublic function " . $elem_data['data']['table'] . "()\n\t" . "{\n\t\t" . "return \$this->" . $elem_data['data']['relation'] . "('" . $panel->model_name_for($elem_data['data']['table']) . "'" . $pivot_table . ")" . $order_by . ";\n\t" . "}\n";
             }
         }
     }
     $code .= "\t" . $this->gen_end;
     $code .= $is_new ? "\n\n\t// Feel free to add any new code after this line\n}" : "";
     return $code;
 }