Dotclear

source: plugins/pollsFactory/_widgets.php @ 2139

Revision 2139, 5.6 KB checked in by JcDenis, 14 years ago (diff)

pollsFactory 1.0:

  • Rewrited plugin
Line 
1<?php
2# -- BEGIN LICENSE BLOCK ----------------------------------
3# This file is part of pollsFactory, a plugin for Dotclear 2.
4#
5# Copyright (c) 2009-2010 JC Denis and contributors
6# jcdenis@gdwd.com
7#
8# Licensed under the GPL version 2.0 license.
9# A copy of this license is available in LICENSE file or at
10# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
11# -- END LICENSE BLOCK ------------------------------------
12
13if (!defined('DC_RC_PATH')){return;}
14
15# List of polls
16$core->addBehavior('initWidgets',array('widgetPollsFactory','adminPollsList'));
17# Selected polls
18$core->addBehavior('initWidgets',array('widgetPollsFactory','adminPollsSelected'));
19# Polls linked to an entry
20$core->addBehavior('initWidgets',array('widgetPollsFactory','adminPollsPost'));
21
22class widgetPollsFactory
23{
24     public static function adminPollsList($w)
25     {
26          $w->create('pollfactlist',
27               __('Polls list'),
28               array('widgetPollsFactory','publicPollsList')
29          );
30          # Title
31          $w->pollfactlist->setting('title',
32               __('Title:'),__('Polls list'),'text'
33          );
34          # Limit
35          $w->pollfactlist->setting('limit',
36               __('Polls limit:'),10,'text'
37          );
38          # Sort type
39          $w->pollfactlist->setting('sortby',
40               __('Order by:'),'poll_strdt','combo',
41               array(
42                    __('Date') => 'post_dt',
43                    __('Title') => 'post_title'
44               )
45          );
46          # Sort order
47          $w->pollfactlist->setting('sort',
48               __('Sort:'),'desc','combo',
49               array(
50                    __('Ascending') => 'asc',
51                    __('Descending') => 'desc'
52               )
53          );
54          # Period
55          $w->pollfactlist->setting('period',
56               __('Vote:'),'desc','combo',
57               array(
58                    __('All') => '-',
59                    __('Opened') => 'opened',
60                    __('Closed') => 'closed'
61               )
62          );
63          # Home only
64          $w->pollfactlist->setting('homeonly',
65               __('Home page only'),1,'check'
66          );
67     }
68
69     public static function adminPollsPost($w)
70     {
71          $w->create('pollfactpost',
72               __('Polls of an entry'),
73               array('widgetPollsFactory','publicPollsPost')
74          );
75          $w->pollfactpost->setting('title',
76               __('Title:'),__('Related polls'),'text'
77          );
78          $w->pollfactpost->setting('showdesc',
79               __('Show description'),0,'check'
80          );
81          $w->pollfactpost->setting('usegraph',
82               __('Use graphic results'),0,'check'
83          );
84     }
85
86     public static function adminPollsSelected($w)
87     {
88          $w->create('pollfactselected',
89               __('Selected polls'),
90               array('widgetPollsFactory','publicPollsSelected')
91          );
92          $w->pollfactselected->setting('title',
93               __('Title:'),__('Selected polls'),'text'
94          );
95          $w->pollfactselected->setting('limit',
96               __('Polls limit:'),1,'text'
97          );
98          $w->pollfactselected->setting('showdesc',
99               __('Show description'),0,'check'
100          );
101          $w->pollfactselected->setting('usegraph',
102               __('Use graphic results'),0,'check'
103          );
104          $w->pollfactselected->setting('homeonly',
105               __('Home page only'),1,'check'
106          );
107     }
108
109     public static function publicPollsList($w)
110     {
111          global $core; 
112
113          if (!$core->blog->settings->pollsFactory_active 
114           || $w->homeonly && $core->url->type != 'default') return;
115
116          $params = array(
117               'post_type' => 'pollsfactory',
118               'no_content' => true,
119               'sql' => ''
120          );
121          # order
122          $params['order'] = in_array($w->sortby,array('post_dt','post_title')) ?
123               $w->sortby : 'post_dt ';
124          $params['order'] .= $w->sort == 'asc' ? ' asc' : ' desc';
125          # limit
126          $params['limit'] = abs((integer) $w->limit);
127          # period
128          if ($w->period == 'opened') {
129               $params['sql'] .= 'AND post_open_tb = 1 ';
130          }
131          elseif ($w->period == 'closed') {
132               $params['sql'] .= 'AND post_open_tb = 0 ';
133          }
134
135          $polls = $core->blog->getPosts($params);
136
137          if ($polls->isEmpty()) return;
138
139          $res = '';
140          while($polls->fetch())
141          {
142               $res .= '<li><a href="'.$core->blog->url.$core->url->getBase('pollsFactoryPage').'/'.$polls->post_url.'">'.html::escapeHTML($polls->post_title).'</a></li>';
143          }
144          return 
145          '<div class="pollsfactory pollsselected-widget">'.
146          ($w->title ? '<h2>'.$w->title.'</h2>' : '').
147          '<ul>'.$res.'</ul>'.
148          '</div>';
149     }
150
151     public static function publicPollsPost($w)
152     {
153          global $core, $_ctx; 
154
155          if (!$core->blog->settings->pollsFactory_active 
156           || !$_ctx->exists('posts')) return;
157
158
159          $params['option_type'] = 'pollspost';
160          $params['post_id'] = $_ctx->posts->post_id;
161
162          $obj = new pollsfactory($core);
163          $rs = $obj->getOptions($params);
164
165          if ($rs->isEmpty()) return;
166
167          $res = '';
168          while($rs->fetch())
169          {
170               $res .= publicPollsFactoryForm($core,$rs->option_meta,true,$w->showdesc,$w->usegraph);
171          }
172          return 
173          '<div class="pollsfactory pollspost-widget">'.
174          ($w->title ? '<h2>'.$w->title.'</h2>' : '').
175          $res.
176          '</div>';
177     }
178
179     public static function publicPollsSelected($w)
180     {
181          global $core; 
182
183          if (!$core->blog->settings->pollsFactory_active 
184           || $w->homeonly && $core->url->type != 'default') return;
185
186          $params['no_content'] = true;
187          $params['post_type'] = 'pollsfactory';
188          $params['post_selected'] = 1;
189          $params['limit'] = abs((integer) $w->limit);
190          $params['order'] = 'post_dt ASC ';
191          $params['from'] = $core->con->driver() == 'pgsql' ? // postgresql cast compatibility
192                'LEFT JOIN '.$core->prefix.'post_option O ON P.post_id = O.option_meta::bigint ' :
193                'LEFT JOIN '.$core->prefix.'post_option O ON O.option_meta = P.post_id ';
194          $params['sql'] = "AND O.option_type = 'pollspost' ";
195
196          $rs = $core->blog->getPosts($params);
197
198          if ($rs->isEmpty()) return;
199
200          $res = '';
201          while($rs->fetch())
202          {
203               $res .= publicPollsFactoryForm($core,$rs->post_id,true,$w->showdesc,$w->usegraph);
204          }
205          return 
206          '<div class="pollsfactory pollsselected-widget">'.
207          ($w->title ? '<h2>'.$w->title.'</h2>' : '').
208          $res.
209          '</div>';
210     }
211}
212?>
Note: See TracBrowser for help on using the repository browser.

Sites map