array(
'field'=>'birth-date',
'label'=>'lang:user_birth_date',
- 'rules'=>'trim|callback__valid_date'
+ 'rules'=>'trim|callback__valid_date|callback__postprocess_birth_date'
),
array(
'field'=>'locality',
'label'=>'lang:user_email',
'rules'=>'trim|required|xss_clean|valid_email'
)
+ ),
+ 'comment_video'=> array(
+ array(
+ 'field'=>'comment',
+ 'label'=>'lang:video_comment',
+ 'rules'=>'trim|required|xss_clean|callback__is_user_loggedin|callback__do_comment'
+ )
)
);
*/
$config['search_results_per_page'] = 20;
+/*
+|--------------------------------------------------------------------------
+| Video Comments per Page
+|--------------------------------------------------------------------------
+|
+| The number of video comments shown per page (as in video/watch).
+|
+*/
+$config['video_comments_per_page'] = 20;
+
/*
|--------------------------------------------------------------------------
| A list with all available languages in which the site is translated
$config['full_tag_open'] = '<div class="pagination">';
$config['full_tag_close'] = '</div>';
+$config['first_tag_open'] = ' <span class="pg-first">';
+$config['first_tag_close'] = '</span> ';
$config['first_link'] = $CI->lang->line('ui_page_first');
+
+$config['prev_tag_open'] = ' <span class="pg-prev">';
+$config['prev_tag_close'] = '</span> ';
$config['prev_link'] = $CI->lang->line('ui_page_previous');
+
+$config['next_tag_open'] = ' <span class="pg-next">';
+$config['next_tag_close'] = '</span> ';
$config['next_link'] = $CI->lang->line('ui_page_next');
-$config['last_link'] = $CI->lang->line('ui_page_last');
\ No newline at end of file
+
+$config['last_tag_open'] = ' <span class="pg-last">';
+$config['last_tag_close'] = '</span> ';
+$config['last_link'] = $CI->lang->line('ui_page_last');
+
+$config['num_tag_open'] = ' <span class="pg-num">';
+$config['num_tag_close'] = '</span> ';
\ No newline at end of file
public function login($redirect = '')
{
$this->load->library('form_validation');
-
$this->form_validation->set_error_delimiters('<span class="error">',
'</span>');
640, 480, IMAGETYPE_AUTO);
}
// Create thumbnail.
- $data['picture'] = $upload_data['file_name']. '-thumb.jpg';
+ $data['picture'] = $upload_data['file_name'];
$this->image->save_thumbnail($upload_data['file_path']
. $upload_data['file_name']. '-thumb.jpg', 120, 90);
}
return (preg_match('/[\d]{4}-[\d]{2}-[\d]{2}/', $date) === 1);
}
+ public function _postprocess_birth_date($date)
+ {
+ // If the user entered no birth date NULL needs to be inserted into DB.
+ if (! $date)
+ return NULL;
+
+ return $date;
+ }
+
public function _valid_old_password($old_password, $field_username)
{
if (! $old_password)
}
+ public function test($video_id)
+ {
+ // Display page.
+ $params = array( 'title' => $this->config->item('site_name'),
+ 'css' => array(
+ 'video.css'
+ ),
+ 'js' => array(
+ ),
+ //'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('video/watch_view', $data, TRUE);
+ $this->load->view('echo', array('output'=>
+ $this->_ajax_comment(TRUE, $video_id)));
+
+ $this->load->view('footer');
+ $this->load->view('html_end');
+ }
+
/**
* The page used for watching a video
*
echo $res;
}
+ public function ajax_comment($video_id,
+ $ordering = 'newest', $offset = '0')
+ {
+ $this->_ajax_comment(FALSE, $video_id, $ordering, $offset);
+ }
+
+ public function _ajax_comment($return_output, $video_id,
+ $ordering = 'newest', $offset = '0')
+ {
+ $video_id = intval($video_id);
+
+ $this->load->library('form_validation');
+ $this->form_validation->set_error_delimiters('<span class="error">',
+ '</span>');
+ $this->form_validation->run('comment_video');
+
+ // **
+ // ** MODEL **
+ // **
+ $this->load->model('videos_model');
+ $data['comments'] = $this->videos_model->get_video_comments($video_id,
+ $offset, $this->config->item('video_comments_per_page'), $ordering);
+ $data['comments_count'] =
+ $this->videos_model->get_video_comments_count($video_id);
+ $data['video_id'] = $video_id;
+
+ // Pagination
+ $this->load->library('pagination');
+ $pg_config['base_url'] = site_url("video/ajax_comment/$video_id/$ordering/");
+ $pg_config['uri_segment'] = 5;
+ $pg_config['total_rows'] = $data['comments_count'];
+ $pg_config['per_page'] = $this->config->item('video_comments_per_page');
+ $this->pagination->initialize($pg_config);
+ $data['comments_pagination'] = $this->pagination->create_links();
+
+ // **
+ // ** VIEWS **
+ // **
+ $output = $this->load->view('video/comments_view',
+ $data, $return_output);
+
+ if ($return_output)
+ return $output;
+ }
+
+ public function _is_user_loggedin($param)
+ {
+ if (! $this->session->userdata('user_id'))
+ return FALSE;
+
+ return TRUE;
+ }
+
+ public function _do_comment($comment)
+ {
+ // Note: Videos_model must be already loaded.
+ $this->load->model('videos_model');
+
+ $video_id = intval($this->input->post('video-id'));
+ $user_id = intval($this->session->userdata('user_id'));
+
+ $this->videos_model->comment_video($video_id, $user_id, $comment);
+ }
+
/**
- * AJAX page which retrieves a video plugin.
+ * OBSOLETE: AJAX page which retrieves a video plugin.
*
* The view associated with this controller should be parameter type
* concatenated with '_plugin_view' and must be located in
}
/**
- * Video plugin controller
+ * OBSOLETE: Video plugin controller
*
* See plugin function for details. If the second parameter is TRUE
* the output is return instead of being displayed (used in preloading).
$lang['video_like'] = 'Like';
$lang['video_dislike'] = 'Dislike';
+$lang['video_title_comment'] = 'Comment';
+$lang['video_title_all_comments'] = 'All Comments';
+$lang['video_title_no_comments'] = 'No comments yet';
+$lang['video_submit_post_comment'] = 'Post';
+
/* End of file video_lang.php */
/* Location: ./application/language/english/video_lang.php */
\ No newline at end of file
$vals = '';
foreach ($data as $col=> $val)
{
+ if ($val === NULL)
+ {
+ $cols .= "$col, ";
+ $vals .= "NULL, ";
+ continue;
+ }
+
$cols .= "$col, ";
if (is_int($val))
$vals .= "$val, ";
- else
+ else if (is_string($val))
$vals .= "'$val', ";
}
$cols = substr($cols, 0, -2);
$query = $this->db->query("INSERT INTO `users`
($cols, registration_date, last_login)
VALUES ($vals, utc_timestamp(), utc_timestamp())");
-
if ($query === FALSE)
return FALSE;
if ($query->num_rows() === 0)
return FALSE;
- return $query->row_array();
+ $userdata = $query->row_array();
+
+ // Post process userdata.
+ if (isset($userdata['picture']))
+ {
+ $userdata['picture_thumb'] = site_url(
+ "data/user_pictures/{$userdata['picture']}-thumb.jpg");
+ $userdata['picture'] = site_url(
+ "data/user_pictures/{$userdata['picture']}");
+ }
+
+ return $userdata;
}
/**
{
if (is_int($val))
$set .= "$col = $val, ";
- else
+ else if (is_string($val))
$set .= "$col = '$val', ";
+ else if (is_null($var))
+ $set .= "$col = NULL, ";
}
$set = substr($set, 0, -2);
*
* @param int $category_id
* @param mixed $user an user_id (as int) or an username (as string)
- * @return int number of videos or NULL if an error occured
+ * @return int number of videos or FALSE if an error occured
*/
public function get_videos_count($category_id = NULL, $user = NULL)
{
return $query->row()->count;
// Error
- return NULL;
+ return FALSE;
}
/**
return $video;
}
+ /**
+ * Retrieves comments for a video.
+ *
+ * @param int $video_id
+ * @param int $offset
+ * @param int $count
+ * @param string $ordering control comments ording by these possibilities:
+ * <ul>
+ * <li><strong>'hottest':</strong> newest most appreciated first. An
+ * appreciated comment is one which has a bigger
+ * score = likes - dislikes.</li>
+ * <li><strong>'newest':</strong> newest first.</li>
+ * </ul>
+ * @return array an array with comments
+ */
+ public function get_video_comments($video_id, $offset, $count,
+ $ordering = 'newest')
+ {
+ // Ordering
+ switch ($ordering)
+ {
+ case 'newest':
+ $order_statement = "ORDER BY time DESC";
+ break;
+ case 'hottest':
+ $order_statement = "ORDER BY time DESC, score DESC";
+ break;
+
+ default:
+ $order_statement = "";
+ }
+
+ $query = $this->db->query(
+ "SELECT c.*, u.username, (c.likes + c.dislikes) AS score
+ FROM `videos_comments` c, `users` u
+ WHERE c.user_id = u.id AND video_id = $video_id
+ $order_statement");
+
+ if ($query->num_rows() == 0)
+ return array();
+
+ $comments = $query->result_array();
+
+ return $comments;
+ }
+
+ public function get_video_comments_count($video_id)
+ {
+ $query = $this->db->query(
+ "SELECT COUNT(*) count
+ FROM `videos_comments`
+ WHERE video_id = $video_id");
+
+ if ($query->num_rows() == 0)
+ return FALSE;
+
+ return $query->row()->count;
+ }
+
+ /**
+ * Insert in DB a comment for a video.
+ *
+ * @param int $video_id
+ * @param int $user_id
+ * @param string $content
+ */
+ public function comment_video($video_id, $user_id, $content)
+ {
+ return $query = $this->db->query(
+ "INSERT INTO `videos_comments` (video_id, user_id, content, time)
+ VALUES ($video_id, $user_id, '$content', UTC_TIMESTAMP())");
+ }
+
/**
* Increments views count for a video.
*
<tr>
<td>
<?php if ($userdata['picture']): ?>
- <img src="<?php echo site_url("data/user_pictures/{$userdata['picture']}") ?>" style="float: left" />
+ <a href="<?php echo $userdata['picture'] ?>"><img src="<?php echo $userdata['picture_thumb'] ?>" style="float: left" /></a>
<?php endif ?>
</td>
<td></td>
<tr>
<th><?php echo $this->lang->line('user_picture'). ' : ' ?></th>
<td>
- <img src="<?php echo site_url("data/user_pictures/{$userdata['picture']}") ?>" alt="<?php echo $userdata['username'] ?>" />
+ <a href="<?php echo $userdata['picture'] ?>"><img src="<?php echo $userdata['picture_thumb'] ?>" alt="<?php echo $userdata['username'] ?>" /></a>
</td>
</tr>
<tr><td></td><td></td></tr>
--- /dev/null
+<div id="video-comments">
+ <h4><?php echo $this->lang->line('video_title_comment') ?>: </h4>
+
+ <?php echo form_open("video/comment/$video_id") ?>
+ <textarea name="comment" id="comment" rows="2" cols="56"></textarea>
+
+ <div><input type="button" id="button-post" value="<?php echo $this->lang->line('video_submit_post_comment') ?>" /></div>
+ </form>
+
+ <?php if ($comments_count == 0): ?>
+ <h4><?php echo $this->lang->line('video_title_no_comments') ?></h4>
+ <?php else: ?>
+ <h4><?php echo $this->lang->line('video_title_all_comments'). " ($comments_count): " ?></h4>
+
+ <?php foreach ($comments as $comment): ?>
+ <div class="comment-info"><span class="comment-user"><a href="<?php echo site_url("user/profile/{$comment['username']}") ?>"><?php echo $comment['username'] ?></a></span>
+ (<span class="comment-time"><?php echo $comment['time'] ?></span>)
+ </div>
+ <div class="comment-content"><?php echo $comment['content'] ?></div>
+ <?php endforeach ?>
+ <?php endif ?>
+</div>
+
+<script type="text/javascript">
+ $(function() {
+ $('#button-post')
+ .click(function() {
+ $.post('<?php echo site_url("video/ajax_comment/$video_id") ?>',
+ {comment: $('#comment').val(), 'video-id': <?php echo $video_id ?>},
+ function(data) {
+ $('#video-comments').html(data);
+ });
+ });
+ });
+
+</script>
\ No newline at end of file
<div id="video-info" style="clear: both">
<div id="video-upload-info">
<?php echo $this->lang->line('ui_uploaded_by') ?>
- <span id="video-date"><a href="<?php echo site_url("user/profile/{$video['username']}") ?>"><?php echo $video['username'] ?></a></span>
+ <span id="video-user"><a href="<?php echo site_url("user/profile/{$video['username']}") ?>"><?php echo $video['username'] ?></a></span>
<?php echo $this->lang->line('ui_on_date') ?>
<span id="video-date"><?php echo $video['date'] ?></span>
</div>