当前位置: 首页>>代码示例>>PHP>>正文


PHP Util_Environment::is_url方法代码示例

本文整理汇总了PHP中Util_Environment::is_url方法的典型用法代码示例。如果您正苦于以下问题:PHP Util_Environment::is_url方法的具体用法?PHP Util_Environment::is_url怎么用?PHP Util_Environment::is_url使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Util_Environment的用法示例。


在下文中一共展示了Util_Environment::is_url方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: minify_filename_to_urls_for_minification

 /**
  * Decode a minify auto filename into an array of files.
  *
  * @param unknown $compressed
  * @param unknown $type
  * @return array
  */
 public static function minify_filename_to_urls_for_minification($filename, $type)
 {
     $v = get_option('w3tc_minify');
     $minify_filenames = @json_decode($v, true);
     if (!is_array($minify_filenames)) {
         $minify_filenames = array();
     }
     $minify_filename = $filename . '.' . $type;
     if (!isset($minify_filenames[$minify_filename])) {
         return array();
     }
     $urls_unverified = $minify_filenames[$minify_filename];
     $urls = array();
     foreach ($urls_unverified as $file) {
         $verified = false;
         if (Util_Environment::is_url($file)) {
             $c = Dispatcher::config();
             $external = $c->get_array('minify.cache.files');
             foreach ($external as $ext) {
                 if (preg_match('#' . Util_Environment::get_url_regexp($ext) . '#', $file) && !$verified) {
                     $verified = true;
                 }
             }
             if (!$verified) {
                 Minify_Core::debug_error(sprintf('Remote file not in external files/libraries list: "%s"', $file));
             }
         } elseif (strpos($file, '..') != false || strpos($file, '//') !== false || strpos($file, '\\') !== false && strtoupper(substr(PHP_OS, 0, 3)) != 'WIN' || preg_match('/(?:^|[^\\.])\\.\\//', $file) || !preg_match('/^[a-zA-Z0-9_.\\/-]|[\\\\]+$/', $file)) {
             $verified = false;
             Minify_Core::debug_error(sprintf('File path invalid: "%s"', $file));
         } else {
             $verified = true;
         }
         if ($verified) {
             $urls[] = $file;
         }
     }
     return $urls;
 }
开发者ID:developmentDM2,项目名称:Whohaha,代码行数:45,代码来源:Minify_Core.php

示例2: is_file_for_minification

 /**
  * URL file filter
  *
  * @param string  $file
  * @return bool
  */
 public function is_file_for_minification($file)
 {
     static $external;
     if (!isset($external)) {
         $external = $this->config->get_array('minify.cache.files');
     }
     foreach ($external as $ext) {
         if (preg_match('#' . Util_Environment::get_url_regexp($ext) . '#', $file)) {
             if ($this->debug) {
                 Minify_Core::log('is_file_for_minification: whilelisted ' . $file);
             }
             return true;
         }
     }
     $file_normalized = Util_Environment::remove_query_all($file);
     $ext = strrchr($file_normalized, '.');
     if ($ext != '.js' && $ext != '.css') {
         if ($this->debug) {
             Minify_Core::log('is_file_for_minification: unknown extension ' . $ext . ' for ' . $file);
         }
         return false;
     }
     if (Util_Environment::is_url($file_normalized)) {
         if ($this->debug) {
             Minify_Core::log('is_file_for_minification: its url ' . $file);
         }
         return false;
     }
     $path = Util_Environment::document_root() . '/' . $file;
     if (!file_exists($path)) {
         if ($this->debug) {
             Minify_Core::log('is_file_for_minification: file doesnt exists ' . $path);
         }
         return false;
     }
     if ($this->debug) {
         Minify_Core::log('is_file_for_minification: true for file ' . $file . ' path ' . $path);
     }
     return true;
 }
开发者ID:eduardodomingos,项目名称:eduardodomingos.com,代码行数:46,代码来源:Minify_Plugin.php

