Advertisement
AnrDaemon

XML-compliant PHP+Smarty embedded template.

Jul 4th, 2016
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 6.34 KB | None | 0 0
  1. <?php
  2.  
  3. require_once 'console_hack.php';
  4. require_once '_library_init.php';
  5.  
  6. $smarty = new Smarty();
  7.  
  8. $smarty->setConfigDir( $_SERVER['DOCUMENT_ROOT']);
  9.  
  10. if(!is_dir($_SERVER['DOCUMENT_ROOT'] . '/cache'))
  11.   mkdir($_SERVER['DOCUMENT_ROOT'] . '/cache');
  12. $smarty->setCacheDir(  $_SERVER['DOCUMENT_ROOT'] . '/cache');
  13.  
  14. if(!is_dir($_SERVER['DOCUMENT_ROOT'] . '/cache/templates'))
  15.   mkdir($_SERVER['DOCUMENT_ROOT'] . '/cache/templates');
  16. $smarty->setCompileDir($_SERVER['DOCUMENT_ROOT'] . '/cache/templates');
  17.  
  18. // add before current plugins directory:
  19. $pluginsDirs = $smarty->getPluginsDir();
  20. if(!is_dir($_SERVER['DOCUMENT_ROOT'] . '/plugins'))
  21.   mkdir($_SERVER['DOCUMENT_ROOT'] . '/plugins');
  22. array_unshift($pluginsDirs, $_SERVER['DOCUMENT_ROOT'] . '/plugins');
  23. $smarty->setPluginsDir($pluginsDirs);
  24.  
  25. $smarty->force_compile = defined('TEST_FORCE_COMPILE') ? TEST_FORCE_COMPILE : true;
  26.  
  27. $smarty->registerFilter('pre',
  28.   function($tpl_source, Smarty_Internal_Template $template)
  29.   {
  30.     $stack = stristr($tpl_source, '__HALT' . '_COMPILER');
  31.     $tpl = substr($stack, strpos($stack, '?'.'>') + 2);
  32.     return $tpl ?: $tpl_source;
  33.   }
  34. );
  35.  
  36. $smarty->left_delimiter = '<![CDATA[';
  37. $smarty->right_delimiter = ']]>';
  38. $smarty->assign('equip', array(
  39.     'helmet',
  40.     'chestplate',
  41.     'leggings',
  42.     'boots',
  43.   ));
  44. $smarty->assign('wield', array('equipped',));
  45. $smarty->display(__FILE__);
  46. __halt_compiler();
  47. ?><?xml version="1.0" encoding="UTF-8"?>
  48. <config>
  49.     <lines at="topleft">
  50.         <line>
  51.             <str>Day {day}, </str>
  52.             <if>
  53.                 <var>daytime</var>
  54.                 <str>$2</str>
  55.                 <str>$4</str>
  56.             </if>
  57.             <str>{mctime}$r</str>
  58.         </line>
  59.         <line>
  60.             <str>Light: </str>
  61.             <max>
  62.                 <var>light</var>
  63.                 <num>7.5</num>
  64.                 <str>$e</str>
  65.                 <str>$c</str>
  66.             </max>
  67.             <var>light</var>
  68.             <str>$r / </str>
  69.             <max>
  70.                 <var>lightfeet</var>
  71.                 <num>7.5</num>
  72.                 <str>$e</str>
  73.                 <str>$c</str>
  74.             </max>
  75.             <var>lightfeet</var>
  76.             <str>$r</str>
  77.         </line>
  78.         <line>
  79.             <str> </str>
  80.         </line>
  81. <![CDATA[foreach $equip as $item]]>
  82.         <line>
  83.             <if>
  84.                 <equal>
  85.                     <var><![CDATA[$item]]>name</var>
  86.                     <str/>
  87.                 </equal>
  88.                 <str/>
  89.                 <concat>
  90.                     <str>{<![CDATA[$item]]>icon} {<![CDATA[$item]]>name} </str>
  91.                     <if>
  92.                         <greater>
  93.                             <var><![CDATA[$item]]>damageleft</var>
  94.                             <num>0</num>
  95.                         </greater>
  96.                         <op>
  97.                             <str>gt</str>
  98.                             <pct>
  99.                                 <var><![CDATA[$item]]>damageleft</var>
  100.                                 <var><![CDATA[$item]]>maxdamage</var>
  101.                             </pct>
  102.                             <num>50</num> <num>20</num> <num>10</num>
  103.                             <str>$e</str> <str>$6</str> <str>$c</str> <str>$4</str>
  104.                         </op>
  105.                     </if>
  106.                     <max>
  107.                         <var><![CDATA[$item]]>damageleft</var>
  108.                         <num>0.5</num>
  109.                         <str>{<![CDATA[$item]]>damageleft}$r / $e{<![CDATA[$item]]>maxdamage}</str>
  110.                         <str/>
  111.                     </max>
  112.                 </concat>
  113.             </if>
  114.         </line>
  115. <![CDATA[/foreach]]>
  116.         <line>
  117.             <if>
  118.                 <and>
  119. <![CDATA[foreach $equip as $item]]>
  120.                     <equal><str/><var><![CDATA[$item]]>name</var></equal>
  121. <![CDATA[/foreach]]>
  122.                 </and>
  123.                 <str/>
  124.                 <str> </str>
  125.             </if>
  126.         </line>
  127. <![CDATA[foreach $wield as $item]]>
  128.         <line>
  129.             <if>
  130.                 <equal>
  131.                     <var><![CDATA[$item]]>name</var>
  132.                     <str/>
  133.                 </equal>
  134.                 <str/>
  135.                 <concat>
  136.                     <str>{<![CDATA[$item]]>icon} {<![CDATA[$item]]>name} </str>
  137.                     <if>
  138.                         <greater>
  139.                             <var><![CDATA[$item]]>damageleft</var>
  140.                             <num>0</num>
  141.                         </greater>
  142.                         <op>
  143.                             <str>gt</str>
  144.                             <pct>
  145.                                 <var><![CDATA[$item]]>damageleft</var>
  146.                                 <var><![CDATA[$item]]>maxdamage</var>
  147.                             </pct>
  148.                             <num>50</num> <num>20</num> <num>10</num> <num>0</num>
  149.                             <str>$e</str> <str>$6</str> <str>$c</str> <str>$4</str>
  150.                             <str/>
  151.                         </op>
  152.                     </if>
  153.                     <max>
  154.                         <var><![CDATA[$item]]>damageleft</var>
  155.                         <num>0.5</num>
  156.                         <str>{<![CDATA[$item]]>damageleft}$r / $e{<![CDATA[$item]]>maxdamage}</str>
  157.                         <str/>
  158.                     </max>
  159.                 </concat>
  160.             </if>
  161.         </line>
  162. <![CDATA[/foreach]]>
  163.         <line>
  164.             <if>
  165.                 <equal>
  166.                     <var>equippedname</var>
  167.                     <str/>
  168.                 </equal>
  169.                 <str/>
  170.                 <str> </str>
  171.             </if>
  172.         </line>
  173. <![CDATA[for $i=0 to 15]]>
  174.         <line>
  175.             <if>
  176.                 <var>potionnegative<![CDATA[$i]]></var>
  177.                 <str>$c</str>
  178.             </if>
  179.             <op>
  180.                 <str>eq</str>
  181.                 <str/>
  182.                 <var>potioneffect<![CDATA[$i]]></var>
  183.                 <str/>
  184.                 <str>{potionicon<![CDATA[$i]]>} {potioneffect<![CDATA[$i]]>}$r </str>
  185.             </op>
  186.             <max>
  187.                 <var>potiondurationticks<![CDATA[$i]]></var>
  188.                 <num>10</num>
  189.                 <str>{yellow}{potionduration<![CDATA[$i]]>}{reset}</str>
  190.                 <str/>
  191.             </max>
  192.         </line>
  193. <![CDATA[/for]]>    </lines>
  194. </config>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement