Esempio n. 1
0
 public function article($uri)
 {
     $this->template->content = View::factory('blog/view')->bind('post', $post)->bind('comments', $comments)->bind('form', $form);
     $post = ORM::factory('blog_post', (string) $uri);
     // Show 404 if we don't find posts
     if (!$post->loaded) {
         Event::run('system.404');
     }
     $comments = $post->blog_comments;
     $this->head->title->prepend($post->title);
     if (!($post->comment_status === 'open' and config::get('blog.comment_status') === 'open')) {
         return;
     }
     $form = Formo::factory()->plugin('csrf')->add('text', 'author', array('label' => __('Name')))->add('text', 'email', array('label' => __('Email')))->add('text', 'url', array('label' => __('Homepage')))->add('textarea', 'content', array('label' => __('Comment')))->add('submit', 'submit', array('label' => __('Submit')))->pre_filter('all', 'trim')->pre_filter('author', 'security::xss_clean')->pre_filter('content', 'security::xss_clean')->pre_filter('url', 'security::xss_clean')->pre_filter('url', 'format::url')->add_rule('author', 'required', __('You must provide your name'))->add_rule('author', 'length[2,40]', __('Your Name is too long'))->add_rule('email', 'valid::email', __('Email address is not valid'))->add_rule('content', 'required', __('You must enter a comment'));
     if (config::get('blog.enable_captcha') === 'yes') {
         $form->add('captcha', 'security', array('label' => __('Security code')));
         $form->security->error_msg = __('Invalid security code');
     }
     if ($form->validate()) {
         $comment = ORM::factory('blog_comment');
         $comment->author = $form->author->value;
         $comment->email = $form->email->value;
         $comment->content = $form->content->value;
         $comment->url = $form->url->value;
         $comment->ip = $this->input->ip_address();
         $comment->agent = Kohana::$user_agent;
         $comment->date = date("Y-m-d H:i:s", time());
         $post->add_comment($comment);
         Event::run('blog.comment_added', $comment);
         Cache::instance()->delete('s7n_blog_feed');
         Cache::instance()->delete('s7n_blog_feed_comments');
         url::redirect($post->url());
     }
     $form = View::factory('blog/form_comment', $form->get(TRUE));
 }
Esempio n. 2
0
 public function html()
 {
     foreach ($this->_field->get('options') as $label => $options) {
         $this->_field->append(Formo::field($label, 'option', $options));
     }
     $this->_view->set_var('tag', 'optgroup')->attr('label', $this->_field->alias());
 }
Esempio n. 3
0
 public function html()
 {
     foreach ($this->field->get('options') as $label => $options) {
         $this->field->append(Formo::field($label, 'option', $options));
     }
     $this->decorator->set('tag', 'select')->attr('name', $this->name());
 }
Esempio n. 4
0
 public function add($client = NULL)
 {
     $client_id = $this->input->post('client') ? $this->input->post('client') : $client;
     if ($client_id == '' and $client_id != '-') {
         url::redirect('clients/new?client=' . urlencode($this->input->post('client_new')));
     }
     $invoices = ORM::factory('invoice');
     $clients = $this->cache->get('client') ? $this->cache->get('client') : ORM::factory('client')->find_all_as_array();
     // $client_list = array();
     foreach ($clients as $client) {
         $client_list[$client['id']] = $client['company'];
     }
     $data = array('hour', 'day', 'service', 'product');
     $form = Formo::factory('invoice_add')->set('class', 'simple-form')->add('invoice_id', array('class' => 'size', 'label' => 'Invoice ID'))->add('po_number', array('class' => 'size', 'label' => 'P.O. Number', 'required' => FALSE))->add_select('client', $client_list, array('class' => 'size', 'value' => $client_id))->add_textarea('notes', array('class' => 'size', 'required' => FALSE))->add('qty', array('class' => 'qty'))->add_select('type', $data)->add_textarea('description')->add('unit_price', array('class' => 'qty'))->add('submit', 'Submit');
     if ($form->validate()) {
         // echo Kohana::debug($form); die;
         $invoice = ORM::factory('invoice');
         $invoice->invoice_no = $form->invoice_id->value;
         $invoice->po_number = $form->po_number->value;
         $invoice->client_id = $form->client->value;
         $invoice->notes = $form->notes->value;
         $invoice->save();
         $item = ORM::factory('item');
         $item->qty = $form->qty->value;
         $item->description = $form->description->value;
         $item->unit_price = $form->unit_price->value;
         $item->type = $form->type->value;
         $item->invoice_id = $invoice->id;
         $item->save() and $this->cache->delete_tag('clients');
         url::redirect('invoices');
     }
     $this->template->content = new View('invoices/add', $form->get(TRUE));
     $this->template->content->client_name = $client_list[$client_id];
     $this->template->content->item_view = new View('invoices/items', $form->get(TRUE));
 }
