This is obviously a BIG commit.

It involves how widgets work. 

Now widgets must always be *registered* to work, even blockparser's.

Blockparser has got then a nice GUI to select which pages should be available as widgets; once the page has been enabled it is then available in the main widget panels

This solves the non-editable input things with non-firefox browsers: this way you just won't have the editbox anymore :P

I hope you'll like the changes.

There are many additions in lang files, so be careful to update (otherwise you'll get blank lines)!
This commit is contained in:
real_nowhereman 2008-02-29 16:10:33 +00:00
parent 461d02ad78
commit 7414932235
8 changed files with 120 additions and 61 deletions

View File

@ -22,7 +22,7 @@
$widget_list[$wpos][$idx] = array();
@list($newid, $params) = explode(":", $wdg);
$newid = $wdg; # @list($newid, $params) = explode(":", $wdg);
$widget_list[$wpos][$idx]['id'] = $newid;
@ -46,8 +46,13 @@
} else {
global $lang;
$widget_list[$wpos][$idx]['name'] = $newid;
$widget_list[$wpos][$idx]['class'] = 'warnings';
$widget_list[$wpos][$idx]['class'] = 'errors';
$errs = sprintf($lang['admin']['widgets']['errors']['generic'], $newid);
$this->smarty->append('warnings', $errs);
}
}
@ -63,7 +68,7 @@
lang_load('admin.widgets');
$this->smarty->assign('warnings', admin_widgets_checkall());
# $this->smarty->assign('warnings', admin_widgets_checkall());
global $fp_widgets;

View File

@ -47,7 +47,7 @@
<ul id="widgetsetid-{$widgetset}">
{foreach from=$widgetarr item=widget}
<li class="widget-instance widget-id-{$widget.id}">
<li class="widget-instance widget-id-{$widget.id} {$widget.class}">
<input class="widget-id" type="hidden" name="widgets[{$widgetset}][]"
value="{$widget.id}{if $widget.params}:{$widget.params}{/if}" />
{if $widget.params}

View File

@ -24,7 +24,15 @@ $fp_config = array (
'dateformat' => '%A, %B %e, %Y',
'charset' => 'utf-8',
'lang' => 'en-us',
)
),
'plugins' =>
array (
'blockparser' =>
array (
'menu',
'about',
),
),
);
?>

View File

@ -42,13 +42,13 @@
global $fp_registered_widgets;
$content = array();
do {
$content = array();
list(,$id) = each($this->_list[$hor]);
@list($newid, $params) = explode(":", $id);
if ($params) $params = explode(',', $params); else $params = array();
$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 (function_exists($var)) {
@ -65,9 +65,9 @@
);
*/
} while(!$content);
} while(!$content && $id);
return array_change_key_case($content, CASE_LOWER);
return array_change_key_case($content, CASE_LOWER);

View File

@ -76,8 +76,8 @@
/* system errors */
$lang['admin']['widgets']['errors'] = array(
'generic' => 'Could not find widget in plugin <strong>%s</strong>. '.
'Check if it is enabled in the <a href="admin.php?p=plugin">plugin panel</a>'
'generic' => 'The widget called <strong>%s</strong> is not registered, and it might not work. '.
'Is the plugin enabled in the <a href="admin.php?p=plugin">plugin panel</a>?'
);

View File

