Example #1
0
function ns_get_upload_dir($id, $logfile = false)
{
    // ---------------------------------------------------------------------------------------------------------------------
    //										T E S T I N G  	 N E W    C O D E
    // ---------------------------------------------------------------------------------------------------------------------
    // initialize
    switch_to_blog($id);
    $wp_upload_dir_a = wp_upload_dir();
    restore_current_blog();
    $wp_upload_dir = ns_norm_winpath($wp_upload_dir_a['basedir']);
    $upload_dir = '';
    // eventual return value
    // handle difference between ID = 1 and everything else
    // in ID = 1 test_1 and test_2 are identical
    if ($id == 1) {
        $test_1_base = ns_norm_winpath(WP_CONTENT_DIR . '/uploads');
        $test_1_upload_dir = ns_norm_winpath($test_1_base);
        $test_2_base = ns_norm_winpath(WP_CONTENT_DIR . '/uploads');
        $test_2_upload_dir = ns_norm_winpath($test_2_base);
    } else {
        $test_1_base = ns_norm_winpath(WP_CONTENT_DIR . '/blogs.dir');
        $test_1_upload_dir = ns_norm_winpath($test_1_base . '/' . $id . '/files');
        $test_2_base = ns_norm_winpath(WP_CONTENT_DIR . '/uploads/sites');
        $test_2_upload_dir = ns_norm_winpath($test_2_base . '/' . $id);
    }
    // compare and set conditions for determining confidence level
    $test_1_base_exists = file_exists($test_1_base) ? true : false;
    $test_1_upload_dir_exists = file_exists($test_1_upload_dir) ? true : false;
    $test_1_matches_wp = $test_1_upload_dir == $wp_upload_dir ? true : false;
    $test_2_base_exists = file_exists($test_2_base) ? true : false;
    $test_2_upload_dir_exists = file_exists($test_2_upload_dir) ? true : false;
    $test_2_matches_wp = $test_2_upload_dir == $wp_upload_dir ? true : false;
    $wp_upload_dir_exists = file_exists($wp_upload_dir) ? true : false;
    // cascade in order of confidence
    // HIGH CONFIDENCE ----------------------------------------------------------------------------------
    // WP Origin < 3.5
    if ($test_1_base_exists && $test_1_upload_dir_exists && $test_1_matches_wp) {
        $upload_dir = $test_1_upload_dir;
        $confidence = 'HIGH CONFIDENCE';
    }
    // WP Origin > 3.5 (fall through if $upload_dir already set)
    if ($upload_dir == '' && $test_2_base_exists && $test_2_upload_dir_exists && $test_2_matches_wp) {
        $upload_dir = $test_2_upload_dir;
        $confidence = 'HIGH CONFIDENCE';
    }
    // MEDIUM CONFIDENCE --------------------------------------------------------------------------------
    // WP Origin < 3.5 (fall through if $upload_dir already set)
    if ($upload_dir == '' && $test_1_base_exists && $test_1_matches_wp) {
        $upload_dir = $test_1_upload_dir;
        $confidence = 'MEDIUM CONFIDENCE';
    }
    // WP Origin > 3.5 (fall through if $upload_dir already set)
    if ($upload_dir == '' && $test_2_base_exists && $test_2_matches_wp) {
        $upload_dir = $test_2_upload_dir;
        $confidence = 'MEDIUM CONFIDENCE';
    }
    // LOW CONFIDENCE -----------------------------------------------------------------------------------
    // WP Origin < 3.5 (fall through if $upload_dir already set)
    if ($upload_dir == '' && $test_1_base_exists) {
        $upload_dir = $test_1_upload_dir;
        $confidence = 'LOW CONFIDENCE';
    }
    // WP Origin > 3.5 (fall through if $upload_dir already set)
    if ($upload_dir == '' && $test_2_base_exists) {
        $upload_dir = $test_2_upload_dir;
        $confidence = 'LOW CONFIDENCE';
    }
    // FAIL SAFE ----------------------------------------------------------------------------------------
    if ($upload_dir == '') {
        $upload_dir = $wp_upload_dir;
        $confidence = 'FAIL SAFE';
    }
    // log results for debugging
    ns_log_section_break($logfile);
    ns_log_write('TESTING UPLOAD LOCATION for ID = ' . $id, $logfile);
    ns_log_section_break($logfile);
    ns_log_write('wp_upload_dir	     = ' . $wp_upload_dir . ns_t2e($wp_upload_dir_exists), $logfile);
    ns_log_write('test_1_base        = ' . $test_1_base . ns_t2e($test_1_base_exists), $logfile);
    ns_log_write('test_1_upload_dir  = ' . $test_1_upload_dir . ns_t2e($test_1_upload_dir_exists), $logfile);
    ns_log_write('test_1_matches_wp  = ' . ns_t2e($test_1_matches_wp), $logfile);
    ns_log_write('test_2_base        = ' . $test_2_base . ns_t2e($test_2_base_exists), $logfile);
    ns_log_write('test_2_upload_dir  = ' . $test_2_upload_dir . ns_t2e($test_2_upload_dir_exists), $logfile);
    ns_log_write('test_2_matches_wp  = ' . ns_t2e($test_2_matches_wp), $logfile);
    ns_log_write('<b>upload_dir = ' . $upload_dir . '</b> with ' . $confidence, $logfile);
    ns_log_section_break($logfile);
    return $upload_dir;
}
Example #2
0
 public function dlog_break($debug_only = false)
 {
     $is_ajax = $this->current_action == "ajax_validate" || defined('DOING_AJAX') && DOING_AJAX == true;
     $is_extra_debug_on = isset($this->request["debug"]) && $this->request["debug"] == true;
     if (($debug_only == true || $is_ajax) && !$is_extra_debug_on) {
         return;
     }
     ns_log_section_break(NS_CLONER_LOG_FILE_DETAILED);
 }
