Changeset 25815
- Timestamp:
- Dec 7, 2013, 12:21:07 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/template.class.php
r25812 r25815 76 76 * @var string $path 77 77 */ 78 function __construct($root = ".", $theme= "", $path ="template")78 function __construct($root=".", $theme="", $path="template") 79 79 { 80 80 global $conf, $lang_info; … … 1193 1193 class PwgTemplateAdapter 1194 1194 { 1195 /** 1196 * @deprecated use "translate" modifier 1197 */ 1195 1198 function l10n($text) 1196 1199 { … … 1198 1201 } 1199 1202 1203 /** 1204 * @deprecated use "translate_dec" modifier 1205 */ 1200 1206 function l10n_dec($s, $p, $v) 1201 1207 { … … 1203 1209 } 1204 1210 1211 /** 1212 * @deprecated use "translate" or "sprintf" modifier 1213 */ 1205 1214 function sprintf() 1206 1215 { … … 1209 1218 } 1210 1219 1220 /** 1221 * @param string $type 1222 * @param array $img 1223 * @return DerivativeImage 1224 */ 1211 1225 function derivative($type, $img) 1212 1226 { … … 1214 1228 } 1215 1229 1230 /** 1231 * @param string $type 1232 * @param array $img 1233 * @return string 1234 */ 1216 1235 function derivative_url($type, $img) 1217 1236 { … … 1221 1240 1222 1241 1242 /** 1243 * A Combinable represents a JS or CSS file ready for cobination and minification. 1244 */ 1223 1245 class Combinable 1224 1246 { 1247 /** @var string */ 1225 1248 public $id; 1249 /** @var string */ 1226 1250 public $path; 1251 /** @var string */ 1227 1252 public $version; 1253 /** @var bool */ 1228 1254 public $is_template; 1229 1255 1230 function __construct($id, $path, $version) 1256 /** 1257 * @param string $id 1258 * @param string $path 1259 * @param string $version 1260 */ 1261 function __construct($id, $path, $version=0) 1231 1262 { 1232 1263 $this->id = $id; 1233 1264 $this->set_path($path); 1234 1265 $this->version = $version; 1235 } 1236 1266 $this->is_template = false; 1267 } 1268 1269 /** 1270 * @param string $path 1271 */ 1237 1272 function set_path($path) 1238 1273 { … … 1241 1276 } 1242 1277 1278 /** 1279 * @return bool 1280 */ 1243 1281 function is_remote() 1244 1282 { 1245 return url_is_remote( $this->path) || strncmp($this->path, '//', 2)==0;1283 return url_is_remote($this->path) || strncmp($this->path, '//', 2)==0; 1246 1284 } 1247 1285 } 1248 1286 1287 /** 1288 * Implementation of Combinable for JS files. 1289 */ 1249 1290 final class Script extends Combinable 1250 1291 { 1292 /** @var int 0,1,2 */ 1251 1293 public $load_mode; 1252 public $precedents = array(); 1253 public $extra = array(); 1254 1255 function __construct($load_mode, $id, $path, $version, $precedents) 1294 /** @var array */ 1295 public $precedents; 1296 /** @var array */ 1297 public $extra; 1298 1299 /** 1300 * @param int 0,1,2 1301 * @param string $id 1302 * @param string $path 1303 * @param string $version 1304 * @param array $precedents 1305 */ 1306 function __construct($load_mode, $id, $path, $version=0, $precedents=array()) 1256 1307 { 1257 1308 parent::__construct($id, $path, $version); 1258 1309 $this->load_mode = $load_mode; 1259 1310 $this->precedents = $precedents; 1311 $this->extra = array(); 1260 1312 } 1261 1313 } 1262 1314 1315 /** 1316 * Implementation of Combinable for CSS files. 1317 */ 1263 1318 final class Css extends Combinable 1264 1319 { 1320 /** @var int */ 1265 1321 public $order; 1266 1322 1267 function __construct($id, $path, $version, $order) 1323 /** 1324 * @param string $id 1325 * @param string $path 1326 * @param string $version 1327 * @param int $order 1328 */ 1329 function __construct($id, $path, $version=0, $order=0) 1268 1330 { 1269 1331 parent::__construct($id, $path, $version); … … 1273 1335 1274 1336 1275 /** Manage a list of css files */ 1337 /** 1338 * Manages a list of CSS files and combining them in a unique file. 1339 */ 1276 1340 class CssLoader 1277 1341 { 1342 /** @param Css[] */ 1278 1343 private $registered_css; 1279 1280 /** used to keep declaration order */ 1344 /** @param int used to keep declaration order */ 1281 1345 private $counter; 1282 1346 … … 1292 1356 } 1293 1357 1358 /** 1359 * @return Combinable[] array of combined CSS. 1360 */ 1294 1361 function get_css() 1295 1362 { … … 1299 1366 } 1300 1367 1368 /** 1369 * Callback for CSS files sorting. 1370 */ 1301 1371 private static function cmp_by_order($a, $b) 1302 1372 { … … 1304 1374 } 1305 1375 1376 /** 1377 * Adds a new file, if a file with the same $id already exsists, the one with 1378 * the higher $order or higher $version is kept. 1379 * 1380 * @param string $id 1381 * @param string $path 1382 * @param string $version 1383 * @param int $order 1384 * @param bool $is_template 1385 */ 1306 1386 function add($id, $path, $version=0, $order=0, $is_template=false) 1307 1387 { … … 1327 1407 1328 1408 1329 /** Manage a list of required scripts for a page, by optimizing their loading location (head, bottom, async) 1330 and later on by combining them in a unique file respecting at the same time dependencies.*/ 1409 /** 1410 * Manage a list of required scripts for a page, by optimizing their loading location (head, footer, async) 1411 * and later on by combining them in a unique file respecting at the same time dependencies. 1412 */ 1331 1413 class ScriptLoader 1332 1414 { 1415 /** @var Script[] */ 1333 1416 private $registered_scripts; 1417 /** @var string[] */ 1334 1418 public $inline_scripts; 1335 1419 1420 /** @var bool */ 1336 1421 private $did_head; 1422 /** @var bool */ 1337 1423 private $head_done_scripts; 1424 /** @var bool */ 1338 1425 private $did_footer; 1339 1426 … … 1364 1451 } 1365 1452 1453 /** 1454 * @return bool 1455 */ 1456 function did_head() 1457 { 1458 return $this->did_head; 1459 } 1460 1461 /** 1462 * @return Script[] 1463 */ 1366 1464 function get_all() 1367 1465 { … … 1369 1467 } 1370 1468 1469 /** 1470 * @param string $code 1471 * @param string[] $require 1472 */ 1371 1473 function add_inline($code, $require) 1372 1474 { … … 1386 1488 } 1387 1489 1490 /** 1491 * @param string $id 1492 * @param int $load_mode 1493 * @param string[] $require 1494 * @param string $path 1495 * @param string $version 1496 */ 1388 1497 function add($id, $load_mode, $require, $path, $version=0) 1389 1498 { … … 1431 1540 } 1432 1541 1433 function did_head()1434 {1435 return $this->did_head;1436 }1437 1542 /** 1543 * Returns combined scripts loaded in header. 1544 * 1545 * @return Combinable[] 1546 */ 1438 1547 function get_head_scripts() 1439 1548 { … … 1459 1568 } 1460 1569 1570 /** 1571 * Returns combined scripts loaded in footer. 1572 * 1573 * @return Combinable[] 1574 */ 1461 1575 function get_footer_scripts() 1462 1576 { … … 1490 1604 } 1491 1605 1606 /** 1607 * @param Script[] $scripts 1608 * @param int $load_mode 1609 * @return Combinable[] 1610 */ 1492 1611 private static function do_combine($scripts, $load_mode) 1493 1612 { … … 1496 1615 } 1497 1616 1498 // checks that if B depends on A, then B->load_mode >= A->load_mode in order to respect execution order 1617 /** 1618 * Checks dependencies among Scripts. 1619 * Checks that if B depends on A, then B->load_mode >= A->load_mode in order to respect execution order. 1620 * 1621 * @param Script[] $scripts 1622 */ 1499 1623 private static function check_load_dep($scripts) 1500 1624 { … … 1526 1650 } 1527 1651 1528 1652 /** 1653 * Fill a script dependancies with the known jQuery UI scripts. 1654 * 1655 * @param string $id in FileCombiner::$known_paths 1656 * @param Script $script 1657 */ 1529 1658 private static function fill_well_known($id, $script) 1530 1659 { … … 1561 1690 } 1562 1691 1692 /** 1693 * Add a known jQuery UI script to loaded scripts. 1694 * 1695 * @param string $id in FileCombiner::$known_paths 1696 * @param int $load_mode 1697 * @return bool 1698 */ 1563 1699 private function load_known_required_script($id, $load_mode) 1564 1700 { … … 1571 1707 } 1572 1708 1709 /** 1710 * Compute script order depending on dependencies. 1711 * Assigned to $script->extra['order']. 1712 * 1713 * @param string $script_id 1714 * @param int $recursion_limiter 1715 * @return int 1716 */ 1573 1717 private function compute_script_topological_order($script_id, $recursion_limiter=0) 1574 1718 { … … 1591 1735 } 1592 1736 1737 /** 1738 * Callback for scripts sorter. 1739 */ 1593 1740 private static function cmp_by_mode_and_order($s1, $s2) 1594 1741 { … … 1608 1755 1609 1756 1610 /*Allows merging of javascript and css files into a single one.*/ 1757 /** 1758 * Allows merging of javascript and css files into a single one. 1759 */ 1611 1760 final class FileCombiner 1612 1761 { 1613 private $type; // js or css 1762 /** @var string 'js' or 'css' */ 1763 private $type; 1764 /** @var bool */ 1614 1765 private $is_css; 1766 /** @var Combinable[] */ 1615 1767 private $combinables; 1616 1768 1617 function FileCombiner($type, $combinables=array()) 1769 /** 1770 * @param string $type 'js' or 'css' 1771 * @param Combinable[] $combinables 1772 */ 1773 function __construct($type, $combinables=array()) 1618 1774 { 1619 1775 $this->type = $type; … … 1622 1778 } 1623 1779 1780 /** 1781 * Deletes all combined files from cache directory. 1782 */ 1624 1783 static function clear_combined_files() 1625 1784 { … … 1633 1792 } 1634 1793 1635 function add($combinables) 1636 { 1637 if ($combinables instanceof Combinable) 1638 { 1639 $this->combinables[] = $combinables; 1794 /** 1795 * @param Combinable|Combinable[] $combinable 1796 */ 1797 function add($combinable) 1798 { 1799 if (is_array($combinable)) 1800 { 1801 $this->combinables = array_merge($this->combinables, $combinable); 1640 1802 } 1641 1803 else 1642 1804 { 1643 foreach($combinables as $combinable) 1644 $this->combinables[] = $combinable; 1645 } 1646 } 1647 1805 $this->combinables[] = $combinable; 1806 } 1807 } 1808 1809 /** 1810 * @return Combinable[] 1811 */ 1648 1812 function combine() 1649 1813 { … … 1686 1850 } 1687 1851 1852 /** 1853 * Process a set of pending files. 1854 * 1855 * @param array &$result 1856 * @param array &$pending 1857 * @param string[] $key 1858 * @param bool $force 1859 */ 1688 1860 private function flush_pending(&$result, &$pending, $key, $force) 1689 1861 { … … 1716 1888 } 1717 1889 1890 /** 1891 * Process one combinable file. 1892 * 1893 * @param Combinable $combinable 1894 * @param bool $return_content 1895 * @param bool $force 1896 * @return null|string 1897 */ 1718 1898 private function process_combinable($combinable, $return_content, $force) 1719 1899 { … … 1742 1922 1743 1923 if ($this->is_css) 1744 $content = self::process_css($content, dirname($combinable->path));1924 $content = self::process_css($content, $combinable->path ); 1745 1925 else 1746 1926 $content = self::process_js($content, $combinable->path ); … … 1755 1935 $content = file_get_contents(PHPWG_ROOT_PATH . $combinable->path); 1756 1936 if ($this->is_css) 1757 $content = self::process_css($content, dirname($combinable->path));1937 $content = self::process_css($content, $combinable->path ); 1758 1938 else 1759 1939 $content = self::process_js($content, $combinable->path ); … … 1762 1942 } 1763 1943 1944 /** 1945 * Process a JS file. 1946 * 1947 * @param string $js file content 1948 * @param string $file 1949 * @return string 1950 */ 1764 1951 private static function process_js($js, $file) 1765 1952 { … … 1772 1959 } 1773 1960 1774 private static function process_css($css, $dir) 1775 { 1776 $css = self::process_css_rec($css, $dir); 1777 if (version_compare(PHP_VERSION, '5.2.4', '>=')) 1961 /** 1962 * Process a CSS file. 1963 * 1964 * @param string $css file content 1965 * @param string $file 1966 * @return string 1967 */ 1968 private static function process_css($css, $file) 1969 { 1970 $css = self::process_css_rec($css, dirname($file)); 1971 if (strpos($file, '.min')===false and version_compare(PHP_VERSION, '5.2.4', '>=')) 1778 1972 { 1779 1973 require_once(PHPWG_ROOT_PATH.'include/cssmin.class.php'); … … 1784 1978 } 1785 1979 1980 /** 1981 * Resolves relative links in CSS file. 1982 * 1983 * @param string $css file content 1984 * @param string $dir 1985 * @return string 1986 */ 1786 1987 private static function process_css_rec($css, $dir) 1787 1988 { … … 1817 2018 return $css; 1818 2019 } 1819 1820 2020 } 1821 2021
Note: See TracChangeset
for help on using the changeset viewer.