From: Jerome Jutteau Date: Fri, 7 Dec 2012 20:41:43 +0000 (+0000) Subject: code reformating X-Git-Tag: 1.0~28 X-Git-Url: https://git.p6c8.net/jirafeau_project.git/commitdiff_plain/3cf8b39b331dd5f80c4ac674d13a6387d01d49b9?ds=sidebyside code reformating --- diff --git a/file.php b/file.php index edf0199..32c097f 100644 --- a/file.php +++ b/file.php @@ -17,124 +17,136 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ +define ('JIRAFEAU_ROOT', dirname (__FILE__) . '/'); -define('JIRAFEAU_ROOT', dirname(__FILE__) . '/'); +require (JIRAFEAU_ROOT.'lib/config.php'); +require (JIRAFEAU_ROOT.'lib/settings.php'); +require (JIRAFEAU_ROOT.'lib/functions.php'); -require(JIRAFEAU_ROOT . 'lib/config.php'); -require(JIRAFEAU_ROOT . 'lib/settings.php'); -require(JIRAFEAU_ROOT . 'lib/functions.php'); +if (isset ($_GET['h']) && !empty ($_GET['h'])) +{ + $link_name = $_GET['h']; -if(isset($_GET['h']) && !empty($_GET['h'])) { - $link_name = $_GET['h']; + $delete_code = ''; + if (isset ($_GET['d']) && !empty ($_GET['d'])) + $delete_code = $_GET['d']; - $delete_code = ''; - if(isset($_GET['d']) && !empty($_GET['d'])) - $delete_code = $_GET['d']; + if (!ereg ('[0-9a-f]{32}$', $link_name)) + { + header ("HTTP/1.0 404 Not Found"); - if(!ereg('[0-9a-f]{32}$', $link_name)) { - header("HTTP/1.0 404 Not Found"); - - require(JIRAFEAU_ROOT . 'lib/template/header.php'); - echo '

Error 404: Not Found

'; - require(JIRAFEAU_ROOT . 'lib/template/footer.php'); - exit; - } - - $link_file = VAR_LINKS . $link_name; - if(file_exists($link_file)) { - $content = file($link_file); - $file_name = trim($content[0]); - $mime_type = trim($content[1]); - $file_size = trim($content[2]); - $key = trim($content[3], NL); - $time = trim($content[4]); - $md5 = trim($content[5]); - $onetime = trim($content[6]); - $link_code = trim($content[9]); - - - - if(!file_exists(VAR_FILES . $md5)) { - jirafeau_delete($link_name); - require(JIRAFEAU_ROOT . 'lib/template/header.php'); - echo '

' . _('File not available.') . '

'; - require(JIRAFEAU_ROOT . 'lib/template/footer.php'); - exit; + require (JIRAFEAU_ROOT.'lib/template/header.php'); + echo '

Error 404: Not Found

'; + require (JIRAFEAU_ROOT.'lib/template/footer.php'); + exit; } - if(!empty($delete_code) && $delete_code == $link_code) { - jirafeau_delete($link_name); - require(JIRAFEAU_ROOT . 'lib/template/header.php'); - echo '

' . _('File has been deleted.') . '

'; - require(JIRAFEAU_ROOT . 'lib/template/footer.php'); - exit; - } + $link_file = VAR_LINKS.$link_name; + if (file_exists ($link_file)) + { + $content = file ($link_file); + $file_name = trim ($content[0]); + $mime_type = trim ($content[1]); + $file_size = trim ($content[2]); + $key = trim ($content[3], NL); + $time = trim ($content[4]); + $md5 = trim ($content[5]); + $onetime = trim ($content[6]); + $link_code = trim ($content[9]); + + if (!file_exists (VAR_FILES.$md5)) + { + jirafeau_delete ($link_name); + require (JIRAFEAU_ROOT.'lib/template/header.php'); + echo '

'._('File not available.'). + '

'; + require (JIRAFEAU_ROOT.'lib/template/footer.php'); + exit; + } - if($time != JIRAFEAU_INFINITY && time() > $time) { - jirafeau_delete($link_name); - require(JIRAFEAU_ROOT . 'lib/template/header.php'); - echo '

' . _('The time limit of this file has expired. It has been deleted.') . '

'; - require(JIRAFEAU_ROOT . 'lib/template/footer.php'); - exit; - } + if (!empty ($delete_code) && $delete_code == $link_code) + { + jirafeau_delete ($link_name); + require (JIRAFEAU_ROOT.'lib/template/header.php'); + echo '

'._('File has been deleted.'). + '

