diff --git a/boot.php b/boot.php index 8b5cda68ab..f5ce32ac5c 100644 --- a/boot.php +++ b/boot.php @@ -2160,7 +2160,7 @@ function random_digits($digits) { } function get_cachefile($file, $writemode = true) { - $cache = get_config("system","itemcache"); + $cache = get_itemcachepath(); if ((! $cache) || (! is_dir($cache))) return(""); @@ -2181,7 +2181,7 @@ function get_cachefile($file, $writemode = true) { function clear_cache($basepath = "", $path = "") { if ($path == "") { - $basepath = get_config('system','itemcache'); + $basepath = get_itemcachepath(); $path = $basepath; } @@ -2209,6 +2209,63 @@ function clear_cache($basepath = "", $path = "") { } } +function get_itemcachepath() { + // Checking, if the cache is deactivated + $cachetime = (int)get_config('system','itemcache_duration'); + if ($cachetime < 0) + return ""; + + $itemcache = get_config('system','itemcache'); + if (($itemcache != "") AND is_dir($itemcache) AND is_writable($itemcache)) + return($itemcache); + + $temppath = get_temppath(); + + if ($temppath != "") { + $itemcache = $temppath."/itemcache"; + mkdir($itemcache); + + if (is_dir($itemcache) AND is_writable($itemcache)) { + set_config("system", "itemcache", $itemcache); + return($itemcache); + } + } + return ""; +} + +function get_lockpath() { + $lockpath = get_config('system','lockpath'); + if (($lockpath != "") AND is_dir($lockpath) AND is_writable($lockpath)) + return($lockpath); + + $temppath = get_temppath(); + + if ($temppath != "") { + $lockpath = $temppath."/lock"; + mkdir($lockpath); + + if (is_dir($lockpath) AND is_writable($lockpath)) { + set_config("system", "lockpath", $lockpath); + return($lockpath); + } + } + return ""; +} + +function get_temppath() { + $temppath = get_config("system","temppath"); + if (($temppath != "") AND is_dir($temppath) AND is_writable($temppath)) + return($temppath); + + $temppath = sys_get_temp_dir(); + if (($temppath != "") AND is_dir($temppath) AND is_writable($temppath)) { + set_config("system", "temppath", $temppath); + return($temppath); + } + + return(""); +} + function set_template_engine(&$a, $engine = 'internal') { // This function is no longer necessary, but keep it as a wrapper to the class method // to avoid breaking themes again unnecessarily diff --git a/include/Photo.php b/include/Photo.php index 1ba0177cf5..d20dd2ca08 100644 --- a/include/Photo.php +++ b/include/Photo.php @@ -764,7 +764,7 @@ function get_photo_info($url) { if (is_null($data)) { $img_str = fetch_url($url, true, $redirects, 4); - $tempfile = tempnam(get_config("system","temppath"), "cache"); + $tempfile = tempnam(get_temppath(), "cache"); file_put_contents($tempfile, $img_str); $data = getimagesize($tempfile); unlink($tempfile); diff --git a/include/bbcode.php b/include/bbcode.php index 4c2d6e547c..63748ef45a 100644 --- a/include/bbcode.php +++ b/include/bbcode.php @@ -424,7 +424,7 @@ function bb_ShareAttributes($match) { $posted = ""; - $itemcache = get_config("system","itemcache"); + $itemcache = get_itemcachepath(); // relative dates only make sense when they aren't cached if ($itemcache == "") { @@ -661,7 +661,7 @@ function bb_ShareAttributes($share, $simplehtml) { $posted = ""; - $itemcache = get_config("system","itemcache"); + $itemcache = get_itemcachepath(); // relative dates only make sense when they aren't cached if ($itemcache == "") { @@ -949,8 +949,8 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true, $simplehtml = fal // removing multiplicated newlines if (get_config("system", "remove_multiplicated_lines")) { - $search = array("\n\n\n", "\n ", " \n", "[/quote]\n\n", "\n[/quote]", "[/li]\n", "\n[li]", "\n[ul]", "[/ul]\n"); - $replace = array("\n\n", "\n", "\n", "[/quote]\n", "[/quote]", "[/li]", "[li]", "[ul]", "[/ul]"); + $search = array("\n\n\n", "\n ", " \n", "[/quote]\n\n", "\n[/quote]", "[/li]\n", "\n[li]", "\n[ul]", "[/ul]\n", "\n\n[share "); + $replace = array("\n\n", "\n", "\n", "[/quote]\n", "[/quote]", "[/li]", "[li]", "[ul]", "[/ul]", "\n[share "); do { $oldtext = $Text; $Text = str_replace($search, $replace, $Text); diff --git a/include/cronhooks.php b/include/cronhooks.php index 0ba453555c..031011ac36 100644 --- a/include/cronhooks.php +++ b/include/cronhooks.php @@ -35,7 +35,7 @@ function cronhooks_run(&$argv, &$argc){ } } - $lockpath = get_config('system','lockpath'); + $lockpath = get_lockpath(); if ($lockpath != '') { $pidfile = new pidfile($lockpath, 'cronhooks'); if($pidfile->is_already_running()) { diff --git a/include/onepoll.php b/include/onepoll.php index 15b8e7c2cc..309764c74f 100644 --- a/include/onepoll.php +++ b/include/onepoll.php @@ -58,7 +58,7 @@ function onepoll_run(&$argv, &$argc){ } // Test - $lockpath = get_config('system','lockpath'); + $lockpath = get_lockpath(); if ($lockpath != '') { $pidfile = new pidfile($lockpath, 'onepoll'.$contact_id); if($pidfile->is_already_running()) { diff --git a/include/poller.php b/include/poller.php index b04c77f744..46f1079fd1 100644 --- a/include/poller.php +++ b/include/poller.php @@ -41,7 +41,7 @@ function poller_run(&$argv, &$argc){ } } - $lockpath = get_config('system','lockpath'); + $lockpath = get_lockpath(); if ($lockpath != '') { $pidfile = new pidfile($lockpath, 'poller'); if($pidfile->is_already_running()) { diff --git a/include/queue.php b/include/queue.php index bc3cc258cc..3c28cefaf2 100644 --- a/include/queue.php +++ b/include/queue.php @@ -84,7 +84,7 @@ function queue_run(&$argv, &$argc){ load_config('config'); load_config('system'); - $lockpath = get_config('system','lockpath'); + $lockpath = get_lockpath(); if ($lockpath != '') { $pidfile = new pidfile($lockpath, 'queue'); if($pidfile->is_already_running()) { diff --git a/mod/admin.php b/mod/admin.php index 76129204c3..3b22811d14 100644 --- a/mod/admin.php +++ b/mod/admin.php @@ -548,12 +548,17 @@ function admin_page_site(&$a) { /* Banner */ $banner = get_config('system','banner'); - if($banner == false) + if($banner == false) $banner = 'Friendica'; $banner = htmlspecialchars($banner); $info = get_config('config','info'); $info = htmlspecialchars($info); + // Automatically create temporary paths + get_temppath(); + get_lockpath(); + get_itemcachepath(); + //echo "
"; var_dump($lang_choices); die(""); /* Register policy */ @@ -631,7 +636,7 @@ function admin_page_site(&$a) { '$use_fulltext_engine' => array('use_fulltext_engine', t("Use MySQL full text engine"), get_config('system','use_fulltext_engine'), t("Activates the full text engine. Speeds up search - but can only search for four and more characters.")), '$suppress_language' => array('suppress_language', t("Suppress Language"), get_config('system','suppress_language'), t("Suppress language information in meta information about a posting.")), '$itemcache' => array('itemcache', t("Path to item cache"), get_config('system','itemcache'), "The item caches buffers generated bbcode and external images."), - '$itemcache_duration' => array('itemcache_duration', t("Cache duration in seconds"), get_config('system','itemcache_duration'), t("How long should the cache files be hold? Default value is 86400 seconds (One day).")), + '$itemcache_duration' => array('itemcache_duration', t("Cache duration in seconds"), get_config('system','itemcache_duration'), t("How long should the cache files be hold? Default value is 86400 seconds (One day). To disable the item cache, set the value to -1.")), '$max_comments' => array('max_comments', t("Maximum numbers of comments per post"), get_config('system','max_comments'), t("How much comments should be shown for each post? Default value is 100.")), '$lockpath' => array('lockpath', t("Path for lock file"), get_config('system','lockpath'), "The lock file is used to avoid multiple pollers at one time. Only define a folder here."), '$temppath' => array('temppath', t("Temp path"), get_config('system','temppath'), "If you have a restricted system where the webserver can't access the system temp path, enter another path here."),