Enable Media Replace - Version 2.3

Version Description

  • Lots of code trimmed and enhanced, thanks to Ben ter Stal! Now working properly with Windows systems, better security, optimized loading, and much more.
  • Added Dutch translation by Ben ter Stal.
Download this release

Release Info

Developer MungoBBQ
Plugin Icon 128x128 Enable Media Replace
Version 2.3
Comparing to
See all releases

Code changes from version 2.2 to 2.3

emr-list.png DELETED
Binary file
emr-preview.png DELETED
Binary file
enable-media-replace-nl_NL.mo ADDED
Binary file
enable-media-replace-nl_NL.po ADDED
@@ -0,0 +1,89 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ msgid ""
2
+ msgstr ""
3
+ "Project-Id-Version: enable-media-replace\n"
4
+ "Report-Msgid-Bugs-To: \n"
5
+ "POT-Creation-Date: 2010-09-10 20:53+0100\n"
6
+ "PO-Revision-Date: \n"
7
+ "Last-Translator: WarmStal D!sign | Ben ter Stal <mail@warmstal.nl>\n"
8
+ "Language-Team: \n"
9
+ "MIME-Version: 1.0\n"
10
+ "Content-Type: text/plain; charset=UTF-8\n"
11
+ "Content-Transfer-Encoding: 8bit\n"
12
+ "X-Poedit-KeywordsList: __;_e\n"
13
+ "X-Poedit-Basepath: .\n"
14
+ "X-Poedit-SearchPath-0: .\n"
15
+
16
+ #: enable-media-replace.php:26
17
+ #: enable-media-replace.php:45
18
+ msgid "Replace media"
19
+ msgstr "Vervangen media"
20
+
21
+ #: enable-media-replace.php:45
22
+ msgid "Upload a new file"
23
+ msgstr "Uploaden nieuw bestand"
24
+
25
+ #: enable-media-replace.php:45
26
+ msgid "To replace the current file, click the link and upload a replacement."
27
+ msgstr "Klik om het bestaande bestand te vervangen door een nieuw te uploaden bestand."
28
+
29
+ #: popup.php:7
30
+ #: upload.php:10
31
+ msgid "You do not have permission to upload files."
32
+ msgstr "U heeft geen rechten om bestanden te uplaoden"
33
+
34
+ #: popup.php:23
35
+ msgid "Replace Media Upload"
36
+ msgstr "Replace Media Upload"
37
+
38
+ #: popup.php:34
39
+ msgid "NOTE: You are about to replace the media file"
40
+ msgstr "Opmerking: U staat op het punt het media bestand"
41
+
42
+ #: popup.php:34
43
+ msgid "There is no undo. Think about it!"
44
+ msgstr "Deze bewerking kan niet ongedaan worden gemaakt!"
45
+
46
+ #: popup.php:36
47
+ msgid "Choose a file to upload from your computer"
48
+ msgstr "Selecteer een bestand op de PC om te uploaden"
49
+
50
+ #: popup.php:40
51
+ msgid "Select media replacement type:"
52
+ msgstr "Selecteer de wijze van vervanging"
53
+
54
+ #: popup.php:42
55
+ msgid "Just replace the file"
56
+ msgstr "Vervang alleen het bestand"
57
+
58
+ #: popup.php:43
59
+ msgid "Note: This option requires you to upload a file of the same type ("
60
+ msgstr "Opmerking: voor deze optie moet u een bestand van hetzelfde type uploaden ("
61
+
62
+ #: popup.php:43
63
+ msgid ") as the one you are replacing. The name of the attachment will stay the same ("
64
+ msgstr ") De naam in de media bibliotheek blijft hetzelfde ("
65
+
66
+ #: popup.php:43
67
+ msgid ") no matter what the file you upload is called."
68
+ msgstr ") onafhankelijk van de naam van het nieuwe bestand."
69
+
70
+ #: popup.php:45
71
+ msgid "Replace the file, use new file name and update all links"
72
+ msgstr "Vervang het bestand, gebruik de nieuwe naam en werk alle links bij."
73
+
74
+ #: popup.php:46
75
+ msgid "Note: If you check this option, the name and type of the file you are about to upload will replace the old file. All links pointing to the current file ("
76
+ msgstr "Opmerking: bij deze keuze wordt het bestand volledig vervangen. Alle links naar het huidige bestand ("
77
+
78
+ #: popup.php:46
79
+ msgid ") will be updated to point to the new file name."
80
+ msgstr ") worden bijgewerkt naar het nieuwe bestand."
81
+
82
+ #: popup.php:48
83
+ msgid "Upload"
84
+ msgstr "Uploaden"
85
+
86
+ #: popup.php:48
87
+ msgid "Cancel"
88
+ msgstr "Annuleren"
89
+
enable-media-replace-ru_RU.mo CHANGED
Binary file
enable-media-replace-ru_RU.po CHANGED
@@ -2,9 +2,9 @@ msgid ""
2
  msgstr ""
3
  "Project-Id-Version: enable-media-replace\n"
4
  "Report-Msgid-Bugs-To: \n"
5
- "POT-Creation-Date: 2009-05-29 13:49+0100\n"
6
  "PO-Revision-Date: \n"
7
- "Last-Translator: Fat Cow <zhr@tut.by>\n"
8
  "Language-Team: <zhr@tut.by>\n"
9
  "MIME-Version: 1.0\n"
10
  "Content-Type: text/plain; charset=UTF-8\n"
@@ -16,83 +16,79 @@ msgstr ""
16
  "X-Poedit-SourceCharset: utf-8\n"
17
  "X-Poedit-SearchPath-0: .\n"
18
 
19
- #: enable-media-replace.php:27
20
- #: enable-media-replace_sv_SE.php:27
21
  msgid "Replace media"
22
  msgstr "Заменить медиа"
23
 
24
- #: enable-media-replace.php:27
25
- #: enable-media-replace_sv_SE.php:27
26
  msgid "Upload a new file"
27
  msgstr "Загрузить новый файл"
28
 
29
- #: enable-media-replace.php:27
30
- #: enable-media-replace_sv_SE.php:27
31
  msgid "To replace the current file, click the link and upload a replacement."
32
  msgstr "Для того, чтобы заменить текущий файл, нажмите на ссылку и загрузите замену. "
33
 
34
- #: popup.php:9
35
- #: upload.php:9
36
  msgid "You do not have permission to upload files."
37
  msgstr "У вас нет прав для загрузки файлов. "
38
 
39
- #: popup.php:26
40
- msgid "Replace media upload"
41
- msgstr "Загрузить замену"
42
-
43
- #: popup.php:36
44
  msgid "Replace Media Upload"
45
  msgstr "Загрузить замену"
46
 
47
- #: popup.php:40
48
  msgid "NOTE: You are about to replace the media file"
49
  msgstr "Памятка: о замене медиафайла"
50
 
51
- #: popup.php:40
52
  msgid "There is no undo. Think about it!"
53
  msgstr "Нельзя отменить. Знайте это!"