Esempio n. 5
0
	public function html()
	{
		foreach ($this->_field->get('options') as $alias => $options)
		{
			$this->_field->append(Formo::field($alias, 'checkbox', $options));
		}
	}
Esempio n. 6
0
	public function html()
	{
		foreach ($this->_field->get('options') as $label => $options)
		{
			$this->_field->append(Formo::field($label, 'radio', $options));
		}
	}
Esempio n. 7
0
 public function html()
 {
     $this->render_field->append(Formo::field('', 'option'));
     foreach ($this->render_field->options as $label => $options) {
         $this->render_field->append(Formo::field($label, 'option', $options));
     }
     $this->render_field->set('tag', 'select')->attr('name', $this->field->alias());
 }
Esempio n. 8
0
 protected function _get_val()
 {
     $new_value = $this->_field->get('new_value');
     if (Formo::is_set($new_value) === TRUE) {
         return $new_value;
     }
     return ($val = $this->_field->get('value')) ? $val : array('name' => '', 'type' => '', 'tmp_name' => '', 'error' => '', 'size' => '');
 }
Esempio n. 9
0
 public static function shortcut($defs, $value, $tag = 'h3', $props = NULL)
 {
     $name = strtolower(str_replace(' ', '_', $value));
     $info = self::process_info($defs, array(), $name);
     $info['tags'] = array('<' . $tag . Formo::quicktagss($props) . '>', '</' . $tag . '>');
     $info['value'] = $value;
     return new Formo_h_Driver($name, $info);
 }
Esempio n. 10
0
 public function getval()
 {
     // If the form was sent but the field wasn't set, return empty array as value
     if ($this->field->sent() and Formo::notset($this->field->get('new_value'))) {
         return FALSE;
     }
     // Otherwise return the value that's set
     return !Formo::notset($this->field->get('new_value')) ? (bool) $this->field->get('new_value') : (bool) $this->field->get('value');
 }
Esempio n. 11
0
 public function checked()
 {
     $parent_newval = $this->field->parent()->get('new_value');
     $parent_value = $this->field->parent()->get('value');
     if (Formo::is_set($parent_newval) === FALSE and !$this->field->parent(Formo::PARENT)->sent()) {
         return in_array($this->val(), (array) $parent_value);
     }
     return in_array($this->field->val(), (array) $parent_newval);
 }
Esempio n. 12
0
 protected function _get_val()
 {
     $new_value = $this->_field->get('new_value');
     // If the form was sent but the field wasn't set, return FALSE
     if ($this->_field->sent() and Formo::is_set($new_value) === FALSE) {
         return FALSE;
     }
     // Otherwise return the value that's set
     return Formo::is_set($new_value) === TRUE ? (bool) $new_value : (bool) $this->_field->get('value');
 }
Esempio n. 13
0
 public function blank($element = '', $list = FALSE)
 {
     $form = Formo::instance($this->formo_name);
     $list = !$list ? $element : $list;
     $element = $list ? $element : Formo::$last_accessed;
     if (!is_array($list)) {
         $list = TRUE;
     }
     $form->{$this->name}->blank = $list;
 }
Esempio n. 14
0
 /**
  * Create a new field
  * 
  * @access public
  * @param mixed $alias
  * @param mixed $driver. (default: NULL)
  * @param mixed array $options. (default: NULL)
  * @return void
  */
 public function __construct($alias, $driver = NULL, $value = NULL, array $options = NULL)
 {
     $options = func_get_args();
     $orig_options = $options;
     $options = Formo::args(__CLASS__, __FUNCTION__, $options);
     // Add all the options to the object
     $this->load_options($options);
     // Run the driver's post_construct() method
     $this->driver()->post_construct();
 }
Esempio n. 15
0
 public function check($group, $element = '')
 {
     $form = Formo::instance($this->formo_name);
     if (is_object($form->{$group}) and get_class($form->{$group}) == 'Formo_Group') {
         foreach (Formo::splitby($element) as $el) {
             $form->{$group}->{$el}->checked = TRUE;
         }
     } else {
         $form->{$group}->checked = TRUE;
     }
 }
