Exemple #1
0
 public function action_index()
 {
     if ($this->request->method() == HTTP_Request::POST) {
         try {
             $post = $this->request->post();
             if ($post['action'] == 'delete') {
                 foreach ($post['messages'] as $message) {
                     $message = ORM::factory('Message')->where('id', '=', $message)->where('receiver_id', '=', $this->user->id)->where('sent', '=', 1)->find();
                     if ($message->loaded()) {
                         $message->delete();
                     }
                 }
                 Hint::success('You have deleted the selected messages');
             }
             $this->redirect(Route::url('message.outbox'));
         } catch (ORM_Validation_Exception $e) {
             Hint::error($e->errors('models'));
         }
     }
     $this->view = new View_Message_Outbox();
     // TODO: Add pagination
     $messages = ORM::factory('Message')->where('receiver_id', '=', $this->user->id)->where('sent', '=', 1)->order_by('created', 'DESC');
     $paginate = Paginate::factory($messages)->execute();
     $this->view->pagination = $paginate->render();
     $this->view->messages = $paginate->result();
     $this->view->outbox = 1;
 }
Exemple #2
0
 public function action_index()
 {
     $settings = new Settings();
     $settings->add_setting(new Setting_Preferences($this->user));
     $settings->add_setting(new Setting_Profile($this->user));
     $settings->add_setting(new Setting_Account($this->user));
     // Run the events.
     Event::fire('user.settings', array($this->user, $settings));
     if ($this->request->method() == HTTP_Request::POST) {
         $setting = $settings->get_by_id($this->request->post('settings-tab'));
         if ($setting) {
             $post = $this->request->post();
             $validation = $setting->get_validation($post);
             if ($validation->check()) {
                 try {
                     $setting->save($post);
                     Hint::success('Updated ' . $setting->title . '!');
                 } catch (ORM_Validation_Exception $e) {
                     Hint::error($e->errors('models'));
                 }
             } else {
                 Hint::error($validation->errors());
             }
         } else {
             Hint::error('Invalid settings id!');
         }
     }
     $this->view = new View_User_Settings();
     $this->view->settings = $settings;
 }
Exemple #3
0
 public function action_index()
 {
     $username = $this->request->param('username');
     $this->view = new View_Message_Create();
     $this->view->username = $username;
     if ($this->request->method() == HTTP_Request::POST) {
         try {
             $post = $this->request->post();
             $receiver = ORM::factory('User')->where('username', '=', $post['receiver'])->find();
             if (!$receiver->loaded()) {
                 return Hint::error('Cannot find a user with the username: '******'You cannot send a message to yourself!');
             }
             $message_data = Arr::merge($this->request->post(), array('sender_id' => $this->user->id, 'receiver_id' => $receiver->id));
             $message = ORM::factory('Message')->create_message($message_data, array('receiver_id', 'subject', 'content', 'sender_id'));
             $message_data_sent = Arr::merge($this->request->post(), array('receiver_id' => $this->user->id, 'sender_id' => $receiver->id, 'sent' => 1, 'read' => 1));
             ORM::factory('Message')->create_message($message_data_sent, array('receiver_id', 'subject', 'content', 'sender_id', 'sent', 'read'));
             Hint::success('You have sent a message');
             $this->redirect(Route::get('message.inbox')->uri());
         } catch (ORM_Validation_Exception $e) {
             Hint::error($e->errors('models'));
         }
     }
 }
Exemple #4
0
 /**
  * Save the user information.
  *
  * @param array $post
  */
 public function save(array $post)
 {
     $this->user->update_user($post, array('email', 'password'));
     if (!empty($post['password'])) {
         Hint::success('Updated password!');
     }
 }
Exemple #5
0
 public function action_index()
 {
     if ($this->request->method() == HTTP_Request::POST) {
         try {
             if ($this->request->post('active')) {
                 $pet = ORM::factory('User_Pet')->where('user_pet.id', '=', $this->request->post('active'))->where('user_id', '=', $this->user->id)->find();
                 $pet->active = time();
                 $pet->save();
                 Hint::success($pet->name . ' is now your active pet.');
             }
             if ($this->request->post('abandon')) {
                 $pet = ORM::factory('User_Pet')->where('user_pet.id', '=', $this->request->post('abandon'))->where('user_id', '=', $this->user->id)->find();
                 $pet->user_id = NULL;
                 $pet->abandoned = time();
                 $pet->save();
                 Hint::success('You have abandoned ' . $pet->name . '.');
             }
             $this->redirect(Route::get('pets')->uri());
         } catch (ORM_Validation_Exception $e) {
             Hint::error($e->errors('models'));
         }
     }
     $this->view = new View_Pet_Index();
     $pets = ORM::factory('User_Pet')->where('user_id', '=', $this->user->id)->order_by('active', 'desc');
     $paginate = Paginate::factory($pets)->execute();
     $this->view->pagination = $paginate->render();
     $this->view->pets = $paginate->result();
     $this->view->pets_count = count($pets);
     $this->view->href = array('create' => Route::url('pet.create'), 'adopt' => Route::url('pet.adopt'));
 }
