Changeset 29636
- Timestamp:
- Sep 19, 2014, 10:46:12 AM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/template.class.php
r29389 r29636 1916 1916 { 1917 1917 $output = ''; 1918 $header = ''; 1918 1919 foreach ($pending as $combinable) 1919 1920 { 1920 1921 $output .= "/*BEGIN $combinable->path */\n"; 1921 $output .= $this->process_combinable($combinable, true, $force );1922 $output .= $this->process_combinable($combinable, true, $force, $header); 1922 1923 $output .= "\n"; 1923 1924 } 1925 $output = "/*BEGIN header */\n" . $header . "\n" . $output; 1924 1926 mkgetdir( dirname(PHPWG_ROOT_PATH.$file) ); 1925 1927 file_put_contents( PHPWG_ROOT_PATH.$file, $output ); … … 1930 1932 elseif ( count($pending)==1) 1931 1933 { 1932 $this->process_combinable($pending[0], false, $force); 1934 $header = ''; 1935 $this->process_combinable($pending[0], false, $force, $header); 1933 1936 $result[] = $pending[0]; 1934 1937 } … … 1943 1946 * @param bool $return_content 1944 1947 * @param bool $force 1948 * @param string $header CSS directives that must appear first in 1949 * the minified file (only used when 1950 * $return_content===true) 1945 1951 * @return null|string 1946 1952 */ 1947 private function process_combinable($combinable, $return_content, $force )1953 private function process_combinable($combinable, $return_content, $force, &$header) 1948 1954 { 1949 1955 global $conf; … … 1971 1977 1972 1978 if ($this->is_css) 1973 $content = self::process_css($content, $combinable->path );1979 $content = self::process_css($content, $combinable->path, $header ); 1974 1980 else 1975 1981 $content = self::process_js($content, $combinable->path ); … … 1984 1990 $content = file_get_contents(PHPWG_ROOT_PATH . $combinable->path); 1985 1991 if ($this->is_css) 1986 $content = self::process_css($content, $combinable->path );1992 $content = self::process_css($content, $combinable->path, $header ); 1987 1993 else 1988 1994 $content = self::process_js($content, $combinable->path ); … … 2013 2019 * @param string $css file content 2014 2020 * @param string $file 2021 * @param string $header CSS directives that must appear first in 2022 * the minified file. 2015 2023 * @return string 2016 2024 */ 2017 private static function process_css($css, $file )2018 { 2019 $css = self::process_css_rec($css, dirname($file) );2025 private static function process_css($css, $file, &$header) 2026 { 2027 $css = self::process_css_rec($css, dirname($file), $header); 2020 2028 if (strpos($file, '.min')===false and version_compare(PHP_VERSION, '5.2.4', '>=')) 2021 2029 { … … 2032 2040 * @param string $css file content 2033 2041 * @param string $dir 2042 * @param string $header CSS directives that must appear first in 2043 * the minified file. 2034 2044 * @return string 2035 2045 */ 2036 private static function process_css_rec($css, $dir )2046 private static function process_css_rec($css, $dir, &$header) 2037 2047 { 2038 2048 static $PATTERN_URL = "#url\(\s*['|\"]{0,1}(.*?)['|\"]{0,1}\s*\)#"; … … 2057 2067 { 2058 2068 $search = $replace = array(); 2069 2059 2070 foreach ($matches as $match) 2060 2071 { 2061 2072 $search[] = $match[0]; 2062 $sub_css = file_get_contents(PHPWG_ROOT_PATH . $dir . "/$match[1]"); 2063 $replace[] = self::process_css_rec($sub_css, dirname($dir . "/$match[1]") ); 2073 2074 if ( 2075 strpos($match[1], '..') !== false // Possible attempt to get out of Piwigo's dir 2076 or strpos($match[1], '://') !== false // Remote URL 2077 or !is_readable(PHPWG_ROOT_PATH . $dir . '/' . $match[1]) 2078 ) 2079 { 2080 // If anything is suspicious, don't try to process the 2081 // @import. Since @import need to be first and we are 2082 // concatenating several CSS files, remove it from here and return 2083 // it through $header. 2084 $header .= $match[0]; 2085 $replace[] = ''; 2086 } 2087 else 2088 { 2089 $sub_css = file_get_contents(PHPWG_ROOT_PATH . $dir . "/$match[1]"); 2090 $replace[] = self::process_css_rec($sub_css, dirname($dir . "/$match[1]"), $header); 2091 } 2064 2092 } 2065 2093 $css = str_replace($search, $replace, $css);
Note: See TracChangeset
for help on using the changeset viewer.