Getting FlatPress ready for PHP 8: Added a lot of missing checks for undefined variables and array keys in template and PHP files.

This commit is contained in:
azett 2020-12-19 12:52:53 +01:00
parent 9332d78fd1
commit 5a0b7541e7
10 changed files with 1135 additions and 1205 deletions

View File

@ -18,7 +18,7 @@
{/foreach} {/foreach}
</ul> </ul>
{if $submenu} {if isset($submenu)}
<ul id="admin-submenu"> <ul id="admin-submenu">
{foreach from=$submenu key=subtab item=item} {foreach from=$submenu key=subtab item=item}
{if $item} {if $item}
@ -34,6 +34,9 @@
{/if} {/if}
<div id="admin-content"> <div id="admin-content">
{if isset($action)}
{include file=$admin_resource|default:"admin:$panel/$action"} {include file=$admin_resource|default:"admin:$panel/$action"}
{else}
{include file=$admin_resource|default:"admin:$panel"}
{/if}
</div> </div>

View File

@ -8,6 +8,9 @@
{if !isset($catdefs)}
{assign var=catdefs value=""}
{/if}
{html_form} {html_form}
<p> <p>

View File

@ -26,7 +26,7 @@
<p>{$panelstrings.descr}</p> <p>{$panelstrings.descr}</p>
<form method="get" action="{$smarty.request.PHP_SELF}?p=entry"> <form method="get" action="{$smarty.server.PHP_SELF}?p=entry">
<p> <input type="hidden" name="p" value="entry" /> </p> <p> <input type="hidden" name="p" value="entry" /> </p>
<fieldset><legend>{$panelstrings.filter}</legend> <fieldset><legend>{$panelstrings.filter}</legend>
<select name="category" class="alignleft"> <select name="category" class="alignleft">

View File

@ -5,7 +5,7 @@
{entry_block} {entry_block}
<div id="admin-post-preview"> <div id="admin-post-preview">
{if $preview} {if isset($preview)}
<fieldset id="post-preview"><legend>{$panelstrings.preview}</legend> <fieldset id="post-preview"><legend>{$panelstrings.preview}</legend>
{include file=preview.tpl} {include file=preview.tpl}
</fieldset> </fieldset>
@ -14,7 +14,9 @@
{html_form} {html_form}
{if !isset($post)}
{assign var=post value=""}
{/if}
{entry content=$post alwaysshow=true} {entry content=$post alwaysshow=true}
<div id="admin-editor"> <div id="admin-editor">

View File

@ -1,6 +1,6 @@
<h2>{$panelstrings.head}</h2> <h2>{$panelstrings.head}</h2>
{include file=shared:errorlist.tpl} {include file=shared:errorlist.tpl}
{if $files} {if isset($files)}
<p>{$panelstrings.chmod_info}</p> <p>{$panelstrings.chmod_info}</p>
<p><a href="admin.php?p=maintain">{$panelstrings.opt0}</a></p> <p><a href="admin.php?p=maintain">{$panelstrings.opt0}</a></p>
<ul> <ul>
@ -9,7 +9,7 @@
{/foreach} {/foreach}
</ul> </ul>
<p><a href="admin.php?p=maintain">{$panelstrings.opt0}</a></p> <p><a href="admin.php?p=maintain">{$panelstrings.opt0}</a></p>
{elseif $phpinfo} {elseif isset($phpinfo)}
<p><a href="admin.php?p=maintain">{$panelstrings.opt0}</a></p> <p><a href="admin.php?p=maintain">{$panelstrings.opt0}</a></p>
{$phpinfo} {$phpinfo}
<p><a href="admin.php?p=maintain">{$panelstrings.opt0}</a></p> <p><a href="admin.php?p=maintain">{$panelstrings.opt0}</a></p>

View File

