Plugin Directory

Changeset 1011291


Ignore:
Timestamp:
10/21/2014 09:56:54 AM (11 years ago)
Author:
aueda
Message:

media-file-manager_1.3.1pre

Location:
media-file-manager/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • media-file-manager/trunk/media-relocator.js

    r844441 r1011291  
    8686    this.checked_loc = -1;
    8787    this.last_div_id = "";
    88     this.chk_prepare_id = 0;
     88    this.chk_prepare_id = -1;
    8989    this.opposite=this;
    9090
     
    222222    //if (this.flg_chkbox) {
    223223        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        }
    225227    //}
    226228    jQuery('#'+this.id_wrapper).css('cursor:default');
    227229    return dir;
    228230}
    229 
    230231
    231232
     
    239240    if (jQuery('#'+this.last_div_id).length>0) {
    240241        clearInterval(this.chk_prepare_id);
     242        this.chk_prepare_id = -1;
    241243
    242244        for (i=0; i<this.dir_disp_list.length; i++) {
     
    408410// description : moving checked files/directories
    409411// argument : (pane_from)pane object; (pane_to)pane object
    410 function mrloc_move(pane_from, pane_to)
    411 {
     412var global_pane_from = "";
     413var global_pane_to = "";
     414var global_num_par_no = 0;
     415var global_move_no = 0;
     416var global_move_cnt = 0;
     417var global_move_continue=0;
     418function 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   
    412440    var i,j;
    413441    var flist="";
     
    415443    if (pane_from.cur_dir == pane_to.cur_dir) return;
    416444
     445    var chk_no = -1;
    417446    // make list of checked item
    418447    for (i=0; i<pane_from.dir_disp_list.length; i++) {
    419448        var attr = jQuery('#'+pane_from.get_chkid(i)).attr('checked');
    420449        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++;
    421457            flist += pane_from.dir_list[pane_from.dir_disp_list[i]].name + "/";
    422458            for (j=0; j<pane_from.dir_list.length; j++) {
     
    427463        }
    428464    }
    429     if (flist=="") return;
     465
     466    if (flist=="") {
     467        if (no == 1) {
     468            return;
     469        }
     470    }
    430471    flist = flist.substr(0, flist.length-1);
     472    //alert(flist);
    431473
    432474    var data = {
     
    436478        items: flist
    437479    };
    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    }
    439487    jQuery.post(ajaxurl, data, function(response) {
    440488        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        }
    444496    });
    445497}
  • media-file-manager/trunk/media-relocator.php

    r1007641 r1011291  
    44Plugin URI: http://tempspace.net/plugins/?page_id=111
    55Description: 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.0
     6Version: 1.3.1pre
    77Author: Atsushi Ueda
    88Author URI: http://tempspace.net/plugins/
     
    1010*/
    1111
     12set_time_limit(600);
     13
    1214if (!is_admin()) {
    1315    return;
     
    1618define("MLOC_DEBUG", 0);
    1719
    18 function dbg2($str){}//{$fp=fopen("log.txt","a");fwrite($fp,$str . "\n");fclose($fp);}
     20function dbg2($str){$fp=fopen("/tmp/log.txt","a");fwrite($fp,$str . "\n");fclose($fp);}
    1921
    2022include 'set_document_root.php';
     
    3840
    3941
    40 // 設定メニューの追加
     42// add a setting menu
    4143add_action('admin_menu', 'mrelocator_plugin_menu');
    4244function mrelocator_plugin_menu()
     
    5153        for ($j=0; $j<count($roles); $j++) {
    5254            if ($accepted[$i] == $roles[$j]) {
    53                 /*  設定画面の追加  */
     55                /*  add a configuration screen  */
    5456                add_submenu_page('upload.php', 'Media File Manager', 'Media File Manager', $roles[$j], 'mrelocator-submenu-handle', 'mrelocator_magic_function');
    5557                return;
     
    6062
    6163
    62 /*  設定画面出力  */
     64/*  show a configuration screen  */
    6365function mrelocator_magic_function()
    6466{
     
    103105                <div style="clear:both;"></div>
    104106                <div class="mrl_pane" id="mrl_right_pane"></div>
     107
    105108            </div>
    106109        </div>
     
    174177    // set no-rename flag to prevent causing problem.
    175178    // (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++) {
    177181        $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++) {
    180185            if (!$dir1[$i]['isdir'] && !$dir1[$i]['isdir']) {
    181186                if (strpos($dir1[$j]['name'], $dir1[$i]['name'])===0) {
    182187                    $dir1[$i]['norename'] = 1;
     188                    break;
     189                } else {
     190                    break;
    183191                }
    184192            }
    185193        }
    186194    }
    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   
    188220    for ($i=count($dir1)-1; $i>=0; $i--) {
    189221        $dir1[$i]['id'] = "";
     
    203235        if ($dir1[$i]['isthumb']==1 || $dir1[$i]['isdir']==1) {continue;}
    204236        $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."'");
    206238        $dir1[$i]['parent'] = "";
    207239        $dir1[$i]['thumbnail'] = "";
    208240        $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 );
    212246            if (!is_array($res)) {
    213247                //mrelocator_log(print_r($res,true));
     
    220254                    $min_child = -1;
    221255                    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;
    232264                            }
    233265                        }
     
    235267                    $dir1[$i]['thumbnail'] = $min_child;
    236268                    $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 );
    239271                    if ( is_array($backup_sizes) ) {
    240272                        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;
    247277                            }
    248278                        }
     
    260290        }
    261291    }
     292//dbg2("mrelocator_getdir_callback end ".date("l jS \of F Y h:i:s A"));
    262293    echo json_encode($dir1);
    263294   
    264     if ($errflg) mrelocator_log(json_encode($dir1));
     295    //if ($errflg) mrelocator_log(json_encode($dir1));
    265296
    266297    die();
     
    270301
    271302function 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
     309function mrelocator_dircmp_r($a, $b)
    272310{
    273311    $ret = $b['isdir'] - $a['isdir'];
     
    275313    return strcasecmp($a['name'], $b['name']);
    276314}
    277 
    278315
    279316function mrelocator_mkdir_callback()
     
    325362function mrelocator_rename_callback()
    326363{
    327 //rename ('/home/ued/public_html/w/wp-content/uploads/2011','/home/ued/public_html/w/wp-content/uploads/2011aaaa');die();
    328 
    329364    global $wpdb;
    330365    global $mrelocator_uploaddir;
     
    332367
    333368    ignore_user_abort(true);
    334     set_time_limit(900);
     369    set_time_limit(1800);
    335370    ini_set("track_errors",true);
    336371
Note: See TracChangeset for help on using the changeset viewer.