Exemple #6
0
 public function action_buy()
 {
     $shop_id = $this->request->param('id');
     $shop = ORM::factory('Shop', $shop_id);
     if (!$shop->loaded()) {
         Hint::error('You can\'t buy an item from a shop that does not exist.');
     } elseif ($shop->status == 'closed') {
         Hint::error('You\'re trying to buy an item from a closed shop.');
     } else {
         $item_id = $this->request->post('id');
         $item = ORM::factory('Shop_Inventory')->where('shop_id', '=', $shop->id)->where('item_id', '=', $item_id)->find();
         if (!$item->loaded()) {
             Hint::error('The item you tried to buy has already been sold.');
         } elseif ($item->price > $this->user->get_property('points')) {
             Hint::error('You don\'t have enough points to buy ' . $item->item->name);
         } else {
             // retract the points
             $this->user->set_property('points', $this->user->get_property('points') - $item->price);
             $this->user->save();
             // send over the item
             Item::factory($item->item)->to_user($this->user, 'shops.' . $shop_id);
             // remove from shop if needed
             if ($shop->stock_type != 'steady') {
                 if ($item->stock - 1 == 0) {
                     $item->delete();
                 } else {
                     $item->stock -= 1;
                     $item->save();
                 }
             }
             Hint::success('You\'ve successfully bought ' . $item->item->name);
         }
     }
     $this->redirect(Route::get('item.shops.view')->uri(array('id' => $shop_id)));
 }
Exemple #7
0
 public function action_complete()
 {
     // Get the transaction details.
     $fetch = $this->_gateway->fetchTransaction($this->_payment_vars())->send();
     $data = $fetch->getData();
     // Add the buyer email to parameters.
     $parameters = $this->_payment_vars() + array('email' => $data['EMAIL']);
     /** @var Payment_PayPal_CreateRecurringPaymentsRequest $request */
     $request = $this->_gateway->createRecurringPaymentsProfile($parameters);
     // Overwrite Item Category.
     $data = $request->getData();
     $data['L_PAYMENTREQUEST_0_ITEMCATEGORY0'] = $this->_config['itemCategory'];
     /** @var Omnipay\PayPal\Message\ExpressAuthorizeResponse $response */
     $response = $request->sendData($data);
     if ($response->isSuccessful()) {
         $response_data = $response->getData();
         // Get the transaction details.
         // $fetch = $this->_gateway->fetchTransaction($this->_payment_vars())->send();
         // $data = $fetch->getData();
         ORM::factory('Payment_Subscription')->values(array('user_id' => $this->user->id, 'package_id' => $this->_package->id, 'status' => Model_Payment_Subscription::PENDING, 'recurring_payment_id' => $response_data['PROFILEID']))->create();
         Hint::success(Kohana::message('payment', 'payment.success'));
         $this->redirect(Route::get('payment')->uri());
     } else {
         // Log the error.
         Kohana::$log->add(Log::ERROR, IPN::array_to_string($response->getData()));
         throw HTTP_Exception::factory('403', 'Something went wrong, no cash should have been drawn, if the error proceeds contact support!');
     }
 }
Exemple #8
0
 public function action_move()
 {
     $items = $this->request->post('items');
     if (count($items) > 0) {
         foreach ($items as $id => $item) {
             if ($item['amount'] > 0) {
                 $i = ORM::factory('User_Item', $id);
                 if ($i->loaded() and $i->location == 'safe' and $i->user_id == $this->user->id) {
                     if ($item['amount'] > $i->amount) {
                         Hint::error(__('You can\'t move :name, you only have :amount.', array(':amount' => $i->amount, ':name' => $i->item->name($item['amount']))));
                     } elseif ($item['location'] == 'shop') {
                         $shop = ORM::factory('User_Shop')->where('user_id', '=', $this->user->id)->find();
                         $shop_item = ORM::factory('User_Item')->where('user_id', '=', $this->user->id)->where('location', '=', 'shop')->where('item_id', '=', $i->item_id)->find();
                         if (!$shop->loaded()) {
                             Hint::error('You don\'t have a shop yet.');
                         } elseif (!$shop->inventory_space() and !$shop_item->loaded()) {
                             Hint::error('Your shop is already full.');
                         } else {
                             $i->move('shop', $item['amount']);
                             Hint::success(__('You\'ve moved :items to your shop.', array(':items' => $i->item->name($item['amount']))));
                         }
                     } elseif ($item['location'] == 'inventory') {
                         $i->move('inventory', $item['amount']);
                         Hint::success(__('You\'ve moved :items to your inventory.', array(':items' => $i->item->name($item['amount']))));
                     }
                 }
             }
         }
     }
     $this->redirect(Route::get('item.safe')->uri());
 }
