Enforcing standards ahead of moving App to src

This commit is contained in:
Hypolite Petovan 2017-05-01 22:50:24 -04:00
commit 68c1939d12
13 changed files with 1216 additions and 1222 deletions

134
boot.php
View file

@ -8,7 +8,7 @@ define('EOL', "<br />\r\n");
define('REGISTER_CLOSED', 0);
define('REGISTER_APPROVE', 1);
define('REGISTER_OPEN', 2);
define('REGISTER_OPEN', 2);
define('DIRECTION_NONE', 0);
define('DIRECTION_IN', 1);
@ -17,22 +17,20 @@ define('DIRECTION_BOTH', 3);
define('NOTIFY_INTRO', 0x0001);
define('NOTIFY_CONFIRM', 0x0002);
define('NOTIFY_WALL', 0x0004);
define('NOTIFY_WALL', 0x0004);
define('NOTIFY_COMMENT', 0x0008);
define('NOTIFY_MAIL', 0x0010);
define('NOTIFY_MAIL', 0x0010);
define('NAMESPACE_DFRN', 'http://purl.org/macgirvin/dfrn/1.0');
/**
* log levels
*/
define('LOGGER_NORMAL', 0);
define('LOGGER_TRACE', 1);
define('LOGGER_DEBUG', 2);
define('LOGGER_DATA', 3);
define('LOGGER_ALL', 4);
define('LOGGER_NORMAL', 0);
define('LOGGER_TRACE', 1);
define('LOGGER_DEBUG', 2);
define('LOGGER_DATA', 3);
define('LOGGER_ALL', 4);
class App
{
@ -64,15 +62,13 @@ class App
{
$this->config = array();
$this->page = array();
$this->pager= array();
$this->pager = array();
$this->scheme = ((isset($_SERVER['HTTPS'])
&& ($_SERVER['HTTPS'])) ? 'https' : 'http');
$this->hostname = str_replace('www.', '',
$_SERVER['SERVER_NAME']);
$this->scheme = ((isset($_SERVER['HTTPS']) && ($_SERVER['HTTPS'])) ? 'https' : 'http');
$this->hostname = str_replace('www.', '', $_SERVER['SERVER_NAME']);
set_include_path("include/$this->hostname"
. PATH_SEPARATOR . 'include'
. PATH_SEPARATOR . '.');
. PATH_SEPARATOR . 'include'
. PATH_SEPARATOR . '.');
if (substr($_SERVER['QUERY_STRING'], 0, 2) == "q=") {
$_SERVER['QUERY_STRING'] = substr($_SERVER['QUERY_STRING'], 2);
@ -104,8 +100,7 @@ class App
}
$this->baseurl = (($ssl) ? 'https' : $this->scheme) . "://" . $this->hostname
. ((isset($this->path) && strlen($this->path))
? '/' . $this->path : '');
. ((isset($this->path) && strlen($this->path)) ? '/' . $this->path : '');
return $this->baseurl;
}
@ -152,13 +147,12 @@ class App
$s = file_get_contents("view/head.tpl");
}
$this->page['htmlhead'] = replace_macros($s, array(
'$baseurl' => $this->get_baseurl()
));
'$baseurl' => $this->get_baseurl()
));
}
}
if (! function_exists('x')) {
if (!function_exists('x')) {
function x($s, $k = null)
{
if ($k != null) {
@ -181,7 +175,7 @@ if (! function_exists('x')) {
}
}
if (! function_exists('system_unavailable')) {
if (!function_exists('system_unavailable')) {
function system_unavailable()
{
include('system_unavailable.php');
@ -189,14 +183,14 @@ if (! function_exists('system_unavailable')) {
}
}
if (! function_exists('logger')) {
if (!function_exists('logger')) {
function logger($msg, $level = 0)
{
$debugging = 1;
$loglevel = LOGGER_ALL;
$logfile = 'logfile.out';
$loglevel = LOGGER_ALL;
$logfile = 'logfile.out';
if ((! $debugging) || (! $logfile) || ($level > $loglevel)) {
if ((!$debugging) || (!$logfile) || ($level > $loglevel)) {
return;
}
require_once('include/datetime.php');
@ -207,7 +201,7 @@ if (! function_exists('logger')) {
}
if (! function_exists('replace_macros')) {
if (!function_exists('replace_macros')) {
function replace_macros($s, $r)
{
$search = array();
@ -215,7 +209,7 @@ if (! function_exists('replace_macros')) {
if (is_array($r) && count($r)) {
foreach ($r as $k => $v) {
$search[] = $k;
$search[] = $k;
$replace[] = $v;
}
}
@ -224,14 +218,14 @@ if (! function_exists('replace_macros')) {
}
if (! function_exists('load_translation_table')) {
if (!function_exists('load_translation_table')) {
function load_translation_table($lang)
{
global $a;
}
}
if (! function_exists('t')) {
if (!function_exists('t')) {
function t($s)
{
global $a;
@ -243,14 +237,11 @@ if (! function_exists('t')) {
}
}
if (! function_exists('fetch_url')) {
function fetch_url($url, $binary = false, $timeout=20)
if (!function_exists('fetch_url')) {
function fetch_url($url, $binary = false, $timeout = 20)
{
$ch = curl_init($url);
if (! $ch) {
if (!$ch) {
return false;
}
@ -269,12 +260,11 @@ if (! function_exists('fetch_url')) {
}
}
if (! function_exists('post_url')) {
if (!function_exists('post_url')) {
function post_url($url, $params)
{
$ch = curl_init($url);
if (! $ch) {
if (!$ch) {
return false;
}
@ -290,30 +280,29 @@ if (! function_exists('post_url')) {
}
}
if (! function_exists('random_string')) {
if (!function_exists('random_string')) {
function random_string()
{
return(hash('sha256', uniqid(rand(), true)));
}
}
if (! function_exists('notags')) {
if (!function_exists('notags')) {
function notags($string)
{
// protect against :<> with high-bit set
return(str_replace(array("<", ">", "\xBA", "\xBC", "\xBE"), array('[', ']', '', '', ''), $string));
return(str_replace(array("<", ">", "\xBA", "\xBC", "\xBE"), array('[', ']', '', '', ''), $string));
}
}
if (! function_exists('escape_tags')) {
if (!function_exists('escape_tags')) {
function escape_tags($string)
{
return(htmlspecialchars($string));
}
}
if (! function_exists('login')) {
if (!function_exists('login')) {
function login($register = false)
{
$o = "";
@ -325,14 +314,13 @@ if (! function_exists('login')) {
} else {
$o = file_get_contents("view/login.tpl");
$o = replace_macros($o, array('$register_html' => $register_html ));
$o = replace_macros($o, array('$register_html' => $register_html));
}
return $o;
}
}
if (! function_exists('killme')) {
if (!function_exists('killme')) {
function killme()
{
session_write_close();
@ -341,7 +329,7 @@ if (! function_exists('killme')) {
}
}
if (! function_exists('goaway')) {
if (!function_exists('goaway')) {
function goaway($s)
{
header("Location: $s");
@ -349,7 +337,7 @@ if (! function_exists('goaway')) {
}
}
if (! function_exists('local_user')) {
if (!function_exists('local_user')) {
function local_user()
{
if ((x($_SESSION, 'authenticated')) && (x($_SESSION, 'uid'))) {
@ -359,7 +347,7 @@ if (! function_exists('local_user')) {
}
}
if (! function_exists('notice')) {
if (!function_exists('notice')) {
function notice($s)
{
if (!isset($_SESSION['sysmsg'])) {
@ -369,18 +357,14 @@ if (! function_exists('notice')) {
}
}
if (! function_exists('hex2bin')) {
if (!function_exists('hex2bin')) {
function hex2bin($s)
{
return(pack("H*", $s));
}
}
if (! function_exists('paginate')) {
if (!function_exists('paginate')) {
function paginate(&$a)
{
$o = '';
@ -388,16 +372,15 @@ if (! function_exists('paginate')) {
$stripped = str_replace('q=', '', $stripped);
$stripped = trim($stripped, '/');
$pagenum = $a->pager['page'];
$url = $a->get_baseurl() . '/' . $stripped ;
$url = $a->get_baseurl() . '/' . $stripped;
if ($a->pager['total'] > $a->pager['itemspage']) {
$o .= '<div class="pager">';
if ($a->pager['page'] != 1) {
$o .= '<span class="pager_prev">'."<a href=\"$url".'&page='.($a->pager['page'] - 1).'">' . t('prev') . '</a></span> ';
$o .= '<span class="pager_prev">' . "<a href=\"$url" . '&page=' . ($a->pager['page'] - 1) . '">' . t('prev') . '</a></span> ';
}
$o .= "<span class=\"pager_first\"><a href=\"$url"."&page=1\">" . t('first') . "</a></span> ";
$o .= "<span class=\"pager_first\"><a href=\"$url" . "&page=1\">" . t('first') . "</a></span> ";
$numpages = $a->pager['total'] / $a->pager['itemspage'];
@ -411,35 +394,34 @@ if (! function_exists('paginate')) {
for ($i = $numstart; $i <= $numstop; $i++) {
if ($i == $a->pager['page']) {
$o .= '<span class="pager_current">'.(($i < 10) ? '&nbsp;'.$i : $i);
$o .= '<span class="pager_current">' . (($i < 10) ? '&nbsp;' . $i : $i);
} else {
$o .= "<span class=\"pager_n\"><a href=\"$url"."&page=$i\">".(($i < 10) ? '&nbsp;'.$i : $i)."</a>";
$o .= "<span class=\"pager_n\"><a href=\"$url" . "&page=$i\">" . (($i < 10) ? '&nbsp;' . $i : $i) . "</a>";
}
$o .= '</span> ';
}
if (($a->pager['total'] % $a->pager['itemspage']) != 0) {
if ($i == $a->pager['page']) {
$o .= '<span class="pager_current">'.(($i < 10) ? '&nbsp;'.$i : $i);
$o .= '<span class="pager_current">' . (($i < 10) ? '&nbsp;' . $i : $i);
} else {
$o .= "<span class=\"pager_n\"><a href=\"$url"."&page=$i\">".(($i < 10) ? '&nbsp;'.$i : $i)."</a>";
$o .= "<span class=\"pager_n\"><a href=\"$url" . "&page=$i\">" . (($i < 10) ? '&nbsp;' . $i : $i) . "</a>";
}
$o .= '</span> ';
}
$lastpage = (($numpages > intval($numpages)) ? intval($numpages)+1 : $numpages);
$o .= "<span class=\"pager_last\"><a href=\"$url"."&page=$lastpage\">" . t('last') . "</a></span> ";
$lastpage = (($numpages > intval($numpages)) ? intval($numpages) + 1 : $numpages);
$o .= "<span class=\"pager_last\"><a href=\"$url" . "&page=$lastpage\">" . t('last') . "</a></span> ";
if (($a->pager['total'] - ($a->pager['itemspage'] * $a->pager['page'])) > 0) {
$o .= '<span class="pager_next">'."<a href=\"$url"."&page=".($a->pager['page'] + 1).'">' . t('next') . '</a></span>';
$o .= '<span class="pager_next">' . "<a href=\"$url" . "&page=" . ($a->pager['page'] + 1) . '">' . t('next') . '</a></span>';
}
$o .= '</div>'."\r\n";
$o .= '</div>' . "\r\n";
}
return $o;
}
}
function get_my_url()
{
if (x($_SESSION, 'my_url')) {
@ -450,10 +432,10 @@ function get_my_url()
function zrl($s, $force = false)
{
if (! strlen($s)) {
if (!strlen($s)) {
return $s;
}
if ((! strpos($s, '/profile/')) && (! $force)) {
if ((!strpos($s, '/profile/')) && (!$force)) {
return $s;
}
$achar = strpos($s, '?') ? '&' : '?';
@ -464,7 +446,7 @@ function zrl($s, $force = false)
return $s;
}
if (! function_exists('link_compare')) {
if (!function_exists('link_compare')) {
function link_compare($a, $b)
{
if (strcasecmp(normalise_link($a), normalise_link($b)) === 0) {
@ -474,7 +456,7 @@ if (! function_exists('link_compare')) {
}
}
if (! function_exists('normalise_link')) {
if (!function_exists('normalise_link')) {
function normalise_link($url)
{
$ret = str_replace(array('https:', '//www.'), array('http:', '//'), $url);