Dotclear

Ticket #700: items_actions.php

File items_actions.php, 11.3 KB (added by jojojr, 12 years ago)
Line 
1<?php
2# -- BEGIN LICENSE BLOCK ----------------------------------
3#
4# This file is part of Dotclear 2 Gallery plugin.
5#
6# Copyright (c) 2004-2008 Bruno Hondelatte, and contributors.
7# Many, many thanks to Olivier Meunier and the Dotclear Team.
8# Licensed under the GPL version 2.0 license.
9# See LICENSE file or
10# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
11#
12# -- END LICENSE BLOCK ------------------------------------
13
14if (!defined('DC_CONTEXT_ADMIN')) { exit; }
15$core->meta=new dcMeta($core);
16
17/* Actions
18-------------------------------------------------------- */
19if (!empty($_POST['action']) && !empty($_POST['entries']))
20{
21     $entries = $_POST['entries'];
22     $action = $_POST['action'];
23     
24     if (isset($_POST['redir']) && strpos($_POST['redir'],'://') === false)
25     {
26          $redir = $_POST['redir'];
27     }
28     else
29     {
30          $redir =
31          'plugin.php?p=gallery&m=items&user_id='.$_POST['user_id'].
32          '&cat_id='.$_POST['cat_id'].
33          '&status='.$_POST['status'].
34          '&selected='.$_POST['selected'].
35          '&month='.$_POST['month'].
36          '&lang='.$_POST['lang'].
37          '&sortby='.$_POST['sortby'].
38          '&order='.$_POST['order'].
39          '&gal_id='.$_POST['gal_id'].
40          '&media_dir='.$_POST['media_dir'].
41          '&tag='.$_POST['tag'].
42          '&page='.$_POST['page'].
43          '&nb='.$_POST['nb'];
44     }
45     
46     foreach ($entries as $k => $v) {
47          $entries[$k] = (integer) $v;
48     }
49     
50     $params['sql'] = 'AND P.post_id IN('.implode(',',$entries).') ';
51     $params['no_content'] = true;
52     
53     $posts = $core->gallery->getGalItems($params);
54     
55     if (preg_match('/^(publish|unpublish|schedule|pending)$/',$action))
56     {
57          switch ($action) {
58               case 'unpublish' : $status = 0; break;
59               case 'schedule' : $status = -1; break;
60               case 'pending' : $status = -2; break;
61               default : $status = 1; break;
62          }
63         
64          try
65          {
66               while ($posts->fetch()) {
67                    $core->blog->updPostStatus($posts->post_id,$status);
68               }
69               
70               http::redirect($redir);
71          }
72          catch (Exception $e)
73          {
74               $core->error->add($e->getMessage());
75          }
76     }
77     elseif ($action == 'selected' || $action == 'unselected')
78     {
79          try
80          {
81               while ($posts->fetch()) {
82                    $core->blog->updPostSelected($posts->post_id,$action == 'selected');
83               }
84               
85               http::redirect($redir);
86          }
87          catch (Exception $e)
88          {
89               $core->error->add($e->getMessage());
90          }
91     }
92     elseif ($action == 'removeimgpost')
93     {
94          try
95          {
96               while ($posts->fetch()) {
97                    $core->blog->delPost($posts->post_id);
98               }
99               
100               http::redirect($redir);
101          }
102          catch (Exception $e)
103          {
104               $core->error->add($e->getMessage());
105          }
106         
107     }
108     elseif ($action == 'category' && isset($_POST['new_cat_id']))
109     {
110          try
111          {
112               while ($posts->fetch())
113               {
114                    $new_cat_id = (integer) $_POST['new_cat_id'];
115                    $core->blog->updPostCategory($posts->post_id,$new_cat_id);
116               }
117               http::redirect($redir);
118          }
119          catch (Exception $e)
120          {
121               $core->error->add($e->getMessage());
122          }
123     }
124     elseif ($action == 'author' && isset($_POST['new_auth_id'])
125     && $core->auth->check('admin',$core->blog->id))
126     {
127          $new_user_id = $_POST['new_auth_id'];
128         
129          try
130          {
131               if ($core->getUser($new_user_id)->isEmpty()) {
132                    throw new Exception(__('This user does not exist'));
133               }
134               
135               while ($posts->fetch())
136               {
137                    $cur = $core->con->openCursor($core->prefix.'post');
138                    $cur->user_id = $new_user_id;
139                    $cur->update('WHERE post_id = '.(integer) $posts->post_id);
140               }
141               
142               http::redirect($redir);
143          }
144          catch (Exception $e)
145          {
146               $core->error->add($e->getMessage());
147          }
148     }
149     elseif ($action == 'tags' && !empty($_POST['new_tags']))
150     {
151          try
152          {
153               $meta = new dcMeta($core);
154               $tags = $meta->splitMetaValues($_POST['new_tags']);
155               
156               while ($posts->fetch())
157               {
158                    # Get tags for post
159                    $pm = array();
160                $post_tags = $meta->getMetadata(array(
161                    'meta_type' => 'tag',
162                    'post_id' => (integer) $posts->post_id))->toStatic()->rows();
163                foreach ($post_tags as $key => $v) {
164                    $pm [] = $v['meta_id'];
165                }       
166                   
167                foreach ($tags as $t) {
168                    if (!in_array($t,$pm)) {
169                        $meta->setPostMeta($posts->post_id,'tag',$t);
170                    }
171                }
172            }
173               
174            http::redirect($redir);
175          }
176          catch (Exception $e)
177          {
178               $core->error->add($e->getMessage());
179          }
180     }
181    elseif ($action == 'tags_remove' && !empty($_POST['meta_id']) 
182        && $core->auth->check('delete,contentadmin',$core->blog->id)) {
183        try {
184            $meta =& $GLOBALS['core']->meta;
185            while ($posts->fetch()) {
186                foreach ($_POST['meta_id'] as $v) {
187                    $meta->delPostMeta($posts->post_id,'tag',$v);
188                }
189            }   
190            http::redirect($redir);
191        }
192        catch (Exception $e) {
193            $core->error->add($e->getMessage());
194        }
195    }
196}
197/* DISPLAY
198-------------------------------------------------------- */
199if (!isset($action)) {
200     exit;
201}
202$max_ajax_requests = (int) $core->gallery->settings->gallery_max_ajax_requests;
203if ($max_ajax_requests == 0)
204     $max_ajax_requests=5;
205
206?>
207<html>
208<head>
209  <title><?php echo __('Entries'); ?></title>
210  <?php
211     if ($action == 'fixexif' || $action == "missingthumbs") {
212        echo '<script type="text/javascript">'."\n".
213               "//<![CDATA[\n".
214                    "dotclear.maxajaxrequests = ".$max_ajax_requests.";\n".
215               "\n//]]>\n".
216               "</script>\n".
217               dcPage::jsLoad('index.php?pf=gallery/js/jquery.ajaxmanager.js').
218               dcPage::jsLoad('index.php?pf=gallery/js/_ajax_tools.js').
219               dcPage::jsLoad('index.php?pf=gallery/js/_items_actions.js').
220               dcPage::jsPageTabs("new_items");
221          echo 
222          '<script type="text/javascript">'."\n".
223          "//<![CDATA[\n".
224          "dotclear.maxajaxrequests = ".$max_ajax_requests.";\n".
225          "var imgs = [".implode(',',$entries)."];\n".
226          "dotclear.msg.please_wait = '".html::escapeJS(__('Waiting...'))."';\n".
227          "dotclear.msg.update_exif = '".html::escapeJS(__('updating date to media exif'))."';\n".
228          "\n//]]>\n".
229          "</script>\n";
230     }
231  ?>
232</head>
233<body>
234
235<h2><?php echo html::escapeHTML($core->blog->name); ?> &gt;
236<?php
237$hidden_fields = '';
238while ($posts->fetch()) {
239     $hidden_fields .= form::hidden(array('entries[]'),$posts->post_id);
240}
241
242if (isset($_POST['redir']) && strpos($_POST['redir'],'://') === false)
243{
244     $hidden_fields .= form::hidden(array('redir'),$_POST['redir']);
245}
246else
247{
248     $hidden_fields .=
249     form::hidden(array('user_id'),$_POST['user_id']).
250     form::hidden(array('cat_id'),$_POST['cat_id']).
251     form::hidden(array('status'),$_POST['status']).
252     form::hidden(array('selected'),$_POST['selected']).
253     form::hidden(array('month'),$_POST['month']).
254     form::hidden(array('lang'),$_POST['lang']).
255     form::hidden(array('sortby'),$_POST['sortby']).
256     form::hidden(array('order'),$_POST['order']).
257     form::hidden(array('gal_id'),$_POST['gal_id']).
258     form::hidden(array('media_dir'),$_POST['media_dir']).
259     form::hidden(array('tag'),$_POST['tag']).
260     form::hidden(array('page'),$_POST['page']).
261     form::hidden(array('nb'),$_POST['nb']);
262}
263
264
265if ($action == 'category')
266{
267     echo __('Change category for entries').'</h2>';
268     
269     # categories list
270     # Getting categories
271     $categories_combo = array('&nbsp;' => '');
272     try {
273          $categories = $core->blog->getCategories();
274          while ($categories->fetch()) {
275               $categories_combo[str_repeat('&nbsp;&nbsp;',$categories->level-1).'&bull;'.html::escapeHTML($categories->cat_title)] = $categories->cat_id;
276          }
277     } catch (Exception $e) { }
278     
279     echo
280     '<form action="plugin.php?p=gallery&amp;m=itemsactions" method="post">'.
281     '<p><label class="classic">'.__('Category:').' '.
282     form::combo('new_cat_id',$categories_combo,'').
283     '</label> ';
284     
285     echo
286     $core->formNonce().
287     $hidden_fields.
288     form::hidden(array('action'),'category').
289     '<input type="submit" value="'.__('save').'" /></p>'.
290     '</form>';
291}
292elseif ($action == 'author' && $core->auth->check('admin',$core->blog->id))
293{
294     echo __('Change author for entries').'</h2>';
295     
296     echo
297     '<form action="plugin.php?p=gallery&amp;m=itemsactions" method="post">'.
298     '<p><label class="classic">'.__('Author ID:').' '.
299     form::field('new_auth_id',20,255).
300     '</label> ';
301     
302     echo
303     $core->formNonce().
304     $hidden_fields.
305     form::hidden(array('action'),'author').
306     '<input type="submit" value="'.__('save').'" /></p>'.
307     '</form>';
308}
309elseif ($action == 'tags')
310{
311     echo
312     '<h2>'.__('Add tags to entries').'</h2>'.
313     '<form action="plugin.php?p=gallery&amp;m=itemsactions" method="post">'.
314     '<p><label class="area">'.__('Tags to add:').' '.
315     form::textarea('new_tags',60,3).
316     '</label> '.
317     
318     $core->formNonce().
319     $hidden_fields.
320     form::hidden(array('action'),'tags').
321     '<input type="submit" value="'.__('save').'" /></p>'.
322     '</form>';
323}
324elseif ($action == 'tags_remove') {
325    $meta =& $GLOBALS['core']->meta;
326    $tags = array();
327    foreach ($_POST['entries'] as $id) {
328        $post_tags = $meta->getMetadata(array(
329            'meta_type' => 'tag',
330            'post_id' => (integer) $id))->toStatic()->rows();
331        foreach ($post_tags as $v) {
332            if (isset($tags[$v['meta_id']])) {
333                $tags[$v['meta_id']]++;
334            } else {
335                $tags[$v['meta_id']] = 1;
336            }
337        }
338    }
339    echo '<h2>'.__('Remove selected tags from entries').'</h2>';           
340    if (empty($tags)) {
341        echo '<p>'.__('No tags for selected entries').'</p>';
342        return;
343    }
344    $posts_count = count($_POST['entries']); 
345    echo 
346        '<form action="plugin.php?p=gallery&amp;m=itemsactions" method="post">'.
347        '<fieldset><legend>'.__('Following tags have been found in selected entries:').'</legend>';
348   
349    foreach ($tags as $k => $n) {
350        $label = '<label class="classic">%s %s</label>';
351        if ($posts_count == $n) {
352            $label = sprintf($label,'%s','<strong>%s</strong>');
353        }
354        echo '<p>'.sprintf($label,
355            form::checkbox(array('meta_id[]'),html::escapeHTML($k)),
356            html::escapeHTML($k)).
357            '</p>';
358    }
359    echo
360        '<p><input type="submit" value="'.__('ok').'" /></p>'.
361        $hidden_fields.
362        $core->formNonce().
363        form::hidden(array('action'),'tags_remove').
364        '</fieldset></form>';
365    }
366
367elseif ($action == 'fixexif')
368{
369
370     echo __('Fix images date').'</h2>';
371     echo '<fieldset><legend>'.__('Processing result').'</legend>';
372     echo '<p><input type="button" id="abort" value="'.__('Abort processing').'" /></p>';
373     echo '<h3>'.__('Actions').'</h3>';
374     echo '<table id="resulttable"><tr class="keepme"><th>'.__('Request').'</th><th>'.__('Result').'</th></tr></table>';
375     echo '</fieldset>';
376     echo '<script type="text/javascript">'."\n".
377          '$(document).ready(function(){'.
378          ' fix_exif(imgs);'.
379          '});'.
380          '</script>';
381
382}
383elseif ($action == 'missingthumbs') {
384     $mediars = $core->gallery->getMediaForGalItems($entries);
385     $mediaids = array();
386     while ($mediars->fetch()) {
387          $mediaids[] = "'".$mediars->post_id."':'".$mediars->media_id."'";
388     }
389     echo __('Generating missing thumbs').'</h2>';
390     echo '<fieldset><legend>'.__('Processing result').'</legend>';
391     echo '<p><input type="button" id="abort" value="'.__('Abort processing').'" /></p>';
392     echo '<h3>'.__('Actions').'</h3>';
393     echo '<table id="resulttable"><tr class="keepme"><th>'.__('Request').'</th><th>'.__('Result').'</th></tr></table>';
394     echo '</fieldset>';
395     echo
396          '<script type="text/javascript">'."\n".
397          "//<![CDATA[\n".
398          "var media = {".implode(',',$mediaids)."};\n".
399          "\n//]]>\n".
400          '$(document).ready(function(){'.
401          ' regenerate_thumbs(media);'.
402          '});'.
403          '</script>';
404
405          "</script>\n";
406
407}
408echo '<p><a href="'.str_replace('&','&amp;',$redir).'">'.__('back').'</a></p>';
409
410
411
412
413
414?>
415</body>
416</html>

Sites map