users can comment videos and can like and dislike comments => a new production version
authorCalin Burloiu <calin.burloiu@gmail.com>
Thu, 6 Oct 2011 14:11:17 +0000 (17:11 +0300)
committerCalin Burloiu <calin.burloiu@gmail.com>
Thu, 6 Oct 2011 14:11:17 +0000 (17:11 +0300)
14 files changed:
application/config/config.php
application/config/form_validation.php
application/config/pagination.php
application/controllers/user.php
application/controllers/video.php
application/helpers/MY_date_helper.php [new file with mode: 0644]
application/language/english/form_validation_lang.php
application/language/english/ui_lang.php
application/language/english/video_lang.php
application/models/videos_model.php
application/views/video/comments_view.php
application/views/video/watch_view.php
css/video.css
js/jquery.ui.ajax_links_maker.js [new file with mode: 0644]

index 81ea72d..f5a488d 100644 (file)
@@ -248,7 +248,7 @@ $config['sess_cookie_name']         = 'p2ptube_session';
 $config['sess_expiration']             = 7200;
 $config['sess_expire_on_close']        = FALSE;
 $config['sess_encrypt_cookie'] = FALSE;
-$config['sess_use_database']   = FALSE;
+$config['sess_use_database']   = TRUE;
 $config['sess_table_name']             = 'sessions';
 $config['sess_match_ip']               = TRUE;
 $config['sess_match_useragent']        = TRUE;
@@ -384,4 +384,3 @@ function __autoload($class)
         }
     }
 } 
-
index a3f9df3..a52115c 100644 (file)
@@ -105,7 +105,7 @@ $config = array(
                array(
                        'field'=>'comment',
                        'label'=>'lang:video_comment',
-                       'rules'=>'trim|required|xss_clean|callback__is_user_loggedin|callback__do_comment'
+                       'rules'=>'trim|required|xss_clean|callback__is_user_loggedin'
                )
        )
 );
index e373ed9..82aea73 100644 (file)
@@ -8,21 +8,24 @@ $config['num_links'] = 2;
 $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_tag_open'] = '<span class="pg-first">';
+$config['first_tag_close'] = '</span>&nbsp; ';
 $config['first_link'] = $CI->lang->line('ui_page_first');
 
-$config['prev_tag_open'] = ' <span class="pg-prev">';
-$config['prev_tag_close'] = '</span> ';
+$config['prev_tag_open'] = ' &nbsp;<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_tag_open'] = ' &nbsp;<span class="pg-next">';
+$config['next_tag_close'] = '</span>&nbsp; ';
 $config['next_link'] = $CI->lang->line('ui_page_next');
 
-$config['last_tag_open'] = ' <span class="pg-last">';
-$config['last_tag_close'] = '</span> ';
+$config['last_tag_open'] = ' &nbsp;<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
+$config['num_tag_open'] = ' &nbsp;<span class="pg-num">';
+$config['num_tag_close'] = '</span>';
+
+$config['cur_tag_open'] = ' &nbsp;<strong>';
+$config['cur_tag_close'] = '</strong>';
\ No newline at end of file
index 43b26a3..8ebfdb3 100644 (file)
@@ -257,19 +257,14 @@ class User extends CI_Controller {
                // **
                // Logged in user time zone
                $time_zone = $this->session->userdata('time_zone');
-               if (! $time_zone)
-                       $time_zone = 'UTC';
                
                // User data
                $userdata = $this->users_model->get_userdata($username);
                $userdata['roles'] = Users_model::roles_to_string($userdata['roles']);
                $country_list = $this->config->item('country_list');
                $userdata['country_name'] = $country_list[ $userdata['country'] ];
-               $userdata['last_login'] = date('Y-m-d H:i:s',  
-                       gmt_to_local(
-                               strtotime($userdata['last_login']), 
-                               $time_zone, 
-                               TRUE)) . ($time_zone == 'UTC' ? ' (UTC)' : '');
+               $userdata['last_login'] = human_gmt_to_human_local(
+                       $userdata['last_login'], $time_zone); 
                $userdata['time_zone'] = $this->lang->line($userdata['time_zone']);
                
                // User's videos
index 4ffa089..4e31540 100644 (file)
@@ -29,6 +29,7 @@ class Video extends CI_Controller {
                                                                                'video.css'
                ),
                                                                        'js' => array(
+                                                                               'jquery.ui.ajax_links_maker.js'
                ),
                //'metas' => array('description'=>'','keywords'=>'')
                );
