Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Untagged #1

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 80 additions & 0 deletions includes/jquery-ui-1.8.9.autocomplete.min.js

Large diffs are not rendered by default.

347 changes: 347 additions & 0 deletions jquery-ui-1.8.9.autocomplete.css

Large diffs are not rendered by default.

93 changes: 93 additions & 0 deletions services/bookmarkservice.php
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,99 @@ function & getBookmarks($start = 0, $perpage = NULL, $user = NULL, $tags = NULL,
return array ('bookmarks' => $bookmarks, 'total' => $total);
}

function & getUntaggedBookmarks($start = 0, $perpage = NULL, $user = NULL, $tags = NULL, $terms = NULL, $sortOrder = NULL, $watched = NULL, $startdate = NULL, $enddate = NULL, $hash = NULL) {
// Only get the bookmarks that have no tag assigned for the current user. Our rules:
// - if the $user is NULL or not logged in, return nothing.
// - if the $user is set and isn't the logged-in user, return nothing.
// - if the $user is set and IS the logged-in user, then get all bookmarks that haven't been tagged yet.
$userservice =& ServiceFactory::getServiceInstance('UserService');
$tagservice =& ServiceFactory::getServiceInstance('TagService');
$sId = $userservice->getCurrentUserId();

if ($userservice->isLoggedOn()) {
// All public bookmarks, user's own bookmarks and any shared with user
$privacy = ' AND (B.uId = '. $sId .')';
} else {
// Just return nothing
return array ('bookmarks' => array(), 'total' => 0);
}

// Set up the SQL query.
$query_1 = 'SELECT DISTINCT ';
if (SQL_LAYER == 'mysql4') {
$query_1 .= 'SQL_CALC_FOUND_ROWS ';
}
$query_1 .= 'B.*, U.'. $userservice->getFieldName('username');

$query_2 = ' FROM '. $userservice->getTableName() .' AS U, '. $GLOBALS['tableprefix'] .'bookmarks AS B';

$query_3 = ' WHERE B.uId = U.'. $userservice->getFieldName('primary') . $privacy;

switch($sortOrder) {
case 'date_asc':
$query_5 = ' ORDER BY B.bDatetime ASC ';
break;
case 'title_desc':
$query_5 = ' ORDER BY B.bTitle DESC ';
break;
case 'title_asc':
$query_5 = ' ORDER BY B.bTitle ASC ';
break;
case 'url_desc':
$query_5 = ' ORDER BY B.bAddress DESC ';
break;
case 'url_asc':
$query_5 = ' ORDER BY B.bAddress ASC ';
break;
default:
$query_5 = ' ORDER BY B.bDatetime DESC ';
}

// Handle the parts of the query that depend on any tags that are present.
$query_4 = '';
$query_2 .= ', '. $GLOBALS['tableprefix'] .'tags AS T'. $i;
$query_4 .= ' AND T'. $i .'.tag like "system%" AND T'. $i .'.bId = B.bId';

// Start and end dates
if ($startdate) {
$query_4 .= ' AND B.bDatetime > "'. $startdate .'"';
}
if ($enddate) {
$query_4 .= ' AND B.bDatetime < "'. $enddate .'"';
}

// Hash
if ($hash) {
$query_4 .= ' AND B.bHash = "'. $hash .'"';
}

$query = $query_1 . $query_2 . $query_3 . $query_4 . $query_5;
if (!($dbresult = & $this->db->sql_query_limit($query, intval($perpage), intval($start)))) {
message_die(GENERAL_ERROR, 'Could not get bookmarks', '', __LINE__, __FILE__, $query, $this->db);
return false;
}

if (SQL_LAYER == 'mysql4') {
$totalquery = 'SELECT FOUND_ROWS() AS total';
} else {
$totalquery = 'SELECT COUNT(*) AS total'. $query_2 . $query_3 . $query_4;
}

if (!($totalresult = & $this->db->sql_query($totalquery)) || (!($row = & $this->db->sql_fetchrow($totalresult)))) {
message_die(GENERAL_ERROR, 'Could not get total bookmarks', '', __LINE__, __FILE__, $totalquery, $this->db);
return false;
}

$total = $row['total'];

$bookmarks = array();
while ($row = & $this->db->sql_fetchrow($dbresult)) {
$row['tags'] = $tagservice->getTagsForBookmark(intval($row['bId']));
$bookmarks[] = $row;
}
return array ('bookmarks' => $bookmarks, 'total' => $total);
}