Exemple #9
0
 /**
  * Sign out the user AND redirect him to the frontpage.
  */
 public function action_index()
 {
     if ($this->request->method() == HTTP_Request::POST) {
         Hint::success(Kohana::message('user', 'logout.success'));
         $this->auth->logout();
         $this->redirect('');
     } else {
         $this->view = new View_User_Logout();
     }
 }
Exemple #10
0
 /**
  * Retrieve the news feed items. First try from cache, otherwise load it from the website.
  * @return array
  */
 private function _get_news_feed()
 {
     $benchmark = Profiler::start('Admin Dashboard', __FUNCTION__);
     $cache = Cache::instance();
     // Attempt to load feed from cache otherwise get it from the website.
     if (!($feed = $cache->get('admin.dashboard.news_feed', FALSE))) {
         try {
             $feed = Feed::parse($this->_news_feed_url);
             $cache->set('admin.dashboard.news_feed', $feed, 360);
         } catch (Exception $e) {
             Hint::error($e);
         }
     }
     Profiler::stop($benchmark);
     return $feed;
 }
Exemple #11
0
 /**
  * Create new topic.
  */
 public function action_create()
 {
     $this->logged_in_required();
     if (!$this->user->can('Forum_Topic_Create', array('category' => $this->category))) {
         throw HTTP_Exception::factory('403', 'Category is locked');
     }
     if ($this->request->method() == HTTP_Request::POST) {
         try {
             $topic = new Model_Forum_Topic();
             $topic->create_topic(array('category_id' => $this->category->id, 'user_id' => $this->user->id, 'title' => $this->request->post('title'), 'content' => $this->request->post('content')), array('category_id', 'user_id', 'title'));
             Hint::success('You have created a topic');
             $this->redirect(Route::get('forum.topic')->uri(array('id' => $topic->id)));
         } catch (ORM_Validation_Exception $e) {
             Hint::error($e->errors('models'));
         }
     }
     $this->view = new View_Forum_Topic_Create();
     $this->view->category = $this->category;
 }
Exemple #12
0
 /**
  * Display AND handle the register form.
  */
 public function action_index()
 {
     $this->_not_logged_in();
     if ($this->request->method() == HTTP_Request::POST) {
         if ($this->_honeypot_empty()) {
             try {
                 $user = $this->_create_user($this->request->post());
                 $this->_send_welcome_email($user);
                 // Log in the user, and send him to his dashboard.
                 $this->auth->force_login($user);
                 $this->redirect(Route::get('user')->uri());
             } catch (ORM_Validation_Exception $e) {
                 Hint::error($e->errors('models'));
             }
         } else {
             Hint::error(Kohana::message('user', 'register.honeypot'));
         }
     }
     $this->view = new View_User_Register();
 }
Exemple #13
0
 /**
  * Display the login page AND handle login attempts.
  */
 public function action_index()
 {
     $this->_not_logged_in();
     if ($this->request->method() == HTTP_Request::POST) {
         $post = $this->request->post();
         if ($this->auth->login($post['username'], $post['password'], isset($post['remember']))) {
             Hint::success(Kohana::message('user', 'login.success'));
             // Redirect the page to ?page= value if local url.
             if ($page = $this->request->query('page')) {
                 // Ensure the url is local, we don't want the user to change site.
                 if (strpos($page, '://') === FALSE) {
                     $this->redirect($page);
                 }
             }
             $this->redirect(Route::get('user.dashboard')->uri());
         } else {
             Hint::error(Kohana::message('user', 'login.incorrect'));
         }
     }
     $this->view = new View_User_Login();
 }
