OpenID login and comment improoved
authorCalin-Andrei Burloiu <calin.burloiu@gmail.com>
Tue, 25 Oct 2011 14:16:57 +0000 (17:16 +0300)
committerCalin-Andrei Burloiu <calin.burloiu@gmail.com>
Tue, 25 Oct 2011 14:16:57 +0000 (17:16 +0300)
14 files changed:
application/language/english/video_lang.php
application/libraries/Auth/extensions.php [new file with mode: 0644]
application/libraries/Openid.php
application/models/users_model.php
application/models/videos_model.php
application/views/user/login_view.php
application/views/video/comments_view.php
application/views/video/watch_view.php
css/default.css
css/video.css
img/icon-google.png [new file with mode: 0644]
img/icon-myopenid.png [new file with mode: 0644]
img/icon-yahoo.png [new file with mode: 0644]
js/jquery.ui.nsinstall.js

index 3accd07..fbe373e 100644 (file)
@@ -3,6 +3,9 @@
 $lang['video_like'] = 'Like';
 $lang['video_dislike'] = 'Dislike';
 
+$lang['video_show_more'] = 'Show more';
+$lang['video_show_less'] = 'Show less';
+
 $lang['video_comment'] = 'Comment';
 $lang['video_title_comment'] = 'Comment';
 $lang['video_title_all_comments'] = 'All Comments';
diff --git a/application/libraries/Auth/extensions.php b/application/libraries/Auth/extensions.php
new file mode 100644 (file)
index 0000000..041dd00
--- /dev/null
@@ -0,0 +1,69 @@
+<?php
+
+/**
+ * CodeIgniter style sessions.
+ * 
+ * @package OpenID
+ */
+class Auth_Yadis_CISession extends Auth_Yadis_PHPSession {
+       
+       protected $ci = NULL;
+       
+       public function __construct()
+       {
+               $this->ci =& get_instance();
+               $this->ci->load->library('session');
+       }
+       
+    /**
+     * Set a session key/value pair.
+     *
+     * @param string $name The name of the session key to add.
+     * @param string $value The value to add to the session.
+     */
+    function set($name, $value)
+    {
+               $this->ci->session->set_userdata($name, $value);
+    }
+
+    /**
+     * Get a key's value from the session.
+     *
+     * @param string $name The name of the key to retrieve.
+     * @param string $default The optional value to return if the key
+     * is not found in the session.
+     * @return string $result The key's value in the session or
+     * $default if it isn't found.
+     */
+    function get($name, $default=NULL)
+    {
+               $value = $this->ci->session->userdata($name);
+        if ($value !== FALSE) 
+               {
+            return $value;
+        }
+               else
+               {
+            return $default;
+        }
+    }
+
+    /**
+     * Remove a key/value pair from the session.
+     *
+     * @param string $name The name of the key to remove.
+     */
+    function del($name)
+    {
+        $this->ci->session->unset_userdata($name);
+    }
+
+    /**
+     * Return the contents of the session in array form.
+     */
+    function contents()
+    {
+        return $this->ci->session->all_userdata();
+    }
+}
+?>
index bf20e85..8cb1f90 100644 (file)
@@ -48,6 +48,7 @@ class Openid {
                require_once "Auth/OpenID/SReg.php";
                require_once "Auth/OpenID/AX.php";
                require_once "Auth/OpenID/PAPE.php";
+               require_once "Auth/extensions.php";
        }
 
        function set_sreg($enable, $required = NULL, $optional = NULL, $policy = NULL)
@@ -225,7 +226,8 @@ class Openid {
                }
 
                $store = new Auth_OpenID_FileStore($this->storePath);
-               $consumer = new Auth_OpenID_Consumer($store);
+               $consumer = new Auth_OpenID_Consumer($store,
+                               new Auth_Yadis_CISession());
 
                return $consumer;
        }
