public function action_edit($id)
 {
     $post = \Blog\Models\Post::find($id);
     if ($post === null) {
         return Event::first('404');
     }
     if (Str::lower(Request::method()) == "post") {
         $validator = Validator::make(Input::all(), self::$rules);
         if ($validator->passes()) {
             $post->title = Input::get('title');
             if (Input::get('slug')) {
                 $post->slug = Str::slug(Input::get('slug'));
             } else {
                 $post->slug = Str::slug(Input::get('title'));
             }
             $post->intro = Input::get('intro');
             $post->content = Input::get('content');
             $post->author_id = Input::get('author_id');
             $post->category_id = Input::get('category_id');
             $post->publicated_at = Input::get('publicated_at_date') . ' ' . Input::get('publicated_at_time');
             $post->save();
             return Redirect::to_action('blog::admin.post@list');
         } else {
             return Redirect::back()->with_errors($validator)->with_input();
         }
     } else {
         $categories = array();
         $originalCategories = \Blog\Models\Category::all();
         foreach ($originalCategories as $cat) {
             $categories[$cat->id] = $cat->name;
         }
         return View::make('blog::admin.post.new')->with_post($post)->with('editMode', true)->with('categories', $categories);
     }
 }
Example #2
0
 public static function update($view, $id)
 {
     // Get the Account
     $response = API::get(array('account', $id));
     // Handle response codes other than 200 OK
     if (!$response->success) {
         return Event::first($response->code);
     }
     // The response body is the Account
     $account = $response->get();
     // Get Roles and put it in a nice array for the dropdown
     $roles = array('' => '') + model_array_pluck(API::get(array('role', 'all'))->get('results'), function ($role) {
         return $role->lang->name;
     }, 'id');
     // Get the Roles that belong to a User and put it in a nice array for the dropdown
     $active_roles = array();
     if (isset($account->roles)) {
         $active_roles = model_array_pluck($account->roles, 'id', '');
     }
     // Get Languages and put it in a nice array for the dropdown
     $languages = model_array_pluck(API::get(array('language', 'all'))->get('results'), function ($language) {
         return $language->name;
     }, 'id');
     $view->text('name', __('admin::account.update.form.name'), Input::old('name', $account->name));
     $view->text('email', __('admin::account.update.form.email'), Input::old('email', $account->email));
     $view->password('password', __('admin::account.update.form.password'));
     $view->multiple('roles[]', __('admin::account.update.form.roles'), $roles, Input::old('roles', $active_roles));
     $view->dropdown('language_id', __('admin::account.update.form.language'), $languages, Input::old('language_id', $account->language->id));
     $view->actions(function ($view) {
         $view->submit(__('admin::account.update.buttons.edit'), 'primary');
     });
 }
 public function action_resolve($post_id)
 {
     if ($post = Post::where_id($post_id)->first(array('id', 'slug'))) {
         return Redirect::to_action('blog::home@show', array($post->id, $post->slug));
     } else {
         return Event::first('404');
     }
 }
 public function action_index()
 {
     if (Auth::guest()) {
         return Event::first('404');
     }
     $topics = Forumtopic::getPosted();
     return View::make('forums::posted.index', array('topics' => $topics));
 }
 public function action_index($slug, $id)
 {
     $topics = Forumtopic::getHomePageList($id);
     if (!$topics) {
         return Event::first('404');
     }
     $pagination = $topics->links();
     $topics = $topics->results;
     $category = Forumcategory::where_id($id)->first(array('id', 'slug', 'title'));
     return View::make('forums::category.index', array('category' => $category, 'topics' => $topics, 'pagination' => $pagination));
 }
Example #6
0
 /**
  * Return an error page, optionally with data/message
  *
  * @param  int           HTTP status code
  * @param  array|string  Data or message
  */
 public static function error($status = 500, $data = array())
 {
     is_string($data) && ($data = array('message' => $data));
     $data['error'] = true;
     if (Request::ajax() || Request::accepts('application/json')) {
         return parent::json($data, $status);
     }
     if ($status == 404) {
         return parent::error($status, $data);
     }
     return \Event::first('response.error', [$status, $data]);
 }
Example #7
0
 public function get_profile($id, $action = 'essentials')
 {
     $user = u::find($id);
     if ($user === NULL) {
         return \Event::first('404');
     } else {
         if (u::current()->id == $id || u::current()->isAdmin()) {
             return \View::make('fluxbb::user.profile.' . $action)->with('user', $user);
         } else {
             return \View::make('fluxbb::user.profile.view')->with('user', $user);
         }
     }
 }
