whitespace consistency

This commit is contained in:
Shish 2012-03-09 22:27:12 +00:00
parent eb8c15b9a0
commit f9910ba98f
4 changed files with 94 additions and 139 deletions

View File

@ -113,7 +113,7 @@ Copyright (C) <a href="'.$this->sitedomain.'">'.$this->sitename.'</a><br />
log_info("mail", "Error sending message '$this->subject' to '$this->to'"); log_info("mail", "Error sending message '$this->subject' to '$this->to'");
} }
return $sent; return $sent;
} }
} }
?> ?>

View File

@ -300,8 +300,7 @@ class Page {
* This function returns FALSE if it failed to cache the files, * This function returns FALSE if it failed to cache the files,
* and returns TRUE if it was successful. * and returns TRUE if it was successful.
*/ */
private function add_cached_auto_html_headers() private function add_cached_auto_html_headers() {
{
global $config; global $config;
// store local copy for speed. // store local copy for speed.
@ -326,8 +325,7 @@ class Page {
$data_href = get_base_href(); $data_href = get_base_href();
/* ----- CSS Files ----- */ /* ----- CSS Files ----- */
if ($autocache_css) if($autocache_css) {
{
// First get all the CSS from the lib directory // First get all the CSS from the lib directory
$contents_from_lib = ''; $contents_from_lib = '';
$css_files = glob("lib/*.css"); $css_files = glob("lib/*.css");
@ -358,7 +356,7 @@ class Page {
$data = $contents_from_lib .' '. $contents_from_extensions; $data = $contents_from_lib .' '. $contents_from_extensions;
// Minify the CSS if enabled. // Minify the CSS if enabled.
if ($config->get_bool("autocache_min_css")){ if($config->get_bool("autocache_min_css")) {
// not supported yet. // not supported yet.
// TODO: add support for Minifying CSS files. // TODO: add support for Minifying CSS files.
} }
@ -366,19 +364,20 @@ class Page {
// compute the MD5 sum of the concatenated CSS files // compute the MD5 sum of the concatenated CSS files
$md5sum = md5($data); $md5sum = md5($data);
if (!file_exists($cache_location.$md5sum.'.css')) { if(!file_exists($cache_location.$md5sum.'.css')) {
// remove any old cached CSS files. // remove any old cached CSS files.
$mask = '*.css'; $mask = '*.css';
array_map( 'unlink', glob( $mask ) ); array_map( 'unlink', glob( $mask ) );
// output the combined file // output the combined file
if (file_put_contents($cache_location.$md5sum.'.css', $data, LOCK_EX) === FALSE) { if(file_put_contents($cache_location.$md5sum.'.css', $data, LOCK_EX) === FALSE) {
return false; // failed to write the file return false; // failed to write the file
} }
} }
// tell the client where to get the css cache file // tell the client where to get the css cache file
$this->add_html_header('<link rel="stylesheet" href="'.$data_href.'/'.$cache_location.$md5sum.'.css" type="text/css">'); $this->add_html_header('<link rel="stylesheet" href="'.$data_href.'/'.$cache_location.$md5sum.'.css" type="text/css">');
} else { }
else {
// Caching of CSS disabled. // Caching of CSS disabled.
foreach(glob("lib/*.css") as $css) { foreach(glob("lib/*.css") as $css) {
$this->add_html_header('<link rel="stylesheet" href="'.$data_href.'/'.$css.'" type="text/css">'); $this->add_html_header('<link rel="stylesheet" href="'.$data_href.'/'.$css.'" type="text/css">');
@ -393,8 +392,7 @@ class Page {
/* ----- JavaScript Files ----- */ /* ----- JavaScript Files ----- */
if ($autocache_js) if($autocache_js) {
{
$data = ''; $data = '';
$js_files = glob("lib/*.js"); $js_files = glob("lib/*.js");
if($js_files) { if($js_files) {
@ -428,7 +426,8 @@ class Page {
} }
// tell the client where to get the js cache file // tell the client where to get the js cache file
$this->add_html_header('<script src="'.$data_href.'/'.$cache_location.$md5sum.'.js" type="text/javascript"></script>'); $this->add_html_header('<script src="'.$data_href.'/'.$cache_location.$md5sum.'.js" type="text/javascript"></script>');
} else { }
else {
// Caching of Javascript disabled. // Caching of Javascript disabled.
foreach(glob("lib/*.js") as $js) { foreach(glob("lib/*.js") as $js) {
$this->add_html_header('<script src="'.$data_href.'/'.$js.'" type="text/javascript"></script>'); $this->add_html_header('<script src="'.$data_href.'/'.$js.'" type="text/javascript"></script>');
@ -443,6 +442,5 @@ class Page {
return true; return true;
} }
} }
?> ?>

View File

@ -146,15 +146,14 @@ function autodate($date, $html=true) {
* *
* @retval boolean * @retval boolean
*/ */
function isValidDateTime($dateTime) function isValidDateTime($dateTime) {
{ if (preg_match("/^(\d{4})-(\d{2})-(\d{2}) ([01][0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9])$/", $dateTime, $matches)) {
if (preg_match("/^(\d{4})-(\d{2})-(\d{2}) ([01][0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9])$/", $dateTime, $matches)) { if (checkdate($matches[2], $matches[3], $matches[1])) {
if (checkdate($matches[2], $matches[3], $matches[1])) { return true;
return true; }
} }
}
return false; return false;
} }
/** /**
@ -162,16 +161,15 @@ function isValidDateTime($dateTime)
* *
* @retval boolean * @retval boolean
*/ */
function isValidDate($date) function isValidDate($date) {
{ if (preg_match("/^(\d{4})-(\d{2})-(\d{2})$/", $date, $matches)) {
if (preg_match("/^(\d{4})-(\d{2})-(\d{2})$/", $date, $matches)) {
// checkdate wants (month, day, year) // checkdate wants (month, day, year)
if (checkdate($matches[2], $matches[3], $matches[1])) { if (checkdate($matches[2], $matches[3], $matches[1])) {
return true; return true;
} }
} }
return false; return false;
} }
/** /**
@ -420,10 +418,11 @@ function captcha_check() {
$rpk = $config->get_string('api_recaptcha_pubkey'); $rpk = $config->get_string('api_recaptcha_pubkey');
if(!empty($rpk)) { if(!empty($rpk)) {
$resp = recaptcha_check_answer( $resp = recaptcha_check_answer(
$rpk, $rpk,
$_SERVER["REMOTE_ADDR"], $_SERVER["REMOTE_ADDR"],
$_POST["recaptcha_challenge_field"], $_POST["recaptcha_challenge_field"],
$_POST["recaptcha_response_field"]); $_POST["recaptcha_response_field"]
);
if(!$resp->is_valid) { if(!$resp->is_valid) {
log_info("core", "Captcha failed (ReCaptcha): " . $resp->error); log_info("core", "Captcha failed (ReCaptcha): " . $resp->error);
@ -548,21 +547,16 @@ function get_memory_limit() {
*/ */
$memory = parse_shorthand_int(ini_get("memory_limit")); $memory = parse_shorthand_int(ini_get("memory_limit"));
if ($memory == -1) { if($memory == -1) {
// No memory limit. // No memory limit.
// Return the larger of the set limits. // Return the larger of the set limits.
if ($shimmie_limit > $default_limit) { return max($shimmie_limit, $default_limit);
return $shimmie_limit; }
} else { else {
return $default_limit; // return the default memory limit
}
} else {
// PHP has a memory limit set. // PHP has a memory limit set.
if ($shimmie_limit > $memory) { if ($shimmie_limit > $memory) {
// Shimmie wants more memory than what PHP is currently set for. // Shimmie wants more memory than what PHP is currently set for.
// Attempt to set PHP's memory limit. // Attempt to set PHP's memory limit.
if ( ini_set("memory_limit", $shimmie_limit) === FALSE ) { if ( ini_set("memory_limit", $shimmie_limit) === FALSE ) {
/* We can't change PHP's limit, oh well, return whatever its currently set to */ /* We can't change PHP's limit, oh well, return whatever its currently set to */
@ -570,7 +564,7 @@ function get_memory_limit() {
} }
$memory = parse_shorthand_int(ini_get("memory_limit")); $memory = parse_shorthand_int(ini_get("memory_limit"));
} }
// PHP's memory limit is more than Shimmie needs. // PHP's memory limit is more than Shimmie needs.
return $memory; // return the current setting return $memory; // return the current setting
} }
@ -583,10 +577,10 @@ function get_memory_limit() {
* @retval string * @retval string
*/ */
function get_session_ip(Config $config) { function get_session_ip(Config $config) {
$mask = $config->get_string("session_hash_mask", "255.255.0.0"); $mask = $config->get_string("session_hash_mask", "255.255.0.0");
$addr = $_SERVER['REMOTE_ADDR']; $addr = $_SERVER['REMOTE_ADDR'];
$addr = inet_ntop(inet_pton($addr) & inet_pton($mask)); $addr = inet_ntop(inet_pton($addr) & inet_pton($mask));
return $addr; return $addr;
} }
/** /**
@ -826,18 +820,18 @@ function ip_in_range($IP, $CIDR) {
*/ */
function deltree($f) { function deltree($f) {
//Because Windows (I know, bad excuse) //Because Windows (I know, bad excuse)
if (PHP_OS === 'WINNT') { if(PHP_OS === 'WINNT') {
$real = realpath($f); $real = realpath($f);
$path = realpath('./').'\\'.str_replace('/', '\\', $f); $path = realpath('./').'\\'.str_replace('/', '\\', $f);
if ($path != $real) { if($path != $real) {
rmdir($path); rmdir($path);
} }
else else {
{
foreach(glob($f.'/*') as $sf) { foreach(glob($f.'/*') as $sf) {
if (is_dir($sf) && !is_link($sf)) { if (is_dir($sf) && !is_link($sf)) {
deltree($sf); deltree($sf);
} else { }
else {
unlink($sf); unlink($sf);
} }
} }
@ -852,7 +846,8 @@ function deltree($f) {
foreach(glob($f.'/*') as $sf) { foreach(glob($f.'/*') as $sf) {
if (is_dir($sf) && !is_link($sf)) { if (is_dir($sf) && !is_link($sf)) {
deltree($sf); deltree($sf);
} else { }
else {
unlink($sf); unlink($sf);
} }
} }
@ -981,7 +976,8 @@ function get_debug_info() {
if($config->get_string("commit_hash", "unknown") == "unknown"){ if($config->get_string("commit_hash", "unknown") == "unknown"){
$commit = ""; $commit = "";
}else{ }
else {
$commit = " (".$config->get_string("commit_hash").")"; $commit = " (".$config->get_string("commit_hash").")";
} }
$time = sprintf("%5.2f", microtime(true) - $_load_start); $time = sprintf("%5.2f", microtime(true) - $_load_start);
@ -998,53 +994,6 @@ function get_debug_info() {
return $debug; return $debug;
} }
// print_obj ($object, $title, $return)
function print_obj($object,$title="Object Information", $return=false) {
global $user;
if(DEBUG && isset($_GET['DEBUG']) && $user->can("override_config")) {
$pr = print_r($object,true);
$count = substr_count($pr,"\n")<=25?substr_count($pr,"\n"):25;
$pr = "<textarea rows='".$count."' cols='80'>$pr</textarea>";
if($return) {
return $pr;
} else {
global $page;
$page->add_block(new Block($title,$pr,"main",1000));
return true;
}
}
}
// preset tests.
// Prints the contents of $event->args, even though they are clearly visible in
// the URL bar.
function print_url_args() {
global $event;
print_obj($event->args,"URL Arguments");
}
// Prints all the POST data.
function print_POST() {
print_obj($_POST,"\$_POST");
}
// Prints GET, though this is also visible in the url ( url?var&var&var)
function print_GET() {
print_obj($_GET,"\$_GET");
}
$_last_time = microtime(true);
$_last_msg = null;
function timeline($text) {
if(empty($_GET["timeline"])) return;
global $_last_time, $_last_msg;
$time = microtime(true);
if($_last_msg) printf("TL: %s (%dms)<br>", $_last_msg, (int)(($time-$_last_time)*1000));
$_last_time = $time;
$_last_msg = $text;
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\
* Request initialisation stuff * * Request initialisation stuff *

View File

@ -59,34 +59,34 @@ require_once __SHIMMIE_ROOT__."core/util.inc.php";
require_once __SHIMMIE_ROOT__."core/exceptions.class.php"; require_once __SHIMMIE_ROOT__."core/exceptions.class.php";
require_once __SHIMMIE_ROOT__."core/database.class.php"; require_once __SHIMMIE_ROOT__."core/database.class.php";
// repair console {{{
/* /*
* This file lets anyone destroy the database -- disable it * This file lets anyone destroy the database -- disable it
* as soon as the admin is done installing for the first time * as soon as the admin is done installing for the first time
*/ */
if(is_readable("config.php")) { if(is_readable("config.php")) {
session_start(); session_start();
?> echo '<div id="iblock">';
<div id="iblock"> echo '<h1>Shimmie Repair Console</h1>';
<h1>Shimmie Repair Console</h1>
<?php
// Load the config // Load the config
require_once __SHIMMIE_ROOT__."config.php"; // Load user/site specifics First require_once __SHIMMIE_ROOT__."config.php"; // Load user/site specifics First
require_once __SHIMMIE_ROOT__."core/default_config.inc.php"; // Defaults for the rest. require_once __SHIMMIE_ROOT__."core/default_config.inc.php"; // Defaults for the rest.
if ( if(
( array_key_exists('dsn', $_SESSION) && $_SESSION['dsn'] === DATABASE_DSN ) || (array_key_exists('dsn', $_SESSION) && $_SESSION['dsn'] === DATABASE_DSN) ||
( array_key_exists('dsn', $_POST) && $_POST['dsn'] === DATABASE_DSN ) (array_key_exists('dsn', $_POST) && $_POST['dsn'] === DATABASE_DSN)
) ) {
{ if (array_key_exists('dsn', $_POST) && !empty($_POST['dsn'])) {
if ( array_key_exists('dsn', $_POST) && !empty($_POST['dsn']) )
{
$_SESSION['dsn'] = $_POST['dsn']; $_SESSION['dsn'] = $_POST['dsn'];
} }
if(empty($_GET["action"])) { if(empty($_GET["action"])) {
echo "<h3>Basic Checks</h3>"; echo "
echo "If these checks fail, something is broken; if they all pass, "; <h3>Basic Checks</h3>
echo "something <i>might</i> be broken, just not checked for..."; If these checks fail, something is broken; if they all pass,
something <i>might</i> be broken, just not checked for...
";
eok("Images writable", is_writable("images")); eok("Images writable", is_writable("images"));
eok("Thumbs writable", is_writable("thumbs")); eok("Thumbs writable", is_writable("thumbs"));
eok("Data writable", is_writable("data")); eok("Data writable", is_writable("data"));
@ -105,8 +105,8 @@ if(is_readable("config.php")) {
"; ";
*/ */
echo "<h3>Log Out</h3>";
echo " echo "
<h3>Log Out</h3>
<form action='install.php?action=logout' method='POST'> <form action='install.php?action=logout' method='POST'>
<input type='submit' value='Leave'> <input type='submit' value='Leave'>
</form> </form>
@ -116,7 +116,8 @@ if(is_readable("config.php")) {
session_destroy(); session_destroy();
echo "<h3>Logged Out</h3><p>You have been logged out.</p><a href='index.php'>Main Shimmie Page</a>"; echo "<h3>Logged Out</h3><p>You have been logged out.</p><a href='index.php'>Main Shimmie Page</a>";
} }
} else { }
else {
echo " echo "
<h3>Login</h3> <h3>Login</h3>
<p>Enter the database DSN exactly as in config.php (ie, as originally installed) to access advanced recovery tools:</p> <p>Enter the database DSN exactly as in config.php (ie, as originally installed) to access advanced recovery tools:</p>
@ -134,6 +135,7 @@ if(is_readable("config.php")) {
echo "\t\t</div>"; echo "\t\t</div>";
exit; exit;
} }
// }}}
do_install(); do_install();
@ -205,15 +207,19 @@ function begin() { // {{{
$dberr = ""; $dberr = "";
if(check_gd_version() == 0 && check_im_version() == 0) { if(check_gd_version() == 0 && check_im_version() == 0) {
$thumberr = "<p>PHP's GD extension seems to be missing, ". $thumberr = "
"and imagemagick's \"convert\" command cannot be found - ". <p>PHP's GD extension seems to be missing,
"no thumbnailing engines are available."; and imagemagick's \"convert\" command cannot be found -
no thumbnailing engines are available.
";
} }
if(!function_exists("mysql_connect")) { if(!function_exists("mysql_connect")) {
$dberr = "<p>PHP's MySQL extension seems to be missing; you may ". $dberr = "
"be able to use an unofficial alternative, checking ". <p>PHP's MySQL extension seems to be missing; you may
"for libraries..."; be able to use an unofficial alternative, checking
for libraries...
";
if(!function_exists("pg_connect")) { if(!function_exists("pg_connect")) {
$dberr .= "<br>PgSQL is missing"; $dberr .= "<br>PgSQL is missing";
} }
@ -378,15 +384,17 @@ function build_dirs() { // {{{
if(!is_writable("data") ) @chmod("data", 0755); if(!is_writable("data") ) @chmod("data", 0755);
if( if(
!file_exists("images") || !file_exists("thumbs") || !file_exists("data") || !file_exists("images") || !file_exists("thumbs") || !file_exists("data") ||
!is_writable("images") || !is_writable("thumbs") || !is_writable("data") !is_writable("images") || !is_writable("thumbs") || !is_writable("data")
) { ) {
print "<p>Shimmie needs three folders in it's directory, 'images', 'thumbs', and 'data', print "
and they need to be writable by the PHP user.</p> <p>Shimmie needs three folders in it's directory, 'images', 'thumbs', and 'data',
<p>If you see this error, if probably means the folders are owned by you, and they need to be and they need to be writable by the PHP user.</p>
writable by the web server.</p> <p>If you see this error, if probably means the folders are owned by you, and they need to be
<p>PHP reports that it is currently running as user: ".$_ENV["USER"]." (". $_SERVER["USER"] .")</p> writable by the web server.</p>
<p>Once you have created these folders and/or changed the ownership of the shimmie folder, hit 'refresh' to continue.</p>"; <p>PHP reports that it is currently running as user: ".$_ENV["USER"]." (". $_SERVER["USER"] .")</p>
<p>Once you have created these folders and / or changed the ownership of the shimmie folder, hit 'refresh' to continue.</p>
";
exit; exit;
} }
} // }}} } // }}}
@ -401,14 +409,14 @@ function write_config() { // {{{
else { else {
$h_file_content = htmlentities($file_content); $h_file_content = htmlentities($file_content);
print <<<EOD print <<<EOD
The web server isn't allowed to write to the config file; please copy The web server isn't allowed to write to the config file; please copy
the text below, save it as 'config.php', and upload it into the shimmie the text below, save it as 'config.php', and upload it into the shimmie
folder manually. Make sure that when you save it, there is no whitespace folder manually. Make sure that when you save it, there is no whitespace
before the "&lt;?php" or after the "?&gt;" before the "&lt;?php" or after the "?&gt;"
<p><textarea cols="80" rows="2">$file_content</textarea> <p><textarea cols="80" rows="2">$file_content</textarea>
<p>One done, <a href='index.php'>Continue</a> <p>One done, <a href='index.php'>Continue</a>
EOD; EOD;
exit; exit;
} }