Guest User

Untitled

a guest
Nov 4th, 2017
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.69 KB | None | 0 0
  1. <?php
  2. /**
  3. * Template parsing engine.
  4. *
  5. * @package MyAAC
  6. * @author Slawkens <slawkens@gmail.com>
  7. * @copyright 2017 MyAAC
  8. * @version 0.6.6
  9. * @link http://my-aac.org
  10. */
  11. defined('MYAAC') or die('Direct access not allowed!');
  12.  
  13. // template
  14. $template_name = $config['template'];
  15. if($config['template_allow_change'])
  16. {
  17. if(isset($_GET['template']))
  18. {
  19. $template_name = $_GET['template'];
  20. if(!preg_match("/[^A-z0-9_\-]/", $template_name)) { // validate template
  21. //setcookie('template', $template_name, 0, BASE_DIR . '/', $_SERVER["SERVER_NAME"]);
  22. setSession('template', $template_name);
  23. header('Location:' . getSession('last_uri'));
  24. }
  25. else
  26. $template_name = $config['template'];
  27. }
  28. else {
  29. $template_session = getSession('template');
  30. if ($template_session !== false) {
  31. if (!preg_match("/[^A-z0-9_\-]/", $template_session)) {
  32. $template_name = $template_session;
  33. } else {
  34. $template_name = $config['template'];
  35. }
  36. }
  37. }
  38. }
  39. $template_path = 'templates/' . $template_name;
  40.  
  41. if(!file_exists($template_path . '/index.php') &&
  42. !file_exists($template_path . '/template.php') &&
  43. !file_exists($template_path . '/layout.php'))
  44. {
  45. $template_name = 'kathrine';
  46. $template_path = 'templates/' . $template_name;
  47. }
  48.  
  49. $file = $template_path . '/config.ini';
  50. $exists = file_exists($file);
  51. if($exists || ($config['backward_support'] && file_exists($template_path . '/layout_config.ini')))
  52. {
  53. if(!$exists)
  54. $file = $template_path . '/layout_config.ini';
  55.  
  56. if($cache->enabled())
  57. {
  58. $tmp = '';
  59. if($cache->fetch('template_ini_' . $template_name, $tmp))
  60. $template_ini = unserialize($tmp);
  61. else
  62. {
  63. $template_ini = parse_ini_file($file);
  64. $cache->set('template_ini_' . $template_name, serialize($template_ini));
  65. }
  66. }
  67. else
  68. $template_ini = parse_ini_file($file);
  69.  
  70. foreach($template_ini as $key => $value)
  71. $config[$key] = $value;
  72. }
  73. else if(file_exists($template_path . '/config.php'))
  74. require($template_path . '/config.php');
  75.  
  76. $template = array();
  77. $template['link_account_manage'] = getLink('account/manage');
  78. $template['link_account_create'] = getLink('account/create');
  79. $template['link_account_lost'] = getLink('account/lost');
  80. $template['link_account_logout'] = getLink('account/logout');
  81.  
  82. $template['link_news_archive'] = getLink('news/archive');
  83.  
  84. $links = array('news', 'changelog', 'rules', 'downloads', 'characters', 'online', 'highscores', 'powergamers', 'lastkills', 'houses', 'guilds', 'wars', 'polls', 'bans', 'team', 'creatures', 'spells', 'commands', 'experienceStages', 'freeHouses', 'serverInfo', 'experienceTable', 'faq', 'points', 'gifts', 'bugtracker', 'gallery');
  85. foreach($links as $link) {
  86. $template['link_' . $link] = getLink($link);
  87. }
  88.  
  89. $template['link_screenshots'] = getLink('gallery');
  90. $template['link_movies'] = getLink('videos');
  91.  
  92. $template['link_gifts_history'] = getLink('gifts', 'history');
  93. if($config['forum'] != '')
  94. {
  95. if(strtolower($config['forum']) == 'site')
  96. $template['link_forum'] = "<a href='" . getLink('forum') . "'>";
  97. else
  98. $template['link_forum'] = "<a href='" . $config['forum'] . "' target='_blank'>";
  99. }
  100.  
  101. $twig->addGlobal('template_path', $template_path);
  102. if($twig_loader && file_exists(BASE . $template_path))
  103. $twig_loader->prependPath(BASE . $template_path);
  104.  
  105. function get_template_menus() {
  106. global $db, $template_name;
  107.  
  108. $menus = array();
  109. $query = $db->query('SELECT `name`, `link`, `category` FROM `' . TABLE_PREFIX . 'menu` WHERE `template` = ' . $db->quote($template_name) . ' ORDER BY `ordering` ASC');
  110. foreach($query->fetchAll() as $menu) {
  111. $menus[$menu['category']][] = array('name' => $menu['name'], 'link' => $menu['link']);
  112. }
  113.  
  114. return $menus;
  115. }
  116. ?>
Add Comment
Please, Sign In to add comment