Commit 96707e02 authored by Dan Untenzu's avatar Dan Untenzu Committed by Jerome Jutteau

[FEATURE] Switch to PSR-2

Convert all PHP files to PSR-2, which defined
a basic Coding Style Guide for PHP projects.

Using the awesome friendsofphp/php-cs-fixer tool,
running with the @PSR2 ruleset.

1) script.php (no_spaces_after_function_name, braces)
2) f.php (indentation_type, no_spaces_after_function_name, braces)
3) install.php (indentation_type, function_declaration, elseif, no_spaces_after_function_name, braces)
4) lib/functions.php (no_spaces_inside_parenthesis, method_argument_space, function_declaration, elseif, no_spaces_after_function_name, lowercase_constants, lowercase_keywords, braces, single_blank_line_at_eof)
5) lib/functions.js.php (no_spaces_after_function_name)
6) lib/lang.php (function_declaration, no_spaces_after_function_name, lowercase_constants, no_closing_tag, braces, single_blank_line_at_eof)
7) lib/template/footer.php (braces)
8) lib/config.local.bak.php (method_argument_space, no_spaces_after_function_name, no_closing_tag, single_blank_line_at_eof)
9) lib/config.original.php (no_spaces_after_function_name, no_closing_tag, single_blank_line_at_eof)
0) lib/settings.php (indentation_type, no_spaces_after_function_name, braces)
1) lib/config.local.php (no_spaces_after_function_name, single_blank_line_at_eof)
2) index.php (indentation_type, no_spaces_after_function_name, braces)
3) admin.php (no_spaces_after_function_name, braces)
4) tos.php (no_spaces_after_function_name, no_closing_tag, single_blank_line_at_eof)

