squirrelmail-webmail  1.4.22
About: SquirrelMail is a standards-based webmail package with strong MIME support, address books, and folder manipulation (written in PHP4).
  Fossies Dox: squirrelmail-webmail-1.4.22.tar.gz  ("inofficial" and yet experimental doxygen-generated source code documentation)  

prefs.php
Go to the documentation of this file.
1 <?php
2 
16 require_once(SM_PATH . 'functions/global.php');
17 require_once(SM_PATH . 'functions/plugin.php');
18 
20 include_once(SM_PATH . 'functions/display_messages.php');
21 
22 sqgetGlobalVar('prefs_cache', $prefs_cache, SQ_SESSION );
23 sqgetGlobalVar('prefs_are_cached', $prefs_are_cached, SQ_SESSION );
24 
25 $rg = ini_get('register_globals');
26 
27 if ( !sqsession_is_registered('prefs_are_cached') ||
28  !isset($prefs_cache) ||
29  !is_array($prefs_cache)
30  ) {
31  $prefs_are_cached = false;
32  $prefs_cache = array();
33 }
34 
35 $prefs_backend = do_hook_function('prefs_backend');
36 if (isset($prefs_backend) && !empty($prefs_backend) && file_exists(SM_PATH . $prefs_backend)) {
37  require_once(SM_PATH . $prefs_backend);
38 } elseif (isset($prefs_dsn) && !empty($prefs_dsn)) {
39  require_once(SM_PATH . 'functions/db_prefs.php');
40 } else {
41  require_once(SM_PATH . 'functions/file_prefs.php');
42 }
43 
44 /* Hashing functions */
45 
56 function getHashedFile($username, $dir, $datafile, $hash_search = true) {
57  global $dir_hash_level;
58 
59  /* Remove trailing slash from $dir if found */
60  if (substr($dir, -1) == '/') {
61  $dir = substr($dir, 0, strlen($dir) - 1);
62  }
63 
64  /* Compute the hash for this user and extract the hash directories. */
65  $hash_dirs = computeHashDirs($username);
66 
67  /* First, get and make sure the full hash directory exists. */
68  $real_hash_dir = getHashedDir($username, $dir, $hash_dirs);
69 
70  /* Set the value of our real data file, after we've removed unwanted characters. */
71  $datafile = str_replace('/', '_', $datafile);
72  $result = "$real_hash_dir/$datafile";
73 
74  /* Check for this file in the real hash directory. */
75  if ($hash_search && !@file_exists($result)) {
76  /* First check the base directory, the most common location. */
77  if (@file_exists("$dir/$datafile")) {
78  rename("$dir/$datafile", $result);
79 
80  /* Then check the full range of possible hash directories. */
81  } else {
82  $check_hash_dir = $dir;
83  for ($h = 0; $h < 4; ++$h) {
84  $check_hash_dir .= '/' . $hash_dirs[$h];
85  if (@is_readable("$check_hash_dir/$datafile")) {
86  rename("$check_hash_dir/$datafile", $result);
87  break;
88  }
89  }
90  }
91  }
92 
93  /* Return the full hashed datafile path. */
94  return ($result);
95 }
96 
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($dir, 0, strlen($dir) - 1);
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_dir, 0770)) {
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 
147  /* Compute the hash for this user and extract the hash directories. */
148  /* Note that the crc32() function result will be different on 32 and */
149  /* 64 bit systems, thus the hack below. */
150  $crc = crc32($username);
151  if ($crc & 0x80000000) {
152  $crc ^= 0xffffffff;
153  $crc += 1;
154  }
155  $hash = base_convert($crc, 10, 16);
156  $hash_dirs = array();
157  for ($h = 0; $h < 4; ++ $h) {
158  $hash_dirs[] = substr($hash, $h, 1);
159  }
160 
161  /* Return our array of hash directories. */
162  return ($hash_dirs);
163 }
164 
elseif
if(! sqgetGlobalVar('sound', $sound, SQ_GET)) elseif($sound=='(none)')
Definition: testsound.php:25
sqgetGlobalVar
sqgetGlobalVar($name, &$value, $search=SQ_INORDER)
Definition: global.php:344
SQ_SESSION
const SQ_SESSION
Definition: global.php:18
sprintf
powered by Systran sprintf(_("Number of supported language pairs: %s"), '36').' '
Definition: options.php:107
$username
global $username
Definition: validate.php:55
$rg
$rg
Definition: prefs.php:25
$prefs_cache
if(!include_once('DB.php')) global $prefs_cache
Definition: db_prefs.php:39
computeHashDirs
computeHashDirs($username)
Definition: prefs.php:146
$prefs_dsn
$prefs_dsn
Definition: config_default.php:970
getHashedDir
getHashedDir($username, $dir, $hash_dirs='')
Definition: prefs.php:109
sqsession_is_registered
sqsession_is_registered($name)
Definition: global.php:318
do_hook_function
do_hook_function($name, $parm=NULL)
Definition: plugin.php:69
$prefs_backend
if(!sqsession_is_registered('prefs_are_cached')||!isset($prefs_cache)||!is_array($prefs_cache)) $prefs_backend
Definition: prefs.php:35
exit
exit
Definition: help.php:128
SM_PATH
const SM_PATH
Definition: decrypt_headers.php:16
_
_($str)
Definition: gettext.php:160
getHashedFile
getHashedFile($username, $dir, $datafile, $hash_search=true)
Definition: prefs.php:56
$dir_hash_level
$dir_hash_level
Definition: config_default.php:530
$prefs_are_cached
if(!include_once('DB.php')) global $prefs_are_cached
Definition: db_prefs.php:39