/**
  * This method can be used to create a new xajax.js file out of the
  * xajax_uncompressed.js file (which will only happen if xajax.js doesn't
  * already exist on the filesystem).
  * 
  * @param string an optional argument containing the full server file path
  *               of xajax.js.
  */
 function autoCompressJavascript($sJsFullFilename = NULL)
 {
     $sJsFile = "xajax_js/xajax.js";
     if ($sJsFullFilename) {
         $realJsFile = $sJsFullFilename;
     } else {
         $realPath = realpath(dirname(__FILE__));
         $realJsFile = $realPath . "/" . $sJsFile;
     }
     // Create a compressed file if necessary
     if (!file_exists($realJsFile)) {
         $srcFile = str_replace(".js", "_uncompressed.js", $realJsFile);
         if (!file_exists($srcFile)) {
             trigger_error("The xajax uncompressed Javascript file could not be found in the <b>" . dirname($realJsFile) . "</b> folder. Error ", E_USER_ERROR);
         }
         require dirname(__FILE__) . "/xajaxCompress.php";
         $javaScript = implode('', file($srcFile));
         $compressedScript = xajaxCompressJavascript($javaScript);
         $fH = @fopen($realJsFile, "w");
         if (!$fH) {
             trigger_error("The xajax compressed javascript file could not be written in the <b>" . dirname($realJsFile) . "</b> folder. Error ", E_USER_ERROR);
         } else {
             fwrite($fH, $compressedScript);
             fclose($fH);
         }
     }
 }
Exemple #2
0
 function getJavascript($sJsURI = "", $sJsFile = NULL, $sJsFullFilename = NULL)
 {
     if ($sJsFile == NULL) {
         $sJsFile = "xajax_js/xajax.js";
     }
     if ($sJsURI != "" && substr($sJsURI, -1) != "/") {
         $sJsURI .= "/";
     }
     $html = "\t<script type=\"text/javascript\">\n";
     $html .= "var xajaxRequestUri=\"" . $this->sRequestURI . "\";\n";
     $html .= "var xajaxDebug=" . ($this->bDebug ? "true" : "false") . ";\n";
     $html .= "var xajaxStatusMessages=" . ($this->bStatusMessages ? "true" : "false") . ";\n";
     $html .= "var xajaxWaitCursor=" . ($this->bWaitCursor ? "true" : "false") . ";\n";
     $html .= "var xajaxDefinedGet=" . XAJAX_GET . ";\n";
     $html .= "var xajaxDefinedPost=" . XAJAX_POST . ";\n";
     foreach ($this->aFunctions as $sFunction => $bExists) {
         $html .= $this->_wrap($sFunction, $this->aFunctionRequestTypes[$sFunction]);
     }
     $html .= "</script>\n";
     // Create a compressed file if necessary
     if ($sJsFullFilename) {
         $realJsFile = $sJsFullFilename;
     } else {
         $realPath = realpath(dirname(__FILE__));
         $realJsFile = $realPath . "/" . $sJsFile;
     }
     $srcFile = str_replace(".js", "_uncompressed.js", $realJsFile);
     if (!file_exists($srcFile)) {
         trigger_error("The xajax uncompressed Javascript file could not be found in the <b>" . dirname($realJsFile) . "</b> folder. Error ", E_USER_ERROR);
     }
     if ($this->bDebug) {
         if (!@copy($srcFile, $realJsFile)) {
             trigger_error("The xajax uncompressed javascript file could not be copied to the <b>" . dirname($realJsFile) . "</b> folder. Error ", E_USER_ERROR);
         }
     } else {
         if (!file_exists($realJsFile)) {
             require dirname($realJsFile) . "/xajaxCompress.php";
             $javaScript = implode('', file($srcFile));
             $compressedScript = xajaxCompressJavascript($javaScript);
             $fH = @fopen($realJsFile, "w");
             if (!$fH) {
                 trigger_error("The xajax compressed javascript file could not be written in the <b>" . dirname($realJsFile) . "</b> folder. Error ", E_USER_ERROR);
             } else {
                 fwrite($fH, $compressedScript);
                 fclose($fH);
             }
         }
     }
     $html .= "\t<script type=\"text/javascript\" src=\"" . $sJsURI . $sJsFile . "\"></script>\n";
     return $html;
 }