X-Git-Url: http://git.cyclocoop.org/?p=ptitvelo%2Fweb%2Fwww.git;a=blobdiff_plain;f=www%2Fplugins-dist%2Fcompresseur%2Flib%2Fcsstidy%2FDocs%2F__filesource%2Ffsource_csstidy__class.csstidy_print.php.html;fp=www%2Fplugins-dist%2Fcompresseur%2Flib%2Fcsstidy%2FDocs%2F__filesource%2Ffsource_csstidy__class.csstidy_print.php.html;h=0000000000000000000000000000000000000000;hp=f49644e434de5cc2e6c364f8e2ccc6a00e83ea73;hb=e847eea4a82a7396dd0abf860f9b30d654f38629;hpb=d686c3e22e97dd46ef42bcd0f138c65083f8f232 diff --git a/www/plugins-dist/compresseur/lib/csstidy/Docs/__filesource/fsource_csstidy__class.csstidy_print.php.html b/www/plugins-dist/compresseur/lib/csstidy/Docs/__filesource/fsource_csstidy__class.csstidy_print.php.html deleted file mode 100644 index f49644e..0000000 --- a/www/plugins-dist/compresseur/lib/csstidy/Docs/__filesource/fsource_csstidy__class.csstidy_print.php.html +++ /dev/null @@ -1,402 +0,0 @@ - - -File Source for class.csstidy_print.php - - - - - - - - - - - - - -
csstidy
- [ class tree: csstidy ] - [ index: csstidy ] - [ all elements ] -
- - - - - - -
-
- -

Source for file class.csstidy_print.php

-

Documentation is available at class.csstidy_print.php