Example #8
0
 /**
  * Handle an exception and display the exception report.
  *
  * @param  Exception  $exception
  * @return void
  */
 public static function exception($exception)
 {
     static::log($exception);
     // If detailed errors are enabled, we'll just format the exception into
     // a simple error message and display it on the screen. We don't use a
     // View in case the problem is in the View class.
     if (Config::get('error.detail')) {
         echo "<html><h2>Unhandled Exception</h2>\n\t\t\t\t  <h3>Message:</h3>\n\t\t\t\t  <pre>" . $exception->getMessage() . "</pre>\n\t\t\t\t  <h3>Location:</h3>\n\t\t\t\t  <pre>" . $exception->getFile() . " on line " . $exception->getLine() . "</pre>\n\t\t\t\t  <h3>Stack Trace:</h3>\n\t\t\t\t  <pre>" . $exception->getTraceAsString() . "</pre></html>";
     } else {
         $response = Event::first('500');
         return Response::prepare($response)->send();
     }
     exit(1);
 }
Example #9
0
 public function get_post($pid)
 {
     // If a post ID is specified we determine topic ID and page number so we can show the correct message
     $post = Post::where('id', '=', $pid)->select(array('topic_id', 'posted'))->first();
     if ($post === NULL) {
         return \Event::first('404');
     }
     $tid = $post->topic_id;
     $posted = $post->posted;
     // Determine on what page the post is located (depending on $forum_user['disp_posts'])
     $num_posts = Post::where('topic_id', '=', $tid)->where('posted', '<', $posted)->count('id') + 1;
     $disp_posts = $this->user()->dispPosts();
     $p = ceil($num_posts / $disp_posts);
     // FIXME: second parameter for $page number
     return $this->get_topic($tid);
 }
Example #10
0
 public function post_add_pdf()
 {
     $rules = Config::get('rules.add_pdf');
     $validation = Validator::make(Input::all(), $rules);
     if ($validation->passes()) {
         $pdf = Input::file('pdf');
         if (is_file($pdf['tmp_name']) and $pdf['error'] === UPLOAD_ERR_OK) {
             if (Pdfs::add(Input::all())) {
                 return Redirect::to('add_pdf')->with('success', TRUE);
             } else {
                 return Event::first('500', 'The PDF could not be added due to a system error. We apologize for any inconvenience.');
             }
         }
         Session::flash('failed', TRUE);
     }
     return Redirect::to('add_pdf')->with_input()->with_errors($validation);
 }
Example #11
0
 public function delete($view, $id)
 {
     // Get the Account
     $response = API::get(array('module', $id));
     // Handle response codes other than 200 OK
     if (!$response->success) {
         return Event::first($response->code);
     }
     // The response body is the Account
     $module = $response->get();
     $view->page_header(function ($view) {
         $view->float_right(function ($view) {
             $view->search();
         });
         $view->title(__('admin::module.delete.title'));
     });
     $view->well(function ($view) use($module) {
         $view->raw(__('admin::module.delete.message', array('name' => $module->name, 'email' => $module->email)));
     });
     $view->form(Module::form('module.delete', $id), 'DELETE', prefix('admin') . 'module/delete/' . $id);
 }
