Guest User

Untitled

a guest
Jul 16th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.23 KB | None | 0 0
  1. <?php defined('SYSPATH') OR die('No direct access allowed.');
  2.  
  3. class Signature_Controller extends AuthorizedController{
  4. public function index(){
  5. // Loading common view
  6. $view = View::factory('signature')
  7. ->set('header', new View('header'))
  8. ->set('footer', new View('footer'))
  9. ->set('menubar', new View('menubar'));
  10.  
  11. // User object
  12. $user = ORM::factory('user', $this->session->get('user_id',false));
  13.  
  14. $view->render(true);
  15. }
  16. public function _render_form($form){
  17. View::factory('addsignature')
  18. ->set('header', new View('header'))
  19. ->set('footer', new View('footer'))
  20. ->set('form',$form->get(true))
  21. ->set('menubar', new View('menubar'))
  22. ->render(true);
  23. }
  24. public function _check_feed_source($feed_source){
  25. $url = parse_url($feed_source);
  26.  
  27. // Building url correct condition
  28. $condition = isset($url['scheme'])
  29. && ($url['scheme']=='http' || $url['scheme']=='https')
  30. && isset($url['host']) && !empty($url['host'])
  31. && isset($url['path']) && !empty($url['path']);
  32.  
  33. if($condition==false){
  34. return false;
  35. }
  36.  
  37. // Checking whether the url is accessible
  38.  
  39. $feed = new SimplePie();
  40. $feed->set_feed_url($feed_source);
  41. $feed->enable_order_by_date(false);
  42. $feed->set_cache_location(Kohana::config('feed.cache_path'));
  43. $feed->init();
  44.  
  45. // If we get a response return it valid
  46. if($feed->get_title()){
  47. return true;
  48. }else{
  49. return false;
  50. }
  51. /*
  52. * @todo Feed must be validated by an feed validator or xml validator.
  53. */
  54. }
  55. public function add(){
  56. // A wizard to add new signature
  57.  
  58. $form = Formo::factory()
  59. ->add('Friendly feed name')
  60. ->add('Feed source')
  61. ->add('submit', 'value=Next')
  62. ->add_rule('friendly_feed_name','alpha_numeric','Name must be alpha numeric')
  63. ->add_rule('friendly_feed_name','length[6,32]','Size of name should be in between 6 to 32 characters')
  64. ->add_rule('feed_source','url','Feed source must be a valid url')
  65. ->add_rule('feed_source',array($this, '_check_feed_source'),'Feed source must be a valid accessible remote feed url');
  66. if($form->validate()){
  67. // Get the values
  68. $data = $form->get_values();
  69.  
  70. // Save the values in session
  71. $this->session->set('feed_source',$data['feed_source']);
  72. $this->session->set('feed_name',$data['friendly_feed_name']);
  73.  
  74. // Forword to next part of the wizard
  75. url::redirect('/signature/add2');
  76.  
  77. }else{
  78. $this->_render_form($form);
  79. }
  80. }
  81. public function _check_text_color($color){
  82. return preg_match('/^[\dA-Ha-h]{6}$/', $color);
  83. }
  84. public function _check_text_format($text_format){
  85. if(empty($text_format)){
  86. return true;
  87. }else{
  88. return preg_match('/^[\s \w @\-_\,\.\%]{1,64}$/', $text_format);
  89. }
  90. }
  91. public function add2(){
  92. // A wizard to add new signature
  93.  
  94. // Get the feed
  95.  
  96. $feed = new SimplePie();
  97. $feed->set_feed_url($this->session->get('feed_source',false));
  98. $feed->enable_order_by_date(false);
  99. $feed->set_cache_location(Kohana::config('feed.cache_path'));
  100. $feed->init();
  101.  
  102. $feed->get_item_quantity();
  103.  
  104. $form = Formo::factory()
  105. ->add_select('Item index',range(0,$feed->get_item_quantity()-1,1), 'Item index')
  106. ->add_select('Item element name',array('title'=>'Title','link'=>'Link','description'=>'Description'))
  107. ->add('Text format')
  108. ->add('Text color')
  109. ->add('submit', 'value=Show Preview')
  110. ->add_rule('item_index','digit','Item index must be a valid index')
  111. ->add_rule('item_element_name','alpha_dash','Must be a valid Feed element name')
  112. ->add_rule('text_color', array($this, '_check_text_color'),'Must be in hexadecimal color coded format')
  113. ->add_rule('text_format',array($this,'_check_text_format'),'only @-%_,. and alphanumeric characters with spaces allowed');
  114.  
  115.  
  116. if($form->validate()){
  117. // Get the values
  118. $data = $form->get_values();
  119.  
  120. // Save the values in session
  121. $this->session->set('item_index',$data['item_index']);
  122. $this->session->set('item_element_name',$data['item_element_name']);
  123. $this->session->set('text_color',$data['text_color']);
  124. $this->session->set('text_format',$data['text_format']);
  125.  
  126. // Forword to next part of the wizard
  127. // url::redirect('/signature/add3');
  128. echo "Will show preview here";
  129.  
  130. }else{
  131. $this->_render_form($form);
  132. }
  133. }
  134. }
Add Comment
Please, Sign In to add comment