Exemple #14
0
 public function action_index()
 {
     if ($this->request->method() == HTTP_Request::POST) {
         try {
             $array = Arr::merge($this->request->post(), array('user_id' => $this->user->id, 'active' => time()));
             $new_pet = ORM::factory('User_Pet')->create_pet($array, array('user_id', 'specie_id', 'colour_id', 'gender', 'name', 'active'));
             Hint::success('You have created a pet named ' . $new_pet->name);
             $this->redirect(Route::get('pets')->uri());
         } catch (ORM_Validation_Exception $e) {
             Hint::error($e->errors('models'));
         }
     }
     $species = ORM::factory('Pet_Specie')->find_all();
     $this->view = new View_Pet_Create();
     $colours = ORM::factory('Pet_Colour')->where('locked', '=', 0)->find_all();
     $this->view->colours = $colours;
     $this->view->species = $species;
     $this->view->default_specie = $species[0]->dir;
     $this->view->default_colour = $colours[0]->image;
     $this->view->href = array('adopt' => Route::url('pet.adopt'));
 }
Exemple #15
0
 /**
  * Enter new password, accessed if token is in the url.
  */
 public function action_token()
 {
     $tokens = ORM::factory('User_Property')->where('key', '=', 'reset_token')->find_all();
     $token = $this->_get_token($tokens);
     if (!$token) {
         Hint::error('Incorrect token, perhaps it expired?');
         $this->redirect();
     }
     if ($this->request->method() == HTTP_Request::POST) {
         $user = $token->user;
         try {
             $user->update_user($this->request->post(), array('password'));
             // Delete the token.
             $token->delete();
             // Confirm and redirect the user.
             Hint::success('Password changed, please login.');
             $this->redirect(Route::get('user.login')->uri());
         } catch (ORM_Validation_Exception $e) {
             Hint::error($e->errors('models'));
         }
     }
     $this->view = new View_User_Reset_Enter();
 }
 public function action_index()
 {
     $this->view = new View_Game_RockPaperScissors();
     $can_play = $this->can_play();
     $this->view->can_play = $can_play;
     if ($this->request->method() == HTTP_Request::POST and $can_play) {
         try {
             $post = $this->request->post();
             if (isset($post['collect']) and $this->game->winnings) {
                 $this->game->collect_winnings(TRUE);
                 Hint::success('You have collected your winnings');
                 $this->redirect(Route::url('games.rock-paper-scissors'));
             }
             $validation = Validation::factory($post)->rule('move', 'not_empty')->rule('move', 'in_array', array(':value', array('rock', 'paper', 'scissors')));
             if ($validation->check()) {
                 $play = $this->play($post['move'], $this->game);
                 $this->view->play = $play;
             }
         } catch (ORM_Validation_Exception $e) {
             Hint::error($e->errors('models'));
         }
     }
     $this->view->game = $this->game;
 }
Exemple #17
0
 public function action_index()
 {
     $this->view = new View_Game_LuckyWheel();
     $can_play = $this->can_play();
     $this->view->can_play = $can_play;
     $this->view->has_price = $this->user->get_property('points') >= $this->price;
     if ($this->request->method() == HTTP_Request::POST) {
         try {
             $post = $this->request->post();
             if (isset($post['collect']) and $this->game->winnings) {
                 $this->game->collect_winnings(FALSE);
                 Hint::success('You have collected your winnings');
                 $this->redirect(Route::url('games.lucky-wheel'));
             }
             if ($can_play) {
                 $play = $this->play($this->game);
                 $this->view->play = $play;
             }
         } catch (ORM_Validation_Exception $e) {
             Hint::error($e->errors('models'));
         }
     }
     $this->view->game = $this->game;
 }
Exemple #18
0
 public function action_delete()
 {
     $post = $this->post;
     if (!$this->user->can('Forum_Post_Delete', array('post' => $post))) {
         throw HTTP_Exception::factory('403', 'Permission denied to delete post');
     }
     if ($this->request->method() == HTTP_Request::POST) {
         $topic_redirect = Route::get('forum.topic')->uri(array('id' => $post->topic->id));
         try {
             // First post? delete the topic.
             if ($post->id == $post->topic->posts->limit(1)->find()->id) {
                 $topic_redirect = Route::get('forum.category')->uri(array('id' => $post->topic->category));
                 $post->topic->delete();
             }
             $post->delete();
         } catch (ORM_Validation_Exception $e) {
             Hint::error($e->errors('models'));
         }
         Hint::success('Deleted post');
         $this->redirect($topic_redirect);
     }
     $this->view = new View_Forum_Post_Delete();
     $this->view->post = $post;
 }
Exemple #19
0
 public function hints()
 {
     return Hint::get_once();
 }