'; + require (JIRAFEAU_ROOT.'lib/template/footer.php'); + exit; + } - if(!empty($key)) { - if(!isset($_POST['key'])) { - require(JIRAFEAU_ROOT . 'lib/template/header.php'); -?> -
-
- -
- - - - - - - - -
-
-
-
- $time) + { + jirafeau_delete ($link_name); + require (JIRAFEAU_ROOT.'lib/template/header.php'); + echo '

'. + _('The time limit of this file has expired.' . + 'It has been deleted.') . '

'; + require (JIRAFEAU_ROOT.'lib/template/footer.php'); + exit; + } - require(JIRAFEAU_ROOT . 'lib/template/header.php'); - echo '

Error 403: Forbidden

'; - require(JIRAFEAU_ROOT . 'lib/template/footer.php'); - exit; + if (!empty ($key)) + { + if (!isset ($_POST['key'])) + { + require (JIRAFEAU_ROOT.'lib/template/header.php'); + ?>
+
" method = + "post"> " />
+ +
" + />
+

Error 403: Forbidden

'; + require (JIRAFEAU_ROOT.'lib/template/footer.php'); + exit; + } + } } - } - } - header('Content-Length: ' . $file_size); - header('Content-Type: ' . $mime_type); - if(!jirafeau_is_viewable($mime_type)) { - header('Content-Disposition: attachment; filename="' . $file_name . '"'); - } - readfile(VAR_FILES . $md5); + header ('Content-Length: ' . $file_size); + header ('Content-Type: ' . $mime_type); + if (!jirafeau_is_viewable ($mime_type)) + { + header ('Content-Disposition: attachment; filename="' . + $file_name . '"'); + } + readfile (VAR_FILES.$md5); - if($onetime == 'O') { - jirafeau_delete($link_name); + if ($onetime == 'O') + jirafeau_delete ($link_name); + exit; } - exit; - } else { - header("HTTP/1.0 404 Not Found"); + else + { + header ("HTTP/1.0 404 Not Found"); - require(JIRAFEAU_ROOT . 'lib/template/header.php'); - echo '

Error 404: Not Found

'; - require(JIRAFEAU_ROOT . 'lib/template/footer.php'); + require (JIRAFEAU_ROOT.'lib/template/header.php'); + echo '

Error 404: Not Found

'; + require (JIRAFEAU_ROOT.'lib/template/footer.php'); + exit; + } +} +else +{ + header ('Location: '.$cfg['web_root']); exit; - } -} else { - header('Location: ' . $cfg['web_root']); - exit; } ?> diff --git a/index.php b/index.php index 9e1222c..41a0d5f 100644 --- a/index.php +++ b/index.php @@ -17,134 +17,145 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ +define ('JIRAFEAU_ROOT', dirname (__FILE__) . '/'); +define ('DEBUG', true); -define('JIRAFEAU_ROOT', dirname(__FILE__) . '/'); -define('DEBUG', true); - -require(JIRAFEAU_ROOT . 'lib/config.php'); -require(JIRAFEAU_ROOT . 'lib/settings.php'); -require(JIRAFEAU_ROOT . 'lib/functions.php'); +require (JIRAFEAU_ROOT . 'lib/config.php'); +require (JIRAFEAU_ROOT . 'lib/settings.php'); +require (JIRAFEAU_ROOT . 'lib/functions.php'); /* check if the destination dirs are writable */ -$writable = is_writable(VAR_FILES) && is_writable(VAR_LINKS); - -$res = array(); -if($writable && isset($_POST['jirafeau'])) { - - $key = $_POST['key']; - - $time = time(); - switch($_POST['time']) { - case 'minute': - $time += JIRAFEAU_MINUTE; - break; - case 'hour': - $time += JIRAFEAU_HOUR; - break; - case 'day': - $time += JIRAFEAU_DAY; - break; - case 'week': - $time += JIRAFEAU_WEEK; - break; - case 'month': - $time += JIRAFEAU_MONTH; - break; - default: - $time = JIRAFEAU_INFINITY; - break; - } - - $res = jirafeau_upload($_FILES['file'], isset($_POST['one_time_download']), $key, $time, $cfg, $_SERVER['REMOTE_ADDR']); +$writable = is_writable (VAR_FILES) && is_writable (VAR_LINKS); + +$res = array (); +if ($writable && isset ($_POST['jirafeau'])) +{ + + $key = $_POST['key']; + + $time = time (); + switch ($_POST['time']) + { + case 'minute': + $time += JIRAFEAU_MINUTE; + break; + case 'hour': + $time += JIRAFEAU_HOUR; + break; + case 'day': + $time += JIRAFEAU_DAY; + break; + case 'week': + $time += JIRAFEAU_WEEK; + break; + case 'month': + $time += JIRAFEAU_MONTH; + break; + default: + $time = JIRAFEAU_INFINITY; + break; + } + + $res = + jirafeau_upload ($_FILES['file'], isset ($_POST['one_time_download']), + $key, $time, $cfg, $_SERVER['REMOTE_ADDR']); } -require(JIRAFEAU_ROOT . 'lib/template/header.php'); +require (JIRAFEAU_ROOT.'lib/template/header.php'); /* Checking for errors. */ -if(!is_writable(VAR_FILES)) { - add_error (_('The file directory is not writable!'), VAR_FILES); -} +if (!is_writable (VAR_FILES)) + add_error (_('The file directory is not writable!'), VAR_FILES); -if(!is_writable(VAR_LINKS)) { - add_error (_('The link directory is not writable!'), VAR_LINKS); -} +if (!is_writable (VAR_LINKS)) + add_error (_('The link directory is not writable!'), VAR_LINKS); /* Check if the install.php script is still in the directory. */ -if (file_exists(JIRAFEAU_ROOT . 'install.php')) { - add_error (_('Installer script still present'), - _('Please make sure to delete the installer script "install.php" before continuing.')); -} - -if(!has_error() && !empty($res)) { - if($res['error']['has_error']) { - add_error (_('An error occurred.'), $res['error']['why']); - } else { - $link = $cfg['web_root']; - $delete_link = $cfg['web_root']; - - if($cfg['rewrite']) { - $link .= 'file-' . $res['link']; - $delete_link .= 'file-' . $res['link'] . '-delete-' . $res['delete_link']; - } else { - $link .= 'file.php?h=' . $res['link']; // h because 'h' looks like a jirafeau ;) - $delete_link .= 'file.php?h=' . $res['link'] . '&d=' . $res['delete_link']; +if (file_exists (JIRAFEAU_ROOT . 'install.php')) + add_error (_('Installer script still present'), + _('Please make sure to delete the installer script ' . + '"install.php" before continuing.')); + +if (!has_error () && !empty ($res)) +{ + if ($res['error']['has_error']) + add_error (_('An error occurred.'), $res['error']['why']); + else + { + $link = $cfg['web_root']; + $delete_link = $cfg['web_root']; + + if ($cfg['rewrite']) + { + $link .= 'file-'.$res['link']; + $delete_link .= + 'file-'.$res['link'].'-delete-'.$res['delete_link']; + } + else + { + /* h because 'h' looks like a jirafeau ;) */ + $link .= 'file.php?h='.$res['link']; + $delete_link .= + 'file.php?h='.$res['link'].'&d='.$res['delete_link']; + } + + echo '
'.NL; + echo '

'._('File uploaded! Copy the following URL to get it:'). + '
' . NL; + echo ''.$link.'' . NL; + + if ($time != JIRAFEAU_INFINITY) + { + echo '
'._('This file is valid until the following date:') . + '
' . strftime ('%c', $time) . ''; + } + + echo '

'; + + echo '
' . NL; + echo '

' . _('Keep the following URL to delete it:') . '
' . NL; + echo '' . $delete_link . '' . NL; + echo '

'; } - - echo '
' . NL; - echo '

' . _('File uploaded! Copy the following URL to get it:') . '
' . NL; - echo '' . $link . '' . NL; - - if($time != JIRAFEAU_INFINITY) { - echo '
' . _('This file is valid until the following date:') . '
' . strftime('%c' ,$time) . ''; - } - - echo '

'; - - echo '
' . NL; - echo '

' . _('Keep the following URL to delete it:') . '
' . NL; - echo '' . $delete_link . '' . NL; - echo '

'; - } } -if(has_error ()) { +if (has_error ()) show_errors (); -} -if(!has_error () && $writable) { -?> - -
-
-
-
- -

-

-

- -
- -
-

-

-

- -

-
-
-
-
- -
+
+

" />

+

+

+

diff --git a/install.php b/install.php index d313684..8a34477 100644 --- a/install.php +++ b/install.php @@ -16,46 +16,53 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ +define ('JIRAFEAU_ROOT', dirname (__FILE__) . '/'); +define ('NL', "\n"); +define ('QUOTE', "'"); -define('JIRAFEAU_ROOT', dirname(__FILE__) . '/'); -define('NL', "\n"); -define('QUOTE', "'"); +define ('JIRAFEAU_CFG', JIRAFEAU_ROOT.'lib/config.local.php'); +define ('JIRAFEAU_VAR_RAND_LENGTH', 15); -define('JIRAFEAU_CFG', JIRAFEAU_ROOT . 'lib/config.local.php'); -define('JIRAFEAU_VAR_RAND_LENGTH', 15); +require (JIRAFEAU_ROOT . 'lib/config.php'); -require(JIRAFEAU_ROOT . 'lib/config.php'); - -function jirafeau_quoted($str) { - return QUOTE . str_replace(QUOTE, "\'", $str) . QUOTE; +function +jirafeau_quoted ($str) +{ + return QUOTE . str_replace (QUOTE, "\'", $str) . QUOTE; } -function jirafeau_export_cfg($cfg) { - $handle = fopen(JIRAFEAU_CFG, 'w'); - fwrite($handle, ' $item) { - fwrite($handle, '$cfg[' . jirafeau_quoted($key) . '] = '); - if(is_bool($item)) { - fwrite($handle, ($item ? 'true' : 'false')); - } else if(is_string($item)) { - fwrite($handle, jirafeau_quoted($item)); - } else { - fwrite($handle, 'null'); +function +jirafeau_export_cfg ($cfg) +{ + $handle = fopen (JIRAFEAU_CFG, 'w'); + fwrite ($handle, ' $item) + { + fwrite ($handle, '$cfg[' . jirafeau_quoted ($key) . '] = '); + if (is_bool ($item)) + fwrite ($handle, ($item ? 'true' : 'false')); + else if (is_string ($item)) + fwrite ($handle, jirafeau_quoted ($item)); + else + fwrite ($handle, 'null'); + fwrite ($handle, ';'.NL); } - fwrite($handle, ';' . NL); - } - fwrite($handle, '?>'); // no newline at the end of the file to be able to send headers - fclose($handle); + /* No newline at the end of the file to be able to send headers. */ + fwrite ($handle, '?>'); + fclose ($handle); } -function jirafeau_mkdir($path) { - if(!file_exists($path)) { - if(!@mkdir($path, 0755)) { - return false; - } - } - return true; +function +jirafeau_mkdir ($path) +{ + if (!file_exists ($path) && !@mkdir ($path, 0755)) + return false; + return true; } /** @@ -64,253 +71,229 @@ function jirafeau_mkdir($path) { * @param $path is the file or directory to be tested. * @return true if $path is writable. */ -function jirafeau_is_writable($path) { - return is_writable($path) || @chmod($path, 0777); // "@" gets rid of error messages. +function +jirafeau_is_writable ($path) +{ + /* "@" gets rid of error messages. */ + return is_writable ($path) || @chmod ($path, 0777); } -function jirafeau_check_var_dir($path) { - $mkdir_str1 = _('The following directory could not be created:'); - $mkdir_str2 = _('You should create this directory by hand.'); - $write_str1 = _('The following directory is not writable:'); - $write_str2 = _('You should give the write right to the web server on this directory.'); - $solution_str = _('Here is a solution:'); - - if(!jirafeau_mkdir($path)) { - return array( - 'has_error' => true, - 'why' => $mkdir_str1 . '
' . $path . '
' . $solution_str . '
' . $mkdir_str2 - ); - } - - if(!jirafeau_is_writable($path)) { - return array( - 'has_error' => true, - 'why' => $write_str1 . '
' . $path . '
' . $solution_str . '
' . $write_str2 - ); - } - - foreach(array('files', 'links') as $subdir) { - $subpath = $path . $subdir; - - if(!jirafeau_mkdir($subpath)) { - return array( - 'has_error' => true, - 'why' => $mkdir_str1 . '
' . $subpath . '
' . $solution_str . '
' . $mkdir_str2 - ); +function +jirafeau_check_var_dir ($path) +{ + $mkdir_str1 = _('The following directory could not be created:'); + $mkdir_str2 = _('You should create this directory by hand.'); + $write_str1 = _('The following directory is not writable:'); + $write_str2 = _('You should give the write right to the web server on ' . + 'this directory.'); + $solution_str = _('Here is a solution:'); + + if (!jirafeau_mkdir ($path) || !jirafeau_is_writable ($path)) + return array ('has_error' => true, + 'why' => $mkdir_str1 . '
' . + $path . '
' . $solution_str . + '
' . $mkdir_str2); + + foreach (array ('files', 'links') as $subdir) + { + $subpath = $path.$subdir; + + if (!jirafeau_mkdir ($subpath) || !jirafeau_is_writable ($subpath)) + return array ('has_error' => true, + 'why' => $mkdir_str1 . '
' . + $subpath . '
' . $solution_str . + '
' . $mkdir_str2); } - if(!jirafeau_is_writable($subpath)) { - return array( - 'has_error' => true, - 'why' => $write_str1 . '
' . $subpath . '
' . $solution_str . '
' . $write_str2 - ); - } - - } - - return array('has_error' => false, 'why' => ''); + return array ('has_error' => false, 'why' => ''); } -function jirafeau_add_ending_slash($path) { - return $path . ((substr($path, -1) == '/') ? '' : '/'); +function +jirafeau_add_ending_slash ($path) +{ + return $path . ((substr ($path, -1) == '/') ? '' : '/'); } -if(!file_exists(JIRAFEAU_CFG)) { - // we try to create an empty one - if(!@touch(JIRAFEAU_CFG)) { - require(JIRAFEAU_ROOT . 'lib/template/header.php'); - echo '

' . _('The local configuration file could not be created. Create a lib/config.local.php file and give the write right to the web server (preferred solution), or give the write right to the web server on the lib directory.') . '

'; - require(JIRAFEAU_ROOT . 'lib/template/footer.php'); - exit; - } +if (!file_exists (JIRAFEAU_CFG)) +{ + /* We try to create an empty one. */ + if (!@touch (JIRAFEAU_CFG)) + { + require (JIRAFEAU_ROOT . 'lib/template/header.php'); + echo '

' . + _('The local configuration file could not be created. Create a ' . + 'lib/config.local.php file and give the write ' . + 'right to the web server (preferred solution), or give the ' . + 'write right to the web server on the lib ' . + 'directory.') . + '

'; + require (JIRAFEAU_ROOT . 'lib/template/footer.php'); + exit; + } } -if (!is_writable(JIRAFEAU_CFG) && !@chmod(JIRAFEAU_CFG, '0666')) { - require(JIRAFEAU_ROOT . 'lib/template/header.php'); - echo '

' . _('The local configuration is not writable by the web server. Give the write right to the web server on the lib/config.local.php file.') . '

'; - require(JIRAFEAU_ROOT . 'lib/template/footer.php'); - exit; +if (!is_writable (JIRAFEAU_CFG) && !@chmod (JIRAFEAU_CFG, '0666')) +{ + require (JIRAFEAU_ROOT . 'lib/template/header.php'); + echo '

' . + _('The local configuration is not writable by the web server. ' . + 'Give the write right to the web server on the ' . + 'lib/config.local.php file.') . + '

'; + require (JIRAFEAU_ROOT . 'lib/template/footer.php'); + exit; } -if(isset($_POST['step']) && isset($_POST['next'])) { - switch($_POST['step']) { - case 1: - $cfg['lang'] = $_POST['lang']; - jirafeau_export_cfg($cfg); - break; - - case 2: - $cfg['web_root'] = jirafeau_add_ending_slash($_POST['web_root']); - $cfg['var_root'] = jirafeau_add_ending_slash($_POST['var_root']); - jirafeau_export_cfg($cfg); - break; - - default: - // nothing to do - } +if (isset ($_POST['step']) && isset ($_POST['next'])) +{ + switch ($_POST['step']) + { + case 1: + $cfg['lang'] = $_POST['lang']; + jirafeau_export_cfg ($cfg); + break; + + case 2: + $cfg['web_root'] = jirafeau_add_ending_slash ($_POST['web_root']); + $cfg['var_root'] = jirafeau_add_ending_slash ($_POST['var_root']); + jirafeau_export_cfg ($cfg); + break; + + default: break; + } } -require(JIRAFEAU_ROOT . 'lib/settings.php'); -require(JIRAFEAU_ROOT . 'lib/template/header.php'); +require (JIRAFEAU_ROOT . 'lib/settings.php'); +require (JIRAFEAU_ROOT . 'lib/template/header.php'); $current = 1; -if(isset($_POST['next'])) { - $current = $_POST['step'] + 1; -} else if(isset($_POST['previous'])) { - $current = $_POST['step'] - 1; -} else if(isset($_POST['retry'])) { - $current = $_POST['step']; -} - -switch($current) { - case 3: -?> -

-
-
- - -
- - - - - - - - - -
-
-
-
- -

' . $err['why'] . '
' . NL; -?> -

- - - -
-'; - } else { - echo '

' . _('Your website is now fully operational:') . '
' . $cfg['web_root'] . '

'; +if (isset ($_POST['next'])) + $current = $_POST['step'] + 1; +else if (isset ($_POST['previous'])) + $current = $_POST['step'] - 1; +else if (isset ($_POST['retry'])) + $current = $_POST['step']; + +switch ($current) +{ +case 3: + ?>

" method = "post"> " />
+
+

'.$err['why'].'
'.NL; + ?>

" />" />
+ '; + } + else + { + echo '

' . + _('Your website is now fully operational:') . + '
' . + $cfg['web_root'].'

'; } break; - case 2: -?> -

-
-
- - -
- - - - - - - - +
" method = "post"> " />
+ - - - - - - - + + - - - - -
- - -
-
- - - 'English', - 'fr_FR.UTF-8' => 'Français' - ); -?> -

-
-
- - -
- - - - - - - - - - - - - -
- -
-
-
-
-" size = "40" />
'English', 'fr_FR.UTF-8' => 'Français'); + ?>

