Esempio n. 1
0
 public function before()
 {
     parent::before();
     // Save the old action so it can be brought back on after
     $this->_action = $this->request->action;
     // Set the current action
     $current_action = $this->request->action;
     $id = $this->request->param('id', NULL);
     // Let's guess the action based on the params
     if (!in_array($this->request->action, array('edit', 'add', 'delete')) and (!is_null($id) or !empty($id))) {
         $current_action = 'read';
     }
     if (!method_exists($this, 'action_' . $this->request->action)) {
         $model = Jelly::select(Inflector::singular($this->request->controller));
         foreach ($model->get_state() as $key => $value) {
             $param = $this->request->param($key, NULL);
             if (!is_null($param)) {
                 $model->set_state($key, $param);
             }
         }
         $this->request->response = Kostache::factory($this->request->controller . '/' . $current_action)->set_model($model);
         // Since the magic has been executed, just execute an empty action
         $this->request->action = 'default';
     }
 }
Esempio n. 2
0
 public function action_delete($id)
 {
     $post = Jelly::select('forum_post')->where('id', '=', $id)->load();
     if ($post->loaded()) {
         $this->title = 'Forum - Post - Delete';
     } else {
         Message::set(Message::ERROR, 'Post does not exist');
         $this->request->redirect('forum');
     }
     if ($this->user->id != $post->user->id) {
         Message::set(Message::ERROR, 'You are not the author of this post.');
         $this->request->redirect('forum');
     } else {
         $topic = Jelly::select('forum_topic')->where('id', '=', $post->topic->id)->load();
         if ($topic->posts > 1) {
             $topic->posts = $topic->posts - 1;
             $topic->save();
             $post->delete();
             Message::set(Message::SUCCESS, 'Post has been deleted.');
             $this->request->redirect('forum');
         }
         if ($topic->posts == 1) {
             $topic->delete();
             $post->delete();
             Message::set(Message::SUCCESS, 'Post has been deleted.');
             $this->request->redirect('forum');
         }
     }
     $this->template->content = View::factory('forum/post/delete')->set('post', $post);
 }
Esempio n. 3
0
 /**
  * Create a new post.
  */
 public function action_reply($id)
 {
     $topic = Jelly::select('forum_topic')->where('id', '=', $id)->load();
     // Make sure the topic exists
     if (!$topic->loaded()) {
         Message::set(Message::ERROR, 'Topic does not exist');
         $this->request->redirect('forum');
     }
     $this->title = 'Forum - Reply to ' . $topic->title;
     // Validate the form input
     $post = Validate::factory($_POST)->filter(TRUE, 'trim')->filter(TRUE, 'htmlspecialchars', array(ENT_QUOTES))->rule('title', 'not_empty')->rule('title', 'min_length', array(3))->rule('title', 'max_length', array(20))->rule('content', 'not_empty')->rule('content', 'min_length', array(5))->rule('content', 'max_length', array(1000));
     if ($post->check()) {
         $values = array('title' => $post['title'], 'content' => $post['content'], 'user' => $this->user->id, 'topic' => $id);
         $message = Jelly::factory('forum_post');
         // Assign the validated data to the Jelly object
         $message->set($values);
         $message->save();
         $topic_id = $id;
         $topic = Jelly::select('forum_topic')->where('id', '=', $topic_id)->load();
         $topic->posts = $topic->posts + 1;
         $topic->save();
         Message::set(Message::SUCCESS, 'You posted a new reply.');
         $this->request->redirect('forum/topic/' . $id);
     } else {
         $this->errors = $post->errors('forum');
     }
     if (!empty($this->errors)) {
         Message::set(Message::ERROR, $this->errors);
     }
     $this->template->content = View::factory('forum/post/create')->set('post', $post->as_array());
 }
