Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> templates jak w phpbb
vtuner
post
Post #1





Grupa: Zarejestrowani
Postów: 220
Pomógł: 10
Dołączył: 23.08.2005
Skąd: Łódź

Ostrzeżenie: (0%)
-----


Jak prosto zrobić aby sam kod funkcji itp. będą w samym pliku test.php natomiast caly wyglad w test.tpl w phpbb jest cos takiego:
  1. <?php
  2. $template->set_filenames(array(
  3. 'body' => 'test.tpl')
  4. );
  5. ?>


i potem odpowiednie odwolania do roznych czesci strony
  1. <?php
  2. $template->assign_vars(array(
  3. 'MARKETCONFIGINFO' => "$marketinfo",
  4. 'MARKETTABLETITLE' => "Stwórz lub Zmodyfikuj swój Market",
  5. 'S_CONFIG_ACTION' => append_sid('admin_shop.' . $phpEx),
  6. 'MARKETTITLE' => "Edycja Marketu",
  7. 'MARKETGENERAL' => $lang['conf_config'],
  8. 'MARKETSETTINGS' => $lang['conf_conf'],
  9. 'MARKETCOMMISIONS' => $lang['commissions'],
  10. 'MARKETEXPLAIN' => "Sekcja ta służy do tworzenia lub modyfikowania powstałego Marketu.",
  11. 'MARKETGLASS' => $board_config['market_glass'])
  12. );
  13. ?>


patrzylem na te wszytkie funcje assign_vars i set_filenames ale one maja odwołania w całym kodzie forum. Czy można to jakość w prostrzy sposob zrobic??
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
Dex1987
post
Post #2





Grupa: Zarejestrowani
Postów: 246
Pomógł: 0
Dołączył: 28.09.2004

Ostrzeżenie: (0%)
-----


