code.fastix.org

Dateiansicht:

Datei:Projekte -> PHP,Bash:Template-Übersetzer -> myTemplateToPHP.sh
md5:bb8180ac20006abf52ae0d91b7149437
sha1:e6d599cf813ebb8f5a84fc34141d68ee545bbd7a
Download-Link:Download
  1. #! /bin/bash
  2. ### file ~/bin/myTemplateToPHP.sh
  3.  
  4. ### Description: Replace simple placeholders with PHP-native syntax.
  5. ### Version: 1.1.3
  6.  
  7. htmlSafeMode='yes';
  8. placeHolderLeft='{{';
  9. placeHolderRight='}}';
  10.  
  11. if [ "no" == ${htmlSafeMode} ]; then
  12.     replacementLeft="<?=\$tpl['";
  13.     replacementRight="'];?>";
  14. else
  15.     replacementLeft="<?=htmlspecialchars\( \$tpl['";
  16.     replacementRight="'] \);?>";
  17. fi
  18.  
  19. placeHolderLeft=$(echo  ${placeHolderLeft}  | sed 's/#/\\#/g');
  20. placeHolderRight=$(echo ${placeHolderRight} | sed 's/#/\\#/g');
  21. replacementLeft=$(echo  ${replacementLeft}  | sed 's/#/\\#/g');
  22. replacementRight=$(echo ${replacementRight} | sed 's/#/\\#/g');
  23.  
  24. sedSkriptFile=$(mktemp --suffix '.sed');
  25. echo "s#${placeHolderLeft}#${replacementLeft}#g"    > "${sedSkriptFile}";
  26. echo "s#${placeHolderRight}#${replacementRight}#g" >> "${sedSkriptFile}";
  27.  
  28. while [ $1 ]; do
  29.     fileIn=$1;
  30.     fileOut=$(echo ${fileIn} | sed -s 's#\.txt$#.php#i');
  31.     if [ ${fileOut} != ${fileIn} ]; then
  32.         if [ -r "${fileIn}" ]; then
  33.             touch "${fileOut}";
  34.             sed -f "${sedSkriptFile}" < ${fileIn} > "${fileOut}";
  35.             if [ "0" == "$?" ]; then
  36.                 echo "Success: Has generated the '${fileOut}' from '${fileIn}'";
  37.             else
  38.                 echo "Error: Can't generate '${fileOut}' from '${fileIn}' Can you write '${fileOut}'?";
  39.                 hasErrors='1';
  40.             fi
  41.         else
  42.             echo "Error: Can't read from '${fileIn}'. Filename incorrect? Rights?";
  43.             hasErrors='1';
  44.         fi
  45.     else
  46.         echo "Error: Input File  '${fileIn}' ending on '.php'. This is unwanted. Rename the File to '.txt' or show your argumentlist. (Do not start ${0} with asterix as argumentlist)";
  47.         hasErrors='1';
  48.     fi
  49.     shift;
  50. done;
  51.  
  52. if [ hasErrors == "1" ]; then
  53.     echo "You can show the sed-skript: '${sedSkriptFile}'";
  54. else
  55.     rm "${sedSkriptFile}";
  56. fi