Esempio n. 4
0
 public function action_update()
 {
     $this->content->bind('form', $supply);
     $this->content->bind('errors', $errors);
     $id = $this->request->param('id');
     $supply = Jelly::select('supply', $id);
     $supply->set('product', $supply->product);
     // bez tego nie dziala, lol
     if (!$supply->loaded()) {
         $this->request->redirect($this->_base);
     }
     if ($_POST and !$this->session->get($_POST['seed'], FALSE)) {
         if (in_array($supply->status, array('done'))) {
             unset($_POST['status']);
         }
         if (!in_array($supply->status, array('added'))) {
             unset($_POST['quantity'], $_POST['supplier']);
         }
         try {
             $supply->set($_POST);
             $supply->save();
             $this->session->set($_POST['seed'], TRUE);
             // 'seed' jest zintegrowany w formularz
             $this->request->redirect($this->_base);
         } catch (Validate_Exception $e) {
             $errors = $e->errors();
         }
     }
 }
Esempio n. 5
0
 public function action_register()
 {
     if ($this->user) {
         Request::instance()->redirect('');
     }
     // Experimental facebook connection
     $this->facebook = new Fb();
     // User accessed from facebook!
     if ($this->facebook->validate_fb_params()) {
         $this->facebook->require_frame();
         $_SESSION['fb_uid'] = $this->facebook->require_login();
     } elseif (!isset($_SESSION['fb_uid'])) {
         Request::instance()->redirect('');
     }
     // Check if the user got an account.
     $user_facebook = Jelly::select('user_facebook')->where('facebook_id', '=', $_SESSION['fb_uid'])->load();
     // If we found it, log him in.
     if ($user_facebook->loaded()) {
         $this->a1->force_login($user_facebook->user->username);
         $_SESSION['facebook'] = 'TRUE';
         // Used for verifying if logged in using facebook.
         Request::instance()->redirect('');
     }
     $user = Jelly::factory('user');
     // Validate the form input
     $post = Validate::factory($_POST)->filter(TRUE, 'trim')->rule('username', 'not_empty')->rule('username', 'min_length', array(3))->rule('username', 'max_length', array(20))->rule('username', 'alpha_numeric')->rule('email', 'email')->rule('tos', 'not_empty');
     if ($post->check()) {
         $values = array('username' => $post['username'], 'email' => $post['email']);
         // Assign the validated data to the sprig object
         $user->set($values);
         // Hash the password
         $user->password = '';
         // Set the default role for registered user.
         $user->role = 'facebook';
         try {
             // Create the new user
             $testy = $user->save();
             //print_r($testy);
             $user_id = mysql_insert_id();
             $ufb = Jelly::factory('user_facebook');
             $ufb->facebook_id = $_SESSION['fb_uid'];
             $ufb->user = $user_id;
             $ufb->save();
             $this->a1->force_login($values['username']);
             $_SESSION['facebook'] = 'TRUE';
             // Used for verifying if logged in using facebook.
             // Redirect the user to the login page
             $this->request->redirect('');
         } catch (Validate_Exception $e) {
             // Get the errors using the Validate::errors() method
             $this->errors = $e->array->errors('register');
         }
     } else {
         $this->errors = $post->errors('account/register');
     }
     if (!empty($this->errors)) {
         Message::set(Message::ERROR, $this->errors);
     }
     $this->template->content = View::factory('facebook/register')->set('post', $post->as_array());
 }
Esempio n. 6
0
 /**
  * Displays a selection of models to relate to
  *
  * @param   string  $prefix  The prefix to put before the filename to be rendered
  * @return  View
  **/
 public function input($prefix = 'jelly/field', $data = array())
 {
     if (!isset($data['options'])) {
         $data['options'] = Jelly::select($this->foreign['model'])->execute()->as_array(':primary_key', ':name_key');
     }
     return parent::input($prefix, $data);
 }