@ -3,43 +3,48 @@
class FPDB_QueryParams { class FPDB_QueryParams {
var $id = null; var $id = null;
var $d = null; var $d = null;
var $m = null; var $m = null;
var $y = null; var $y = null;
var $start = 0; var $start = 0;
var $count = -1; var $count = -1;
var $random = 0; var $random = 0;
var $category = 0; var $category = 0;
var $exclude = null; var $exclude = null;
var $page = 1; var $page = 1;
var $fullparse = false; var $fullparse = false;
var $comments = false; var $comments = false;
function __construct($params) { function __construct($params) {
if (is_string($params)) { if (is_string($params)) {
$this->parse_string($params); $this->parse_string($params);
} elseif (is_array($params)) { } elseif (is_array($params)) {
$this->validate_array($params); $this->validate_array($params);
} else { } else {
trigger_error("FPDB_QueryParams: parameters were not in a valid form", trigger_error("FPDB_QueryParams: parameters were not in a valid form", E_USER_ERROR);
E_USER_ERROR);
} }
} }
function pad_date($date) { function pad_date($date) {
if (is_numeric($date) && strlen($date) <= 2) { if (is_numeric($date) && strlen($date) <= 2) {
return str_pad($date, 2, '0', STR_PAD_LEFT); return str_pad($date, 2, '0', STR_PAD_LEFT);
} }
return null; return null;
} }
function validate_array($params) { function validate_array($params) {
global $fp_config; global $fp_config;
if (isset($params ['id'])) { if (isset($params ['id'])) {
@ -51,23 +56,16 @@
$this->count = 0; $this->count = 0;
return; return;
} }
} }
if (isset($params ['fullparse'])) { if (isset($params ['fullparse'])) {
$this->fullparse = $this->fullparse = is_string($params ['fullparse']) ? ($params ['fullparse'] != 'false') : $params ['fullparse'];
is_string($params['fullparse'])?
($params['fullparse'] != 'false')
:
$params['fullparse'];
if ($this->fullparse) if ($this->fullparse)
$this->comments = true; $this->comments = true;
} }
if (isset($params ['y'])) { if (isset($params ['y'])) {
$this->y = $this->pad_date($params ['y']); $this->y = $this->pad_date($params ['y']);
@ -77,9 +75,7 @@
if ($this->m && isset($params ['d'])) { if ($this->m && isset($params ['d'])) {
$this->d = $this->pad_date($params ['d']); $this->d = $this->pad_date($params ['d']);
} }
} }
} }
if (isset($params ['random']) && !$this->id) { if (isset($params ['random']) && !$this->id) {
@ -103,15 +99,12 @@
$this->count = intval($fp_config ['general'] ['maxentries']); $this->count = intval($fp_config ['general'] ['maxentries']);
} }
$this->start = ($this->page - 1) * $this->count; $this->start = ($this->page - 1) * $this->count;
if (isset($params ['start'])) { if (isset($params ['start'])) {
$this->start = intval($params ['start']); $this->start = intval($params ['start']);
} }
if (isset($params ['category'])) { if (isset($params ['category'])) {
$this->category = intval($params ['category']); $this->category = intval($params ['category']);
} }
@ -123,7 +116,6 @@
if (isset($params ['exclude'])) { if (isset($params ['exclude'])) {
$this->exclude = intval($params ['exclude']); $this->exclude = intval($params ['exclude']);
} }
} }
function parse_string($str) { function parse_string($str) {
@ -136,27 +128,41 @@
class FPDB_Query { class FPDB_Query {
var $counter = -1; var $counter = -1;
var $params = null; var $params = null;
var $single = false; var $single = false;
var $pointer = 0; /* pointer points always to NEXT element */
var $pointer = 0;
/* pointer points always to NEXT element */
var $processed = false; var $processed = false;
var $ID = 0; /* query id */
var $ID = 0;
/* query id */
var $lastentry = array(
null,
array()
);
var $lastentry = array(null, array());
var $localcache = array(); var $localcache = array();
var $nextid = ''; var $nextid = '';
var $previd = ''; var $previd = '';
var $currentid = ''; var $currentid = '';
var $main_idx = null; var $main_idx = null;
var $secondary_idx = null; var $secondary_idx = null;
var $walker = null; var $walker = null;
function __construct($params, $ID) { function __construct($params, $ID) {
global $current_query; global $current_query;
$this->params = new FPDB_QueryParams($params); $this->params = new FPDB_QueryParams($params);
$this->ID = $ID; $this->ID = $ID;
@ -165,14 +171,11 @@
} }
$GLOBALS ['current_query'] = & $this; $GLOBALS ['current_query'] = & $this;
} }
function prepare() { function prepare() {
global $fpdb; global $fpdb;
$fpdb->init(); $fpdb->init();
$this->main_idx = & $fpdb->get_index($this->params->category); $this->main_idx = & $fpdb->get_index($this->params->category);
@ -204,9 +207,6 @@
// force first entry to be loaded: updates count, pointer // force first entry to be loaded: updates count, pointer
$this->peekEntry(); $this->peekEntry();
} }
function _prepare_single(&$entry_index) { function _prepare_single(&$entry_index) {
@ -227,11 +227,11 @@
$prevkey = entry_timetokey($time + 1); $prevkey = entry_timetokey($time + 1);
$key = entry_idtokey($qp->id); $key = entry_idtokey($qp->id);
#print_r($key); // print_r($key);
#$key = entry_idtokey($qp->id); // $key = entry_idtokey($qp->id);
if (!($entry_index->has_key($key))) { if (!($entry_index->has_key($key))) {
#trigger_error("FPDB: no entry found for {$qp->id}", E_USER_WARNING); // trigger_error("FPDB: no entry found for {$qp->id}", E_USER_WARNING);
$qp->count = 0; $qp->count = 0;
return; return;
} }
@ -240,7 +240,6 @@
// i.e. includes the first key $newkey such as $newkey <= $prevkey // i.e. includes the first key $newkey such as $newkey <= $prevkey
// also, if $prevkey != $newkey then $prevkey := $newkey // also, if $prevkey != $newkey then $prevkey := $newkey
$this->walker = & $entry_index->walker($prevkey, 2, null, null); $this->walker = & $entry_index->walker($prevkey, 2, null, null);
// since we're searching for $prevkey, i.e. a key preceding the target $id // since we're searching for $prevkey, i.e. a key preceding the target $id
@ -267,28 +266,21 @@
} }
} }
} }
} }
function _prepare_list(&$entry_index) { function _prepare_list(&$entry_index) {
$qp = & $this->params; $qp = & $this->params;
$entry_num = 0; $entry_num = 0;
if (!$qp->y) { if (!$qp->y) {
// searches the whole index // searches the whole index
#$this->local_list = array_keys($entry_index); // $this->local_list = array_keys($entry_index);
$firstid = null; $firstid = null;
$index_count = $entry_index->length(); $index_count = $entry_index->length();
$this->walker = & $entry_index->walker($firstid); $this->walker = & $entry_index->walker($firstid);
} else { } else {
// notice this won't work with cats (for now) // notice this won't work with cats (for now)
@ -300,9 +292,7 @@
if ($filteredkeys) { if ($filteredkeys) {
$error302var1 = entry_idtokey($filteredkeys [0]); $error302var1 = entry_idtokey($filteredkeys [0]);
$this->walker = $entry_index->walker( $this->walker = $entry_index->walker($error302var1, true, entry_idtokey($filteredkeys [$index_count - 1]), true);
$error302var1, true,
entry_idtokey($filteredkeys[$index_count-1]), true);
} }
} }
@ -310,7 +300,6 @@
// count<0 means 'all' // count<0 means 'all'
$qp->count = $index_count; $qp->count = $index_count;
} elseif (($qp->start + $qp->count) > $index_count) { } elseif (($qp->start + $qp->count) > $index_count) {
if ($index_count >= $qp->start) if ($index_count >= $qp->start)
@ -318,7 +307,6 @@
else else
$index_count = $qp->start = $qp->count = 0; $index_count = $qp->start = $qp->count = 0;
} }
} }
// not so great implementation... doesn't work well // not so great implementation... doesn't work well
@ -343,9 +331,7 @@
} }
/* reading functions */ /* reading functions */
function hasMore() { function hasMore() {
$GLOBALS ['current_query'] = & $this; $GLOBALS ['current_query'] = & $this;
// if system init has not been done (filling pointer variable etc.) // if system init has not been done (filling pointer variable etc.)
@ -356,21 +342,23 @@
// hasMore() returns false either if pointer exceeded the count // hasMore() returns false either if pointer exceeded the count
// or peekEntry returns false // or peekEntry returns false
return ((bool) $this->peekEntry() return ((bool) $this->peekEntry() && $this->pointer < $this->params->start + $this->params->count);
&& $this->pointer < $this->params->start + $this->params->count );
} }
function &peekEntry() { function &peekEntry() {
global $post; global $post;
$qp = & $this->params; $qp = & $this->params;
$return = array(false, false); $return = array(
false,
false
);
if ($this->counter < 0) if ($this->counter < 0)
$this->prepare(); $this->prepare();
if ($this->pointer == $this->params->start + $this->params->count) return $return; if ($this->pointer == $this->params->start + $this->params->count)
return $return;
if ($qp->id) { if ($qp->id) {
$idx = $this->main_idx; $idx = $this->main_idx;
@ -386,34 +374,41 @@
$post = $entry; $post = $entry;
if (!$entry) return $return; if (!$entry)
return $return;
} else { } else {
$entry = array('subject' => $v); $entry = array(
'subject' => $v
);
$post = $entry; $post = $entry;
} }
$return = array($this->params->id, $entry); $return = array(
$this->params->id,
$entry
);
return $return; return $return;
} }
if (!$this->walker) { if (!$this->walker) {
$false = array(false, false); $false = array(
false,
false
);
return $false; return $false;
} }
// search first eligible post // search first eligible post
while ($this->walker->valid && $this->pointer < $qp->start) { while ($this->walker->valid && $this->pointer < $qp->start) {
$this->previd = $this->currentid; $this->previd = $this->currentid;
$key = $this->walker->current_key(); $key = $this->walker->current_key();
$id = $this->currentid = entry_keytoid($key); $id = $this->currentid = entry_keytoid($key);
if ($this->single) if ($this->single)
$this->preventry = array('subject' => $this->walker->current_value()); $this->preventry = array(
'subject' => $this->walker->current_value()
);
$this->walker->next(); $this->walker->next();
$this->pointer++; $this->pointer++;
@ -423,27 +418,23 @@
if ($this->secondary_idx) { if ($this->secondary_idx) {
// skips posts until we find one which is not in the secondary idx // skips posts until we find one which is not in the secondary idx
while ( $this->walker->valid while ($this->walker->valid && ($key = $this->walker->current_key()) && $this->secondary_idx->has_key($key)) {
&& ($key = $this->walker->current_key())
&& $this->secondary_idx->has_key($key)) {
$this->walker->next(); $this->walker->next();
// $qp->count--; // $qp->count--;
} }
} }
if (!$this->walker->valid) { if (!$this->walker->valid) {
$cont = false; return $cont; $cont = false;
return $cont;
} }
// pointer == start // pointer == start
$prevcurr = $this->currentid; $prevcurr = $this->currentid;
$id = $this->currentid = entry_keytoid($this->walker->current_key()); $id = $this->currentid = entry_keytoid($this->walker->current_key());
if ($id != $prevcurr) $this->previd = $prevcurr; if ($id != $prevcurr)
$this->previd = $prevcurr;
if ($qp->fullparse && $this->counter <= 0) { if ($qp->fullparse && $this->counter <= 0) {
@ -451,8 +442,6 @@
$cont = array(); $cont = array();
$cont = isset($this->localcache [$id]) ? $this->localcache [$id] : entry_parse($id); $cont = isset($this->localcache [$id]) ? $this->localcache [$id] : entry_parse($id);
} else { } else {
// only title // only title
@ -460,7 +449,6 @@
'subject' => $this->walker->current_value(), 'subject' => $this->walker->current_value(),
'date' => entry_idtotime($id) 'date' => entry_idtotime($id)
); );
} }
if (!$cont) { if (!$cont) {
@ -476,13 +464,14 @@
$post = $cont; $post = $cont;
$post ['id'] = $id; $post ['id'] = $id;
$var = array(&$id, &$cont); $var = array(
&$id,
&$cont
);
return $var; return $var;
} }
function &getEntry() { function &getEntry() {
if (!$this->hasMore()) if (!$this->hasMore())
return false; return false;
@ -503,8 +492,6 @@
return $this->comments->getCount(); return $this->comments->getCount();
} }
function _getOffsetId($offset, $assume_pointer = null) { function _getOffsetId($offset, $assume_pointer = null) {
if (is_int($assume_pointer)) if (is_int($assume_pointer))
$i = $assume_pointer + $offset; $i = $assume_pointer + $offset;
@ -517,12 +504,10 @@
return $this->currentid = $this->_getOffsetId(0); return $this->currentid = $this->_getOffsetId(0);
} }
function _fillNextId() { function _fillNextId() {
return $this->nextid = $this->_getOffsetId(1); return $this->nextid = $this->_getOffsetId(1);
} }
function _fillPrevId() { function _fillPrevId() {
return $this->previd = $this->_getOffsetId(-1); return $this->previd = $this->_getOffsetId(-1);
} }
@ -540,69 +525,75 @@
} }
function getNextPage() { function getNextPage() {
if ($this->single) { if ($this->single) {
$key = $this->nextkey; $key = $this->nextkey;
if (!$key) if (!$key)
return array(null, null); return array(
null,
null
);
else { else {
$val = $this->main_idx->getitem($key); $val = $this->main_idx->getitem($key);
return array($val, entry_keytoid($key)); return array(
$val,
entry_keytoid($key)
);
} }
} }
if ($this->params->page) { if ($this->params->page) {
#if ($this->_getOffsetId(0, ($this->params->start + $this->params->count))) // if ($this->_getOffsetId(0, ($this->params->start + $this->params->count)))
if ($this->walker->valid) if ($this->walker->valid)
return array($GLOBALS['lang']['main']['nextpage'], $this->params->page + 1); return array(
$GLOBALS ['lang'] ['main'] ['nextpage'],
$this->params->page + 1
);
} }
} }
function getPrevPage() { function getPrevPage() {
if ($this->single) { if ($this->single) {
$key = $this->prevkey; $key = $this->prevkey;
if (!$key) if (!$key)
return array(null, null); return array(
null,
null
);
else { else {
$val = $this->main_idx->getitem($key); $val = $this->main_idx->getitem($key);
return array($val, entry_keytoid($key)); return array(
$val,
entry_keytoid($key)
);
} }
} }
if ($this->params->page > 1) { if ($this->params->page > 1) {
return array($GLOBALS['lang']['main']['prevpage'], $this->params->page - 1); return array(
$GLOBALS ['lang'] ['main'] ['prevpage'],
$this->params->page - 1
);
}
} }
} }
}
class FPDB_CommentList { class FPDB_CommentList {
var $count = 0; var $count = 0;
var $list = array(); var $list = array();
var $current = ''; var $current = '';
var $entryid = ''; var $entryid = '';
function __construct($ID, $array) { function __construct($ID, $array) {
if (is_array($array)) { if (is_array($array)) {
$this->list = $array; $this->list = $array;
$this->count = count($array); $this->count = count($array);
$this->entryid = $ID; $this->entryid = $ID;
} }
} }
function getCount() { function getCount() {
@ -610,26 +601,25 @@
} }
function hasMore() { function hasMore() {
if ($this->count) { if ($this->count) {
return current($this->list) !== false; return current($this->list) !== false;
} }
return false; return false;
} }
function &getComment() { function &getComment() {
if (!$this->hasMore()) if (!$this->hasMore())
return false; return false;
$id = array_shift($this->list); $id = array_shift($this->list);
$comment = comment_parse($this->entryid, $id); $comment = comment_parse($this->entryid, $id);
$couplet = array(&$id, &$comment); $couplet = array(
&$id,
&$comment
);
return $couplet; return $couplet;
} }
} }
@ -637,23 +627,23 @@
class FPDB { class FPDB {
var $_indexer = array(); var $_indexer = array();
var $_categories = array();
var $queries = array();
var $_categories = array();
var $queries = array();
function __construct() { function __construct() {
// constructor // constructor
} }
function init() { function init() {
#if (!$this->_indexer) { // if (!$this->_indexer) {
#$this->_indexer = new entry_indexer(); // $this->_indexer = new entry_indexer();
$this->_categories = entry_categories_get(); $this->_categories = entry_categories_get();
#$obj =& $this->_indexer; // $obj =& $this->_indexer;
#$this->entry_index = $obj->getList(); // $this->entry_index = $obj->getList();
// }
#}
} }
function &get_index($cat_id = 0) { function &get_index($cat_id = 0) {
@ -664,18 +654,20 @@
} }
function reset($queryId = null) { function reset($queryId = null) {
switch ($queryId) { switch ($queryId) {
case null: $this->_query = array(); break; case null:
default: unset($this->_query[$queryId]); $this->_query = array();
break;
default:
unset($this->_query [$queryId]);
} }
} }
/** /**
* function query * function query
* @param mixed params *
* @param
* mixed params
* $params may be an associative array or a query string with the following syntax: * $params may be an associative array or a query string with the following syntax:
* 'key:val,key:val,key:val'; * 'key:val,key:val,key:val';
* example: <code>$params = 'start:0,count:5';<br /> * example: <code>$params = 'start:0,count:5';<br />
@ -715,24 +707,18 @@
* set fullparse=true; defaults to false. * set fullparse=true; defaults to false.
* *
*/ */
function query($params = array()) { function query($params = array()) {
static $queryId = -1; static $queryId = -1;
$queryId++; $queryId++;
$this->queries [$queryId] = new FPDB_Query($params, $queryId); $this->queries [$queryId] = new FPDB_Query($params, $queryId);
$this->init(); $this->init();
return $queryId; return $queryId;
} }
function doquery($queryId = 0) { function doquery($queryId = 0) {
if (isset($this->queries [$queryId])) { if (isset($this->queries [$queryId])) {
$q = & $this->queries [$queryId]; $q = & $this->queries [$queryId];
} else { } else {
@ -746,47 +732,41 @@
// $this->init(); // $this->init();
/** /**
@todo return true/false *
* @todo return true/false
*/ */
return $q->prepare($this->entry_index); return $q->prepare($this->entry_index);
} }
// "get" functions. todo: move out? // "get" functions. todo: move out?
function &getQuery($queryId = 0) { function &getQuery($queryId = 0) {
$o = null; $o = null;
if (isset($this->queries [$queryId])) if (isset($this->queries [$queryId]))
$o = & $this->queries [$queryId]; $o = & $this->queries [$queryId];
return $o; return $o;
} }
}
}
class FPDB_transaction { class FPDB_transaction {
var $_index = null; var $_index = null;
var $_offset = 0; var $_offset = 0;
var $_nodesize = 30; var $_nodesize = 30;
var $_keysize = 12; var $_keysize = 12;
function __construct($id_cat = 0) { function __construct($id_cat = 0) {
$this->_index = INDEX_DIR . 'index-' . $id_cat; $this->_index = INDEX_DIR . 'index-' . $id_cat;
$this->_tree = caching_SBPT( $this->_tree = caching_SBPT(fopen($this->_cachefile . '.dat', 'r'), fopen($this->_cachefile . '.strings.dat', 'r'), $this->_offset, $this->_chunksize, $this->_keysize);
fopen($this->_cachefile.'.dat', 'r'),
fopen($this->_cachefile.'.strings.dat', 'r'),
$this->_offset,
$this->_chunksize,
$this->_keysize
);
} }
} }
// SMARTY FUNCTIONS ---------------------------------------------------- // SMARTY FUNCTIONS ----------------------------------------------------
function smarty_block_entries($params, $content, &$smarty, &$repeat) { function smarty_block_entries($params, $content, &$smarty, &$repeat) {
global $fpdb; global $fpdb;
@ -805,32 +785,26 @@
} }
// $show = @$fpdb->doquery(); // $show = @$fpdb->doquery();
} else { } else {
if (!isset($fpdb->queries [0]->comments) || !$fpdb->queries [0]->comments) if (!isset($fpdb->queries [0]->comments) || !$fpdb->queries [0]->comments)
$fpdb->reset(0); $fpdb->reset(0);
$show = true; $show = true;
} }
$show = true; $show = true;
if ($show) if ($show)
return $content; return $content;
} }
function smarty_block_entry($params, $content, &$smarty, &$repeat) { function smarty_block_entry($params, $content, &$smarty, &$repeat) {
global $fpdb; global $fpdb;
// clean old variables // clean old variables
$smarty->assign(array( 'subject'=>'', $smarty->assign(array(
'subject' => '',
'content' => '', 'content' => '',
'categories' => array(), 'categories' => array(),
'filed_under' => '', 'filed_under' => '',
@ -838,10 +812,7 @@
'author' => '', 'author' => '',
'version' => '', 'version' => '',
'ip-address' => '' 'ip-address' => ''
) ));
);
if (isset($params ['content']) && is_array($params ['content']) && $params ['content']) { if (isset($params ['content']) && is_array($params ['content']) && $params ['content']) {
// foreach ($params['entry'] as $k => $val) // foreach ($params['entry'] as $k => $val)
@ -857,7 +828,6 @@
if ($repeat = $q->hasMore()) { if ($repeat = $q->hasMore()) {
$couplet = & $q->getEntry(); $couplet = & $q->getEntry();
$id = & $couplet [0]; $id = & $couplet [0];
@ -867,24 +837,21 @@
$entry = theme_entry_filters($entry, $id); $entry = theme_entry_filters($entry, $id);
} }
foreach ($entry as $k => $v) foreach ($entry as $k => $v)
$smarty->assign_by_ref($k, $entry [$k]); $smarty->assign_by_ref($k, $entry [$k]);
$smarty->assign_by_ref('id', $id); $smarty->assign_by_ref('id', $id);
$smarty->assign('entry_commslock', @in_array('commslock',$entry['categories'])); if (array_key_exists('categories', $entry)) {
$smarty->assign('entry_commslock', in_array('commslock', $entry ['categories']));
}
do_action('entry_block', $id); do_action('entry_block', $id);
} }
return $content; return $content;
} }
function smarty_block_comment($params, $content, &$smarty, &$repeat) { function smarty_block_comment($params, $content, &$smarty, &$repeat) {
global $fpdb; global $fpdb;
@ -899,9 +866,8 @@
'email' => '', 'email' => '',
'version' => '', 'version' => '',
'ip-address' => '', 'ip-address' => '',
'loggedin'=>'', 'loggedin' => ''
) ));
);
$q = & $fpdb->getQuery(); $q = & $fpdb->getQuery();
@ -912,7 +878,6 @@
$id = & $couplet [0]; $id = & $couplet [0];
$comment = & $couplet [1]; $comment = & $couplet [1];
foreach ($comment as $k => $v) { foreach ($comment as $k => $v) {
$kk = str_replace('-', '_', $k); $kk = str_replace('-', '_', $k);
$smarty->assign_by_ref($kk, $comment [$k]); $smarty->assign_by_ref($kk, $comment [$k]);
@ -923,16 +888,9 @@
} }
$smarty->assign('id', $id); $smarty->assign('id', $id);
} }
return $content; return $content;
} }
function smarty_block_comments($params, $content, &$smarty, &$repeat) { function smarty_block_comments($params, $content, &$smarty, &$repeat) {
@ -942,7 +900,6 @@
$show = $q->comments->getCount(); $show = $q->comments->getCount();
$smarty->assign('entryid', $q->comments->entryid); $smarty->assign('entryid', $q->comments->entryid);
if ($show) { if ($show) {
return $content; return $content;
@ -950,13 +907,14 @@
$repeat = false; $repeat = false;
} }
} }
function smarty_function_nextpage($params) { function smarty_function_nextpage($params) {
$nextPageLink = get_nextpage_link();
list ($caption, $link) = get_nextpage_link(); if (empty($nextPageLink)) {
return;
}
list ($caption, $link) = $nextPageLink;
if (!$link) if (!$link)
return; return;
@ -966,14 +924,15 @@
$link = BLOG_BASEURL . 'admin.php' . $qstr; $link = BLOG_BASEURL . 'admin.php' . $qstr;
} }
return "<div class=\"alignright\"><a href=\"$link\">$caption</a></div>"; return "<div class=\"alignright\"><a href=\"$link\">$caption</a></div>";
} }
function smarty_function_prevpage($params) { function smarty_function_prevpage($params) {
$prevPageLink = get_prevpage_link();
list($caption, $link) = get_prevpage_link(); if (empty($prevPageLink)) {
return;
}
list ($caption, $link) = $prevPageLink;
if (!$link) if (!$link)
return; return;
@ -983,10 +942,7 @@
$link = BLOG_BASEURL . 'admin.php' . $qstr; $link = BLOG_BASEURL . 'admin.php' . $qstr;
} }
return "<div class=\"alignleft\"><a href=\"$link\">$caption</a></div>"; return "<div class=\"alignleft\"><a href=\"$link\">$caption</a></div>";
} }
$_FP_SMARTY->register_block('comment', 'smarty_block_comment'); $_FP_SMARTY->register_block('comment', 'smarty_block_comment');

