The temporary paths (temp, lock, itemcache) are now detected automatically when used.

This commit is contained in:
Michael Vogel 2014-06-23 01:24:39 +02:00
parent 38fb43702f
commit 5ed5773f57
8 changed files with 75 additions and 13 deletions

View file

@ -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

View file

@ -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);

View file

@ -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);

View file

@ -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()) {

View file

@ -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()) {

View file

@ -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()) {

View file

@ -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()) {

View file

@ -554,6 +554,11 @@ function admin_page_site(&$a) {
$info = get_config('config','info');
$info = htmlspecialchars($info);
// Automatically create temporary paths
get_temppath();
get_lockpath();
get_itemcachepath();
//echo "<pre>"; var_dump($lang_choices); die("</pre>");
/* 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."),