Skip to content

Commit

Permalink
Merge pull request #313 from teiling88/feature/optimize-source
Browse files Browse the repository at this point in the history
Feature/optimize source
  • Loading branch information
MacGyver-NRW committed May 24, 2016
2 parents 7d3f82c + 7be3332 commit 598c1ed
Show file tree
Hide file tree
Showing 9 changed files with 181 additions and 131 deletions.
119 changes: 119 additions & 0 deletions .scrutinizer.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
filter:
paths:
- 'htdocs/*'
- 'local/*'
excluded_paths:
- 'bin/*'
- 'doc/*'
- 'htdocs/okapi/*'
dependency_paths:
- 'htdocs/vendor/*'

checks:
php:
fix_php_opening_tag: false
remove_php_closing_tag: false
avoid_closing_tag: true
one_class_per_file: true
side_effects_or_types: true
no_mixed_inline_html: false
require_braces_around_control_structures: true
php5_style_constructor: true
no_global_keyword: true
avoid_usage_of_logical_operators: true
psr2_class_declaration: true
no_underscore_prefix_in_properties: true
no_underscore_prefix_in_methods: true
blank_line_after_namespace_declaration: true
single_namespace_per_use: true
psr2_switch_declaration: true
psr2_control_structure_declaration: true
avoid_superglobals: false
security_vulnerabilities: true
no_exit: false
uppercase_constants: true
return_doc_comments: true
remove_extra_empty_lines: true
properties_in_camelcaps: true
prefer_while_loop_over_for_loop: true
phpunit_assertions: true
parameter_doc_comments: true
optional_parameters_at_the_end: true
no_long_variable_names:
maximum: '20'
no_goto: true
function_in_camel_caps: true
fix_use_statements:
remove_unused: true
preserve_multiple: false
preserve_blanklines: false
order_alphabetically: true
encourage_single_quotes: true
encourage_postdec_operator: true
classes_in_camel_caps: true
avoid_multiple_statements_on_same_line: true
avoid_fixme_comments: true

javascript:
valid_typeof: true
yoda:
setting: 'Disallow Yoda Conditions'
wrap_iife: true
no_use_before_define: true
no_unused_vars: true
no_unreachable: true
no_undef: true
no_trailing_spaces: true
no_space_before_semi: true
no_shadow: true
no_self_compare: true
no_script_url: true
no_return_assign: true
no_reserved_keys: true
no_redeclare: true
no_mixed_spaces_and_tabs: true
no_loop_func: true
no_irregular_whitespace: true

coding_style:
php:
spaces:
around_operators:
concatenation: false
ternary_operator:
before_condition: true
after_condition: true
before_alternative: true
after_alternative: true
other:
after_type_cast: false
braces:
classes_functions:
class: new-line
function: new-line
closure: end-of-line
if:
opening: end-of-line
for:
opening: end-of-line
while:
opening: end-of-line
do_while:
opening: end-of-line
switch:
opening: end-of-line
try:
opening: end-of-line
upper_lower_casing:
keywords:
general: lower
constants:
true_false_null: lower

tools:
php_code_sniffer:
config:
standard: "PSR2"
php_cs_fixer:
enabled: true
config: { level: psr2 }
5 changes: 4 additions & 1 deletion htdocs/lib/clicompatbase.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,10 @@ function sql_warn($warnmessage)
$email_content .= print_r(debug_backtrace(), true);

if (admin_errormail($sql_errormail, 'sql_warn', $email_content, $emailheaders)) {
@mb_send_mail($sql_errormail, 'sql_warn: ' . $absolute_server_URI, $email_content, $emailheaders);
$sendMail = @mb_send_mail($sql_errormail, 'sql_warn: ' . $absolute_server_URI, $email_content, $emailheaders);
if ($sendMail === false) {
throw new \RuntimeException('the E-Mail can not be send.');
}
}
}

Expand Down
47 changes: 0 additions & 47 deletions htdocs/lib/common.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,53 +32,6 @@
//detecting errors
$error = false;

//no slashes in variables! originally from phpBB2 copied
@set_magic_quotes_runtime(0); // Disable magic_quotes_runtime

