Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php defined('SYSPATH') OR die('No direct access allowed.');
- class Signature_Controller extends AuthorizedController{
- public function index(){
- // Loading common view
- $view = View::factory('signature')
- ->set('header', new View('header'))
- ->set('footer', new View('footer'))
- ->set('menubar', new View('menubar'));
- // User object
- $user = ORM::factory('user', $this->session->get('user_id',false));
- $view->render(true);
- }
- public function _render_form($form){
- View::factory('addsignature')
- ->set('header', new View('header'))
- ->set('footer', new View('footer'))
- ->set('form',$form->get(true))
- ->set('menubar', new View('menubar'))
- ->render(true);
- }
- public function _check_feed_source($feed_source){
- $url = parse_url($feed_source);
- // Building url correct condition
- $condition = isset($url['scheme'])
- && ($url['scheme']=='http' || $url['scheme']=='https')
- && isset($url['host']) && !empty($url['host'])
- && isset($url['path']) && !empty($url['path']);
- if($condition==false){
- return false;
- }
- // Checking whether the url is accessible
- $feed = new SimplePie();
- $feed->set_feed_url($feed_source);
- $feed->enable_order_by_date(false);
- $feed->set_cache_location(Kohana::config('feed.cache_path'));
- $feed->init();
- // If we get a response return it valid
- if($feed->get_title()){
- return true;
- }else{
- return false;
- }
- /*
- * @todo Feed must be validated by an feed validator or xml validator.
- */
- }
- public function add(){
- // A wizard to add new signature
- $form = Formo::factory()
- ->add('Friendly feed name')
- ->add('Feed source')
- ->add('submit', 'value=Next')
- ->add_rule('friendly_feed_name','alpha_numeric','Name must be alpha numeric')
- ->add_rule('friendly_feed_name','length[6,32]','Size of name should be in between 6 to 32 characters')
- ->add_rule('feed_source','url','Feed source must be a valid url')
- ->add_rule('feed_source',array($this, '_check_feed_source'),'Feed source must be a valid accessible remote feed url');
- if($form->validate()){
- // Get the values
- $data = $form->get_values();
- // Save the values in session
- $this->session->set('feed_source',$data['feed_source']);
- $this->session->set('feed_name',$data['friendly_feed_name']);
- // Forword to next part of the wizard
- url::redirect('/signature/add2');
- }else{
- $this->_render_form($form);
- }
- }
- public function _check_text_color($color){
- return preg_match('/^[\dA-Ha-h]{6}$/', $color);
- }
- public function _check_text_format($text_format){
- if(empty($text_format)){
- return true;
- }else{
- return preg_match('/^[\s \w @\-_\,\.\%]{1,64}$/', $text_format);
- }
- }
- public function add2(){
- // A wizard to add new signature
- // Get the feed
- $feed = new SimplePie();
- $feed->set_feed_url($this->session->get('feed_source',false));
- $feed->enable_order_by_date(false);
- $feed->set_cache_location(Kohana::config('feed.cache_path'));
- $feed->init();
- $feed->get_item_quantity();
- $form = Formo::factory()
- ->add_select('Item index',range(0,$feed->get_item_quantity()-1,1), 'Item index')
- ->add_select('Item element name',array('title'=>'Title','link'=>'Link','description'=>'Description'))
- ->add('Text format')
- ->add('Text color')
- ->add('submit', 'value=Show Preview')
- ->add_rule('item_index','digit','Item index must be a valid index')
- ->add_rule('item_element_name','alpha_dash','Must be a valid Feed element name')
- ->add_rule('text_color', array($this, '_check_text_color'),'Must be in hexadecimal color coded format')
- ->add_rule('text_format',array($this,'_check_text_format'),'only @-%_,. and alphanumeric characters with spaces allowed');
- if($form->validate()){
- // Get the values
- $data = $form->get_values();
- // Save the values in session
- $this->session->set('item_index',$data['item_index']);
- $this->session->set('item_element_name',$data['item_element_name']);
- $this->session->set('text_color',$data['text_color']);
- $this->session->set('text_format',$data['text_format']);
- // Forword to next part of the wizard
- // url::redirect('/signature/add3');
- echo "Will show preview here";
- }else{
- $this->_render_form($form);
- }
- }
- }
Add Comment
Please, Sign In to add comment