@@ -40,9 +41,12 @@ class Video extends CI_Controller {
                $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)));
+               $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');
@@ -81,7 +85,8 @@ class Video extends CI_Controller {
                                                                'video.css'
                                                        ),
                                                        'js' => array(
-                                                               'jquery.ui.nsvideo.js'
+                                                               'jquery.ui.nsvideo.js',
+                                                               'jquery.ui.ajax_links_maker.js'
                                                        ),
                                                        //'metas' => array('description'=>'','keywords'=>'')
                                                        );
@@ -96,6 +101,9 @@ class Video extends CI_Controller {
                // TODO remove old AJAX plugin content
 //             $data['plugin_content'] = $this->_plugin('ns-html5', 
 //                     $data['video']['url'][0], TRUE);
+
+               // Comments
+               $data['comments'] = $this->_ajax_comment(TRUE, $id);
                
                // **
                // ** LOADING VIEWS
@@ -111,20 +119,39 @@ class Video extends CI_Controller {
        }
        
        /**
-        * Increments likes count for video with the specified id and returns to 
-        * the client as plain text the number if likes. 
+       * Increments (dis)likes count for video with the specified id and returns to
+       * the client as plain text the number if likes.
+       *
+       * @param string $action 'like' or 'dislike'
+       * @param string $video_id
+       * @param string $user_id
+       */
+       public function ajax_vote($action, $video_id)
+       {
+               $video_id = intval($video_id);
+               $user_id = $this->session->userdata('user_id');
+               $this->load->model('videos_model');
+       
+               $res = $this->videos_model->vote($video_id, $user_id,
+                       (strcmp($action, 'like') == 0 ? TRUE : FALSE));
+       
+               if ($res !== -1)
+                       echo $res;
+       }
+       /**
+        * Increments (dis)likes count for a comment with a specified id and returns
+        * to the client as plain text the number if likes. 
         * 
         * @param string $action        'like' or 'dislike'
-        * @param string $video_id
-        * @param string $user_id
+        * @param string $comment_id
         */
-       public function ajax_vote($action, $video_id, $user_id = NULL)
+       public function ajax_vote_comment($action, $comment_id)
        {
-               $video_id = intval($video_id);
-               $user_id = intval($user_id);
+               $comment_id = intval($comment_id);
+               $user_id = $this->session->userdata('user_id');
                $this->load->model('videos_model');
                
-               $res = $this->videos_model->vote($video_id, $user_id, 
+               $res = $this->videos_model->vote_comment($comment_id, $user_id,
                        (strcmp($action, 'like') == 0 ? TRUE : FALSE));
                
                if ($res !== -1)
@@ -145,7 +172,15 @@ class Video extends CI_Controller {
                $this->load->library('form_validation');
                $this->form_validation->set_error_delimiters('<span class="error">',
                                        '</span>');
-               $this->form_validation->run('comment_video');
+               
+               if ($this->form_validation->run('comment_video'))
+               {
+                       $this->load->model('videos_model');
+                       $user_id = intval($this->session->userdata('user_id'));
+                       $comment = $this->input->post('comment');
+                       
+                       $this->videos_model->comment_video($video_id, $user_id, $comment);
+               }
                
                // **
                // ** MODEL **
@@ -155,7 +190,10 @@ class Video extends CI_Controller {
                        $offset, $this->config->item('video_comments_per_page'), $ordering);
                $data['comments_count'] =
                        $this->videos_model->get_video_comments_count($video_id);
+               $data['hottest_comments'] = $this->videos_model->get_video_comments(
+                       $video_id, 0, 2, 'hottest');
                $data['video_id'] = $video_id;
+               $data['user_id'] = $this->session->userdata('user_id');
                
                // Pagination
                $this->load->library('pagination');
diff --git a/application/helpers/MY_date_helper.php b/application/helpers/MY_date_helper.php
new file mode 100644 (file)
index 0000000..8703577
--- /dev/null
@@ -0,0 +1,16 @@
+<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+
+function human_gmt_to_human_local($human_gmt, $time_zone = NULL)
+{
+       if (! $time_zone)
+               $time_zone = 'UTC';
+       
+       return date('Y-m-d H:i:s',  
+                       gmt_to_local(
+                               strtotime($human_gmt), 
+                               $time_zone, 
+                               TRUE)) . ($time_zone == 'UTC' ? ' (UTC)' : '');
+}
+
+/* End of file MY_date_helper.php */
+/* Location: ./application/helpers/MY_date_helper.php */
\ No newline at end of file
index 8ca5b5b..e86f027 100644 (file)
@@ -22,7 +22,8 @@ $lang['_username_exists']                     = 'There is no account registered with this username
 $lang['_internal_account']                     = 'You cannot change the password for this account because authentication is provided by a third-party.';
 $lang['_do_recover_password']          = 'Username and e-mail address are not associated with the same account.';
 
-
+// Comment Video
+$lang['_is_user_loggedin']             = 'In order to comment a video you must be logged in.';
 
 /* End of file form_validation_lang.php */
 /* Location: ./system/language/english/form_validation_lang.php */
\ No newline at end of file
index fcbebc7..bd290ad 100644 (file)
@@ -55,6 +55,7 @@ $lang['ui_from'] = 'from';
 $lang['ui_by'] = 'by';
 $lang['ui_category'] = 'category';
 $lang['ui_tags'] = 'tags';
+$lang['ui_download_torrents'] = 'Download Torrents';
 $lang['ui_license'] = 'license';
 $lang['ui_uploaded_by'] = 'Uploaded by';
 $lang['ui_on_date'] = 'on';
@@ -62,5 +63,7 @@ $lang['ui_on_date'] = 'on';
 $lang['ui_msg_login_restriction'] = 'You must log in to perform this action.';
 $lang['ui_msg_repeated_action_restriction'] = 'You can only perform this action once a day.';
 
+$lang['ui_chars_left'] = 'characters left';
+
 /* End of file ui_lang.php */
 /* Location: ./application/language/english/ui_lang.php */
\ No newline at end of file
index 0f667e0..3accd07 100644 (file)
@@ -3,8 +3,10 @@
 $lang['video_like'] = 'Like';
 $lang['video_dislike'] = 'Dislike';
 
+$lang['video_comment'] = 'Comment';
 $lang['video_title_comment'] = 'Comment';
 $lang['video_title_all_comments'] = 'All Comments';
+$lang['video_title_hottest_comments'] = 'Most Popular Comments';
 $lang['video_title_no_comments'] = 'No comments yet';
 $lang['video_submit_post_comment'] = 'Post';
 
index da7cdfe..2b0add6 100644 (file)
@@ -225,6 +225,7 @@ class Videos_model extends CI_Model {
                foreach ($video['assets'] as & $asset)
                {
                        $def = substr($asset['res'], strpos($asset['res'], 'x') + 1) . 'p';
+                       $asset['def'] = $def;
                        $asset['src'] = site_url('data/torrents/'. $video['name'] . '_'
                                . $def . '.'. $asset['ext']
                                . '.'. $this->config->item('default_torrent_ext'));
@@ -260,6 +261,9 @@ class Videos_model extends CI_Model {
        public function get_video_comments($video_id, $offset, $count,
                        $ordering = 'newest')
        {
+               $this->load->helper('date');
+               $cond_hottest = '';
+               
                // Ordering
                switch ($ordering)
                {
@@ -267,7 +271,8 @@ class Videos_model extends CI_Model {
                        $order_statement = "ORDER BY time DESC";
                        break;
                case 'hottest':
-                       $order_statement = "ORDER BY time DESC, score DESC";
+                       $order_statement = "ORDER BY score DESC, time DESC";
+                       $cond_hottest = "AND c.likes + c.dislikes > 0";
                        break;
                                
                default:
@@ -275,16 +280,23 @@ class Videos_model extends CI_Model {
                }
                
                $query = $this->db->query(
-                       "SELECT c.*, u.username, (c.likes + c.dislikes) AS score
+                       "SELECT c.*, u.username, u.time_zone, (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");
+                               WHERE c.user_id = u.id AND video_id = $video_id $cond_hottest
+                               $order_statement
+                               LIMIT $offset, $count");
                
                if ($query->num_rows() == 0)
                        return array();
                
                $comments = $query->result_array();
                
+               foreach ($comments as & $comment)
+               {
+                       $comment['local_time'] = human_gmt_to_human_local($comment['time'],
+                               $comment['time_zone']);
+               }
+               
                return $comments;
        }
        
@@ -310,6 +322,11 @@ class Videos_model extends CI_Model {
         */
        public function comment_video($video_id, $user_id, $content)
        {
+               // Prepping content.
+               $content = substr($content, 0, 512);
+               $content = htmlspecialchars($content);
+               $content = nl2br($content);
+               
                return $query = $this->db->query(
                        "INSERT INTO `videos_comments` (video_id, user_id, content, time)
                        VALUES ($video_id, $user_id, '$content', UTC_TIMESTAMP())");
@@ -373,6 +390,51 @@ class Videos_model extends CI_Model {
                return FALSE;
        }
        
+       public function vote_comment($comment_id, $user_id, $like = TRUE)
+       {
+               if ($like)
+               {
+                       $col = 'likes';
+                       $action = 'like';
+               }
+               else
+               {
+                       $col = 'dislikes';
+                       $action = 'dislike';
+               }
+       
+               $query = $this->db->query("SELECT * FROM `users_actions`
+                               WHERE user_id = $user_id
+                                       AND target_id = $comment_id
+                                       AND target_type = 'vcomment'
+                                       AND action = '$action'
+                                       AND date = CURDATE()");
+               // User already voted today
+               if ($query->num_rows() > 0)
+                       return -1;
+       
+               $this->db->query("UPDATE `videos_comments`
+                               SET $col = $col + 1
+                               WHERE id = $comment_id");
+       
+               // Mark this action so that the user cannot repeat it today.
+               $this->db->query("INSERT INTO `users_actions`
+                                       (user_id, action, target_type, target_id, date)
+                               VALUES ( $user_id, '$action', 'vcomment', $comment_id, CURDATE() )");
+       
+               $query = $this->db->query("SELECT $col FROM `videos_comments`
+                               WHERE id = $comment_id");
+       
+               if ($query->num_rows() === 1)
+               {
+                       $row = $query->row_array();
+                       return $row[ $col ];
+               }
+       
+               // Error
+               return FALSE;
+       }
+       
        public function get_thumbs($name, $count)
        {
                $thumbs = array();
index d4ebc3f..80f56fd 100644 (file)
-<div id="video-comments">
-       <h4><?php echo $this->lang->line('video_title_comment') ?>: </h4>
+<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 echo form_open("video/comment/$video_id") ?>
+       <textarea name="comment" id="comment" rows="4" cols="56"><?php echo set_value('comment', '') ?></textarea>
+       
+       <div><input type="button" id="button-post" value="<?php echo $this->lang->line('video_submit_post_comment') ?>" />
+               <span id="comment-chars-left">512</span> <?php echo $this->lang->line('ui_chars_left') ?>
+       </div>
+       <div><?php echo form_error('comment') ?></div>
+</form>
+
+<?php if ($comments_count == 0): ?>
+
+<h4><?php echo $this->lang->line('video_title_no_comments') ?></h4>
 
-  <?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 else: ?>
 
-       <?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>)
+  <?php if ($hottest_comments): ?>
+       <h4><?php echo $this->lang->line('video_title_hottest_comments'). ": " ?></h4>
+
+       <?php foreach ($hottest_comments as $hottest_comment): ?>
+               <div class="comment-info"><strong class="comment-user"><a href="<?php echo site_url("user/profile/{$hottest_comment['username']}") ?>"><?php echo $hottest_comment['username'] ?></a></strong>
+                       (<span class="comment-time"><?php echo $hottest_comment['local_time'] ?></span>)
+               </div>
+               
+               <div class="comment-content"><?php echo $hottest_comment['content'] ?></div>
+               
+               <div class="comment-popularity"><a class="link-vote-video-comment" data-action="like" data-commentid="<?php echo $hottest_comment['id'] ?>" href="#"><?php echo $this->lang->line('video_like') ?></a>
+                       &nbsp;<a class="link-vote-video-comment" data-action="dislike" data-commentid="<?php echo $hottest_comment['id'] ?>" href="#"><?php echo $this->lang->line('video_dislike') ?></a>
+                       &nbsp;&nbsp;&nbsp;&nbsp;<span id="<?php echo "video-comment-{$hottest_comment['id']}-likes" ?>"><?php echo $hottest_comment['likes'] ?></span> <?php
+                               echo $this->lang->line('ui_likes') ?>,
+                       <span id="<?php echo "video-comment-{$hottest_comment['id']}-dislikes" ?>"><?php echo $hottest_comment['dislikes'] ?></span> <?php
+                               echo $this->lang->line('ui_dislikes'); ?>
                </div>
-               <div class="comment-content"><?php echo $comment['content'] ?></div>
        <?php endforeach ?>
   <?php endif ?>
-</div>
+
+<h4><?php echo $this->lang->line('video_title_all_comments'). " ($comments_count): " ?></h4>
+
+<?php foreach ($comments as $comment): ?>
+       <div class="comment-info"><strong class="comment-user"><a href="<?php echo site_url("user/profile/{$comment['username']}") ?>"><?php echo $comment['username'] ?></a></strong>
+               (<span class="comment-time"><?php echo $comment['local_time'] ?></span>)
+       </div>
+       
+       <div class="comment-content"><?php echo $comment['content'] ?></div>
+       
+       <div class="comment-popularity"><a class="link-vote-video-comment" data-action="like" data-commentid="<?php echo $comment['id'] ?>" href="#"><?php echo $this->lang->line('video_like') ?></a>
+               &nbsp;<a class="link-vote-video-comment" data-action="dislike" data-commentid="<?php echo $comment['id'] ?>" href="#"><?php echo $this->lang->line('video_dislike') ?></a>
+               &nbsp;&nbsp;&nbsp;&nbsp;<span id="<?php echo "video-comment-{$comment['id']}-likes" ?>"><?php echo $comment['likes'] ?></span> <?php
+                       echo $this->lang->line('ui_likes') ?>,
+               <span id="<?php echo "video-comment-{$comment['id']}-dislikes" ?>"><?php echo $comment['dislikes'] ?></span> <?php
+                       echo $this->lang->line('ui_dislikes'); ?>
+       </div>
+<?php endforeach ?>
+
+<?php echo $comments_pagination ?>
+<?php endif ?>
 
 <script type="text/javascript">
+
+       function updateCommentCharsLeft($textarea) 
+       {
+               $('#comment-chars-left').html('' + (512 - $textarea.val().length));
+       }
+       
        $(function() {
                $('#button-post')
                        .click(function() {
                                $.post('<?php echo site_url("video/ajax_comment/$video_id") ?>',
-                                       {comment: $('#comment').val(), 'video-id': <?php echo $video_id ?>},
+                                       {comment: $('#comment').val()},
                                        function(data) {
                                                $('#video-comments').html(data);
                                        });
                        });
+               
+               $('.pagination')
+                       .ajaxLinksMaker({
+                               linkSelectors: [
+                                       '.pg-first',
+                                       '.pg-prev',
+                                       '.pg-next',
+                                       '.pg-last',
+                                       '.pg-num'
+                               ],
+                               target: '#video-comments'
+                       });
+                       
+               $('.link-vote-video-comment')
+                       .click(function(event) {
+                               var user_id = "<?php echo $user_id ?>";
+                               var action, idOutput, commentId;
+                               commentId = $(this).data('commentid');
+                               if ($(this).data('action') == 'like')
+                               {
+                                       var action = 'like';
+                                       var idOutput = '#video-comment-' + commentId + '-likes';
+                               }
+                               else
+                               {
+                                       var action = 'dislike';
+                                       var idOutput = '#video-comment-' + commentId + '-dislikes';
+                               }
+                               //alert(action + " " + user_id);
+                               
+                               event.preventDefault();
+                               
+                               if (user_id.length != 0)
+                               {
+                                       $.ajax({
+                                               type: "GET",
+                                               url: "<?php echo site_url("video/ajax_vote_comment") ?>/"
+                                                       + action
+                                                       + "/" + commentId,
+                                               data: {t: ""+Math.random()},
+                                               dataType: "text",
+                                               success: function(text) {
+                                                       if (text)
+                                                               $(idOutput).html(text);
+                                                       else
+                                                               alert('<?php echo $this->lang->line('ui_msg_repeated_action_restriction') ?>');
+                                               }
+                                       });
+                               }
+                               else
+                                       alert('<?php echo $this->lang->line('ui_msg_login_restriction') ?>');
+                       });
+               
+               $('#comment')
+                       .keydown(function(event) {
+                               updateCommentCharsLeft($(this));
+                               
+                               if ($(this).val().length == 513)
+                                       $(this).val($(this).val().substring(0, 512));
+                       })
+                       .change(function() {
+                               updateCommentCharsLeft($(this));
+                       });
        });
-
 </script>
\ No newline at end of file
index f102c4e..2da1ba0 100644 (file)
                <div id="video-widget"></div>
        </div>
        
-       <div id="video-info" style="clear: both">
-       <div id="video-upload-info">
-               <?php echo $this->lang->line('ui_uploaded_by') ?>
-                       <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>
+       <div style="clear: both"></div>
        
-       <div id="video-popularity">
-               <div id="video-views">
-                       <?php echo $video['views'] . ' '
-                               . ($video['views'] == 1 ? 
-                                       $this->lang->line('ui_view') : 
-                                       $this->lang->line('ui_views') );
-                       ?>
-               </div>
-               
-               <div><!--<a id="link-like" href="#"><?php echo $this->lang->line('video_like') ?></a>
-                       <a id="link-dislike" href="#"><?php echo $this->lang->line('video_dislike') ?></a>-->
-                       <a class="link-vote" data-action="like" href="#"><?php echo $this->lang->line('video_like') ?></a>
-                       <a class="link-vote" data-action="dislike" href="#"><?php echo $this->lang->line('video_dislike') ?></a>
-                       <span id="video-likes"><?php echo $video['likes'] ?></span> <?php
-                               echo $this->lang->line('ui_likes') ?>,
-                       <span id="video-dislikes"><?php echo $video['dislikes'] ?></span> <?php
-                               echo $this->lang->line('ui_dislikes'); ?>
+       <div id="video-footer">
+               <div id="video-info" style="clear: both">
+                       <div id="video-upload-info">
+                               <?php echo $this->lang->line('ui_uploaded_by') ?>
+                                       <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>
+                       
+                       <div id="video-popularity">
+                               <div id="video-views">
+                                       <?php echo $video['views'] . ' '
+                                               . ($video['views'] == 1 ? 
+                                                       $this->lang->line('ui_view') : 
+                                                       $this->lang->line('ui_views') );
+                                       ?>
+                               </div>
+                               
+                               <div><a class="link-vote" data-action="like" href="#"><?php echo $this->lang->line('video_like') ?></a>
+                                       <a class="link-vote" data-action="dislike" href="#"><?php echo $this->lang->line('video_dislike') ?></a>
+                                       <span id="video-likes"><?php echo $video['likes'] ?></span> <?php
+                                               echo $this->lang->line('ui_likes') ?>,
+                                       <span id="video-dislikes"><?php echo $video['dislikes'] ?></span> <?php
+                                               echo $this->lang->line('ui_dislikes'); ?>
+                               </div>
+                       </div>
+                       
+                       <div id="video-description"><?php echo $video['description'] ?></div>
+                       
+                       <dl id="video-category">
+                               <dt><?php echo ucwords($this->lang->line('ui_category'))
+                                       . ': ' ?></dt>
+                               <dd><?php echo $video['category_title'] ?></dd>
+                       </dl>
+                       
+                       <dl id="video-tags">
+                               <dt><?php echo ucwords($this->lang->line('ui_tags')). ': ' ?></dt>
+                               <dd><?php if (isset($video['tags'])): 
+                               foreach ($video['tags'] as $tag => $score): ?>
+                               <a href="<?php echo site_url('catalog/search/'. $tag) ?>" class="video-tag">
+                                       <?php echo "$tag " // TODO print score in future ?>
+                               </a>
+                               <?php endforeach; endif ?></dd>
+                       </dl>
+                       
+                       <dl id="video-torrents">
+                               <dt><?php echo $this->lang->line('ui_download_torrents') ?>: </dt>
+                         <?php foreach ($video['assets'] as $asset): ?>
+                               <dd><a href="<?php echo $asset['src'] ?>"><?php echo $asset['def'] ?></a></dd>
+                         <?php endforeach ?>
+                       </dl>
+                       
+                       <dl id="video-license">
+                               <dt><?php echo ucwords($this->lang->line('ui_license')).': ' ?></dt>
+                               <dd><?php echo $video['license'] ?></dd>
+                       </dl>
                </div>
-       </div>
-       
-       <div id="video-description"><?php echo $video['description'] ?></div>
        
-       <dl id="video-category">
-               <dt><?php echo ucwords($this->lang->line('ui_category'))
-                       . ': ' ?></dt>
-               <dd><?php echo $video['category_title'] ?></dd>
-       </dl>
-       
-       <dl id="video-tags">
-               <dt><?php echo ucwords($this->lang->line('ui_tags')). ': ' ?></dt>
-               <dd><?php if (isset($video['tags'])): 
-               foreach ($video['tags'] as $tag => $score): ?>
-               <a href="<?php echo site_url('catalog/search/'. $tag) ?>" class="video-tag">
-                       <?php echo "$tag " // TODO print score in future ?>
-               </a>
-               <?php endforeach; endif ?></dd>
-       </dl>
-       
-       <dl id="video-license">
-               <dt><?php echo ucwords($this->lang->line('ui_license')).': ' ?></dt>
-               <dd><?php echo $video['license'] ?></dd>
-       </dl>
+               <div id="video-comments"><?php echo $comments ?></div>
        </div>
-       
 
 <?php endif // if (isset($video['err'])): ?>
 </div>
                        });
                
                $('.link-vote')
-                       .click(function() {
+                       .click(function(event) {
                                var user_id = "<?php echo $user_id ?>";
                                var action, idOutput;
                                if ($(this).data('action') == 'like')
                                }
                                //alert(action + " " + user_id);
                                
+                               event.preventDefault();
+                               
                                if (user_id.length != 0)
                                {
                                        $.ajax({
                                                type: "GET",
                                                url: "<?php echo site_url("video/ajax_vote") ?>/"
                                                        + action
-                                                       + "<?php echo "/{$video['id']}/$user_id" ?>",
+                                                       + "<?php echo "/{$video['id']}" ?>",
                                                data: {t: ""+Math.random()},
                                                dataType: "text",
                                                success: function(text) {
                                {
                                        $.ajax({
                                                type: "GET",
-                                               url: "<?php echo site_url("video/ajax_vote/like/{$video['id']}/$user_id") ?>",
+                                               url: "<?php echo site_url("video/ajax_vote/like/{$video['id']}") ?>",
                                                dataType: "text",
                                                success: function(text) {
                                                        if (text)
index fe76565..babcef9 100644 (file)
@@ -1,12 +1,14 @@
-#watch-main
+.ui-tabs-panel
 {
-       width: 1056px;
-       margin: 0 auto;
+       padding: 0 !important;
 }
 
-.ui-tabs-panel
+#video-footer
 {
-       padding: 0 !important;
+       float: left;
+       width: 752px;
+       margin: 8px;
+       /* outline: 2px outset gray; */
 }
 
 dt
@@ -31,4 +33,18 @@ dd
 .video-tag
 {
        margin-right: 1.6em;
+}
+
+.comment-info
+{
+       margin-bottom: 0.33em;
+}
+.comment-content
+{
+       margin-bottom: 0.33em;
+}
+.comment-popularity
+{
+       font-size: 0.8em;
+       margin-bottom: 2em;
 }
\ No newline at end of file
diff --git a/js/jquery.ui.ajax_links_maker.js b/js/jquery.ui.ajax_links_maker.js
new file mode 100644 (file)
index 0000000..2895e70
--- /dev/null
@@ -0,0 +1,56 @@
+/*
+ * jQuery UI AJAX Links Maker 1.0.0 beta
+ * 
+ * Transforms normal anchors into AJAX anchors. The AJAX URL is took from
+ * href HTML attribute. Anchors to be transformed are found within elements
+ * listed in option linkSelectors. The AJAX content retrieved from the server
+ * is placed in the option target.
+ *
+ * Copyright 2011, Călin-Andrei Burloiu
+ * Dual licensed under the MIT or GPL Version 2 licenses.
+ * http://jquery.org/license
+ *
+ * Depends:
+ *   jquery.ui.core.js
+ *   jquery.ui.widget.js
+ */
+(function( $, undefined ) {
+
+$.widget( "ui.ajaxLinksMaker", {
+       version: "1.0.0 beta",
+       options: {
+               
+       },
+       
+       _create: function() {
+               var widget = this;
+               
+               for (i in widget.options.linkSelectors)
+               {
+                       var selector = widget.options.linkSelectors[i];
+
+                       $(selector + ' a', widget[0])
+                               .each(function(index) {
+                                       var url = $(this).attr('href');
+                                       
+                                       if (typeof(url) == 'undefined')
+                                               return;
+                                       
+                                       $(this)
+                                               .click(function(event) {
+                                                       event.preventDefault();
+                                                       
+                                                       $.post(
+                                                                       url,
+                                                                       function(data) {
+                                                                               $(widget.options.target).html(data);
+                                                                       });
+                                               });
+                               });
+                               
+               }
+       }
+       
+});
+
+})( jQuery );
\ No newline at end of file