function deleteBookmark($bookmarkid) {
$query = 'DELETE FROM '. $GLOBALS['tableprefix'] .'bookmarks WHERE bId = '. intval($bookmarkid);
$this->db->sql_transaction('begin');
Expand Down
2 changes: 1 addition & 1 deletion tagrename.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
exit();
} else {
// Rename the tag.
if($tagservice->renameTag($userservice->getCurrentUserId(), $old, $new, true)) {
if($tagservice->renameTag($userservice->getCurrentUserId(), $old, $new, false)) {
$tplVars['msg'] = T_('Tag renamed');
$logged_on_user = $userservice->getCurrentUser();
header('Location: '. createURL('bookmarks', $logged_on_user[$userservice->getFieldName('username')]));
Expand Down
66 changes: 62 additions & 4 deletions templates/dynamictags.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
$logged_on_userid = $userservice->getCurrentUserId();

$userPopularTags =& $tagservice->getPopularTags($logged_on_userid, 25, $logged_on_userid);
$userPopularTagsCloud =& $tagservice->tagCloud($userPopularTags, 5, 90, 175);
$userAllTags =& $tagservice->getPopularTags($logged_on_userid, 10000, $logged_on_userid);
$userPopularTagsCloud =& $tagservice->tagCloud($userPopularTags, 5, 90, 175);
$userPopularTagsCount = count($userPopularTags);

if ($userPopularTagsCount > 0) {
Expand Down Expand Up @@ -55,8 +56,8 @@
function addonload(addition) {
var existing = window.onload;
window.onload = function () {
existing();
addition();
existing;
addition;
}
}

Expand All @@ -77,6 +78,7 @@ function () {

function addTag(ele) {
var thisTag = ele.innerHTML;
thisTag = thisTag.replace(/&amp;/,'&');
var taglist = document.getElementById('tags');
var tags = taglist.value.split(', ');

Expand Down Expand Up @@ -112,6 +114,62 @@ function addTag(ele) {
document.write('<?php echo $taglist ?>');
document.write('<\/p>');
document.write('<\/div>');

var availableTags = [
<?php

foreach(array_keys($userAllTags) as $key) {
print '"'.$userAllTags[$key]['tag'].'",'."\n";
}
?>
];
function split( val ) {
return val.split( /,\s*/ );
}
function extractLast( term ) {
return split( term ).pop();
}

$( "#tags" )
// don't navigate away from the field on tab when selecting an item
.bind( "keydown", function( event ) {
if ( event.keyCode === $.ui.keyCode.TAB &&
$( this ).data( "autocomplete" ).menu.active ) {
event.preventDefault();
}
})
.autocomplete({
minLength: 0,
source: function( request, response ) {
// delegate back to autocomplete, but extract the last term
response( $.ui.autocomplete.filter(
availableTags, extractLast( request.term ) ) );
},
focus: function() {
// prevent value inserted on focus
return false;
},
select: function( event, ui ) {
var terms = split( this.value );
// remove the current input
terms.pop();
// add the selected item
var newterm = ui.item.value;
terms.push( newterm );

$("#popularTags").children().each(function() {
if (this.innerHTML == newterm) {
this.className = 'selected';
}
});
// add placeholder to get the comma-and-space at the end
terms.push( "" );
this.value = terms.join( ", " );
return false;
}
});


</script>

<?php } ?>
<?php } ?>
1 change: 1 addition & 0 deletions templates/toolbar.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<ul id="navigation">
<li><a href="<?php echo createURL('bookmarks', $cUsername); ?>"><?php echo T_('Bookmarks'); ?></a></li>
<li><a href="<?php echo createURL('watchlist', $cUsername); ?>"><?php echo T_('Watchlist'); ?></a></li>
<li><a href="<?php echo createURL('untagged', $cUsername); ?>"><?php echo T_('Untagged'); ?></a></li>
<li><a href="<?php echo createURL('bookmarks', $cUsername . '?action=add'); ?>"><?php echo T_('Add a Bookmark'); ?></a></li>
<li class="access"><a href="<?php echo $GLOBALS['root']; ?>?action=logout"><?php echo T_('Log Out'); ?></a></li>
</ul>
Expand Down
2 changes: 2 additions & 0 deletions templates/top.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="icon" type="image/png" href="<?php echo $GLOBALS['root']; ?>icon.png" />
<link rel="stylesheet" type="text/css" href="<?php echo $GLOBALS['root']; ?>scuttle.css" />
<link rel="stylesheet" type="text/css" href="<?php echo $GLOBALS['root']; ?>jquery-ui-1.8.9.autocomplete.css" />
<?php
$size = count($rsschannels);
for ($i = 0; $i < $size; $i++) {
Expand All @@ -14,6 +15,7 @@
?>
<?php if ($loadjs): ?>
<script type="text/javascript" src="<?php echo $GLOBALS['root']; ?>includes/jquery-1.4.4.min.js"></script>
<script type="text/javascript" src="<?php echo $GLOBALS['root']; ?>includes/jquery-ui-1.8.9.autocomplete.min.js"></script>
<script type="text/javascript" src="<?php echo $GLOBALS['root']; ?>jsScuttle.php"></script>
<?php endif; ?>
</head>
Expand Down
124 changes: 124 additions & 0 deletions untagged.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
<?php
/***************************************************************************
Copyright (c) 2004 - 2006 Marcus Campbell
http://scuttle.org/

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program 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 General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
***************************************************************************/
require_once 'header.inc.php';

$bookmarkservice =& ServiceFactory::getServiceInstance('BookmarkService');
$templateservice =& ServiceFactory::getServiceInstance('TemplateService');
$userservice =& ServiceFactory::getServiceInstance('UserService');
$cacheservice =& ServiceFactory::getServiceInstance('CacheService');

$tplVars = array();

@list($url, $user, $page) = isset($_SERVER['PATH_INFO']) ? explode('/', $_SERVER['PATH_INFO']) : NULL;

$loggedon = false;
if ($userservice->isLoggedOn()) {
$loggedon = true;
$currentUser = $userservice->getCurrentUser();
$currentUsername = $currentUser[$userservice->getFieldName('username')];
}

if ($usecache) {
// Generate hash for caching on
if ($loggedon) {
if ($currentUsername != $user) {
$cachehash = md5($_SERVER['REQUEST_URI'] . $currentUsername);

// Cache for 5 minutes
$cacheservice->Start($cachehash);
}
} else {
// Cache for 30 minutes
$cachehash = md5($_SERVER['REQUEST_URI']);
$cacheservice->Start($cachehash, 1800);
}
}

if ($user) {
if (is_int($user)) {
$userid = intval($user);
} else {
if (!($userinfo = $userservice->getUserByUsername($user) ) ) {
// Throw a 404 error
$tplVars['error'] = sprintf(T_('User with username %s was not found'), $user);
$templateservice->loadTemplate('error.404.tpl', $tplVars);
exit();
} else {
$userid =& $userinfo['uId'];
}
}
}

// Header variables
$tplVars['loadjs'] = true;

if ($user) {
$tplVars['user'] = $user;
$tplVars['userid'] = $userid;
$tplVars['userinfo'] =& $userinfo;

// Pagination
$perpage = getPerPageCount();
if (isset($_GET['page']) && intval($_GET['page']) > 1) {
$page = $_GET['page'];
$start = ($page - 1) * $perpage;
} else {
$page = 0;
$start = 0;
}

// Set template vars
$tplVars['page'] = $page;
$tplVars['start'] = $start;
$tplVars['bookmarkCount'] = $start + 1;

$bookmarks =& $bookmarkservice->getUntaggedBookmarks($start, $perpage, $userid, NULL, NULL, getSortOrder(), true);

$tplVars['sidebar_blocks'] = array('watchlist');
$tplVars['watched'] = true;
$tplVars['total'] = $bookmarks['total'];
$tplVars['bookmarks'] =& $bookmarks['bookmarks'];
$tplVars['cat_url'] = createURL('tags', '%2$s');
$tplVars['nav_url'] = createURL('watchlist', '%s/%s%s');

if ($user == $currentUsername) {
$title = T_('My Watchlist');
} else {
$title = T_('Watchlist') .': '. $user;
}
$tplVars['pagetitle'] = $title;
$tplVars['subtitle'] = $title;

$tplVars['rsschannels'] = array(
array(filter($sitename .': '. $title), createURL('rss', 'watchlist/'. filter($user, 'url')))
);

$templateservice->loadTemplate('bookmarks.tpl', $tplVars);
} else {
$tplVars['error'] = T_('Username was not specified');
$templateservice->loadTemplate('error.404.tpl', $tplVars);
exit();
}

if ($usecache) {
// Cache output if existing copy has expired
$cacheservice->End($hash);
}
?>