Fixed "syntax error, unexpected '['" bug under PHP 5.3, reported here: https://forum.flatpress.org/viewtopic.php?f=2&t=131

This commit is contained in:
azett 2020-04-15 14:43:54 +02:00
parent a1f5d625ee
commit 50c11928f6

View File

@ -19,18 +19,18 @@ class draft_indexer extends fs_filelister {
if (is_dir($f) && ctype_digit($file)) {
return 1;
}
if (fnmatch('entry*' . EXT, $file)) {
$id = basename($file, EXT);
$arr = draft_parse($id);
// $this->add($id, $arr['subject']);
$this->_list [$id] = $arr ['subject'];
return 0;
}
}
}
function &draft_init() {
@ -42,27 +42,27 @@ function &draft_init() {
function draft_getlist() {
static $list = array();
if (!$list) {
$obj = & draft_init();
$list = $obj->getList();
krsort($list);
}
return $list;
}
function draft_parse($id) {
if ($fname = draft_exists($id)) {
$entry = io_load_file($fname);
$entry = utils_kexplode($entry);
if (!isset($entry ['categories']))
$entry ['categories'] = array();
else
$entry ['categories'] = explode(',', $entry ['categories']);
return $entry;
}
return array();
@ -72,38 +72,38 @@ function draft_save(&$entry, $id = null, $update_index = false, $update_date = f
if (!$id) {
$id = bdb_idfromtime('entry', $entry ['date']);
}
$ed = entry_dir($id);
$dd = draft_dir($id);
if (file_exists($ed . EXT)) {
// move collateral files
@rename($ed, $dd);
if ($update_index) {
// delete normal entry
fs_delete($ed . EXT);
// remove from normal flow
$o = & entry_init();
$o->delete($id, null);
}
}
$new_entry = entry_prepare($entry);
if ($new_entry ['categories'])
$new_entry ['categories'] = implode(',', $entry ['categories']);
else
unset($new_entry ['categories']);
$string = utils_kimplode($new_entry);
if (!io_write_file($dd . EXT, $string)) {
return false;
} else
return $id;
return false;
}
@ -120,25 +120,25 @@ function draft_exists($id) {
$dir = draft_dir($id);
if (!$dir)
return false;
$f = $dir . EXT;
if (file_exists($f))
return $f;
return false;
}
function draft_delete($id) {
$dir = draft_dir($id);
$f = $dir . EXT;
if (!file_exists($f))
return false;
// $draftdb =& draft_init();
// $draftdb->delete($id);
fs_delete_recursive($dir);
return fs_delete($f);
}
@ -154,14 +154,14 @@ function draft_delete($id) {
function draft_to_entry($draftid) {
$dir = draft_dir($draftid);
$dir2 = entry_dir($draftid);
@rename($dir, $dir2);
draft_delete($draftid);
}
function smarty_block_draftlist($params, $content, &$smarty, &$repeat) {
global $fpdb;
if ($list = draft_getlist()) {
$smarty->assign('draft_list', $list);
return $content;
@ -169,8 +169,6 @@ function smarty_block_draftlist($params, $content, &$smarty, &$repeat) {
}
function smarty_block_draft($params, $content, &$smarty, &$repeat) {
static $list = array();
$smarty->assign(array(
'subject' => '',
'content' => '',
@ -180,21 +178,21 @@ function smarty_block_draft($params, $content, &$smarty, &$repeat) {
'id' => ''
));
$arr = & $smarty->get_template_vars('draft_list');
$id = $subject = null;
if ($arr) {
$firstElement = utils_array_kshift($arr);
$id = array_keys($firstElement) [0];
$subject = $firstElement [$id];
$id = array_keys($firstElement);
$subject = $firstElement [$id [0]];
}
if ($id) {
$smarty->assign('subject', $subject);
$smarty->assign('id', $id);
}
$repeat = (bool) $id;
return $content;
}