Example #1
0
 public function generateClientScript()
 {
     $sJsURI = $this->sJsURI;
     $aJsFiles = $this->aJsFiles;
     if ($sJsURI != '' && substr($sJsURI, -1) != '/') {
         $sJsURI .= '/';
     }
     if ($this->bDeferScriptGeneration == true) {
         $sJsURI .= 'xajax_js/';
     }
     $aJsFiles[] = array($this->_getScriptFilename('xajax_js/xajax_core.js'), 'xajax');
     if (true === $this->bDebug) {
         $aJsFiles[] = array($this->_getScriptFilename('xajax_js/xajax_debug.js'), 'xajax.debug');
     }
     if (true === $this->bVerboseDebug) {
         $aJsFiles[] = array($this->_getScriptFilename('xajax_js/xajax_verbose.js'), 'xajax.debug.verbose');
     }
     if (null !== $this->sLanguage) {
         $aJsFiles[] = array($this->_getScriptFilename('xajax_js/xajax_lang_' . $this->sLanguage . '.js'), 'xajax');
     }
     $sCrLf = "\n";
     echo $sCrLf;
     echo '<';
     echo 'script type="text/javascript" ';
     echo $this->sDefer;
     echo 'charset="UTF-8">';
     echo $sCrLf;
     echo '/* <';
     echo '![CDATA[ */';
     echo $sCrLf;
     echo 'try { if (undefined == typeof xajax.config) xajax.config = {};  } catch (e) { xajax = {}; xajax.config = {};  };';
     echo $sCrLf;
     echo 'xajax.config.requestURI = "';
     echo $this->sRequestURI;
     echo '";';
     echo $sCrLf;
     echo 'xajax.config.statusMessages = ';
     echo $this->sStatusMessages;
     echo ';';
     echo $sCrLf;
     echo 'xajax.config.waitCursor = ';
     echo $this->sWaitCursor;
     echo ';';
     echo $sCrLf;
     echo 'xajax.config.version = "';
     echo $this->sVersion;
     echo '";';
     echo $sCrLf;
     echo 'xajax.config.defaultMode = "';
     echo $this->sDefaultMode;
     echo '";';
     echo $sCrLf;
     echo 'xajax.config.defaultMethod = "';
     echo $this->sDefaultMethod;
     echo '";';
     echo $sCrLf;
     echo 'xajax.config.JavaScriptURI = "';
     echo $this->sJsURI;
     echo '";';
     echo $sCrLf;
     echo 'xajax.config.responseType = "';
     echo $this->sResponseType;
     echo '";';
     if (false === (null === $this->nResponseQueueSize)) {
         echo $sCrLf;
         echo 'xajax.config.responseQueueSize = ';
         echo $this->nResponseQueueSize;
         echo ';';
     }
     if (true === $this->bDebug) {
         if (false === (null === $this->sDebugOutputID)) {
             echo $sCrLf;
             echo 'xajax.debug = {};';
             echo $sCrLf;
             echo 'xajax.debug.outputID = "';
             echo $this->sDebugOutputID;
             echo '";';
         }
     }
     if (0 < $this->nScriptLoadTimeout) {
         foreach ($aJsFiles as $aJsFile) {
             //				echo '<';
             //				echo 'script type="text/javascript" ';
             //				echo $this->sDefer;
             //				echo 'charset="UTF-8">';
             echo $sCrLf;
             echo '/* <';
             echo '![CDATA[ */';
             echo $sCrLf;
             echo 'window.setTimeout(';
             echo $sCrLf;
             echo ' function() {';
             echo $sCrLf;
             echo '  var scriptExists = false;';
             echo $sCrLf;
             echo '  try { if (';
             echo $aJsFile[1];
             echo '.isLoaded) scriptExists = true; }';
             echo $sCrLf;
             echo '  catch (e) {}';
             echo $sCrLf;
             echo '  if (!scriptExists) {';
             echo $sCrLf;
             echo '   alert("Error: the ';
             echo $aJsFile[1];
             echo ' Javascript component could not be included. Perhaps the URL is incorrect?\\nURL: ';
             echo $sJsURI;
             echo $aJsFile[0];
             echo '");';
             echo $sCrLf;
             echo '  }';
             echo $sCrLf;
             echo ' }, ';
             echo $this->nScriptLoadTimeout;
             echo ');';
             echo $sCrLf;
             //				echo '/* ]]> */';
             //				echo $sCrLf;
             //				echo '<';
             //				echo '/script>';
             //				echo $sCrLf;
         }
     }
     echo $sCrLf;
     echo '/* ]]> */';
     echo $sCrLf;
     echo '<';
     echo '/script>';
     echo $sCrLf;
     if (true === $this->bDeferScriptGeneration) {
         $sHash = $this->generateHash();
         $sOutFile = $sHash . '.js';
         $sOutPath = dirname(dirname(__FILE__)) . '/xajax_js/deferred/';
         if (!is_file($sOutPath . $sOutFile)) {
             ob_start();
             $sInPath = dirname(dirname(__FILE__)) . '/';
             foreach ($aJsFiles as $aJsFile) {
                 print file_get_contents($sInPath . $aJsFile[0]);
             }
             print $sCrLf;
             print $this->printPluginScripts();
             $sScriptCode = stripslashes(ob_get_clean());
             require_once dirname(__FILE__) . '/xajaxCompress.inc.php';
             $sScriptCode = xajaxCompressFile($sScriptCode);
             file_put_contents($sOutPath . $sOutFile, $sScriptCode);
         }
         echo '<';
         echo 'script type="text/javascript" src="';
         echo $sJsURI;
         echo 'deferred/';
         echo $sOutFile;
         echo '" ';
         echo $this->sDefer;
         echo 'charset="UTF-8"><';
         echo '/script>';
         echo $sCrLf;
     } else {
         echo $sCrLf;
         echo '<';
         echo 'script type="text/javascript" ';
         echo $this->sDefer;
         echo 'charset="UTF-8">';
         echo $sCrLf;
         echo '/* <';
         echo '![CDATA[ */';
         echo $sCrLf;
         $this->printPluginScripts();
         echo $sCrLf;
         echo '/* ]]> */';
         echo $sCrLf;
         echo '<';
         echo '/script>';
         echo $sCrLf;
         foreach ($aJsFiles as $aJsFile) {
             echo '<';
             echo 'script type="text/javascript" src="';
             echo $sJsURI;
             echo $aJsFile[0];
             echo '" ';
             echo $this->sDefer;
             echo 'charset="UTF-8"><';
             echo '/script>';
             echo $sCrLf;
         }
     }
 }
