Compare commits

...

35 Commits

Author SHA1 Message Date
Mark Pemberton
f18b8c0444 Final updates to rss.php with correct authentication and bookmark results 2011-05-12 23:12:11 -04:00
Mark Pemberton
23cdbb53d0 merged master into privatekey 2011-05-12 19:25:51 -04:00
Mark Pemberton
0d5dc418bc modified loginPrivateKey to only authenticate with privatekey 2011-05-12 17:58:05 -04:00
Mark Pemberton
6fbc47774f Fixed testPrivateBookmarks error on accessing invalid array element 2011-05-07 01:30:10 -04:00
Christian Weiske
eb47149a40 split up privateKeyExists tests into several methods and test empty string values 2011-04-12 08:39:58 +02:00
Christian Weiske
20f4404e4c add @covers 2011-04-11 17:05:52 +02:00
Christian Weiske
f63adfba34 rewrite getNewPrivateKey to use less code 2011-04-11 17:04:10 +02:00
Christian Weiske
ae828e9d78 another updateuser privatekey test 2011-04-11 17:00:44 +02:00
Christian Weiske
d06924c662 first tests for privatekey support in updateUser 2011-04-11 16:55:25 +02:00
Christian Weiske
0ddf87c14d clarify error return value 2011-04-11 16:47:59 +02:00
Christian Weiske
8982afef1e CS fixes for privatekey 2011-04-11 16:43:08 +02:00
Christian Weiske
92f64f95cb add test for addUser method 2011-04-11 16:36:26 +02:00
Christian Weiske
7796e739ef split up loginPrivateKey method into several ones to find errors easier 2011-04-11 07:59:50 +02:00
Christian Weiske
294930e697 move test comments into error message, they are of more help there when something breaks 2011-04-08 19:20:07 +02:00
Christian Weiske
3ef5813f97 test Service_User::getUserByPrivateKey and explicitely make it publci 2011-04-08 19:16:19 +02:00
Christian Weiske
b4f6b0449b use correct coverage whitelist 2011-04-08 18:10:14 +02:00
Christian Weiske
4da00aa439 merge master 2011-04-08 08:42:52 +02:00
Mark Pemberton
828b8fdf32 Final changes to privateweb 2011-04-06 14:33:15 -04:00
Mark Pemberton
331f7e9687 Backed out bookmark query updates and additional column to User table. Added additional tests 2011-03-19 01:40:56 -04:00
Mark Pemberton
c18207edb9 Added enablePrivateKey column to user table and added additional index in bookmarks table 2011-02-28 02:06:14 -05:00
Mark Pemberton
71a717b1b3 Merge branch 'master' into privatekey
Conflicts:

	www/gsearch/index.php
2011-02-28 01:44:02 -05:00
Mark Pemberton
2a4e91f8f3 Added enable feature and removed ajax call in profile.php 2011-02-27 00:37:14 -05:00
Mark Pemberton
7109719b5c Proposed attempt at enhancing database queries 2011-02-27 00:08:25 -05:00
Mark Pemberton
38fde526eb Included private rss in index.php and fixed bug in profile.php on call to updateUser() 2011-02-12 17:03:36 -05:00
Mark Pemberton
8f64c0acb4 Altered method of rss authentication to be temporarily logged in 2011-02-07 00:11:33 -05:00
Mark Pemberton
2242a0da33 Final changes to Private Key branch 2011-02-05 00:09:48 -05:00
Mark Pemberton
f6873268e5 Updated tests to reflect private key changes 2011-02-04 23:38:21 -05:00
Mark Pemberton
181f33b258 Merge commit 'origin/master' into privatekey 2011-02-02 23:16:59 -05:00
Mark Pemberton
43ad8e7725 Cleaned up User.php and moved Private Key function to it 2011-02-02 23:16:23 -05:00
Mark Pemberton
a32c9a1578 added secondary rss feed to bookmark page to test 2011-01-31 02:01:41 -05:00
Mark Pemberton
97717684c4 added new file 2011-01-31 01:47:16 -05:00
Mark Pemberton
ce9124bfd5 mostly done with the private key updates 2011-01-31 01:41:57 -05:00
Mark Pemberton
000cfd76cc More code cleanup 2011-01-24 21:49:33 -05:00
Mark Pemberton
456af09a04 Cleaning up some code in www folder 2011-01-24 02:04:08 -05:00
root
8d91bf83bc Partial update to Private Key update 2011-01-22 20:38:31 -05:00
79 changed files with 2426 additions and 1337 deletions

4
.gitignore vendored
View File

@ -1,4 +1,8 @@
dist/ dist/
.project
.buildpath
.settings
build.properties build.properties
html.properties
package.xml package.xml
semanticscuttle-dump.sql semanticscuttle-dump.sql

View File

@ -2,3 +2,6 @@ CREATE TABLE `sc_version` (
`schema_version` int(11) NOT NULL `schema_version` int(11) NOT NULL
) DEFAULT CHARSET=utf8; ) DEFAULT CHARSET=utf8;
INSERT INTO `sc_version` (`schema_version`) VALUES ('6'); INSERT INTO `sc_version` (`schema_version`) VALUES ('6');
ALTER TABLE `sc_users` ADD `privateKey` VARCHAR(33) NULL;
CREATE INDEX `privateKey` ON `sc_users` (`privateKey`);

View File

@ -23,7 +23,8 @@ CREATE TABLE `sc_bookmarks` (
PRIMARY KEY (`bId`), PRIMARY KEY (`bId`),
KEY `sc_bookmarks_usd` (`uId`,`bStatus`,`bDatetime`), KEY `sc_bookmarks_usd` (`uId`,`bStatus`,`bDatetime`),
KEY `sc_bookmarks_hui` (`bHash`,`uId`,`bId`), KEY `sc_bookmarks_hui` (`bHash`,`uId`,`bId`),
KEY `sc_bookmarks_du` (`bDatetime`,`uId`) KEY `sc_bookmarks_du` (`bDatetime`,`uId`).
KEY `sc_bookmarks_mod` (`bModified`)
) CHARACTER SET utf8 COLLATE utf8_general_ci ; ) CHARACTER SET utf8 COLLATE utf8_general_ci ;
-- -------------------------------------------------------- -- --------------------------------------------------------
@ -72,7 +73,9 @@ CREATE TABLE `sc_users` (
`email` varchar(50) NOT NULL default '', `email` varchar(50) NOT NULL default '',
`homepage` varchar(255) default NULL, `homepage` varchar(255) default NULL,
`uContent` text, `uContent` text,
PRIMARY KEY (`uId`) `privateKey` varchar(33) default NULL,
PRIMARY KEY (`uId`),
UNIQUE KEY `privateKey` (`privateKey`)
) CHARACTER SET utf8 COLLATE utf8_general_ci ; ) CHARACTER SET utf8 COLLATE utf8_general_ci ;
-- -------------------------------------------------------- -- --------------------------------------------------------

View File

@ -4,7 +4,7 @@ $this->includeTemplate($GLOBALS['top_include']);
<ul> <ul>
<li><?php echo T_('<strong>Store</strong> all your favourite links in one place, accessible from anywhere.'); ?></li> <li><?php echo T_('<strong>Store</strong> all your favourite links in one place, accessible from anywhere.'); ?></li>
<li><?php echo T_('<strong>Share</strong> your bookmarks with everyone, with friends on your watchlist or just keep them private.') ;?></li> <li><?php echo T_('<strong>Share</strong> your bookmarks with everyone, with friends on your watchlist or just keep them private.'); ?></li>
<li><?php echo T_('<strong>Tag</strong> your bookmarks with as many labels as you want, instead of wrestling with folders.'); ?></li> <li><?php echo T_('<strong>Tag</strong> your bookmarks with as many labels as you want, instead of wrestling with folders.'); ?></li>
<li><?php echo sprintf('<strong><a href="'.createURL('register').'">'.T_('Register now').'</a> </strong>'.T_(' to start using %s!'), $GLOBALS['sitename']); ?></li> <li><?php echo sprintf('<strong><a href="'.createURL('register').'">'.T_('Register now').'</a> </strong>'.T_(' to start using %s!'), $GLOBALS['sitename']); ?></li>
</ul> </ul>
@ -16,9 +16,11 @@ $this->includeTemplate($GLOBALS['top_include']);
<?php if(!is_null($currentUser) && $currentUser->isAdmin()): ?> <?php
<li>SemanticScuttle v0.97.0</li> if (!is_null($currentUser) && $currentUser->isAdmin()) {
<?php endif ?> echo "<li>SemanticScuttle v0.97.0</li>";
}
?>
</ul> </ul>
<h3><?php echo T_('Tips'); ?></h3> <h3><?php echo T_('Tips'); ?></h3>

View File

