PluginProbe
Photo Engine (Media Organizer & Lightroom) / 0.4
Photo Engine (Media Organizer & Lightroom) v0.4
6.5.5 6.5.4 6.5.3 6.5.2 trunk 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.8.2 0.8.3 0.8.4 0.8.6 0.8.8 1.2.4 1.3.0 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 All 157 releases
wplr-sync / lrsync_admin.php

lrsync_admin.php in Photo Engine (Media Organizer & Lightroom) 0.4, at lrsync_admin.php

466 lines 15.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 class Meow_WPLR_Sync_Admin extends Meow_WPLR_Sync_RPC {
4
5 public function __construct() {
6 parent::__construct();
7 add_action( 'admin_menu', array( $this, 'admin_menu' ) );
8 }
9
10 function admin_menu() {
11 add_submenu_page( 'tools.php', 'WP/LR Sync', 'WP/LR Sync', 'manage_options', 'wplrsync_tools', array( $this, 'tools' ) );
12 add_media_page( 'WP/LR Sync', 'WP/LR Sync', 'manage_options', 'wplrsync', array( $this, 'wplrsync_media' ) );
13 }
14
15 function display_image_box( $wpid, $image = null ) {
16 echo "<div id='wplr-image-box-$wpid' class='wplr-image-box'>";
17 echo "<span class='wplr-title-wpid'>Media ID #<a target='_blank' href='post.php?post=$wpid&action=edit'>$wpid</a></span><br />";
18 echo "<a target='_blank' href='post.php?post=$wpid&action=edit'>" . wp_get_attachment_image( $wpid ) . "</a>";
19 echo "<div style='clear: both;'></div>";
20 echo "<span class='wplr-actions'>";
21 if ( $image ) {
22 echo "<a style='background: #B34A4A;' href='upload.php?page=wplrsync&show=duplicates&action=unlink&wpid=$wpid&lrid=$image->lr_id'>Unlink</a>";
23 echo "<a style='' href='upload.php?page=wplrsync&show=duplicates&action=delete&wpid=$wpid&lrid=$image->lr_id'>Delete</a>";
24 }
25 else {
26 echo "<div>
27 LR ID:
28 <input type='text' class='wplr-sync-lrid-input' id='wplrsync-link-" . $wpid . "'></input>
29 <a href='#' style='background: #3E79BB;' onclick='wplrsync_link($wpid)'>Link</a>
30 </div>";
31 }
32 echo "</span>";
33
34
35 echo "</div>";
36 }
37
38 function wplrsync_media() {
39 $images = array();
40 global $wpdb;
41 $table_name = $wpdb->prefix . "lrsync";
42 $show = null;
43 if ( isset( $_GET['action'] ) ) {
44 $wpid = isset( $_GET['wpid'] ) ? $_GET['wpid'] : null;
45 $lrid = isset( $_GET['lrid'] ) ? $_GET['lrid'] : null;
46 if ( $_GET['action'] == "link" ) {
47 $this->link_media( $lrid, $wpid );
48 }
49 else if ( $_GET['action'] == "unlink" ) {
50 $this->unlink_media( $lrid, $wpid );
51 }
52 else if ( $_GET['action'] == "delete" ) {
53 $this->unlink_media( $lrid, $wpid );
54 wp_delete_attachment( $wpid );
55 }
56 }
57
58 if ( isset( $_GET['show'] ) && $_GET['show'] == "duplicates" ) {
59 $show = "duplicates";
60 $images = $wpdb->get_results(
61 "SELECT lr.lr_id, lr.lr_file, GROUP_CONCAT(lr.wp_id SEPARATOR ',') as wpids
62 FROM $wpdb->posts p, $table_name lr
63 WHERE p.ID = lr.wp_id AND lr.lr_id != 0
64 GROUP BY lr.lr_id
65 HAVING COUNT(p.ID) > 1
66 ORDER BY lr.lr_id DESC", OBJECT );
67 }
68 else {
69 $show = "unlinked";
70 $images = $this->list_unlinks( true );
71 }
72
73 ?>
74 <style>
75
76 .wplr-title-lrid {
77 background: #515151;
78 color: white;
79 padding: 0px 2px;
80 margin-left: 5px;
81 }
82
83 .wplr-duplicates-box {
84 padding: 5px;
85 border: 2px solid #515151;
86 border-radius: 5px;
87 margin-bottom: 10px;
88 }
89
90 .wplr-image-box {
91 width: 150px;
92 margin-right: 5px;
93 float: left;
94 font-size: 10px;
95 }
96
97 .wplr-title-wpid {
98 font-size: 110%;
99 }
100
101 .wplr-title-wpid a {
102 text-decoration: none;
103 }
104
105 .wplr-actions a {
106 margin-right: 5px;
107 padding: 1px 3px;
108 background: rgb(92, 92, 92);
109 color: white;
110 }
111
112 </style>
113
114 <div class='wrap'>
115 <div id="icon-upload" class="icon32"><br></div>
116 <h2>WP/LR Sync</h2>
117 <p>You can easily link your unlinked photos through this screen. You can also check if you have any duplicate links (1 LR photo = more than 1 WP photo). Be careful, those actions are <u>instantaneous</u> and <u>unrecoverable</u>.</p>
118 <ul class="subsubsub">
119 <li><a class="<?php echo $show == "unlinked" ? "current" : "" ?>" href="upload.php?page=wplrsync&show=unlinked">Unlinked Photos</a> |</li>
120 <li><a class="<?php echo $show == "duplicates" ? "current" : "" ?>" href="upload.php?page=wplrsync&show=duplicates">Duplicated Links</a></li>
121 </ul>
122 <div style='clear: both; margin-bottom: 18px; margin-top: -5px;'></div>
123
124 <?php
125
126 if ( count( $images ) == 0 && $show == "unlinked" )
127 echo "<div class='updated'><p>There are no unlinked photos. Good job!</p></div>";
128 else if ( count( $images ) == 0 && $show == "duplicates" )
129 echo "<div class='updated'><p>There are no duplicated links.</p></div>";
130 else {
131 foreach ( $images as $image ) {
132 if ( $show == "duplicates" ) {
133 echo "<b class='wplr-title-lrid'>LR ID " . $image->lr_id . "</b> Filename: " . ( $image->lr_file ? $image->lr_file : "Unknown" );
134 echo "<div class='wplr-duplicates-box'>";
135 $wpids = explode( ',', $image->wpids );
136 foreach ( $wpids as $wpid ) {
137 $this->display_image_box( $wpid, $image );
138 }
139 echo "<div style='clear: both;'></div>";
140 echo "</div>";
141 }
142 else if ( $show == "unlinked" ) {
143 $this->display_image_box( $image->ID );
144 }
145 }
146 }
147
148 echo "</div>";
149 }
150
151 function tools() {
152 if ( !current_user_can( 'manage_options' ) ) {
153 wp_die( __( 'You do not have sufficient permissions to access this page.' ) );
154 }
155
156 // HEADER
157 ?>
158 <div class="wrap" >
159
160 <style>
161
162 .left {
163 width: 450px;
164 }
165
166 .right {
167 position: absolute;
168 left: 460px;
169 }
170
171 h3 {
172 margin-bottom: 5px;
173 }
174
175 p {
176 margin-top: 0px;
177 margin-bottom: 10px;
178 }
179
180 .wplrsync-form {
181 border: 1px solid lightgrey;
182 padding: 5px;
183 background: white;
184 border-radius: 5px;
185 width: 420px;
186 }
187
188 th {
189 text-align: left;
190 }
191
192 #wpfooter {
193 display: none;
194 }
195
196 </style>
197
198 <h2>
199 WP/LR Sync
200 <span>
201 <form style="float: right;" method="post" action="">
202 <input type="hidden" name="action" value="reset">
203 <input type="submit" name="submit" id="submit" class="button button-primary" value="Reset">
204 </form>
205 <form style="float: right; margin-right: 5px;" method="post" action="">
206 <input type="hidden" name="action" value="duplicates">
207 <input type="submit" name="submit" id="submit" class="button button-primary" value="Get Duplicates">
208 </form>
209 <form style="float: right; margin-right: 5px;" method="post" action="">
210 <input type="hidden" name="action" value="scan">
211 <input type="submit" name="submit" id="submit" class="button button-primary" value="Get Unlinked">
212 </form>
213 <form style="float: right; margin-right: 5px;" method="post" action="">
214 <input type="hidden" name="action" value="list">
215 <input type="submit" name="submit" id="submit" class="button button-primary" value="Get Linked">
216 </form>
217 </span>
218 </h2>
219 <?php
220
221 global $wpdb;
222 $table_name = $wpdb->prefix . "lrsync";
223
224 if ( isset( $_POST['action'] ) ) {
225
226 $action = $_POST['action'];
227 if ( $action == "reset" ) {
228 $this->reset_db();
229 echo "<div class='updated'><p>The database was reset.</p></div>";
230 }
231 else if ( $action == "duplicates" ) {
232 echo "<div class='updated'><p>Checked duplicates.</p></div>";
233 }
234 else if ( $action == "scan" ) {
235 $unlinks = $this->list_unlinks();
236 }
237 else if ( $action == "list" ) {
238 $list = $this->list_sync_media();
239 }
240 else if ( $action == "link" ) {
241 if ( $this->link_media( $_POST['lr_id'], $_POST['wp_id'] ) ) {
242 echo "<div class='updated'><p>Link successful.</p></div>";
243 }
244 else {
245 echo "<div class='error'><p>" . $this->get_error()->message . "</p></div>";
246 }
247 }
248 else if ( $action == "linkinfo_upload" ) {
249 if ( isset( $_FILES['file'], $_FILES['file']['tmp_name'] ) && !empty( $_FILES['file']['tmp_name'] ) ) {
250 $tmp_path = $_FILES['file']['tmp_name'];
251 $linkinfo = $this->linkinfo_upload( $tmp_path, null );
252 }
253 else {
254 $linkinfo = $this->linkinfo_media( $_POST['wp_id'] );
255 }
256 if ( $linkinfo )
257 echo "<div class='updated'><p>Link info retrieved.</p></div>";
258 else
259 echo "<div class='error'><p>" . $this->get_error()->message . "</p></div>";
260 }
261 else if ( $action == "sync" ) {
262 $tmp_path = $_FILES['file']['tmp_name'];
263 $lrinfo = new Meow_WPLR_LRInfo();
264 $lrinfo->lr_id = $_POST['lr_id'] == "" ? -1 : $_POST['lr_id'];
265 $lrinfo->lr_file = $_FILES['file']['name'];
266 $lrinfo->lr_title = isset( $_POST['title'] ) ? $_POST['title'] : "";
267 $lrinfo->lr_caption = $_POST['caption'];
268 $lrinfo->lr_desc = isset( $_POST['desc'] ) ? $_POST['desc'] : "";
269 $lrinfo->lr_alt_text = isset( $_POST['altText'] ) ? $_POST['altText'] : "";
270 $lrinfo->sync_title = isset( $_POST['syncTitle'] ) && $_POST['syncTitle'] == 'on';
271 $lrinfo->sync_caption = isset( $_POST['syncCaption'] ) && $_POST['syncCaption'] == 'on';
272 $lrinfo->sync_desc = isset( $_POST['syncDesc'] ) && $_POST['syncDesc'] == 'on';
273 $lrinfo->sync_alt_text = isset( $_POST['syncAltText'] ) && $_POST['syncAltText'] == 'on';
274 $lrinfo->type = $_FILES['file']['type'];
275 if ( $this->sync_media( $lrinfo, $tmp_path ) )
276 echo "<div class='updated'><p>Lr ID " . $_POST['lr_id'] . " was synchronized with the attachment.</p></div>";
277 else
278 echo "<div class='error'><p>" . $this->get_error()->message . "</p></div>";
279
280 }
281 else if ( $action == "unlink" ) {
282 if ( $this->unlink_media( $_POST['lr_id'], $_POST['wp_id'] ) )
283 echo "<div class='updated'><p>Media unlinked.</p></div>";
284 else
285 echo "<div class='error'><p>" . $this->get_error()->message . "</p></div>";
286 }
287 else if ( $action == "remove" ) {
288 if ( $this->delete_media( $_POST['lr_id'] ) )
289 echo "<div class='updated'><p>Media removed.</p></div>";
290 else
291 echo "<div class='error'><p>" . $this->get_error()->message . "</p></div>";
292 }
293 else {
294 echo "<div class='error'<p>Unknown action.</p></div>";
295 }
296
297 }
298
299 $link_files = $this->list_sync_media();
300 $unlink_files = $this->list_unlinks();
301 $link_files_count = count( $link_files );
302 $unlink_files_count = count( $unlink_files );
303
304 // CONTENT & FORMS
305 ?>
306 <div class="right">
307 <?php
308 if ( isset( $_POST['action'] ) && $action == "scan" ) {
309 echo '<pre>';
310 print_r( $unlinks );
311 echo '</pre>';
312 }
313 else if ( isset( $_POST['action'] ) && $action == "list" ) {
314 echo '<pre>';
315 print_r( $list );
316 echo '</pre>';
317 }
318 else if ( isset( $_POST['action'] ) && $action == "linkinfo_upload" ) {
319 echo '<pre>';
320 print_r( $linkinfo );
321 echo '</pre>';
322 }
323 else if ( isset( $_POST['duplicates'] ) && $action == "list" ) {
324
325
326
327 echo '<pre>';
328 print_r( $list );
329 echo '</pre>';
330 }
331 ?>
332 </div>
333
334 <div class="left">
335 <div style="font-weight: bold;"><?php echo $link_files_count ?> linked files out of <?php echo ( $link_files_count + $unlink_files_count ) ?> media files.</div>
336
337 <h3>Link</h3>
338 <p>Will link the WP Media ID to the Lr ID.</p>
339 <form class="wplrsync-form" method="post" action="" enctype="multipart/form-data">
340 <input type="hidden" name="action" value="link">
341 <table>
342 <tr>
343 <th scope="row"><label for="lr_id">Lr ID</label></th>
344 <td><input name="lr_id" type="text" id="lr_id" value="" class="regular-text code"></td>
345 </tr>
346 <tr>
347 <th scope="row"><label for="wp_id">Media ID</label></th>
348 <td><input name="wp_id" type="text" id="wp_id" value="" class="regular-text code"></td>
349 </tr>
350 <tr>
351 <th scope="row"></th>
352 <td><input type="submit" name="submit" id="submit" class="button button-primary" value="Link Media ID + Lr ID"></td>
353 </tr>
354 </table>
355
356 </form>
357
358 <h3>Unlink</h3>
359 <p>Will unlink the media.</p>
360 <form class="wplrsync-form" method="post" action="">
361 <input type="hidden" name="action" value="unlink">
362 <table>
363 <tr>
364 <th scope="row"><label for="lr_id">Lr ID</label></th>
365 <td><input name="lr_id" type="text" id="lr_id" value="" class="regular-text code"></td>
366 </tr>
367 <tr>
368 <th scope="row"><label for="wp_id">Media ID</label></th>
369 <td><input name="wp_id" type="text" id="wp_id" value="" class="regular-text code"></td>
370 </tr>
371 <tr>
372 <th scope="row"></th>
373 <td><input type="submit" name="submit" id="submit" class="button button-primary" value="Unlink"></td>
374 </tr>
375 </table>
376 </form>
377
378 <h3>Sync</h3>
379 <p>Will create the entry if doesn't exist, will update it if exists.</p>
380 <form class="wplrsync-form" method="post" action="" enctype="multipart/form-data">
381 <input type="hidden" name="action" value="sync">
382 <table>
383 <tr>
384 <th scope="row"><label for="lr_id">Lr ID</label></th>
385 <td><input name="lr_id" type="text" id="lr_id" value="" class="regular-text code"></td>
386 </tr>
387 <tr>
388 <th scope="row"><label for="title">Title</label></th>
389 <td><input name="title" type="text" id="title" class="regular-text code"></td>
390 </tr>
391 <tr>
392 <th scope="row"><label for="title">Caption</label></th>
393 <td><input name="caption" type="text" id="caption" class="regular-text code"></td>
394 </tr>
395 <tr>
396 <th scope="row"><label for="title">Desc</label></th>
397 <td><input name="desc" type="text" id="desc" class="regular-text code"></td>
398 </tr>
399 <tr>
400 <th scope="row"><label for="title">Alt</label></th>
401 <td><input name="altText" type="text" id="altText" class="regular-text code"></td>
402 </tr>
403 <tr>
404 <th scope="row"><label for="file">File</label></th>
405 <td><input name="file" type="file" id="file"></td>
406 </tr>
407 <tr>
408 <th scope="row"><label for="sync">Sync</label></th>
409 <td>
410 <label><input type="checkbox" id="syncTitle" name="syncTitle">Title</label>
411 <label><input type="checkbox" id="syncCaption" name="syncCaption">Caption</label>
412 <label><input type="checkbox" id="syncDesc" name="syncDesc">Desc</label>
413 <label><input type="checkbox" id="syncAltText" name="syncAltText">Alt</label>
414 </td>
415 </tr>
416 <tr>
417 <th scope="row"></th>
418 <td><input type="submit" name="submit" id="submit" class="button button-primary" value="Sync Media"></td>
419 </tr>
420 </table>
421 </form>
422
423 <h3>Remove</h3>
424 <p>Will remove the media.</p>
425 <form class="wplrsync-form" method="post" action="">
426 <input type="hidden" name="action" value="remove">
427 <table>
428 <tr>
429 <th scope="row"><label for="lr_id">Lr ID</label></th>
430 <td><input name="lr_id" type="text" id="lr_id" value="" class="regular-text code"></td>
431 </tr>
432 <tr>
433 <th scope="row"></th>
434 <td><input type="submit" name="submit" id="submit" class="button button-primary" value="Remove Media"></td>
435 </tr>
436 </table>
437 </form>
438
439 <h3>Link info</h3>
440 <p>Link info for either a WP ID <b>or</b> the Uploaded File.</p>
441 <form class="wplrsync-form" method="post" action="" enctype="multipart/form-data">
442 <input type="hidden" name="action" value="linkinfo_upload">
443 <table>
444 <tr>
445 <th scope="row"><label for="wp_id">WP ID</label></th>
446 <td><input name="wp_id" type="text" id="wp_id" value="" class="regular-text code"></td>
447 </tr>
448 <tr>
449 <th scope="row"><label for="file">File</label></th>
450 <td><input name="file" type="file" id="file"></td>
451 </tr>
452 <tr>
453 <th scope="row"></th>
454 <td><input type="submit" name="submit" id="submit" class="button button-primary" value="Check"></td>
455 </tr>
456 </table>
457 </form>
458
459 </div>
460 </div>
461 </div>
462 <?php
463 }
464 }
465
466 ?>