Esempio n. 7
0
 /**
  * Moves the character to a new zone
  * 
  * @param  integer  $id
  */
 public function action_travel($id)
 {
     // Make sure id is an integer.
     if (!is_numeric($id)) {
         Message::set(Message::ERROR, 'Invalid ID');
         $this->request->redirect('travel');
     }
     if ($id == $this->character->zone->id) {
         Message::set(Message::ERROR, 'You cannot move to where you already are.');
         $this->request->redirect('travel');
     }
     // Load the zone
     $zone = Jelly::select('zone')->where('id', '=', $id)->load();
     $character = $this->character;
     // Make sure the character got enough of engery
     if ($character->energy < $zone->energy) {
         Message::set(Message::ERROR, 'Not enough energy.');
         $this->request->redirect('travel');
     }
     // Set the new zone, and energy
     $character->zone = $zone->id;
     $character->energy = $character->energy - $zone->energy;
     $character->save();
     $this->request->redirect('character');
 }
Esempio n. 8
0
 /**
  * Create a new topic.
  */
 public function action_new_topic($id)
 {
     $this->title = 'Forum - New Topic';
     $category = Jelly::select('forum_category')->where('id', '=', $id)->load();
     if (!$category->loaded()) {
         Message::set(Message::ERROR, 'Category does not exist');
         $this->request->redirect('forum');
     }
     // Validate the form input
     $post = Validate::factory($_POST)->filter(TRUE, 'trim')->filter(TRUE, 'htmlspecialchars', array(ENT_QUOTES))->rule('title', 'not_empty')->rule('title', 'min_length', array(3))->rule('title', 'max_length', array(20))->rule('content', 'not_empty')->rule('content', 'min_length', array(5))->rule('content', 'max_length', array(1000));
     if ($post->check()) {
         $topic_values = array('title' => $post['title'], 'user' => $this->user->id, 'category' => $id, 'status' => 'open', 'posts' => '1');
         $topic = Jelly::factory('forum_topic');
         // Assign the validated data to the sprig object
         $topic->set($topic_values);
         $topic->save();
         $topic_id = $topic->id;
         $post_values = array('title' => $post['title'], 'content' => $post['content'], 'user' => $this->user->id, 'topic' => $topic_id);
         $message = Jelly::factory('forum_post');
         // Assign the validated data to the sprig object
         $message->set($post_values);
         $message->save();
         Message::set(Message::SUCCESS, 'You created a topic.');
         $this->request->redirect('forum/category/' . $id);
     } else {
         $this->errors = $post->errors('forum');
     }
     if (!empty($this->errors)) {
         Message::set(Message::ERROR, $this->errors);
     }
     $this->template->content = View::factory('forum/topic/create')->set('post', $post->as_array());
 }
Esempio n. 9
0
 public function action_all(Params $param)
 {
     $this->content->bind('projects', $projects);
     $projects = Jelly::select('project');
     $this->template->title = __('My works');
     $this->template->active = array('portfolio' => ' class="active"');
 }
Esempio n. 10
0
 public function input($prefix = 'jelly/field', $data = array())
 {
     if (!isset($data['options'])) {
         $data['options'] = Jelly::select($this->foreign['model'])->join('products_suppliers', 'LEFT')->on('products_suppliers.supplier_id', '=', $this->foreign['model'] . ':primary_key')->where('products_suppliers.product_id', '=', $this->product->id)->execute()->as_array($this->foreign['model'] . ':primary_key', $this->foreign['model'] . ':name_key');
     }
     return parent::input($prefix, $data);
 }