if (get_magic_quotes_gpc()) {
if (is_array($_GET)) {
while (list($k, $v) = each($_GET)) {
if (is_array($_GET[$k])) {
while (list($k2, $v2) = each($_GET[$k])) {
$_GET[$k][$k2] = stripslashes($v2);
}
@reset($_GET[$k]);
} else {
$_GET[$k] = stripslashes($v);
}
}
@reset($_GET);
}

if (is_array($_POST)) {
while (list($k, $v) = each($_POST)) {
if (is_array($_POST[$k])) {
while (list($k2, $v2) = each($_POST[$k])) {
$_POST[$k][$k2] = stripslashes($v2);
}
@reset($_POST[$k]);
} else {
$_POST[$k] = stripslashes($v);
}
}
@reset($_POST);
}

if (is_array($HTTP_COOKIE_VARS)) {
while (list($k, $v) = each($HTTP_COOKIE_VARS)) {
if (is_array($HTTP_COOKIE_VARS[$k])) {
while (list($k2, $v2) = each($HTTP_COOKIE_VARS[$k])) {
$HTTP_COOKIE_VARS[$k][$k2] = stripslashes($v2);
}
@reset($HTTP_COOKIE_VARS[$k]);
} else {
$HTTP_COOKIE_VARS[$k] = stripslashes($v);
}
}
@reset($HTTP_COOKIE_VARS);
}
}

if (!isset($rootpath)) {
$rootpath = './';
}
Expand Down
68 changes: 0 additions & 68 deletions htdocs/lib2/common.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,6 @@ function __autoload($class_name)
mb_internal_encoding('UTF-8');
mb_regex_encoding('UTF-8');

// if magic_quotes is enabled, fix it
fix_magic_quotes_gpc();

// set options
require_once $opt['rootpath'] . 'config2/settings-dist.inc.php';
require_once $opt['rootpath'] . 'config2/settings.inc.php';
Expand Down Expand Up @@ -268,71 +265,6 @@ function check_useragent()
$ocpropping = isset($_SERVER['HTTP_USER_AGENT']) && strpos($_SERVER['HTTP_USER_AGENT'], "Ocprop/") !== false;
}

function fix_magic_quotes_gpc()
{
// Disable magic_quotes_runtime
@set_magic_quotes_runtime(0);

if (get_magic_quotes_gpc()) {
if (is_array($_GET)) {
while (list($k, $v) = each($_GET)) {
if (is_array($_GET[$k])) {
while (list($k2, $v2) = each($_GET[$k])) {
$_GET[$k][$k2] = stripslashes($v2);
}
@reset($_GET[$k]);
} else {
$_GET[$k] = stripslashes($v);
}
}
@reset($_GET);
}

if (is_array($_POST)) {
while (list($k, $v) = each($_POST)) {
if (is_array($_POST[$k])) {
while (list($k2, $v2) = each($_POST[$k])) {
$_POST[$k][$k2] = stripslashes($v2);
}
@reset($_POST[$k]);
} else {
$_POST[$k] = stripslashes($v);
}
}
@reset($_POST);
}

if (is_array($_REQUEST)) {
while (list($k, $v) = each($_REQUEST)) {
if (is_array($_REQUEST[$k])) {
while (list($k2, $v2) = each($_REQUEST[$k])) {
$_REQUEST[$k][$k2] = stripslashes($v2);
}
@reset($_REQUEST[$k]);
} else {
$_REQUEST[$k] = stripslashes($v);
}
}
@reset($_REQUEST);
}

if (is_array($_COOKIE)) {
while (list($k, $v) = each($_COOKIE)) {
if (is_array($_COOKIE[$k])) {
while (list($k2, $v2) = each($_COOKIE[$k])) {
$_COOKIE[$k][$k2] = stripslashes($v2);
}
@reset($_COOKIE[$k]);
} else {
$_COOKIE[$k] = stripslashes($v);
}
}
@reset($_COOKIE);
}
}
}