kiedys napisalem funkcje do obslugi szablonow... duzo jej do doskonalosci, ale moze sam ja skonczysz, oto kod

  1. <?php
  2.  
  3. class TemplateManager {
  4.  
  5. var $TemplateName;
  6. var $TemplateContent;
  7.  
  8. var $Varible;
  9. var $Section;
  10.  
  11. var $TemplatesDir = "templates/default";
  12. var $CacheDir  = "cache/templates";
  13.  
  14. function AssignVarible ($VaribleName, $VaribleValue) {
  15.  
  16. $this -> Varible[$VaribleName] = $VaribleValue;
  17. $this -> Section[$VaribleName] = $VaribleValue;
  18. }
  19.  
  20. function TemplateDisplay ($TemplateName) {
  21.  
  22. $this -> TemplateName  = $TemplateName;
  23. $this -> TemplateContent = "<?php /* File compiled from '" .$this -> TemplateName. "' to '" .$this -> TemplateName. ".php' on (date) */ ?>nn";
  24.  
  25. if (!@implode ("", file ($this -> TemplatesDir. "/" .$this -> TemplateName))) {
  26.  
  27. echo "<font face='verdana' size='1'>Nie można otworzyc pliku <b>" .$this -> TemplateName. "</b>.<br></font>";
  28.  
  29. } else {
  30.  
  31. $this -> TemplateContent .= @implode ("", file ($this -> TemplatesDir. "/" .$this -> TemplateName));
  32. }
  33.  
  34. if (preg_match ('/{$([a-zA-Z0-9_]+)}/', $this -> TemplateContent)) {
  35.  
  36. $this -> TemplateContent = preg_replace ('/{$([a-zA-Z0-9_]+)}/', '<?php echo $this -> Varible['$1']; ?>', $this -> TemplateContent);
  37. }
  38.  
  39. if (preg_match ('/{Section[$([a-zA-Z0-9_]+)]}/', $this -> TemplateContent)) {
  40.  
  41. $this -> TemplateContent = preg_replace ('/{Section[$([a-zA-Z0-9_]+)]}/', '<?php for ($this -> Section['start'] = 0; $this -> Section['start'] <= count ($this -> Section['$1'])-1; $this -> Section['start']++) { ?>', $this -> TemplateContent);
  42. }
  43.  
  44. if (preg_match ('/{Section[$([a-zA-Z0-9_]+)].([a-zA-Z0-9_]+)}/', $this -> TemplateContent)) {
  45.  
  46. $this -> TemplateContent = preg_replace ('/{Section[$([a-zA-Z0-9_]+)].([a-zA-Z0-9_]+)}/', '<?php echo $this -> Varible['$1'][$this -> Section['start']]['$2']; ?>', $this -> TemplateContent);
  47. }
  48.  
  49. if (preg_match ('/{/Section}/', $this -> TemplateContent)) {
  50.  
  51. $this -> TemplateContent = preg_replace ('/{/Section}/', '<?php } ?>', $this -> TemplateContent);
  52. }
  53.  
  54. if (preg_match ('/{iteration[$([a-zA-Z0-9_]+)]}/', $this -> TemplateContent)) {
  55.  
  56. $this -> TemplateContent = preg_replace ('/{iteration[$([a-zA-Z0-9_]+)]}/', '<?php echo $this -> Section['start']+1; ?>', $this -> TemplateContent);
  57. }
  58.  
  59. if (preg_match ('/{include=$([a-zA-Z0-9_]+)}/', $this -> TemplateContent)) {
  60.  
  61. $this -> TemplateContent = preg_replace ('/{include=$([a-zA-Z0-9_]+)}/', '<?php include ($this -> Varible['$1']); ?>', $this -> TemplateContent);
  62. }
  63.  
  64. if (preg_match ('/{if $([a-zA-Z0-9_]+) (.*?) "([a-zA-Z0-9_]+)"}/', $this -> TemplateContent)) {
  65.  
  66. $this -> TemplateContent = preg_replace ('/{if $([a-zA-Z0-9_]+) (.*?) "([a-zA-Z0-9_]+)"}/', '<?php if ($this -> Varible['$1'] $2 "$3") { ?>', $this -> TemplateContent);
  67. }
  68. #
  69. if (preg_match ('/{if $([a-zA-Z0-9_]+) == "empty"}/', $this -> TemplateContent)) {
  70.  
  71. $this -> TemplateContent = preg_replace ('/{if $([a-zA-Z0-9_]+) == "empty"}/', '<?php if (empty ($this -> Varible['$1'])) { ?>', $this -> TemplateContent);
  72. }
  73. #
  74. if (preg_match ('/{if Section[$([a-zA-Z0-9_]+)].([a-zA-Z0-9_]+) (.*?) "([a-zA-Z0-9_]+)"}/', $this -> TemplateContent)) {
  75.  
  76. $this -> TemplateContent = preg_replace ('/{if Section[$([a-zA-Z0-9_]+)].([a-zA-Z0-9_]+) (.*?) "([a-zA-Z0-9_]+)"}/', '<?php if ($this -> Varible['$1'][$this -> Section['start']]['$2'] $3 "$4") { ?>', $this -> TemplateContent);
  77. }
  78.  
  79. if (preg_match ('/{else}/', $this -> TemplateContent)) {
  80.  
  81. $this -> TemplateContent = preg_replace ('/{else}/', '<?php } else { ?>', $this -> TemplateContent);
  82. }
  83.  
  84. if (preg_match ('/{/if}/', $this -> TemplateContent)) {
  85.  
  86. $this -> TemplateContent = preg_replace ('/{/if}/', '<?php } ?>', $this -> TemplateContent);
  87. }
  88.  
  89. if (!$file_open = @fopen ($this -> CacheDir. "/" .$this -> TemplateName. ".php", 'w')) {
  90.  
  91. echo "<font face='verdana' size='1'>Nie można utworzyć pliku wykonywalnego dla systemu szablonów: <b>" .$this -> TemplateName. ".php</b>.<br></font>";
  92. }
  93.  
  94. if (!@fputs ($file_open, $this -> TemplateContent)) {
  95.  
  96. echo "<font face='verdana' size='1'>Błąd zapisu do pliku: <b>" .$this -> TemplateName. "</b>.<br></font>";
  97. }
  98.  
  99. if (!@fclose ($file_open)) {
  100.  
  101. echo "<font face='verdana' size='1'>Błąd przy zamykaniu pliku: <b>" .$this -> TemplateName. "</b>.<br></font>";
  102. }
  103.  
  104. if (!include ($this -> CacheDir. "/" .$this -> TemplateName. ".php")) {
  105.  
  106. echo "<font face='verdana' size='1'>Błąd dołączenia sparsowanego pliku: <b>" .$this -> TemplateName. "</b>.<br></font>";
  107. }
  108. }
  109. }
  110.  
  111. ?>
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 6.10.2025 - 14:44