ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
HTMLPurifier_DefinitionCache_Serializer Class Reference
+ Inheritance diagram for HTMLPurifier_DefinitionCache_Serializer:
+ Collaboration diagram for HTMLPurifier_DefinitionCache_Serializer:

Public Member Functions

 add ($def, $config)
 set ($def, $config)
 replace ($def, $config)
 get ($config)
 remove ($config)
 flush ($config)
 cleanup ($config)
 generateFilePath ($config)
 Generates the file path to the serial file corresponding to the configuration and definition name.
 generateDirectoryPath ($config)
 Generates the path to the directory contain this cache's serial files.
 generateBaseDirectoryPath ($config)
 Generates path to base directory that contains all definition type serials.
- Public Member Functions inherited from HTMLPurifier_DefinitionCache
 __construct ($type)
 generateKey ($config)
 Generates a unique identifier for a particular configuration.
 isOld ($key, $config)
 Tests whether or not a key is old with respect to the configuration's version and revision number.
 checkDefType ($def)
 Checks if a definition's type jives with the cache's type.

Private Member Functions

 _write ($file, $data, $config)
 Convenience wrapper function for file_put_contents.
 _prepareDir ($config)
 Prepares the directory that this type stores the serials in.
 _testPermissions ($dir, $chmod)
 Tests permissions on a directory and throws out friendly error messages and attempts to chmod it itself if possible.

Additional Inherited Members

- Data Fields inherited from HTMLPurifier_DefinitionCache
 $type
 string

Detailed Description

Definition at line 3 of file Serializer.php.

Member Function Documentation

HTMLPurifier_DefinitionCache_Serializer::_prepareDir (   $config)
private

Prepares the directory that this type stores the serials in.

Parameters
HTMLPurifier_Config$config
Returns
bool True if successful

Definition at line 203 of file Serializer.php.

References _testPermissions(), generateBaseDirectoryPath(), and generateDirectoryPath().

Referenced by add(), cleanup(), flush(), replace(), and set().