54
 
55
- #: popup.php:42
56
  msgid "Choose a file to upload from your computer"
57
  msgstr "Выберите файл для загрузки с вашего компьютера"
58
 
59
- #: popup.php:46
60
  msgid "Select media replacement type:"
61
  msgstr "Выберите тип замены:"
62
 
63
- #: popup.php:48
64
  msgid "Just replace the file"
65
  msgstr "Только заменить файл"
66
 
67
- #: popup.php:49
68
  msgid "Note: This option requires you to upload a file of the same type ("
69
  msgstr "Примечание: Этот вариант требуется, если нужно загрузить файл того же типа"
70
 
71
- #: popup.php:49
72
  msgid ") as the one you are replacing. The name of the attachment will stay the same ("
73
  msgstr ") в качестве одного вы заменяете. Имя вложения останется той же ( "
74
 
75
- #: popup.php:49
76
  msgid ") no matter what the file you upload is called."
77
  msgstr ") Вне зависимости от того, как называется загружаемый файл."
78
 
79
- #: popup.php:51
80
  msgid "Replace the file, use new file name and update all links"
81
  msgstr "Для того, чтобы заменить этот файл, используйте новое имя файла и обновите все ссылки"
82
 
83
- #: popup.php:52
84
  msgid "Note: If you check this option, the name and type of the file you are about to upload will replace the old file. All links pointing to the current file ("
85
  msgstr "Примечание: Если вы отметите эту опцию, название и тип файла, который Вы собираетесь загрузить, заменит старый файл. Все ссылки, указывающие на текущий файл ( "
86
 
87
- #: popup.php:52
88
  msgid ") will be updated to point to the new file name."
89
  msgstr ") бдет обновлен "
90
 
91
- #: popup.php:54
92
  msgid "Upload"
93
  msgstr "Загрузить"
94
 
95
- #: popup.php:54
96
  msgid "Cancel"
97
  msgstr "Отмена"
98
 
 
 
2
  msgstr ""
3
  "Project-Id-Version: enable-media-replace\n"
4
  "Report-Msgid-Bugs-To: \n"
5
+ "POT-Creation-Date: 2010-09-13 14:57+0100\n"
6
  "PO-Revision-Date: \n"
7
+ "Last-Translator: Måns Jonasson <mans@mansjonasson.se>\n"
8
  "Language-Team: <zhr@tut.by>\n"
9
  "MIME-Version: 1.0\n"
10
  "Content-Type: text/plain; charset=UTF-8\n"
16
  "X-Poedit-SourceCharset: utf-8\n"
17
  "X-Poedit-SearchPath-0: .\n"
18
 
19
+ #: enable-media-replace.php:40
20
+ #: enable-media-replace.php:68
21
  msgid "Replace media"
22
  msgstr "Заменить медиа"
23
 
24
+ #: enable-media-replace.php:68
 
25
  msgid "Upload a new file"
26
  msgstr "Загрузить новый файл"
27
 
28
+ #: enable-media-replace.php:68
 
29
  msgid "To replace the current file, click the link and upload a replacement."
30
  msgstr "Для того, чтобы заменить текущий файл, нажмите на ссылку и загрузите замену. "
31
 
32
+ #: popup.php:14
33
+ #: upload.php:21
34
  msgid "You do not have permission to upload files."
35
  msgstr "У вас нет прав для загрузки файлов. "
36
 
37
+ #: popup.php:30
 
 
 
 
38
  msgid "Replace Media Upload"
39
  msgstr "Загрузить замену"
40
 
41
+ #: popup.php:41
42
  msgid "NOTE: You are about to replace the media file"
43
  msgstr "Памятка: о замене медиафайла"
44
 
45
+ #: popup.php:41
46
  msgid "There is no undo. Think about it!"
47
  msgstr "Нельзя отменить. Знайте это!"
48
 
49
+ #: popup.php:43
50
  msgid "Choose a file to upload from your computer"
51
  msgstr "Выберите файл для загрузки с вашего компьютера"
52
 
53
+ #: popup.php:47
54
  msgid "Select media replacement type:"
55
  msgstr "Выберите тип замены:"
56
 
57
+ #: popup.php:49
58
  msgid "Just replace the file"
59
  msgstr "Только заменить файл"
60
 
61
+ #: popup.php:50
62
  msgid "Note: This option requires you to upload a file of the same type ("
63
  msgstr "Примечание: Этот вариант требуется, если нужно загрузить файл того же типа"
64
 
65
+ #: popup.php:50
66
  msgid ") as the one you are replacing. The name of the attachment will stay the same ("
67
  msgstr ") в качестве одного вы заменяете. Имя вложения останется той же ( "
68
 
69
+ #: popup.php:50
70
  msgid ") no matter what the file you upload is called."
71
  msgstr ") Вне зависимости от того, как называется загружаемый файл."
72
 
73
+ #: popup.php:52
74
  msgid "Replace the file, use new file name and update all links"
75
  msgstr "Для того, чтобы заменить этот файл, используйте новое имя файла и обновите все ссылки"
76
 
77
+ #: popup.php:53
78
  msgid "Note: If you check this option, the name and type of the file you are about to upload will replace the old file. All links pointing to the current file ("
79
  msgstr "Примечание: Если вы отметите эту опцию, название и тип файла, который Вы собираетесь загрузить, заменит старый файл. Все ссылки, указывающие на текущий файл ( "
80
 
81
+ #: popup.php:53
82
  msgid ") will be updated to point to the new file name."
83
  msgstr ") бдет обновлен "
84
 
85
+ #: popup.php:55
86
  msgid "Upload"
87
  msgstr "Загрузить"
88
 
89
+ #: popup.php:55
90
  msgid "Cancel"
91
  msgstr "Отмена"
92
 
93
+ #~ msgid "Replace media upload"
94
+ #~ msgstr "Загрузить замену"
enable-media-replace-sv_SE.mo CHANGED
Binary file
enable-media-replace-sv_SE.po CHANGED
@@ -2,7 +2,7 @@ msgid ""
2
  msgstr ""
3
  "Project-Id-Version: enable-media-replace\n"
4
  "Report-Msgid-Bugs-To: \n"
5
- "POT-Creation-Date: 2010-05-17 16:43+0100\n"
6
  "PO-Revision-Date: \n"
7
  "Last-Translator: Måns Jonasson <mans@mansjonasson.se>\n"
8
  "Language-Team: \n"
@@ -13,103 +13,102 @@ msgstr ""
13
  "X-Poedit-Basepath: .\n"
14
  "X-Poedit-SearchPath-0: .\n"
15
 
16
- #: enable-media-replace.php:26
17
- msgid "Enable Media Replace"
18
- msgstr "Ladda upp ny fil"
19
-
20
- #: enable-media-replace.php:26
21
- #: enable-media-replace.php:39
22
  msgid "Replace media"
23
  msgstr "Ersätt media"
24
 
25
- #: enable-media-replace.php:39
26
  msgid "Upload a new file"