Exemple #20
0
 /**
  * Return the user from paypal, and process the payment.
  *
  * @throws HTTP_Exception
  */
 public function action_complete()
 {
     /** @var Omnipay\PayPal\Message\ExpressAuthorizeResponse $response */
     $response = $this->_gateway->completePurchase($this->_payment_vars())->send();
     if ($response->isSuccessful()) {
         // Get the transaction details.
         $fetch = $this->_gateway->fetchTransaction($this->_payment_vars())->send();
         $data = $fetch->getData();
         $transaction = ORM::factory('Payment_Transaction')->where('TOKEN', '=', $data['TOKEN'])->find();
         // Update the transaction with the buyers information.
         $transaction->values(array('status' => 'completed', 'email' => $data['EMAIL'], 'first_name' => $data['FIRSTNAME'], 'last_name' => $data['LASTNAME'], 'country' => $data['COUNTRYCODE']))->save();
         // Give the player the rewards.
         foreach ($this->_package->rewards as $key => $value) {
             $reward = Payment_Reward::factory($key, $value);
             $reward->reward($this->user);
         }
         $this->user->save();
         Hint::success(Kohana::message('payment', 'payment.success'));
         $this->redirect(Route::get('payment')->uri());
     } else {
         // Log the error.
         Kohana::$log->add(Log::ERROR, IPN::array_to_string($response->getData()));
         throw HTTP_Exception::factory('403', 'Something went wrong, no cash should have been drawn, if the error proceeds contact support!');
     }
 }
Exemple #21
0
 public function before()
 {
     $this->_tpl = View::factory('s4k/layout');
     $this->_tpl->hints = Hint::render(null, true, 's4k/hint');
 }
Exemple #22
0
 public function action_consume()
 {
     $item = ORM::factory('User_Item', $this->request->param('id'));
     $action = $this->request->post('action');
     $errors = array();
     if (!$item->loaded()) {
         Hint::error('You can\'t use an item that does not exist');
     } elseif ($item->user_id != $this->user->id) {
         Hint::error('You can\'t access another player\'s item');
     } elseif ($item->location != 'inventory') {
         Hint::error('The item you want to view is not located in your inventory');
     } elseif ($action == NULL) {
         Hint::error('No action to perform has been specified');
     } else {
         $def_cmd = Item_Command::factory($item->item->type->default_command);
         if (Valid::digit($action)) {
             // we'll want to perform an action on a pet
             $pet = ORM::factory('User_Pet', $action);
             if (!$pet->loaded()) {
                 Hint::error('No existing pet has been specified');
             } elseif ($pet->user_id != $this->user->id) {
                 Hint::error('You can\'t let a pet comsume this item if it\'s not yours');
             } elseif ($def_cmd->pets_required() == FALSE) {
                 Hint::error('can\'t perform this item action on a pet');
             } else {
                 $commands = $item->item->commands;
                 $results = array();
                 $db = Database::instance();
                 $db->begin();
                 $error = FALSE;
                 foreach ($commands as $command) {
                     $cmd = Item_Command::factory($command['name']);
                     $res = $cmd->perform($item, $command['param'], $pet);
                     if ($res == FALSE) {
                         // the command couldn't be performed, spit out error, rollback changes and break the loop
                         Hint::error(__(':item_name could not be used on :pet_name', array(':item_name' => $item->item->name, ':pet_name' => $pet->name)));
                         $error = TRUE;
                         $db->rollback();
                         break;
                     } else {
                         $results[] = $res;
                     }
                 }
                 if ($error == FALSE) {
                     $log = Journal::log('consume', 'item', ':item_name consumed', array(':item_name' => $item->item->name));
                     $log->notify('consume' . $item->item_id, 'item', ':item_name consumed');
                     if ($def_cmd->delete_after_consume == TRUE) {
                         $item->amount('-', 1);
                     }
                     $db->commit();
                 }
             }
         } else {
             $results = array();
             switch ($action) {
                 case 'consume':
                     $commands = $item->item->commands;
                     $results = array();
                     $db = Database::instance();
                     $db->begin();
                     $error = FALSE;
                     foreach ($commands as $command) {
                         $cmd = Item_Command::factory($command['name']);
                         $res = $cmd->perform($item, $command['param']);
                         if ($res == FALSE) {
                             // the command couldn't be performed, spit out error, rollback changes and break the loop
                             Hint::error(__(':item_name could not be used', array(':item_name' => $item->name)));
                             $db->rollback();
                             $error = TRUE;
                             break;
                         } else {
                             $results[] = $res;
                         }
                     }
                     if ($error = FALSE) {
                         Journal::log('consume' . $item->item_id, 'item', ':item_name consumed', array(':item_name' => $item->item->name));
                         if ($def_cmd->delete_after_consume == TRUE) {
                             $item->amount('-', 1);
                         }
                         $db->commit();
                     }
                     break;
                 case 'remove':
                     // takes an amount
                     $amount = $this->request->post('amount');
                     if ($amount == NULL) {
                         $amount = 1;
                     }
                     if (!Valid::digit($amount)) {
                         Hint::error('The amount you submitted isn\'t a number.');
                     } elseif ($amount <= 0 or $amount > $item->amount) {
                         Hint::error('You only have ' . $item->name() . ', not ' . $amount);
                     } else {
                         if ($amount > 1) {
                             $name = Inflector::plural($item->name(), $amount);
                             $verb = 'were';
                         } else {
                             $name = $item->item->name(1);
                             $verb = 'was';
                         }
                         $item->amount('-', $amount);
                         Journal::log('remove.' . $item->item_id, 'item', ':item_name removed', array(':item_name' => $name));
                         $results = __(':item :verb deleted successfully', array(':verb' => $verb, ':item' => $name));
                     }
                     break;
                 case 'gift':
                     // takes a username
                     $username = $this->request->post('username');
                     if ($this->user->username == $username) {
                         Hint::error('You can\'t send a gift to yourself');
                     } else {
                         $user = ORM::factory('User')->where('username', '=', $username)->find();
                         if ($user->loaded()) {
                             $log = $item->transfer($user);
                             $log->notify($user, 'items.gift', array(':item_name' => $item->item->name(1)));
                             $results = __('You\'ve successfully sent :item to :username', array(':item' => $item->item->name, ':username' => $user->username));
                         } else {
                             Hint::error(__('Couldn\'t find a user named ":username"', array(':username' => $username)));
                         }
                     }
                     break;
                 default:
                     // Moving items can take an amount
                     if (substr($action, 0, 5) == 'move_') {
                         $location = substr($action, 5);
                         $cmd = Item_Command::factory('Move_' . ucfirst($location));
                         $amount = $this->request->post('amount');
                         if ($amount == NULL) {
                             $amount = 1;
                         }
                         if (!Valid::digit($amount)) {
                             Hint::error('The amount you submitted isn\'t a number.');
                         } elseif ($amount <= 0 or $amount > $item->amount) {
                             Hint::error('You only have ' . $item->name() . ', not ' . $amount);
                         } else {
                             $results = $cmd->perform($item, $amount);
                         }
                     } else {
                         Hint::error('The action you want to perform with this item does not exist');
                     }
                     break;
             }
         }
     }
     $show = Kohana::$config->load('items.inventory.consume_show_results');
     $output = array();
     if (!is_array($results)) {
         $output[] = $results;
     } elseif ($show == 'first') {
         $output[] = $results[0];
     } elseif (!empty($results)) {
         foreach ($results as $result) {
             $output[] = $result;
         }
     }
     if ($this->request->is_ajax()) {
         $return = array();
         $return = Hint::dump();
         Hint::ajax_dump();
         if ($return['status'] == 'success') {
             $amount = $item->loaded() ? $item->name() : 0;
             $return = array_merge($return, array('result' => $output, 'new_amount' => $amount));
         }
         $this->response->headers('Content-Type', 'application/json');
         return $this->response->body(json_encode($return));
     }
     if (count($output) > 0) {
         foreach ($output as $result) {
             Hint::success($result);
         }
     }
     $this->redirect(Route::get('item.inventory')->uri());
 }