@ -4,19 +4,23 @@
$lang['admin']['widgets']['blockparser'] = array(
'head' => 'BlockParser Widgets',
'description'=>'BlockParser plugin allows you to create a widget '.
'from a static page. '.
'Select one or more static pages from the list to make a '.
' corresponding widget available.',
'description' => 'BlockParser plugin allows you to create a widget from a static page. </p><p>
Select one or more static pages from the list to make a corresponding widget available.</p><p>
Each <a href="?p=static&amp;action=write">new static page</a> you create will be listed here.',
'id' => 'Static page',
'title' => 'Title',
'action' => 'Action',
'enable' => 'Enable',
'disable' => 'Disable',
'edit' => 'Edit',
);
$lang['admin']['plugin']['blockparser']['msgs'] = array(
1 => 'The new widget is available. Activate it from the main panel!',
-1 => 'Can\'t create the requested widget'
$lang['admin']['widgets']['blockparser']['msgs'] = array(
1 => 'Your new widget is available. Add it to your blog from the <a href="?p=widgets">main panel!</a>',
-1 => 'Can\'t create the requested widget',
2 => 'You have disabled a widget: don\'t forget to remove any references from the <a href="?p=widgets">main panel</a>!',
-2 => 'Can\'t disable the widget'
);
?>

View File

@ -27,7 +27,7 @@ function plugin_blockparser_parse($blockid) {
return false;
}
register_widget('blockparser', 'BlockParser', 'plugin_blockparser_widget', 1);
# register_widget('blockparser', 'BlockParser', 'plugin_blockparser_widget', 1);
function plugin_blockparser_widget($blockid) {
@ -44,8 +44,6 @@ function plugin_blockparser_widget($blockid) {
function plugin_blockparser_init() {
global $fp_config;
// for instance:
// $fp_config['plugins']['blockparser']['pages'] = array('menu');
@ -57,58 +55,75 @@ function plugin_blockparser_init() {
// this would suggest to use an object, though :B
// anyway the result is the same...
/*
if (isset($fp_config['plugins']['blockparser'])) {
$pgs = $fp_config['plugins']['blockparser']['pages'];
$pgs = plugin_getoptions('blockparser', 'pages');
if (is_array($pgs)) {
foreach ($pgs as $page) {
register_widget($page, create_function('', "return plugin_blockparser_widget('$page');"));
register_widget(
'blockparser:'.$page, // widget id
'BlockParser: ' .$page, // widget name
create_function('', "return plugin_blockparser_widget('$page');") // lambda func
);
}
}
*/
}
add_action('init', 'plugin_blockparser_init');
if (false and class_exists('AdminPanelAction')){
if (class_exists('AdminPanelAction')){
class admin_widgets_blockparser extends AdminPanelAction {
var $langres = 'plugin:blockparser';
var $commands = array('enable', 'disable');
function doenable($id) {
$success = -1;
$enabled =& $this->bp_enabled;
if (static_exists($id)) {
if (!$enabled) {
$enabled = array();
}
if (!in_array($id, $enabled)) {
$enabled[] = $id;
sort($enabled);
plugin_addoption('blockparser', 'pages', $enabled);
plugin_saveoptions();
$success = 1;
}
}
$this->smarty->assign('success', $success);
return PANEL_REDIRECT_CURRENT;
}
function dodisable($id) {
$success = -2;
$enabled =& $this->bp_enabled;
if ($enabled && is_numeric( $v = array_search($id, $enabled ) ) ) {
unset($enabled[$v]);
@sort($enabled);
@plugin_addoption('blockparser', 'pages', $enabled);
plugin_saveoptions();
$success = 2;
}
$this->smarty->assign('success', $success);
return PANEL_REDIRECT_CURRENT;
}
function setup() {
$this->smarty->assign('admin_resource', "plugin:blockparser/admin.plugin.blockparser");
$this->smarty->assign('enabledlist', $this->bp_enabled = plugin_getoptions('blockparser', 'pages'));
}
function main() {
global $fp_config;
$this->smarty->assign_by_ref('enabledpages', $fp_config['plugins']['blockparser']);
// $this->smarty->assign_by_ref('enabledpages', plugin_getoptions('blockparser'));
$this->smarty->assign('statics', $assign = static_getlist());
}
function onsubmit() {
global $fp_config;
if ($_POST['wp-apikey']){
$fp_config['plugins']['akismet']['apikey'] = $_POST['wp-apikey'];
config_save();
$this->smarty->assign('success', 1);
} else {
$this->smarty->assign('success', -1);
}
// redirect to this panel (clears POSTDATA;
// 1 would redirect to the default 'action' for widget panel)
return 2;
}
}
admin_addpanelaction('widgets', 'blockparser', true);

View File

@ -1,7 +1,5 @@
{*assign var="ps" value=`$panelstrings.blockparser`*}
{*assign var="panelstrings" value=`$panelstrings.blockparser`*}
<h2>{$ps.head}</h2>
<p>{$ps.description}</p>
<h2>{$plang.head}</h2>
<p>{$plang.description}</p>
{include file=shared:errorlist.tpl}
{static_block}
@ -12,11 +10,40 @@
<table class="entrylist">
<thead>
<tr><th>{$panelstrings.title}</th>
<th>{$panelstrings.enable}</th></tr></thead>
<tr>
<th>{$plang.id}</th>
<th>{$panelstrings.title}</th>
<th>{$panelstrings.action}</th></tr></thead>
<tbody>
{static}
<tr>
{assign var=inarr value=$id|in_array:$enabledlist}
<tr{if $inarr} class="enabled" {/if}>
<td> {$id} </td>
<td class="main-cell"> {$subject} </td>
<td>
<a
class="link-general"
href="{"?p=static"|action_link:write}&amp;page={$id}">
{$panelstrings.edit}
</a>
{if $inarr}
<a class="link-disable"
href="{$action_url|cmd_link:disable:$id}">
{$panelstrings.disable}
</a>
{else}
<a class="link-enable"
href="{$action_url|cmd_link:enable:$id}">
{$panelstrings.enable}
</a>
{/if}
</td>
</tr>
{*** <tr>
<td>
<a href="admin.php?p=static&amp;page={$id}&amp;action=write">{$subject|truncate:70}</a>
@ -24,7 +51,7 @@
<td>enable/disable</td>
</tr>
***}
{/static}
</tbody></table>
</form>