{
$directory = $this->generateDirectoryPath($config);
$chmod = $config->get('Cache.SerializerPermissions');
if (!$chmod) {
$chmod = 0755; // invalid config or simpletest
}
if (!is_dir($directory)) {
$base = $this->generateBaseDirectoryPath($config);
if (!is_dir($base)) {
trigger_error(
'Base directory ' . $base . ' does not exist,
please create or change using %Cache.SerializerPath',
E_USER_WARNING
);
return false;
} elseif (!$this->_testPermissions($base, $chmod)) {
return false;
}
$old = umask(0000);
mkdir($directory, $chmod);
umask($old);
} elseif (!$this->_testPermissions($directory, $chmod)) {
return false;
}
return true;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

HTMLPurifier_DefinitionCache_Serializer::_testPermissions (   $dir,
  $chmod 
)
private

Tests permissions on a directory and throws out friendly error messages and attempts to chmod it itself if possible.

Parameters
string$dirDirectory path
int$chmodPermissions
Returns
bool True if directory is writable

Definition at line 238 of file Serializer.php.

Referenced by _prepareDir().

{
// early abort, if it is writable, everything is hunky-dory
if (is_writable($dir)) {
return true;
}
if (!is_dir($dir)) {
// generally, you'll want to handle this beforehand
// so a more specific error message can be given
trigger_error(
'Directory ' . $dir . ' does not exist',
E_USER_WARNING
);
return false;
}
if (function_exists('posix_getuid')) {
// POSIX system, we can give more specific advice
if (fileowner($dir) === posix_getuid()) {
// we can chmod it ourselves
$chmod = $chmod | 0700;
if (chmod($dir, $chmod)) {
return true;
}
} elseif (filegroup($dir) === posix_getgid()) {
$chmod = $chmod | 0070;
} else {
// PHP's probably running as nobody, so we'll
// need to give global permissions
$chmod = $chmod | 0777;
}
trigger_error(
'Directory ' . $dir . ' not writable, ' .
'please chmod to ' . decoct($chmod),
E_USER_WARNING
);
} else {
// generic error message
trigger_error(
'Directory ' . $dir . ' not writable, ' .
'please alter file permissions',
E_USER_WARNING
);
}
return false;
}

+ Here is the caller graph for this function:

HTMLPurifier_DefinitionCache_Serializer::_write (   $file,
  $data,
  $config 
)
private

Convenience wrapper function for file_put_contents.

Parameters
string$fileFile name to write to
string$dataData to write into file
HTMLPurifier_Config$config
Returns
int|bool Number of bytes written if success, or false if failure.

Definition at line 183 of file Serializer.php.

References $file, and $result.

Referenced by add(), replace(), and set().

{
$result = file_put_contents($file, $data);
if ($result !== false) {
// set permissions of the new file (no execute)
$chmod = $config->get('Cache.SerializerPermissions');
if (!$chmod) {
$chmod = 0644; // invalid config or simpletest
}
$chmod = $chmod & 0666;
chmod($file, $chmod);
}
return $result;
}

+ Here is the caller graph for this function:

HTMLPurifier_DefinitionCache_Serializer::add (   $def,
  $config 
)
Parameters
HTMLPurifier_Definition$def
HTMLPurifier_Config$config
Returns
int|bool

Reimplemented from HTMLPurifier_DefinitionCache.

Definition at line 11 of file Serializer.php.

References $file, _prepareDir(), _write(), HTMLPurifier_DefinitionCache\checkDefType(), and generateFilePath().

{
if (!$this->checkDefType($def)) {
return;
}
$file = $this->generateFilePath($config);
if (file_exists($file)) {
return false;
}
if (!$this->_prepareDir($config)) {
return false;
}
return $this->_write($file, serialize($def), $config);
}

+ Here is the call graph for this function:

HTMLPurifier_DefinitionCache_Serializer::cleanup (   $config)
Parameters
HTMLPurifier_Config$config
Returns
bool

Reimplemented from HTMLPurifier_DefinitionCache.

Definition at line 115 of file Serializer.php.

References $filename, _prepareDir(), generateDirectoryPath(), and HTMLPurifier_DefinitionCache\isOld().

{
if (!$this->_prepareDir($config)) {
return false;
}
$dir = $this->generateDirectoryPath($config);
$dh = opendir($dir);
while (false !== ($filename = readdir($dh))) {
if (empty($filename)) {
continue;
}
if ($filename[0] === '.') {
continue;
}
$key = substr($filename, 0, strlen($filename) - 4);
if ($this->isOld($key, $config)) {
unlink($dir . '/' . $filename);
}
}
}

+ Here is the call graph for this function:

HTMLPurifier_DefinitionCache_Serializer::flush (   $config)
Parameters
HTMLPurifier_Config$config
Returns
bool

Reimplemented from HTMLPurifier_DefinitionCache.

Definition at line 93 of file Serializer.php.

References $filename, _prepareDir(), and generateDirectoryPath().

{
if (!$this->_prepareDir($config)) {
return false;
}
$dir = $this->generateDirectoryPath($config);
$dh = opendir($dir);
while (false !== ($filename = readdir($dh))) {
if (empty($filename)) {
continue;
}
if ($filename[0] === '.') {
continue;
}
unlink($dir . '/' . $filename);
}
}

+ Here is the call graph for this function:

HTMLPurifier_DefinitionCache_Serializer::generateBaseDirectoryPath (   $config)

Generates path to base directory that contains all definition type serials.

Parameters
HTMLPurifier_Config$config
Returns
mixed|string
Todo:
Make protected

Definition at line 169 of file Serializer.php.

Referenced by _prepareDir(), and generateDirectoryPath().

{
$base = $config->get('Cache.SerializerPath');
$base = is_null($base) ? HTMLPURIFIER_PREFIX . '/HTMLPurifier/DefinitionCache/Serializer' : $base;
return $base;
}

+ Here is the caller graph for this function:

HTMLPurifier_DefinitionCache_Serializer::generateDirectoryPath (   $config)

Generates the path to the directory contain this cache's serial files.

Parameters
HTMLPurifier_Config$config
Returns
string
Note
No trailing slash
Todo:
Make protected

Definition at line 156 of file Serializer.php.

References HTMLPurifier_DefinitionCache\$type, and generateBaseDirectoryPath().

Referenced by _prepareDir(), cleanup(), flush(), and generateFilePath().

{
$base = $this->generateBaseDirectoryPath($config);
return $base . '/' . $this->type;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

HTMLPurifier_DefinitionCache_Serializer::generateFilePath (   $config)

Generates the file path to the serial file corresponding to the configuration and definition name.

Parameters
HTMLPurifier_Config$config
Returns
string
Todo:
Make protected

Definition at line 143 of file Serializer.php.

References generateDirectoryPath(), and HTMLPurifier_DefinitionCache\generateKey().

Referenced by add(), get(), remove(), replace(), and set().

{
$key = $this->generateKey($config);
return $this->generateDirectoryPath($config) . '/' . $key . '.ser';
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

HTMLPurifier_DefinitionCache_Serializer::get (   $config)
Parameters
HTMLPurifier_Config$config
Returns
bool|HTMLPurifier_Config

Reimplemented from HTMLPurifier_DefinitionCache.

Definition at line 67 of file Serializer.php.

References $file, and generateFilePath().

{
$file = $this->generateFilePath($config);
if (!file_exists($file)) {
return false;
}
return unserialize(file_get_contents($file));
}

+ Here is the call graph for this function:

HTMLPurifier_DefinitionCache_Serializer::remove (   $config)
Parameters
HTMLPurifier_Config$config
Returns
bool

Reimplemented from HTMLPurifier_DefinitionCache.

Definition at line 80 of file Serializer.php.

References $file, and generateFilePath().

{
$file = $this->generateFilePath($config);
if (!file_exists($file)) {
return false;
}
return unlink($file);
}

+ Here is the call graph for this function:

HTMLPurifier_DefinitionCache_Serializer::replace (   $def,
  $config 
)
Parameters
HTMLPurifier_Definition$def
HTMLPurifier_Config$config
Returns
int|bool

Reimplemented from HTMLPurifier_DefinitionCache.

Definition at line 48 of file Serializer.php.

References $file, _prepareDir(), _write(), HTMLPurifier_DefinitionCache\checkDefType(), and generateFilePath().

{
if (!$this->checkDefType($def)) {
return;
}
$file = $this->generateFilePath($config);
if (!file_exists($file)) {
return false;
}
if (!$this->_prepareDir($config)) {
return false;
}
return $this->_write($file, serialize($def), $config);
}

+ Here is the call graph for this function:

HTMLPurifier_DefinitionCache_Serializer::set (   $def,
  $config 
)
Parameters
HTMLPurifier_Definition$def
HTMLPurifier_Config$config
Returns
int|bool

Reimplemented from HTMLPurifier_DefinitionCache.

Definition at line 31 of file Serializer.php.

References $file, _prepareDir(), _write(), HTMLPurifier_DefinitionCache\checkDefType(), and generateFilePath().

{
if (!$this->checkDefType($def)) {
return;
}
$file = $this->generateFilePath($config);
if (!$this->_prepareDir($config)) {
return false;
}
return $this->_write($file, serialize($def), $config);
}

+ Here is the call graph for this function:


The documentation for this class was generated from the following file: