From 8269d73157518cae557446f311e1ab013aa8915c Mon Sep 17 00:00:00 2001 From: =?utf8?q?C=C4=83lin-Andrei=20Burloiu?= Date: Mon, 13 Feb 2012 23:56:30 +0200 Subject: [PATCH] add video model and controller partially implemented --- application/config/form_validation.php | 2 +- application/controllers/video.php | 149 +++++--------------- application/helpers/av_info_helper.php | 1 + application/helpers/video_helper.php | 21 +++ application/language/english/video_lang.php | 1 + application/models/videos_model.php | 83 ++++++++++- application/views/video/upload_view.php | 1 - 7 files changed, 142 insertions(+), 116 deletions(-) diff --git a/application/config/form_validation.php b/application/config/form_validation.php index 85c5ca8..6c5c1e6 100644 --- a/application/config/form_validation.php +++ b/application/config/form_validation.php @@ -129,7 +129,7 @@ $config = array( array( 'field'=>'video-upload-file', 'label'=>'lang:video_upload_file', - 'rules'=>'callback__required_upload|callback__valid_upload' + 'rules'=>'callback__valid_upload' ), array( 'field'=>'video-title', diff --git a/application/controllers/video.php b/application/controllers/video.php index eb4ed80..eb89005 100644 --- a/application/controllers/video.php +++ b/application/controllers/video.php @@ -18,38 +18,22 @@ class Video extends CI_Controller { public function index() { - } - public function test($video_id) + public function test() { - // Display page. - $params = array( 'title' => $this->config->item('site_name'), - 'css' => array( - 'video.css' - ), - 'js' => array( - 'jquery.ui.ajax_links_maker.js' - ), - //'metas' => array('description'=>'','keywords'=>'') - ); - $this->load->library('html_head_params', $params); - - // ** - // ** LOADING VIEWS - // ** - $this->load->view('html_begin', $this->html_head_params); - $this->load->view('header'); - - $main_params['content'] = - $this->load->view('echo', array('output'=> - $this->_ajax_comment(TRUE, $video_id)), - TRUE); - $main_params['side'] = $this->load->view('side_default', NULL, TRUE); - $this->load->view('main', $main_params); - - $this->load->view('footer'); - $this->load->view('html_end'); + $r = new HttpRequest('http://example.com/form.php', HttpRequest::METH_POST); + $r->setOptions(array('cookies' => array('lang' => 'de'))); + $r->addPostFields(array('user' => 'mike', 'pass' => 's3c|r3t')); + $r->addPostFile('image', 'profile.jpg', 'image/jpeg'); + try + { + echo $r->send()->getBody(); + } + catch (HttpException $ex) + { + echo $ex; + } } /** @@ -117,68 +101,6 @@ class Video extends CI_Controller { $this->load->view('footer'); $this->load->view('html_end'); } - -// public function upload() -// { -// $this->load->library('form_validation'); -// -// $this->form_validation->set_error_delimiters('', -// ''); -// $error_upload = ''; -// -// if ($this->form_validation->run('upload')) -// { -// if ($_FILES['video-upload-file']['tmp_name']) -// { -// // Upload library -// $config_upload['upload_path'] = './data/upload'; -// $this->load->library('upload', $config_upload); -// -// $b_validation = $this->upload->do_upload('video-upload-file'); -// $error_upload = -// $this->upload->display_errors('', -// ''); -// } -// else -// { -// $b_validation = FALSE; -// } -// } -// else -// $b_validation = FALSE; -// -// if ($b_validation === FALSE) -// { -// $params = array('title' => -// $this->lang->line('ui_nav_menu_upload') -// .' – ' -// . $this->config->item('site_name'), -// //'metas' => array('description'=>'') -// ); -// $this->load->library('html_head_params', $params); -// -// // ** -// // ** LOADING VIEWS -// // ** -// $this->load->view('html_begin', $this->html_head_params); -// $this->load->view('header', -// array('selected_menu' => 'upload')); -// -// $main_params['content'] = $this->load->view( -// 'video/upload_view', -// array('error_upload'=> $error_upload), -// TRUE); -// $main_params['side'] = $this->load->view('side_default', NULL, TRUE); -// $this->load->view('main', $main_params); -// -// $this->load->view('footer'); -// $this->load->view('html_end'); -// } -// else -// { -// -// } -// } public function upload() { @@ -186,7 +108,8 @@ class Video extends CI_Controller { $this->form_validation->set_error_delimiters('', ''); - $error_upload = ''; + + // TODO check if user is logged in if ($this->form_validation->run('upload') === FALSE) { @@ -206,9 +129,7 @@ class Video extends CI_Controller { array('selected_menu' => 'upload')); $main_params['content'] = $this->load->view( - 'video/upload_view', - array('error_upload'=> $error_upload), - TRUE); + 'video/upload_view', array(), TRUE); $main_params['side'] = $this->load->view('side_default', NULL, TRUE); $this->load->view('main', $main_params); @@ -217,7 +138,20 @@ class Video extends CI_Controller { } else { - + $this->load->model('videos_model'); + $this->load->helper('video'); + + $file_name = './data/upload/'. $_FILES['video-upload-file']['name']; + $av_info = get_av_info($file_name); + + // TODO category_id, user_id +// $this->videos_model->add_video( +// $this->input->post('video-title'), +// $this->input->post('video-description'), +// $this->input->post('video-tags'), +// $av_info, 0, 1); + + // TODO call CIS } } @@ -351,16 +285,6 @@ class Video extends CI_Controller { return TRUE; } - public function _required_upload($file) - { - if ($_FILES['video-upload-file']['tmp_name']) - { - return TRUE; - } - - return FALSE; - } - public function _valid_upload($file) { if ($_FILES['video-upload-file']['tmp_name']) @@ -375,12 +299,17 @@ class Video extends CI_Controller { { return TRUE; } - - $this->form_validation->set_message('_valid_upload', - $this->upload->display_errors('', - '')); + else + { + $this->form_validation->set_message('_valid_upload', + $this->upload->display_errors('', + '')); + return FALSE; + } } + $this->form_validation->set_message('_valid_upload', + $this->lang->line('_required_upload')); return FALSE; } diff --git a/application/helpers/av_info_helper.php b/application/helpers/av_info_helper.php index 013dab3..b3f3a55 100644 --- a/application/helpers/av_info_helper.php +++ b/application/helpers/av_info_helper.php @@ -1,6 +1,7 @@ + *
  • width
  • + *
  • height
  • + *
  • dar (display aspect ratio)
  • + *
  • duration (formated as [HH:]mm:ss)
  • + *
  • size (in bytes)
  • + * + */ +function get_av_info($file_name) +{ + // TODO use ffprobe to return width, height, DAR, duration and size of a video + + return array('width'=> 800, 'height'=> 600, 'dar'=> '16:9', + 'duration'=> '00:10', 'size'=> 1101693); +} + /* End of file video_helper.php */ /* Location: ./application/helpers/video_helper.php */ \ No newline at end of file diff --git a/application/language/english/video_lang.php b/application/language/english/video_lang.php index 056b751..459a5df 100644 --- a/application/language/english/video_lang.php +++ b/application/language/english/video_lang.php @@ -22,6 +22,7 @@ $lang['video_description'] = 'Description'; $lang['video_tags'] = 'Tags'; $lang['video_tags_hint'] = 'comma separated tags'; $lang['video_submit_upload'] = 'Upload'; +$lang['video_msg_video_uploaded'] = 'Your video has been uploaded and is now being processed.'; /* End of file video_lang.php */ diff --git a/application/models/videos_model.php b/application/models/videos_model.php index afcfd3d..b03cd16 100644 --- a/application/models/videos_model.php +++ b/application/models/videos_model.php @@ -166,11 +166,11 @@ class Videos_model extends CI_Model { * If $name does not match with the video's `name` from the DB an error is * marked in the key 'err'. If it's NULL it is ignored. * - * @access public - * @param string $id video's `id` column from `videos` DB table - * @param string $name video's `name` column from `videos` DB + * @access public + * @param string $id video's `id` column from `videos` DB table + * @param string $name video's `name` column from `videos` DB * table. NULL means there is no name provided. - * @return array an associative list with information about a video + * @return array an associative list with information about a video * with the following keys: *