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

View File

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

View File

@ -26,7 +26,7 @@
<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>
<fieldset><legend>{$panelstrings.filter}</legend>
<select name="category" class="alignleft">

View File

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

View File

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

File diff suppressed because it is too large Load Diff

View File

@ -1,174 +1,142 @@
<?php
/**
* Block-Managing Functions
*/
/**
* Block-Managing Functions
*/
class widget_indexer extends fs_filelister {
var $_varname = 'fp_widgets';
var $_enabledlist = null;
class widget_indexer extends fs_filelister {
var $_varname = 'fp_widgets';
var $_enabledlist = null;
function __construct() {
if (!file_exists(CONFIG_DIR. 'widgets.conf.php'))
trigger_error('widgets.conf.php not found. Blog may not work as expected, create a widgetlist.conf.php
function __construct() {
if (!file_exists(CONFIG_DIR . 'widgets.conf.php'))
trigger_error('widgets.conf.php not found. Blog may not work as expected, create a widgetlist.conf.php
or reinstall completely FlatPress. If you have just installed FlatPress, the package you
downloaded may be corrupted.', E_USER_WARNING);
$this->_enabledlist = CONFIG_DIR . 'widgets.conf.php';
$this->getEnableds();
}
function getEnableds() {
if (!file_exists($this->_enabledlist))
return;
include($this->_enabledlist);
$this->_list = ${$this->_varname};
}
function hasMore($hor) {
return is_array($this->_list[$hor]) && (current($this->_list[$hor]) !== false);
}
function get($hor) {
global $fp_registered_widgets;
do {
$content = array();
$id = array_shift($this->_list[$hor]);
$newid=$id;# @list($newid, $params) = explode(":", $id);
if (@$params) $params = explode(',', $params); else $params = array();
// $var = 'plugin_' . $newid . '_widget';
$var = $fp_registered_widgets[ $newid ]['func'];
if (is_callable($var)) {
$content = call_user_func_array($var, $params);
if (!isset($content['id'])) {
$content['id'] = "widget-$newid";
}
} /*
else $content = array(
'subject' => "Sidebar::Error",
'content' => "<ul class=\"widget-error\"><li>No $var function found for plugin $newid.
Plugin may not have been loaded.
Verify whether it is enabled.</li></ul>",
);
*/
} while(!$content && $id);
return array_change_key_case($content, CASE_LOWER);
}
$this->_enabledlist = CONFIG_DIR . 'widgets.conf.php';
$this->getEnableds();
}
function getEnableds() {
if (!file_exists($this->_enabledlist))
return;
function register_widgetset($widgetset) {
global $fp_registered_widgetsets;
if (!$fp_registered_widgetsets) {
$fp_registered_widgetsets = array();
}
if (!in_array($widgetset, $fp_registered_widgetsets))
$fp_registered_widgetsets[] = $widgetset;
include ($this->_enabledlist);
$this->_list = ${$this->_varname};
}
function get_registered_widgetsets($widgetset) {
global $fp_registered_widgetsets;
if (!$fp_registered_widgetsets) {
$fp_registered_widgetsets = array();
}
return $fp_registered_widgetsets;
function hasMore($hor) {
return array_key_exists($hor, $this->_list) && is_array($this->_list [$hor]) && (current($this->_list [$hor]) !== false);
}
function register_widget(
$widgetid, // widget id
$widgetname, // name to show
$widget_func, // function/method to call
$num_params = 0, // number of eventually needed parameters
// -1 means optional,
// 0 means no parameters
// each N>0 means *at least* N parameters
$limit_params_to=array()// indexed array of arrays, containing
// allowed parameters (not impl.)
) {
global $fp_registered_widgets;
if (!$fp_registered_widgets)
$fp_registered_widgets = array();
/* we won't mind about collisions, for now */
$fp_registered_widgets[$widgetid] = array(
'name' => $widgetname,
'func' => $widget_func,
'nparams'=> $num_params,
//'needed'=> $params_needed,
'params'=> $limit_params_to
);
}
function get_registered_widgets($widget=null) {
function get($hor) {
global $fp_registered_widgets;
if (!$fp_registered_widgets)
$fp_registered_widgets = array();
do {
$content = array();
$id = array_shift($this->_list [$hor]);
ksort($fp_registered_widgets);
if ($widget)
return isset($fp_registered_widgets[$widget])?
$fp_registered_widgets[$widget]
:
false;
return $fp_registered_widgets;
$newid = $id; // @list($newid, $params) = explode(":", $id);
if (@$params)
$params = explode(',', $params);
else
$params = array();
// $var = 'plugin_' . $newid . '_widget';
$var = $fp_registered_widgets [$newid] ['func'];
if (is_callable($var)) {
$content = call_user_func_array($var, $params);
if (!isset($content ['id'])) {
$content ['id'] = "widget-$newid";
}
} /*
* else $content = array(
* 'subject' => "Sidebar::Error",
* 'content' => "<ul class=\"widget-error\"><li>No $var function found for plugin $newid.
* Plugin may not have been loaded.
* Verify whether it is enabled.</li></ul>",
* );
*/
} while (!$content && $id);
return array_change_key_case($content, CASE_LOWER);
}
}
function smarty_block_widgets($params, $content, &$smarty, &$repeat) {
global $fp_widgets;
if($repeat = $fp_widgets->hasMore(($params['pos']))) {
$entry = $fp_widgets->get(($params['pos']));
$smarty->assign($entry);
}
return $content;
function register_widgetset($widgetset) {
global $fp_registered_widgetsets;
if (!$fp_registered_widgetsets) {
$fp_registered_widgetsets = array();
}
if (!in_array($widgetset, $fp_registered_widgetsets))
$fp_registered_widgetsets [] = $widgetset;
}
$smarty->register_block('widgets','smarty_block_widgets');
function get_registered_widgetsets($widgetset) {
global $fp_registered_widgetsets;
if (!$fp_registered_widgetsets) {
$fp_registered_widgetsets = array();
}
return $fp_registered_widgetsets;
}
function register_widget($widgetid, // widget id
$widgetname, // name to show
$widget_func, // function/method to call
$num_params = 0, // number of eventually needed parameters
// -1 means optional,
// 0 means no parameters
// each N>0 means *at least* N parameters
$limit_params_to = array()) // indexed array of arrays, containing
// allowed parameters (not impl.)
{
global $fp_registered_widgets;
if (!$fp_registered_widgets)
$fp_registered_widgets = array();
/* we won't mind about collisions, for now */
$fp_registered_widgets [$widgetid] = array(
'name' => $widgetname,
'func' => $widget_func,
'nparams' => $num_params,
// 'needed'=> $params_needed,
'params' => $limit_params_to
);
}
function get_registered_widgets($widget = null) {
global $fp_registered_widgets;
if (!$fp_registered_widgets)
$fp_registered_widgets = array();
ksort($fp_registered_widgets);
if ($widget)
return isset($fp_registered_widgets [$widget]) ? $fp_registered_widgets [$widget] : false;
return $fp_registered_widgets;
}
function smarty_block_widgets($params, $content, &$smarty, &$repeat) {
global $fp_widgets;
if ($repeat = $fp_widgets->hasMore(($params ['pos']))) {
$entry = $fp_widgets->get(($params ['pos']));
$smarty->assign($entry);
}
return $content;
}
$smarty->register_block('widgets', 'smarty_block_widgets');
?>

View File

@ -1,70 +1,71 @@
<?php
/**
* Smarty plugin
* -------------------------------------------------------------
* File: function.list_categories.php
* Type: function
* Name: list_categories
* Purpose: print out the comment form
* File: function.list_categories.php
* Type: function
* Name: list_categories
* Purpose: print out the comment form
*
* @param string after
* @param string before
* -------------------------------------------------------------
* @param
* string after
* @param
* string before
* -------------------------------------------------------------
*/
function smarty_function_list_categories($params) //, &$smarty)
function smarty_function_list_categories($params) // , &$smarty)
{
$cat_params = array(
'ild'=>'<li>','ird'=>"</li>\n",
'old'=>"<ul>\n",'ord'=>"</ul>\n",
'name' => isset($params['name'])? $params['name'] : '',
'selected' => array()
);
'ild' => '<li>',
'ird' => "</li>\n",
'old' => "<ul>\n",
'ord' => "</ul>\n",
'name' => isset($params ['name']) ? $params ['name'] : '',
'selected' => array()
);
$cat_params = array_merge($cat_params, $params);
// 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')) {
$cats = trim(io_load_file(CONTENT_DIR . 'categories.txt'));
$stack=array(0);
$arr=array();
$stack = array(
0
);
$arr = array();
$line36error = explode("\n", $cats);
$line35error = '<ul>'.do_print_categories_list($line36error, $stack, $arr, $cat_params).'</ul>';
$line36error = explode("\n", $cats);
$line35error = '<ul>' . do_print_categories_list($line36error, $stack, $arr, $cat_params) . '</ul>';
return $line35error;
return $line35error;
} else {
global $lang;
$content = '<a href="'.BLOG_BASEURL.'">Unfiled</a>';
if (isset($lang['admin']['entry']['publish']['nocategories']))
$content = $lang['admin']['entry']['publish']['nocategories'];
return '<ul><li>' . $content .'</li></ul>' ;
$content = '<a href="' . BLOG_BASEURL . '">Unfiled</a>';
if (isset($lang ['admin'] ['entry'] ['publish'] ['nocategories']))
$content = $lang ['admin'] ['entry'] ['publish'] ['nocategories'];
return '<ul><li>' . $content . '</li></ul>';
}
//<label><input name="cats[{$catId}]"
//{if (bool)array_intersect(array($catId),$categories) }
//checked="checked"{/if} type="checkbox" /> {$cat} </label><br />
// <label><input name="cats[{$catId}]"
// {if (bool)array_intersect(array($catId),$categories) }
// checked="checked"{/if} type="checkbox" /> {$cat} </label><br />
}
function do_print_categories_list(&$lines, &$indentstack, &$result, $params) {
global $smarty, $fpdb;
extract($params);
if (empty($lines)) {
$l = count($indentstack)-1;
if (empty($lines)) {
$l = count($indentstack) - 1;
if ($l > 0)
$arr = array_fill(0, $l, $ord.$ird);
$arr = array_fill(0, $l, $ord . $ird);
else
$arr = array();
@ -72,86 +73,83 @@ function do_print_categories_list(&$lines, &$indentstack, &$result, $params) {
return '';
}
$str = '';
$v = reset($lines);
$vt = ltrim($v);
$str = '';
$v = reset($lines);
$vt = ltrim($v);
$indent = utils_countdashes($vt, $text);
$indent_old = end($indentstack);
$indent = utils_countdashes($vt, $text);
$indent_old = end($indentstack);
$val = explode(':', $text);
$vt = $val[0];
$vid = trim($val[1]);
$vt = $val [0];
$vid = trim($val [1]);
$catname = $params['name'];
$catname = $params ['name'];
if ($indent > $indent_old) {
array_push($indentstack, $indent);
if ($indent > $indent_old) {
array_push($indentstack, $indent);
array_pop($result);
array_push($result, $old);
//array_push($result, $ild);
do_print_categories_list($lines, $indentstack, $result, $params);
}elseif($indent < $indent_old) {
array_pop($indentstack);
array_pop($result);
array_push($result, $old);
// array_push($result, $ild);
do_print_categories_list($lines, $indentstack, $result, $params);
} elseif ($indent < $indent_old) {
array_pop($indentstack);
array_push($result, $ord);
array_push($result, $ird);
do_print_categories_list($lines, $indentstack, $result, $params);
}else{
array_push($result, $ild);
do_print_categories_list($lines, $indentstack, $result, $params);
} else {
array_push($result, $ild);
$cat_entry = $params ['selected'];
$cat_entry = $params['selected'];
if (isset($params ['type']) && ($params ['type'] == 'form' || $params ['type'] == 'check')) {
$string = '<label><input name="' . $catname . 'cats[' . $vid . ']" ';
if (isset($params['type']) && ($params['type']=='form' || $params['type']=='check')) {
$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 .= 'type="checkbox" />';
$string .= 'type="checkbox" />';
$before = $string;
}elseif (isset($params['type']) && $params['type']=='radio') {
$string = '<label><input name="'.$catname.'cats" type="radio" value="'.$vid.'"';
if ((bool) array_intersect(array($vid), $cat_entry))
} elseif (isset($params ['type']) && $params ['type'] == 'radio') {
$string = '<label><input name="' . $catname . 'cats" type="radio" value="' . $vid . '"';
if ((bool) array_intersect(array(
$vid
), $cat_entry))
$string .= 'checked="checked" ';
$string .= ' />';
$before = $string;
}elseif(isset($params['type']) && $params['type']=='linked'){
$before = '<a href="'.get_category_link($vid).'">';
} elseif (isset($params ['type']) && $params ['type'] == 'linked') {
$before = '<a href="' . get_category_link($vid) . '">';
}
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')) {
$string = '</label>';
$after = $string;
}elseif(isset($params['type']) && $params['type']=='linked'){
$after='</a>';
if (isset($params['count']) && $params['count']) {
$index =& $fpdb->get_index($vid);
$count = ($index)? $index->length() : 0;
$after = " ($count) ". $after;
} elseif (isset($params ['type']) && $params ['type'] == 'linked') {
$after = '</a>';
if (isset($params ['count']) && $params ['count']) {
$index = & $fpdb->get_index($vid);
$count = ($index) ? $index->length() : 0;
$after = " ($count) " . $after;
}
}
array_push($result, $after);
array_push($result, $ird);
array_shift($lines);
do_print_categories_list($lines, $indentstack, $result, $params);
}
return implode($result);
array_push($result, $ird);
array_shift($lines);
do_print_categories_list($lines, $indentstack, $result, $params);
}
return implode($result);
}

View File

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

View File

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