1
1
Fork 0

Yet more standards

This commit is contained in:
Hypolite Petovan 2017-05-02 22:42:29 -04:00
parent a76256e6e9
commit 3437e73ae4
6 changed files with 153 additions and 178 deletions

231
boot.php
View file

@ -1,4 +1,5 @@
<?php <?php
/** @file boot.php /** @file boot.php
* *
* This file defines some global constants and includes the central App class. * This file defines some global constants and includes the central App class.
@ -17,23 +18,23 @@
* easily as email does today. * easily as email does today.
*/ */
require_once(__DIR__ . DIRECTORY_SEPARATOR. 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php'); require_once(__DIR__ . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php');
use Friendica\App; use Friendica\App;
use Friendica\Core\Config; use Friendica\Core\Config;
require_once('include/config.php'); require_once 'include/config.php';
require_once('include/network.php'); require_once 'include/network.php';
require_once('include/plugin.php'); require_once 'include/plugin.php';
require_once('include/text.php'); require_once 'include/text.php';
require_once('include/datetime.php'); require_once 'include/datetime.php';
require_once('include/pgettext.php'); require_once 'include/pgettext.php';
require_once('include/nav.php'); require_once 'include/nav.php';
require_once('include/cache.php'); require_once 'include/cache.php';
require_once('include/features.php'); require_once 'include/features.php';
require_once('include/identity.php'); require_once 'include/identity.php';
require_once('update.php'); require_once 'update.php';
require_once('include/dbstructure.php'); require_once 'include/dbstructure.php';
define ( 'FRIENDICA_PLATFORM', 'Friendica'); define ( 'FRIENDICA_PLATFORM', 'Friendica');
define ( 'FRIENDICA_CODENAME', 'Asparagus'); define ( 'FRIENDICA_CODENAME', 'Asparagus');
@ -51,7 +52,6 @@ define ( 'DB_UPDATE_VERSION', 1222 );
define ( 'EOL', "<br />\r\n" ); define ( 'EOL', "<br />\r\n" );
define ( 'ATOM_TIME', 'Y-m-d\TH:i:s\Z' ); define ( 'ATOM_TIME', 'Y-m-d\TH:i:s\Z' );
/** /**
* @brief Image storage quality. * @brief Image storage quality.
* *
@ -62,8 +62,8 @@ define ( 'ATOM_TIME', 'Y-m-d\TH:i:s\Z' );
* below about 50 * below about 50
* *
*/ */
define ( 'JPEG_QUALITY', 100 ); define ( 'JPEG_QUALITY', 100 );
/** /**
* $a->config['system']['png_quality'] from 0 (uncompressed) to 9 * $a->config['system']['png_quality'] from 0 (uncompressed) to 9
*/ */
@ -87,12 +87,10 @@ define ( 'PNG_QUALITY', 8 );
*/ */
define ( 'MAX_IMAGE_LENGTH', -1 ); define ( 'MAX_IMAGE_LENGTH', -1 );
/** /**
* Not yet used * Not yet used
*/ */
define ( 'DEFAULT_DB_ENGINE', 'InnoDB' );
define ( 'DEFAULT_DB_ENGINE', 'MyISAM' );
/** /**
* @name SSL Policy * @name SSL Policy
@ -166,7 +164,6 @@ define ( 'UPDATE_SUCCESS', 0);
define ( 'UPDATE_FAILED', 1); define ( 'UPDATE_FAILED', 1);
/** @}*/ /** @}*/
/** /**
* @name page/profile types * @name page/profile types
* *
@ -292,20 +289,16 @@ $netgroup_ids = array(
NETWORK_PHANTOM => (-127), NETWORK_PHANTOM => (-127),
); );
/** /**
* Maximum number of "people who like (or don't like) this" that we will list by name * Maximum number of "people who like (or don't like) this" that we will list by name
*/ */
define ( 'MAX_LIKERS', 75); define ( 'MAX_LIKERS', 75);
/** /**
* Communication timeout * Communication timeout
*/ */
define ( 'ZCURL_TIMEOUT' , (-1)); define ( 'ZCURL_TIMEOUT' , (-1));
/** /**
* @name Notify * @name Notify
* *
@ -346,8 +339,6 @@ define ( 'TERM_CONVERSATION', 7 );
define ( 'TERM_OBJ_POST', 1 ); define ( 'TERM_OBJ_POST', 1 );
define ( 'TERM_OBJ_PHOTO', 2 ); define ( 'TERM_OBJ_PHOTO', 2 );
/** /**
* @name Namespaces * @name Namespaces
* *
@ -459,14 +450,13 @@ define('SR_SCOPE_TAGS', 'tags');
/** /**
* Lowest possible date time value * Lowest possible date time value
*/ */
define ('NULL_DATE', '0001-01-01 00:00:00'); define ('NULL_DATE', '0001-01-01 00:00:00');
// Normally this constant is defined - but not if "pcntl" isn't installed // Normally this constant is defined - but not if "pcntl" isn't installed
if (!defined("SIGTERM")) { if (!defined("SIGTERM")) {
define("SIGTERM", 15); define("SIGTERM", 15);
} }
/** /**
* *
* Reverse the effect of magic_quotes_gpc if it is enabled. * Reverse the effect of magic_quotes_gpc if it is enabled.
@ -474,9 +464,7 @@ if (!defined("SIGTERM")) {
* See http://php.net/manual/en/security.magicquotes.disabling.php * See http://php.net/manual/en/security.magicquotes.disabling.php
* *
*/ */
function startup() { function startup() {
error_reporting(E_ERROR | E_WARNING | E_PARSE); error_reporting(E_ERROR | E_WARNING | E_PARSE);
set_time_limit(0); set_time_limit(0);
@ -484,7 +472,6 @@ function startup() {
// This has to be quite large to deal with embedded private photos // This has to be quite large to deal with embedded private photos
ini_set('pcre.backtrack_limit', 500000); ini_set('pcre.backtrack_limit', 500000);
if (get_magic_quotes_gpc()) { if (get_magic_quotes_gpc()) {
$process = array(&$_GET, &$_POST, &$_COOKIE, &$_REQUEST); $process = array(&$_GET, &$_POST, &$_COOKIE, &$_REQUEST);
while (list($key, $val) = each($process)) { while (list($key, $val) = each($process)) {
@ -500,7 +487,6 @@ function startup() {
} }
unset($process); unset($process);
} }
} }
/** /**
@ -513,7 +499,6 @@ function get_app() {
return $a; return $a;
} }
/** /**
* @brief Multi-purpose function to check variable state. * @brief Multi-purpose function to check variable state.
* *
@ -528,7 +513,7 @@ function get_app() {
* *
* @return bool|int * @return bool|int
*/ */
function x($s,$k = NULL) { function x($s, $k = NULL) {
if ($k != NULL) { if ($k != NULL) {
if ((is_array($s)) && (array_key_exists($k, $s))) { if ((is_array($s)) && (array_key_exists($k, $s))) {
if ($s[$k]) { if ($s[$k]) {
@ -548,7 +533,6 @@ function x($s,$k = NULL) {
} }
} }
/** /**
* @brief Called from db initialisation if db is dead. * @brief Called from db initialisation if db is dead.
*/ */
@ -558,7 +542,6 @@ function system_unavailable() {
killme(); killme();
} }
function clean_urls() { function clean_urls() {
$a = get_app(); $a = get_app();
return true; return true;
@ -567,7 +550,7 @@ function clean_urls() {
function z_path() { function z_path() {
$base = App::get_baseurl(); $base = App::get_baseurl();
if (! clean_urls()) { if (!clean_urls()) {
$base .= '/?q='; $base .= '/?q=';
} }
@ -594,7 +577,7 @@ function z_root() {
* @return string * @return string
*/ */
function absurl($path) { function absurl($path) {
if (strpos($path,'/') === 0) { if (strpos($path, '/') === 0) {
return z_path() . $path; return z_path() . $path;
} }
return $path; return $path;
@ -611,25 +594,23 @@ function is_ajax() {
function check_db() { function check_db() {
$build = get_config('system','build'); $build = get_config('system', 'build');
if (! x($build)) { if (!x($build)) {
set_config('system','build',DB_UPDATE_VERSION); set_config('system', 'build', DB_UPDATE_VERSION);
$build = DB_UPDATE_VERSION; $build = DB_UPDATE_VERSION;
} }
if ($build != DB_UPDATE_VERSION) { if ($build != DB_UPDATE_VERSION) {
proc_run(PRIORITY_CRITICAL, 'include/dbupdate.php'); proc_run(PRIORITY_CRITICAL, 'include/dbupdate.php');
} }
} }
/** /**
* Sets the base url for use in cmdline programs which don't have * Sets the base url for use in cmdline programs which don't have
* $_SERVER variables * $_SERVER variables
*/ */
function check_url(App $a) { function check_url(App $a) {
$url = get_config('system','url'); $url = get_config('system', 'url');
// if the url isn't set or the stored url is radically different // if the url isn't set or the stored url is radically different
// than the currently visited url, store the current value accordingly. // than the currently visited url, store the current value accordingly.
@ -637,24 +618,23 @@ function check_url(App $a) {
// and www.example.com vs example.com. // and www.example.com vs example.com.
// We will only change the url to an ip address if there is no existing setting // We will only change the url to an ip address if there is no existing setting
if (! x($url)) { if (!x($url)) {
$url = set_config('system','url',App::get_baseurl()); $url = set_config('system', 'url', App::get_baseurl());
} }
if ((! link_compare($url,App::get_baseurl())) && (! preg_match("/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/",$a->get_hostname))) { if ((!link_compare($url, App::get_baseurl())) && (!preg_match("/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/", $a->get_hostname))) {
$url = set_config('system','url',App::get_baseurl()); $url = set_config('system', 'url', App::get_baseurl());
} }
return; return;
} }
/** /**
* @brief Automatic database updates * @brief Automatic database updates
*/ */
function update_db(App $a) { function update_db(App $a) {
$build = get_config('system','build'); $build = get_config('system', 'build');
if (! x($build)) { if (!x($build)) {
$build = set_config('system','build',DB_UPDATE_VERSION); $build = set_config('system', 'build', DB_UPDATE_VERSION);
} }
if ($build != DB_UPDATE_VERSION) { if ($build != DB_UPDATE_VERSION) {
@ -665,7 +645,6 @@ function update_db(App $a) {
// We're reporting a different version than what is currently installed. // We're reporting a different version than what is currently installed.
// Run any existing update scripts to bring the database up to current. // Run any existing update scripts to bring the database up to current.
// make sure that boot.php and update.php are the same release, we might be // make sure that boot.php and update.php are the same release, we might be
// updating right this very second and the correct version of the update.php // updating right this very second and the correct version of the update.php
// file may not be here yet. This can happen on a very busy site. // file may not be here yet. This can happen on a very busy site.
@ -673,12 +652,12 @@ function update_db(App $a) {
if (DB_UPDATE_VERSION == UPDATE_VERSION) { if (DB_UPDATE_VERSION == UPDATE_VERSION) {
// Compare the current structure with the defined structure // Compare the current structure with the defined structure
$t = get_config('database','dbupdate_'.DB_UPDATE_VERSION); $t = get_config('database', 'dbupdate_' . DB_UPDATE_VERSION);
if ($t !== false) { if ($t !== false) {
return; return;
} }
set_config('database','dbupdate_'.DB_UPDATE_VERSION, time()); set_config('database', 'dbupdate_' . DB_UPDATE_VERSION, time());
// run old update routine (wich could modify the schema and // run old update routine (wich could modify the schema and
// conflits with new routine) // conflits with new routine)
@ -702,7 +681,7 @@ function update_db(App $a) {
); );
return; return;
} else { } else {
set_config('database','dbupdate_'.DB_UPDATE_VERSION, 'success'); set_config('database', 'dbupdate_' . DB_UPDATE_VERSION, 'success');
} }
// run any left update_nnnn functions in update.php // run any left update_nnnn functions in update.php
@ -726,15 +705,14 @@ function run_update_function($x) {
// We want exactly one process to run the update command. // We want exactly one process to run the update command.
// So store the fact that we're taking responsibility // So store the fact that we're taking responsibility
// after first checking to see if somebody else already has. // after first checking to see if somebody else already has.
// If the update fails or times-out completely you may need to // If the update fails or times-out completely you may need to
// delete the config entry to try again. // delete the config entry to try again.
$t = get_config('database','update_' . $x); $t = get_config('database', 'update_' . $x);
if ($t !== false) { if ($t !== false) {
return false; return false;
} }
set_config('database','update_' . $x, time()); set_config('database', 'update_' . $x, time());
// call the specific update // call the specific update
@ -749,13 +727,13 @@ function run_update_function($x) {
); );
return false; return false;
} else { } else {
set_config('database','update_' . $x, 'success'); set_config('database', 'update_' . $x, 'success');
set_config('system','build', $x + 1); set_config('system', 'build', $x + 1);
return true; return true;
} }
} else { } else {
set_config('database','update_' . $x, 'success'); set_config('database', 'update_' . $x, 'success');
set_config('system','build', $x + 1); set_config('system', 'build', $x + 1);
return true; return true;
} }
return true; return true;
@ -784,11 +762,11 @@ function check_plugins(App $a) {
$installed = array(); $installed = array();
} }
$plugins = get_config('system','addon'); $plugins = get_config('system', 'addon');
$plugins_arr = array(); $plugins_arr = array();
if ($plugins) { if ($plugins) {
$plugins_arr = explode(',',str_replace(' ', '',$plugins)); $plugins_arr = explode(',', str_replace(' ', '', $plugins));
} }
$a->plugins = $plugins_arr; $a->plugins = $plugins_arr;
@ -797,7 +775,7 @@ function check_plugins(App $a) {
if (count($installed)) { if (count($installed)) {
foreach ($installed as $i) { foreach ($installed as $i) {
if (! in_array($i['name'],$plugins_arr)) { if (!in_array($i['name'], $plugins_arr)) {
uninstall_plugin($i['name']); uninstall_plugin($i['name']);
} else { } else {
$installed_arr[] = $i['name']; $installed_arr[] = $i['name'];
@ -807,20 +785,18 @@ function check_plugins(App $a) {
if (count($plugins_arr)) { if (count($plugins_arr)) {
foreach ($plugins_arr as $p) { foreach ($plugins_arr as $p) {
if (! in_array($p,$installed_arr)) { if (!in_array($p, $installed_arr)) {
install_plugin($p); install_plugin($p);
} }
} }
} }
load_hooks(); load_hooks();
return; return;
} }
function get_guid($size=16, $prefix = "") { function get_guid($size = 16, $prefix = "") {
if ($prefix == "") { if ($prefix == "") {
$a = get_app(); $a = get_app();
$prefix = hash("crc32", $a->get_hostname()); $prefix = hash("crc32", $a->get_hostname());
@ -853,7 +829,7 @@ function get_guid($size=16, $prefix = "") {
* @hooks 'login_hook' * @hooks 'login_hook'
* string $o * string $o
*/ */
function login($register = false, $hiddens=false) { function login($register = false, $hiddens = false) {
$a = get_app(); $a = get_app();
$o = ""; $o = "";
$reg = false; $reg = false;
@ -864,14 +840,14 @@ function login($register = false, $hiddens=false) {
); );
} }
$noid = get_config('system','no_openid'); $noid = get_config('system', 'no_openid');
$dest_url = $a->query_string; $dest_url = $a->query_string;
if (local_user()) { if (local_user()) {
$tpl = get_markup_template("logout.tpl"); $tpl = get_markup_template("logout.tpl");
} else { } else {
$a->page['htmlhead'] .= replace_macros(get_markup_template("login_head.tpl"),array( $a->page['htmlhead'] .= replace_macros(get_markup_template("login_head.tpl"), array(
'$baseurl' => $a->get_baseurl(true) '$baseurl' => $a->get_baseurl(true)
)); ));
@ -905,10 +881,9 @@ function login($register = false, $hiddens=false) {
'$privacytitle' => t('Website Privacy Policy'), '$privacytitle' => t('Website Privacy Policy'),
'$privacylink' => t('privacy policy'), '$privacylink' => t('privacy policy'),
)); ));
call_hooks('login_hook',$o); call_hooks('login_hook', $o);
return $o; return $o;
} }
@ -917,7 +892,6 @@ function login($register = false, $hiddens=false) {
* @brief Used to end the current process, after saving session state. * @brief Used to end the current process, after saving session state.
*/ */
function killme() { function killme() {
if (!get_app()->is_backend()) { if (!get_app()->is_backend()) {
session_write_close(); session_write_close();
} }
@ -930,14 +904,13 @@ function killme() {
*/ */
function goaway($s) { function goaway($s) {
if (!strstr(normalise_link($s), "http://")) { if (!strstr(normalise_link($s), "http://")) {
$s = App::get_baseurl()."/".$s; $s = App::get_baseurl() . "/" . $s;
} }
header("Location: $s"); header("Location: $s");
killme(); killme();
} }
/** /**
* @brief Returns the user id of locally logged in user or false. * @brief Returns the user id of locally logged in user or false.
* *
@ -979,7 +952,7 @@ function public_contact() {
* @return int|bool visitor_id or false * @return int|bool visitor_id or false
*/ */
function remote_user() { function remote_user() {
if ((x($_SESSION,'authenticated')) && (x($_SESSION,'visitor_id'))) { if ((x($_SESSION, 'authenticated')) && (x($_SESSION, 'visitor_id'))) {
return intval($_SESSION['visitor_id']); return intval($_SESSION['visitor_id']);
} }
return false; return false;
@ -994,7 +967,7 @@ function remote_user() {
*/ */
function notice($s) { function notice($s) {
$a = get_app(); $a = get_app();
if (! x($_SESSION,'sysmsg')) { if (!x($_SESSION, 'sysmsg')) {
$_SESSION['sysmsg'] = array(); $_SESSION['sysmsg'] = array();
} }
if ($a->interactive) { if ($a->interactive) {
@ -1012,11 +985,11 @@ function notice($s) {
function info($s) { function info($s) {
$a = get_app(); $a = get_app();
if (local_user() AND get_pconfig(local_user(),'system','ignore_info')) { if (local_user() AND get_pconfig(local_user(), 'system', 'ignore_info')) {
return; return;
} }
if (! x($_SESSION,'sysmsg_info')) { if (!x($_SESSION, 'sysmsg_info')) {
$_SESSION['sysmsg_info'] = array(); $_SESSION['sysmsg_info'] = array();
} }
if ($a->interactive) { if ($a->interactive) {
@ -1024,7 +997,6 @@ function info($s) {
} }
} }
/** /**
* @brief Wrapper around config to limit the text length of an incoming message * @brief Wrapper around config to limit the text length of an incoming message
* *
@ -1032,7 +1004,7 @@ function info($s) {
*/ */
function get_max_import_size() { function get_max_import_size() {
$a = get_app(); $a = get_app();
return ((x($a->config,'max_import_size')) ? $a->config['max_import_size'] : 0 ); return ((x($a->config, 'max_import_size')) ? $a->config['max_import_size'] : 0 );
} }
/** /**
@ -1050,7 +1022,7 @@ function get_max_import_size() {
* @hooks 'proc_run' * @hooks 'proc_run'
* array $arr * array $arr
*/ */
function proc_run($cmd){ function proc_run($cmd) {
$a = get_app(); $a = get_app();
@ -1083,7 +1055,7 @@ function proc_run($cmd){
$arr = array('args' => $args, 'run_cmd' => true); $arr = array('args' => $args, 'run_cmd' => true);
call_hooks("proc_run", $arr); call_hooks("proc_run", $arr);
if (!$arr['run_cmd'] OR !count($args)) { if (!$arr['run_cmd'] OR ! count($args)) {
return; return;
} }
@ -1105,8 +1077,7 @@ function proc_run($cmd){
array_shift($argv); array_shift($argv);
$parameters = json_encode($argv); $parameters = json_encode($argv);
$found = q("SELECT `id` FROM `workerqueue` WHERE `parameter` = '%s'", $found = q("SELECT `id` FROM `workerqueue` WHERE `parameter` = '%s'", dbesc($parameters));
dbesc($parameters));
if (!dbm::is_result($found)) { if (!dbm::is_result($found)) {
q("INSERT INTO `workerqueue` (`parameter`, `created`, `priority`) q("INSERT INTO `workerqueue` (`parameter`, `created`, `priority`)
@ -1142,7 +1113,7 @@ function proc_run($cmd){
$a->proc_run($args); $a->proc_run($args);
} }
function current_theme(){ function current_theme() {
$app_base_themes = array('duepuntozero', 'dispy', 'quattro'); $app_base_themes = array('duepuntozero', 'dispy', 'quattro');
$a = get_app(); $a = get_app();
@ -1164,7 +1135,7 @@ function current_theme(){
// This works only if the user is on the same server // This works only if the user is on the same server
if ($page_theme && local_user() && (local_user() != $a->profile_uid)) { if ($page_theme && local_user() && (local_user() != $a->profile_uid)) {
if (get_pconfig(local_user(),'system','always_my_theme')) { if (get_pconfig(local_user(), 'system', 'always_my_theme')) {
$page_theme = null; $page_theme = null;
} }
} }
@ -1174,7 +1145,7 @@ function current_theme(){
$is_mobile = $a->is_mobile || $a->is_tablet; $is_mobile = $a->is_mobile || $a->is_tablet;
$standard_system_theme = Config::get('system', 'theme', ''); $standard_system_theme = Config::get('system', 'theme', '');
$standard_theme_name = ((isset($_SESSION) && x($_SESSION,'theme')) ? $_SESSION['theme'] : $standard_system_theme); $standard_theme_name = ((isset($_SESSION) && x($_SESSION, 'theme')) ? $_SESSION['theme'] : $standard_system_theme);
if ($is_mobile) { if ($is_mobile) {
if (isset($_SESSION['show-mobile']) && !$_SESSION['show-mobile']) { if (isset($_SESSION['show-mobile']) && !$_SESSION['show-mobile']) {
@ -1185,7 +1156,7 @@ function current_theme(){
if ($system_theme == '') { if ($system_theme == '') {
$system_theme = $standard_system_theme; $system_theme = $standard_system_theme;
} }
$theme_name = ((isset($_SESSION) && x($_SESSION,'mobile-theme')) ? $_SESSION['mobile-theme'] : $system_theme); $theme_name = ((isset($_SESSION) && x($_SESSION, 'mobile-theme')) ? $_SESSION['mobile-theme'] : $system_theme);
if ($theme_name === '---') { if ($theme_name === '---') {
// user has selected to have the mobile theme be the same as the normal one // user has selected to have the mobile theme be the same as the normal one
@ -1219,9 +1190,9 @@ function current_theme(){
} }
} }
$fallback = array_merge(glob('view/theme/*/style.css'),glob('view/theme/*/style.php')); $fallback = array_merge(glob('view/theme/*/style.css'), glob('view/theme/*/style.php'));
if (count($fallback)) { if (count($fallback)) {
return (str_replace('view/theme/','', substr($fallback[0],0,-10))); return (str_replace('view/theme/', '', substr($fallback[0], 0, -10)));
} }
/// @TODO No final return statement? /// @TODO No final return statement?
@ -1241,13 +1212,13 @@ function current_theme_url() {
$opts = (($a->profile_uid) ? '?f=&puid=' . $a->profile_uid : ''); $opts = (($a->profile_uid) ? '?f=&puid=' . $a->profile_uid : '');
if (file_exists('view/theme/' . $t . '/style.php')) { if (file_exists('view/theme/' . $t . '/style.php')) {
return('view/theme/'.$t.'/style.pcss'.$opts); return('view/theme/' . $t . '/style.pcss' . $opts);
} }
return('view/theme/'.$t.'/style.css'); return('view/theme/' . $t . '/style.css');
} }
function feed_birthday($uid,$tz) { function feed_birthday($uid, $tz) {
/** /**
* *
@ -1267,11 +1238,9 @@ function feed_birthday($uid,$tz) {
* 6:00PM the day before, but that will correspond to midnight to the birthday person. * 6:00PM the day before, but that will correspond to midnight to the birthday person.
* *
*/ */
$birthday = ''; $birthday = '';
if (! strlen($tz)) { if (!strlen($tz)) {
$tz = 'UTC'; $tz = 'UTC';
} }
@ -1280,16 +1249,16 @@ function feed_birthday($uid,$tz) {
); );
if (dbm::is_result($p)) { if (dbm::is_result($p)) {
$tmp_dob = substr($p[0]['dob'],5); $tmp_dob = substr($p[0]['dob'], 5);
if (intval($tmp_dob)) { if (intval($tmp_dob)) {
$y = datetime_convert($tz,$tz,'now','Y'); $y = datetime_convert($tz, $tz, 'now', 'Y');
$bd = $y . '-' . $tmp_dob . ' 00:00'; $bd = $y . '-' . $tmp_dob . ' 00:00';
$t_dob = strtotime($bd); $t_dob = strtotime($bd);
$now = strtotime(datetime_convert($tz,$tz,'now')); $now = strtotime(datetime_convert($tz, $tz, 'now'));
if ($t_dob < $now) { if ($t_dob < $now) {
$bd = $y + 1 . '-' . $tmp_dob . ' 00:00'; $bd = $y + 1 . '-' . $tmp_dob . ' 00:00';
} }
$birthday = datetime_convert($tz,'UTC',$bd,ATOM_TIME); $birthday = datetime_convert($tz, 'UTC', $bd, ATOM_TIME);
} }
} }
@ -1307,7 +1276,7 @@ function is_site_admin() {
$adminlist = explode(",", str_replace(" ", "", $a->config['admin_email'])); $adminlist = explode(",", str_replace(" ", "", $a->config['admin_email']));
//if(local_user() && x($a->user,'email') && x($a->config,'admin_email') && ($a->user['email'] === $a->config['admin_email'])) //if(local_user() && x($a->user,'email') && x($a->config,'admin_email') && ($a->user['email'] === $a->config['admin_email']))
if (local_user() && x($a->user,'email') && x($a->config,'admin_email') && in_array($a->user['email'], $adminlist)) { if (local_user() && x($a->user, 'email') && x($a->config, 'admin_email') && in_array($a->user['email'], $adminlist)) {
return true; return true;
} }
return false; return false;
@ -1329,7 +1298,7 @@ function build_querystring($params, $name = null) {
if ($name == null) { if ($name == null) {
$ret .= build_querystring($val, $key); $ret .= build_querystring($val, $key);
} else { } else {
$ret .= build_querystring($val, $name."[$key]"); $ret .= build_querystring($val, $name . "[$key]");
} }
} else { } else {
$val = urlencode($val); $val = urlencode($val);
@ -1377,10 +1346,10 @@ function explode_querystring($query) {
} }
/** /**
* Returns the complete URL of the current page, e.g.: http(s)://something.com/network * Returns the complete URL of the current page, e.g.: http(s)://something.com/network
* *
* Taken from http://webcheatsheet.com/php/get_current_page_url.php * Taken from http://webcheatsheet.com/php/get_current_page_url.php
*/ */
function curPageURL() { function curPageURL() {
$pageURL = 'http'; $pageURL = 'http';
if ($_SERVER["HTTPS"] == "on") { if ($_SERVER["HTTPS"] == "on") {
@ -1390,9 +1359,9 @@ function curPageURL() {
$pageURL .= "://"; $pageURL .= "://";
if ($_SERVER["SERVER_PORT"] != "80" && $_SERVER["SERVER_PORT"] != "443") { if ($_SERVER["SERVER_PORT"] != "80" && $_SERVER["SERVER_PORT"] != "443") {
$pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"]; $pageURL .= $_SERVER["SERVER_NAME"] . ":" . $_SERVER["SERVER_PORT"] . $_SERVER["REQUEST_URI"];
} else { } else {
$pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"]; $pageURL .= $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"];
} }
return $pageURL; return $pageURL;
} }
@ -1401,7 +1370,7 @@ function random_digits($digits) {
$rn = ''; $rn = '';
for ($i = 0; $i < $digits; $i++) { for ($i = 0; $i < $digits; $i++) {
/// @TODO rand() is different to mt_rand() and maybe lesser "random" /// @TODO rand() is different to mt_rand() and maybe lesser "random"
$rn .= rand(0,9); $rn .= rand(0, 9);
} }
return $rn; return $rn;
} }
@ -1419,7 +1388,7 @@ function get_server() {
function get_cachefile($file, $writemode = true) { function get_cachefile($file, $writemode = true) {
$cache = get_itemcachepath(); $cache = get_itemcachepath();
if ((! $cache) || (! is_dir($cache))) { if ((!$cache) || (!is_dir($cache))) {
return(""); return("");
} }
@ -1444,7 +1413,7 @@ function clear_cache($basepath = "", $path = "") {
$path = $basepath; $path = $basepath;
} }
if (($path == "") OR (!is_dir($path))) { if (($path == "") OR ( !is_dir($path))) {
return; return;
} }
@ -1452,19 +1421,19 @@ function clear_cache($basepath = "", $path = "") {
return; return;
} }
$cachetime = (int)get_config('system','itemcache_duration'); $cachetime = (int) get_config('system', 'itemcache_duration');
if ($cachetime == 0) { if ($cachetime == 0) {
$cachetime = 86400; $cachetime = 86400;
} }
if (is_writable($path)){ if (is_writable($path)) {
if ($dh = opendir($path)) { if ($dh = opendir($path)) {
while (($file = readdir($dh)) !== false) { while (($file = readdir($dh)) !== false) {
$fullpath = $path."/".$file; $fullpath = $path . "/" . $file;
if ((filetype($fullpath) == "dir") and ($file != ".") and ($file != "..")) { if ((filetype($fullpath) == "dir") and ( $file != ".") and ( $file != "..")) {
clear_cache($basepath, $fullpath); clear_cache($basepath, $fullpath);
} }
if ((filetype($fullpath) == "file") and (filectime($fullpath) < (time() - $cachetime))) { if ((filetype($fullpath) == "file") and ( filectime($fullpath) < (time() - $cachetime))) {
unlink($fullpath); unlink($fullpath);
} }
} }
@ -1475,12 +1444,12 @@ function clear_cache($basepath = "", $path = "") {
function get_itemcachepath() { function get_itemcachepath() {
// Checking, if the cache is deactivated // Checking, if the cache is deactivated
$cachetime = (int)get_config('system','itemcache_duration'); $cachetime = (int) get_config('system', 'itemcache_duration');
if ($cachetime < 0) { if ($cachetime < 0) {
return ""; return "";
} }
$itemcache = get_config('system','itemcache'); $itemcache = get_config('system', 'itemcache');
if (($itemcache != "") AND App::directory_usable($itemcache)) { if (($itemcache != "") AND App::directory_usable($itemcache)) {
return $itemcache; return $itemcache;
} }
@ -1488,7 +1457,7 @@ function get_itemcachepath() {
$temppath = get_temppath(); $temppath = get_temppath();
if ($temppath != "") { if ($temppath != "") {
$itemcache = $temppath."/itemcache"; $itemcache = $temppath . "/itemcache";
if (!file_exists($itemcache) && !is_dir($itemcache)) { if (!file_exists($itemcache) && !is_dir($itemcache)) {
mkdir($itemcache); mkdir($itemcache);
} }
@ -1507,7 +1476,7 @@ function get_itemcachepath() {
* @return string Spool path * @return string Spool path
*/ */
function get_spoolpath() { function get_spoolpath() {
$spoolpath = get_config('system','spoolpath'); $spoolpath = get_config('system', 'spoolpath');
if (($spoolpath != "") AND App::directory_usable($spoolpath)) { if (($spoolpath != "") AND App::directory_usable($spoolpath)) {
// We have a spool path and it is usable // We have a spool path and it is usable
return $spoolpath; return $spoolpath;
@ -1518,7 +1487,7 @@ function get_spoolpath() {
if ($temppath != "") { if ($temppath != "") {
// To avoid any interferences with other systems we create our own directory // To avoid any interferences with other systems we create our own directory
$spoolpath = $temppath."/spool"; $spoolpath = $temppath . "/spool";
if (!is_dir($spoolpath)) { if (!is_dir($spoolpath)) {
mkdir($spoolpath); mkdir($spoolpath);
} }
@ -1554,7 +1523,7 @@ function get_temppath() {
// Check if it is usable // Check if it is usable
if (($temppath != "") AND App::directory_usable($temppath)) { if (($temppath != "") AND App::directory_usable($temppath)) {
// To avoid any interferences with other systems we create our own directory // To avoid any interferences with other systems we create our own directory
$new_temppath = $temppath."/".$a->get_hostname(); $new_temppath = $temppath . "/" . $a->get_hostname();
if (!is_dir($new_temppath)) { if (!is_dir($new_temppath)) {
/// @TODO There is a mkdir()+chmod() upwards, maybe generalize this (+ configurable) into a function/method? /// @TODO There is a mkdir()+chmod() upwards, maybe generalize this (+ configurable) into a function/method?
mkdir($new_temppath); mkdir($new_temppath);
@ -1600,7 +1569,7 @@ function validate_include(&$file) {
return false; return false;
} }
$file = str_replace(getcwd()."/", "", $file, $count); $file = str_replace(getcwd() . "/", "", $file, $count);
if ($count != 1) { if ($count != 1) {
return false; return false;
} }
@ -1652,7 +1621,7 @@ function argc() {
* @return string Value of the argv key * @return string Value of the argv key
*/ */
function argv($x) { function argv($x) {
if (array_key_exists($x,get_app()->argv)) { if (array_key_exists($x, get_app()->argv)) {
return get_app()->argv[$x]; return get_app()->argv[$x];
} }
@ -1674,8 +1643,8 @@ function argv($x) {
*/ */
function infinite_scroll_data($module) { function infinite_scroll_data($module) {
if (get_pconfig(local_user(),'system','infinite_scroll') if (get_pconfig(local_user(), 'system', 'infinite_scroll')
AND ($module == "network") AND ($_GET["mode"] != "minimal")) { AND ( $module == "network") AND ( $_GET["mode"] != "minimal")) {
// get the page number // get the page number
if (is_string($_GET["page"])) { if (is_string($_GET["page"])) {
@ -1688,12 +1657,12 @@ function infinite_scroll_data($module) {
// try to get the uri from which we load the content // try to get the uri from which we load the content
foreach ($_GET AS $param => $value) { foreach ($_GET AS $param => $value) {
if (($param != "page") AND ($param != "q")) { if (($param != "page") AND ( $param != "q")) {
$reload_uri .= "&" . $param . "=" . urlencode($value); $reload_uri .= "&" . $param . "=" . urlencode($value);
} }
} }
if (($a->page_offset != "") AND !strstr($reload_uri, "&offset=")) { if (($a->page_offset != "") AND ! strstr($reload_uri, "&offset=")) {
$reload_uri .= "&offset=" . urlencode($a->page_offset); $reload_uri .= "&offset=" . urlencode($a->page_offset);
} }

View file

@ -91,7 +91,6 @@ function poller_run($argv, $argc){
if (time() > ($starttime + 3600)) if (time() > ($starttime + 3600))
return; return;
} }
} }
/** /**

View file

@ -16,8 +16,8 @@
use Friendica\App; use Friendica\App;
use Friendica\Core\Config; use Friendica\Core\Config;
require_once('boot.php'); require_once 'boot.php';
require_once('object/BaseObject.php'); require_once 'object/BaseObject.php';
$a = new App; $a = new App;
BaseObject::set_app($a); BaseObject::set_app($a);
@ -74,7 +74,7 @@ if (!$install) {
exit(); exit();
} }
require_once("include/session.php"); require_once 'include/session.php';
load_hooks(); load_hooks();
call_hooks('init_1'); call_hooks('init_1');

View file

@ -375,8 +375,8 @@ class App {
include '.htpreconfig.php'; include '.htpreconfig.php';
} }
if (get_config('config', 'hostname') != '') { if (Config::get('config', 'hostname') != '') {
$this->hostname = get_config('config', 'hostname'); $this->hostname = Config::get('config', 'hostname');
} }
if (!isset($this->hostname) OR ( $this->hostname == '')) { if (!isset($this->hostname) OR ( $this->hostname == '')) {
@ -386,8 +386,8 @@ class App {
} }
function get_hostname() { function get_hostname() {
if (get_config('config', 'hostname') != '') { if (Config::get('config', 'hostname') != '') {
$this->hostname = get_config('config', 'hostname'); $this->hostname = Config::get('config', 'hostname');
} }
return $this->hostname; return $this->hostname;
@ -420,7 +420,7 @@ class App {
} }
function init_pagehead() { function init_pagehead() {
$interval = ((local_user()) ? get_pconfig(local_user(), 'system', 'update_interval') : 40000); $interval = ((local_user()) ? PConfig::get(local_user(), 'system', 'update_interval') : 40000);
// If the update is 'deactivated' set it to the highest integer number (~24 days) // If the update is 'deactivated' set it to the highest integer number (~24 days)
if ($interval < 0) { if ($interval < 0) {
@ -457,12 +457,12 @@ class App {
$stylesheet = '$stylesheet'; $stylesheet = '$stylesheet';
} }
$shortcut_icon = get_config('system', 'shortcut_icon'); $shortcut_icon = Config::get('system', 'shortcut_icon');
if ($shortcut_icon == '') { if ($shortcut_icon == '') {
$shortcut_icon = 'images/friendica-32.png'; $shortcut_icon = 'images/friendica-32.png';
} }
$touch_icon = get_config('system', 'touch_icon'); $touch_icon = Config::get('system', 'touch_icon');
if ($touch_icon == '') { if ($touch_icon == '') {
$touch_icon = 'images/friendica-128.png'; $touch_icon = 'images/friendica-128.png';
} }
@ -773,13 +773,13 @@ class App {
if ($this->is_backend()) { if ($this->is_backend()) {
$process = 'backend'; $process = 'backend';
$max_processes = get_config('system', 'max_processes_backend'); $max_processes = Config::get('system', 'max_processes_backend');
if (intval($max_processes) == 0) { if (intval($max_processes) == 0) {
$max_processes = 5; $max_processes = 5;
} }
} else { } else {
$process = 'frontend'; $process = 'frontend';
$max_processes = get_config('system', 'max_processes_frontend'); $max_processes = Config::get('system', 'max_processes_frontend');
if (intval($max_processes) == 0) { if (intval($max_processes) == 0) {
$max_processes = 20; $max_processes = 20;
} }
@ -845,13 +845,13 @@ class App {
if ($this->is_backend()) { if ($this->is_backend()) {
$process = 'backend'; $process = 'backend';
$maxsysload = intval(get_config('system', 'maxloadavg')); $maxsysload = intval(Config::get('system', 'maxloadavg'));
if ($maxsysload < 1) { if ($maxsysload < 1) {
$maxsysload = 50; $maxsysload = 50;
} }
} else { } else {
$process = 'frontend'; $process = 'frontend';
$maxsysload = intval(get_config('system', 'maxloadavg_frontend')); $maxsysload = intval(Config::get('system', 'maxloadavg_frontend'));
if ($maxsysload < 1) { if ($maxsysload < 1) {
$maxsysload = 50; $maxsysload = 50;
} }
@ -957,5 +957,4 @@ class App {
} }
return true; return true;
} }
} }

View file

@ -1,13 +1,14 @@
<?php <?php
/** /**
* @package util * @package util
*/ */
use Friendica\App; use Friendica\App;
/* /*
* require boot.php * require boot.php
*/ */
require_once("boot.php"); require_once("boot.php");
$a = new App; $a = new App;
@ -18,15 +19,15 @@ load_translation_table($lang);
require_once("include/dba.php"); require_once("include/dba.php");
$db = new dba($db_host, $db_user, $db_pass, $db_data, false); $db = new dba($db_host, $db_user, $db_pass, $db_data, false);
unset($db_host, $db_user, $db_pass, $db_data); unset($db_host, $db_user, $db_pass, $db_data);
$build = get_config('system','build'); $build = get_config('system', 'build');
echo "Old DB VERSION: " . $build . "\n"; echo "Old DB VERSION: " . $build . "\n";
echo "New DB VERSION: " . DB_UPDATE_VERSION . "\n"; echo "New DB VERSION: " . DB_UPDATE_VERSION . "\n";
if($build != DB_UPDATE_VERSION) { if ($build != DB_UPDATE_VERSION) {
echo "Updating database..."; echo "Updating database...";
check_db($a); check_db($a);
echo "Done\n"; echo "Done\n";

View file

@ -1,50 +1,55 @@
<?php <?php
// Tired of chasing typos and finding them after a commit. // Tired of chasing typos and finding them after a commit.
// Run this from cmdline in basedir and quickly see if we've // Run this from cmdline in basedir and quickly see if we've
// got any parse errors in our application files. // got any parse errors in our application files.
use Friendica\App; use Friendica\App;
error_reporting(E_ERROR | E_WARNING | E_PARSE ); error_reporting(E_ERROR | E_WARNING | E_PARSE);
ini_set('display_errors', '1'); ini_set('display_errors', '1');
ini_set('log_errors','0'); ini_set('log_errors', '0');
include 'boot.php'; include 'boot.php';
$a = new App(); $a = new App();
if(x($a->config,'php_path')) if (x($a->config, 'php_path')) {
$phpath = $a->config['php_path']; $phpath = $a->config['php_path'];
else } else {
$phpath = 'php'; $phpath = 'php';
}
echo "Directory: mod\n"; echo "Directory: mod\n";
$files = glob('mod/*.php'); $files = glob('mod/*.php');
foreach($files as $file) { foreach ($files as $file) {
passthru("$phpath -l $file", $ret); $ret===0 or die(); passthru("$phpath -l $file", $ret);
$ret === 0 or die();
} }
echo "Directory: include\n"; echo "Directory: include\n";
$files = glob('include/*.php'); $files = glob('include/*.php');
foreach($files as $file) { foreach ($files as $file) {
passthru("$phpath -l $file", $ret); $ret===0 or die(); passthru("$phpath -l $file", $ret);
$ret === 0 or die();
} }
echo "Directory: object\n"; echo "Directory: object\n";
$files = glob('object/*.php'); $files = glob('object/*.php');
foreach($files as $file) { foreach ($files as $file) {
passthru("$phpath -l $file", $ret); $ret===0 or die(); passthru("$phpath -l $file", $ret);
$ret === 0 or die();
} }
echo "Directory: addon\n"; echo "Directory: addon\n";
$dirs = glob('addon/*'); $dirs = glob('addon/*');
foreach($dirs as $dir) { foreach ($dirs as $dir) {
$addon = basename($dir); $addon = basename($dir);
$files = glob($dir . '/' . $addon . '.php'); $files = glob($dir . '/' . $addon . '.php');
foreach($files as $file) { foreach ($files as $file) {
passthru("$phpath -l $file", $ret); $ret===0 or die(); passthru("$phpath -l $file", $ret);
$ret === 0 or die();
} }
} }
@ -52,9 +57,11 @@ foreach($dirs as $dir) {
echo "String files\n"; echo "String files\n";
echo 'util/strings.php' . "\n"; echo 'util/strings.php' . "\n";
passthru("$phpath -l util/strings.php", $ret); $ret===0 or die(); passthru("$phpath -l util/strings.php", $ret);
$ret === 0 or die();
$files = glob('view/lang/*/strings.php'); $files = glob('view/lang/*/strings.php');
foreach($files as $file) { foreach ($files as $file) {
passthru("$phpath -l $file", $ret); $ret===0 or die(); passthru("$phpath -l $file", $ret);
$ret === 0 or die();
} }