[10356] | 1 | <?php |
---|
| 2 | /* |
---|
| 3 | Plugin Name: Posted Date Changer |
---|
| 4 | Version: auto |
---|
| 5 | Description: Change the posted date of photos in batch manager. |
---|
| 6 | Plugin URI: http://piwigo.org/ext/extension_view.php?eid=528 |
---|
| 7 | Author: P@t |
---|
| 8 | Author URI: http://www.gauchon.com |
---|
| 9 | */ |
---|
| 10 | |
---|
| 11 | if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
---|
| 12 | |
---|
| 13 | add_event_handler('loc_end_element_set_global', 'change_posted_date'); |
---|
| 14 | add_event_handler('element_set_global_action', 'change_posted_date_action', 50, 2); |
---|
| 15 | |
---|
| 16 | function change_posted_date() |
---|
| 17 | { |
---|
| 18 | global $template; |
---|
| 19 | |
---|
| 20 | load_language('plugin.lang', dirname(__FILE__).'/'); |
---|
| 21 | |
---|
| 22 | $template->set_filename('change_posted_date', dirname(__FILE__).'/change_posted_date.tpl'); |
---|
| 23 | |
---|
| 24 | $day = empty($_POST['date_available_day']) ? date('j') : $_POST['date_available_day']; |
---|
| 25 | $month = empty($_POST['date_available_month']) ? date('n') : $_POST['date_available_month']; |
---|
| 26 | $year = empty($_POST['date_available_year']) ? date('Y') : $_POST['date_available_year']; |
---|
| 27 | |
---|
| 28 | $template->assign(array( |
---|
| 29 | 'DATE_AVAILABLE_DAY' => (int)$day, |
---|
| 30 | 'DATE_AVAILABLE_MONTH'=> (int)$month, |
---|
| 31 | 'DATE_AVAILABLE_YEAR' => (int)$year, |
---|
| 32 | ) |
---|
| 33 | ); |
---|
| 34 | |
---|
| 35 | $template->append('element_set_global_plugins_actions', array( |
---|
| 36 | 'ID' => 'date_available', |
---|
| 37 | 'NAME' => l10n('Change Posted Date'), |
---|
| 38 | 'CONTENT' => $template->parse('change_posted_date', true), |
---|
| 39 | ) |
---|
| 40 | ); |
---|
| 41 | } |
---|
| 42 | |
---|
| 43 | function change_posted_date_action($action, $collection) |
---|
| 44 | { |
---|
| 45 | if ($action == 'date_available') |
---|
| 46 | { |
---|
| 47 | $date_available = sprintf( |
---|
| 48 | '%u-%u-%u', |
---|
| 49 | $_POST['date_available_year'], |
---|
| 50 | $_POST['date_available_month'], |
---|
| 51 | $_POST['date_available_day'] |
---|
| 52 | ); |
---|
| 53 | |
---|
| 54 | $datas = array(); |
---|
| 55 | foreach ($collection as $image_id) |
---|
| 56 | { |
---|
| 57 | array_push( |
---|
| 58 | $datas, |
---|
| 59 | array( |
---|
| 60 | 'id' => $image_id, |
---|
| 61 | 'date_available' => $date_available |
---|
| 62 | ) |
---|
| 63 | ); |
---|
| 64 | } |
---|
| 65 | |
---|
| 66 | mass_updates( |
---|
| 67 | IMAGES_TABLE, |
---|
| 68 | array('primary' => array('id'), 'update' => array('date_available')), |
---|
| 69 | $datas |
---|
| 70 | ); |
---|
| 71 | } |
---|
| 72 | } |
---|
| 73 | |
---|
| 74 | ?> |
---|