// Exchange the protocol (http or https) in an URL to *this* website to the
// protocol of the current request. Do not change external links.
// This prevents i.e. Internet Explorer nag screens when embedding images
Expand Down
8 changes: 6 additions & 2 deletions htdocs/lib2/cookie.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,12 @@ public function close()
global $opt;
if ($opt['session']['mode'] == SAVE_SESSION) {
if ($this->session_initalized == true) {
if (count($_SESSION) == 0) {
@session_destroy();
if (count($_SESSION) === 0) {
try {
session_destroy();
} catch (Exception $e) {
// @todo implement login
}
} else {
session_write_close();
}
Expand Down
23 changes: 16 additions & 7 deletions htdocs/lib2/errorhandler.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,17 @@ function php_errormail($errmsg)
{
global $opt, $sql_errormail, $absolute_server_URI;

$sendMail = true;
$subject = '[' . $opt['page']['domain'] . '] PHP error';

if (isset($opt['db']['error']['mail']) && $opt['db']['error']['mail'] != '') {
@mb_send_mail($opt['db']['error']['mail'], $subject, $errmsg);
$sendMail = mb_send_mail($opt['db']['error']['mail'], $subject, $errmsg);
} elseif (isset($sql_errormail) && $sql_errormail != '') {
@mb_send_mail($sql_errormail, $subject, $errmsg);
$sendMail = mb_send_mail($sql_errormail, $subject, $errmsg);
}

if ($sendMail === false) {
throw new \RuntimeException('the E-Mail can not be send.');
}
}

Expand All @@ -122,11 +127,15 @@ function admin_errormail($to, $errortype, $message, $headers)
$old_logsize = @filesize($errorlog_path) + 0;
$msg = date("Y-m-d H:i:s.u") . " " . $errortype . "\n" . $message . "\n" .
"-------------------------------------------------------------------------\n\n";
@error_log(
$msg,
3, // log to file
$errorlog_path
);
try {
error_log(
$msg,
3, // log to file
$errorlog_path
);
} catch (Exception $e) {
// @todo implement login
}
// @filesize() may still return the old size here, because logging takes place
// asynchronously. Instead we calculate the new size:
$new_logsize = $old_logsize + strlen($msg);
Expand Down
6 changes: 5 additions & 1 deletion htdocs/lib2/logic/cracklib.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,11 @@ function cracklib_checkpw($pw, $addwords)
if ($opt['logic']['cracklib'] == true) {
// load cracklib
if (!function_exists('crack_check')) {
@dl('crack.so');
try {
dl('crack.so');
} catch (Exception $e) {
// @todo implement login
}
}

// cracklib loaded?
Expand Down
24 changes: 20 additions & 4 deletions htdocs/lib2/logic/picture.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,11 @@ public function save($restore = false, $original_id = 0, $original_url = "")
$this->setUrl($original_url); // set the url, so that we can
$filename = $this->getFilename(); // .. retreive the file path+name
$this->setFilenames($filename); // now set url(s) from the new uuid
@rename($this->deleted_filename($filename), $this->getFilename());
try {
rename($this->deleted_filename($filename), $this->getFilename());
} catch (Exception $e) {
// @todo implement login
}
}
}

Expand Down Expand Up @@ -481,12 +485,24 @@ public function delete($restore = false)

// archive picture if picture record has been archived
if (sql_value("SELECT `id` FROM `pictures_modified` WHERE `id`='&1'", 0, $this->getPictureId()) != 0) {
@rename($filename, $this->deleted_filename($filename));
try {
rename($filename, $this->deleted_filename($filename));
} catch (Exception $e) {
// @todo implement login
}
} else {
@unlink($filename);
try {
unlink($filename);
} catch (Exception $e) {
// @todo implement login
}
}

@unlink($this->getThumbFilename());
try {
unlink($this->getThumbFilename());
} catch (Exception $e) {
// @todo implement login
}

return true;
}
Expand Down
12 changes: 11 additions & 1 deletion htdocs/lib2/translationHandler.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,17 @@ private function createMessageFile($language)

fclose($f);

@exec('msgfmt -o ' . escapeshellcmd($opt['rootpath'] . 'cache2/translate/' . $language_lower . '/LC_MESSAGES/messages.mo') . ' ' . escapeshellcmd($opt['rootpath'] . 'cache2/translate/' . $language_lower . '/LC_MESSAGES/messages.po'));
try {
exec(
'msgfmt -o ' . escapeshellcmd(
$opt['rootpath'] . 'cache2/translate/' . $language_lower . '/LC_MESSAGES/messages.mo'
) . ' ' . escapeshellcmd(
$opt['rootpath'] . 'cache2/translate/' . $language_lower . '/LC_MESSAGES/messages.po'
)
);
} catch (Exception $e) {
// @todo implement login
}
}

/* escape string for po-file
Expand Down

0 comments on commit 598c1ed

Please sign in to comment.