diff options
Diffstat (limited to 'src/SemanticScuttle/Service')
| -rw-r--r-- | src/SemanticScuttle/Service/Bookmark.php | 62 | ||||
| -rw-r--r-- | src/SemanticScuttle/Service/Bookmark2Tag.php (renamed from src/SemanticScuttle/Service/Bookmark2tag.php) | 83 | ||||
| -rw-r--r-- | src/SemanticScuttle/Service/Cache.php | 29 | ||||
| -rw-r--r-- | src/SemanticScuttle/Service/CommonDescription.php | 24 | ||||
| -rw-r--r-- | src/SemanticScuttle/Service/Factory.php | 20 | ||||
| -rw-r--r-- | src/SemanticScuttle/Service/SearchHistory.php | 24 | ||||
| -rw-r--r-- | src/SemanticScuttle/Service/Tag.php | 24 | ||||
| -rw-r--r-- | src/SemanticScuttle/Service/Tag2Tag.php (renamed from src/SemanticScuttle/Service/Tag2tag.php) | 43 | ||||
| -rw-r--r-- | src/SemanticScuttle/Service/TagCache.php | 54 | ||||
| -rw-r--r-- | src/SemanticScuttle/Service/TagStat.php | 31 | ||||
| -rw-r--r-- | src/SemanticScuttle/Service/Template.php | 23 | ||||
| -rw-r--r-- | src/SemanticScuttle/Service/User.php | 111 | 
12 files changed, 325 insertions, 203 deletions
| diff --git a/src/SemanticScuttle/Service/Bookmark.php b/src/SemanticScuttle/Service/Bookmark.php index f119593..6075a0d 100644 --- a/src/SemanticScuttle/Service/Bookmark.php +++ b/src/SemanticScuttle/Service/Bookmark.php @@ -1,23 +1,33 @@  <?php -class BookmarkService { -	var $db; +class SemanticScuttle_Service_Bookmark extends SemanticScuttle_Service +{  	var $tablename; -	function & getInstance(& $db) { +    /** +     * Returns the single service instance +     * +     * @param DB $db Database object +     * +     * @return SemanticScuttle_Service +     */ +	public static function getInstance($db) +    {  		static $instance; -		if (!isset ($instance)) -		$instance = & new BookmarkService($db); +		if (!isset($instance)) { +            $instance = new self($db); +        }  		return $instance;  	} -	function BookmarkService(& $db) { -		$this->db = & $db; +	public function __construct($db) +    { +		$this->db = $db;  		$this->tablename = $GLOBALS['tableprefix'] .'bookmarks';  	}  	function _getbookmark($fieldname, $value, $all = false) {  		if (!$all) { -			$userservice = & ServiceFactory :: getServiceInstance('UserService'); +			$userservice = SemanticScuttle_Service_Factory :: getServiceInstance('User');  			$sId = $userservice->getCurrentUserId();  			$range = ' AND uId = '. $sId;  		} else { @@ -51,7 +61,7 @@ class BookmarkService {  		if ($row = & $this->db->sql_fetchrow($dbresult)) {  			if ($include_tags) { -				$b2tservice = & ServiceFactory :: getServiceInstance('Bookmark2TagService'); +				$b2tservice = SemanticScuttle_Service_Factory :: getServiceInstance('Bookmark2Tag');  				$row['tags'] = $b2tservice->getTagsForBookmark($bid);  			}  			$output = $row;			 @@ -118,7 +128,7 @@ class BookmarkService {  			return false;  		} -		$userservice = & ServiceFactory::getServiceInstance('UserService'); +		$userservice = SemanticScuttle_Service_Factory::getServiceInstance('User');  		$user = $userservice->getCurrentUser();  		//user has to be either admin, or owner @@ -160,7 +170,7 @@ class BookmarkService {  	// Note that date is expected to be a string that's interpretable by strtotime().  	function addBookmark($address, $title, $description, $privateNote, $status, $categories, $date = NULL, $fromApi = false, $fromImport = false, $sId = -1) {  		if($sId == -1) { -			$userservice = & ServiceFactory :: getServiceInstance('UserService'); +			$userservice = SemanticScuttle_Service_Factory :: getServiceInstance('User');  			$sId = $userservice->getCurrentUserId();  		} @@ -204,7 +214,7 @@ class BookmarkService {  		$extension = end($uriparts);  		unset($uriparts); -		$b2tservice = & ServiceFactory :: getServiceInstance('Bookmark2TagService'); +		$b2tservice = SemanticScuttle_Service_Factory :: getServiceInstance('Bookmark2Tag');  		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); @@ -260,7 +270,7 @@ class BookmarkService {  		$extension = end($uriparts);  		unset($uriparts); -		$b2tservice = & ServiceFactory :: getServiceInstance('Bookmark2TagService'); +		$b2tservice = SemanticScuttle_Service_Factory :: getServiceInstance('Bookmark2Tag');  		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); @@ -282,9 +292,9 @@ class BookmarkService {  		//    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'); +		$userservice =SemanticScuttle_Service_Factory::getServiceInstance('User'); +		$b2tservice =SemanticScuttle_Service_Factory::getServiceInstance('Bookmark2Tag'); +		$tag2tagservice =SemanticScuttle_Service_Factory::getServiceInstance('Tag2Tag');  		$sId = $userservice->getCurrentUserId();  		if ($userservice->isLoggedOn()) { @@ -480,15 +490,15 @@ class BookmarkService {  		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 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) { @@ -496,7 +506,7 @@ class BookmarkService {  			return false;  		} -		$userservice = & ServiceFactory :: getServiceInstance('UserService'); +		$userservice = SemanticScuttle_Service_Factory :: getServiceInstance('User');  		$sId = $userservice->getCurrentUserId();  		if ($userservice->isLoggedOn()) { diff --git a/src/SemanticScuttle/Service/Bookmark2tag.php b/src/SemanticScuttle/Service/Bookmark2Tag.php index 918fb5b..bd3f3af 100644 --- a/src/SemanticScuttle/Service/Bookmark2tag.php +++ b/src/SemanticScuttle/Service/Bookmark2Tag.php @@ -1,17 +1,28 @@  <?php -class Bookmark2TagService { -	var $db; +class SemanticScuttle_Service_Bookmark2Tag extends SemanticScuttle_Service +{  	var $tablename; -	function &getInstance(&$db) { + +    /** +     * Returns the single service instance +     * +     * @param DB $db Database object +     * +     * @return SemanticScuttle_Service +     */ +	public static function getInstance($db) +    {  		static $instance; -		if (!isset($instance)) -		$instance =& new Bookmark2TagService($db); +		if (!isset($instance)) { +            $instance = new self($db); +        }  		return $instance;  	} -	function Bookmark2TagService(&$db) { -		$this->db =& $db; +	public function __construct($db) +    { +		$this->db = $db;  		$this->tablename = $GLOBALS['tableprefix'] .'bookmarks2tags';  	} @@ -42,7 +53,7 @@ class Bookmark2TagService {  			}  		} -		$tagservice =& ServiceFactory::getServiceInstance('TagService'); +		$tagservice =SemanticScuttle_Service_Factory::getServiceInstance('Tag');  		$tags = $tagservice->normalize($tags); @@ -51,7 +62,7 @@ class Bookmark2TagService {  		for ($i = 0; $i < $tags_count; $i++) {  			$tags[$i] = trim(strtolower($tags[$i]));  			if ($fromApi) { -				include_once(dirname(__FILE__) .'/../functions.inc.php'); +				include_once 'SemanticScuttle/functions.php';  				$tags[$i] = convertTag($tags[$i], 'in');  			}  		} @@ -70,7 +81,7 @@ class Bookmark2TagService {  		// Media and file types  		if (!is_null($extension)) { -			include_once(dirname(__FILE__) .'/../functions.inc.php'); +			include_once 'SemanticScuttle/functions.php';  			if ($keys = multi_array_search($extension, $GLOBALS['filetypes'])) {  				$tags[] = 'system:filetype:'. $extension; @@ -93,8 +104,8 @@ class Bookmark2TagService {  			}  		} -		$bs =& ServiceFactory::getServiceInstance('BookmarkService'); -		$tts =& ServiceFactory::getServiceInstance('Tag2TagService'); +		$bs =SemanticScuttle_Service_Factory::getServiceInstance('Bookmark'); +		$tts =SemanticScuttle_Service_Factory::getServiceInstance('Tag2Tag');  		// Create links between tags  		foreach($tags as $key => $tag) { @@ -150,7 +161,7 @@ class Bookmark2TagService {  	}  	function deleteTag($uId, $tag) { -		$bs =& ServiceFactory::getServiceInstance('BookmarkService'); +		$bs =SemanticScuttle_Service_Factory::getServiceInstance('Bookmark');  		$query = 'DELETE FROM '. $this->getTableName();  		$query.= ' USING '. $this->getTableName() .', '. $bs->getTableName(); @@ -183,23 +194,23 @@ class Bookmark2TagService {  	}  	/* Allow deletion in admin page */ -	function deleteTagsForUser($uId) {
 -		$qmask = 'DELETE FROM %s USING %s, %s WHERE %s.bId = %s.bId AND %s.uId = %d';
 -		$query = sprintf($qmask,
 -		$this->getTableName(),
 -		$this->getTableName(),
 -		$GLOBALS['tableprefix'].'bookmarks',
 -		$this->getTableName(),
 -		$GLOBALS['tableprefix'].'bookmarks',
 -		$GLOBALS['tableprefix'].'bookmarks',
 -		$uId);
 -
 -		if (!($dbresult =& $this->db->sql_query($query))) {
 -			message_die(GENERAL_ERROR, 'Could not delete tags', '', __LINE__, __FILE__, $query, $this->db);
 -			return false;
 -		}
 -
 -		return true;
 +	function deleteTagsForUser($uId) { +		$qmask = 'DELETE FROM %s USING %s, %s WHERE %s.bId = %s.bId AND %s.uId = %d'; +		$query = sprintf($qmask, +		$this->getTableName(), +		$this->getTableName(), +		$GLOBALS['tableprefix'].'bookmarks', +		$this->getTableName(), +		$GLOBALS['tableprefix'].'bookmarks', +		$GLOBALS['tableprefix'].'bookmarks', +		$uId); + +		if (!($dbresult =& $this->db->sql_query($query))) { +			message_die(GENERAL_ERROR, 'Could not delete tags', '', __LINE__, __FILE__, $query, $this->db); +			return false; +		} + +		return true;  	}  	function &getTagsForBookmark($bookmarkid) { @@ -224,7 +235,7 @@ class Bookmark2TagService {  	}  	function &getTags($userid = NULL) { -		$userservice =& ServiceFactory::getServiceInstance('UserService'); +		$userservice =SemanticScuttle_Service_Factory::getServiceInstance('User');  		$logged_on_user = $userservice->getCurrentUserId();  		$query = 'SELECT T.tag, COUNT(B.bId) AS bCount FROM '. $GLOBALS['tableprefix'] .'bookmarks AS B INNER JOIN '. $userservice->getTableName() .' AS U ON B.uId = U.'. $userservice->getFieldName('primary') .' INNER JOIN '. $GLOBALS['tableprefix'] .'bookmarks2tags AS T ON B.bId = T.bId'; @@ -299,7 +310,7 @@ class Bookmark2TagService {  	// Returns the most popular tags used for a particular bookmark hash  	function &getRelatedTagsByHash($hash, $limit = 20) { -		$userservice = & ServiceFactory :: getServiceInstance('UserService'); +		$userservice = SemanticScuttle_Service_Factory :: getServiceInstance('User');  		$sId = $userservice->getCurrentUserId();  		// Logged in  		if ($userservice->isLoggedOn()) { @@ -329,7 +340,7 @@ class Bookmark2TagService {  	function &getAdminTags($limit = 30, $logged_on_user = NULL, $days = NULL) {  		// look for admin ids -		$userservice = & ServiceFactory :: getServiceInstance('UserService'); +		$userservice = SemanticScuttle_Service_Factory :: getServiceInstance('User');  		$adminIds = $userservice->getAdminIds();  		// ask for their tags @@ -338,7 +349,7 @@ class Bookmark2TagService {  	function &getContactTags($user, $limit = 30, $logged_on_user = NULL, $days = NULL) {  		// look for contact ids -		$userservice = & ServiceFactory :: getServiceInstance('UserService'); +		$userservice = SemanticScuttle_Service_Factory :: getServiceInstance('User');  		$contacts = $userservice->getWatchlist($user);  		// add the user (to show him/her also his/her tags) @@ -406,8 +417,8 @@ class Bookmark2TagService {  	}  	function renameTag($userid, $old, $new, $fromApi = false) { -		$bookmarkservice =& ServiceFactory::getServiceInstance('BookmarkService'); -		$tagservice =& ServiceFactory::getServiceInstance('TagService'); +		$bookmarkservice =SemanticScuttle_Service_Factory::getServiceInstance('Bookmark'); +		$tagservice =SemanticScuttle_Service_Factory::getServiceInstance('Tag');  		if (is_null($userid) || is_null($old) || is_null($new))  		return false; diff --git a/src/SemanticScuttle/Service/Cache.php b/src/SemanticScuttle/Service/Cache.php index fe66d38..5ca2843 100644 --- a/src/SemanticScuttle/Service/Cache.php +++ b/src/SemanticScuttle/Service/Cache.php @@ -1,18 +1,27 @@  <?php -class CacheService { +class SemanticScuttle_Service_Cache extends SemanticScuttle_Service +{      var $basedir;      var $fileextension = '.cache'; -    function &getInstance() { -        static $instance; -         -        if (!isset($instance)) -            $instance =& new CacheService(); - -        return $instance; -    } +    /** +     * Returns the single service instance +     * +     * @param DB $db Database object +     * +     * @return SemanticScuttle_Service +     */ +	public static function getInstance($db) +    { +		static $instance; +		if (!isset($instance)) { +            $instance = new self($db); +        } +		return $instance; +	} -    function CacheService() { +    protected function __construct() +    {          $this->basedir = $GLOBALS['dir_cache'];          } diff --git a/src/SemanticScuttle/Service/CommonDescription.php b/src/SemanticScuttle/Service/CommonDescription.php index 86e0c0f..ed1ffdd 100644 --- a/src/SemanticScuttle/Service/CommonDescription.php +++ b/src/SemanticScuttle/Service/CommonDescription.php @@ -1,17 +1,27 @@  <?php -class CommonDescriptionService { -	var $db; +class SemanticScuttle_Service_CommonDescription extends SemanticScuttle_Service +{  	var $tablename; -	function &getInstance(&$db) { +    /** +     * Returns the single service instance +     * +     * @param DB $db Database object +     * +     * @return SemanticScuttle_Service +     */ +	public static function getInstance($db) +    {  		static $instance; -		if (!isset($instance)) -		$instance =& new CommonDescriptionService($db); +		if (!isset($instance)) { +            $instance = new self($db); +        }  		return $instance;  	} -	function CommonDescriptionService(&$db) { -		$this->db =& $db; +	public function __construct($db) +    { +		$this->db = $db;  		$this->tablename = $GLOBALS['tableprefix'] .'commondescription';  	} diff --git a/src/SemanticScuttle/Service/Factory.php b/src/SemanticScuttle/Service/Factory.php index b5215e3..b4ba28e 100644 --- a/src/SemanticScuttle/Service/Factory.php +++ b/src/SemanticScuttle/Service/Factory.php @@ -1,16 +1,19 @@  <?php  /* Connect to the database and build services */ -class ServiceFactory { -	function ServiceFactory(&$db, $serviceoverrules = array()) { +class SemanticScuttle_Service_Factory +{ +	public function __construct($db, $serviceoverrules = array()) +    {  	} -	function &getServiceInstance($name, $servicedir = NULL) { +	public function getServiceInstance($name, $servicedir = null) +    {  		global $dbhost, $dbuser, $dbpass, $dbname, $dbport, $dbpersist, $dbtype;  		static $instances = array();  		static $db;  		if (!isset($db)) { -			require_once(dirname(__FILE__) .'/../includes/db/'. $dbtype .'.php'); +			require_once 'SemanticScuttle/db/'. $dbtype .'.php';  			$db = new sql_db();  			$db->sql_connect($dbhost, $dbuser, $dbpass, $dbname, $dbport, $dbpersist);  			if(!$db->db_connect_id) { @@ -25,12 +28,15 @@ class ServiceFactory {  			}  			if (!class_exists($name)) {  				if (!isset($servicedir)) { -					$servicedir = dirname(__FILE__) .'/'; +					$servicedir = 'SemanticScuttle/Service/';  				} -				require_once($servicedir . strtolower($name) . '.php'); +				require_once $servicedir . $name . '.php';  			} -			$instances[$name] = call_user_func(array($name, 'getInstance'), $db); +			$instances[$name] = call_user_func( +                array('SemanticScuttle_Service_' . $name, 'getInstance'), +                $db +            );  		}  		return $instances[$name];  	} diff --git a/src/SemanticScuttle/Service/SearchHistory.php b/src/SemanticScuttle/Service/SearchHistory.php index 91457e8..7cffa83 100644 --- a/src/SemanticScuttle/Service/SearchHistory.php +++ b/src/SemanticScuttle/Service/SearchHistory.php @@ -1,18 +1,28 @@  <?php -class SearchHistoryService { -	var $db; +class SemanticScuttle_Service_SearchHistory extends SemanticScuttle_Service +{  	var $tablename;  	var $sizeSearchHistory; -	function &getInstance(&$db) { +    /** +     * Returns the single service instance +     * +     * @param DB $db Database object +     * +     * @return SemanticScuttle_Service +     */ +	public static function getInstance($db) +    {  		static $instance; -		if (!isset($instance)) -		$instance =& new SearchHistoryService($db); +		if (!isset($instance)) { +            $instance = new self($db); +        }  		return $instance;  	} -	function SearchHistoryService(& $db) { -		$this->db =& $db; +	public function __construct($db) +    { +		$this->db = $db;  		$this->tablename = $GLOBALS['tableprefix'] .'searchhistory';  		if(isset($GLOBALS['sizeSearchHistory'])) {  			$this->sizeSearchHistory = $GLOBALS['sizeSearchHistory']; diff --git a/src/SemanticScuttle/Service/Tag.php b/src/SemanticScuttle/Service/Tag.php index fc44a99..2a70948 100644 --- a/src/SemanticScuttle/Service/Tag.php +++ b/src/SemanticScuttle/Service/Tag.php @@ -1,17 +1,27 @@  <?php -class TagService { -	var $db; +class SemanticScuttle_Service_Tag extends SemanticScuttle_Service +{  	var $tablename; -	function &getInstance(&$db) { +    /** +     * Returns the single service instance +     * +     * @param DB $db Database object +     * +     * @return SemanticScuttle_Service +     */ +	public static function getInstance($db) +    {  		static $instance; -		if (!isset($instance)) -		$instance =& new TagService($db); +		if (!isset($instance)) { +            $instance = new self($db); +        }  		return $instance;  	} -	function TagService(&$db) { -		$this->db =& $db; +	public function __construct($db) +    { +		$this->db = $db;  		$this->tablename = $GLOBALS['tableprefix'] .'tags';  	} diff --git a/src/SemanticScuttle/Service/Tag2tag.php b/src/SemanticScuttle/Service/Tag2Tag.php index 956fd49..b209d60 100644 --- a/src/SemanticScuttle/Service/Tag2tag.php +++ b/src/SemanticScuttle/Service/Tag2Tag.php @@ -1,22 +1,33 @@  <?php -class Tag2TagService { -	var $db; -	var $tablename; - -	function &getInstance(&$db) { +class SemanticScuttle_Service_Tag2Tag extends SemanticScuttle_Service +{ +	protected $tablename; + +    /** +     * Returns the single service instance +     * +     * @param DB $db Database object +     * +     * @return SemanticScuttle_Service +     */ +	public static function getInstance($db) +    {  		static $instance; -		if (!isset($instance)) -		$instance =& new Tag2TagService($db); +		if (!isset($instance)) { +            $instance = new self($db); +        }  		return $instance;  	} -	function Tag2TagService(&$db) { + +	function __construct(&$db) +    {  		$this->db =& $db;  		$this->tablename = $GLOBALS['tableprefix'] .'tags2tags';  	}  	function addLinkedTags($tag1, $tag2, $relationType, $uId) { -		$tagservice =& ServiceFactory::getServiceInstance('TagService'); +		$tagservice =SemanticScuttle_Service_Factory::getServiceInstance('Tag');  		$tag1 = $tagservice->normalize($tag1);  		$tag2 = $tagservice->normalize($tag2); @@ -46,7 +57,7 @@ class Tag2TagService {  	// Return linked tags just for admin users  	function getAdminLinkedTags($tag, $relationType, $inverseRelation = false, $stopList = array()) {  		// look for admin ids -		$userservice = & ServiceFactory :: getServiceInstance('UserService'); +		$userservice = SemanticScuttle_Service_Factory :: getServiceInstance('User');  		$adminIds = $userservice->getAdminIds();  		//ask for their linked tags @@ -119,7 +130,7 @@ class Tag2TagService {  		}  		// try to find data in cache -		$tcs = & ServiceFactory::getServiceInstance('TagCacheService'); +		$tcs = SemanticScuttle_Service_Factory::getServiceInstance('TagCache');  		if(count($stopList) == 0) {  			$activatedCache = true;  		} else { @@ -177,7 +188,7 @@ class Tag2TagService {  		$query = "SELECT DISTINCT tts.tag1 as tag";  		$query.= " FROM `". $this->getTableName() ."` tts";  		if($orderBy != null) { -			$tsts =& ServiceFactory::getServiceInstance('TagStatService'); +			$tsts =SemanticScuttle_Service_Factory::getServiceInstance('TagStat');  			$query.= ", ".$tsts->getTableName() ." tsts";  		}  		$query.= " WHERE tts.tag1 <> ALL"; @@ -328,7 +339,7 @@ class Tag2TagService {  	}	  	function renameTag($uId, $oldName, $newName) { -		$tagservice =& ServiceFactory::getServiceInstance('TagService'); +		$tagservice =SemanticScuttle_Service_Factory::getServiceInstance('Tag');  		$newName = $tagservice->normalize($newName);  		$query = 'UPDATE `'. $this->getTableName() .'`'; @@ -355,10 +366,10 @@ class Tag2TagService {  	}  	function update($tag1, $tag2, $relationType, $uId) { -		$tsts =& ServiceFactory::getServiceInstance('TagStatService'); +		$tsts =SemanticScuttle_Service_Factory::getServiceInstance('TagStat');  		$tsts->updateStat($tag1, $relationType, $uId); -		$tcs = & ServiceFactory::getServiceInstance('TagCacheService'); +		$tcs = SemanticScuttle_Service_Factory::getServiceInstance('TagCache');  		$tcs->deleteByUser($uId);  	} @@ -366,7 +377,7 @@ class Tag2TagService {  		$query = 'TRUNCATE TABLE `'. $this->getTableName() .'`';  		$this->db->sql_query($query); -		$tsts =& ServiceFactory::getServiceInstance('TagStatService'); +		$tsts =SemanticScuttle_Service_Factory::getServiceInstance('TagStat');  		$tsts->deleteAll();  	} diff --git a/src/SemanticScuttle/Service/TagCache.php b/src/SemanticScuttle/Service/TagCache.php index ed2eefc..30f9ebd 100644 --- a/src/SemanticScuttle/Service/TagCache.php +++ b/src/SemanticScuttle/Service/TagCache.php @@ -1,31 +1,43 @@  <?php - -/* - * This class infers on relation between tags by storing all the including tags or synonymous tag. - * For example, if the user creates: tag1>tag2>tag3, the system can infer that tag is included into tag1. - * Instead of computing this relation several times, it is saved into this current table. +/** + * This class infers on relation between tags by storing all + * the including tags or synonymous tag. + * For example, if the user creates: tag1>tag2>tag3, the system + * can infer that tag is included into tag1. + * Instead of computing this relation several times, it is saved + * into this current table.   * For synonymy, this table stores also the group of synonymous tags. - * The table must be updated for each modification of the relations between tags. + * The table must be updated for each modification of + * the relations between tags.   */ - -class TagCacheService { -	var $db; +class SemanticScuttle_Service_TagCache extends SemanticScuttle_Service +{  	var $tablename; -	function &getInstance(&$db) { +    /** +     * Returns the single service instance +     * +     * @param DB $db Database object +     * +     * @return SemanticScuttle_Service +     */ +	public static function getInstance($db) +    {  		static $instance; -		if (!isset($instance)) -		$instance =& new TagCacheService($db); +		if (!isset($instance)) { +            $instance = new self($db); +        }  		return $instance;  	} -	function TagCacheService(&$db) { -		$this->db =& $db; +	protected function __construct($db) +    { +		$this->db =$db;  		$this->tablename = $GLOBALS['tableprefix'] .'tagscache';  	}  	function getChildren($tag1, $uId) { -		$tagservice =& ServiceFactory::getServiceInstance('TagService'); +		$tagservice =SemanticScuttle_Service_Factory::getServiceInstance('Tag');  		$tag1 = $tagservice->normalize($tag1);  		if($tag1 == '') return false; @@ -54,7 +66,7 @@ class TagCacheService {  	}  	function addChild($tag1, $tag2, $uId) { -		$tagservice =& ServiceFactory::getServiceInstance('TagService'); +		$tagservice =SemanticScuttle_Service_Factory::getServiceInstance('Tag');  		$tag1 = $tagservice->normalize($tag1);  		$tag2 = $tagservice->normalize($tag2); @@ -98,7 +110,7 @@ class TagCacheService {  	}  	function existsChild($tag1, $tag2, $uId) { -		$tagservice =& ServiceFactory::getServiceInstance('TagService'); +		$tagservice =SemanticScuttle_Service_Factory::getServiceInstance('Tag');  		$tag1 = $tagservice->normalize($tag1);  		$tag2 = $tagservice->normalize($tag2); @@ -202,7 +214,7 @@ class TagCacheService {  	}  	function _isSynonymKey($tag1, $uId) { -		$tagservice =& ServiceFactory::getServiceInstance('TagService'); +		$tagservice =SemanticScuttle_Service_Factory::getServiceInstance('Tag');  		$tag1 = $tagservice->normalize($tag1);  		$query = "SELECT tag1 FROM `". $this->getTableName() ."`"; @@ -214,7 +226,7 @@ class TagCacheService {  	}  	function _isSynonymValue($tag2, $uId) { -		$tagservice =& ServiceFactory::getServiceInstance('TagService'); +		$tagservice =SemanticScuttle_Service_Factory::getServiceInstance('Tag');  		$tag2 = $tagservice->normalize($tag2);  		$query = "SELECT tag2 FROM `". $this->getTableName() ."`"; @@ -238,7 +250,7 @@ class TagCacheService {  	}  	function _getSynonymKey($tag2, $uId) { -		$tagservice =& ServiceFactory::getServiceInstance('TagService'); +		$tagservice =SemanticScuttle_Service_Factory::getServiceInstance('Tag');  		$tag2 = $tagservice->normalize($tag2);  		if($this->_isSynonymKey($tag2)) return $tag2; @@ -267,7 +279,7 @@ class TagCacheService {  	 * $tagExcepted allows to hide a value.  	 */  	function _getSynonymValues($tag1, $uId, $tagExcepted = NULL) { -		$tagservice =& ServiceFactory::getServiceInstance('TagService'); +		$tagservice =SemanticScuttle_Service_Factory::getServiceInstance('Tag');  		$tag1 = $tagservice->normalize($tag1);  		$tagExcepted = $tagservice->normalize($tagExcepted); diff --git a/src/SemanticScuttle/Service/TagStat.php b/src/SemanticScuttle/Service/TagStat.php index 9d3ca5d..c54dcb7 100644 --- a/src/SemanticScuttle/Service/TagStat.php +++ b/src/SemanticScuttle/Service/TagStat.php @@ -1,22 +1,33 @@  <?php -class TagStatService { -	var $db; +class SemanticScuttle_Service_TagStat extends SemanticScuttle_Service +{ +  	var $tablename; -	function &getInstance(&$db) { +    /** +     * Returns the single service instance +     * +     * @param DB $db Database object +     * +     * @return SemanticScuttle_Service +     */ +	public static function getInstance($db) +    {  		static $instance; -		if (!isset($instance)) -		$instance =& new TagStatService($db); +		if (!isset($instance)) { +            $instance = new self($db); +        }  		return $instance;  	} -	function TagStatService(&$db) { -		$this->db =& $db; +	protected function __construct($db) +    { +		$this->db = $db;  		$this->tablename = $GLOBALS['tableprefix'] .'tagsstats';  	}  	function getNbChildren($tag1, $relationType, $uId) { -		$tts =& ServiceFactory::getServiceInstance('Tag2TagService'); +		$tts =SemanticScuttle_Service_Factory::getServiceInstance('Tag2Tag');  		$query = "SELECT tag1, relationType, uId FROM `". $tts->getTableName() ."`";  		$query.= " WHERE tag1 = '" .$tag1 ."'";  		$query.= " AND relationType = '". $relationType ."'"; @@ -91,7 +102,7 @@ class TagStatService {  			return false;  		} -		$tts =& ServiceFactory::getServiceInstance('Tag2TagService'); +		$tts =SemanticScuttle_Service_Factory::getServiceInstance('Tag2Tag');  		$linkedTags = $tts->getLinkedTags($tag1, $relationType, $uId);  		$nbDescendants = 0;  		$maxDepth = 0; @@ -112,7 +123,7 @@ class TagStatService {  	}  	function updateAllStat() { -		$tts =& ServiceFactory::getServiceInstance('Tag2TagService'); +		$tts =SemanticScuttle_Service_Factory::getServiceInstance('Tag2Tag');  		$query = "SELECT tag1, uId FROM `". $tts->getTableName() ."`";  		$query.= " WHERE relationType = '>'"; diff --git a/src/SemanticScuttle/Service/Template.php b/src/SemanticScuttle/Service/Template.php index 05e494c..dbe5670 100644 --- a/src/SemanticScuttle/Service/Template.php +++ b/src/SemanticScuttle/Service/Template.php @@ -1,15 +1,26 @@  <?php -class TemplateService { -	var $basedir; +class SemanticScuttle_Service_Template extends SemanticScuttle_Service +{ +	protected $basedir; -	function &getInstance() { +    /** +     * Returns the single service instance +     * +     * @param DB $db Database object +     * +     * @return SemanticScuttle_Service +     */ +	public static function getInstance($db) +    {  		static $instance; -		if (!isset($instance)) -		$instance =& new TemplateService(); +		if (!isset($instance)) { +            $instance = new self($db); +        }  		return $instance;  	} -	function TemplateService() { +	public function __construct() +    {  		$this->basedir = $GLOBALS['TEMPLATES_DIR'];  	} diff --git a/src/SemanticScuttle/Service/User.php b/src/SemanticScuttle/Service/User.php index 407632b..bc88c0b 100644 --- a/src/SemanticScuttle/Service/User.php +++ b/src/SemanticScuttle/Service/User.php @@ -1,28 +1,39 @@  <?php -class UserService { -	var $db; -	var $fields = array( +class SemanticScuttle_Service_User extends SemanticScuttle_Service +{ +	protected $db; +	protected $fields = array(          'primary'   =>  'uId',          'username'  =>  'username',          'password'  =>  'password'); -	var $profileurl; -	var $tablename; -	var $sessionkey; -	var $cookiekey; -	var $cookietime = 1209600; // 2 weeks - -	function &getInstance(&$db) { +	protected $profileurl; +	protected $tablename; +	protected $sessionkey; +	protected $cookiekey; +	protected $cookietime = 1209600; // 2 weeks + +    /** +     * Returns the single service instance +     * +     * @param DB $db Database object +     * +     * @return SemanticScuttle_Service +     */ +	public static function getInstance($db) +    {  		static $instance; -		if (!isset($instance)) -		$instance =& new UserService($db); +		if (!isset($instance)) { +            $instance = new self($db); +        }  		return $instance;  	} -	function UserService(& $db) { -		$this->db =& $db; -		$this->tablename = $GLOBALS['tableprefix'] .'users'; +	protected function __construct($db) +    { +		$this->db = $db; +		$this->tablename  = $GLOBALS['tableprefix'] .'users';  		$this->sessionkey = INSTALLATION_ID.'-currentuserid'; -		$this->cookiekey = INSTALLATION_ID.'-login'; +		$this->cookiekey  = INSTALLATION_ID.'-login';  		$this->profileurl = createURL('profile', '%2$s');  		$this->updateSessionStability();  	} @@ -436,21 +447,21 @@ class UserService {  		return true;  	} -	function getAllUsers ( ) {
 -		$query = 'SELECT * FROM '. $this->getTableName();
 -
 -		if (! ($dbresult =& $this->db->sql_query($query)) ) {
 -			message_die(GENERAL_ERROR, 'Could not get users', '', __LINE__, __FILE__, $query, $this->db);
 -			return false;
 -		}
 -
 -		$rows = array();
 -
 -		while ( $row = $this->db->sql_fetchrow($dbresult) ) {
 -			$rows[] = $row;
 -		}
 -		$this->db->sql_freeresult($dbresult);
 -		return $rows;
 +	function getAllUsers ( ) { +		$query = 'SELECT * FROM '. $this->getTableName(); + +		if (! ($dbresult =& $this->db->sql_query($query)) ) { +			message_die(GENERAL_ERROR, 'Could not get users', '', __LINE__, __FILE__, $query, $this->db); +			return false; +		} + +		$rows = array(); + +		while ( $row = $this->db->sql_fetchrow($dbresult) ) { +			$rows[] = $row; +		} +		$this->db->sql_freeresult($dbresult); +		return $rows;  	}  	// Returns an array with admin uIds @@ -461,18 +472,18 @@ class UserService {  			$admins[] = $this->getIdFromUser($adminName);   		}  		return $admins; -	}
 -
 -	function deleteUser($uId) {
 -		$query = 'DELETE FROM '. $this->getTableName() .' WHERE uId = '. intval($uId);
 -
 -		if (!($dbresult = & $this->db->sql_query($query))) {
 -			message_die(GENERAL_ERROR, 'Could not delete user', '', __LINE__, __FILE__, $query, $this->db);
 -			return false;
 -		}
 -
 -		return true;
 -	}
 +	} + +	function deleteUser($uId) { +		$query = 'DELETE FROM '. $this->getTableName() .' WHERE uId = '. intval($uId); + +		if (!($dbresult = & $this->db->sql_query($query))) { +			message_die(GENERAL_ERROR, 'Could not delete user', '', __LINE__, __FILE__, $query, $this->db); +			return false; +		} + +		return true; +	}  	function sanitisePassword($password) { @@ -601,7 +612,7 @@ class User {  	function getName() {  		// Look for value only if not already set  		if(!isset($this->name)) { -			$userservice =& ServiceFactory::getServiceInstance('UserService'); +			$userservice =SemanticScuttle_Service_Factory::getServiceInstance('User');  			$user = $userservice->getUser($this->id);  			$this->name = $user['name'];  		} @@ -611,7 +622,7 @@ class User {  	function getEmail() {  		// Look for value only if not already set  		if(!isset($this->email)) { -			$userservice =& ServiceFactory::getServiceInstance('UserService'); +			$userservice =SemanticScuttle_Service_Factory::getServiceInstance('User');  			$user = $userservice->getUser($this->id);  			$this->email = $user['email'];  		} @@ -621,7 +632,7 @@ class User {  	function getHomepage() {  		// Look for value only if not already set  		if(!isset($this->homepage)) { -			$userservice =& ServiceFactory::getServiceInstance('UserService'); +			$userservice =SemanticScuttle_Service_Factory::getServiceInstance('User');  			$user = $userservice->getUser($this->id);  			$this->homepage = $user['homepage'];  		} @@ -631,7 +642,7 @@ class User {  	function getContent() {  		// Look for value only if not already set  		if(!isset($this->content)) { -			$userservice =& ServiceFactory::getServiceInstance('UserService'); +			$userservice =SemanticScuttle_Service_Factory::getServiceInstance('User');  			$user = $userservice->getUser($this->id);  			$this->content = $user['uContent'];  		} @@ -641,7 +652,7 @@ class User {  	function getDatetime() {  		// Look for value only if not already set  		if(!isset($this->content)) { -			$userservice =& ServiceFactory::getServiceInstance('UserService'); +			$userservice =SemanticScuttle_Service_Factory::getServiceInstance('User');  			$user = $userservice->getUser($this->id);  			$this->datetime = $user['uDatetime'];  		} @@ -651,14 +662,14 @@ class User {  	function isAdmin() {  		// Look for value only if not already set  		if(!isset($this->isAdmin)) { -			$userservice =& ServiceFactory::getServiceInstance('UserService'); +			$userservice =SemanticScuttle_Service_Factory::getServiceInstance('User');  			$this->isAdmin = $userservice->isAdmin($this->id);  		}  		return $this->isAdmin;  	}  	function getNbBookmarks($range = 'public') { -		$bookmarkservice =& ServiceFactory::getServiceInstance('BookmarkService'); +		$bookmarkservice =SemanticScuttle_Service_Factory::getServiceInstance('Bookmark');  		return $bookmarkservice->countBookmarks($this->getId(), $range);  	}  } | 
