Ejemplo n.º 1
0
 /**
  * Returns upload info
  *
  * @return array
  */
 public static function upload_info()
 {
     static $upload_info = null;
     if ($upload_info === null) {
         $upload_info = Util_Environment::wp_upload_dir();
         if (empty($upload_info['error'])) {
             $parse_url = @parse_url($upload_info['baseurl']);
             if ($parse_url) {
                 $baseurlpath = !empty($parse_url['path']) ? trim($parse_url['path'], '/') : '';
             } else {
                 $baseurlpath = 'wp-content/uploads';
             }
             $upload_info['baseurlpath'] = '/' . $baseurlpath . '/';
         } else {
             $upload_info = false;
         }
     }
     return $upload_info;
 }
 /**
  * Generates rules for WP dir
  *
  * @param Config  $config
  * @return string
  */
 private static function rules_generate_nginx($config)
 {
     $a = Util_Environment::wp_upload_dir();
     $parse_url = @parse_url($a['baseurl']);
     if (empty($parse_url['path'])) {
         return '';
     }
     $uploads_path = $parse_url['path'];
     $rules = W3TC_MARKER_BEGIN_FEEDBURNER . "\n";
     $rules .= "if (\$http_user_agent ~* \"(FeedBurner)\") {\n";
     $rules .= "    rewrite ^{$uploads_path}/([0-9]+)/([0-9]+)/hotlink-ok/(.*)\$ {$uploads_path}/\$1/\$2/\$3 last;\n";
     $rules .= "}\n";
     $rules .= W3TC_MARKER_END_FEEDBURNER . "\n";
     return $rules;
 }
Ejemplo n.º 3
0
 /**
  * Convert local uri path to CDN type specific path
  *
  * @param unknown $local_uri_path
  * @return string
  */
 function uri_to_cdn_uri($local_uri)
 {
     $local_uri = ltrim($local_uri, '/');
     $remote_uri = $local_uri;
     if (Util_Environment::is_wpmu() && defined('DOMAIN_MAPPING') && DOMAIN_MAPPING) {
         $remote_uri = str_replace(site_url(), '', $local_uri);
     }
     $engine = $this->_config->get_string('cdn.engine');
     if (Cdn_Util::is_engine_mirror($engine)) {
         if (Util_Environment::is_wpmu() && strpos($local_uri, 'files') === 0) {
             $upload_dir = Util_Environment::wp_upload_dir();
             $remote_uri = $this->abspath_to_relative_path(dirname($upload_dir['basedir'])) . '/' . $local_uri;
         }
     } elseif (Util_Environment::is_wpmu() && !Util_Environment::is_wpmu_subdomain() && Util_Environment::is_using_master_config() && Cdn_Util::is_engine_push($engine)) {
         // in common config files are uploaded for network home url
         // so mirror will not contain /subblog/ path in uri
         $home = trim(home_url('', 'relative'), '/') . '/';
         $network_home = trim(network_home_url('', 'relative'), '/') . '/';
         if ($home != $network_home && substr($local_uri, 0, strlen($home)) == $home) {
             $remote_uri = $network_home . substr($local_uri, strlen($home));
         }
     }
     return ltrim($remote_uri, '/');
 }
Ejemplo n.º 4
0
 static function replace_folder_placeholders($file)
 {
     static $content_dir, $plugin_dir, $upload_dir;
     if (empty($content_dir)) {
         $content_dir = str_replace(Util_Environment::document_root(), '', WP_CONTENT_DIR);
         $content_dir = substr($content_dir, strlen(Util_Environment::site_url_uri()));
         $content_dir = trim($content_dir, '/');
         if (defined('WP_PLUGIN_DIR')) {
             $plugin_dir = str_replace(Util_Environment::document_root(), '', WP_PLUGIN_DIR);
             $plugin_dir = trim($plugin_dir, '/');
         } else {
             $plugin_dir = str_replace(Util_Environment::document_root(), '', WP_CONTENT_DIR . '/plugins');
             $plugin_dir = trim($plugin_dir, '/');
         }
         $upload_dir = Util_Environment::wp_upload_dir();
         $upload_dir = str_replace(Util_Environment::document_root(), '', $upload_dir['basedir']);
         $upload_dir = trim($upload_dir, '/');
     }
     $file = str_replace('{wp_content_dir}', $content_dir, $file);
     $file = str_replace('{plugins_dir}', $plugin_dir, $file);
     $file = str_replace('{uploads_dir}', $upload_dir, $file);
     return $file;
 }