[Phpfreechat-svn] SF.net SVN: phpfreechat: [906] trunk/lib
Status: Beta
Brought to you by:
kerphi
From: <ke...@us...> - 2006-12-21 06:30:25
|
Revision: 906 http://svn.sourceforge.net/phpfreechat/?rev=906&view=rev Author: kerphi Date: 2006-12-20 22:30:19 -0800 (Wed, 20 Dec 2006) Log Message: ----------- optimizations on interface loading (work in progress) Added Paths: ----------- trunk/lib/csstidy-1.2/ trunk/lib/csstidy-1.2/COPYING trunk/lib/csstidy-1.2/README trunk/lib/csstidy-1.2/class.csstidy.php trunk/lib/csstidy-1.2/class.csstidy_optimise.php trunk/lib/csstidy-1.2/class.csstidy_print.php trunk/lib/csstidy-1.2/css_optimiser.php trunk/lib/csstidy-1.2/cssparse.css trunk/lib/csstidy-1.2/data.inc.php trunk/lib/csstidy-1.2/lang.inc.php trunk/lib/csstidy-1.2/template.tpl trunk/lib/csstidy-1.2/template1.tpl trunk/lib/csstidy-1.2/template2.tpl trunk/lib/csstidy-1.2/template3.tpl trunk/lib/xajax_0.5_beta1/ trunk/lib/xajax_0.5_beta1/LICENSE.txt trunk/lib/xajax_0.5_beta1/xajax_core/ trunk/lib/xajax_0.5_beta1/xajax_core/legacy.inc.php trunk/lib/xajax_0.5_beta1/xajax_core/plugin_layer/ trunk/lib/xajax_0.5_beta1/xajax_core/plugin_layer/xajaxDefaultIncludePlugin.inc.php trunk/lib/xajax_0.5_beta1/xajax_core/plugin_layer/xajaxDefaultRequestProcessorPlugin.inc.php trunk/lib/xajax_0.5_beta1/xajax_core/plugin_layer/xajaxIncludePlugin.inc.php trunk/lib/xajax_0.5_beta1/xajax_core/plugin_layer/xajaxPluginManager.inc.php trunk/lib/xajax_0.5_beta1/xajax_core/plugin_layer/xajaxRequestProcessorPlugin.inc.php trunk/lib/xajax_0.5_beta1/xajax_core/plugin_layer/xajaxResponsePlugin.inc.php trunk/lib/xajax_0.5_beta1/xajax_core/xajax.inc.php trunk/lib/xajax_0.5_beta1/xajax_core/xajaxCompress.inc.php trunk/lib/xajax_0.5_beta1/xajax_core/xajaxResponse.inc.php trunk/lib/xajax_0.5_beta1/xajax_js/ trunk/lib/xajax_0.5_beta1/xajax_js/xajax.js trunk/lib/xajax_0.5_beta1/xajax_js/xajax_uncompressed.js Removed Paths: ------------- trunk/lib/javascript/activity.js trunk/lib/javascript/cookie.js trunk/lib/javascript/image_preloader.js trunk/lib/javascript/md5.js trunk/lib/javascript/mousepos.js trunk/lib/javascript/myprototype.js trunk/lib/javascript/regex.js trunk/lib/javascript/sprintf2.js trunk/lib/javascript/utf8.js trunk/lib/xajax_0.2.3/ Added: trunk/lib/csstidy-1.2/COPYING =================================================================== --- trunk/lib/csstidy-1.2/COPYING (rev 0) +++ trunk/lib/csstidy-1.2/COPYING 2006-12-21 06:30:19 UTC (rev 906) @@ -0,0 +1,340 @@ + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc. + 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Library General Public License instead.) You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + <one line to give the program's name and a brief idea of what it does.> + Copyright (C) <year> <name of author> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) year name of author + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + <signature of Ty Coon>, 1 April 1989 + Ty Coon, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Library General +Public License instead of this License. Added: trunk/lib/csstidy-1.2/README =================================================================== --- trunk/lib/csstidy-1.2/README (rev 0) +++ trunk/lib/csstidy-1.2/README 2006-12-21 06:30:19 UTC (rev 906) @@ -0,0 +1,28 @@ +CSSTidy + +Changelog: http://cdburnerxp.se/cssparse/csstidy/changelog.php + +css_optimiser.php is the web-interface, css_parser.php contains the PHP class (CSSTidy). + +This class represents a CSS parser which reads CSS code and saves it in an array. +In opposite to most other CSS parsers, it does not use regular expressions and +thus has full CSS2 support and a higher reliability. The downside of not using regular expressions +is a lower speed though. +Additional to that it applies some optimisations and fixes to the CSS code. +An online version should be available here: http://cdburnerxp.se/cssparse/css_optimiser.php + + + +CSSTidy is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +CSSTidy is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with CSSTidy; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA Added: trunk/lib/csstidy-1.2/class.csstidy.php =================================================================== --- trunk/lib/csstidy-1.2/class.csstidy.php (rev 0) +++ trunk/lib/csstidy-1.2/class.csstidy.php 2006-12-21 06:30:19 UTC (rev 906) @@ -0,0 +1,986 @@ +<?php +/** + * CSSTidy - CSS Parser and Optimiser + * + * CSS Parser class + * + * This file is part of CSSTidy. + * + * CSSTidy is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * CSSTidy is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with CSSTidy; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + * @license http://opensource.org/licenses/gpl-license.php GNU Public License + * @package csstidy + * @author Florian Schmitz (floele at gmail dot com) 2005-2006 + */ + +/** + * Various CSS data needed for correct optimisations etc. + * + * @version 1.2 + */ +require('data.inc.php'); + +/** + * Contains a class for printing CSS code + * + * @version 1.0 + */ +require('class.csstidy_print.php'); + +/** + * Contains a class for optimising CSS code + * + * @version 1.0 + */ +require('class.csstidy_optimise.php'); + +/** + * CSS Parser class + * + * This class represents a CSS parser which reads CSS code and saves it in an array. + * In opposite to most other CSS parsers, it does not use regular expressions and + * thus has full CSS2 support and a higher reliability. + * Additional to that it applies some optimisations and fixes to the CSS code. + * An online version should be available here: http://cdburnerxp.se/cssparse/css_optimiser.php + * @package csstidy + * @author Florian Schmitz (floele at gmail dot com) 2005-2006 + * @version 1.2 + */ +class csstidy { + +/** + * Saves the parsed CSS + * @var array + * @access public + */ +var $css = array(); + +/** + * Saves the parsed CSS (raw) + * @var array + * @access private + */ +var $tokens = array(); + +/** + * Printer class + * @see csstidy_print + * @var object + * @access public + */ +var $print; + +/** + * Optimiser class + * @see csstidy_optimise + * @var object + * @access private + */ +var $optimise; + +/** + * Saves the CSS charset (@charset) + * @var string + * @access private + */ +var $charset = ''; + +/** + * Saves all @import URLs + * @var array + * @access private + */ +var $import = array(); + +/** + * Saves the namespace + * @var string + * @access private + */ +var $namespace = ''; + +/** + * Contains the version of csstidy + * @var string + * @access private + */ +var $version = '1.2'; + +/** + * Stores the settings + * @var array + * @access private + */ +var $settings = array(); + +/** + * Saves the parser-status. + * + * Possible values: + * - is = in selector + * - ip = in property + * - iv = in value + * - instr = in string (started at " or ' or ( ) + * - ic = in comment (ignore everything) + * - at = in @-block + * + * @var string + * @access private + */ +var $status = 'is'; + + +/** + * Saves the current at rule (@media) + * @var string + * @access private + */ +var $at = ''; + +/** + * Saves the current selector + * @var string + * @access private + */ +var $selector = ''; + +/** + * Saves the current property + * @var string + * @access private + */ +var $property = ''; + +/** + * Saves the position of , in selectors + * @var array + * @access private + */ +var $sel_separate = array(); + +/** + * Saves the current value + * @var string + * @access private + */ +var $value = ''; + +/** + * Saves the current sub-value + * + * Example for a subvalue: + * background:url(foo.png) red no-repeat; + * "url(foo.png)", "red", and "no-repeat" are subvalues, + * seperated by whitespace + * @var string + * @access private + */ +var $sub_value = ''; + +/** + * Array which saves all subvalues for a property. + * @var array + * @see sub_value + * @access private + */ +var $sub_value_arr = array(); + +/** + * Saves the char which opened the last string + * @var string + * @access private + */ +var $str_char = ''; + +/** + * Status from which the parser switched to ic or instr + * @var string + * @access private + */ +var $from = ''; + +/** + * Variable needed to manage string-in-strings, for example url("foo.png") + * @var string + * @access private + */ +var $str_in_str = false; + +/** + * =true if in invalid at-rule + * @var bool + * @access private + */ +var $invalid_at = false; + +/** + * =true if something has been added to the current selector + * @var bool + * @access private + */ +var $added = false; + +/** + * Array which saves the message log + * @var array + * @access private + */ +var $log = array(); + +/** + * Saves the line number + * @var integer + * @access private + */ +var $line = 1; + +/** + * Loads standard template and sets default settings + * @access private + * @version 1.2 + */ +function csstidy() +{ + $this->settings['remove_bslash'] = true; + $this->settings['compress_colors'] = true; + $this->settings['compress_font-weight'] = true; + $this->settings['lowercase_s'] = false; + $this->settings['optimise_shorthands'] = 1; + $this->settings['remove_last_;'] = false; + $this->settings['case_properties'] = 1; + $this->settings['sort_properties'] = false; + $this->settings['sort_selectors'] = false; + $this->settings['merge_selectors'] = 2; + $this->settings['discard_invalid_properties'] = false; + $this->settings['css_level'] = 'CSS2.1'; + $this->settings['preserve_css'] = false; + $this->settings['timestamp'] = false; + + $this->load_template('default'); + $this->print = new csstidy_print($this); + $this->optimise = new csstidy_optimise($this); +} + +/** + * Get the value of a setting. + * @param string $setting + * @access public + * @return mixed + * @version 1.0 + */ +function get_cfg($setting) +{ + if(isset($this->settings[$setting])) + { + return $this->settings[$setting]; + } + return false; +} + +/** + * Set the value of a setting. + * @param string $setting + * @param mixed $value + * @access public + * @return bool + * @version 1.0 + */ +function set_cfg($setting,$value) +{ + if(isset($this->settings[$setting]) && $value !== '') + { + $this->settings[$setting] = $value; + return true; + } + return false; +} + +/** + * Adds a token to $this->tokens + * @param mixed $type + * @param string $data + * @param bool $do add a token even if preserve_css is off + * @access private + * @version 1.0 + */ +function _add_token($type, $data, $do = false) { + if($this->get_cfg('preserve_css') || $do) { + $this->tokens[] = array($type, ($type == COMMENT) ? $data : trim($data)); + } +} + +/** + * Add a message to the message log + * @param string $message + * @param string $type + * @param integer $line + * @access private + * @version 1.0 + */ +function log($message,$type,$line = -1) +{ + if($line === -1) + { + $line = $this->line; + } + $line = intval($line); + $add = array('m' => $message, 't' => $type); + if(!isset($this->log[$line]) || !in_array($add,$this->log[$line])) + { + $this->log[$line][] = $add; + } +} + +/** + * Parse unicode notations and find a replacement character + * @param string $string + * @param integer $i + * @access private + * @return string + * @version 1.2 + */ +function _unicode(&$string, &$i) +{ + ++$i; + $add = ''; + $tokens =& $GLOBALS['csstidy']['tokens']; + $replaced = false; + + while($i < strlen($string) && (ctype_xdigit($string{$i}) || ctype_space($string{$i})) && strlen($add) < 6) + { + $add .= $string{$i}; + + if(ctype_space($string{$i})) { + break; + } + $i++; + } + + if(hexdec($add) > 47 && hexdec($add) < 58 || hexdec($add) > 64 && hexdec($add) < 91 || hexdec($add) > 96 && hexdec($add) < 123) + { + $this->log('Replaced unicode notation: Changed \\'. $add .' to ' . chr(hexdec($add)),'Information'); + $add = chr(hexdec($add)); + $replaced = true; + } + else { + $add = trim('\\'.$add); + } + + if(@ctype_xdigit($string{$i+1}) && ctype_space($string{$i}) + && !$replaced || !ctype_space($string{$i})) { + $i--; + } + + if($add != '\\' || !$this->get_cfg('remove_bslash') || strpos($tokens, $string{$i+1}) !== false) { + return $add; + } + + if($add == '\\') { + $this->log('Removed unnecessary backslash','Information'); + } + return ''; +} + +/** + * Loads a new template + * @param string $content either filename (if $from_file == true), content of a template file, "high_compression", "highest_compression", "low_compression", or "default" + * @param bool $from_file uses $content as filename if true + * @access public + * @version 1.1 + * @see http://csstidy.sourceforge.net/templates.php + */ +function load_template($content, $from_file=true) +{ + $predefined_templates =& $GLOBALS['csstidy']['predefined_templates']; + if($content == 'high_compression' || $content == 'default' || $content == 'highest_compression' || $content == 'low_compression') + { + $this->template = $predefined_templates[$content]; + return; + } + + if($from_file) + { + $content = strip_tags(file_get_contents($content),'<span>'); + } + $content = str_replace("\r\n","\n",$content); // Unify newlines (because the output also only uses \n) + $template = explode('|',$content); + + for ($i = 0; $i < count($template); $i++ ) + { + $this->template[$i] = $template[$i]; + } +} + +/** + * Starts parsing from URL + * @param string $url + * @access public + * @version 1.0 + */ +function parse_from_url($url) +{ + return $this->parse(@file_get_contents($url)); +} + +/** + * Checks if there is a token at the current position + * @param string $string + * @param integer $i + * @access public + * @version 1.11 + */ +function is_token(&$string, $i) +{ + $tokens =& $GLOBALS['csstidy']['tokens']; + return (strpos($tokens, $string{$i}) !== false && !csstidy::escaped($string,$i)); +} + + +/** + * Parses CSS in $string. The code is saved as array in $this->css + * @param string $string the CSS code + * @access public + * @return bool + * @version 1.1 + */ +function parse($string) { + // PHP bug? Settings need to be refreshed in PHP4 + $this->print = new csstidy_print($this); + $this->optimise = new csstidy_optimise($this); + + $all_properties =& $GLOBALS['csstidy']['all_properties']; + $at_rules =& $GLOBALS['csstidy']['at_rules']; + + $this->css = array(); + $this->print->input_css = $string; + $string = str_replace("\r\n","\n",$string) . ' '; + $cur_comment = ''; + + for ($i = 0, $size = strlen($string); $i < $size; $i++ ) + { + if($string{$i} == "\n" || $string{$i} == "\r") + { + ++$this->line; + } + + switch($this->status) + { + /* Case in at-block */ + case 'at': + if(csstidy::is_token($string,$i)) + { + if($string{$i} == '/' && @$string{$i+1} == '*') + { + $this->status = 'ic'; ++$i; + $this->from = 'at'; + } + elseif($string{$i} == '{') + { + $this->status = 'is'; + $this->_add_token(AT_START, $this->at); + } + elseif($string{$i} == ',') + { + $this->at = trim($this->at).','; + } + elseif($string{$i} == '\\') + { + $this->at .= $this->_unicode($string,$i); + } + } + else + { + $lastpos = strlen($this->at)-1; + if(!( (ctype_space($this->at{$lastpos}) || csstidy::is_token($this->at,$lastpos) && $this->at{$lastpos} == ',') && ctype_space($string{$i}))) + { + $this->at .= $string{$i}; + } + } + break; + + /* Case in-selector */ + case 'is': + if(csstidy::is_token($string,$i)) + { + if($string{$i} == '/' && @$string{$i+1} == '*' && trim($this->selector) == '') + { + $this->status = 'ic'; ++$i; + $this->from = 'is'; + } + elseif($string{$i} == '@' && trim($this->selector) == '') + { + // Check for at-rule + $this->invalid_at = true; + foreach($at_rules as $name => $type) + { + if(!strcasecmp(substr($string,$i+1,strlen($name)),$name)) + { + ($type == 'at') ? $this->at = '@'.$name : $this->selector = '@'.$name; + $this->status = $type; + $i += strlen($name); + $this->invalid_at = false; + } + } + + if($this->invalid_at) + { + $this->selector = '@'; + $invalid_at_name = ''; + for($j = $i+1; $j < $size; ++$j) + { + if(!ctype_alpha($string{$j})) + { + break; + } + $invalid_at_name .= $string{$j}; + } + $this->log('Invalid @-rule: '.$invalid_at_name.' (removed)','Warning'); + } + } + elseif(($string{$i} == '"' || $string{$i} == "'")) + { + $this->selector .= $string{$i}; + $this->status = 'instr'; + $this->str_char = $string{$i}; + $this->from = 'is'; + } + elseif($this->invalid_at && $string{$i} == ';') + { + $this->invalid_at = false; + $this->status = 'is'; + } + elseif($string{$i} == '{') + { + $this->status = 'ip'; + $this->_add_token(SEL_START, $this->selector); + $this->added = false; + } + elseif($string{$i} == '}') + { + $this->_add_token(AT_END, $this->at); + $this->at = ''; + $this->selector = ''; + $this->sel_separate = array(); + } + elseif($string{$i} == ',') + { + $this->selector = trim($this->selector).','; + $this->sel_separate[] = strlen($this->selector); + } + elseif($string{$i} == '\\') + { + $this->selector .= $this->_unicode($string,$i); + } + else $this->selector .= $string{$i}; + } + else + { + $lastpos = strlen($this->selector)-1; + if($lastpos == -1 || !( (ctype_space($this->selector{$lastpos}) || csstidy::is_token($this->selector,$lastpos) && $this->selector{$lastpos} == ',') && ctype_space($string{$i}))) + { + $this->selector .= $string{$i}; + } + } + break; + + /* Case in-property */ + case 'ip': + if(csstidy::is_token($string,$i)) + { + if(($string{$i} == ':' || $string{$i} == '=') && $this->property != '') + { + $this->status = 'iv'; + if(csstidy::property_is_valid($this->property) || !$this->get_cfg('discard_invalid_properties')) { + $this->_add_token(PROPERTY, $this->property); + } + } + elseif($string{$i} == '/' && @$string{$i+1} == '*' && $this->property == '') + { + $this->status = 'ic'; ++$i; + $this->from = 'ip'; + } + elseif($string{$i} == '}') + { + $this->explode_selectors(); + $this->status = 'is'; + $this->invalid_at = false; + $this->_add_token(SEL_END, $this->selector); + $this->selector = ''; + $this->property = ''; + } + elseif($string{$i} == ';') + { + $this->property = ''; + } + elseif($string{$i} == '\\') + { + $this->property .= $this->_unicode($string,$i); + } + } + elseif(!ctype_space($string{$i})) + { + $this->property .= $string{$i}; + } + break; + + /* Case in-value */ + case 'iv': + $pn = (($string{$i} == "\n" || $string{$i} == "\r") && $this->property_is_next($string,$i+1) || $i == strlen($string)-1); + if(csstidy::is_token($string,$i) || $pn) + { + if($string{$i} == '/' && @$string{$i+1} == '*') + { + $this->status = 'ic'; ++$i; + $this->from = 'iv'; + } + elseif(($string{$i} == '"' || $string{$i} == "'" || $string{$i} == '(')) + { + $this->sub_value .= $string{$i}; + $this->str_char = ($string{$i} == '(') ? ')' : $string{$i}; + $this->status = 'instr'; + $this->from = 'iv'; + } + elseif($string{$i} == ',') + { + $this->sub_value = trim($this->sub_value).','; + } + elseif($string{$i} == '\\') + { + $this->sub_value .= $this->_unicode($string,$i); + } + elseif($string{$i} == ';' || $pn) + { + if($this->selector{0} == '@' && isset($at_rules[substr($this->selector,1)]) && $at_rules[substr($this->selector,1)] == 'iv') + { + $this->sub_value_arr[] = trim($this->sub_value); + + $this->status = 'is'; + + switch($this->selector) + { + case '@charset': $this->charset = $this->sub_value_arr[0]; break; + case '@namespace': $this->namespace = implode(' ',$this->sub_value_arr); break; + case '@import': $this->import[] = implode(' ',$this->sub_value_arr); break; + } + + $this->sub_value_arr = array(); + $this->sub_value = ''; + $this->selector = ''; + $this->sel_separate = array(); + } + else + { + $this->status = 'ip'; + } + } + elseif($string{$i} != '}') + { + $this->sub_value .= $string{$i}; + } + if(($string{$i} == '}' || $string{$i} == ';' || $pn) && !empty($this->selector)) + { + if($this->at == '') + { + $this->at = DEFAULT_AT; + } + + // case settings + if($this->get_cfg('lowercase_s')) + { + $this->selector = strtolower($this->selector); + } + $this->property = strtolower($this->property); + + $this->optimise->subvalue(); + if($this->sub_value != '') { + $this->sub_value_arr[] = $this->sub_value; + $this->sub_value = ''; + } + + $this->value = implode(' ',$this->sub_value_arr); + + $this->selector = trim($this->selector); + + $this->optimise->value(); + + $valid = csstidy::property_is_valid($this->property); + if((!$this->invalid_at || $this->get_cfg('preserve_css')) && (!$this->get_cfg('discard_invalid_properties') || $valid)) + { + $this->css_add_property($this->at,$this->selector,$this->property,$this->value); + $this->_add_token(VALUE, $this->value); + $this->optimise->shorthands(); + } + if(!$valid) + { + if($this->get_cfg('discard_invalid_properties')) + { + $this->log('Removed invalid property: '.$this->property,'Warning'); + } + else + { + $this->log('Invalid property in '.strtoupper($this->get_cfg('css_level')).': '.$this->property,'Warning'); + } + } + + $this->property = ''; + $this->sub_value_arr = array(); + $this->value = ''; + } + if($string{$i} == '}') + { + $this->explode_selectors(); + $this->_add_token(SEL_END, $this->selector); + $this->status = 'is'; + $this->invalid_at = false; + $this->selector = ''; + } + } + elseif(!$pn) + { + $this->sub_value .= $string{$i}; + + if(ctype_space($string{$i})) + { + $this->optimise->subvalue(); + if($this->sub_value != '') { + $this->sub_value_arr[] = $this->sub_value; + $this->sub_value = ''; + } + } + } + break; + + /* Case in string */ + case 'instr': + if($this->str_char == ')' && $string{$i} == '"' && !$this->str_in_str && !csstidy::escaped($string,$i)) + { + $this->str_in_str = true; + } + elseif($this->str_char == ')' && $string{$i} == '"' && $this->str_in_str && !csstidy::escaped($string,$i)) + { + $this->str_in_str = false; + } + if($string{$i} == $this->str_char && !csstidy::escaped($string,$i) && !$this->str_in_str) + { + $this->status = $this->from; + } + $temp_add = $string{$i}; + // ...and no not-escaped backslash at the previous position + if( ($string{$i} == "\n" || $string{$i} == "\r") && !($string{$i-1} == '\\' && !csstidy::escaped($string,$i-1)) ) + { + $temp_add = "\\A "; + $this->log('Fixed incorrect newline in string','Warning'); + } + if($this->from == 'iv') + { + $this->sub_value .= $temp_add; + } + elseif($this->from == 'is') + { + $this->selector .= $temp_add; + } + break; + + /* Case in-comment */ + case 'ic': + if($string{$i} == '*' && $string{$i+1} == '/') + { + $this->status = $this->from; + $i++; + $this->_add_token(COMMENT, $cur_comment); + $cur_comment = ''; + } + else + { + $cur_comment .= $string{$i}; + } + break; + } + } + + $this->optimise->postparse(); + + $this->print->_reset(); + + return !(empty($this->css) && empty($this->import) && empty($this->charset) && empty($this->tokens) && empty($this->namespace)); +} + +/** + * Explodes selectors + * @access private + * @version 1.0 + */ +function explode_selectors() +{ + // Explode multiple selectors + if($this->get_cfg('merge_selectors') == 1) + { + $new_sels = array(); + $lastpos = 0; + $this->sel_separate[] = strlen($this->selector); + foreach($this->sel_separate as $num => $pos) + { + if($num == count($this->sel_separate)-1) { + $pos += 1; + } + + $new_sels[] = substr($this->selector,$lastpos,$pos-$lastpos-1); + $lastpos = $pos; + } + + if(count($new_sels) > 1) + { + foreach($new_sels as $selector) + { + $this->merge_css_blocks($this->at,$selector,$this->css[$this->at][$this->selector]); + } + unset($this->css[$this->at][$this->selector]); + } + } + $this->sel_separate = array(); +} + +/** + * Checks if a character is escaped (and returns true if it is) + * @param string $string + * @param integer $pos + * @access public + * @return bool + * @version 1.02 + */ +function escaped(&$string,$pos) +{ + return !(@($string{$pos-1} != '\\') || csstidy::escaped($string,$pos-1)); +} + +/** + * Adds a property with value to the existing CSS code + * @param string $media + * @param string $selector + * @param string $property + * @param string $new_val + * @access private + * @version 1.2 + */ +function css_add_property($media,$selector,$property,$new_val) +{ + if($this->get_cfg('preserve_css') || trim($new_val) == '') { + return; + } + + $this->added = true; + if(isset($this->css[$media][$selector][$property])) + { + if((csstidy::is_important($this->css[$media][$selector][$property]) && csstidy::is_important($new_val)) || !csstidy::is_important($this->css[$media][$selector][$property])) + { + unset($this->css[$media][$selector][$property]); + $this->css[$media][$selector][$property] = trim($new_val); + } + } + else + { + $this->css[$media][$selector][$property] = trim($new_val); + } +} + +/** + * Adds CSS to an existing media/selector + * @param string $media + * @param string $selector + * @param array $css_add + * @access private + * @version 1.1 + */ +function merge_css_blocks($media,$selector,$css_add) +{ + foreach($css_add as $property => $value) + { + $this->css_add_property($media,$selector,$property,$value,false); + } +} + +/** + * Checks if $value is !important. + * @param string $value + * @return bool + * @access public + * @version 1.0 + */ +function is_important(&$value) +{ + return (!strcasecmp(substr(str_replace($GLOBALS['csstidy']['whitespace'],'',$value),-10,10),'!important')); +} + +/** + * Returns a value without !important + * @param string $value + * @return string + * @access public + * @version 1.0 + */ +function gvw_important($value) +{ + if(csstidy::is_important($value)) + { + $value = trim($value); + $value = substr($value,0,-9); + $value = trim($value); + $value = substr($value,0,-1); + $value = trim($value); + return $value; + } + return $value; +} + +/** + * Checks if the next word in a string from pos is a CSS property + * @param string $istring + * @param integer $pos + * @return bool + * @access private + * @version 1.2 + */ +function property_is_next($istring, $pos) +{ + $all_properties =& $GLOBALS['csstidy']['all_properties']; + $istring = substr($istring,$pos,strlen($istring)-$pos); + $pos = strpos($istring,':'); + if($pos === false) + { + return false; + } + $istring = strtolower(trim(substr($istring,0,$pos))); + if(isset($all_properties[$istring])) + { + $this->log('Added semicolon to the end of declaration','Warning'); + return true; + } + return false; +} + +/** + * Checks if a property is valid + * @param string $property + * @return bool; + * @access public + * @version 1.0 + */ +function property_is_valid($property) { + $all_properties =& $GLOBALS['csstidy']['all_properties']; + return (isset($all_properties[$property]) && strpos($all_properties[$property],strtoupper($this->get_cfg('css_level'))) !== false ); +} + +} +?> \ No newline at end of file Added: trunk/lib/csstidy-1.2/class.csstidy_optimise.php =================================================================== --- trunk/lib/csstidy-1.2/class.csstidy_optimise.php (rev 0) +++ trunk/lib/csstidy-1.2/class.csstidy_optimise.php 2006-12-21 06:30:19 UTC (rev 906) @@ -0,0 +1,799 @@ +<?php +/** + * CSSTidy - CSS Parser and Optimiser + * + * CSS Optimising Class + * This class optimises CSS data generated by csstidy. + * + * This file is part of CSSTidy. + * + * CSSTidy is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * CSSTidy is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with CSSTidy; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + * @license http://opensource.org/licenses/gpl-license.php GNU Public License + * @package csstidy + * @author Florian Schmitz (floele at gmail dot com) 2005-2006 + */ + +/** + * CSS Optimising Class + * + * This class optimises CSS data generated by csstidy. + * + * @package csstidy + * @author Florian Schmitz (floele at gmail dot com) 2005-2006 + * @version 1.0 + */ + +class csstidy_optimise +{ + /** + * Constructor + * @param array $css contains the class csstidy + * @access private + * @version 1.0 + */ + function csstidy_optimise(&$css) + { + $this->parser =& $css; + $this->css =& $css->css; + $this->sub_value =& $css->sub_value; + $this->at =& $css->at; + $this->selector =& $css->selector; + $this->property =& $css->property; + $this->value =& $css->value; + } + + /** + * Optimises $css after parsing + * @access public + * @version 1.0 + */ + function postparse() + { + if ($this->parser->get_cfg('preserve_css')) { + return; + } + + if ($this->parser->get_cfg('merge_selectors') == 2) + { + foreach ($this->css as $medium => $value) + { + $this->merge_selectors($this->css[$medium]); + } + } + + if ($this->parser->get_cfg('optimise_shorthands') > 0) + { + foreach ($this->css as $medium => $value) + { + foreach ($value as $selector => $value1) + { + $this->css[$medium][$selector] = csstidy_optimise::merge_4value_shorthands($this->css[$medium][$selector]); + + if ($this->parser->get_cfg('optimise_shorthands') < 2) { + continue; + } + + $this->css[$medium][$selector] = csstidy_optimise::merge_bg($this->css[$medium][$selector]); + if (empty($this->css[$medium][$selector])) { + unset($this->css[$medium][$selector]); + } + } + } + } + } + + /** + * Optimises values + * @access public + * @version 1.0 + */ + function value() + { + $shorthands =& $GLOBALS['csstidy']['shorthands']; + + // optimise shorthand properties + if(isset($shorthands[$this->property])) + { + $temp = csstidy_optimise::shorthand($this->value); // FIXME - move + if($temp != $this->value) + { + $this->parser->log('Optimised shorthand notation ('.$this->property.'): Changed "'.$this->value.'" to "'.$temp.'"','Information'); + } + $this->value = $temp; + } + + // Remove whitespace at ! important + if($this->value != $this->compress_important($this->value)) + { + $this->parser->log('Optimised !important','Information'); + } + } + + /** + * Optimises shorthands + * @access public + * @version 1.0 + */ + function shorthands() + { + $shorthands =& $GLOBALS['csstidy']['shorthands']; + + if(!$this->parser->get_cfg('optimise_shorthands') || $this->parser->get_cfg('preserve_css')) { + return; + } + + if($this->property == 'background' && $this->parser->get_cfg('optimise_shorthands') > 1) + { + unset($this->css[$this->at][$this->selector]['background']); + $this->parser->merge_css_blocks($this->at,$this->selector,csstidy_optimise::dissolve_short_bg($this->value)); + } + if(isset($shorthands[$this->property])) + { + $this->parser->merge_css_blocks($this->at,$this->selector,csstidy_optimise::dissolve_4value_shorthands($this->property,$this->value)); + if(is_array($shorthands[$this->property])) + { + unset($this->css[$this->at][$this->selector][$this->property]); + } + } + } + + /** + * Optimises a sub-value + * @access public + * @version 1.0 + */ + function subvalue() + { + $replace_colors =& $GLOBALS['csstidy']['replace_colors']; + + $this->sub_value = trim($this->sub_value); + if($this->sub_value == '') // caution : '0' + { + return; + } + + // Compress font-weight + if($this->property == 'font-weight' && $this->parser->get_cfg('compress_font-weight')) + { + $important = ''; + if(csstidy::is_important($this->sub_value)) + { + $important = ' !important'; + $this->sub_value = csstidy::gvw_important($this->sub_value); + } + if($this->sub_value == 'bold') + { + $this->sub_value = '700'.$important; + $this->parser->log('Optimised font-weight: Changed "bold" to "700"','Information'); + } + else if($this->sub_value == 'normal') + { + $this->sub_value = '400'.$important; + $this->parser->log('Optimised font-weight: Changed "normal" to "400"','Information'); + } + } + + $temp = $this->compress_numbers($this->sub_value); + if($temp != $this->sub_value) + { + if(strlen($temp) > strlen($this->sub_value)) { + $this->parser->log('Fixed invalid number: Changed "'.$this->sub_value.'" to "'.$temp.'"','Warning'); + } else { + $this->parser->log('Optimised number: Changed "'.$this->sub_value.'" to "'.$temp.'"','Information'); + } + $this->sub_value = $temp; + } + if($this->parser->get_cfg('compress_colors')) + { + $temp = $this->cut_color($this->sub_value); + if($temp !== $this->sub_value) + { + if(isset($replace_colors[$this->sub_value])) { + $this->parser->log('Fixed invalid color name: Changed "'.$this->sub_value.'" to "'.$temp.'"','Warning'); + } else { + $this->parser->log('Optimised color: Changed "'.$this->sub_value.'" to "'.$temp.'"','Information'); + } + $this->sub_value = $temp; + } + } + } + + /** + * Compresses shorthand values. Example: margin:1px 1px 1px 1px -> margin:1px + * @param string $value + * @access public + * @return string + * @version 1.0 + */ + function shorthand($value) + { + $important = ''; + if(csstidy::is_important($value)) + { + $values = csstidy::gvw_important($value); + $important = ' !important'; + } + else $values = $value; + + $values = explode(' ',$values); + switch(count($values)) + { + case 4: + if($values[0] == $values[1] && $values[0] == $values[2] && $values[0] == $values[3]) + { + return $values[0].$important; + } + elseif($values[1] == $values[3] && $values[0] == $values[2]) + { + return $values[0].' '.$values[1].$important; + } + elseif($values[1] == $values[3]) + { + return $values[0].' '.$values[1].' '.$values[2].$important; + } + break; + + case 3: + if($values[0] == $values[1] && $values[0] == $values[2]) + { + return $values[0].$important; + } + elseif($values[0] == $values[2]) + { + return $values[0].' '.$values[1].$important; + } + break; + + case 2: + if($values[0] == $values[1]) + ... [truncated message content] |