]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - jssource/src_files/include/javascript/phpjs/get_html_translation_table.js
Release 6.5.0
[Github/sugarcrm.git] / jssource / src_files / include / javascript / phpjs / get_html_translation_table.js
1 /*
2  * More info at: http://phpjs.org
3  *
4  * This is version: 3.25
5  * php.js is copyright 2011 Kevin van Zonneveld.
6  *
7  * Portions copyright Brett Zamir (http://brett-zamir.me), Kevin van Zonneveld
8  * (http://kevin.vanzonneveld.net), Onno Marsman, Theriault, Michael White
9  * (http://getsprink.com), Waldo Malqui Silva, Paulo Freitas, Jonas Raoni
10  * Soares Silva (http://www.jsfromhell.com), Jack, Philip Peterson, Legaev
11  * Andrey, Ates Goral (http://magnetiq.com), Ratheous, Alex, Rafa? Kukawski
12  * (http://blog.kukawski.pl), Martijn Wieringa, lmeyrick
13  * (https://sourceforge.net/projects/bcmath-js/), Nate, Enrique Gonzalez,
14  * Philippe Baumann, Webtoolkit.info (http://www.webtoolkit.info/), Jani
15  * Hartikainen, Ole Vrijenhoek, Ash Searle (http://hexmen.com/blog/), Carlos
16  * R. L. Rodrigues (http://www.jsfromhell.com), travc, Michael Grier,
17  * Erkekjetter, Johnny Mast (http://www.phpvrouwen.nl), Rafa? Kukawski
18  * (http://blog.kukawski.pl/), GeekFG (http://geekfg.blogspot.com), Andrea
19  * Giammarchi (http://webreflection.blogspot.com), WebDevHobo
20  * (http://webdevhobo.blogspot.com/), d3x, marrtins,
21  * http://stackoverflow.com/questions/57803/how-to-convert-decimal-to-hex-in-javascript,
22  * pilus, stag019, T.Wild, Martin (http://www.erlenwiese.de/), majak, Marc
23  * Palau, Mirek Slugen, Chris, Diplom@t (http://difane.com/), Breaking Par
24  * Consulting Inc
25  * (http://www.breakingpar.com/bkp/home.nsf/0/87256B280015193F87256CFB006C45F7),
26  * gettimeofday, Arpad Ray (mailto:arpad@php.net), Oleg Eremeev, Josh Fraser
27  * (http://onlineaspect.com/2007/06/08/auto-detect-a-time-zone-with-javascript/),
28  * Steve Hilder, mdsjack (http://www.mdsjack.bo.it), Kevin van Zonneveld
29  * (http://kevin.vanzonneveld.net/), gorthaur, Aman Gupta, Sakimori, Joris,
30  * Robin, Kankrelune (http://www.webfaktory.info/), Alfonso Jimenez
31  * (http://www.alfonsojimenez.com), David, Felix Geisendoerfer
32  * (http://www.debuggable.com/felix), Lars Fischer, Karol Kowalski, Imgen Tata
33  * (http://www.myipdf.com/), Steven Levithan (http://blog.stevenlevithan.com),
34  * Tim de Koning (http://www.kingsquare.nl), Dreamer, AJ, Paul Smith, KELAN,
35  * Pellentesque Malesuada, felix, Michael White, Mailfaker
36  * (http://www.weedem.fr/), Thunder.m, Tyler Akins (http://rumkin.com),
37  * saulius, Public Domain (http://www.json.org/json2.js), Caio Ariede
38  * (http://caioariede.com), Steve Clay, David James, madipta, Marco, Ole
39  * Vrijenhoek (http://www.nervous.nl/), class_exists, T. Wild, noname, Arno,
40  * Frank Forte, Francois, Scott Cariss, Slawomir Kaniecki, date, Itsacon
41  * (http://www.itsacon.net/), Billy, vlado houba, Jalal Berrami,
42  * ReverseSyntax, Mateusz "loonquawl" Zalega, john (http://www.jd-tech.net),
43  * mktime, Douglas Crockford (http://javascript.crockford.com), ger, Nick
44  * Kolosov (http://sammy.ru), Nathan, nobbler, Fox, marc andreu, Alex Wilson,
45  * Raphael (Ao RUDLER), Bayron Guevara, Adam Wallner
46  * (http://web2.bitbaro.hu/), paulo kuong, jmweb, Lincoln Ramsay, djmix,
47  * Pyerre, Jon Hohle, Thiago Mata (http://thiagomata.blog.com), lmeyrick
48  * (https://sourceforge.net/projects/bcmath-js/this.), Linuxworld, duncan,
49  * Gilbert, Sanjoy Roy, Shingo, sankai, Oskar Larsson H�gfeldt
50  * (http://oskar-lh.name/), Denny Wardhana, 0m3r, Everlasto, Subhasis Deb,
51  * josh, jd, Pier Paolo Ramon (http://www.mastersoup.com/), P, merabi, Soren
52  * Hansen, EdorFaus, Eugene Bulkin (http://doubleaw.com/), Der Simon
53  * (http://innerdom.sourceforge.net/), echo is bad, JB, LH, kenneth, J A R,
54  * Marc Jansen, Stoyan Kyosev (http://www.svest.org/), Francesco, XoraX
55  * (http://www.xorax.info), Ozh, Brad Touesnard, MeEtc
56  * (http://yass.meetcweb.com), Peter-Paul Koch
57  * (http://www.quirksmode.org/js/beat.html), Olivier Louvignes
58  * (http://mg-crea.com/), T0bsn, Tim Wiel, Bryan Elliott, nord_ua, Martin, JT,
59  * David Randall, Thomas Beaucourt (http://www.webapp.fr), Tim de Koning,
60  * stensi, Pierre-Luc Paour, Kristof Coomans (SCK-CEN Belgian Nucleair
61  * Research Centre), Martin Pool, Kirk Strobeck, Rick Waldron, Brant Messenger
62  * (http://www.brantmessenger.com/), Devan Penner-Woelk, Saulo Vallory, Wagner
63  * B. Soares, Artur Tchernychev, Valentina De Rosa, Jason Wong
64  * (http://carrot.org/), Christoph, Daniel Esteban, strftime, Mick@el, rezna,
65  * Simon Willison (http://simonwillison.net), Anton Ongson, Gabriel Paderni,
66  * Marco van Oort, penutbutterjelly, Philipp Lenssen, Bjorn Roesbeke
67  * (http://www.bjornroesbeke.be/), Bug?, Eric Nagel, Tomasz Wesolowski,
68  * Evertjan Garretsen, Bobby Drake, Blues (http://tech.bluesmoon.info/), Luke
69  * Godfrey, Pul, uestla, Alan C, Ulrich, Rafal Kukawski, Yves Sucaet,
70  * sowberry, Norman "zEh" Fuchs, hitwork, Zahlii, johnrembo, Nick Callen,
71  * Steven Levithan (stevenlevithan.com), ejsanders, Scott Baker, Brian Tafoya
72  * (http://www.premasolutions.com/), Philippe Jausions
73  * (http://pear.php.net/user/jausions), Aidan Lister
74  * (http://aidanlister.com/), Rob, e-mike, HKM, ChaosNo1, metjay, strcasecmp,
75  * strcmp, Taras Bogach, jpfle, Alexander Ermolaev
76  * (http://snippets.dzone.com/user/AlexanderErmolaev), DxGx, kilops, Orlando,
77  * dptr1988, Le Torbi, James (http://www.james-bell.co.uk/), Pedro Tainha
78  * (http://www.pedrotainha.com), James, Arnout Kazemier
79  * (http://www.3rd-Eden.com), Chris McMacken, Yannoo, jakes, gabriel paderni,
80  * FGFEmperor, Greg Frazier, baris ozdil, 3D-GRAF, daniel airton wermann
81  * (http://wermann.com.br), Howard Yeend, Diogo Resende, Allan Jensen
82  * (http://www.winternet.no), Benjamin Lupton, Atli ?�r, Maximusya, davook,
83  * Tod Gentille, Ryan W Tenney (http://ryan.10e.us), Nathan Sepulveda, Cord,
84  * fearphage (http://http/my.opera.com/fearphage/), Victor, Rafa? Kukawski
85  * (http://kukawski.pl), Matteo, Manish, Matt Bradley, Riddler
86  * (http://www.frontierwebdev.com/), Alexander M Beedie, T.J. Leahy, Rafa?
87  * Kukawski, taith, Luis Salazar (http://www.freaky-media.com/), FremyCompany,
88  * Rival, Luke Smith (http://lucassmith.name), Andrej Pavlovic, Garagoth, Le
89  * Torbi (http://www.letorbi.de/), Dino, Josep Sanz (http://www.ws3.es/), rem,
90  * Russell Walker (http://www.nbill.co.uk/), Jamie Beck
91  * (http://www.terabit.ca/), setcookie, Michael, YUI Library:
92  * http://developer.yahoo.com/yui/docs/YAHOO.util.DateLocale.html, Blues at
93  * http://hacks.bluesmoon.info/strftime/strftime.js, Ben
94  * (http://benblume.co.uk/), DtTvB
95  * (http://dt.in.th/2008-09-16.string-length-in-bytes.html), Andreas, William,
96  * meo, incidence, Cagri Ekin, Amirouche, Amir Habibi
97  * (http://www.residence-mixte.com/), Kheang Hok Chin
98  * (http://www.distantia.ca/), Jay Klehr, Lorenzo Pisani, Tony, Yen-Wei Liu,
99  * Greenseed, mk.keck, Leslie Hoare, dude, booeyOH, Ben Bryan
100  *
101  * Dual licensed under the MIT (MIT-LICENSE.txt)
102  * and GPL (GPL-LICENSE.txt) licenses.
103  *
104  * Permission is hereby granted, free of charge, to any person obtaining a
105  * copy of this software and associated documentation files (the
106  * "Software"), to deal in the Software without restriction, including
107  * without limitation the rights to use, copy, modify, merge, publish,
108  * distribute, sublicense, and/or sell copies of the Software, and to
109  * permit persons to whom the Software is furnished to do so, subject to
110  * the following conditions:
111  *
112  * The above copyright notice and this permission notice shall be included
113  * in all copies or substantial portions of the Software.
114  *
115  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
116  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
117  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
118  * IN NO EVENT SHALL KEVIN VAN ZONNEVELD BE LIABLE FOR ANY CLAIM, DAMAGES
119  * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
120  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
121  * OTHER DEALINGS IN THE SOFTWARE.
122  */
123
124 function get_html_translation_table (table, quote_style) {
125     // http://kevin.vanzonneveld.net
126     // +   original by: Philip Peterson
127     // +    revised by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
128     // +   bugfixed by: noname
129     // +   bugfixed by: Alex
130     // +   bugfixed by: Marco
131     // +   bugfixed by: madipta
132     // +   improved by: KELAN
133     // +   improved by: Brett Zamir (http://brett-zamir.me)
134     // +   bugfixed by: Brett Zamir (http://brett-zamir.me)
135     // +      input by: Frank Forte
136     // +   bugfixed by: T.Wild
137     // +      input by: Ratheous
138     // %          note: It has been decided that we're not going to add global
139     // %          note: dependencies to php.js, meaning the constants are not
140     // %          note: real constants, but strings instead. Integers are also supported if someone
141     // %          note: chooses to create the constants themselves.
142     // *     example 1: get_html_translation_table('HTML_SPECIALCHARS');
143     // *     returns 1: {'"': '&quot;', '&': '&amp;', '<': '&lt;', '>': '&gt;'}
144     var entities = {},
145         hash_map = {},
146         decimal = 0,
147         symbol = '';
148     var constMappingTable = {},
149         constMappingQuoteStyle = {};
150     var useTable = {},
151         useQuoteStyle = {};
152
153     // Translate arguments
154     constMappingTable[0] = 'HTML_SPECIALCHARS';
155     constMappingTable[1] = 'HTML_ENTITIES';
156     constMappingQuoteStyle[0] = 'ENT_NOQUOTES';
157     constMappingQuoteStyle[2] = 'ENT_COMPAT';
158     constMappingQuoteStyle[3] = 'ENT_QUOTES';
159
160     useTable = !isNaN(table) ? constMappingTable[table] : table ? table.toUpperCase() : 'HTML_SPECIALCHARS';
161     useQuoteStyle = !isNaN(quote_style) ? constMappingQuoteStyle[quote_style] : quote_style ? quote_style.toUpperCase() : 'ENT_COMPAT';
162
163     if (useTable !== 'HTML_SPECIALCHARS' && useTable !== 'HTML_ENTITIES') {
164         throw new Error("Table: " + useTable + ' not supported');
165         // return false;
166     }
167
168     entities['38'] = '&amp;';
169     if (useTable === 'HTML_ENTITIES') {
170         entities['160'] = '&nbsp;';
171         entities['161'] = '&iexcl;';
172         entities['162'] = '&cent;';
173         entities['163'] = '&pound;';
174         entities['164'] = '&curren;';
175         entities['165'] = '&yen;';
176         entities['166'] = '&brvbar;';
177         entities['167'] = '&sect;';
178         entities['168'] = '&uml;';
179         entities['169'] = '&copy;';
180         entities['170'] = '&ordf;';
181         entities['171'] = '&laquo;';
182         entities['172'] = '&not;';
183         entities['173'] = '&shy;';
184         entities['174'] = '&reg;';
185         entities['175'] = '&macr;';
186         entities['176'] = '&deg;';
187         entities['177'] = '&plusmn;';
188         entities['178'] = '&sup2;';
189         entities['179'] = '&sup3;';
190         entities['180'] = '&acute;';
191         entities['181'] = '&micro;';
192         entities['182'] = '&para;';
193         entities['183'] = '&middot;';
194         entities['184'] = '&cedil;';
195         entities['185'] = '&sup1;';
196         entities['186'] = '&ordm;';
197         entities['187'] = '&raquo;';
198         entities['188'] = '&frac14;';
199         entities['189'] = '&frac12;';
200         entities['190'] = '&frac34;';
201         entities['191'] = '&iquest;';
202         entities['192'] = '&Agrave;';
203         entities['193'] = '&Aacute;';
204         entities['194'] = '&Acirc;';
205         entities['195'] = '&Atilde;';
206         entities['196'] = '&Auml;';
207         entities['197'] = '&Aring;';
208         entities['198'] = '&AElig;';
209         entities['199'] = '&Ccedil;';
210         entities['200'] = '&Egrave;';
211         entities['201'] = '&Eacute;';
212         entities['202'] = '&Ecirc;';
213         entities['203'] = '&Euml;';
214         entities['204'] = '&Igrave;';
215         entities['205'] = '&Iacute;';
216         entities['206'] = '&Icirc;';
217         entities['207'] = '&Iuml;';
218         entities['208'] = '&ETH;';
219         entities['209'] = '&Ntilde;';
220         entities['210'] = '&Ograve;';
221         entities['211'] = '&Oacute;';
222         entities['212'] = '&Ocirc;';
223         entities['213'] = '&Otilde;';
224         entities['214'] = '&Ouml;';
225         entities['215'] = '&times;';
226         entities['216'] = '&Oslash;';
227         entities['217'] = '&Ugrave;';
228         entities['218'] = '&Uacute;';
229         entities['219'] = '&Ucirc;';
230         entities['220'] = '&Uuml;';
231         entities['221'] = '&Yacute;';
232         entities['222'] = '&THORN;';
233         entities['223'] = '&szlig;';
234         entities['224'] = '&agrave;';
235         entities['225'] = '&aacute;';
236         entities['226'] = '&acirc;';
237         entities['227'] = '&atilde;';
238         entities['228'] = '&auml;';
239         entities['229'] = '&aring;';
240         entities['230'] = '&aelig;';
241         entities['231'] = '&ccedil;';
242         entities['232'] = '&egrave;';
243         entities['233'] = '&eacute;';
244         entities['234'] = '&ecirc;';
245         entities['235'] = '&euml;';
246         entities['236'] = '&igrave;';
247         entities['237'] = '&iacute;';
248         entities['238'] = '&icirc;';
249         entities['239'] = '&iuml;';
250         entities['240'] = '&eth;';
251         entities['241'] = '&ntilde;';
252         entities['242'] = '&ograve;';
253         entities['243'] = '&oacute;';
254         entities['244'] = '&ocirc;';
255         entities['245'] = '&otilde;';
256         entities['246'] = '&ouml;';
257         entities['247'] = '&divide;';
258         entities['248'] = '&oslash;';
259         entities['249'] = '&ugrave;';
260         entities['250'] = '&uacute;';
261         entities['251'] = '&ucirc;';
262         entities['252'] = '&uuml;';
263         entities['253'] = '&yacute;';
264         entities['254'] = '&thorn;';
265         entities['255'] = '&yuml;';
266     }
267
268     if (useQuoteStyle !== 'ENT_NOQUOTES') {
269         entities['34'] = '&quot;';
270     }
271     if (useQuoteStyle === 'ENT_QUOTES') {
272         entities['39'] = '&#39;';
273     }
274     entities['60'] = '&lt;';
275     entities['62'] = '&gt;';
276
277
278     // ascii decimals to real symbols
279     for (decimal in entities) {
280         symbol = String.fromCharCode(decimal);
281         hash_map[symbol] = entities[decimal];
282     }
283
284     return hash_map;
285 }