-
-
  1. <?php
  2. -
  3. /**
  4. -
  5. * CSSTidy - CSS Parser and Optimiser
  6. -
  7. *
  8. -
  9. * CSS Printing class
  10. -
  11. * This class prints CSS data generated by csstidy.
  12. -
  13. *
  14. -
  15. * This file is part of CSSTidy.
  16. -
  17. *
  18. -
  19. * CSSTidy is free software; you can redistribute it and/or modify
  20. -
  21. * it under the terms of the GNU General Public License as published by
  22. -
  23. * the Free Software Foundation; either version 2 of the License, or
  24. -
  25. * (at your option) any later version.
  26. -
  27. *
  28. -
  29. * CSSTidy is distributed in the hope that it will be useful,
  30. -
  31. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  32. -
  33. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  34. -
  35. * GNU General Public License for more details.
  36. -
  37. *
  38. -
  39. * You should have received a copy of the GNU General Public License
  40. -
  41. * along with CSSTidy; if not, write to the Free Software
  42. -
  43. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  44. -
  45. *
  46. -
  47. * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  48. -
  49. * @package csstidy
  50. -
  51. * @author Florian Schmitz (floele at gmail dot com) 2005-2006
  52. -
  53. */
  54. -
  55. -
  56. /**
  57. -
  58. * CSS Printing class
  59. -
  60. *
  61. -
  62. * This class prints CSS data generated by csstidy.
  63. -
  64. *
  65. -
  66. * @package csstidy
  67. -
  68. * @author Florian Schmitz (floele at gmail dot com) 2005-2006
  69. -
  70. * @version 1.0
  71. -
  72. */
  73. -
  74. -
  75. class csstidy_print
  76. -
  77. {
  78. -
  79. /**
  80. -
  81. * Saves the input CSS string
  82. -
  83. * @var string
  84. -
  85. * @access private
  86. -
  87. */
  88. -
  89. var $input_css = '';
  90. -
  91.  
  92. -
  93. /**
  94. -
  95. * Saves the formatted CSS string
  96. -
  97. * @var string
  98. -
  99. * @access public
  100. -
  101. */
  102. -
  103. var $output_css = '';
  104. -
  105.  
  106. -
  107. /**
  108. -
  109. * Saves the formatted CSS string (plain text)
  110. -
  111. * @var string
  112. -
  113. * @access public
  114. -
  115. */
  116. -
  117. var $output_css_plain = '';
  118. -
  119.  
  120. -
  121. /**
  122. -
  123. * Constructor
  124. -
  125. * @param array $css contains the class csstidy
  126. -
  127. * @access private
  128. -
  129. * @version 1.0
  130. -
  131. */
  132. -
  133. function csstidy_print(&$css)
  134. -
  135. {
  136. -
  137. $this->parser =& $css;
  138. -
  139. $this->css =& $css->css;
  140. -
  141. $this->template =& $css->template;
  142. -
  143. $this->tokens =& $css->tokens;
  144. -
  145. $this->charset =& $css->charset;
  146. -
  147. $this->import =& $css->import;
  148. -
  149. $this->namespace =& $css->namespace;
  150. -
  151. }
  152. -
  153.  
  154. -
  155. /**
  156. -
  157. * Resets output_css and output_css_plain (new css code)
  158. -
  159. * @access private
  160. -
  161. * @version 1.0
  162. -
  163. */
  164. -
  165. function _reset()
  166. -
  167. {
  168. -
  169. $this->output_css = '';
  170. -
  171. $this->output_css_plain = '';
  172. -
  173. }
  174. -
  175.  
  176. -
  177. /**
  178. -
  179. * Returns the CSS code as plain text
  180. -
  181. * @return string
  182. -
  183. * @access public
  184. -
  185. * @version 1.0
  186. -
  187. */
  188. -
  189. function plain()
  190. -
  191. {
  192. -
  193. $this->_print(true);
  194. -
  195. return $this->output_css_plain;
  196. -
  197. }
  198. -
  199.  
  200. -
  201. /**
  202. -
  203. * Returns the formatted CSS code
  204. -
  205. * @return string
  206. -
  207. * @access public
  208. -
  209. * @version 1.0
  210. -
  211. */
  212. -
  213. function formatted()
  214. -
  215. {
  216. -
  217. $this->_print(false);
  218. -
  219. return $this->output_css;
  220. -
  221. }
  222. -
  223. -
  224. /**
  225. -
  226. * Returns the formatted CSS Code and saves it into $this->output_css and $this->output_css_plain
  227. -
  228. * @param bool $plain plain text or not
  229. -
  230. * @access private
  231. -
  232. * @version 2.0
  233. -
  234. */
  235. -
  236. function _print($plain = false)
  237. -
  238. {
  239. -
  240. if ($this->output_css && $this->output_css_plain) {
  241. -
  242. return;
  243. -
  244. }
  245. -
  246. -
  247. $output = '';
  248. -
  249. if (!$this->parser->get_cfg('preserve_css')) {
  250. -
  251. $this->_convert_raw_css();
  252. -
  253. }
  254. -
  255.  
  256. -
  257. $template =& $this->template;
  258. -
  259.  
  260. -
  261. if ($plain) {
  262. -
  263. $template = array_map('strip_tags', $template);
  264. -
  265. }
  266. -
  267. -
  268. if ($this->parser->get_cfg('timestamp')) {
  269. -
  270. array_unshift($this->tokens, array(COMMENT, ' CSSTidy ' . $this->parser->version . ': ' . date('r') . ' '));
  271. -
  272. }
  273. -
  274. -
  275. if (!empty($this->charset)) {
  276. -
  277. $output .= $template[0].'@charset '.$template[5].$this->charset.$template[6];
  278. -
  279. }
  280. -
  281. -
  282. if (!empty($this->import)) {
  283. -
  284. for ($i = 0, $size = count($this->import); $i < $size; $i ++) {
  285. -
  286. $output .= $template[0].'@import '.$template[5].$this->import[$i].$template[6];
  287. -
  288. }
  289. -
  290. }
  291. -
  292. -
  293. if (!empty($this->namespace)) {
  294. -
  295. $output .= $template[0].'@namespace '.$template[5].$this->namespace.$template[6];
  296. -
  297. }
  298. -
  299. -
  300. $output .= $template[13];
  301. -
  302. $in_at_out = '';
  303. -
  304. $out =& $output;
  305. -
  306. -
  307. foreach ($this->tokens as $key => $token)
  308. -
  309. {
  310. -
  311. switch ($token[0])
  312. -
  313. {
  314. -
  315. case AT_START:
  316. -
  317. $out .= $template[0].$this->_htmlsp($token[1], $plain).$template[1];
  318. -
  319. $out =& $in_at_out;
  320. -
  321. break;
  322. -
  323. -
  324. case SEL_START:
  325. -
  326. if($this->parser->get_cfg('lowercase_s')) $token[1] = strtolower($token[1]);
  327. -
  328. $out .= ($token[1]{0} !== '@') ? $template[2].$this->_htmlsp($token[1], $plain) : $template[0].$this->_htmlsp($token[1], $plain);
  329. -
  330. $out .= $template[3];
  331. -
  332. break;
  333. -
  334. -
  335. case PROPERTY:
  336. -
  337. if($this->parser->get_cfg('case_properties') == 2) $token[1] = strtoupper($token[1]);
  338. -
  339. if($this->parser->get_cfg('case_properties') == 1) $token[1] = strtolower($token[1]);
  340. -
  341. $out .= $template[4] . $this->_htmlsp($token[1], $plain) . ':' . $template[5];
  342. -
  343. break;
  344. -
  345. -
  346. case VALUE:
  347. -
  348. $out .= $this->_htmlsp($token[1], $plain);
  349. -
  350. if($this->_seeknocomment($key, 1) == SEL_END && $this->parser->get_cfg('remove_last_;')) {
  351. -
  352. $out .= str_replace(';', '', $template[6]);
  353. -
  354. } else {
  355. -
  356. $out .= $template[6];
  357. -
  358. }
  359. -
  360. break;
  361. -
  362. -
  363. case SEL_END:
  364. -
  365. $out .= $template[7];
  366. -
  367. if($this->_seeknocomment($key, 1) != AT_END) $out .= $template[8];
  368. -
  369. break;
  370. -
  371. -
  372. case AT_END:
  373. -
  374. $out =& $output;
  375. -
  376. $out .= $template[10] . str_replace("\n", "\n" . $template[10], $in_at_out);
  377. -
  378. $in_at_out = '';
  379. -
  380. $out .= $template[9];
  381. -
  382. break;
  383. -
  384.  
  385. -
  386. case COMMENT:
  387. -
  388. $out .= $template[11] . '/*' . $this->_htmlsp($token[1], $plain) . '*/' . $template[12];
  389. -
  390. break;
  391. -
  392. }
  393. -
  394. }
  395. -
  396.  
  397. -
  398. $output = trim($output);
  399. -
  400. -
  401. if (!$plain) {
  402. -
  403. $this->output_css = $output;
  404. -
  405. $this->_print(true);
  406. -
  407. } else {
  408. -
  409. $this->output_css_plain = $output;
  410. -
  411. }
  412. -
  413. }
  414. -
  415. -
  416. /**
  417. -
  418. * Gets the next token type which is $move away from $key, excluding comments
  419. -
  420. * @param integer $key current position
  421. -
  422. * @param integer $move move this far
  423. -
  424. * @return mixed a token type
  425. -
  426. * @access private
  427. -
  428. * @version 1.0
  429. -
  430. */
  431. -
  432. function _seeknocomment($key, $move) {
  433. -
  434. $go = ($move > 0) ? 1 : -1;
  435. -
  436. for ($i = $key + 1; abs($key-$i)-1 < abs($move); $i += $go) {
  437. -
  438. if (!isset($this->tokens[$i])) {
  439. -
  440. return;
  441. -
  442. }
  443. -
  444. if ($this->tokens[$i][0] == COMMENT) {
  445. -
  446. $move += 1;
  447. -
  448. continue;
  449. -
  450. }
  451. -
  452. return $this->tokens[$i][0];
  453. -
  454. }
  455. -
  456. }
  457. -
  458. -
  459. /**
  460. -
  461. * Converts $this->css array to a raw array ($this->tokens)
  462. -
  463. * @access private
  464. -
  465. * @version 1.0
  466. -
  467. */
  468. -
  469. function _convert_raw_css()
  470. -
  471. {
  472. -
  473. $this->tokens = array();
  474. -
  475. ksort($this->css);
  476. -
  477. -
  478. foreach ($this->css as $medium => $val)
  479. -
  480. {
  481. -
  482. if ($this->parser->get_cfg('sort_selectors')) ksort($val);
  483. -
  484. if ($medium != DEFAULT_AT) {
  485. -
  486. $this->parser->_add_token(AT_START, $medium, true);
  487. -
  488. }
  489. -
  490. -
  491. foreach ($val as $selector => $vali)
  492. -
  493. {
  494. -
  495. if ($this->parser->get_cfg('sort_properties')) ksort($vali);
  496. -
  497. $this->parser->_add_token(SEL_START, $selector, true);
  498. -
  499. -
  500. foreach ($vali as $property => $valj)
  501. -
  502. {
  503. -
  504. $this->parser->_add_token(PROPERTY, $property, true);
  505. -
  506. $this->parser->_add_token(VALUE, $valj, true);
  507. -
  508. }
  509. -
  510. -
  511. $this->parser->_add_token(SEL_END, $selector, true);
  512. -
  513. }
  514. -
  515. -
  516. if ($medium != DEFAULT_AT) {
  517. -
  518. $this->parser->_add_token(AT_END, $medium, true);
  519. -
  520. }
  521. -
  522. }
  523. -
  524. }
  525. -
  526. -
  527. /**
  528. -
  529. * Same as htmlspecialchars, only that chars are not replaced if $plain !== true. This makes print_code() cleaner.
  530. -
  531. * @param string $string
  532. -
  533. * @param bool $plain
  534. -
  535. * @return string
  536. -
  537. * @see csstidy_print::_print()
  538. -
  539. * @access private
  540. -
  541. * @version 1.0
  542. -
  543. */
  544. -
  545. function _htmlsp($string, $plain)
  546. -
  547. {
  548. -
  549. if (!$plain) {
  550. -
  551. return htmlspecialchars($string);
  552. -
  553. }
  554. -
  555. return $string;
  556. -
  557. }
  558. -
  559. -
  560. /**
  561. -
  562. * Get compression ratio
  563. -
  564. * @access public
  565. -
  566. * @return float
  567. -
  568. * @version 1.2
  569. -
  570. */
  571. -
  572. function get_ratio()
  573. -
  574. {
  575. -
  576. if (!$this->output_css_plain) {
  577. -
  578. $this->formatted();
  579. -
  580. }
  581. -
  582. return round((strlen($this->input_css) - strlen($this->output_css_plain)) / strlen($this->input_css), 3) * 100;
  583. -
  584. }
  585. -
  586.  
  587. -
  588. /**
  589. -
  590. * Get difference between the old and new code in bytes and prints the code if necessary.
  591. -
  592. * @access public
  593. -
  594. * @return string
  595. -
  596. * @version 1.1
  597. -
  598. */
  599. -
  600. function get_diff()
  601. -
  602. {
  603. -
  604. if (!$this->output_css_plain) {
  605. -
  606. $this->formatted();
  607. -
  608. }
  609. -
  610. -
  611. $diff = strlen($this->output_css_plain) - strlen($this->input_css);
  612. -
  613. -
  614. if ($diff > 0) {
  615. -
  616. return '+' . $diff;
  617. -
  618. } elseif ($diff == 0) {
  619. -
  620. return '+-' . $diff;
  621. -
  622. }
  623. -
  624. -
  625. return $diff;
  626. -
  627. }
  628. -
  629.  
  630. -
  631. /**
  632. -
  633. * Get the size of either input or output CSS in KB
  634. -
  635. * @param string $loc default is "output"
  636. -
  637. * @access public
  638. -
  639. * @return integer
  640. -
  641. * @version 1.0
  642. -
  643. */
  644. -
  645. function size($loc = 'output')
  646. -
  647. {
  648. -
  649. if ($loc == 'output' && !$this->output_css) {
  650. -
  651. $this->formatted();
  652. -
  653. }
  654. -
  655. -
  656. if ($loc == 'input') {
  657. -
  658. return (strlen($this->input_css) / 1000);
  659. -
  660. } else {
  661. -
  662. return (strlen($this->output_css_plain) / 1000);
  663. -
  664. }
  665. -
  666. }
  667. -
  668. }
  669. -
  670. ?>
  671. -
-
-
-
- Documentation generated on Mon, 15 May 2006 22:55:42 +0200 by phpDocumentor 1.3.0RC3 -
-
-
- - - \ No newline at end of file