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 | |
---|
13 | if (!defined('DC_CONTEXT_ADMIN')){return;} |
---|
14 | |
---|
15 | require_once dirname(__FILE__).'/_widgets.php'; |
---|
16 | |
---|
17 | $_menu['Plugins']->addItem( |
---|
18 | __('Polls factory'), |
---|
19 | 'plugin.php?p=pollsFactory','index.php?pf=pollsFactory/icon.png', |
---|
20 | preg_match('/plugin.php\?p=pollsFactory(&.*)?$/',$_SERVER['REQUEST_URI']), |
---|
21 | $core->auth->check('admin',$core->blog->id) |
---|
22 | ); |
---|
23 | |
---|
24 | $core->addBehavior('adminPostNavLinks',array('adminPollsFactory','adminPostNavLinks')); |
---|
25 | $core->addBehavior('adminBeforePostDelete',array('adminPollsFactory','adminBeforePostDelete')); |
---|
26 | $core->addBehavior('adminPostsActionsCombo',array('adminPollsFactory','adminPostsActionsCombo')); |
---|
27 | $core->addBehavior('adminPostsActionsContent',array('adminPollsFactory','adminPostsActionsContent')); |
---|
28 | $core->addBehavior('adminPostsActions',array('adminPollsFactory','adminPostsActions')); |
---|
29 | |
---|
30 | class adminPollsFactory |
---|
31 | { |
---|
32 | public static function adminPostNavLinks($post) |
---|
33 | { |
---|
34 | global $core; |
---|
35 | |
---|
36 | if (!$core->blog->settings->pollsFactory_active |
---|
37 | || !$core->auth->check('admin',$core->blog->id) |
---|
38 | || $post === null ) return; |
---|
39 | |
---|
40 | $fact = new pollsFactory($core); |
---|
41 | $rs = $fact->getPolls(array('post_id'=>$post->post_id)); |
---|
42 | if ($rs->isEmpty()) { |
---|
43 | echo |
---|
44 | ' - <a title="'.__('add a poll to this entry').'" '. |
---|
45 | 'href="plugin.php?p=pollsFactory&tab=addpoll&post_id='. |
---|
46 | $post->post_id.'">'.__('add poll').'</a>'; |
---|
47 | } |
---|
48 | else { |
---|
49 | echo |
---|
50 | ' - <a title="'.__('edit poll linked to this entry').'" '. |
---|
51 | 'href="plugin.php?p=pollsFactory&tab=addpoll&post_id='. |
---|
52 | $post->post_id.'">'.__('edit poll').'</a>'; |
---|
53 | } |
---|
54 | } |
---|
55 | |
---|
56 | public static function adminBeforePostDelete($post_id) |
---|
57 | { |
---|
58 | global $core; |
---|
59 | |
---|
60 | if ($post_id === null || !$core->auth->check('admin',$core->blog->id)) return; |
---|
61 | |
---|
62 | $fact = new pollsFactory($core); |
---|
63 | $poll = $fact->getPolls(array('post_id'=>$post_id)); |
---|
64 | if ($poll->isEmpty()) return; |
---|
65 | |
---|
66 | libPollsFactory::deletePoll($fact,$poll->poll_id); |
---|
67 | } |
---|
68 | |
---|
69 | public static function adminPostsActionsCombo(&$args) |
---|
70 | { |
---|
71 | global $core; |
---|
72 | if (!$core->blog->settings->pollsFactory_active |
---|
73 | || !$core->auth->check('admin',$core->blog->id)) return; |
---|
74 | |
---|
75 | $args[0][__('Polls factory')][__('delete poll')] = 'delete_poll'; |
---|
76 | $args[0][__('Polls factory')][__('remove poll')] = 'remove_poll'; |
---|
77 | $args[0][__('Polls factory')][__('close poll')] = 'close_poll'; |
---|
78 | } |
---|
79 | |
---|
80 | public static function adminPostsActionsContent($core,$action,$hidden_fields) |
---|
81 | { |
---|
82 | if (!in_array($action,array('delete_poll','remove_poll','close_poll'))) return; |
---|
83 | |
---|
84 | try |
---|
85 | { |
---|
86 | foreach ($_POST['entries'] as $k => $v) { |
---|
87 | $entries[$k] = (integer) $v; |
---|
88 | } |
---|
89 | |
---|
90 | $params = array(); |
---|
91 | $params['sql'] = 'AND P.post_id '.$core->con->in($entries); |
---|
92 | $params['no_content'] = true; |
---|
93 | $params['poll_status'] = ''; |
---|
94 | |
---|
95 | $fact = new pollsFactory($core); |
---|
96 | $rs = $fact->getPolls($params); |
---|
97 | |
---|
98 | if ($action == 'delete_poll') { |
---|
99 | echo '<h2>'.__('delete polls related to selected entries').'</h2>'; |
---|
100 | } |
---|
101 | elseif ($action == 'close_poll') { |
---|
102 | echo '<h2>'.__('close polls related to selected entries').'</h2>'; |
---|
103 | } |
---|
104 | elseif ($action == 'remove_poll') { |
---|
105 | echo '<h2>'.__('remove polls related to selected entries').'</h2>'. |
---|
106 | '<p>'.__('This does not erase poll.').'</p>'; |
---|
107 | } |
---|
108 | |
---|
109 | if ($rs->isEmpty()) |
---|
110 | { |
---|
111 | echo '<p>'.__('There is no poll for selected entries').'</p>'; |
---|
112 | } |
---|
113 | else |
---|
114 | { |
---|
115 | echo |
---|
116 | '<form action="posts_actions.php" method="post"><ul>'; |
---|
117 | |
---|
118 | while($rs->fetch()) |
---|
119 | { |
---|
120 | echo |
---|
121 | '<li><label class="classic">'. |
---|
122 | form::checkbox(array('pollentries[]'),$rs->post_id,0).' '. |
---|
123 | $rs->post_title. |
---|
124 | '</label></li>'; |
---|
125 | } |
---|
126 | |
---|
127 | echo |
---|
128 | '</ul><p>'. |
---|
129 | $hidden_fields. |
---|
130 | $core->formNonce(). |
---|
131 | form::hidden(array('action'),$action). |
---|
132 | '<input type="submit" value="'.__('yes').'" /></p>'. |
---|
133 | '</form>'; |
---|
134 | } |
---|
135 | } |
---|
136 | catch (Exception $e) |
---|
137 | { |
---|
138 | $core->error->add($e->getMessage()); |
---|
139 | } |
---|
140 | } |
---|
141 | |
---|
142 | public static function adminPostsActions(&$core,$posts,$action,$redir) |
---|
143 | { |
---|
144 | if (!in_array($action,array('delete_poll','remove_poll','close_poll')) |
---|
145 | || empty($_POST['pollentries'])) return; |
---|
146 | |
---|
147 | try { |
---|
148 | $fact = new pollsFactory($core); |
---|
149 | |
---|
150 | while($posts->fetch()) |
---|
151 | { |
---|
152 | $rs = $fact->getPolls(array('post_id'=>$posts->post_id)); |
---|
153 | if (!$rs->isEmpty()) |
---|
154 | { |
---|
155 | if ($action == 'delete_poll') { |
---|
156 | libPollsFactory::deletePoll($fact,$rs->poll_id); |
---|
157 | } |
---|
158 | elseif ($action == 'close_poll') { |
---|
159 | libPollsFactory::closePoll($fact,$rs->poll_id); |
---|
160 | } |
---|
161 | elseif ($action == 'remove_poll') { |
---|
162 | libPollsFactory::uncompletePoll($fact,$rs->poll_id); |
---|
163 | } |
---|
164 | } |
---|
165 | } |
---|
166 | http::redirect($redir); |
---|
167 | } |
---|
168 | catch (Exception $e) { |
---|
169 | $core->error->add($e->getMessage()); |
---|
170 | } |
---|
171 | } |
---|
172 | } |
---|
173 | ?> |
---|