27
  msgstr "Ladda upp en ny fil"
28
 
29
- #: enable-media-replace.php:39
30
  msgid "To replace the current file, click the link and upload a replacement."
31
  msgstr "För att ersätta den nuvarande filen, klicka på länken och ladda upp en ny fil."
32
 
33
- #: enable-media-replace.php:53
34
- msgid "This plugin allows you to replace any uploaded media file by uploading a new one."
35
- msgstr "Detta plugin låter dig ersätta en fil i mediebiblioteket genom att ladda upp en ny."
36
-
37
- #: enable-media-replace.php:55
38
- msgid "First, locate the uploaded file you want to replace, using the"
39
- msgstr "Hitta först den fil du vill ersätta genom att bläddra i "
40
-
41
- #: enable-media-replace.php:55
42
- msgid "media library browser"
43
- msgstr "mediebiblioteket"
44
-
45
- #: enable-media-replace.php:55
46
- msgid "Click the \"Edit\" link"
47
- msgstr "Tryck på \"Redigera\"-länken"
48
-
49
- #: enable-media-replace.php:57
50
- msgid "Second, click the link \"Upload a new file\" and follow the instructions."
51
- msgstr "Tryck sen på länken \"Ladda upp ny fil\" och följ instruktionerna."
52
-
53
- #: popup.php:6
54
- #: upload.php:9
55
  msgid "You do not have permission to upload files."
56
  msgstr "Du har inte tillåtelse att ladda upp filer."
57
 
58
- #: popup.php:22
59
  msgid "Replace Media Upload"
60
  msgstr "Ladda upp ny fil"
61
 
62
- #: popup.php:26
63
  msgid "NOTE: You are about to replace the media file"
64
  msgstr "OBS: Du är på väg att ersätta filen"
65
 
66
- #: popup.php:26
67
  msgid "There is no undo. Think about it!"
68
  msgstr "Det finns inget sätt att ångra. Tänk efter först!"
69
 
70
- #: popup.php:28
71
  msgid "Choose a file to upload from your computer"
72
  msgstr "Välj en fil att ladda upp från din dator"
73
 
74
- #: popup.php:32
75
  msgid "Select media replacement type:"
76
  msgstr "Välj ersättningsform:"
77
 
78
- #: popup.php:34
79
  msgid "Just replace the file"
80
  msgstr "Ersätt bara filen"
81
 
82
- #: popup.php:35
83
  msgid "Note: This option requires you to upload a file of the same type ("
84
  msgstr "Detta val kräver att du laddar upp en fil av exakt samma typ ("
85
 
86
- #: popup.php:35
87
  msgid ") as the one you are replacing. The name of the attachment will stay the same ("
88
  msgstr ") som den du ersätter. Namnet på filen kommer att behållas ("
89
 
90
- #: popup.php:35
91
  msgid ") no matter what the file you upload is called."
92
  msgstr ") oavsett vad filen du laddar upp heter på din dator."
93
 
94
- #: popup.php:37
95
  msgid "Replace the file, use new file name and update all links"
96
  msgstr "Ersätt filen, använd det nya filnamnet och uppdatera alla länkar"
97
 
98
- #: popup.php:38
99
  msgid "Note: If you check this option, the name and type of the file you are about to upload will replace the old file. All links pointing to the current file ("
100
  msgstr "Om du klickar i den här rutan kommer den även namnet och typen på den nya filen du laddar upp helt att ersätta den gamla. Alla länkar som pekar på den gamla filen ("
101
 
102
- #: popup.php:38
103
  msgid ") will be updated to point to the new file name."
104
  msgstr ") kommer att uppdateras så att de pekar på det nya filnamnet."
105
 
106
- #: popup.php:40
107
  msgid "Upload"
108
  msgstr "Ladda upp"
109
 
110
- #: popup.php:40
111
  msgid "Cancel"
112
  msgstr "Avbryt"
113
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
114
  #~ msgid "Replace media upload"
115
  #~ msgstr "Ladda upp ny fil"
2
  msgstr ""
3
  "Project-Id-Version: enable-media-replace\n"
4
  "Report-Msgid-Bugs-To: \n"
5
+ "POT-Creation-Date: 2010-09-13 14:57+0100\n"
6
  "PO-Revision-Date: \n"
7
  "Last-Translator: Måns Jonasson <mans@mansjonasson.se>\n"
8
  "Language-Team: \n"
13
  "X-Poedit-Basepath: .\n"
14
  "X-Poedit-SearchPath-0: .\n"
15
 
16
+ #: enable-media-replace.php:40
17
+ #: enable-media-replace.php:68
 
 
 
 
18
  msgid "Replace media"
19
  msgstr "Ersätt media"
20
 
21
+ #: enable-media-replace.php:68
22
  msgid "Upload a new file"
23
  msgstr "Ladda upp en ny fil"
24
 
25
+ #: enable-media-replace.php:68
26
  msgid "To replace the current file, click the link and upload a replacement."
27
  msgstr "För att ersätta den nuvarande filen, klicka på länken och ladda upp en ny fil."
28
 
29
+ #: popup.php:14
30
+ #: upload.php:21
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
31
  msgid "You do not have permission to upload files."
32
  msgstr "Du har inte tillåtelse att ladda upp filer."
33
 
34
+ #: popup.php:30
35
  msgid "Replace Media Upload"
36
  msgstr "Ladda upp ny fil"
37
 
38
+ #: popup.php:41
39
  msgid "NOTE: You are about to replace the media file"
40
  msgstr "OBS: Du är på väg att ersätta filen"
41
 
42
+ #: popup.php:41
43
  msgid "There is no undo. Think about it!"
44
  msgstr "Det finns inget sätt att ångra. Tänk efter först!"
45
 
46
+ #: popup.php:43
47
  msgid "Choose a file to upload from your computer"
48
  msgstr "Välj en fil att ladda upp från din dator"
49
 
50
+ #: popup.php:47
51
  msgid "Select media replacement type:"
52
  msgstr "Välj ersättningsform:"
53
 
54
+ #: popup.php:49
55
  msgid "Just replace the file"
56
  msgstr "Ersätt bara filen"
57
 
58
+ #: popup.php:50
59
  msgid "Note: This option requires you to upload a file of the same type ("
60
  msgstr "Detta val kräver att du laddar upp en fil av exakt samma typ ("
61
 
62
+ #: popup.php:50
63
  msgid ") as the one you are replacing. The name of the attachment will stay the same ("
64
  msgstr ") som den du ersätter. Namnet på filen kommer att behållas ("
65
 
66
+ #: popup.php:50
67
  msgid ") no matter what the file you upload is called."
68
  msgstr ") oavsett vad filen du laddar upp heter på din dator."
69
 
70
+ #: popup.php:52
71
  msgid "Replace the file, use new file name and update all links"
72
  msgstr "Ersätt filen, använd det nya filnamnet och uppdatera alla länkar"
73
 