@ -27,7 +27,7 @@ window.onload = function() {
<td></td> <td></td>
<td> <td>
<?php <?php
if(strlen($description['cdDatetime'])>0) { if (strlen($description['cdDatetime'])>0) {
echo T_('Last modification:').' '.$description['cdDatetime'].', '; echo T_('Last modification:').' '.$description['cdDatetime'].', ';
$lastUser = $userservice->getUser($description['uId']); $lastUser = $userservice->getUser($description['uId']);
echo '<a href="'.createURL('profile', $lastUser['username']).'">' echo '<a href="'.createURL('profile', $lastUser['username']).'">'

View File

@ -32,12 +32,12 @@ $this->includeTemplate($GLOBALS['top_include']);
include('search.menu.php'); include('search.menu.php');
?> ?>
<?php if($pageName == PAGE_INDEX && $GLOBALS['welcomeMessage']):?> <?php if ($pageName == PAGE_INDEX && $GLOBALS['welcomeMessage']):?>
<p id="welcome"><?php echo $GLOBALS['welcomeMessage'];?></p> <p id="welcome"><?php echo $GLOBALS['welcomeMessage'];?></p>
<?php endif?> <?php endif?>
<?php if($GLOBALS['enableAdminColors']!=false && isset($userid) && $userservice->isAdmin($userid) && $pageName != PAGE_WATCHLIST) : ?> <?php if ($GLOBALS['enableAdminColors']!=false && isset($userid) && $userservice->isAdmin($userid) && $pageName != PAGE_WATCHLIST) : ?>
<div style="width:70%;text-align:center;"> <div style="width:70%;text-align:center;">
<img src="<?php echo ROOT ?>images/logo_24.gif" width="12px"/> <?php echo T_('Bookmarks on this page are managed by an admin user.'); ?><img src="<?php echo ROOT ?>images/logo_24.gif" width="12px"/> <img src="<?php echo ROOT ?>images/logo_24.gif" width="12px"/> <?php echo T_('Bookmarks on this page are managed by an admin user.'); ?><img src="<?php echo ROOT ?>images/logo_24.gif" width="12px"/>
</div> </div>
@ -46,19 +46,19 @@ include('search.menu.php');
<?php <?php
// common tag description // common tag description
if(($currenttag!= '' && $GLOBALS['enableCommonTagDescription']) if (($currenttag!= '' && $GLOBALS['enableCommonTagDescription'])
|| (isset($hash) && $GLOBALS['enableCommonBookmarkDescription'])):?> || (isset($hash) && $GLOBALS['enableCommonBookmarkDescription'])):?>
<p class="commondescription"><?php <p class="commondescription"><?php
$cDescription = ''; $cDescription = '';
if($currenttag!= '' && $cdservice->getLastTagDescription($currenttag)) { if ($currenttag!= '' && $cdservice->getLastTagDescription($currenttag)) {
$cDescription = $cdservice->getLastTagDescription($currenttag); $cDescription = $cdservice->getLastTagDescription($currenttag);
echo nl2br(filter($cDescription['cdDescription'])); echo nl2br(filter($cDescription['cdDescription']));
} elseif(isset($hash) && $cdservice->getLastBookmarkDescription($hash)) { } elseif (isset($hash) && $cdservice->getLastBookmarkDescription($hash)) {
$cDescription = $cdservice->getLastBookmarkDescription($hash); $cDescription = $cdservice->getLastBookmarkDescription($hash);
echo nl2br(filter($cDescription['cdTitle'])). "<br/>"; echo nl2br(filter($cDescription['cdTitle'])). "<br/>";
echo nl2br(filter($cDescription['cdDescription'])). "<br/>"; echo nl2br(filter($cDescription['cdDescription'])). "<br/>";
} }
//common tag description edit //common tag description edit
@ -82,26 +82,26 @@ if ($userservice->isLoggedOn()) {
<?php <?php
/* personal tag description */ /* personal tag description */
if($currenttag!= '' && $user!='') { if ($currenttag!= '' && $user!='') {
$userObject = $userservice->getUserByUsername($user); $userObject = $userservice->getUserByUsername($user);
if($tagservice->getDescription($currenttag, $userObject['uId'])) { ?> if ($tagservice->getDescription($currenttag, $userObject['uId'])) { ?>
<p class="commondescription"><?php <p class="commondescription"><?php
$pDescription = $tagservice->getDescription($currenttag, $userObject['uId']); $pDescription = $tagservice->getDescription($currenttag, $userObject['uId']);
echo nl2br(filter($pDescription['tDescription'])); echo nl2br(filter($pDescription['tDescription']));
//personal tag description edit //personal tag description edit
if($userservice->isLoggedOn()) { if ($userservice->isLoggedOn()) {
if($currenttag!= '') { if ($currenttag!= '') {
echo ' <a href="'. createURL('tagedit', $currenttag).'" title="'.T_('Edit your personal description of this tag').'" >'; echo ' <a href="'. createURL('tagedit', $currenttag).'" title="'.T_('Edit your personal description of this tag').'" >';
echo strlen($pDescription['tDescription'])==0?T_('Edit your personal description of this tag'):''; echo strlen($pDescription['tDescription'])==0?T_('Edit your personal description of this tag'):'';
echo ' <img src="'.ROOT.'images/b_edit.png" /></a>'; echo ' <img src="'.ROOT.'images/b_edit.png" /></a>';
} }
} }
?></p> ?></p>
<?php <?php
} }
} }
?> ?>
@ -119,7 +119,7 @@ $dateSort = 'date_desc';
$titleSort = 'title_asc'; $titleSort = 'title_asc';
$votingSort = 'voting_desc'; $votingSort = 'voting_desc';
switch(getSortOrder()) { switch (getSortOrder()) {
case 'date_asc': case 'date_asc':
$dateArrow = ' ↑'; $dateArrow = ' ↑';
$dateSort = 'date_desc'; $dateSort = 'date_desc';
@ -178,58 +178,48 @@ if ($currenttag!= '') {
?></p> ?></p>
<?php <?php
// PAGINATION // PAGINATION
// Ordering // Ordering
$sortOrder = ''; $sortOrder = '';
if (GET_SORT != '') { if (GET_SORT != '') {
$sortOrder = 'sort=' . getSortOrder(); $sortOrder = 'sort=' . getSortOrder();
} }
$sortAmp = (($sortOrder) ? '&amp;'. $sortOrder : ''); $sortAmp = (($sortOrder) ? '&amp;'. $sortOrder : '');
$sortQue = (($sortOrder) ? '?'. $sortOrder : ''); $sortQue = (($sortOrder) ? '?'. $sortOrder : '');
// Previous // Previous
$perpage = getPerPageCount($currentUser); $perpage = getPerPageCount($currentUser);
if (!$page || $page < 2) { if (!$page || $page < 2) {
$page = 1; $page = 1;
$start = 0; $start = 0;
$bfirst = '<span class="disable">'. T_('First') .'</span>'; $bfirst = '<span class="disable">'. T_('First') .'</span>';
$bprev = '<span class="disable">'. T_('Previous') .'</span>'; $bprev = '<span class="disable">'. T_('Previous') .'</span>';
} else { } else {
$prev = $page - 1; $prev = $page - 1;
$prev = 'page='. $prev; $prev = 'page='. $prev;
$start = ($page - 1) * $perpage; $start = ($page - 1) * $perpage;
$bfirst= '<a href="'. sprintf($nav_url, $user, $currenttag, '') . $sortQue .'">'. T_('First') .'</a>'; $bfirst= '<a href="'. sprintf($nav_url, $user, $currenttag, '') . $sortQue .'">'. T_('First') .'</a>';
$bprev = '<a href="'. sprintf($nav_url, $user, $currenttag, '?') . $prev . $sortAmp .'">'. T_('Previous') .'</a>'; $bprev = '<a href="'. sprintf($nav_url, $user, $currenttag, '?') . $prev . $sortAmp .'">'. T_('Previous') .'</a>';
} }
// Next // Next
$next = $page + 1; $next = $page + 1;
$totalpages = ceil($total / $perpage); $totalpages = ceil($total / $perpage);
if (count($bookmarks) < $perpage || $perpage * $page == $total) { if (count($bookmarks) < $perpage || $perpage * $page == $total) {
$bnext = '<span class="disable">'. T_('Next') .'</span>'; $bnext = '<span class="disable">'. T_('Next') .'</span>';
$blast = '<span class="disable">'. T_('Last') ."</span>\n"; $blast = '<span class="disable">'. T_('Last') ."</span>\n";
} else { } else {
$bnext = '<a href="'. sprintf($nav_url, $user, $currenttag, '?page=') . $next . $sortAmp .'">'. T_('Next') .'</a>'; $bnext = '<a href="'. sprintf($nav_url, $user, $currenttag, '?page=') . $next . $sortAmp .'">'. T_('Next') .'</a>';
$blast = '<a href="'. sprintf($nav_url, $user, $currenttag, '?page=') . $totalpages . $sortAmp .'">'. T_('Last') ."</a>\n"; $blast = '<a href="'. sprintf($nav_url, $user, $currenttag, '?page=') . $totalpages . $sortAmp .'">'. T_('Last') ."</a>\n";
} }
// RSS $pagesBanner = '<p class="paging">'. $bfirst .'<span> / </span>'. $bprev .'<span> / </span>'. $bnext .'<span> / </span>'. $blast .'<span> / </span>'. sprintf(T_('Page %d of %d'), $page, $totalpages) ." </p>\n";
$brss = '';
$size = count($rsschannels);
for ($i = 0; $i < $size; $i++) {
$brss = '<a style="background:#FFFFFF" href="'. htmlspecialchars($rsschannels[$i][1]) . '"'
. ' title="' . htmlspecialchars($rsschannels[$i][0]) . '">'
. '<img src="' . ROOT . 'images/rss.gif" width="16" height="16" alt="' . htmlspecialchars($rsschannels[$i][0]) .'"/>'
. '</a>';
}
$pagesBanner = '<p class="paging">'. $bfirst .'<span> / </span>'. $bprev .'<span> / </span>'. $bnext .'<span> / </span>'. $blast .'<span> / </span>'. sprintf(T_('Page %d of %d'), $page, $totalpages) ." ". $brss ." </p>\n"; if (getPerPageCount($currentUser) > 10) {
echo $pagesBanner; // display a page banner if too many bookmarks to manage
if (getPerPageCount($currentUser) > 10) { }
echo $pagesBanner; // display a page banner if too many bookmarks to manage
}
?> ?>
@ -257,43 +247,43 @@ if ($currenttag!= '') {
$watchedNames = null; $watchedNames = null;
} }
foreach ($bookmarks as $key => &$row) { foreach ($bookmarks as $key => &$row) {
switch ($row['bStatus']) { switch ($row['bStatus']) {
case 0: case 0:
$access = ''; $access = '';
break; break;
case 1: case 1:
$access = ' shared'; $access = ' shared';
break; break;
case 2: case 2:
$access = ' private'; $access = ' private';
break; break;
} }
$cats = ''; $cats = '';
$tagsForCopy = ''; $tagsForCopy = '';
$tags = $row['tags']; $tags = $row['tags'];
foreach ($tags as $tkey => &$tag) { foreach ($tags as $tkey => &$tag) {
$tagcaturl = sprintf( $tagcaturl = sprintf(
$cat_url, $cat_url,
filter($row['username'], 'url'), filter($row['username'], 'url'),
filter($tag, 'url') filter($tag, 'url')
); );
$cats .= sprintf( $cats .= sprintf(
'<a href="%s" rel="tag">%s</a>, ', '<a href="%s" rel="tag">%s</a>, ',
$tagcaturl, filter($tag) $tagcaturl, filter($tag)
); );
$tagsForCopy .= $tag . ','; $tagsForCopy .= $tag . ',';
} }
$cats = substr($cats, 0, -2); $cats = substr($cats, 0, -2);
if ($cats != '') { if ($cats != '') {
$cats = T_('Tags:') . ' ' . $cats; $cats = T_('Tags:') . ' ' . $cats;
} }
// Edit and delete links // Edit and delete links
$edit = ''; $edit = '';
if ($bookmarkservice->editAllowed($row)) { if ($bookmarkservice->editAllowed($row)) {
$edit = ' - <a href="' . createURL('edit', $row['bId']) . '">' $edit = ' - <a href="' . createURL('edit', $row['bId']) . '">'
. T_('Edit') . T_('Edit')
. '</a>' . '</a>'
. ' <a href="#" onclick="deleteBookmark(this, '. $row['bId'] .'); return false;">' . ' <a href="#" onclick="deleteBookmark(this, '. $row['bId'] .'); return false;">'
@ -337,7 +327,7 @@ if ($currenttag!= '') {
&& ($currentUser->getId() != $row['uId']) && ($currentUser->getId() != $row['uId'])
&& !$existence[$row['bAddress']] && !$existence[$row['bAddress']]
) { ) {
$copy .= ' - <a href="' $copy .= ' - <a href="'
. createURL( . createURL(
'bookmarks', 'bookmarks',
$currentUser->getUsername() $currentUser->getUsername()
@ -345,40 +335,40 @@ if ($currenttag!= '') {
. '" title="'.T_('Copy this bookmark to YOUR bookmarks.').'">' . '" title="'.T_('Copy this bookmark to YOUR bookmarks.').'">'
. T_('Copy') . T_('Copy')
. '</a>'; . '</a>';
} }
// Nofollow option // Nofollow option
$rel = ''; $rel = '';
if ($GLOBALS['nofollow']) { if ($GLOBALS['nofollow']) {
$rel = ' rel="nofollow"'; $rel = ' rel="nofollow"';
} }
$address = filter($row['bAddress']); $address = filter($row['bAddress']);
$oaddress = $address; $oaddress = $address;
// Redirection option // Redirection option
if ($GLOBALS['useredir']) { if ($GLOBALS['useredir']) {
$address = $GLOBALS['url_redir'] . $address; $address = $GLOBALS['url_redir'] . $address;
} }
// Admin specific design // Admin specific design
if ($userservice->isAdmin($row['username']) && $GLOBALS['enableAdminColors']) { if ($userservice->isAdmin($row['username']) && $GLOBALS['enableAdminColors']) {
$adminBgClass = ' class="adminBackground"'; $adminBgClass = ' class="adminBackground"';
$adminStar = ' <img src="'. ROOT .'images/logo_24.gif" width="12px" title="'. T_('This bookmark is certified by an admin user.') .'" />'; $adminStar = ' <img src="'. ROOT .'images/logo_24.gif" width="12px" title="'. T_('This bookmark is certified by an admin user.') .'" />';
} else { } else {
$adminBgClass = ''; $adminBgClass = '';
$adminStar = ''; $adminStar = '';
} }
// Private Note (just visible by the owner and his/her contacts) // Private Note (just visible by the owner and his/her contacts)
if ($watchedNames !== null if ($watchedNames !== null
&& ($currentUser->getId() == $row['uId'] && ($currentUser->getId() == $row['uId']
|| in_array($row['username'], $watchedNames) || in_array($row['username'], $watchedNames)
) )
) { ) {
$privateNoteField = $row['bPrivateNote']; $privateNoteField = $row['bPrivateNote'];
} else { } else {
$privateNoteField = ''; $privateNoteField = '';
} }
if ($GLOBALS['enableVoting'] && $GLOBALS['hideBelowVoting'] !== null if ($GLOBALS['enableVoting'] && $GLOBALS['hideBelowVoting'] !== null
&& $row['bVoting'] < $GLOBALS['hideBelowVoting'] && $row['bVoting'] < $GLOBALS['hideBelowVoting']
@ -386,8 +376,8 @@ if ($currenttag!= '') {
$access .= ' below-threshold'; $access .= ' below-threshold';
} }
// Output // Output
echo ' <li class="xfolkentry'. $access .'">'."\n"; echo ' <li class="xfolkentry'. $access .'">'."\n";
include 'bookmarks-thumbnail.inc.tpl.php'; include 'bookmarks-thumbnail.inc.tpl.php';
include 'bookmarks-vote.inc.tpl.php'; include 'bookmarks-vote.inc.tpl.php';
@ -397,46 +387,46 @@ if ($currenttag!= '') {
. '<a href="'. htmlspecialchars($address) .'"'. $rel .' class="taggedlink">' . '<a href="'. htmlspecialchars($address) .'"'. $rel .' class="taggedlink">'
. filter($row['bTitle']) . filter($row['bTitle'])
. '</a>' . $adminStar . "</div>\n"; . '</a>' . $adminStar . "</div>\n";
if ($row['bDescription'] == '') { if ($row['bDescription'] == '') {
$bkDescription = $GLOBALS['blankDescription']; $bkDescription = $GLOBALS['blankDescription'];
} else { } else {
// Improve description display (anchors, links, ...) // Improve description display (anchors, links, ...)
$bkDescription = preg_replace('|\[\/.*?\]|', '', filter($row['bDescription'])); // remove final anchor $bkDescription = preg_replace('|\[\/.*?\]|', '', filter($row['bDescription'])); // remove final anchor
$bkDescription = preg_replace('|\[(.*?)\]|', ' <span class="anchorBookmark">$1</span> » ', $bkDescription); // highlight starting anchor $bkDescription = preg_replace('|\[(.*?)\]|', ' <span class="anchorBookmark">$1</span> » ', $bkDescription); // highlight starting anchor
$bkDescription = preg_replace('@((http|https|ftp)://.*?)( |\r|$)@', '<a href="$1" rel="nofollow">$1</a>$3', $bkDescription); // make url clickable $bkDescription = preg_replace('@((http|https|ftp)://.*?)( |\r|$)@', '<a href="$1" rel="nofollow">$1</a>$3', $bkDescription); // make url clickable
} }
echo ' <div class="description">'. nl2br($bkDescription) ."</div>\n"; echo ' <div class="description">'. nl2br($bkDescription) ."</div>\n";
echo ' <div class="address">' . shortenString($oaddress) . "</div>\n"; echo ' <div class="address">' . shortenString($oaddress) . "</div>\n";
echo ' <div class="meta">' echo ' <div class="meta">'
. $cats . "\n" . $cats . "\n"
. $copy . "\n" . $copy . "\n"
. $edit . "\n" . $edit . "\n"
. $update . "\n" . $update . "\n"
. " </div>\n"; . " </div>\n";
echo $privateNoteField != '' echo $privateNoteField != ''
? ' <div class="privateNote" title="'. T_('Private Note on this bookmark') .'">'.$privateNoteField."</div>\n" ? ' <div class="privateNote" title="'. T_('Private Note on this bookmark') .'">'.$privateNoteField."</div>\n"
: ''; : '';
echo ' '; echo ' ';
include 'bookmarks-vote-horizontal.inc.tpl.php'; include 'bookmarks-vote-horizontal.inc.tpl.php';
echo " </div>\n"; echo " </div>\n";
echo " </li>\n"; echo " </li>\n";
} }
?> ?>
</ol> </ol>
<?php <?php
if(getPerPageCount($currentUser)>7) { if(getPerPageCount($currentUser)>7) {
echo '<p class="backToTop"><a href="#header" title="'.T_('Come back to the top of this page.').'">'.T_('Top of the page').'</a></p>'; echo '<p class="backToTop"><a href="#header" title="'.T_('Come back to the top of this page.').'">'.T_('Top of the page').'</a></p>';
} }
echo $pagesBanner; // display previous and next links pages + RSS link echo $pagesBanner; // display previous and next links pages + RSS link
} else { } else {
echo '<p class="error">'.T_('No bookmarks available').'</p>'; echo '<p class="error">'.T_('No bookmarks available').'</p>';
} }
$this->includeTemplate('sidebar.tpl'); $this->includeTemplate('sidebar.tpl');
$this->includeTemplate($GLOBALS['bottom_include']); $this->includeTemplate($GLOBALS['bottom_include']);

View File

@ -28,6 +28,14 @@ $this->includeTemplate($GLOBALS['top_include']);
<td><input type="text" name="pMail" size="75" value="<?php echo filter($objectUser->getEmail(), 'xml'); ?>" /></td> <td><input type="text" name="pMail" size="75" value="<?php echo filter($objectUser->getEmail(), 'xml'); ?>" /></td>
<td> <?php echo T_('Required'); ?></td> <td> <?php echo T_('Required'); ?></td>
</tr> </tr>
<tr>
<th align="left"><?php echo T_('Private RSS Feed'); ?></th>
<td><input type="checkbox" id="pEnablePrivateKey" name="pEnablePrivateKey" value="true" <?php echo $privateKeyIsEnabled;?> />
<label for="pEnablePrivateKey"><?php echo T_('Enable'); ?></label>&nbsp;&nbsp;&nbsp;
<input type="text" id="pPrivateKey" name="pPrivateKey" size="40" value="<?php echo $privateKey;?>" readonly="readonly" />
<input type="submit" name="submittedPK" value="<?php echo T_('Generate New Key'); ?>" />
</td>
</tr>
</table> </table>
<h3><?php echo T_('Personal Details'); ?></h3> <h3><?php echo T_('Personal Details'); ?></h3>

View File

@ -3,7 +3,7 @@ echo '<' . '?xml version="1.0" encoding="utf-8" ?' . ">\n";
?> ?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"> <rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
<channel> <channel>
<title><?php echo htmlspecialchars($feedtitle); ?></title> <title><?php echo $feedtitle; ?></title>
<link><?php echo htmlspecialchars($feedlink); ?></link> <link><?php echo htmlspecialchars($feedlink); ?></link>
<description><?php echo htmlspecialchars($feeddescription); ?></description> <description><?php echo htmlspecialchars($feeddescription); ?></description>
<pubDate><?php echo date('r'); ?></pubDate> <pubDate><?php echo date('r'); ?></pubDate>
@ -23,4 +23,4 @@ echo '<' . '?xml version="1.0" encoding="utf-8" ?' . ">\n";
</item> </item>
<?php endforeach; ?> <?php endforeach; ?>
</channel> </channel>
</rss> </rss>

View File

@ -9,11 +9,10 @@
<link rel="search" type="application/opensearchdescription+xml" href="<?php echo ROOT ?>api/opensearch.php" title="<?php echo htmlspecialchars($GLOBALS['sitename']) ?>"/> <link rel="search" type="application/opensearchdescription+xml" href="<?php echo ROOT ?>api/opensearch.php" title="<?php echo htmlspecialchars($GLOBALS['sitename']) ?>"/>
<?php <?php
if (isset($rsschannels)) { if (isset($rsschannels)) {
$size = count($rsschannels); $size = count($rsschannels);
for ($i = 0; $i < $size; $i++) { for ($i = 0; $i < $size; $i++) {
echo ' <link rel="alternate" type="application/rss+xml" title="' echo ' <link rel="alternate" type="application/rss+xml" title="' . $rsschannels[$i][0] . '"'
. htmlspecialchars($rsschannels[$i][0]) . '"' . ' href="'. $rsschannels[$i][1] .'" />'."\n";
. ' href="'. $rsschannels[$i][1] .'" />';
} }
} }
?> ?>

View File

@ -12,6 +12,9 @@ Database updates: Apply data/schema/6.sql or do the following:
INSERT INTO `sc_version` (`schema_version`) VALUES ('6'); INSERT INTO `sc_version` (`schema_version`) VALUES ('6');
ALTER TABLE `sc_users` ADD `privateKey` VARCHAR(33) NULL;
CREATE INDEX `privateKey` ON `sc_users` (`privateKey`);
From version 0.96 to 0.97 From version 0.96 to 0.97
------------------------- -------------------------

View File

@ -5,10 +5,11 @@
require_once dirname(__FILE__) . '/../src/SemanticScuttle/header-standalone.php'; require_once dirname(__FILE__) . '/../src/SemanticScuttle/header-standalone.php';
$us = SemanticScuttle_Service_Factory::get('User'); $us = SemanticScuttle_Service_Factory::get('User');
$uid = $us->addUser('dummy', 'dummy', 'dummy@example.org'); //$uid = $us->addUser('dummy', 'dummy', 'dummy@example.org');
$uid = $us->getUserByUserName('user123');
$bs = SemanticScuttle_Service_Factory::get('Bookmark'); $bs = SemanticScuttle_Service_Factory::get('Bookmark');
for ($nA = 0; $nA < 10; $nA++) { for ($nA = 0; $nA < 10000; $nA++) {
$rand = rand(); $rand = rand();
$bid = $bs->addBookmark( $bid = $bs->addBookmark(
'http://example.org/' . $rand, 'http://example.org/' . $rand,
@ -21,4 +22,4 @@ for ($nA = 0; $nA < 10; $nA++) {
$uid $uid
); );
} }
?> ?>

View File

@ -16,7 +16,7 @@
* *
* @category Bookmarking * @category Bookmarking
* @package SemanticScuttle * @package SemanticScuttle
* @author Christian Weiske <cweiske@cweiske.de> * @author Christian Weiske <cweiske@cweiske.de>
* @license GPL http://www.gnu.org/licenses/gpl.html * @license GPL http://www.gnu.org/licenses/gpl.html
* @link http://sourceforge.net/projects/semanticscuttle * @link http://sourceforge.net/projects/semanticscuttle
*/ */

View File

@ -35,6 +35,7 @@ class SemanticScuttle_Model_User
var $content; var $content;
var $datetime; var $datetime;
var $isAdmin; var $isAdmin;
var $privateKey;
/** /**
* Create a new user object * Create a new user object
@ -68,6 +69,29 @@ class SemanticScuttle_Model_User
return $this->username; return $this->username;
} }
/**
* Returns private key
*
* @param boolean return sanitized value which basically drops
* leading dash if exists
*
* @return string private key
*/
public function getPrivateKey($sanitized = false)
{
// Look for value only if not already set
if (!isset($this->privateKey)) {
$us = SemanticScuttle_Service_Factory::get('User');
$user = $us->getUser($this->id);
$this->privateKey = $user['privateKey'];
}
if ($sanitized == true) {
return substr($this->privateKey, -32);
} else {
return $this->privateKey;
}
}
/** /**
* Returns full user name as specified in the profile. * Returns full user name as specified in the profile.
* *
@ -108,7 +132,7 @@ class SemanticScuttle_Model_User
public function getHomepage() public function getHomepage()
{ {
// Look for value only if not already set // Look for value only if not already set
if(!isset($this->homepage)) { if (!isset($this->homepage)) {
$us = SemanticScuttle_Service_Factory::get('User'); $us = SemanticScuttle_Service_Factory::get('User');
$user = $us->getUser($this->id); $user = $us->getUser($this->id);
$this->homepage = $user['homepage']; $this->homepage = $user['homepage'];
@ -124,7 +148,7 @@ class SemanticScuttle_Model_User
public function getContent() public function getContent()
{ {
// Look for value only if not already set // Look for value only if not already set
if(!isset($this->content)) { if (!isset($this->content)) {
$us = SemanticScuttle_Service_Factory::get('User'); $us = SemanticScuttle_Service_Factory::get('User');
$user = $us->getUser($this->id); $user = $us->getUser($this->id);
$this->content = $user['uContent']; $this->content = $user['uContent'];
@ -141,7 +165,7 @@ class SemanticScuttle_Model_User
public function getDatetime() public function getDatetime()
{ {
// Look for value only if not already set // Look for value only if not already set
if(!isset($this->content)) { if (!isset($this->content)) {
$us = SemanticScuttle_Service_Factory::get('User'); $us = SemanticScuttle_Service_Factory::get('User');
$user = $us->getUser($this->id); $user = $us->getUser($this->id);
$this->datetime = $user['uDatetime']; $this->datetime = $user['uDatetime'];
@ -157,7 +181,7 @@ class SemanticScuttle_Model_User
public function isAdmin() public function isAdmin()
{ {
// Look for value only if not already set // Look for value only if not already set
if(!isset($this->isAdmin)) { if (!isset($this->isAdmin)) {
$us = SemanticScuttle_Service_Factory::get('User'); $us = SemanticScuttle_Service_Factory::get('User');
$this->isAdmin = $us->isAdmin($this->username); $this->isAdmin = $us->isAdmin($this->username);
} }
@ -182,4 +206,4 @@ class SemanticScuttle_Model_User
} }
} }
?> ?>

View File

@ -33,8 +33,6 @@ class SemanticScuttle_Service
*/ */
protected $db; protected $db;
/** /**
* Returns the single service instance * Returns the single service instance
* *
@ -47,14 +45,14 @@ class SemanticScuttle_Service
* *
* @return SemanticScuttle_Service * @return SemanticScuttle_Service
*/ */
public static function getInstance($db) public static function getInstance($db)
{ {
static $instance; static $instance;
if (!isset($instance)) { if (!isset($instance)) {
$instance = new self($db); $instance = new self($db);
} }
return $instance; return $instance;
} }
} }
?> ?>

View File

@ -86,7 +86,7 @@ class SemanticScuttle_Service_AuthUser extends SemanticScuttle_Service_User
/** /**
* Create new instance * Create new instance
* *
* @var sql_db $db Database object * @param sql_db $db Database object
*/ */
protected function __construct($db) protected function __construct($db)
{ {
@ -208,7 +208,7 @@ class SemanticScuttle_Service_AuthUser extends SemanticScuttle_Service_User
} }
return true; return true;
} }
@ -229,4 +229,4 @@ class SemanticScuttle_Service_AuthUser extends SemanticScuttle_Service_User
} }
} }
?> ?>

View File

@ -304,15 +304,14 @@ class SemanticScuttle_Service_Bookmark extends SemanticScuttle_DbService
{ {
if (!is_numeric($bookmark) if (!is_numeric($bookmark)
&& (!is_array($bookmark) && (!is_array($bookmark)
|| !isset($bookmark['bId']) || !isset($bookmark['bId'])
|| !is_numeric($bookmark['bId']) || !is_numeric($bookmark['bId']))
)
) { ) {
return false; return false;
} }
if (!is_array($bookmark) if (!is_array($bookmark)
&& !($bookmark = $this->getBookmark($bookmark)) && !($bookmark = $this->getBookmark($bookmark))
) { ) {
return false; return false;
} }
@ -717,9 +716,10 @@ class SemanticScuttle_Service_Bookmark extends SemanticScuttle_DbService
// All public bookmarks, user's own bookmarks // All public bookmarks, user's own bookmarks
// and any shared with user // and any shared with user
$privacy = ' AND ((B.bStatus = 0) OR (B.uId = '. $sId .')'; $privacy = ' AND ((B.bStatus = 0) OR (B.uId = '. $sId .')';
$watchnames = $userservice->getWatchNames($sId, true); $watchnames = $userservice->getWatchNames($sId);
foreach ($watchnames as $watchuser) { foreach ($watchnames as $watchuser) {
$privacy .= ' OR (U.username = "'. $watchuser .'" AND B.bStatus = 1)'; $privacy .= ' OR (U.username = "'. $watchuser;
$privacy .= '" AND B.bStatus = 1)';
} }
$privacy .= ')'; $privacy .= ')';
} else { } else {
@ -748,7 +748,8 @@ class SemanticScuttle_Service_Bookmark extends SemanticScuttle_DbService
$query_2 = ' FROM '. $userservice->getTableName() .' AS U' $query_2 = ' FROM '. $userservice->getTableName() .' AS U'
. ', '. $this->getTableName() .' AS B'; . ', '. $this->getTableName() .' AS B';
$query_3 = ' WHERE B.uId = U.'. $userservice->getFieldName('primary') . $privacy; $query_3 = ' WHERE B.uId = U.'. $userservice->getFieldName('primary');
$query_3 .= $privacy;
if ($GLOBALS['enableVoting'] && $GLOBALS['hideBelowVoting'] !== null if ($GLOBALS['enableVoting'] && $GLOBALS['hideBelowVoting'] !== null
&& !$userservice->isAdmin($userservice->getCurrentUserId()) && !$userservice->isAdmin($userservice->getCurrentUserId())

View File

@ -99,7 +99,7 @@ class SemanticScuttle_Service_Bookmark2Tag extends SemanticScuttle_DbService
$tags_count = is_array($tags)?count($tags):0; $tags_count = is_array($tags)?count($tags):0;
for ($i = 0; $i < $tags_count; $i++) { for ($i = 0; $i < $tags_count; $i++) {
$tags[$i] = trim(strtolower($tags[$i])); $tags[$i] = trim(utf8_strtolower($tags[$i]));
if ($fromApi) { if ($fromApi) {
include_once 'SemanticScuttle/functions.php'; include_once 'SemanticScuttle/functions.php';
$tags[$i] = convertTag($tags[$i], 'in'); $tags[$i] = convertTag($tags[$i], 'in');

View File

@ -141,10 +141,10 @@ class SemanticScuttle_Service_Tag extends SemanticScuttle_DbService
//normalize //normalize
if(!is_array($tags)) { if(!is_array($tags)) {
$tags = strtolower(trim($tags)); $tags = utf8_strtolower(trim($tags));
} else { } else {
for($i=0; $i<count($tags); $i++) { for($i=0; $i<count($tags); $i++) {
$tags[$i] = strtolower(trim($tags[$i])); $tags[$i] = utf8_strtolower(trim($tags[$i]));
} }
} }
return $tags; return $tags;

View File

@ -48,9 +48,10 @@ class SemanticScuttle_Service_User extends SemanticScuttle_DbService
protected $currentuser = null; protected $currentuser = null;
protected $fields = array( protected $fields = array(
'primary' => 'uId', 'primary' => 'uId',
'username' => 'username', 'username' => 'username',
'password' => 'password' 'password' => 'password',
'privatekey' => 'privatekey'
); );
protected $profileurl; protected $profileurl;
@ -74,6 +75,11 @@ class SemanticScuttle_Service_User extends SemanticScuttle_DbService
return $instance; return $instance;
} }
/**
* Create a new instance
*
* @param sql_db $db Database object
*/
protected function __construct($db) protected function __construct($db)
{ {
$this->db = $db; $this->db = $db;
@ -95,7 +101,8 @@ class SemanticScuttle_Service_User extends SemanticScuttle_DbService
protected function _getuser($fieldname, $value) protected function _getuser($fieldname, $value)
{ {
$query = 'SELECT * FROM '. $this->getTableName() $query = 'SELECT * FROM '. $this->getTableName()
. ' WHERE ' . $fieldname . ' = "' . $this->db->sql_escape($value) . '"'; . ' WHERE ' . $fieldname . ' = "'
. $this->db->sql_escape($value) . '"';
if (!($dbresult = $this->db->sql_query($query)) ) { if (!($dbresult = $this->db->sql_query($query)) ) {
message_die( message_die(
@ -114,13 +121,25 @@ class SemanticScuttle_Service_User extends SemanticScuttle_DbService
} }
} }
function & getUsers($nb=0) { /**
* Fetches the list of users from the database
* optionally limiting the results set
*
* @param integer $nb Max number of users to return
*
* @return array Data array from database
*/
public function & getUsers($nb = 0)
{
$query = 'SELECT * FROM '. $this->getTableName() .' ORDER BY `uId` DESC'; $query = 'SELECT * FROM '. $this->getTableName() .' ORDER BY `uId` DESC';
if($nb>0) { if ($nb>0) {
$query .= ' LIMIT 0, '.$nb; $query .= ' LIMIT 0, '.$nb;
} }
if (! ($dbresult =& $this->db->sql_query($query)) ) { if (!($dbresult =& $this->db->sql_query($query))) {
message_die(GENERAL_ERROR, 'Could not get user', '', __LINE__, __FILE__, $query, $this->db); message_die(
GENERAL_ERROR, 'Could not get user', '',
__LINE__, __FILE__, $query, $this->db
);
return false; return false;
} }
@ -167,7 +186,13 @@ class SemanticScuttle_Service_User extends SemanticScuttle_DbService
return $users; return $users;
} }
function _randompassword() { /**
* Generate a Random Password
*
* @return string random password
*/
function _randompassword()
{
$seed = (integer) md5(microtime()); $seed = (integer) md5(microtime());
mt_srand($seed); mt_srand($seed);
$password = mt_rand(1, 99999999); $password = mt_rand(1, 99999999);
@ -175,15 +200,30 @@ class SemanticScuttle_Service_User extends SemanticScuttle_DbService
return $password; return $password;
} }
function _updateuser($uId, $fieldname, $value) { /**
* Update Specific field on User Record
*
* @param integer $uId User ID
* @param string $fieldname Field Name
* @param string $value Value
*
* @return boolean true if a user is logged in
*/
function _updateuser($uId, $fieldname, $value)
{
$updates = array ($fieldname => $value); $updates = array ($fieldname => $value);
$sql = 'UPDATE '. $this->getTableName() .' SET '. $this->db->sql_build_array('UPDATE', $updates) .' WHERE '. $this->getFieldName('primary') .'='. intval($uId); $sql = 'UPDATE '. $this->getTableName() .' SET '
. $this->db->sql_build_array('UPDATE', $updates) .' WHERE '
. $this->getFieldName('primary') .'='. intval($uId);
// Execute the statement. // Execute the statement.
$this->db->sql_transaction('begin'); $this->db->sql_transaction('begin');
if (!($dbresult = & $this->db->sql_query($sql))) { if (!($dbresult = & $this->db->sql_query($sql))) {
$this->db->sql_transaction('rollback'); $this->db->sql_transaction('rollback');
message_die(GENERAL_ERROR, 'Could not update user', '', __LINE__, __FILE__, $sql, $this->db); message_die(
GENERAL_ERROR, 'Could not update user', '',
__LINE__, __FILE__, $sql, $this->db
);
return false; return false;
} }
$this->db->sql_transaction('commit'); $this->db->sql_transaction('commit');
@ -192,22 +232,59 @@ class SemanticScuttle_Service_User extends SemanticScuttle_DbService
return true; return true;
} }
function getProfileUrl($id, $username) { /**
* Generate Profile URL
*
* @param integer $id User ID
* @param string $username User Name
*
* @return string Profile URL
*/
function getProfileUrl($id, $username)
{
return sprintf($this->profileurl, urlencode($id), urlencode($username)); return sprintf($this->profileurl, urlencode($id), urlencode($username));
} }
function getUserByUsername($username) { /**
* Returns user row from database.
*
* @param string $username User Name
*
* @return array User array from database, false if no user was found
*/
public function getUserByUsername($username)
{
return $this->_getuser($this->getFieldName('username'), $username); return $this->_getuser($this->getFieldName('username'), $username);
} }
function getObjectUserByUsername($username) { /**
* Returns user row from database.
*
* @param string $privatekey Private Key
*
* @return array User array from database, false if no user was found
*/
public function getUserByPrivateKey($privatekey)
{
return $this->_getuser($this->getFieldName('privatekey'), $privatekey);
}
/**
* Returns user row from database.
*
* @param string $username User Name
*
* @return array User array from database, else null
*/
function getObjectUserByUsername($username)
{
$user = $this->_getuser($this->getFieldName('username'), $username); $user = $this->_getuser($this->getFieldName('username'), $username);
if($user != false) { if ($user != false) {
return new SemanticScuttle_Model_User( return new SemanticScuttle_Model_User(
$user[$this->getFieldName('primary')], $username $user[$this->getFieldName('primary')], $username
); );
} else { } else {
return NULL; return null;
} }
} }
@ -238,7 +315,7 @@ class SemanticScuttle_Service_User extends SemanticScuttle_DbService
* *
* @param integer $id User ID * @param integer $id User ID
* *
* @return array User array from database * @return array User array from database, false if not found
*/ */
public function getUser($id) public function getUser($id)
{ {
@ -260,10 +337,32 @@ class SemanticScuttle_Service_User extends SemanticScuttle_DbService
); );
} }
function isLoggedOn() { /**
* Checks if there is a user logged in
*
* @return boolean true if a user is logged in
*/
function isLoggedOn()
{
return ($this->getCurrentUserId() !== false); return ($this->getCurrentUserId() !== false);
} }
/**
* Tells you if the private key is enabled and valid
*
* @param string $privateKey Private Key
*
* @return boolean True if enabled and valid
*/
public function isPrivateKeyValid($privateKey)
{
// check length of private key
if (strlen($privateKey) == 32) {
return true;
}
return false;
}
/** /**
* Returns the current user object * Returns the current user object
* *
@ -278,7 +377,7 @@ class SemanticScuttle_Service_User extends SemanticScuttle_DbService
{ {
if (!is_null($newval)) { if (!is_null($newval)) {
//internal use only: reset currentuser //internal use only: reset currentuser
$currentuser = $newval; $this->currentuser = $newval;
} else if ($refresh || !isset($this->currentuser)) { } else if ($refresh || !isset($this->currentuser)) {
if ($id = $this->getCurrentUserId()) { if ($id = $this->getCurrentUserId()) {
$this->currentuser = $this->getUser($id); $this->currentuser = $this->getUser($id);
@ -315,16 +414,32 @@ class SemanticScuttle_Service_User extends SemanticScuttle_DbService
return $currentObjectUser; return $currentObjectUser;
} }
function existsUserWithUsername($username) { /**
if($this->getUserByUsername($username) != '') { * Checks if the given user exists
*
* @param string $username User Name
*
* @return boolean true if the user exists
*/
function existsUserWithUsername($username)
{
if ($this->getUserByUsername($username) != '') {
return true; return true;
} else { } else {
return false; return false;
} }
} }
function existsUser($id) { /**
if($this->getUser($id) != '') { * Checks if the given user exists
*
* @param integer $id User ID
*
* @return boolean true if the user exists
*/
function existsUser($id)
{
if ($this->getUser($id) != '') {
return true; return true;
} else { } else {
return false; return false;
@ -343,7 +458,7 @@ class SemanticScuttle_Service_User extends SemanticScuttle_DbService
* @param integer|array|string $user User ID or user row from DB * @param integer|array|string $user User ID or user row from DB
* or user name * or user name
* *
* @return boolean True if the user is admin * @return boolean true if the user is admin
*/ */
function isAdmin($user) function isAdmin($user)
{ {
@ -414,13 +529,13 @@ class SemanticScuttle_Service_User extends SemanticScuttle_DbService
/** /**
* Set the current user ID (i.e. when logging on) * Set the current user ID (i.e. when logging on)
* *
* @internal
* No ID verification is being done.
*
* @param integer $user User ID or null to unset the user * @param integer $user User ID or null to unset the user
* @param boolean $storeInSession Store the user ID in the session * @param boolean $storeInSession Store the user ID in the session
* *
* @return void * @return void
*
* @internal
* No ID verification is being done.
*/ */
public function setCurrentUserId($user, $storeInSession = false) public function setCurrentUserId($user, $storeInSession = false)
{ {
@ -456,7 +571,12 @@ class SemanticScuttle_Service_User extends SemanticScuttle_DbService
public function login($username, $password, $remember = false) public function login($username, $password, $remember = false)
{ {
$password = $this->sanitisePassword($password); $password = $this->sanitisePassword($password);
$query = 'SELECT '. $this->getFieldName('primary') .' FROM '. $this->getTableName() .' WHERE '. $this->getFieldName('username') .' = "'. $this->db->sql_escape($username) .'" AND '. $this->getFieldName('password') .' = "'. $this->db->sql_escape($password) .'"'; $query = 'SELECT '. $this->getFieldName('primary') .' FROM '
. $this->getTableName() .' WHERE '
. $this->getFieldName('username') .' = "'
. $this->db->sql_escape($username) .'" AND '
. $this->getFieldName('password') .' = "'
. $this->db->sql_escape($password) .'"';
if (!($dbresult = $this->db->sql_query($query))) { if (!($dbresult = $this->db->sql_query($query))) {
message_die( message_die(
@ -485,6 +605,47 @@ class SemanticScuttle_Service_User extends SemanticScuttle_DbService
} }
} }
/**
* Try to authenticate via the privatekey
*
* @param string $privatekey Private Key
*
* @return boolean true if the user could be authenticated,
* false if not.
*/
public function loginPrivateKey($privatekey)
{
/* Check if private key valid and enabled */
if (!$this->isPrivateKeyValid($privatekey)) {
return false;
}
$query = 'SELECT '. $this->getFieldName('primary') .' FROM '
. $this->getTableName() .' WHERE '
. $this->getFieldName('privatekey') .' = "'
. $this->db->sql_escape($privatekey) .'"';
if (!($dbresult = $this->db->sql_query($query))) {
message_die(
GENERAL_ERROR,
'Could not get user',
'', __LINE__, __FILE__, $query, $this->db
);
return false;
}
$row = $this->db->sql_fetchrow($dbresult);
$this->db->sql_freeresult($dbresult);
if ($row) {
$id = $_SESSION[$this->getSessionKey()]
= $row[$this->getFieldName('primary')];
return true;
} else {
return false;
}
}
/** /**
* Logs the user off * Logs the user off
* *
@ -495,15 +656,28 @@ class SemanticScuttle_Service_User extends SemanticScuttle_DbService
@setcookie($this->getCookiekey(), '', time() - 1, '/'); @setcookie($this->getCookiekey(), '', time() - 1, '/');
unset($_COOKIE[$this->getCookiekey()]); unset($_COOKIE[$this->getCookiekey()]);
session_unset(); session_unset();
$this->getCurrentUser(TRUE, false); $this->currentuserId = null;
$this->currentuser = null;
} }
function getWatchlist($uId) { /**
// Gets the list of user IDs being watched by the given user. * Gets the list of user IDs being watched by the given user.
$query = 'SELECT watched FROM '. $GLOBALS['tableprefix'] .'watched WHERE uId = '. intval($uId); *
* @param string $uId Current User ID
*
* @return mixed array if valid query and generates data
* boolean false if an error occured
*/
function getWatchlist($uId)
{
$query = 'SELECT watched FROM '. $GLOBALS['tableprefix']
.'watched WHERE uId = '. intval($uId);
if (! ($dbresult =& $this->db->sql_query($query)) ) { if (! ($dbresult =& $this->db->sql_query($query)) ) {
message_die(GENERAL_ERROR, 'Could not get watchlist', '', __LINE__, __FILE__, $query, $this->db); message_die(
GENERAL_ERROR, 'Could not get watchlist', '',
__LINE__, __FILE__, $query, $this->db
);
return false; return false;
} }
@ -570,34 +744,58 @@ class SemanticScuttle_Service_User extends SemanticScuttle_DbService
} }
function getWatchStatus($watcheduser, $currentuser) { function getWatchStatus($watcheduser, $currentuser)
// Returns true if the current user is watching the given user, and false otherwise. {
$query = 'SELECT watched FROM '. $GLOBALS['tableprefix'] .'watched AS W INNER JOIN '. $this->getTableName() .' AS U ON U.'. $this->getFieldName('primary') .' = W.watched WHERE U.'. $this->getFieldName('primary') .' = '. intval($watcheduser) .' AND W.uId = '. intval($currentuser); // Returns true if the current user is watching
// the given user, and false otherwise.
$query = 'SELECT watched FROM '. $GLOBALS['tableprefix'] .'watched AS W'
. ' INNER JOIN '. $this->getTableName() .' AS U'
. ' ON U.'. $this->getFieldName('primary') .' = W.watched'
. ' WHERE U.'. $this->getFieldName('primary') .' = '
. intval($watcheduser) .' AND W.uId = '. intval($currentuser);
if (! ($dbresult =& $this->db->sql_query($query)) ) { if (! ($dbresult =& $this->db->sql_query($query)) ) {
message_die(GENERAL_ERROR, 'Could not get watchstatus', '', __LINE__, __FILE__, $query, $this->db); message_die(
GENERAL_ERROR, 'Could not get watchstatus', '',
__LINE__, __FILE__, $query, $this->db
);
return false; return false;
} }
$arrWatch = array(); $arrWatch = array();
if ($this->db->sql_numrows($dbresult) == 0) if ($this->db->sql_numrows($dbresult) == 0) {
return false; return false;
else } else {
return true; return true;
}
} }
function setWatchStatus($subjectUserID) { /**
if (!is_numeric($subjectUserID)) * Set Watch Status
return false; *
* @param string $subjectUserID User ID to Watch
*
* @return boolean true if it successful, false if not
*/
function setWatchStatus($subjectUserID)
{
if (!is_numeric($subjectUserID)) {
return false;
}
$currentUserID = $this->getCurrentUserId(); $currentUserID = $this->getCurrentUserId();
$watched = $this->getWatchStatus($subjectUserID, $currentUserID); $watched = $this->getWatchStatus($subjectUserID, $currentUserID);
if ($watched) { if ($watched) {
$sql = 'DELETE FROM '. $GLOBALS['tableprefix'] .'watched WHERE uId = '. intval($currentUserID) .' AND watched = '. intval($subjectUserID); $sql = 'DELETE FROM '. $GLOBALS['tableprefix']
.'watched WHERE uId = '. intval($currentUserID)
.' AND watched = '. intval($subjectUserID);
if (!($dbresult =& $this->db->sql_query($sql))) { if (!($dbresult =& $this->db->sql_query($sql))) {
$this->db->sql_transaction('rollback'); $this->db->sql_transaction('rollback');
message_die(GENERAL_ERROR, 'Could not add user to watch list', '', __LINE__, __FILE__, $sql, $this->db); message_die(
GENERAL_ERROR, 'Could not add user to watch list',
'', __LINE__, __FILE__, $sql, $this->db
);
return false; return false;
} }
} else { } else {
@ -605,10 +803,14 @@ class SemanticScuttle_Service_User extends SemanticScuttle_DbService
'uId' => intval($currentUserID), 'uId' => intval($currentUserID),
'watched' => intval($subjectUserID) 'watched' => intval($subjectUserID)
); );
$sql = 'INSERT INTO '. $GLOBALS['tableprefix'] .'watched '. $this->db->sql_build_array('INSERT', $values); $sql = 'INSERT INTO '. $GLOBALS['tableprefix'] .'watched '
. $this->db->sql_build_array('INSERT', $values);
if (!($dbresult =& $this->db->sql_query($sql))) { if (!($dbresult =& $this->db->sql_query($sql))) {
$this->db->sql_transaction('rollback'); $this->db->sql_transaction('rollback');
message_die(GENERAL_ERROR, 'Could not add user to watch list', '', __LINE__, __FILE__, $sql, $this->db); message_die(
GENERAL_ERROR, 'Could not add user to watch list',
'', __LINE__, __FILE__, $sql, $this->db
);
return false; return false;
} }
} }
@ -622,24 +824,26 @@ class SemanticScuttle_Service_User extends SemanticScuttle_DbService
* No checks are done in here - you ought to have checked * No checks are done in here - you ought to have checked
* everything before calling this method! * everything before calling this method!
* *
* @param string $username Username to use * @param string $username Username to use
* @param string $password Password to use * @param string $password Password to use
* @param string $email Email to use * @param string $email Email to use
* @param string $privateKey Key for RSS auth
* *
* @return mixed Integer user ID if all is well, * @return mixed Integer user ID if all is well,
* boolean false if an error occured * boolean false if an error occured
*/ */
public function addUser($username, $password, $email) public function addUser($username, $password, $email, $privateKey = null)
{ {
// Set up the SQL UPDATE statement. // Set up the SQL UPDATE statement.
$datetime = gmdate('Y-m-d H:i:s', time()); $datetime = gmdate('Y-m-d H:i:s', time());
$password = $this->sanitisePassword($password); $password = $this->sanitisePassword($password);
$values = array( $values = array(
'username' => $username, 'username' => $username,
'password' => $password, 'password' => $password,
'email' => $email, 'email' => $email,
'uDatetime' => $datetime, 'uDatetime' => $datetime,
'uModified' => $datetime 'uModified' => $datetime,
'privateKey' => $privateKey
); );
$sql = 'INSERT INTO '. $this->getTableName() $sql = 'INSERT INTO '. $this->getTableName()
. ' '. $this->db->sql_build_array('INSERT', $values); . ' '. $this->db->sql_build_array('INSERT', $values);
@ -660,23 +864,76 @@ class SemanticScuttle_Service_User extends SemanticScuttle_DbService
return $uId; return $uId;
} }
function updateUser($uId, $password, $name, $email, $homepage, $uContent) { /**
if (!is_numeric($uId)) * Update user record.
return false; * Updates all values even if they are empty, except passwords.
* An empty password is not set.
*
* No validation is made here.
*
* @param integer $uId User ID
* @param string $password User Password
* @param string $name User Name
* @param string $email Email Address
* @param string $homepage Homepage URL
* @param string $uContent Content
* @param string $privateKey RSS Private Key
* @param boolean $enablePrivateKey RSS Private Key Flag
*
* @return boolean true if it successful, false if not
*/
public function updateUser(
$uId, $password, $name, $email, $homepage, $uContent,
$privateKey = null, $enablePrivateKey = false
) {
if (!is_numeric($uId)) {
return false;
}
// prepend '-' to privateKey if disabled
if ($privateKey != null && strlen($privateKey) == 32
&& $enablePrivateKey == false
) {
$privateKey = '-' . $privateKey;
}
// remove '-' from privateKey if enabling
if ($privateKey != null && strlen($privateKey) == 33
&& $enablePrivateKey == true
) {
$privateKey = substr($privateKey, 1, 32);
}
// if new user is enabling Private Key, create new key
if ($privateKey == null && $enablePrivateKey == true) {
$privateKey = $this->getNewPrivateKey();
}
// Set up the SQL UPDATE statement. // Set up the SQL UPDATE statement.
$moddatetime = gmdate('Y-m-d H:i:s', time()); $moddatetime = gmdate('Y-m-d H:i:s', time());
if ($password == '') if ($password == '') {
$updates = array ('uModified' => $moddatetime, 'name' => $name, 'email' => $email, 'homepage' => $homepage, 'uContent' => $uContent); $updates = array (
else 'uModified' => $moddatetime, 'name' => $name,
$updates = array ('uModified' => $moddatetime, 'password' => $this->sanitisePassword($password), 'name' => $name, 'email' => $email, 'homepage' => $homepage, 'uContent' => $uContent); 'email' => $email, 'homepage' => $homepage,
$sql = 'UPDATE '. $this->getTableName() .' SET '. $this->db->sql_build_array('UPDATE', $updates) .' WHERE '. $this->getFieldName('primary') .'='. intval($uId); 'uContent' => $uContent, 'privateKey' => $privateKey);
} else {
$updates = array ('uModified' => $moddatetime,
'password' => $this->sanitisePassword($password),
'name' => $name, 'email' => $email, 'homepage' => $homepage,
'uContent' => $uContent, 'privateKey' => $privateKey);
}
$sql = 'UPDATE '. $this->getTableName() .' SET '
. $this->db->sql_build_array('UPDATE', $updates) .' WHERE '
. $this->getFieldName('primary') .'='. intval($uId);
// Execute the statement. // Execute the statement.
$this->db->sql_transaction('begin'); $this->db->sql_transaction('begin');
if (!($dbresult = & $this->db->sql_query($sql))) { if (!($dbresult = & $this->db->sql_query($sql))) {
$this->db->sql_transaction('rollback'); $this->db->sql_transaction('rollback');
message_die(GENERAL_ERROR, 'Could not update user', '', __LINE__, __FILE__, $sql, $this->db); message_die(
GENERAL_ERROR, 'Could not update user', '',
__LINE__, __FILE__, $sql, $this->db
);
return false; return false;
} }
$this->db->sql_transaction('commit'); $this->db->sql_transaction('commit');
@ -685,17 +942,26 @@ class SemanticScuttle_Service_User extends SemanticScuttle_DbService
return true; return true;
} }
function getAllUsers ( ) { /**
* Get list of All Users
*
* @return array List of Users
*/
function getAllUsers()
{
$query = 'SELECT * FROM '. $this->getTableName(); $query = 'SELECT * FROM '. $this->getTableName();
if (! ($dbresult =& $this->db->sql_query($query)) ) { if (! ($dbresult =& $this->db->sql_query($query)) ) {
message_die(GENERAL_ERROR, 'Could not get users', '', __LINE__, __FILE__, $query, $this->db); message_die(
GENERAL_ERROR, 'Could not get users', '',
__LINE__, __FILE__, $query, $this->db
);
return false; return false;
} }
$rows = array(); $rows = array();
while ( $row = $this->db->sql_fetchrow($dbresult) ) { while ($row = $this->db->sql_fetchrow($dbresult)) {
$rows[] = $row; $rows[] = $row;
} }
$this->db->sql_freeresult($dbresult); $this->db->sql_freeresult($dbresult);
@ -703,20 +969,39 @@ class SemanticScuttle_Service_User extends SemanticScuttle_DbService
} }
// Returns an array with admin uIds // Returns an array with admin uIds
function getAdminIds() { /**
* Get list of Admin IDs
*
* @return array Admins Admin IDs
*/
function getAdminIds()
{
$admins = array(); $admins = array();
foreach($GLOBALS['admin_users'] as $adminName) { foreach ($GLOBALS['admin_users'] as $adminName) {
if($this->getIdFromUser($adminName) != NULL) if ($this->getIdFromUser($adminName) != null) {
$admins[] = $this->getIdFromUser($adminName); $admins[] = $this->getIdFromUser($adminName);
}
} }
return $admins; return $admins;
} }
function deleteUser($uId) { /**
$query = 'DELETE FROM '. $this->getTableName() .' WHERE uId = '. intval($uId); * Delete a user based on user ID
*
* @param string $uId User ID
*
* @return boolean true if it successful, false if not
*/
function deleteUser($uId)
{
$query = 'DELETE FROM '. $this->getTableName() .
' WHERE uId = '. intval($uId);
if (!($dbresult = & $this->db->sql_query($query))) { if (!($dbresult = & $this->db->sql_query($query))) {
message_die(GENERAL_ERROR, 'Could not delete user', '', __LINE__, __FILE__, $query, $this->db); message_die(
GENERAL_ERROR, 'Could not delete user',
'', __LINE__, __FILE__, $query, $this->db
);
return false; return false;
} }
@ -777,7 +1062,66 @@ class SemanticScuttle_Service_User extends SemanticScuttle_DbService
} }
} }
function isReserved($username) {
/**
* Generates a new private key and confirms it isn't being used.
* Private key is 32 characters long, consisting of lowercase and
* numeric characters.
*
* @return string the new key value
*/
public function getNewPrivateKey()
{
do {
$newKey = md5(uniqid('SemanticScuttle', true));
} while ($this->privateKeyExists($newKey));
return $newKey;
}
/**
* Checks if a private key already exists
*
* @param string $privateKey key that has been generated
*
* @return boolean true when the private key exists,
* False if not.
*/
public function privateKeyExists($privateKey)
{
if (!$privateKey) {
return false;
}
$crit = array('privateKey' => $privateKey);
$sql = 'SELECT COUNT(*) as "0" FROM '
. $GLOBALS['tableprefix'] . 'users'
. ' WHERE '. $this->db->sql_build_array('SELECT', $crit);
if (!($dbresult = $this->db->sql_query($sql))) {
message_die(
GENERAL_ERROR, 'Could not get vars', '',
__LINE__, __FILE__, $sql, $this->db
);
}
if ($this->db->sql_fetchfield(0, 0) > 0) {
$exists = true;
} else {
$exists = false;
}
$this->db->sql_freeresult($dbresult);
return $exists;
}
/**
* Checks if the given username is a reserved username
*
* @param string $username User Name
*
* @return boolean true if it is valid, false if not
*/
function isReserved($username)
{
if (in_array($username, $GLOBALS['reservedusers'])) { if (in_array($username, $GLOBALS['reservedusers'])) {
return true; return true;
} else { } else {
@ -785,11 +1129,20 @@ class SemanticScuttle_Service_User extends SemanticScuttle_DbService
} }
} }
function isValidUsername($username) { /**
* Checks if the given username is valid
*
* @param string $username User Name
*
* @return boolean true if it is valid, false if not
*/
function isValidUsername($username)
{
if (strlen($username) < 4) { if (strlen($username) < 4) {
return false; return false;
}elseif (strlen($username) > 24) { } elseif (strlen($username) > 24) {
// too long usernames are cut by database and may cause bugs when compared // too long usernames are cut by database
//and may cause bugs when compared
return false; return false;
} elseif (preg_match('/(\W)/', $username) > 0) { } elseif (preg_match('/(\W)/', $username) > 0) {
// forbidden non-alphanumeric characters // forbidden non-alphanumeric characters
@ -798,14 +1151,12 @@ class SemanticScuttle_Service_User extends SemanticScuttle_DbService
return true; return true;
} }
/** /**
* Checks if the given email address is valid * Checks if the given email address is valid
* *
* @param string $email Email address * @param string $email Email address
* *
* @return boolean True if it is valid, false if not * @return boolean true if it is valid, false if not
*/ */
public function isValidEmail($email) public function isValidEmail($email)
{ {
@ -837,7 +1188,7 @@ class SemanticScuttle_Service_User extends SemanticScuttle_DbService
* call with that session id. If the session is old, * call with that session id. If the session is old,
* we know that cookies (or session persistance) works * we know that cookies (or session persistance) works
* *
* @return boolean True if the * @return boolean true if the
* *
* @see updateSessionStability() * @see updateSessionStability()
*/ */
@ -873,11 +1224,49 @@ class SemanticScuttle_Service_User extends SemanticScuttle_DbService
$this->fields[$field] = $value; $this->fields[$field] = $value;
} }
function getSessionKey() { return $this->sessionkey; } /**
function setSessionKey($value) { $this->sessionkey = $value; } * Get session key
*
* @return string Value
*/
function getSessionKey()
{
return $this->sessionkey;
}
function getCookieKey() { return $this->cookiekey; } /**
function setCookieKey($value) { $this->cookiekey = $value; } * Set session key
*
* @param string $value Session Key
*
* @return void
*/
function setSessionKey($value)
{
$this->sessionkey = $value;
}
/**
* Get cookie key
*
* @return string Value
*/
function getCookieKey()
{
return $this->cookiekey;
}
/**
* Set cookie key
*
* @param string $value Cookie Key
*
* @return void
*/
function setCookieKey($value)
{
$this->cookiekey = $value;
}
} }
?> ?>

View File

@ -550,7 +550,7 @@ class sql_db
} }
$sql_report .= '</p>'; $sql_report .= '</p>';
echo $sql_report;
$this->sql_time += $endtime - $curtime; $this->sql_time += $endtime - $curtime;
break; break;
} }
@ -559,4 +559,4 @@ class sql_db
} // if ... define } // if ... define
?> ?>

View File

@ -18,34 +18,36 @@
// Converts tags: // Converts tags:
// - direction = out: convert spaces to underscores; // - direction = out: convert spaces to underscores;
// - direction = in: convert underscores to spaces. // - direction = in: convert underscores to spaces.
function convertTag($tag, $direction = 'out') { function convertTag($tag, $direction = 'out')
if ($direction == 'out') { {
$tag = str_replace(' ', '_', $tag); if ($direction == 'out') {
} else { $tag = str_replace(' ', '_', $tag);
$tag = str_replace('_', ' ', $tag); } else {
} $tag = str_replace('_', ' ', $tag);
return $tag; }
return $tag;
} }
function filter($data, $type = NULL) { function filter($data, $type = null)
if (is_string($data)) { {
$data = trim($data); if (is_string($data)) {
$data = stripslashes($data); $data = trim($data);
switch ($type) { $data = stripslashes($data);
case 'url': switch ($type) {
$data = rawurlencode($data); case 'url':
break; $data = rawurlencode($data);
default: break;
$data = htmlspecialchars($data); default:
break; $data = htmlspecialchars($data);
} break;
} else if (is_array($data)) { }
foreach(array_keys($data) as $key) { } else if (is_array($data)) {
$row =& $data[$key]; foreach (array_keys($data) as $key) {
$row = filter($row, $type); $row =& $data[$key];
} $row = filter($row, $type);
} }
return $data; }
return $data;
} }
/** /**
@ -60,63 +62,67 @@ function filter($data, $type = NULL) {
*/ */
function getPerPageCount($userObject = null) function getPerPageCount($userObject = null)
{ {
global $defaultPerPage, $defaultPerPageForAdmins; global $defaultPerPage, $defaultPerPageForAdmins;
if (isset($defaultPerPageForAdmins) if (isset($defaultPerPageForAdmins)
&& $userObject != null && $userObject->isAdmin() && $userObject != null
&& $userObject->isAdmin()
) { ) {
return $defaultPerPageForAdmins; return $defaultPerPageForAdmins;
} else { } else {
return $defaultPerPage; return $defaultPerPage;
} }
} }
function getSortOrder($override = NULL) { function getSortOrder($override = null)
global $defaultOrderBy; {
global $defaultOrderBy;
if (isset($_GET['sort'])) { if (isset($_GET['sort'])) {
return preg_replace('/[^a-z_]/', '', $_GET['sort']); return preg_replace('/[^a-z_]/', '', $_GET['sort']);
} else if (isset($override)) { } elseif (isset($override)) {
return $override; return $override;
} else { } else {
return $defaultOrderBy; return $defaultOrderBy;
} }
} }
function multi_array_search($needle, $haystack) { function multi_array_search($needle, $haystack)
if (is_array($haystack)) { {
foreach(array_keys($haystack) as $key) { if (is_array($haystack)) {
$value =& $haystack[$key]; foreach (array_keys($haystack) as $key) {
$result = multi_array_search($needle, $value); $value =& $haystack[$key];
if (is_array($result)) { $result = multi_array_search($needle, $value);
$return = $result; if (is_array($result)) {
array_unshift($return, $key); $return = $result;
return $return; array_unshift($return, $key);
} elseif ($result == true) { return $return;
$return[] = $key; } elseif ($result == true) {
return $return; $return[] = $key;
} return $return;
} }
return false; }
} else { return false;
if ($needle === $haystack) { } else {
return true; if ($needle === $haystack) {
} else { return true;
return false; } else {
} return false;
} }
}
} }
function createURL($page = '', $ending = '') { function createURL($page = '', $ending = '')
global $cleanurls; {
if (!$cleanurls && $page != '') { global $cleanurls;
$page .= '.php'; if (!$cleanurls && $page != '') {
} $page .= '.php';
if(strlen($ending)>0) { }
return ROOT . $page .'/'. $ending; if (strlen($ending)>0) {
} else { return ROOT . $page .'/'. $ending;
return ROOT . $page; } else {
} return ROOT . $page;
}
} }
/** /**
* Creates a "vote for/against this bookmark" URL. * Creates a "vote for/against this bookmark" URL.
@ -139,116 +145,129 @@ function createVoteURL($for, $bId)
} }
/* Shorten a string like a URL for example by cutting the middle of it */ /* Shorten a string like a URL for example by cutting the middle of it */
function shortenString($string, $maxSize=75) { function shortenString($string, $maxSize=75)
$output = ''; {
if(strlen($string) > $maxSize) { $output = '';
$output = substr($string, 0, $maxSize/2).'...'.substr($string, -$maxSize/2); if (strlen($string) > $maxSize) {
} else { $output = substr($string, 0, $maxSize/2).'...'.substr($string, -$maxSize/2);
$output = $string; } else {
} $output = $string;
return $output; }
return $output;
} }
/* Check url format and check online if the url is a valid page (Not a 404 error for example) */ /* Check url format and check online if the url is a valid page (Not a 404 error for example) */
function checkUrl($url, $checkOnline = true) { function checkUrl($url, $checkOnline = true)
//check format {
if(!preg_match("#(ht|f)tp(s?)\://\S+\.\S+#i",$url)) { //check format
return false; if (!preg_match("#(ht|f)tp(s?)\://\S+\.\S+#i", $url)) {
} return false;
}
if($checkOnline) { if ($checkOnline) {
//look if the page doesn't return a void or 40X or 50X HTTP code error //look if the page doesn't return a void or 40X or 50X HTTP code error
$h = @get_headers($url); $h = @get_headers($url);
if(is_array($h) && strpos($h[0], '40') === false && strpos($h[0], '50') === false) { if (is_array($h) && strpos($h[0], '40') === false && strpos($h[0], '50') === false) {
return true; return true;
} else { } else {
return false; return false;
} }
} else { } else {
return true; return true;
} }
} }
/* Returns a concatenated String /* Returns a concatenated String
* including all the tags from the array $arrayTags (excepted of the $exceptedTag) * including all the tags from the array $arrayTags (excepted of the $exceptedTag)
* separated by the $separator. * separated by the $separator.
* */ * */
function aggregateTags($arrayTags, $separator = ' + ', $exceptedTag = '') { function aggregateTags($arrayTags, $separator = ' + ', $exceptedTag = '')
$output = ''; {
$output = '';
for($i = 0; $i<count($arrayTags); $i++) { for ($i = 0; $i<count($arrayTags); $i++) {
if($arrayTags[$i] != $exceptedTag) { if ($arrayTags[$i] != $exceptedTag) {
$output.= $arrayTags[$i] . $separator; $output.= $arrayTags[$i] . $separator;
} }
} }
return substr($output, 0, strlen($output) - strlen($separator) ); return substr($output, 0, strlen($output) - strlen($separator));
} }
function message_die($msg_code, $msg_text = '', $msg_title = '', $err_line = '', $err_file = '', $sql = '', $db = NULL) { function message_die($msg_code, $msg_text = '', $msg_title = '', $err_line = '', $err_file = '', $sql = '', $db = null)
if(defined('HAS_DIED')) {
die(T_('message_die() was called multiple times.')); if (defined('HAS_DIED')) {
define('HAS_DIED', 1); die(T_('message_die() was called multiple times.'));
}
define('HAS_DIED', 1);
$sql_store = $sql; $sql_store = $sql;
// Get SQL error if we are debugging. Do this as soon as possible to prevent // Get SQL error if we are debugging. Do this as soon as possible to prevent
// subsequent queries from overwriting the status of sql_error() // subsequent queries from overwriting the status of sql_error()
if (DEBUG_MODE && ($msg_code == GENERAL_ERROR || $msg_code == CRITICAL_ERROR)) { if (DEBUG_MODE && ($msg_code == GENERAL_ERROR || $msg_code == CRITICAL_ERROR)) {
$sql_error = is_null($db) ? '' : $db->sql_error(); $sql_error = is_null($db) ? '' : $db->sql_error();
$debug_text = ''; $debug_text = '';
if ($sql_error['message'] != '') if ($sql_error['message'] != '') {
$debug_text .= '<br /><br />'. T_('SQL Error') .' : '. $sql_error['code'] .' '. $sql_error['message']; $debug_text .= '<br /><br />'. T_('SQL Error') .' : '. $sql_error['code'] .' '. $sql_error['message'];
}
if ($sql_store != '') if ($sql_store != '') {
$debug_text .= '<br /><br />'. $sql_store; $debug_text .= '<br /><br />'. $sql_store;
}
if ($err_line != '' && $err_file != '') if ($err_line != '' && $err_file != '') {
$debug_text .= '</br /><br />'. T_('Line') .' : '. $err_line .'<br />'. T_('File') .' :'. $err_file; $debug_text .= '</br /><br />'. T_('Line') .' : '. $err_line .'<br />'. T_('File') .' :'. $err_file;
}
debug_print_backtrace(); debug_print_backtrace();
} }
switch($msg_code) { switch($msg_code) {
case GENERAL_MESSAGE: case GENERAL_MESSAGE:
if ($msg_title == '') if ($msg_title == '') {
$msg_title = T_('Information'); $msg_title = T_('Information');
break; }
break;
case CRITICAL_MESSAGE: case CRITICAL_MESSAGE:
if ($msg_title == '') if ($msg_title == '') {
$msg_title = T_('Critical Information'); $msg_title = T_('Critical Information');
break; }
break;
case GENERAL_ERROR: case GENERAL_ERROR:
if ($msg_text == '') if ($msg_text == '') {
$msg_text = T_('An error occured'); $msg_text = T_('An error occured');
}
if ($msg_title == '') {
$msg_title = T_('General Error');
}
break;
if ($msg_title == '') case CRITICAL_ERROR:
$msg_title = T_('General Error'); // Critical errors mean we cannot rely on _ANY_ DB information being
break; // available so we're going to dump out a simple echo'd statement
case CRITICAL_ERROR: if ($msg_text == '') {
// Critical errors mean we cannot rely on _ANY_ DB information being $msg_text = T_('An critical error occured');
// available so we're going to dump out a simple echo'd statement }
if ($msg_title == '') {
$msg_title = T_('Critical Error');
}
break;
}
if ($msg_text == '') // Add on DEBUG_MODE info if we've enabled debug mode and this is an error. This
$msg_text = T_('An critical error occured'); // prevents debug info being output for general messages should DEBUG_MODE be
// set TRUE by accident (preventing confusion for the end user!)
if (DEBUG_MODE && ($msg_code == GENERAL_ERROR || $msg_code == CRITICAL_ERROR)) {
if ($debug_text != '') {
$msg_text = $msg_text . '<br /><br /><strong>'. T_('DEBUG MODE') .'</strong>'. $debug_text;
}
}
if ($msg_title == '') echo "<html>\n<body>\n". $msg_title ."\n<br /><br />\n". $msg_text ."</body>\n</html>";
$msg_title = T_('Critical Error'); exit;
break;
}
// Add on DEBUG_MODE info if we've enabled debug mode and this is an error. This
// prevents debug info being output for general messages should DEBUG_MODE be
// set TRUE by accident (preventing confusion for the end user!)
if (DEBUG_MODE && ($msg_code == GENERAL_ERROR || $msg_code == CRITICAL_ERROR)) {
if ($debug_text != '')
$msg_text = $msg_text . '<br /><br /><strong>'. T_('DEBUG MODE') .'</strong>'. $debug_text;
}
echo "<html>\n<body>\n". $msg_title ."\n<br /><br />\n". $msg_text ."</body>\n</html>";
exit;
} }
?> ?>

View File

@ -58,4 +58,4 @@ class AllTests extends PHPUnit_Framework_TestSuite
{ {
} }
} }
?> ?>

View File

@ -608,4 +608,4 @@ class Bookmark2TagTest extends TestBase
$this->assertContains(array('tag' => 'usable', 'bCount' => '2'), $arTags); $this->assertContains(array('tag' => 'usable', 'bCount' => '2'), $arTags);
} }
} }
?> ?>

View File

@ -1150,7 +1150,7 @@ class BookmarkTest extends TestBase
//create bookmarks for main user and other one //create bookmarks for main user and other one
$this->addBookmark($uid, $address, 0); $this->addBookmark($uid, $address, 0);
$this->addBookmark($friendPublic1, $address, 1);//1 is shared $this->addBookmark($friendPublic1, $address, 1);//1 is shared
//log main user in //log main user in
$this->us->setCurrentUserId($uid); $this->us->setCurrentUserId($uid);
@ -1328,6 +1328,51 @@ class BookmarkTest extends TestBase
); );
} }
/**
* Test private bookmarks
*
* @return void
*/
public function testPrivateBookmarks()
{
$uid = $this->addUser();
/* create private bookmark */
$this->bs->addBookmark(
'http://test', 'test', 'desc', 'note',
2,//private
array(), null, null, false, false, $uid
);
/* create public bookmark */
$this->bs->addBookmark(
'http://example.org', 'title', 'desc', 'priv',
0,//public
array(), null, null, false, false, $uid
);
$this->assertEquals(1, $this->bs->countBookmarks($uid, 'public'));
$this->assertEquals(1, $this->bs->countBookmarks($uid, 'private'));
$this->assertEquals(0, $this->bs->countBookmarks($uid, 'shared'));
$this->assertEquals(2, $this->bs->countBookmarks($uid, 'all'));
$this->us->setCurrentUserId($uid);
$bookmarks = $this->bs->getBookmarks();
// first record should be private bookmark
$b0 = $bookmarks['bookmarks'][0];
$this->assertEquals('test', $b0['bTitle']);
// second record should be public bookmark
$b0 = $bookmarks['bookmarks'][1];
$this->assertEquals('title', $b0['bTitle']);
// test non authenticated query
$this->us->setCurrentUserId(null);
$bookmarks = $this->bs->getBookmarks();
// should only result in one link - public
$b2 = $bookmarks['bookmarks'][0];
$this->assertEquals('title', $b2['bTitle']);
// there should be no second record
$this->assertEquals(1,count($bookmarks['bookmarks']));
}
} }