Esempio n. 16
0
File: view.php Progetto: refo/kohana
	/**
	 * Retrieve the label text
	 *
	 * @access public
	 * @return void
	 */
	public function label($utf8 = FALSE)
	{
		$label = ($label = $this->_field->get('label'))
			? $label
			: $this->_field->alias();

		// Translate if needed
		return (Formo::config($this->_field, 'translate') === TRUE)
			? __($label)
			: $label;
	}
Esempio n. 17
0
 protected function _add_input_rules()
 {
     // Grab the rules from the formo config
     $rules = Formo::config($this->_field, 'input_rules.' . $this->get_type());
     if ($rules) {
         // Attach rules to the field's parent
         $this->_field->parent()->rules($this->_field->alias(), $rules);
     }
     if ($bindings = Formo::config($this->_field, 'formo.html5_bindings.' . $this->get_type())) {
         $this->_field->set('bindings', $bindings);
     }
 }
Esempio n. 18
0
 public function render()
 {
     $sel = '';
     $sel .= '<select name="' . $this->name . '"' . Formo::quicktagss($this->_find_tags()) . ">" . "\n";
     foreach ($this->values as $k => $v) {
         $k = preg_replace('/_[bB][lL][aA][nN][kK][0-9]*_/', '', $k);
         $selected = $v == $this->value ? " selected='selected'" : '';
         $sel .= "\t\t" . '<option value="' . $v . '"' . $selected . '>' . $k . '</option>' . "\n";
     }
     $sel .= "</select>";
     return $sel;
 }
Esempio n. 19
0
 public function translate($str)
 {
     $new_str = $str;
     if (Formo::config($this->_field, 'use_messages') === TRUE) {
         $msg_file = Formo::config($this->_field, 'message_file');
         $new_str = Kohana::message($msg_file, $str, $str);
     }
     if (Formo::config($this->_field, 'translate') === TRUE) {
         $new_str = __($new_str);
     }
     return $new_str;
 }
Esempio n. 20
0
 public function index()
 {
     $this->head->title->append(__('Settings'));
     $this->template->title = __('Settings');
     $form = Formo::factory()->plugin('csrf')->add('text', 'site_title', array('label' => __('Site title'), 'value' => config::get('s7n.site_title')))->add_select('theme', theme::available(), array('label' => __('Theme'), 'value' => config::get('s7n.theme')))->add('submit', 'submit', array('label' => __('Save')));
     if ($form->validate()) {
         config::set('s7n.site_title', $form->site_title->value);
         config::set('s7n.theme', $form->theme->value);
         message::info(__('Settings edited successfully'), 'admin/settings');
     }
     $this->template->content = View::factory('settings/settings', $form->get(TRUE));
 }
Esempio n. 21
0
 public function render()
 {
     // create captcha object here if it's an image
     if (!$this->captcha) {
         $this->captcha = Captcha::factory($this->group);
     }
     // add the clear html to the close tag
     $this->close = $this->clear . $this->close;
     // only load the captcha if we're not sure it's a human
     if (!$this->captcha->promoted()) {
         return $this->captcha_open . "\n" . $this->captcha->render(TRUE) . "\n" . $this->captcha_close . $this->input_open . '<input type="text" name="' . $this->name . '"' . Formo::quicktagss($this->_find_tags()) . ' />' . "\n" . $this->input_close;
     }
 }
Esempio n. 22
0
 /**
  * Create a new field
  *
  * @access public
  * @param mixed $alias
  * @param mixed $driver. (default: NULL)
  * @param mixed array $options. (default: NULL)
  * @return void
  */
 public function __construct($alias, $driver = NULL, $value = NULL, array $options = NULL)
 {
     $options = func_get_args();
     $orig_options = $options;
     $options = Formo::args(__CLASS__, __FUNCTION__, $options);
     // Always process the driver first
     $driver = $options['driver'];
     unset($options['driver']);
     $options = Arr::merge(array('driver' => $driver), $options);
     // Add all the options to the object
     $this->_load_options($options);
     // Run the driver's post_construct() method
     $this->driver()->post_construct();
 }
Esempio n. 23
0
 public function action_update()
 {
     $element = ORM::Factory($this->_orm_model, $_GET['id']);
     $form = Formo::form()->orm('load', $element);
     $form->add('update', 'submit', 'Save');
     if ($form->load($_POST)->validate()) {
         if ($this->_update_passed($form, $element)) {
             $element->save();
             $form->orm('save_rel', $element);
             $this->request->redirect(Route::get($this->_route_name)->uri(array('controller' => Request::current()->controller())));
         }
     } else {
         $this->_update_failed($form, $element);
     }
     return $this->render('update', array('form' => $form));
 }