Exemple #23
0
 public function action_delete()
 {
     $id = $this->request->param('id');
     try {
         $group = Sentry::getGroupProvider()->findById($id);
         $name = $group->name;
         $group->delete();
         //set a success message an redirect to the management page
         Hint::set(Hint::SUCCESS, 'You\'ve deleted group "' . $name . '"');
         $this->redirect(Route::url('S4K.groups', null, true));
     } catch (Cartalyst\Sentry\Groups\GroupNotFoundException $e) {
         //set an error message an redirect to the management page
         Hint::set(Hint::ERROR, 'No corresponding group found');
         $this->redirect(Route::url('S4K.groups', null, true));
     }
 }
Exemple #24
0
 public function action_complete()
 {
     $item = ORM::factory('User_Item', $this->request->param('id'));
     $action = $this->request->post('action');
     $errors = array();
     if (!$item->loaded()) {
         $errors[] = 'You can\'t use a recipe that does not exist';
     } elseif ($item->user_id != $this->user->id) {
         $errors[] = 'You can\'t access another player\'s recipe';
     } elseif ($item->location != 'cookbook') {
         $errors[] = 'The recipe you want to view is not located in your cookbook';
     } elseif ($item->item->type->default_command != 'General_Cook') {
         $errors[] = 'You can\'t use this item as a recipe.';
     } elseif ($action == NULL) {
         $errors[] = 'No action to perform has been specified';
     } else {
         $recipe = ORM::factory('Item_Recipe')->where('item_recipe.name', '=', $item->item->commands[0]['param'])->find();
         $coll = $recipe->materials->find_all();
         $materials = 0;
         $db = Database::instance();
         $db->begin();
         foreach ($coll as $material) {
             $user_item = Item::factory($material->item)->user_has('inventory');
             if ($user_item != FALSE and $user_item->amount >= $material->amount) {
                 $user_item->amount('-', $material->amount);
                 $materials++;
             }
         }
         if ($materials == count($coll)) {
             Item::factory($recipe->item)->to_user($this->user);
             $item->amount('-', 1);
             $db->commit();
             $result = 'You\'ve successfully made ' . $recipe->item->name;
         } else {
             $db->rollback();
             $errors[] = 'You don\'t have all the required ingredients for this recipe.';
         }
     }
     if ($this->request->is_ajax()) {
         if (count($errors) > 0) {
             $return = array('status' => 'error', 'errors' => $errors);
         } else {
             $return = array('status' => 'success', 'result' => $result, 'item' => $item->amount);
         }
         $this->response->headers('Content-Type', 'application/json');
         return $this->response->body(json_encode($return));
     } elseif (count($errors) > 0) {
         Hint::error($errors[0]);
         $this->redirect(Route::get('item.cookbook')->uri());
     } else {
         Hint::success($result);
         $this->redirect(Route::get('item.cookbook')->uri());
     }
 }