Example #12
0
 public function post_forgot_password()
 {
     $rules = Config::get('rules.forgot_password');
     $validation = Validator::make(Input::get(), $rules);
     if ($validation->passes()) {
         $new_password = User::new_password(Input::get('email'));
         if (!$new_password) {
             return Event::first('500', 'Your password could not be changed due to a system error. We apologize for any inconvenience.');
         }
         //$message = "Your password to log into <whatever site> has been temporarily changed to '$new_password'. Please log in using that password and this email address. Then you may change your password to something more familiar.";
         //mail(Input::get('email'), 'Your temporary password.', $message, 'From: admin@example.com');
         Session::flash('success', TRUE);
     }
     return Redirect::to('forgot_password')->with_input()->with_errors($validation);
 }
 public function test_delegate_setter_gh_98()
 {
     Venue::$use_custom_set_state_setter = true;
     $event = Event::first();
     $event->state = 'MEXICO';
     $this->assert_equals('MEXICO#', $event->venue->state);
     Venue::$use_custom_set_state_setter = false;
 }
 public function action_postedit($topic_slug, $topic_id, $message_id)
 {
     $topic = Forumtopic::find($topic_id);
     if (is_null($topic)) {
         return Event::first('404');
     }
     $category = $topic->category;
     $message = Forummessage::find($message_id);
     if (is_null($message)) {
         return Event::first('404');
     }
     if ($message->user->id != Auth::user()->id && !Auth::user()->is('Forumer')) {
         return Event::first('404');
     }
     $rules = array('content' => 'required|min:30');
     $content = trim(Input::get('content'));
     $toValidate = compact('content');
     $editTitle = false;
     if ($topic->messages[0]->id == $message->id && trim(Input::get('title')) != $topic->title) {
         $editTitle = true;
         $rules['title'] = 'required|min:2';
         $title = trim(Input::get('title'));
         $toValidate['title'] = $title;
     }
     $validator = Validator::make($toValidate, $rules);
     if ($validator->fails()) {
         return Redirect::back()->with_errors($validator)->with_input();
     }
     if ($editTitle) {
         $topic->title = $toValidate['title'];
         $topic->slug = Str::slug($toValidate['title']);
         $originalSlug = $topic->slug;
         $incSlug = 0;
         do {
             try {
                 $topic->save();
                 $incSlug = 0;
             } catch (Exception $e) {
                 if ($e->getCode() == 23000) {
                     $incSlug++;
                 }
                 $topic->slug = $originalSlug . '-' . $incSlug;
             }
         } while ($incSlug != 0);
     }
     $message->content = BBCodeParser::parse($content);
     $message->content_bbcode = $content;
     $message->save();
     $topic->touch();
     $topic_id = $topic->id;
     $topic_slug = $topic->slug;
     $url = URL::to_action('forums::topic@index', compact('topic_slug', 'topic_id')) . '?page=last#message' . $message->id;
     return Redirect::to($url);
 }
Example #15
0
 /**
  * Load all of the language lines from a language file.
  *
  * @param  string  $bundle
  * @param  string  $language
  * @param  string  $file
  * @return bool
  */
 public static function load($bundle, $language, $file)
 {
     if (isset(static::$lines[$bundle][$language][$file])) {
         return true;
     }
     // We use a "loader" event to delegate the loading of the language
     // array, which allows the develop to organize the language line
     // arrays for their application however they wish.
     $lines = Event::first(static::loader, func_get_args());
     static::$lines[$bundle][$language][$file] = $lines;
     return count($lines) > 0;
 }
 public function testDelegateSetterGh98()
 {
     Venue::$useCustomSetStateSetter = true;
     $event = Event::first();
     $event->state = 'MEXICO';
     $this->assertEquals('MEXICO#', $event->venue->state);
     Venue::$useCustomSetStateSetter = false;
 }
Example #17
0
 static function format($str, array $info, $formatter)
 {
     if (is_array($str)) {
         foreach ($str as &$s) {
             $s = static::format($s, $info, $formatter);
         }
         return $str;
     } elseif (isset($str)) {
         if (is_callable($formatter)) {
             $str = call_user_func($formatter, $str, $info);
         } elseif ($formatter === 'raw') {
             $str = (string) $str;
         } elseif ($formatter === 'php') {
             $vars = array();
             extract($info, EXTR_SKIP);
             ob_start();
             eval("?>{$str}");
             $str = $vars + array('content' => ob_get_clean());
         } elseif (is_string($formatter)) {
             $type = trim(strtok($formatter, ':'));
             $class = trim(strtok('->'));
             $method = trim(strtok(null) ?: 'format', '> ');
             switch ($type) {
                 case 'class':
                     break;
                 case 'ioc':
                     $class = IoC::resolve($class, array($str, $info));
                     break;
                 case 'event':
                     $class = Event::first($class, array($str, $info));
                     break;
                 default:
                     throw new Exception("Text Publisher: invalid 'formatter' string value.");
             }
             if ($type === 'class' or is_object($class)) {
                 $str = call_user_func(array($class, $method), $str, $info);
             } else {
                 $str = $class;
             }
         } else {
             throw new Exception("Text Publisher: invalid 'formatter' value type.");
         }
         return ($str !== null and $str !== false) ? $str : null;
     }
 }
 public function test_delegate_setter()
 {
     $event = Event::first();
     $event->state = 'MEXICO';
     $this->assert_equals('MEXICO', $event->venue->state);
 }