Esempio n. 24
0
 /**
  * @dataProvider provider_attr
  */
 public function test_attr(array $construct, $attr, $val, array $checks)
 {
     $expected = TRUE;
     $result = TRUE;
     $field = Formo::factory($construct);
     if (is_array($attr)) {
         $field->attr($attr);
     } else {
         $field->attr($attr, $val);
     }
     foreach ($checks as $key => $value) {
         if ($field->attr($key) !== $value) {
             $result = FALSE;
         }
     }
     $this->assertSame($expected, $result);
 }
Esempio n. 25
0
 /**
  * Adds a field to a form
  *
  * @access public
  * @param mixed $alias
  * @param mixed $driver. (default: NULL)
  * @param mixed $value. (default: NULL)
  * @param mixed array $options. (default: NULL)
  * @return object
  */
 public function add($alias, $driver = NULL, $value = NULL, array $options = NULL)
 {
     // If Formo instnace was passed
     if ($alias instanceof Formo_Form) {
         return $this->add_object($alias);
     }
     if ($driver instanceof Formo_Form) {
         return $this->add_object($driver->alias($alias));
     }
     if ($value instanceof Formo_Form) {
         return $this->add_object($value->set('driver', $driver)->alias($alias));
     }
     $orig_options = $options;
     $options = func_get_args();
     $options = Formo::args(__CLASS__, __FUNCTION__, $options);
     // If a driver is named but not an alias, make the driver text and the alias the driver
     if (empty($options['driver'])) {
         $options['driver'] = Arr::get($this->config, 'default_driver', 'text');
     }
     // Allow loading rules, callbacks, filters upon adding a field
     $validate_options = array('rules', 'triggers', 'filters');
     // Create the array
     $validate_settings = array();
     foreach ($validate_options as $option) {
         if (!empty($options[$option])) {
             $validate_settings[$option] = $options[$option];
             unset($options[$option]);
         }
     }
     // Create the new field
     $field = Formo::field($options);
     $this->append($field);
     // Add the validation rules
     foreach ($validate_settings as $method => $array) {
         foreach ($array as $callback => $opts) {
             if ($opts instanceof Formo_Validator_Item) {
                 // The rules method will suffice for all Formo_Validator_Item objects
                 $field->rules(NULL, $opts);
                 continue;
             }
             $args = array(NULL, $callback, $opts);
             call_user_func_array(array($field, $method), $args);
         }
     }
     return $this;
 }
Esempio n. 26
0
 public function edit($id)
 {
     $client = ORM::factory('client', (int) $id);
     $form = Formo::factory('client_edit')->set('class', 'smart-form')->add('company', array('class' => 'size', 'value' => $client->company))->add('address', array('class' => 'size', 'value' => $client->address))->add('address1', array('class' => 'size', 'value' => $client->address1, 'required' => FALSE))->add('city', array('class' => 'size', 'value' => $client->city))->add('postcode', array('class' => 'size', 'value' => $client->postcode))->add('phone', array('class' => 'size', 'value' => $client->phone))->add('fax', array('class' => 'size', 'value' => $client->fax, 'required' => FALSE))->add('url', array('label' => 'Website', 'class' => 'size', 'value' => $client->url, 'required' => FALSE))->add_rule('url', 'valid::url')->add('submit', 'Submit');
     if ($form->validate()) {
         $client->company = $form->company->value;
         $client->address = $form->address->value;
         $client->address1 = $form->address1->value;
         $client->city = $form->city->value;
         $client->postcode = $form->postcode->value;
         $client->phone = $form->phone->value;
         $client->fax = $form->fax->value;
         $client->url = $form->url->value;
         $client->save() and $this->cache->delete_tag('clients') and url::redirect('clients');
     }
     $this->template->content = new View('clients/add');
     $this->template->content->form = $form;
 }
