From 2881d1393f363efd3c5f0e9b58706e6e35e85717 Mon Sep 17 00:00:00 2001 From: Calin-Andrei Burloiu Date: Tue, 25 Oct 2011 17:16:57 +0300 Subject: [PATCH] OpenID login and comment improoved --- application/language/english/video_lang.php | 3 + application/libraries/Auth/extensions.php | 69 ++++++++++++++++ application/libraries/Openid.php | 4 +- application/models/users_model.php | 80 ++++++++++++------ application/models/videos_model.php | 5 ++ application/views/user/login_view.php | 16 +++- application/views/video/comments_view.php | 17 ++-- application/views/video/watch_view.php | 87 ++++++++++++++------ css/default.css | 13 +++ css/video.css | 8 +- img/icon-google.png | Bin 0 -> 854 bytes img/icon-myopenid.png | Bin 0 -> 776 bytes img/icon-yahoo.png | Bin 0 -> 575 bytes js/jquery.ui.nsinstall.js | 5 +- 14 files changed, 240 insertions(+), 67 deletions(-) create mode 100644 application/libraries/Auth/extensions.php create mode 100644 img/icon-google.png create mode 100644 img/icon-myopenid.png create mode 100644 img/icon-yahoo.png diff --git a/application/language/english/video_lang.php b/application/language/english/video_lang.php index 3accd07..fbe373e 100644 --- a/application/language/english/video_lang.php +++ b/application/language/english/video_lang.php @@ -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 index 0000000..041dd00 --- /dev/null +++ b/application/libraries/Auth/extensions.php @@ -0,0 +1,69 @@ +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(); + } +} +?> diff --git a/application/libraries/Openid.php b/application/libraries/Openid.php index bf20e85..8cb1f90 100644 --- a/application/libraries/Openid.php +++ b/application/libraries/Openid.php @@ -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; } diff --git a/application/models/users_model.php b/application/models/users_model.php index 8046ed3..252a5db 100644 --- a/application/models/users_model.php +++ b/application/models/users_model.php @@ -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; diff --git a/application/models/videos_model.php b/application/models/videos_model.php index 2b0add6..64ee48e 100644 --- a/application/models/videos_model.php +++ b/application/models/videos_model.php @@ -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; } diff --git a/application/views/user/login_view.php b/application/views/user/login_view.php index 3d3aaa0..5b6226d 100644 --- a/application/views/user/login_view.php +++ b/application/views/user/login_view.php @@ -76,11 +76,10 @@ $(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'; @@ -101,7 +100,16 @@ document.close(); }); }) - .button(); + .each(function() { + var op = $(this).data('op'); + + $(this) + .button({ + icons: { + primary: 'ui-icon-' + op + } + }); + }); }); \ No newline at end of file diff --git a/application/views/video/comments_view.php b/application/views/video/comments_view.php index 80f56fd..f2b4145 100644 --- a/application/views/video/comments_view.php +++ b/application/views/video/comments_view.php @@ -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') @@ -126,14 +127,14 @@ }); $('#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); }); }); \ No newline at end of file diff --git a/application/views/video/watch_view.php b/application/views/video/watch_view.php index 2da1ba0..4477f8f 100644 --- a/application/views/video/watch_view.php +++ b/application/views/video/watch_view.php @@ -63,35 +63,41 @@ -
+
-
-
lang->line('ui_category')) - . ': ' ?>
-
-
- -
-
lang->line('ui_tags')). ': ' ?>
-
$score): ?> - - - -
-
- -
-
lang->line('ui_download_torrents') ?>:
- -
- -
+
+
+ +
+
lang->line('ui_category')) + . ': ' ?>
+
+
+ +
+
lang->line('ui_tags')). ': ' ?>
+
$score): ?> + + + +
+
+ +
+
lang->line('ui_download_torrents') ?>:
+ +
+ +
+ +
+
lang->line('ui_license')).': ' ?>
+
+
+
-
-
lang->line('ui_license')).': ' ?>
-
-
+ lang->line('video_show_more') ?>
@@ -225,5 +231,32 @@ alert('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('lang->line('video_show_less') ?>'); + } + else + { + $(this).data('val', 'more'); + $(this).html('lang->line('video_show_more') ?>'); + } + }); }); \ No newline at end of file diff --git a/css/default.css b/css/default.css index ff8a424..4fc1be2 100644 --- a/css/default.css +++ b/css/default.css @@ -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 diff --git a/css/video.css b/css/video.css index babcef9..60ae7b7 100644 --- a/css/video.css +++ b/css/video.css @@ -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 index 0000000000000000000000000000000000000000..ffa48426b1d0069acc9a1a95a662b28f8457d1dd GIT binary patch literal 854 zcmV-c1F8IpP)l)GLt5>wb4Wxlq}kaLXZZmwgsP{ z6c=g>f(ov5+ife|2!e>v`oK*rB8UiLkcv=SANY#a7)_xu&7-DmI+M;!=H7eG`ML1( z7kp4v&7A6w3rjkDWLl#~KG4@bo>i|-llo0PH#Mn$2$~wB9@JyBCFlmIs;co0tcBxe z=2&d^6Sm#W$5p5&u}h*a*CHT>LjcsfS=Kn_Dp- ze!mD<3S)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W+A?GtRcE~M=@MBAxHqWk@~lKgMxw=XZQPg5WO0000q_n!S_AKBDJI=B?X*UOzXd?(5H;NPQ(U#jLUyAsrx(!sM~r!R;9({u*D>HdW} z5s`Pk2b?v_@X|HA&&06j&bFIn?*i>A0~mEDFXosU6I(eU$aKx+@-r=SPdqriRw;d> zj_j)|OY7#HObl2i%=XC3{*D0brMJROAMhhjrH+9@o5?&ry?Xl{F#f`VS zJ1yE$w(Rs}*;Lo7@LowiNcZ}Zpwr*o#pc?}O**)0@#R;a{NHe|74BnM6mUlp7y+s! zt`Q~4MX8A;sk$jZg2BkZ&`{UVK-b7P#K_pn$im9lSlhtB%D}*`v3Md(LvDUbW?Cfy V4T%P' + ''); - 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", { + '' + ''); - var msg = 'SwarmPlayer ' + widget.options.msg[widget.options.error]; + msg = 'SwarmPlayer ' + widget.options.msg[widget.options.error]; $('#install-swarmplayer-msg').html(msg); } -- 2.20.1