View File

@ -3,12 +3,10 @@
/** /**
* Block-Managing Functions * Block-Managing Functions
*/ */
class widget_indexer extends fs_filelister { class widget_indexer extends fs_filelister {
var $_varname = 'fp_widgets'; var $_varname = 'fp_widgets';
var $_enabledlist = null; var $_enabledlist = null;
function __construct() { function __construct() {
@ -21,25 +19,19 @@
} }
function getEnableds() { function getEnableds() {
if (!file_exists($this->_enabledlist)) if (!file_exists($this->_enabledlist))
return; return;
include ($this->_enabledlist); include ($this->_enabledlist);
$this->_list = ${$this->_varname}; $this->_list = ${$this->_varname};
} }
function hasMore($hor) { function hasMore($hor) {
return array_key_exists($hor, $this->_list) && is_array($this->_list [$hor]) && (current($this->_list [$hor]) !== false);
return is_array($this->_list[$hor]) && (current($this->_list[$hor]) !== false);
} }
function get($hor) { function get($hor) {
global $fp_registered_widgets; global $fp_registered_widgets;
do { do {
@ -47,8 +39,11 @@
$id = array_shift($this->_list [$hor]); $id = array_shift($this->_list [$hor]);
$newid=$id;# @list($newid, $params) = explode(":", $id); $newid = $id; // @list($newid, $params) = explode(":", $id);
if (@$params) $params = explode(',', $params); else $params = array(); if (@$params)
$params = explode(',', $params);
else
$params = array();
// $var = 'plugin_' . $newid . '_widget'; // $var = 'plugin_' . $newid . '_widget';
$var = $fp_registered_widgets [$newid] ['func']; $var = $fp_registered_widgets [$newid] ['func'];
if (is_callable($var)) { if (is_callable($var)) {
@ -57,26 +52,20 @@
$content ['id'] = "widget-$newid"; $content ['id'] = "widget-$newid";
} }
} /* } /*
else $content = array( * else $content = array(
'subject' => "Sidebar::Error", * 'subject' => "Sidebar::Error",
'content' => "<ul class=\"widget-error\"><li>No $var function found for plugin $newid. * 'content' => "<ul class=\"widget-error\"><li>No $var function found for plugin $newid.
Plugin may not have been loaded. * Plugin may not have been loaded.
Verify whether it is enabled.</li></ul>", * Verify whether it is enabled.</li></ul>",
); * );
*/ */
} while (!$content && $id); } while (!$content && $id);
return array_change_key_case($content, CASE_LOWER); return array_change_key_case($content, CASE_LOWER);
} }
} }
function register_widgetset($widgetset) { function register_widgetset($widgetset) {
global $fp_registered_widgetsets; global $fp_registered_widgetsets;
if (!$fp_registered_widgetsets) { if (!$fp_registered_widgetsets) {
@ -85,11 +74,8 @@
if (!in_array($widgetset, $fp_registered_widgetsets)) if (!in_array($widgetset, $fp_registered_widgetsets))
$fp_registered_widgetsets [] = $widgetset; $fp_registered_widgetsets [] = $widgetset;
} }
function get_registered_widgetsets($widgetset) { function get_registered_widgetsets($widgetset) {
global $fp_registered_widgetsets; global $fp_registered_widgetsets;
if (!$fp_registered_widgetsets) { if (!$fp_registered_widgetsets) {
@ -99,10 +85,7 @@
return $fp_registered_widgetsets; return $fp_registered_widgetsets;
} }
function register_widget($widgetid, // widget id
function register_widget(
$widgetid, // widget id
$widgetname, // name to show $widgetname, // name to show
$widget_func, // function/method to call $widget_func, // function/method to call
$num_params = 0, // number of eventually needed parameters $num_params = 0, // number of eventually needed parameters
@ -110,10 +93,9 @@
// 0 means no parameters // 0 means no parameters
// each N>0 means *at least* N parameters // each N>0 means *at least* N parameters
$limit_params_to=array()// indexed array of arrays, containing $limit_params_to = array()) // indexed array of arrays, containing
// allowed parameters (not impl.) // allowed parameters (not impl.)
) { {
global $fp_registered_widgets; global $fp_registered_widgets;
if (!$fp_registered_widgets) if (!$fp_registered_widgets)
$fp_registered_widgets = array(); $fp_registered_widgets = array();
@ -127,32 +109,22 @@
// 'needed'=> $params_needed, // 'needed'=> $params_needed,
'params' => $limit_params_to 'params' => $limit_params_to
); );
} }
function get_registered_widgets($widget = null) { function get_registered_widgets($widget = null) {
global $fp_registered_widgets; global $fp_registered_widgets;
if (!$fp_registered_widgets) if (!$fp_registered_widgets)
$fp_registered_widgets = array(); $fp_registered_widgets = array();
ksort($fp_registered_widgets); ksort($fp_registered_widgets);
if ($widget) if ($widget)
return isset($fp_registered_widgets[$widget])? return isset($fp_registered_widgets [$widget]) ? $fp_registered_widgets [$widget] : false;
$fp_registered_widgets[$widget]
:
false;
return $fp_registered_widgets; return $fp_registered_widgets;
} }
function smarty_block_widgets($params, $content, &$smarty, &$repeat) { function smarty_block_widgets($params, $content, &$smarty, &$repeat) {
global $fp_widgets; global $fp_widgets;
@ -163,12 +135,8 @@
} }
return $content; return $content;
} }
$smarty->register_block('widgets', 'smarty_block_widgets'); $smarty->register_block('widgets', 'smarty_block_widgets');
?> ?>

View File

@ -1,4 +1,5 @@
<?php <?php
/** /**
* Smarty plugin * Smarty plugin
* ------------------------------------------------------------- * -------------------------------------------------------------
@ -7,15 +8,19 @@
* Name: list_categories * Name: list_categories
* Purpose: print out the comment form * Purpose: print out the comment form
* *
* @param string after * @param
* @param string before * string after
* @param
* string before
* ------------------------------------------------------------- * -------------------------------------------------------------
*/ */
function smarty_function_list_categories($params) // , &$smarty) function smarty_function_list_categories($params) // , &$smarty)
{ {
$cat_params = array( $cat_params = array(
'ild'=>'<li>','ird'=>"</li>\n", 'ild' => '<li>',
'old'=>"<ul>\n",'ord'=>"</ul>\n", 'ird' => "</li>\n",
'old' => "<ul>\n",
'ord' => "</ul>\n",
'name' => isset($params ['name']) ? $params ['name'] : '', 'name' => isset($params ['name']) ? $params ['name'] : '',
'selected' => array() 'selected' => array()
); );
@ -23,13 +28,15 @@ function smarty_function_list_categories($params) //, &$smarty)
$cat_params = array_merge($cat_params, $params); $cat_params = array_merge($cat_params, $params);
// makese 'selected' an arr // makese 'selected' an arr
$cat_params['selected'] = (array)$params['selected']; $cat_params ['selected'] = array_key_exists('selected', $params) ? (array) $params ['selected'] : array();
// echo "<pre>" . print_r(entry_categories_get()) . "</pre>"; // echo "<pre>" . print_r(entry_categories_get()) . "</pre>";
if (file_exists(CONTENT_DIR . 'categories.txt')) { if (file_exists(CONTENT_DIR . 'categories.txt')) {
$cats = trim(io_load_file(CONTENT_DIR . 'categories.txt')); $cats = trim(io_load_file(CONTENT_DIR . 'categories.txt'));
$stack=array(0); $stack = array(
0
);
$arr = array(); $arr = array();
$line36error = explode("\n", $cats); $line36error = explode("\n", $cats);
@ -48,15 +55,9 @@ function smarty_function_list_categories($params) //, &$smarty)
// <label><input name="cats[{$catId}]" // <label><input name="cats[{$catId}]"
// {if (bool)array_intersect(array($catId),$categories) } // {if (bool)array_intersect(array($catId),$categories) }
// checked="checked"{/if} type="checkbox" /> {$cat} </label><br /> // checked="checked"{/if} type="checkbox" /> {$cat} </label><br />
} }
function do_print_categories_list(&$lines, &$indentstack, &$result, $params) { function do_print_categories_list(&$lines, &$indentstack, &$result, $params) {
global $smarty, $fpdb; global $smarty, $fpdb;
extract($params); extract($params);
@ -72,7 +73,6 @@ function do_print_categories_list(&$lines, &$indentstack, &$result, $params) {
return ''; return '';
} }
$str = ''; $str = '';
$v = reset($lines); $v = reset($lines);
$vt = ltrim($v); $vt = ltrim($v);
@ -103,34 +103,33 @@ function do_print_categories_list(&$lines, &$indentstack, &$result, $params) {
} else { } else {
array_push($result, $ild); array_push($result, $ild);
$cat_entry = $params ['selected']; $cat_entry = $params ['selected'];
if (isset($params ['type']) && ($params ['type'] == 'form' || $params ['type'] == 'check')) { if (isset($params ['type']) && ($params ['type'] == 'form' || $params ['type'] == 'check')) {
$string = '<label><input name="' . $catname . 'cats[' . $vid . ']" '; $string = '<label><input name="' . $catname . 'cats[' . $vid . ']" ';
if ((bool) array_intersect(array($vid), $cat_entry)) if ((bool) array_intersect(array(
$vid
), $cat_entry))
$string .= 'checked="checked" '; $string .= 'checked="checked" ';
$string .= 'type="checkbox" />'; $string .= 'type="checkbox" />';
$before = $string; $before = $string;
} elseif (isset($params ['type']) && $params ['type'] == 'radio') { } elseif (isset($params ['type']) && $params ['type'] == 'radio') {
$string = '<label><input name="' . $catname . 'cats" type="radio" value="' . $vid . '"'; $string = '<label><input name="' . $catname . 'cats" type="radio" value="' . $vid . '"';
if ((bool) array_intersect(array($vid), $cat_entry)) if ((bool) array_intersect(array(
$vid
), $cat_entry))
$string .= 'checked="checked" '; $string .= 'checked="checked" ';
$string .= ' />'; $string .= ' />';
$before = $string; $before = $string;
} elseif (isset($params ['type']) && $params ['type'] == 'linked') { } elseif (isset($params ['type']) && $params ['type'] == 'linked') {
$before = '<a href="' . get_category_link($vid) . '">'; $before = '<a href="' . get_category_link($vid) . '">';
} }
array_push($result, $before); array_push($result, $before);
array_push($result, $vt); array_push($result, $vt);
if (isset($params ['type']) && ($params ['type'] == 'form' || $params ['type'] == 'check' || $params ['type'] == 'radio')) { if (isset($params ['type']) && ($params ['type'] == 'form' || $params ['type'] == 'check' || $params ['type'] == 'radio')) {
@ -153,5 +152,4 @@ function do_print_categories_list(&$lines, &$indentstack, &$result, $params) {
} }
return implode($result); return implode($result);
} }

View File

@ -1,5 +1,5 @@
<div id="errorlist"> <div id="errorlist">
{if $error} {if isset($error)}
<ul class="msgs errors"> <ul class="msgs errors">
{foreach from=$error key=field item=msg} {foreach from=$error key=field item=msg}
<li> <li>
@ -13,7 +13,7 @@
</ul> </ul>
{/if} {/if}
{if $warnings} {if isset($warnings)}
<ul class="msgs warnings"> <ul class="msgs warnings">
{foreach from=$warnings key=field item=msg} {foreach from=$warnings key=field item=msg}
<li> <li>
@ -27,7 +27,7 @@
</ul> </ul>
{/if} {/if}
{if $notifications} {if isset($notifications)}
<ul class="msgs notifications"> <ul class="msgs notifications">
{foreach from=$notifications item=msg} {foreach from=$notifications item=msg}
<li>{$msg}</li> <li>{$msg}</li>

View File

@ -62,8 +62,8 @@ class plugin_commentcenter {
function lock() { function lock() {
global $fp_params, $post, $smarty; global $fp_params, $post, $smarty;
$this->loadPolicies(); $this->loadPolicies();
$cats = is_array($post ['categories']) ? $post ['categories'] : array(); $cats = array_key_exists('categories', $post) && is_array($post ['categories']) ? $post ['categories'] : array();
$behavoir = $this->behavoirFromPolicies($fp_params ['entry'], $cats); $behavoir = array_key_exists('entry', $fp_params) ? $this->behavoirFromPolicies($fp_params ['entry'], $cats) : 1;
if ($behavoir == -1 && !user_loggedin()) { if ($behavoir == -1 && !user_loggedin()) {
$smarty->assign('entry_commslock', true); $smarty->assign('entry_commslock', true);
} }