Exemple #25
0
 public static function dump()
 {
     $error_messages = Hint::get(Hint::ERROR);
     if (count($error_messages) > 0) {
         return array('status' => 'error', 'errors' => $error_messages);
     } else {
         return array('status' => 'success', 'result' => Hint::get(Hint::SUCCESS));
     }
 }
Exemple #26
0
 public function action_buy()
 {
     $shop = ORM::factory('User_Shop', $this->request->param('id'));
     // if no shop's found redirect to previous page
     if (!$shop->loaded()) {
         $this->redirect($this->request->referrer());
     }
     if ($this->request->method() == HTTP_Request::POST) {
         $item_id = $this->request->post('item_id');
         $item = ORM::factory('User_Item', $item_id);
         if (!$item->loaded() or $item->location != 'shop') {
             Hint::error('This item is not in stock');
         } elseif ($this->user->id == $item->user->id) {
             Hint::error('You cannot buy items from your own shop.');
         } elseif ($this->user->get_property('points') < $item->parameter) {
             Hint::error(__('You don\'t have enough :currency to buy a ":item_name"', array(':item_name' => $item->item->name)));
         } else {
             $this->user->set_property('points', $this->user->get_property('points') - $item->parameter);
             $this->user->save();
             // log this action
             $log = Journal::log('user_shop.' . $shop->id, 'item', ':username bought 1 :item_name for :price', array('item_name' => $item->item->name, 'username' => $this->user->username, 'price' => $item->parameter));
             $shop->till += $item->parameter;
             $shop->save();
             $item->transfer($this->user);
             $log->notify($shop->user, 'user_shop.buy');
             Hint::success(__('You\'ve successfully bought :item_name from :shop_owner for :price.', array(':shop_owner' => $shop->user->username, ':item_name' => $item->item->name('1'), ':price' => $item->parameter)));
         }
     }
     $this->redirect(Route::get('item.user_shop.view')->uri(array('id' => $shop->id)));
 }
Exemple #27
0
 public function action_delete()
 {
     $id = $this->request->param('id');
     try {
         $user = Sentry::getUserProvider()->findById($id);
         $id = $user->id;
         $user->delete();
         Hint::set(Hint::SUCCESS, 'You\'ve deleted user "#' . $id);
         $this->redirect(Route::url('S4K.users.manage', null, true));
     } catch (\Cartalyst\Sentry\Users\UserNotFoundException $e) {
         Hint::set(Hint::ERROR, 'No corresponding user found');
         $this->redirect(Route::url('S4K.users.manage', null, true));
     }
 }
