Changeset 1011291
- Timestamp:
- 10/21/2014 09:56:54 AM (11 years ago)
- Location:
- media-file-manager/trunk
- Files:
-
- 2 edited
-
media-relocator.js (modified) (7 diffs)
-
media-relocator.php (modified) (16 diffs)
Legend:
- Unmodified
- Added
- Removed
-
media-file-manager/trunk/media-relocator.js
r844441 r1011291 86 86 this.checked_loc = -1; 87 87 this.last_div_id = ""; 88 this.chk_prepare_id = 0;88 this.chk_prepare_id = -1; 89 89 this.opposite=this; 90 90 … … 222 222 //if (this.flg_chkbox) { 223 223 function callMethod_chkprepare() {that.prepare_checkboxes();} 224 this.chk_prepare_id = setInterval(callMethod_chkprepare, 20); 224 if (this.chk_prepare_id == -1) { 225 this.chk_prepare_id = setInterval(callMethod_chkprepare, 20); 226 } 225 227 //} 226 228 jQuery('#'+this.id_wrapper).css('cursor:default'); 227 229 return dir; 228 230 } 229 230 231 231 232 … … 239 240 if (jQuery('#'+this.last_div_id).length>0) { 240 241 clearInterval(this.chk_prepare_id); 242 this.chk_prepare_id = -1; 241 243 242 244 for (i=0; i<this.dir_disp_list.length; i++) { … … 408 410 // description : moving checked files/directories 409 411 // argument : (pane_from)pane object; (pane_to)pane object 410 function mrloc_move(pane_from, pane_to) 411 { 412 var global_pane_from = ""; 413 var global_pane_to = ""; 414 var global_num_par_no = 0; 415 var global_move_no = 0; 416 var global_move_cnt = 0; 417 var global_move_continue=0; 418 function mrloc_move(pane_from, pane_to, no) 419 { 420 no = typeof no !== 'undefined' ? no : 0; 421 var cnt = global_move_cnt; 422 423 if (no==0) { 424 global_pane_from = pane_from; 425 global_pane_to = pane_to; 426 global_move_cnt = 0; 427 mrloc_move(pane_from, pane_to, 1); 428 return; 429 } 430 431 var num_par_no = 50; 432 global_num_par_no = num_par_no; 433 global_move_continue = 0; 434 var no_from = (no-1)*num_par_no; 435 var no_to = no_from + num_par_no-1; 436 437 //alert(no+" "+global_pane_from.cur_dir+"-"+global_pane_to.cur_dir+" "+no_from+"-"+no_to); 438 439 412 440 var i,j; 413 441 var flist=""; … … 415 443 if (pane_from.cur_dir == pane_to.cur_dir) return; 416 444 445 var chk_no = -1; 417 446 // make list of checked item 418 447 for (i=0; i<pane_from.dir_disp_list.length; i++) { 419 448 var attr = jQuery('#'+pane_from.get_chkid(i)).attr('checked'); 420 449 if (attr=='checked' || attr===true) { 450 chk_no ++; 451 if (chk_no<no_from) continue; 452 if (chk_no>no_to) { 453 global_move_continue = 1; 454 continue; 455 } 456 cnt++; 421 457 flist += pane_from.dir_list[pane_from.dir_disp_list[i]].name + "/"; 422 458 for (j=0; j<pane_from.dir_list.length; j++) { … … 427 463 } 428 464 } 429 if (flist=="") return; 465 466 if (flist=="") { 467 if (no == 1) { 468 return; 469 } 470 } 430 471 flist = flist.substr(0, flist.length-1); 472 //alert(flist); 431 473 432 474 var data = { … … 436 478 items: flist 437 479 }; 438 mrl_ajax_in(); 480 481 global_move_no = no; 482 global_move_cnt = cnt; 483 484 if (no == 1) { 485 mrl_ajax_in(); 486 } 439 487 jQuery.post(ajaxurl, data, function(response) { 440 488 if (response.search(/Success/i) < 0) alert("mrloc_move(): "+response); 441 pane_left.refresh(); 442 pane_right.refresh(); 443 mrl_ajax_out(); 489 if (global_move_continue) { 490 mrloc_move(global_pane_from, global_pane_to, global_move_no+1); 491 } else { 492 pane_left.refresh(); 493 pane_right.refresh(); 494 mrl_ajax_out(); 495 } 444 496 }); 445 497 } -
media-file-manager/trunk/media-relocator.php
r1007641 r1011291 4 4 Plugin URI: http://tempspace.net/plugins/?page_id=111 5 5 Description: You can make sub-directories in the upload directory, and move files into them. At the same time, this plugin modifies the URLs/path names in the database. Also an alternative file-selector is added in the editing post/page screen, so you can pick up media files from the subfolders easily. 6 Version: 1.3. 06 Version: 1.3.1pre 7 7 Author: Atsushi Ueda 8 8 Author URI: http://tempspace.net/plugins/ … … 10 10 */ 11 11 12 set_time_limit(600); 13 12 14 if (!is_admin()) { 13 15 return; … … 16 18 define("MLOC_DEBUG", 0); 17 19 18 function dbg2($str){ }//{$fp=fopen("log.txt","a");fwrite($fp,$str . "\n");fclose($fp);}20 function dbg2($str){$fp=fopen("/tmp/log.txt","a");fwrite($fp,$str . "\n");fclose($fp);} 19 21 20 22 include 'set_document_root.php'; … … 38 40 39 41 40 // 設定メニューの追加42 // add a setting menu 41 43 add_action('admin_menu', 'mrelocator_plugin_menu'); 42 44 function mrelocator_plugin_menu() … … 51 53 for ($j=0; $j<count($roles); $j++) { 52 54 if ($accepted[$i] == $roles[$j]) { 53 /* 設定画面の追加*/55 /* add a configuration screen */ 54 56 add_submenu_page('upload.php', 'Media File Manager', 'Media File Manager', $roles[$j], 'mrelocator-submenu-handle', 'mrelocator_magic_function'); 55 57 return; … … 60 62 61 63 62 /* 設定画面出力*/64 /* show a configuration screen */ 63 65 function mrelocator_magic_function() 64 66 { … … 103 105 <div style="clear:both;"></div> 104 106 <div class="mrl_pane" id="mrl_right_pane"></div> 107 105 108 </div> 106 109 </div> … … 174 177 // set no-rename flag to prevent causing problem. 175 178 // (When "abc.jpg" and "abc.jpg.jpg" exist, and rename "abc.jpg", "abc.jpg.jpg" in posts will be affected.) 176 for ($i=0; $i<count($dir0); $i++) { 179 usort($dir1, "mrelocator_dircmp"); 180 for ($i=0; $i<count($dir1); $i++) { 177 181 $dir1[$i]['norename'] = 0; 178 for ($j=0; $j<count($dir1); $j++) { 179 if ($j==$i) continue; 182 } 183 for ($i=0; $i<count($dir1); $i++) { 184 for ($j=$i+1; $j<count($dir1); $j++) { 180 185 if (!$dir1[$i]['isdir'] && !$dir1[$i]['isdir']) { 181 186 if (strpos($dir1[$j]['name'], $dir1[$i]['name'])===0) { 182 187 $dir1[$i]['norename'] = 1; 188 break; 189 } else { 190 break; 183 191 } 184 192 } 185 193 } 186 194 } 187 usort($dir1, "mrelocator_dircmp"); 195 usort($dir1, "mrelocator_dircmp_r"); 196 $sql = "select a.post_id, a.meta_value as meta_value_a, b.meta_value as meta_value_b, c.meta_value as meta_value_c " . 197 "from $wpdb->postmeta a " . 198 "left join $wpdb->postmeta b on a.post_id=b.post_id and b.meta_key='_wp_attachment_metadata' " . 199 "left join $wpdb->postmeta c on a.post_id=b.post_id and c.meta_key='_wp_attachment_backup_sizes' " . 200 "where a.meta_value in ("; 201 for ($i=count($dir1)-1; $i>=0; $i--) { 202 $subdir_fn = mrelocator_get_subdir($dir) . $dir1[$i]['name']; 203 $sql .= "'".$subdir_fn."'"; 204 if ($i>0) $sql .= ","; 205 } 206 $sql .= ")"; 207 $dbres_all = $wpdb->get_results($sql); 208 209 $idx_subdir_fn = array(); 210 for ($i=0; $i<count($dbres_all); $i++) { 211 $subdir_fn = $dbres_all[$i]->meta_value_a; 212 $idx_subdir_fn[$subdir_fn] = $i; 213 } 214 215 $idx_dir1 = array(); 216 for ($i=0; $i<count($dir1); $i++) { 217 $idx_dir1[$dir1[$i]['name']] = $i; 218 } 219 188 220 for ($i=count($dir1)-1; $i>=0; $i--) { 189 221 $dir1[$i]['id'] = ""; … … 203 235 if ($dir1[$i]['isthumb']==1 || $dir1[$i]['isdir']==1) {continue;} 204 236 $subdir_fn = mrelocator_get_subdir($dir) . $dir1[$i]['name']; 205 $dbres =$wpdb->get_results("select post_id from $wpdb->postmeta where meta_value='".$subdir_fn."'");237 @$db_idx = $idx_subdir_fn[$subdir_fn]; //$wpdb->get_results("select post_id from $wpdb->postmeta where meta_value='".$subdir_fn."'"); 206 238 $dir1[$i]['parent'] = ""; 207 239 $dir1[$i]['thumbnail'] = ""; 208 240 $dir1[$i]['thumbnail_url'] = ""; 209 if (count($dbres)) { 210 $dir1[$i]['id'] = $dbres[0]->post_id; 211 $res = wp_get_attachment_metadata( $dbres[0]->post_id ); 241 242 //if (count($dbres_all[$db_idx])) { 243 if (!is_null($db_idx)) { 244 $dir1[$i]['id'] = $dbres_all[$db_idx]->post_id; 245 $res = unserialize($dbres_all[$db_idx]->meta_value_b);//wp_get_attachment_metadata( $dbres_all[$db_idx]->post_id ); 212 246 if (!is_array($res)) { 213 247 //mrelocator_log(print_r($res,true)); … … 220 254 $min_child = -1; 221 255 foreach ($res['sizes'] as $key => $value) { 222 for ($j=0; $j<count($dir1); $j++) { 223 if ($dir1[$j]['name'] == $res['sizes'][$key]['file']) { 224 $dir1[$j]['parent'] = $i; 225 $dir1[$j]['isthumb'] = 1; 226 $size = $res['sizes'][$key]['width']*$res['sizes'][$key]['height']; 227 if ($size < $min_size || $min_size==-1) { 228 $min_size = $size; 229 $min_child = $j; 230 } 231 break; 256 $j = $idx_dir1[$res['sizes'][$key]['file']]; 257 if (!is_null($j)) { 258 $dir1[$j]['parent'] = $i; 259 $dir1[$j]['isthumb'] = 1; 260 $size = $res['sizes'][$key]['width']*$res['sizes'][$key]['height']; 261 if ($size < $min_size || $min_size==-1) { 262 $min_size = $size; 263 $min_child = $j; 232 264 } 233 265 } … … 235 267 $dir1[$i]['thumbnail'] = $min_child; 236 268 $dir1[$i]['thumbnail_url'] = mrelocator_path2url($dir . $dir1[$min_child]['name']); 237 $backup_sizes = get_post_meta( $dbres[0]->post_id, '_wp_attachment_backup_sizes', true );238 $meta = wp_get_attachment_metadata( $dbres[0]->post_id );269 $backup_sizes = unserialize($dbres_all[$db_idx]->meta_value_c); //get_post_meta( $dbres_all[$db_idx]->post_id, '_wp_attachment_backup_sizes', true ); 270 //$meta = wp_get_attachment_metadata( $dbres_all[$db_idx]->post_id ); 239 271 if ( is_array($backup_sizes) ) { 240 272 foreach ( $backup_sizes as $size ) { 241 for ($j=0; $j<count($dir1); $j++) { 242 if ($dir1[$j]['name'] == $size['file']) { 243 $dir1[$j]['parent'] = $i; 244 $dir1[$j]['isthumb'] = 1; 245 break; 246 } 273 $j = $idx_dir1[$size['file']]; 274 if (!is_null($j)) { 275 $dir1[$j]['parent'] = $i; 276 $dir1[$j]['isthumb'] = 1; 247 277 } 248 278 } … … 260 290 } 261 291 } 292 //dbg2("mrelocator_getdir_callback end ".date("l jS \of F Y h:i:s A")); 262 293 echo json_encode($dir1); 263 294 264 if ($errflg) mrelocator_log(json_encode($dir1));295 //if ($errflg) mrelocator_log(json_encode($dir1)); 265 296 266 297 die(); … … 270 301 271 302 function mrelocator_dircmp($a, $b) 303 { 304 $ret = $b['isdir'] - $a['isdir']; 305 if ($ret) return $ret; 306 return strcasecmp($b['name'], $a['name']); 307 } 308 309 function mrelocator_dircmp_r($a, $b) 272 310 { 273 311 $ret = $b['isdir'] - $a['isdir']; … … 275 313 return strcasecmp($a['name'], $b['name']); 276 314 } 277 278 315 279 316 function mrelocator_mkdir_callback() … … 325 362 function mrelocator_rename_callback() 326 363 { 327 //rename ('/home/ued/public_html/w/wp-content/uploads/2011','/home/ued/public_html/w/wp-content/uploads/2011aaaa');die();328 329 364 global $wpdb; 330 365 global $mrelocator_uploaddir; … … 332 367 333 368 ignore_user_abort(true); 334 set_time_limit( 900);369 set_time_limit(1800); 335 370 ini_set("track_errors",true); 336 371
Note: See TracChangeset
for help on using the changeset viewer.