Esempio n. 11
0
 public static function init()
 {
     //get list of all registered modules
     self::$_modules = Jelly::select('module')->execute()->as_array('name');
     //Jx_Debug::dump(self::$_modules,'module listing');
     $paths = array();
     //go through the modules directory and get directory names
     $iter = new DirectoryIterator(MODPATH);
     foreach ($iter as $f) {
         if (!$f->isDot() && $f->isDir()) {
             //compare with registered modules
             $fname = $f->getFilename();
             if (self::isRegistered($fname)) {
                 if (self::isActivated($fname) && !self::isPermanent($fname)) {
                     //if registered, activated, and not permanent, run init.php for the module
                     //permanent modules are initialized by Kohana directly.
                     $path = MODPATH . $fname;
                     $paths[] = realpath(MODPATH . $fname) . DS;
                 }
             } else {
                 self::register($fname);
             }
         }
     }
     Kohana::addPaths($paths);
     foreach ($paths as $path) {
         if (is_file($path . 'init.php')) {
             require_once $path . 'init.php';
         }
     }
 }
Esempio n. 12
0
 protected function submit($task, $id, $type)
 {
     $item = Jelly::select($type, $id);
     $redirect = HTML::uri(array('action' => Inflector::plural($type)));
     switch ($task) {
         case 'apply':
             $item->set($_POST)->save();
             $redirect = HTML::uri(array('action' => $type, 'task' => 'edit', 'id' => $item->id));
             $this->request->redirect($redirect);
             break;
         case 'save':
             $item->set($_POST)->save();
             $this->request->redirect($redirect);
             break;
         case 'cancel':
             $this->request->redirect($redirect);
             break;
         case 'delete':
             if ($ids = Arr::get($_POST, 'cid', NULL)) {
                 $items = Jelly::delete($item)->where(':primary_key', 'IN', $ids)->execute();
             }
             $this->request->redirect($redirect);
             break;
         case 'default':
             if (!$item->loaded()) {
                 $this->request->redirect($redirect);
             }
             break;
     }
     return $item;
 }
Esempio n. 13
0
 public function action_edit()
 {
     $this->require_login();
     $this->init_template('Update profile');
     $model = $this->auth->get_user();
     $model = Jelly::select('kadmium_user', $model->id());
     $this->show_edit_page_from_model('Profile', $model, false);
 }
Esempio n. 14
0
 /**
  * Loads the user object from database using username
  *
  * @param   string   username
  * @return  object   User Object
  */
 protected function _load_user($username)
 {
     $query = Jelly::select($this->_config['user_model'])->where($this->_config['columns']['username'], '=', $username);
     if (isset($this->_config['columns']['active'])) {
         $query = $query->where($this->_config['columns']['active'], '=', TRUE);
     }
     return $query->limit(1)->execute();
 }
Esempio n. 15
0
 /**
  * Tests that models in a collection aren't returned as references to the original
  * object but as a distinct model.
  */
 public function testIssue87()
 {
     $last = NULL;
     foreach (Jelly::select('post')->execute() as $post) {
         $this->assertNotEquals($post, $last);
         $last = $post;
     }
 }
Esempio n. 16
0
 /**
  * Tests for Jelly_Field_BelongsTo::get()
  *
  * @dataProvider  provider_get
  * @param         Jelly         $builder
  * @param         bool          $loaded
  * @return        void
  */
 public function test_get($builder, $loaded)
 {
     $this->assertTrue($builder instanceof Jelly_Builder);
     // Load the model
     $model = $builder->select();
     // Ensure it's loaded if it should be
     $this->assertSame($loaded, $model->loaded());
 }
Esempio n. 17
0
 public function action_index()
 {
     // Get the total number of users.
     $users = Jelly::select('user')->count();
     // Get the number of active users.
     $active_users = Jelly::select('user')->where('last_login', '>', time() - $this->active_time)->count();
     $this->template->content = View::factory('admin/index')->set('users', $users)->set('active_users', $active_users);
 }
Esempio n. 18
0
 public function action_index()
 {
     // Initialize the character class, and set the players character as the default.
     $char = new Character($this->character);
     // Load the users history, limit with 10
     $history = Jelly::select('user_history')->where(':primary_key', '=', $this->user->id)->limit(10)->execute();
     $this->template->content = View::factory('dashboard/index')->set('character', $this->character)->set('char', $char)->set('history', $history);
 }
