source: extensions/photo_update/main.inc.php @ 16102

Last change on this file since 16102 was 11651, checked in by plg, 13 years ago

new plugin to update a photo (the JPEG/PNG file) from its administration screen

File size: 2.5 KB
Line 
1<?php
2/*
3Plugin Name: Photo Update
4Version: auto
5Description: Update a photo with a new file
6Plugin URI: http://piwigo.org/ext/extension_view.php?eid=
7Author: plg
8Author URI: http://piwigo.wordpress.com
9*/
10
11if (!defined('PHPWG_ROOT_PATH'))
12{
13  die('Hacking attempt!');
14}
15
16add_event_handler('loc_begin_admin', 'photo_update_add_form');
17function photo_update_add_form()
18{
19  global $template;
20
21  $template->set_prefilter('picture_modify', 'photo_update_add_form_prefilter');
22}
23
24function photo_update_add_form_prefilter($content, &$smarty)
25{
26  $search = '#<form id="associations"#';
27  $replacement = '
28<form id="photo_update" method="post" action="{$F_ACTION}" enctype="multipart/form-data">
29  <fieldset>
30    <legend>{\'Photo Update\'|@translate}</legend>
31
32    <p style="text-align:left" class="file"><input type="file" size="60" name="photo_update"></p>
33    <p style="text-align:left"><input class="submit" type="submit" value="{\'Update\'|@translate}" name="photo_update"></p>
34  </fieldset>
35</form>
36
37<form id="associations"
38';
39
40  return preg_replace($search, $replacement, $content);
41}
42
43add_event_handler('loc_begin_admin_page', 'photo_update_process_update');
44function photo_update_process_update()
45{
46  load_language('plugin.lang', PHPWG_PLUGINS_PATH.basename(dirname(__FILE__)).'/');
47 
48  global $page, $template;
49 
50  if (isset($_FILES['photo_update']))
51  {
52    include_once(PHPWG_ROOT_PATH.'admin/include/functions_upload.inc.php');
53   
54    if ($_FILES['photo_update']['error'] !== UPLOAD_ERR_OK)
55    {
56      $error_message = file_upload_error_message($_FILES['photo_update']['error']);
57
58      array_push(
59        $page['errors'],
60        $error_message
61        );
62    }
63    else
64    {
65      check_status(ACCESS_ADMINISTRATOR);
66      check_input_parameter('image_id', $_GET, false, PATTERN_ID);
67
68      add_uploaded_file(
69        $_FILES['photo_update']['tmp_name'],
70        $_FILES['photo_update']['name'],
71        null,
72        null,
73        $_GET['image_id']
74        );
75
76      $page['photo_update_refresh_thumbnail'] = true;
77
78      $template->set_prefilter('picture_modify', 'photo_update_force_thumbnail_refresh_prefilter');
79
80      $template->assign('REFRESH_KEY', time());
81     
82      array_push(
83        $page['infos'],
84        l10n('The photo was updated')
85        );
86    }
87  }
88}
89
90function photo_update_force_thumbnail_refresh_prefilter($content, &$smarty)
91{
92  $search = '#<img src="{\$TN_SRC}"#';
93  $replacement = '<img src="{$TN_SRC}?{$REFRESH_KEY}"';
94
95  return preg_replace($search, $replacement, $content);
96}
97?>
Note: See TracBrowser for help on using the repository browser.