X-Git-Url: https://vcs.fsf.org/?p=squirrelmail.git;a=blobdiff_plain;f=functions%2Fprefs.php;h=6aab8d8d24b39f781c401c67e4e70a26f3ab390f;hp=6962e6a585220d98a7cae5b262ae842aa76a3106;hb=4b4abf93a9624311afef0c385023724ee46a2b60;hpb=5f29dd3b476131f4cdadf71c0d6e076aec7afc60 diff --git a/functions/prefs.php b/functions/prefs.php index 6962e6a5..6aab8d8d 100644 --- a/functions/prefs.php +++ b/functions/prefs.php @@ -1,111 +1,183 @@ -"; - exit; - } - $file = fopen($filename, "r"); - - /** read in all the preferences **/ - for ($i=0; !feof($file); $i++) { - $pref[$i] = fgets($file, 1024); - if (substr($pref[$i], 0, strpos($pref[$i], "=")) == $string) { - $found = true; - $pos = $i; - } - } - fclose($file); - - $file = fopen($filename, "w"); - if ($found == true) { - for ($i=0; $i < count($pref); $i++) { - if ($i == $pos) { - fwrite($file, "$string=$set_to\n", 1024); - } else { - fwrite($file, "$pref[$i]", 1024); + + } + } + + /* Return the full hashed datafile path. */ + return ($result); +} + +/** + * Helper function for getHashedFile, given a username returns the hashed + * dir for that username. + * + * @param string username the username of the current user + * @param string dir the SquirrelMail datadir + * @param string hash_dirs default '' + * @return the path to the hash dir for username + * @since 1.2.0 + */ +function getHashedDir($username, $dir, $hash_dirs = '') { + global $dir_hash_level; + + /* Remove trailing slash from $dir if found */ + if (substr($dir, -1) == '/') { + $dir = substr($dir, 0, strlen($dir) - 1); + } + + /* If necessary, populate the hash dir variable. */ + if ($hash_dirs == '') { + $hash_dirs = computeHashDirs($username); + } + + /* Make sure the full hash directory exists. */ + $real_hash_dir = $dir; + for ($h = 0; $h < $dir_hash_level; ++$h) { + $real_hash_dir .= '/' . $hash_dirs[$h]; + if (!@is_dir($real_hash_dir)) { + if (!@mkdir($real_hash_dir, 0770)) { + echo sprintf(_("Error creating directory %s."), $real_hash_dir) . '
' . + _("Could not create hashed directory structure!") . "
\n" . + _("Please contact your system administrator and report this error.") . "
\n"; + exit; + } + } + } + + /* And return that directory. */ + return ($real_hash_dir); +} + +/** + * Helper function for getHashDir which does the actual hash calculation. + * + * @param string username the username to calculate the hash dir for + * @return array a list of hash dirs for this username + * @since 1.2.0 + */ +function computeHashDirs($username) { + /* Compute the hash for this user and extract the hash directories. */ + $hash = base_convert(crc32($username), 10, 16); + $hash_dirs = array(); + for ($h = 0; $h < 4; ++ $h) { + $hash_dirs[] = substr($hash, $h, 1); + } + + /* Return our array of hash directories. */ + return ($hash_dirs); +} + +/** + * Javascript support detection function + * @param boolean $reset recheck javascript support if set to true. + * @return integer SMPREF_JS_ON or SMPREF_JS_OFF ({@see functions/constants.php}) + * @since 1.5.1 + */ +function checkForJavascript($reset = FALSE) { + global $data_dir, $username, $javascript_on, $javascript_setting; + + if ( !$reset && sqGetGlobalVar('javascript_on', $javascript_on, SQ_SESSION) ) + return $javascript_on; + + if ( $reset || !isset($javascript_setting) ) + $javascript_setting = getPref($data_dir, $username, 'javascript_setting', SMPREF_JS_AUTODETECT); + + if ( !sqGetGlobalVar('new_js_autodetect_results', $js_autodetect_results) && + !sqGetGlobalVar('js_autodetect_results', $js_autodetect_results) ) + $js_autodetect_results = SMPREF_JS_OFF; + + if ( $javascript_setting == SMPREF_JS_AUTODETECT ) + $javascript_on = $js_autodetect_results; + else + $javascript_on = $javascript_setting; + + sqsession_register($javascript_on, 'javascript_on'); + return $javascript_on; +} + +?> \ No newline at end of file