3
* This file implements the "Single Item widget" widget
5
* @author {@link http://wonderwinds.com/ Ed Bennett}
6
* @copyright (c) 2013 by {@link http://quamplures.net/ the Quam Plures project}
7
* @license http://www.gnu.org/licenses/gpl.txt GNU General Public License v3
10
if( !defined('QP_MAIN_INIT') ) die( 'Please, do not access this page directly.' );
13
* single_item_Widget class
16
class single_item_Widget extends ComponentWidget
21
function single_item_Widget( $db_row = NULL )
23
// Call parent constructor
24
parent::ComponentWidget( $db_row, 'widget', 'single_item' );
26
$this->widget_name = T_('Single Item / Post');
27
$this->widget_title = '';
32
* Get widget's short description
36
return T_('Display a link to a single item');
42
* @todo (3069): rename this to get_title()
44
function get_short_desc()
46
return format_to_output( $this->disp_params['widget_title'] );
51
* Get definitions for editable params
53
* @see Plugin::GetDefaultSettings()
54
* @param local params like 'for_editing' => true
56
function get_param_definitions( $params )
58
$r = array_merge( array(
60
'label' => T_('Item'),
61
'note' => T_('ID of the post/item to link'),
64
'item_markup' => array(
65
'label' => T_('Item markup'),
77
'note' => T_('HTML markup for the item title'),
78
'defaultvalue' => 'h3',
81
'label' => T_('Link text'),
82
'note' => T_('leave blank for item\'s title'),
85
'link_title' => array(
86
'label' => T_('Link title'),
87
'defaultvalue' => T_('this is a link to an important article'),
89
'show_excerpt' => array(
91
'label' => T_('Show excerpt'),
93
'note' => T_('check to display an excerpt of the item'),
95
'excerpt_markup' => array(
96
'label' => T_('Excerpt markup'),
106
'none' => T_('none'),
108
'note' => T_('HTML markup for the item excerpt'),
109
'defaultvalue' => 'default',
111
), parent::get_param_definitions( $params ) );
118
* Display the widget!
120
* @param array MUST contain at least the basic display params
122
function display( $params )
124
$this->init_display( $params );
126
if( $this->disp_params['item_ID'] == '' )
131
$ItemCache = & get_Cache( 'ItemCache' );
132
$Item = & $ItemCache->get_by_ID( $this->disp_params['item_ID'], false );
134
// are we using a different text?
135
$text = $Item->title;
136
if( $this->disp_params['link_text'] != '' )
138
$text = $this->disp_params['link_text'];
140
// create a link even though it ain't done
141
$linked_text = '<a href="'.$Item->get_permanent_url().'" title="'.$this->disp_params['link_title'].'">'.$text.'</a>';
144
if( $this->disp_params['item_markup'] != 'none' )
146
$pre_text = '<'.$this->disp_params['item_markup'].'>';
147
$post_text = '</'.$this->disp_params['item_markup'].'>';
150
// start the output process...
151
echo $this->disp_params['block_start'];
152
// display a title if we have one
154
// display the linked item
155
echo $pre_text.$linked_text.$post_text;
157
// now for the excerpt, if desired
158
if( $this->disp_params['show_excerpt'] )
162
if( $this->disp_params['excerpt_markup'] != 'none' )
164
$pre_excerpt = '<'.$this->disp_params['excerpt_markup'].'>';
165
$post_excerpt = '</'.$this->disp_params['excerpt_markup'].'>';
167
echo $pre_excerpt.$Item->excerpt.$post_excerpt;
171
echo $this->disp_params['block_end'];