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">
{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> </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,8 +14,10 @@
{html_form} {html_form}
{if !isset($post)}
{entry content=$post alwaysshow=true} {assign var=post value=""}
{/if}
{entry content=$post alwaysshow=true}
<div id="admin-editor"> <div id="admin-editor">
<p><label for="subject">{$panelstrings.subject}</label><br /> <p><label for="subject">{$panelstrings.subject}</label><br />

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>

File diff suppressed because it is too large Load Diff

View File

@ -1,174 +1,142 @@
<?php <?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 { function __construct() {
if (!file_exists(CONFIG_DIR . 'widgets.conf.php'))
var $_varname = 'fp_widgets'; trigger_error('widgets.conf.php not found. Blog may not work as expected, create a widgetlist.conf.php
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
or reinstall completely FlatPress. If you have just installed FlatPress, the package you or reinstall completely FlatPress. If you have just installed FlatPress, the package you
downloaded may be corrupted.', E_USER_WARNING); downloaded may be corrupted.', E_USER_WARNING);
$this->_enabledlist = CONFIG_DIR . 'widgets.conf.php'; $this->_enabledlist = CONFIG_DIR . 'widgets.conf.php';
$this->getEnableds(); $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);
}
} }
function getEnableds() {
if (!file_exists($this->_enabledlist))
return;
function register_widgetset($widgetset) { include ($this->_enabledlist);
global $fp_registered_widgetsets;
if (!$fp_registered_widgetsets) {
$fp_registered_widgetsets = array();
}
if (!in_array($widgetset, $fp_registered_widgetsets))
$fp_registered_widgetsets[] = $widgetset;
$this->_list = ${$this->_varname};
} }
function hasMore($hor) {
return array_key_exists($hor, $this->_list) && is_array($this->_list [$hor]) && (current($this->_list [$hor]) !== false);
function get_registered_widgetsets($widgetset) {
global $fp_registered_widgetsets;
if (!$fp_registered_widgetsets) {
$fp_registered_widgetsets = array();
}
return $fp_registered_widgetsets;
} }
function get($hor) {
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; global $fp_registered_widgets;
if (!$fp_registered_widgets) do {
$fp_registered_widgets = array(); $content = array();
$id = array_shift($this->_list [$hor]);
ksort($fp_registered_widgets); $newid = $id; // @list($newid, $params) = explode(":", $id);
if (@$params)
if ($widget) $params = explode(',', $params);
return isset($fp_registered_widgets[$widget])? else
$fp_registered_widgets[$widget] $params = array();
: // $var = 'plugin_' . $newid . '_widget';
false; $var = $fp_registered_widgets [$newid] ['func'];
if (is_callable($var)) {
return $fp_registered_widgets; $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 register_widgetset($widgetset) {
function smarty_block_widgets($params, $content, &$smarty, &$repeat) { global $fp_registered_widgetsets;
global $fp_widgets; if (!$fp_registered_widgetsets) {
$fp_registered_widgetsets = array();
if($repeat = $fp_widgets->hasMore(($params['pos']))) {
$entry = $fp_widgets->get(($params['pos']));
$smarty->assign($entry);
}
return $content;
} }
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 <?php
/** /**
* Smarty plugin * Smarty plugin
* ------------------------------------------------------------- * -------------------------------------------------------------
* File: function.list_categories.php * File: function.list_categories.php
* Type: function * Type: function
* 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",
'name' => isset($params['name'])? $params['name'] : '', 'old' => "<ul>\n",
'selected' => array() 'ord' => "</ul>\n",
); 'name' => isset($params ['name']) ? $params ['name'] : '',
'selected' => array()
);
$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(
$arr=array(); 0
);
$arr = array();
$line36error = explode("\n", $cats); $line36error = explode("\n", $cats);
$line35error = '<ul>'.do_print_categories_list($line36error, $stack, $arr, $cat_params).'</ul>'; $line35error = '<ul>' . do_print_categories_list($line36error, $stack, $arr, $cat_params) . '</ul>';
return $line35error; return $line35error;
} else { } else {
global $lang; global $lang;
$content = '<a href="'.BLOG_BASEURL.'">Unfiled</a>'; $content = '<a href="' . BLOG_BASEURL . '">Unfiled</a>';
if (isset($lang['admin']['entry']['publish']['nocategories'])) if (isset($lang ['admin'] ['entry'] ['publish'] ['nocategories']))
$content = $lang['admin']['entry']['publish']['nocategories']; $content = $lang ['admin'] ['entry'] ['publish'] ['nocategories'];
return '<ul><li>' . $content .'</li></ul>' ; return '<ul><li>' . $content . '</li></ul>';
} }
//<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);
if (empty($lines)) { if (empty($lines)) {
$l = count($indentstack)-1; $l = count($indentstack) - 1;
if ($l > 0) if ($l > 0)
$arr = array_fill(0, $l, $ord.$ird); $arr = array_fill(0, $l, $ord . $ird);
else else
$arr = array(); $arr = array();
@ -72,86 +73,83 @@ function do_print_categories_list(&$lines, &$indentstack, &$result, $params) {
return ''; return '';
} }
$str = '';
$v = reset($lines);
$vt = ltrim($v);
$str = ''; $indent = utils_countdashes($vt, $text);
$v = reset($lines); $indent_old = end($indentstack);
$vt = ltrim($v);
$indent = utils_countdashes($vt, $text);
$indent_old = end($indentstack);
$val = explode(':', $text); $val = explode(':', $text);
$vt = $val[0]; $vt = $val [0];
$vid = trim($val[1]); $vid = trim($val [1]);
$catname = $params['name']; $catname = $params ['name'];
if ($indent > $indent_old) { if ($indent > $indent_old) {
array_push($indentstack, $indent); array_push($indentstack, $indent);
array_pop($result); array_pop($result);
array_push($result, $old); array_push($result, $old);
//array_push($result, $ild); // array_push($result, $ild);
do_print_categories_list($lines, $indentstack, $result, $params); do_print_categories_list($lines, $indentstack, $result, $params);
}elseif($indent < $indent_old) { } elseif ($indent < $indent_old) {
array_pop($indentstack); array_pop($indentstack);
array_push($result, $ord); array_push($result, $ord);
array_push($result, $ird); array_push($result, $ird);
do_print_categories_list($lines, $indentstack, $result, $params); 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')) {
$string = '<label><input name="' . $catname . 'cats[' . $vid . ']" ';
if (isset($params['type']) && ($params['type']=='form' || $params['type']=='check')) { if ((bool) array_intersect(array(
$string = '<label><input name="'.$catname.'cats['.$vid.']" '; $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') {
$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, $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>'; $string = '</label>';
$after = $string; $after = $string;
}elseif(isset($params['type']) && $params['type']=='linked'){ } elseif (isset($params ['type']) && $params ['type'] == 'linked') {
$after='</a>'; $after = '</a>';
if (isset($params['count']) && $params['count']) { if (isset($params ['count']) && $params ['count']) {
$index =& $fpdb->get_index($vid); $index = & $fpdb->get_index($vid);
$count = ($index)? $index->length() : 0; $count = ($index) ? $index->length() : 0;
$after = " ($count) ". $after; $after = " ($count) " . $after;
} }
} }
array_push($result, $after); array_push($result, $after);
array_push($result, $ird); array_push($result, $ird);
array_shift($lines); array_shift($lines);
do_print_categories_list($lines, $indentstack, $result, $params); 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);
} }