コード例 #1
0
/**
 * Check writeability
 */
function ns_log_check($logfile, $savefile = true)
{
    if (!empty($logfile) && !file_exists($logfile)) {
        $handle = @fopen($logfile, 'w') or ns_add_admin_notice(sprintf(__('Unable to create log file %s. Functionality will work, but you won\'t have logs in case anything needs debugging. Is that file\'s parent directory writable by the server?', 'ns-cloner'), $logfile), "error", "all", is_network_admin());
        @fclose($handle);
        if (file_exists($logfile) && !$savefile) {
            unlink($logfile);
        }
    }
}
コード例 #2
0
ファイル: ns-cloner.php プロジェクト: AlexanderDolgan/ojahuri
 function set_up_target_vars($target_id, $vars = array('id', 'prefix', 'subd', 'title', 'upload_dir', 'upload_url', 'url'))
 {
     //db
     if (is_null($this->target_db)) {
         global $wpdb;
         $default_db_creds = array('host' => DB_HOST, 'name' => DB_NAME, 'user' => DB_USER, 'password' => DB_PASSWORD);
         $target_db_creds = apply_filters('ns_cloner_target_db_credentials', $default_db_creds, $this);
         if ($target_db_creds !== $default_db_creds) {
             $this->target_db = @new ns_wpdb($target_db_creds['user'], $target_db_creds['password'], $target_db_creds['name'], $target_db_creds['host']);
             if (!empty($this->target_db->last_error)) {
                 $this->dlog("Could not connect to and select the target database. Error:" . $this->target_db->last_error);
                 if (is_network_admin()) {
                     ns_add_admin_notice(__("Could not connect to and select the target database", "ns-cloner"), "error", $this->menu_slug, true);
                     wp_redirect(wp_get_referer());
                     exit;
                 }
             }
         } else {
             $this->target_db = $wpdb;
         }
     }
     //ids
     if (in_array('id', $vars)) {
         $this->target_id = $this->report[__("New Site ID", "ns-cloner")] = $target_id;
         $this->dlog("Setting target id: " . $this->target_id);
     }
     //db prefixes
     if (in_array('prefix', $vars)) {
         $this->target_prefix = $target_id == 1 ? $this->target_db->base_prefix : $this->target_db->base_prefix . $target_id . '_';
         $this->dlog("Setting target prefix: " . $this->target_prefix);
     }
     //subdomains/dirs
     if (in_array('subd', $vars)) {
         $this->target_subd = untrailingslashit(get_blog_details($this->target_id)->domain . get_blog_details($this->target_id)->path);
         $this->dlog("Setting target subdomain/subdirectory: " . $this->target_subd);
     }
     //titles
     if (in_array('title', $vars)) {
         $this->target_title = get_blog_details($this->target_id)->blogname;
         $this->dlog("Setting target site title: " . $this->target_title);
     }
     //upload dirs
     if (in_array('upload_dir', $vars)) {
         $this->target_upload_dir = ns_get_upload_dir($this->target_id, NS_CLONER_LOG_FILE_DETAILED);
         $this->target_upload_dir_relative = str_replace(ns_norm_winpath(ABSPATH), '', $this->target_upload_dir);
         $this->dlog("Setting target full upload dir path: " . $this->target_upload_dir . " and shorter relative path: " . $this->target_upload_dir_relative);
     }
     //upload urls
     if (in_array('upload_url', $vars)) {
         $this->target_upload_url = ns_get_upload_url($this->target_id, NS_CLONER_LOG_FILE_DETAILED);
         $this->target_upload_url_relative = str_replace(get_site_url($this->target_id) . '/', '', $this->target_upload_url);
         $this->dlog("Setting target full upload url: " . $this->target_upload_url . " and shorter relative url: " . $this->target_upload_url_relative);
     }
     //urls
     if (in_array('url', $vars)) {
         $this->target_url = $this->report[__('New Site', 'ns-cloner')] = get_blog_details($this->target_id, true)->siteurl;
         $this->dlog("Setting target url " . $this->target_url);
     }
 }