fix: URLs without protocol are now linked to via HTTP

This commit is contained in:
Arthur Schiwon 2011-08-25 13:23:52 +02:00
parent e0a69bbeac
commit 0972606072
4 changed files with 12 additions and 3 deletions

View File

@ -41,7 +41,7 @@ $tmpl = new OC_Template( 'bookmarks', 'addBm', 'user' );
$url = isset($_GET['url']) ? urldecode($_GET['url']) : '';
$metadata = getURLMetadata($url);
$tmpl->assign('URL', htmlentities($url));
$tmpl->assign('URL', htmlentities($metadata['url']));
$tmpl->assign('TITLE', htmlentities($metadata['title']));
$tmpl->assign('DESCRIPTION', htmlentities($metadata['description']));

View File

@ -59,7 +59,6 @@ $params=array(
$query->execute($params);
$b_id = OC_DB::insertid();
if($b_id !== false) {
$query = OC_DB::prepare("
INSERT INTO *PREFIX*bookmarks_tags

View File

@ -7,6 +7,7 @@ function getURLMetadata($url) {
if(preg_match($protocols, $url) == 0) {
$url = 'http://' . $url;
}
$metadata['url'] = $url;
$page = file_get_contents($url);
@preg_match( "/<title>(.*)<\/title>/si", $page, $match );

View File

@ -49,7 +49,8 @@ function getMetadata() {
$.ajax({
url: 'ajax/getMeta.php',
data: 'url=' + encodeURI(url),
success: function(pageinfo){
success: function(pageinfo){
$('#bookmark_add_url').val(pageinfo.data.url);
$('#bookmark_add_description').val(pageinfo.data.description);
$('#bookmark_add_title').val(pageinfo.data.title);
}
@ -111,6 +112,9 @@ function updateBookmarksList(bookmark) {
for ( var i=0, len=tags.length; i<len; ++i ){
taglist = taglist + '<a class="bookmark_tags" href="?tag=' + encodeURI(tags[i]) + '">' + tags[i] + '</a> ';
}
if(!hasProtocol(bookmark.url)) {
bookmark.url = 'http://' + bookmark.url;
}
$('.bookmarks_list').append(
'<div class="bookmark_single">' +
'<p class="bookmark_title"><a href="' + encodeEntities(bookmark.url) + '" target="_new" class="bookmark_link">' + encodeEntities(bookmark.title) + '</a></p>' +
@ -144,3 +148,8 @@ function encodeEntities(s){
return "";
}
}
function hasProtocol(url) {
var regexp = /(ftp|http|https|sftp)/;
return regexp.test(url);
}