index 8046ed3..252a5db 100644 (file)
@@ -189,65 +189,97 @@ class Users_model extends CI_Model {
        {
                $sreg_resp = Auth_OpenID_SRegResponse::fromSuccessResponse($op_response);
                $ax_resp = Auth_OpenID_AX_FetchResponse::fromSuccessResponse($op_response);
+               
+               if ($ax_resp)
+               {
+                       $ax_email = $ax_resp->get('http://axschema.org/contact/email');
+                       $ax_first_name = $ax_resp->get(
+                                       'http://axschema.org/namePerson/first');
+                       $ax_last_name = $ax_resp->get('http://axschema.org/namePerson/last');
+                       $ax_country = $ax_resp->get('http://axschema.org/contact/country');
+               }
+               else
+               {
+                       $ax_email = '';
+                       $ax_first_name = '';
+                       $ax_last_name = '';
+                       $ax_country = '';
+               }
+               
+               if ($sreg_resp)
+               {
+                       $sreg_email = $sreg_resp->get('email', '');
+                       $sreg_fullname = $sreg_resp->get('fullname', '');
+                       $sreg_nickname = $sreg_resp->get('nickname', '');
+                       $sreg_country = $sreg_resp->get('country', '');
+                       $sreg_dob = $sreg_resp->get('dob', NULL);
+               }
+               else
+               {
+                       $sreg_email = $sreg_fullname = $sreg_nickname = $sreg_country = '';
+                       $sreg_dob = NULL;
+               }
 
                // E-mail
-               $email = $ax_resp->get('http://axschema.org/contact/email');
-               if (empty($email) || is_a($email, 'Auth_OpenID_AX_Error'))
-                       $data['email'] = $sreg_resp->get('email', '');
+               if (empty($ax_email) || is_a($ax_email, 'Auth_OpenID_AX_Error'))
+                       $data['email'] = $sreg_email;
                else
-                       $data['email'] = $email[0];
+                       $data['email'] = $ax_email[0];
+               $data['email'] = strtolower($data['email']);
                
                // First Name
-               $first_name = $ax_resp->get('http://axschema.org/namePerson/first');
-               if (empty($first_name) || is_a($first_name, 'Auth_OpenID_AX_Error'))
+               if (empty($ax_first_name)
+                               || is_a($ax_first_name, 'Auth_OpenID_AX_Error'))
                        $data['first_name'] = '';
                else
-                       $data['first_name'] = $first_name[0];
+                       $data['first_name'] = $ax_first_name[0];
                
                // Sur Name
-               $last_name = $ax_resp->get('http://axschema.org/namePerson/last');
-               if (empty($last_name) || is_a($last_name, 'Auth_OpenID_AX_Error'))
+               if (empty($ax_last_name) || is_a($ax_last_name, 'Auth_OpenID_AX_Error'))
                        $data['last_name'] = '';
                else
-                       $data['last_name'] = $last_name[0];
+                       $data['last_name'] = $ax_last_name[0];
                
                // First Name and Last Name
                if (empty($data['first_name']) || empty($data['last_name']))
                {
-                       $fullname = $sreg_resp->get('fullname');
-                       
-                       if ($fullname)
+                       if ($sreg_fullname)
                        {
                                if (empty($data['first_name']))
                                        $data['first_name'] = substr(
-                                                       $fullname, 0, strrpos($fullname, ' '));
+                                                       $sreg_fullname, 0, strrpos($sreg_fullname, ' '));
                                if (empty($data['last_name']))
                                        $data['last_name'] = substr(
-                                                       $fullname, strrpos($fullname, ' ') + 1);
+                                                       $sreg_fullname, strrpos($sreg_fullname, ' ') + 1);
                        }
                }
                
                // Username
-               $data['username'] = $sreg_resp->get('nickname');
+               $data['username'] = $sreg_nickname;
                if (!$data['username'])
                {
+                       // Generate username from email
                        if (!empty($data['email']))
                        {
-                               $data['email'] = strtolower($data['email']);
                                $data['username'] = substr($data['email'],
                                                0, strpos($data['email'], '@'));
                                $data['username'] = preg_replace(array('/[^a-z0-9\._]*/'),
                                                array(''), $data['username']);
                        }
+                       // Generate username from first name and sur name
                        else if(!empty($data['first_name']) || !empty($data['last_name']))
                        {
                                $data['username'] = $data['first_name'] . '_'
                                                . $data['last_name'];
                        }
+                       // Generate a random username
                        else
                                $data['username'] = $this->gen_username();
                }
+               // Limit username to 24 characters because a prefix of 8 characters
+               // will be added: 'autogen_'.
                $data['username'] = substr($data['username'], 0, 24);