Esempio n. 27
0
 public function database_setup()
 {
     $form = Formo::factory('database_setup')->set('class', 'smart-form')->add('host', array('class' => 'size'))->add('username', array('class' => 'size'))->add('password', array('class' => 'size', 'required' => FALSE))->type('password')->add('database', array('class' => 'size'))->add('prefix', array('class' => 'size', 'value' => 'bc_'))->add('checkbox', 'drop', array('label' => 'Drop Tables', 'required' => FALSE))->add('checkbox', 'data', array('label' => 'Insert Data', 'required' => FALSE))->add('submit', 'submit', array('value' => __('Install'), 'class' => 'button'));
     if ($form->validate()) {
         try {
             setup::check_db($form->username->value, $form->password->value, $form->host->value, $form->database->value, $form->prefix->value);
             $data = array('username' => $form->username->value, 'password' => $form->password->value, 'host' => $form->host->value, 'database' => $form->database->value, 'prefix' => $form->prefix->value, 'data' => $form->data->checked);
             Session::instance()->set('database_data', $data);
             $redirect = $form->drop->checked ? 'install/step_drop_tables' : 'install/step_create_structure';
             url::redirect($redirect);
         } catch (Exception $e) {
             $error = $e->getMessage();
             Session::instance()->delete('conn_status');
             switch ($error) {
                 case 'access':
                     $conn_error = __('Wrong username or password.');
                     break;
                 case 'unknown_host':
                     $conn_error = __('Could not find the host.');
                     break;
                 case 'connect_to_host':
                     $conn_error = __('Could not connect to host.');
                     break;
                 case 'create':
                     $conn_error = __('Could not create the database.');
                     break;
                 case 'select':
                     $conn_error = __('Could not select the database.');
                     break;
                 case 'prefix':
                     $conn_error = __('The Table Prefix you chose is already in use.');
                     break;
                 default:
                     $conn_error = $error;
             }
         }
     }
     $this->template->page_title = __('Database Setup');
     $data = $form->get(TRUE);
     $this->template->content = new View('install/database_setup', $data);
     $this->template->content->success = __('%bc will work correctly with your environment', array('%bc' => Kohana::config('bc.bc')));
     $this->template->content->error = isset($conn_error) ? $conn_error : '';
     $this->template->content->passed = Session::instance()->get('conn_status');
 }
Esempio n. 28
0
 public function do_functions()
 {
     $use = !$this->form->_validated ? 'on_failure' : 'on_success';
     foreach ($this->{$use} as $array) {
         list($function, $args) = Formo::into_function($array['function']);
         if ($array['args']) {
             array_unshift($args, $array['args']);
         }
         array_unshift($args, $this->form->get_values());
         switch ($function) {
             case 'url::redirect':
                 url::redirect($args[count($args) - 1]);
                 break;
             default:
                 call_user_func_array($function, $args);
                 return;
         }
     }
 }
Esempio n. 29
0
 public function change_client($id = NULL)
 {
     $contact = ORM::factory('contact', $id);
     if ($contact->id == '') {
         $this->session->set_flash('contact', 'There is no contact associated with the id provided.');
         url::redirect();
     }
     $clients = $this->cache->get('client') ? $this->cache->get('client') : ORM::factory('client')->find_all_as_array();
     // $client_list = array();
     foreach ($clients as $client) {
         $client_list[$client['id']] = $client['company'];
     }
     $form = Formo::factory('contact_edit')->set('class', 'smart-form')->add_select('client', $client_list, array('value' => $contact->client_id))->add('submit', 'Submit');
     if ($form->validate()) {
         $contact->client_id = $form->client->value;
         $contact->save() and $this->cache->delete_tag('contacts') and url::redirect('clients');
     }
     $this->template->content = new View('contacts/add');
     $this->template->content->form = $form;
 }
Esempio n. 30
0
 public function edit($id)
 {
     $comment = ORM::factory('blog_comment', (int) $id);
     if (!$comment->loaded) {
         message::error(__('Invalid ID'), 'admin/blog');
     }
     $this->head->title->append(__('Edit comment #%id', array('%id' => $comment->id)));
     $this->template->title .= __('Edit comment #%id', array('%id' => $comment->id));
     $form = Formo::factory()->plugin('csrf')->add('text', 'author', array('label' => __('Author'), 'value' => $comment->author))->add('text', 'email', array('label' => __('Email'), 'value' => $comment->email))->add('text', 'url', array('label' => __('Homepage'), 'value' => $comment->url))->add('textarea', 'content', array('label' => __('Comment'), 'value' => $comment->content))->add('submit', 'submit', array('label' => __('Save')));
     if ($form->validate()) {
         $comment->author = $form->author->value;
         $comment->email = $form->email->value;
         $comment->url = $form->url->value;
         $comment->content = $form->content->value;
         $comment->save();
         Cache::instance()->delete('s7n_blog_feed_comments');
         message::info(__('Comment edited successfully'), 'admin/blog/comments/view/' . $comment->blog_post_id);
     }
     $this->template->content = View::factory('blog/editcomment', $form->get(TRUE));
 }