Esempio n. 19
0
 public function action_category()
 {
     $id = $this->request->param('id');
     $page = $this->request->param('page') - 1;
     $this->view->title = Jelly::select('category', $id)->title;
     $this->content->products = Jelly::select('product')->belongs_to_category($id)->page($page)->execute();
     $this->content->pagination = new Pagination(array('total_items' => Jelly::select('product')->belongs_to_category($id)->count()));
 }
Esempio n. 20
0
 /**
  * Attempt to find a page in the CMS, return the response
  *
  * @param  string  The url to load, will be autodetected if needed
  * @return void
  */
 public function action_view($url = NULL)
 {
     if (Kohana::$profiling === TRUE) {
         // Start a new benchmark
         $benchmark = Profiler::start('Kohanut', 'Kohanut Controller');
     }
     // If no $url is passed, default to the server request uri
     if ($url === NULL) {
         $url = $_SERVER['REQUEST_URI'];
     }
     // Trim off Kohana::$base_url
     $url = preg_replace('#^' . Kohana::$base_url . '#', '', $url);
     // Ensure no trailing slash
     $url = preg_replace('/\\/$/', '', $url);
     // Ensure no leading slash
     $url = preg_replace('/^\\//', '', $url);
     // Remove anything ofter a ? or #
     $url = preg_replace('/[\\?#].+/', '', $url);
     // Try to find what to do on this url
     try {
         // Make sure the url is clean. See http://www.faqs.org/rfcs/rfc2396.html see section 2.3
         // TODO - this needs to be better
         if (preg_match("/[^\\/A-Za-z0-9-_\\.!~\\*\\(\\)]/", $url)) {
             Kohana::$log->add('INFO', "Kohanut - Request had unknown characters. '{$url}'");
             throw new Kohanut_Exception("Url request had unknown characters '{$url}'", array(), 404);
         }
         // Check for a redirect on this url
         Jelly::factory('kohanut_redirect')->set(array('url', $url))->go();
         // Find the page that matches this url, and isn't an external link
         $page = Jelly::select('kohanut_page')->where('url', '=', $url)->where('islink', '=', 0)->limit(1)->execute();
         if (!$page->loaded()) {
             // Could not find page in database, throw a 404
             Kohana::$log->add('INFO', "Kohanut - Could not find '{$url}' (404)");
             throw new Kohanut_Exception("Could not find '{$page->url}'", array(), 404);
         }
         // Set the status to 200, rather than 404, which was set by the router with the reflectionexception
         Kohanut::status(200);
         $out = $page->render();
     } catch (Kohanut_Exception $e) {
         // Find the error page
         $error = Jelly::select('kohanut_page')->where('url', '=', 'error')->limit(1)->execute();
         // If i couldn't find the error page, just give a generic message
         if (!$error->loaded()) {
             Kohanut::status(404);
             $this->request->response = View::factory('kohanut/generic404');
             return;
         }
         // Set the response
         $out = $error->render();
     }
     if (isset($benchmark)) {
         // Stop the benchmark
         Profiler::stop($benchmark);
     }
     // Set the response
     $this->request->response = $out;
 }
Esempio n. 21
0
 /**
  * Returns the record that the model has
  *
  * @param   Jelly_Model  $model
  * @param   mixed        $value
  * @param   boolean      $loaded
  * @return  mixed
  */
 public function get($model, $value)
 {
     if ($model->changed($this->name)) {
         // Return a real object
         return Jelly::select($this->foreign['model'])->where(':primary_key', '=', $value)->limit(1);
     } else {
         return Jelly::select($this->foreign['model'])->where($this->foreign['column'], '=', $model->id())->limit(1);
     }
 }