View File

@ -78,14 +78,15 @@ class TestBase extends PHPUnit_Framework_TestCase
* *
* @param string $username Username * @param string $username Username
* @param string $password Password * @param string $password Password
* @param string $pkey Private Key
* *
* @return integer ID of user * @return integer ID of user
* *
* @uses addUserData() * @uses addUserData()
*/ */
protected function addUser($username = null, $password = null) protected function addUser($username = null, $password = null, $pkey = null)
{ {
return reset($this->addUserData($username, $password)); return reset($this->addUserData($username, $password, $pkey));
} }
@ -95,10 +96,11 @@ class TestBase extends PHPUnit_Framework_TestCase
* *
* @param string $username Username * @param string $username Username
* @param string $password Password * @param string $password Password
* @param string $pkey Private Key
* *
* @return array ID of user, Name of user, password of user * @return array ID of user, Name of user, password of user
*/ */
protected function addUserData($username = null, $password = null) protected function addUserData($username = null, $password = null, $pkey = null)
{ {
$us = SemanticScuttle_Service_Factory::get('User'); $us = SemanticScuttle_Service_Factory::get('User');
$rand = rand(); $rand = rand();
@ -113,7 +115,8 @@ class TestBase extends PHPUnit_Framework_TestCase
$uid = $us->addUser( $uid = $us->addUser(
$username, $username,
$password, $password,
'unittest-' . $rand . '@example.org' 'unittest-' . $rand . '@example.org',
$pkey
); );
return array($uid, $username, $password); return array($uid, $username, $password);
} }
@ -148,4 +151,4 @@ class TestBase extends PHPUnit_Framework_TestCase
} }
} }
?> ?>

View File

@ -241,4 +241,4 @@ class TestBaseApi extends TestBase
); );
} }
} }
?> ?>

View File

@ -34,6 +34,157 @@ class UserTest extends TestBase
/**
* @covers SemanticScuttle_Service_User::addUser
*/
public function testAddUserPrivateKey()
{
$name = substr(md5(uniqid()), 0, 6);
$pkey = 'my-privatekey';
$id = $this->us->addUser(
$name, uniqid(), 'foo@example.org', $pkey
);
$this->assertNotEquals(false, $id);
$this->assertInternalType('integer', $id);
$arUser = $this->us->getUserByPrivateKey($pkey);
$this->assertNotEquals(false, $arUser, 'user not found by private key');
$this->assertEquals($id, $arUser['uId'], 'wrong user loaded');
}
/**
* @covers SemanticScuttle_Service_User::updateUser
*/
public function testUpdateUserFalseWhenIdNotNumeric()
{
$this->assertFalse(
$this->us->updateUser('foo', null, null, null, null, null)
);
}
/**
* @covers SemanticScuttle_Service_User::updateUser
*/
public function testUpdateUserPrivateKeyNewKeyEnabled()
{
$pkey = 'testUpdateUserPrivateKeyNewKey12';
$uid = $this->addUser();
$this->assertTrue(
$this->us->updateUser(
$uid, 'password', 'name', 'test@example.org', '', '',
$pkey, true
)
);
$arUser = $this->us->getUser($uid);
$this->assertInternalType('array', $arUser);
$this->assertEquals($pkey, $arUser['privateKey']);
}
/**
* @covers SemanticScuttle_Service_User::updateUser
*/
public function testUpdateUserPrivateKeyNewKeyDisabled()
{
$pkey = 'testUpdateUserPrivateKeyNewKeyDi';
$uid = $this->addUser();
$this->assertTrue(
$this->us->updateUser(
$uid, 'password', 'name', 'test@example.org', '', '',
$pkey, false
)
);
$arUser = $this->us->getUser($uid);
$this->assertInternalType('array', $arUser);
$this->assertEquals(
'-' . $pkey, $arUser['privateKey'],
'private key did not get disabled'
);
}
/**
* Passing an empty string / NULL as key but enabling it
* should automatically create a new key.
*
* @covers SemanticScuttle_Service_User::updateUser
*/
public function testUpdateUserPrivateKeyNoKeyEnabled()
{
$pkey = 'testUpdateUserPrivateKeyNoKeyEna';
$uid = $this->addUser();
$this->assertTrue(
$this->us->updateUser(
$uid, 'password', 'name', 'test@example.org', '', '',
null, true
)
);
$arUser = $this->us->getUser($uid);
$this->assertInternalType('array', $arUser);
$this->assertNotEquals(
'', $arUser['privateKey'], 'private key was not created'
);
}
/**
* Passing an empty string / NULL as key and disabling it
* should keep no key
*
* @covers SemanticScuttle_Service_User::updateUser
*/
public function testUpdateUserPrivateKeyNoKeyDisabled()
{
$pkey = 'testUpdateUserPrivateKeyNoKeyDis';
$uid = $this->addUser();
$this->assertTrue(
$this->us->updateUser(
$uid, 'password', 'name', 'test@example.org', '', '',
null, false
)
);
$arUser = $this->us->getUser($uid);
$this->assertInternalType('array', $arUser);
$this->assertEquals(
'', $arUser['privateKey'], 'private key was set'
);
}
/**
* Passing an empty string / NULL as key and disabling it
* should keep no key
*
* @covers SemanticScuttle_Service_User::updateUser
*/
public function testUpdateUserPrivateKeyExistingKeyEnabled()
{
$pkey = '12345678901234567890123456789012';
$uid = $this->addUser();
$this->assertTrue(
$this->us->updateUser(
$uid, 'password', 'name', 'test@example.org', '', '',
'-' . $pkey, true
)
);
$arUser = $this->us->getUser($uid);
$this->assertInternalType('array', $arUser);
$this->assertEquals(
$pkey, $arUser['privateKey'], 'private key was not enabled'
);
}
//FIXME: verify I cannot re-use private key of different user
/** /**
* Test that setting the current user ID is permanent. * Test that setting the current user ID is permanent.
* and that the current user array is the same ID * and that the current user array is the same ID
@ -176,5 +327,185 @@ class UserTest extends TestBase
); );
} }
public function testGetUserByPrivateKeyEmptyKey()
{
$arUser = $this->us->getUserByPrivateKey(null);
$this->assertFalse($arUser);
}
public function testGetUserByPrivateKeyInvalid()
{
$arUser = $this->us->getUserByPrivateKey('foobar');
$this->assertFalse($arUser);
$arUser = $this->us->getUserByPrivateKey('%');
$this->assertFalse($arUser);
}
public function testGetUserByPrivateKeyValidKey()
{
$pkey = $this->us->getNewPrivateKey();
$uId = $this->addUser(null, null, $pkey);
$arUser = $this->us->getUserByPrivateKey($pkey);
$this->assertInternalType('array', $arUser);
$this->assertArrayHasKey('uId', $arUser);
$this->assertArrayHasKey('username', $arUser);
$this->assertEquals($uId, $arUser['uId']);
}
/**
* @covers SemanticScuttle_Service_User::privateKeyExists
*/
public function testPrivateKeyExistsEmpty()
{
$this->assertFalse($this->us->privateKeyExists(null));
$this->assertFalse($this->us->privateKeyExists(''));
}
/**
* @covers SemanticScuttle_Service_User::privateKeyExists
*/
public function testPrivateKeyExistsInvalid()
{
$this->assertFalse($this->us->privateKeyExists('-1'));
}
/**
* @covers SemanticScuttle_Service_User::privateKeyExists
*/
public function testPrivateKeyExists()
{
$randKey = $this->us->getNewPrivateKey();
$this->assertFalse($this->us->privateKeyExists($randKey));
$uid = $this->addUser(null, null, $randKey);
$this->us->setCurrentUserId($uid);
$this->assertEquals($uid, $this->us->getCurrentUserId());
$this->assertTrue($this->us->privateKeyExists($randKey));
}
/**
* @covers SemanticScuttle_Service_User::isPrivateKeyValid
*/
public function testIsPrivateKeyValid()
{
$this->assertFalse(
$this->us->isPrivateKeyValid(null),
'NULL is an invalid private key'
);
$randKey = $this->us->getNewPrivateKey();
$this->assertTrue(
$this->us->isPrivateKeyValid($randKey),
'generated key should be valid'
);
$randKey2 = '-'.$this->us->getNewPrivateKey();
$this->assertFalse(
$this->us->isPrivateKeyValid($randKey2),
'disabled privatekey should return false'
);
}
public function testLoginPrivateKeyInvalid()
{
/* normal user with enabled privatekey */
$randKey = $this->us->getNewPrivateKey();
$uid1 = $this->addUser('testusername', 'passw0rd', $randKey);
/* user that has disabled privatekey */
$randKey2 = '-'.$this->us->getNewPrivateKey();
$uid2 = $this->addUser('seconduser', 'passw0RD', $randKey2);
/* test invalid private key */
$this->assertFalse(
$this->us->loginPrivateKey('02848248084082408240824802408248')
);
}
public function testLoginPrivateKeyValidEnabledKey()
{
/* normal user with enabled privatekey */
$randKey = $this->us->getNewPrivateKey();
$uid1 = $this->addUser('testusername', 'passw0rd', $randKey);
/* user that has disabled privatekey */
$randKey2 = '-'.$this->us->getNewPrivateKey();
$uid2 = $this->addUser('seconduser', 'passw0RD', $randKey2);
/* test valid credentials with private key enabled */
$this->assertTrue(
$this->us->loginPrivateKey($randKey)
);
}
public function testLoginPrivateKeyInvalidEnabledKey()
{
/* normal user with enabled privatekey */
$randKey = $this->us->getNewPrivateKey();
$uid1 = $this->addUser('testusername', 'passw0rd', $randKey);
/* user that has disabled privatekey */
$randKey2 = '-'.$this->us->getNewPrivateKey();
$uid2 = $this->addUser('seconduser', 'passw0RD', $randKey2);
/* test valid credentials with private key enabled but invalid key */
$this->assertFalse(
$this->us->loginPrivateKey('123')
);
}
public function testLoginPrivateKeyValidDisabledKey()
{
/* normal user with enabled privatekey */
$randKey = $this->us->getNewPrivateKey();
$uid1 = $this->addUser('testusername', 'passw0rd', $randKey);
/* user that has disabled privatekey */
$randKey2 = '-'.$this->us->getNewPrivateKey();
$uid2 = $this->addUser('seconduser', 'passw0RD', $randKey2);
/* confirm user exists so future fails should be due to randkey */
$this->assertTrue(
$this->us->login('seconduser', 'passw0RD', false)
);
/* test valid credentials with private key disabled */
$this->assertFalse(
$this->us->loginPrivateKey($randKey2)
);
}
public function testLoginPrivateKeyInvalidDisabled()
{
/* normal user with enabled privatekey */
$randKey = $this->us->getNewPrivateKey();
$uid1 = $this->addUser('testusername', 'passw0rd', $randKey);
/* user that has disabled privatekey */
$randKey2 = '-'.$this->us->getNewPrivateKey();
$uid2 = $this->addUser('seconduser', 'passw0RD', $randKey2);
/* test valid credentials with private key disabled and invalid key */
$this->assertFalse(
$this->us->loginPrivateKey('-1')
);
$this->assertFalse(
$this->us->loginPrivateKey(null)
);
}
} }
?> ?>