Example #3
0
/**
 * Diagnostics
 */
function ns_diag($logfile)
{
    global $wp_version, $wp_db_version, $required_php_version, $required_mysql_version;
    ns_log_write("ENVIRONMENT DIAGNOSTICS:", $logfile);
    ns_log_write("Web Server Info:", $logfile);
    ns_log_write("PHP Version Required: <strong>" . $required_php_version . " </strong>", $logfile);
    ns_log_write("PHP Version Current: <strong>" . phpversion() . " </strong>", $logfile);
    ns_log_write("MySQL Version Required: <strong>" . $required_mysql_version . " </strong>", $logfile);
    ns_log_write("MySQL Version Current: <strong>" . ns_get_mysql_variable('version') . " </strong>", $logfile);
    ns_log_write("WP Version: <strong>{$wp_version}</strong>", $logfile);
    ns_log_write("WP Memory Limit: <strong>" . WP_MEMORY_LIMIT . " </strong>", $logfile);
    ns_log_write("WP Debug Mode: <strong>" . WP_DEBUG . " </strong>", $logfile);
    ns_log_write("WP Multisite: <strong>" . MULTISITE . " </strong>", $logfile);
    ns_log_write("WP Subdomain Install: <strong>" . SUBDOMAIN_INSTALL . " </strong>", $logfile);
    ns_log_write("PHP Post Max Size: <strong>" . ini_get('post_max_size') . " </strong>", $logfile);
    ns_log_write("PHP Upload Max Size: <strong>" . ini_get('upload_max_size') . " </strong>", $logfile);
    ns_log_write("PHP Memory Limit: <strong>" . ini_get('memory_limit') . " </strong>", $logfile);
    ns_log_write("PHP Max Input Vars: <strong>" . ini_get('max_input_vars') . " </strong>", $logfile);
    ns_log_write("PHP Max Execution Time: <strong>" . ini_get('max_execution_time') . " </strong>", $logfile);
    ns_log_section_break($logfile);
    ns_log_write("PLUGIN DIAGNOSTICS:", $logfile);
    foreach (get_plugins() as $plugin_file => $data) {
        ns_log_write("{$data['Name']} {$data['Version']} by {$data['Author']}" . ($data["Network"] == true ? " <strong>Network Enabled</strong>" : ""), $logfile);
    }
}