Example #19
0
 /**
  * Load all of the configuration items from a configuration file.
  *
  * @param  string  $bundle
  * @param  string  $file
  * @return bool
  */
 public static function load($bundle, $file)
 {
     if (isset(static::$items[$bundle][$file])) {
         return true;
     }
     // We allow a "config.loader" event to be registered which is responsible for
     // returning an array representing the configuration for the bundle and file
     // requested. This allows many types of config "drivers".
     $config = Event::first(static::loader, func_get_args());
     // If configuration items were actually found for the bundle and file we
     // will add them to the configuration array and return true, otherwise
     // we will return false indicating the file was not found.
     if (count($config) > 0) {
         static::$items[$bundle][$file] = $config;
     }
     return isset(static::$items[$bundle][$file]);
 }
Example #20
0
});
Event::listen('500', function ($message = '') {
    return Response::error('500', array('message' => $message));
});
//--------------------------------------------------------------------------
// Route Filters
//--------------------------------------------------------------------------
Route::filter('before', function () {
});
Route::filter('after', function ($response) {
});
Route::filter('csrf', function () {
    if (Request::forged()) {
        return Response::error('500');
    }
});
Route::filter('auth', function () {
    if (Auth::guest()) {
        return Event::first('403', 'Logged in users only.');
    }
});
Route::filter('admin', function () {
    if (Auth::user()->type !== 'admin') {
        return Event::first('403', 'Admin access only.');
    }
});
Route::filter('member', function () {
    if (!Auth::guest()) {
        return Redirect::to('/');
    }
});
 public function testBelongsToWithAnInvalidOption()
 {
     Event::$belongsTo[0]['joins'] = 'venue';
     $event = Event::first()->venue;
     $this->assertSqlDoesntHas('INNER JOIN venues ON(events.venue_id = venues.id)', Event::table()->lastSql);
 }
Example #22
0
 public function delete_delete($slug = null)
 {
     // Delete the Page
     $response = API::delete(array('page', $slug));
     // Handle response codes other than 200 OK
     if (!$response->success) {
         return Event::first($response->code);
     }
     // Add success notification
     Notification::success('Successfully deleted page');
     return Redirect::to(prefix('admin') . 'pages');
 }
Example #23
0
 public function delete_delete($id = null)
 {
     // Delete the Account
     $response = API::delete(array('account', $id));
     // Handle response codes other than 200 OK
     if (!$response->success) {
         return Event::first($response->code);
     }
     // Add success notification
     Notification::success('Successfully deleted account');
     return Redirect::to(prefix('admin') . 'accounts');
 }
 public function test_belongs_to_with_an_invalid_option()
 {
     Event::$belongs_to[0]['joins'] = 'venue';
     $event = Event::first()->venue;
     $this->assert_false(strpos(Event::table()->last_sql, 'INNER JOIN `venues` ON(`events`.venue_id = `venues`.id)'));
 }
Example #25
0
 public function put_topic($fid)
 {
     $forum = Forum::with(array('perms'))->where('id', '=', $fid)->first();
     if ($forum === NULL) {
         return \Event::first('404');
     }
     // TODO: Flood protection
     $rules = array('req_subject' => 'required|max:70', 'req_message' => 'required');
     // TODO: More validation
     if (\Auth::isGuest()) {
         if (Config::enabled('p_force_guest_email') || \Input::get('email') != '') {
             $rules['req_email'] = 'required|email';
         }
         // TODO: banned email
     }
     $validation = $this->make_validator(Input::all(), $rules);
     if ($validation->fails()) {
         return \Redirect::to_action('fluxbb::posting@topic', array($fid))->with_input()->with_errors($validation);
     }
     $topic_data = array('poster' => User::current()->username, 'subject' => \Input::get('req_subject'), 'posted' => \Request::time(), 'last_post' => \Request::time(), 'last_poster' => User::current()->username, 'sticky' => \Input::get('stick_topic') ? '1' : '0', 'forum_id' => $fid);
     if (\Auth::isGuest()) {
         $topic_data['poster'] = $topic_data['last_poster'] = \Input::get('req_username');
     }
     // Create the topic
     $topic = Topic::create($topic_data);
     // To subscribe or not to subscribe
     $topic->subscribe(\Input::get('subscribe'));
     $post_data = array('poster' => User::current()->username, 'poster_id' => User::current()->id, 'poster_ip' => \Request::ip(), 'message' => \Input::get('req_message'), 'hide_smilies' => \Input::get('hide_smilies') ? '1' : '0', 'posted' => \Request::time(), 'topic_id' => $topic->id);
     if (\Auth::isGuest()) {
         $post_data['poster'] = \Input::get('req_username');
         $post_data['poster_email'] = Config::enabled('p_force_guest_email') ? \Input::get('req_email') : \Input::get('email');
     }
     // Create the post ("topic post")
     $post = Post::create($post_data);
     // Update the topic with last_post_id
     $topic->last_post_id = $topic->first_post_id = $post->id;
     $topic->save();
     // Update forum (maybe $forum->update_forum() ?)
     $forum->num_posts += 1;
     $forum->num_topics += 1;
     $forum->last_post = $topic->last_post;
     $forum->last_post_id = $topic->last_post_id;
     $forum->last_poster = $topic->last_poster;
     $forum->save();
     // TODO: update_search_index();
     // If the posting user is logged in, increment his/her post count
     $user = User::current();
     if (\Auth::isAuthed()) {
         $user->num_posts += 1;
         $user->last_post = \Request::time();
         $user->save();
         // TODO: Promote this user to a new group if enabled
     } else {
         $user->online()->update(array('last_post' => \Request::time()));
     }
     return \Redirect::to_action('fluxbb::topic', array($topic->id))->with('message', trans('fluxbb::topic.topic_added'));
 }