+               // Append a random character to the username each time it still exists.
                if ($this->get_userdata($data['username']))
                {
                        $chars = 'abcdefghijklmnopqrstuvwxyz0123456789';
@@ -258,23 +290,23 @@ class Users_model extends CI_Model {
                                $data['username'] .= $chars[ mt_rand(0, $len_chars - 1) ];
                        } while($this->get_userdata($data['username']));
                }
+               // Usernames autogenerated have 'autogen_' prefix and can be changed
+               // by the user from the account section. After this process it cannot
+               // be changed anymore.
                $data['username'] = 'autogen_' . $data['username'];
                
                // Country
-               $country = $ax_resp->get('http://axschema.org/contact/country');
-               if (empty($country) || is_a($country, 'Auth_OpenID_AX_Error'))
-                       $data['country'] = $sreg_resp->get('country', '');
+               if (empty($ax_country) || is_a($ax_country, 'Auth_OpenID_AX_Error'))
+                       $data['country'] = $sreg_country;
                else
-                       $data['country'] = $country[0];
+                       $data['country'] = $ax_country[0];
                
                // Birth Date
-               $data['birth_date'] = $sreg_resp->get('dob', NULL);
+               $data['birth_date'] = $sreg_dob;
                
                // OpenID
                $data['auth_src'] = 'openid';
                
-//             print_r($data);
-               
                if (!$this->register($data, $op_response->getDisplayIdentifier()))
                        return FALSE;
                
index 2b0add6..64ee48e 100644 (file)
@@ -189,6 +189,7 @@ class Videos_model extends CI_Model {
        public function get_video($id, $name = NULL)
        {
                $this->load->helper('video');
+               $this->load->helper('text');
                
                $query = $this->db->query("SELECT v.*, u.username 
                                                                FROM `videos` v, `users` u
@@ -240,6 +241,10 @@ class Videos_model extends CI_Model {
                // Thumbnails
                $video['thumbs'] = $this->get_thumbs($video['name'], $video['thumbs_count']);
                
+               // Shorted description
+               $video['shorted_description'] = character_limiter(
+                               $video['description'], 128);
+               
                return $video;
        }
        
index 3d3aaa0..5b6226d 100644 (file)
        $(function() {
                $('.login-openid')
                        .click(function() {
+                               var op = $(this).data('op');
                                var openId;
                                
-                               console.log($(this).data('op'));
-                               
-                               switch ($(this).data('op'))
+                               switch (op)
                                {
                                case 'google':
                                        openId = 'https://www.google.com/accounts/o8/id';
                                                        document.close();
                                                });
                        })
-                       .button();
+                       .each(function() {
+                               var op = $(this).data('op');
+                               
+                               $(this)
+                                       .button({
+                                               icons: {
+                                                       primary: 'ui-icon-' + op
+                                               }
+                                       });
+                       });
                
        });
 </script>
\ No newline at end of file
index 80f56fd..f2b4145 100644 (file)
@@ -60,7 +60,7 @@
 
        function updateCommentCharsLeft($textarea) 
        {
-               $('#comment-chars-left').html('' + (512 - $textarea.val().length));
+               
        }
        
        $(function() {
@@ -71,6 +71,7 @@
                                        function(data) {
                                                $('#video-comments').html(data);
                                        });
+                               $('#comment').val('');
                        });
                
                $('.pagination')
                        });
                
                $('#comment')
-                       .keydown(function(event) {
-                               updateCommentCharsLeft($(this));
+                       .bind('keyup paste drop change', function(event) {
+                               $textarea = $(this);
                                
-                               if ($(this).val().length == 513)
-                                       $(this).val($(this).val().substring(0, 512));
-                       })
-                       .change(function() {
-                               updateCommentCharsLeft($(this));
+                               if ($textarea.val().length >= 513)
+                                       $textarea.val($textarea.val().substring(0, 512));
+
+                               $('#comment-chars-left').html('' + (512 - $textarea.val().length));
+                               console.log(event.type);
                        });
        });
 </script>
\ No newline at end of file
index 2da1ba0..4477f8f 100644 (file)
                                </div>
                        </div>
                        
