Minor refactoring: introduce user as an object.
git-svn-id: https://semanticscuttle.svn.sourceforge.net/svnroot/semanticscuttle/trunk@172 b3834d28-1941-0410-a4f8-b48e95affb8f
This commit is contained in:
parent
49dec69230
commit
9aafe7551e
3 changed files with 590 additions and 553 deletions
|
@ -13,7 +13,6 @@ if(DEBUG_MODE) {
|
||||||
ini_set('display_errors', '1');
|
ini_set('display_errors', '1');
|
||||||
ini_set('mysql.trace_mode', '1');
|
ini_set('mysql.trace_mode', '1');
|
||||||
error_reporting(E_ALL);
|
error_reporting(E_ALL);
|
||||||
//error_reporting(E_ALL^E_NOTICE);
|
|
||||||
} else {
|
} else {
|
||||||
ini_set('display_errors', '0');
|
ini_set('display_errors', '0');
|
||||||
ini_set('mysql.trace_mode', '0');
|
ini_set('mysql.trace_mode', '0');
|
||||||
|
|
|
@ -1,6 +1,15 @@
|
||||||
<?php
|
<?php
|
||||||
class UserService {
|
class UserService {
|
||||||
var $db;
|
var $db;
|
||||||
|
var $fields = array(
|
||||||
|
'primary' => 'uId',
|
||||||
|
'username' => 'username',
|
||||||
|
'password' => 'password');
|
||||||
|
var $profileurl;
|
||||||
|
var $tablename;
|
||||||
|
var $sessionkey;
|
||||||
|
var $cookiekey;
|
||||||
|
var $cookietime = 1209600; // 2 weeks
|
||||||
|
|
||||||
function &getInstance(&$db) {
|
function &getInstance(&$db) {
|
||||||
static $instance;
|
static $instance;
|
||||||
|
@ -9,17 +18,6 @@ class UserService {
|
||||||
return $instance;
|
return $instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
var $fields = array(
|
|
||||||
'primary' => 'uId',
|
|
||||||
'username' => 'username',
|
|
||||||
'password' => 'password'
|
|
||||||
);
|
|
||||||
var $profileurl;
|
|
||||||
var $tablename;
|
|
||||||
var $sessionkey;
|
|
||||||
var $cookiekey;
|
|
||||||
var $cookietime = 1209600; // 2 weeks
|
|
||||||
|
|
||||||
function UserService(& $db) {
|
function UserService(& $db) {
|
||||||
$this->db =& $db;
|
$this->db =& $db;
|
||||||
$this->tablename = $GLOBALS['tableprefix'] .'users';
|
$this->tablename = $GLOBALS['tableprefix'] .'users';
|
||||||
|
@ -115,15 +113,21 @@ class UserService {
|
||||||
return $this->_getuser($this->getFieldName('primary'), $id);
|
return $this->_getuser($this->getFieldName('primary'), $id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Momentary useful in order to go to object code
|
||||||
|
function getObjectUser($id) {
|
||||||
|
$user = $this->_getuser($this->getFieldName('primary'), $id);
|
||||||
|
return new User($id, $user[$this->getFieldName('username')]);
|
||||||
|
}
|
||||||
|
|
||||||
function isLoggedOn() {
|
function isLoggedOn() {
|
||||||
return ($this->getCurrentUserId() !== false);
|
return ($this->getCurrentUserId() !== false);
|
||||||
}
|
}
|
||||||
|
|
||||||
function &getCurrentUser($refresh = FALSE, $newval = NULL) {
|
function &getCurrentUser($refresh = FALSE, $newval = NULL) {
|
||||||
static $currentuser;
|
static $currentuser;
|
||||||
if (!is_null($newval)) //internal use only: reset currentuser
|
if (!is_null($newval)) { //internal use only: reset currentuser
|
||||||
$currentuser = $newval;
|
$currentuser = $newval;
|
||||||
else if ($refresh || !isset($currentuser)) {
|
} else if ($refresh || !isset($currentuser)) {
|
||||||
if ($id = $this->getCurrentUserId()) {
|
if ($id = $this->getCurrentUserId()) {
|
||||||
$currentuser = $this->getUser($id);
|
$currentuser = $this->getUser($id);
|
||||||
} else {
|
} else {
|
||||||
|
@ -133,6 +137,21 @@ class UserService {
|
||||||
return $currentuser;
|
return $currentuser;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Momentary useful in order to go to object code
|
||||||
|
function getCurrentObjectUser($refresh = FALSE, $newval = NULL) {
|
||||||
|
static $currentObjectUser;
|
||||||
|
if (!is_null($newval)) { //internal use only: reset currentuser
|
||||||
|
$currentObjectUser = $newval;
|
||||||
|
} else if ($refresh || !isset($currentObjectUser)) {
|
||||||
|
if ($id = $this->getCurrentUserId()) {
|
||||||
|
$currentObjectUser = $this->getObjectUser($id);
|
||||||
|
} else {
|
||||||
|
$currentObjectUser = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $currentObjectUser;
|
||||||
|
}
|
||||||
|
|
||||||
function isAdmin($userid) {
|
function isAdmin($userid) {
|
||||||
$user = $this->getUser($userid);
|
$user = $this->getUser($userid);
|
||||||
|
|
||||||
|
@ -144,13 +163,11 @@ class UserService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* return current user id based on session or cookie */
|
||||||
function getCurrentUserId() {
|
function getCurrentUserId() {
|
||||||
if (isset($_SESSION[$this->getSessionKey()])) {
|
if (isset($_SESSION[$this->getSessionKey()])) {
|
||||||
//echo "session";die($_SESSION[$this->getSessionKey()]);
|
|
||||||
return $_SESSION[$this->getSessionKey()];
|
return $_SESSION[$this->getSessionKey()];
|
||||||
} else if (isset($_COOKIE[$this->getCookieKey()])) {
|
} else if (isset($_COOKIE[$this->getCookieKey()])) {
|
||||||
//echo "cookie";die();
|
|
||||||
|
|
||||||
$cook = split(':', $_COOKIE[$this->getCookieKey()]);
|
$cook = split(':', $_COOKIE[$this->getCookieKey()]);
|
||||||
//cookie looks like this: 'id:md5(username+password)'
|
//cookie looks like this: 'id:md5(username+password)'
|
||||||
$query = 'SELECT * FROM '. $this->getTableName() .
|
$query = 'SELECT * FROM '. $this->getTableName() .
|
||||||
|
@ -428,4 +445,33 @@ class UserService {
|
||||||
function getCookieKey() { return $this->cookiekey; }
|
function getCookieKey() { return $this->cookiekey; }
|
||||||
function setCookieKey($value) { $this->cookiekey = $value; }
|
function setCookieKey($value) { $this->cookiekey = $value; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class User {
|
||||||
|
|
||||||
|
var $id;
|
||||||
|
var $username;
|
||||||
|
var $isAdmin;
|
||||||
|
|
||||||
|
function User($id, $username) {
|
||||||
|
$this->id = $id;
|
||||||
|
$this->username = $username;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getId() {
|
||||||
|
return $this->id;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getUsername() {
|
||||||
|
return $this->username;
|
||||||
|
}
|
||||||
|
|
||||||
|
function isAdmin() {
|
||||||
|
// Look for value if not already set
|
||||||
|
if(!isset($this->isAdmin)) {
|
||||||
|
$userservice =& ServiceFactory::getServiceInstance('UserService');
|
||||||
|
$this->isAdmin = $userservice->isAdmin($this->id);
|
||||||
|
}
|
||||||
|
return $this->isAdmin;
|
||||||
|
}
|
||||||
|
}
|
||||||
?>
|
?>
|
||||||
|
|
|
@ -8,9 +8,13 @@ $cdservice =& ServiceFactory::getServiceInstance('CommonDescriptionService');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$logged_on_userid = $userservice->getCurrentUserId();
|
//$logged_on_userid = $userservice->getCurrentUserId();
|
||||||
$currentUser = $userservice->getCurrentUser();
|
//$currentUser = $userservice->getCurrentUser();
|
||||||
$currentUsername = $currentUser[$userservice->getFieldName('username')];
|
//$currentUsername = $currentUser[$userservice->getFieldName('username')];
|
||||||
|
|
||||||
|
// Momentary useful to go to object code
|
||||||
|
$currentObjectUser = $userservice->getCurrentObjectUser();
|
||||||
|
|
||||||
$pageName = isset($pageName)?$pageName:"";
|
$pageName = isset($pageName)?$pageName:"";
|
||||||
|
|
||||||
$this->includeTemplate($GLOBALS['top_include']);
|
$this->includeTemplate($GLOBALS['top_include']);
|
||||||
|
@ -26,9 +30,7 @@ include('search.inc.php');
|
||||||
<?php
|
<?php
|
||||||
if((isset($currenttag) && $GLOBALS['enableCommonTagDescription'])
|
if((isset($currenttag) && $GLOBALS['enableCommonTagDescription'])
|
||||||
|| (isset($hash) && $GLOBALS['enableCommonBookmarkDescription'])):?>
|
|| (isset($hash) && $GLOBALS['enableCommonBookmarkDescription'])):?>
|
||||||
<p class="commondescription">
|
<p class="commondescription"><?php
|
||||||
|
|
||||||
<?php
|
|
||||||
if(isset($currenttag) && $cdservice->getLastTagDescription($currenttag)) {
|
if(isset($currenttag) && $cdservice->getLastTagDescription($currenttag)) {
|
||||||
$description = $cdservice->getLastTagDescription($currenttag);
|
$description = $cdservice->getLastTagDescription($currenttag);
|
||||||
echo nl2br(filter($description['cdDescription']));
|
echo nl2br(filter($description['cdDescription']));
|
||||||
|
@ -38,7 +40,7 @@ if(isset($currenttag) && $cdservice->getLastTagDescription($currenttag)) {
|
||||||
echo nl2br(filter($description['cdDescription'])). "<br/>";
|
echo nl2br(filter($description['cdDescription'])). "<br/>";
|
||||||
}
|
}
|
||||||
|
|
||||||
if($logged_on_userid>0) {
|
if($userservice->isLoggedOn()) {
|
||||||
if(isset($currenttag)) {
|
if(isset($currenttag)) {
|
||||||
echo ' (<a href="'. createURL('tagcommondescriptionedit', $currenttag).'">';
|
echo ' (<a href="'. createURL('tagcommondescriptionedit', $currenttag).'">';
|
||||||
echo T_('edit common description').'</a>)';
|
echo T_('edit common description').'</a>)';
|
||||||
|
@ -47,8 +49,7 @@ if($logged_on_userid>0) {
|
||||||
echo T_('edit common description').'</a>)';
|
echo T_('edit common description').'</a>)';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
?>
|
?></p>
|
||||||
</p>
|
|
||||||
<?php endif ?>
|
<?php endif ?>
|
||||||
|
|
||||||
|
|
||||||
|
@ -58,12 +59,10 @@ if(isset($currenttag) && isset($user)) {
|
||||||
$userObject = $userservice->getUserByUsername($user);
|
$userObject = $userservice->getUserByUsername($user);
|
||||||
if($tagservice->getDescription($currenttag, $userObject['uId'])) { ?>
|
if($tagservice->getDescription($currenttag, $userObject['uId'])) { ?>
|
||||||
|
|
||||||
<p class="commondescription">
|
<p class="commondescription"><?php
|
||||||
<?php
|
|
||||||
$description = $tagservice->getDescription($currenttag, $userObject['uId']);
|
$description = $tagservice->getDescription($currenttag, $userObject['uId']);
|
||||||
echo nl2br(filter($description['tDescription']));
|
echo nl2br(filter($description['tDescription']));
|
||||||
?>
|
?></p>
|
||||||
</p>
|
|
||||||
|
|
||||||
<?php
|
<?php
|
||||||
}
|
}
|
||||||
|
@ -75,44 +74,38 @@ if(isset($currenttag) && isset($user)) {
|
||||||
window.onload = playerLoad;
|
window.onload = playerLoad;
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<p id="sort">
|
<p id="sort"><?php echo $total.' '.T_("bookmark(s)"); ?> - <?php echo T_("Sort by:"); ?>
|
||||||
<?php echo $total.' '.T_("bookmark(s)"); ?> -
|
|
||||||
<?php echo T_("Sort by:"); ?>
|
|
||||||
<?php
|
<?php
|
||||||
$dateSort = (getSortOrder()=='date_desc')? 'date_asc':'date_desc';
|
$dateSort = (getSortOrder()=='date_desc')? 'date_asc':'date_desc';
|
||||||
$titleSort = (getSortOrder()=='title_asc')? 'title_desc':'title_asc';
|
$titleSort = (getSortOrder()=='title_asc')? 'title_desc':'title_asc';
|
||||||
$urlSort = (getSortOrder()=='url_asc')? 'url_desc':'url_asc';
|
$urlSort = (getSortOrder()=='url_asc')? 'url_desc':'url_asc';
|
||||||
?>
|
?> <a href="?sort=<?php echo $dateSort ?>"><?php echo T_("Date"); ?></a><span>
|
||||||
<a href="?sort=<?php echo $dateSort ?>"><?php echo T_("Date"); ?></a><span> / </span>
|
/ </span> <a href="?sort=<?php echo $titleSort ?>"><?php echo T_("Title"); ?></a><span>
|
||||||
<a href="?sort=<?php echo $titleSort ?>"><?php echo T_("Title"); ?></a><span> / </span>
|
/ </span> <?php
|
||||||
<?php
|
|
||||||
if (!isset($hash)) {
|
if (!isset($hash)) {
|
||||||
?>
|
?> <a href="?sort=<?php echo $urlSort ?>"><?php echo T_("URL"); ?></a>
|
||||||
<a href="?sort=<?php echo $urlSort ?>"><?php echo T_("URL"); ?></a>
|
|
||||||
<?php
|
<?php
|
||||||
}
|
}
|
||||||
?>
|
?> <?php
|
||||||
|
|
||||||
<?php
|
|
||||||
if(isset($currenttag)) {
|
if(isset($currenttag)) {
|
||||||
if(isset($user)) {
|
if(isset($user)) {
|
||||||
echo ' - ';
|
echo ' - ';
|
||||||
echo '<a href="'. createURL('tags', $currenttag) .'">';
|
echo '<a href="'. createURL('tags', $currenttag) .'">';
|
||||||
echo T_('Bookmarks from other users for this tag').'</a>';
|
echo T_('Bookmarks from other users for this tag').'</a>';
|
||||||
//echo T_(' for these tags');
|
//echo T_(' for these tags');
|
||||||
} else if($logged_on_userid>0){
|
} else if($userservice->isLoggedOn()){
|
||||||
echo ' - ';
|
echo ' - ';
|
||||||
echo '<a href="'. createURL('bookmarks', $currentUsername.'/'.$currenttag) .'">';
|
echo '<a href="'. createURL('bookmarks', $currentObjectUser->getUsername().'/'.$currenttag) .'">';
|
||||||
echo T_('Only your bookmarks for this tag').'</a>';
|
echo T_('Only your bookmarks for this tag').'</a>';
|
||||||
//echo T_(' for these tags');
|
//echo T_(' for these tags');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
?>
|
?></p>
|
||||||
</p>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<ol<?php echo ($start > 0 ? ' start="'. ++$start .'"' : ''); ?> id="bookmarks">
|
<ol <?php echo ($start > 0 ? ' start="'. ++$start .'"' : ''); ?>
|
||||||
|
id="bookmarks">
|
||||||
|
|
||||||
<?php
|
<?php
|
||||||
foreach(array_keys($bookmarks) as $key) {
|
foreach(array_keys($bookmarks) as $key) {
|
||||||
|
@ -172,11 +165,10 @@ window.onload = playerLoad;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Copy link
|
// Copy link
|
||||||
if ($userservice->isLoggedOn() && ($logged_on_userid != $row['uId']) && !$bookmarkservice->bookmarkExists($row['bAddress'], $logged_on_userid)) {
|
if ($userservice->isLoggedOn()
|
||||||
// Get the username of the current user
|
&& ($currentObjectUser->getId() != $row['uId'])
|
||||||
$currentUser = $userservice->getCurrentUser();
|
&& !$bookmarkservice->bookmarkExists($row['bAddress'], $currentObjectUser->getId())) {
|
||||||
$currentUsername = $currentUser[$userservice->getFieldName('username')];
|
$copy .= ' - <a href="'. createURL('bookmarks', $currentObjectUser->getUsername() .'?action=add&address='. urlencode($row['bAddress']) .'&title='. urlencode($row['bTitle'])). '&description='.urlencode($row['bDescription']). '&tags='.$tagsForCopy .'">'. T_('Copy') .'</a>';
|
||||||
$copy .= ' - <a href="'. createURL('bookmarks', $currentUsername .'?action=add&address='. urlencode($row['bAddress']) .'&title='. urlencode($row['bTitle'])). '&description='.urlencode($row['bDescription']). '&tags='.$tagsForCopy .'">'. T_('Copy') .'</a>';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Nofollow option
|
// Nofollow option
|
||||||
|
|
Loading…
Reference in a new issue