Example #2
0
 function _compile($sFolder = null, $bWriteFile = true)
 {
     if (null == $sFolder) {
         $sFolder = dirname(__FILE__);
     }
     require_once dirname(__FILE__) . '/xajaxCompress.inc.php';
     $aOutput = array();
     if ($handle = opendir($sFolder)) {
         while (!(false === ($sName = readdir($handle)))) {
             if ('.' != $sName && '..' != $sName && is_dir($sFolder . '/' . $sName)) {
                 $aOutput[] = $this->_compile($sFolder . '/' . $sName, false);
             } else {
                 if (8 < strlen($sName)) {
                     if ('.inc.php' == substr($sName, strlen($sName) - 8, 8)) {
                         $sName = substr($sName, 0, strlen($sName) - 8);
                         $sPath = $sFolder . '/' . $sName . '.inc.php';
                         if ('xajaxAIO' != $sName && 'legacy' != $sName && 'xajaxCompress' != $sName) {
                             if (file_exists($sPath)) {
                                 $aParsed = array();
                                 $aFile = file($sPath);
                                 $nSkip = 0;
                                 foreach (array_keys($aFile) as $sKey) {
                                     if ('//SkipDebug' == substr($aFile[$sKey], 0, 11)) {
                                         ++$nSkip;
                                     } else {
                                         if ('//EndSkipDebug' == substr($aFile[$sKey], 0, 14)) {
                                             --$nSkip;
                                         } else {
                                             if ('//SkipAIO' == substr($aFile[$sKey], 0, 9)) {
                                                 ++$nSkip;
                                             } else {
                                                 if ('//EndSkipAIO' == substr($aFile[$sKey], 0, 12)) {
                                                     --$nSkip;
                                                 } else {
                                                     if ('<' . '?php' == substr($aFile[$sKey], 0, 5)) {
                                                     } else {
                                                         if ('?' . '>' == substr($aFile[$sKey], 0, 2)) {
                                                         } else {
                                                             if (0 == $nSkip) {
                                                                 $aParsed[] = $aFile[$sKey];
                                                             }
                                                         }
                                                     }
                                                 }
                                             }
                                         }
                                     }
                                 }
                                 unset($aFile);
                                 $aOutput[] = xajaxCompressFile(implode('', $aParsed));
                             }
                         }
                     }
                 }
             }
         }
         closedir($handle);
     }
     if ($bWriteFile) {
         $fH = @fopen($sFolder . '/xajaxAIO.inc.php', 'w');
         if (!$fH) {
             trigger_error($this->objLanguageManager->getText('CMPRSAIO:WTERR:01') . $sFolder . $this->objLanguageManager->getText('CMPRSAIO:WTERR:02'), E_USER_ERROR);
         } else {
             fwrite($fH, '<' . '?php ');
             fwrite($fH, implode('', $aOutput));
             fclose($fH);
         }
     }
     return implode('', $aOutput);
 }
Example #3
0
 function _compressSelf($sFolder)
 {
     if (null == $sFolder) {
         $sFolder = dirname(dirname(__FILE__));
     }
     require_once dirname(__FILE__) . '/xajaxCompress.inc.php';
     if ($handle = opendir($sFolder)) {
         while (!(false === ($sName = readdir($handle)))) {
             if ('.' != $sName && '..' != $sName && is_dir($sFolder . '/' . $sName)) {
                 $this->_compressSelf($sFolder . '/' . $sName);
             } else {
                 if (8 < strlen($sName) && 0 == strpos($sName, '.compressed')) {
                     if ('.inc.php' == substr($sName, strlen($sName) - 8, 8)) {
                         $sName = substr($sName, 0, strlen($sName) - 8);
                         $sPath = $sFolder . '/' . $sName . '.inc.php';
                         if (file_exists($sPath)) {
                             $compressedScript = xajaxCompressFile(implode('', file($sPath)));
                             //$sNewPath = $sFolder . '/' . $sName . '.compressed.php';
                             $sNewPath = $sPath;
                             $fH = @fopen($sNewPath, 'w');
                             if (!$fH) {
                                 trigger_error('The xajax compressed file <b>' . $sNewPath . '</b> could not be written to. Error ', E_USER_ERROR);
                             } else {
                                 fwrite($fH, $compressedScript);
                                 fclose($fH);
                             }
                         }
                     }
                 }
             }
         }
         closedir($handle);
     }
 }