$themename, 'dir' => $dir ); } } return $themes; } else return false; } /** * Get the site title from the options, and return it. * * @since 4.6 * @package all * @return string The site title. */ function get_sitetitle() { if (file_exists('data/settings/options.php')) { global $sitetitle; return $sitetitle; } } /** * Redirect the user to a given address after a number of seconds. * * @since 4.6 * @package all * @param string $url The redirect address. * @param integer $time The number of seconds before the redirect. */ function redirect($url, $time) { //Replace & with &. $url = str_replace('&', '&', $url); //Then, urlencode the entire url. $url = urlencode($url); //Then undo that for ? chars. $url = str_replace('%3F', '?', $url); //And undo that for = chars. $url = str_replace('%3D', '=', $url); //And undo that for & chars. $url = str_replace('%26', '&', $url); //And undo that for / chars. $url = str_replace('%2F', '/', $url); //And undo that for : chars. $url = str_replace('%3A', ':', $url); //Finally generate the metatag for redirecting echo ''; } /** * Read files or directories in a directory, and return the names in an array. * * @since 4.6 * @package all * @param string $directory The directory where the files are in. * @param string $mode Set to 'dirs' or 'files', to return directories or files respectively. * @return array The directories or files. */ function read_dir_contents($directory, $mode) { if (!is_dir($directory)) return false; $path = opendir($directory); while (false !== ($file = readdir($path))) { if ($file != '.' && $file != '..') { if (is_file($directory.'/'.$file)) $files[] = $file; elseif (is_dir($directory.'/'.$file)) $dirs[] = $file; } } closedir($path); if ($mode == 'files' && isset($files)) return $files; elseif ($mode == 'dirs' && isset($dirs)) return $dirs; else return false; } /** * Universal function for saving files. * * @since 4.7 * @package all * @param string $file Full patch to the file. * @param mixed $content The data to save. If it's an array, it will create the structure for you. * @param int $chmod With leading zero! If set to FALSE, no chmod operation is performed. */ function save_file($file, $content, $chmod = 0777) { $data = fopen($file, 'w'); //If it's an array, we have to create the structure. if (is_array($content) && !empty($content)) { $final_content = ' $value) { $final_content .= '$'.$var.' = \''.$value.'\';'."\n"; } $final_content .= '?>'; fputs($data, $final_content); } else fputs($data, $content); fclose($data); if ($chmod != FALSE) chmod($file, $chmod); } /** * Sanitize a variable, to make it ready for saving in a file. * * @since 4.7 * @package all * @param string $var The variable to sanitize. * @param boolean $html Should it convert HTML too? Defaults to true. * @return string The sanitized variable. */ function sanitize($var, $html = true) { $var = str_replace('\\', '\\\\', $var); $var = str_replace('\'', '\\\'', $var); $var = str_replace('<', '', $var); $var = str_replace('>', '', $var); if ($html == true) $var = htmlspecialchars($var, ENT_COMPAT, 'UTF-8', false); return $var; } /** * Sanitize a variable, to make it ready for saving in a file. * * @since 4.7 * @package all * @param string $var The variable to sanitize. * @param boolean $html Should it convert HTML too? Defaults to true. * @return string The sanitized variable. */ function sanitizePageContent($var, $html = true) { $var = str_replace('\\', '\\\\', $var); $var = str_replace('\'', '\\\'', $var); if ($html == true) $var = htmlspecialchars($var, ENT_COMPAT, 'UTF-8', false); return $var; } /** * PreventXSS from a URL, to make it ready for saving in a file. * * @since 4.7.5 * @package all * @param string $var The url to sanitize. * @return string The sanitized variable. */ function preventXSS($var) { $var = str_replace('\'', '', $var); $var = str_replace('<', '', $var); $var = str_replace('>', '', $var); $var = htmlspecialchars($var, ENT_COMPAT, 'UTF-8', false); return $var; } /** * latinOnlyInput from a URL, to make it ready for saving in a file. * * @since 4.7.5 * @package all * @param string $var Variable * @return string The sanitized variable. * * Added as bugfix for XSS and backdoor file upload found by s7acktrac3 */ function latinOnlyInput($var) { $var = str_replace(chr(0), '', $var); $var = preg_replace("/[^a-zA-Z0-9.\ \-_]+/", "", $var);; return $var; } /** * Displays or returns an error, notice or success message. * * @since 4.7 * @package all * @param string $message The message to display. * @param integer $level 1: error, 2: notice and 3: success. * @param bool $return Should it return the error? * @return string NOTE: Only returns when $return is true. */ function show_error($message, $level, $return = false) { switch ($level) { case 1: $class = 'error'; break; case 2: $class = 'notice'; break; case 3: $class = 'success'; break; default: $class = 'notice'; } $value = '