-                       <div id="video-description"><?php echo $video['description'] ?></div>
+                       <div id="video-shorted-description" class="video-description"><?php echo $video['shorted_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>
+                       <div id="video-info-details">
+                               <div id="video-description" class="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>
                        
-                       <dl id="video-license">
-                               <dt><?php echo ucwords($this->lang->line('ui_license')).': ' ?></dt>
-                               <dd><?php echo $video['license'] ?></dd>
-                       </dl>
+                       <a id="a-show-info-details" data-val="more" href="#"><?php echo $this->lang->line('video_show_more') ?></a>
                </div>
        
                <div id="video-comments"><?php echo $comments ?></div>
                                        alert('<?php echo $this->lang->line('ui_msg_login_restriction') ?>');
                        })
                        .button();
+                       
+               $('#video-info-details').hide();
+               
+               $('#a-show-info-details')
+//                     .button({
+//                             icons: {
+//                                     primary: 'ui-icon-triangle-1-s'
+//                             },
+//                             text: false
+//                     })
+                       .click(function(event) {
+                               event.preventDefault(true);
+                               $('#video-shorted-description').toggle();
+                               $('#video-info-details').fadeToggle();
+                               
+                               //console.log($(this).button('option', 'icons'));
+                               if ($(this).data('val') == 'more')
+                               {
+                                       $(this).data('val', 'less');
+                                       $(this).html('<?php echo $this->lang->line('video_show_less') ?>');
+                               }
+                               else
+                               {
+                                       $(this).data('val', 'more');
+                                       $(this).html('<?php echo $this->lang->line('video_show_more') ?>');
+                               }
+                       });
        });
 </script>
\ No newline at end of file
index ff8a424..4fc1be2 100644 (file)
@@ -269,3 +269,16 @@ label.strong
        word-spacing: 0.5em;
        margin-bottom: 0.5em;
 }
+
+.ui-icon-google
+{
+       background-image: url("/img/icon-google.png") !important;
+}
+.ui-icon-yahoo
+{
+       background-image: url("/img/icon-yahoo.png") !important;
+}
+.ui-icon-myopenid
+{
+       background-image: url("/img/icon-myopenid.png") !important;
+}
\ No newline at end of file
index babcef9..60ae7b7 100644 (file)
@@ -20,12 +20,18 @@ dd
        margin-left: 1em;
 }
 
+#a-show-info-details
+{
+/*     display: block;
+       text-align: center;*/
+}
+
 #video-upload-info, #video-popularity
 {
        font-size: 0.8em;
        line-height: 150%;
 }
-#video-description
+.video-description
 {
        margin-top: 1em;
        margin-bottom: 0.5em;
diff --git a/img/icon-google.png b/img/icon-google.png
new file mode 100644 (file)
index 0000000..ffa4842
Binary files /dev/null and b/img/icon-google.png differ
diff --git a/img/icon-myopenid.png b/img/icon-myopenid.png
new file mode 100644 (file)
index 0000000..25a2113
Binary files /dev/null and b/img/icon-myopenid.png differ
diff --git a/img/icon-yahoo.png b/img/icon-yahoo.png
new file mode 100644 (file)
index 0000000..1487bfc
Binary files /dev/null and b/img/icon-yahoo.png differ
index 78c6189..772fa6f 100644 (file)
@@ -108,6 +108,7 @@ $.widget( "ui.nsinstall", {
        
        _createSwarmPlayerInstall: function() {
                var widget = this;
+               var msg;
                
                if (widget.options.error == 'none')
                {
@@ -133,7 +134,7 @@ $.widget( "ui.nsinstall", {
                                        + '</div>'
                                + '</div>');
                        
-                       var msg = 'SwarmPlayer ' + widget.options.msg[widget.options.error];
+                       msg = 'SwarmPlayer ' + widget.options.msg[widget.options.error];
                        $('#install-swarmplayer-msg').html(msg);
                }
                else
@@ -149,7 +150,7 @@ $.widget( "ui.nsinstall", {
                                        + '</div>'
                                + '</div>');
                        
-                       var msg = 'SwarmPlayer ' + widget.options.msg[widget.options.error];
+                       msg = 'SwarmPlayer ' + widget.options.msg[widget.options.error];
                        $('#install-swarmplayer-msg').html(msg);
                }