~quam-plures-core/quam-plures/qp5_colls-blogs_chaps-cats

« back to all changes in this revision

Viewing changes to qp_inc/widgets/_single_item.widget.php

http://forums.quamplures.net/viewtopic.php?p=9237#p9237

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
/**
 
3
 * This file implements the "Single Item widget" widget
 
4
 *
 
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
 
8
 * @package widgets
 
9
 */
 
10
if( !defined('QP_MAIN_INIT') ) die( 'Please, do not access this page directly.' );
 
11
 
 
12
/**
 
13
 * single_item_Widget class
 
14
 * @package widgets
 
15
 */
 
16
class single_item_Widget extends ComponentWidget
 
17
{
 
18
        /**
 
19
         * Constructor
 
20
         */
 
21
        function single_item_Widget( $db_row = NULL )
 
22
        {
 
23
                // Call parent constructor
 
24
                parent::ComponentWidget( $db_row, 'widget', 'single_item' );
 
25
 
 
26
                $this->widget_name = T_('Single Item / Post');
 
27
                $this->widget_title = '';
 
28
        }
 
29
 
 
30
 
 
31
  /**
 
32
         * Get widget's short description
 
33
         */
 
34
        function get_desc()
 
35
        {
 
36
                return T_('Display a link to a single item');
 
37
        }
 
38
 
 
39
 
 
40
        /**
 
41
         * Get widget's title
 
42
         * @todo (3069): rename this to get_title()
 
43
         */
 
44
        function get_short_desc()
 
45
        {
 
46
                return format_to_output( $this->disp_params['widget_title'] );
 
47
        }
 
48
 
 
49
 
 
50
        /**
 
51
         * Get definitions for editable params
 
52
         *
 
53
         * @see Plugin::GetDefaultSettings()
 
54
         * @param local params like 'for_editing' => true
 
55
         */
 
56
        function get_param_definitions( $params )
 
57
        {
 
58
                $r = array_merge( array(
 
59
                                'item_ID' => array(
 
60
                                        'label' => T_('Item'),
 
61
                                        'note' => T_('ID of the post/item to link'),
 
62
                                        'size' => 4,
 
63
                                ),
 
64
                                'item_markup' => array(
 
65
                                        'label' => T_('Item markup'),
 
66
                                        'type' => 'select',
 
67
                                        'options' => array(
 
68
                                                'p' => 'P',
 
69
                                                'h1' => 'H1',
 
70
                                                'h2' => 'H2',
 
71
                                                'h3' => 'H3',
 
72
                                                'h4' => 'H4',
 
73
                                                'h5' => 'H5',
 
74
                                                'h6' => 'H6',
 
75
                                                'none' => T_('none'),
 
76
                                        ),
 
77
                                        'note' => T_('HTML markup for the item title'),
 
78
                                        'defaultvalue' => 'h3',
 
79
                                ),
 
80
                                'link_text' => array(
 
81
                                        'label' => T_('Link text'),
 
82
                                        'note' => T_('leave blank for item\'s title'),
 
83
                                        'defaultvalue' => '',
 
84
                                ),
 
85
                                'link_title' => array(
 
86
                                        'label' => T_('Link title'),
 
87
                                        'defaultvalue' => T_('this is a link to an important article'),
 
88
                                ),
 
89
                                'show_excerpt' => array(
 
90
                                        'type' => 'checkbox',
 
91
                                        'label' => T_('Show excerpt'),
 
92
                                        'defaultvalue' => 0,
 
93
                                        'note' => T_('check to display an excerpt of the item'),
 
94
                                ),
 
95
                                'excerpt_markup' => array(
 
96
                                        'label' => T_('Excerpt markup'),
 
97
                                        'type' => 'select',
 
98
                                        'options' => array(
 
99
                                                'p' => 'P',
 
100
                                                'h1' => 'H1',
 
101
                                                'h2' => 'H2',
 
102
                                                'h3' => 'H3',
 
103
                                                'h4' => 'H4',
 
104
                                                'h5' => 'H5',
 
105
                                                'h6' => 'H6',
 
106
                                                'none' => T_('none'),
 
107
                                        ),
 
108
                                        'note' => T_('HTML markup for the item excerpt'),
 
109
                                        'defaultvalue' => 'default',
 
110
                                ),
 
111
                        ), parent::get_param_definitions( $params ) );
 
112
 
 
113
                return $r;
 
114
        }
 
115
 
 
116
 
 
117
        /**
 
118
         * Display the widget!
 
119
         *
 
120
         * @param array MUST contain at least the basic display params
 
121
         */
 
122
        function display( $params )
 
123
        {
 
124
                $this->init_display( $params );
 
125
 
 
126
                if( $this->disp_params['item_ID'] == '' )
 
127
                {
 
128
                        return;
 
129
                }
 
130
 
 
131
                $ItemCache = & get_Cache( 'ItemCache' );
 
132
                $Item = & $ItemCache->get_by_ID( $this->disp_params['item_ID'], false );
 
133
 
 
134
                // are we using a different text?
 
135
                $text = $Item->title;
 
136
                if( $this->disp_params['link_text'] != '' )
 
137
                {
 
138
                        $text = $this->disp_params['link_text'];
 
139
                }
 
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>';
 
142
                $pre_text = '';
 
143
                $post_text = '';
 
144
                if( $this->disp_params['item_markup'] != 'none' )
 
145
                {
 
146
                        $pre_text = '<'.$this->disp_params['item_markup'].'>';
 
147
                        $post_text = '</'.$this->disp_params['item_markup'].'>';
 
148
                }
 
149
 
 
150
                // start the output process...
 
151
                echo $this->disp_params['block_start'];
 
152
                // display a title if we have one
 
153
                $this->disp_title();
 
154
                // display the linked item
 
155
                echo $pre_text.$linked_text.$post_text;
 
156
 
 
157
                // now for the excerpt, if desired
 
158
                if( $this->disp_params['show_excerpt'] )
 
159
                {
 
160
                        $pre_excerpt = '';
 
161
                        $post_excerpt = '';
 
162
                        if( $this->disp_params['excerpt_markup'] != 'none' )
 
163
                        {
 
164
                                $pre_excerpt = '<'.$this->disp_params['excerpt_markup'].'>';
 
165
                                $post_excerpt = '</'.$this->disp_params['excerpt_markup'].'>';
 
166
                        }
 
167
                        echo $pre_excerpt.$Item->excerpt.$post_excerpt;
 
168
                }
 
169
 
 
170
                // close the block
 
171
                echo $this->disp_params['block_end'];
 
172
        }
 
173
 
 
174
}
 
175
 
 
176
?>