示例3: parse_sitemap

 /**
  * Parses sitemap
  *
  * @param string  $url
  * @return array
  */
 function parse_sitemap($url)
 {
     if (!Util_Environment::is_url($url)) {
         $url = home_url($url);
     }
     $urls = array();
     $response = Util_Http::get($url);
     if (!is_wp_error($response) && $response['response']['code'] == 200) {
         $url_matches = null;
         $sitemap_matches = null;
         if (preg_match_all('~<sitemap>(.*?)</sitemap>~is', $response['body'], $sitemap_matches)) {
             $loc_matches = null;
             foreach ($sitemap_matches[1] as $sitemap_match) {
                 if (preg_match('~<loc>(.*?)</loc>~is', $sitemap_match, $loc_matches)) {
                     $loc = trim($loc_matches[1]);
                     if ($loc) {
                         $urls = array_merge($urls, $this->parse_sitemap($loc));
                     }
                 }
             }
         } elseif (preg_match_all('~<url>(.*?)</url>~is', $response['body'], $url_matches)) {
             $locs = array();
             $loc_matches = null;
             $priority_matches = null;
             foreach ($url_matches[1] as $url_match) {
                 $loc = '';
                 $priority = 0;
                 if (preg_match('~<loc>(.*?)</loc>~is', $url_match, $loc_matches)) {
                     $loc = trim($loc_matches[1]);
                 }
                 if (preg_match('~<priority>(.*?)</priority>~is', $url_match, $priority_matches)) {
                     $priority = (double) trim($priority_matches[1]);
                 }
                 if ($loc && $priority) {
                     $locs[$loc] = $priority;
                 }
             }
             arsort($locs);
             $urls = array_keys($locs);
         }
     }
     return $urls;
 }
开发者ID:eduardodomingos,项目名称:eduardodomingos.com,代码行数:49,代码来源:PgCache_Plugin_Admin.php

示例4: minify_filename_to_filenames_for_minification

 /**
  * Returns custom files
  *
  * @param string  $hash
  * @param string  $type
  * @return array
  */
 function minify_filename_to_filenames_for_minification($hash, $type)
 {
     // if bad data passed as get parameter - it shouldn't fire internal errors
     try {
         $files = Minify_Core::minify_filename_to_urls_for_minification($hash, $type);
     } catch (Exception $e) {
         $files = array();
     }
     $result = array();
     if (is_array($files) && count($files) > 0) {
         foreach ($files as $file) {
             $file = Util_Environment::url_to_docroot_filename($file);
             if (Util_Environment::is_url($file)) {
                 $precached_file = $this->_precache_file($file, $type);
                 if ($precached_file) {
                     $result[] = $precached_file;
                 } else {
                     Minify_Core::debug_error(sprintf('Unable to cache remote file: "%s"', $file));
                 }
             } else {
                 $path = Util_Environment::document_root() . '/' . $file;
                 if (file_exists($path)) {
                     $result[] = $file;
                 } else {
                     Minify_Core::debug_error(sprintf('File "%s" doesn\'t exist', $path));
                 }
             }
         }
     } else {
         Minify_Core::debug_error(sprintf('Unable to fetch custom files list: "%s.%s"', $hash, $type), false, 404);
     }
     return $result;
 }
开发者ID:developmentDM2,项目名称:Whohaha,代码行数:40,代码来源:Minify_MinifiedFileRequestHandler.php

