git-svn-id: https://semanticscuttle.svn.sourceforge.net/svnroot/semanticscuttle/trunk@150 b3834d28-1941-0410-a4f8-b48e95affb8f
This commit is contained in:
parent
c35ab1bf2b
commit
a62b9742ee
5 changed files with 549 additions and 544 deletions
28
about.php
28
about.php
|
@ -1,22 +1,22 @@
|
||||||
<?php
|
<?php
|
||||||
/***************************************************************************
|
/***************************************************************************
|
||||||
Copyright (C) 2004, 2005 Scuttle project
|
Copyright (C) 2004, 2005 Scuttle project
|
||||||
http://sourceforge.net/projects/scuttle/
|
http://sourceforge.net/projects/scuttle/
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or modify
|
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
|
it under the terms of the GNU General Public License as published by
|
||||||
the Free Software Foundation; either version 2 of the License, or
|
the Free Software Foundation; either version 2 of the License, or
|
||||||
(at your option) any later version.
|
(at your option) any later version.
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
This program is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
GNU General Public License for more details.
|
GNU General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
along with this program; if not, write to the Free Software
|
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
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
|
|
||||||
require_once('header.inc.php');
|
require_once('header.inc.php');
|
||||||
$templateservice =& ServiceFactory::getServiceInstance('TemplateService');
|
$templateservice =& ServiceFactory::getServiceInstance('TemplateService');
|
||||||
|
|
|
@ -1,23 +1,23 @@
|
||||||
<?php
|
<?php
|
||||||
/***************************************************************************
|
/***************************************************************************
|
||||||
Copyright (C) 2005 - 2006 Scuttle project
|
Copyright (C) 2005 - 2006 Scuttle project
|
||||||
http://sourceforge.net/projects/scuttle/
|
http://sourceforge.net/projects/scuttle/
|
||||||
http://scuttle.org/
|
http://scuttle.org/
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or modify
|
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
|
it under the terms of the GNU General Public License as published by
|
||||||
the Free Software Foundation; either version 2 of the License, or
|
the Free Software Foundation; either version 2 of the License, or
|
||||||
(at your option) any later version.
|
(at your option) any later version.
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
This program is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
GNU General Public License for more details.
|
GNU General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
along with this program; if not, write to the Free Software
|
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
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
|
|
||||||
header('Content-Type: text/xml; charset=UTF-8');
|
header('Content-Type: text/xml; charset=UTF-8');
|
||||||
header("Last-Modified: ". gmdate("D, d M Y H:i:s") ." GMT");
|
header("Last-Modified: ". gmdate("D, d M Y H:i:s") ." GMT");
|
||||||
|
@ -26,41 +26,45 @@ header("Cache-Control: no-cache, must-revalidate");
|
||||||
require_once('header.inc.php');
|
require_once('header.inc.php');
|
||||||
|
|
||||||
function getTitle($url) {
|
function getTitle($url) {
|
||||||
$fd = @fopen($url, 'r');
|
$fd = @fopen($url, 'r');
|
||||||
if ($fd) {
|
if ($fd) {
|
||||||
$html = fread($fd, 1750);
|
$html = fread($fd, 1750);
|
||||||
fclose($fd);
|
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"?>';
|
||||||
?>
|
?>
|
||||||
<response>
|
<response>
|
||||||
<method>getTitle</method>
|
<method>
|
||||||
<result><?php echo getTitle($_GET['url']); ?></result>
|
getTitle
|
||||||
|
</method>
|
||||||
|
<result>
|
||||||
|
<?php echo getTitle($_GET['url']); ?>
|
||||||
|
</result>
|
||||||
</response>
|
</response>
|
68
index.php
68
index.php
|
@ -1,23 +1,23 @@
|
||||||
<?php
|
<?php
|
||||||
/***************************************************************************
|
/***************************************************************************
|
||||||
Copyright (C) 2004 - 2006 Scuttle project
|
Copyright (C) 2004 - 2006 Scuttle project
|
||||||
http://sourceforge.net/projects/scuttle/
|
http://sourceforge.net/projects/scuttle/
|
||||||
http://scuttle.org/
|
http://scuttle.org/
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or modify
|
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
|
it under the terms of the GNU General Public License as published by
|
||||||
the Free Software Foundation; either version 2 of the License, or
|
the Free Software Foundation; either version 2 of the License, or
|
||||||
(at your option) any later version.
|
(at your option) any later version.
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
This program is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
GNU General Public License for more details.
|
GNU General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
along with this program; if not, write to the Free Software
|
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
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
|
|
||||||
require_once('header.inc.php');
|
require_once('header.inc.php');
|
||||||
$bookmarkservice =& ServiceFactory::getServiceInstance('BookmarkService');
|
$bookmarkservice =& ServiceFactory::getServiceInstance('BookmarkService');
|
||||||
|
@ -27,38 +27,38 @@ $cacheservice =& ServiceFactory::getServiceInstance('CacheService');
|
||||||
|
|
||||||
$tplvars = array();
|
$tplvars = array();
|
||||||
if (isset($_GET['action'])){
|
if (isset($_GET['action'])){
|
||||||
if ($_GET['action'] == "logout") {
|
if ($_GET['action'] == "logout") {
|
||||||
$userservice->logout();
|
$userservice->logout();
|
||||||
$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(sprintf(T_('%s: Recent bookmarks'), $sitename), createURL('rss').'?sort='.getSortOrder())
|
||||||
);
|
);
|
||||||
|
|
||||||
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();
|
$perpage = getPerPageCount();
|
||||||
if (isset($_GET['page']) && intval($_GET['page']) > 1) {
|
if (isset($_GET['page']) && intval($_GET['page']) > 1) {
|
||||||
$page = $_GET['page'];
|
$page = $_GET['page'];
|
||||||
$start = ($page - 1) * $perpage;
|
$start = ($page - 1) * $perpage;
|
||||||
} else {
|
} else {
|
||||||
$page = 0;
|
$page = 0;
|
||||||
$start = 0;
|
$start = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
$dtend = date('Y-m-d H:i:s', strtotime('tomorrow'));
|
$dtend = date('Y-m-d H:i:s', strtotime('tomorrow'));
|
||||||
|
@ -84,7 +84,7 @@ $tplVars['pageName'] = PAGE_INDEX;
|
||||||
$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);
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
|
|
@ -1,468 +1,469 @@
|
||||||
<?php
|
<?php
|
||||||
class BookmarkService {
|
class BookmarkService {
|
||||||
var $db;
|
var $db;
|
||||||
var $tablename;
|
var $tablename;
|
||||||
|
|
||||||
function & getInstance(& $db) {
|
function & getInstance(& $db) {
|
||||||
static $instance;
|
static $instance;
|
||||||
if (!isset ($instance))
|
if (!isset ($instance))
|
||||||
$instance = & new BookmarkService($db);
|
$instance = & new BookmarkService($db);
|
||||||
return $instance;
|
return $instance;
|
||||||
}
|
|
||||||
|
|
||||||
function BookmarkService(& $db) {
|
|
||||||
$this->db = & $db;
|
|
||||||
$this->tablename = $GLOBALS['tableprefix'] .'bookmarks';
|
|
||||||
}
|
|
||||||
|
|
||||||
function _getbookmark($fieldname, $value, $all = false) {
|
|
||||||
if (!$all) {
|
|
||||||
$userservice = & ServiceFactory :: getServiceInstance('UserService');
|
|
||||||
$sId = $userservice->getCurrentUserId();
|
|
||||||
$range = ' AND uId = '. $sId;
|
|
||||||
}
|
|
||||||
|
|
||||||
$query = 'SELECT * FROM '. $this->getTableName() .' WHERE '. $fieldname .' = "'. $this->db->sql_escape($value) .'"'. $range;
|
|
||||||
|
|
||||||
if (!($dbresult = & $this->db->sql_query_limit($query, 1, 0))) {
|
|
||||||
message_die(GENERAL_ERROR, 'Could not get bookmark', '', __LINE__, __FILE__, $query, $this->db);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($row =& $this->db->sql_fetchrow($dbresult)) {
|
|
||||||
return $row;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function & getBookmark($bid, $include_tags = false) {
|
|
||||||
if (!is_numeric($bid))
|
|
||||||
return;
|
|
||||||
|
|
||||||
$sql = 'SELECT * FROM '. $this->getTableName() .' WHERE bId = '. $this->db->sql_escape($bid);
|
|
||||||
|
|
||||||
if (!($dbresult = & $this->db->sql_query($sql)))
|
|
||||||
message_die(GENERAL_ERROR, 'Could not get vars', '', __LINE__, __FILE__, $sql, $this->db);
|
|
||||||
|
|
||||||
if ($row = & $this->db->sql_fetchrow($dbresult)) {
|
|
||||||
if ($include_tags) {
|
|
||||||
$b2tservice = & ServiceFactory :: getServiceInstance('Bookmark2TagService');
|
|
||||||
$row['tags'] = $b2tservice->getTagsForBookmark($bid);
|
|
||||||
}
|
|
||||||
return $row;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function getBookmarkByAddress($address) {
|
|
||||||
$hash = md5($address);
|
|
||||||
return $this->getBookmarkByHash($hash);
|
|
||||||
}
|
|
||||||
|
|
||||||
function getBookmarkByHash($hash) {
|
|
||||||
return $this->_getbookmark('bHash', $hash, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
function editAllowed($bookmark) {
|
|
||||||
if (!is_numeric($bookmark) && (!is_array($bookmark) || !is_numeric($bookmark['bId'])))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if (!is_array($bookmark))
|
|
||||||
if (!($bookmark = $this->getBookmark($bookmark)))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
$userservice = & ServiceFactory :: getServiceInstance('UserService');
|
|
||||||
$userid = $userservice->getCurrentUserId();
|
|
||||||
if ($userservice->isAdmin($userid))
|
|
||||||
return true;
|
|
||||||
else
|
|
||||||
return ($bookmark['uId'] == $userid);
|
|
||||||
}
|
|
||||||
|
|
||||||
function bookmarkExists($address = false, $uid = NULL) {
|
|
||||||
if (!$address) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// If address doesn't contain ":", add "http://" as the default protocol
|
|
||||||
if (strpos($address, ':') === false) {
|
|
||||||
$address = 'http://'. $address;
|
|
||||||
}
|
|
||||||
|
|
||||||
$crit = array ('bHash' => md5($address));
|
|
||||||
if (isset ($uid)) {
|
|
||||||
$crit['uId'] = $uid;
|
|
||||||
}
|
|
||||||
|
|
||||||
$sql = 'SELECT COUNT(*) FROM '. $GLOBALS['tableprefix'] .'bookmarks 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);
|
|
||||||
}
|
|
||||||
return ($this->db->sql_fetchfield(0, 0) > 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Adds a bookmark to the database.
|
|
||||||
// Note that date is expected to be a string that's interpretable by strtotime().
|
|
||||||
function addBookmark($address, $title, $description, $status, $categories, $date = NULL, $fromApi = false, $fromImport = false, $sId = -1) {
|
|
||||||
if($sId == -1) {
|
|
||||||
$userservice = & ServiceFactory :: getServiceInstance('UserService');
|
|
||||||
$sId = $userservice->getCurrentUserId();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// If bookmark address doesn't contain ":", add "http://" to the start as a default protocol
|
function BookmarkService(& $db) {
|
||||||
if (strpos($address, ':') === false) {
|
$this->db = & $db;
|
||||||
$address = 'http://'. $address;
|
$this->tablename = $GLOBALS['tableprefix'] .'bookmarks';
|
||||||
}
|
|
||||||
if (substr($address, -1) == '/') {
|
|
||||||
$address = substr($address, 0, count($address)-2);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the client's IP address and the date; note that the date is in GMT.
|
function _getbookmark($fieldname, $value, $all = false) {
|
||||||
if (getenv('HTTP_CLIENT_IP'))
|
if (!$all) {
|
||||||
$ip = getenv('HTTP_CLIENT_IP');
|
$userservice = & ServiceFactory :: getServiceInstance('UserService');
|
||||||
else
|
$sId = $userservice->getCurrentUserId();
|
||||||
if (getenv('REMOTE_ADDR'))
|
$range = ' AND uId = '. $sId;
|
||||||
$ip = getenv('REMOTE_ADDR');
|
}
|
||||||
else
|
|
||||||
$ip = getenv('HTTP_X_FORWARDED_FOR');
|
|
||||||
|
|
||||||
// Note that if date is NULL, then it's added with a date and time of now, and if it's present,
|
$query = 'SELECT * FROM '. $this->getTableName() .' WHERE '. $fieldname .' = "'. $this->db->sql_escape($value) .'"'. $range;
|
||||||
// it's expected to be a string that's interpretable by strtotime().
|
|
||||||
if (is_null($date))
|
|
||||||
$time = time();
|
|
||||||
else
|
|
||||||
$time = strtotime($date);
|
|
||||||
$datetime = gmdate('Y-m-d H:i:s', $time);
|
|
||||||
|
|
||||||
// Set up the SQL insert statement and execute it.
|
if (!($dbresult = & $this->db->sql_query_limit($query, 1, 0))) {
|
||||||
$values = array('uId' => intval($sId), 'bIp' => $ip, 'bDatetime' => $datetime, 'bModified' => $datetime, 'bTitle' => $title, 'bAddress' => $address, 'bDescription' => $description, 'bStatus' => intval($status), 'bHash' => md5($address));
|
message_die(GENERAL_ERROR, 'Could not get bookmark', '', __LINE__, __FILE__, $query, $this->db);
|
||||||
$sql = 'INSERT INTO '. $this->getTableName() .' '. $this->db->sql_build_array('INSERT', $values);
|
return false;
|
||||||
$this->db->sql_transaction('begin');
|
}
|
||||||
if (!($dbresult = & $this->db->sql_query($sql))) {
|
|
||||||
$this->db->sql_transaction('rollback');
|
|
||||||
message_die(GENERAL_ERROR, 'Could not insert bookmark', '', __LINE__, __FILE__, $sql, $this->db);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
// Get the resultant row ID for the bookmark.
|
|
||||||
$bId = $this->db->sql_nextid($dbresult);
|
|
||||||
if (!isset($bId) || !is_int($bId)) {
|
|
||||||
$this->db->sql_transaction('rollback');
|
|
||||||
message_die(GENERAL_ERROR, 'Could not insert bookmark', '', __LINE__, __FILE__, $sql, $this->db);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
$uriparts = explode('.', $address);
|
if ($row =& $this->db->sql_fetchrow($dbresult)) {
|
||||||
$extension = end($uriparts);
|
return $row;
|
||||||
unset($uriparts);
|
} else {
|
||||||
|
return false;
|
||||||
$b2tservice = & ServiceFactory :: getServiceInstance('Bookmark2TagService');
|
}
|
||||||
if (!$b2tservice->attachTags($bId, $categories, $fromApi, $extension, false, $fromImport)) {
|
|
||||||
$this->db->sql_transaction('rollback');
|
|
||||||
message_die(GENERAL_ERROR, 'Could not insert bookmark', '', __LINE__, __FILE__, $sql, $this->db);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
$this->db->sql_transaction('commit');
|
|
||||||
// Everything worked out, so return the new bookmark's bId.
|
|
||||||
return $bId;
|
|
||||||
}
|
|
||||||
|
|
||||||
function updateBookmark($bId, $address, $title, $description, $status, $categories, $date = NULL, $fromApi = false) {
|
|
||||||
if (!is_numeric($bId))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
// Get the client's IP address and the date; note that the date is in GMT.
|
|
||||||
if (getenv('HTTP_CLIENT_IP'))
|
|
||||||
$ip = getenv('HTTP_CLIENT_IP');
|
|
||||||
else
|
|
||||||
if (getenv('REMOTE_ADDR'))
|
|
||||||
$ip = getenv('REMOTE_ADDR');
|
|
||||||
else
|
|
||||||
$ip = getenv('HTTP_X_FORWARDED_FOR');
|
|
||||||
|
|
||||||
$moddatetime = gmdate('Y-m-d H:i:s', time());
|
|
||||||
|
|
||||||
// Set up the SQL update statement and execute it.
|
|
||||||
$updates = array('bModified' => $moddatetime, 'bTitle' => $title, 'bAddress' => $address, 'bDescription' => $description, 'bStatus' => $status, 'bHash' => md5($address));
|
|
||||||
|
|
||||||
if (!is_null($date)) {
|
|
||||||
$datetime = gmdate('Y-m-d H:i:s', strtotime($date));
|
|
||||||
$updates[] = array('bDateTime' => $datetime);
|
|
||||||
}
|
|
||||||
|
|
||||||
$sql = 'UPDATE '. $GLOBALS['tableprefix'] .'bookmarks SET '. $this->db->sql_build_array('UPDATE', $updates) .' WHERE bId = '. intval($bId);
|
|
||||||
$this->db->sql_transaction('begin');
|
|
||||||
|
|
||||||
if (!($dbresult = & $this->db->sql_query($sql))) {
|
|
||||||
$this->db->sql_transaction('rollback');
|
|
||||||
message_die(GENERAL_ERROR, 'Could not update bookmark', '', __LINE__, __FILE__, $sql, $this->db);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
$uriparts = explode('.', $address);
|
|
||||||
$extension = end($uriparts);
|
|
||||||
unset($uriparts);
|
|
||||||
|
|
||||||
$b2tservice = & ServiceFactory :: getServiceInstance('Bookmark2TagService');
|
|
||||||
if (!$b2tservice->attachTags($bId, $categories, $fromApi, $extension)) {
|
|
||||||
$this->db->sql_transaction('rollback');
|
|
||||||
message_die(GENERAL_ERROR, 'Could not update bookmark', '', __LINE__, __FILE__, $sql, $this->db);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->db->sql_transaction('commit');
|
|
||||||
// Everything worked out, so return true.
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
function & getBookmarks($start = 0, $perpage = NULL, $user = NULL, $tags = NULL, $terms = NULL, $sortOrder = NULL, $watched = NULL, $startdate = NULL, $enddate = NULL, $hash = NULL) {
|
|
||||||
// Only get the bookmarks that are visible to the current user. Our rules:
|
|
||||||
// - if the $user is NULL, that means get bookmarks from ALL users, so we need to make
|
|
||||||
// sure to check the logged-in user's watchlist and get the contacts-only bookmarks from
|
|
||||||
// those users. If the user isn't logged-in, just get the public bookmarks.
|
|
||||||
// - if the $user is set and isn't the logged-in user, then get that user's bookmarks, and
|
|
||||||
// if that user is on the logged-in user's watchlist, get the public AND contacts-only
|
|
||||||
// bookmarks; otherwise, just get the public bookmarks.
|
|
||||||
// - if the $user is set and IS the logged-in user, then get all bookmarks.
|
|
||||||
$userservice =& ServiceFactory::getServiceInstance('UserService');
|
|
||||||
$b2tservice =& ServiceFactory::getServiceInstance('Bookmark2TagService');
|
|
||||||
$tag2tagservice =& ServiceFactory::getServiceInstance('Tag2TagService');
|
|
||||||
$sId = $userservice->getCurrentUserId();
|
|
||||||
|
|
||||||
if ($userservice->isLoggedOn()) {
|
|
||||||
// All public bookmarks, user's own bookmarks and any shared with user
|
|
||||||
$privacy = ' AND ((B.bStatus = 0) OR (B.uId = '. $sId .')';
|
|
||||||
$watchnames = $userservice->getWatchNames($sId, true);
|
|
||||||
foreach($watchnames as $watchuser) {
|
|
||||||
$privacy .= ' OR (U.username = "'. $watchuser .'" AND B.bStatus = 1)';
|
|
||||||
}
|
|
||||||
$privacy .= ')';
|
|
||||||
} else {
|
|
||||||
// Just public bookmarks
|
|
||||||
$privacy = ' AND B.bStatus = 0';
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set up the tags, if need be.
|
|
||||||
if (!is_array($tags) && !is_null($tags)) {
|
|
||||||
$tags = explode('+', trim($tags));
|
|
||||||
}
|
|
||||||
|
|
||||||
$tagcount = count($tags);
|
|
||||||
for ($i = 0; $i < $tagcount; $i ++) {
|
|
||||||
$tags[$i] = trim($tags[$i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set up the SQL query.
|
|
||||||
$query_1 = 'SELECT DISTINCT ';
|
|
||||||
if (SQL_LAYER == 'mysql4') {
|
|
||||||
$query_1 .= 'SQL_CALC_FOUND_ROWS ';
|
|
||||||
}
|
|
||||||
$query_1 .= 'B.*, U.'. $userservice->getFieldName('username');
|
|
||||||
|
|
||||||
$query_2 = ' FROM '. $userservice->getTableName() .' AS U, '. $this->getTableName() .' AS B';
|
|
||||||
|
|
||||||
$query_3 = ' WHERE B.uId = U.'. $userservice->getFieldName('primary') . $privacy;
|
|
||||||
if (is_null($watched)) {
|
|
||||||
if (!is_null($user)) {
|
|
||||||
$query_3 .= ' AND B.uId = '. $user;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$arrWatch = $userservice->getWatchlist($user);
|
|
||||||
if (count($arrWatch) > 0) {
|
|
||||||
foreach($arrWatch as $row) {
|
|
||||||
$query_3_1 .= 'B.uId = '. intval($row) .' OR ';
|
|
||||||
}
|
|
||||||
$query_3_1 = substr($query_3_1, 0, -3);
|
|
||||||
} else {
|
|
||||||
$query_3_1 = 'B.uId = -1';
|
|
||||||
}
|
|
||||||
$query_3 .= ' AND ('. $query_3_1 .') AND B.bStatus IN (0, 1)';
|
|
||||||
}
|
|
||||||
|
|
||||||
$query_5 = '';
|
|
||||||
if($hash == null) {
|
|
||||||
$query_5.= ' GROUP BY B.bHash';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
switch($sortOrder) {
|
function & getBookmark($bid, $include_tags = false) {
|
||||||
case 'date_asc':
|
if (!is_numeric($bid))
|
||||||
$query_5.= ' ORDER BY B.bDatetime ASC ';
|
return;
|
||||||
break;
|
|
||||||
case 'title_desc':
|
|
||||||
$query_5.= ' ORDER BY B.bTitle DESC ';
|
|
||||||
break;
|
|
||||||
case 'title_asc':
|
|
||||||
$query_5.= ' ORDER BY B.bTitle ASC ';
|
|
||||||
break;
|
|
||||||
case 'url_desc':
|
|
||||||
$query_5.= ' ORDER BY B.bAddress DESC ';
|
|
||||||
break;
|
|
||||||
case 'url_asc':
|
|
||||||
$query_5.= ' ORDER BY B.bAddress ASC ';
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
$query_5.= ' ORDER BY B.bDatetime DESC ';
|
|
||||||
}
|
|
||||||
|
|
||||||
// Handle the parts of the query that depend on any tags that are present.
|
$sql = 'SELECT * FROM '. $this->getTableName() .' WHERE bId = '. $this->db->sql_escape($bid);
|
||||||
$query_4 = '';
|
|
||||||
for ($i = 0; $i < $tagcount; $i ++) {
|
|
||||||
$query_2 .= ', '. $b2tservice->getTableName() .' AS T'. $i;
|
|
||||||
$query_4 .= ' AND (';
|
|
||||||
|
|
||||||
$allLinkedTags = $tag2tagservice->getAllLinkedTags($this->db->sql_escape($tags[$i]), '>', $user);
|
if (!($dbresult = & $this->db->sql_query($sql)))
|
||||||
|
message_die(GENERAL_ERROR, 'Could not get vars', '', __LINE__, __FILE__, $sql, $this->db);
|
||||||
|
|
||||||
while (is_array($allLinkedTags) && count($allLinkedTags)>0) {
|
if ($row = & $this->db->sql_fetchrow($dbresult)) {
|
||||||
$query_4 .= ' T'. $i .'.tag = "'. array_pop($allLinkedTags) .'"';
|
if ($include_tags) {
|
||||||
$query_4 .= ' OR';
|
$b2tservice = & ServiceFactory :: getServiceInstance('Bookmark2TagService');
|
||||||
}
|
$row['tags'] = $b2tservice->getTagsForBookmark($bid);
|
||||||
|
}
|
||||||
|
return $row;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$query_4 .= ' T'. $i .'.tag = "'. $this->db->sql_escape($tags[$i]) .'"';
|
function getBookmarkByAddress($address) {
|
||||||
|
$hash = md5($address);
|
||||||
|
return $this->getBookmarkByHash($hash);
|
||||||
|
}
|
||||||
|
|
||||||
$query_4 .= ') AND T'. $i .'.bId = B.bId';
|
function getBookmarkByHash($hash) {
|
||||||
//die($query_4);
|
return $this->_getbookmark('bHash', $hash, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Search terms
|
function editAllowed($bookmark) {
|
||||||
if ($terms) {
|
if (!is_numeric($bookmark) && (!is_array($bookmark) || !is_numeric($bookmark['bId'])))
|
||||||
// Multiple search terms okay
|
return false;
|
||||||
$aTerms = explode(' ', $terms);
|
|
||||||
$aTerms = array_map('trim', $aTerms);
|
|
||||||
|
|
||||||
// Search terms in tags as well when none given
|
if (!is_array($bookmark))
|
||||||
if (!count($tags)) {
|
if (!($bookmark = $this->getBookmark($bookmark)))
|
||||||
$query_2 .= ' LEFT JOIN '. $b2tservice->getTableName() .' AS T ON B.bId = T.bId';
|
return false;
|
||||||
$dotags = true;
|
|
||||||
} else {
|
|
||||||
$dotags = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
$query_4 = '';
|
$userservice = & ServiceFactory :: getServiceInstance('UserService');
|
||||||
for ($i = 0; $i < count($aTerms); $i++) {
|
$userid = $userservice->getCurrentUserId();
|
||||||
$query_4 .= ' AND (B.bTitle LIKE "%'. $this->db->sql_escape($aTerms[$i]) .'%"';
|
if ($userservice->isAdmin($userid))
|
||||||
$query_4 .= ' OR B.bDescription LIKE "%'. $this->db->sql_escape($aTerms[$i]) .'%"';
|
return true;
|
||||||
if ($dotags) {
|
else
|
||||||
$query_4 .= ' OR T.tag = "'. $this->db->sql_escape($aTerms[$i]) .'"';
|
return ($bookmark['uId'] == $userid);
|
||||||
}
|
}
|
||||||
$query_4 .= ')';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Start and end dates
|
function bookmarkExists($address = false, $uid = NULL) {
|
||||||
if ($startdate) {
|
if (!$address) {
|
||||||
$query_4 .= ' AND B.bDatetime > "'. $startdate .'"';
|
return;
|
||||||
}
|
}
|
||||||
if ($enddate) {
|
|
||||||
$query_4 .= ' AND B.bDatetime < "'. $enddate .'"';
|
|
||||||
}
|
|
||||||
|
|
||||||
// Hash
|
// If address doesn't contain ":", add "http://" as the default protocol
|
||||||
if ($hash) {
|
if (strpos($address, ':') === false) {
|
||||||
$query_4 .= ' AND B.bHash = "'. $hash .'"';
|
$address = 'http://'. $address;
|
||||||
}
|
}
|
||||||
$query = $query_1 . $query_2 . $query_3 . $query_4 . $query_5;
|
|
||||||
//die($query);
|
|
||||||
if (!($dbresult = & $this->db->sql_query_limit($query, intval($perpage), intval($start)))) {
|
|
||||||
message_die(GENERAL_ERROR, 'Could not get bookmarks', '', __LINE__, __FILE__, $query, $this->db);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (SQL_LAYER == 'mysql4') {
|
$crit = array ('bHash' => md5($address));
|
||||||
$totalquery = 'SELECT FOUND_ROWS() AS total';
|
if (isset ($uid)) {
|
||||||
} else {
|
$crit['uId'] = $uid;
|
||||||
if ($hash) {
|
}
|
||||||
$totalquery = 'SELECT COUNT(*) AS total'. $query_2 . $query_3 . $query_4;
|
|
||||||
} else {
|
|
||||||
$totalquery = 'SELECT COUNT(DISTINCT bAddress) AS total'. $query_2 . $query_3 . $query_4;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!($totalresult = & $this->db->sql_query($totalquery)) || (!($row = & $this->db->sql_fetchrow($totalresult)))) {
|
$sql = 'SELECT COUNT(*) FROM '. $GLOBALS['tableprefix'] .'bookmarks WHERE '. $this->db->sql_build_array('SELECT', $crit);
|
||||||
message_die(GENERAL_ERROR, 'Could not get total bookmarks', '', __LINE__, __FILE__, $totalquery, $this->db);
|
if (!($dbresult = & $this->db->sql_query($sql))) {
|
||||||
return false;
|
message_die(GENERAL_ERROR, 'Could not get vars', '', __LINE__, __FILE__, $sql, $this->db);
|
||||||
}
|
}
|
||||||
|
return ($this->db->sql_fetchfield(0, 0) > 0);
|
||||||
|
}
|
||||||
|
|
||||||
$total = $row['total'];
|
// Adds a bookmark to the database.
|
||||||
|
// Note that date is expected to be a string that's interpretable by strtotime().
|
||||||
|
function addBookmark($address, $title, $description, $status, $categories, $date = NULL, $fromApi = false, $fromImport = false, $sId = -1) {
|
||||||
|
if($sId == -1) {
|
||||||
|
$userservice = & ServiceFactory :: getServiceInstance('UserService');
|
||||||
|
$sId = $userservice->getCurrentUserId();
|
||||||
|
}
|
||||||
|
|
||||||
$bookmarks = array();
|
// If bookmark address doesn't contain ":", add "http://" to the start as a default protocol
|
||||||
while ($row = & $this->db->sql_fetchrow($dbresult)) {
|
if (strpos($address, ':') === false) {
|
||||||
$row['tags'] = $b2tservice->getTagsForBookmark(intval($row['bId']));
|
$address = 'http://'. $address;
|
||||||
$bookmarks[] = $row;
|
}
|
||||||
}
|
if (substr($address, -1) == '/') {
|
||||||
|
$address = substr($address, 0, count($address)-2);
|
||||||
|
}
|
||||||
|
|
||||||
$output = array ('bookmarks' => $bookmarks, 'total' => $total);
|
// Get the client's IP address and the date; note that the date is in GMT.
|
||||||
return $output;
|
if (getenv('HTTP_CLIENT_IP'))
|
||||||
}
|
$ip = getenv('HTTP_CLIENT_IP');
|
||||||
|
else
|
||||||
|
if (getenv('REMOTE_ADDR'))
|
||||||
|
$ip = getenv('REMOTE_ADDR');
|
||||||
|
else
|
||||||
|
$ip = getenv('HTTP_X_FORWARDED_FOR');
|
||||||
|
|
||||||
function deleteBookmark($bookmarkid) {
|
// Note that if date is NULL, then it's added with a date and time of now, and if it's present,
|
||||||
$query = 'DELETE FROM '. $GLOBALS['tableprefix'] .'bookmarks WHERE bId = '. intval($bookmarkid);
|
// it's expected to be a string that's interpretable by strtotime().
|
||||||
$this->db->sql_transaction('begin');
|
if (is_null($date))
|
||||||
if (!($dbresult = & $this->db->sql_query($query))) {
|
$time = time();
|
||||||
$this->db->sql_transaction('rollback');
|
else
|
||||||
message_die(GENERAL_ERROR, 'Could not delete bookmarks', '', __LINE__, __FILE__, $query, $this->db);
|
$time = strtotime($date);
|
||||||
return false;
|
$datetime = gmdate('Y-m-d H:i:s', $time);
|
||||||
}
|
|
||||||
|
|
||||||
$query = 'DELETE FROM '. $GLOBALS['tableprefix'] .'tags WHERE bId = '. intval($bookmarkid);
|
// Set up the SQL insert statement and execute it.
|
||||||
$this->db->sql_transaction('begin');
|
$values = array('uId' => intval($sId), 'bIp' => $ip, 'bDatetime' => $datetime, 'bModified' => $datetime, 'bTitle' => $title, 'bAddress' => $address, 'bDescription' => $description, 'bStatus' => intval($status), 'bHash' => md5($address));
|
||||||
if (!($dbresult = & $this->db->sql_query($query))) {
|
$sql = 'INSERT INTO '. $this->getTableName() .' '. $this->db->sql_build_array('INSERT', $values);
|
||||||
$this->db->sql_transaction('rollback');
|
$this->db->sql_transaction('begin');
|
||||||
message_die(GENERAL_ERROR, 'Could not delete bookmarks', '', __LINE__, __FILE__, $query, $this->db);
|
if (!($dbresult = & $this->db->sql_query($sql))) {
|
||||||
return false;
|
$this->db->sql_transaction('rollback');
|
||||||
}
|
message_die(GENERAL_ERROR, 'Could not insert bookmark', '', __LINE__, __FILE__, $sql, $this->db);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// Get the resultant row ID for the bookmark.
|
||||||
|
$bId = $this->db->sql_nextid($dbresult);
|
||||||
|
if (!isset($bId) || !is_int($bId)) {
|
||||||
|
$this->db->sql_transaction('rollback');
|
||||||
|
message_die(GENERAL_ERROR, 'Could not insert bookmark', '', __LINE__, __FILE__, $sql, $this->db);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
$this->db->sql_transaction('commit');
|
$uriparts = explode('.', $address);
|
||||||
return true;
|
$extension = end($uriparts);
|
||||||
}
|
unset($uriparts);
|
||||||
|
|
||||||
function deleteBookmarksForUser($uId) {
|
$b2tservice = & ServiceFactory :: getServiceInstance('Bookmark2TagService');
|
||||||
$query = 'DELETE FROM '. $GLOBALS['tableprefix'] .'bookmarks WHERE uId = '. intval($uId);
|
if (!$b2tservice->attachTags($bId, $categories, $fromApi, $extension, false, $fromImport)) {
|
||||||
|
$this->db->sql_transaction('rollback');
|
||||||
|
message_die(GENERAL_ERROR, 'Could not insert bookmark', '', __LINE__, __FILE__, $sql, $this->db);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$this->db->sql_transaction('commit');
|
||||||
|
// Everything worked out, so return the new bookmark's bId.
|
||||||
|
return $bId;
|
||||||
|
}
|
||||||
|
|
||||||
if (!($dbresult = & $this->db->sql_query($query))) {
|
function updateBookmark($bId, $address, $title, $description, $status, $categories, $date = NULL, $fromApi = false) {
|
||||||
message_die(GENERAL_ERROR, 'Could not delete bookmarks', '', __LINE__, __FILE__, $query, $this->db);
|
if (!is_numeric($bId))
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
// Get the client's IP address and the date; note that the date is in GMT.
|
||||||
}
|
if (getenv('HTTP_CLIENT_IP'))
|
||||||
|
$ip = getenv('HTTP_CLIENT_IP');
|
||||||
|
else
|
||||||
|
if (getenv('REMOTE_ADDR'))
|
||||||
|
$ip = getenv('REMOTE_ADDR');
|
||||||
|
else
|
||||||
|
$ip = getenv('HTTP_X_FORWARDED_FOR');
|
||||||
|
|
||||||
function countOthers($address) {
|
$moddatetime = gmdate('Y-m-d H:i:s', time());
|
||||||
if (!$address) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
$userservice = & ServiceFactory :: getServiceInstance('UserService');
|
// Set up the SQL update statement and execute it.
|
||||||
$sId = $userservice->getCurrentUserId();
|
$updates = array('bModified' => $moddatetime, 'bTitle' => $title, 'bAddress' => $address, 'bDescription' => $description, 'bStatus' => $status, 'bHash' => md5($address));
|
||||||
|
|
||||||
if ($userservice->isLoggedOn()) {
|
if (!is_null($date)) {
|
||||||
// All public bookmarks, user's own bookmarks and any shared with user
|
$datetime = gmdate('Y-m-d H:i:s', strtotime($date));
|
||||||
$privacy = ' AND ((B.bStatus = 0) OR (B.uId = '. $sId .')';
|
$updates[] = array('bDateTime' => $datetime);
|
||||||
$watchnames = $userservice->getWatchNames($sId, true);
|
}
|
||||||
foreach($watchnames as $watchuser) {
|
|
||||||
$privacy .= ' OR (U.username = "'. $watchuser .'" AND B.bStatus = 1)';
|
|
||||||
}
|
|
||||||
$privacy .= ')';
|
|
||||||
} else {
|
|
||||||
// Just public bookmarks
|
|
||||||
$privacy = ' AND B.bStatus = 0';
|
|
||||||
}
|
|
||||||
|
|
||||||
$sql = 'SELECT COUNT(*) FROM '. $userservice->getTableName() .' AS U, '. $GLOBALS['tableprefix'] .'bookmarks AS B WHERE U.'. $userservice->getFieldName('primary') .' = B.uId AND B.bHash = "'. md5($address) .'"'. $privacy;
|
$sql = 'UPDATE '. $GLOBALS['tableprefix'] .'bookmarks SET '. $this->db->sql_build_array('UPDATE', $updates) .' WHERE bId = '. intval($bId);
|
||||||
if (!($dbresult = & $this->db->sql_query($sql))) {
|
$this->db->sql_transaction('begin');
|
||||||
message_die(GENERAL_ERROR, 'Could not get vars', '', __LINE__, __FILE__, $sql, $this->db);
|
|
||||||
}
|
|
||||||
return $this->db->sql_fetchfield(0, 0) - 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
function deleteAll() {
|
if (!($dbresult = & $this->db->sql_query($sql))) {
|
||||||
$query = 'TRUNCATE TABLE `'. $this->getTableName() .'`';
|
$this->db->sql_transaction('rollback');
|
||||||
$this->db->sql_query($query);
|
message_die(GENERAL_ERROR, 'Could not update bookmark', '', __LINE__, __FILE__, $sql, $this->db);
|
||||||
}
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// Properties
|
$uriparts = explode('.', $address);
|
||||||
function getTableName() { return $this->tablename; }
|
$extension = end($uriparts);
|
||||||
function setTableName($value) { $this->tablename = $value; }
|
unset($uriparts);
|
||||||
|
|
||||||
|
$b2tservice = & ServiceFactory :: getServiceInstance('Bookmark2TagService');
|
||||||
|
if (!$b2tservice->attachTags($bId, $categories, $fromApi, $extension)) {
|
||||||
|
$this->db->sql_transaction('rollback');
|
||||||
|
message_die(GENERAL_ERROR, 'Could not update bookmark', '', __LINE__, __FILE__, $sql, $this->db);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->db->sql_transaction('commit');
|
||||||
|
// Everything worked out, so return true.
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
function & getBookmarks($start = 0, $perpage = NULL, $user = NULL, $tags = NULL, $terms = NULL, $sortOrder = NULL, $watched = NULL, $startdate = NULL, $enddate = NULL, $hash = NULL) {
|
||||||
|
// Only get the bookmarks that are visible to the current user. Our rules:
|
||||||
|
// - if the $user is NULL, that means get bookmarks from ALL users, so we need to make
|
||||||
|
// sure to check the logged-in user's watchlist and get the contacts-only bookmarks from
|
||||||
|
// those users. If the user isn't logged-in, just get the public bookmarks.
|
||||||
|
// - if the $user is set and isn't the logged-in user, then get that user's bookmarks, and
|
||||||
|
// if that user is on the logged-in user's watchlist, get the public AND contacts-only
|
||||||
|
// bookmarks; otherwise, just get the public bookmarks.
|
||||||
|
// - if the $user is set and IS the logged-in user, then get all bookmarks.
|
||||||
|
|
||||||
|
$userservice =& ServiceFactory::getServiceInstance('UserService');
|
||||||
|
$b2tservice =& ServiceFactory::getServiceInstance('Bookmark2TagService');
|
||||||
|
$tag2tagservice =& ServiceFactory::getServiceInstance('Tag2TagService');
|
||||||
|
$sId = $userservice->getCurrentUserId();
|
||||||
|
|
||||||
|
if ($userservice->isLoggedOn()) {
|
||||||
|
// All public bookmarks, user's own bookmarks and any shared with user
|
||||||
|
$privacy = ' AND ((B.bStatus = 0) OR (B.uId = '. $sId .')';
|
||||||
|
$watchnames = $userservice->getWatchNames($sId, true);
|
||||||
|
foreach($watchnames as $watchuser) {
|
||||||
|
$privacy .= ' OR (U.username = "'. $watchuser .'" AND B.bStatus = 1)';
|
||||||
|
}
|
||||||
|
$privacy .= ')';
|
||||||
|
} else {
|
||||||
|
// Just public bookmarks
|
||||||
|
$privacy = ' AND B.bStatus = 0';
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set up the tags, if need be.
|
||||||
|
if (!is_array($tags) && !is_null($tags)) {
|
||||||
|
$tags = explode('+', trim($tags));
|
||||||
|
}
|
||||||
|
|
||||||
|
$tagcount = count($tags);
|
||||||
|
for ($i = 0; $i < $tagcount; $i ++) {
|
||||||
|
$tags[$i] = trim($tags[$i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set up the SQL query.
|
||||||
|
$query_1 = 'SELECT DISTINCT ';
|
||||||
|
if (SQL_LAYER == 'mysql4') {
|
||||||
|
$query_1 .= 'SQL_CALC_FOUND_ROWS ';
|
||||||
|
}
|
||||||
|
$query_1 .= 'B.*, U.'. $userservice->getFieldName('username');
|
||||||
|
|
||||||
|
$query_2 = ' FROM '. $userservice->getTableName() .' AS U, '. $this->getTableName() .' AS B';
|
||||||
|
|
||||||
|
$query_3 = ' WHERE B.uId = U.'. $userservice->getFieldName('primary') . $privacy;
|
||||||
|
if (is_null($watched)) {
|
||||||
|
if (!is_null($user)) {
|
||||||
|
$query_3 .= ' AND B.uId = '. $user;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$arrWatch = $userservice->getWatchlist($user);
|
||||||
|
if (count($arrWatch) > 0) {
|
||||||
|
foreach($arrWatch as $row) {
|
||||||
|
$query_3_1 .= 'B.uId = '. intval($row) .' OR ';
|
||||||
|
}
|
||||||
|
$query_3_1 = substr($query_3_1, 0, -3);
|
||||||
|
} else {
|
||||||
|
$query_3_1 = 'B.uId = -1';
|
||||||
|
}
|
||||||
|
$query_3 .= ' AND ('. $query_3_1 .') AND B.bStatus IN (0, 1)';
|
||||||
|
}
|
||||||
|
|
||||||
|
$query_5 = '';
|
||||||
|
if($hash == null) {
|
||||||
|
$query_5.= ' GROUP BY B.bHash';
|
||||||
|
}
|
||||||
|
|
||||||
|
switch($sortOrder) {
|
||||||
|
case 'date_asc':
|
||||||
|
$query_5.= ' ORDER BY B.bDatetime ASC ';
|
||||||
|
break;
|
||||||
|
case 'title_desc':
|
||||||
|
$query_5.= ' ORDER BY B.bTitle DESC ';
|
||||||
|
break;
|
||||||
|
case 'title_asc':
|
||||||
|
$query_5.= ' ORDER BY B.bTitle ASC ';
|
||||||
|
break;
|
||||||
|
case 'url_desc':
|
||||||
|
$query_5.= ' ORDER BY B.bAddress DESC ';
|
||||||
|
break;
|
||||||
|
case 'url_asc':
|
||||||
|
$query_5.= ' ORDER BY B.bAddress ASC ';
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
$query_5.= ' ORDER BY B.bDatetime DESC ';
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handle the parts of the query that depend on any tags that are present.
|
||||||
|
$query_4 = '';
|
||||||
|
for ($i = 0; $i < $tagcount; $i ++) {
|
||||||
|
$query_2 .= ', '. $b2tservice->getTableName() .' AS T'. $i;
|
||||||
|
$query_4 .= ' AND (';
|
||||||
|
|
||||||
|
$allLinkedTags = $tag2tagservice->getAllLinkedTags($this->db->sql_escape($tags[$i]), '>', $user);
|
||||||
|
|
||||||
|
while (is_array($allLinkedTags) && count($allLinkedTags)>0) {
|
||||||
|
$query_4 .= ' T'. $i .'.tag = "'. array_pop($allLinkedTags) .'"';
|
||||||
|
$query_4 .= ' OR';
|
||||||
|
}
|
||||||
|
|
||||||
|
$query_4 .= ' T'. $i .'.tag = "'. $this->db->sql_escape($tags[$i]) .'"';
|
||||||
|
|
||||||
|
$query_4 .= ') AND T'. $i .'.bId = B.bId';
|
||||||
|
//die($query_4);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Search terms
|
||||||
|
if ($terms) {
|
||||||
|
// Multiple search terms okay
|
||||||
|
$aTerms = explode(' ', $terms);
|
||||||
|
$aTerms = array_map('trim', $aTerms);
|
||||||
|
|
||||||
|
// Search terms in tags as well when none given
|
||||||
|
if (!count($tags)) {
|
||||||
|
$query_2 .= ' LEFT JOIN '. $b2tservice->getTableName() .' AS T ON B.bId = T.bId';
|
||||||
|
$dotags = true;
|
||||||
|
} else {
|
||||||
|
$dotags = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$query_4 = '';
|
||||||
|
for ($i = 0; $i < count($aTerms); $i++) {
|
||||||
|
$query_4 .= ' AND (B.bTitle LIKE "%'. $this->db->sql_escape($aTerms[$i]) .'%"';
|
||||||
|
$query_4 .= ' OR B.bDescription LIKE "%'. $this->db->sql_escape($aTerms[$i]) .'%"';
|
||||||
|
if ($dotags) {
|
||||||
|
$query_4 .= ' OR T.tag = "'. $this->db->sql_escape($aTerms[$i]) .'"';
|
||||||
|
}
|
||||||
|
$query_4 .= ')';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Start and end dates
|
||||||
|
if ($startdate) {
|
||||||
|
$query_4 .= ' AND B.bDatetime > "'. $startdate .'"';
|
||||||
|
}
|
||||||
|
if ($enddate) {
|
||||||
|
$query_4 .= ' AND B.bDatetime < "'. $enddate .'"';
|
||||||
|
}
|
||||||
|
|
||||||
|
// Hash
|
||||||
|
if ($hash) {
|
||||||
|
$query_4 .= ' AND B.bHash = "'. $hash .'"';
|
||||||
|
}
|
||||||
|
$query = $query_1 . $query_2 . $query_3 . $query_4 . $query_5;
|
||||||
|
//die($query);
|
||||||
|
if (!($dbresult = & $this->db->sql_query_limit($query, intval($perpage), intval($start)))) {
|
||||||
|
message_die(GENERAL_ERROR, 'Could not get bookmarks', '', __LINE__, __FILE__, $query, $this->db);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (SQL_LAYER == 'mysql4') {
|
||||||
|
$totalquery = 'SELECT FOUND_ROWS() AS total';
|
||||||
|
} else {
|
||||||
|
if ($hash) {
|
||||||
|
$totalquery = 'SELECT COUNT(*) AS total'. $query_2 . $query_3 . $query_4;
|
||||||
|
} else {
|
||||||
|
$totalquery = 'SELECT COUNT(DISTINCT bAddress) AS total'. $query_2 . $query_3 . $query_4;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!($totalresult = & $this->db->sql_query($totalquery)) || (!($row = & $this->db->sql_fetchrow($totalresult)))) {
|
||||||
|
message_die(GENERAL_ERROR, 'Could not get total bookmarks', '', __LINE__, __FILE__, $totalquery, $this->db);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$total = $row['total'];
|
||||||
|
|
||||||
|
$bookmarks = array();
|
||||||
|
while ($row = & $this->db->sql_fetchrow($dbresult)) {
|
||||||
|
$row['tags'] = $b2tservice->getTagsForBookmark(intval($row['bId']));
|
||||||
|
$bookmarks[] = $row;
|
||||||
|
}
|
||||||
|
|
||||||
|
$output = array ('bookmarks' => $bookmarks, 'total' => $total);
|
||||||
|
return $output;
|
||||||
|
}
|
||||||
|
|
||||||
|
function deleteBookmark($bookmarkid) {
|
||||||
|
$query = 'DELETE FROM '. $GLOBALS['tableprefix'] .'bookmarks WHERE bId = '. intval($bookmarkid);
|
||||||
|
$this->db->sql_transaction('begin');
|
||||||
|
if (!($dbresult = & $this->db->sql_query($query))) {
|
||||||
|
$this->db->sql_transaction('rollback');
|
||||||
|
message_die(GENERAL_ERROR, 'Could not delete bookmarks', '', __LINE__, __FILE__, $query, $this->db);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$query = 'DELETE FROM '. $GLOBALS['tableprefix'] .'tags WHERE bId = '. intval($bookmarkid);
|
||||||
|
$this->db->sql_transaction('begin');
|
||||||
|
if (!($dbresult = & $this->db->sql_query($query))) {
|
||||||
|
$this->db->sql_transaction('rollback');
|
||||||
|
message_die(GENERAL_ERROR, 'Could not delete bookmarks', '', __LINE__, __FILE__, $query, $this->db);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->db->sql_transaction('commit');
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
function deleteBookmarksForUser($uId) {
|
||||||
|
$query = 'DELETE FROM '. $GLOBALS['tableprefix'] .'bookmarks WHERE uId = '. intval($uId);
|
||||||
|
|
||||||
|
if (!($dbresult = & $this->db->sql_query($query))) {
|
||||||
|
message_die(GENERAL_ERROR, 'Could not delete bookmarks', '', __LINE__, __FILE__, $query, $this->db);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
function countOthers($address) {
|
||||||
|
if (!$address) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$userservice = & ServiceFactory :: getServiceInstance('UserService');
|
||||||
|
$sId = $userservice->getCurrentUserId();
|
||||||
|
|
||||||
|
if ($userservice->isLoggedOn()) {
|
||||||
|
// All public bookmarks, user's own bookmarks and any shared with user
|
||||||
|
$privacy = ' AND ((B.bStatus = 0) OR (B.uId = '. $sId .')';
|
||||||
|
$watchnames = $userservice->getWatchNames($sId, true);
|
||||||
|
foreach($watchnames as $watchuser) {
|
||||||
|
$privacy .= ' OR (U.username = "'. $watchuser .'" AND B.bStatus = 1)';
|
||||||
|
}
|
||||||
|
$privacy .= ')';
|
||||||
|
} else {
|
||||||
|
// Just public bookmarks
|
||||||
|
$privacy = ' AND B.bStatus = 0';
|
||||||
|
}
|
||||||
|
|
||||||
|
$sql = 'SELECT COUNT(*) FROM '. $userservice->getTableName() .' AS U, '. $GLOBALS['tableprefix'] .'bookmarks AS B WHERE U.'. $userservice->getFieldName('primary') .' = B.uId AND B.bHash = "'. md5($address) .'"'. $privacy;
|
||||||
|
if (!($dbresult = & $this->db->sql_query($sql))) {
|
||||||
|
message_die(GENERAL_ERROR, 'Could not get vars', '', __LINE__, __FILE__, $sql, $this->db);
|
||||||
|
}
|
||||||
|
return $this->db->sql_fetchfield(0, 0) - 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
function deleteAll() {
|
||||||
|
$query = 'TRUNCATE TABLE `'. $this->getTableName() .'`';
|
||||||
|
$this->db->sql_query($query);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Properties
|
||||||
|
function getTableName() { return $this->tablename; }
|
||||||
|
function setTableName($value) { $this->tablename = $value; }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
50
users.php
50
users.php
|
@ -1,23 +1,23 @@
|
||||||
<?php
|
<?php
|
||||||
/***************************************************************************
|
/***************************************************************************
|
||||||
Copyright (C) 2004 - 2006 Scuttle project
|
Copyright (C) 2004 - 2006 Scuttle project
|
||||||
http://sourceforge.net/projects/scuttle/
|
http://sourceforge.net/projects/scuttle/
|
||||||
http://scuttle.org/
|
http://scuttle.org/
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or modify
|
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
|
it under the terms of the GNU General Public License as published by
|
||||||
the Free Software Foundation; either version 2 of the License, or
|
the Free Software Foundation; either version 2 of the License, or
|
||||||
(at your option) any later version.
|
(at your option) any later version.
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
This program is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
GNU General Public License for more details.
|
GNU General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
along with this program; if not, write to the Free Software
|
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
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
|
|
||||||
require_once('header.inc.php');
|
require_once('header.inc.php');
|
||||||
|
|
||||||
|
@ -33,15 +33,15 @@ list($url, $cat) = explode('/', $_SERVER['PATH_INFO']);
|
||||||
$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'] . $userservice->getCurrentUserID());
|
$hash = md5($_SERVER['REQUEST_URI'] . $userservice->getCurrentUserID());
|
||||||
} 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
|
||||||
|
@ -58,7 +58,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);
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
|
Loading…
Reference in a new issue