Refs #103
parent 719b7e58
This diff is collapsed.
This diff is collapsed.
......@@ -18,66 +18,59 @@
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
define ('JIRAFEAU_ROOT', dirname (__FILE__) . '/');
define('JIRAFEAU_ROOT', dirname(__FILE__) . '/');
require (JIRAFEAU_ROOT . 'lib/settings.php');
require (JIRAFEAU_ROOT . 'lib/functions.php');
require (JIRAFEAU_ROOT . 'lib/lang.php');
require(JIRAFEAU_ROOT . 'lib/settings.php');
require(JIRAFEAU_ROOT . 'lib/functions.php');
require(JIRAFEAU_ROOT . 'lib/lang.php');
check_errors ($cfg);
if (has_error ())
{
show_errors ();
require (JIRAFEAU_ROOT . 'lib/template/footer.php');
check_errors($cfg);
if (has_error()) {
show_errors();
require(JIRAFEAU_ROOT . 'lib/template/footer.php');
exit;
}
require (JIRAFEAU_ROOT . 'lib/template/header.php');
require(JIRAFEAU_ROOT . 'lib/template/header.php');
/* Check if user is allowed to upload. */
if (!jirafeau_challenge_upload_ip ($cfg, get_ip_address($cfg)))
{
if (!jirafeau_challenge_upload_ip($cfg, get_ip_address($cfg))) {
echo '<div class="error"><p>' . t('Access denied') . '</p></div>';
require (JIRAFEAU_ROOT.'lib/template/footer.php');
require(JIRAFEAU_ROOT.'lib/template/footer.php');
exit;
}
/* Ask password if upload password is set. */
if (jirafeau_has_upload_password ($cfg))
{
if (jirafeau_has_upload_password($cfg)) {
session_start();
/* Unlog if asked. */
if (isset ($_POST['action']) && (strcmp ($_POST['action'], 'logout') == 0))
session_unset ();
if (isset($_POST['action']) && (strcmp($_POST['action'], 'logout') == 0)) {
session_unset();
}
/* Auth. */
if (isset ($_POST['upload_password']))
{
if (jirafeau_challenge_upload_password ($cfg, $_POST['upload_password']))
{
if (isset($_POST['upload_password'])) {
if (jirafeau_challenge_upload_password($cfg, $_POST['upload_password'])) {
$_SESSION['upload_auth'] = true;
$_SESSION['user_upload_password'] = $_POST['upload_password'];
}
else
{
} else {
$_SESSION['admin_auth'] = false;
echo '<div class="error"><p>' . t('Wrong password.') . '</p></div>';
require (JIRAFEAU_ROOT.'lib/template/footer.php');
require(JIRAFEAU_ROOT.'lib/template/footer.php');
exit;
}
}
/* Show auth page. */
if (!isset ($_SESSION['upload_auth']) || $_SESSION['upload_auth'] != true)
{
?>
if (!isset($_SESSION['upload_auth']) || $_SESSION['upload_auth'] != true) {
?>
<form action = "<?php echo basename(__FILE__); ?>" method = "post">
<fieldset>
<table>
<tr>
<td class = "label"><label for = "enter_password">
<?php echo t('Upload password') . ':';?></label>
<?php echo t('Upload password') . ':'; ?></label>
</td>
<td class = "field"><input type = "password"
name = "upload_password" id = "upload_password"
......@@ -95,7 +88,7 @@ if (jirafeau_has_upload_password ($cfg))
</fieldset>
</form>
<?php
require (JIRAFEAU_ROOT.'lib/template/footer.php');
require(JIRAFEAU_ROOT.'lib/template/footer.php');
exit;
}
}
......@@ -112,12 +105,14 @@ if (jirafeau_has_upload_password ($cfg))
<p><a id="upload_link" href=""></a></p>
</div>
<?php if ($cfg['preview'] == true) { ?>
<?php if ($cfg['preview'] == true) {
?>
<div id="upload_finished_preview">
<p><?php echo t('View link') ?>:</p>
<p><a id="preview_link" href=""></a></p>
</div>
<?php } ?>
<?php
} ?>
<div id="upload_direct_download">
<p><?php echo t('Direct download link') ?>:</p>
......@@ -137,7 +132,7 @@ if (jirafeau_has_upload_password ($cfg))
<div id="uploading">
<p>
<?php echo t ('Uploading ...'); ?>
<?php echo t('Uploading ...'); ?>
<div id="uploaded_percentage"></div>
<div id="uploaded_speed"></div>
<div id="uploaded_time"></div>
......@@ -154,7 +149,7 @@ if (jirafeau_has_upload_password ($cfg))
</legend>
<p>
<input type="file" id="file_select" size="30"
onchange="control_selected_file_size(<?php echo $cfg['maximal_upload_size'] ?>, '<?php echo t ('File is too big') . ', ' . t ('File size is limited to') . " " . $cfg['maximal_upload_size'] . " MB"; ?>')"/>
onchange="control_selected_file_size(<?php echo $cfg['maximal_upload_size'] ?>, '<?php echo t('File is too big') . ', ' . t('File size is limited to') . " " . $cfg['maximal_upload_size'] . " MB"; ?>')"/>
</p>
<div id="options">
......@@ -206,59 +201,57 @@ if (jirafeau_has_upload_password ($cfg))
)
);
foreach ($expirationTimeOptions as $expirationTimeOption) {
$selected = ($expirationTimeOption['value'] === $cfg['availability_default'])? 'selected="selected"' : '';
if(true === $cfg['availabilities'][$expirationTimeOption['value']]) {
echo '<option value="' . $expirationTimeOption['value'] . '" ' .
$selected = ($expirationTimeOption['value'] === $cfg['availability_default'])? 'selected="selected"' : '';
if (true === $cfg['availabilities'][$expirationTimeOption['value']]) {
echo '<option value="' . $expirationTimeOption['value'] . '" ' .
$selected . '>' . t($expirationTimeOption['label']) . '</option>';
}
}
}
?>
</select></td>
</tr>
<?php
if ($cfg['maximal_upload_size'] > 0)
{
echo '<p class="config">' . t ('File size is limited to');
echo " " . $cfg['maximal_upload_size'] . " MB</p>";
if ($cfg['maximal_upload_size'] > 0) {
echo '<p class="config">' . t('File size is limited to');
echo " " . $cfg['maximal_upload_size'] . " MB</p>";
}
?>
<p id="max_file_size" class="config"></p>
<p>
<?php
if (jirafeau_has_upload_password ($cfg) && $_SESSION['upload_auth'])
{
?>
if (jirafeau_has_upload_password($cfg) && $_SESSION['upload_auth']) {
?>
<input type="hidden" id="upload_password" name="upload_password" value="<?php echo $_SESSION['user_upload_password'] ?>"/>
<?php
}
else
{
?>
} else {
?>
<input type="hidden" id="upload_password" name="upload_password" value=""/>
<?php
}
?>
<input type="submit" id="send" value="<?php echo t('Send'); ?>"
onclick="
document.getElementById('upload').style.display = 'none';
document.getElementById('uploading').style.display = '';
upload ('<?php echo $cfg['web_root']; ?>', <?php echo jirafeau_get_max_upload_size_bytes (); ?>);
upload ('<?php echo $cfg['web_root']; ?>', <?php echo jirafeau_get_max_upload_size_bytes(); ?>);
"/>
</p>
</table>
</div> </fieldset>
<?php
if (jirafeau_has_upload_password ($cfg))
{
?>
if (jirafeau_has_upload_password($cfg)) {
?>
<form action = "<?php echo basename(__FILE__); ?>" method = "post">
<input type = "hidden" name = "action" value = "logout"/>
<input type = "submit" value = "<?php echo t('Logout'); ?>" />
</form>
<?php
}
?>
......@@ -272,7 +265,7 @@ if (jirafeau_has_upload_password ($cfg))
document.getElementById('send').style.display = 'none';
if (!check_html5_file_api ())
document.getElementById('max_file_size').innerHTML = '<?php
echo t('You browser may not support HTML5 so the maximum file size is ') . jirafeau_get_max_upload_size ();
echo t('You browser may not support HTML5 so the maximum file size is ') . jirafeau_get_max_upload_size();
?>';
</script>
<?php require (JIRAFEAU_ROOT . 'lib/template/footer.php'); ?>
<?php require(JIRAFEAU_ROOT . 'lib/template/footer.php'); ?>
This diff is collapsed.
......@@ -109,7 +109,7 @@ $cfg['admin_http_auth_user'] = '';
* 'year': file available for one year
* 'none': unlimited availability
*/
$cfg['availabilities'] = array (
$cfg['availabilities'] = array(
'minute' => true,
'hour' => true,
'day' => true,
......@@ -143,5 +143,3 @@ $cfg['proxy_ip'] = array();
* or needs to start the installation script
*/
$cfg['installation_done'] = false;
?>
\ No newline at end of file
......@@ -20,16 +20,16 @@
header('Content-Type: text/javascript');
define ('JIRAFEAU_ROOT', dirname (__FILE__) . '/../');
define('JIRAFEAU_ROOT', dirname(__FILE__) . '/../');
require (JIRAFEAU_ROOT . 'lib/settings.php');
require (JIRAFEAU_ROOT . 'lib/functions.php');
require (JIRAFEAU_ROOT . 'lib/lang.php');
require(JIRAFEAU_ROOT . 'lib/settings.php');
require(JIRAFEAU_ROOT . 'lib/functions.php');
require(JIRAFEAU_ROOT . 'lib/lang.php');
?>
function translate (expr)
{
var lang_array = <?php echo json_lang_generator () ?>;
var lang_array = <?php echo json_lang_generator() ?>;
if (lang_array.hasOwnProperty(expr))
return lang_array[expr];
return expr;
......
This diff is collapsed.
......@@ -18,7 +18,7 @@
*/
global $languages_list;
$languages_list = array ('auto' => 'Automatic',
$languages_list = array('auto' => 'Automatic',
'de' => 'Deutsch',
'en' => 'English',
'el' => 'Ελληνικά',
......@@ -34,78 +34,85 @@ $languages_list = array ('auto' => 'Automatic',
'zh' => '汉语');
/* Translation */
function t ($text)
function t($text)
{
$cfg = $GLOBALS['cfg'];
$languages_list = $GLOBALS['languages_list'];
/* Detect user's langage if we are in automatic mode. */
if (strcmp ($cfg['lang'], 'auto') == 0)
{
if (isset ($_SERVER['HTTP_ACCEPT_LANGUAGE']))
$l = substr ($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2);
else
if (strcmp($cfg['lang'], 'auto') == 0) {
if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
$l = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2);
} else {
$l = "en";
}
else
}
} else {
$l = $cfg['lang'];
}
/* Is the langage in the list ? */
$found = false;
foreach ($languages_list as $key => $v)
if (strcmp ($l, $key) == 0)
foreach ($languages_list as $key => $v) {
if (strcmp($l, $key) == 0) {
$found = true;
}
}
/* Don't translate english. */
if (!($found && strcmp ($l, "en")))
if (!($found && strcmp($l, "en"))) {
return $text;
}
/* Open translation file. */
$trans_j = file_get_contents (JIRAFEAU_ROOT . "lib/locales/$l.json");
if ($trans_j === FALSE)
$trans_j = file_get_contents(JIRAFEAU_ROOT . "lib/locales/$l.json");
if ($trans_j === false) {
return $text;
}
/* Decode JSON. */
$trans = json_decode ($trans_j, true);
if ($trans === NULL)
$trans = json_decode($trans_j, true);
if ($trans === null) {
return $text;
}
/* Try to find translation. */
if (!array_key_exists ($text, $trans))
if (!array_key_exists($text, $trans)) {
return $text;
}
return $trans[$text];
}
function json_lang_generator ()
function json_lang_generator()
{
$cfg = $GLOBALS['cfg'];
$languages_list = $GLOBALS['languages_list'];
/* Detect user's langage if we are in automatic mode. */
if (strcmp ($cfg['lang'], 'auto') == 0)
{
if (isset ($_SERVER['HTTP_ACCEPT_LANGUAGE']))
$l = substr ($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2);
else
if (strcmp($cfg['lang'], 'auto') == 0) {
if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
$l = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2);
} else {
$l = "en";
}
else
}
} else {
$l = $cfg['lang'];
}
/* Is the langage in the list ? */
$found = false;
foreach ($languages_list as $key => $v)
if (strcmp ($l, $key) == 0)
foreach ($languages_list as $key => $v) {
if (strcmp($l, $key) == 0) {
$found = true;
}
}
/* Don't translate english. */
if (!($found && strcmp ($l, "en")))
if (!($found && strcmp($l, "en"))) {
return "{}";
}
/* Open translation file. */
$trans_j = file_get_contents (JIRAFEAU_ROOT . "lib/locales/$l.json");
$trans_j = file_get_contents(JIRAFEAU_ROOT . "lib/locales/$l.json");
return $trans_j;
}
?>
......@@ -20,50 +20,49 @@
global $cfg;
// Read config files
require (JIRAFEAU_ROOT . 'lib/config.original.php');
if (file_exists(JIRAFEAU_ROOT . 'lib/config.local.php'))
{
// read local copy and merge with original values
$cfgOriginal = $cfg;
require (JIRAFEAU_ROOT . 'lib/config.local.php');
$cfg = array_merge($cfgOriginal, $cfg);
unset($cfgOriginal);
require(JIRAFEAU_ROOT . 'lib/config.original.php');
if (file_exists(JIRAFEAU_ROOT . 'lib/config.local.php')) {
// read local copy and merge with original values
$cfgOriginal = $cfg;
require(JIRAFEAU_ROOT . 'lib/config.local.php');
$cfg = array_merge($cfgOriginal, $cfg);
unset($cfgOriginal);
}
// Set constants
/* Jirafeau package */
define ('JIRAFEAU_PACKAGE', 'Jirafeau');
define ('JIRAFEAU_VERSION', '2.0.0');
define('JIRAFEAU_PACKAGE', 'Jirafeau');
define('JIRAFEAU_VERSION', '2.0.0');
/* Directories. */
define ('VAR_FILES', $cfg['var_root'] . 'files/');
define ('VAR_LINKS', $cfg['var_root'] . 'links/');
define ('VAR_ASYNC', $cfg['var_root'] . 'async/');
define ('VAR_ALIAS', $cfg['var_root'] . 'alias/');
define('VAR_FILES', $cfg['var_root'] . 'files/');
define('VAR_LINKS', $cfg['var_root'] . 'links/');
define('VAR_ASYNC', $cfg['var_root'] . 'async/');
define('VAR_ALIAS', $cfg['var_root'] . 'alias/');
// helping variable to build absolute link to
// root of the domain without handling the URL scheme
$absPrefix = parse_url($cfg['web_root'], PHP_URL_PATH);
if(true === empty($absPrefix)) {
// fallback if installation isnt done yet: relative links to same level on the current page
$absPrefix = './';
if (true === empty($absPrefix)) {
// fallback if installation isnt done yet: relative links to same level on the current page
$absPrefix = './';
}
define ('JIRAFEAU_ABSPREFIX', $absPrefix);
define('JIRAFEAU_ABSPREFIX', $absPrefix);
/* Useful constants. */
if (!defined ('NL')) {
define ('NL', "\n");
if (!defined('NL')) {
define('NL', "\n");
}
if (!defined ('QUOTE')) {
define ('QUOTE', "'");
if (!defined('QUOTE')) {
define('QUOTE', "'");
}
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_QUARTER', 7257600); // JIRAFEAU_MONTH * 3
define ('JIRAFEAU_YEAR', 29030400); // JIRAFEAU_MONTH * 12
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_QUARTER', 7257600); // JIRAFEAU_MONTH * 3
define('JIRAFEAU_YEAR', 29030400); // JIRAFEAU_MONTH * 12
......@@ -9,10 +9,9 @@
?>
<!-- Installation dependend links -->
<?php
if (true == $cfg['installation_done'])
{
echo ' | ';
echo '<a href="' . JIRAFEAU_ABSPREFIX . 'tos.php">' . t('Terms of Service') . '</a>';
if (true == $cfg['installation_done']) {
echo ' | ';
echo '<a href="' . JIRAFEAU_ABSPREFIX . 'tos.php">' . t('Terms of Service') . '</a>';
}
?>
</p>
......
This diff is collapsed.
......@@ -16,11 +16,11 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
define ('JIRAFEAU_ROOT', dirname (__FILE__) . '/');
define('JIRAFEAU_ROOT', dirname(__FILE__) . '/');
require (JIRAFEAU_ROOT . 'lib/settings.php');
require (JIRAFEAU_ROOT . 'lib/functions.php');
require (JIRAFEAU_ROOT . 'lib/lang.php');
require(JIRAFEAU_ROOT . 'lib/settings.php');
require(JIRAFEAU_ROOT . 'lib/functions.php');
require(JIRAFEAU_ROOT . 'lib/lang.php');
// Read ToS template
if (is_readable(JIRAFEAU_ROOT . 'lib/tos.local.txt')) {
......@@ -30,11 +30,9 @@ if (is_readable(JIRAFEAU_ROOT . 'lib/tos.local.txt')) {
}
// Replace markers and print ToS
require (JIRAFEAU_ROOT . 'lib/template/header.php');
require(JIRAFEAU_ROOT . 'lib/template/header.php');
echo '<h2>Terms of Service</h2>';
echo '<div>' . jirafeau_replace_markers($content, true) . '</div>';
require (JIRAFEAU_ROOT . 'lib/template/footer.php');
?>
\ No newline at end of file
require(JIRAFEAU_ROOT . 'lib/template/footer.php');
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment