Skip to content

Commit 63f6f9a

Browse files
committed
Snippet settings per widget for plugin "Tag to Snippet"
1 parent 9100f1f commit 63f6f9a

1 file changed

Lines changed: 68 additions & 26 deletions

File tree

plugins/_tag_snippet.plugin.php

Lines changed: 68 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ function GetDefaultSettings( & $params )
6262
return array(
6363
'snippets' => array(
6464
'label' => T_('Snippets'),
65+
'note' => T_('Please note snippets defined here may be overridden per collection and per widget by same tag.'),
6566
'type' => 'array',
6667
'entries' => array(
6768
'tag' => array(
@@ -92,9 +93,14 @@ function GetDefaultSettings( & $params )
9293
*/
9394
function get_coll_setting_definitions( & $params )
9495
{
96+
global $admin_url;
97+
9598
return array_merge( array(
9699
'snippets' => array(
97100
'label' => T_('Snippets'),
101+
'note' => sprintf( T_('Please note snippets defined here override snippets with same tag defined in <a %s>general settings of the plugin "%s"</a>, and they may be overridden per widget by same tag.'),
102+
'href="'.$admin_url.'?ctrl=plugins&action=edit_settings&plugin_ID='.$this->ID.'"',
103+
$this->name ),
98104
'type' => 'array',
99105
'entries' => array(
100106
'tag' => array(
@@ -118,6 +124,48 @@ function get_coll_setting_definitions( & $params )
118124
}
119125

120126

127+
/**
128+
* Get definitions for widget specific editable params
129+
*
130+
* @see Plugin::GetDefaultSettings()
131+
* @param local params like 'for_editing' => true
132+
*/
133+
function get_widget_param_definitions( $params )
134+
{
135+
global $Blog, $admin_url;
136+
137+
return array(
138+
'title' => array(
139+
'label' => T_('Block title'),
140+
'note' => T_('Title to display in your skin.'),
141+
'size' => 60,
142+
'defaultvalue' => '',
143+
),
144+
'snippets' => array(
145+
'label' => T_('Snippets'),
146+
'note' => sprintf( T_('Please note snippets defined here override snippets with same tag defined in <a %s>current collection plugin settings</a> and in <a %s>general settings of the plugin "%s"</a>.'),
147+
'href="'.$admin_url.'?ctrl=coll_settings&tab=plugins&plugin_group=widget&blog='.$Blog->ID.'"',
148+
'href="'.$admin_url.'?ctrl=plugins&action=edit_settings&plugin_ID='.$this->ID.'"',
149+
$this->name ),
150+
'type' => 'array',
151+
'entries' => array(
152+
'tag' => array(
153+
'label' => T_('Tag'),
154+
'defaultvalue' => '',
155+
'size' => 50,
156+
),
157+
'html_snippet' => array(
158+
'label' => T_('HTML snippet'),
159+
'type' => 'textarea',
160+
'defaultvalue' => '',
161+
'rows' => 4,
162+
),
163+
),
164+
),
165+
);
166+
}
167+
168+
121169
/**
122170
* Get keys for block/widget caching
123171
*
@@ -171,32 +219,46 @@ function SkinTag( & $params )
171219
return false;
172220
}
173221

174-
$widget_snippets = array();
222+
$tag_snippets = array();
223+
// 1) Use firsty General plugin setting:
175224
$general_snippets = $this->get_setting( 'snippets', $Blog );
176225
if( is_array( $general_snippets ) )
177226
{
178227
foreach( $general_snippets as $general_snippet )
179228
{
180229
if( in_array( $general_snippet['tag'], $item_tags ) )
181230
{
182-
$widget_snippets[ $general_snippet['tag'] ] = $general_snippet['html_snippet'];
231+
$tag_snippets[ $general_snippet['tag'] ] = $general_snippet['html_snippet'];
183232
}
184233
}
185234
}
186-
// Override general setting with settings per collection:
235+
// 2) Override general settings with settings per collection:
187236
$coll_snippets = $this->get_coll_setting( 'snippets', $Blog );
188237
if( is_array( $coll_snippets ) )
189238
{
190239
foreach( $coll_snippets as $coll_snippet )
191240
{
192241
if( in_array( $coll_snippet['tag'], $item_tags ) )
193242
{
194-
$widget_snippets[ $coll_snippet['tag'] ] = $coll_snippet['html_snippet'];
243+
$tag_snippets[ $coll_snippet['tag'] ] = $coll_snippet['html_snippet'];
244+
}
245+
}
246+
}
247+
// 2) Override general and/or collection settings with settings per widget:
248+
$widget_snippets = $this->get_widget_setting( 'snippets' );
249+
if( is_array( $widget_snippets ) )
250+
{
251+
foreach( $widget_snippets as $widget_snippet )
252+
{
253+
if( in_array( $widget_snippet['tag'], $item_tags ) )
254+
{
255+
$tag_snippets[ $widget_snippet['tag'] ] = $widget_snippet['html_snippet'];
195256
}
196257
}
197258
}
259+
198260

199-
if( empty( $widget_snippets ) )
261+
if( empty( $tag_snippets ) )
200262
{ // Don't display this widget when no snippets are defined for tags of the current Item::
201263
$this->display_widget_debug_message( 'Plugin widget "'.$this->name.'" is hidden because no defined snippets for tags of this Item.' );
202264
return false;
@@ -209,33 +271,13 @@ function SkinTag( & $params )
209271
echo $this->widget_params['block_body_start'];
210272

211273
// Display snippets what found for tags of the current Item:
212-
echo implode( ' ', $widget_snippets );
274+
echo implode( ' ', $tag_snippets );
213275

214276
echo $this->widget_params['block_body_end'];
215277

216278
echo $this->widget_params['block_end'];
217279

218280
return true;
219281
}
220-
221-
222-
/**
223-
* Get definitions for widget specific editable params
224-
*
225-
* @see Plugin::GetDefaultSettings()
226-
* @param local params like 'for_editing' => true
227-
*/
228-
function get_widget_param_definitions( $params )
229-
{
230-
$r = array(
231-
'title' => array(
232-
'label' => T_('Block title'),
233-
'note' => T_('Title to display in your skin.'),
234-
'size' => 60,
235-
'defaultvalue' => '',
236-
),
237-
);
238-
return $r;
239-
}
240282
}
241283
?>

0 commit comments

Comments
 (0)