示例5: import_library

 /**
  * Imports library
  *
  * @param integer $limit
  * @param integer $offset
  * @param integer $count
  * @param integer $total
  * @param array   $results
  * @return boolean
  */
 function import_library($limit, $offset, &$count, &$total, &$results)
 {
     global $wpdb;
     $count = 0;
     $total = 0;
     $results = array();
     $upload_info = Util_Http::upload_info();
     $uploads_use_yearmonth_folders = get_option('uploads_use_yearmonth_folders');
     $document_root = Util_Environment::document_root();
     @set_time_limit($this->_config->get_integer('timelimit.cdn_import'));
     if ($upload_info) {
         /**
          * Search for posts with links or images
          */
         $sql = sprintf('SELECT
     		ID,
     		post_content,
     		post_date
         FROM
             %sposts
         WHERE
             post_status = "publish"
             AND (post_type = "post" OR post_type = "page")
             AND (post_content LIKE "%%src=%%"
             	OR post_content LIKE "%%href=%%")
    		', $wpdb->prefix);
         if ($limit) {
             $sql .= sprintf(' LIMIT %d', $limit);
             if ($offset) {
                 $sql .= sprintf(' OFFSET %d', $offset);
             }
         }
         $posts = $wpdb->get_results($sql);
         if ($posts) {
             $count = count($posts);
             $total = $this->get_import_posts_count();
             $regexp = '~(' . $this->get_regexp_by_mask($this->_config->get_string('cdn.import.files')) . ')$~';
             $config_state = Dispatcher::config_state();
             $import_external = $config_state->get_boolean('cdn.import.external');
             foreach ($posts as $post) {
                 $matches = null;
                 $replaced = array();
                 $attachments = array();
                 $post_content = $post->post_content;
                 /**
                  * Search for all link and image sources
                  */
                 if (preg_match_all('~(href|src)=[\'"]?([^\'"<>\\s]+)[\'"]?~', $post_content, $matches, PREG_SET_ORDER)) {
                     foreach ($matches as $match) {
                         list($search, $attribute, $origin) = $match;
                         /**
                          * Check if $search is already replaced
                          */
                         if (isset($replaced[$search])) {
                             continue;
                         }
                         $error = '';
                         $result = false;
                         $src = Util_Environment::normalize_file_minify($origin);
                         $dst = '';
                         /**
                          * Check if file exists in the library
                          */
                         if (stristr($origin, $upload_info['baseurl']) === false) {
                             /**
                              * Check file extension
                              */
                             $check_src = $src;
                             if (Util_Environment::is_url($check_src)) {
                                 $qpos = strpos($check_src, '?');
                                 if ($qpos !== false) {
                                     $check_src = substr($check_src, 0, $qpos);
                                 }
                             }
                             if (preg_match($regexp, $check_src)) {
                                 /**
                                  * Check for already uploaded attachment
                                  */
                                 if (isset($attachments[$src])) {
                                     list($dst, $dst_url) = $attachments[$src];
                                     $result = true;
                                 } else {
                                     if ($uploads_use_yearmonth_folders) {
                                         $upload_subdir = date('Y/m', strtotime($post->post_date));
                                         $upload_dir = sprintf('%s/%s', $upload_info['basedir'], $upload_subdir);
                                         $upload_url = sprintf('%s/%s', $upload_info['baseurl'], $upload_subdir);
                                     } else {
                                         $upload_subdir = '';
                                         $upload_dir = $upload_info['basedir'];
                                         $upload_url = $upload_info['baseurl'];
//.........这里部分代码省略.........
开发者ID:developmentDM2,项目名称:Whohaha,代码行数:101,代码来源:Cdn_Core_Admin.php

示例6: get_files_minify

 /**
  * Exports min files to CDN
  *
  * @return array
  */
 function get_files_minify()
 {
     $files = array();
     if ($this->_config->get_boolean('minify.rewrite') && Util_Rule::can_check_rules() && (!$this->_config->get_boolean('minify.auto') || Cdn_Util::is_engine_mirror($this->_config->get_string('cdn.engine')))) {
         $minify = Dispatcher::component('Minify_Plugin');
         $document_root = Util_Environment::document_root();
         $minify_root = Util_Environment::cache_blog_dir('minify');
         $minify_path = ltrim(str_replace($document_root, '', $minify_root), '/');
         $urls = $minify->get_urls();
         // in WPMU + network admin (this code used for minify manual only)
         // common minify files are stored under context of main blog (i.e. 1)
         // but have urls of 0 blog, so download has to be used
         if ($this->_config->get_string('minify.engine') == 'file' && !(Util_Environment::is_wpmu() && is_network_admin())) {
             foreach ($urls as $url) {
                 Util_Http::get($url);
             }
             $files = Cdn_Util::search_files($minify_root, $minify_path, '*.css;*.js');
         } else {
             foreach ($urls as $url) {
                 $file = Util_Environment::normalize_file_minify($url);
                 $file = Util_Environment::translate_file($file);
                 if (!Util_Environment::is_url($file)) {
                     $file = $document_root . '/' . $file;
                     $file = ltrim(str_replace($minify_root, '', $file), '/');
                     $dir = dirname($file);
                     if ($dir) {
                         Util_File::mkdir($dir, 0777, $minify_root);
                     }
                     if (Util_Http::download($url, $minify_root . '/' . $file) !== false) {
                         $files[] = $minify_path . '/' . $file;
                     }
                 }
             }
         }
     }
     return $files;
 }
开发者ID:developmentDM2,项目名称:Whohaha,代码行数:42,代码来源:Cdn_Plugin.php

示例7: normalize_file_minify

 /**
  * Normalizes file name for minify
  *
  * Relative to document root!
  *
  * @param string  $file
  * @return string
  */
 public static function normalize_file_minify($file)
 {
     if (Util_Environment::is_url($file)) {
         if (strstr($file, '?') === false) {
             $domain_url_regexp = '~' . Util_Environment::home_domain_root_url_regexp() . '~i';
             $file = preg_replace($domain_url_regexp, '', $file);
         }
     }
     if (!Util_Environment::is_url($file)) {
         $file = Util_Environment::normalize_path($file);
         $file = str_replace(Util_Environment::document_root(), '', $file);
         $file = ltrim($file, '/');
     }
     return $file;
 }
开发者ID:developmentDM2,项目名称:Whohaha,代码行数:23,代码来源:Util_Environment.php


注:本文中的Util_Environment::is_url方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。