5 use Friendica\Core\Config;
6 use Friendica\Core\PConfig;
11 use Detection\MobileDetect;
19 * @brief Our main application structure for the life of this page.
21 * Primarily deals with the URL that got us here
22 * and tries to make some sense of it, and
23 * stores our page contents and config storage
24 * and anything else that might need to be passed around
25 * before we spit the page out.
30 public $module_loaded = false;
42 public $data = array();
43 public $error = false;
54 public $interactive = true;
56 public $apps = array();
58 public $is_mobile = false;
59 public $is_tablet = false;
60 public $is_friendica_app;
61 public $performance = array();
62 public $callstack = array();
63 public $theme_info = array();
64 public $backend = true;
67 // Allow themes to control internal parameters
68 // by changing App values in theme.php
70 public $sourcename = '';
71 public $videowidth = 425;
72 public $videoheight = 350;
73 public $force_max_items = 0;
74 public $theme_thread_allow = true;
75 public $theme_events_in_profile = true;
78 * @brief An array for all theme-controllable parameters
80 * Mostly unimplemented yet. Only options 'template_engine' and
83 public $theme = array(
87 'force_max_items' => 0,
88 'thread_allow' => true,
90 'template_engine' => 'smarty3',
94 * @brief An array of registered template engines ('name'=>'class name')
96 public $template_engines = array();
99 * @brief An array of instanced template engines ('name'=>'instance')
101 public $template_engine_instance = array();
104 private $ldelim = array(
108 private $rdelim = array(
116 private $curl_content_type;
117 private $curl_headers;
118 private $cached_profile_image;
119 private $cached_profile_picdate;
123 * @brief App constructor.
125 * @param string $basepath Path to the app base folder
127 function __construct($basepath) {
129 global $default_timezone;
133 if (file_exists('.htpreconfig.php')) {
134 include '.htpreconfig.php';
137 $this->timezone = ((x($default_timezone)) ? $default_timezone : 'UTC');
139 date_default_timezone_set($this->timezone);
141 $this->performance['start'] = microtime(true);
142 $this->performance['database'] = 0;
143 $this->performance['database_write'] = 0;
144 $this->performance['network'] = 0;
145 $this->performance['file'] = 0;
146 $this->performance['rendering'] = 0;
147 $this->performance['parser'] = 0;
148 $this->performance['marktime'] = 0;
149 $this->performance['markstart'] = microtime(true);
151 $this->callstack['database'] = array();
152 $this->callstack['database_write'] = array();
153 $this->callstack['network'] = array();
154 $this->callstack['file'] = array();
155 $this->callstack['rendering'] = array();
156 $this->callstack['parser'] = array();
158 $this->config = array();
159 $this->page = array();
160 $this->pager = array();
162 $this->query_string = '';
164 $this->process_id = uniqid('log', true);
168 $this->scheme = 'http';
170 if ((x($_SERVER, 'HTTPS') && $_SERVER['HTTPS']) ||
171 (x($_SERVER, 'HTTP_FORWARDED') && preg_match('/proto=https/', $_SERVER['HTTP_FORWARDED'])) ||
172 (x($_SERVER, 'HTTP_X_FORWARDED_PROTO') && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https') ||
173 (x($_SERVER, 'HTTP_X_FORWARDED_SSL') && $_SERVER['HTTP_X_FORWARDED_SSL'] == 'on') ||
174 (x($_SERVER, 'FRONT_END_HTTPS') && $_SERVER['FRONT_END_HTTPS'] == 'on') ||
175 (x($_SERVER, 'SERVER_PORT') && (intval($_SERVER['SERVER_PORT']) == 443)) // XXX: reasonable assumption, but isn't this hardcoding too much?
177 $this->scheme = 'https';
180 if (x($_SERVER, 'SERVER_NAME')) {
181 $this->hostname = $_SERVER['SERVER_NAME'];
183 if (x($_SERVER, 'SERVER_PORT') && $_SERVER['SERVER_PORT'] != 80 && $_SERVER['SERVER_PORT'] != 443) {
184 $this->hostname .= ':' . $_SERVER['SERVER_PORT'];
187 * Figure out if we are running at the top of a domain
188 * or in a sub-directory and adjust accordingly
191 /// @TODO This kind of escaping breaks syntax-highlightning on CoolEdit (Midnight Commander)
192 $path = trim(dirname($_SERVER['SCRIPT_NAME']), '/\\');
193 if (isset($path) && strlen($path) && ($path != $this->path)) {
198 if ($hostname != '') {
199 $this->hostname = $hostname;
202 if (! static::directory_usable($basepath, false)) {
203 throw new Exception('Basepath ' . $basepath . ' isn\'t usable.');
206 $this->basepath = rtrim($basepath, DIRECTORY_SEPARATOR);
209 get_include_path() . PATH_SEPARATOR
210 . $this->basepath . DIRECTORY_SEPARATOR . 'include' . PATH_SEPARATOR
211 . $this->basepath . DIRECTORY_SEPARATOR . 'library' . PATH_SEPARATOR
212 . $this->basepath . DIRECTORY_SEPARATOR . 'library/langdet' . PATH_SEPARATOR
216 if (is_array($_SERVER['argv']) && $_SERVER['argc'] > 1 && substr(end($_SERVER['argv']), 0, 4) == 'http') {
217 $this->set_baseurl(array_pop($_SERVER['argv']));
221 if ((x($_SERVER, 'QUERY_STRING')) && substr($_SERVER['QUERY_STRING'], 0, 9) === 'pagename=') {
222 $this->query_string = substr($_SERVER['QUERY_STRING'], 9);
224 // removing trailing / - maybe a nginx problem
225 $this->query_string = ltrim($this->query_string, '/');
226 } elseif ((x($_SERVER, 'QUERY_STRING')) && substr($_SERVER['QUERY_STRING'], 0, 2) === 'q=') {
227 $this->query_string = substr($_SERVER['QUERY_STRING'], 2);
229 // removing trailing / - maybe a nginx problem
230 $this->query_string = ltrim($this->query_string, '/');
233 if (x($_GET, 'pagename')) {
234 $this->cmd = trim($_GET['pagename'], '/\\');
235 } elseif (x($_GET, 'q')) {
236 $this->cmd = trim($_GET['q'], '/\\');
240 $this->query_string = str_replace($this->cmd . '&', $this->cmd . '?', $this->query_string);
242 // unix style "homedir"
243 if (substr($this->cmd, 0, 1) === '~') {
244 $this->cmd = 'profile/' . substr($this->cmd, 1);
247 // Diaspora style profile url
248 if (substr($this->cmd, 0, 2) === 'u/') {
249 $this->cmd = 'profile/' . substr($this->cmd, 2);
253 * Break the URL path into C style argc/argv style arguments for our
254 * modules. Given "http://example.com/module/arg1/arg2", $this->argc
255 * will be 3 (integer) and $this->argv will contain:
261 * There will always be one argument. If provided a naked domain
262 * URL, $this->argv[0] is set to "home".
265 $this->argv = explode('/', $this->cmd);
266 $this->argc = count($this->argv);
267 if ((array_key_exists('0', $this->argv)) && strlen($this->argv[0])) {
268 $this->module = str_replace('.', '_', $this->argv[0]);
269 $this->module = str_replace('-', '_', $this->module);
272 $this->argv = array('home');
273 $this->module = 'home';
276 // See if there is any page number information, and initialise pagination
277 $this->pager['page'] = ((x($_GET, 'page') && intval($_GET['page']) > 0) ? intval($_GET['page']) : 1);
278 $this->pager['itemspage'] = 50;
279 $this->pager['start'] = ($this->pager['page'] * $this->pager['itemspage']) - $this->pager['itemspage'];
281 if ($this->pager['start'] < 0) {
282 $this->pager['start'] = 0;
284 $this->pager['total'] = 0;
286 // Detect mobile devices
287 $mobile_detect = new MobileDetect();
288 $this->is_mobile = $mobile_detect->isMobile();
289 $this->is_tablet = $mobile_detect->isTablet();
292 $this->is_friendica_app = ($_SERVER['HTTP_USER_AGENT'] == 'Apache-HttpClient/UNAVAILABLE (java 1.4)');
294 // Register template engines
295 $dc = get_declared_classes();
296 foreach ($dc as $k) {
297 if (in_array('ITemplateEngine', class_implements($k))) {
298 $this->register_template_engine($k);
306 * @brief Returns the base filesystem path of the App
308 * It first checks for the internal variable, then for DOCUMENT_ROOT and
313 public static function get_basepath() {
315 $basepath = $this->basepath;
319 $basepath = Config::get('system', 'basepath');
322 if (! $basepath && x($_SERVER, 'DOCUMENT_ROOT')) {
323 $basepath = $_SERVER['DOCUMENT_ROOT'];
326 if (! $basepath && x($_SERVER, 'PWD')) {
327 $basepath = $_SERVER['PWD'];
333 function get_scheme() {
334 return $this->scheme;
338 * @brief Retrieves the Friendica instance base URL
340 * This function assembles the base URL from multiple parts:
341 * - Protocol is determined either by the request or a combination of
342 * system.ssl_policy and the $ssl parameter.
343 * - Host name is determined either by system.hostname or inferred from request
344 * - Path is inferred from SCRIPT_NAME
346 * Note: $ssl parameter value doesn't directly correlate with the resulting protocol
348 * @param bool $ssl Whether to append http or https under SSL_POLICY_SELFSIGN
349 * @return string Friendica server base URL
351 function get_baseurl($ssl = false) {
352 // Is the function called statically?
353 if (!(isset($this) && get_class($this) == __CLASS__)) {
354 return self::$a->get_baseurl($ssl);
357 $scheme = $this->scheme;
359 if (Config::get('system', 'ssl_policy') == SSL_POLICY_FULL) {
363 // Basically, we have $ssl = true on any links which can only be seen by a logged in user
364 // (and also the login link). Anything seen by an outsider will have it turned off.
366 if (Config::get('system', 'ssl_policy') == SSL_POLICY_SELFSIGN) {
374 if (Config::get('config', 'hostname') != '') {
375 $this->hostname = Config::get('config', 'hostname');
378 return $scheme . '://' . $this->hostname . ((isset($this->path) && strlen($this->path)) ? '/' . $this->path : '' );
382 * @brief Initializes the baseurl components
384 * Clears the baseurl cache to prevent inconstistencies
388 function set_baseurl($url) {
389 $parsed = @parse_url($url);
392 $this->scheme = $parsed['scheme'];
394 $hostname = $parsed['host'];
395 if (x($parsed, 'port')) {
396 $hostname .= ':' . $parsed['port'];
398 if (x($parsed, 'path')) {
399 $this->path = trim($parsed['path'], '\\/');
402 if (file_exists('.htpreconfig.php')) {
403 include '.htpreconfig.php';
406 if (Config::get('config', 'hostname') != '') {
407 $this->hostname = Config::get('config', 'hostname');
410 if (!isset($this->hostname) || ( $this->hostname == '')) {
411 $this->hostname = $hostname;
416 function get_hostname() {
417 if (Config::get('config', 'hostname') != '') {
418 $this->hostname = Config::get('config', 'hostname');
421 return $this->hostname;
424 function set_hostname($h) {
425 $this->hostname = $h;
428 function set_path($p) {
429 $this->path = trim(trim($p), '/');
432 function get_path() {
436 function set_pager_total($n) {
437 $this->pager['total'] = intval($n);
440 function set_pager_itemspage($n) {
441 $this->pager['itemspage'] = ((intval($n) > 0) ? intval($n) : 0);
442 $this->pager['start'] = ($this->pager['page'] * $this->pager['itemspage']) - $this->pager['itemspage'];
445 function set_pager_page($n) {
446 $this->pager['page'] = $n;
447 $this->pager['start'] = ($this->pager['page'] * $this->pager['itemspage']) - $this->pager['itemspage'];
450 function init_pagehead() {
451 $interval = ((local_user()) ? PConfig::get(local_user(), 'system', 'update_interval') : 40000);
453 // If the update is 'deactivated' set it to the highest integer number (~24 days)
455 $interval = 2147483647;
458 if ($interval < 10000) {
462 // compose the page title from the sitename and the
463 // current module called
464 if (!$this->module == '') {
465 $this->page['title'] = $this->config['sitename'] . ' (' . $this->module . ')';
467 $this->page['title'] = $this->config['sitename'];
470 /* put the head template at the beginning of page['htmlhead']
471 * since the code added by the modules frequently depends on it
474 if (!isset($this->page['htmlhead'])) {
475 $this->page['htmlhead'] = '';
478 // If we're using Smarty, then doing replace_macros() will replace
479 // any unrecognized variables with a blank string. Since we delay
480 // replacing $stylesheet until later, we need to replace it now
481 // with another variable name
482 if ($this->theme['template_engine'] === 'smarty3') {
483 $stylesheet = $this->get_template_ldelim('smarty3') . '$stylesheet' . $this->get_template_rdelim('smarty3');
485 $stylesheet = '$stylesheet';
488 $shortcut_icon = Config::get('system', 'shortcut_icon');
489 if ($shortcut_icon == '') {
490 $shortcut_icon = 'images/friendica-32.png';
493 $touch_icon = Config::get('system', 'touch_icon');
494 if ($touch_icon == '') {
495 $touch_icon = 'images/friendica-128.png';
498 // get data wich is needed for infinite scroll on the network page
499 $invinite_scroll = infinite_scroll_data($this->module);
501 $tpl = get_markup_template('head.tpl');
502 $this->page['htmlhead'] = replace_macros($tpl, array(
503 '$baseurl' => $this->get_baseurl(), // FIXME for z_path!!!!
504 '$local_user' => local_user(),
505 '$generator' => 'Friendica' . ' ' . FRIENDICA_VERSION,
506 '$delitem' => t('Delete this item?'),
507 '$showmore' => t('show more'),
508 '$showfewer' => t('show fewer'),
509 '$update_interval' => $interval,
510 '$shortcut_icon' => $shortcut_icon,
511 '$touch_icon' => $touch_icon,
512 '$stylesheet' => $stylesheet,
513 '$infinite_scroll' => $invinite_scroll,
514 )) . $this->page['htmlhead'];
517 function init_page_end() {
518 if (!isset($this->page['end'])) {
519 $this->page['end'] = '';
521 $tpl = get_markup_template('end.tpl');
522 $this->page['end'] = replace_macros($tpl, array(
523 '$baseurl' => $this->get_baseurl() // FIXME for z_path!!!!
524 )) . $this->page['end'];
527 function set_curl_code($code) {
528 $this->curl_code = $code;
531 function get_curl_code() {
532 return $this->curl_code;
535 function set_curl_content_type($content_type) {
536 $this->curl_content_type = $content_type;
539 function get_curl_content_type() {
540 return $this->curl_content_type;
543 function set_curl_headers($headers) {
544 $this->curl_headers = $headers;
547 function get_curl_headers() {
548 return $this->curl_headers;
551 function get_cached_avatar_image($avatar_image) {
552 return $avatar_image;
556 * @brief Removes the baseurl from an url. This avoids some mixed content problems.
558 * @param string $orig_url
560 * @return string The cleaned url
562 function remove_baseurl($orig_url) {
564 // Is the function called statically?
565 if (!(isset($this) && get_class($this) == __CLASS__)) {
566 return self::$a->remove_baseurl($orig_url);
569 // Remove the hostname from the url if it is an internal link
570 $nurl = normalise_link($orig_url);
571 $base = normalise_link($this->get_baseurl());
572 $url = str_replace($base . '/', '', $nurl);
574 // if it is an external link return the orignal value
575 if ($url == normalise_link($orig_url)) {
583 * @brief Register template engine class
585 * If $name is '', is used class static property $class::$name
587 * @param string $class
588 * @param string $name
590 function register_template_engine($class, $name = '') {
591 /// @TODO Really === and not just == ?
593 $v = get_class_vars($class);
598 echo "template engine <tt>$class</tt> cannot be registered without a name.\n";
601 $this->template_engines[$name] = $class;
605 * @brief Return template engine instance.
607 * If $name is not defined, return engine defined by theme,
610 * @param strin $name Template engine name
611 * @return object Template Engine instance
613 function template_engine($name = '') {
614 /// @TODO really type-check included?
616 $template_engine = $name;
618 $template_engine = 'smarty3';
619 if (x($this->theme, 'template_engine')) {
620 $template_engine = $this->theme['template_engine'];
624 if (isset($this->template_engines[$template_engine])) {
625 if (isset($this->template_engine_instance[$template_engine])) {
626 return $this->template_engine_instance[$template_engine];
628 $class = $this->template_engines[$template_engine];
630 $this->template_engine_instance[$template_engine] = $obj;
635 echo "template engine <tt>$template_engine</tt> is not registered!\n";
640 * @brief Returns the active template engine.
644 function get_template_engine() {
645 return $this->theme['template_engine'];
648 function set_template_engine($engine = 'smarty3') {
649 $this->theme['template_engine'] = $engine;
652 function get_template_ldelim($engine = 'smarty3') {
653 return $this->ldelim[$engine];
656 function get_template_rdelim($engine = 'smarty3') {
657 return $this->rdelim[$engine];
660 function save_timestamp($stamp, $value) {
661 if (!isset($this->config['system']['profiler']) || !$this->config['system']['profiler']) {
665 $duration = (float) (microtime(true) - $stamp);
667 if (!isset($this->performance[$value])) {
668 // Prevent ugly E_NOTICE
669 $this->performance[$value] = 0;
672 $this->performance[$value] += (float) $duration;
673 $this->performance['marktime'] += (float) $duration;
675 $callstack = $this->callstack();
677 if (!isset($this->callstack[$value][$callstack])) {
678 // Prevent ugly E_NOTICE
679 $this->callstack[$value][$callstack] = 0;
682 $this->callstack[$value][$callstack] += (float) $duration;
686 * @brief Log active processes into the "process" table
688 function start_process() {
689 $trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 1);
691 $command = basename($trace[0]['file']);
693 $this->remove_inactive_processes();
695 q('START TRANSACTION');
697 $r = q('SELECT `pid` FROM `process` WHERE `pid` = %d', intval(getmypid()));
698 if (!dbm::is_result($r)) {
699 q("INSERT INTO `process` (`pid`,`command`,`created`) VALUES (%d, '%s', '%s')", intval(getmypid()), dbesc($command), dbesc(datetime_convert()));
705 * @brief Remove inactive processes
707 function remove_inactive_processes() {
708 q('START TRANSACTION');
710 $r = q('SELECT `pid` FROM `process`');
711 if (dbm::is_result($r)) {
712 foreach ($r AS $process) {
713 if (!posix_kill($process['pid'], 0)) {
714 q('DELETE FROM `process` WHERE `pid` = %d', intval($process['pid']));
722 * @brief Remove the active process from the "process" table
724 function end_process() {
725 q('DELETE FROM `process` WHERE `pid` = %d', intval(getmypid()));
729 * @brief Returns a string with a callstack. Can be used for logging.
733 function callstack($depth = 4) {
734 $trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, $depth + 2);
736 // We remove the first two items from the list since they contain data that we don't need.
740 $callstack = array();
741 foreach ($trace AS $func) {
742 $callstack[] = $func['function'];
745 return implode(', ', $callstack);
748 function get_useragent() {
750 FRIENDICA_PLATFORM . " '" .
751 FRIENDICA_CODENAME . "' " .
752 FRIENDICA_VERSION . '-' .
753 DB_UPDATE_VERSION . '; ' .
754 $this->get_baseurl();
757 function is_friendica_app() {
758 return $this->is_friendica_app;
762 * @brief Checks if the site is called via a backend process
764 * This isn't a perfect solution. But we need this check very early.
765 * So we cannot wait until the modules are loaded.
767 * @return bool Is it a known backend?
769 function is_backend() {
770 static $backends = array();
771 $backends[] = '_well_known';
773 $backends[] = 'dfrn_notify';
774 $backends[] = 'fetch';
775 $backends[] = 'hcard';
776 $backends[] = 'hostxrd';
777 $backends[] = 'nodeinfo';
778 $backends[] = 'noscrape';
780 $backends[] = 'poco';
781 $backends[] = 'post';
782 $backends[] = 'proxy';
783 $backends[] = 'pubsub';
784 $backends[] = 'pubsubhubbub';
785 $backends[] = 'receive';
786 $backends[] = 'rsd_xml';
787 $backends[] = 'salmon';
788 $backends[] = 'statistics_json';
791 // Check if current module is in backend or backend flag is set
792 return (in_array($this->module, $backends) || $this->backend);
796 * @brief Checks if the maximum number of database processes is reached
798 * @return bool Is the limit reached?
800 function max_processes_reached() {
801 // Deactivated, needs more investigating if this check really makes sense
804 if ($this->is_backend()) {
805 $process = 'backend';
806 $max_processes = Config::get('system', 'max_processes_backend');
807 if (intval($max_processes) == 0) {
811 $process = 'frontend';
812 $max_processes = Config::get('system', 'max_processes_frontend');
813 if (intval($max_processes) == 0) {
818 $processlist = dbm::processlist();
819 if ($processlist['list'] != '') {
820 logger('Processcheck: Processes: ' . $processlist['amount'] . ' - Processlist: ' . $processlist['list'], LOGGER_DEBUG);
822 if ($processlist['amount'] > $max_processes) {
823 logger('Processcheck: Maximum number of processes for ' . $process . ' tasks (' . $max_processes . ') reached.', LOGGER_DEBUG);
831 * @brief Checks if the minimal memory is reached
833 * @return bool Is the memory limit reached?
835 public function min_memory_reached() {
836 $min_memory = Config::get('system', 'min_memory', 0);
837 if ($min_memory == 0) {
841 if (!is_readable('/proc/meminfo')) {
845 $memdata = explode("\n", file_get_contents('/proc/meminfo'));
848 foreach ($memdata as $line) {
849 list($key, $val) = explode(':', $line);
850 $meminfo[$key] = (int) trim(str_replace('kB', '', $val));
851 $meminfo[$key] = (int) ($meminfo[$key] / 1024);
854 if (!isset($meminfo['MemAvailable']) || ! isset($meminfo['MemFree'])) {
858 $free = $meminfo['MemAvailable'] + $meminfo['MemFree'];
860 $reached = ($free < $min_memory);
863 logger('Minimal memory reached: ' . $free . '/' . $meminfo['MemTotal'] . ' - limit ' . $min_memory, LOGGER_DEBUG);
870 * @brief Checks if the maximum load is reached
872 * @return bool Is the load reached?
874 function maxload_reached() {
876 if ($this->is_backend()) {
877 $process = 'backend';
878 $maxsysload = intval(Config::get('system', 'maxloadavg'));
879 if ($maxsysload < 1) {
883 $process = 'frontend';
884 $maxsysload = intval(Config::get('system', 'maxloadavg_frontend'));
885 if ($maxsysload < 1) {
890 $load = current_load();
892 if (intval($load) > $maxsysload) {
893 logger('system: load ' . $load . ' for ' . $process . ' tasks (' . $maxsysload . ') too high.');
900 function proc_run($args) {
902 if (!function_exists('proc_open')) {
906 // If the last worker fork was less than 2 seconds before then don't fork another one.
907 // This should prevent the forking of masses of workers.
908 $cachekey = 'app:proc_run:started';
909 $result = Cache::get($cachekey);
911 if (!is_null($result) && ( time() - $result) < 2) {
915 // Set the timestamp of the last proc_run
916 Cache::set($cachekey, time(), CACHE_MINUTE);
918 array_unshift($args, ((x($this->config, 'php_path')) && (strlen($this->config['php_path'])) ? $this->config['php_path'] : 'php'));
920 // add baseurl to args. cli scripts can't construct it
921 $args[] = $this->get_baseurl();
923 for ($x = 0; $x < count($args); $x ++) {
924 $args[$x] = escapeshellarg($args[$x]);
927 $cmdline = implode($args, ' ');
929 if ($this->min_memory_reached()) {
933 if (Config::get('system', 'proc_windows')) {
934 $resource = proc_open('cmd /c start /b ' . $cmdline, array(), $foo, $this->get_basepath());
936 $resource = proc_open($cmdline . ' &', array(), $foo, $this->get_basepath());
938 if (!is_resource($resource)) {
939 logger('We got no resource for command ' . $cmdline, LOGGER_DEBUG);
942 proc_close($resource);
946 * @brief Returns the system user that is executing the script
948 * This mostly returns something like "www-data".
950 * @return string system username
952 static function systemuser() {
953 if (!function_exists('posix_getpwuid') || ! function_exists('posix_geteuid')) {
957 $processUser = posix_getpwuid(posix_geteuid());
958 return $processUser['name'];
962 * @brief Checks if a given directory is usable for the system
964 * @return boolean the directory is usable
966 static function directory_usable($directory, $check_writable = true) {
967 if ($directory == '') {
968 logger('Directory is empty. This shouldn\'t happen.', LOGGER_DEBUG);
972 if (!file_exists($directory)) {
973 logger('Path "' . $directory . '" does not exist for user ' . self::systemuser(), LOGGER_DEBUG);
976 if (is_file($directory)) {
977 logger('Path "' . $directory . '" is a file for user ' . self::systemuser(), LOGGER_DEBUG);
980 if (!is_dir($directory)) {
981 logger('Path "' . $directory . '" is not a directory for user ' . self::systemuser(), LOGGER_DEBUG);
984 if ($check_writable && !is_writable($directory)) {
985 logger('Path "' . $directory . '" is not writable for user ' . self::systemuser(), LOGGER_DEBUG);