Enforce coding standards in index.php

This commit is contained in:
Hypolite Petovan 2017-04-20 19:53:51 -04:00
parent e82a1e3816
commit 34a5adb9e9

View file

@ -1,20 +1,21 @@
<?php <?php
require_once('vendor/autoload.php'); require_once 'vendor/autoload.php';
require_once('boot.php'); require_once 'boot.php';
$a = new App; $a = new App;
error_reporting(E_ERROR | E_WARNING | E_PARSE ); error_reporting(E_ERROR | E_WARNING | E_PARSE );
ini_set('error_log','php.out'); error_reporting(E_ALL );
ini_set('log_errors','1'); ini_set('error_log', 'php.out');
ini_set('log_errors', '1');
ini_set('display_errors', '0'); ini_set('display_errors', '0');
$debug_text = ''; $debug_text = '';
require_once('.htconfig.php'); require_once '.htconfig.php';
require_once("dba.php"); require_once 'dba.php';
$db = new dba($db_host, $db_user, $db_pass, $db_data); $db = new dba($db_host, $db_user, $db_pass, $db_data);
unset($db_host, $db_user, $db_pass, $db_data); unset($db_host, $db_user, $db_pass, $db_data);
@ -22,73 +23,68 @@ $db = new dba($db_host, $db_user, $db_pass, $db_data);
$a->init_pagehead(); $a->init_pagehead();
$a->page['aside'] .= '<div id="logo"><img src="images/friendica-32.png" alt="friendica logo" /> <a href="http://friendica.com">Friendica</a></div><div id="slogan">Your friends. Your web.</div>'; $a->page['aside'] .= '<div id="logo"><img src="images/friendica-32.png" alt="friendica logo" /> <a href="http://friendica.com">Friendica</a></div><div id="slogan">Your friends. Your web.</div>';
require_once("session.php"); require_once 'session.php';
session_start(); session_start();
if ((x($_SESSION, 'authenticated')) || (x($_POST, 'auth-params')) || ($a->module === 'login')) {
if((x($_SESSION,'authenticated')) || (x($_POST,'auth-params')) || ($a->module === 'login')) require 'auth.php';
require("auth.php"); }
$dreamhost_error_hack = 1; $dreamhost_error_hack = 1;
if (x($_GET, 'zrl')) {
if(x($_GET,'zrl')) {
$_SESSION['my_url'] = $_GET['zrl']; $_SESSION['my_url'] = $_GET['zrl'];
$a->query_string = preg_replace('/[\?&]*zrl=(.*?)([\?&]|$)/is','',$a->query_string); $a->query_string = preg_replace('/[\?&]*zrl=(.*?)([\?&]|$)/is', '', $a->query_string);
} }
if(strlen($a->module)) { if (strlen($a->module)) {
if(file_exists("mod/{$a->module}.php")) { if (file_exists("mod/{$a->module}.php")) {
include("mod/{$a->module}.php"); include("mod/{$a->module}.php");
$a->module_loaded = true; $a->module_loaded = true;
} }
if(! $a->module_loaded) { if (! $a->module_loaded) {
if((x($_SERVER,'QUERY_STRING')) && ($_SERVER['QUERY_STRING'] === 'q=internal_error.html') && isset($dreamhost_error_hack)) { if ((x($_SERVER, 'QUERY_STRING')) && ($_SERVER['QUERY_STRING'] === 'q=internal_error.html') && isset($dreamhost_error_hack)) {
goaway($a->get_baseurl() . $_SERVER['REQUEST_URI']); goaway($a->get_baseurl() . $_SERVER['REQUEST_URI']);
} }
header($_SERVER["SERVER_PROTOCOL"] . ' 404 ' . t('Not Found')); header($_SERVER['SERVER_PROTOCOL'] . ' 404 ' . t('Not Found'));
notice( t('Page not found' ) . EOL); notice(t('Page not found' ) . EOL);
} }
} }
if($a->module_loaded) { if ($a->module_loaded) {
$a->page['page_title'] = $a->module; $a->page['page_title'] = $a->module;
if(function_exists($a->module . '_init')) { if (function_exists($a->module . '_init')) {
$func = $a->module . '_init'; $func = $a->module . '_init';
$func($a); $func($a);
} }
if(($_SERVER['REQUEST_METHOD'] == 'POST') && (! $a->error) if (($_SERVER['REQUEST_METHOD'] == 'POST') && (! $a->error)
&& (function_exists($a->module . '_post')) && (function_exists($a->module . '_post'))
&& (! x($_POST,'auth-params'))) { && (! x($_POST, 'auth-params'))) {
$func = $a->module . '_post'; $func = $a->module . '_post';
$func($a); $func($a);
} }
if((! $a->error) && (function_exists($a->module . '_afterpost'))) { if ((! $a->error) && (function_exists($a->module . '_afterpost'))) {
$func = $a->module . '_afterpost'; $func = $a->module . '_afterpost';
$func($a); $func($a);
} }
if((! $a->error) && (function_exists($a->module . '_content'))) { if ((! $a->error) && (function_exists($a->module . '_content'))) {
$func = $a->module . '_content'; $func = $a->module . '_content';
$a->page['content'] .= $func($a); $a->page['content'] .= $func($a);
} }
} }
if(stristr($_SESSION['sysmsg'], t('Permission denied'))) { if (stristr($_SESSION['sysmsg'], t('Permission denied'))) {
header($_SERVER["SERVER_PROTOCOL"] . ' 403 ' . t('Permission denied.')); header($_SERVER['SERVER_PROTOCOL'] . ' 403 ' . t('Permission denied.'));
} }
// report anything important happening // report anything important happening
if(x($_SESSION,'sysmsg')) { if (x($_SESSION, 'sysmsg')) {
$a->page['content'] = '<div id="sysmsg" class="error-message">' . $_SESSION['sysmsg'] . '</div>' . "\r\n" $a->page['content'] = '<div id="sysmsg" class="error-message">' . $_SESSION['sysmsg'] . '</div>' . PHP_EOL
. $a->page['content']; . $a->page['content'];
unset($_SESSION['sysmsg']); unset($_SESSION['sysmsg']);
} }
@ -97,20 +93,19 @@ if(x($_SESSION,'sysmsg')) {
$a->page['htmlhead'] = replace_macros($a->page['htmlhead'], array( $a->page['htmlhead'] = replace_macros($a->page['htmlhead'], array(
'$stylesheet' => $a->get_baseurl() . '/view/theme/' '$stylesheet' => $a->get_baseurl() . '/view/theme/'
. ((x($_SESSION,'theme')) ? $_SESSION['theme'] : 'default') . ((x($_SESSION, 'theme')) ? $_SESSION['theme'] : 'default')
. '/style.css' . '/style.css'
)); ));
$page = $a->page; $page = $a->page;
$profile = $a->profile; $profile = $a->profile;
header("Content-type: text/html; charset=utf-8"); header('Content-type: text/html; charset=utf-8');
$template = "view/" $template = 'view/'
. ((x($a->page,'template')) ? $a->page['template'] : 'default' ) . ((x($a->page, 'template')) ? $a->page['template'] : 'default' )
. ".php"; . '.php';
require_once($template); require_once $template;
session_write_close(); session_write_close();
closedb(); closedb();
exit; exit;