(root)/shared-tags-TagGlobalID.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 TagGlobalID
extends lockableClass
{
var $globalID; ///< @var string The globalID the tags of which are represented by this instance of TagGlobalID
var $parentHandler; ///< @var TagsHandler A reference to the TagsHandler instance containing this TagGlobalID
var $users; ///< @var Array containing usernames and their associated keywords - users[username][keyword]
var $keywords; ///< @var Array containing keywords and their associated usernames - keywords[keyword][username]
function TagGlobalID
( &$parentHandler, $globalID )
{
global $setup_folder;
$this->globalID = $globalID;
$this->parentHandler =& $parentHandler;
$this->filename = "$setup_folder/tags/" . urlencode( $globalID ) . ".php";
$this->lockfile = $this->filename . ".lock";
if( $this->lock() )
{
$this->load();
$this->unlock();
}
}
function load
()
{
if( file_exists( $this->filename ) )
{
include( $this->filename );
$this->users = $saveData["users"];
$this->keywords = $saveData["keywords"];
}
}
function save
()
{
$saveData["users"] = $this->users;
$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["users"] ) > 0 )
fileSave
( $this->filename, array_export
( $saveData, "saveData" ) );
}
/**
* Clear all tags associated with this globalID
* This would likely be used mainly for when a piece of information represented by a globalID is deleted
*
* @return bool Wether or not the clearing was successful
*/
function clearTags
()
{
die("Implement TagGlobalID::clearTags()");
}
/**
* Update the tags for a globalID - for example renaming a gallery or a page
*
* @param string newID The new name of the globalID
*
* @return bool Wether or not the tag information was successful updated
*/
function renameGlobalID
( $newID )
{
die("Implement TagGlobalID::renameGlobalID()");
}
/**
* Add an association between this globalID and the specified username and password
*
* @param string username The username 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
( $username, $keyword, $doRecurse = true )
{
if( $this->lock() )
{
$this->load();
// Only dive into globalID and keyword instantiation if we were not called by someone specific...
if( $doRecurse == true )
{
$theUser =& $parentHandler->getUser($username);
$theUser->addTag( $this->globalID, $keyword, false );
$theKeyword =& $parentHandler->getKeyword($keyword);
$theKeyword->addTag( $this->globalID, $username, false );
}
$this->save();
$this->unlock();
return true;
}
return false;
}
/**
* Remove the association between this globalID and the specified username and password
*
* @param string username The username 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
( $username, $keyword, $doRecurse = true )
{
if( $this->lock() )
{
$this->load();
// Only dive into globalID and keyword instantiation if we were not called by someone specific...
if( $doRecurse == true )
{
$theUser =& $parentHandler->getUser($username);
$theUser->removeTag( $this->globalID, $keyword, false );
$theKeyword =& $parentHandler->getKeyword($keyword);
$theKeyword->removeTag( $this->globalID, $username, false );
}
$this->save();
$this->unlock();
return true;
}
return false;
}
}
?>