View File

@ -12,4 +12,4 @@
</exclude> </exclude>
</whitelist> </whitelist>
</filter> </filter>
</phpunit> </phpunit>

View File

@ -36,4 +36,4 @@ if ($GLOBALS['debugMode'] == true
. '!!! The combination of debugMode and dbtype==mysql4' . '!!! The combination of debugMode and dbtype==mysql4'
. ' will wreck some tests' . "\n\n"; . ' will wreck some tests' . "\n\n";
} }
?> ?>

View File

@ -3,7 +3,6 @@
# (see $cleanurls in config.inc.php) # (see $cleanurls in config.inc.php)
##################################### #####################################
# Rewrite clean URLs onto real files # Rewrite clean URLs onto real files
<IfModule mod_rewrite.c> <IfModule mod_rewrite.c>
Options +FollowSymlinks Options +FollowSymlinks

View File

@ -35,57 +35,56 @@ $tplVars['sidebar_blocks'] = array('users' );
$tplVars['error'] = ''; $tplVars['error'] = '';
$tplVars['msg'] = ''; $tplVars['msg'] = '';
if ( !$userservice->isLoggedOn() ) { if (!$userservice->isLoggedOn()) {
header('Location: '. createURL('login', '')); header('Location: '. createURL('login', ''));
exit(); exit();
} }
if ( !$currentUser->isAdmin() ) { if (!$currentUser->isAdmin()) {
header('Location: '. createURL('bookmarks', $currentUser->getUsername())); header('Location: '. createURL('bookmarks', $currentUser->getUsername()));
exit(); exit();
} }
@list($url, $action, $user) = isset($_SERVER['PATH_INFO']) ? explode('/', $_SERVER['PATH_INFO']) : NULL; @list($url, $action, $user) = isset($_SERVER['PATH_INFO']) ? explode('/', $_SERVER['PATH_INFO']) : null;
if ( $action // Prevent CSRF attacks
&& (strpos($_SERVER['HTTP_REFERER'], ROOT.'admin') === 0) // Prevent CSRF attacks if ($action && (strpos($_SERVER['HTTP_REFERER'], ROOT.'admin') === 0)) {
) { switch ($action) {
switch ( $action ) { case 'delete':
case 'delete': if ($user && ($userinfo = $userservice->getUserByUsername($user))) {
if ( $user && ($userinfo = $userservice->getUserByUsername($user)) ) { $uId = $userinfo['uId'];
$uId = $userinfo['uId'];
$tagcacheservice->deleteByUser($uId); $tagcacheservice->deleteByUser($uId);
$tag2tagservice->removeLinkedTagsForUser($uId); $tag2tagservice->removeLinkedTagsForUser($uId);
$userservice->deleteUser($uId); $userservice->deleteUser($uId);
$bookmark2tagservice->deleteTagsForUser($uId); $bookmark2tagservice->deleteTagsForUser($uId);
$commondescriptionservice->deleteDescriptionsForUser($uId); $commondescriptionservice->deleteDescriptionsForUser($uId);
$searchhistoryservice->deleteSearchHistoryForUser($uId); $searchhistoryservice->deleteSearchHistoryForUser($uId);
$tagstatservice->deleteTagStatForUser($uId); $tagstatservice->deleteTagStatForUser($uId);
// XXX: don't delete bookmarks before tags, else tags can't be deleted !!! // XXX: don't delete bookmarks before tags, else tags can't be deleted !!!
$bookmarkservice->deleteBookmarksForUser($uId); $bookmarkservice->deleteBookmarksForUser($uId);
$tplVars['msg'] = sprintf(T_('%s and all his bookmarks and tags were deleted.'), $user); $tplVars['msg'] = sprintf(T_('%s and all his bookmarks and tags were deleted.'), $user);
} }
break; break;
case 'checkUrl' : case 'checkUrl' :
$bookmarks =& $bookmarkservice->getBookmarks(0, NULL, NULL, NULL, NULL, getSortOrder()); $bookmarks =& $bookmarkservice->getBookmarks(0, null, null, null, null, getSortOrder());
foreach($bookmarks['bookmarks'] as $bookmark) { foreach ($bookmarks['bookmarks'] as $bookmark) {
if(!checkUrl($bookmark['bAddress'])) { if (!checkUrl($bookmark['bAddress'])) {
$tplVars['error'].= T_('Problem with ').$bookmark['bAddress'].' ('. $bookmark['username'] .')<br/>'; $tplVars['error'].= T_('Problem with ').$bookmark['bAddress'].' ('. $bookmark['username'] .')<br/>';
} }
} }
break; break;
default: default:
// DO NOTHING // DO NOTHING
} }
} }
$templatename = 'admin.tpl'; $templatename = 'admin.tpl';
$users =& $userservice->getObjectUsers(); $users =& $userservice->getObjectUsers();
if ( !is_array($users) ) { if (!is_array($users)) {
$users = array(); $users = array();
} }
$tplVars['users'] =& $users; $tplVars['users'] =& $users;

View File

@ -19,26 +19,25 @@ along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
***************************************************************************/ ***************************************************************************/
/* Return a json file with list of tags according to current user and sort by popularity*/ /* Return a json file with list of tags according */
/* to current user and sort by popularity */
$httpContentType = 'application/json'; $httpContentType = 'application/json';
require_once '../www-header.php'; require_once '../www-header.php';
/* Service creation: only useful services are created */ /* Service creation: only useful services are created */
$b2tservice =SemanticScuttle_Service_Factory::get('Bookmark2Tag'); $b2tservice = SemanticScuttle_Service_Factory::get('Bookmark2Tag');
$bookmarkservice =SemanticScuttle_Service_Factory::get('Tag'); $bookmarkservice = SemanticScuttle_Service_Factory::get('Tag');
?> ?>
{identifier:"tag", {identifier:"tag",
items: [ items: [
<?php <?php
$listTags = $b2tservice->getPopularTags($userservice->getCurrentUserId(), 1000, $userservice->getCurrentUserId()); $listTags = $b2tservice->getPopularTags(
foreach($listTags as $t) { $userservice->getCurrentUserId(), 1000, $userservice->getCurrentUserId()
echo "{tag: \"".$t['tag']."\"},"; );
} foreach ($listTags as $t) {
echo "{tag: \"".$t['tag']."\"},";
}
?> ?>
]} ]}

View File

@ -0,0 +1,42 @@
<?php
/***************************************************************************
Copyright (C) 2005 - 2006 Scuttle project
http://sourceforge.net/projects/scuttle/
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
***************************************************************************/
header("Last-Modified: ". gmdate("D, d M Y H:i:s") ." GMT");
header("Cache-Control: no-cache, must-revalidate");
$httpContentType = 'text/xml';
require_once 'www-header.php';
$us = SemanticScuttle_Service_Factory::get('User');
/* Managing all possible inputs */
isset($_GET['url']) ? define('GET_URL', $_GET['url']): define('GET_URL', '');
echo '<?xml version="1.0" encoding="utf-8"?>';
?>
<response>
<method>
getNewPrivateKey
</method>
<result>
<?php echo $us->getNewPrivateKey(); ?>
</result>
</response>

View File

@ -28,38 +28,39 @@ require_once 'www-header.php';
/* Managing all possible inputs */ /* Managing all possible inputs */
isset($_GET['url']) ? define('GET_URL', $_GET['url']): define('GET_URL', ''); isset($_GET['url']) ? define('GET_URL', $_GET['url']): define('GET_URL', '');
function getTitle($url) { function getTitle($url)
$fd = @fopen($url, 'r'); {
if ($fd) { $fd = @fopen($url, 'r');
$html = fread($fd, 1750); if ($fd) {
fclose($fd); $html = fread($fd, 1750);
fclose($fd);
// Get title from title tag // Get title from title tag
preg_match_all('/<title>(.*)<\/title>/si', $html, $matches); preg_match_all('/<title>(.*)<\/title>/si', $html, $matches);
$title = $matches[1][0]; $title = $matches[1][0];
// Get encoding from charset attribute // Get encoding from charset attribute
preg_match_all('/<meta.*charset=([^;"]*)">/i', $html, $matches); preg_match_all('/<meta.*charset=([^;"]*)">/i', $html, $matches);
$encoding = strtoupper($matches[1][0]); $encoding = strtoupper($matches[1][0]);
// Convert to UTF-8 from the original encoding // Convert to UTF-8 from the original encoding
if (function_exists("mb_convert_encoding")) { if (function_exists("mb_convert_encoding")) {
$title = @mb_convert_encoding($title, 'UTF-8', $encoding); $title = @mb_convert_encoding($title, 'UTF-8', $encoding);
} }
if (utf8_strlen($title) > 0) { if (utf8_strlen($title) > 0) {
return $title; return $title;
} else { } else {
// No title, so return filename // No title, so return filename
$uriparts = explode('/', $url); $uriparts = explode('/', $url);
$filename = end($uriparts); $filename = end($uriparts);
unset($uriparts); unset($uriparts);
return $filename; return $filename;
} }
} else { } else {
return false; return false;
} }
} }
echo '<?xml version="1.0" encoding="utf-8"?>'; echo '<?xml version="1.0" encoding="utf-8"?>';
?> ?>

View File

@ -30,37 +30,35 @@ list($url, $user) = explode(
isset($_SERVER['PATH_INFO']) ? $_SERVER['PATH_INFO'] : '/' isset($_SERVER['PATH_INFO']) ? $_SERVER['PATH_INFO'] : '/'
); );
if (!$user) { if (!$user) {
header('Location: '. createURL('populartags')); header('Location: '. createURL('populartags'));
exit; exit;
} }
if ($usecache) { if ($usecache) {
// Generate hash for caching on // Generate hash for caching on
$hashtext = $_SERVER['REQUEST_URI']; $hashtext = $_SERVER['REQUEST_URI'];
if ($userservice->isLoggedOn()) { if ($userservice->isLoggedOn()) {
$hashtext .= $userservice->getCurrentUserID(); $hashtext .= $userservice->getCurrentUserID();
} }
$hash = md5($hashtext); $hash = md5($hashtext);
// Cache for an hour // Cache for an hour
$cacheservice->Start($hash, 3600); $cacheservice->Start($hash, 3600);
} }
// Header variables // Header variables
$pagetitle = T_('All Tags'); $pagetitle = T_('All Tags');
if (isset($user) && $user != '') { if (isset($user) && $user != '') {
$userid = $userservice->getIdFromUser($user);
$userid = $userservice->getIdFromUser($user); if ($userid == null) {
if($userid == NULL) { $tplVars['error'] = sprintf(T_('User with username %s was not found'), $user);
$tplVars['error'] = sprintf(T_('User with username %s was not found'), $user); $templateservice->loadTemplate('error.404.tpl', $tplVars);
$templateservice->loadTemplate('error.404.tpl', $tplVars); exit();
exit(); }
} $pagetitle .= ': '. ucfirst($user);
$pagetitle .= ': '. ucfirst($user);
} else { } else {
$userid = NULL; $userid = null;
} }
$tags =& $b2tservice->getTags($userid); $tags =& $b2tservice->getTags($userid);
@ -68,9 +66,9 @@ $tplVars['tags'] =& $b2tservice->tagCloud($tags, 5, 90, 225, getSortOrder());
$tplVars['user'] = $user; $tplVars['user'] = $user;
if (isset($userid)) { if (isset($userid)) {
$tplVars['cat_url'] = createURL('bookmarks', '%s/%s'); $tplVars['cat_url'] = createURL('bookmarks', '%s/%s');
} else { } else {
$tplVars['cat_url'] = createURL('tags', '%2$s'); $tplVars['cat_url'] = createURL('tags', '%2$s');
} }
$tplVars['sidebar_blocks'] = array('linked'); $tplVars['sidebar_blocks'] = array('linked');
@ -82,7 +80,7 @@ $tplVars['subtitle'] = $pagetitle;
$templateservice->loadTemplate('tags.tpl', $tplVars); $templateservice->loadTemplate('tags.tpl', $tplVars);
if ($usecache) { if ($usecache) {
// Cache output if existing copy has expired // Cache output if existing copy has expired
$cacheservice->End($hash); $cacheservice->End($hash);
} }
?> ?>

View File

