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


PHP Booster::getpath方法代码示例

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


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

示例1: booster_wp

function booster_wp()
{
    // Dump output buffer
    if ($out = ob_get_contents()) {
        // Check for right PHP version
        if (strnatcmp(phpversion(), '5.0.0') >= 0) {
            $booster_cache_dir = BOOSTER_CACHE_DIR;
            $js_plain = '';
            $booster_out = '';
            $booster_folder = explode('/', rtrim(str_replace('\\', '/', realpath(dirname(__FILE__))), '/'));
            $booster_folder = $booster_folder[count($booster_folder) - 1];
            $booster = new Booster();
            if (!is_dir($booster_cache_dir)) {
                @mkdir($booster_cache_dir, 0777);
                @chmod($booster_cache_dir, 0777);
            }
            if (is_dir($booster_cache_dir) && is_writable($booster_cache_dir) && substr(decoct(fileperms($booster_cache_dir)), 1) == "0777") {
                $booster_cache_reldir = $booster->getpath(str_replace('\\', '/', realpath($booster_cache_dir)), str_replace('\\', '/', dirname(__FILE__)));
            } else {
                $booster_cache_dir = rtrim(str_replace('\\', '/', dirname(__FILE__)), '/') . '/../../booster_cache';
                $booster_cache_reldir = '../../booster_cache';
            }
            $booster->booster_cachedir = $booster_cache_reldir;
            $booster->js_minify = FALSE;
            // Calculate relative path from root to Booster directory
            $root_to_booster_path = $booster->getpath(str_replace('\\', '/', dirname(__FILE__)), str_replace('\\', '/', dirname(realpath(ABSPATH))));
            if (preg_match_all('/<head.*<\\/head>/ims', $out, $headtreffer, PREG_PATTERN_ORDER) > 0) {
                // Prevent processing of conditional comments
                $headtreffer[0][0] = preg_replace('/<!--\\[if.+?endif\\]-->/ims', '', $headtreffer[0][0]);
                // CSS part
                $css_rel_files = array();
                // Start width inline-files
                preg_match_all('/<style[^>]*>(.*?)<\\/style>/ims', $headtreffer[0][0], $treffer, PREG_PATTERN_ORDER);
                for ($i = 0; $i < count($treffer[0]); $i++) {
                    // Get media-type
                    if (preg_match('/media=[\'"]*([^\'"]+)[\'"]*/ims', $treffer[0][$i], $mediatreffer)) {
                        $media = preg_replace('/[^a-z]+/i', '', $mediatreffer[1]);
                        if (trim($media) == '') {
                            $media = 'all';
                        }
                    } else {
                        $media = 'all';
                    }
                    // Save plain CSS to file to keep everything in line
                    $filename = $booster_cache_dir . '/' . md5($treffer[1][$i]) . '_plain.css';
                    if (!file_exists($filename)) {
                        file_put_contents($filename, $treffer[1][$i]);
                    }
                    if (file_exists($filename)) {
                        @chmod($filename, 0777);
                        // Calculate relative path from Booster to file
                        $booster_to_file_path = $booster->getpath($booster_cache_dir . '/', str_replace('\\', '/', dirname(realpath(__FILE__))) . '/');
                        $linkhref = get_option('siteurl') . '/wp-content/plugins/' . $booster_folder . '/' . $booster_to_file_path . '/' . basename($filename);
                        $booster_cache_dir = $booster_cache_dir;
                        $linkcode = '<!-- Moved to file by Booster ' . $treffer[0][$i] . ' --><link rel="stylesheet" media="' . $media . '" href="' . $linkhref . '" />';
                        $headtreffer[0][0] = str_replace($treffer[0][$i], $linkcode, $headtreffer[0][0]);
                        $out = str_replace($treffer[0][$i], $linkcode, $out);
                    } else {
                        $linkcode = '<!-- Failed to move inline-style to file ' . $filename . ' by Booster -->' . $treffer[0][$i];
                        $headtreffer[0][0] = str_replace($treffer[0][$i], $linkcode, $headtreffer[0][0]);
                        $out = str_replace($treffer[0][$i], $linkcode, $out);
                    }
                }
                // Continue with external files
                preg_match_all('/<link[^>]*?href=[\'"]*?([^\'"]+?\\.css)[\'"]*?[^>]*?>/ims', $headtreffer[0][0], $treffer, PREG_PATTERN_ORDER);
                for ($i = 0; $i < count($treffer[0]); $i++) {
                    // Get media-type
                    if (preg_match('/media=[\'"]*([^\'"]+)[\'"]*/ims', $treffer[0][$i], $mediatreffer)) {
                        $media = preg_replace('/[^a-z]+/i', '', $mediatreffer[1]);
                        if (trim($media) == '') {
                            $media = 'all';
                        }
                    } else {
                        $media = 'all';
                    }
                    // Get relation
                    if (preg_match('/rel=[\'"]*([^\'"]+)[\'"]*/ims', $treffer[0][$i], $reltreffer)) {
                        $rel = $reltreffer[1];
                    } else {
                        $rel = 'stylesheet';
                    }
                    // Convert file's URI into an absolute local path
                    $filename = preg_replace('/^http:\\/\\/[^\\/]+/', rtrim($_SERVER['DOCUMENT_ROOT'], '/'), $treffer[1][$i]);
                    // Remove any parameters from file's URI
                    $filename = preg_replace('/\\?.*$/', '', $filename);
                    // If file exists
                    if (file_exists($filename)) {
                        // If its a normal CSS-file
                        if (substr($filename, strlen($filename) - 4, 4) == '.css' && file_exists($filename)) {
                            // Put file-reference inside a comment
                            $out = str_replace($treffer[0][$i], '<!-- Processed by Booster ' . $treffer[0][$i] . ' -->', $out);
                            // Calculate relative path from Booster to file
                            $booster_to_file_path = $booster->getpath(str_replace('\\', '/', dirname($filename)), str_replace('\\', '/', dirname(__FILE__)));
                            $filename = $booster_to_file_path . '/' . basename($filename);
                            // Create sub-arrays if not yet there
                            if (!isset($css_rel_files[$media])) {
                                $css_rel_files[$media] = array();
                            }
                            if (!isset($css_abs_files[$media])) {
                                $css_abs_files[$media] = array();
//.........这里部分代码省略.........
开发者ID:ChrisCinelli,项目名称:CSS-JS-Booster,代码行数:101,代码来源:wp_booster.php


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