From: Calin-Andrei Burloiu Date: Tue, 25 Oct 2011 14:16:57 +0000 (+0300) Subject: OpenID login and comment improoved X-Git-Url: http://p2p-next.cs.pub.ro/gitweb/?a=commitdiff_plain;h=2881d1393f363efd3c5f0e9b58706e6e35e85717;hp=480a21049384e47afe920e73972ca336ec8e6a54;p=living-lab-site.git OpenID login and comment improoved --- 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 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 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 index 0000000..1487bfc Binary files /dev/null and b/img/icon-yahoo.png differ diff --git a/js/jquery.ui.nsinstall.js b/js/jquery.ui.nsinstall.js index 78c6189..772fa6f 100644 --- a/js/jquery.ui.nsinstall.js +++ b/js/jquery.ui.nsinstall.js @@ -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", { + '' + ''); - 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); }