1
0

view.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  1. <?php
  2. /*
  3. *
  4. * OGP - Open Game Panel
  5. * Copyright (C) Copyright (C) 2008 - 2014 The OGP Development Team
  6. *
  7. * http://www.opengamepanel.org/
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License
  11. * as published by the Free Software Foundation; either version 2
  12. * of the License, or any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  22. *
  23. */
  24. define("DEFAULT_REFRESH_TIME","2");
  25. class OGPView {
  26. private $meta;
  27. private $title;
  28. private $refreshTime;
  29. private $refreshUrl;
  30. function __construct() {
  31. ob_start();
  32. $this->logo = "home.php?m=dashboard&p=dashboard";
  33. $this->bg_wrapper = "";
  34. $this->title = "Open Game Panel";
  35. $this->charset = "utf-8";
  36. $this->refreshTime = DEFAULT_REFRESH_TIME;
  37. }
  38. function __destruct() {
  39. }
  40. function menu(){}
  41. function printView($cleared = false, $dataType = "html") {
  42. global $db;
  43. if ( is_object($db) && array_key_exists( "OGPDatabase", class_parents($db) ) ) {
  44. $panel_settings = $db->getSettings();
  45. }
  46. $path = "";
  47. if ( isset($_SESSION['users_theme']) &&
  48. !empty($_SESSION['users_theme']) &&
  49. is_dir( 'themes/'.$_SESSION['users_theme'] ) &&
  50. is_file( 'themes/'.$_SESSION['users_theme'].'/layout.html') )
  51. {
  52. $path = 'themes/'.$_SESSION['users_theme'].'/';
  53. }
  54. // Using default theme if there is not one selected.
  55. else if ( !isset($panel_settings['theme']) )
  56. {
  57. $path = 'themes/Revolution/';
  58. }
  59. else if ( is_dir( 'themes/'.$panel_settings['theme'] ) &&
  60. is_file( 'themes/'.$panel_settings['theme'].'/layout.html') )
  61. {
  62. $path = 'themes/'.$panel_settings['theme'].'/';
  63. }
  64. // In case the theme that was selected is invalid print error and use default.
  65. else
  66. {
  67. $path = 'themes/Revolution/';
  68. }
  69. $page = file_get_contents($path.'layout.html');
  70. @$top = file_get_contents($path.'top.html');
  71. @$bottom = file_get_contents($path.'bottom.html');
  72. @$topbody = file_get_contents($path.'topbody.html');
  73. @$botbody = file_get_contents($path.'botbody.html');
  74. if ( isset($panel_settings['logo_link']) &&
  75. !empty($panel_settings['logo_link']))
  76. $this->logo = $panel_settings['logo_link'];
  77. if ( isset($panel_settings['bg_wrapper']) &&
  78. !empty($panel_settings['bg_wrapper']))
  79. $this->bg_wrapper = $panel_settings['bg_wrapper'];
  80. if ( isset($panel_settings['charset']) &&
  81. !empty($panel_settings['charset']))
  82. {
  83. $this->charset = $panel_settings['charset'];
  84. ini_set('default_charset', $panel_settings['charset']);
  85. }
  86. if ( isset($panel_settings['time_zone']) &&
  87. !empty($panel_settings['time_zone']))
  88. {
  89. $this->time_zone = $panel_settings['time_zone'];
  90. ini_set('date.timezone', $panel_settings['time_zone']);
  91. }
  92. if ( isset($panel_settings['panel_name']) &&
  93. !empty($panel_settings['panel_name']))
  94. $this->title = $panel_settings['panel_name'];
  95. if ( isset($panel_settings['header_code']) &&
  96. !empty($panel_settings['header_code']))
  97. $this->header_code = $panel_settings['header_code']."\n";
  98. else
  99. $this->header_code = "";
  100. $module = isset($_GET['m']) ? $_GET['m'] : "";
  101. $subpage = isset($_GET['p']) ? $_GET['p'] : $module;
  102. if( file_exists( $path . MODULES . "$module/$subpage.css" ) )
  103. $this->header_code .= "<link rel='stylesheet' href='" . $path . MODULES . "$module/$subpage.css'>";
  104. elseif( file_exists( MODULES . "$module/$subpage.css" ) )
  105. $this->header_code .= "<link rel='stylesheet' href='" . MODULES . "$module/$subpage.css'>";
  106. $module_name = isset($_GET['m']) ? get_lang($_GET['m']) : "";
  107. $page_name = isset($_GET['p']) ? get_lang($_GET['p']) : "";
  108. $title = $page_name == "" ? $module_name : "$module_name - $page_name";
  109. $title = str_replace("_", " ", $title);
  110. $this->title = $title == "" ? $this->title : $this->title . " [$title]";
  111. // Include jQuery, jQuery UI, and our global CSS file in the header code
  112. $this->header_code .= '<link rel="stylesheet" href="js/jquery/ui/jquery-ui.min.css">';
  113. $this->header_code .= '<script type="text/javascript" src="js/jquery/jquery.min.js"></script><script type="text/javascript" src="js/jquery/ui/jquery-ui.min.js"></script>';
  114. // Include magnific popup
  115. $this->header_code .= '<script type="text/javascript" src="js/magnific/magnific.js"></script>';
  116. $this->header_code .= '<link rel="stylesheet" href="js/magnific/magnific.css">';
  117. // Include our global JS and CSS
  118. $this->header_code .= '<script type="text/javascript" src="js/global.js"></script>';
  119. $this->header_code .= '<link rel="stylesheet" href="css/global.css">';
  120. $buffer = ob_get_contents();
  121. ob_end_clean();
  122. if ( !empty($this->refreshUrl) )
  123. {
  124. if ( $panel_settings['page_auto_refresh'] == "1" )
  125. {
  126. $topbody .= "<div id='refresh-manual'>";
  127. if($this->refreshUrl != "{CURRENT_PAGE}"){
  128. $topbody .= "<a href='".$this->refreshUrl."' class='redirectLink'>".get_lang('redirecting_in')." ".$this->refreshTime."s.</a>";
  129. }else{
  130. $url = "//{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}";
  131. $escaped_url = htmlspecialchars( $url, ENT_QUOTES, 'UTF-8' );
  132. $topbody .= "<a href='" . $escaped_url . "' class='redirectLink'>".get_lang('redirecting_in')." ".$this->refreshTime."s.</a>";
  133. }
  134. $topbody .= "</div>";
  135. $this->meta .= "<meta http-equiv='refresh' content='".$this->refreshTime.";";
  136. if($this->refreshUrl != "{CURRENT_PAGE}"){
  137. $this->meta .= "url=".$this->refreshUrl;
  138. }
  139. $this->meta .= "' />";
  140. }
  141. else
  142. {
  143. $topbody .= "<div id='refresh-manual'>";
  144. if($this->refreshUrl != "{CURRENT_PAGE}"){
  145. $topbody .= "<a href='" . $this->refreshUrl . "'>".get_lang('refresh_page')."</a>";
  146. }else{
  147. $url = "//{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}";
  148. $escaped_url = htmlspecialchars( $url, ENT_QUOTES, 'UTF-8' );
  149. $topbody .= "<a href='" . $escaped_url . "'>".get_lang('refresh_page')."</a>";
  150. }
  151. $topbody .= "</div>";
  152. }
  153. }
  154. $footer = "";
  155. if ( is_object($db) && array_key_exists( "OGPDatabase", class_parents($db) ) ) {
  156. $footer .= "<div class=\"footer center\">";
  157. $footer .= get_lang_f('cur_theme', !empty($_SESSION['users_theme']) ? $_SESSION['users_theme'] : @$panel_settings['theme']) . " - " . $db->getNbOfQueries()." ".get_lang('queries_executed');
  158. $footer .= "<br />".get_lang('copyright')." &copy; <a href=\"http://www.opengamepanel.org\">Open Game Panel</a> " . date("Y") . " - ".get_lang('all_rights_reserved')." - <span class='versionInfo'>".get_lang('show_version')."</span><br /><div class='inline-block OGPVersionArea'><span class='version hide'>" . get_lang('version') . ":</span>&nbsp; <span class='hide versionNumber'>".@$panel_settings['ogp_version']."</span> <span class='copyVersionResult'></span></div></div>";
  159. }
  160. else
  161. {
  162. $footer .= "<div class='footer center'>".get_lang('copyright')." &copy; <a href=\"http://www.opengamepanel.org\">Open Game Panel</a> " . date("Y") . " - ".get_lang('all_rights_reserved').".</div>";
  163. }
  164. // Add our magnific popup holder to the page (hidden element):
  165. $footer .= '<div class="mangificWrapper hide"><div class="white-popup"><div class="magnificTitle"></div><div class="magnificSubTitle"></div><div class="magnificContentsDiv"></div><button title="Close (Esc)" type="button" class="mfp-close">&times;</button></div></div>';
  166. if (!isset($_GET['action']))
  167. {
  168. $filename = 'install.php';
  169. if ( !empty($_SESSION['users_theme']) ) $theme = $_SESSION['users_theme'];
  170. else $theme = $panel_settings['theme'];
  171. // Attempt to automatically delete the install file only if an admin user has already been created and exists
  172. if(is_object($db)){
  173. $admins = $db->getAdmins();
  174. if (file_exists($filename) && is_array($admins) && !empty($admins)) {
  175. unlink($filename);
  176. }
  177. }
  178. if (is_readable($filename))
  179. {
  180. if (is_readable($filename) AND $theme == "Modern")
  181. {
  182. $top = "<h4 class='failure'>".get_lang('remove_install')."</h4>".$top;
  183. }
  184. else
  185. {
  186. $topbody = "<h4 class='failure'>".get_lang('remove_install')."</h4>".$topbody;
  187. }
  188. }
  189. }
  190. if ( isset($panel_settings['maintenance_mode']) && $panel_settings['maintenance_mode'] == "1" )
  191. {
  192. if ( !empty($_SESSION['users_theme']) ) $theme = $_SESSION['users_theme'];
  193. else $theme = $panel_settings['theme'];
  194. if (@$_SESSION['users_group'] == "admin" AND $theme == "Modern")
  195. {
  196. $top = "<h4 class='failure'>".get_lang('maintenance_mode_on')."!</b></h4>".$top;
  197. }
  198. elseif (@$_SESSION['users_group'] == "admin")
  199. {
  200. $topbody = "<h4 class='failure'>".get_lang('maintenance_mode_on')."!</b></h4>".$topbody;
  201. }
  202. }
  203. if($cleared){
  204. $page = $buffer;
  205. }
  206. else
  207. {
  208. $page = str_replace("%meta%",$this->meta,$page);
  209. $top = str_replace("%logo%",$this->logo,$top);
  210. $topbody = str_replace("%bg_wrapper%",$this->bg_wrapper,$topbody);
  211. if ( !empty($_SESSION['users_theme']) )
  212. $theme = $_SESSION['users_theme'];
  213. else
  214. $theme = @$panel_settings['theme'];
  215. $page = str_replace("%bg_wrapper%",$this->bg_wrapper,$page);
  216. $page = str_replace("%title%",$this->title,$page);
  217. $page = str_replace("%header_code%",$this->header_code,$page);
  218. $page = str_replace("%charset%",$this->charset,$page);
  219. $page = str_replace("%body%",$buffer,$page);
  220. $page = str_replace("%top%",$top,$page);
  221. $page = str_replace("%topbody%",$topbody,$page);
  222. $page = str_replace("%botbody%",$botbody,$page);
  223. $page = str_replace("%bottom%",$bottom,$page);
  224. $page = str_replace("%footer%",$footer,$page);
  225. $page = str_replace("%notifications%",@$notifications,$page);
  226. }
  227. // Set the content-type header as this is needed by older browsers
  228. if($dataType == "html"){
  229. header("Content-type: text/html; charset=" . $this->charset);
  230. }else if($dataType == "json"){
  231. header("Content-type: application/json; charset=" . $this->charset);
  232. }
  233. // Print everything for the template.
  234. print $page;
  235. }
  236. function refresh($url,$time = "")
  237. {
  238. if ( !empty($time) || $time === 0 )
  239. $this->refreshTime = $time;
  240. $this->refreshUrl = $url;
  241. }
  242. function setTitle($title)
  243. {
  244. $this->title = $title;
  245. }
  246. function setCharset($charset)
  247. {
  248. $this->charset = $charset;
  249. ini_set('default_charset', $charset);
  250. }
  251. function setTimeZone($time_zone)
  252. {
  253. $time_zone = (!isset($time_zone) or $time_zone == "") ? "America/Chicago" : $time_zone;
  254. $this->time_zone = $time_zone;
  255. ini_set('date.timezone', $time_zone);
  256. $_SESSION['time_zone'] = $time_zone;
  257. }
  258. }
  259. ?>