Commit 0e77fa23a5d079de94ebae618da1b7189b5b2ec0
1 parent
e114bd6c
Exists in
master
and in
7 other branches
Correção na verificação de erros de timeout
Showing
7 changed files
with
2947 additions
and
238 deletions
Show diff stats
ferramentas/buscafotos/funcoes.php
... | ... | @@ -4,6 +4,7 @@ require_once("../../classesphp/pega_variaveis.php"); |
4 | 4 | require_once("../../pacotes/cpaint/cpaint2.inc.php"); |
5 | 5 | require_once("../../ms_configura.php"); |
6 | 6 | require_once("../../pacotes/phpflickr/phpFlickr.php"); |
7 | +error_reporting(0); | |
7 | 8 | $cp = new cpaint(); |
8 | 9 | if($funcao == "listafotosflickr") |
9 | 10 | {$cp->register('listafotosflickr');} |
... | ... | @@ -33,6 +34,8 @@ function listafotospanoramio() |
33 | 34 | global $ret, $cp,$ai,$af; |
34 | 35 | $ret = explode(" ",$ret); |
35 | 36 | $resultado = ""; |
37 | + //echo "http://www.panoramio.com/map/get_panoramas.php?order=upload_date&set=public&from=".$ai."&to=".$af."&minx=".$ret[0]."&miny=".$ret[1]."&maxx=".$ret[2]."&maxy=".$ret[3]."&size=thumbnail"; | |
38 | + //return; | |
36 | 39 | $recent = file_get_contents("http://www.panoramio.com/map/get_panoramas.php?order=upload_date&set=public&from=".$ai."&to=".$af."&minx=".$ret[0]."&miny=".$ret[1]."&maxx=".$ret[2]."&maxy=".$ret[3]."&size=thumbnail"); |
37 | 40 | $recent = str_replace("\n","",$recent); |
38 | 41 | $recent = str_replace("'","",$recent); | ... | ... |
ferramentas/buscafotos/index.htm
... | ... | @@ -21,17 +21,17 @@ |
21 | 21 | De qualquer forma, são mostrados no máximo 250 registros. |
22 | 22 | O ano diz respeito a inclusão da foto no Flickr |
23 | 23 | <p>Texto: <input style='cursor:text' class=digitar type=text size=30 value="" id='texto' /> |
24 | - <p>Ano inicial: <input style='cursor:text' class=digitar type=text size=10 value="2008" id='ai' /> | |
25 | - Ano final: <input style='cursor:text' class=digitar type=text size=10 value="2008" id='af' /> | |
24 | + <p>Ano inicial: <input style='cursor:text' class=digitar type=text size=10 value="2009" id='ai' /> | |
25 | + Ano final: <input style='cursor:text' class=digitar type=text size=10 value="2009" id='af' /> | |
26 | 26 | </div> |
27 | 27 | <div style=width:350px > |
28 | 28 | <span style=width:30px onclick='busca("1")' ><input id=botao2 size=20 type=button value='Procurar fotos' /></span> |
29 | 29 | <input type=radio onclick="esconde(this)" name=buscador value=flickr id=buscaflickr /><a href="http://www.flickr.com" target="_blank" >Flickr</a> |
30 | - <input type=radio onclick="esconde(this)" name=buscador value=panoramio id=buscapanoramio checked /><a href="http://www.panoramio.com" target="_blank" >Panoramio</a> | |
30 | + <input type=radio onclick="esconde(this)" name=buscador value=panoramio id=buscapanoramio /><a href="http://www.panoramio.com" target="_blank" >Panoramio</a> | |
31 | 31 | <input type=radio onclick="esconde(this)" name=buscador value=panoramio id=buscalocr /><a href="http://www.locr.com" target="_blank" >Locr</a> |
32 | 32 | </div> |
33 | 33 | <div id="paginas" style="top:10px;"></div><br> |
34 | - <div style="top:0px;left:5px;display:block;width:90%;height:150px;overflow:auto" id="resultadofotos" >Aguarde...</div> | |
34 | + <div style="top:0px;left:5px;display:block;width:90%;height:150px;overflow:auto" id="resultadofotos" ></div> | |
35 | 35 | </div> |
36 | 36 | <script type="text/javascript"> |
37 | 37 | //chave de acesso ao flicker | ... | ... |
ferramentas/buscafotos/index.js
... | ... | @@ -38,7 +38,7 @@ function mostramenu() |
38 | 38 | { |
39 | 39 | $i("mensagem").style.display="none" |
40 | 40 | $i("busca").style.display="block" |
41 | - busca(1) | |
41 | + //busca(1) | |
42 | 42 | } |
43 | 43 | function busca(pagina) |
44 | 44 | { |
... | ... | @@ -98,6 +98,8 @@ function busca(pagina) |
98 | 98 | function listafotospanoramio(retorno) |
99 | 99 | { |
100 | 100 | aguarde("none") |
101 | + if (retorno.data==undefined ) | |
102 | + {$i("resultadofotos").innerHTML = "Erro. A operação demorou muito.";return;} | |
101 | 103 | $i("resultadofotos").style.height = "335px" |
102 | 104 | eval("var data = "+retorno.data) |
103 | 105 | if(!retorno.data) |
... | ... | @@ -137,6 +139,8 @@ function listafotospanoramio(retorno) |
137 | 139 | function listafotosflickr(retorno) |
138 | 140 | { |
139 | 141 | aguarde("none") |
142 | + if (retorno.data==undefined ) | |
143 | + {$i("resultadofotos").innerHTML = "Erro. A operação demorou muito.";return;} | |
140 | 144 | $i("resultadofotos").style.height = "150px" |
141 | 145 | if((!retorno.data) || (retorno.data == "")) |
142 | 146 | {ins = "<br><span style=color:red>Problemas no acesso aos dados!</span><br><br>";$i("resultadofotos").innerHTML = ins;return;} |
... | ... | @@ -172,6 +176,8 @@ function listafotosflickr(retorno) |
172 | 176 | function listafotoslocr(retorno) |
173 | 177 | { |
174 | 178 | aguarde("none") |
179 | + if (retorno.data==undefined ) | |
180 | + {$i("resultadofotos").innerHTML = "Erro. A operação demorou muito.";return;} | |
175 | 181 | $i("resultadofotos").style.height = "340px" |
176 | 182 | eval("var data = "+retorno.data) |
177 | 183 | if(!retorno.data) | ... | ... |
ferramentas/i3geo_tudo_compacto.js
... | ... | @@ -5180,119 +5180,1468 @@ YAHOO.util.Event.purgeElement(D,true);D.innerHTML="";for(var C in this){if(YAHOO |
5180 | 5180 | this._toggleContainer(false);};YAHOO.widget.AutoComplete.prototype._jumpSelection=function(){if(this._oCurItem){this._selectItem(this._oCurItem);}else{this._toggleContainer(false);}};YAHOO.widget.AutoComplete.prototype._moveSelection=function(G){if(this._bContainerOpen){var E=this._oCurItem;var F=-1;if(E){F=E._nItemIndex;}var D=(G==40)?(F+1):(F-1);if(D<-2||D>=this._nDisplayedItems){return ;}if(E){this._toggleHighlight(E,"from");this.itemArrowFromEvent.fire(this,E);}if(D==-1){if(this.delimChar&&this._sSavedQuery){if(!this._textMatchesOption()){this._elTextbox.value=this._sSavedQuery;}else{this._elTextbox.value=this._sSavedQuery+this._sCurQuery;}}else{this._elTextbox.value=this._sCurQuery;}this._oCurItem=null;return ;}if(D==-2){this._toggleContainer(false);return ;}var C=this._aListItems[D];var A=this._elContent;var B=((YAHOO.util.Dom.getStyle(A,"overflow")=="auto")||(YAHOO.util.Dom.getStyle(A,"overflowY")=="auto"));if(B&&(D>-1)&&(D<this._nDisplayedItems)){if(G==40){if((C.offsetTop+C.offsetHeight)>(A.scrollTop+A.offsetHeight)){A.scrollTop=(C.offsetTop+C.offsetHeight)-A.offsetHeight;}else{if((C.offsetTop+C.offsetHeight)<A.scrollTop){A.scrollTop=C.offsetTop;}}}else{if(C.offsetTop<A.scrollTop){this._elContent.scrollTop=C.offsetTop;}else{if(C.offsetTop>(A.scrollTop+A.offsetHeight)){this._elContent.scrollTop=(C.offsetTop+C.offsetHeight)-A.offsetHeight;}}}}this._toggleHighlight(C,"to");this.itemArrowToEvent.fire(this,C);if(this.typeAhead){this._updateValue(C);}}};YAHOO.widget.AutoComplete.prototype._onItemMouseover=function(A,B){if(B.prehighlightClassName){B._togglePrehighlight(this,"mouseover");}else{B._toggleHighlight(this,"to");}B.itemMouseOverEvent.fire(B,this);};YAHOO.widget.AutoComplete.prototype._onItemMouseout=function(A,B){if(B.prehighlightClassName){B._togglePrehighlight(this,"mouseout");}else{B._toggleHighlight(this,"from");}B.itemMouseOutEvent.fire(B,this);};YAHOO.widget.AutoComplete.prototype._onItemMouseclick=function(A,B){B._toggleHighlight(this,"to");B._selectItem(this);};YAHOO.widget.AutoComplete.prototype._onContainerMouseover=function(A,B){B._bOverContainer=true;};YAHOO.widget.AutoComplete.prototype._onContainerMouseout=function(A,B){B._bOverContainer=false;if(B._oCurItem){B._toggleHighlight(B._oCurItem,"to");}};YAHOO.widget.AutoComplete.prototype._onContainerScroll=function(A,B){B._elTextbox.focus();};YAHOO.widget.AutoComplete.prototype._onContainerResize=function(A,B){B._toggleContainerHelpers(B._bContainerOpen);};YAHOO.widget.AutoComplete.prototype._onTextboxKeyDown=function(A,B){var C=A.keyCode;switch(C){case 9:if((navigator.userAgent.toLowerCase().indexOf("mac")==-1)){if(B._oCurItem){if(B.delimChar&&(B._nKeyCode!=C)){if(B._bContainerOpen){YAHOO.util.Event.stopEvent(A);}}B._selectItem(B._oCurItem);}else{B._toggleContainer(false);}}break;case 13:if((navigator.userAgent.toLowerCase().indexOf("mac")==-1)){if(B._oCurItem){if(B._nKeyCode!=C){if(B._bContainerOpen){YAHOO.util.Event.stopEvent(A);}}B._selectItem(B._oCurItem);}else{B._toggleContainer(false);}}break;case 27:B._toggleContainer(false);return ;case 39:B._jumpSelection();break;case 38:YAHOO.util.Event.stopEvent(A);B._moveSelection(C);break;case 40:YAHOO.util.Event.stopEvent(A);B._moveSelection(C);break;default:break;}};YAHOO.widget.AutoComplete.prototype._onTextboxKeyPress=function(A,B){var C=A.keyCode;if((navigator.userAgent.toLowerCase().indexOf("mac")!=-1)){switch(C){case 9:if(B._oCurItem){if(B.delimChar&&(B._nKeyCode!=C)){if(B._bContainerOpen){YAHOO.util.Event.stopEvent(A);}}B._selectItem(B._oCurItem);}else{B._toggleContainer(false);}break;case 13:if(B._oCurItem){if(B._nKeyCode!=C){if(B._bContainerOpen){YAHOO.util.Event.stopEvent(A);}}B._selectItem(B._oCurItem);}else{B._toggleContainer(false);}break;default:break;}}else{if(C==229){B._queryInterval=setInterval(function(){B._onIMEDetected(B);},500);}}};YAHOO.widget.AutoComplete.prototype._onTextboxKeyUp=function(B,D){D._initProps();var E=B.keyCode;D._nKeyCode=E;var C=this.value;if(D._isIgnoreKey(E)||(C.toLowerCase()==D._sCurQuery)){return ;}else{D._bItemSelected=false;YAHOO.util.Dom.removeClass(D._oCurItem,D.highlightClassName);D._oCurItem=null;D.textboxKeyEvent.fire(D,E);}if(D.queryDelay>0){var A=setTimeout(function(){D._sendQuery(C);},(D.queryDelay*1000));if(D._nDelayID!=-1){clearTimeout(D._nDelayID);}D._nDelayID=A;}else{D._sendQuery(C);}};YAHOO.widget.AutoComplete.prototype._onTextboxFocus=function(A,B){B._elTextbox.setAttribute("autocomplete","off");B._bFocused=true;if(!B._bItemSelected){B.textboxFocusEvent.fire(B);}};YAHOO.widget.AutoComplete.prototype._onTextboxBlur=function(A,B){if(!B._bOverContainer||(B._nKeyCode==9)){if(!B._bItemSelected){var C=B._textMatchesOption();if(!B._bContainerOpen||(B._bContainerOpen&&(C===null))){if(B.forceSelection){B._clearSelection();}else{B.unmatchedItemSelectEvent.fire(B);}}else{if(B.forceSelection){B._selectItem(C);}}}if(B._bContainerOpen){B._toggleContainer(false);}B._cancelIntervalDetection(B);B._bFocused=false;B.textboxBlurEvent.fire(B);}};YAHOO.widget.AutoComplete.prototype._onWindowUnload=function(A,B){if(B&&B._elTextbox&&B.allowBrowserAutocomplete){B._elTextbox.setAttribute("autocomplete","on");}};YAHOO.widget.DataSource=function(){};YAHOO.widget.DataSource.ERROR_DATANULL="Response data was null";YAHOO.widget.DataSource.ERROR_DATAPARSE="Response data could not be parsed";YAHOO.widget.DataSource.prototype.maxCacheEntries=15;YAHOO.widget.DataSource.prototype.queryMatchContains=false;YAHOO.widget.DataSource.prototype.queryMatchSubset=false;YAHOO.widget.DataSource.prototype.queryMatchCase=false;YAHOO.widget.DataSource.prototype.toString=function(){return"DataSource "+this._sName;};YAHOO.widget.DataSource.prototype.getResults=function(A,D,B){var C=this._doQueryCache(A,D,B);if(C.length===0){this.queryEvent.fire(this,B,D);this.doQuery(A,D,B);}};YAHOO.widget.DataSource.prototype.doQuery=function(A,C,B){};YAHOO.widget.DataSource.prototype.flushCache=function(){if(this._aCache){this._aCache=[];}if(this._aCacheHelper){this._aCacheHelper=[]; |
5181 | 5181 | }this.cacheFlushEvent.fire(this);};YAHOO.widget.DataSource.prototype.queryEvent=null;YAHOO.widget.DataSource.prototype.cacheQueryEvent=null;YAHOO.widget.DataSource.prototype.getResultsEvent=null;YAHOO.widget.DataSource.prototype.getCachedResultsEvent=null;YAHOO.widget.DataSource.prototype.dataErrorEvent=null;YAHOO.widget.DataSource.prototype.cacheFlushEvent=null;YAHOO.widget.DataSource._nIndex=0;YAHOO.widget.DataSource.prototype._sName=null;YAHOO.widget.DataSource.prototype._aCache=null;YAHOO.widget.DataSource.prototype._init=function(){var A=this.maxCacheEntries;if(!YAHOO.lang.isNumber(A)||(A<0)){A=0;}if(A>0&&!this._aCache){this._aCache=[];}this._sName="instance"+YAHOO.widget.DataSource._nIndex;YAHOO.widget.DataSource._nIndex++;this.queryEvent=new YAHOO.util.CustomEvent("query",this);this.cacheQueryEvent=new YAHOO.util.CustomEvent("cacheQuery",this);this.getResultsEvent=new YAHOO.util.CustomEvent("getResults",this);this.getCachedResultsEvent=new YAHOO.util.CustomEvent("getCachedResults",this);this.dataErrorEvent=new YAHOO.util.CustomEvent("dataError",this);this.cacheFlushEvent=new YAHOO.util.CustomEvent("cacheFlush",this);};YAHOO.widget.DataSource.prototype._addCacheElem=function(B){var A=this._aCache;if(!A||!B||!B.query||!B.results){return ;}if(A.length>=this.maxCacheEntries){A.shift();}A.push(B);};YAHOO.widget.DataSource.prototype._doQueryCache=function(A,I,N){var H=[];var G=false;var J=this._aCache;var F=(J)?J.length:0;var K=this.queryMatchContains;var D;if((this.maxCacheEntries>0)&&J&&(F>0)){this.cacheQueryEvent.fire(this,N,I);if(!this.queryMatchCase){D=I;I=I.toLowerCase();}for(var P=F-1;P>=0;P--){var E=J[P];var B=E.results;var C=(!this.queryMatchCase)?encodeURIComponent(E.query).toLowerCase():encodeURIComponent(E.query);if(C==I){G=true;H=B;if(P!=F-1){J.splice(P,1);this._addCacheElem(E);}break;}else{if(this.queryMatchSubset){for(var O=I.length-1;O>=0;O--){var R=I.substr(0,O);if(C==R){G=true;for(var M=B.length-1;M>=0;M--){var Q=B[M];var L=(this.queryMatchCase)?encodeURIComponent(Q[0]).indexOf(I):encodeURIComponent(Q[0]).toLowerCase().indexOf(I);if((!K&&(L===0))||(K&&(L>-1))){H.unshift(Q);}}E={};E.query=I;E.results=H;this._addCacheElem(E);break;}}if(G){break;}}}}if(G){this.getCachedResultsEvent.fire(this,N,D,H);A(D,H,N);}}return H;};YAHOO.widget.DS_XHR=function(C,A,D){if(D&&(D.constructor==Object)){for(var B in D){this[B]=D[B];}}if(!YAHOO.lang.isArray(A)||!YAHOO.lang.isString(C)){return ;}this.schema=A;this.scriptURI=C;this._init();};YAHOO.widget.DS_XHR.prototype=new YAHOO.widget.DataSource();YAHOO.widget.DS_XHR.TYPE_JSON=0;YAHOO.widget.DS_XHR.TYPE_XML=1;YAHOO.widget.DS_XHR.TYPE_FLAT=2;YAHOO.widget.DS_XHR.ERROR_DATAXHR="XHR response failed";YAHOO.widget.DS_XHR.prototype.connMgr=YAHOO.util.Connect;YAHOO.widget.DS_XHR.prototype.connTimeout=0;YAHOO.widget.DS_XHR.prototype.scriptURI=null;YAHOO.widget.DS_XHR.prototype.scriptQueryParam="query";YAHOO.widget.DS_XHR.prototype.scriptQueryAppend="";YAHOO.widget.DS_XHR.prototype.responseType=YAHOO.widget.DS_XHR.TYPE_JSON;YAHOO.widget.DS_XHR.prototype.responseStripAfter="\n<!-";YAHOO.widget.DS_XHR.prototype.doQuery=function(E,G,B){var J=(this.responseType==YAHOO.widget.DS_XHR.TYPE_XML);var D=this.scriptURI+"?"+this.scriptQueryParam+"="+G;if(this.scriptQueryAppend.length>0){D+="&"+this.scriptQueryAppend;}var C=null;var F=this;var I=function(K){if(!F._oConn||(K.tId!=F._oConn.tId)){F.dataErrorEvent.fire(F,B,G,YAHOO.widget.DataSource.ERROR_DATANULL);return ;}for(var N in K){}if(!J){K=K.responseText;}else{K=K.responseXML;}if(K===null){F.dataErrorEvent.fire(F,B,G,YAHOO.widget.DataSource.ERROR_DATANULL);return ;}var M=F.parseResponse(G,K,B);var L={};L.query=decodeURIComponent(G);L.results=M;if(M===null){F.dataErrorEvent.fire(F,B,G,YAHOO.widget.DataSource.ERROR_DATAPARSE);M=[];}else{F.getResultsEvent.fire(F,B,G,M);F._addCacheElem(L);}E(G,M,B);};var A=function(K){F.dataErrorEvent.fire(F,B,G,YAHOO.widget.DS_XHR.ERROR_DATAXHR);return ;};var H={success:I,failure:A};if(YAHOO.lang.isNumber(this.connTimeout)&&(this.connTimeout>0)){H.timeout=this.connTimeout;}if(this._oConn){this.connMgr.abort(this._oConn);}F._oConn=this.connMgr.asyncRequest("GET",D,H,null);};YAHOO.widget.DS_XHR.prototype.parseResponse=function(sQuery,oResponse,oParent){var aSchema=this.schema;var aResults=[];var bError=false;var nEnd=((this.responseStripAfter!=="")&&(oResponse.indexOf))?oResponse.indexOf(this.responseStripAfter):-1;if(nEnd!=-1){oResponse=oResponse.substring(0,nEnd);}switch(this.responseType){case YAHOO.widget.DS_XHR.TYPE_JSON:var jsonList,jsonObjParsed;if(YAHOO.lang.JSON){jsonObjParsed=YAHOO.lang.JSON.parse(oResponse);if(!jsonObjParsed){bError=true;break;}else{try{jsonList=eval("jsonObjParsed."+aSchema[0]);}catch(e){bError=true;break;}}}else{if(oResponse.parseJSON){jsonObjParsed=oResponse.parseJSON();if(!jsonObjParsed){bError=true;}else{try{jsonList=eval("jsonObjParsed."+aSchema[0]);}catch(e){bError=true;break;}}}else{if(window.JSON){jsonObjParsed=JSON.parse(oResponse);if(!jsonObjParsed){bError=true;break;}else{try{jsonList=eval("jsonObjParsed."+aSchema[0]);}catch(e){bError=true;break;}}}else{try{while(oResponse.substring(0,1)==" "){oResponse=oResponse.substring(1,oResponse.length);}if(oResponse.indexOf("{")<0){bError=true;break;}if(oResponse.indexOf("{}")===0){break;}var jsonObjRaw=eval("("+oResponse+")");if(!jsonObjRaw){bError=true;break;}jsonList=eval("(jsonObjRaw."+aSchema[0]+")");}catch(e){bError=true;break;}}}}if(!jsonList){bError=true;break;}if(!YAHOO.lang.isArray(jsonList)){jsonList=[jsonList];}for(var i=jsonList.length-1;i>=0;i--){var aResultItem=[];var jsonResult=jsonList[i];for(var j=aSchema.length-1;j>=1;j--){var dataFieldValue=jsonResult[aSchema[j]];if(!dataFieldValue){dataFieldValue="";}aResultItem.unshift(dataFieldValue);}if(aResultItem.length==1){aResultItem.push(jsonResult);}aResults.unshift(aResultItem);}break;case YAHOO.widget.DS_XHR.TYPE_XML:var xmlList=oResponse.getElementsByTagName(aSchema[0]);if(!xmlList){bError=true;break;}for(var k=xmlList.length-1;k>=0;k--){var result=xmlList.item(k); |
5182 | 5182 | var aFieldSet=[];for(var m=aSchema.length-1;m>=1;m--){var sValue=null;var xmlAttr=result.attributes.getNamedItem(aSchema[m]);if(xmlAttr){sValue=xmlAttr.value;}else{var xmlNode=result.getElementsByTagName(aSchema[m]);if(xmlNode&&xmlNode.item(0)&&xmlNode.item(0).firstChild){sValue=xmlNode.item(0).firstChild.nodeValue;}else{sValue="";}}aFieldSet.unshift(sValue);}aResults.unshift(aFieldSet);}break;case YAHOO.widget.DS_XHR.TYPE_FLAT:if(oResponse.length>0){var newLength=oResponse.length-aSchema[0].length;if(oResponse.substr(newLength)==aSchema[0]){oResponse=oResponse.substr(0,newLength);}if(oResponse.length>0){var aRecords=oResponse.split(aSchema[0]);for(var n=aRecords.length-1;n>=0;n--){if(aRecords[n].length>0){aResults[n]=aRecords[n].split(aSchema[1]);}}}}break;default:break;}sQuery=null;oResponse=null;oParent=null;if(bError){return null;}else{return aResults;}};YAHOO.widget.DS_XHR.prototype._oConn=null;YAHOO.widget.DS_ScriptNode=function(D,A,C){if(C&&(C.constructor==Object)){for(var B in C){this[B]=C[B];}}if(!YAHOO.lang.isArray(A)||!YAHOO.lang.isString(D)){return ;}this.schema=A;this.scriptURI=D;this._init();};YAHOO.widget.DS_ScriptNode.prototype=new YAHOO.widget.DataSource();YAHOO.widget.DS_ScriptNode.prototype.getUtility=YAHOO.util.Get;YAHOO.widget.DS_ScriptNode.prototype.scriptURI=null;YAHOO.widget.DS_ScriptNode.prototype.scriptQueryParam="query";YAHOO.widget.DS_ScriptNode.prototype.asyncMode="allowAll";YAHOO.widget.DS_ScriptNode.prototype.scriptCallbackParam="callback";YAHOO.widget.DS_ScriptNode.callbacks=[];YAHOO.widget.DS_ScriptNode._nId=0;YAHOO.widget.DS_ScriptNode._nPending=0;YAHOO.widget.DS_ScriptNode.prototype.doQuery=function(A,F,C){var B=this;if(YAHOO.widget.DS_ScriptNode._nPending===0){YAHOO.widget.DS_ScriptNode.callbacks=[];YAHOO.widget.DS_ScriptNode._nId=0;}var E=YAHOO.widget.DS_ScriptNode._nId;YAHOO.widget.DS_ScriptNode._nId++;YAHOO.widget.DS_ScriptNode.callbacks[E]=function(G){if((B.asyncMode!=="ignoreStaleResponses")||(E===YAHOO.widget.DS_ScriptNode.callbacks.length-1)){B.handleResponse(G,A,F,C);}else{}delete YAHOO.widget.DS_ScriptNode.callbacks[E];};YAHOO.widget.DS_ScriptNode._nPending++;var D=this.scriptURI+"&"+this.scriptQueryParam+"="+F+"&"+this.scriptCallbackParam+"=YAHOO.widget.DS_ScriptNode.callbacks["+E+"]";this.getUtility.script(D,{autopurge:true,onsuccess:YAHOO.widget.DS_ScriptNode._bumpPendingDown,onfail:YAHOO.widget.DS_ScriptNode._bumpPendingDown});};YAHOO.widget.DS_ScriptNode.prototype.handleResponse=function(oResponse,oCallbackFn,sQuery,oParent){var aSchema=this.schema;var aResults=[];var bError=false;var jsonList,jsonObjParsed;try{jsonList=eval("(oResponse."+aSchema[0]+")");}catch(e){bError=true;}if(!jsonList){bError=true;jsonList=[];}else{if(!YAHOO.lang.isArray(jsonList)){jsonList=[jsonList];}}for(var i=jsonList.length-1;i>=0;i--){var aResultItem=[];var jsonResult=jsonList[i];for(var j=aSchema.length-1;j>=1;j--){var dataFieldValue=jsonResult[aSchema[j]];if(!dataFieldValue){dataFieldValue="";}aResultItem.unshift(dataFieldValue);}if(aResultItem.length==1){aResultItem.push(jsonResult);}aResults.unshift(aResultItem);}if(bError){aResults=null;}if(aResults===null){this.dataErrorEvent.fire(this,oParent,sQuery,YAHOO.widget.DataSource.ERROR_DATAPARSE);aResults=[];}else{var resultObj={};resultObj.query=decodeURIComponent(sQuery);resultObj.results=aResults;this._addCacheElem(resultObj);this.getResultsEvent.fire(this,oParent,sQuery,aResults);}oCallbackFn(sQuery,aResults,oParent);};YAHOO.widget.DS_ScriptNode._bumpPendingDown=function(){YAHOO.widget.DS_ScriptNode._nPending--;};YAHOO.widget.DS_JSFunction=function(A,C){if(C&&(C.constructor==Object)){for(var B in C){this[B]=C[B];}}if(!YAHOO.lang.isFunction(A)){return ;}else{this.dataFunction=A;this._init();}};YAHOO.widget.DS_JSFunction.prototype=new YAHOO.widget.DataSource();YAHOO.widget.DS_JSFunction.prototype.dataFunction=null;YAHOO.widget.DS_JSFunction.prototype.doQuery=function(C,F,D){var B=this.dataFunction;var E=[];E=B(F);if(E===null){this.dataErrorEvent.fire(this,D,F,YAHOO.widget.DataSource.ERROR_DATANULL);return ;}var A={};A.query=decodeURIComponent(F);A.results=E;this._addCacheElem(A);this.getResultsEvent.fire(this,D,F,E);C(F,E,D);return ;};YAHOO.widget.DS_JSArray=function(A,C){if(C&&(C.constructor==Object)){for(var B in C){this[B]=C[B];}}if(!YAHOO.lang.isArray(A)){return ;}else{this.data=A;this._init();}};YAHOO.widget.DS_JSArray.prototype=new YAHOO.widget.DataSource();YAHOO.widget.DS_JSArray.prototype.data=null;YAHOO.widget.DS_JSArray.prototype.doQuery=function(E,I,A){var F;var C=this.data;var J=[];var D=false;var B=this.queryMatchContains;if(I){if(!this.queryMatchCase){I=I.toLowerCase();}for(F=C.length-1;F>=0;F--){var H=[];if(YAHOO.lang.isString(C[F])){H[0]=C[F];}else{if(YAHOO.lang.isArray(C[F])){H=C[F];}}if(YAHOO.lang.isString(H[0])){var G=(this.queryMatchCase)?encodeURIComponent(H[0]).indexOf(I):encodeURIComponent(H[0]).toLowerCase().indexOf(I);if((!B&&(G===0))||(B&&(G>-1))){J.unshift(H);}}}}else{for(F=C.length-1;F>=0;F--){if(YAHOO.lang.isString(C[F])){J.unshift([C[F]]);}else{if(YAHOO.lang.isArray(C[F])){J.unshift(C[F]);}}}}this.getResultsEvent.fire(this,A,I,J);E(I,J,A);};YAHOO.register("autocomplete",YAHOO.widget.AutoComplete,{version:"2.5.2",build:"1076"}); |
5183 | -function cpaint(){this.version='2.0.3';var config=new Array();config['debugging']=-1;config['proxy_url']='';config['transfer_mode']='GET';config['async']=true;config['response_type']='OBJECT';config['persistent_connection']=false;config['use_cpaint_api']=true;var stack_count=0;this.capable=test_ajax_capability();this.set_debug=function(){if(typeof arguments[0]=='boolean'){if(arguments[0]===true){config['debugging']=1;}else{config['debugging']=0;}}else if(typeof arguments[0]=='number'){config['debugging']=Math.round(arguments[0]);}} | |
5184 | -this.set_proxy_url=function(){if(typeof arguments[0]=='string'){config['proxy_url']=arguments[0];}} | |
5185 | -this.set_transfer_mode=function(){if(arguments[0].toUpperCase()=='GET'||arguments[0].toUpperCase()=='POST'){config['transfer_mode']=arguments[0].toUpperCase();}} | |
5186 | -this.set_async=function(){if(typeof arguments[0]=='boolean'){config['async']=arguments[0];}} | |
5187 | -this.set_response_type=function(){if(arguments[0].toUpperCase()=='TEXT'||arguments[0].toUpperCase()=='XML'||arguments[0].toUpperCase()=='OBJECT'||arguments[0].toUpperCase()=='E4X'||arguments[0].toUpperCase()=='JSON'){config['response_type']=arguments[0].toUpperCase();}} | |
5188 | -this.set_persistent_connection=function(){if(typeof arguments[0]=='boolean'){config['persistent_connection']=arguments[0];}} | |
5189 | -this.set_use_cpaint_api=function(){if(typeof arguments[0]=='boolean'){config['use_cpaint_api']=arguments[0];}} | |
5190 | -function test_ajax_capability(){var cpc=new cpaint_call(0,config,this.version);return cpc.test_ajax_capability();} | |
5191 | -this.call=function(){var use_stack=-1;if(config['persistent_connection']==true&&__cpaint_stack[0]!=null){switch(__cpaint_stack[0].get_http_state()){case-1:use_stack=0;debug('no XMLHttpObject object to re-use for persistence, creating new one later',2);break;case 4:use_stack=0 | |
5192 | -debug('re-using the persistent connection',2);break;default:debug('the persistent connection is in use - skipping this request',2);}}else if(config['persistent_connection']==true){use_stack=0;__cpaint_stack[use_stack]=new cpaint_call(use_stack,config,this.version);debug('no cpaint_call object available for re-use, created new one',2);}else{use_stack=stack_count;__cpaint_stack[use_stack]=new cpaint_call(use_stack,config,this.version);debug('no cpaint_call object created new one',2);} | |
5193 | -if(use_stack!=-1){__cpaint_stack[use_stack].set_client_callback(arguments[2]);if(config['proxy_url']!=''){__cpaint_stack[use_stack].call_proxy(arguments);}else{__cpaint_stack[use_stack].call_direct(arguments);} | |
5194 | -stack_count++;debug('stack size: '+__cpaint_stack.length,2);}} | |
5195 | -var debug=function(message,debug_level){var prefix='[CPAINT Debug] ';if(debug_level<1){prefix='[CPAINT Error] ';} | |
5196 | -if(config['debugging']>=debug_level){alert(prefix+message);}if (message.search("error") > 1){client_callback("", message);}}} | |
5197 | -var __cpaint_stack=new Array();var __cpaint_transformer=new cpaint_transformer();function cpaint_call(){var version=arguments[2];var config=new Array();config['debugging']=arguments[1]['debugging'];config['proxy_url']=arguments[1]['proxy_url'];config['transfer_mode']=arguments[1]['transfer_mode'];config['async']=arguments[1]['async'];config['response_type']=arguments[1]['response_type'];config['persistent_connection']=arguments[1]['persistent_connection'];config['use_cpaint_api']=arguments[1]['use_cpaint_api'];var httpobj=false;var client_callback;var stack_id=arguments[0];this.set_client_callback=function(){if(typeof arguments[0]=='function'){client_callback=arguments[0];}} | |
5198 | -this.get_http_state=function(){var return_value=-1;if(typeof httpobj=='object'){return_value=httpobj.readyState;} | |
5199 | -return return_value;} | |
5200 | -this.call_direct=function(call_arguments){var url=call_arguments[0];var remote_method=call_arguments[1];var querystring='';var i=0;if(url=='SELF'){url=document.location.href;} | |
5201 | -if(config['use_cpaint_api']==true){for(i=3;i<call_arguments.length;i++){if((typeof call_arguments[i]=='string'&&call_arguments[i]!=''&&call_arguments[i].search(/^\s+$/g)==-1)&&!isNaN(call_arguments[i])&&isFinite(call_arguments[i])){querystring+='&cpaint_argument[]='+encodeURIComponent(JSON.stringify(Number(call_arguments[i])));}else{querystring+='&cpaint_argument[]='+encodeURIComponent(JSON.stringify(call_arguments[i]));}} | |
5202 | -querystring+='&cpaint_response_type='+config['response_type'];if(config['transfer_mode']=='GET'){if(url.indexOf('?')!=-1){url=url+'&cpaint_function='+remote_method+querystring;}else{url=url+'?cpaint_function='+remote_method+querystring;}}else{querystring='cpaint_function='+remote_method+querystring;}}else{for(i=3;i<call_arguments.length;i++){if(i==3){querystring+=encodeURIComponent(call_arguments[i]);}else{querystring+='&'+encodeURIComponent(call_arguments[i]);}} | |
5203 | -if(config['transfer_mode']=='GET'){url=url+querystring;}} | |
5204 | -get_connection_object();debug('opening connection to "'+url+'"',1);httpobj.open(config['transfer_mode'],url,config['async']);if(config['transfer_mode']=='POST'){try{httpobj.setRequestHeader('Content-Type','application/x-www-form-urlencoded');}catch(cp_err){debug('POST cannot be completed due to incompatible browser. Use GET as your request method.',0);}} | |
5205 | -httpobj.setRequestHeader('X-Powered-By','CPAINT v'+version+' :: http://sf.net/projects/cpaint');httpobj.onreadystatechange=callback;if(config['transfer_mode']=='GET'){httpobj.send(null);}else{debug('sending query: '+querystring,1);httpobj.send(querystring);} | |
5206 | -if(config['async']==true){callback();}} | |
5207 | -this.call_proxy=function(call_arguments){var proxyscript=config['proxy_url'];var url=call_arguments[0];var remote_method=call_arguments[1];var querystring='';var i=0;var querystring_argument_prefix='cpaint_argument[]=';if(config['use_cpaint_api']==false){querystring_argument_prefix='';} | |
5208 | -for(i=3;i<call_arguments.length;i++){if(config['use_cpaint_api']==true){if((typeof call_arguments[i]=='string'&&call_arguments[i]!=''&&call_arguments[i].search(/^\s+$/g)==-1)&&!isNaN(call_arguments[i])&&isFinite(call_arguments[i])){querystring+=encodeURIComponent(querystring_argument_prefix+JSON.stringify(Number(call_arguments[i]))+'&');}else{querystring+=encodeURIComponent(querystring_argument_prefix+JSON.stringify(call_arguments[i])+'&');}}else{querystring+=encodeURIComponent(querystring_argument_prefix+call_arguments[i]+'&');}} | |
5209 | -if(config['use_cpaint_api']==true){querystring+=encodeURIComponent('&cpaint_function='+remote_method);querystring+=encodeURIComponent('&cpaint_responsetype='+config['response_type']);} | |
5210 | -if(config['transfer_mode']=='GET'){proxyscript+='?cpaint_remote_url='+encodeURIComponent(url) | |
5211 | -+'&cpaint_remote_query='+querystring | |
5212 | -+'&cpaint_remote_method='+config['transfer_mode'] | |
5213 | -+'&cpaint_response_type='+config['response_type'];}else{querystring='cpaint_remote_url='+encodeURIComponent(url) | |
5214 | -+'&cpaint_remote_query='+querystring | |
5215 | -+'&cpaint_remote_method='+config['transfer_mode'] | |
5216 | -+'&cpaint_response_type='+config['response_type'];} | |
5217 | -get_connection_object();debug('opening connection to proxy "'+proxyscript+'"',1);httpobj.open(config['transfer_mode'],proxyscript,config['async']);if(config['transfer_mode']=='POST'){try{httpobj.setRequestHeader('Content-Type','application/x-www-form-urlencoded');}catch(cp_err){debug('POST cannot be completed due to incompatible browser. Use GET as your request method.',0);}} | |
5218 | -httpobj.setRequestHeader('X-Powered-By','CPAINT v'+version);httpobj.onreadystatechange=callback;if(config['transfer_mode']=='GET'){httpobj.send(null);}else{debug('sending query: '+querystring,1);httpobj.send(querystring);} | |
5219 | -if(config['async']==false){callback();}} | |
5220 | -this.test_ajax_capability=function(){return get_connection_object();} | |
5221 | -var get_connection_object=function(){var return_value=false;var new_connection=false;if(config['persistent_connection']==false){debug('Using new connection object',1);new_connection=true;}else{debug('Using shared connection object.',1);if(typeof httpobj!='object'){debug('Getting new persistent connection object.',1);new_connection=true;}} | |
5222 | -if(new_connection==true){try{httpobj=new XMLHttpRequest();}catch(e1){try{httpobj=new ActiveXObject('Msxml2.XMLHTTP');}catch(e){try{httpobj=new ActiveXObject('Microsoft.XMLHTTP');}catch(oc){httpobj=null;}}} | |
5223 | -if(!httpobj){debug('Could not create connection object',0);}else{return_value=true;}} | |
5224 | -if(httpobj.readyState!=4){httpobj.abort();} | |
5225 | -return return_value;} | |
5226 | -var callback=function(){var response=null;if(httpobj.readyState==4&&httpobj.status==200){debug(httpobj.responseText,1);debug('using response type '+config['response_type'],2);switch(config['response_type']){case'XML':debug(httpobj.responseXML,2);response=__cpaint_transformer.xml_conversion(httpobj.responseXML);break;case'OBJECT':response=__cpaint_transformer.object_conversion(httpobj.responseXML);break;case'TEXT':response=__cpaint_transformer.text_conversion(httpobj.responseText);break;case'E4X':response=__cpaint_transformer.e4x_conversion(httpobj.responseText);break;case'JSON':response=__cpaint_transformer.json_conversion(httpobj.responseText);break;default:debug('invalid response type \''+response_type+'\'',0);} | |
5227 | -if(response!=null&&typeof client_callback=='function'){client_callback(response,httpobj.responseText);} | |
5228 | -remove_from_stack();}else if(httpobj.readyState==4&&httpobj.status!=200){debug('invalid HTTP response code \''+Number(httpobj.status)+'\'',0);client_callback("", "erro");}} | |
5229 | -var remove_from_stack=function(){if(typeof stack_id=='number'&&__cpaint_stack[stack_id]&&config['persistent_connection']==false){__cpaint_stack[stack_id]=null;}} | |
5230 | -var debug=function(message,debug_level){var prefix='[CPAINT Debug] ';if(config['debugging']<1){prefix='[CPAINT Error] ';if (message.search(" error") > 1){client_callback("", message);}} | |
5231 | -if(config['debugging']>=debug_level){alert(prefix+message);}}} | |
5232 | -function cpaint_transformer(){this.object_conversion=function(xml_document){var return_value=new cpaint_result_object();var i=0;var firstNodeName='';if(typeof xml_document=='object'&&xml_document!=null){for(i=0;i<xml_document.childNodes.length;i++){if(xml_document.childNodes[i].nodeType==1){firstNodeName=xml_document.childNodes[i].nodeName;break;}} | |
5233 | -var ajax_response=xml_document.getElementsByTagName(firstNodeName);return_value[firstNodeName]=new Array();for(i=0;i<ajax_response.length;i++){var tmp_node=create_object_structure(ajax_response[i]);tmp_node.id=ajax_response[i].getAttribute('id') | |
5234 | -return_value[firstNodeName].push(tmp_node);}}else{debug('received invalid XML response',0);} | |
5235 | -return return_value;} | |
5236 | -this.xml_conversion=function(xml_document){return xml_document;} | |
5237 | -this.text_conversion=function(text){return decode(text);} | |
5238 | -this.e4x_conversion=function(text){text=text.replace(/^\<\?xml[^>]+\>/,'');return new XML(text);} | |
5239 | -this.json_conversion=function(text){return JSON.parse(text);} | |
5240 | -var create_object_structure=function(stream){var return_value=new cpaint_result_object();var node_name='';var i=0;var attrib=0;if(stream.hasChildNodes()==true){for(i=0;i<stream.childNodes.length;i++){node_name=stream.childNodes[i].nodeName;node_name=node_name.replace(/[^a-zA-Z0-9_]*/g,'');if(typeof return_value[node_name]!='object'){return_value[node_name]=new Array();} | |
5241 | -if(stream.childNodes[i].nodeType==1){var tmp_node=create_object_structure(stream.childNodes[i]);for(attrib=0;attrib<stream.childNodes[i].attributes.length;attrib++){tmp_node.set_attribute(stream.childNodes[i].attributes[attrib].nodeName,stream.childNodes[i].attributes[attrib].nodeValue);} | |
5242 | -return_value[node_name].push(tmp_node);}else if(stream.childNodes[i].nodeType==3){return_value.data=decode(String(stream.firstChild.data));}}} | |
5243 | -return return_value;} | |
5244 | -var decode=function(rawtext){var plaintext='';var i=0;var c1=0;var c2=0;var c3=0;var u=0;var t=0;while(i<rawtext.length){if(rawtext.charAt(i)=='\\'&&rawtext.charAt(i+1)=='u'){u=0;for(j=2;j<6;j+=1){t=parseInt(rawtext.charAt(i+j),16);if(!isFinite(t)){break;} | |
5245 | -u=u*16+t;} | |
5246 | -plaintext+=String.fromCharCode(u);i+=6;}else{plaintext+=rawtext.charAt(i);i++;}} | |
5247 | -if(plaintext!=''&&plaintext.search(/^\s+$/g)==-1&&!isNaN(plaintext)&&isFinite(plaintext)){plaintext=Number(plaintext);} | |
5248 | -return plaintext;}} | |
5249 | -function cpaint_result_object(){this.id=0;this.data='';var __attributes=new Array();this.find_item_by_id=function(){var return_value=null;var type=arguments[0];var id=arguments[1];var i=0;if(this[type]){for(i=0;i<this[type].length;i++){if(this[type][i].get_attribute('id')==id){return_value=this[type][i];break;}}} | |
5250 | -return return_value;} | |
5251 | -this.get_attribute=function(){var return_value=null;var id=arguments[0];if(typeof __attributes[id]!='undefined'){return_value=__attributes[id];} | |
5252 | -return return_value;} | |
5253 | -this.set_attribute=function(){__attributes[arguments[0]]=arguments[1];}} | |
5254 | -Array.prototype.______array='______array';var JSON={org:'http://www.JSON.org',copyright:'(c)2005 JSON.org',license:'http://www.crockford.com/JSON/license.html',stringify:function(arg){var c,i,l,s='',v;var numeric=true;switch(typeof arg){case'object':if(arg){if(arg.______array=='______array'){for(i in arg){if(i!='______array'&&(isNaN(i)||!isFinite(i))){numeric=false;break;}} | |
5255 | -if(numeric==true){for(i=0;i<arg.length;++i){if(typeof arg[i]!='undefined'){v=this.stringify(arg[i]);if(s){s+=',';} | |
5256 | -s+=v;}else{s+=',null';}} | |
5257 | -return'['+s+']';}else{for(i in arg){if(i!='______array'){v=arg[i];if(typeof v!='undefined'&&typeof v!='function'){v=this.stringify(v);if(s){s+=',';} | |
5258 | -s+=this.stringify(i)+':'+v;}}} | |
5259 | -return'{'+s+'}';}}else if(typeof arg.toString!='undefined'){for(i in arg){v=arg[i];if(typeof v!='undefined'&&typeof v!='function'){v=this.stringify(v);if(s){s+=',';} | |
5260 | -s+=this.stringify(i)+':'+v;}} | |
5261 | -return'{'+s+'}';}} | |
5262 | -return'null';case'number':return isFinite(arg)?String(arg):'null';case'string':l=arg.length;s='"';for(i=0;i<l;i+=1){c=arg.charAt(i);if(c>=' '){if(c=='\\'||c=='"'){s+='\\';} | |
5263 | -s+=c;}else{switch(c){case'\b':s+='\\b';break;case'\f':s+='\\f';break;case'\n':s+='\\n';break;case'\r':s+='\\r';break;case'\t':s+='\\t';break;default:c=c.charCodeAt();s+='\\u00'+Math.floor(c/16).toString(16)+ | |
5264 | -(c%16).toString(16);}}} | |
5265 | -return s+'"';case'boolean':return String(arg);default:return'null';}},parse:function(text){var at=0;var ch=' ';function error(m){throw{name:'JSONError',message:m,at:at-1,text:text};} | |
5266 | -function next(){ch=text.charAt(at);at+=1;return ch;} | |
5267 | -function white(){while(ch!=''&&ch<=' '){next();}} | |
5268 | -function str(){var i,s='',t,u;if(ch=='"'){outer:while(next()){if(ch=='"'){next();return s;}else if(ch=='\\'){switch(next()){case'b':s+='\b';break;case'f':s+='\f';break;case'n':s+='\n';break;case'r':s+='\r';break;case't':s+='\t';break;case'u':u=0;for(i=0;i<4;i+=1){t=parseInt(next(),16);if(!isFinite(t)){break outer;} | |
5269 | -u=u*16+t;} | |
5270 | -s+=String.fromCharCode(u);break;default:s+=ch;}}else{s+=ch;}}} | |
5271 | -error("Bad string");} | |
5272 | -function arr(){var a=[];if(ch=='['){next();white();if(ch==']'){next();return a;} | |
5273 | -while(ch){a.push(val());white();if(ch==']'){next();return a;}else if(ch!=','){break;} | |
5274 | -next();white();}} | |
5275 | -error("Bad array");} | |
5276 | -function obj(){var k,o={};if(ch=='{'){next();white();if(ch=='}'){next();return o;} | |
5277 | -while(ch){k=str();white();if(ch!=':'){break;} | |
5278 | -next();o[k]=val();white();if(ch=='}'){next();return o;}else if(ch!=','){break;} | |
5279 | -next();white();}} | |
5280 | -error("Bad object");} | |
5281 | -function assoc(){var k,a=[];if(ch=='<'){next();white();if(ch=='>'){next();return a;} | |
5282 | -while(ch){k=str();white();if(ch!=':'){break;} | |
5283 | -next();a[k]=val();white();if(ch=='>'){next();return a;}else if(ch!=','){break;} | |
5284 | -next();white();}} | |
5285 | -error("Bad associative array");} | |
5286 | -function num(){var n='',v;if(ch=='-'){n='-';next();} | |
5287 | -while(ch>='0'&&ch<='9'){n+=ch;next();} | |
5288 | -if(ch=='.'){n+='.';while(next()&&ch>='0'&&ch<='9'){n+=ch;}} | |
5289 | -if(ch=='e'||ch=='E'){n+='e';next();if(ch=='-'||ch=='+'){n+=ch;next();} | |
5290 | -while(ch>='0'&&ch<='9'){n+=ch;next();}} | |
5291 | -v=+n;if(!isFinite(v)){error("Bad number");}else{return v;}} | |
5292 | -function word(){switch(ch){case't':if(next()=='r'&&next()=='u'&&next()=='e'){next();return true;} | |
5293 | -break;case'f':if(next()=='a'&&next()=='l'&&next()=='s'&&next()=='e'){next();return false;} | |
5294 | -break;case'n':if(next()=='u'&&next()=='l'&&next()=='l'){next();return null;} | |
5295 | -break;} | |
5296 | -error("Syntax error");} | |
5297 | -function val(){white();switch(ch){case'{':return obj();case'[':return arr();case'<':return assoc();case'"':return str();case'-':return num();default:return ch>='0'&&ch<='9'?num():word();}} | |
5298 | -return val();}}; | |
5183 | +/** | |
5184 | +* CPAINT - Cross-Platform Asynchronous INterface Toolkit | |
5185 | +* | |
5186 | +* http://sf.net/projects/cpaint | |
5187 | +* | |
5188 | +* released under the terms of the LGPL | |
5189 | +* see http://www.fsf.org/licensing/licenses/lgpl.txt for details | |
5190 | +* | |
5191 | +* @package CPAINT | |
5192 | +* @access public | |
5193 | +* @copyright Copyright (c) 2005-2006 Paul Sullivan, Dominique Stender - http://sf.net/projects/cpaint | |
5194 | +* @author Paul Sullivan <wiley14@gmail.com> | |
5195 | +* @author Dominique Stender <dstender@st-webdevelopment.de> | |
5196 | +* @author Stephan Tijink <stijink@googlemail.com> | |
5197 | +* @version 2.0.3 | |
5198 | +*/ | |
5199 | +function cpaint() { | |
5200 | + /** | |
5201 | + * CPAINT version | |
5202 | + * | |
5203 | + * @access protected | |
5204 | + * @var string version | |
5205 | + */ | |
5206 | + this.version = '2.0.3'; | |
5207 | + | |
5208 | + /** | |
5209 | + * configuration options both for this class but also for the cpaint_call() objects. | |
5210 | + * | |
5211 | + * @access protected | |
5212 | + * @var array config | |
5213 | + */ | |
5214 | + var config = new Array(); | |
5215 | + config['debugging'] = -1; | |
5216 | + config['proxy_url'] = ''; | |
5217 | + config['transfer_mode'] = 'GET'; | |
5218 | + config['async'] = true; | |
5219 | + config['response_type'] = 'OBJECT'; | |
5220 | + config['persistent_connection'] = false; | |
5221 | + config['use_cpaint_api'] = true; | |
5222 | + | |
5223 | + /** | |
5224 | + * maintains the next free index in the stack | |
5225 | + * | |
5226 | + * @access protected | |
5227 | + * @var integer stack_count | |
5228 | + */ | |
5229 | + var stack_count = 0; | |
5230 | + | |
5231 | + /** | |
5232 | + * property returns whether or not the browser is AJAX capable | |
5233 | + * | |
5234 | + * @access public | |
5235 | + * @return boolean | |
5236 | + */ | |
5237 | + this.capable = test_ajax_capability(); | |
5238 | + | |
5239 | + /** | |
5240 | + * switches debug mode on/off. | |
5241 | + * | |
5242 | + * @access public | |
5243 | + * @param boolean debug debug flag | |
5244 | + * @return void | |
5245 | + */ | |
5246 | + this.set_debug = function() { | |
5247 | + | |
5248 | + if (typeof arguments[0] == 'boolean') { | |
5249 | + if (arguments[0] === true) { | |
5250 | + config['debugging'] = 1; | |
5251 | + | |
5252 | + } else { | |
5253 | + config['debugging'] = 0; | |
5254 | + } | |
5255 | + | |
5256 | + } else if (typeof arguments[0] == 'number') { | |
5257 | + config['debugging'] = Math.round(arguments[0]); | |
5258 | + } | |
5259 | + } | |
5260 | + | |
5261 | + /** | |
5262 | + * defines the URL of the proxy script. | |
5263 | + * | |
5264 | + * @access public | |
5265 | + * @param string proxy_url URL of the proxyscript to connect | |
5266 | + * @return void | |
5267 | + */ | |
5268 | + this.set_proxy_url = function() { | |
5269 | + | |
5270 | + if (typeof arguments[0] == 'string') { | |
5271 | + | |
5272 | + config['proxy_url'] = arguments[0]; | |
5273 | + } | |
5274 | + } | |
5275 | + | |
5276 | + /** | |
5277 | + * sets the transfer_mode (GET|POST). | |
5278 | + * | |
5279 | + * @access public | |
5280 | + * @param string transfer_mode transfer_mode | |
5281 | + * @return void | |
5282 | + */ | |
5283 | + this.set_transfer_mode = function() { | |
5284 | + | |
5285 | + if (arguments[0].toUpperCase() == 'GET' | |
5286 | + || arguments[0].toUpperCase() == 'POST') { | |
5287 | + | |
5288 | + config['transfer_mode'] = arguments[0].toUpperCase(); | |
5289 | + } | |
5290 | + } | |
5291 | + | |
5292 | + /** | |
5293 | + * sets the flag whether or not to use asynchronous calls. | |
5294 | + * | |
5295 | + * @access public | |
5296 | + * @param boolean async syncronization flag | |
5297 | + * @return void | |
5298 | + */ | |
5299 | + this.set_async = function() { | |
5300 | + | |
5301 | + if (typeof arguments[0] == 'boolean') { | |
5302 | + config['async'] = arguments[0]; | |
5303 | + } | |
5304 | + } | |
5305 | + | |
5306 | + /** | |
5307 | + * defines the response type. | |
5308 | + * | |
5309 | + * allowed values are: | |
5310 | + * TEXT = raw text response | |
5311 | + * XML = raw XMLHttpObject | |
5312 | + * OBJECT = parsed JavaScript object structure from XMLHttpObject | |
5313 | + * | |
5314 | + * the default is OBJECT. | |
5315 | + * | |
5316 | + * @access public | |
5317 | + * @param string response_type response type | |
5318 | + * @return void | |
5319 | + */ | |
5320 | + this.set_response_type = function() { | |
5321 | + | |
5322 | + if (arguments[0].toUpperCase() == 'TEXT' | |
5323 | + || arguments[0].toUpperCase() == 'XML' | |
5324 | + || arguments[0].toUpperCase() == 'OBJECT' | |
5325 | + || arguments[0].toUpperCase() == 'E4X' | |
5326 | + || arguments[0].toUpperCase() == 'JSON') { | |
5327 | + | |
5328 | + config['response_type'] = arguments[0].toUpperCase(); | |
5329 | + } | |
5330 | + } | |
5331 | + | |
5332 | + /** | |
5333 | + * sets the flag whether or not to use a persistent connection. | |
5334 | + * | |
5335 | + * @access public | |
5336 | + * @param boolean persistent_connection persistance flag | |
5337 | + * @return void | |
5338 | + */ | |
5339 | + this.set_persistent_connection = function() { | |
5340 | + | |
5341 | + if (typeof arguments[0] == 'boolean') { | |
5342 | + config['persistent_connection'] = arguments[0]; | |
5343 | + } | |
5344 | + } | |
5345 | + | |
5346 | + | |
5347 | + /** | |
5348 | + * sets the flag whether or not to use the cpaint api on the backend. | |
5349 | + * | |
5350 | + * @access public | |
5351 | + * @param boolean cpaint_api api_flag | |
5352 | + * @return void | |
5353 | + */ | |
5354 | + this.set_use_cpaint_api = function() { | |
5355 | + if (typeof arguments[0] == 'boolean') { | |
5356 | + config['use_cpaint_api'] = arguments[0]; | |
5357 | + } | |
5358 | + } | |
5359 | + | |
5360 | + /** | |
5361 | + * tests whether one of the necessary implementations | |
5362 | + * of the XMLHttpRequest class are available | |
5363 | + * | |
5364 | + * @access protected | |
5365 | + * @return boolean | |
5366 | + */ | |
5367 | + function test_ajax_capability() { | |
5368 | + var cpc = new cpaint_call(0, config, this.version); | |
5369 | + return cpc.test_ajax_capability(); | |
5370 | + } | |
5371 | + | |
5372 | + /** | |
5373 | + * takes the arguments supplied and triggers a call to the CPAINT backend | |
5374 | + * based on the settings. | |
5375 | + * | |
5376 | + * upon response cpaint_call.callback() will automatically be called | |
5377 | + * to perform post-processing operations. | |
5378 | + * | |
5379 | + * @access public | |
5380 | + * @param string url remote URL to call | |
5381 | + * @param string remote_method remote method to call | |
5382 | + * @param object client_callback client side callback method to deliver the remote response to. do NOT supply a string! | |
5383 | + * @param mixed argN remote parameters from now on | |
5384 | + * @return void | |
5385 | + */ | |
5386 | + this.call = function() { | |
5387 | + //incluido por edmar | |
5388 | + var sUrl = escape(arguments[0]); | |
5389 | + var re = new RegExp("%3F", "g"); | |
5390 | + var sUrl = sUrl.replace(re,'?'); | |
5391 | + var re = new RegExp("%3D", "g"); | |
5392 | + var sUrl = sUrl.replace(re,'='); | |
5393 | + var re = new RegExp("%26", "g"); | |
5394 | + var sUrl = sUrl.replace(re,'&'); | |
5395 | + var re = new RegExp("%3A", "g"); | |
5396 | + var sUrl = sUrl.replace(re,':'); | |
5397 | + //alert(sUrl) | |
5398 | + arguments[0] = sUrl; | |
5399 | + // | |
5400 | + var use_stack = -1; | |
5401 | + | |
5402 | + if (config['persistent_connection'] == true | |
5403 | + && __cpaint_stack[0] != null) { | |
5404 | + | |
5405 | + switch (__cpaint_stack[0].get_http_state()) { | |
5406 | + case -1: | |
5407 | + // no XMLHttpObject object has already been instanciated | |
5408 | + // create new object and configure it | |
5409 | + use_stack = 0; | |
5410 | + debug('no XMLHttpObject object to re-use for persistence, creating new one later', 2); | |
5411 | + break; | |
5412 | + | |
5413 | + case 4: | |
5414 | + // object is ready for a new request, no need to do anything | |
5415 | + use_stack = 0 | |
5416 | + debug('re-using the persistent connection', 2); | |
5417 | + break; | |
5418 | + | |
5419 | + default: | |
5420 | + // connection is currently in use, don't do anything | |
5421 | + debug('the persistent connection is in use - skipping this request', 2); | |
5422 | + } | |
5423 | + | |
5424 | + } else if (config['persistent_connection'] == true) { | |
5425 | + // persistent connection is active, but no object has been instanciated | |
5426 | + use_stack = 0; | |
5427 | + __cpaint_stack[use_stack] = new cpaint_call(use_stack, config, this.version); | |
5428 | + debug('no cpaint_call object available for re-use, created new one', 2); | |
5429 | + | |
5430 | + } else { | |
5431 | + // no connection persistance | |
5432 | + use_stack = stack_count; | |
5433 | + __cpaint_stack[use_stack] = new cpaint_call(use_stack, config, this.version); | |
5434 | + debug('no cpaint_call object created new one', 2); | |
5435 | + } | |
5436 | + | |
5437 | + // configure cpaint_call if allowed to | |
5438 | + if (use_stack != -1) { | |
5439 | + __cpaint_stack[use_stack].set_client_callback(arguments[2]); | |
5440 | + | |
5441 | + // distribute according to proxy use | |
5442 | + if (config['proxy_url'] != '') { | |
5443 | + __cpaint_stack[use_stack].call_proxy(arguments); | |
5444 | + | |
5445 | + } else { | |
5446 | + __cpaint_stack[use_stack].call_direct(arguments); | |
5447 | + } | |
5448 | + | |
5449 | + // increase stack counter | |
5450 | + stack_count++; | |
5451 | + debug('stack size: ' + __cpaint_stack.length, 2); | |
5452 | + } | |
5453 | + } | |
5454 | + | |
5455 | + /** | |
5456 | + * debug method | |
5457 | + * | |
5458 | + * @access protected | |
5459 | + * @param string message the message to debug | |
5460 | + * @param integer debug_level debug level at which the message appears | |
5461 | + * @return void | |
5462 | + */ | |
5463 | + var debug = function(message, debug_level) { | |
5464 | + var prefix = '[CPAINT Debug] '; | |
5465 | + | |
5466 | + if (debug_level < 1) { | |
5467 | + prefix = '[CPAINT Error] '; | |
5468 | + } | |
5469 | + | |
5470 | + if (config['debugging'] >= debug_level) { | |
5471 | + alert(prefix + message); | |
5472 | + } | |
5473 | + } | |
5474 | +} | |
5475 | + | |
5476 | +/** | |
5477 | +* internal FIFO stack of cpaint_call() objects. | |
5478 | +* | |
5479 | +* @access protected | |
5480 | +* @var array __cpaint_stack | |
5481 | +*/ | |
5482 | +var __cpaint_stack = new Array(); | |
5483 | + | |
5484 | +/** | |
5485 | +* local instance of cpaint_transformer | |
5486 | +* MSIE is unable to handle static classes... sheesh. | |
5487 | +* | |
5488 | +* @access public | |
5489 | +* @var object __cpaint_transformer | |
5490 | +*/ | |
5491 | +var __cpaint_transformer = new cpaint_transformer(); | |
5492 | + | |
5493 | +/** | |
5494 | +* transport agent class | |
5495 | +* | |
5496 | +* creates the request object, takes care of the response, handles the | |
5497 | +* client callback. Is configured by the cpaint() object. | |
5498 | +* | |
5499 | +* @package CPAINT | |
5500 | +* @access public | |
5501 | +* @copyright Copyright (c) 2005-2006 Paul Sullivan, Dominique Stender - http://sf.net/projects/cpaint | |
5502 | +* @author Dominique Stender <dstender@st-webdevelopment.de> | |
5503 | +* @author Paul Sullivan <wiley14@gmail.com> | |
5504 | +* @param integer stack_id stack Id in cpaint | |
5505 | +* @param array config configuration array for this call | |
5506 | +* @param string version CPAINT API version | |
5507 | +*/ | |
5508 | +function cpaint_call() { | |
5509 | + /** | |
5510 | + * CPAINT version | |
5511 | + * | |
5512 | + * @access protected | |
5513 | + * @var string version | |
5514 | + */ | |
5515 | + var version = arguments[2]; | |
5516 | + | |
5517 | + /** | |
5518 | + * configuration options both for this class objects. | |
5519 | + * | |
5520 | + * @access protected | |
5521 | + * @var array config | |
5522 | + */ | |
5523 | + var config = new Array(); | |
5524 | + config['debugging'] = arguments[1]['debugging']; | |
5525 | + config['proxy_url'] = arguments[1]['proxy_url']; | |
5526 | + config['transfer_mode'] = arguments[1]['transfer_mode']; | |
5527 | + config['async'] = arguments[1]['async']; | |
5528 | + config['response_type'] = arguments[1]['response_type']; | |
5529 | + config['persistent_connection'] = arguments[1]['persistent_connection']; | |
5530 | + config['use_cpaint_api'] = arguments[1]['use_cpaint_api']; | |
5531 | + | |
5532 | + /** | |
5533 | + * XMLHttpObject used for this request. | |
5534 | + * | |
5535 | + * @access protected | |
5536 | + * @var object httpobj | |
5537 | + */ | |
5538 | + var httpobj = false; | |
5539 | + | |
5540 | + /** | |
5541 | + * client callback function. | |
5542 | + * | |
5543 | + * @access public | |
5544 | + * @var function client_callback | |
5545 | + */ | |
5546 | + var client_callback; | |
5547 | + | |
5548 | + /** | |
5549 | + * stores the stack Id within the cpaint object | |
5550 | + * | |
5551 | + * @access protected | |
5552 | + * @var stack_id | |
5553 | + */ | |
5554 | + var stack_id = arguments[0]; | |
5555 | + | |
5556 | + /** | |
5557 | + * sets the client callback function. | |
5558 | + * | |
5559 | + * @access public | |
5560 | + * @param function client_callback the client callback function | |
5561 | + * @return void | |
5562 | + */ | |
5563 | + this.set_client_callback = function() { | |
5564 | + | |
5565 | + if (typeof arguments[0] == 'function') { | |
5566 | + client_callback = arguments[0]; | |
5567 | + } | |
5568 | + } | |
5569 | + | |
5570 | + /** | |
5571 | + * returns the ready state of the internal XMLHttpObject | |
5572 | + * | |
5573 | + * if no such object was set up already, -1 is returned | |
5574 | + * | |
5575 | + * @access public | |
5576 | + * @return integer | |
5577 | + */ | |
5578 | + this.get_http_state = function() { | |
5579 | + var return_value = -1; | |
5580 | + | |
5581 | + if (typeof httpobj == 'object') { | |
5582 | + return_value = httpobj.readyState; | |
5583 | + } | |
5584 | + | |
5585 | + return return_value; | |
5586 | + } | |
5587 | + | |
5588 | + /** | |
5589 | + * internal method for remote calls to the local server without use of the proxy script. | |
5590 | + * | |
5591 | + * @access public | |
5592 | + * @param array call_arguments array of arguments initially passed to cpaint.call() | |
5593 | + * @return void | |
5594 | + */ | |
5595 | + this.call_direct = function(call_arguments) { | |
5596 | + var url = call_arguments[0]; | |
5597 | + var remote_method = call_arguments[1]; | |
5598 | + var querystring = ''; | |
5599 | + var i = 0; | |
5600 | + | |
5601 | + // correct link to self | |
5602 | + if (url == 'SELF') { | |
5603 | + url = document.location.href; | |
5604 | + } | |
5605 | + | |
5606 | + if (config['use_cpaint_api'] == true) { | |
5607 | + // backend uses cpaint api | |
5608 | + // pass parameters to remote method | |
5609 | + for (i = 3; i < call_arguments.length; i++) { | |
5610 | + | |
5611 | + if ((typeof call_arguments[i] == 'string' | |
5612 | + && call_arguments[i] != '' | |
5613 | + && call_arguments[i].search(/^\s+$/g) == -1) | |
5614 | + && !isNaN(call_arguments[i]) | |
5615 | + && isFinite(call_arguments[i])) { | |
5616 | + // numerical value, convert it first | |
5617 | + querystring += '&cpaint_argument[]=' + encodeURIComponent(JSON.stringify(Number(call_arguments[i]))); | |
5618 | + | |
5619 | + } else { | |
5620 | + querystring += '&cpaint_argument[]=' + encodeURIComponent(JSON.stringify(call_arguments[i])); | |
5621 | + } | |
5622 | + } | |
5623 | + | |
5624 | + // add response type to querystring | |
5625 | + querystring += '&cpaint_response_type=' + config['response_type']; | |
5626 | + | |
5627 | + // build header | |
5628 | + if (config['transfer_mode'] == 'GET') { | |
5629 | + | |
5630 | + if(url.indexOf('?') != -1) { | |
5631 | + url = url + '&cpaint_function=' + remote_method + querystring; | |
5632 | + | |
5633 | + } else { | |
5634 | + url = url + '?cpaint_function=' + remote_method + querystring; | |
5635 | + } | |
5636 | + | |
5637 | + } else { | |
5638 | + querystring = 'cpaint_function=' + remote_method + querystring; | |
5639 | + } | |
5640 | + | |
5641 | + } else { | |
5642 | + // backend does not use cpaint api | |
5643 | + // pass parameters to remote method | |
5644 | + for (i = 3; i < call_arguments.length; i++) { | |
5645 | + | |
5646 | + if (i == 3) { | |
5647 | + querystring += encodeURIComponent(call_arguments[i]); | |
5648 | + | |
5649 | + } else { | |
5650 | + querystring += '&' + encodeURIComponent(call_arguments[i]); | |
5651 | + } | |
5652 | + } | |
5653 | + | |
5654 | + // build header | |
5655 | + if (config['transfer_mode'] == 'GET') { | |
5656 | + url = url + querystring; | |
5657 | + } | |
5658 | + } | |
5659 | + | |
5660 | + // open connection | |
5661 | + get_connection_object(); | |
5662 | + | |
5663 | + // open connection to remote target | |
5664 | + debug('opening connection to "' + url + '"', 1); | |
5665 | + httpobj.open(config['transfer_mode'], url, config['async']); | |
5666 | + | |
5667 | + // send "urlencoded" header if necessary (if POST) | |
5668 | + if (config['transfer_mode'] == 'POST') { | |
5669 | + | |
5670 | + try { | |
5671 | + httpobj.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); | |
5672 | + | |
5673 | + } catch (cp_err) { | |
5674 | + debug('POST cannot be completed due to incompatible browser. Use GET as your request method.', 0); | |
5675 | + } | |
5676 | + } | |
5677 | + | |
5678 | + // make ourselves known | |
5679 | + httpobj.setRequestHeader('X-Powered-By', 'CPAINT v' + version + ' :: http://sf.net/projects/cpaint'); | |
5680 | + | |
5681 | + // callback handling for asynchronous calls | |
5682 | + httpobj.onreadystatechange = callback; | |
5683 | + | |
5684 | + // send content | |
5685 | + if (config['transfer_mode'] == 'GET') { | |
5686 | + httpobj.send(null); | |
5687 | + | |
5688 | + } else { | |
5689 | + debug('sending query: ' + querystring, 1); | |
5690 | + httpobj.send(querystring); | |
5691 | + } | |
5692 | + | |
5693 | + if (config['async'] == true) { | |
5694 | + // manual callback handling for synchronized calls | |
5695 | + callback(); | |
5696 | + } | |
5697 | + } | |
5698 | + | |
5699 | + /** | |
5700 | + * internal method for calls to remote servers through the proxy script. | |
5701 | + * | |
5702 | + * @access public | |
5703 | + * @param array call_arguments array of arguments passed to cpaint.call() | |
5704 | + * @return void | |
5705 | + */ | |
5706 | + this.call_proxy = function(call_arguments) { | |
5707 | + var proxyscript = config['proxy_url']; | |
5708 | + var url = call_arguments[0]; | |
5709 | + var remote_method = call_arguments[1]; | |
5710 | + var querystring = ''; | |
5711 | + var i = 0; | |
5712 | + | |
5713 | + var querystring_argument_prefix = 'cpaint_argument[]='; | |
5714 | + | |
5715 | + // pass parameters to remote method | |
5716 | + if (config['use_cpaint_api'] == false) { | |
5717 | + // when not talking to a CPAINT backend, don't prefix arguments | |
5718 | + querystring_argument_prefix = ''; | |
5719 | + } | |
5720 | + | |
5721 | + for (i = 3; i < call_arguments.length; i++) { | |
5722 | + | |
5723 | + if (config['use_cpaint_api'] == true) { | |
5724 | + | |
5725 | + if ((typeof call_arguments[i] == 'string' | |
5726 | + && call_arguments[i] != '' | |
5727 | + && call_arguments[i].search(/^\s+$/g) == -1) | |
5728 | + && !isNaN(call_arguments[i]) | |
5729 | + && isFinite(call_arguments[i])) { | |
5730 | + // numerical value, convert it first | |
5731 | + querystring += encodeURIComponent(querystring_argument_prefix + JSON.stringify(Number(call_arguments[i])) + '&'); | |
5732 | + | |
5733 | + } else { | |
5734 | + querystring += encodeURIComponent(querystring_argument_prefix + JSON.stringify(call_arguments[i]) + '&'); | |
5735 | + } | |
5736 | + | |
5737 | + } else { | |
5738 | + // no CPAINT in the backend | |
5739 | + querystring += encodeURIComponent(querystring_argument_prefix + call_arguments[i] + '&'); | |
5740 | + } | |
5741 | + } | |
5742 | + | |
5743 | + if (config['use_cpaint_api'] == true) { | |
5744 | + // add remote function name to querystring | |
5745 | + querystring += encodeURIComponent('&cpaint_function=' + remote_method); | |
5746 | + | |
5747 | + // add response type to querystring | |
5748 | + querystring += encodeURIComponent('&cpaint_responsetype=' + config['response_type']); | |
5749 | + } | |
5750 | + | |
5751 | + // build header | |
5752 | + if (config['transfer_mode'] == 'GET') { | |
5753 | + proxyscript += '?cpaint_remote_url=' + encodeURIComponent(url) | |
5754 | + + '&cpaint_remote_query=' + querystring | |
5755 | + + '&cpaint_remote_method=' + config['transfer_mode'] | |
5756 | + + '&cpaint_response_type=' + config['response_type']; | |
5757 | + | |
5758 | + } else { | |
5759 | + querystring = 'cpaint_remote_url=' + encodeURIComponent(url) | |
5760 | + + '&cpaint_remote_query=' + querystring | |
5761 | + + '&cpaint_remote_method=' + config['transfer_mode'] | |
5762 | + + '&cpaint_response_type=' + config['response_type']; | |
5763 | + } | |
5764 | + | |
5765 | + // open connection | |
5766 | + get_connection_object(); | |
5767 | + | |
5768 | + // open connection to remote target | |
5769 | + debug('opening connection to proxy "' + proxyscript + '"', 1); | |
5770 | + httpobj.open(config['transfer_mode'], proxyscript, config['async']); | |
5771 | + | |
5772 | + // send "urlencoded" header if necessary (if POST) | |
5773 | + if (config['transfer_mode'] == 'POST') { | |
5774 | + | |
5775 | + try { | |
5776 | + httpobj.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); | |
5777 | + | |
5778 | + } catch (cp_err) { | |
5779 | + debug('POST cannot be completed due to incompatible browser. Use GET as your request method.', 0); | |
5780 | + } | |
5781 | + } | |
5782 | + | |
5783 | + httpobj.setRequestHeader('X-Powered-By', 'CPAINT v' + version); | |
5784 | + | |
5785 | + // callback handling for asynchronous calls | |
5786 | + httpobj.onreadystatechange = callback; | |
5787 | + | |
5788 | + // send content | |
5789 | + if (config['transfer_mode'] == 'GET') { | |
5790 | + httpobj.send(null); | |
5791 | + | |
5792 | + } else { | |
5793 | + debug('sending query: ' + querystring, 1); | |
5794 | + httpobj.send(querystring); | |
5795 | + } | |
5796 | + | |
5797 | + if (config['async'] == false) { | |
5798 | + // manual callback handling for synchronized calls | |
5799 | + callback(); | |
5800 | + } | |
5801 | + } | |
5802 | + | |
5803 | + this.test_ajax_capability = function() { | |
5804 | + return get_connection_object(); | |
5805 | + } | |
5806 | + | |
5807 | + /** | |
5808 | + * creates a new connection object. | |
5809 | + * | |
5810 | + * @access protected | |
5811 | + * @return boolean | |
5812 | + */ | |
5813 | + var get_connection_object = function() { | |
5814 | + var return_value = false; | |
5815 | + var new_connection = false; | |
5816 | + | |
5817 | + // open new connection only if necessary | |
5818 | + if (config['persistent_connection'] == false) { | |
5819 | + // no persistance, create a new object every time | |
5820 | + debug('Using new connection object', 1); | |
5821 | + new_connection = true; | |
5822 | + | |
5823 | + } else { | |
5824 | + // persistent connection object, only open one if no object exists | |
5825 | + debug('Using shared connection object.', 1); | |
5826 | + | |
5827 | + if (typeof httpobj != 'object') { | |
5828 | + debug('Getting new persistent connection object.', 1); | |
5829 | + new_connection = true; | |
5830 | + } | |
5831 | + } | |
5832 | + | |
5833 | + if (new_connection == true) { | |
5834 | + | |
5835 | + try { | |
5836 | + httpobj = new XMLHttpRequest(); | |
5837 | + } catch (e1) { | |
5838 | + | |
5839 | + try { | |
5840 | + httpobj = new ActiveXObject('Msxml2.XMLHTTP'); | |
5841 | + | |
5842 | + } catch (e) { | |
5843 | + | |
5844 | + try { | |
5845 | + httpobj = new ActiveXObject('Microsoft.XMLHTTP'); | |
5846 | + | |
5847 | + } catch (oc) { | |
5848 | + httpobj = null; | |
5849 | + } | |
5850 | + } | |
5851 | + } | |
5852 | + | |
5853 | + | |
5854 | + if (!httpobj) { | |
5855 | + debug('Could not create connection object', 0); | |
5856 | + | |
5857 | + } else { | |
5858 | + return_value = true; | |
5859 | + } | |
5860 | + } | |
5861 | + | |
5862 | + if (httpobj.readyState != 4) { | |
5863 | + httpobj.abort(); | |
5864 | + } | |
5865 | + | |
5866 | + return return_value; | |
5867 | + } | |
5868 | + | |
5869 | + /** | |
5870 | + * internal callback function. | |
5871 | + * | |
5872 | + * will perform some consistency checks (response code, NULL value testing) | |
5873 | + * and if response_type = 'OBJECT' it will automatically call | |
5874 | + * cpaint_call.parse_ajax_xml() to have a JavaScript object structure generated. | |
5875 | + * | |
5876 | + * after all that is done the client side callback function will be called | |
5877 | + * with the generated response as single value. | |
5878 | + * | |
5879 | + * @access protected | |
5880 | + * @return void | |
5881 | + */ | |
5882 | + var callback = function() { | |
5883 | + var response = null; | |
5884 | + if (httpobj.readyState == 4 | |
5885 | + && httpobj.status == 200) { | |
5886 | + if(httpobj.responseText == ""){ | |
5887 | + alert("O servidor demorou muito - timeout"); | |
5888 | + client_callback("", "erro"); | |
5889 | + return; | |
5890 | + } | |
5891 | + debug(httpobj.responseText, 1); | |
5892 | + debug('using response type ' + config['response_type'], 2); | |
5893 | + | |
5894 | + // fetch correct response | |
5895 | + switch (config['response_type']) { | |
5896 | + case 'XML': | |
5897 | + debug(httpobj.responseXML, 2); | |
5898 | + response = __cpaint_transformer.xml_conversion(httpobj.responseXML); | |
5899 | + break; | |
5900 | + | |
5901 | + case 'OBJECT': | |
5902 | + response = __cpaint_transformer.object_conversion(httpobj.responseXML); | |
5903 | + break; | |
5904 | + | |
5905 | + case 'TEXT': | |
5906 | + response = __cpaint_transformer.text_conversion(httpobj.responseText); | |
5907 | + break; | |
5908 | + | |
5909 | + case 'E4X': | |
5910 | + response = __cpaint_transformer.e4x_conversion(httpobj.responseText); | |
5911 | + break; | |
5912 | + | |
5913 | + case 'JSON': | |
5914 | + response = __cpaint_transformer.json_conversion(httpobj.responseText); | |
5915 | + break; | |
5916 | + | |
5917 | + default: | |
5918 | + debug('invalid response type \'' + response_type + '\'', 0); | |
5919 | + } | |
5920 | + | |
5921 | + // call client side callback | |
5922 | + if (response != null | |
5923 | + && typeof client_callback == 'function') { | |
5924 | + try{ | |
5925 | + if(response.data) | |
5926 | + client_callback(response, httpobj.responseText); | |
5927 | + else | |
5928 | + client_callback("", "erro"); | |
5929 | + } | |
5930 | + catch(e){ | |
5931 | + client_callback("", "erro"); | |
5932 | + } | |
5933 | + } | |
5934 | + // remove ourselves from the stack | |
5935 | + remove_from_stack(); | |
5936 | + | |
5937 | + } else | |
5938 | + { | |
5939 | + if(httpobj.readyState==4&&httpobj.status!=200) | |
5940 | + { | |
5941 | + debug('invalid HTTP response code \''+Number(httpobj.status)+'\'',0); | |
5942 | + if(httpobj.status==500){ | |
5943 | + alert("O servidor demorou muito - timeout"); | |
5944 | + client_callback("", "erro"); | |
5945 | + } | |
5946 | + else{ | |
5947 | + client_callback("", "erro"); | |
5948 | + } | |
5949 | + } | |
5950 | + | |
5951 | + } | |
5952 | + } | |
5953 | + | |
5954 | + /** | |
5955 | + * removes an entry from the stack | |
5956 | + * | |
5957 | + * @access protected | |
5958 | + * @return void | |
5959 | + */ | |
5960 | + var remove_from_stack = function() { | |
5961 | + // remove only if everything is okay and we're not configured as persistent connection | |
5962 | + if (typeof stack_id == 'number' | |
5963 | + && __cpaint_stack[stack_id] | |
5964 | + && config['persistent_connection'] == false) { | |
5965 | + | |
5966 | + __cpaint_stack[stack_id] = null; | |
5967 | + } | |
5968 | + } | |
5969 | + | |
5970 | + /** | |
5971 | + * debug method | |
5972 | + * | |
5973 | + * @access protected | |
5974 | + * @param string message the message to debug | |
5975 | + * @param integer debug_level debug level at which the message appears | |
5976 | + * @return void | |
5977 | + */ | |
5978 | + var debug = function(message, debug_level) { | |
5979 | + var prefix = '[CPAINT Debug] '; | |
5980 | + | |
5981 | + if (config['debugging'] < 1) { | |
5982 | + prefix = '[CPAINT Error] '; | |
5983 | + } | |
5984 | + | |
5985 | + if (config['debugging'] >= debug_level) { | |
5986 | + alert(prefix + message); | |
5987 | + } | |
5988 | + if (message.search(" error") > 1){client_callback("", message);} | |
5989 | + } | |
5990 | +} | |
5991 | + | |
5992 | +/** | |
5993 | +* CPAINT transformation object | |
5994 | +* | |
5995 | +* @package CPAINT | |
5996 | +* @access public | |
5997 | +* @copyright Copyright (c) 2005-2006 Paul Sullivan, Dominique Stender - http://sf.net/projects/cpaint | |
5998 | +* @author Paul Sullivan <wiley14@gmail.com> | |
5999 | +* @author Dominique Stender <dstender@st-webdevelopment.de> | |
6000 | +*/ | |
6001 | +function cpaint_transformer() { | |
6002 | + | |
6003 | + /** | |
6004 | + * will take a XMLHttpObject and generate a JavaScript | |
6005 | + * object structure from it. | |
6006 | + * | |
6007 | + * is internally called by cpaint_call.callback() if necessary. | |
6008 | + * will call cpaint_call.create_object_structure() to create nested object structures. | |
6009 | + * | |
6010 | + * @access public | |
6011 | + * @param object xml_document a XMLHttpObject | |
6012 | + * @return object | |
6013 | + */ | |
6014 | + this.object_conversion = function(xml_document) { | |
6015 | + var return_value = new cpaint_result_object(); | |
6016 | + var i = 0; | |
6017 | + var firstNodeName = ''; | |
6018 | + | |
6019 | + if (typeof xml_document == 'object' | |
6020 | + && xml_document != null) { | |
6021 | + | |
6022 | + // find the first element node - for MSIE the <?xml?> node is the very first... | |
6023 | + for (i = 0; i < xml_document.childNodes.length; i++) { | |
6024 | + | |
6025 | + if (xml_document.childNodes[i].nodeType == 1) { | |
6026 | + firstNodeName = xml_document.childNodes[i].nodeName; | |
6027 | + break; | |
6028 | + } | |
6029 | + } | |
6030 | + | |
6031 | + var ajax_response = xml_document.getElementsByTagName(firstNodeName); | |
6032 | + | |
6033 | + return_value[firstNodeName] = new Array(); | |
6034 | + | |
6035 | + for (i = 0; i < ajax_response.length; i++) { | |
6036 | + var tmp_node = create_object_structure(ajax_response[i]); | |
6037 | + tmp_node.id = ajax_response[i].getAttribute('id') | |
6038 | + return_value[firstNodeName].push(tmp_node); | |
6039 | + } | |
6040 | + | |
6041 | + } else { | |
6042 | + debug('received invalid XML response', 0); | |
6043 | + } | |
6044 | + | |
6045 | + return return_value; | |
6046 | + } | |
6047 | + | |
6048 | + /** | |
6049 | + * performs the necessary conversions for the XML response type | |
6050 | + * | |
6051 | + * @access public | |
6052 | + * @param object xml_document a XMLHttpObject | |
6053 | + * @return object | |
6054 | + */ | |
6055 | + this.xml_conversion = function(xml_document) { | |
6056 | + return xml_document; | |
6057 | + } | |
6058 | + | |
6059 | + /** | |
6060 | + * performs the necessary conversions for the TEXT response type | |
6061 | + * | |
6062 | + * @access public | |
6063 | + * @param string text the response text | |
6064 | + * @return string | |
6065 | + */ | |
6066 | + this.text_conversion = function(text) { | |
6067 | + return decode(text); | |
6068 | + } | |
6069 | + | |
6070 | + /** | |
6071 | + * performs the necessary conversions for the E4X response type | |
6072 | + * | |
6073 | + * @access public | |
6074 | + * @param string text the response text | |
6075 | + * @return string | |
6076 | + */ | |
6077 | + this.e4x_conversion = function(text) { | |
6078 | + // remove <?xml ?>tag | |
6079 | + text = text.replace(/^\<\?xml[^>]+\>/, ''); | |
6080 | + return new XML(text); | |
6081 | + } | |
6082 | + | |
6083 | + /** | |
6084 | + * performs the necessary conversions for the JSON response type | |
6085 | + * | |
6086 | + * @access public | |
6087 | + * @param string text the response text | |
6088 | + * @return string | |
6089 | + */ | |
6090 | + this.json_conversion = function(text) { | |
6091 | + return JSON.parse(text); | |
6092 | + } | |
6093 | + | |
6094 | + /** | |
6095 | + * this method takes a HTML / XML node object and creates a | |
6096 | + * JavaScript object structure from it. | |
6097 | + * | |
6098 | + * @access public | |
6099 | + * @param object stream a node in the XML structure | |
6100 | + * @return object | |
6101 | + */ | |
6102 | + var create_object_structure = function(stream) { | |
6103 | + var return_value = new cpaint_result_object(); | |
6104 | + var node_name = ''; | |
6105 | + var i = 0; | |
6106 | + var attrib = 0; | |
6107 | + | |
6108 | + if (stream.hasChildNodes() == true) { | |
6109 | + for (i = 0; i < stream.childNodes.length; i++) { | |
6110 | + | |
6111 | + node_name = stream.childNodes[i].nodeName; | |
6112 | + node_name = node_name.replace(/[^a-zA-Z0-9_]*/g, ''); | |
6113 | + | |
6114 | + // reset / create subnode | |
6115 | + if (typeof return_value[node_name] != 'object') { | |
6116 | + return_value[node_name] = new Array(); | |
6117 | + } | |
6118 | + | |
6119 | + if (stream.childNodes[i].nodeType == 1) { | |
6120 | + var tmp_node = create_object_structure(stream.childNodes[i]); | |
6121 | + | |
6122 | + for (attrib = 0; attrib < stream.childNodes[i].attributes.length; attrib++) { | |
6123 | + tmp_node.set_attribute(stream.childNodes[i].attributes[attrib].nodeName, stream.childNodes[i].attributes[attrib].nodeValue); | |
6124 | + } | |
6125 | + | |
6126 | + return_value[node_name].push(tmp_node); | |
6127 | + | |
6128 | + } else if (stream.childNodes[i].nodeType == 3) { | |
6129 | + return_value.data = decode(String(stream.firstChild.data)); | |
6130 | + } | |
6131 | + } | |
6132 | + } | |
6133 | + | |
6134 | + return return_value; | |
6135 | + } | |
6136 | + | |
6137 | + /** | |
6138 | + * converts an encoded text back to viewable characters. | |
6139 | + * | |
6140 | + * @access public | |
6141 | + * @param string rawtext raw text as provided by the backend | |
6142 | + * @return mixed | |
6143 | + */ | |
6144 | + var decode = function(rawtext) { | |
6145 | + var plaintext = ''; | |
6146 | + var i = 0; | |
6147 | + var c1 = 0; | |
6148 | + var c2 = 0; | |
6149 | + var c3 = 0; | |
6150 | + var u = 0; | |
6151 | + var t = 0; | |
6152 | + | |
6153 | + // remove special JavaScript encoded non-printable characters | |
6154 | + while (i < rawtext.length) { | |
6155 | + if (rawtext.charAt(i) == '\\' | |
6156 | + && rawtext.charAt(i + 1) == 'u') { | |
6157 | + | |
6158 | + u = 0; | |
6159 | + | |
6160 | + for (j = 2; j < 6; j += 1) { | |
6161 | + t = parseInt(rawtext.charAt(i + j), 16); | |
6162 | + | |
6163 | + if (!isFinite(t)) { | |
6164 | + break; | |
6165 | + } | |
6166 | + u = u * 16 + t; | |
6167 | + } | |
6168 | + | |
6169 | + plaintext += String.fromCharCode(u); | |
6170 | + i += 6; | |
6171 | + | |
6172 | + } else { | |
6173 | + plaintext += rawtext.charAt(i); | |
6174 | + i++; | |
6175 | + } | |
6176 | + } | |
6177 | + | |
6178 | + // convert numeric data to number type | |
6179 | + if (plaintext != '' | |
6180 | + && plaintext.search(/^\s+$/g) == -1 | |
6181 | + && !isNaN(plaintext) | |
6182 | + && isFinite(plaintext)) { | |
6183 | + | |
6184 | + plaintext = Number(plaintext); | |
6185 | + } | |
6186 | + | |
6187 | + return plaintext; | |
6188 | + } | |
6189 | +} | |
6190 | + | |
6191 | +/** | |
6192 | +* this is the basic prototype for a cpaint node object | |
6193 | +* as used in cpaint_call.parse_ajax_xml() | |
6194 | +* | |
6195 | +* @package CPAINT | |
6196 | +* @access public | |
6197 | +* @copyright Copyright (c) 2005-2006 Paul Sullivan, Dominique Stender - http://sf.net/projects/cpaint | |
6198 | +* @author Paul Sullivan <wiley14@gmail.com> | |
6199 | +* @author Dominique Stender <dstender@st-webdevelopment.de> | |
6200 | +*/ | |
6201 | +function cpaint_result_object() { | |
6202 | + this.id = 0; | |
6203 | + this.data = ''; | |
6204 | + var __attributes = new Array(); | |
6205 | + | |
6206 | + /** | |
6207 | + * Returns a subnode with the given type and id. | |
6208 | + * | |
6209 | + * @access public | |
6210 | + * @param string type The type of the subnode. Equivalent to the XML tag name. | |
6211 | + * @param string id The id of the subnode. Equivalent to the XML tag names id attribute. | |
6212 | + * @return object | |
6213 | + */ | |
6214 | + this.find_item_by_id = function() { | |
6215 | + var return_value = null; | |
6216 | + var type = arguments[0]; | |
6217 | + var id = arguments[1]; | |
6218 | + var i = 0; | |
6219 | + | |
6220 | + if (this[type]) { | |
6221 | + | |
6222 | + for (i = 0; i < this[type].length; i++) { | |
6223 | + | |
6224 | + if (this[type][i].get_attribute('id') == id) { | |
6225 | + return_value = this[type][i]; | |
6226 | + break; | |
6227 | + } | |
6228 | + } | |
6229 | + } | |
6230 | + | |
6231 | + return return_value; | |
6232 | + } | |
6233 | + | |
6234 | + /** | |
6235 | + * retrieves the value of an attribute. | |
6236 | + * | |
6237 | + * @access public | |
6238 | + * @param string name name of the attribute | |
6239 | + * @return mixed | |
6240 | + */ | |
6241 | + this.get_attribute = function() { | |
6242 | + var return_value = null; | |
6243 | + var id = arguments[0]; | |
6244 | + | |
6245 | + if (typeof __attributes[id] != 'undefined') { | |
6246 | + return_value = __attributes[id]; | |
6247 | + } | |
6248 | + | |
6249 | + return return_value; | |
6250 | + } | |
6251 | + | |
6252 | + /** | |
6253 | + * assigns a value to an attribute. | |
6254 | + * | |
6255 | + * if that attribute does not exist it will be created. | |
6256 | + * | |
6257 | + * @access public | |
6258 | + * @param string name name of the attribute | |
6259 | + * @param string value value of the attribute | |
6260 | + * @return void | |
6261 | + */ | |
6262 | + this.set_attribute = function() { | |
6263 | + __attributes[arguments[0]] = arguments[1]; | |
6264 | + } | |
6265 | +} | |
6266 | + | |
6267 | + | |
6268 | +/* | |
6269 | +Copyright (c) 2005 JSON.org | |
6270 | + | |
6271 | +Permission is hereby granted, free of charge, to any person obtaining a copy | |
6272 | +of this software and associated documentation files (the "Software"), to deal | |
6273 | +in the Software without restriction, including without limitation the rights | |
6274 | +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
6275 | +copies of the Software, and to permit persons to whom the Software is | |
6276 | +furnished to do so, subject to the following conditions: | |
6277 | + | |
6278 | +The Software shall be used for Good, not Evil. | |
6279 | + | |
6280 | +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
6281 | +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
6282 | +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
6283 | +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
6284 | +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
6285 | +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |
6286 | +SOFTWARE. | |
6287 | +*/ | |
6288 | + | |
6289 | + | |
6290 | +Array.prototype.______array = '______array'; | |
6291 | + | |
6292 | +var JSON = { | |
6293 | + org: 'http://www.JSON.org', | |
6294 | + copyright: '(c)2005 JSON.org', | |
6295 | + license: 'http://www.crockford.com/JSON/license.html', | |
6296 | + | |
6297 | + stringify: function (arg) { | |
6298 | + var c, i, l, s = '', v; | |
6299 | + var numeric = true; | |
6300 | + | |
6301 | + switch (typeof arg) { | |
6302 | + case 'object': | |
6303 | + if (arg) { | |
6304 | + if (arg.______array == '______array') { | |
6305 | + // do a test whether all array keys are numeric | |
6306 | + for (i in arg) { | |
6307 | + if (i != '______array' | |
6308 | + && (isNaN(i) | |
6309 | + || !isFinite(i))) { | |
6310 | + numeric = false; | |
6311 | + break; | |
6312 | + } | |
6313 | + } | |
6314 | + | |
6315 | + if (numeric == true) { | |
6316 | + for (i = 0; i < arg.length; ++i) { | |
6317 | + if (typeof arg[i] != 'undefined') { | |
6318 | + v = this.stringify(arg[i]); | |
6319 | + if (s) { | |
6320 | + s += ','; | |
6321 | + } | |
6322 | + s += v; | |
6323 | + } else { | |
6324 | + s += ',null'; | |
6325 | + } | |
6326 | + } | |
6327 | + return '[' + s + ']'; | |
6328 | + } else { | |
6329 | + for (i in arg) { | |
6330 | + if (i != '______array') { | |
6331 | + v = arg[i]; | |
6332 | + if (typeof v != 'undefined' && typeof v != 'function') { | |
6333 | + v = this.stringify(v); | |
6334 | + if (s) { | |
6335 | + s += ','; | |
6336 | + } | |
6337 | + s += this.stringify(i) + ':' + v; | |
6338 | + } | |
6339 | + } | |
6340 | + } | |
6341 | + // return as object | |
6342 | + return '{' + s + '}'; | |
6343 | + } | |
6344 | + } else if (typeof arg.toString != 'undefined') { | |
6345 | + for (i in arg) { | |
6346 | + v = arg[i]; | |
6347 | + if (typeof v != 'undefined' && typeof v != 'function') { | |
6348 | + v = this.stringify(v); | |
6349 | + if (s) { | |
6350 | + s += ','; | |
6351 | + } | |
6352 | + s += this.stringify(i) + ':' + v; | |
6353 | + } | |
6354 | + } | |
6355 | + return '{' + s + '}'; | |
6356 | + } | |
6357 | + } | |
6358 | + return 'null'; | |
6359 | + case 'number': | |
6360 | + return isFinite(arg) ? String(arg) : 'null'; | |
6361 | + case 'string': | |
6362 | + l = arg.length; | |
6363 | + s = '"'; | |
6364 | + for (i = 0; i < l; i += 1) { | |
6365 | + c = arg.charAt(i); | |
6366 | + if (c >= ' ') { | |
6367 | + if (c == '\\' || c == '"') { | |
6368 | + s += '\\'; | |
6369 | + } | |
6370 | + s += c; | |
6371 | + } else { | |
6372 | + switch (c) { | |
6373 | + case '\b': | |
6374 | + s += '\\b'; | |
6375 | + break; | |
6376 | + case '\f': | |
6377 | + s += '\\f'; | |
6378 | + break; | |
6379 | + case '\n': | |
6380 | + s += '\\n'; | |
6381 | + break; | |
6382 | + case '\r': | |
6383 | + s += '\\r'; | |
6384 | + break; | |
6385 | + case '\t': | |
6386 | + s += '\\t'; | |
6387 | + break; | |
6388 | + default: | |
6389 | + c = c.charCodeAt(); | |
6390 | + s += '\\u00' + Math.floor(c / 16).toString(16) + | |
6391 | + (c % 16).toString(16); | |
6392 | + } | |
6393 | + } | |
6394 | + } | |
6395 | + return s + '"'; | |
6396 | + case 'boolean': | |
6397 | + return String(arg); | |
6398 | + default: | |
6399 | + return 'null'; | |
6400 | + } | |
6401 | + }, | |
6402 | + parse: function (text) { | |
6403 | + var at = 0; | |
6404 | + var ch = ' '; | |
6405 | + | |
6406 | + function error(m) { | |
6407 | + throw { | |
6408 | + name: 'JSONError', | |
6409 | + message: m, | |
6410 | + at: at - 1, | |
6411 | + text: text | |
6412 | + }; | |
6413 | + } | |
6414 | + | |
6415 | + function next() { | |
6416 | + ch = text.charAt(at); | |
6417 | + at += 1; | |
6418 | + return ch; | |
6419 | + } | |
6420 | + | |
6421 | + function white() { | |
6422 | + while (ch != '' && ch <= ' ') { | |
6423 | + next(); | |
6424 | + } | |
6425 | + } | |
6426 | + | |
6427 | + function str() { | |
6428 | + var i, s = '', t, u; | |
6429 | + | |
6430 | + if (ch == '"') { | |
6431 | +outer: while (next()) { | |
6432 | + if (ch == '"') { | |
6433 | + next(); | |
6434 | + return s; | |
6435 | + } else if (ch == '\\') { | |
6436 | + switch (next()) { | |
6437 | + case 'b': | |
6438 | + s += '\b'; | |
6439 | + break; | |
6440 | + case 'f': | |
6441 | + s += '\f'; | |
6442 | + break; | |
6443 | + case 'n': | |
6444 | + s += '\n'; | |
6445 | + break; | |
6446 | + case 'r': | |
6447 | + s += '\r'; | |
6448 | + break; | |
6449 | + case 't': | |
6450 | + s += '\t'; | |
6451 | + break; | |
6452 | + case 'u': | |
6453 | + u = 0; | |
6454 | + for (i = 0; i < 4; i += 1) { | |
6455 | + t = parseInt(next(), 16); | |
6456 | + if (!isFinite(t)) { | |
6457 | + break outer; | |
6458 | + } | |
6459 | + u = u * 16 + t; | |
6460 | + } | |
6461 | + s += String.fromCharCode(u); | |
6462 | + break; | |
6463 | + default: | |
6464 | + s += ch; | |
6465 | + } | |
6466 | + } else { | |
6467 | + s += ch; | |
6468 | + } | |
6469 | + } | |
6470 | + } | |
6471 | + error("Bad string"); | |
6472 | + } | |
6473 | + | |
6474 | + function arr() { | |
6475 | + var a = []; | |
6476 | + | |
6477 | + if (ch == '[') { | |
6478 | + next(); | |
6479 | + white(); | |
6480 | + if (ch == ']') { | |
6481 | + next(); | |
6482 | + return a; | |
6483 | + } | |
6484 | + while (ch) { | |
6485 | + a.push(val()); | |
6486 | + white(); | |
6487 | + if (ch == ']') { | |
6488 | + next(); | |
6489 | + return a; | |
6490 | + } else if (ch != ',') { | |
6491 | + break; | |
6492 | + } | |
6493 | + next(); | |
6494 | + white(); | |
6495 | + } | |
6496 | + } | |
6497 | + error("Bad array"); | |
6498 | + } | |
6499 | + | |
6500 | + function obj() { | |
6501 | + var k, o = {}; | |
6502 | + | |
6503 | + if (ch == '{') { | |
6504 | + next(); | |
6505 | + white(); | |
6506 | + if (ch == '}') { | |
6507 | + next(); | |
6508 | + return o; | |
6509 | + } | |
6510 | + while (ch) { | |
6511 | + k = str(); | |
6512 | + white(); | |
6513 | + if (ch != ':') { | |
6514 | + break; | |
6515 | + } | |
6516 | + next(); | |
6517 | + o[k] = val(); | |
6518 | + white(); | |
6519 | + if (ch == '}') { | |
6520 | + next(); | |
6521 | + return o; | |
6522 | + } else if (ch != ',') { | |
6523 | + break; | |
6524 | + } | |
6525 | + next(); | |
6526 | + white(); | |
6527 | + } | |
6528 | + } | |
6529 | + error("Bad object"); | |
6530 | + } | |
6531 | + | |
6532 | + function assoc() { | |
6533 | + var k, a = []; | |
6534 | + | |
6535 | + if (ch == '<') { | |
6536 | + next(); | |
6537 | + white(); | |
6538 | + if (ch == '>') { | |
6539 | + next(); | |
6540 | + return a; | |
6541 | + } | |
6542 | + while (ch) { | |
6543 | + k = str(); | |
6544 | + white(); | |
6545 | + if (ch != ':') { | |
6546 | + break; | |
6547 | + } | |
6548 | + next(); | |
6549 | + a[k] = val(); | |
6550 | + white(); | |
6551 | + if (ch == '>') { | |
6552 | + next(); | |
6553 | + return a; | |
6554 | + } else if (ch != ',') { | |
6555 | + break; | |
6556 | + } | |
6557 | + next(); | |
6558 | + white(); | |
6559 | + } | |
6560 | + } | |
6561 | + error("Bad associative array"); | |
6562 | + } | |
6563 | + | |
6564 | + function num() { | |
6565 | + var n = '', v; | |
6566 | + if (ch == '-') { | |
6567 | + n = '-'; | |
6568 | + next(); | |
6569 | + } | |
6570 | + while (ch >= '0' && ch <= '9') { | |
6571 | + n += ch; | |
6572 | + next(); | |
6573 | + } | |
6574 | + if (ch == '.') { | |
6575 | + n += '.'; | |
6576 | + while (next() && ch >= '0' && ch <= '9') { | |
6577 | + n += ch; | |
6578 | + } | |
6579 | + } | |
6580 | + if (ch == 'e' || ch == 'E') { | |
6581 | + n += 'e'; | |
6582 | + next(); | |
6583 | + if (ch == '-' || ch == '+') { | |
6584 | + n += ch; | |
6585 | + next(); | |
6586 | + } | |
6587 | + while (ch >= '0' && ch <= '9') { | |
6588 | + n += ch; | |
6589 | + next(); | |
6590 | + } | |
6591 | + } | |
6592 | + v = +n; | |
6593 | + if (!isFinite(v)) { | |
6594 | + error("Bad number"); | |
6595 | + } else { | |
6596 | + return v; | |
6597 | + } | |
6598 | + } | |
6599 | + | |
6600 | + function word() { | |
6601 | + switch (ch) { | |
6602 | + case 't': | |
6603 | + if (next() == 'r' && next() == 'u' && next() == 'e') { | |
6604 | + next(); | |
6605 | + return true; | |
6606 | + } | |
6607 | + break; | |
6608 | + case 'f': | |
6609 | + if (next() == 'a' && next() == 'l' && next() == 's' && | |
6610 | + next() == 'e') { | |
6611 | + next(); | |
6612 | + return false; | |
6613 | + } | |
6614 | + break; | |
6615 | + case 'n': | |
6616 | + if (next() == 'u' && next() == 'l' && next() == 'l') { | |
6617 | + next(); | |
6618 | + return null; | |
6619 | + } | |
6620 | + break; | |
6621 | + } | |
6622 | + error("Syntax error"); | |
6623 | + } | |
6624 | + | |
6625 | + function val() { | |
6626 | + white(); | |
6627 | + switch (ch) { | |
6628 | + case '{': | |
6629 | + return obj(); | |
6630 | + case '[': | |
6631 | + return arr(); | |
6632 | + case '<': | |
6633 | + return assoc(); | |
6634 | + case '"': | |
6635 | + return str(); | |
6636 | + case '-': | |
6637 | + return num(); | |
6638 | + default: | |
6639 | + return ch >= '0' && ch <= '9' ? num() : word(); | |
6640 | + } | |
6641 | + } | |
6642 | + | |
6643 | + return val(); | |
6644 | + } | |
6645 | +}; | |
6646 | + | |
6647 | + | ... | ... |
ferramentas/i3geo_tudo_compacto.js.php
... | ... | @@ -5180,121 +5180,1470 @@ YAHOO.util.Event.purgeElement(D,true);D.innerHTML="";for(var C in this){if(YAHOO |
5180 | 5180 | this._toggleContainer(false);};YAHOO.widget.AutoComplete.prototype._jumpSelection=function(){if(this._oCurItem){this._selectItem(this._oCurItem);}else{this._toggleContainer(false);}};YAHOO.widget.AutoComplete.prototype._moveSelection=function(G){if(this._bContainerOpen){var E=this._oCurItem;var F=-1;if(E){F=E._nItemIndex;}var D=(G==40)?(F+1):(F-1);if(D<-2||D>=this._nDisplayedItems){return ;}if(E){this._toggleHighlight(E,"from");this.itemArrowFromEvent.fire(this,E);}if(D==-1){if(this.delimChar&&this._sSavedQuery){if(!this._textMatchesOption()){this._elTextbox.value=this._sSavedQuery;}else{this._elTextbox.value=this._sSavedQuery+this._sCurQuery;}}else{this._elTextbox.value=this._sCurQuery;}this._oCurItem=null;return ;}if(D==-2){this._toggleContainer(false);return ;}var C=this._aListItems[D];var A=this._elContent;var B=((YAHOO.util.Dom.getStyle(A,"overflow")=="auto")||(YAHOO.util.Dom.getStyle(A,"overflowY")=="auto"));if(B&&(D>-1)&&(D<this._nDisplayedItems)){if(G==40){if((C.offsetTop+C.offsetHeight)>(A.scrollTop+A.offsetHeight)){A.scrollTop=(C.offsetTop+C.offsetHeight)-A.offsetHeight;}else{if((C.offsetTop+C.offsetHeight)<A.scrollTop){A.scrollTop=C.offsetTop;}}}else{if(C.offsetTop<A.scrollTop){this._elContent.scrollTop=C.offsetTop;}else{if(C.offsetTop>(A.scrollTop+A.offsetHeight)){this._elContent.scrollTop=(C.offsetTop+C.offsetHeight)-A.offsetHeight;}}}}this._toggleHighlight(C,"to");this.itemArrowToEvent.fire(this,C);if(this.typeAhead){this._updateValue(C);}}};YAHOO.widget.AutoComplete.prototype._onItemMouseover=function(A,B){if(B.prehighlightClassName){B._togglePrehighlight(this,"mouseover");}else{B._toggleHighlight(this,"to");}B.itemMouseOverEvent.fire(B,this);};YAHOO.widget.AutoComplete.prototype._onItemMouseout=function(A,B){if(B.prehighlightClassName){B._togglePrehighlight(this,"mouseout");}else{B._toggleHighlight(this,"from");}B.itemMouseOutEvent.fire(B,this);};YAHOO.widget.AutoComplete.prototype._onItemMouseclick=function(A,B){B._toggleHighlight(this,"to");B._selectItem(this);};YAHOO.widget.AutoComplete.prototype._onContainerMouseover=function(A,B){B._bOverContainer=true;};YAHOO.widget.AutoComplete.prototype._onContainerMouseout=function(A,B){B._bOverContainer=false;if(B._oCurItem){B._toggleHighlight(B._oCurItem,"to");}};YAHOO.widget.AutoComplete.prototype._onContainerScroll=function(A,B){B._elTextbox.focus();};YAHOO.widget.AutoComplete.prototype._onContainerResize=function(A,B){B._toggleContainerHelpers(B._bContainerOpen);};YAHOO.widget.AutoComplete.prototype._onTextboxKeyDown=function(A,B){var C=A.keyCode;switch(C){case 9:if((navigator.userAgent.toLowerCase().indexOf("mac")==-1)){if(B._oCurItem){if(B.delimChar&&(B._nKeyCode!=C)){if(B._bContainerOpen){YAHOO.util.Event.stopEvent(A);}}B._selectItem(B._oCurItem);}else{B._toggleContainer(false);}}break;case 13:if((navigator.userAgent.toLowerCase().indexOf("mac")==-1)){if(B._oCurItem){if(B._nKeyCode!=C){if(B._bContainerOpen){YAHOO.util.Event.stopEvent(A);}}B._selectItem(B._oCurItem);}else{B._toggleContainer(false);}}break;case 27:B._toggleContainer(false);return ;case 39:B._jumpSelection();break;case 38:YAHOO.util.Event.stopEvent(A);B._moveSelection(C);break;case 40:YAHOO.util.Event.stopEvent(A);B._moveSelection(C);break;default:break;}};YAHOO.widget.AutoComplete.prototype._onTextboxKeyPress=function(A,B){var C=A.keyCode;if((navigator.userAgent.toLowerCase().indexOf("mac")!=-1)){switch(C){case 9:if(B._oCurItem){if(B.delimChar&&(B._nKeyCode!=C)){if(B._bContainerOpen){YAHOO.util.Event.stopEvent(A);}}B._selectItem(B._oCurItem);}else{B._toggleContainer(false);}break;case 13:if(B._oCurItem){if(B._nKeyCode!=C){if(B._bContainerOpen){YAHOO.util.Event.stopEvent(A);}}B._selectItem(B._oCurItem);}else{B._toggleContainer(false);}break;default:break;}}else{if(C==229){B._queryInterval=setInterval(function(){B._onIMEDetected(B);},500);}}};YAHOO.widget.AutoComplete.prototype._onTextboxKeyUp=function(B,D){D._initProps();var E=B.keyCode;D._nKeyCode=E;var C=this.value;if(D._isIgnoreKey(E)||(C.toLowerCase()==D._sCurQuery)){return ;}else{D._bItemSelected=false;YAHOO.util.Dom.removeClass(D._oCurItem,D.highlightClassName);D._oCurItem=null;D.textboxKeyEvent.fire(D,E);}if(D.queryDelay>0){var A=setTimeout(function(){D._sendQuery(C);},(D.queryDelay*1000));if(D._nDelayID!=-1){clearTimeout(D._nDelayID);}D._nDelayID=A;}else{D._sendQuery(C);}};YAHOO.widget.AutoComplete.prototype._onTextboxFocus=function(A,B){B._elTextbox.setAttribute("autocomplete","off");B._bFocused=true;if(!B._bItemSelected){B.textboxFocusEvent.fire(B);}};YAHOO.widget.AutoComplete.prototype._onTextboxBlur=function(A,B){if(!B._bOverContainer||(B._nKeyCode==9)){if(!B._bItemSelected){var C=B._textMatchesOption();if(!B._bContainerOpen||(B._bContainerOpen&&(C===null))){if(B.forceSelection){B._clearSelection();}else{B.unmatchedItemSelectEvent.fire(B);}}else{if(B.forceSelection){B._selectItem(C);}}}if(B._bContainerOpen){B._toggleContainer(false);}B._cancelIntervalDetection(B);B._bFocused=false;B.textboxBlurEvent.fire(B);}};YAHOO.widget.AutoComplete.prototype._onWindowUnload=function(A,B){if(B&&B._elTextbox&&B.allowBrowserAutocomplete){B._elTextbox.setAttribute("autocomplete","on");}};YAHOO.widget.DataSource=function(){};YAHOO.widget.DataSource.ERROR_DATANULL="Response data was null";YAHOO.widget.DataSource.ERROR_DATAPARSE="Response data could not be parsed";YAHOO.widget.DataSource.prototype.maxCacheEntries=15;YAHOO.widget.DataSource.prototype.queryMatchContains=false;YAHOO.widget.DataSource.prototype.queryMatchSubset=false;YAHOO.widget.DataSource.prototype.queryMatchCase=false;YAHOO.widget.DataSource.prototype.toString=function(){return"DataSource "+this._sName;};YAHOO.widget.DataSource.prototype.getResults=function(A,D,B){var C=this._doQueryCache(A,D,B);if(C.length===0){this.queryEvent.fire(this,B,D);this.doQuery(A,D,B);}};YAHOO.widget.DataSource.prototype.doQuery=function(A,C,B){};YAHOO.widget.DataSource.prototype.flushCache=function(){if(this._aCache){this._aCache=[];}if(this._aCacheHelper){this._aCacheHelper=[]; |
5181 | 5181 | }this.cacheFlushEvent.fire(this);};YAHOO.widget.DataSource.prototype.queryEvent=null;YAHOO.widget.DataSource.prototype.cacheQueryEvent=null;YAHOO.widget.DataSource.prototype.getResultsEvent=null;YAHOO.widget.DataSource.prototype.getCachedResultsEvent=null;YAHOO.widget.DataSource.prototype.dataErrorEvent=null;YAHOO.widget.DataSource.prototype.cacheFlushEvent=null;YAHOO.widget.DataSource._nIndex=0;YAHOO.widget.DataSource.prototype._sName=null;YAHOO.widget.DataSource.prototype._aCache=null;YAHOO.widget.DataSource.prototype._init=function(){var A=this.maxCacheEntries;if(!YAHOO.lang.isNumber(A)||(A<0)){A=0;}if(A>0&&!this._aCache){this._aCache=[];}this._sName="instance"+YAHOO.widget.DataSource._nIndex;YAHOO.widget.DataSource._nIndex++;this.queryEvent=new YAHOO.util.CustomEvent("query",this);this.cacheQueryEvent=new YAHOO.util.CustomEvent("cacheQuery",this);this.getResultsEvent=new YAHOO.util.CustomEvent("getResults",this);this.getCachedResultsEvent=new YAHOO.util.CustomEvent("getCachedResults",this);this.dataErrorEvent=new YAHOO.util.CustomEvent("dataError",this);this.cacheFlushEvent=new YAHOO.util.CustomEvent("cacheFlush",this);};YAHOO.widget.DataSource.prototype._addCacheElem=function(B){var A=this._aCache;if(!A||!B||!B.query||!B.results){return ;}if(A.length>=this.maxCacheEntries){A.shift();}A.push(B);};YAHOO.widget.DataSource.prototype._doQueryCache=function(A,I,N){var H=[];var G=false;var J=this._aCache;var F=(J)?J.length:0;var K=this.queryMatchContains;var D;if((this.maxCacheEntries>0)&&J&&(F>0)){this.cacheQueryEvent.fire(this,N,I);if(!this.queryMatchCase){D=I;I=I.toLowerCase();}for(var P=F-1;P>=0;P--){var E=J[P];var B=E.results;var C=(!this.queryMatchCase)?encodeURIComponent(E.query).toLowerCase():encodeURIComponent(E.query);if(C==I){G=true;H=B;if(P!=F-1){J.splice(P,1);this._addCacheElem(E);}break;}else{if(this.queryMatchSubset){for(var O=I.length-1;O>=0;O--){var R=I.substr(0,O);if(C==R){G=true;for(var M=B.length-1;M>=0;M--){var Q=B[M];var L=(this.queryMatchCase)?encodeURIComponent(Q[0]).indexOf(I):encodeURIComponent(Q[0]).toLowerCase().indexOf(I);if((!K&&(L===0))||(K&&(L>-1))){H.unshift(Q);}}E={};E.query=I;E.results=H;this._addCacheElem(E);break;}}if(G){break;}}}}if(G){this.getCachedResultsEvent.fire(this,N,D,H);A(D,H,N);}}return H;};YAHOO.widget.DS_XHR=function(C,A,D){if(D&&(D.constructor==Object)){for(var B in D){this[B]=D[B];}}if(!YAHOO.lang.isArray(A)||!YAHOO.lang.isString(C)){return ;}this.schema=A;this.scriptURI=C;this._init();};YAHOO.widget.DS_XHR.prototype=new YAHOO.widget.DataSource();YAHOO.widget.DS_XHR.TYPE_JSON=0;YAHOO.widget.DS_XHR.TYPE_XML=1;YAHOO.widget.DS_XHR.TYPE_FLAT=2;YAHOO.widget.DS_XHR.ERROR_DATAXHR="XHR response failed";YAHOO.widget.DS_XHR.prototype.connMgr=YAHOO.util.Connect;YAHOO.widget.DS_XHR.prototype.connTimeout=0;YAHOO.widget.DS_XHR.prototype.scriptURI=null;YAHOO.widget.DS_XHR.prototype.scriptQueryParam="query";YAHOO.widget.DS_XHR.prototype.scriptQueryAppend="";YAHOO.widget.DS_XHR.prototype.responseType=YAHOO.widget.DS_XHR.TYPE_JSON;YAHOO.widget.DS_XHR.prototype.responseStripAfter="\n<!-";YAHOO.widget.DS_XHR.prototype.doQuery=function(E,G,B){var J=(this.responseType==YAHOO.widget.DS_XHR.TYPE_XML);var D=this.scriptURI+"?"+this.scriptQueryParam+"="+G;if(this.scriptQueryAppend.length>0){D+="&"+this.scriptQueryAppend;}var C=null;var F=this;var I=function(K){if(!F._oConn||(K.tId!=F._oConn.tId)){F.dataErrorEvent.fire(F,B,G,YAHOO.widget.DataSource.ERROR_DATANULL);return ;}for(var N in K){}if(!J){K=K.responseText;}else{K=K.responseXML;}if(K===null){F.dataErrorEvent.fire(F,B,G,YAHOO.widget.DataSource.ERROR_DATANULL);return ;}var M=F.parseResponse(G,K,B);var L={};L.query=decodeURIComponent(G);L.results=M;if(M===null){F.dataErrorEvent.fire(F,B,G,YAHOO.widget.DataSource.ERROR_DATAPARSE);M=[];}else{F.getResultsEvent.fire(F,B,G,M);F._addCacheElem(L);}E(G,M,B);};var A=function(K){F.dataErrorEvent.fire(F,B,G,YAHOO.widget.DS_XHR.ERROR_DATAXHR);return ;};var H={success:I,failure:A};if(YAHOO.lang.isNumber(this.connTimeout)&&(this.connTimeout>0)){H.timeout=this.connTimeout;}if(this._oConn){this.connMgr.abort(this._oConn);}F._oConn=this.connMgr.asyncRequest("GET",D,H,null);};YAHOO.widget.DS_XHR.prototype.parseResponse=function(sQuery,oResponse,oParent){var aSchema=this.schema;var aResults=[];var bError=false;var nEnd=((this.responseStripAfter!=="")&&(oResponse.indexOf))?oResponse.indexOf(this.responseStripAfter):-1;if(nEnd!=-1){oResponse=oResponse.substring(0,nEnd);}switch(this.responseType){case YAHOO.widget.DS_XHR.TYPE_JSON:var jsonList,jsonObjParsed;if(YAHOO.lang.JSON){jsonObjParsed=YAHOO.lang.JSON.parse(oResponse);if(!jsonObjParsed){bError=true;break;}else{try{jsonList=eval("jsonObjParsed."+aSchema[0]);}catch(e){bError=true;break;}}}else{if(oResponse.parseJSON){jsonObjParsed=oResponse.parseJSON();if(!jsonObjParsed){bError=true;}else{try{jsonList=eval("jsonObjParsed."+aSchema[0]);}catch(e){bError=true;break;}}}else{if(window.JSON){jsonObjParsed=JSON.parse(oResponse);if(!jsonObjParsed){bError=true;break;}else{try{jsonList=eval("jsonObjParsed."+aSchema[0]);}catch(e){bError=true;break;}}}else{try{while(oResponse.substring(0,1)==" "){oResponse=oResponse.substring(1,oResponse.length);}if(oResponse.indexOf("{")<0){bError=true;break;}if(oResponse.indexOf("{}")===0){break;}var jsonObjRaw=eval("("+oResponse+")");if(!jsonObjRaw){bError=true;break;}jsonList=eval("(jsonObjRaw."+aSchema[0]+")");}catch(e){bError=true;break;}}}}if(!jsonList){bError=true;break;}if(!YAHOO.lang.isArray(jsonList)){jsonList=[jsonList];}for(var i=jsonList.length-1;i>=0;i--){var aResultItem=[];var jsonResult=jsonList[i];for(var j=aSchema.length-1;j>=1;j--){var dataFieldValue=jsonResult[aSchema[j]];if(!dataFieldValue){dataFieldValue="";}aResultItem.unshift(dataFieldValue);}if(aResultItem.length==1){aResultItem.push(jsonResult);}aResults.unshift(aResultItem);}break;case YAHOO.widget.DS_XHR.TYPE_XML:var xmlList=oResponse.getElementsByTagName(aSchema[0]);if(!xmlList){bError=true;break;}for(var k=xmlList.length-1;k>=0;k--){var result=xmlList.item(k); |
5182 | 5182 | var aFieldSet=[];for(var m=aSchema.length-1;m>=1;m--){var sValue=null;var xmlAttr=result.attributes.getNamedItem(aSchema[m]);if(xmlAttr){sValue=xmlAttr.value;}else{var xmlNode=result.getElementsByTagName(aSchema[m]);if(xmlNode&&xmlNode.item(0)&&xmlNode.item(0).firstChild){sValue=xmlNode.item(0).firstChild.nodeValue;}else{sValue="";}}aFieldSet.unshift(sValue);}aResults.unshift(aFieldSet);}break;case YAHOO.widget.DS_XHR.TYPE_FLAT:if(oResponse.length>0){var newLength=oResponse.length-aSchema[0].length;if(oResponse.substr(newLength)==aSchema[0]){oResponse=oResponse.substr(0,newLength);}if(oResponse.length>0){var aRecords=oResponse.split(aSchema[0]);for(var n=aRecords.length-1;n>=0;n--){if(aRecords[n].length>0){aResults[n]=aRecords[n].split(aSchema[1]);}}}}break;default:break;}sQuery=null;oResponse=null;oParent=null;if(bError){return null;}else{return aResults;}};YAHOO.widget.DS_XHR.prototype._oConn=null;YAHOO.widget.DS_ScriptNode=function(D,A,C){if(C&&(C.constructor==Object)){for(var B in C){this[B]=C[B];}}if(!YAHOO.lang.isArray(A)||!YAHOO.lang.isString(D)){return ;}this.schema=A;this.scriptURI=D;this._init();};YAHOO.widget.DS_ScriptNode.prototype=new YAHOO.widget.DataSource();YAHOO.widget.DS_ScriptNode.prototype.getUtility=YAHOO.util.Get;YAHOO.widget.DS_ScriptNode.prototype.scriptURI=null;YAHOO.widget.DS_ScriptNode.prototype.scriptQueryParam="query";YAHOO.widget.DS_ScriptNode.prototype.asyncMode="allowAll";YAHOO.widget.DS_ScriptNode.prototype.scriptCallbackParam="callback";YAHOO.widget.DS_ScriptNode.callbacks=[];YAHOO.widget.DS_ScriptNode._nId=0;YAHOO.widget.DS_ScriptNode._nPending=0;YAHOO.widget.DS_ScriptNode.prototype.doQuery=function(A,F,C){var B=this;if(YAHOO.widget.DS_ScriptNode._nPending===0){YAHOO.widget.DS_ScriptNode.callbacks=[];YAHOO.widget.DS_ScriptNode._nId=0;}var E=YAHOO.widget.DS_ScriptNode._nId;YAHOO.widget.DS_ScriptNode._nId++;YAHOO.widget.DS_ScriptNode.callbacks[E]=function(G){if((B.asyncMode!=="ignoreStaleResponses")||(E===YAHOO.widget.DS_ScriptNode.callbacks.length-1)){B.handleResponse(G,A,F,C);}else{}delete YAHOO.widget.DS_ScriptNode.callbacks[E];};YAHOO.widget.DS_ScriptNode._nPending++;var D=this.scriptURI+"&"+this.scriptQueryParam+"="+F+"&"+this.scriptCallbackParam+"=YAHOO.widget.DS_ScriptNode.callbacks["+E+"]";this.getUtility.script(D,{autopurge:true,onsuccess:YAHOO.widget.DS_ScriptNode._bumpPendingDown,onfail:YAHOO.widget.DS_ScriptNode._bumpPendingDown});};YAHOO.widget.DS_ScriptNode.prototype.handleResponse=function(oResponse,oCallbackFn,sQuery,oParent){var aSchema=this.schema;var aResults=[];var bError=false;var jsonList,jsonObjParsed;try{jsonList=eval("(oResponse."+aSchema[0]+")");}catch(e){bError=true;}if(!jsonList){bError=true;jsonList=[];}else{if(!YAHOO.lang.isArray(jsonList)){jsonList=[jsonList];}}for(var i=jsonList.length-1;i>=0;i--){var aResultItem=[];var jsonResult=jsonList[i];for(var j=aSchema.length-1;j>=1;j--){var dataFieldValue=jsonResult[aSchema[j]];if(!dataFieldValue){dataFieldValue="";}aResultItem.unshift(dataFieldValue);}if(aResultItem.length==1){aResultItem.push(jsonResult);}aResults.unshift(aResultItem);}if(bError){aResults=null;}if(aResults===null){this.dataErrorEvent.fire(this,oParent,sQuery,YAHOO.widget.DataSource.ERROR_DATAPARSE);aResults=[];}else{var resultObj={};resultObj.query=decodeURIComponent(sQuery);resultObj.results=aResults;this._addCacheElem(resultObj);this.getResultsEvent.fire(this,oParent,sQuery,aResults);}oCallbackFn(sQuery,aResults,oParent);};YAHOO.widget.DS_ScriptNode._bumpPendingDown=function(){YAHOO.widget.DS_ScriptNode._nPending--;};YAHOO.widget.DS_JSFunction=function(A,C){if(C&&(C.constructor==Object)){for(var B in C){this[B]=C[B];}}if(!YAHOO.lang.isFunction(A)){return ;}else{this.dataFunction=A;this._init();}};YAHOO.widget.DS_JSFunction.prototype=new YAHOO.widget.DataSource();YAHOO.widget.DS_JSFunction.prototype.dataFunction=null;YAHOO.widget.DS_JSFunction.prototype.doQuery=function(C,F,D){var B=this.dataFunction;var E=[];E=B(F);if(E===null){this.dataErrorEvent.fire(this,D,F,YAHOO.widget.DataSource.ERROR_DATANULL);return ;}var A={};A.query=decodeURIComponent(F);A.results=E;this._addCacheElem(A);this.getResultsEvent.fire(this,D,F,E);C(F,E,D);return ;};YAHOO.widget.DS_JSArray=function(A,C){if(C&&(C.constructor==Object)){for(var B in C){this[B]=C[B];}}if(!YAHOO.lang.isArray(A)){return ;}else{this.data=A;this._init();}};YAHOO.widget.DS_JSArray.prototype=new YAHOO.widget.DataSource();YAHOO.widget.DS_JSArray.prototype.data=null;YAHOO.widget.DS_JSArray.prototype.doQuery=function(E,I,A){var F;var C=this.data;var J=[];var D=false;var B=this.queryMatchContains;if(I){if(!this.queryMatchCase){I=I.toLowerCase();}for(F=C.length-1;F>=0;F--){var H=[];if(YAHOO.lang.isString(C[F])){H[0]=C[F];}else{if(YAHOO.lang.isArray(C[F])){H=C[F];}}if(YAHOO.lang.isString(H[0])){var G=(this.queryMatchCase)?encodeURIComponent(H[0]).indexOf(I):encodeURIComponent(H[0]).toLowerCase().indexOf(I);if((!B&&(G===0))||(B&&(G>-1))){J.unshift(H);}}}}else{for(F=C.length-1;F>=0;F--){if(YAHOO.lang.isString(C[F])){J.unshift([C[F]]);}else{if(YAHOO.lang.isArray(C[F])){J.unshift(C[F]);}}}}this.getResultsEvent.fire(this,A,I,J);E(I,J,A);};YAHOO.register("autocomplete",YAHOO.widget.AutoComplete,{version:"2.5.2",build:"1076"}); |
5183 | -function cpaint(){this.version='2.0.3';var config=new Array();config['debugging']=-1;config['proxy_url']='';config['transfer_mode']='GET';config['async']=true;config['response_type']='OBJECT';config['persistent_connection']=false;config['use_cpaint_api']=true;var stack_count=0;this.capable=test_ajax_capability();this.set_debug=function(){if(typeof arguments[0]=='boolean'){if(arguments[0]===true){config['debugging']=1;}else{config['debugging']=0;}}else if(typeof arguments[0]=='number'){config['debugging']=Math.round(arguments[0]);}} | |
5184 | -this.set_proxy_url=function(){if(typeof arguments[0]=='string'){config['proxy_url']=arguments[0];}} | |
5185 | -this.set_transfer_mode=function(){if(arguments[0].toUpperCase()=='GET'||arguments[0].toUpperCase()=='POST'){config['transfer_mode']=arguments[0].toUpperCase();}} | |
5186 | -this.set_async=function(){if(typeof arguments[0]=='boolean'){config['async']=arguments[0];}} | |
5187 | -this.set_response_type=function(){if(arguments[0].toUpperCase()=='TEXT'||arguments[0].toUpperCase()=='XML'||arguments[0].toUpperCase()=='OBJECT'||arguments[0].toUpperCase()=='E4X'||arguments[0].toUpperCase()=='JSON'){config['response_type']=arguments[0].toUpperCase();}} | |
5188 | -this.set_persistent_connection=function(){if(typeof arguments[0]=='boolean'){config['persistent_connection']=arguments[0];}} | |
5189 | -this.set_use_cpaint_api=function(){if(typeof arguments[0]=='boolean'){config['use_cpaint_api']=arguments[0];}} | |
5190 | -function test_ajax_capability(){var cpc=new cpaint_call(0,config,this.version);return cpc.test_ajax_capability();} | |
5191 | -this.call=function(){var use_stack=-1;if(config['persistent_connection']==true&&__cpaint_stack[0]!=null){switch(__cpaint_stack[0].get_http_state()){case-1:use_stack=0;debug('no XMLHttpObject object to re-use for persistence, creating new one later',2);break;case 4:use_stack=0 | |
5192 | -debug('re-using the persistent connection',2);break;default:debug('the persistent connection is in use - skipping this request',2);}}else if(config['persistent_connection']==true){use_stack=0;__cpaint_stack[use_stack]=new cpaint_call(use_stack,config,this.version);debug('no cpaint_call object available for re-use, created new one',2);}else{use_stack=stack_count;__cpaint_stack[use_stack]=new cpaint_call(use_stack,config,this.version);debug('no cpaint_call object created new one',2);} | |
5193 | -if(use_stack!=-1){__cpaint_stack[use_stack].set_client_callback(arguments[2]);if(config['proxy_url']!=''){__cpaint_stack[use_stack].call_proxy(arguments);}else{__cpaint_stack[use_stack].call_direct(arguments);} | |
5194 | -stack_count++;debug('stack size: '+__cpaint_stack.length,2);}} | |
5195 | -var debug=function(message,debug_level){var prefix='[CPAINT Debug] ';if(debug_level<1){prefix='[CPAINT Error] ';} | |
5196 | -if(config['debugging']>=debug_level){alert(prefix+message);}if (message.search("error") > 1){client_callback("", message);}}} | |
5197 | -var __cpaint_stack=new Array();var __cpaint_transformer=new cpaint_transformer();function cpaint_call(){var version=arguments[2];var config=new Array();config['debugging']=arguments[1]['debugging'];config['proxy_url']=arguments[1]['proxy_url'];config['transfer_mode']=arguments[1]['transfer_mode'];config['async']=arguments[1]['async'];config['response_type']=arguments[1]['response_type'];config['persistent_connection']=arguments[1]['persistent_connection'];config['use_cpaint_api']=arguments[1]['use_cpaint_api'];var httpobj=false;var client_callback;var stack_id=arguments[0];this.set_client_callback=function(){if(typeof arguments[0]=='function'){client_callback=arguments[0];}} | |
5198 | -this.get_http_state=function(){var return_value=-1;if(typeof httpobj=='object'){return_value=httpobj.readyState;} | |
5199 | -return return_value;} | |
5200 | -this.call_direct=function(call_arguments){var url=call_arguments[0];var remote_method=call_arguments[1];var querystring='';var i=0;if(url=='SELF'){url=document.location.href;} | |
5201 | -if(config['use_cpaint_api']==true){for(i=3;i<call_arguments.length;i++){if((typeof call_arguments[i]=='string'&&call_arguments[i]!=''&&call_arguments[i].search(/^\s+$/g)==-1)&&!isNaN(call_arguments[i])&&isFinite(call_arguments[i])){querystring+='&cpaint_argument[]='+encodeURIComponent(JSON.stringify(Number(call_arguments[i])));}else{querystring+='&cpaint_argument[]='+encodeURIComponent(JSON.stringify(call_arguments[i]));}} | |
5202 | -querystring+='&cpaint_response_type='+config['response_type'];if(config['transfer_mode']=='GET'){if(url.indexOf('?')!=-1){url=url+'&cpaint_function='+remote_method+querystring;}else{url=url+'?cpaint_function='+remote_method+querystring;}}else{querystring='cpaint_function='+remote_method+querystring;}}else{for(i=3;i<call_arguments.length;i++){if(i==3){querystring+=encodeURIComponent(call_arguments[i]);}else{querystring+='&'+encodeURIComponent(call_arguments[i]);}} | |
5203 | -if(config['transfer_mode']=='GET'){url=url+querystring;}} | |
5204 | -get_connection_object();debug('opening connection to "'+url+'"',1);httpobj.open(config['transfer_mode'],url,config['async']);if(config['transfer_mode']=='POST'){try{httpobj.setRequestHeader('Content-Type','application/x-www-form-urlencoded');}catch(cp_err){debug('POST cannot be completed due to incompatible browser. Use GET as your request method.',0);}} | |
5205 | -httpobj.setRequestHeader('X-Powered-By','CPAINT v'+version+' :: http://sf.net/projects/cpaint');httpobj.onreadystatechange=callback;if(config['transfer_mode']=='GET'){httpobj.send(null);}else{debug('sending query: '+querystring,1);httpobj.send(querystring);} | |
5206 | -if(config['async']==true){callback();}} | |
5207 | -this.call_proxy=function(call_arguments){var proxyscript=config['proxy_url'];var url=call_arguments[0];var remote_method=call_arguments[1];var querystring='';var i=0;var querystring_argument_prefix='cpaint_argument[]=';if(config['use_cpaint_api']==false){querystring_argument_prefix='';} | |
5208 | -for(i=3;i<call_arguments.length;i++){if(config['use_cpaint_api']==true){if((typeof call_arguments[i]=='string'&&call_arguments[i]!=''&&call_arguments[i].search(/^\s+$/g)==-1)&&!isNaN(call_arguments[i])&&isFinite(call_arguments[i])){querystring+=encodeURIComponent(querystring_argument_prefix+JSON.stringify(Number(call_arguments[i]))+'&');}else{querystring+=encodeURIComponent(querystring_argument_prefix+JSON.stringify(call_arguments[i])+'&');}}else{querystring+=encodeURIComponent(querystring_argument_prefix+call_arguments[i]+'&');}} | |
5209 | -if(config['use_cpaint_api']==true){querystring+=encodeURIComponent('&cpaint_function='+remote_method);querystring+=encodeURIComponent('&cpaint_responsetype='+config['response_type']);} | |
5210 | -if(config['transfer_mode']=='GET'){proxyscript+='?cpaint_remote_url='+encodeURIComponent(url) | |
5211 | -+'&cpaint_remote_query='+querystring | |
5212 | -+'&cpaint_remote_method='+config['transfer_mode'] | |
5213 | -+'&cpaint_response_type='+config['response_type'];}else{querystring='cpaint_remote_url='+encodeURIComponent(url) | |
5214 | -+'&cpaint_remote_query='+querystring | |
5215 | -+'&cpaint_remote_method='+config['transfer_mode'] | |
5216 | -+'&cpaint_response_type='+config['response_type'];} | |
5217 | -get_connection_object();debug('opening connection to proxy "'+proxyscript+'"',1);httpobj.open(config['transfer_mode'],proxyscript,config['async']);if(config['transfer_mode']=='POST'){try{httpobj.setRequestHeader('Content-Type','application/x-www-form-urlencoded');}catch(cp_err){debug('POST cannot be completed due to incompatible browser. Use GET as your request method.',0);}} | |
5218 | -httpobj.setRequestHeader('X-Powered-By','CPAINT v'+version);httpobj.onreadystatechange=callback;if(config['transfer_mode']=='GET'){httpobj.send(null);}else{debug('sending query: '+querystring,1);httpobj.send(querystring);} | |
5219 | -if(config['async']==false){callback();}} | |
5220 | -this.test_ajax_capability=function(){return get_connection_object();} | |
5221 | -var get_connection_object=function(){var return_value=false;var new_connection=false;if(config['persistent_connection']==false){debug('Using new connection object',1);new_connection=true;}else{debug('Using shared connection object.',1);if(typeof httpobj!='object'){debug('Getting new persistent connection object.',1);new_connection=true;}} | |
5222 | -if(new_connection==true){try{httpobj=new XMLHttpRequest();}catch(e1){try{httpobj=new ActiveXObject('Msxml2.XMLHTTP');}catch(e){try{httpobj=new ActiveXObject('Microsoft.XMLHTTP');}catch(oc){httpobj=null;}}} | |
5223 | -if(!httpobj){debug('Could not create connection object',0);}else{return_value=true;}} | |
5224 | -if(httpobj.readyState!=4){httpobj.abort();} | |
5225 | -return return_value;} | |
5226 | -var callback=function(){var response=null;if(httpobj.readyState==4&&httpobj.status==200){debug(httpobj.responseText,1);debug('using response type '+config['response_type'],2);switch(config['response_type']){case'XML':debug(httpobj.responseXML,2);response=__cpaint_transformer.xml_conversion(httpobj.responseXML);break;case'OBJECT':response=__cpaint_transformer.object_conversion(httpobj.responseXML);break;case'TEXT':response=__cpaint_transformer.text_conversion(httpobj.responseText);break;case'E4X':response=__cpaint_transformer.e4x_conversion(httpobj.responseText);break;case'JSON':response=__cpaint_transformer.json_conversion(httpobj.responseText);break;default:debug('invalid response type \''+response_type+'\'',0);} | |
5227 | -if(response!=null&&typeof client_callback=='function'){client_callback(response,httpobj.responseText);} | |
5228 | -remove_from_stack();}else if(httpobj.readyState==4&&httpobj.status!=200){debug('invalid HTTP response code \''+Number(httpobj.status)+'\'',0);client_callback("", "erro");}} | |
5229 | -var remove_from_stack=function(){if(typeof stack_id=='number'&&__cpaint_stack[stack_id]&&config['persistent_connection']==false){__cpaint_stack[stack_id]=null;}} | |
5230 | -var debug=function(message,debug_level){var prefix='[CPAINT Debug] ';if(config['debugging']<1){prefix='[CPAINT Error] ';if (message.search(" error") > 1){client_callback("", message);}} | |
5231 | -if(config['debugging']>=debug_level){alert(prefix+message);}}} | |
5232 | -function cpaint_transformer(){this.object_conversion=function(xml_document){var return_value=new cpaint_result_object();var i=0;var firstNodeName='';if(typeof xml_document=='object'&&xml_document!=null){for(i=0;i<xml_document.childNodes.length;i++){if(xml_document.childNodes[i].nodeType==1){firstNodeName=xml_document.childNodes[i].nodeName;break;}} | |
5233 | -var ajax_response=xml_document.getElementsByTagName(firstNodeName);return_value[firstNodeName]=new Array();for(i=0;i<ajax_response.length;i++){var tmp_node=create_object_structure(ajax_response[i]);tmp_node.id=ajax_response[i].getAttribute('id') | |
5234 | -return_value[firstNodeName].push(tmp_node);}}else{debug('received invalid XML response',0);} | |
5235 | -return return_value;} | |
5236 | -this.xml_conversion=function(xml_document){return xml_document;} | |
5237 | -this.text_conversion=function(text){return decode(text);} | |
5238 | -this.e4x_conversion=function(text){text=text.replace(/^\<\?xml[^>]+\>/,'');return new XML(text);} | |
5239 | -this.json_conversion=function(text){return JSON.parse(text);} | |
5240 | -var create_object_structure=function(stream){var return_value=new cpaint_result_object();var node_name='';var i=0;var attrib=0;if(stream.hasChildNodes()==true){for(i=0;i<stream.childNodes.length;i++){node_name=stream.childNodes[i].nodeName;node_name=node_name.replace(/[^a-zA-Z0-9_]*/g,'');if(typeof return_value[node_name]!='object'){return_value[node_name]=new Array();} | |
5241 | -if(stream.childNodes[i].nodeType==1){var tmp_node=create_object_structure(stream.childNodes[i]);for(attrib=0;attrib<stream.childNodes[i].attributes.length;attrib++){tmp_node.set_attribute(stream.childNodes[i].attributes[attrib].nodeName,stream.childNodes[i].attributes[attrib].nodeValue);} | |
5242 | -return_value[node_name].push(tmp_node);}else if(stream.childNodes[i].nodeType==3){return_value.data=decode(String(stream.firstChild.data));}}} | |
5243 | -return return_value;} | |
5244 | -var decode=function(rawtext){var plaintext='';var i=0;var c1=0;var c2=0;var c3=0;var u=0;var t=0;while(i<rawtext.length){if(rawtext.charAt(i)=='\\'&&rawtext.charAt(i+1)=='u'){u=0;for(j=2;j<6;j+=1){t=parseInt(rawtext.charAt(i+j),16);if(!isFinite(t)){break;} | |
5245 | -u=u*16+t;} | |
5246 | -plaintext+=String.fromCharCode(u);i+=6;}else{plaintext+=rawtext.charAt(i);i++;}} | |
5247 | -if(plaintext!=''&&plaintext.search(/^\s+$/g)==-1&&!isNaN(plaintext)&&isFinite(plaintext)){plaintext=Number(plaintext);} | |
5248 | -return plaintext;}} | |
5249 | -function cpaint_result_object(){this.id=0;this.data='';var __attributes=new Array();this.find_item_by_id=function(){var return_value=null;var type=arguments[0];var id=arguments[1];var i=0;if(this[type]){for(i=0;i<this[type].length;i++){if(this[type][i].get_attribute('id')==id){return_value=this[type][i];break;}}} | |
5250 | -return return_value;} | |
5251 | -this.get_attribute=function(){var return_value=null;var id=arguments[0];if(typeof __attributes[id]!='undefined'){return_value=__attributes[id];} | |
5252 | -return return_value;} | |
5253 | -this.set_attribute=function(){__attributes[arguments[0]]=arguments[1];}} | |
5254 | -Array.prototype.______array='______array';var JSON={org:'http://www.JSON.org',copyright:'(c)2005 JSON.org',license:'http://www.crockford.com/JSON/license.html',stringify:function(arg){var c,i,l,s='',v;var numeric=true;switch(typeof arg){case'object':if(arg){if(arg.______array=='______array'){for(i in arg){if(i!='______array'&&(isNaN(i)||!isFinite(i))){numeric=false;break;}} | |
5255 | -if(numeric==true){for(i=0;i<arg.length;++i){if(typeof arg[i]!='undefined'){v=this.stringify(arg[i]);if(s){s+=',';} | |
5256 | -s+=v;}else{s+=',null';}} | |
5257 | -return'['+s+']';}else{for(i in arg){if(i!='______array'){v=arg[i];if(typeof v!='undefined'&&typeof v!='function'){v=this.stringify(v);if(s){s+=',';} | |
5258 | -s+=this.stringify(i)+':'+v;}}} | |
5259 | -return'{'+s+'}';}}else if(typeof arg.toString!='undefined'){for(i in arg){v=arg[i];if(typeof v!='undefined'&&typeof v!='function'){v=this.stringify(v);if(s){s+=',';} | |
5260 | -s+=this.stringify(i)+':'+v;}} | |
5261 | -return'{'+s+'}';}} | |
5262 | -return'null';case'number':return isFinite(arg)?String(arg):'null';case'string':l=arg.length;s='"';for(i=0;i<l;i+=1){c=arg.charAt(i);if(c>=' '){if(c=='\\'||c=='"'){s+='\\';} | |
5263 | -s+=c;}else{switch(c){case'\b':s+='\\b';break;case'\f':s+='\\f';break;case'\n':s+='\\n';break;case'\r':s+='\\r';break;case'\t':s+='\\t';break;default:c=c.charCodeAt();s+='\\u00'+Math.floor(c/16).toString(16)+ | |
5264 | -(c%16).toString(16);}}} | |
5265 | -return s+'"';case'boolean':return String(arg);default:return'null';}},parse:function(text){var at=0;var ch=' ';function error(m){throw{name:'JSONError',message:m,at:at-1,text:text};} | |
5266 | -function next(){ch=text.charAt(at);at+=1;return ch;} | |
5267 | -function white(){while(ch!=''&&ch<=' '){next();}} | |
5268 | -function str(){var i,s='',t,u;if(ch=='"'){outer:while(next()){if(ch=='"'){next();return s;}else if(ch=='\\'){switch(next()){case'b':s+='\b';break;case'f':s+='\f';break;case'n':s+='\n';break;case'r':s+='\r';break;case't':s+='\t';break;case'u':u=0;for(i=0;i<4;i+=1){t=parseInt(next(),16);if(!isFinite(t)){break outer;} | |
5269 | -u=u*16+t;} | |
5270 | -s+=String.fromCharCode(u);break;default:s+=ch;}}else{s+=ch;}}} | |
5271 | -error("Bad string");} | |
5272 | -function arr(){var a=[];if(ch=='['){next();white();if(ch==']'){next();return a;} | |
5273 | -while(ch){a.push(val());white();if(ch==']'){next();return a;}else if(ch!=','){break;} | |
5274 | -next();white();}} | |
5275 | -error("Bad array");} | |
5276 | -function obj(){var k,o={};if(ch=='{'){next();white();if(ch=='}'){next();return o;} | |
5277 | -while(ch){k=str();white();if(ch!=':'){break;} | |
5278 | -next();o[k]=val();white();if(ch=='}'){next();return o;}else if(ch!=','){break;} | |
5279 | -next();white();}} | |
5280 | -error("Bad object");} | |
5281 | -function assoc(){var k,a=[];if(ch=='<'){next();white();if(ch=='>'){next();return a;} | |
5282 | -while(ch){k=str();white();if(ch!=':'){break;} | |
5283 | -next();a[k]=val();white();if(ch=='>'){next();return a;}else if(ch!=','){break;} | |
5284 | -next();white();}} | |
5285 | -error("Bad associative array");} | |
5286 | -function num(){var n='',v;if(ch=='-'){n='-';next();} | |
5287 | -while(ch>='0'&&ch<='9'){n+=ch;next();} | |
5288 | -if(ch=='.'){n+='.';while(next()&&ch>='0'&&ch<='9'){n+=ch;}} | |
5289 | -if(ch=='e'||ch=='E'){n+='e';next();if(ch=='-'||ch=='+'){n+=ch;next();} | |
5290 | -while(ch>='0'&&ch<='9'){n+=ch;next();}} | |
5291 | -v=+n;if(!isFinite(v)){error("Bad number");}else{return v;}} | |
5292 | -function word(){switch(ch){case't':if(next()=='r'&&next()=='u'&&next()=='e'){next();return true;} | |
5293 | -break;case'f':if(next()=='a'&&next()=='l'&&next()=='s'&&next()=='e'){next();return false;} | |
5294 | -break;case'n':if(next()=='u'&&next()=='l'&&next()=='l'){next();return null;} | |
5295 | -break;} | |
5296 | -error("Syntax error");} | |
5297 | -function val(){white();switch(ch){case'{':return obj();case'[':return arr();case'<':return assoc();case'"':return str();case'-':return num();default:return ch>='0'&&ch<='9'?num():word();}} | |
5298 | -return val();}}; | |
5183 | +/** | |
5184 | +* CPAINT - Cross-Platform Asynchronous INterface Toolkit | |
5185 | +* | |
5186 | +* http://sf.net/projects/cpaint | |
5187 | +* | |
5188 | +* released under the terms of the LGPL | |
5189 | +* see http://www.fsf.org/licensing/licenses/lgpl.txt for details | |
5190 | +* | |
5191 | +* @package CPAINT | |
5192 | +* @access public | |
5193 | +* @copyright Copyright (c) 2005-2006 Paul Sullivan, Dominique Stender - http://sf.net/projects/cpaint | |
5194 | +* @author Paul Sullivan <wiley14@gmail.com> | |
5195 | +* @author Dominique Stender <dstender@st-webdevelopment.de> | |
5196 | +* @author Stephan Tijink <stijink@googlemail.com> | |
5197 | +* @version 2.0.3 | |
5198 | +*/ | |
5199 | +function cpaint() { | |
5200 | + /** | |
5201 | + * CPAINT version | |
5202 | + * | |
5203 | + * @access protected | |
5204 | + * @var string version | |
5205 | + */ | |
5206 | + this.version = '2.0.3'; | |
5207 | + | |
5208 | + /** | |
5209 | + * configuration options both for this class but also for the cpaint_call() objects. | |
5210 | + * | |
5211 | + * @access protected | |
5212 | + * @var array config | |
5213 | + */ | |
5214 | + var config = new Array(); | |
5215 | + config['debugging'] = -1; | |
5216 | + config['proxy_url'] = ''; | |
5217 | + config['transfer_mode'] = 'GET'; | |
5218 | + config['async'] = true; | |
5219 | + config['response_type'] = 'OBJECT'; | |
5220 | + config['persistent_connection'] = false; | |
5221 | + config['use_cpaint_api'] = true; | |
5222 | + | |
5223 | + /** | |
5224 | + * maintains the next free index in the stack | |
5225 | + * | |
5226 | + * @access protected | |
5227 | + * @var integer stack_count | |
5228 | + */ | |
5229 | + var stack_count = 0; | |
5230 | + | |
5231 | + /** | |
5232 | + * property returns whether or not the browser is AJAX capable | |
5233 | + * | |
5234 | + * @access public | |
5235 | + * @return boolean | |
5236 | + */ | |
5237 | + this.capable = test_ajax_capability(); | |
5238 | + | |
5239 | + /** | |
5240 | + * switches debug mode on/off. | |
5241 | + * | |
5242 | + * @access public | |
5243 | + * @param boolean debug debug flag | |
5244 | + * @return void | |
5245 | + */ | |
5246 | + this.set_debug = function() { | |
5247 | + | |
5248 | + if (typeof arguments[0] == 'boolean') { | |
5249 | + if (arguments[0] === true) { | |
5250 | + config['debugging'] = 1; | |
5251 | + | |
5252 | + } else { | |
5253 | + config['debugging'] = 0; | |
5254 | + } | |
5255 | + | |
5256 | + } else if (typeof arguments[0] == 'number') { | |
5257 | + config['debugging'] = Math.round(arguments[0]); | |
5258 | + } | |
5259 | + } | |
5260 | + | |
5261 | + /** | |
5262 | + * defines the URL of the proxy script. | |
5263 | + * | |
5264 | + * @access public | |
5265 | + * @param string proxy_url URL of the proxyscript to connect | |
5266 | + * @return void | |
5267 | + */ | |
5268 | + this.set_proxy_url = function() { | |
5269 | + | |
5270 | + if (typeof arguments[0] == 'string') { | |
5271 | + | |
5272 | + config['proxy_url'] = arguments[0]; | |
5273 | + } | |
5274 | + } | |
5275 | + | |
5276 | + /** | |
5277 | + * sets the transfer_mode (GET|POST). | |
5278 | + * | |
5279 | + * @access public | |
5280 | + * @param string transfer_mode transfer_mode | |
5281 | + * @return void | |
5282 | + */ | |
5283 | + this.set_transfer_mode = function() { | |
5284 | + | |
5285 | + if (arguments[0].toUpperCase() == 'GET' | |
5286 | + || arguments[0].toUpperCase() == 'POST') { | |
5287 | + | |
5288 | + config['transfer_mode'] = arguments[0].toUpperCase(); | |
5289 | + } | |
5290 | + } | |
5291 | + | |
5292 | + /** | |
5293 | + * sets the flag whether or not to use asynchronous calls. | |
5294 | + * | |
5295 | + * @access public | |
5296 | + * @param boolean async syncronization flag | |
5297 | + * @return void | |
5298 | + */ | |
5299 | + this.set_async = function() { | |
5300 | + | |
5301 | + if (typeof arguments[0] == 'boolean') { | |
5302 | + config['async'] = arguments[0]; | |
5303 | + } | |
5304 | + } | |
5305 | + | |
5306 | + /** | |
5307 | + * defines the response type. | |
5308 | + * | |
5309 | + * allowed values are: | |
5310 | + * TEXT = raw text response | |
5311 | + * XML = raw XMLHttpObject | |
5312 | + * OBJECT = parsed JavaScript object structure from XMLHttpObject | |
5313 | + * | |
5314 | + * the default is OBJECT. | |
5315 | + * | |
5316 | + * @access public | |
5317 | + * @param string response_type response type | |
5318 | + * @return void | |
5319 | + */ | |
5320 | + this.set_response_type = function() { | |
5321 | + | |
5322 | + if (arguments[0].toUpperCase() == 'TEXT' | |
5323 | + || arguments[0].toUpperCase() == 'XML' | |
5324 | + || arguments[0].toUpperCase() == 'OBJECT' | |
5325 | + || arguments[0].toUpperCase() == 'E4X' | |
5326 | + || arguments[0].toUpperCase() == 'JSON') { | |
5327 | + | |
5328 | + config['response_type'] = arguments[0].toUpperCase(); | |
5329 | + } | |
5330 | + } | |
5331 | + | |
5332 | + /** | |
5333 | + * sets the flag whether or not to use a persistent connection. | |
5334 | + * | |
5335 | + * @access public | |
5336 | + * @param boolean persistent_connection persistance flag | |
5337 | + * @return void | |
5338 | + */ | |
5339 | + this.set_persistent_connection = function() { | |
5340 | + | |
5341 | + if (typeof arguments[0] == 'boolean') { | |
5342 | + config['persistent_connection'] = arguments[0]; | |
5343 | + } | |
5344 | + } | |
5345 | + | |
5346 | + | |
5347 | + /** | |
5348 | + * sets the flag whether or not to use the cpaint api on the backend. | |
5349 | + * | |
5350 | + * @access public | |
5351 | + * @param boolean cpaint_api api_flag | |
5352 | + * @return void | |
5353 | + */ | |
5354 | + this.set_use_cpaint_api = function() { | |
5355 | + if (typeof arguments[0] == 'boolean') { | |
5356 | + config['use_cpaint_api'] = arguments[0]; | |
5357 | + } | |
5358 | + } | |
5359 | + | |
5360 | + /** | |
5361 | + * tests whether one of the necessary implementations | |
5362 | + * of the XMLHttpRequest class are available | |
5363 | + * | |
5364 | + * @access protected | |
5365 | + * @return boolean | |
5366 | + */ | |
5367 | + function test_ajax_capability() { | |
5368 | + var cpc = new cpaint_call(0, config, this.version); | |
5369 | + return cpc.test_ajax_capability(); | |
5370 | + } | |
5371 | + | |
5372 | + /** | |
5373 | + * takes the arguments supplied and triggers a call to the CPAINT backend | |
5374 | + * based on the settings. | |
5375 | + * | |
5376 | + * upon response cpaint_call.callback() will automatically be called | |
5377 | + * to perform post-processing operations. | |
5378 | + * | |
5379 | + * @access public | |
5380 | + * @param string url remote URL to call | |
5381 | + * @param string remote_method remote method to call | |
5382 | + * @param object client_callback client side callback method to deliver the remote response to. do NOT supply a string! | |
5383 | + * @param mixed argN remote parameters from now on | |
5384 | + * @return void | |
5385 | + */ | |
5386 | + this.call = function() { | |
5387 | + //incluido por edmar | |
5388 | + var sUrl = escape(arguments[0]); | |
5389 | + var re = new RegExp("%3F", "g"); | |
5390 | + var sUrl = sUrl.replace(re,'?'); | |
5391 | + var re = new RegExp("%3D", "g"); | |
5392 | + var sUrl = sUrl.replace(re,'='); | |
5393 | + var re = new RegExp("%26", "g"); | |
5394 | + var sUrl = sUrl.replace(re,'&'); | |
5395 | + var re = new RegExp("%3A", "g"); | |
5396 | + var sUrl = sUrl.replace(re,':'); | |
5397 | + //alert(sUrl) | |
5398 | + arguments[0] = sUrl; | |
5399 | + // | |
5400 | + var use_stack = -1; | |
5401 | + | |
5402 | + if (config['persistent_connection'] == true | |
5403 | + && __cpaint_stack[0] != null) { | |
5404 | + | |
5405 | + switch (__cpaint_stack[0].get_http_state()) { | |
5406 | + case -1: | |
5407 | + // no XMLHttpObject object has already been instanciated | |
5408 | + // create new object and configure it | |
5409 | + use_stack = 0; | |
5410 | + debug('no XMLHttpObject object to re-use for persistence, creating new one later', 2); | |
5411 | + break; | |
5412 | + | |
5413 | + case 4: | |
5414 | + // object is ready for a new request, no need to do anything | |
5415 | + use_stack = 0 | |
5416 | + debug('re-using the persistent connection', 2); | |
5417 | + break; | |
5418 | + | |
5419 | + default: | |
5420 | + // connection is currently in use, don't do anything | |
5421 | + debug('the persistent connection is in use - skipping this request', 2); | |
5422 | + } | |
5423 | + | |
5424 | + } else if (config['persistent_connection'] == true) { | |
5425 | + // persistent connection is active, but no object has been instanciated | |
5426 | + use_stack = 0; | |
5427 | + __cpaint_stack[use_stack] = new cpaint_call(use_stack, config, this.version); | |
5428 | + debug('no cpaint_call object available for re-use, created new one', 2); | |
5429 | + | |
5430 | + } else { | |
5431 | + // no connection persistance | |
5432 | + use_stack = stack_count; | |
5433 | + __cpaint_stack[use_stack] = new cpaint_call(use_stack, config, this.version); | |
5434 | + debug('no cpaint_call object created new one', 2); | |
5435 | + } | |
5436 | + | |
5437 | + // configure cpaint_call if allowed to | |
5438 | + if (use_stack != -1) { | |
5439 | + __cpaint_stack[use_stack].set_client_callback(arguments[2]); | |
5440 | + | |
5441 | + // distribute according to proxy use | |
5442 | + if (config['proxy_url'] != '') { | |
5443 | + __cpaint_stack[use_stack].call_proxy(arguments); | |
5444 | + | |
5445 | + } else { | |
5446 | + __cpaint_stack[use_stack].call_direct(arguments); | |
5447 | + } | |
5448 | + | |
5449 | + // increase stack counter | |
5450 | + stack_count++; | |
5451 | + debug('stack size: ' + __cpaint_stack.length, 2); | |
5452 | + } | |
5453 | + } | |
5454 | + | |
5455 | + /** | |
5456 | + * debug method | |
5457 | + * | |
5458 | + * @access protected | |
5459 | + * @param string message the message to debug | |
5460 | + * @param integer debug_level debug level at which the message appears | |
5461 | + * @return void | |
5462 | + */ | |
5463 | + var debug = function(message, debug_level) { | |
5464 | + var prefix = '[CPAINT Debug] '; | |
5465 | + | |
5466 | + if (debug_level < 1) { | |
5467 | + prefix = '[CPAINT Error] '; | |
5468 | + } | |
5469 | + | |
5470 | + if (config['debugging'] >= debug_level) { | |
5471 | + alert(prefix + message); | |
5472 | + } | |
5473 | + } | |
5474 | +} | |
5475 | + | |
5476 | +/** | |
5477 | +* internal FIFO stack of cpaint_call() objects. | |
5478 | +* | |
5479 | +* @access protected | |
5480 | +* @var array __cpaint_stack | |
5481 | +*/ | |
5482 | +var __cpaint_stack = new Array(); | |
5483 | + | |
5484 | +/** | |
5485 | +* local instance of cpaint_transformer | |
5486 | +* MSIE is unable to handle static classes... sheesh. | |
5487 | +* | |
5488 | +* @access public | |
5489 | +* @var object __cpaint_transformer | |
5490 | +*/ | |
5491 | +var __cpaint_transformer = new cpaint_transformer(); | |
5492 | + | |
5493 | +/** | |
5494 | +* transport agent class | |
5495 | +* | |
5496 | +* creates the request object, takes care of the response, handles the | |
5497 | +* client callback. Is configured by the cpaint() object. | |
5498 | +* | |
5499 | +* @package CPAINT | |
5500 | +* @access public | |
5501 | +* @copyright Copyright (c) 2005-2006 Paul Sullivan, Dominique Stender - http://sf.net/projects/cpaint | |
5502 | +* @author Dominique Stender <dstender@st-webdevelopment.de> | |
5503 | +* @author Paul Sullivan <wiley14@gmail.com> | |
5504 | +* @param integer stack_id stack Id in cpaint | |
5505 | +* @param array config configuration array for this call | |
5506 | +* @param string version CPAINT API version | |
5507 | +*/ | |
5508 | +function cpaint_call() { | |
5509 | + /** | |
5510 | + * CPAINT version | |
5511 | + * | |
5512 | + * @access protected | |
5513 | + * @var string version | |
5514 | + */ | |
5515 | + var version = arguments[2]; | |
5516 | + | |
5517 | + /** | |
5518 | + * configuration options both for this class objects. | |
5519 | + * | |
5520 | + * @access protected | |
5521 | + * @var array config | |
5522 | + */ | |
5523 | + var config = new Array(); | |
5524 | + config['debugging'] = arguments[1]['debugging']; | |
5525 | + config['proxy_url'] = arguments[1]['proxy_url']; | |
5526 | + config['transfer_mode'] = arguments[1]['transfer_mode']; | |
5527 | + config['async'] = arguments[1]['async']; | |
5528 | + config['response_type'] = arguments[1]['response_type']; | |
5529 | + config['persistent_connection'] = arguments[1]['persistent_connection']; | |
5530 | + config['use_cpaint_api'] = arguments[1]['use_cpaint_api']; | |
5531 | + | |
5532 | + /** | |
5533 | + * XMLHttpObject used for this request. | |
5534 | + * | |
5535 | + * @access protected | |
5536 | + * @var object httpobj | |
5537 | + */ | |
5538 | + var httpobj = false; | |
5539 | + | |
5540 | + /** | |
5541 | + * client callback function. | |
5542 | + * | |
5543 | + * @access public | |
5544 | + * @var function client_callback | |
5545 | + */ | |
5546 | + var client_callback; | |
5547 | + | |
5548 | + /** | |
5549 | + * stores the stack Id within the cpaint object | |
5550 | + * | |
5551 | + * @access protected | |
5552 | + * @var stack_id | |
5553 | + */ | |
5554 | + var stack_id = arguments[0]; | |
5555 | + | |
5556 | + /** | |
5557 | + * sets the client callback function. | |
5558 | + * | |
5559 | + * @access public | |
5560 | + * @param function client_callback the client callback function | |
5561 | + * @return void | |
5562 | + */ | |
5563 | + this.set_client_callback = function() { | |
5564 | + | |
5565 | + if (typeof arguments[0] == 'function') { | |
5566 | + client_callback = arguments[0]; | |
5567 | + } | |
5568 | + } | |
5569 | + | |
5570 | + /** | |
5571 | + * returns the ready state of the internal XMLHttpObject | |
5572 | + * | |
5573 | + * if no such object was set up already, -1 is returned | |
5574 | + * | |
5575 | + * @access public | |
5576 | + * @return integer | |
5577 | + */ | |
5578 | + this.get_http_state = function() { | |
5579 | + var return_value = -1; | |
5580 | + | |
5581 | + if (typeof httpobj == 'object') { | |
5582 | + return_value = httpobj.readyState; | |
5583 | + } | |
5584 | + | |
5585 | + return return_value; | |
5586 | + } | |
5587 | + | |
5588 | + /** | |
5589 | + * internal method for remote calls to the local server without use of the proxy script. | |
5590 | + * | |
5591 | + * @access public | |
5592 | + * @param array call_arguments array of arguments initially passed to cpaint.call() | |
5593 | + * @return void | |
5594 | + */ | |
5595 | + this.call_direct = function(call_arguments) { | |
5596 | + var url = call_arguments[0]; | |
5597 | + var remote_method = call_arguments[1]; | |
5598 | + var querystring = ''; | |
5599 | + var i = 0; | |
5600 | + | |
5601 | + // correct link to self | |
5602 | + if (url == 'SELF') { | |
5603 | + url = document.location.href; | |
5604 | + } | |
5605 | + | |
5606 | + if (config['use_cpaint_api'] == true) { | |
5607 | + // backend uses cpaint api | |
5608 | + // pass parameters to remote method | |
5609 | + for (i = 3; i < call_arguments.length; i++) { | |
5610 | + | |
5611 | + if ((typeof call_arguments[i] == 'string' | |
5612 | + && call_arguments[i] != '' | |
5613 | + && call_arguments[i].search(/^\s+$/g) == -1) | |
5614 | + && !isNaN(call_arguments[i]) | |
5615 | + && isFinite(call_arguments[i])) { | |
5616 | + // numerical value, convert it first | |
5617 | + querystring += '&cpaint_argument[]=' + encodeURIComponent(JSON.stringify(Number(call_arguments[i]))); | |
5618 | + | |
5619 | + } else { | |
5620 | + querystring += '&cpaint_argument[]=' + encodeURIComponent(JSON.stringify(call_arguments[i])); | |
5621 | + } | |
5622 | + } | |
5623 | + | |
5624 | + // add response type to querystring | |
5625 | + querystring += '&cpaint_response_type=' + config['response_type']; | |
5626 | + | |
5627 | + // build header | |
5628 | + if (config['transfer_mode'] == 'GET') { | |
5629 | + | |
5630 | + if(url.indexOf('?') != -1) { | |
5631 | + url = url + '&cpaint_function=' + remote_method + querystring; | |
5632 | + | |
5633 | + } else { | |
5634 | + url = url + '?cpaint_function=' + remote_method + querystring; | |
5635 | + } | |
5636 | + | |
5637 | + } else { | |
5638 | + querystring = 'cpaint_function=' + remote_method + querystring; | |
5639 | + } | |
5640 | + | |
5641 | + } else { | |
5642 | + // backend does not use cpaint api | |
5643 | + // pass parameters to remote method | |
5644 | + for (i = 3; i < call_arguments.length; i++) { | |
5645 | + | |
5646 | + if (i == 3) { | |
5647 | + querystring += encodeURIComponent(call_arguments[i]); | |
5648 | + | |
5649 | + } else { | |
5650 | + querystring += '&' + encodeURIComponent(call_arguments[i]); | |
5651 | + } | |
5652 | + } | |
5653 | + | |
5654 | + // build header | |
5655 | + if (config['transfer_mode'] == 'GET') { | |
5656 | + url = url + querystring; | |
5657 | + } | |
5658 | + } | |
5659 | + | |
5660 | + // open connection | |
5661 | + get_connection_object(); | |
5662 | + | |
5663 | + // open connection to remote target | |
5664 | + debug('opening connection to "' + url + '"', 1); | |
5665 | + httpobj.open(config['transfer_mode'], url, config['async']); | |
5666 | + | |
5667 | + // send "urlencoded" header if necessary (if POST) | |
5668 | + if (config['transfer_mode'] == 'POST') { | |
5669 | + | |
5670 | + try { | |
5671 | + httpobj.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); | |
5672 | + | |
5673 | + } catch (cp_err) { | |
5674 | + debug('POST cannot be completed due to incompatible browser. Use GET as your request method.', 0); | |
5675 | + } | |
5676 | + } | |
5677 | + | |
5678 | + // make ourselves known | |
5679 | + httpobj.setRequestHeader('X-Powered-By', 'CPAINT v' + version + ' :: http://sf.net/projects/cpaint'); | |
5680 | + | |
5681 | + // callback handling for asynchronous calls | |
5682 | + httpobj.onreadystatechange = callback; | |
5683 | + | |
5684 | + // send content | |
5685 | + if (config['transfer_mode'] == 'GET') { | |
5686 | + httpobj.send(null); | |
5687 | + | |
5688 | + } else { | |
5689 | + debug('sending query: ' + querystring, 1); | |
5690 | + httpobj.send(querystring); | |
5691 | + } | |
5692 | + | |
5693 | + if (config['async'] == true) { | |
5694 | + // manual callback handling for synchronized calls | |
5695 | + callback(); | |
5696 | + } | |
5697 | + } | |
5698 | + | |
5699 | + /** | |
5700 | + * internal method for calls to remote servers through the proxy script. | |
5701 | + * | |
5702 | + * @access public | |
5703 | + * @param array call_arguments array of arguments passed to cpaint.call() | |
5704 | + * @return void | |
5705 | + */ | |
5706 | + this.call_proxy = function(call_arguments) { | |
5707 | + var proxyscript = config['proxy_url']; | |
5708 | + var url = call_arguments[0]; | |
5709 | + var remote_method = call_arguments[1]; | |
5710 | + var querystring = ''; | |
5711 | + var i = 0; | |
5712 | + | |
5713 | + var querystring_argument_prefix = 'cpaint_argument[]='; | |
5714 | + | |
5715 | + // pass parameters to remote method | |
5716 | + if (config['use_cpaint_api'] == false) { | |
5717 | + // when not talking to a CPAINT backend, don't prefix arguments | |
5718 | + querystring_argument_prefix = ''; | |
5719 | + } | |
5720 | + | |
5721 | + for (i = 3; i < call_arguments.length; i++) { | |
5722 | + | |
5723 | + if (config['use_cpaint_api'] == true) { | |
5724 | + | |
5725 | + if ((typeof call_arguments[i] == 'string' | |
5726 | + && call_arguments[i] != '' | |
5727 | + && call_arguments[i].search(/^\s+$/g) == -1) | |
5728 | + && !isNaN(call_arguments[i]) | |
5729 | + && isFinite(call_arguments[i])) { | |
5730 | + // numerical value, convert it first | |
5731 | + querystring += encodeURIComponent(querystring_argument_prefix + JSON.stringify(Number(call_arguments[i])) + '&'); | |
5732 | + | |
5733 | + } else { | |
5734 | + querystring += encodeURIComponent(querystring_argument_prefix + JSON.stringify(call_arguments[i]) + '&'); | |
5735 | + } | |
5736 | + | |
5737 | + } else { | |
5738 | + // no CPAINT in the backend | |
5739 | + querystring += encodeURIComponent(querystring_argument_prefix + call_arguments[i] + '&'); | |
5740 | + } | |
5741 | + } | |
5742 | + | |
5743 | + if (config['use_cpaint_api'] == true) { | |
5744 | + // add remote function name to querystring | |
5745 | + querystring += encodeURIComponent('&cpaint_function=' + remote_method); | |
5746 | + | |
5747 | + // add response type to querystring | |
5748 | + querystring += encodeURIComponent('&cpaint_responsetype=' + config['response_type']); | |
5749 | + } | |
5750 | + | |
5751 | + // build header | |
5752 | + if (config['transfer_mode'] == 'GET') { | |
5753 | + proxyscript += '?cpaint_remote_url=' + encodeURIComponent(url) | |
5754 | + + '&cpaint_remote_query=' + querystring | |
5755 | + + '&cpaint_remote_method=' + config['transfer_mode'] | |
5756 | + + '&cpaint_response_type=' + config['response_type']; | |
5757 | + | |
5758 | + } else { | |
5759 | + querystring = 'cpaint_remote_url=' + encodeURIComponent(url) | |
5760 | + + '&cpaint_remote_query=' + querystring | |
5761 | + + '&cpaint_remote_method=' + config['transfer_mode'] | |
5762 | + + '&cpaint_response_type=' + config['response_type']; | |
5763 | + } | |
5764 | + | |
5765 | + // open connection | |
5766 | + get_connection_object(); | |
5767 | + | |
5768 | + // open connection to remote target | |
5769 | + debug('opening connection to proxy "' + proxyscript + '"', 1); | |
5770 | + httpobj.open(config['transfer_mode'], proxyscript, config['async']); | |
5771 | + | |
5772 | + // send "urlencoded" header if necessary (if POST) | |
5773 | + if (config['transfer_mode'] == 'POST') { | |
5774 | + | |
5775 | + try { | |
5776 | + httpobj.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); | |
5777 | + | |
5778 | + } catch (cp_err) { | |
5779 | + debug('POST cannot be completed due to incompatible browser. Use GET as your request method.', 0); | |
5780 | + } | |
5781 | + } | |
5782 | + | |
5783 | + httpobj.setRequestHeader('X-Powered-By', 'CPAINT v' + version); | |
5784 | + | |
5785 | + // callback handling for asynchronous calls | |
5786 | + httpobj.onreadystatechange = callback; | |
5787 | + | |
5788 | + // send content | |
5789 | + if (config['transfer_mode'] == 'GET') { | |
5790 | + httpobj.send(null); | |
5791 | + | |
5792 | + } else { | |
5793 | + debug('sending query: ' + querystring, 1); | |
5794 | + httpobj.send(querystring); | |
5795 | + } | |
5796 | + | |
5797 | + if (config['async'] == false) { | |
5798 | + // manual callback handling for synchronized calls | |
5799 | + callback(); | |
5800 | + } | |
5801 | + } | |
5802 | + | |
5803 | + this.test_ajax_capability = function() { | |
5804 | + return get_connection_object(); | |
5805 | + } | |
5806 | + | |
5807 | + /** | |
5808 | + * creates a new connection object. | |
5809 | + * | |
5810 | + * @access protected | |
5811 | + * @return boolean | |
5812 | + */ | |
5813 | + var get_connection_object = function() { | |
5814 | + var return_value = false; | |
5815 | + var new_connection = false; | |
5816 | + | |
5817 | + // open new connection only if necessary | |
5818 | + if (config['persistent_connection'] == false) { | |
5819 | + // no persistance, create a new object every time | |
5820 | + debug('Using new connection object', 1); | |
5821 | + new_connection = true; | |
5822 | + | |
5823 | + } else { | |
5824 | + // persistent connection object, only open one if no object exists | |
5825 | + debug('Using shared connection object.', 1); | |
5826 | + | |
5827 | + if (typeof httpobj != 'object') { | |
5828 | + debug('Getting new persistent connection object.', 1); | |
5829 | + new_connection = true; | |
5830 | + } | |
5831 | + } | |
5832 | + | |
5833 | + if (new_connection == true) { | |
5834 | + | |
5835 | + try { | |
5836 | + httpobj = new XMLHttpRequest(); | |
5837 | + } catch (e1) { | |
5838 | + | |
5839 | + try { | |
5840 | + httpobj = new ActiveXObject('Msxml2.XMLHTTP'); | |
5841 | + | |
5842 | + } catch (e) { | |
5843 | + | |
5844 | + try { | |
5845 | + httpobj = new ActiveXObject('Microsoft.XMLHTTP'); | |
5846 | + | |
5847 | + } catch (oc) { | |
5848 | + httpobj = null; | |
5849 | + } | |
5850 | + } | |
5851 | + } | |
5852 | + | |
5853 | + | |
5854 | + if (!httpobj) { | |
5855 | + debug('Could not create connection object', 0); | |
5856 | + | |
5857 | + } else { | |
5858 | + return_value = true; | |
5859 | + } | |
5860 | + } | |
5861 | + | |
5862 | + if (httpobj.readyState != 4) { | |
5863 | + httpobj.abort(); | |
5864 | + } | |
5865 | + | |
5866 | + return return_value; | |
5867 | + } | |
5868 | + | |
5869 | + /** | |
5870 | + * internal callback function. | |
5871 | + * | |
5872 | + * will perform some consistency checks (response code, NULL value testing) | |
5873 | + * and if response_type = 'OBJECT' it will automatically call | |
5874 | + * cpaint_call.parse_ajax_xml() to have a JavaScript object structure generated. | |
5875 | + * | |
5876 | + * after all that is done the client side callback function will be called | |
5877 | + * with the generated response as single value. | |
5878 | + * | |
5879 | + * @access protected | |
5880 | + * @return void | |
5881 | + */ | |
5882 | + var callback = function() { | |
5883 | + var response = null; | |
5884 | + if (httpobj.readyState == 4 | |
5885 | + && httpobj.status == 200) { | |
5886 | + if(httpobj.responseText == ""){ | |
5887 | + alert("O servidor demorou muito - timeout"); | |
5888 | + client_callback("", "erro"); | |
5889 | + return; | |
5890 | + } | |
5891 | + debug(httpobj.responseText, 1); | |
5892 | + debug('using response type ' + config['response_type'], 2); | |
5893 | + | |
5894 | + // fetch correct response | |
5895 | + switch (config['response_type']) { | |
5896 | + case 'XML': | |
5897 | + debug(httpobj.responseXML, 2); | |
5898 | + response = __cpaint_transformer.xml_conversion(httpobj.responseXML); | |
5899 | + break; | |
5900 | + | |
5901 | + case 'OBJECT': | |
5902 | + response = __cpaint_transformer.object_conversion(httpobj.responseXML); | |
5903 | + break; | |
5904 | + | |
5905 | + case 'TEXT': | |
5906 | + response = __cpaint_transformer.text_conversion(httpobj.responseText); | |
5907 | + break; | |
5908 | + | |
5909 | + case 'E4X': | |
5910 | + response = __cpaint_transformer.e4x_conversion(httpobj.responseText); | |
5911 | + break; | |
5912 | + | |
5913 | + case 'JSON': | |
5914 | + response = __cpaint_transformer.json_conversion(httpobj.responseText); | |
5915 | + break; | |
5916 | + | |
5917 | + default: | |
5918 | + debug('invalid response type \'' + response_type + '\'', 0); | |
5919 | + } | |
5920 | + | |
5921 | + // call client side callback | |
5922 | + if (response != null | |
5923 | + && typeof client_callback == 'function') { | |
5924 | + try{ | |
5925 | + if(response.data) | |
5926 | + client_callback(response, httpobj.responseText); | |
5927 | + else | |
5928 | + client_callback("", "erro"); | |
5929 | + } | |
5930 | + catch(e){ | |
5931 | + client_callback("", "erro"); | |
5932 | + } | |
5933 | + } | |
5934 | + // remove ourselves from the stack | |
5935 | + remove_from_stack(); | |
5936 | + | |
5937 | + } else | |
5938 | + { | |
5939 | + if(httpobj.readyState==4&&httpobj.status!=200) | |
5940 | + { | |
5941 | + debug('invalid HTTP response code \''+Number(httpobj.status)+'\'',0); | |
5942 | + if(httpobj.status==500){ | |
5943 | + alert("O servidor demorou muito - timeout"); | |
5944 | + client_callback("", "erro"); | |
5945 | + } | |
5946 | + else{ | |
5947 | + client_callback("", "erro"); | |
5948 | + } | |
5949 | + } | |
5950 | + | |
5951 | + } | |
5952 | + } | |
5953 | + | |
5954 | + /** | |
5955 | + * removes an entry from the stack | |
5956 | + * | |
5957 | + * @access protected | |
5958 | + * @return void | |
5959 | + */ | |
5960 | + var remove_from_stack = function() { | |
5961 | + // remove only if everything is okay and we're not configured as persistent connection | |
5962 | + if (typeof stack_id == 'number' | |
5963 | + && __cpaint_stack[stack_id] | |
5964 | + && config['persistent_connection'] == false) { | |
5965 | + | |
5966 | + __cpaint_stack[stack_id] = null; | |
5967 | + } | |
5968 | + } | |
5969 | + | |
5970 | + /** | |
5971 | + * debug method | |
5972 | + * | |
5973 | + * @access protected | |
5974 | + * @param string message the message to debug | |
5975 | + * @param integer debug_level debug level at which the message appears | |
5976 | + * @return void | |
5977 | + */ | |
5978 | + var debug = function(message, debug_level) { | |
5979 | + var prefix = '[CPAINT Debug] '; | |
5980 | + | |
5981 | + if (config['debugging'] < 1) { | |
5982 | + prefix = '[CPAINT Error] '; | |
5983 | + } | |
5984 | + | |
5985 | + if (config['debugging'] >= debug_level) { | |
5986 | + alert(prefix + message); | |
5987 | + } | |
5988 | + if (message.search(" error") > 1){client_callback("", message);} | |
5989 | + } | |
5990 | +} | |
5991 | + | |
5992 | +/** | |
5993 | +* CPAINT transformation object | |
5994 | +* | |
5995 | +* @package CPAINT | |
5996 | +* @access public | |
5997 | +* @copyright Copyright (c) 2005-2006 Paul Sullivan, Dominique Stender - http://sf.net/projects/cpaint | |
5998 | +* @author Paul Sullivan <wiley14@gmail.com> | |
5999 | +* @author Dominique Stender <dstender@st-webdevelopment.de> | |
6000 | +*/ | |
6001 | +function cpaint_transformer() { | |
6002 | + | |
6003 | + /** | |
6004 | + * will take a XMLHttpObject and generate a JavaScript | |
6005 | + * object structure from it. | |
6006 | + * | |
6007 | + * is internally called by cpaint_call.callback() if necessary. | |
6008 | + * will call cpaint_call.create_object_structure() to create nested object structures. | |
6009 | + * | |
6010 | + * @access public | |
6011 | + * @param object xml_document a XMLHttpObject | |
6012 | + * @return object | |
6013 | + */ | |
6014 | + this.object_conversion = function(xml_document) { | |
6015 | + var return_value = new cpaint_result_object(); | |
6016 | + var i = 0; | |
6017 | + var firstNodeName = ''; | |
6018 | + | |
6019 | + if (typeof xml_document == 'object' | |
6020 | + && xml_document != null) { | |
6021 | + | |
6022 | + // find the first element node - for MSIE the <?xml?> node is the very first... | |
6023 | + for (i = 0; i < xml_document.childNodes.length; i++) { | |
6024 | + | |
6025 | + if (xml_document.childNodes[i].nodeType == 1) { | |
6026 | + firstNodeName = xml_document.childNodes[i].nodeName; | |
6027 | + break; | |
6028 | + } | |
6029 | + } | |
6030 | + | |
6031 | + var ajax_response = xml_document.getElementsByTagName(firstNodeName); | |
6032 | + | |
6033 | + return_value[firstNodeName] = new Array(); | |
6034 | + | |
6035 | + for (i = 0; i < ajax_response.length; i++) { | |
6036 | + var tmp_node = create_object_structure(ajax_response[i]); | |
6037 | + tmp_node.id = ajax_response[i].getAttribute('id') | |
6038 | + return_value[firstNodeName].push(tmp_node); | |
6039 | + } | |
6040 | + | |
6041 | + } else { | |
6042 | + debug('received invalid XML response', 0); | |
6043 | + } | |
6044 | + | |
6045 | + return return_value; | |
6046 | + } | |
6047 | + | |
6048 | + /** | |
6049 | + * performs the necessary conversions for the XML response type | |
6050 | + * | |
6051 | + * @access public | |
6052 | + * @param object xml_document a XMLHttpObject | |
6053 | + * @return object | |
6054 | + */ | |
6055 | + this.xml_conversion = function(xml_document) { | |
6056 | + return xml_document; | |
6057 | + } | |
6058 | + | |
6059 | + /** | |
6060 | + * performs the necessary conversions for the TEXT response type | |
6061 | + * | |
6062 | + * @access public | |
6063 | + * @param string text the response text | |
6064 | + * @return string | |
6065 | + */ | |
6066 | + this.text_conversion = function(text) { | |
6067 | + return decode(text); | |
6068 | + } | |
6069 | + | |
6070 | + /** | |
6071 | + * performs the necessary conversions for the E4X response type | |
6072 | + * | |
6073 | + * @access public | |
6074 | + * @param string text the response text | |
6075 | + * @return string | |
6076 | + */ | |
6077 | + this.e4x_conversion = function(text) { | |
6078 | + // remove <?xml ?>tag | |
6079 | + text = text.replace(/^\<\?xml[^>]+\>/, ''); | |
6080 | + return new XML(text); | |
6081 | + } | |
6082 | + | |
6083 | + /** | |
6084 | + * performs the necessary conversions for the JSON response type | |
6085 | + * | |
6086 | + * @access public | |
6087 | + * @param string text the response text | |
6088 | + * @return string | |
6089 | + */ | |
6090 | + this.json_conversion = function(text) { | |
6091 | + return JSON.parse(text); | |
6092 | + } | |
6093 | + | |
6094 | + /** | |
6095 | + * this method takes a HTML / XML node object and creates a | |
6096 | + * JavaScript object structure from it. | |
6097 | + * | |
6098 | + * @access public | |
6099 | + * @param object stream a node in the XML structure | |
6100 | + * @return object | |
6101 | + */ | |
6102 | + var create_object_structure = function(stream) { | |
6103 | + var return_value = new cpaint_result_object(); | |
6104 | + var node_name = ''; | |
6105 | + var i = 0; | |
6106 | + var attrib = 0; | |
6107 | + | |
6108 | + if (stream.hasChildNodes() == true) { | |
6109 | + for (i = 0; i < stream.childNodes.length; i++) { | |
6110 | + | |
6111 | + node_name = stream.childNodes[i].nodeName; | |
6112 | + node_name = node_name.replace(/[^a-zA-Z0-9_]*/g, ''); | |
6113 | + | |
6114 | + // reset / create subnode | |
6115 | + if (typeof return_value[node_name] != 'object') { | |
6116 | + return_value[node_name] = new Array(); | |
6117 | + } | |
6118 | + | |
6119 | + if (stream.childNodes[i].nodeType == 1) { | |
6120 | + var tmp_node = create_object_structure(stream.childNodes[i]); | |
6121 | + | |
6122 | + for (attrib = 0; attrib < stream.childNodes[i].attributes.length; attrib++) { | |
6123 | + tmp_node.set_attribute(stream.childNodes[i].attributes[attrib].nodeName, stream.childNodes[i].attributes[attrib].nodeValue); | |
6124 | + } | |
6125 | + | |
6126 | + return_value[node_name].push(tmp_node); | |
6127 | + | |
6128 | + } else if (stream.childNodes[i].nodeType == 3) { | |
6129 | + return_value.data = decode(String(stream.firstChild.data)); | |
6130 | + } | |
6131 | + } | |
6132 | + } | |
6133 | + | |
6134 | + return return_value; | |
6135 | + } | |
6136 | + | |
6137 | + /** | |
6138 | + * converts an encoded text back to viewable characters. | |
6139 | + * | |
6140 | + * @access public | |
6141 | + * @param string rawtext raw text as provided by the backend | |
6142 | + * @return mixed | |
6143 | + */ | |
6144 | + var decode = function(rawtext) { | |
6145 | + var plaintext = ''; | |
6146 | + var i = 0; | |
6147 | + var c1 = 0; | |
6148 | + var c2 = 0; | |
6149 | + var c3 = 0; | |
6150 | + var u = 0; | |
6151 | + var t = 0; | |
6152 | + | |
6153 | + // remove special JavaScript encoded non-printable characters | |
6154 | + while (i < rawtext.length) { | |
6155 | + if (rawtext.charAt(i) == '\\' | |
6156 | + && rawtext.charAt(i + 1) == 'u') { | |
6157 | + | |
6158 | + u = 0; | |
6159 | + | |
6160 | + for (j = 2; j < 6; j += 1) { | |
6161 | + t = parseInt(rawtext.charAt(i + j), 16); | |
6162 | + | |
6163 | + if (!isFinite(t)) { | |
6164 | + break; | |
6165 | + } | |
6166 | + u = u * 16 + t; | |
6167 | + } | |
6168 | + | |
6169 | + plaintext += String.fromCharCode(u); | |
6170 | + i += 6; | |
6171 | + | |
6172 | + } else { | |
6173 | + plaintext += rawtext.charAt(i); | |
6174 | + i++; | |
6175 | + } | |
6176 | + } | |
6177 | + | |
6178 | + // convert numeric data to number type | |
6179 | + if (plaintext != '' | |
6180 | + && plaintext.search(/^\s+$/g) == -1 | |
6181 | + && !isNaN(plaintext) | |
6182 | + && isFinite(plaintext)) { | |
6183 | + | |
6184 | + plaintext = Number(plaintext); | |
6185 | + } | |
6186 | + | |
6187 | + return plaintext; | |
6188 | + } | |
6189 | +} | |
6190 | + | |
6191 | +/** | |
6192 | +* this is the basic prototype for a cpaint node object | |
6193 | +* as used in cpaint_call.parse_ajax_xml() | |
6194 | +* | |
6195 | +* @package CPAINT | |
6196 | +* @access public | |
6197 | +* @copyright Copyright (c) 2005-2006 Paul Sullivan, Dominique Stender - http://sf.net/projects/cpaint | |
6198 | +* @author Paul Sullivan <wiley14@gmail.com> | |
6199 | +* @author Dominique Stender <dstender@st-webdevelopment.de> | |
6200 | +*/ | |
6201 | +function cpaint_result_object() { | |
6202 | + this.id = 0; | |
6203 | + this.data = ''; | |
6204 | + var __attributes = new Array(); | |
6205 | + | |
6206 | + /** | |
6207 | + * Returns a subnode with the given type and id. | |
6208 | + * | |
6209 | + * @access public | |
6210 | + * @param string type The type of the subnode. Equivalent to the XML tag name. | |
6211 | + * @param string id The id of the subnode. Equivalent to the XML tag names id attribute. | |
6212 | + * @return object | |
6213 | + */ | |
6214 | + this.find_item_by_id = function() { | |
6215 | + var return_value = null; | |
6216 | + var type = arguments[0]; | |
6217 | + var id = arguments[1]; | |
6218 | + var i = 0; | |
6219 | + | |
6220 | + if (this[type]) { | |
6221 | + | |
6222 | + for (i = 0; i < this[type].length; i++) { | |
6223 | + | |
6224 | + if (this[type][i].get_attribute('id') == id) { | |
6225 | + return_value = this[type][i]; | |
6226 | + break; | |
6227 | + } | |
6228 | + } | |
6229 | + } | |
6230 | + | |
6231 | + return return_value; | |
6232 | + } | |
6233 | + | |
6234 | + /** | |
6235 | + * retrieves the value of an attribute. | |
6236 | + * | |
6237 | + * @access public | |
6238 | + * @param string name name of the attribute | |
6239 | + * @return mixed | |
6240 | + */ | |
6241 | + this.get_attribute = function() { | |
6242 | + var return_value = null; | |
6243 | + var id = arguments[0]; | |
6244 | + | |
6245 | + if (typeof __attributes[id] != 'undefined') { | |
6246 | + return_value = __attributes[id]; | |
6247 | + } | |
6248 | + | |
6249 | + return return_value; | |
6250 | + } | |
6251 | + | |
6252 | + /** | |
6253 | + * assigns a value to an attribute. | |
6254 | + * | |
6255 | + * if that attribute does not exist it will be created. | |
6256 | + * | |
6257 | + * @access public | |
6258 | + * @param string name name of the attribute | |
6259 | + * @param string value value of the attribute | |
6260 | + * @return void | |
6261 | + */ | |
6262 | + this.set_attribute = function() { | |
6263 | + __attributes[arguments[0]] = arguments[1]; | |
6264 | + } | |
6265 | +} | |
6266 | + | |
6267 | + | |
6268 | +/* | |
6269 | +Copyright (c) 2005 JSON.org | |
6270 | + | |
6271 | +Permission is hereby granted, free of charge, to any person obtaining a copy | |
6272 | +of this software and associated documentation files (the "Software"), to deal | |
6273 | +in the Software without restriction, including without limitation the rights | |
6274 | +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
6275 | +copies of the Software, and to permit persons to whom the Software is | |
6276 | +furnished to do so, subject to the following conditions: | |
6277 | + | |
6278 | +The Software shall be used for Good, not Evil. | |
6279 | + | |
6280 | +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
6281 | +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
6282 | +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
6283 | +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
6284 | +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
6285 | +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |
6286 | +SOFTWARE. | |
6287 | +*/ | |
6288 | + | |
6289 | + | |
6290 | +Array.prototype.______array = '______array'; | |
6291 | + | |
6292 | +var JSON = { | |
6293 | + org: 'http://www.JSON.org', | |
6294 | + copyright: '(c)2005 JSON.org', | |
6295 | + license: 'http://www.crockford.com/JSON/license.html', | |
6296 | + | |
6297 | + stringify: function (arg) { | |
6298 | + var c, i, l, s = '', v; | |
6299 | + var numeric = true; | |
6300 | + | |
6301 | + switch (typeof arg) { | |
6302 | + case 'object': | |
6303 | + if (arg) { | |
6304 | + if (arg.______array == '______array') { | |
6305 | + // do a test whether all array keys are numeric | |
6306 | + for (i in arg) { | |
6307 | + if (i != '______array' | |
6308 | + && (isNaN(i) | |
6309 | + || !isFinite(i))) { | |
6310 | + numeric = false; | |
6311 | + break; | |
6312 | + } | |
6313 | + } | |
6314 | + | |
6315 | + if (numeric == true) { | |
6316 | + for (i = 0; i < arg.length; ++i) { | |
6317 | + if (typeof arg[i] != 'undefined') { | |
6318 | + v = this.stringify(arg[i]); | |
6319 | + if (s) { | |
6320 | + s += ','; | |
6321 | + } | |
6322 | + s += v; | |
6323 | + } else { | |
6324 | + s += ',null'; | |
6325 | + } | |
6326 | + } | |
6327 | + return '[' + s + ']'; | |
6328 | + } else { | |
6329 | + for (i in arg) { | |
6330 | + if (i != '______array') { | |
6331 | + v = arg[i]; | |
6332 | + if (typeof v != 'undefined' && typeof v != 'function') { | |
6333 | + v = this.stringify(v); | |
6334 | + if (s) { | |
6335 | + s += ','; | |
6336 | + } | |
6337 | + s += this.stringify(i) + ':' + v; | |
6338 | + } | |
6339 | + } | |
6340 | + } | |
6341 | + // return as object | |
6342 | + return '{' + s + '}'; | |
6343 | + } | |
6344 | + } else if (typeof arg.toString != 'undefined') { | |
6345 | + for (i in arg) { | |
6346 | + v = arg[i]; | |
6347 | + if (typeof v != 'undefined' && typeof v != 'function') { | |
6348 | + v = this.stringify(v); | |
6349 | + if (s) { | |
6350 | + s += ','; | |
6351 | + } | |
6352 | + s += this.stringify(i) + ':' + v; | |
6353 | + } | |
6354 | + } | |
6355 | + return '{' + s + '}'; | |
6356 | + } | |
6357 | + } | |
6358 | + return 'null'; | |
6359 | + case 'number': | |
6360 | + return isFinite(arg) ? String(arg) : 'null'; | |
6361 | + case 'string': | |
6362 | + l = arg.length; | |
6363 | + s = '"'; | |
6364 | + for (i = 0; i < l; i += 1) { | |
6365 | + c = arg.charAt(i); | |
6366 | + if (c >= ' ') { | |
6367 | + if (c == '\\' || c == '"') { | |
6368 | + s += '\\'; | |
6369 | + } | |
6370 | + s += c; | |
6371 | + } else { | |
6372 | + switch (c) { | |
6373 | + case '\b': | |
6374 | + s += '\\b'; | |
6375 | + break; | |
6376 | + case '\f': | |
6377 | + s += '\\f'; | |
6378 | + break; | |
6379 | + case '\n': | |
6380 | + s += '\\n'; | |
6381 | + break; | |
6382 | + case '\r': | |
6383 | + s += '\\r'; | |
6384 | + break; | |
6385 | + case '\t': | |
6386 | + s += '\\t'; | |
6387 | + break; | |
6388 | + default: | |
6389 | + c = c.charCodeAt(); | |
6390 | + s += '\\u00' + Math.floor(c / 16).toString(16) + | |
6391 | + (c % 16).toString(16); | |
6392 | + } | |
6393 | + } | |
6394 | + } | |
6395 | + return s + '"'; | |
6396 | + case 'boolean': | |
6397 | + return String(arg); | |
6398 | + default: | |
6399 | + return 'null'; | |
6400 | + } | |
6401 | + }, | |
6402 | + parse: function (text) { | |
6403 | + var at = 0; | |
6404 | + var ch = ' '; | |
6405 | + | |
6406 | + function error(m) { | |
6407 | + throw { | |
6408 | + name: 'JSONError', | |
6409 | + message: m, | |
6410 | + at: at - 1, | |
6411 | + text: text | |
6412 | + }; | |
6413 | + } | |
6414 | + | |
6415 | + function next() { | |
6416 | + ch = text.charAt(at); | |
6417 | + at += 1; | |
6418 | + return ch; | |
6419 | + } | |
6420 | + | |
6421 | + function white() { | |
6422 | + while (ch != '' && ch <= ' ') { | |
6423 | + next(); | |
6424 | + } | |
6425 | + } | |
6426 | + | |
6427 | + function str() { | |
6428 | + var i, s = '', t, u; | |
6429 | + | |
6430 | + if (ch == '"') { | |
6431 | +outer: while (next()) { | |
6432 | + if (ch == '"') { | |
6433 | + next(); | |
6434 | + return s; | |
6435 | + } else if (ch == '\\') { | |
6436 | + switch (next()) { | |
6437 | + case 'b': | |
6438 | + s += '\b'; | |
6439 | + break; | |
6440 | + case 'f': | |
6441 | + s += '\f'; | |
6442 | + break; | |
6443 | + case 'n': | |
6444 | + s += '\n'; | |
6445 | + break; | |
6446 | + case 'r': | |
6447 | + s += '\r'; | |
6448 | + break; | |
6449 | + case 't': | |
6450 | + s += '\t'; | |
6451 | + break; | |
6452 | + case 'u': | |
6453 | + u = 0; | |
6454 | + for (i = 0; i < 4; i += 1) { | |
6455 | + t = parseInt(next(), 16); | |
6456 | + if (!isFinite(t)) { | |
6457 | + break outer; | |
6458 | + } | |
6459 | + u = u * 16 + t; | |
6460 | + } | |
6461 | + s += String.fromCharCode(u); | |
6462 | + break; | |
6463 | + default: | |
6464 | + s += ch; | |
6465 | + } | |
6466 | + } else { | |
6467 | + s += ch; | |
6468 | + } | |
6469 | + } | |
6470 | + } | |
6471 | + error("Bad string"); | |
6472 | + } | |
6473 | + | |
6474 | + function arr() { | |
6475 | + var a = []; | |
6476 | + | |
6477 | + if (ch == '[') { | |
6478 | + next(); | |
6479 | + white(); | |
6480 | + if (ch == ']') { | |
6481 | + next(); | |
6482 | + return a; | |
6483 | + } | |
6484 | + while (ch) { | |
6485 | + a.push(val()); | |
6486 | + white(); | |
6487 | + if (ch == ']') { | |
6488 | + next(); | |
6489 | + return a; | |
6490 | + } else if (ch != ',') { | |
6491 | + break; | |
6492 | + } | |
6493 | + next(); | |
6494 | + white(); | |
6495 | + } | |
6496 | + } | |
6497 | + error("Bad array"); | |
6498 | + } | |
6499 | + | |
6500 | + function obj() { | |
6501 | + var k, o = {}; | |
6502 | + | |
6503 | + if (ch == '{') { | |
6504 | + next(); | |
6505 | + white(); | |
6506 | + if (ch == '}') { | |
6507 | + next(); | |
6508 | + return o; | |
6509 | + } | |
6510 | + while (ch) { | |
6511 | + k = str(); | |
6512 | + white(); | |
6513 | + if (ch != ':') { | |
6514 | + break; | |
6515 | + } | |
6516 | + next(); | |
6517 | + o[k] = val(); | |
6518 | + white(); | |
6519 | + if (ch == '}') { | |
6520 | + next(); | |
6521 | + return o; | |
6522 | + } else if (ch != ',') { | |
6523 | + break; | |
6524 | + } | |
6525 | + next(); | |
6526 | + white(); | |
6527 | + } | |
6528 | + } | |
6529 | + error("Bad object"); | |
6530 | + } | |
6531 | + | |
6532 | + function assoc() { | |
6533 | + var k, a = []; | |
6534 | + | |
6535 | + if (ch == '<') { | |
6536 | + next(); | |
6537 | + white(); | |
6538 | + if (ch == '>') { | |
6539 | + next(); | |
6540 | + return a; | |
6541 | + } | |
6542 | + while (ch) { | |
6543 | + k = str(); | |
6544 | + white(); | |
6545 | + if (ch != ':') { | |
6546 | + break; | |
6547 | + } | |
6548 | + next(); | |
6549 | + a[k] = val(); | |
6550 | + white(); | |
6551 | + if (ch == '>') { | |
6552 | + next(); | |
6553 | + return a; | |
6554 | + } else if (ch != ',') { | |
6555 | + break; | |
6556 | + } | |
6557 | + next(); | |
6558 | + white(); | |
6559 | + } | |
6560 | + } | |
6561 | + error("Bad associative array"); | |
6562 | + } | |
6563 | + | |
6564 | + function num() { | |
6565 | + var n = '', v; | |
6566 | + if (ch == '-') { | |
6567 | + n = '-'; | |
6568 | + next(); | |
6569 | + } | |
6570 | + while (ch >= '0' && ch <= '9') { | |
6571 | + n += ch; | |
6572 | + next(); | |
6573 | + } | |
6574 | + if (ch == '.') { | |
6575 | + n += '.'; | |
6576 | + while (next() && ch >= '0' && ch <= '9') { | |
6577 | + n += ch; | |
6578 | + } | |
6579 | + } | |
6580 | + if (ch == 'e' || ch == 'E') { | |
6581 | + n += 'e'; | |
6582 | + next(); | |
6583 | + if (ch == '-' || ch == '+') { | |
6584 | + n += ch; | |
6585 | + next(); | |
6586 | + } | |
6587 | + while (ch >= '0' && ch <= '9') { | |
6588 | + n += ch; | |
6589 | + next(); | |
6590 | + } | |
6591 | + } | |
6592 | + v = +n; | |
6593 | + if (!isFinite(v)) { | |
6594 | + error("Bad number"); | |
6595 | + } else { | |
6596 | + return v; | |
6597 | + } | |
6598 | + } | |
6599 | + | |
6600 | + function word() { | |
6601 | + switch (ch) { | |
6602 | + case 't': | |
6603 | + if (next() == 'r' && next() == 'u' && next() == 'e') { | |
6604 | + next(); | |
6605 | + return true; | |
6606 | + } | |
6607 | + break; | |
6608 | + case 'f': | |
6609 | + if (next() == 'a' && next() == 'l' && next() == 's' && | |
6610 | + next() == 'e') { | |
6611 | + next(); | |
6612 | + return false; | |
6613 | + } | |
6614 | + break; | |
6615 | + case 'n': | |
6616 | + if (next() == 'u' && next() == 'l' && next() == 'l') { | |
6617 | + next(); | |
6618 | + return null; | |
6619 | + } | |
6620 | + break; | |
6621 | + } | |
6622 | + error("Syntax error"); | |
6623 | + } | |
6624 | + | |
6625 | + function val() { | |
6626 | + white(); | |
6627 | + switch (ch) { | |
6628 | + case '{': | |
6629 | + return obj(); | |
6630 | + case '[': | |
6631 | + return arr(); | |
6632 | + case '<': | |
6633 | + return assoc(); | |
6634 | + case '"': | |
6635 | + return str(); | |
6636 | + case '-': | |
6637 | + return num(); | |
6638 | + default: | |
6639 | + return ch >= '0' && ch <= '9' ? num() : word(); | |
6640 | + } | |
6641 | + } | |
6642 | + | |
6643 | + return val(); | |
6644 | + } | |
6645 | +}; | |
6646 | + | |
6647 | + | |
5299 | 6648 | |
5300 | 6649 | <?php if(extension_loaded('zlib')){ob_end_flush();}?> |
5301 | 6650 | \ No newline at end of file | ... | ... |
ferramentas/wiki/funcoes.php
1 | 1 | <?php |
2 | -error_reporting(0); | |
3 | 2 | //set_time_limit(600); |
4 | 3 | require_once("../../pacotes/cpaint/cpaint2.inc.php"); |
5 | 4 | require_once("../../classesphp/pega_variaveis.php"); |
6 | 5 | require_once("../../classesphp/carrega_ext.php"); |
6 | +error_reporting(0); | |
7 | 7 | $cp = new cpaint(); |
8 | 8 | $cp->register('listaartigos'); |
9 | 9 | $cp->start(); | ... | ... |
ferramentas/wiki/index.js
... | ... | @@ -48,6 +48,8 @@ function buscawiki() |
48 | 48 | } |
49 | 49 | function listaartigos(retorno) |
50 | 50 | { |
51 | + if (retorno.data==undefined ) | |
52 | + {$i("resultadowiki").innerHTML = "Erro. A operação demorou muito.";return;} | |
51 | 53 | var ins = "<p>A busca no Mediawiki traz apenas os 20 primeiros resultados" |
52 | 54 | ins += "<p>Se a abrangência geográfica de busca for muito grande, pode ocorrer erro devido ao tempo de processamento." |
53 | 55 | ins += '<p>Mais detalhes sobre a busca, veja <a href="http://www.geonames.org" >Geonames</a>' | ... | ... |