@ -20,7 +20,7 @@ require_once 'httpauth.inc.php';
header("Content-disposition: filename=exportBookmarks.csv"); header("Content-disposition: filename=exportBookmarks.csv");
/* Service creation: only useful services are created */ /* Service creation: only useful services are created */
$bookmarkservice =SemanticScuttle_Service_Factory::get('Bookmark'); $bookmarkservice = SemanticScuttle_Service_Factory::get('Bookmark');
// Check to see if a tag was specified. // Check to see if a tag was specified.
if (isset($_REQUEST['tag']) && (trim($_REQUEST['tag']) != '')) { if (isset($_REQUEST['tag']) && (trim($_REQUEST['tag']) != '')) {
@ -40,22 +40,27 @@ $bookmarks = $bookmarkservice->getBookmarks(
echo 'url;title;tags;description'; echo 'url;title;tags;description';
echo "\n"; echo "\n";
foreach($bookmarks['bookmarks'] as $row) { foreach ($bookmarks['bookmarks'] as $row) {
if (is_null($row['bDescription']) || (trim($row['bDescription']) == '')) if (is_null($row['bDescription']) || (trim($row['bDescription']) == '')) {
$description = ''; $description = '';
else } else {
$description = filter(str_replace(array("\r\n", "\n", "\r"),"", $row['bDescription']), 'xml'); $description = filter(
str_replace(array("\r\n", "\n", "\r"), "", $row['bDescription']), 'xml'
);
}
$taglist = ''; $taglist = '';
if (count($row['tags']) > 0) { if (count($row['tags']) > 0) {
foreach($row['tags'] as $tag) foreach ($row['tags'] as $tag) {
$taglist .= convertTag($tag) .','; $taglist .= convertTag($tag) .',';
}
$taglist = substr($taglist, 0, -1); $taglist = substr($taglist, 0, -1);
} else { } else {
$taglist = 'system:unfiled'; $taglist = 'system:unfiled';
} }
echo '"'.filter($row['bAddress'], 'xml') .'";"'. filter($row['bTitle'], 'xml') .'";"'. filter($taglist, 'xml') .'";"'. $description .'"'; echo '"'.filter($row['bAddress'], 'xml') .'";"'. filter($row['bTitle'], 'xml') .
'";"'. filter($taglist, 'xml') .'";"'. $description .'"';
echo "\n"; echo "\n";
} }

View File

@ -1,21 +1,33 @@
<?php <?php
/*
Export for Google Custom Search /**
* Export for Google Custom Search
*
* PHP version 5.
*
* @category Bookmarking
* @package SemanticScuttle
* @author Benjamin Huynh-Kim-Bang <mensonge@users.sourceforge.net>
* @author Christian Weiske <cweiske@cweiske.de>
* @author Eric Dane <ericdane@users.sourceforge.net>
* @license GPL http://www.gnu.org/licenses/gpl.html
* @link http://sourceforge.net/projects/semanticscuttle
*/ */
// Force HTTP authentication first! // Force HTTP authentication first!
//require_once('httpauth.inc.php'); //require_once('httpauth.inc.php');
$httpContentType = false; $httpContentType = false;
require_once '../www-header.php'; require_once '../www-header.php';
if($GLOBALS['enableGoogleCustomSearch'] == false) { if ($GLOBALS['enableGoogleCustomSearch'] == false) {
echo "Google Custom Search disabled. You can enable it into the config.php file."; echo "Google Custom Search disabled. " .
"You can enable it into the config.php file.";
die; die;
} }
/* Service creation: only useful services are created */ /* Service creation: only useful services are created */
$bookmarkservice =SemanticScuttle_Service_Factory::get('Bookmark'); $bookmarkservice = SemanticScuttle_Service_Factory::get('Bookmark');
/* /*
// Restrict to admins? // Restrict to admins?
@ -24,44 +36,48 @@ $bookmarkservice =SemanticScuttle_Service_Factory::get('Bookmark');
}*/ }*/
// Check if queried format is xml // Check if queried format is xml
if (isset($_REQUEST['xml']) && (trim($_REQUEST['xml']) == 1)) if (isset($_REQUEST['xml']) && (trim($_REQUEST['xml']) == 1)) {
$xml = true; $xml = true;
else } else {
$xml = false; $xml = false;
}
// Check to see if a tag was specified. // Check to see if a tag was specified.
if (isset($_REQUEST['tag']) && (trim($_REQUEST['tag']) != '')) if (isset($_REQUEST['tag']) && (trim($_REQUEST['tag']) != '')) {
$tag = trim($_REQUEST['tag']); $tag = trim($_REQUEST['tag']);
else } else {
$tag = NULL; $tag = null;
}
// Get the posts relevant to the passed-in variables. // Get the posts relevant to the passed-in variables.
$bookmarks =& $bookmarkservice->getBookmarks(0, NULL, NULL, $tag, NULL, getSortOrder()); $bookmarks =& $bookmarkservice->getBookmarks(
0, null, null, $tag, null, getSortOrder()
);
// Set up the plain file and output all the posts. // Set up the plain file and output all the posts.
header('Content-Type: text/plain; charset=utf-8'); header('Content-Type: text/plain; charset=utf-8');
if(!$xml) { if (!$xml) {
header('Content-Type: text/plain'); header('Content-Type: text/plain');
foreach($bookmarks['bookmarks'] as $row) { foreach ($bookmarks['bookmarks'] as $row) {
if(checkUrl($row['bAddress'], false)) { if (checkUrl($row['bAddress'], false)) {
echo $row['bAddress']."\n"; echo $row['bAddress']."\n";
} }
} }
} else { } else {
header('Content-Type: text/xml'); header('Content-Type: text/xml');
echo '<GoogleCustomizations>'."\n"; echo '<GoogleCustomizations>'."\n";
echo ' <Annotations>'."\n"; echo ' <Annotations>'."\n";
foreach($bookmarks['bookmarks'] as $row) { foreach ($bookmarks['bookmarks'] as $row) {
//if(substr($row['bAddress'], 0, 7) == "http://") { //if(substr($row['bAddress'], 0, 7) == "http://") {
if(checkUrl($row['bAddress'], false)) { if (checkUrl($row['bAddress'], false)) {
echo ' <Annotation about="'.filter($row['bAddress']).'">'."\n"; echo ' <Annotation about="'.filter($row['bAddress']).'">'."\n";
echo ' <Label name="include"/>'."\n"; echo ' <Label name="include"/>'."\n";
echo ' </Annotation>'."\n"; echo ' </Annotation>'."\n";
} }
} }
echo ' </Annotations>'."\n"; echo ' </Annotations>'."\n";
echo '</GoogleCustomizations>'."\n"; echo '</GoogleCustomizations>'."\n";
} }
?> ?>

View File

@ -50,11 +50,13 @@ echo '<!DOCTYPE NETSCAPE-Bookmark-file-1>'."\r\n";
echo '<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8" />'; echo '<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8" />';
echo '<!-- This is an automatically generated file. -->'."\r\n"; echo '<!-- This is an automatically generated file. -->'."\r\n";
echo '<TITLE>Bookmarks</TITLE>'."\r\n"; echo '<TITLE>Bookmarks</TITLE>'."\r\n";
echo '<H1 LAST_MODIFIED="'. date('U') .'">Bookmarks for '. htmlspecialchars($currentUser->getUsername()) .''. (is_null($tag) ? '' : ' tag="'. htmlspecialchars($tag) .'"') ." from " . $sitename ."</H1>\r\n"; echo '<H1 LAST_MODIFIED="'. date('U');
echo '">Bookmarks for '. htmlspecialchars($currentUser->getUsername());
echo (is_null($tag) ? '' : ' tag="'. htmlspecialchars($tag) .'"');
echo ' from ' . $sitename .'</H1>\r\n';
echo '<DL>'."\r\n"; echo '<DL>'."\r\n";
foreach ($bookmarks['bookmarks'] as $row) { foreach ($bookmarks['bookmarks'] as $row) {
if (is_null($row['bDescription']) || (trim($row['bDescription']) == '')) { if (is_null($row['bDescription']) || (trim($row['bDescription']) == '')) {
$description = ''; $description = '';
@ -73,7 +75,11 @@ foreach ($bookmarks['bookmarks'] as $row) {
$taglist = 'system:unfiled'; $taglist = 'system:unfiled';
} }
echo "\t<DT><A HREF=\"". filter($row['bAddress'], 'xml') .'" '. $description .' hash="'. md5($row['bAddress']) .'" tags="'. filter($taglist, 'xml') .'" ADD_DATE="'. date('U', strtotime($row['bDatetime'])) ."\" >" . filter($row['bTitle'], 'xml') ."</a>\r\n"; echo "\t<DT><A HREF=\"". filter($row['bAddress'], 'xml') .'" ';
echo $description .' hash="'. md5($row['bAddress']) .'" tags="';
echo filter($taglist, 'xml') .'" ADD_DATE="';
echo date('U', strtotime($row['bDatetime']));
echo "\" >" . filter($row['bTitle'], 'xml') ."</a>\r\n";
} }

View File

@ -1,12 +1,29 @@
<?php <?php
/* Export data with semantic format (SIOC: http://sioc-project.org/, FOAF, SKOS, Annotea Ontology) */ /**
* Export data with semantic format
*
* (SIOC: http://sioc-project.org/, FOAF, SKOS, Annotea Ontology)
*
* SemanticScuttle - your social bookmark manager.
*
* PHP version 5.
*
* @category Bookmarking
* @package SemanticScuttle
* @author Benjamin Huynh-Kim-Bang <mensonge@users.sourceforge.net>
* @author Christian Weiske <cweiske@cweiske.de>
* @author Eric Dane <ericdane@users.sourceforge.net>
* @license GPL http://www.gnu.org/licenses/gpl.html
* @link http://sourceforge.net/projects/semanticscuttle
*/
$httpContentType = 'text/xml'; $httpContentType = 'text/xml';
require_once '../www-header.php'; require_once '../www-header.php';
/* Service creation: only useful services are created */ /* Service creation: only useful services are created */
$userservice =SemanticScuttle_Service_Factory::get('User'); $userservice = SemanticScuttle_Service_Factory::get('User');
$bookmarkservice =SemanticScuttle_Service_Factory::get('Bookmark'); $bookmarkservice = SemanticScuttle_Service_Factory::get('Bookmark');
?> ?>
<?php echo "<?xml version=\"1.0\" encoding=\"utf-8\"\n?>"; ?> <?php echo "<?xml version=\"1.0\" encoding=\"utf-8\"\n?>"; ?>
@ -37,19 +54,17 @@ $bookmarkservice =SemanticScuttle_Service_Factory::get('Bookmark');
$users = $userservice->getObjectUsers(); $users = $userservice->getObjectUsers();
$usersArray = array(); // useful for bookmarks display $usersArray = array(); // useful for bookmarks display
foreach($users as $user) { foreach ($users as $user) {
$usersArray[$user->getId()] = $user->getUserName(); $usersArray[$user->getId()] = $user->getUserName();
} }
?>
<?php foreach($users as $user) :?> foreach ($users as $user) { ?>
<sioc:User rdf:about="<?php echo createUrl('profile', $user->getUserName())?>"> <sioc:User rdf:about="<?php echo createUrl('profile', $user->getUserName())?>">
<sioc:name><?php echo $user->getUserName() ?></sioc:name> <sioc:name><?php echo $user->getUserName() ?></sioc:name>
<sioc:member_of rdf:resource="<?php echo ROOT?>" /> <sioc:member_of rdf:resource="<?php echo ROOT?>" />
</sioc:User> </sioc:User>
<?php endforeach; ?> <?php
}
<?php
/* /*
No page for usergroup (users/admin) for the moment No page for usergroup (users/admin) for the moment
<sioc:Usergroup rdf:ID="authors"> <sioc:Usergroup rdf:ID="authors">
@ -57,31 +72,33 @@ No page for usergroup (users/admin) for the moment
<sioc:has_member rdf:nodeID="sioc-id2245901" /> <sioc:has_member rdf:nodeID="sioc-id2245901" />
</sioc:Usergroup> </sioc:Usergroup>
*/ */
?>
<?php
//bookmarks are described using Annotea ontology //bookmarks are described using Annotea ontology
$bookmarks =& $bookmarkservice->getBookmarks(0, NULL, NULL, NULL); $bookmarks =& $bookmarkservice->getBookmarks(0, null, null, null);
?>
<?php foreach($bookmarks['bookmarks'] as $bookmark): ?>
<bm:Bookmark rdf:about="<?php echo createUrl('history', $bookmark['bHash']) ?>">
<dc:title><?php echo filter($bookmark['bTitle']) ?></dc:title>
<dc:created><?php echo filter($bookmark['bCreated']) ?></dc:created>
<dc:description><?php echo filter(strip_tags($bookmark['bDescription'])) ?></dc:description>
<dc:date><?php echo $bookmark['bDateTime'] ?></dc:date>
<bm:recalls rdf:resource="<?php echo filter($bookmark['bAddress']) ?>"/>
<sioc:owner_of rdf:resource="<?php echo createUrl('profile', $usersArray[$bookmark['uId']]) ?>"/>
<?php foreach($bookmark['tags'] as $tag): ?>
<sioc:topic>
<skos:concept rdf:about="<?php echo createUrl('bookmarks', $usersArray[$bookmark['uId']].'/'.$tag) ?>" />
</sioc:topic>
<?php endforeach; ?>
</bm:Bookmark>
<?php endforeach; ?> foreach ($bookmarks['bookmarks'] as $bookmark) { ?>
<bm:Bookmark rdf:about="<?php echo createUrl('history', $bookmark['bHash']) ?>">
<dc:title><?php echo filter($bookmark['bTitle']) ?></dc:title>
<dc:created><?php echo filter($bookmark['bCreated']) ?></dc:created>
<dc:description><?php echo filter(strip_tags($bookmark['bDescription'])) ?>
</dc:description>
<dc:date><?php echo $bookmark['bDateTime'] ?></dc:date>
<bm:recalls rdf:resource="<?php echo filter($bookmark['bAddress']) ?>"/>
<sioc:owner_of rdf:resource="<?php
echo createUrl('profile', $usersArray[$bookmark['uId']])
?>"/>
<?php foreach ($bookmark['tags'] as $tag) { ?>
<sioc:topic>
<skos:concept rdf:about="<?php
echo createUrl('bookmarks', $usersArray[$bookmark['uId']].'/'.$tag)
?>" />
</sioc:topic>
<?php } ?>
</bm:Bookmark>
<?php
}
<?php
// tags and concepts are described using SKOS ontology // tags and concepts are described using SKOS ontology
//concept for user/admins, preflabel, definition, top concept //concept for user/admins, preflabel, definition, top concept
?> ?>

View File

@ -1,4 +1,5 @@
<?php <?php
/** /**
* Checks if the user is logged on and sends a HTTP basic auth * Checks if the user is logged on and sends a HTTP basic auth
* request to the browser if not. In that case the script ends. * request to the browser if not. In that case the script ends.
@ -17,36 +18,40 @@
* @license GPL http://www.gnu.org/licenses/gpl.html * @license GPL http://www.gnu.org/licenses/gpl.html
* @link http://sourceforge.net/projects/semanticscuttle * @link http://sourceforge.net/projects/semanticscuttle
*/ */
require_once '../www-header.php'; require_once '../www-header.php';
/** /**
* Sends HTTP auth headers to the browser * Sends HTTP auth headers to the browser
*
* @return nothing
*/ */
function authenticate() function authenticate()
{ {
header('WWW-Authenticate: Basic realm="SemanticScuttle API"'); header('WWW-Authenticate: Basic realm="SemanticScuttle API"');
header('HTTP/1.0 401 Unauthorized'); header('HTTP/1.0 401 Unauthorized');
die(T_("Use of the API calls requires authentication.")); die(T_("Use of the API calls requires authentication."));
} }
if (!$userservice->isLoggedOn()) { if (!$userservice->isLoggedOn()) {
/* Maybe we have caught authentication data in $_SERVER['REMOTE_USER'] /* Maybe we have caught authentication data in $_SERVER['REMOTE_USER']
( Inspired by http://www.yetanothercommunitysystem.com/article-321-regle-comment-utiliser-l-authentification-http-en-php-chez-ovh ) */ ( Inspired by http://www.yetanothercommunitysystem.com/article-321-regle-comment-utiliser-l-authentification-http-en-php-chez-ovh ) */
if ((!isset($_SERVER['PHP_AUTH_USER']) || !isset($_SERVER['PHP_AUTH_PW'])) if ((!isset($_SERVER['PHP_AUTH_USER']) || !isset($_SERVER['PHP_AUTH_PW']))
&& isset($_SERVER['REMOTE_USER']) && isset($_SERVER['REMOTE_USER'])
&& preg_match('/Basic\s+(.*)$/i', $_SERVER['REMOTE_USER'], $matches) && preg_match('/Basic\s+(.*)$/i', $_SERVER['REMOTE_USER'], $matches)
) { ) {
list($name, $password) = explode(':', base64_decode($matches[1])); list($name, $password) = explode(':', base64_decode($matches[1]));
$_SERVER['PHP_AUTH_USER'] = strip_tags($name); $_SERVER['PHP_AUTH_USER'] = strip_tags($name);
$_SERVER['PHP_AUTH_PW'] = strip_tags($password); $_SERVER['PHP_AUTH_PW'] = strip_tags($password);
} }
if (!isset($_SERVER['PHP_AUTH_USER'])) { if (!isset($_SERVER['PHP_AUTH_USER'])) {
authenticate(); authenticate();
} else { } else {
$login = $userservice->login( $login = $userservice->login(
$_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW'] $_SERVER['PHP_AUTH_USER'],
$_SERVER['PHP_AUTH_PW']
); );
if ($login) { if ($login) {
$currentUser = $userservice->getCurrentObjectUser(); $currentUser = $userservice->getCurrentObjectUser();
@ -55,4 +60,5 @@ if (!$userservice->isLoggedOn()) {
} }
} }
} }
?> ?>

View File

@ -1,7 +1,22 @@
<?php <?php
/**
* Perform OpenSearch
*
* PHP version 5.
*
* @category Bookmarking
* @package SemanticScuttle
* @author Benjamin Huynh-Kim-Bang <mensonge@users.sourceforge.net>
* @author Christian Weiske <cweiske@cweiske.de>
* @author Eric Dane <ericdane@users.sourceforge.net>
* @license GPL http://www.gnu.org/licenses/gpl.html
* @link http://sourceforge.net/projects/semanticscuttle
*/
$httpContentType = 'text/xml'; $httpContentType = 'text/xml';
require_once '../www-header.php'; require_once '../www-header.php';
?> ?>
<?xml version="1.0" encoding="utf-8" ?> <?xml version="1.0" encoding="utf-8" ?>
<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/"> <OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/">
<ShortName><?php echo $GLOBALS['sitename']?></ShortName> <ShortName><?php echo $GLOBALS['sitename']?></ShortName>

View File

@ -2,7 +2,10 @@
/** /**
* API for adding a new bookmark. * API for adding a new bookmark.
* *
* PHP version 5.
*
* The following POST and GET parameters are accepted: * The following POST and GET parameters are accepted:
*
* @param string $url URL of the bookmark (required) * @param string $url URL of the bookmark (required)
* @param string $description Bookmark title (required) * @param string $description Bookmark title (required)
* @param string $extended Extended bookmark description (optional) * @param string $extended Extended bookmark description (optional)
@ -28,8 +31,6 @@
* *
* SemanticScuttle - your social bookmark manager. * SemanticScuttle - your social bookmark manager.
* *
* PHP version 5.
*
* @category Bookmarking * @category Bookmarking
* @package SemanticScuttle * @package SemanticScuttle
* @author Benjamin Huynh-Kim-Bang <mensonge@users.sourceforge.net> * @author Benjamin Huynh-Kim-Bang <mensonge@users.sourceforge.net>
@ -38,7 +39,7 @@
* @license GPL http://www.gnu.org/licenses/gpl.html * @license GPL http://www.gnu.org/licenses/gpl.html
* @link http://sourceforge.net/projects/semanticscuttle * @link http://sourceforge.net/projects/semanticscuttle
* @link http://www.delicious.com/help/api * @link http://www.delicious.com/help/api
*/ */
// Force HTTP authentication // Force HTTP authentication
$httpContentType = 'text/xml'; $httpContentType = 'text/xml';
@ -143,4 +144,4 @@ if (is_null($url)) {
// Set up the XML file and output the result. // Set up the XML file and output the result.
echo '<?xml version="1.0" standalone="yes" ?' . ">\r\n"; echo '<?xml version="1.0" standalone="yes" ?' . ">\r\n";
echo '<result code="' . $msg .'" />'; echo '<result code="' . $msg .'" />';
?> ?>

View File

@ -1,47 +1,70 @@
<?php <?php
// Implements the del.icio.us API request for all a user's posts, optionally filtered by tag. /**
* Implements the del.icio.us API request for all a user's posts
* optionally filtered by tag.
*
* del.icio.us behavior:
* - doesn't include the filtered tag as an attribute on the root element (we do)
*
* PHP version 5.
*
* @category Bookmarking
* @package SemanticScuttle
* @author Benjamin Huynh-Kim-Bang <mensonge@users.sourceforge.net>
* @author Christian Weiske <cweiske@cweiske.de>
* @author Eric Dane <ericdane@users.sourceforge.net>
* @license GPL http://www.gnu.org/licenses/gpl.html
* @link http://sourceforge.net/projects/semanticscuttle
*/
// del.icio.us behavior: //Force HTTP authentication first!
// - doesn't include the filtered tag as an attribute on the root element (we do)
// Force HTTP authentication first!
$httpContentType = 'text/xml'; $httpContentType = 'text/xml';
require_once 'httpauth.inc.php'; require_once 'httpauth.inc.php';
/* Service creation: only useful services are created */ /* Service creation: only useful services are created */
$bookmarkservice =SemanticScuttle_Service_Factory::get('Bookmark'); $bookmarkservice = SemanticScuttle_Service_Factory::get('Bookmark');
// Check to see if a tag was specified. // Check to see if a tag was specified.
if (isset($_REQUEST['tag']) && (trim($_REQUEST['tag']) != '')) if (isset($_REQUEST['tag']) && (trim($_REQUEST['tag']) != '')) {
$tag = trim($_REQUEST['tag']); $tag = trim($_REQUEST['tag']);
else } else {
$tag = NULL; $tag = null;
}
// Get the posts relevant to the passed-in variables. // Get the posts relevant to the passed-in variables.
$bookmarks =& $bookmarkservice->getBookmarks(0, NULL, $userservice->getCurrentUserId(), $tag); $bookmarks =& $bookmarkservice->getBookmarks(
0, null, $userservice->getCurrentUserId(), $tag
);
// Set up the XML file and output all the posts. // Set up the XML file and output all the posts.
echo '<?xml version="1.0" standalone="yes" ?'.">\r\n"; echo '<?xml version="1.0" standalone="yes" ?'.">\r\n";
echo '<posts update="'. gmdate('Y-m-d\TH:i:s\Z') .'" user="'. htmlspecialchars($currentUser->getUsername()) .'"'. (is_null($tag) ? '' : ' tag="'. htmlspecialchars($tag) .'"') .">\r\n"; echo '<posts update="'. gmdate('Y-m-d\TH:i:s\Z');
echo '" user="'. htmlspecialchars($currentUser->getUsername());
echo '"'. (is_null($tag) ? '' : ' tag="'. htmlspecialchars($tag) .'"') .">\r\n";
foreach($bookmarks['bookmarks'] as $row) { foreach ($bookmarks['bookmarks'] as $row) {
if (is_null($row['bDescription']) || (trim($row['bDescription']) == '')) if (is_null($row['bDescription']) || (trim($row['bDescription']) == '')) {
$description = ''; $description = '';
else } else {
$description = 'extended="'. filter($row['bDescription'], 'xml') .'" '; $description = 'extended="'. filter($row['bDescription'], 'xml') .'" ';
}
$taglist = ''; $taglist = '';
if (count($row['tags']) > 0) { if (count($row['tags']) > 0) {
foreach($row['tags'] as $tag) foreach ($row['tags'] as $tag) {
$taglist .= convertTag($tag) .' '; $taglist .= convertTag($tag) .' ';
}
$taglist = substr($taglist, 0, -1); $taglist = substr($taglist, 0, -1);
} else { } else {
$taglist = 'system:unfiled'; $taglist = 'system:unfiled';
} }
echo "\t<post href=\"". filter($row['bAddress'], 'xml') .'" description="'. filter($row['bTitle'], 'xml') .'" '. $description .'hash="'. md5($row['bAddress']) .'" tag="'. filter($taglist, 'xml') .'" time="'. gmdate('Y-m-d\TH:i:s\Z', strtotime($row['bDatetime'])) ."\" />\r\n"; echo "\t<post href=\"". filter($row['bAddress'], 'xml');
echo '" description="'. filter($row['bTitle'], 'xml');
echo '" '. $description .'hash="'. md5($row['bAddress']);
echo '" tag="'. filter($taglist, 'xml') .'" time="';
echo gmdate('Y-m-d\TH:i:s\Z', strtotime($row['bDatetime'])) ."\" />\r\n";
} }
echo '</posts>'; echo '</posts>';
?> ?>

View File

@ -38,7 +38,8 @@ $bookmarks = $bookmarkservice->getBookmarks(
// Set up the XML file and output all the tags. // Set up the XML file and output all the tags.
echo '<?xml version="1.0" standalone="yes" ?'.">\r\n"; echo '<?xml version="1.0" standalone="yes" ?'.">\r\n";
echo '<dates tag="'. (is_null($tag) ? '' : filter($tag, 'xml')) .'" user="'. filter($currentUser->getUsername(), 'xml') ."\">\r\n"; echo '<dates tag="'. (is_null($tag) ? '' : filter($tag, 'xml'));
echo '" user="'. filter($currentUser->getUsername(), 'xml') ."\">\r\n";
$lastdate = null; $lastdate = null;
$count = 0; $count = 0;
@ -57,4 +58,4 @@ if ($lastdate !== null) {
} }
echo "</dates>"; echo "</dates>";
?> ?>

View File

@ -6,7 +6,8 @@
* uses GMT dates -- so we do too. * uses GMT dates -- so we do too.
* *
* del.icio.us behavior: * del.icio.us behavior:
* - includes an empty tag attribute on the root element when it hasn't been specified * - includes an empty tag attribute on the root element
* when it hasn't been specified
* *
* Scuttle behavior: * Scuttle behavior:
* - Uses today, instead of the last bookmarked date, if no date is specified * - Uses today, instead of the last bookmarked date, if no date is specified
@ -56,7 +57,9 @@ $bookmarks = $bookmarkservice->getBookmarks(
// Set up the XML file and output all the tags. // Set up the XML file and output all the tags.
echo '<?xml version="1.0" standalone="yes" ?'.">\r\n"; echo '<?xml version="1.0" standalone="yes" ?'.">\r\n";
echo '<posts'. (is_null($dtstart) ? '' : ' dt="'. $dtstart .'"') .' tag="'. (is_null($tag) ? '' : filter($tag, 'xml')) .'" user="'. filter($currentUser->getUsername(), 'xml') ."\">\r\n"; echo '<posts'. (is_null($dtstart) ? '' : ' dt="'. $dtstart .'"') .' tag="';
echo (is_null($tag) ? '' : filter($tag, 'xml')) .'" user="';
echo filter($currentUser->getUsername(), 'xml') ."\">\r\n";
foreach ($bookmarks['bookmarks'] as $row) { foreach ($bookmarks['bookmarks'] as $row) {
if (is_null($row['bDescription']) || (trim($row['bDescription']) == '')) { if (is_null($row['bDescription']) || (trim($row['bDescription']) == '')) {
@ -75,8 +78,14 @@ foreach ($bookmarks['bookmarks'] as $row) {
$taglist = 'system:unfiled'; $taglist = 'system:unfiled';
} }
echo "\t<post href=\"". filter($row['bAddress'], 'xml') .'" description="'. filter($row['bTitle'], 'xml') .'" '. $description .'hash="'. $row['bHash'] .'" others="'. $bookmarkservice->countOthers($row['bAddress']) .'" tag="'. filter($taglist, 'xml') .'" time="'. gmdate('Y-m-d\TH:i:s\Z', strtotime($row['bDatetime'])) ."\" />\r\n"; echo "\t<post href=\"". filter($row['bAddress'], 'xml');
echo '" description="'. filter($row['bTitle'], 'xml');
echo '" '. $description .'hash="'. $row['bHash'];
echo '" others="'. $bookmarkservice->countOthers($row['bAddress']);
echo '" tag="'. filter($taglist, 'xml');
echo '" time="'. gmdate('Y-m-d\TH:i:s\Z', strtotime($row['bDatetime'])) ."\" />";
echo "\r\n";
} }
echo '</posts>'; echo '</posts>';
?> ?>

View File

@ -1,8 +1,21 @@
<?php <?php
// Implements the del.icio.us API request for all a user's posts, optionally filtered by tag. /**
* Implements the del.icio.us API request for all a user's posts
// del.icio.us behavior: * optionally filtered by tag.
// - doesn't include the filtered tag as an attribute on the root element (we do) *
* del.icio.us behavior:
* - doesn't include the filtered tag as an attribute on the root element (we do)
*
* PHP version 5.
*
* @category Bookmarking
* @package SemanticScuttle
* @author Benjamin Huynh-Kim-Bang <mensonge@users.sourceforge.net>
* @author Christian Weiske <cweiske@cweiske.de>
* @author Eric Dane <ericdane@users.sourceforge.net>
* @license GPL http://www.gnu.org/licenses/gpl.html
* @link http://sourceforge.net/projects/semanticscuttle
*/
// Force HTTP authentication first! // Force HTTP authentication first!
//require_once('httpauth.inc.php'); //require_once('httpauth.inc.php');
@ -10,38 +23,46 @@ $httpContentType = 'text/xml';
require_once '../www-header.php'; require_once '../www-header.php';
/* Service creation: only useful services are created */ /* Service creation: only useful services are created */
$bookmarkservice =SemanticScuttle_Service_Factory::get('Bookmark'); $bookmarkservice = SemanticScuttle_Service_Factory::get('Bookmark');
// Check to see if a tag was specified. // Check to see if a tag was specified.
if (isset($_REQUEST['tag']) && (trim($_REQUEST['tag']) != '')) if (isset($_REQUEST['tag']) && (trim($_REQUEST['tag']) != '')) {
$tag = trim($_REQUEST['tag']); $tag = trim($_REQUEST['tag']);
else } else {
$tag = NULL; $tag = null;
}
// Get the posts relevant to the passed-in variables. // Get the posts relevant to the passed-in variables.
$bookmarks =& $bookmarkservice->getBookmarks(0, NULL, NULL, $tag); $bookmarks =& $bookmarkservice->getBookmarks(0, null, null, $tag);
// Set up the XML file and output all the posts. // Set up the XML file and output all the posts.
echo '<?xml version="1.0" standalone="yes" ?'.">\r\n"; echo '<?xml version="1.0" standalone="yes" ?'.">\r\n";
echo '<posts update="'. gmdate('Y-m-d\TH:i:s\Z') .'" '. (is_null($tag) ? '' : ' tag="'. htmlspecialchars($tag) .'"') .">\r\n"; echo '<posts update="'. gmdate('Y-m-d\TH:i:s\Z') .'" ';
echo (is_null($tag) ? '' : ' tag="'. htmlspecialchars($tag) .'"') .">\r\n";
foreach($bookmarks['bookmarks'] as $row) { foreach ($bookmarks['bookmarks'] as $row) {
if (is_null($row['bDescription']) || (trim($row['bDescription']) == '')) if (is_null($row['bDescription']) || (trim($row['bDescription']) == '')) {
$description = ''; $description = '';
else } else {
$description = 'extended="'. filter($row['bDescription'], 'xml') .'" '; $description = 'extended="'. filter($row['bDescription'], 'xml') .'" ';
}
$taglist = ''; $taglist = '';
if (count($row['tags']) > 0) { if (count($row['tags']) > 0) {
foreach($row['tags'] as $tag) foreach ($row['tags'] as $tag) {
$taglist .= convertTag($tag) .' '; $taglist .= convertTag($tag) .' ';
}
$taglist = substr($taglist, 0, -1); $taglist = substr($taglist, 0, -1);
} else { } else {
$taglist = 'system:unfiled'; $taglist = 'system:unfiled';
} }
echo "\t<post href=\"". filter($row['bAddress'], 'xml') .'" description="'. filter($row['bTitle'], 'xml') .'" '. $description .'hash="'. md5($row['bAddress']) .'" tag="'. filter($taglist, 'xml') .'" time="'. gmdate('Y-m-d\TH:i:s\Z', strtotime($row['bDatetime'])) ."\" />\r\n"; echo "\t<post href=\"". filter($row['bAddress'], 'xml');
echo '" description="'. filter($row['bTitle'], 'xml');
echo '" '. $description .'hash="'. md5($row['bAddress']);
echo '" tag="'. filter($taglist, 'xml');
echo '" time="'. gmdate('Y-m-d\TH:i:s\Z', strtotime($row['bDatetime'])) ."\" />";
echo "\r\n";
} }
echo '</posts>'; echo '</posts>';

View File

@ -56,7 +56,8 @@ $bookmarks = $bookmarkservice->getBookmarks(
// Set up the XML file and output all the tags. // Set up the XML file and output all the tags.
echo '<?xml version="1.0" standalone="yes" ?'.">\r\n"; echo '<?xml version="1.0" standalone="yes" ?'.">\r\n";
echo '<posts tag="'. (is_null($tag) ? '' : filter($tag, 'xml')) .'" user="'. filter($currentUser->getUsername(), 'xml') ."\">\r\n"; echo '<posts tag="'. (is_null($tag) ? '' : filter($tag, 'xml'));
echo '" user="'. filter($currentUser->getUsername(), 'xml') ."\">\r\n";
foreach ($bookmarks['bookmarks'] as $row) { foreach ($bookmarks['bookmarks'] as $row) {
if (is_null($row['bDescription']) || (trim($row['bDescription']) == '')) { if (is_null($row['bDescription']) || (trim($row['bDescription']) == '')) {
@ -75,8 +76,13 @@ foreach ($bookmarks['bookmarks'] as $row) {
$taglist = 'system:unfiled'; $taglist = 'system:unfiled';
} }
echo "\t<post href=\"". filter($row['bAddress'], 'xml') .'" description="'. filter($row['bTitle'], 'xml') .'" '. $description .'hash="'. $row['bHash'] .'" tag="'. filter($taglist, 'xml') .'" time="'. gmdate('Y-m-d\TH:i:s\Z', strtotime($row['bDatetime'])) ."\" />\r\n"; echo "\t<post href=\"". filter($row['bAddress'], 'xml');
echo '" description="'. filter($row['bTitle'], 'xml');
echo '" '. $description .'hash="'. $row['bHash'];
echo '" tag="'. filter($taglist, 'xml');
echo '" time="'. gmdate('Y-m-d\TH:i:s\Z', strtotime($row['bDatetime'])) ."\" />";
echo "\r\n";
} }
echo '</posts>'; echo '</posts>';
?> ?>

View File

@ -1,15 +1,29 @@
<?php <?php
// Implements the del.icio.us API request for all a user's tags.
// del.icio.us behavior: /**
// - tags can't have spaces * Implements the del.icio.us API request for all a user's tags.
*
* del.icio.us behavior:
* - tags can't have spaces
*
* PHP version 5.
*
* @category Bookmarking
* @package SemanticScuttle
* @author Benjamin Huynh-Kim-Bang <mensonge@users.sourceforge.net>
* @author Christian Weiske <cweiske@cweiske.de>
* @author Eric Dane <ericdane@users.sourceforge.net>
* @license GPL http://www.gnu.org/licenses/gpl.html
* @link http://sourceforge.net/projects/semanticscuttle
*/
// Force HTTP authentication first! // Force HTTP authentication first!
$httpContentType = 'text/xml'; $httpContentType = 'text/xml';
require_once 'httpauth.inc.php'; require_once 'httpauth.inc.php';
/* Service creation: only useful services are created */ /* Service creation: only useful services are created */
$b2tservice =SemanticScuttle_Service_Factory::get('Bookmark2Tag'); $b2tservice = SemanticScuttle_Service_Factory::get('Bookmark2Tag');
// Get the tags relevant to the passed-in variables. // Get the tags relevant to the passed-in variables.
@ -18,8 +32,9 @@ $tags =& $b2tservice->getTags($userservice->getCurrentUserId());
// Set up the XML file and output all the tags. // Set up the XML file and output all the tags.
echo '<?xml version="1.0" standalone="yes" ?'.">\r\n"; echo '<?xml version="1.0" standalone="yes" ?'.">\r\n";
echo "<tags>\r\n"; echo "<tags>\r\n";
foreach($tags as $row) { foreach ($tags as $row) {
echo "\t<tag count=\"". $row['bCount'] .'" tag="'. filter(convertTag($row['tag'], 'out'), 'xml') ."\" />\r\n"; echo "\t<tag count=\"". $row['bCount'] .'" tag="';
echo filter(convertTag($row['tag'], 'out'), 'xml') ."\" />\r\n";
} }
echo "</tags>"; echo "</tags>";
?> ?>

View File

@ -1,32 +1,49 @@
<?php <?php
// Implements the del.icio.us API request to rename a user's tag. /**
* Implements the del.icio.us API request to rename a user's tag.
// del.icio.us behavior: *
// - oddly, returns an entirely different result (<result></result>) than the other API calls. * del.icio.us behavior:
* - oddly, returns an entirely different result (<result></result>) than
* the other API calls.
*
* PHP version 5.
*
* @category Bookmarking
* @package SemanticScuttle
* @author Benjamin Huynh-Kim-Bang <mensonge@users.sourceforge.net>
* @author Christian Weiske <cweiske@cweiske.de>
* @author Eric Dane <ericdane@users.sourceforge.net>
* @license GPL http://www.gnu.org/licenses/gpl.html
* @link http://sourceforge.net/projects/semanticscuttle
*/
// Force HTTP authentication first! // Force HTTP authentication first!
$httpContentType = 'text/xml'; $httpContentType = 'text/xml';
require_once 'httpauth.inc.php'; require_once 'httpauth.inc.php';
/* Service creation: only useful services are created */ /* Service creation: only useful services are created */
$b2tservice =SemanticScuttle_Service_Factory::get('Bookmark2Tag'); $b2tservice = SemanticScuttle_Service_Factory::get('Bookmark2Tag');
// Get the tag info. // Get the tag info.
if (isset($_REQUEST['old']) && (trim($_REQUEST['old']) != '')) if (isset($_REQUEST['old']) && (trim($_REQUEST['old']) != '')) {
$old = trim($_REQUEST['old']); $old = trim($_REQUEST['old']);
else } else {
$old = NULL; $old = null;
}
if (isset($_REQUEST['new']) && (trim($_REQUEST['new']) != '')) if (isset($_REQUEST['new']) && (trim($_REQUEST['new']) != '')) {
$new = trim($_REQUEST['new']); $new = trim($_REQUEST['new']);
else } else {
$new = NULL; $new = null;
}
if (is_null($old) || is_null($new)) { if (is_null($old) || is_null($new)) {
$renamed = false; $renamed = false;
} else { } else {
// Rename the tag. // Rename the tag.
$result = $b2tservice->renameTag($userservice->getCurrentUserId(), $old, $new, true); $result = $b2tservice->renameTag(
$userservice->getCurrentUserId(), $old, $new, true
);
$renamed = $result; $renamed = $result;
} }

View File

@ -33,46 +33,42 @@ isset($_POST['title']) ? define('POST_TITLE', $_POST['title']): define('POST_TIT
isset($_POST['description']) ? define('POST_DESCRIPTION', $_POST['description']): define('POST_DESCRIPTION', ''); isset($_POST['description']) ? define('POST_DESCRIPTION', $_POST['description']): define('POST_DESCRIPTION', '');
// prevent cycle between personal and common edit page // prevent cycle between personal and common edit page
if(!isset($_POST['referrer'])) { if (!isset($_POST['referrer'])) {
define('POST_REFERRER', ''); define('POST_REFERRER', '');
} elseif(strpos($_POST['referrer'], ROOT.'edit.php') == 0) { } elseif (strpos($_POST['referrer'], ROOT.'edit.php') == 0) {
define('POST_REFERRER', createUrl('history', POST_HASH)); define('POST_REFERRER', createUrl('history', POST_HASH));
} else { } else {
define('POST_REFERRER', $_POST['referrer']); define('POST_REFERRER', $_POST['referrer']);
} }
list ($url, $hash) = explode('/', $_SERVER['PATH_INFO']); list ($url, $hash) = explode('/', $_SERVER['PATH_INFO']);
$template = 'bookmarkcommondescriptionedit.tpl'; $template = 'bookmarkcommondescriptionedit.tpl';
//permissions //permissions
if(is_null($currentUser)) { if (is_null($currentUser)) {
$tplVars['error'] = T_('Permission denied.'); $tplVars['error'] = T_('Permission denied.');
$templateservice->loadTemplate('error.500.tpl', $tplVars); $templateservice->loadTemplate('error.500.tpl', $tplVars);
exit(); exit();
} }
if (POST_CONFIRM) { if (POST_CONFIRM) {
if (strlen($hash)>0 && if (strlen($hash)>0 && $cdservice->addBookmarkDescription(POST_HASH, stripslashes(POST_TITLE), stripslashes(POST_DESCRIPTION), $currentUser->getId(), time())) {
$cdservice->addBookmarkDescription(POST_HASH, stripslashes(POST_TITLE), stripslashes(POST_DESCRIPTION), $currentUser->getId(), time()) $tplVars['msg'] = T_('Bookmark common description updated');
) { header('Location: '. POST_REFERRER);
$tplVars['msg'] = T_('Bookmark common description updated'); } else {
header('Location: '. POST_REFERRER); $tplVars['error'] = T_('Failed to update the bookmark common description');
} else { $template = 'error.500.tpl';
$tplVars['error'] = T_('Failed to update the bookmark common description'); }
$template = 'error.500.tpl';
}
} elseif (POST_CANCEL) { } elseif (POST_CANCEL) {
header('Location: '. POST_REFERRER); header('Location: '. POST_REFERRER);
} else { } else {
$bkm = $bookmarkservice->getBookmarkByHash($hash); $bkm = $bookmarkservice->getBookmarkByHash($hash);
$tplVars['subtitle'] = T_('Edit Bookmark Common Description') .': '. $bkm['bAddress']; $tplVars['subtitle'] = T_('Edit Bookmark Common Description') .': '. $bkm['bAddress'];
$tplVars['formaction'] = $_SERVER['SCRIPT_NAME'] .'/'. $hash; $tplVars['formaction'] = $_SERVER['SCRIPT_NAME'] .'/'. $hash;
$tplVars['referrer'] = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : ''; $tplVars['referrer'] = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '';
$tplVars['hash'] = $hash; $tplVars['hash'] = $hash;
$tplVars['description'] = $cdservice->getLastBookmarkDescription($hash); $tplVars['description'] = $cdservice->getLastBookmarkDescription($hash);
} }
$templateservice->loadTemplate($template, $tplVars); $templateservice->loadTemplate($template, $tplVars);
?> ?>

View File

@ -22,8 +22,8 @@
require_once 'www-header.php'; require_once 'www-header.php';
/* Service creation: only useful services are created */ /* Service creation: only useful services are created */
$bookmarkservice =SemanticScuttle_Service_Factory::get('Bookmark'); $bookmarkservice = SemanticScuttle_Service_Factory::get('Bookmark');
$cacheservice =SemanticScuttle_Service_Factory::get('Cache'); $cacheservice = SemanticScuttle_Service_Factory::get('Cache');
/* Managing all possible inputs */ /* Managing all possible inputs */
isset($_GET['action']) ? define('GET_ACTION', $_GET['action']): define('GET_ACTION', ''); isset($_GET['action']) ? define('GET_ACTION', $_GET['action']): define('GET_ACTION', '');
@ -56,70 +56,66 @@ if (!isset($_POST['tags'])) {
if ((GET_ACTION == "add") && !$userservice->isLoggedOn()) { if ((GET_ACTION == "add") && !$userservice->isLoggedOn()) {
$loginqry = str_replace("'", '%27', stripslashes($_SERVER['QUERY_STRING'])); $loginqry = str_replace("'", '%27', stripslashes($_SERVER['QUERY_STRING']));
header('Location: '. createURL('login', '?'. $loginqry)); header('Location: '. createURL('login', '?'. $loginqry));
exit(); exit();
} }
if ($userservice->isLoggedOn()) { if ($userservice->isLoggedOn()) {
$currentUser = $userservice->getCurrentObjectUser(); $currentUser = $userservice->getCurrentObjectUser();
$currentUserID = $currentUser->getId(); $currentUserID = $currentUser->getId();
$currentUsername = $currentUser->getUsername(); $currentUsername = $currentUser->getUsername();
} }
@list($url, $user, $cat) = isset($_SERVER['PATH_INFO']) ? explode('/', $_SERVER['PATH_INFO']) : null;
@list($url, $user, $cat) = isset($_SERVER['PATH_INFO']) ? explode('/', $_SERVER['PATH_INFO']) : NULL;
$endcache = false; $endcache = false;
if ($usecache) { if ($usecache) {
// Generate hash for caching on // Generate hash for caching on
$hash = md5($_SERVER['REQUEST_URI'] . $user); $hash = md5($_SERVER['REQUEST_URI'] . $user);
// Don't cache if its users' own bookmarks // Don't cache if its users' own bookmarks
if ($userservice->isLoggedOn()) { if ($userservice->isLoggedOn()) {
if ($currentUsername != $user) { if ($currentUsername != $user) {
// Cache for 5 minutes // Cache for 5 minutes
$cacheservice->Start($hash); $cacheservice->Start($hash);
$endcache = true; $endcache = true;
} }
} else { } else {
// Cache for 30 minutes // Cache for 30 minutes
$cacheservice->Start($hash, 1800); $cacheservice->Start($hash, 1800);
$endcache = true; $endcache = true;
} }
} }
$pagetitle = $rssCat = $catTitle = ''; $pagetitle = $rssCat = $catTitle = '';
if ($user) { if ($user) {
if (is_int($user)) { if (is_int($user)) {
$userid = intval($user); $userid = intval($user);
} else { } else {
if (!($userinfo = $userservice->getUserByUsername($user))) { if (!($userinfo = $userservice->getUserByUsername($user))) {
$tplVars['error'] = sprintf(T_('User with username %s was not found'), $user); $tplVars['error'] = sprintf(T_('User with username %s was not found'), $user);
$templateservice->loadTemplate('error.404.tpl', $tplVars); $templateservice->loadTemplate('error.404.tpl', $tplVars);
exit(); exit();
} else { } else {
$userid =& $userinfo['uId']; $userid =& $userinfo['uId'];
} }
} }
$pagetitle .= ': '. $user; $pagetitle .= ': '. $user;
} }
if ($cat) { if ($cat) {
$catTitle = ': '. str_replace('+', ' + ', $cat); $catTitle = ': '. str_replace('+', ' + ', $cat);
$catTitleWithUrls = ': '; $catTitleWithUrls = ': ';
$titleTags = explode('+', filter($cat)); $titleTags = explode('+', filter($cat));
for($i = 0; $i<count($titleTags);$i++) { for ($i = 0; $i<count($titleTags);$i++) {
$catTitleWithUrls.= $titleTags[$i].'<a href="'.createUrl('bookmarks', $user.'/'.aggregateTags($titleTags, '+', $titleTags[$i])).'" title="'.T_('Remove the tag from the selection').'">*</a> + '; $catTitleWithUrls.= $titleTags[$i].'<a href="'.createUrl('bookmarks', $user.'/'.aggregateTags($titleTags, '+', $titleTags[$i])).'" title="'.T_('Remove the tag from the selection').'">*</a> + ';
} }
$catTitleWithUrls = substr($catTitleWithUrls, 0, strlen($catTitleWithUrls) - strlen(' + ')); $catTitleWithUrls = substr($catTitleWithUrls, 0, strlen($catTitleWithUrls) - strlen(' + '));
$pagetitle .= $catTitleWithUrls; $pagetitle .= $catTitleWithUrls;
} } else {
else $catTitleWithUrls = '';
{
$catTitleWithUrls = '';
} }
$pagetitle = substr($pagetitle, 2); $pagetitle = substr($pagetitle, 2);
@ -171,21 +167,21 @@ if ($userservice->isLoggedOn() && POST_SUBMITTED != '') {
} }
if (GET_ACTION == "add") { if (GET_ACTION == "add") {
// If the bookmark exists already, edit the original // If the bookmark exists already, edit the original
if ($bookmarkservice->bookmarkExists(stripslashes(GET_ADDRESS), $currentUserID)) { if ($bookmarkservice->bookmarkExists(stripslashes(GET_ADDRESS), $currentUserID)) {
$bookmark =& $bookmarkservice->getBookmarks(0, NULL, $currentUserID, NULL, NULL, NULL, NULL, NULL, NULL, $bookmarkservice->getHash(stripslashes(GET_ADDRESS))); $bookmark =& $bookmarkservice->getBookmarks(0, null, $currentUserID, null, null, null, null, null, null, $bookmarkservice->getHash(stripslashes(GET_ADDRESS)));
$popup = (GET_POPUP!='') ? '?popup=1' : ''; $popup = (GET_POPUP!='') ? '?popup=1' : '';
header('Location: '. createURL('edit', $bookmark['bookmarks'][0]['bId'] . $popup)); header('Location: '. createURL('edit', $bookmark['bookmarks'][0]['bId'] . $popup));
exit(); exit();
} }
$templatename = 'editbookmark.tpl'; $templatename = 'editbookmark.tpl';
} }
if ($templatename == 'editbookmark.tpl') { if ($templatename == 'editbookmark.tpl') {
if ($userservice->isLoggedOn()) { if ($userservice->isLoggedOn()) {
$tplVars['formaction'] = createURL('bookmarks', $currentUsername); $tplVars['formaction'] = createURL('bookmarks', $currentUsername);
if (POST_SUBMITTED != '') { if (POST_SUBMITTED != '') {
$tplVars['row'] = array( $tplVars['row'] = array(
'bTitle' => stripslashes(POST_TITLE), 'bTitle' => stripslashes(POST_TITLE),
'bAddress' => stripslashes(POST_ADDRESS), 'bAddress' => stripslashes(POST_ADDRESS),
'bDescription' => stripslashes(POST_DESCRIPTION), 'bDescription' => stripslashes(POST_DESCRIPTION),
@ -288,11 +284,10 @@ if ($templatename == 'editbookmark.tpl') {
$tplVars['summarizeLinkedTags'] = true; $tplVars['summarizeLinkedTags'] = true;
$tplVars['pageName'] = PAGE_BOOKMARKS; $tplVars['pageName'] = PAGE_BOOKMARKS;
$templateservice->loadTemplate($templatename, $tplVars); $templateservice->loadTemplate($templatename, $tplVars);
if ($usecache && $endcache) { if ($usecache && $endcache) {
// Cache output if existing copy has expired // Cache output if existing copy has expired
$cacheservice->End($hash); $cacheservice->End($hash);
} }
?> ?>

View File

@ -45,22 +45,19 @@ $tplVars['pagetitle'] = T_('Edit Bookmark');
$tplVars['subtitle'] = T_('Edit Bookmark'); $tplVars['subtitle'] = T_('Edit Bookmark');
$tplVars['loadjs'] = true; $tplVars['loadjs'] = true;
list ($url, $bookmark) = explode('/', $_SERVER['PATH_INFO']); list ($url, $bookmark) = explode('/', $_SERVER['PATH_INFO']);
if (!($row = $bookmarkservice->getBookmark(intval($bookmark), true))) { if (!($row = $bookmarkservice->getBookmark(intval($bookmark), true))) {
$tplVars['error'] = sprintf(T_('Bookmark with id %s not was not found'), $bookmark); $tplVars['error'] = sprintf(T_('Bookmark with id %s not was not found'), $bookmark);
$templateservice->loadTemplate('error.404.tpl', $tplVars); $templateservice->loadTemplate('error.404.tpl', $tplVars);
exit(); exit();
} else { } else {
if (!$bookmarkservice->editAllowed($row)) { if (!$bookmarkservice->editAllowed($row)) {
$tplVars['error'] = T_('You are not allowed to edit this bookmark'); $tplVars['error'] = T_('You are not allowed to edit this bookmark');
$templateservice->loadTemplate('error.500.tpl', $tplVars); $templateservice->loadTemplate('error.500.tpl', $tplVars);
exit(); exit();
} else if (POST_SUBMITTED != '') { } else if (POST_SUBMITTED != '') {
if (!POST_TITLE || !POST_ADDRESS) { if (!POST_TITLE || !POST_ADDRESS) {
$tplVars['error'] = T_('Your bookmark must have a title and an address'); $tplVars['error'] = T_('Your bookmark must have a title and an address');
} else { } else {
@ -80,10 +77,10 @@ if (!($row = $bookmarkservice->getBookmark(intval($bookmark), true))) {
//$tplVars['msg'] = (POST_POPUP != '') ? '<script type="text/javascript">window.close();</script>' : T_('Bookmark saved'); //$tplVars['msg'] = (POST_POPUP != '') ? '<script type="text/javascript">window.close();</script>' : T_('Bookmark saved');
$tplVars['msg'] = '<script type="text/javascript">window.close();</script>'; $tplVars['msg'] = '<script type="text/javascript">window.close();</script>';
} elseif (POST_REFERRER != '') { } elseif (POST_REFERRER != '') {
$tplVars['msg'] = T_('Bookmark saved'); $tplVars['msg'] = T_('Bookmark saved');
header('Location: '. POST_REFERRER); header('Location: '. POST_REFERRER);
} else { } else {
$tplVars['msg'] = T_('Bookmark saved'); $tplVars['msg'] = T_('Bookmark saved');
header('Location: '. createURL('bookmarks', $currentUser->getUsername())); header('Location: '. createURL('bookmarks', $currentUser->getUsername()));
} }
} }
@ -92,9 +89,9 @@ if (!($row = $bookmarkservice->getBookmark(intval($bookmark), true))) {
if (POST_DELETE != '') { if (POST_DELETE != '') {
// Delete bookmark // Delete bookmark
if ($bookmarkservice->deleteBookmark($bookmark)) { if ($bookmarkservice->deleteBookmark($bookmark)) {
if (POST_POPUP != '') { if (POST_POPUP != '') {
$tplVars['msg'] = '<script type="text/javascript">window.close();</script>'; $tplVars['msg'] = '<script type="text/javascript">window.close();</script>';
} elseif (POST_REFERRER != '') { } elseif (POST_REFERRER != '') {
header('Location: '. POST_REFERRER); header('Location: '. POST_REFERRER);
} else { } else {
header('Location: '. createURL('bookmarks', $currentUser->getUsername())); header('Location: '. createURL('bookmarks', $currentUser->getUsername()));

View File

@ -1,7 +1,21 @@
<?php <?php
/**
* Google custom search
*
* PHP version 5.
*
* @category Bookmarking
* @package SemanticScuttle
* @author Benjamin Huynh-Kim-Bang <mensonge@users.sourceforge.net>
* @author Christian Weiske <cweiske@cweiske.de>
* @author Eric Dane <ericdane@users.sourceforge.net>
* @license GPL http://www.gnu.org/licenses/gpl.html
* @link http://sourceforge.net/projects/semanticscuttle
*/
require_once '../www-header.php'; require_once '../www-header.php';
if($GLOBALS['enableGoogleCustomSearch'] == false) { if ($GLOBALS['enableGoogleCustomSearch'] == false) {
echo "Google Custom Search disabled. You can enable it into the config.php file."; echo "Google Custom Search disabled. You can enable it into the config.php file.";
die; die;
} }

View File

@ -43,5 +43,3 @@ if($GLOBALS['enableGoogleCustomSearch']==false) {
</center> </center>
</body> </body>
</html> </html>

View File

@ -29,9 +29,7 @@ $cacheservice =SemanticScuttle_Service_Factory::get('Cache');
isset($_GET['page']) ? define('GET_PAGE', $_GET['page']): define('GET_PAGE', 0); isset($_GET['page']) ? define('GET_PAGE', $_GET['page']): define('GET_PAGE', 0);
isset($_GET['sort']) ? define('GET_SORT', $_GET['sort']): define('GET_SORT', ''); isset($_GET['sort']) ? define('GET_SORT', $_GET['sort']): define('GET_SORT', '');
@list($url, $hash) = isset($_SERVER['PATH_INFO']) ? explode('/', $_SERVER['PATH_INFO']) : NULL; @list($url, $hash) = isset($_SERVER['PATH_INFO']) ? explode('/', $_SERVER['PATH_INFO']) : null;
if ($usecache) { if ($usecache) {
// Generate hash for caching on // Generate hash for caching on
@ -57,7 +55,7 @@ if (intval(GET_PAGE) > 1) {
if ($bookmark =& $bookmarkservice->getBookmarkByHash($hash)) { if ($bookmark =& $bookmarkservice->getBookmarkByHash($hash)) {
// Template variables // Template variables
$bookmarks =& $bookmarkservice->getBookmarks($start, $perpage, NULL, NULL, NULL, getSortOrder(), NULL, NULL, NULL, $hash); $bookmarks =& $bookmarkservice->getBookmarks($start, $perpage, null, null, null, getSortOrder(), null, null, null, $hash);
$tplVars['pagetitle'] = T_('History') .': '. $bookmark['bAddress']; $tplVars['pagetitle'] = T_('History') .': '. $bookmark['bAddress'];
$tplVars['subtitle'] = sprintf(T_('History for %s'), $bookmark['bAddress']); $tplVars['subtitle'] = sprintf(T_('History for %s'), $bookmark['bAddress']);
$tplVars['loadjs'] = true; $tplVars['loadjs'] = true;
@ -73,10 +71,10 @@ if ($bookmark =& $bookmarkservice->getBookmarkByHash($hash)) {
$tplVars['cat_url'] = createURL('bookmarks', '%1$s/%2$s'); $tplVars['cat_url'] = createURL('bookmarks', '%1$s/%2$s');
$tplVars['nav_url'] = createURL('history', $hash .'/%3$s'); $tplVars['nav_url'] = createURL('history', $hash .'/%3$s');
$tplVars['rsschannels'] = array(); $tplVars['rsschannels'] = array();
if($userservice->isLoggedOn()) { if ($userservice->isLoggedOn()) {
$tplVars['user'] = $currentUser->getUsername(); $tplVars['user'] = $currentUser->getUsername();
} else { } else {
$tplVars['user'] = ''; $tplVars['user'] = '';
} }
$templateservice->loadTemplate('bookmarks.tpl', $tplVars); $templateservice->loadTemplate('bookmarks.tpl', $tplVars);
} else { } else {

View File

@ -31,86 +31,90 @@ isset($_POST['status']) ? define('POST_STATUS', $_POST['status']): define('POST_
if ($userservice->isLoggedOn() && sizeof($_FILES) > 0 && $_FILES['userfile']['size'] > 0) { if ($userservice->isLoggedOn() && sizeof($_FILES) > 0 && $_FILES['userfile']['size'] > 0) {
$userinfo = $userservice->getCurrentObjectUser(); $userinfo = $userservice->getCurrentObjectUser();
if (is_numeric(POST_STATUS)) { if (is_numeric(POST_STATUS)) {
$status = intval(POST_STATUS); $status = intval(POST_STATUS);
} else { } else {
$status = 2; $status = 2;
} }
$depth = array(); $depth = array();
$xml_parser = xml_parser_create(); $xml_parser = xml_parser_create();
xml_set_element_handler($xml_parser, "startElement", "endElement"); xml_set_element_handler($xml_parser, "startElement", "endElement");
if (!($fp = fopen($_FILES['userfile']['tmp_name'], "r"))) if (!($fp = fopen($_FILES['userfile']['tmp_name'], "r"))) {
die(T_("Could not open XML input")); die(T_("Could not open XML input"));
}
while ($data = fread($fp, 4096)) { while ($data = fread($fp, 4096)) {
if (!xml_parse($xml_parser, $data, feof($fp))) { if (!xml_parse($xml_parser, $data, feof($fp))) {
die(sprintf(T_("XML error: %s at line %d"), die(sprintf(
xml_error_string(xml_get_error_code($xml_parser)), T_("XML error: %s at line %d"),
xml_get_current_line_number($xml_parser))); xml_error_string(xml_get_error_code($xml_parser)),
} xml_get_current_line_number($xml_parser)
} ));
xml_parser_free($xml_parser); }
header('Location: '. createURL('bookmarks', $userinfo->getUsername())); }
xml_parser_free($xml_parser);
header('Location: '. createURL('bookmarks', $userinfo->getUsername()));
} else { } else {
$templatename = 'importDelicious.tpl'; $templatename = 'importDelicious.tpl';
$tplVars['subtitle'] = T_('Import Bookmarks from del.icio.us'); $tplVars['subtitle'] = T_('Import Bookmarks from del.icio.us');
$tplVars['formaction'] = createURL('import'); $tplVars['formaction'] = createURL('import');
$templateservice->loadTemplate($templatename, $tplVars); $templateservice->loadTemplate($templatename, $tplVars);
} }
function startElement($parser, $name, $attrs)
{
global $depth, $status, $tplVars, $userservice;
$bookmarkservice = SemanticScuttle_Service_Factory::get('Bookmark');
function startElement($parser, $name, $attrs) { if ($name == 'POST') {
global $depth, $status, $tplVars, $userservice; while (list($attrTitle, $attrVal) = each($attrs)) {
switch ($attrTitle) {
case 'HREF':
$bAddress = $attrVal;
break;
case 'DESCRIPTION':
$bTitle = $attrVal;
break;
case 'EXTENDED':
$bDescription = $attrVal;
break;
case 'TIME':
$bDatetime = $attrVal;
break;
case 'TAG':
$tags = strtolower($attrVal);
break;
}
}
if ($bookmarkservice->bookmarkExists($bAddress, $userservice->getCurrentUserId())) {
$tplVars['error'] = T_('You have already submitted this bookmark.');
} else {
// Strangely, PHP can't work out full ISO 8601 dates, so we have to chop off the Z.
$bDatetime = substr($bDatetime, 0, -1);
$bookmarkservice =SemanticScuttle_Service_Factory::get('Bookmark'); // If bookmark claims to be from the future, set it to be now instead
if (strtotime($bDatetime) > time()) {
$bDatetime = gmdate('Y-m-d H:i:s');
}
if ($name == 'POST') { if ($bookmarkservice->addBookmark($bAddress, $bTitle, $bDescription, '', $status, $tags, null, $bDatetime, true, true)) {
while(list($attrTitle, $attrVal) = each($attrs)) { $tplVars['msg'] = T_('Bookmark imported.');
switch ($attrTitle) { } else {
case 'HREF': $tplVars['error'] = T_('There was an error saving your bookmark. Please try again or contact the administrator.');
$bAddress = $attrVal; }
break; }
case 'DESCRIPTION': }
$bTitle = $attrVal; $depth[$parser]++;
break;
case 'EXTENDED':
$bDescription = $attrVal;
break;
case 'TIME':
$bDatetime = $attrVal;
break;
case 'TAG':
$tags = strtolower($attrVal);
break;
}
}
if ($bookmarkservice->bookmarkExists($bAddress, $userservice->getCurrentUserId())) {
$tplVars['error'] = T_('You have already submitted this bookmark.');
} else {
// Strangely, PHP can't work out full ISO 8601 dates, so we have to chop off the Z.
$bDatetime = substr($bDatetime, 0, -1);
// If bookmark claims to be from the future, set it to be now instead
if (strtotime($bDatetime) > time()) {
$bDatetime = gmdate('Y-m-d H:i:s');
}
if ($bookmarkservice->addBookmark($bAddress, $bTitle, $bDescription, '', $status, $tags, null, $bDatetime, true, true))
$tplVars['msg'] = T_('Bookmark imported.');
else
$tplVars['error'] = T_('There was an error saving your bookmark. Please try again or contact the administrator.');
}
}
$depth[$parser]++;
} }
function endElement($parser, $name) { function endElement($parser, $name)
global $depth; {
$depth[$parser]--; global $depth;
$depth[$parser]--;
} }
?> ?>

View File

@ -34,93 +34,93 @@ $countImportedBookmarks = 0;
$tplVars['msg'] = ''; $tplVars['msg'] = '';
if ($userservice->isLoggedOn() && sizeof($_FILES) > 0 && $_FILES['userfile']['size'] > 0) { if ($userservice->isLoggedOn() && sizeof($_FILES) > 0 && $_FILES['userfile']['size'] > 0) {
$userinfo = $userservice->getCurrentObjectUser(); $userinfo = $userservice->getCurrentObjectUser();
if (is_numeric(POST_STATUS)) { if (is_numeric(POST_STATUS)) {
$status = intval(POST_STATUS); $status = intval(POST_STATUS);
} else { } else {
$status = 2; $status = 2;
} }
// File handle // File handle
$html = file_get_contents($_FILES['userfile']['tmp_name']); $html = file_get_contents($_FILES['userfile']['tmp_name']);
// Create link array // Create link array
//preg_match_all('/<a\s+(.*?)\s*\/*>([^<]*)/si', $html, $matches); //preg_match_all('/<a\s+(.*?)\s*\/*>([^<]*)/si', $html, $matches);
preg_match_all('/<a\s+(.*?)>([^<]*?)<\/a>.*?(<dd>([^<]*)|<dt>)/si', $html, $matches); preg_match_all('/<a\s+(.*?)>([^<]*?)<\/a>.*?(<dd>([^<]*)|<dt>)/si', $html, $matches);
//var_dump($matches);die(); //var_dump($matches);die();
$links = $matches[1]; $links = $matches[1];
$titles = $matches[2]; $titles = $matches[2];
$descriptions = $matches[4]; $descriptions = $matches[4];
$size = count($links); $size = count($links);
for ($i = 0; $i < $size; $i++) { for ($i = 0; $i < $size; $i++) {
// echo "<hr/>"; // echo "<hr/>";
// echo $links[$i]."<br/>"; // echo $links[$i]."<br/>";
preg_match_all('/(\w*\s*=\s*"[^"]*")/', $links[$i], $attributes); preg_match_all('/(\w*\s*=\s*"[^"]*")/', $links[$i], $attributes);
//$attributes = $attributes[0]; // we keep just one row //$attributes = $attributes[0]; // we keep just one row
$bDatetime = ""; //bDateTime optional $bDatetime = ""; //bDateTime optional
$bCategories = ""; //bCategories optional $bCategories = ""; //bCategories optional
foreach ($attributes[0] as $attribute) { foreach ($attributes[0] as $attribute) {
$att = preg_split('/\s*=\s*/s', $attribute, 2); $att = preg_split('/\s*=\s*/s', $attribute, 2);
$attrTitle = $att[0]; $attrTitle = $att[0];
$attrVal = eregi_replace('"', '&quot;', preg_replace('/([\'"]?)(.*)\1/', '$2', $att[1])); $attrVal = eregi_replace('"', '&quot;', preg_replace('/([\'"]?)(.*)\1/', '$2', $att[1]));
switch ($attrTitle) { switch ($attrTitle) {
case "HREF": case "HREF":
$bAddress = $attrVal; $bAddress = $attrVal;
break; break;
case "ADD_DATE": case "ADD_DATE":
$bDatetime = gmdate('Y-m-d H:i:s', $attrVal); $bDatetime = gmdate('Y-m-d H:i:s', $attrVal);
break; break;
case "TAGS": case "TAGS":
$bCategories = $attrVal; $bCategories = $attrVal;
break; break;
case "NOTE": case "NOTE":
$bPrivateNote = $attrVal; $bPrivateNote = $attrVal;
} }
} }
$bTitle = trim($titles[$i]); $bTitle = trim($titles[$i]);
$bDescription = trim($descriptions[$i]); $bDescription = trim($descriptions[$i]);
if ($bookmarkservice->bookmarkExists($bAddress, $userservice->getCurrentUserId())) { if ($bookmarkservice->bookmarkExists($bAddress, $userservice->getCurrentUserId())) {
$tplVars['error'] = T_('You have already submitted some of these bookmarks.'); $tplVars['error'] = T_('You have already submitted some of these bookmarks.');
} else { } else {
// If bookmark is local (like javascript: or place: in Firefox3), do nothing // If bookmark is local (like javascript: or place: in Firefox3), do nothing
if(substr($bAddress, 0, 7) == "http://" || substr($bAddress, 0, 8) == "https://") { if (substr($bAddress, 0, 7) == "http://" || substr($bAddress, 0, 8) == "https://") {
// If bookmark claims to be from the future, set it to be now instead // If bookmark claims to be from the future, set it to be now instead
if (strtotime($bDatetime) > time()) { if (strtotime($bDatetime) > time()) {
$bDatetime = gmdate('Y-m-d H:i:s'); $bDatetime = gmdate('Y-m-d H:i:s');
} }
if ($bookmarkservice->addBookmark($bAddress, $bTitle, $bDescription, $bPrivateNote, $status, $bCategories, null, $bDatetime, false, true)) { if ($bookmarkservice->addBookmark($bAddress, $bTitle, $bDescription, $bPrivateNote, $status, $bCategories, null, $bDatetime, false, true)) {
$countImportedBookmarks++; $countImportedBookmarks++;
} else { } else {
$tplVars['error'] = T_('There was an error saving your bookmark. Please try again or contact the administrator.'); $tplVars['error'] = T_('There was an error saving your bookmark. Please try again or contact the administrator.');
} }
} }
} }
} }
//header('Location: '. createURL('bookmarks', $userinfo->getUsername())); //header('Location: '. createURL('bookmarks', $userinfo->getUsername()));
$templatename = 'importNetscape.tpl'; $templatename = 'importNetscape.tpl';
$tplVars['msg'].= T_('Bookmarks found: ').$size.' '; $tplVars['msg'].= T_('Bookmarks found: ').$size.' ';
$tplVars['msg'].= T_('Bookmarks imported: ').' '.$countImportedBookmarks; $tplVars['msg'].= T_('Bookmarks imported: ').' '.$countImportedBookmarks;
$tplVars['subtitle'] = T_('Import Bookmarks from Browser File'); $tplVars['subtitle'] = T_('Import Bookmarks from Browser File');
$tplVars['formaction'] = createURL('importNetscape'); $tplVars['formaction'] = createURL('importNetscape');
$templateservice->loadTemplate($templatename, $tplVars); $templateservice->loadTemplate($templatename, $tplVars);
} else { } else {
$templatename = 'importNetscape.tpl'; $templatename = 'importNetscape.tpl';
$tplVars['subtitle'] = T_('Import Bookmarks from Browser File'); $tplVars['subtitle'] = T_('Import Bookmarks from Browser File');
$tplVars['formaction'] = createURL('importNetscape'); $tplVars['formaction'] = createURL('importNetscape');
$templateservice->loadTemplate($templatename, $tplVars); $templateservice->loadTemplate($templatename, $tplVars);
} }
?> ?>

View File

@ -22,7 +22,7 @@
require_once 'www-header.php'; require_once 'www-header.php';
/* Service creation: only useful services are created */ /* Service creation: only useful services are created */
$tag2tagservice =SemanticScuttle_Service_Factory::get('Tag2Tag'); $tag2tagservice = SemanticScuttle_Service_Factory::get('Tag2Tag');
/* Managing current logged user */ /* Managing current logged user */
$currentUser = $userservice->getCurrentObjectUser(); $currentUser = $userservice->getCurrentObjectUser();
@ -34,37 +34,37 @@ $currentUser = $userservice->getCurrentObjectUser();
$tplVars['msg'] = ''; $tplVars['msg'] = '';
if ($userservice->isLoggedOn() && sizeof($_FILES) > 0 && $_FILES['userfile']['size'] > 0) { if ($userservice->isLoggedOn() && sizeof($_FILES) > 0 && $_FILES['userfile']['size'] > 0) {
$userinfo = $userservice->getCurrentObjectUser(); $userinfo = $userservice->getCurrentObjectUser();
// File handle // File handle
$html = file_get_contents($_FILES['userfile']['tmp_name']); $html = file_get_contents($_FILES['userfile']['tmp_name']);
// Create link array // Create link array
preg_match_all('/(.*?)\n/', $html, $matches); preg_match_all('/(.*?)\n/', $html, $matches);
//print_r($matches); die(); //print_r($matches); die();
$fatherTag = ''; $fatherTag = '';
$countNewLinks = 0; $countNewLinks = 0;
foreach($matches[1] as $match) { foreach ($matches[1] as $match) {
if($match == '') { if ($match == '') {
// do nothing because void line // do nothing because void line
}elseif(substr($match, 0, 2) == '//') { } elseif (substr($match, 0, 2) == '//') {
// do nothing because commentary // do nothing because commentary
} elseif(substr($match, 0, 2) == ' ') { } elseif (substr($match, 0, 2) == ' ') {
// add as child of previous tag // add as child of previous tag
if($fatherTag != '') { if ($fatherTag != '') {
$tag2tagservice->addLinkedTags($fatherTag, $match, '>', $currentUser->getId()); $tag2tagservice->addLinkedTags($fatherTag, $match, '>', $currentUser->getId());
$countNewLinks++; $countNewLinks++;
} else { } else {
$tplVars['error'] = T_('Bad indentation'). ' '.$match; $tplVars['error'] = T_('Bad indentation'). ' '.$match;
} }
} else{ } else {
$fatherTag = $match; $fatherTag = $match;
} }
} }
$tplVars['msg'] = T_('New links between tags: ').$countNewLinks; $tplVars['msg'] = T_('New links between tags: ').$countNewLinks;
} }

View File

@ -22,49 +22,58 @@
require_once 'www-header.php'; require_once 'www-header.php';
/* Service creation: only useful services are created */ /* Service creation: only useful services are created */
$bookmarkservice =SemanticScuttle_Service_Factory::get('Bookmark'); $bookmarkservice = SemanticScuttle_Service_Factory::get('Bookmark');
$cacheservice =SemanticScuttle_Service_Factory::get('Cache'); $cacheservice = SemanticScuttle_Service_Factory::get('Cache');
/* Managing all possible inputs */ /* Managing all possible inputs */
isset($_GET['action']) ? define('GET_ACTION', $_GET['action']): define('GET_ACTION', ''); isset($_GET['action']) ? define('GET_ACTION', $_GET['action']): define('GET_ACTION', '');
isset($_GET['page']) ? define('GET_PAGE', $_GET['page']): define('GET_PAGE', 0); isset($_GET['page']) ? define('GET_PAGE', $_GET['page']): define('GET_PAGE', 0);
isset($_GET['sort']) ? define('GET_SORT', $_GET['sort']): define('GET_SORT', ''); isset($_GET['sort']) ? define('GET_SORT', $_GET['sort']): define('GET_SORT', '');
// Logout action // Logout action
if (GET_ACTION == "logout") { if (GET_ACTION == "logout") {
$userservice->logout(); $userservice->logout();
$tplVars['currentUser'] = null; $tplVars['currentUser'] = null;
$tplvars['msg'] = T_('You have now logged out'); $tplvars['msg'] = T_('You have now logged out');
} }
// Header variables // Header variables
$tplVars['loadjs'] = true; $tplVars['loadjs'] = true;
$tplVars['rsschannels'] = array( $tplVars['rsschannels'] = array(
array(sprintf(T_('%s: Recent bookmarks'), $sitename), createURL('rss').'?sort='.getSortOrder()) array(filter(sprintf(T_('%s: Recent bookmarks'), $sitename)), createURL('rss').'?sort='.getSortOrder())
); );
if ($userservice->isLoggedOn()) {
$currentUsername = $currentUser->getUsername();
if ($userservice->isPrivateKeyValid($currentUser->getPrivateKey())) {
array_push(
$tplVars['rsschannels'],
array(
filter($sitename . sprintf(T_(': (private) ')) . $currentUsername),
createURL('rss', filter($currentUsername, 'url') . '?sort='.getSortOrder().'&amp;privatekey='.$currentUser->getPrivateKey())
)
);
}
}
if ($usecache) { if ($usecache) {
// Generate hash for caching on // Generate hash for caching on
$hashtext = $_SERVER['REQUEST_URI']; $hashtext = $_SERVER['REQUEST_URI'];
if ($userservice->isLoggedOn()) { if ($userservice->isLoggedOn()) {
$hashtext .= $userservice->getCurrentUserID(); $hashtext .= $userservice->getCurrentUserID();
} }
$hash = md5($hashtext); $hash = md5($hashtext);
// Cache for 15 minutes // Cache for 15 minutes
$cacheservice->Start($hash, 900); $cacheservice->Start($hash, 900);
} }
// Pagination // Pagination
$perpage = getPerPageCount($currentUser); $perpage = getPerPageCount($currentUser);
if (intval(GET_PAGE) > 1) { if (intval(GET_PAGE) > 1) {
$page = intval(GET_PAGE); $page = intval(GET_PAGE);
$start = ($page - 1) * $perpage; $start = ($page - 1) * $perpage;
} else { } else {
$page = 0; $page = 0;
$start = 0; $start = 0;
} }
$tplVars['page'] = $page; $tplVars['page'] = $page;
@ -76,7 +85,7 @@ $tplVars['pagetitle'] = T_('Store, share and tag your favourite links');
$tplVars['subtitle'] = T_('All Bookmarks'); $tplVars['subtitle'] = T_('All Bookmarks');
$tplVars['bookmarkCount'] = $start + 1; $tplVars['bookmarkCount'] = $start + 1;
$bookmarks = $bookmarkservice->getBookmarks($start, $perpage, NULL, NULL, NULL, getSortOrder(), NULL, 0, NULL); $bookmarks = $bookmarkservice->getBookmarks($start, $perpage, null, null, null, getSortOrder(), null, 0, null);
$tplVars['total'] = $bookmarks['total']; $tplVars['total'] = $bookmarks['total'];
$tplVars['bookmarks'] =& $bookmarks['bookmarks']; $tplVars['bookmarks'] =& $bookmarks['bookmarks'];
@ -90,7 +99,7 @@ $tplVars['currenttag'] = '';
$templateservice->loadTemplate('bookmarks.tpl', $tplVars); $templateservice->loadTemplate('bookmarks.tpl', $tplVars);
if ($usecache) { if ($usecache) {
// Cache output if existing copy has expired // Cache output if existing copy has expired
$cacheservice->End($hash); $cacheservice->End($hash);
} }
?> ?>

View File

@ -89,6 +89,16 @@ function useAddress(ele) {
} }
} }
function getNewPrivateKey(input, response){
var pk = document.getElementById('pPrivateKey');
if (response != null) {
pk.value = response.trim();
} else {
loadXMLDocProc('<?php echo ROOT; ?>ajaxGetNewPrivateKey.php');
}
return false;
}
function getTitle(input, response){ function getTitle(input, response){
var title = document.getElementById('titleField'); var title = document.getElementById('titleField');
if (title.value == '') { if (title.value == '') {

View File

@ -33,17 +33,18 @@ isset($_POST['username']) ? define('POST_USERNAME', $_POST['username']): define(
isset($_POST['password']) ? define('POST_PASSWORD', $_POST['password']): define('POST_PASSWORD', ''); isset($_POST['password']) ? define('POST_PASSWORD', $_POST['password']): define('POST_PASSWORD', '');
isset($_POST['query']) ? define('POST_QUERY', $_POST['query']): define('POST_QUERY', ''); isset($_POST['query']) ? define('POST_QUERY', $_POST['query']): define('POST_QUERY', '');
$keeppass = (POST_KEEPPASS=='yes')?true:false; $keeppass = (POST_KEEPPASS=='yes') ? true : false;
$login = false; $login = false;
if (POST_SUBMITTED!='' && POST_USERNAME!='' && POST_PASSWORD!='') { if (POST_SUBMITTED!='' && POST_USERNAME!='' && POST_PASSWORD!='') {
$posteduser = trim(utf8_strtolower(POST_USERNAME)); $posteduser = trim(utf8_strtolower(POST_USERNAME));
$login = $userservice->login($posteduser, POST_PASSWORD, $keeppass); $login = $userservice->login($posteduser, POST_PASSWORD, $keeppass);
if ($login) { if ($login) {
if (POST_QUERY) if (POST_QUERY) {
header('Location: '. createURL('bookmarks', $posteduser .'?'. POST_QUERY)); header('Location: '. createURL('bookmarks', $posteduser .'?'. POST_QUERY));
else } else {
header('Location: '. createURL('bookmarks', $posteduser)); header('Location: '. createURL('bookmarks', $posteduser));
}
} else { } else {
$tplVars['error'] = T_('The details you have entered are incorrect. Please try again.'); $tplVars['error'] = T_('The details you have entered are incorrect. Please try again.');
} }

View File

@ -31,44 +31,44 @@ isset($_POST['email']) ? define('POST_EMAIL', $_POST['email']): define('POST_EMA
// IF SUBMITTED // IF SUBMITTED
if (POST_SUBMITTED != '') { if (POST_SUBMITTED != '') {
// NO USERNAME // NO USERNAME
if (!POST_USERNAME) { if (!POST_USERNAME) {
$tplVars['error'] = T_('You must enter your username.'); $tplVars['error'] = T_('You must enter your username.');
// NO E-MAIL // NO E-MAIL
} elseif (!POST_EMAIL) { } elseif (!POST_EMAIL) {
$tplVars['error'] = T_('You must enter your <abbr title="electronic mail">e-mail</abbr> address.'); $tplVars['error'] = T_('You must enter your <abbr title="electronic mail">e-mail</abbr> address.');
// USERNAME AND E-MAIL // USERNAME AND E-MAIL
} else { } else {
// NO MATCH // NO MATCH
$userinfo = $userservice->getObjectUserByUsername(POST_USERNAME); $userinfo = $userservice->getObjectUserByUsername(POST_USERNAME);
if ($userinfo == NULL) { if ($userinfo == null) {
$tplVars['error'] = T_('No matches found for that username.'); $tplVars['error'] = T_('No matches found for that username.');
} elseif (POST_EMAIL != $userinfo->getEmail()) { } elseif (POST_EMAIL != $userinfo->getEmail()) {
$tplVars['error'] = T_('No matches found for that combination of username and <abbr title="electronic mail">e-mail</abbr> address.'); $tplVars['error'] = T_('No matches found for that combination of username and <abbr title="electronic mail">e-mail</abbr> address.');
// MATCH // MATCH
} else { } else {
// GENERATE AND STORE PASSWORD // GENERATE AND STORE PASSWORD
$password = $userservice->generatePassword($userinfo->getId()); $password = $userservice->generatePassword($userinfo->getId());
if (!($password = $userservice->generatePassword($userinfo->getId()))) { if (!($password = $userservice->generatePassword($userinfo->getId()))) {
$tplVars['error'] = T_('There was an error while generating your new password. Please try again.'); $tplVars['error'] = T_('There was an error while generating your new password. Please try again.');
} else { } else {
// SEND E-MAIL // SEND E-MAIL
$message = T_('Your new password is:') ."\n". $password ."\n\n". T_('To keep your bookmarks secure, you should change this password in your profile the next time you log in.'); $message = T_('Your new password is:') ."\n". $password ."\n\n". T_('To keep your bookmarks secure, you should change this password in your profile the next time you log in.');
$message = wordwrap($message, 70); $message = wordwrap($message, 70);
$headers = 'From: '. $adminemail; $headers = 'From: '. $adminemail;
$mail = mail(POST_EMAIL, sprintf(T_('%s Account Information'), $sitename), $message); $mail = mail(POST_EMAIL, sprintf(T_('%s Account Information'), $sitename), $message);
$tplVars['msg'] = sprintf(T_('New password generated and sent to %s'), POST_EMAIL); $tplVars['msg'] = sprintf(T_('New password generated and sent to %s'), POST_EMAIL);
} }
} }
} }
} }
$templatename = 'password.tpl'; $templatename = 'password.tpl';

View File

@ -22,24 +22,24 @@
require_once 'www-header.php'; require_once 'www-header.php';
/* Service creation: only useful services are created */ /* Service creation: only useful services are created */
$b2tservice =SemanticScuttle_Service_Factory::get('Bookmark2Tag'); $b2tservice = SemanticScuttle_Service_Factory::get('Bookmark2Tag');
$cacheservice =SemanticScuttle_Service_Factory::get('Cache'); $cacheservice = SemanticScuttle_Service_Factory::get('Cache');
@list($url, $user) = isset($_SERVER['PATH_INFO']) ? explode('/', $_SERVER['PATH_INFO']) : NULL; @list($url, $user) = isset($_SERVER['PATH_INFO']) ? explode('/', $_SERVER['PATH_INFO']) : null;
if ($usecache) { if ($usecache) {
// Generate hash for caching on // Generate hash for caching on
$hashtext = $_SERVER['REQUEST_URI']; $hashtext = $_SERVER['REQUEST_URI'];
if ($userservice->isLoggedOn()) { if ($userservice->isLoggedOn()) {
$hashtext .= $currentUser->getId(); $hashtext .= $currentUser->getId();
if ($currentUser->getUsername() == $user) { if ($currentUser->getUsername() == $user) {
$hashtext .= $user; $hashtext .= $user;
} }
} }
$hash = md5($hashtext); $hash = md5($hashtext);
// Cache for an hour // Cache for an hour
$cacheservice->Start($hash, 3600); $cacheservice->Start($hash, 3600);
} }
// Header variables // Header variables
@ -47,17 +47,17 @@ $pagetitle = T_('Popular Tags');
if (isset($user) && $user != '') { if (isset($user) && $user != '') {
$userid = $userservice->getIdFromUser($user); $userid = $userservice->getIdFromUser($user);
if($userid == NULL) { if ($userid == null) {
$tplVars['error'] = sprintf(T_('User with username %s was not found'), $user); $tplVars['error'] = sprintf(T_('User with username %s was not found'), $user);
$templateservice->loadTemplate('error.404.tpl', $tplVars); $templateservice->loadTemplate('error.404.tpl', $tplVars);
//throw a 404 error //throw a 404 error
exit(); exit();
} }
$pagetitle .= ': '. ucfirst($user); $pagetitle .= ': '. ucfirst($user);
} else { } else {
$userid = NULL; $userid = null;
} }
$tags = $b2tservice->getPopularTags($userid, 150); $tags = $b2tservice->getPopularTags($userid, 150);
@ -65,9 +65,9 @@ $tplVars['tags'] =& $b2tservice->tagCloud($tags, 5, 90, 225, getSortOrder('alpha
$tplVars['user'] = $user; $tplVars['user'] = $user;
if (isset($userid)) { if (isset($userid)) {
$tplVars['cat_url'] = createURL('bookmarks', '%s/%s'); $tplVars['cat_url'] = createURL('bookmarks', '%s/%s');
} else { } else {
$tplVars['cat_url'] = createURL('tags', '%2$s'); $tplVars['cat_url'] = createURL('tags', '%2$s');
} }
$tplVars['sidebar_blocks'] = array('linked'); $tplVars['sidebar_blocks'] = array('linked');
@ -78,7 +78,7 @@ $tplVars['loadjs'] = true;
$templateservice->loadTemplate('tags.tpl', $tplVars); $templateservice->loadTemplate('tags.tpl', $tplVars);
if ($usecache) { if ($usecache) {
// Cache output if existing copy has expired // Cache output if existing copy has expired
$cacheservice->End($hash); $cacheservice->End($hash);
} }
?> ?>

View File

@ -25,10 +25,13 @@ require_once 'www-header.php';
// No specific services // No specific services
/* Managing all possible inputs */ /* Managing all possible inputs */
isset($_POST['submittedPK']) ? define('POST_SUBMITTEDPK', $_POST['submittedPK']): define('POST_SUBMITTEDPK', '');
isset($_POST['submitted']) ? define('POST_SUBMITTED', $_POST['submitted']): define('POST_SUBMITTED', ''); isset($_POST['submitted']) ? define('POST_SUBMITTED', $_POST['submitted']): define('POST_SUBMITTED', '');
isset($_POST['pPass']) ? define('POST_PASS', $_POST['pPass']): define('POST_PASS', ''); isset($_POST['pPass']) ? define('POST_PASS', $_POST['pPass']): define('POST_PASS', '');
isset($_POST['pPassConf']) ? define('POST_PASSCONF', $_POST['pPassConf']): define('POST_PASSCONF', ''); isset($_POST['pPassConf']) ? define('POST_PASSCONF', $_POST['pPassConf']): define('POST_PASSCONF', '');
isset($_POST['pName']) ? define('POST_NAME', $_POST['pName']): define('POST_NAME', ''); isset($_POST['pName']) ? define('POST_NAME', $_POST['pName']): define('POST_NAME', '');
isset($_POST['pPrivateKey']) ? define('POST_PRIVATEKEY', $_POST['pPrivateKey']): define('POST_PRIVATEKEY', '');
isset($_POST['pEnablePrivateKey']) ? define('POST_ENABLEPRIVATEKEY', $_POST['pEnablePrivateKey']): define('POST_ENABLEPRIVATEKEY', '');
isset($_POST['pMail']) ? define('POST_MAIL', $_POST['pMail']): define('POST_MAIL', ''); isset($_POST['pMail']) ? define('POST_MAIL', $_POST['pMail']): define('POST_MAIL', '');
isset($_POST['pPage']) ? define('POST_PAGE', $_POST['pPage']): define('POST_PAGE', ''); isset($_POST['pPage']) ? define('POST_PAGE', $_POST['pPage']): define('POST_PAGE', '');
isset($_POST['pDesc']) ? define('POST_DESC', $_POST['pDesc']): define('POST_DESC', ''); isset($_POST['pDesc']) ? define('POST_DESC', $_POST['pDesc']): define('POST_DESC', '');
@ -38,33 +41,41 @@ isset($_SESSION['token']) ? define('SESSION_TOKEN', $_SESSION['token']): define(
isset($_SESSION['token_stamp']) ? define('SESSION_TOKENSTAMP', $_SESSION['token_stamp']): define('SESSION_TOKENSTAMP', ''); isset($_SESSION['token_stamp']) ? define('SESSION_TOKENSTAMP', $_SESSION['token_stamp']): define('SESSION_TOKENSTAMP', '');
@list($url, $user) = isset($_SERVER['PATH_INFO']) ? explode('/', $_SERVER['PATH_INFO']) : NULL; @list($url, $user) = isset($_SERVER['PATH_INFO']) ? explode('/', $_SERVER['PATH_INFO']) : null;
if ($user) { if ($user) {
if (is_int($user)) {
if (is_int($user)) { $userid = intval($user);
$userid = intval($user); } else {
} else { $user = urldecode($user);
$user = urldecode($user); $userinfo = $userservice->getObjectUserByUsername($user);
$userinfo = $userservice->getObjectUserByUsername($user); if ($userinfo == null) {
if ($userinfo == NULL) { $tplVars['error'] = sprintf(T_('User with username %s was not found'), $user);
$tplVars['error'] = sprintf(T_('User with username %s was not found'), $user); $templateservice->loadTemplate('error.404.tpl', $tplVars);
$templateservice->loadTemplate('error.404.tpl', $tplVars); exit();
exit(); } else {
} else { $userid =& $userinfo->getId();
$userid =& $userinfo->getId(); }
} }
}
} else { } else {
$tplVars['error'] = T_('Username was not specified'); $tplVars['error'] = T_('Username was not specified');
$templateservice->loadTemplate('error.404.tpl', $tplVars); $templateservice->loadTemplate('error.404.tpl', $tplVars);
exit(); exit();
} }
$tplVars['privateKeyIsEnabled'] = '';
if ($userservice->isLoggedOn() && $user == $currentUser->getUsername()) { if ($userservice->isLoggedOn() && $user == $currentUser->getUsername()) {
$title = T_('My Profile'); $title = T_('My Profile');
$tplVars['privateKey'] = $currentUser->getPrivateKey(true);
if ($userservice->isPrivateKeyValid($currentUser->getPrivateKey())) {
$tplVars['privateKeyIsEnabled'] = 'checked="checked"';
} else {
$tplVars['privateKeyIsEnabled'] = '';
}
} else { } else {
$title = T_('Profile') .': '. $user; $title = T_('Profile') .': '. $user;
$tplVars['privateKey'] = '';
} }
$tplVars['pagetitle'] = $title; $tplVars['pagetitle'] = $title;
$tplVars['subtitle'] = $title; $tplVars['subtitle'] = $title;
@ -72,58 +83,72 @@ $tplVars['subtitle'] = $title;
$tplVars['user'] = $user; $tplVars['user'] = $user;
$tplVars['userid'] = $userid; $tplVars['userid'] = $userid;
/* Update Private Key */
if (POST_SUBMITTEDPK!='' && $currentUser->getId() == $userid) {
$userinfo = $userservice->getObjectUserByUsername($user);
$tplVars['privateKey'] = $userservice->getNewPrivateKey();
}
if (POST_SUBMITTED!='' && $currentUser->getId() == $userid) { if (POST_SUBMITTED!='' && $currentUser->getId() == $userid) {
$error = false; $error = false;
$detPass = trim(POST_PASS); $detPass = trim(POST_PASS);
$detPassConf = trim(POST_PASSCONF); $detPassConf = trim(POST_PASSCONF);
$detName = trim(POST_NAME); $detName = trim(POST_NAME);
$detMail = trim(POST_MAIL); $detPrivateKey = trim(POST_PRIVATEKEY);
$detPage = trim(POST_PAGE); $detEnablePrivateKey = trim(POST_ENABLEPRIVATEKEY);
$detDesc = filter(POST_DESC); $detMail = trim(POST_MAIL);
$detPage = trim(POST_PAGE);
$detDesc = filter(POST_DESC);
// manage token preventing from CSRF vulnaribilities // manage token preventing from CSRF vulnaribilities
if ( SESSION_TOKEN == '' //limit token lifetime, optionnal
|| time() - SESSION_TOKENSTAMP > 600 //limit token lifetime, optionnal if ( SESSION_TOKEN == '' || time() - SESSION_TOKENSTAMP > 600 || SESSION_TOKEN != POST_TOKEN) {
|| SESSION_TOKEN != POST_TOKEN) { $error = true;
$error = true; $tplVars['error'] = T_('Invalid Token');
$tplVars['error'] = T_('Invalid Token'); }
}
if ($detPass != $detPassConf) { if ($detPass != $detPassConf) {
$error = true; $error = true;
$tplVars['error'] = T_('Password and confirmation do not match.'); $tplVars['error'] = T_('Password and confirmation do not match.');
} }
if ($detPass != "" && strlen($detPass) < 6) { if ($detPass != "" && strlen($detPass) < 6) {
$error = true; $error = true;
$tplVars['error'] = T_('Password must be at least 6 characters long.'); $tplVars['error'] = T_('Password must be at least 6 characters long.');
} }
if (!$userservice->isValidEmail($detMail)) { if (!$userservice->isValidEmail($detMail)) {
$error = true; $error = true;
$tplVars['error'] = T_('E-mail address is not valid.'); $tplVars['error'] = T_('E-mail address is not valid.');
} }
if (!$error) { if (!$error) {
if (!$userservice->updateUser($userid, $detPass, $detName, $detMail, $detPage, $detDesc)) { if (!$userservice->updateUser($userid, $detPass, $detName, $detMail, $detPage, $detDesc, $detPrivateKey, $detEnablePrivateKey)) {
$tplvars['error'] = T_('An error occurred while saving your changes.'); $tplvars['error'] = T_('An error occurred while saving your changes.');
} else { } else {
$tplVars['msg'] = T_('Changes saved.'); $tplVars['msg'] = T_('Changes saved.');
} }
} }
$userinfo = $userservice->getObjectUserByUsername($user); $userinfo = $userservice->getObjectUserByUsername($user);
$tplVars['privateKey'] = $userinfo->getPrivateKey(true);
if ($userservice->isPrivateKeyValid($userinfo->getPrivateKey())) {
$tplVars['privateKeyIsEnabled'] = 'checked="checked"';
} else {
$tplVars['privateKeyIsEnabled'] = '';
}
} }
if (!$userservice->isLoggedOn() || $currentUser->getId() != $userid) { if (!$userservice->isLoggedOn() || $currentUser->getId() != $userid) {
$templatename = 'profile.tpl.php'; $templatename = 'profile.tpl.php';
} else { } else {
//Token Init //Token Init
$_SESSION['token'] = md5(uniqid(rand(), true)); $_SESSION['token'] = md5(uniqid(rand(), true));
$_SESSION['token_stamp'] = time(); $_SESSION['token_stamp'] = time();
$templatename = 'editprofile.tpl.php';
$tplVars['formaction'] = createURL('profile', $user);
$tplVars['token'] = $_SESSION['token'];
$templatename = 'editprofile.tpl.php';
$tplVars['formaction'] = createURL('profile', $user);
$tplVars['token'] = $_SESSION['token'];
} }
$tplVars['objectUser'] = $userinfo; $tplVars['objectUser'] = $userinfo;
$tplVars['loadjs'] = true;
$templateservice->loadTemplate($templatename, $tplVars); $templateservice->loadTemplate($templatename, $tplVars);
?> ?>

View File

@ -42,7 +42,7 @@ if (POST_SUBMITTED != '') {
$posteduser = trim(utf8_strtolower(POST_USERNAME)); $posteduser = trim(utf8_strtolower(POST_USERNAME));
// Check if form is incomplete // Check if form is incomplete
if (!($posteduser) || POST_PASS == '' || POST_MAIL == '') { if (!($posteduser) || POST_PASS == '' || POST_MAIL == '') {
$tplVars['error'] = T_('You <em>must</em> enter a username, password and e-mail address.'); $tplVars['error'] = T_('You <em>must</em> enter a username, password and e-mail address.');
// Check if username is reserved // Check if username is reserved

View File

@ -64,9 +64,14 @@ if (!isset($rssEntries) || $rssEntries <= 0) {
$rssEntries = $maxRssEntries; $rssEntries = $maxRssEntries;
} }
$privatekey = null;
if (isset($_GET['privatekey'])) {
$privatekey = $_GET['privatekey'];
}
$watchlist = null; $watchlist = null;
$pagetitle = ''; $pagetitle = '';
$isTempLogin = false;
if ($user && $user != 'all') { if ($user && $user != 'all') {
if ($user == 'watchlist') { if ($user == 'watchlist') {
$user = $cat; $user = $cat;
@ -78,8 +83,23 @@ if ($user && $user != 'all') {
} else { } else {
if ($userinfo = $userservice->getUserByUsername($user)) { if ($userinfo = $userservice->getUserByUsername($user)) {
$userid =& $userinfo[$userservice->getFieldName('primary')]; $userid =& $userinfo[$userservice->getFieldName('primary')];
/* if user is not logged in and has valid privatekey */
if (!$userservice->isLoggedOn()) {
if ($privatekey != null) {
if ($userservice->loginPrivateKey($privatekey)) {
$isTempLogin = true;
} else {
$tplVars['error'] = sprintf(T_('Failed to Autenticate User with username %s using private key'), $user);
header('Content-type: text/html; charset=utf-8');
$templateservice->loadTemplate('error.404.tpl', $tplVars);
//throw a 404 error
exit();
}
}
}
} else { } else {
$tplVars['error'] = sprintf(T_('User with username %s was not found'), $user); $tplVars['error'] = sprintf(T_('User with username %s was not found'), $user);
header('Content-type: text/html; charset=utf-8');
$templateservice->loadTemplate('error.404.tpl', $tplVars); $templateservice->loadTemplate('error.404.tpl', $tplVars);
//throw a 404 error //throw a 404 error
exit(); exit();
@ -87,7 +107,19 @@ if ($user && $user != 'all') {
} }
$pagetitle .= ": ". $user; $pagetitle .= ": ". $user;
} else { } else {
$userid = null; if ($privatekey != null) {
if ($userservice->loginPrivateKey($privatekey)) {
$isTempLogin = true;
} else {
$tplVars['error'] = sprintf(T_('Failed to Autenticate User with username %s using private key'), $user);
header('Content-type: text/html; charset=utf-8');
$templateservice->loadTemplate('error.404.tpl', $tplVars);
//throw a 404 error
exit();
}
} else {
$userid = null;
}
} }
if ($cat) { if ($cat) {
@ -100,7 +132,8 @@ $tplVars['feeddescription'] = sprintf(T_('Recent bookmarks posted to %s'), $GLOB
$bookmarks = $bookmarkservice->getBookmarks( $bookmarks = $bookmarkservice->getBookmarks(
0, $rssEntries, $userid, $cat, 0, $rssEntries, $userid, $cat,
null, getSortOrder(), $watchlist null, getSortOrder(), $watchlist,
null, null, null
); );
$bookmarks_tmp = filter($bookmarks['bookmarks']); $bookmarks_tmp = filter($bookmarks['bookmarks']);
@ -134,6 +167,11 @@ $tplVars['feedlastupdate'] = date('r', strtotime($latestdate));
$templateservice->loadTemplate('rss.tpl', $tplVars); $templateservice->loadTemplate('rss.tpl', $tplVars);
/* If temporary login, please log out */
if ($isTempLogin) {
$userservice->logout();
}
if ($usecache) { if ($usecache) {
// Cache output if existing copy has expired // Cache output if existing copy has expired
$cacheservice->End($hash); $cacheservice->End($hash);

View File

@ -30,8 +30,8 @@ isset($_GET['sort']) ? define('GET_SORT', $_GET['sort']): define('GET_SORT', '')
// POST // POST
if (POST_TERMS != '') { if (POST_TERMS != '') {
// Redirect to GET // Redirect to GET
header( header(
'Location: ' 'Location: '
. createURL('search', POST_RANGE .'/'. filter(POST_TERMS, 'url')) . createURL('search', POST_RANGE .'/'. filter(POST_TERMS, 'url'))
); );
@ -46,17 +46,15 @@ $searchhistoryservice = SemanticScuttle_Service_Factory::get('SearchHistory');
/* Managing current logged user */ /* Managing current logged user */
$currentUserId = $userservice->getCurrentUserId(); $currentUserId = $userservice->getCurrentUserId();
$exploded = isset($_SERVER['PATH_INFO']) ? explode('/', $_SERVER['PATH_INFO']) : null;
$exploded = isset($_SERVER['PATH_INFO']) if (count($exploded) == 4) {
? explode('/', $_SERVER['PATH_INFO']) : null;
if(count($exploded) == 4) {
list($url, $range, $terms, $page) = $exploded; list($url, $range, $terms, $page) = $exploded;
} else if (count($exploded) == 2) { } elseif (count($exploded) == 2) {
list($url, $range) = $exploded; list($url, $range) = $exploded;
$terms = $page = NULL; $terms = $page = null;
} else { } else {
list($url, $range, $terms) = $exploded; list($url, $range, $terms) = $exploded;
$page = NULL; $page = null;
} }
//some OpenSearch clients need that //some OpenSearch clients need that
$terms = urldecode($terms); $terms = urldecode($terms);
@ -73,10 +71,10 @@ if (intval(GET_PAGE) > 1) {
$start = 0; $start = 0;
} }
$s_user = NULL; $s_user = null;
$s_start = NULL; $s_start = null;
$s_end = NULL; $s_end = null;
$s_watchlist = NULL; $s_watchlist = null;
// No search terms // No search terms
if (is_null($terms)) { if (is_null($terms)) {
@ -92,7 +90,7 @@ if (is_null($terms)) {
switch ($range) { switch ($range) {
case 'all': case 'all':
$tplVars['select_all'] = $selected; $tplVars['select_all'] = $selected;
$s_user = NULL; $s_user = null;
break; break;
case 'watchlist': case 'watchlist':
$tplVars['select_watchlist'] = $selected; $tplVars['select_watchlist'] = $selected;
@ -107,7 +105,7 @@ if (is_null($terms)) {
if (isset($s_user)) { if (isset($s_user)) {
$tplVars['user'] = $range; $tplVars['user'] = $range;
$s_user = $userservice->getIdFromUser($s_user); $s_user = $userservice->getIdFromUser($s_user);
if($s_user == NULL) { if ($s_user == null) {
$tplVars['error'] = sprintf(T_('User with username %s was not found'), $s_user); $tplVars['error'] = sprintf(T_('User with username %s was not found'), $s_user);
$templateservice->loadTemplate('error.404.tpl', $tplVars); $templateservice->loadTemplate('error.404.tpl', $tplVars);
exit(); exit();
@ -116,7 +114,7 @@ if (is_null($terms)) {
} }
} }
$bookmarks =& $bookmarkservice->getBookmarks( $bookmarks =& $bookmarkservice->getBookmarks(
$start, $perpage, $s_user, NULL, $terms, getSortOrder(), $start, $perpage, $s_user, null, $terms, getSortOrder(),
$s_watchlist, $s_start, $s_end $s_watchlist, $s_start, $s_end
); );
@ -125,9 +123,7 @@ $searchhistoryservice->addSearch(
$terms, $range, $bookmarks['total'], $currentUserId $terms, $range, $bookmarks['total'], $currentUserId
); );
if (isset($_GET['lucky']) && $_GET['lucky'] if (isset($_GET['lucky']) && $_GET['lucky'] && isset($bookmarks['bookmarks'][0])) {
&& isset($bookmarks['bookmarks'][0])
) {
$url = $bookmarks['bookmarks'][0]['bAddress']; $url = $bookmarks['bookmarks'][0]['bAddress'];
header('Location: ' . $url); header('Location: ' . $url);
exit(); exit();

View File

@ -33,7 +33,7 @@ isset($_POST['tag2']) ? define('POST_TAG2', $_POST['tag2']): define('POST_TAG2',
//permissions //permissions
if(!$userservice->isLoggedOn()) { if (!$userservice->isLoggedOn()) {
$tplVars['error'] = T_('Permission denied.'); $tplVars['error'] = T_('Permission denied.');
$templateservice->loadTemplate('error.500.tpl', $tplVars); $templateservice->loadTemplate('error.500.tpl', $tplVars);
exit(); exit();
@ -62,10 +62,9 @@ if (POST_CONFIRM != '') {
header('Location: '. createURL('bookmarks', $currentUser->getUsername() .'/'. $tags)); header('Location: '. createURL('bookmarks', $currentUser->getUsername() .'/'. $tags));
} }
$tplVars['links'] = $tag2tagservice->getLinks($currentUser->getId()); $tplVars['links'] = $tag2tagservice->getLinks($currentUser->getId());
$tplVars['tag1'] = $tag1;
$tplVars['tag1'] = $tag1; $tplVars['tag2'] = '';
$tplVars['tag2'] = '';
$tplVars['subtitle'] = T_('Add Tag Link') .': '. $tag1; $tplVars['subtitle'] = T_('Add Tag Link') .': '. $tag1;
$tplVars['formaction'] = $_SERVER['SCRIPT_NAME'] .'/'. $tag1; $tplVars['formaction'] = $_SERVER['SCRIPT_NAME'] .'/'. $tag1;
$tplVars['referrer'] = $_SERVER['HTTP_REFERER']; $tplVars['referrer'] = $_SERVER['HTTP_REFERER'];

View File

@ -37,47 +37,44 @@ isset($_SERVER['HTTP_REFERER']) ? define('HTTP_REFERER', $_SERVER['HTTP_REFERER'
$currentUser = $userservice->getCurrentObjectUser(); $currentUser = $userservice->getCurrentObjectUser();
//permissions //permissions
if(!$userservice->isloggedOn()) { if (!$userservice->isloggedOn()) {
$tplVars['error'] = T_('Permission denied.'); $tplVars['error'] = T_('Permission denied.');
$templateservice->loadTemplate('error.500.tpl', $tplVars); $templateservice->loadTemplate('error.500.tpl', $tplVars);
exit(); exit();
} }
/* Managing path info */ /* Managing path info */
if(isset($_SERVER['PATH_INFO'])) { if (isset($_SERVER['PATH_INFO'])) {
$exploded = explode('/', $_SERVER['PATH_INFO']); $exploded = explode('/', $_SERVER['PATH_INFO']);
if(count($exploded) == 3) { if (count($exploded) == 3) {
list ($url, $tag1, $tag2) = explode('/', $_SERVER['PATH_INFO']); list ($url, $tag1, $tag2) = explode('/', $_SERVER['PATH_INFO']);
} else { } else {
list ($url, $tag1) = explode('/', $_SERVER['PATH_INFO']); list ($url, $tag1) = explode('/', $_SERVER['PATH_INFO']);
$tag2 = ''; $tag2 = '';
} }
} else { } else {
$url = $tag1 = $tag2 = ''; $url = $tag1 = $tag2 = '';
} }
if (POST_CONFIRM) { if (POST_CONFIRM) {
$tag = POST_TAG1; $tag = POST_TAG1;
$linkType = POST_LINKTYPE; $linkType = POST_LINKTYPE;
$newTag = POST_TAG2; $newTag = POST_TAG2;
if ($tag2tagservice->removeLinkedTags(POST_TAG1, POST_TAG2, POST_LINKTYPE, $currentUser->getId())) { if ($tag2tagservice->removeLinkedTags(POST_TAG1, POST_TAG2, POST_LINKTYPE, $currentUser->getId())) {
$tplVars['msg'] = T_('Tag link deleted'); $tplVars['msg'] = T_('Tag link deleted');
header('Location: '. createURL('bookmarks', $currentUser->getUsername().'/'.$tag)); header('Location: '. createURL('bookmarks', $currentUser->getUsername().'/'.$tag));
} else { } else {
$tplVars['error'] = T_('Failed to delete the link'); $tplVars['error'] = T_('Failed to delete the link');
$templateservice->loadTemplate('error.500.tpl', $tplVars); $templateservice->loadTemplate('error.500.tpl', $tplVars);
exit(); exit();
} }
} elseif (POST_CANCEL) { } elseif (POST_CANCEL) {
header('Location: '. createURL('bookmarks', $currentUser->getUsername() .'/'. $tags)); header('Location: '. createURL('bookmarks', $currentUser->getUsername() .'/'. $tags));
} }
$tplVars['links'] = $tag2tagservice->getLinks($currentUser->getId()); $tplVars['links'] = $tag2tagservice->getLinks($currentUser->getId());
$tplVars['tag1'] = $tag1;
$tplVars['tag1'] = $tag1; $tplVars['tag2'] = $tag2;
$tplVars['tag2'] = $tag2;
$tplVars['subtitle'] = T_('Delete Link Between Tags') .': '. $tag1.' > '.$tag2; $tplVars['subtitle'] = T_('Delete Link Between Tags') .': '. $tag1.' > '.$tag2;
$tplVars['formaction'] = $_SERVER['SCRIPT_NAME']; $tplVars['formaction'] = $_SERVER['SCRIPT_NAME'];
$tplVars['referrer'] = HTTP_REFERER; $tplVars['referrer'] = HTTP_REFERER;

View File

@ -29,32 +29,31 @@ $tag2tagservice = SemanticScuttle_Service_Factory :: get('Tag2Tag');
isset($_SERVER['HTTP_REFERER']) ? define('HTTP_REFERER', $_SERVER['HTTP_REFERER']): define('HTTP_REFERER', ''); isset($_SERVER['HTTP_REFERER']) ? define('HTTP_REFERER', $_SERVER['HTTP_REFERER']): define('HTTP_REFERER', '');
//permissions //permissions
if(!$userservice->loggedOn()) { if (!$userservice->loggedOn()) {
$tplVars['error'] = T_('Permission denied.'); $tplVars['error'] = T_('Permission denied.');
$templateservice->loadTemplate('error.500.tpl', $tplVars); $templateservice->loadTemplate('error.500.tpl', $tplVars);
exit(); exit();
} }
/* Managing path info */ /* Managing path info */
if(isset($_SERVER['PATH_INFO'])) { if (isset($_SERVER['PATH_INFO'])) {
$exploded = explode('/', $_SERVER['PATH_INFO']); $exploded = explode('/', $_SERVER['PATH_INFO']);
if(count($exploded) == 3) { if (count($exploded) == 3) {
list ($url, $tag1, $tag2) = explode('/', $_SERVER['PATH_INFO']); list ($url, $tag1, $tag2) = explode('/', $_SERVER['PATH_INFO']);
} else { } else {
list ($url, $tag1) = explode('/', $_SERVER['PATH_INFO']); list ($url, $tag1) = explode('/', $_SERVER['PATH_INFO']);
$tag2 = ''; $tag2 = '';
} }
} else { } else {
$url = $tag1 = $tag2 = ''; $url = $tag1 = $tag2 = '';
} }
$tplVars['links'] = $tag2tagservice->getLinks($userservice->getCurrentUserId()); $tplVars['links'] = $tag2tagservice->getLinks($userservice->getCurrentUserId());
$tplVars['tag1'] = $tag1;
$tplVars['tag1'] = $tag1; $tplVars['tag2'] = $tag2;
$tplVars['tag2'] = $tag2; $tplVars['subtitle'] = T_('Edit Link Between Tags') .': '. $tag1.' > '.$tag2;
$tplVars['subtitle'] = T_('Edit Link Between Tags') .': '. $tag1.' > '.$tag2; $tplVars['formaddaction'] = createUrl('tag2tagadd');
$tplVars['formaddaction'] = createUrl('tag2tagadd');
$tplVars['formdeleteaction'] = createUrl('tag2tagdelete'); $tplVars['formdeleteaction'] = createUrl('tag2tagdelete');
$tplVars['referrer'] = HTTP_REFERER; $tplVars['referrer'] = HTTP_REFERER;
$templateservice->loadTemplate('tag2tagedit.tpl', $tplVars); $templateservice->loadTemplate('tag2tagedit.tpl', $tplVars);
?> ?>

View File

@ -43,11 +43,7 @@ $currentUser = $userservice->getCurrentObjectUser();
list ($url, $tag) = explode('/', $_SERVER['PATH_INFO']); list ($url, $tag) = explode('/', $_SERVER['PATH_INFO']);
//permissions //permissions
if (!$userservice->isLoggedOn() if (!$userservice->isLoggedOn() || (!$GLOBALS['enableCommonTagDescriptionEditedByAll'] && !$currentUser->isAdmin())) {
|| (!$GLOBALS['enableCommonTagDescriptionEditedByAll']
&& !$currentUser->isAdmin()
)
) {
$tplVars['error'] = T_('Permission denied.'); $tplVars['error'] = T_('Permission denied.');
$templateservice->loadTemplate('error.500.tpl', $tplVars); $templateservice->loadTemplate('error.500.tpl', $tplVars);
exit(); exit();

View File

@ -22,7 +22,7 @@
require_once 'www-header.php'; require_once 'www-header.php';
/* Service creation: only useful services are created */ /* Service creation: only useful services are created */
$tagservice = SemanticScuttle_Service_Factory :: get('Tag'); $tagservice = SemanticScuttle_Service_Factory :: get('Tag');
/* Managing all possible inputs */ /* Managing all possible inputs */
isset($_POST['confirm']) ? define('POST_CONFIRM', $_POST['confirm']): define('POST_CONFIRM', ''); isset($_POST['confirm']) ? define('POST_CONFIRM', $_POST['confirm']): define('POST_CONFIRM', '');
@ -36,33 +36,31 @@ $currentUser = $userservice->getCurrentObjectUser();
/* Managing path info */ /* Managing path info */
list ($url, $tag) = explode('/', $_SERVER['PATH_INFO']); list ($url, $tag) = explode('/', $_SERVER['PATH_INFO']);
$template = 'tagedit.tpl'; $template = 'tagedit.tpl';
//permissions //permissions
if(!$userservice->isLoggedOn()) { if (!$userservice->isLoggedOn()) {
$tplVars['error'] = T_('Permission denied.'); $tplVars['error'] = T_('Permission denied.');
$templateservice->loadTemplate('error.500.tpl', $tplVars); $templateservice->loadTemplate('error.500.tpl', $tplVars);
exit(); exit();
} }
if (POST_CONFIRM) { if (POST_CONFIRM) {
if ( strlen($tag)>0 && if (strlen($tag)>0 && $tagservice->updateDescription($tag, $currentUser->getId(), stripslashes(POST_DESCRIPTION))) {
$tagservice->updateDescription($tag, $currentUser->getId(), stripslashes(POST_DESCRIPTION)) $tplVars['msg'] = T_('Tag description updated');
) { header('Location: '. POST_REFERRER);
$tplVars['msg'] = T_('Tag description updated'); } else {
header('Location: '. POST_REFERRER); $tplVars['error'] = T_('Failed to update the tag description');
} else { $template = 'error.500.tpl';
$tplVars['error'] = T_('Failed to update the tag description'); }
$template = 'error.500.tpl';
}
} elseif (POST_CANCEL) { } elseif (POST_CANCEL) {
header('Location: '. POST_REFERRER); header('Location: '. POST_REFERRER);
} else { } else {
$tplVars['subtitle'] = T_('Edit Tag Description') .': '. $tag; $tplVars['subtitle'] = T_('Edit Tag Description') .': '. $tag;
$tplVars['formaction'] = $_SERVER['SCRIPT_NAME'] .'/'. $tag; $tplVars['formaction'] = $_SERVER['SCRIPT_NAME'] .'/'. $tag;
$tplVars['referrer'] = $_SERVER['HTTP_REFERER']; $tplVars['referrer'] = $_SERVER['HTTP_REFERER'];
$tplVars['tag'] = $tag; $tplVars['tag'] = $tag;
$tplVars['description'] = $tagservice->getDescription($tag, $currentUser->getId()); $tplVars['description'] = $tagservice->getDescription($tag, $currentUser->getId());
} }
$templateservice->loadTemplate($template, $tplVars); $templateservice->loadTemplate($template, $tplVars);
?> ?>

View File

@ -23,7 +23,7 @@ require_once 'www-header.php';
/* Service creation: only useful services are created */ /* Service creation: only useful services are created */
$b2tservice = SemanticScuttle_Service_Factory :: get('Bookmark2Tag'); $b2tservice = SemanticScuttle_Service_Factory :: get('Bookmark2Tag');
$tagservice = SemanticScuttle_Service_Factory :: get('Tag'); $tagservice = SemanticScuttle_Service_Factory :: get('Tag');
$tag2tagservice = SemanticScuttle_Service_Factory :: get('Tag2Tag'); $tag2tagservice = SemanticScuttle_Service_Factory :: get('Tag2Tag');
/* Managing all possible inputs */ /* Managing all possible inputs */
@ -37,42 +37,41 @@ $currentUser = $userservice->getCurrentObjectUser();
/* Managing path info */ /* Managing path info */
list ($url, $tag) = explode('/', $_SERVER['PATH_INFO']); list ($url, $tag) = explode('/', $_SERVER['PATH_INFO']);
//$tag = isset($_GET['query']) ? $_GET['query'] : NULL; //$tag = isset($_GET['query']) ? $_GET['query'] : null;
$template = 'tagrename.tpl'; $template = 'tagrename.tpl';
if (POST_CONFIRM) { if (POST_CONFIRM) {
if (trim(POST_OLD) != '') { if (trim(POST_OLD) != '') {
$old = trim(POST_OLD); $old = trim(POST_OLD);
} else { } else {
$old = NULL; $old = null;
} }
if (trim(POST_NEW) != '') { if (trim(POST_NEW) != '') {
$new = trim(POST_NEW); $new = trim(POST_NEW);
} else { } else {
$new = NULL; $new = null;
} }
if ( if (!is_null($old)
!is_null($old) && && !is_null($new)
!is_null($new) && && $tagservice->renameTag($currentUser->getId(), $old, $new)
$tagservice->renameTag($currentUser->getId(), $old, $new) && && $b2tservice->renameTag($currentUser->getId(), $old, $new)
$b2tservice->renameTag($currentUser->getId(), $old, $new) && && $tag2tagservice->renameTag($currentUser->getId(), $old, $new)
$tag2tagservice->renameTag($currentUser->getId(), $old, $new) ) {
) { $tplVars['msg'] = T_('Tag renamed');
$tplVars['msg'] = T_('Tag renamed'); header('Location: '. createURL('bookmarks', $currentUser->getUsername()));
header('Location: '. createURL('bookmarks', $currentUser->getUsername())); } else {
} else { $tplVars['error'] = T_('Failed to rename the tag');
$tplVars['error'] = T_('Failed to rename the tag'); $template = 'error.500.tpl';
$template = 'error.500.tpl'; }
}
} elseif (POST_CANCEL) { } elseif (POST_CANCEL) {
header('Location: '. createURL('bookmarks', $currentUser->getUsername() .'/'. $tags)); header('Location: '. createURL('bookmarks', $currentUser->getUsername() .'/'. $tags));
} else { } else {
$tplVars['subtitle'] = T_('Rename Tag') .': '. $tag; $tplVars['subtitle'] = T_('Rename Tag') .': '. $tag;
$tplVars['formaction'] = $_SERVER['SCRIPT_NAME'] .'/'. $tag; $tplVars['formaction'] = $_SERVER['SCRIPT_NAME'] .'/'. $tag;
$tplVars['referrer'] = $_SERVER['HTTP_REFERER']; $tplVars['referrer'] = $_SERVER['HTTP_REFERER'];
$tplVars['old'] = $tag; $tplVars['old'] = $tag;
} }
$templateservice->loadTemplate($template, $tplVars); $templateservice->loadTemplate($template, $tplVars);
?> ?>

View File

@ -22,8 +22,8 @@
require_once 'www-header.php'; require_once 'www-header.php';
/* Service creation: only useful services are created */ /* Service creation: only useful services are created */
$bookmarkservice =SemanticScuttle_Service_Factory::get('Bookmark'); $bookmarkservice = SemanticScuttle_Service_Factory::get('Bookmark');
$cacheservice =SemanticScuttle_Service_Factory::get('Cache'); $cacheservice = SemanticScuttle_Service_Factory::get('Cache');
/* Managing all possible inputs */ /* Managing all possible inputs */
isset($_GET['page']) ? define('GET_PAGE', $_GET['page']): define('GET_PAGE', 0); isset($_GET['page']) ? define('GET_PAGE', $_GET['page']): define('GET_PAGE', 0);
@ -35,49 +35,50 @@ $currentUser = $userservice->getCurrentObjectUser();
/* Managing path info */ /* Managing path info */
list($url, $cat) = explode('/', $_SERVER['PATH_INFO']); list($url, $cat) = explode('/', $_SERVER['PATH_INFO']);
if (!$cat) { if (!$cat) {
header('Location: '. createURL('populartags')); header('Location: '. createURL('populartags'));
exit; exit;
} }
$titleTags = explode('+', filter($cat)); $titleTags = explode('+', filter($cat));
$pagetitle = T_('Tags') .': '; $pagetitle = T_('Tags') .': ';
for($i = 0; $i<count($titleTags);$i++) { for ($i = 0; $i<count($titleTags);$i++) {
$pagetitle.= $titleTags[$i].'<a href="'.createUrl('tags', aggregateTags($titleTags, '+', $titleTags[$i])).'" title="'.T_('Remove the tag from the selection').'">*</a> + '; $pagetitle.= $titleTags[$i].'<a href="'.createUrl('tags', aggregateTags($titleTags, '+', $titleTags[$i])).'" title="'.T_('Remove the tag from the selection').'">*</a> + ';
} }
$pagetitle = substr($pagetitle, 0, strlen($pagetitle) - strlen(' + ')); $pagetitle = substr($pagetitle, 0, strlen($pagetitle) - strlen(' + '));
//$cattitle = str_replace('+', ' + ', $cat); //$cattitle = str_replace('+', ' + ', $cat);
if ($usecache) { if ($usecache) {
// Generate hash for caching on // Generate hash for caching on
if ($userservice->isLoggedOn()) { if ($userservice->isLoggedOn()) {
$hash = md5($_SERVER['REQUEST_URI'] . $currentUser->getId()); $hash = md5($_SERVER['REQUEST_URI'] . $currentUser->getId());
} else { } else {
$hash = md5($_SERVER['REQUEST_URI']); $hash = md5($_SERVER['REQUEST_URI']);
} }
// Cache for 30 minutes // Cache for 30 minutes
$cacheservice->Start($hash, 1800); $cacheservice->Start($hash, 1800);
} }
// Header variables // Header variables
$tplVars['pagetitle'] = T_('Tags') .': '. $cat; $tplVars['pagetitle'] = T_('Tags') .': '. $cat;
$tplVars['loadjs'] = true; $tplVars['loadjs'] = true;
$tplVars['rsschannels'] = array( $tplVars['rsschannels'] = array(
array(filter($sitename .': '. $pagetitle), createURL('rss', 'all/'. filter($cat, 'url')).'?sort='.getSortOrder()) array(
filter($sitename .': '. $pagetitle),
createURL('rss', 'all/'. filter($cat, 'url')).'?sort='.getSortOrder()
)
); );
// Pagination // Pagination
$perpage = getPerPageCount($currentUser); $perpage = getPerPageCount($currentUser);
if (intval(GET_PAGE) > 1) { if (intval(GET_PAGE) > 1) {
$page = intval(GET_PAGE); $page = intval(GET_PAGE);
$start = ($page - 1) * $perpage; $start = ($page - 1) * $perpage;
} else { } else {
$page = 0; $page = 0;
$start = 0; $start = 0;
} }
$tplVars['page'] = $page; $tplVars['page'] = $page;
@ -87,7 +88,7 @@ $tplVars['currenttag'] = $cat;
$tplVars['sidebar_blocks'] = array('linked', 'related', 'menu2');//array('linked', 'related', 'popular'); $tplVars['sidebar_blocks'] = array('linked', 'related', 'menu2');//array('linked', 'related', 'popular');
$tplVars['subtitle'] = $pagetitle; $tplVars['subtitle'] = $pagetitle;
$tplVars['bookmarkCount'] = $start + 1; $tplVars['bookmarkCount'] = $start + 1;
$bookmarks =& $bookmarkservice->getBookmarks($start, $perpage, NULL, $cat, NULL, getSortOrder()); $bookmarks =& $bookmarkservice->getBookmarks($start, $perpage, null, $cat, null, getSortOrder());
$tplVars['total'] = $bookmarks['total']; $tplVars['total'] = $bookmarks['total'];
$tplVars['bookmarks'] =& $bookmarks['bookmarks']; $tplVars['bookmarks'] =& $bookmarks['bookmarks'];
$tplVars['cat_url'] = createURL('bookmarks', '%1$s/%2$s'); $tplVars['cat_url'] = createURL('bookmarks', '%1$s/%2$s');
@ -96,8 +97,8 @@ $tplVars['nav_url'] = createURL('tags', '%2$s%3$s');
$templateservice->loadTemplate('bookmarks.tpl', $tplVars); $templateservice->loadTemplate('bookmarks.tpl', $tplVars);
if ($usecache) { if ($usecache) {
// Cache output if existing copy has expired // Cache output if existing copy has expired
$cacheservice->End($hash); $cacheservice->End($hash);
} }
?> ?>

View File

@ -35,7 +35,7 @@ exit();
// This part below will be executed once you comment the two lines above // This part below will be executed once you comment the two lines above
///////////////// /////////////////
require_once 'www-header.php'; require_once 'www-header.php';
$tagstatservice = SemanticScuttle_Service_Factory :: get('TagStat'); $tagstatservice = SemanticScuttle_Service_Factory :: get('TagStat');
?> ?>
<h1>Upgrade</h1> <h1>Upgrade</h1>
@ -51,11 +51,11 @@ $tagstatservice = SemanticScuttle_Service_Factory :: get('TagStat');
<li>3/ Complete the upgrade by clicking on the following link : <a href="upgrade.php?action=upgrade">upgrade</a></li> <li>3/ Complete the upgrade by clicking on the following link : <a href="upgrade.php?action=upgrade">upgrade</a></li>
</ul> </ul>
<?php <?php
if($_GET['action']=="upgrade") { if ($_GET['action']=="upgrade") {
// Update the stats // Update the stats
$tagstatservice->updateAllStat(); $tagstatservice->updateAllStat();
echo "Upgrade script executed: OK!<br/><br/>"; echo "Upgrade script executed: OK!<br/><br/>";
echo "For security reason, don't forget to uncomment back the first lines into \"upgrade.php\"<br/><br/>"; echo "For security reason, don't forget to uncomment back the first lines into \"upgrade.php\"<br/><br/>";
echo 'In case of problem during upgrade, please use our <a href="http://sourceforge.net/tracker/?group_id=211356&atid=1017431">sourceforge page</a> to inform us. Thank you.'; echo 'In case of problem during upgrade, please use our <a href="http://sourceforge.net/tracker/?group_id=211356&atid=1017431">sourceforge page</a> to inform us. Thank you.';
} }
?> ?>

View File

@ -22,8 +22,8 @@
require_once 'www-header.php'; require_once 'www-header.php';
/* Service creation: only useful services are created */ /* Service creation: only useful services are created */
$bookmarkservice =SemanticScuttle_Service_Factory::get('Bookmark'); $bookmarkservice = SemanticScuttle_Service_Factory::get('Bookmark');
$cacheservice =SemanticScuttle_Service_Factory::get('Cache'); $cacheservice = SemanticScuttle_Service_Factory::get('Cache');
/* Managing current logged user */ /* Managing current logged user */
$currentUser = $userservice->getCurrentObjectUser(); $currentUser = $userservice->getCurrentObjectUser();
@ -31,15 +31,15 @@ $currentUser = $userservice->getCurrentObjectUser();
$pagetitle = T_('Users'); $pagetitle = T_('Users');
if ($usecache) { if ($usecache) {
// Generate hash for caching on // Generate hash for caching on
if ($userservice->isLoggedOn()) { if ($userservice->isLoggedOn()) {
$hash = md5($_SERVER['REQUEST_URI'] . $currentUser->getId()); $hash = md5($_SERVER['REQUEST_URI'] . $currentUser->getId());
} else { } else {
$hash = md5($_SERVER['REQUEST_URI']); $hash = md5($_SERVER['REQUEST_URI']);
} }
// Cache for 30 minutes // Cache for 30 minutes
$cacheservice->Start($hash, 1800); $cacheservice->Start($hash, 1800);
} }
// Header variables // Header variables
@ -56,7 +56,7 @@ $tplVars['users'] =& $userservice->getUsers();
$templateservice->loadTemplate('users.tpl', $tplVars); $templateservice->loadTemplate('users.tpl', $tplVars);
if ($usecache) { if ($usecache) {
// Cache output if existing copy has expired // Cache output if existing copy has expired
$cacheservice->End($hash); $cacheservice->End($hash);
} }
?> ?>

View File

@ -28,34 +28,34 @@ isset($_POST['contact']) ? define('POST_CONTACT', $_POST['contact']): define('PO
isset($_GET['contact']) ? define('GET_CONTACT', $_GET['contact']): define('GET_CONTACT', ''); isset($_GET['contact']) ? define('GET_CONTACT', $_GET['contact']): define('GET_CONTACT', '');
/* Managing path info */ /* Managing path info */
@list($url, $user) = isset($_SERVER['PATH_INFO']) ? explode('/', $_SERVER['PATH_INFO']) : NULL; @list($url, $user) = isset($_SERVER['PATH_INFO']) ? explode('/', $_SERVER['PATH_INFO']) : null;
if($user=='' && POST_CONTACT != '') { if ($user=='' && POST_CONTACT != '') {
$user = POST_CONTACT; $user = POST_CONTACT;
} elseif($user=='' && GET_CONTACT != '') { } elseif ($user=='' && GET_CONTACT != '') {
$user = GET_CONTACT; $user = GET_CONTACT;
} }
if ($userservice->isLoggedOn() && $user) { if ($userservice->isLoggedOn() && $user) {
$pagetitle = ''; $pagetitle = '';
$userid = $userservice->getIdFromUser($user); $userid = $userservice->getIdFromUser($user);
if($userid == NULL) {
$tplVars['error'] = sprintf(T_('User with username %s was not found'), $user);
$templateservice->loadTemplate('error.404.tpl', $tplVars);
exit();
}
$watched = $userservice->getWatchStatus($userid, $currentUser->getId()); if ($userid == null) {
$changed = $userservice->setWatchStatus($userid); $tplVars['error'] = sprintf(T_('User with username %s was not found'), $user);
$templateservice->loadTemplate('error.404.tpl', $tplVars);
exit();
}
if ($watched) { $watched = $userservice->getWatchStatus($userid, $currentUser->getId());
$tplVars['msg'] = T_('User removed from your watchlist'); $changed = $userservice->setWatchStatus($userid);
} else {
$tplVars['msg'] = T_('User added to your watchlist');
}
header('Location: '. createURL('watchlist', $currentUser->getUsername())); if ($watched) {
$tplVars['msg'] = T_('User removed from your watchlist');
} else {
$tplVars['msg'] = T_('User added to your watchlist');
}
header('Location: '. createURL('watchlist', $currentUser->getUsername()));
} }
?> ?>

View File

@ -21,8 +21,8 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
require_once 'www-header.php'; require_once 'www-header.php';
/* Service creation: only useful services are created */ /* Service creation: only useful services are created */
$bookmarkservice =SemanticScuttle_Service_Factory::get('Bookmark'); $bookmarkservice = SemanticScuttle_Service_Factory::get('Bookmark');
$cacheservice =SemanticScuttle_Service_Factory::get('Cache'); $cacheservice = SemanticScuttle_Service_Factory::get('Cache');
/* Managing all possible inputs */ /* Managing all possible inputs */
isset($_GET['page']) ? define('GET_PAGE', $_GET['page']): define('GET_PAGE', 0); isset($_GET['page']) ? define('GET_PAGE', $_GET['page']): define('GET_PAGE', 0);
@ -32,7 +32,7 @@ isset($_GET['sort']) ? define('GET_SORT', $_GET['sort']): define('GET_SORT', '')
$currentUser = $userservice->getCurrentObjectUser(); $currentUser = $userservice->getCurrentObjectUser();
/* Managing path info */ /* Managing path info */
@list($url, $user, $page) = isset($_SERVER['PATH_INFO']) ? explode('/', $_SERVER['PATH_INFO']) : NULL; @list($url, $user, $page) = isset($_SERVER['PATH_INFO']) ? explode('/', $_SERVER['PATH_INFO']) : null;
if ($usecache) { if ($usecache) {
@ -55,8 +55,8 @@ if ($user) {
if (is_int($user)) { if (is_int($user)) {
$userid = intval($user); $userid = intval($user);
} else { } else {
$userinfo = $userservice->getObjectUserByUsername($user); $userinfo = $userservice->getObjectUserByUsername($user);
if ($userinfo == NULL ) { if ($userinfo == null ) {
// Throw a 404 error // Throw a 404 error
$tplVars['error'] = sprintf(T_('User with username %s was not found'), $user); $tplVars['error'] = sprintf(T_('User with username %s was not found'), $user);
$templateservice->loadTemplate('error.404.tpl', $tplVars); $templateservice->loadTemplate('error.404.tpl', $tplVars);
@ -91,7 +91,7 @@ if ($user) {
$tplVars['start'] = $start; $tplVars['start'] = $start;
$tplVars['bookmarkCount'] = $start + 1; $tplVars['bookmarkCount'] = $start + 1;
$bookmarks =& $bookmarkservice->getBookmarks($start, $perpage, $userid, NULL, NULL, getSortOrder(), true); $bookmarks =& $bookmarkservice->getBookmarks($start, $perpage, $userid, null, null, getSortOrder(), true);
$tplVars['sidebar_blocks'] = array('watchlist'); $tplVars['sidebar_blocks'] = array('watchlist');
$tplVars['watched'] = true; $tplVars['watched'] = true;

View File

@ -22,4 +22,4 @@ if ('@data_dir@' == '@' . 'data_dir@') {
//pear installation; files are in include path //pear installation; files are in include path
require_once 'SemanticScuttle/header.php'; require_once 'SemanticScuttle/header.php';
} }
?> ?>