" method = "post"> " />
+ + + + +
+ +
+
diff --git a/jirafeau.js b/jirafeau.js index 658e9f9..8cfcc45 100644 --- a/jirafeau.js +++ b/jirafeau.js @@ -16,10 +16,15 @@ * along with this program. If not, see . */ -function jirafeau_toggle(id) { - if(document.getElementById(id).style.display == 'block') { - document.getElementById(id).style.display = 'none'; - } else { - document.getElementById(id).style.display = 'block'; - } +function +jirafeau_toggle (id) +{ + if (document.getElementById (id).style.display == 'block') + { + document.getElementById (id).style.display = 'none'; + } + else + { + document.getElementById (id).style.display = 'block'; + } } diff --git a/lib/config.php b/lib/config.php index 141d12c..25926e1 100644 --- a/lib/config.php +++ b/lib/config.php @@ -16,14 +16,12 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ - /* * default configuration * if you want to change this, overwrite in a config.local.php file */ - // don't forget the ending '/' -$cfg['web_root'] = ''; + $cfg['web_root'] = ''; $cfg['var_root'] = ''; @@ -35,8 +33,10 @@ $cfg['rewrite'] = false; $cfg['password'] = ''; -if((basename(__FILE__) != 'config.local.php') && file_exists(JIRAFEAU_ROOT . 'lib/config.local.php')) { - require(JIRAFEAU_ROOT . 'lib/config.local.php'); +if ((basename (__FILE__) != 'config.local.php') + && file_exists (JIRAFEAU_ROOT.'lib/config.local.php')) +{ + require (JIRAFEAU_ROOT.'lib/config.local.php'); } ?> diff --git a/lib/functions.php b/lib/functions.php index d4c1b20..bb49079 100644 --- a/lib/functions.php +++ b/lib/functions.php @@ -17,38 +17,42 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ - /** * transforms a php.ini string representing a value in an integer * @param $value the value from php.ini * @returns an integer for this value */ -function jirafeau_ini_to_bytes($value) { - $modifier = substr($value, -1); - $bytes = substr($value, 0, -1); - switch(strtoupper($modifier)) { - case 'P': - $bytes *= 1024; - case 'T': - $bytes *= 1024; - case 'G': - $bytes *= 1024; - case 'M': - $bytes *= 1024; - case 'K': - $bytes *= 1024; - default: - break; - } - return $bytes; +function jirafeau_ini_to_bytes ($value) +{ + $modifier = substr ($value, -1); + $bytes = substr ($value, 0, -1); + switch (strtoupper ($modifier)) + { + case 'P': + $bytes *= 1024; + case 'T': + $bytes *= 1024; + case 'G': + $bytes *= 1024; + case 'M': + $bytes *= 1024; + case 'K': + $bytes *= 1024; + default: + break; + } + return $bytes; } /** * gets the maximum upload size according to php.ini * @returns the maximum upload size */ -function jirafeau_get_max_upload_size() { - return min(jirafeau_ini_to_bytes(ini_get('post_max_size')), jirafeau_ini_to_bytes(ini_get('upload_max_filesize'))); +function +jirafeau_get_max_upload_size () +{ + return min (jirafeau_ini_to_bytes (ini_get ('post_max_size')), + jirafeau_ini_to_bytes (ini_get ('upload_max_filesize'))); } /** @@ -56,59 +60,69 @@ function jirafeau_get_max_upload_size() { * @param $code the error code * @returns a string explaining the error */ -function jirafeau_upload_errstr($code) { - switch($code) { - case UPLOAD_ERR_INI_SIZE: - case UPLOAD_ERR_FORM_SIZE: - return _('Your file exceeds the maximum authorized file size.'); - break; +function +jirafeau_upload_errstr ($code) +{ + switch ($code) + { + case UPLOAD_ERR_INI_SIZE: + case UPLOAD_ERR_FORM_SIZE: + return _('Your file exceeds the maximum authorized file size. '); + break; - case UPLOAD_ERR_PARTIAL: - case UPLOAD_ERR_NO_FILE: - return _('Your file was not uploaded correctly. You may succeed in retrying.'); - break; + case UPLOAD_ERR_PARTIAL: + case UPLOAD_ERR_NO_FILE: + return + _ + ('Your file was not uploaded correctly. You may succeed in retrying. '); + break; - case UPLOAD_ERR_NO_TMP_DIR: - case UPLOAD_ERR_CANT_WRITE: - case UPLOAD_ERR_EXTENSION: - return _('Internal error. You may not succeed in retrying.'); - break; + case UPLOAD_ERR_NO_TMP_DIR: + case UPLOAD_ERR_CANT_WRITE: + case UPLOAD_ERR_EXTENSION: + return _('Internal error. You may not succeed in retrying. '); + break; - default: - break; - } - return _('Unknown error.'); + default: + break; + } + return _('Unknown error. '); } /** Remove link and it's file * @param $link the link's name (hash) */ -function jirafeau_delete($link) { - if(!file_exists(VAR_LINKS . $link)) - return; +function +jirafeau_delete ($link) +{ + if (!file_exists ( VAR_LINKS . $link)) + return; - $content = file(VAR_LINKS . $link); - $md5 = trim($content[5]); - unlink(VAR_LINKS . $link); + $content = file ( VAR_LINKS . $link); + $md5 = trim ($content[5]); + unlink ( VAR_LINKS . $link); - $counter = 1; - if (file_exists(VAR_FILES . $md5 . '_count')) { - $content = file(VAR_FILES . $md5 . '_count'); - $counter = trim($content[0]); - } - $counter--; + $counter = 1; + if (file_exists ( VAR_FILES . $md5. '_count')) + { + $content = file ( VAR_FILES . $md5. '_count'); + $counter = trim ($content[0]); + } + $counter--; - if ($counter >= 1) { - $handle = fopen(VAR_FILES . $md5 . '_count', 'w'); - fwrite($handle, $counter); - fclose($handle); - } + if ($counter >= 1) + { + $handle = fopen ( VAR_FILES . $md5. '_count', 'w'); + fwrite ($handle, $counter); + fclose ($handle); + } - if ($counter == 0 && file_exists(VAR_FILES. $md5)) { - unlink (VAR_FILES . $md5); - unlink (VAR_FILES . $md5 . '_count'); - } + if ($counter == 0 && file_exists ( VAR_FILES . $md5)) + { + unlink ( VAR_FILES . $md5); + unlink ( VAR_FILES . $md5. '_count'); + } } /** @@ -124,87 +138,104 @@ function jirafeau_delete($link) { * 'link' => the link name of the uploaded file * 'delete_link' => the link code to delete file */ -function jirafeau_upload($file, $one_time_download, $key, $time, $cfg, $ip) { - if(empty($file['tmp_name']) || !is_uploaded_file($file['tmp_name'])) { - return(array('error' => array('has_error' => true, 'why' => jirafeau_upload_errstr($file['error'])), 'link' => '', 'delete_link' => '')); - } +function +jirafeau_upload ($file, $one_time_download, $key, $time, $cfg, $ip) +{ + if (empty ($file['tmp_name']) || !is_uploaded_file ($file['tmp_name'])) + { + return (array( + 'error' => + array ('has_error' => true, + 'why' => jirafeau_upload_errstr ($file['error'])), + 'link' => '', + 'delete_link' => '')); + } - /* array representing no error */ - $noerr = array('has_error' => false, 'why' => ''); + /* array representing no error */ + $noerr = array ('has_error' => false, 'why' => ''); - /* file informations */ - $md5 = md5_file($file['tmp_name']); - $name = trim($file['name']); - $mime_type = $file['type']; - $size = $file['size']; + /* file informations */ + $md5 = md5_file ($file['tmp_name']); + $name = trim ($file['name']); + $mime_type = $file['type']; + $size = $file['size']; - /* does file already exist ? */ - $rc = false; - if(file_exists(VAR_FILES . $md5)) { - $rc = unlink($file['tmp_name']); - } - elseif(move_uploaded_file($file['tmp_name'], VAR_FILES . $md5)) { - $rc = true; - } - if(!$rc) - { - return(array( - 'error' => array( - 'has_error' => true, - 'why' => _('Internal error during file creation.')), - 'link' => '', - 'delete_link' => '') - ); - } + /* does file already exist ? */ + $rc = false; + if (file_exists ( VAR_FILES . $md5)) + { + $rc = unlink ($file['tmp_name']); + } + elseif (move_uploaded_file ($file['tmp_name'], VAR_FILES . $md5)) + { + $rc = true; + } + if (!$rc) + { + return (array( + 'error' => + array ('has_error' => true, + 'why' => _('Internal error during file creation. ')), + 'link' =>'', + 'delete_link' => '')); + } - /* increment or create count file */ - $counter=0; - if(file_exists(VAR_FILES . $md5 . '_count')) { - $content = file(VAR_FILES . $md5 . '_count'); - $counter = trim($content[0]); - } - $counter++; - $handle = fopen(VAR_FILES . $md5 . '_count', 'w'); - fwrite($handle, $counter); - fclose($handle); + /* increment or create count file */ + $counter = 0; + if (file_exists (VAR_FILES . $md5 . '_count')) + { + $content = file ( VAR_FILES . $md5. '_count'); + $counter = trim ($content[0]); + } + $counter++; + $handle = fopen ( VAR_FILES . $md5. '_count', 'w'); + fwrite ($handle, $counter); + fclose ($handle); - /* Create delete code. */ - $delete_link_code = 0; - for ($i = 0; $i < 8; $i++) - $delete_link_code .= dechex(rand(0,16)); + /* Create delete code. */ + $delete_link_code = 0; + for ($i = 0; $i < 8; $i++) + $delete_link_code .= dechex (rand (0, 16)); - /* md5 password or empty */ - $password = ''; - if (!empty($key)) - $password = md5($key); + /* md5 password or empty */ + $password = ''; + if (!empty ($key)) + $password = md5 ($key); - /* create link file */ - $link_tmp_name = VAR_LINKS . $md5 . rand(0, 10000) . '.tmp'; - $handle = fopen($link_tmp_name, 'w'); - fwrite($handle, $name . NL . $mime_type . NL . $size . NL . $password . NL . $time . NL . $md5 . NL . ($one_time_download ? 'O' : 'R') . NL . date('U') . NL . $ip . NL . $delete_link_code . NL); - fclose($handle); - $md5_link = md5_file($link_tmp_name); - if(!rename($link_tmp_name, VAR_LINKS . $md5_link)) { - unlink($link_tmp_name); - $counter--; - if ($counter >= 1) { - $handle = fopen(VAR_FILES . $md5 . '_count', 'w'); - fwrite($handle, $counter); - fclose($handle); - } - else { - unlink(VAR_FILES . $md5 . '_count'); - unlink(VAR_FILES . $md5); + /* create link file */ + $link_tmp_name = VAR_LINKS . $md5.rand (0, 10000) . ' .tmp'; + $handle = fopen ($link_tmp_name, 'w'); + fwrite ($handle, + $name . NL. $mime_type . NL. $size . NL. $password . NL. $time . NL . $md5. + NL.($one_time_download ? 'O' : 'R') . NL.date ('U') . NL. $ip . NL. + $delete_link_code . NL); + fclose ($handle); + $md5_link = md5_file ($link_tmp_name); + if (!rename ($link_tmp_name, VAR_LINKS . $md5_link)) + { + unlink ($link_tmp_name); + $counter--; + if ($counter >= 1) + { + $handle = fopen ( VAR_FILES . $md5. '_count', 'w'); + fwrite ($handle, $counter); + fclose ($handle); + } + else + { + unlink ( VAR_FILES . $md5. '_count'); + unlink ( VAR_FILES . $md5); + } + return (array( + 'error' => + array ('has_error' => true, + 'why' => _('Internal error during file creation. ')), + 'link' =>'', + 'delete_link' => '')); } - return(array( - 'error' => array( - 'has_error' => true, - 'why' => _('Internal error during file creation.')), - 'link' => '', - 'delete_link' => '') - ); - } - return(array('error' => $noerr, 'link' => $md5_link, 'delete_link' => $delete_link_code)); + return (array ('error' => $noerr, + 'link' => $md5_link, + 'delete_link' => $delete_link_code)); } /** @@ -212,14 +243,17 @@ function jirafeau_upload($file, $one_time_download, $key, $time, $cfg, $ip) { * @param $mime the mime type * @returns a boolean telling if a mime type is viewable */ -function jirafeau_is_viewable($mime) { - if(!empty($mime)) { - // actually, verify if mime-type is an image or a text - $viewable = array('image', 'text'); - $decomposed = explode('/', $mime); - return in_array($decomposed[0], $viewable); - } - return false; +function +jirafeau_is_viewable ($mime) +{ + if (!empty ($mime)) + { + /* Actually, verify if mime-type is an image or a text. */ + $viewable = array ('image', 'text'); + $decomposed = explode ('/', $mime); + return in_array ($decomposed[0], $viewable); + } + return false; } @@ -232,16 +266,20 @@ $error_list = array (); * @param $title the error's title * @param $description is a human-friendly description of the problem. */ -function add_error ($title, $description) { +function +add_error ($title, $description) +{ global $error_list; - $error_list[] = '

' . $title . '
' . $description . '

'; + $error_list[] = '

' . $title. '
' . $description. '

'; } /** * Informs whether any error has been registered yet. * @return true if there are errors. */ -function has_error () { +function +has_error () +{ global $error_list; return !empty ($error_list); } @@ -249,11 +287,15 @@ function has_error () { /** * Displays all the errors. */ -function show_errors () { - if (has_error ()) { +function +show_errors () +{ + if (has_error ()) + { global $error_list; echo '
'; - foreach ($error_list as $error) { + foreach ($error_list as $error) + { echo $error; } echo '
'; diff --git a/lib/settings.php b/lib/settings.php index 353a8d6..afd16c8 100644 --- a/lib/settings.php +++ b/lib/settings.php @@ -16,36 +16,35 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ - // Jirafeau constants - -define('JIRAFEAU_PACKAGE', 'Jirafeau'); -define('JIRAFEAU_VERSION', '0.4'); +define ('JIRAFEAU_PACKAGE', 'Jirafeau'); +define ('JIRAFEAU_VERSION', '0.4'); // directories -define('VAR_FILES', $cfg['var_root'] . 'files/'); -define('VAR_LINKS', $cfg['var_root'] . 'links/'); +define ('VAR_FILES', $cfg['var_root'] . 'files/'); +define ('VAR_LINKS', $cfg['var_root'] . 'links/'); // i18n -setlocale(LC_ALL, $cfg['lang']); +setlocale (LC_ALL, $cfg['lang']); -bindtextdomain(JIRAFEAU_PACKAGE, JIRAFEAU_ROOT . 'lib/locale'); -textdomain(JIRAFEAU_PACKAGE); +bindtextdomain (JIRAFEAU_PACKAGE, JIRAFEAU_ROOT.'lib/locale'); +textdomain (JIRAFEAU_PACKAGE); // useful constants -if(!defined('NL')) { - define('NL', "\n"); +if (!defined ('NL')) +{ + define ('NL', "\n"); } -define('JIRAFEAU_INFINITY', -1); -define('JIRAFEAU_MINUTE', 60); // 60 -define('JIRAFEAU_HOUR', 3600); // JIRAFEAU_MINUTE * 60 -define('JIRAFEAU_DAY', 86400); // JIRAFEAU_HOUR * 24 -define('JIRAFEAU_WEEK', 604800); // JIRAFEAU_DAY * 7 -define('JIRAFEAU_MONTH', 2419200); // JIRAFEAU_WEEK * 4 +define ('JIRAFEAU_INFINITY', -1); +define ('JIRAFEAU_MINUTE', 60); // 60 +define ('JIRAFEAU_HOUR', 3600); // JIRAFEAU_MINUTE * 60 +define ('JIRAFEAU_DAY', 86400); // JIRAFEAU_HOUR * 24 +define ('JIRAFEAU_WEEK', 604800); // JIRAFEAU_DAY * 7 +define ('JIRAFEAU_MONTH', 2419200); // JIRAFEAU_WEEK * 4 ?>