Example #26
0
 /**
  * @before _secure, _school
  */
 public function change()
 {
     $this->JSONView();
     $view = $this->getActionView();
     if (RequestMethods::post("action") == "reschedule") {
         $event = Event::first(array("id = ?" => RequestMethods::post("id")));
         $event->start = RequestMethods::post("start");
         $event->save();
         $view->set("success", "Event has been rescheduled");
     }
 }
 public function test_belongs_to_with_an_invalid_option()
 {
     Event::$belongs_to[0]['joins'] = 'venue';
     $event = Event::first()->venue;
     $this->assert_sql_doesnt_has('INNER JOIN venues ON(events.venue_id = venues.id)', Event::table()->last_sql);
 }
    if ($config['auto']) {
        Bundle::start($bundle);
    }
}
/*
|--------------------------------------------------------------------------
| Register The Catch-All Route
|--------------------------------------------------------------------------
|
| This route will catch all requests that do not hit another route in
| the application, and will raise the 404 error event so the error
| can be handled by the developer in their 404 event listener.
|
*/
Routing\Router::register('*', '(:all)', function () {
    return Event::first('404');
});
/*
|--------------------------------------------------------------------------
| Route The Incoming Request
|--------------------------------------------------------------------------
|
| Phew! We can finally route the request to the appropriate route and
| execute the route to get the response. This will give an instance
| of the Response object that we can send back to the browser
|
*/
$uri = URI::current();
Request::$route = Routing\Router::route(Request::method(), $uri);
$response = Request::$route->call();
/*
Example #29
-1
 /**
  * Handle an exception and display the exception report.
  *
  * @param  Exception  $exception
  * @param  bool       $trace
  * @return void
  */
 public static function exception($exception, $trace = true)
 {
     static::log($exception);
     ob_get_level() and ob_end_clean();
     $message = $exception->getMessage();
     // For Laravel view errors we want to show a prettier error:
     $file = $exception->getFile();
     if (str_contains($exception->getFile(), 'eval()') and str_contains($exception->getFile(), 'laravel' . DS . 'view.php')) {
         $message = 'Error rendering view: [' . View::$last['name'] . ']' . PHP_EOL . PHP_EOL . $message;
         $file = View::$last['path'];
     }
     // If detailed errors are enabled, we'll just format the exception into
     // a simple error message and display it on the screen. We don't use a
     // View in case the problem is in the View class.
     if (Config::get('error.detail')) {
         $response_body = "<html><h2>Unhandled Exception</h2>\n\t\t\t\t<h3>Message:</h3>\n\t\t\t\t<pre>" . $message . "</pre>\n\t\t\t\t<h3>Location:</h3>\n\t\t\t\t<pre>" . $file . " on line " . $exception->getLine() . "</pre>";
         if ($trace) {
             $response_body .= "\n\t\t\t\t  <h3>Stack Trace:</h3>\n\t\t\t\t  <pre>" . $exception->getTraceAsString() . "</pre></html>";
         }
         $response = Response::make($response_body, 500);
     } else {
         $response = Event::first('500', array($exception));
         $response = Response::prepare($response);
     }
     $response->render();
     $response->send();
     $response->foundation->finish();
     exit(1);
 }