Exemple #28
0
//获取发送方帐号(OpenID)
$toUsername = $postObj->ToUserName;
//获取接收方账号
$messagetype = $postObj->MsgType;
//获取信息类型
$event = $postObj->Event;
//获取事件类型(关注还是非关注)
$eventKey = $postObj->EventKey;
//获取qrscene参数
$keyword = trim($postObj->Content);
//获取消息内容
$time = time();
//获取当前时间戳
//导入HINT末尾
include "conn.php";
$hint = new Hint();
$hint_str = $hint->responseMsg();
//---------- 返 回 数 据 ---------- //
$textTpl = "<xml>\n\t\t\t\t\t<ToUserName><![CDATA[%s]]></ToUserName>\n\t\t\t\t\t<FromUserName><![CDATA[%s]]></FromUserName>\n\t\t\t\t\t<CreateTime>%s</CreateTime>\n\t\t\t\t\t<MsgType><![CDATA[%s]]></MsgType>\n\t\t\t\t\t<Content><![CDATA[%s]]></Content>\n\t\t\t\t\t<FuncFlag>0</FuncFlag>\n\t\t\t\t\t</xml>";
//加载图文模版
$picTpl = "<xml>\n\t\t\t\t\t\t\t<ToUserName><![CDATA[%s]]></ToUserName>\n\t\t\t\t\t\t\t<FromUserName><![CDATA[%s]]></FromUserName>\n\t\t\t\t\t\t\t<CreateTime>%s</CreateTime>\n\t\t\t\t\t\t\t<MsgType><![CDATA[%s]]></MsgType>\n\t\t\t\t\t\t\t<ArticleCount>1</ArticleCount>\n\t\t\t\t\t\t\t<Articles>\n\t\t\t\t\t\t\t<item>\n\t\t\t\t\t\t\t%s\n\t\t\t\t\t\t\t</item>\n\t\t\t\t\t\t\t</Articles>\n\t\t\t\t\t\t\t<FuncFlag>1</FuncFlag>\n\t\t\t\t\t\t\t</xml> ";
//加载图片模版
$picTure = "<xml>\n\t\t\t\t\t<ToUserName><![CDATA[%s]]></ToUserName>\n\t\t\t\t\t<FromUserName><![CDATA[%s]]></FromUserName>\n\t\t\t\t\t<CreateTime>%s</CreateTime>\n\t\t\t\t\t<MsgType><![CDATA[image]]></MsgType>\n\t\t\t\t\t<Image>\n\t\t\t\t\t<MediaId><![CDATA[%s]]></MediaId>\n\t\t\t\t\t</Image>\n\t\t\t\t\t</xml>";
//格式化消息模板
if ($event == "scan") {
    $contentStr = "您扫瞄了二维码";
    $resultStr_text = sprintf($textTpl, $fromUsername, $toUsername, $time, "text", $contentStr);
    echo $resultStr_text;
    //输出结果
    exit;
} elseif ($messagetype == "event" && $event == "subscribe") {
Exemple #29
0
	/**
	 * Redirects the user upon error
	 *
	 * @param	 array	$options	Options from config
	 * @return	void
	 */
	protected function _action_redirect(array $options = array())
	{
		if ($this->code === 'E_PARSE')
		{
			echo '<p><strong>NOTE:</strong> Cannot redirect on a parse error, because it might cause a redirect loop.</p>';
			echo $this->display;
			return;
		}

		$hint_available = (class_exists('Hint') and method_exists('Hint', 'set'));
		$message = Arr::get($options, 'message', false);
		if ($hint_available and $message)
		{
			Hint::set(HINT::ERROR, $message);
		}

		$url = Arr::get($options, 'url');
		if (strpos($url, '://') === false)
		{
			// Make the URI into a URL
			$url = URL::site($url, true);
		}
		header("Location: $url", true);
		exit;
	}
Exemple #30
0
 public function action_reset_valid_complete()
 {
     if ($this->request->post() != null) {
         try {
             // Find the user using the user id
             $user = Sentry::getUserProvider()->findByCredentials(array('email' => $this->request->post('email')));
             if ($this->request->post('password') == '') {
                 Hint::set(Hint::ERROR, 'Please provide a password.');
             } else {
                 if ($user->checkResetPasswordCode($this->request->post('code'))) {
                     // Attempt to reset the user password
                     if ($user->attemptResetPassword($this->request->post('code'), $this->request->post('password'))) {
                         // Password reset passed
                         Hint::set(Hint::SUCCESS, 'You have successfully reset your password');
                         //everything went successful, send the user somewhere else
                         $this->redirect(Route::url('S4K.users.reset_valid', null, true));
                     } else {
                         Hint::set(Hint::ERROR, 'Resetting your password has failed.');
                     }
                 } else {
                     // The provided password reset code is Invalid
                     Hint::set(Hint::ERROR, 'The provided reset code is invalid.');
                 }
             }
         } catch (Cartalyst\Sentry\Users\UserNotFoundException $e) {
             Hint::set(Hint::ERROR, 'There\'s no user with that login credential.');
         }
         // Resetting the password failed, show the form with the errors
         $this->redirect(Route::url('S4K.users.reset_valid', null, true));
         $this->action_reset_valid();
     } else {
         // no post request made, send back
         $this->redirect(Route::url('S4K.users.reset_valid', null, true));
     }
 }