Added a Bookmarklet for the Bookmarks app
This commit is contained in:
parent
365c4fdae2
commit
7cd592e055
|
@ -0,0 +1,48 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ownCloud - bookmarks plugin
|
||||||
|
*
|
||||||
|
* @author Arthur Schiwon
|
||||||
|
* @copyright 2011 Arthur Schiwon blizzz@arthur-schiwon.de
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 3 of the License, or any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
require_once('../../lib/base.php');
|
||||||
|
|
||||||
|
// Check if we are a user
|
||||||
|
if( !OC_User::isLoggedIn()){
|
||||||
|
header( 'Location: '.OC_Helper::linkTo( '', 'index.php' ));
|
||||||
|
exit();
|
||||||
|
}
|
||||||
|
|
||||||
|
require_once('bookmarksHelper.php');
|
||||||
|
|
||||||
|
OC_App::setActiveNavigationEntry( 'bookmarks_index' );
|
||||||
|
|
||||||
|
OC_Util::addScript('bookmarks','addBm');
|
||||||
|
OC_Util::addStyle('bookmarks', 'bookmarks');
|
||||||
|
|
||||||
|
$tmpl = new OC_Template( 'bookmarks', 'addBm', 'user' );
|
||||||
|
|
||||||
|
$url = isset($_GET['url']) ? urldecode($_GET['url']) : '';
|
||||||
|
$metadata = getURLMetadata($url);
|
||||||
|
|
||||||
|
$tmpl->assign('URL', htmlentities($url));
|
||||||
|
$tmpl->assign('TITLE', htmlentities($metadata['title']));
|
||||||
|
$tmpl->assign('DESCRIPTION', htmlentities($metadata['description']));
|
||||||
|
|
||||||
|
$tmpl->printPage();
|
|
@ -35,24 +35,10 @@ if( !OC_User::isLoggedIn()){
|
||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
$metadata = array();
|
// $metadata = array();
|
||||||
|
|
||||||
$url = urldecode($_GET["url"]);
|
require '../bookmarksHelper.php';
|
||||||
//allow only http(s) and (s)ftp
|
|
||||||
$protocols = '/^[hs]{0,1}[tf]{0,1}tp[s]{0,1}\:\/\//i';
|
|
||||||
//if not (allowed) protocol is given, assume http
|
|
||||||
if(preg_match($protocols, $url) == 0) {
|
|
||||||
$url = 'http://' . $url;
|
|
||||||
}
|
|
||||||
|
|
||||||
$page = file_get_contents($url);
|
$metadata = getURLMetadata(urldecode($_GET["url"]));
|
||||||
@preg_match( "/<title>(.*)<\/title>/si", $page, $match );
|
|
||||||
$metadata['title'] = htmlentities(strip_tags(@$match[1]));
|
|
||||||
|
|
||||||
$meta = get_meta_tags($url);
|
|
||||||
|
|
||||||
if(array_key_exists('description', $meta)) {
|
|
||||||
$metadata['description'] = $meta['description'];
|
|
||||||
}
|
|
||||||
|
|
||||||
echo json_encode( array( 'status' => 'success', 'data' => $metadata));
|
echo json_encode( array( 'status' => 'success', 'data' => $metadata));
|
||||||
|
|
|
@ -0,0 +1,22 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
function getURLMetadata($url) {
|
||||||
|
//allow only http(s) and (s)ftp
|
||||||
|
$protocols = '/^[hs]{0,1}[tf]{0,1}tp[s]{0,1}\:\/\//i';
|
||||||
|
//if not (allowed) protocol is given, assume http
|
||||||
|
if(preg_match($protocols, $url) == 0) {
|
||||||
|
$url = 'http://' . $url;
|
||||||
|
}
|
||||||
|
|
||||||
|
$page = file_get_contents($url);
|
||||||
|
@preg_match( "/<title>(.*)<\/title>/si", $page, $match );
|
||||||
|
$metadata['title'] = htmlentities(strip_tags(@$match[1]));
|
||||||
|
|
||||||
|
$meta = get_meta_tags($url);
|
||||||
|
|
||||||
|
if(array_key_exists('description', $meta)) {
|
||||||
|
$metadata['description'] = $meta['description'];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $metadata;
|
||||||
|
}
|
|
@ -0,0 +1,17 @@
|
||||||
|
$(document).ready(function() {
|
||||||
|
$('#bookmark_add_submit').click(addBookmark);
|
||||||
|
});
|
||||||
|
|
||||||
|
function addBookmark(event) {
|
||||||
|
var url = $('#bookmark_add_url').val();
|
||||||
|
var title = $('#bookmark_add_title').val();
|
||||||
|
var description = $('#bookmark_add_description').val();
|
||||||
|
var tags = $('#bookmark_add_tags').val();
|
||||||
|
$.ajax({
|
||||||
|
url: 'ajax/addBookmark.php',
|
||||||
|
data: 'url=' + encodeURI(url) + '&title=' + encodeURI(title) + '&description=' + encodeURI(description) + '&tags=' + encodeURI(tags),
|
||||||
|
success: function(data){
|
||||||
|
location.href='index.php';
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
|
@ -0,0 +1,8 @@
|
||||||
|
<div class="bookmarks_addBm">
|
||||||
|
<p><label class="bookmarks_label">Address</label><input type="text" id="bookmark_add_url" class="bookmarks_input" value="<? echo $_['URL']; ?>"/></p>
|
||||||
|
<p><label class="bookmarks_label">Title</label><input type="text" id="bookmark_add_title" class="bookmarks_input" value="<? echo $_['TITLE']; ?>" /></p>
|
||||||
|
<p><label class="bookmarks_label">Description</label><input type="text" id="bookmark_add_description" class="bookmarks_input" value="<? echo $_['DESCRIPTION']; ?>" /></p>
|
||||||
|
<p><label class="bookmarks_label">Tags</label><input type="text" id="bookmark_add_tags" class="bookmarks_input" /></p>
|
||||||
|
<p><label class="bookmarks_label"> </label><label class="bookmarks_hint">Hint: Use space to separate tags.</label></p>
|
||||||
|
<p><label class="bookmarks_label"></label><input type="submit" id="bookmark_add_submit" /></p>
|
||||||
|
</div>
|
|
@ -2,6 +2,7 @@
|
||||||
<h2 class="bookmarks_headline"><?php echo isset($_GET["tag"]) ? 'Bookmarks with tag: ' . urldecode($_GET["tag"]) : 'All bookmarks'; ?></h2>
|
<h2 class="bookmarks_headline"><?php echo isset($_GET["tag"]) ? 'Bookmarks with tag: ' . urldecode($_GET["tag"]) : 'All bookmarks'; ?></h2>
|
||||||
<div class="bookmarks_menu">
|
<div class="bookmarks_menu">
|
||||||
<input type="button" class="bookmarks_addBtn" value="Add Bookmark" />
|
<input type="button" class="bookmarks_addBtn" value="Add Bookmark" />
|
||||||
|
<a type="button" class="bookmarks_addBml" href="javascript:var url = encodeURI(location.href);window.open('<?php echo (isset($_SERVER['HTTPS']) ? 'https://' : 'http://') . $_SERVER['HTTP_HOST'] . OC_Helper::linkTo('bookmarks', 'addBm.php'); ?>?url='+url, 'owncloud-bookmarks');" title="Drag this to your browser bookmarks and click it, when you want to bookmark a webpage.">Bookmarklet</a>
|
||||||
</div>
|
</div>
|
||||||
<div class="bookmarks_add">
|
<div class="bookmarks_add">
|
||||||
<p><label class="bookmarks_label">Address</label><input type="text" id="bookmark_add_url" class="bookmarks_input" /></p>
|
<p><label class="bookmarks_label">Address</label><input type="text" id="bookmark_add_url" class="bookmarks_input" /></p>
|
||||||
|
|
Loading…
Reference in New Issue