74
+ #: popup.php:53
75
  msgid "Note: If you check this option, the name and type of the file you are about to upload will replace the old file. All links pointing to the current file ("
76
  msgstr "Om du klickar i den här rutan kommer den även namnet och typen på den nya filen du laddar upp helt att ersätta den gamla. Alla länkar som pekar på den gamla filen ("
77
 
78
+ #: popup.php:53
79
  msgid ") will be updated to point to the new file name."
80
  msgstr ") kommer att uppdateras så att de pekar på det nya filnamnet."
81
 
82
+ #: popup.php:55
83
  msgid "Upload"
84
  msgstr "Ladda upp"
85
 
86
+ #: popup.php:55
87
  msgid "Cancel"
88
  msgstr "Avbryt"
89
 
90
+ #~ msgid "Enable Media Replace"
91
+ #~ msgstr "Ladda upp ny fil"
92
+
93
+ #~ msgid ""
94
+ #~ "This plugin allows you to replace any uploaded media file by uploading a "
95
+ #~ "new one."
96
+ #~ msgstr ""
97
+ #~ "Detta plugin låter dig ersätta en fil i mediebiblioteket genom att ladda "
98
+ #~ "upp en ny."
99
+
100
+ #~ msgid "First, locate the uploaded file you want to replace, using the"
101
+ #~ msgstr "Hitta först den fil du vill ersätta genom att bläddra i "
102
+
103
+ #~ msgid "media library browser"
104
+ #~ msgstr "mediebiblioteket"
105
+
106
+ #~ msgid "Click the \"Edit\" link"
107
+ #~ msgstr "Tryck på \"Redigera\"-länken"
108
+
109
+ #~ msgid ""
110
+ #~ "Second, click the link \"Upload a new file\" and follow the instructions."
111
+ #~ msgstr "Tryck sen på länken \"Ladda upp ny fil\" och följ instruktionerna."
112
+
113
  #~ msgid "Replace media upload"
114
  #~ msgstr "Ladda upp ny fil"
enable-media-replace.mo CHANGED
Binary file
enable-media-replace.php CHANGED
@@ -2,84 +2,111 @@
2
  /*
3
  Plugin Name: Enable Media Replace
4
  Plugin URI: http://www.mansjonasson.se/enable-media-replace
5
- Description: Enable replacing media files by uploading a new file in the "Edit Media" section of the WordPress Media Library.
6
- Version: 2.2
7
- Author: Måns Jonasson
8
  Author URI: http://www.mansjonasson.se
9
 
10
  Dual licensed under the MIT and GPL licenses:
11
  http://www.opensource.org/licenses/mit-license.php
12
  http://www.gnu.org/licenses/gpl.html
13
 
14
- Developed for .SE (Stiftelsen för Internetinfrastruktur) - http://www.iis.se
15
  */
16
 
17
- ini_set("display_errors", "on");
18
-
19
-
20
- add_action( 'init', 'enable_media_replace_init' );
 
 
 
 
 
 
 
 
 
21
  add_action('admin_menu', 'emr_menu');
22
  add_filter('attachment_fields_to_edit', 'enable_media_replace', 10, 2);
23
 
24
  add_shortcode('file_modified', 'emr_get_modified_date');
25
 
26
-
 
 
 
27
  function emr_menu() {
28
- add_submenu_page('upload.php', __("Enable Media Replace", "enable-media-replace"), __("Replace media", "enable-media-replace"), 'upload_files', __FILE__, 'emr_options');
29
  }
30
 
31
-
32
- // Initialize this plugin. Called by 'init' hook.
 
 
33
  function enable_media_replace_init() {
34
  load_plugin_textdomain( 'enable-media-replace', false, dirname( plugin_basename( __FILE__ ) ) );
35
- }
 
 
 
 
 
 
 
36
 
37
- function enable_media_replace( $form_fields, $post ) {
38
  if ($_GET["attachment_id"]) {
39
- $editurl = get_bloginfo("wpurl") . "/wp-admin/upload.php?page=enable-media-replace/enable-media-replace.php&attachment_id={$_GET["attachment_id"]}";
 
 
 
 
40
  if (FORCE_SSL_ADMIN) {
41
  $editurl = str_replace("http:", "https:", $editurl);
42
  }
43
  $link = "href=\"$editurl\"";
44
- $form_fields["enable-media-replace"] = array("label" => __("Replace media", "enable-media-replace"), "input" => "html", "html" => "<p><a $link>" . __("Upload a new file", "enable-media-replace") . "</a></p>", "helps" => __("To replace the current file, click the link and upload a replacement.", "enable-media-replace"));
45
  }
46
  return $form_fields;
47
  }
48
 
 
 
 
 
 
49
  function emr_options() {
50
- if ( array_key_exists("attachment_id", $_GET) && $_GET["attachment_id"] > 0) {
51
- include("popup.php");
52
- }
53
-
54
- else {
55
- ?>
56
- <div class="wrap">
57
- <h2>Enable media replace</h2>
58
- <p><?php _e("This plugin allows you to replace any uploaded media file by uploading a new one.", "enable-media-replace"); ?></p>
59
- <img src="<?php echo plugins_url("enable-media-replace/emr-list.png"); ?>" alt="Preview of Enable Media Replace link" />
60
- <p>&nbsp;&nbsp;&nbsp;&nbsp;<?php _e("First, locate the uploaded file you want to replace, using the", "enable-media-replace");?> <a href="<?php echo get_bloginfo("wpurl") . "/wp-admin/upload.php";?>"><?php _e("media library browser", "enable-media-replace");?></a>. <?php _e("Click the \"Edit\" link", "enable-media-replace");?>.</p>
61
- <img style="margin-top: 20px;" src="<?php echo plugins_url("enable-media-replace/emr-preview.png"); ?>" alt="Preview of Enable Media Replace link" />
62
- <p>&nbsp;&nbsp;&nbsp;&nbsp;<?php _e("Second, click the link \"Upload a new file\" and follow the instructions.", "enable-media-replace");?></p>
63
- </div>
64
-
65
- <?php
66
  }
67
  }
