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;
+ }
}
/**
$this->load->view('footer');
$this->load->view('html_end');
}
-
-// public function upload()
-// {
-// $this->load->library('form_validation');
-//
-// $this->form_validation->set_error_delimiters('<span class="error">',
-// '</span>');
-// $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('<span class="error">',
-// '</span>');
-// }
-// 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()
{
$this->form_validation->set_error_delimiters('<span class="error">',
'</span>');
- $error_upload = '';
+
+ // TODO check if user is logged in
if ($this->form_validation->run('upload') === FALSE)
{
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);
}
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
}
}
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'])
{
return TRUE;
}
-
- $this->form_validation->set_message('_valid_upload',
- $this->upload->display_errors('<span class="error">',
- '</span>'));
+ else
+ {
+ $this->form_validation->set_message('_valid_upload',
+ $this->upload->display_errors('<span class="error">',
+ '</span>'));
+ return FALSE;
+ }
}
+ $this->form_validation->set_message('_valid_upload',
+ $this->lang->line('_required_upload'));
return FALSE;
}
* 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:
* <ul>
* <li>all columns form DB with some exceptions that are overwritten or new</li>
return $video;
}
+ public function compute_video_name($title)
+ {
+ $name = str_replace(' ', '-', $title);
+
+ return urlencode($name);
+ }
+
+ /**
+ * Adds a new uploaded video to the DB.
+ *
+ * @param type $title
+ * @param type $description
+ * @param type $tags comma separated tags
+ * @param type $av_info a dictionary of video properties containing keys
+ * width, height, dar (display aspect ratio), duration and size; is can be
+ * returned with function get_av_info from video helper
+ */
+ public function add_video($title, $description, $tags, $av_info,
+ $category_id, $user_id)
+ {
+ $name = $this->compute_video_name($title);
+
+ // Tags.
+ $json_tags = array();
+ $tok = strtok($tags, ',');
+ while ($tok != FALSE)
+ {
+ $json_tags[trim($tok)] = 0;
+
+ $tok = strtok(',');
+ }
+ $json_tags = json_encode($json_tags);
+
+ // TODO formats
+ $json_formats = '[{"res":"1280x720","ext":"ogv","dar":"16:9"},'
+ . '{"res":"1067x600","ext":"ogv","dar":"16:9"}]';
+
+
+ $query = $this->db->query("INSERT INTO `videos`
+ (name, title, description, duration, formats, category_id,
+ user_id, tags, date)
+ VALUES ('$name', '$title', '$description', '"
+ . $av_info['duration']. "', '$json_formats', $category_id,
+ $user_id, '$json_tags', utc_timestamp())");
+ if ($query === FALSE)
+ return FALSE;
+
+ // Find out the id of the new video added.
+ $query = $this->db->query("SELECT id from `videos`
+ WHERE name = '$name'");
+ if ($query->num_rows() === 0)
+ return FALSE;
+ $video_id = $query->row()->id;
+
+ // Activation code.
+ $activation_code = Videos_model::gen_activation_code();
+
+ $query = $this->db->query("INSERT INTO `videos_unactivated`
+ (video_id, activation_code)
+ VALUES ($video_id, '$activation_code')");
+ }
+
/**
* Retrieves comments for a video.
*
return (preg_match('/\*|\+|\-|>|\<|\(|\)|~|"/', $search_query) == 0
? FALSE : TRUE);
}
+
+ public static function gen_activation_code()
+ {
+ $ci =& get_instance();
+
+ $activation_code = substr(
+ sha1($ci->config->item('encryption_key')
+ . mt_rand()),
+ 0,
+ 16);
+
+ return $activation_code;
+ }
}
/* End of file videos_model.php */