<?php
+
/** @file boot.php
*
* This file defines some global constants and includes the central App class.
* 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\Core\System;
use Friendica\Core\Config;
-
-require_once('include/config.php');
-require_once('include/network.php');
-require_once('include/plugin.php');
-require_once('include/text.php');
-require_once('include/datetime.php');
-require_once('include/pgettext.php');
-require_once('include/nav.php');
-require_once('include/cache.php');
-require_once('include/features.php');
-require_once('include/identity.php');
-require_once('update.php');
-require_once('include/dbstructure.php');
+use Friendica\Util\Lock;
+
+require_once 'include/config.php';
+require_once 'include/network.php';
+require_once 'include/plugin.php';
+require_once 'include/text.php';
+require_once 'include/datetime.php';
+require_once 'include/pgettext.php';
+require_once 'include/nav.php';
+require_once 'include/cache.php';
+require_once 'include/features.php';
+require_once 'include/identity.php';
+require_once 'update.php';
+require_once 'include/dbstructure.php';
+require_once 'include/poller.php';
define ( 'FRIENDICA_PLATFORM', 'Friendica');
define ( 'FRIENDICA_CODENAME', 'Asparagus');
-define ( 'FRIENDICA_VERSION', '3.5.2-dev' );
+define ( 'FRIENDICA_VERSION', '3.5.3-dev' );
define ( 'DFRN_PROTOCOL_VERSION', '2.23' );
-define ( 'DB_UPDATE_VERSION', 1222 );
+define ( 'DB_UPDATE_VERSION', 1234 );
/**
* @brief Constant with a HTML line break.
define ( 'EOL', "<br />\r\n" );
define ( 'ATOM_TIME', 'Y-m-d\TH:i:s\Z' );
-
/**
* @brief Image storage quality.
*
* below about 50
*
*/
-
define ( 'JPEG_QUALITY', 100 );
+
/**
* $a->config['system']['png_quality'] from 0 (uncompressed) to 9
*/
*/
define ( 'MAX_IMAGE_LENGTH', -1 );
-
/**
* Not yet used
*/
-
-define ( 'DEFAULT_DB_ENGINE', 'MyISAM' );
+define ( 'DEFAULT_DB_ENGINE', 'InnoDB' );
/**
* @name SSL Policy
define ( 'UPDATE_FAILED', 1);
/** @}*/
-
/**
* @name page/profile types
*
define('PROTOCOL_DFRN', 1);
define('PROTOCOL_DIASPORA', 2);
define('PROTOCOL_OSTATUS_SALMON', 3);
-define('PROTOCOL_OSTATUS_FEED', 4);
-define('PROTOCOL_GS_CONVERSATION', 5);
+define('PROTOCOL_OSTATUS_FEED', 4); // Deprecated
+define('PROTOCOL_GS_CONVERSATION', 5); // Deprecated
+define('PROTOCOL_SPLITTED_CONV', 6);
/** @}*/
/**
NETWORK_PHANTOM => (-127),
);
-
/**
* Maximum number of "people who like (or don't like) this" that we will list by name
*/
-
define ( 'MAX_LIKERS', 75);
/**
* Communication timeout
*/
-
define ( 'ZCURL_TIMEOUT' , (-1));
-
/**
* @name Notify
*
define ( 'NOTIFY_POKE', 0x0200 );
define ( 'NOTIFY_SHARE', 0x0400 );
+define ( 'SYSTEM_EMAIL', 0x4000 );
+
define ( 'NOTIFY_SYSTEM', 0x8000 );
/* @}*/
define ( 'TERM_OBJ_POST', 1 );
define ( 'TERM_OBJ_PHOTO', 2 );
-
-
/**
* @name Namespaces
*
/**
* Lowest possible date time value
*/
-
define ('NULL_DATE', '0001-01-01 00:00:00');
-
// Normally this constant is defined - but not if "pcntl" isn't installed
if (!defined("SIGTERM")) {
define("SIGTERM", 15);
}
+
+/**
+ * Depending on the PHP version this constant does exist - or not.
+ * See here: http://php.net/manual/en/curl.constants.php#117928
+ */
+if (!defined('CURLE_OPERATION_TIMEDOUT')) {
+ define('CURLE_OPERATION_TIMEDOUT', CURLE_OPERATION_TIMEOUTED);
+}
/**
*
* Reverse the effect of magic_quotes_gpc if it is enabled.
* See http://php.net/manual/en/security.magicquotes.disabling.php
*
*/
-
function startup() {
-
error_reporting(E_ERROR | E_WARNING | E_PARSE);
set_time_limit(0);
// This has to be quite large to deal with embedded private photos
ini_set('pcre.backtrack_limit', 500000);
-
if (get_magic_quotes_gpc()) {
$process = array(&$_GET, &$_POST, &$_COOKIE, &$_REQUEST);
while (list($key, $val) = each($process)) {
}
unset($process);
}
-
}
/**
return $a;
}
-
/**
* @brief Multi-purpose function to check variable state.
*
*
* @return bool|int
*/
-function x($s,$k = NULL) {
+function x($s, $k = NULL) {
if ($k != NULL) {
if ((is_array($s)) && (array_key_exists($k, $s))) {
if ($s[$k]) {
}
}
-
/**
* @brief Called from db initialisation if db is dead.
*/
killme();
}
-
-function clean_urls() {
- $a = get_app();
- return true;
-}
-
-function z_path() {
- $base = App::get_baseurl();
-
- if (! clean_urls()) {
- $base .= '/?q=';
- }
-
- return $base;
-}
-
/**
* @brief Returns the baseurl.
*
- * @see App::get_baseurl()
+ * @see System::baseUrl()
*
* @return string
- * @TODO Maybe super-flous and deprecated? Seems to only wrap App::get_baseurl()
+ * @TODO Function is deprecated and only used in some addons
*/
function z_root() {
- return App::get_baseurl();
+ return System::baseUrl();
}
/**
* @return string
*/
function absurl($path) {
- if (strpos($path,'/') === 0) {
+ if (strpos($path, '/') === 0) {
return z_path() . $path;
}
return $path;
function check_db() {
- $build = get_config('system','build');
- if (! x($build)) {
- set_config('system','build',DB_UPDATE_VERSION);
+ $build = get_config('system', 'build');
+ if (!x($build)) {
+ set_config('system', 'build', DB_UPDATE_VERSION);
$build = DB_UPDATE_VERSION;
}
if ($build != DB_UPDATE_VERSION) {
proc_run(PRIORITY_CRITICAL, 'include/dbupdate.php');
}
-
}
-
/**
* Sets the base url for use in cmdline programs which don't have
* $_SERVER variables
*/
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
// than the currently visited url, store the current value accordingly.
// and www.example.com vs example.com.
// We will only change the url to an ip address if there is no existing setting
- if (! x($url)) {
- $url = set_config('system','url',App::get_baseurl());
+ if (!x($url)) {
+ $url = set_config('system', 'url', System::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))) {
- $url = set_config('system','url',App::get_baseurl());
+ if ((!link_compare($url, System::baseUrl())) && (!preg_match("/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/", $a->get_hostname))) {
+ $url = set_config('system', 'url', System::baseUrl());
}
return;
}
-
/**
* @brief Automatic database updates
*/
function update_db(App $a) {
- $build = get_config('system','build');
- if (! x($build)) {
- $build = set_config('system','build',DB_UPDATE_VERSION);
+ $build = get_config('system', 'build');
+ if (!x($build)) {
+ $build = set_config('system', 'build', DB_UPDATE_VERSION);
}
if ($build != DB_UPDATE_VERSION) {
// We're reporting a different version than what is currently installed.
// 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
// 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.
if (DB_UPDATE_VERSION == UPDATE_VERSION) {
// 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) {
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
// conflits with new routine)
);
return;
} 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
// We want exactly one process to run the update command.
// So store the fact that we're taking responsibility
// after first checking to see if somebody else already has.
-
// If the update fails or times-out completely you may need to
// delete the config entry to try again.
- $t = get_config('database','update_' . $x);
+ $t = get_config('database', 'update_' . $x);
if ($t !== false) {
return false;
}
- set_config('database','update_' . $x, time());
+ set_config('database', 'update_' . $x, time());
// call the specific update
);
return false;
} else {
- set_config('database','update_' . $x, 'success');
- set_config('system','build', $x + 1);
+ set_config('database', 'update_' . $x, 'success');
+ set_config('system', 'build', $x + 1);
return true;
}
} else {
- set_config('database','update_' . $x, 'success');
- set_config('system','build', $x + 1);
+ set_config('database', 'update_' . $x, 'success');
+ set_config('system', 'build', $x + 1);
return true;
}
return true;
$installed = array();
}
- $plugins = get_config('system','addon');
+ $plugins = get_config('system', 'addon');
$plugins_arr = array();
if ($plugins) {
- $plugins_arr = explode(',',str_replace(' ', '',$plugins));
+ $plugins_arr = explode(',', str_replace(' ', '', $plugins));
}
$a->plugins = $plugins_arr;
if (count($installed)) {
foreach ($installed as $i) {
- if (! in_array($i['name'],$plugins_arr)) {
+ if (!in_array($i['name'], $plugins_arr)) {
uninstall_plugin($i['name']);
} else {
$installed_arr[] = $i['name'];
if (count($plugins_arr)) {
foreach ($plugins_arr as $p) {
- if (! in_array($p,$installed_arr)) {
+ if (!in_array($p, $installed_arr)) {
install_plugin($p);
}
}
}
-
load_hooks();
return;
}
-function get_guid($size=16, $prefix = "") {
-
+function get_guid($size = 16, $prefix = "") {
if ($prefix == "") {
$a = get_app();
$prefix = hash("crc32", $a->get_hostname());
* @hooks 'login_hook'
* string $o
*/
-function login($register = false, $hiddens=false) {
+function login($register = false, $hiddens = false) {
$a = get_app();
$o = "";
$reg = false;
);
}
- $noid = get_config('system','no_openid');
+ $noid = get_config('system', 'no_openid');
$dest_url = $a->query_string;
if (local_user()) {
$tpl = get_markup_template("logout.tpl");
} 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)
));
'$privacytitle' => t('Website Privacy Policy'),
'$privacylink' => t('privacy policy'),
-
));
- call_hooks('login_hook',$o);
+ call_hooks('login_hook', $o);
return $o;
}
* @brief Used to end the current process, after saving session state.
*/
function killme() {
-
if (!get_app()->is_backend()) {
session_write_close();
}
*/
function goaway($s) {
if (!strstr(normalise_link($s), "http://")) {
- $s = App::get_baseurl()."/".$s;
+ $s = System::baseUrl() . "/" . $s;
}
header("Location: $s");
killme();
}
-
/**
* @brief Returns the user id of locally logged in user or false.
*
* @return int|bool visitor_id or false
*/
function remote_user() {
- if ((x($_SESSION,'authenticated')) && (x($_SESSION,'visitor_id'))) {
+ // You cannot be both local and remote
+ if (local_user()) {
+ return false;
+ }
+ if ((x($_SESSION, 'authenticated')) && (x($_SESSION, 'visitor_id'))) {
return intval($_SESSION['visitor_id']);
}
return false;
*/
function notice($s) {
$a = get_app();
- if (! x($_SESSION,'sysmsg')) {
+ if (!x($_SESSION, 'sysmsg')) {
$_SESSION['sysmsg'] = array();
}
if ($a->interactive) {
function info($s) {
$a = get_app();
- if (local_user() AND get_pconfig(local_user(),'system','ignore_info')) {
+ if (local_user() && get_pconfig(local_user(), 'system', 'ignore_info')) {
return;
}
- if (! x($_SESSION,'sysmsg_info')) {
+ if (!x($_SESSION, 'sysmsg_info')) {
$_SESSION['sysmsg_info'] = array();
}
if ($a->interactive) {
}
}
-
/**
* @brief Wrapper around config to limit the text length of an incoming message
*
*/
function get_max_import_size() {
$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 );
}
/**
* @brief Wrap calls to proc_close(proc_open()) and call hook
- * so plugins can take part in process :)
+ * so plugins can take part in process :)
*
* @param (integer|array) priority or parameter array, $cmd atrings are deprecated and are ignored
*
* @note $cmd and string args are surrounded with ""
*
* @hooks 'proc_run'
- * array $arr
+ * array $arr
*/
-function proc_run($cmd){
+function proc_run($cmd) {
$a = get_app();
$arr = array('args' => $args, 'run_cmd' => true);
call_hooks("proc_run", $arr);
- if (!$arr['run_cmd'] OR !count($args)) {
+ if (!$arr['run_cmd'] || ! count($args)) {
return;
}
$priority = PRIORITY_MEDIUM;
$dont_fork = get_config("system", "worker_dont_fork");
+ $created = datetime_convert();
if (is_int($run_parameter)) {
$priority = $run_parameter;
if (isset($run_parameter['priority'])) {
$priority = $run_parameter['priority'];
}
+ if (isset($run_parameter['created'])) {
+ $created = $run_parameter['created'];
+ }
if (isset($run_parameter['dont_fork'])) {
$dont_fork = $run_parameter['dont_fork'];
}
array_shift($argv);
$parameters = json_encode($argv);
- $found = q("SELECT `id` FROM `workerqueue` WHERE `parameter` = '%s'",
- dbesc($parameters));
+ $found = dba::exists('workerqueue', array('parameter' => $parameters, 'done' => false));
- if (!dbm::is_result($found)) {
- q("INSERT INTO `workerqueue` (`parameter`, `created`, `priority`)
- VALUES ('%s', '%s', %d)",
- dbesc($parameters),
- dbesc(datetime_convert()),
- intval($priority));
+ if (!$found) {
+ dba::insert('workerqueue', array('parameter' => $parameters, 'created' => $created, 'priority' => $priority));
}
// Should we quit and wait for the poller to be called as a cronjob?
return;
}
- // Checking number of workers
- $workers = q("SELECT COUNT(*) AS `workers` FROM `workerqueue` WHERE `executed` > '%s'", dbesc(NULL_DATE));
-
- // Get number of allowed number of worker threads
- $queues = intval(get_config("system", "worker_queues"));
-
- if ($queues == 0) {
- $queues = 4;
+ // If there is a lock then we don't have to check for too much worker
+ if (!Lock::set('poller_worker', 0)) {
+ return;
}
// If there are already enough workers running, don't fork another one
- if ($workers[0]["workers"] >= $queues) {
+ $quit = poller_too_much_workers();
+ Lock::remove('poller_worker');
+
+ if ($quit) {
return;
}
$a->proc_run($args);
}
-function current_theme(){
+function current_theme() {
$app_base_themes = array('duepuntozero', 'dispy', 'quattro');
$a = get_app();
// This works only if the user is on the same server
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;
}
}
$is_mobile = $a->is_mobile || $a->is_tablet;
$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 (isset($_SESSION['show-mobile']) && !$_SESSION['show-mobile']) {
if ($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 === '---') {
// user has selected to have the mobile theme be the same as the normal one
}
if ($theme_name &&
- (file_exists('view/theme/' . $theme_name . '/style.css') ||
- file_exists('view/theme/' . $theme_name . '/style.php'))) {
+ (file_exists('view/theme/' . $theme_name . '/style.css') ||
+ file_exists('view/theme/' . $theme_name . '/style.php'))) {
return($theme_name);
}
foreach ($app_base_themes as $t) {
if (file_exists('view/theme/' . $t . '/style.css') ||
- file_exists('view/theme/' . $t . '/style.php')) {
+ file_exists('view/theme/' . $t . '/style.php')) {
return($t);
}
}
- $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)) {
- 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?
$opts = (($a->profile_uid) ? '?f=&puid=' . $a->profile_uid : '');
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) {
/**
*
* 6:00PM the day before, but that will correspond to midnight to the birthday person.
*
*/
-
-
$birthday = '';
- if (! strlen($tz)) {
+ if (!strlen($tz)) {
$tz = 'UTC';
}
);
if (dbm::is_result($p)) {
- $tmp_dob = substr($p[0]['dob'],5);
+ $tmp_dob = substr($p[0]['dob'], 5);
if (intval($tmp_dob)) {
- $y = datetime_convert($tz,$tz,'now','Y');
+ $y = datetime_convert($tz, $tz, 'now', 'Y');
$bd = $y . '-' . $tmp_dob . ' 00:00';
$t_dob = strtotime($bd);
- $now = strtotime(datetime_convert($tz,$tz,'now'));
+ $now = strtotime(datetime_convert($tz, $tz, 'now'));
if ($t_dob < $now) {
$bd = $y + 1 . '-' . $tmp_dob . ' 00:00';
}
- $birthday = datetime_convert($tz,'UTC',$bd,ATOM_TIME);
+ $birthday = datetime_convert($tz, 'UTC', $bd, ATOM_TIME);
}
}
$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') && 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 false;
if ($name == null) {
$ret .= build_querystring($val, $key);
} else {
- $ret .= build_querystring($val, $name."[$key]");
+ $ret .= build_querystring($val, $name . "[$key]");
}
} else {
$val = urlencode($val);
}
/**
-* 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
-*/
+ * 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
+ */
function curPageURL() {
$pageURL = 'http';
if ($_SERVER["HTTPS"] == "on") {
$pageURL .= "://";
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 {
- $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
+ $pageURL .= $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"];
}
return $pageURL;
}
$rn = '';
for ($i = 0; $i < $digits; $i++) {
/// @TODO rand() is different to mt_rand() and maybe lesser "random"
- $rn .= rand(0,9);
+ $rn .= rand(0, 9);
}
return $rn;
}
$server = get_config("system", "directory");
if ($server == "") {
- $server = "http://dir.friendi.ca";
+ $server = "http://dir.friendica.social";
}
return($server);
}
+function get_temppath() {
+ $a = get_app();
+
+ $temppath = get_config("system", "temppath");
+
+ if (($temppath != "") && App::directory_usable($temppath)) {
+ // We have a temp path and it is usable
+ return App::realpath($temppath);
+ }
+
+ // We don't have a working preconfigured temp path, so we take the system path.
+ $temppath = sys_get_temp_dir();
+
+ // Check if it is usable
+ if (($temppath != "") && App::directory_usable($temppath)) {
+ // Always store the real path, not the path through symlinks
+ $temppath = App::realpath($temppath);
+
+ // To avoid any interferences with other systems we create our own directory
+ $new_temppath = $temppath . "/" . $a->get_hostname();
+ if (!is_dir($new_temppath)) {
+ /// @TODO There is a mkdir()+chmod() upwards, maybe generalize this (+ configurable) into a function/method?
+ mkdir($new_temppath);
+ }
+
+ if (App::directory_usable($new_temppath)) {
+ // The new path is usable, we are happy
+ set_config("system", "temppath", $new_temppath);
+ return $new_temppath;
+ } else {
+ // We can't create a subdirectory, strange.
+ // But the directory seems to work, so we use it but don't store it.
+ return $temppath;
+ }
+ }
+
+ // Reaching this point means that the operating system is configured badly.
+ return '';
+}
+
function get_cachefile($file, $writemode = true) {
$cache = get_itemcachepath();
- if ((! $cache) || (! is_dir($cache))) {
+ if ((!$cache) || (!is_dir($cache))) {
return("");
}
$path = $basepath;
}
- if (($path == "") OR (!is_dir($path))) {
+ if (($path == "") || (!is_dir($path))) {
return;
}
return;
}
- $cachetime = (int)get_config('system','itemcache_duration');
+ $cachetime = (int) get_config('system', 'itemcache_duration');
if ($cachetime == 0) {
$cachetime = 86400;
}
- if (is_writable($path)){
+ if (is_writable($path)) {
if ($dh = opendir($path)) {
while (($file = readdir($dh)) !== false) {
- $fullpath = $path."/".$file;
- if ((filetype($fullpath) == "dir") and ($file != ".") and ($file != "..")) {
+ $fullpath = $path . "/" . $file;
+ if ((filetype($fullpath) == "dir") && ($file != ".") && ($file != "..")) {
clear_cache($basepath, $fullpath);
}
- if ((filetype($fullpath) == "file") and (filectime($fullpath) < (time() - $cachetime))) {
+ if ((filetype($fullpath) == "file") && (filectime($fullpath) < (time() - $cachetime))) {
unlink($fullpath);
}
}
function get_itemcachepath() {
// Checking, if the cache is deactivated
- $cachetime = (int)get_config('system','itemcache_duration');
+ $cachetime = (int) get_config('system', 'itemcache_duration');
if ($cachetime < 0) {
return "";
}
- $itemcache = get_config('system','itemcache');
- if (($itemcache != "") AND App::directory_usable($itemcache)) {
- return $itemcache;
+ $itemcache = get_config('system', 'itemcache');
+ if (($itemcache != "") && App::directory_usable($itemcache)) {
+ return App::realpath($itemcache);
}
$temppath = get_temppath();
if ($temppath != "") {
- $itemcache = $temppath."/itemcache";
+ $itemcache = $temppath . "/itemcache";
if (!file_exists($itemcache) && !is_dir($itemcache)) {
mkdir($itemcache);
}
* @return string Spool path
*/
function get_spoolpath() {
- $spoolpath = get_config('system','spoolpath');
- if (($spoolpath != "") AND App::directory_usable($spoolpath)) {
+ $spoolpath = get_config('system', 'spoolpath');
+ if (($spoolpath != "") && App::directory_usable($spoolpath)) {
// We have a spool path and it is usable
return $spoolpath;
}
if ($temppath != "") {
// To avoid any interferences with other systems we create our own directory
- $spoolpath = $temppath."/spool";
+ $spoolpath = $temppath . "/spool";
if (!is_dir($spoolpath)) {
mkdir($spoolpath);
}
return "";
}
-function get_temppath() {
- $a = get_app();
-
- $temppath = get_config("system", "temppath");
-
- if (($temppath != "") AND App::directory_usable($temppath)) {
- // We have a temp path and it is usable
- return $temppath;
- }
-
- // We don't have a working preconfigured temp path, so we take the system path.
- $temppath = sys_get_temp_dir();
-
- // Check if it is usable
- if (($temppath != "") AND App::directory_usable($temppath)) {
- // To avoid any interferences with other systems we create our own directory
- $new_temppath = $temppath."/".$a->get_hostname();
- if (!is_dir($new_temppath)) {
- /// @TODO There is a mkdir()+chmod() upwards, maybe generalize this (+ configurable) into a function/method?
- mkdir($new_temppath);
- }
-
- if (App::directory_usable($new_temppath)) {
- // The new path is usable, we are happy
- set_config("system", "temppath", $new_temppath);
- return $new_temppath;
- } else {
- // We can't create a subdirectory, strange.
- // But the directory seems to work, so we use it but don't store it.
- return $temppath;
- }
- }
-
- // Reaching this point means that the operating system is configured badly.
- return '';
-}
-
/// @deprecated
function set_template_engine(App $a, $engine = 'internal') {
/// @note This function is no longer necessary, but keep it as a wrapper to the class method
return false;
}
- $file = str_replace(getcwd()."/", "", $file, $count);
+ $file = str_replace(getcwd() . "/", "", $file, $count);
if ($count != 1) {
return false;
}
* @return string Value of the argv key
*/
function argv($x) {
- if (array_key_exists($x,get_app()->argv)) {
+ if (array_key_exists($x, get_app()->argv)) {
return get_app()->argv[$x];
}
*
* @param string $module The name of the module (e.g. "network")
* @return array Of infinite scroll data
- * 'pageno' => $pageno The number of the actual page
- * 'reload_uri' => $reload_uri The URI of the content we have to load
+ * 'pageno' => $pageno The number of the actual page
+ * 'reload_uri' => $reload_uri The URI of the content we have to load
*/
function infinite_scroll_data($module) {
- if (get_pconfig(local_user(),'system','infinite_scroll')
- AND ($module == "network") AND ($_GET["mode"] != "minimal")) {
+ if (get_pconfig(local_user(), 'system', 'infinite_scroll')
+ && ($module == "network") && ($_GET["mode"] != "minimal")) {
// get the page number
if (is_string($_GET["page"])) {
// try to get the uri from which we load the content
foreach ($_GET AS $param => $value) {
- if (($param != "page") AND ($param != "q")) {
+ if (($param != "page") && ($param != "q")) {
$reload_uri .= "&" . $param . "=" . urlencode($value);
}
}
- if (($a->page_offset != "") AND !strstr($reload_uri, "&offset=")) {
+ if (($a->page_offset != "") && ! strstr($reload_uri, "&offset=")) {
$reload_uri .= "&offset=" . urlencode($a->page_offset);
}