Source for file prefs.php

Documentation is available at prefs.php

  1. <?php
  2.  
  3. /**
  4.  * prefs.php
  5.  *
  6.  * This contains functions for filebased user prefs locations
  7.  *
  8.  * @copyright &copy; 1999-2006 The SquirrelMail Project Team
  9.  * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  10.  * @version $Id: prefs.php,v 1.62.2.11 2006/04/14 22:27:08 jervfors Exp $
  11.  * @package squirrelmail
  12.  * @subpackage prefs
  13.  */
  14.  
  15. /** Include global.php */
  16. require_once(SM_PATH 'functions/global.php');
  17. require_once(SM_PATH 'functions/plugin.php');
  18.  
  19. /** include this for error messages */
  20. include_once(SM_PATH 'functions/display_messages.php');
  21.  
  22. sqgetGlobalVar('prefs_cache'$prefs_cacheSQ_SESSION );
  23. sqgetGlobalVar('prefs_are_cached'$prefs_are_cachedSQ_SESSION );
  24.  
  25. $rg ini_get('register_globals');
  26.  
  27. /* if php version >= 4.1 OR (4.0 AND $rg = off) */
  28. if !sqsession_is_registered('prefs_are_cached'||
  29.      !isset$prefs_cache||
  30.      !is_array$prefs_cache||
  31.      check_php_version(4,1||
  32.      empty($rg)
  33.    {
  34.     $prefs_are_cached false;
  35.     $prefs_cache array();
  36. }
  37.  
  38. $prefs_backend do_hook_function('prefs_backend');
  39. if (isset($prefs_backend&& !empty($prefs_backend&& file_exists(SM_PATH $prefs_backend)) {
  40.     require_once(SM_PATH $prefs_backend);
  41. elseif (isset($prefs_dsn&& !empty($prefs_dsn)) {
  42.     require_once(SM_PATH 'functions/db_prefs.php');
  43. else {
  44.     require_once(SM_PATH 'functions/file_prefs.php');
  45. }
  46.  
  47. /* Hashing functions */
  48.  
  49. /**
  50.  * Given a username and datafilename, this will return the path to the
  51.  * hashed location of that datafile.
  52.  *
  53.  * @param string username the username of the current user
  54.  * @param string dir the squirrelmail datadir
  55.  * @param string datafile the name of the file to open
  56.  * @param bool hash_seach default true
  57.  * @return string the hashed location of datafile
  58.  */
  59. function getHashedFile($username$dir$datafile$hash_search true{
  60.     global $dir_hash_level;
  61.  
  62.     /* Remove trailing slash from $dir if found */
  63.     if (substr($dir-1== '/'{
  64.         $dir substr($dir0strlen($dir1);
  65.     }
  66.  
  67.     /* Compute the hash for this user and extract the hash directories. */
  68.     $hash_dirs computeHashDirs($username);
  69.  
  70.     /* First, get and make sure the full hash directory exists. */
  71.     $real_hash_dir getHashedDir($username$dir$hash_dirs);
  72.  
  73.     /* Set the value of our real data file, after we've removed unwanted characters. */
  74.     $datafile str_replace('/''_'$datafile);
  75.     $result "$real_hash_dir/$datafile";
  76.  
  77.     /* Check for this file in the real hash directory. */
  78.     if ($hash_search && !@file_exists($result)) {
  79.         /* First check the base directory, the most common location. */
  80.         if (@file_exists("$dir/$datafile")) {
  81.             rename("$dir/$datafile"$result);
  82.  
  83.         /* Then check the full range of possible hash directories. */
  84.         else {
  85.             $check_hash_dir $dir;
  86.             for ($h 0$h 4++$h{
  87.                 $check_hash_dir .= '/' $hash_dirs[$h];
  88.                 if (@is_readable("$check_hash_dir/$datafile")) {
  89.                     rename("$check_hash_dir/$datafile"$result);
  90.                     break;
  91.                 }
  92.             }
  93.         }
  94.     }
  95.  
  96.     /* Return the full hashed datafile path. */
  97.     return ($result);
  98. }
  99.  
  100. /**
  101.  * Helper function for getHashedFile, given a username returns the hashed
  102.  * dir for that username.
  103.  *
  104.  * @param string username the username of the current user
  105.  * @param string dir the squirrelmail datadir
  106.  * @param string hash_dirs default ''
  107.  * @return the path to the hash dir for username
  108.  */
  109. function getHashedDir($username$dir$hash_dirs ''{
  110.     global $dir_hash_level;
  111.  
  112.     /* Remove trailing slash from $dir if found */
  113.     if (substr($dir-1== '/'{
  114.         $dir substr($dir0strlen($dir1);
  115.     }
  116.  
  117.     /* If necessary, populate the hash dir variable. */
  118.     if ($hash_dirs == ''{
  119.         $hash_dirs computeHashDirs($username);
  120.     }
  121.  
  122.     /* Make sure the full hash directory exists. */
  123.     $real_hash_dir $dir;
  124.     for ($h 0$h $dir_hash_level++$h{
  125.         $real_hash_dir .= '/' $hash_dirs[$h];
  126.         if (!@is_dir($real_hash_dir)) {
  127.             if (!@mkdir($real_hash_dir0770)) {
  128.                 echo sprintf(_("Error creating directory %s.")$real_hash_dir'<br />' .
  129.                      _("Could not create hashed directory structure!""<br />\n" .
  130.                      _("Please contact your system administrator and report this error.""<br />\n";
  131.                 exit;
  132.             }
  133.         }
  134.     }
  135.  
  136.     /* And return that directory. */
  137.     return ($real_hash_dir);
  138. }
  139.  
  140. /**
  141.  * Helper function for getHashDir which does the actual hash calculation.
  142.  *
  143.  * @param string username the username to calculate the hash dir for
  144.  * @return array a list of hash dirs for this username
  145.  */
  146. function computeHashDirs($username{
  147.     /* Compute the hash for this user and extract the hash directories. */
  148.     $hash base_convert(crc32($username)1016);
  149.     $hash_dirs array();
  150.     for ($h 0$h 4++ $h{
  151.         $hash_dirs[substr($hash$h1);
  152.     }
  153.  
  154.     /* Return our array of hash directories. */
  155.     return ($hash_dirs);
  156. }
  157.  
  158. ?>

Documentation generated on Sat, 07 Oct 2006 16:33:04 +0300 by phpDocumentor 1.3.0RC6