(root)/shared-tags-TagUser.class.php - Rev 441
Rev 438 |
Blame |
Compare with Previous |
Last modification |
View Log
| RSS feed
<?php
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* This file is part of Travelsized CMS
* A content management system with modules, based on wiki syntax
*
* Author: Dan Jensen <admin@leinir.dk>
* Copyright 2003/2004
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* The GNU General Public License is available at: http://www.gnu.org/copyleft/
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
class TagUser
extends lockableClass
{
var $username; ///< @var string The username the tags refer to
var $parentHandler; ///< @var TagsHandler A reference to the TagsHandler instance containing this instance of TagUser
var $globalIDs; ///< @var Arrary containing globalIDs and their associated keywords - globalIDs[globalID][keyword]
var $keywords; ///< @var Array containing keywords and their associated globalIDs - keywords[keyword][globalID]
function TagUser
( &$parentHandler, $username )
{
global $userinfo_folder;
$this->username = $username;
$this->parentHandler =& $parentHandler;
$this->filename = "$userinfo_folder/$username/tags.php";
$this->lockfile = $this->filename . ".lock";
if( $this->lock() )
{
$this->load();
$this->unlock();
}
}
function load
()
{
if( file_exists( $this->filename ) )
{
include( $this->filename );
$this->globalIDs = $saveData["globalIDs"];
$this->keywords = $saveData["keywords"];
}
}
function save
()
{
$saveData["globalIDs"] = $this->globalIDs;
$saveData["keywords"] = $this->keywords;
if( file_exists( $this->filename ) )
unlink( $this->filename );
// Only save the datafile if there's actually data to save
if( count( $saveData["globalIDs"] ) > 0 )
fileSave
( $this->filename, array_export
( $saveData, "saveData" ) );
}
/**
* Add an association between this globalID and the specified username and password
*
* @param string globalID The globalID to which you wish to create an association
* @param string keyword The keyword to which you wish to create an association
* @param bool doRecurse Internal use (used to make sure infinite recursion doesn't happen)
*
* @return bool Wether or not the tag was successfully added
*/
function addTag
( $globalID, $keyword, $doRecurse = true )
{
if( $this->lock() )
{
$this->load();
$this->globalIDs[$globalID][$keyword] = "";
$this->keywords[$keyword][$globalID] = "";
// Only dive into globalID and keyword instantiation if we were not called by someone specific...
if( $doRecurse == true )
{
$theGlobalID =& $parentHandler->getGlobalID($globalID);
$theGlobalID->addTag( $this->username, $keyword, false );
$theKeyword =& $parentHandler->getKeyword($keyword);
$theKeyword->addTag( $globalID, $this->username, false );
}
$this->save();
$this->unlock();
return true;
}
return false;
}
/**
* Remove the association between this globalID and the specified username and password
*
* @param string globalID The globalID from which you wish to remove the association
* @param string keyword The keyword from which you wish to remove the association
* @param bool doRecurse Internal use (used to make sure infinite recursion doesn't happen)
*
* @return bool Wether or not the tag was successfully removed
*/
function removeTag
( $globalID, $keyword, $doRecurse = true )
{
if( $this->lock() )
{
$this->load();
unset( $this->globalIDs[$globalID][$keyword] );
if( count( $this->globalIDs[$globalID] ) == 0 )
unset( $this->globalIDs[$globalID] );
unset( $this->keywords[$keyword][$globalID] );
if( count( $this->keywords[$keyword] ) == 0 )
unset( $this->keywords[$keyword] );
// Only dive into globalID and keyword instantiation if we were not called by someone specific...
if( $doRecurse == true )
{
$theGlobalID =& $parentHandler->getGlobalID($globalID);
$theGlobalID->removeTag( $this->username, $keyword, false );
$theKeyword =& $parentHandler->getKeyword($keyword);
$theKeyword->removeTag( $globalID, $this->username, false );
}
$this->save();
$this->unlock();
return true;
}
return false;
}
}
?>