(root)/shared-tags-TagKeyword.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 TagKeyword
extends lockableClass
{
var $keyword; ///< @var string The keyword the tags of which are represented by this instance of TagKeyword
var $parentHandler; ///< @var TagsHandler A reference to the TagsHandler instance containing this instance of TagKeyword
var $globalIDs; ///< @var Array containing globalIDs and their associated usernames - globalIDs[globalID][username]
var $users; ///< @var Array containing usernames and their associated globalIDs - users[username][globalID]
function TagKeyword
( &$parentHandler, $keyword )
{
global $setup_folder;
$this->keyword = $keyword;
$this->parentHandler =& $parentHandler;
$this->filename = "$setup_folder/tags/$keyword.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->users = $saveData["users"];
}
}
function save
()
{
$saveData["globalIDs"] = $this->globalIDs;
$saveData["users"] = $this->users;
if( file_exists( $this->filename ) )
unlink( $this->filename );
// Only save the datafile if there's actually data to save
if( count( $saveData["globalIDs"] ) > 0 )
{
if( !is_dir( "$setup_folder/tags" ) )
RecursiveMkdir
( "$setup_folder/tags" );
fileSave
( $this->filename, array_export
( $saveData, "saveData" ) );
}
}
/**
* Clear all tags associated with this keyword
*
* @return bool
*/
function clearTags
()
{
}
/**
* 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, $username, $doRecurse = true )
{
if( $this->lock() )
{
$this->load();
$this->globalIDs[$globalID][$username] = "";
$this->users[$username][$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( $username, $this->keyword, false );
$theUser =& $parentHandler->getUser($username);
$theUser->addTag( $globalID, $this->keyword, 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, $username, $doRecurse = true )
{
if( $this->lock() )
{
$this->load();
unset( $this->globalIDs[$globalID][$username] );
if( count( $this->globalIDs[$globalID] ) == 0 )
unset( $this->globalIDs[$globalID] );
unset( $this->users[$username][$globalID] );
if( count( $this->users[$username] ) == 0 )
unset( $this->users[$username] );
// Only dive into globalID and keyword instantiation if we were not called by someone specific...
if( $doRecurse == true )
{
$theGlobalID =& $parentHandler->getGlobalID($globalID);
$theGlobalID->removeTag( $username, $this->keyword, false );
$theUser =& $parentHandler->getUser($username);
$theUser->removeTag( $globalID, $this->keyword, false );
}
$this->save();
$this->unlock();
return true;
}
return false;
}
}
?>