Plugin Directory

Changeset 1204026


Ignore:
Timestamp:
07/22/2015 03:19:29 PM (11 years ago)
Author:
Katsushi Kawamori
Message:

Supported moving uploads folder. Please edit the [wp-config.php](http://codex.wordpress.org/Editing_wp-config.php#Moving_uploads_folder). Please do not use other methods. Version 7.7

Location:
media-from-ftp/trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • media-from-ftp/trunk/inc/MediaFromFtp.php

    r1184254 r1204026  
    305305            $ext = end($exts);
    306306            $suffix_file = '.'.$ext;
    307             $new_url = site_url('/').str_replace(ABSPATH, '', $file);
     307            $file = str_replace('\\', '/', $file);
     308            $wordpress_path = str_replace('\\', '/', ABSPATH);
     309            $upload_path = str_replace('\\', '/', MEDIAFROMFTP_PLUGIN_UPLOAD_DIR);
     310            if ( strstr($file, $wordpress_path) ) {
     311                $new_url = site_url('/').str_replace($wordpress_path, '', $file);
     312            } else {
     313                $new_url = MEDIAFROMFTP_PLUGIN_UPLOAD_URL.str_replace($upload_path, '', $file);
     314            }
    308315            $new_titles = explode('/', $new_url);
    309316            $new_title = str_replace($suffix_file, '', end($new_titles));
     
    487494    }
    488495
     496    /* ==================================================
     497     * @param   string  $base
     498     * @param   string  $relationalpath
     499     * @return  string  realurl
     500     * @since   7.7
     501     */
     502    function realurl( $base, $relationalpath ){
     503         $parse = array(
     504              "scheme" => null,
     505              "user" => null,
     506              "pass" => null,
     507              "host" => null,
     508              "port" => null,
     509              "query" => null,
     510              "fragment" => null
     511         );
     512         $parse = parse_url( $base );
     513
     514         if( strpos($parse["path"], "/", (strlen($parse["path"])-1)) !== false ){
     515              $parse["path"] .= ".";
     516         }
     517
     518         if( preg_match("#^https?://#", $relationalpath) ){
     519              return $relationalpath;
     520         }else if( preg_match("#^/.*$#", $relationalpath) ){
     521              return $parse["scheme"] . "://" . $parse["host"] . $relationalpath;
     522         }else{
     523              $basePath = explode("/", dirname($parse["path"]));
     524              $relPath = explode("/", $relationalpath);
     525              foreach( $relPath as $relDirName ){
     526                   if( $relDirName == "." ){
     527                        array_shift( $basePath );
     528                        array_unshift( $basePath, "" );
     529                   }else if( $relDirName == ".." ){
     530                        array_pop( $basePath );
     531                        if( count($basePath) == 0 ){
     532                             $basePath = array("");
     533                        }
     534                   }else{
     535                        array_push($basePath, $relDirName);
     536                   }
     537              }
     538              $path = implode("/", $basePath);
     539              return $parse["scheme"] . "://" . $parse["host"] . $path;
     540         }
     541
     542    }
     543
    489544}
    490545
  • media-from-ftp/trunk/mediafromftp.php

    r1184254 r1204026  
    33Plugin Name: Media from FTP
    44Plugin URI: http://wordpress.org/plugins/media-from-ftp/
    5 Version: 7.6
     5Version: 7.7
    66Description: Register to media library from files that have been uploaded by FTP.
    77Author: Katsushi Kawamori
     
    3131    define("MEDIAFROMFTP_PLUGIN_BASE_DIR", dirname(__FILE__));
    3232    define("MEDIAFROMFTP_PLUGIN_URL", plugins_url($path='',$scheme=null).'/media-from-ftp');
     33
     34    include_once MEDIAFROMFTP_PLUGIN_BASE_DIR.'/inc/MediaFromFtp.php';
     35    $mediafromftp = new MediaFromFtp();
    3336    $wp_uploads = wp_upload_dir();
     37
     38    $relation_path_true = strpos($wp_uploads['baseurl'], '../');
     39    if ( $relation_path_true > 0 ) {
     40        $relationalpath = substr($wp_uploads['baseurl'], $relation_path_true);
     41        $basepath = substr($wp_uploads['baseurl'], 0, $relation_path_true);
     42        $upload_url = $mediafromftp->realurl($basepath, $relationalpath);
     43        define("MEDIAFROMFTP_PLUGIN_UPLOAD_DIR", realpath($wp_uploads['basedir']));
     44    } else {
     45        $upload_url = $wp_uploads['baseurl'];
     46        define("MEDIAFROMFTP_PLUGIN_UPLOAD_DIR", $wp_uploads['basedir']);
     47    }
     48    unset($mediafromftp);
     49
    3450    if(is_ssl()){
    35         define("MEDIAFROMFTP_PLUGIN_UPLOAD_URL", str_replace('http:', 'https:', $wp_uploads['baseurl']));
     51        define("MEDIAFROMFTP_PLUGIN_UPLOAD_URL", str_replace('http:', 'https:', $upload_url));
    3652    } else {
    37         define("MEDIAFROMFTP_PLUGIN_UPLOAD_URL", $wp_uploads['baseurl']);
     53        define("MEDIAFROMFTP_PLUGIN_UPLOAD_URL", $upload_url);
    3854    }
    39     define("MEDIAFROMFTP_PLUGIN_UPLOAD_DIR", $wp_uploads['basedir']);
    40     define("MEDIAFROMFTP_PLUGIN_UPLOAD_PATH", str_replace(site_url('/'), '', MEDIAFROMFTP_PLUGIN_UPLOAD_URL));
     55    if ( $relation_path_true > 0 ) {
     56        define("MEDIAFROMFTP_PLUGIN_UPLOAD_PATH", $relationalpath);
     57    } else {
     58        define("MEDIAFROMFTP_PLUGIN_UPLOAD_PATH", str_replace(site_url('/'), '', MEDIAFROMFTP_PLUGIN_UPLOAD_URL));
     59    }
    4160    define("MEDIAFROMFTP_PLUGIN_TMP_URL", MEDIAFROMFTP_PLUGIN_UPLOAD_URL.'/media-from-ftp-tmp');
    4261    define("MEDIAFROMFTP_PLUGIN_TMP_DIR", MEDIAFROMFTP_PLUGIN_UPLOAD_DIR.'/media-from-ftp-tmp');
  • media-from-ftp/trunk/mediafromftpcmd.php

    r1160562 r1204026  
    6767        define("MEDIAFROMFTP_PLUGIN_BASE_DIR", dirname(__FILE__));
    6868        $wp_uploads = wp_upload_dir();
     69        include_once MEDIAFROMFTP_PLUGIN_BASE_DIR.'/inc/MediaFromFtp.php';
     70        $mediafromftp = new MediaFromFtp();
     71        $wp_uploads = wp_upload_dir();
     72        $relation_path_true = strpos($wp_uploads['baseurl'], '../');
     73        if ( $relation_path_true > 0 ) {
     74            $relationalpath = substr($wp_uploads['baseurl'], $relation_path_true);
     75            $basepath = substr($wp_uploads['baseurl'], 0, $relation_path_true);
     76            $upload_url = $mediafromftp->realurl($basepath, $relationalpath);
     77            define("MEDIAFROMFTP_PLUGIN_UPLOAD_DIR", realpath($wp_uploads['basedir']));
     78        } else {
     79            $upload_url = $wp_uploads['baseurl'];
     80            define("MEDIAFROMFTP_PLUGIN_UPLOAD_DIR", $wp_uploads['basedir']);
     81        }
     82        unset($mediafromftp);
     83
    6984        if(is_ssl()){
    70             define("MEDIAFROMFTP_PLUGIN_UPLOAD_URL", str_replace('http:', 'https:', $wp_uploads['baseurl']));
     85            define("MEDIAFROMFTP_PLUGIN_UPLOAD_URL", str_replace('http:', 'https:', $upload_url));
    7186        } else {
    72             define("MEDIAFROMFTP_PLUGIN_UPLOAD_URL", $wp_uploads['baseurl']);
     87            define("MEDIAFROMFTP_PLUGIN_UPLOAD_URL", $upload_url);
    7388        }
    74         define("MEDIAFROMFTP_PLUGIN_UPLOAD_DIR", $wp_uploads['basedir']);
    7589    }
    7690
  • media-from-ftp/trunk/readme.txt

    r1184254 r1204026  
    55Requires at least: 3.6.0
    66Tested up to: 4.2
    7 Stable tag: 7.6
     7Stable tag: 7.7
    88License: GPLv2 or later
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    4747== Changelog ==
    4848
     49= 7.7 =
     50Supported moving uploads folder. Please edit the [wp-config.php](http://codex.wordpress.org/Editing_wp-config.php#Moving_uploads_folder). Please do not use other methods.
     51
    4952= 7.6 =
    5053Add thumbnails cache remove to uninstall script.
     
    309312== Upgrade Notice ==
    310313
     314= 7.7 =
    311315= 7.6 =
    312316= 7.5 =
  • media-from-ftp/trunk/req/MediaFromFtpAdmin.php

    r1184254 r1204026  
    407407            echo '<div class="updated"><ul><li>'.__('Settings saved.').'</li></ul></div>';
    408408        }
    409         if (!empty($_POST['searchdir'])){
    410             $searchdir = urldecode($_POST['searchdir']);
    411         }
    412409
    413410        $scriptname = admin_url('admin.php?page=mediafromftp-search-register');
    414411
    415         $document_root = ABSPATH.$searchdir;
     412        $document_root = realpath(ABSPATH.$searchdir);
     413
    416414        if( get_option('WPLANG') === 'ja' ) {
    417415            mb_language('Japanese');
     
    444442            $dirs = $mediafromftp->scan_dir(MEDIAFROMFTP_PLUGIN_UPLOAD_DIR);
    445443            $linkselectbox = NULL;
     444            $wordpress_path = str_replace("\\", "/", ABSPATH);
    446445            foreach ($dirs as $linkdir) {
    447                 $linkdirenc = mb_convert_encoding(str_replace(ABSPATH, "", $linkdir), "UTF-8", "auto");
     446                if ( strstr($linkdir, $wordpress_path ) ) {
     447                    $linkdirenc = mb_convert_encoding(str_replace($wordpress_path, '', $linkdir), "UTF-8", "auto");
     448                } else {
     449                    $linkdirenc = MEDIAFROMFTP_PLUGIN_UPLOAD_PATH.mb_convert_encoding(str_replace(MEDIAFROMFTP_PLUGIN_UPLOAD_DIR, "", $linkdir), "UTF-8", "auto");
     450                }
    448451                if( $searchdir === $linkdirenc ){
    449452                    $linkdirs = '<option value="'.urlencode($linkdirenc).'" selected>'.$linkdirenc.'</option>';
     
    888891                } else {
    889892                    $searchdir = $mediafromftp_settings['searchdir'];
     893                    if ( !strstr(realpath(ABSPATH.$searchdir),realpath(MEDIAFROMFTP_PLUGIN_UPLOAD_DIR)) ) {
     894                        $searchdir = MEDIAFROMFTP_PLUGIN_UPLOAD_PATH;
     895                    }
    890896                }
    891897                if (!empty($_POST['ext2type'])){
  • media-from-ftp/trunk/req/MediaFromFtpCron.php

    r1160562 r1204026  
    107107
    108108        $yearmonth_folders = get_option('uploads_use_yearmonth_folders');
    109         $document_root = ABSPATH.$searchdir;
     109        $document_root = realpath(ABSPATH.$searchdir);
    110110
    111111        if( get_option('WPLANG') === 'ja' ) {
Note: See TracChangeset for help on using the changeset viewer.