68
 
 
 
 
 
 
69
  function emr_get_modified_date($atts) {
 
 
 
70
  extract(shortcode_atts(array(
71
  'id' => '',
72
  'format' => get_option('date_format') . " " . get_option('time_format'),
73
  ), $atts));
74
-
75
  if ($id == '') return false;
76
-
77
  // Get path to file
78
  $current_file = get_attached_file($id, true);
79
 
80
- // Get file modification time
81
  $filetime = filemtime($current_file);
82
-
83
  // Do timezone magic to get around UTC
84
  $timezone = date_default_timezone_get();
85
  date_default_timezone_set(get_option('timezone_string'));
@@ -89,9 +116,9 @@ function emr_get_modified_date($atts) {
89
 
90
  // Set timezone back to default
91
  date_default_timezone_set($timezone);
92
-
93
  return $content;
94
-
95
  }
96
 
97
 
2
  /*
3
  Plugin Name: Enable Media Replace
4
  Plugin URI: http://www.mansjonasson.se/enable-media-replace
5
+ Description: Enable replacing media files by uploading a new file in the "Edit Media" section of the WordPress Media Library.
6
+ Version: 2.3
7
+ Author: M�ns Jonasson
8
  Author URI: http://www.mansjonasson.se
9
 
10
  Dual licensed under the MIT and GPL licenses:
11
  http://www.opensource.org/licenses/mit-license.php
12
  http://www.gnu.org/licenses/gpl.html
13
 
14
+ Developed for .SE (Stiftelsen f�r Internetinfrastruktur) - http://www.iis.se
15
  */
16
 
17
+ /**
18
+ * Main Plugin file
19
+ * Set action hooks and add shortcode
20
+ *
21
+ * @author M�ns Jonasson <http://www.mansjonasson.se>
22
+ * @copyright M�ns Jonasson 13 sep 2010
23
+ * @package wordpress
24
+ * @subpackage enable-media-replace
25
+ *
26
+ */
27
+ //ini_set("display_errors", "on");
28
+
29
+ add_action( 'admin_init', 'enable_media_replace_init' );
30
  add_action('admin_menu', 'emr_menu');
31
  add_filter('attachment_fields_to_edit', 'enable_media_replace', 10, 2);
32
 
33
  add_shortcode('file_modified', 'emr_get_modified_date');
34
 
35
+ /**
36
+ * Register this file in WordPress so we can call it with a ?page= GET var.
37
+ * To suppress it in the menu we give it an empty menu title.
38
+ */
39
  function emr_menu() {
40
+ add_submenu_page('upload.php', __("Replace media", "enable-media-replace"), '','upload_files', __FILE__, 'emr_options');
41
  }
42
 
43
+ /**
44
+ * Initialize this plugin. Called by 'admin_init' hook.
45
+ * Only languages files needs loading during init.
46
+ */
47
  function enable_media_replace_init() {
48
  load_plugin_textdomain( 'enable-media-replace', false, dirname( plugin_basename( __FILE__ ) ) );
49
+ }
50
+
51
+ /**
52
+ * Add some new fields to the attachment edit panel.
53
+ * @param array form fields edit panel
54
+ * @return array form fields with enable-media-replace fields added
55
+ */
56
+ function enable_media_replace( $form_fields ) {
57
 
 
58
  if ($_GET["attachment_id"]) {
59
+
60
+ $url = get_bloginfo("wpurl") . "/wp-admin/upload.php?page=enable-media-replace/enable-media-replace.php&action=media_replace&attachment_id={$_GET["attachment_id"]}";
61
+ $action = "media_replace";
62
+ $editurl = wp_nonce_url( $url, $action );
63
+
64
  if (FORCE_SSL_ADMIN) {
65
  $editurl = str_replace("http:", "https:", $editurl);
66
  }
67
  $link = "href=\"$editurl\"";
68
+ $form_fields["enable-media-replace"] = array("label" => __("Replace media", "enable-media-replace"), "input" => "html", "html" => "<p><a class='button-secondary'$link>" . __("Upload a new file", "enable-media-replace") . "</a></p>", "helps" => __("To replace the current file, click the link and upload a replacement.", "enable-media-replace"));
69
  }
70
  return $form_fields;
71
  }
72
 
73
+ /**
74
+ * Load the replace media panel.
75
+ * Panel is show on the action 'media-replace' and a given attachement.
76
+ * Called by GET var ?page=enable-media-replace/enable-media-replace.php
77
+ */
78
  function emr_options() {
79
+
80
+ if ( isset( $_GET['action'] ) && $_GET['action'] == 'media_replace' ) {
81
+ check_admin_referer( 'media_replace' ); // die if invalid or missing nonce
82
+ if ( array_key_exists("attachment_id", $_GET) && $_GET["attachment_id"] > 0) {
83
+ include("popup.php");
84
+ }
 
 
 
 
 
 
 
 
 
 
85
  }
86
  }
87
 
88
+ /**
89
+ * Shorttag function to show the media file modification date/time.
90
+ * @param array shorttag attributes
91
+ * @return string content / replacement shorttag
92
+ */
93
  function emr_get_modified_date($atts) {
94
+ $id=0;
95
+ $format= '';
96
+
97
  extract(shortcode_atts(array(
98
  'id' => '',
99
  'format' => get_option('date_format') . " " . get_option('time_format'),
100
  ), $atts));
101
+
102
  if ($id == '') return false;
103
+
104
  // Get path to file
105
  $current_file = get_attached_file($id, true);
106
 
107
+ // Get file modification time
108
  $filetime = filemtime($current_file);
109
+
110
  // Do timezone magic to get around UTC
111
  $timezone = date_default_timezone_get();
112
  date_default_timezone_set(get_option('timezone_string'));
116
 
117
  // Set timezone back to default
118
  date_default_timezone_set($timezone);
119
+
120
  return $content;
121
+
122
  }
123
 
124
 
enable-media-replace.po CHANGED
@@ -2,7 +2,7 @@ msgid ""
2
  msgstr ""
3
  "Project-Id-Version: enable-media-replace\n"
4
  "Report-Msgid-Bugs-To: \n"
5
- "POT-Creation-Date: 2010-05-17 16:43+0100\n"
6
  "PO-Revision-Date: \n"
7
  "Last-Translator: Måns Jonasson <mans@mansjonasson.se>\n"
8
  "Language-Team: \n"
@@ -13,101 +13,77 @@ msgstr ""
13
  "X-Poedit-Basepath: .\n"
14
  "X-Poedit-SearchPath-0: .\n"
15
 
16
- #: enable-media-replace.php:26
17
- msgid "Enable Media Replace"
18
- msgstr ""
19
-
20
- #: enable-media-replace.php:26
21
- #: enable-media-replace.php:39
22
  msgid "Replace media"
23
  msgstr ""
24
 
25
- #: enable-media-replace.php:39
26
  msgid "Upload a new file"
27
  msgstr ""
28
 
29
- #: enable-media-replace.php:39
30
  msgid "To replace the current file, click the link and upload a replacement."
31
  msgstr ""
32
 
33
- #: enable-media-replace.php:53
34
- msgid "This plugin allows you to replace any uploaded media file by uploading a new one."
35
- msgstr ""
36
-
37
- #: enable-media-replace.php:55
38
- msgid "First, locate the uploaded file you want to replace, using the"
39
- msgstr ""
40
-
41
- #: enable-media-replace.php:55
42
- msgid "media library browser"
43
- msgstr ""
44
-
45
- #: enable-media-replace.php:55
46
- msgid "Click the \"Edit\" link"
47
- msgstr ""
48
-
49
- #: enable-media-replace.php:57
50
- msgid "Second, click the link \"Upload a new file\" and follow the instructions."
51
- msgstr ""
52
-
53
- #: popup.php:6
54
- #: upload.php:9
55
  msgid "You do not have permission to upload files."
56
  msgstr ""
57
 
58
- #: popup.php:22
59
  msgid "Replace Media Upload"
60
  msgstr ""
61
 
62
- #: popup.php:26
63
  msgid "NOTE: You are about to replace the media file"
64
  msgstr ""
65
 
66
- #: popup.php:26
67
  msgid "There is no undo. Think about it!"
68
  msgstr ""
69
 
70
- #: popup.php:28
71
  msgid "Choose a file to upload from your computer"
72
  msgstr ""
73
 
74
- #: popup.php:32
75
  msgid "Select media replacement type:"
76
  msgstr ""
77
 
78
- #: popup.php:34
79
  msgid "Just replace the file"
80
  msgstr ""
81
 
82
- #: popup.php:35
83
  msgid "Note: This option requires you to upload a file of the same type ("
84
  msgstr ""
85
 
86
- #: popup.php:35
87
  msgid ") as the one you are replacing. The name of the attachment will stay the same ("
88
  msgstr ""
89
 
90
- #: popup.php:35
91
  msgid ") no matter what the file you upload is called."
92
  msgstr ""
93
 
94
- #: popup.php:37
95
  msgid "Replace the file, use new file name and update all links"
96
  msgstr ""
97
 
98
- #: popup.php:38
99
  msgid "Note: If you check this option, the name and type of the file you are about to upload will replace the old file. All links pointing to the current file ("
100
  msgstr ""
101
 
102
- #: popup.php:38
103
  msgid ") will be updated to point to the new file name."
104
  msgstr ""
105
 
106
- #: popup.php:40
107
  msgid "Upload"
108
  msgstr ""
109
 
110
- #: popup.php:40
111
  msgid "Cancel"
112
  msgstr ""
113
 
2
  msgstr ""
3
  "Project-Id-Version: enable-media-replace\n"
4
  "Report-Msgid-Bugs-To: \n"
5
+ "POT-Creation-Date: 2010-09-13 14:57+0100\n"
6
  "PO-Revision-Date: \n"
7
  "Last-Translator: Måns Jonasson <mans@mansjonasson.se>\n"
8
  "Language-Team: \n"
13
  "X-Poedit-Basepath: .\n"
14
  "X-Poedit-SearchPath-0: .\n"
15
 
16
+ #: enable-media-replace.php:40
17
+ #: enable-media-replace.php:68
 
 
 
 
18
  msgid "Replace media"
19
  msgstr ""
20
 
21
+ #: enable-media-replace.php:68
22
  msgid "Upload a new file"
23
  msgstr ""
24
 
25
+ #: enable-media-replace.php:68
26
  msgid "To replace the current file, click the link and upload a replacement."
27
  msgstr ""
28
 
29
+ #: popup.php:14
30
+ #: upload.php:21
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
31
  msgid "You do not have permission to upload files."
32
  msgstr ""
33
 
34
+ #: popup.php:30
35
  msgid "Replace Media Upload"
36
  msgstr ""
37
 
38
+ #: popup.php:41
39
  msgid "NOTE: You are about to replace the media file"
40
  msgstr ""
41
 
42
+ #: popup.php:41
43
  msgid "There is no undo. Think about it!"
44
  msgstr ""
45
 
46
+ #: popup.php:43
47
  msgid "Choose a file to upload from your computer"
48
  msgstr ""
49
 
50
+ #: popup.php:47
51
  msgid "Select media replacement type:"
52
  msgstr ""
53
 
54
+ #: popup.php:49
55
  msgid "Just replace the file"
56
  msgstr ""
57
 
58
+ #: popup.php:50
59
  msgid "Note: This option requires you to upload a file of the same type ("
60
  msgstr ""
61
 
62
+ #: popup.php:50
63
  msgid ") as the one you are replacing. The name of the attachment will stay the same ("
64
  msgstr ""
65
 
66
+ #: popup.php:50
67
  msgid ") no matter what the file you upload is called."
68
  msgstr ""
69
 
70
+ #: popup.php:52
71
  msgid "Replace the file, use new file name and update all links"
72
  msgstr ""
73
 
74
+ #: popup.php:53
75
  msgid "Note: If you check this option, the name and type of the file you are about to upload will replace the old file. All links pointing to the current file ("
76
  msgstr ""
77
 
78
+ #: popup.php:53
79
  msgid ") will be updated to point to the new file name."
80
  msgstr ""
81
 
82
+ #: popup.php:55
83
  msgid "Upload"
84
  msgstr ""
85
 
86
+ #: popup.php:55
87
  msgid "Cancel"
88
  msgstr ""
89
 
popup.php CHANGED
@@ -1,6 +1,14 @@
1
  <?php
2
-
3
- $wppath = str_replace("wp-content/plugins/enable-media-replace/popup.php", "", __FILE__);
 
 
 
 
 
 
 
 
4
 
5
  if (!current_user_can('upload_files'))
6
  wp_die(__('You do not have permission to upload files.', 'enable-media-replace'));
@@ -20,30 +28,30 @@ $current_filename = substr($current_filename, (strrpos($current_filename, "/") +
20
  <div class="wrap">
21
  <div id="icon-upload" class="icon32"><br /></div>
22
  <h2><?php echo __("Replace Media Upload", "enable-media-replace"); ?></h2>
23
-
24
  <?php
25
  $formurl = get_bloginfo("wpurl") . "/wp-content/plugins/enable-media-replace/upload.php";
26
  if (FORCE_SSL_ADMIN) {
27
  $formurl = str_replace("http:", "https:", $formurl);
28
  }
29
  ?>
30
-
31
  <form enctype="multipart/form-data" method="post" action="<?php echo $formurl; ?>">
32
  <input type="hidden" name="ID" value="<?php echo $_GET["attachment_id"]; ?>" />
33
  <div id="message" class="updated fade"><p><?php echo __("NOTE: You are about to replace the media file", "enable-media-replace"); ?> "<?php echo $current_filename?>". <?php echo __("There is no undo. Think about it!", "enable-media-replace"); ?></p></div>
34
-
35
  <p><?php echo __("Choose a file to upload from your computer", "enable-media-replace"); ?></p>
36
-
37
  <input type="file" name="userfile" />
38
-
39
  <p><?php echo __("Select media replacement type:", "enable-media-replace"); ?></p>
40
-
41
  <label for="replace_type_1"><input CHECKED id="replace_type_1" type="radio" name="replace_type" value="replace"> <?php echo __("Just replace the file", "enable-media-replace"); ?></label>
42
  <p class="howto"><?php echo __("Note: This option requires you to upload a file of the same type (", "enable-media-replace"); ?><?php echo $current_filetype; ?><?php echo __(") as the one you are replacing. The name of the attachment will stay the same (", "enable-media-replace"); ?><?php echo $current_filename; ?><?php echo __(") no matter what the file you upload is called.", "enable-media-replace"); ?></p>
43
-
44
  <label for="replace_type_2"><input id="replace_type_2" type="radio" name="replace_type" value="replace_and_search"> <?php echo __("Replace the file, use new file name and update all links", "enable-media-replace"); ?></label>
45
  <p class="howto"><?php echo __("Note: If you check this option, the name and type of the file you are about to upload will replace the old file. All links pointing to the current file (", "enable-media-replace"); ?><?php echo $current_filename; ?><?php echo __(") will be updated to point to the new file name.", "enable-media-replace"); ?></p>
46
-
47
  <input type="submit" class="button" value="<?php echo __("Upload", "enable-media-replace"); ?>" /> <a href="#" onclick="window.close();"><?php echo __("Cancel", "enable-media-replace"); ?></a>
48
 
49
  </form>
1
  <?php
2
+ /**
3
+ * Uploadscreen for selecting and uploading new media file
4
+ *
5
+ * @author M�ns Jonasson <http://www.mansjonasson.se>
6
+ * @copyright M�ns Jonasson 13 sep 2010
7
+ * @version $Revision: 2303 $ | $Date: 2010-09-13 11:12:35 +0200 (ma, 13 sep 2010) $
8
+ * @package wordpress
9
+ * @subpackage enable-media-replace
10
+ *
11
+ */
12
 
13
  if (!current_user_can('upload_files'))
14
  wp_die(__('You do not have permission to upload files.', 'enable-media-replace'));
28
  <div class="wrap">
29
  <div id="icon-upload" class="icon32"><br /></div>
30
  <h2><?php echo __("Replace Media Upload", "enable-media-replace"); ?></h2>
31
+
32
  <?php
33
  $formurl = get_bloginfo("wpurl") . "/wp-content/plugins/enable-media-replace/upload.php";
34
  if (FORCE_SSL_ADMIN) {
35
  $formurl = str_replace("http:", "https:", $formurl);
36
  }
37
  ?>
38
+
39
  <form enctype="multipart/form-data" method="post" action="<?php echo $formurl; ?>">
40
  <input type="hidden" name="ID" value="<?php echo $_GET["attachment_id"]; ?>" />
41
  <div id="message" class="updated fade"><p><?php echo __("NOTE: You are about to replace the media file", "enable-media-replace"); ?> "<?php echo $current_filename?>". <?php echo __("There is no undo. Think about it!", "enable-media-replace"); ?></p></div>
42
+
43
  <p><?php echo __("Choose a file to upload from your computer", "enable-media-replace"); ?></p>
44
+
45
  <input type="file" name="userfile" />
46
+
47
  <p><?php echo __("Select media replacement type:", "enable-media-replace"); ?></p>
48
+
49
  <label for="replace_type_1"><input CHECKED id="replace_type_1" type="radio" name="replace_type" value="replace"> <?php echo __("Just replace the file", "enable-media-replace"); ?></label>
50
  <p class="howto"><?php echo __("Note: This option requires you to upload a file of the same type (", "enable-media-replace"); ?><?php echo $current_filetype; ?><?php echo __(") as the one you are replacing. The name of the attachment will stay the same (", "enable-media-replace"); ?><?php echo $current_filename; ?><?php echo __(") no matter what the file you upload is called.", "enable-media-replace"); ?></p>
51
+
52
  <label for="replace_type_2"><input id="replace_type_2" type="radio" name="replace_type" value="replace_and_search"> <?php echo __("Replace the file, use new file name and update all links", "enable-media-replace"); ?></label>
53
  <p class="howto"><?php echo __("Note: If you check this option, the name and type of the file you are about to upload will replace the old file. All links pointing to the current file (", "enable-media-replace"); ?><?php echo $current_filename; ?><?php echo __(") will be updated to point to the new file name.", "enable-media-replace"); ?></p>
54
+
55
  <input type="submit" class="button" value="<?php echo __("Upload", "enable-media-replace"); ?>" /> <a href="#" onclick="window.close();"><?php echo __("Cancel", "enable-media-replace"); ?></a>
56
 
57
  </form>
readme.txt CHANGED
@@ -2,7 +2,7 @@
2
  Contributors: mungobbq
3
  Tags: admin, attachment, media, files
4
  Requires at least: 2.8
5
- Tested up to: 3.0
6
  Stable tag: trunk
7
 
8
  Enables replacing attachment files by simply uploading a new file in the media library edit view.
@@ -37,6 +37,10 @@ If you want more control over the format used to display the time, you can use t
37
 
38
  == Changelog ==
39
 
 
 
 
 
40
  = 2.2 =
41
  * Bug fix, fixed typo in popup.php, thanks to Bill Dennen and others for pointing this out!
42
 
2
  Contributors: mungobbq
3
  Tags: admin, attachment, media, files
4
  Requires at least: 2.8
5
+ Tested up to: 3.0.1
6
  Stable tag: trunk
7
 
8
  Enables replacing attachment files by simply uploading a new file in the media library edit view.
37
 
38
  == Changelog ==
39
 
40
+ = 2.3 =
41
+ * Lots of code trimmed and enhanced, thanks to Ben ter Stal! Now working properly with Windows systems, better security, optimized loading, and much more.
42
+ * Added Dutch translation by Ben ter Stal.
43
+
44
  = 2.2 =
45
  * Bug fix, fixed typo in popup.php, thanks to Bill Dennen and others for pointing this out!
46
 
upload.php CHANGED
@@ -1,13 +1,25 @@
1
  <?php
 
 
 
 
 
 
 
 
 
 
 
2
 
3
- $wppath = str_replace("wp-content/plugins/enable-media-replace/upload.php", "", __FILE__);
 
4
 
5
  require_once($wppath . "wp-load.php");
6
  require_once($wppath . "wp-admin/admin.php");
7
 
8
  if (!current_user_can('upload_files'))
9
  wp_die(__('You do not have permission to upload files.'));
10
-
11
  global $wpdb;
12
 
13
  // Define DB table names
@@ -42,75 +54,80 @@ if (is_uploaded_file($_FILES["userfile"]["tmp_name"])) {
42
 
43
  // Delete old file
44
  unlink($current_file);
45
-
46
  // Move new file to old location/name
47
  move_uploaded_file($_FILES["userfile"]["tmp_name"], $current_file);
48
-
49
  // Chmod new file to 644
50
  chmod($current_file, 0644);
51
-
52
  // Make thumb and/or update metadata
53
  wp_update_attachment_metadata( $_POST["ID"], wp_generate_attachment_metadata( $_POST["ID"], $current_file ) );
54
-
55
  }
56
-
57
  else {
58
  // Replace file, replace file name, update meta data, replace links pointing to old file name
59
-
60
  // Delete old file
61
  unlink($current_file);
62
-
63
  // Massage new filename to adhere to WordPress standards
64
  $new_filename= wp_unique_filename( $current_path, $new_filename );
65
-
66
  // Move new file to old location, new name
67
  $new_file = $current_path . "/" . $new_filename;
68
  move_uploaded_file($_FILES["userfile"]["tmp_name"], $new_file);
69
 
70
  // Chmod new file to 644
71
- chmod($new_file, 0644);
72
-
73
  $new_filetitle = preg_replace('/\.[^.]+$/', '', basename($new_file));
74
  $new_guid = str_replace($current_filename, $new_filename, $current_guid);
75
-
76
  // Update database file name
77
  mysql_query("UPDATE $table_name SET post_title = '$new_filetitle', post_name = '$new_filetitle', guid = '$new_guid', post_mime_type = '$new_filetype' WHERE ID = {$_POST["ID"]}");
78
-
79
  // Update the postmeta file name
80
 
81
  // Get old postmeta _wp_attached_file
82
  $sql = "SELECT meta_value FROM $postmeta_table_name WHERE meta_key = '_wp_attached_file' AND post_id = '{$_POST["ID"]}'";
83
  $old_meta_name = mysql_result(mysql_query($sql),0);
84
-
85
  // Make new postmeta _wp_attached_file
86
  $new_meta_name = str_replace($current_filename, $new_filename, $old_meta_name);
87
  mysql_query("UPDATE $postmeta_table_name SET meta_value = '$new_meta_name' WHERE meta_key = '_wp_attached_file' AND post_id = '{$_POST["ID"]}'");
88
-
89
  // Make thumb and/or update metadata
90
  wp_update_attachment_metadata( $_POST["ID"], wp_generate_attachment_metadata( $_POST["ID"], $new_file) );
91
-
92
  // Search-and-replace filename in post database
93
  $sql = "SELECT ID, post_content FROM $table_name WHERE post_content LIKE '%$current_guid%'";
94
  $rs = mysql_query($sql);
95
-
96
  while($rows = mysql_fetch_assoc($rs)) {
97
-
98
  // replace old guid with new guid
99
  $post_content = $rows["post_content"];
100
  $post_content = addslashes(str_replace($current_guid, $new_guid, $post_content));
101
-
102
  mysql_query("UPDATE $table_name SET post_content = '$post_content' WHERE ID = {$rows["ID"]}");
103
  }
104
-
105
  }
106
-
 
 
 
 
 
107
  }
108
 
109
- $returnurl = get_bloginfo("wpurl") . "/wp-admin/upload.php?posted=3";
110
  if (FORCE_SSL_ADMIN) {
111
- $returnurl = str_replace("http:", "https:", $returnurl);
112
- }
 
 
 
113
 
114
- header("Location: " . $returnurl);
115
-
116
  ?>
1
  <?php
2
+ /**
3
+ * Handling upload new media file
4
+ * We have two types: replace / replace_and_search
5
+ *
6
+ * @author M�ns Jonasson <http://www.mansjonasson.se>
7
+ * @copyright M�ns Jonasson 13 sep 2010
8
+ * @version $Revision: 1984 $ | $Date: 2009-09-09 13:01:30 +0200 (wo, 09 sep 2009) $
9
+ * @package wordpress
10
+ * @subpackage enable-media-replace
11
+ *
12
+ */
13
 
14
+
15
+ $wppath = str_replace("wp-content/plugins/enable-media-replace/upload.php", "", str_replace('\\','/',__FILE__));
16
 
17
  require_once($wppath . "wp-load.php");
18
  require_once($wppath . "wp-admin/admin.php");
19
 
20
  if (!current_user_can('upload_files'))
21
  wp_die(__('You do not have permission to upload files.'));
22
+
23
  global $wpdb;
24
 
25
  // Define DB table names
54
 
55
  // Delete old file
56
  unlink($current_file);
57
+
58
  // Move new file to old location/name
59
  move_uploaded_file($_FILES["userfile"]["tmp_name"], $current_file);
60
+
61
  // Chmod new file to 644
62
  chmod($current_file, 0644);
63
+
64
  // Make thumb and/or update metadata
65
  wp_update_attachment_metadata( $_POST["ID"], wp_generate_attachment_metadata( $_POST["ID"], $current_file ) );
66
+
67
  }
68
+
69
  else {
70
  // Replace file, replace file name, update meta data, replace links pointing to old file name
71
+
72
  // Delete old file
73
  unlink($current_file);
74
+
75
  // Massage new filename to adhere to WordPress standards
76
  $new_filename= wp_unique_filename( $current_path, $new_filename );
77
+
78
  // Move new file to old location, new name
79
  $new_file = $current_path . "/" . $new_filename;
80
  move_uploaded_file($_FILES["userfile"]["tmp_name"], $new_file);
81
 
82
  // Chmod new file to 644
83
+ chmod($new_file, 0644);
84
+
85
  $new_filetitle = preg_replace('/\.[^.]+$/', '', basename($new_file));
86
  $new_guid = str_replace($current_filename, $new_filename, $current_guid);
87
+
88
  // Update database file name
89
  mysql_query("UPDATE $table_name SET post_title = '$new_filetitle', post_name = '$new_filetitle', guid = '$new_guid', post_mime_type = '$new_filetype' WHERE ID = {$_POST["ID"]}");
90
+
91
  // Update the postmeta file name
92
 
93
  // Get old postmeta _wp_attached_file
94
  $sql = "SELECT meta_value FROM $postmeta_table_name WHERE meta_key = '_wp_attached_file' AND post_id = '{$_POST["ID"]}'";
95
  $old_meta_name = mysql_result(mysql_query($sql),0);
96
+
97
  // Make new postmeta _wp_attached_file
98
  $new_meta_name = str_replace($current_filename, $new_filename, $old_meta_name);
99
  mysql_query("UPDATE $postmeta_table_name SET meta_value = '$new_meta_name' WHERE meta_key = '_wp_attached_file' AND post_id = '{$_POST["ID"]}'");
100
+
101
  // Make thumb and/or update metadata
102
  wp_update_attachment_metadata( $_POST["ID"], wp_generate_attachment_metadata( $_POST["ID"], $new_file) );
103
+
104
  // Search-and-replace filename in post database
105
  $sql = "SELECT ID, post_content FROM $table_name WHERE post_content LIKE '%$current_guid%'";
106
  $rs = mysql_query($sql);
107
+
108
  while($rows = mysql_fetch_assoc($rs)) {
109
+
110
  // replace old guid with new guid
111
  $post_content = $rows["post_content"];
112
  $post_content = addslashes(str_replace($current_guid, $new_guid, $post_content));
113
+
114
  mysql_query("UPDATE $table_name SET post_content = '$post_content' WHERE ID = {$rows["ID"]}");
115
  }
116
+
117
  }
118
+
119
+ $returnurl = get_bloginfo("wpurl") . "/wp-admin/upload.php?posted=3";
120
+ } else {
121
+ //TODO Better error handling when no file is selected.
122
+ //For now just go back to media management
123
+ $returnurl = get_bloginfo("wpurl") . "/wp-admin/upload.php";
124
  }
125
 
 
126
  if (FORCE_SSL_ADMIN) {
127
+ $returnurl = str_replace("http:", "https:", $returnurl);
128
+ }
129
+
130
+ //save redirection
131
+ wp_redirect($returnurl);
132
 
 
 
133
  ?>