Esempio n. 22
0
 public function action_details()
 {
     $this->content->bind('form', $client);
     $this->content->bind('errors', $errors);
     $id = $this->request->param('id');
     $this->content->client = Jelly::select('client', $id);
     if (!$this->content->client->loaded()) {
         $this->request->redirect($this->_base);
     }
 }
Esempio n. 23
0
 public function input($prefix = 'jelly/field', $data = array())
 {
     if (!isset($data['options'])) {
         $options = Jelly::select($this->foreign['model'])->execute();
         foreach ($options as $v) {
             $data['options'][$v->id] = $v->name . ' - ' . $v->value . ' zł';
         }
     }
     return parent::input($prefix, $data);
 }
Esempio n. 24
0
 public static function set($key, $value, $description = '')
 {
     $setting = Jelly::select('setting')->where('setting', '=', $key)->limit(1)->execute();
     if (!$setting->loaded()) {
         Jelly::factory('setting')->set(array('setting' => $key, 'value' => $value, 'description' => $description))->save();
     } else {
         $setting->value = $value;
         $setting->save();
     }
 }
Esempio n. 25
0
 public function input(array $attributes = array())
 {
     $options = Jelly::select($this->field->foreign['model'])->execute()->as_array(':primary_key', ':name_key');
     $value = $this->model->__get($this->field->name);
     if ($this->field->null or empty($value) and !array_key_exists('not_empty', $this->field->rules)) {
         $options = array_merge(array('' => __('None')), $options);
     }
     $this->view->set(array('name' => $this->field->name, 'value' => $value, 'options' => $options, 'attributes' => $attributes));
     return parent::input();
 }
Esempio n. 26
0
 public function action_index(Params $param)
 {
     $this->content->bind('project', $project);
     $project = Jelly::select('project')->link($param->link)->with('category')->load();
     if (!$project->loaded()) {
         throw new Error404_Exception();
     }
     $this->template->title = $project->name . ' - ' . $project->category->title;
     $this->template->keywords = $project->keywords;
     $this->template->active = array('portfolio' => ' class="active"');
 }
Esempio n. 27
0
 /**
  * Controller default action
  */
 public function action_index()
 {
     $this->page_title = __('Welcome to :site', array(':site' => Kohana::config('site.site_name')));
     // Display news feed
     $newsfeed = new NewsFeed(self::$user);
     $newsfeed->max_items = 25;
     Widget::add('main', View_Module::factory('generic/newsfeed', array('newsfeed' => $newsfeed->as_array())));
     // Shout
     $shouts = Jelly::select('shout')->limit(10)->execute();
     Widget::add('side', View_Module::factory('generic/shout', array('mod_title' => __('Shouts'), 'shouts' => $shouts, 'can_shout' => Permission::has(new Model_Shout(), Model_Shout::PERMISSION_CREATE), 'errors' => array(), 'values' => array())));
 }
Esempio n. 28
0
 /**
  * Find new unique token
  *
  * @return  string
  */
 public function create_token()
 {
     while (true) {
         // Create random token
         $token = Text::random('alnum', 32);
         // Make sure it's unique
         if (!Jelly::select('user_token')->where('token', '=', $token)->count()) {
             return $token;
         }
     }
 }
Esempio n. 29
0
 public function action_details()
 {
     $id = $this->request->param('id');
     $product = Jelly::select('product')->load($id);
     if (!$product->loaded()) {
         $this->request->redirect($this->_base);
         // mozna albo to albo jakas strone z informacja "Brak takiego produktu"
     }
     $this->view->title = $product->name;
     $this->content->product = $product;
 }
Esempio n. 30
0
File: acl.php Progetto: jonlb/JxCMS
 private static function check_role_for_cap($cap, $role)
 {
     if (is_string($role)) {
         $role = Jelly::select('role')->where('name', '=', $role)->load();
     }
     foreach ($role->capabilities as $capability) {
         if (in_array($capability->capability, $cap)) {
             return TRUE;
         }
     }
     return FALSE;
 }