view.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  1. <?php
  2. /*
  3. *
  4. * OGP - Open Game Panel
  5. * Copyright (C) 2008 - 2017 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. // Our global CSS goes first so that themes can override
  47. $this->header_code = '<link rel="stylesheet" href="css/global.css">' . "\n";
  48. $path = "";
  49. if ( isset($_SESSION['users_theme']) &&
  50. !empty($_SESSION['users_theme']) &&
  51. is_dir( 'themes/'.$_SESSION['users_theme'] ) &&
  52. is_file( 'themes/'.$_SESSION['users_theme'].'/layout.html') )
  53. {
  54. $path = 'themes/'.$_SESSION['users_theme'].'/';
  55. }
  56. // Using default theme if there is not one selected.
  57. else if ( !isset($panel_settings['theme']) )
  58. {
  59. $path = 'themes/Revolution/';
  60. }
  61. else if ( is_dir( 'themes/'.$panel_settings['theme'] ) &&
  62. is_file( 'themes/'.$panel_settings['theme'].'/layout.html') )
  63. {
  64. $path = 'themes/'.$panel_settings['theme'].'/';
  65. }
  66. // In case the theme that was selected is invalid print error and use default.
  67. else
  68. {
  69. $path = 'themes/Revolution/';
  70. }
  71. $page = file_get_contents($path.'layout.html');
  72. @$top = file_get_contents($path.'top.html');
  73. @$bottom = file_get_contents($path.'bottom.html');
  74. @$topbody = file_get_contents($path.'topbody.html');
  75. @$botbody = file_get_contents($path.'botbody.html');
  76. if ( isset($panel_settings['logo_link']) &&
  77. !empty($panel_settings['logo_link']))
  78. $this->logo = $panel_settings['logo_link'];
  79. if ( isset($panel_settings['bg_wrapper']) &&
  80. !empty($panel_settings['bg_wrapper']))
  81. $this->bg_wrapper = $panel_settings['bg_wrapper'];
  82. if ( isset($panel_settings['charset']) &&
  83. !empty($panel_settings['charset']))
  84. {
  85. $this->charset = $panel_settings['charset'];
  86. ini_set('default_charset', $panel_settings['charset']);
  87. }
  88. if ( isset($panel_settings['time_zone']) &&
  89. !empty($panel_settings['time_zone']))
  90. {
  91. $this->time_zone = $panel_settings['time_zone'];
  92. ini_set('date.timezone', $panel_settings['time_zone']);
  93. }
  94. if ( isset($panel_settings['panel_name']) &&
  95. !empty($panel_settings['panel_name']))
  96. $this->title = $panel_settings['panel_name'];
  97. if ( isset($panel_settings['header_code']) &&
  98. !empty($panel_settings['header_code']))
  99. $this->header_code .= $panel_settings['header_code']."\n";
  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'>" . "\n";
  104. elseif( file_exists( MODULES . "$module/$subpage.css" ) )
  105. $this->header_code .= "<link rel='stylesheet' href='" . MODULES . "$module/$subpage.css'>" . "\n";
  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">' . "\n";
  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>' . "\n";
  114. // Include magnific popup
  115. $this->header_code .= '<script type="text/javascript" src="js/magnific/magnific.js"></script>' . "\n";
  116. $this->header_code .= '<link rel="stylesheet" href="js/magnific/magnific.css">' . "\n";
  117. // Include tablesorter, table collapse, and quick search
  118. $this->header_code .= '<script type="text/javascript" src="js/jquery/plugins/jquery.tablesorter.collapsible.js"></script>' . "\n";
  119. $this->header_code .= '<script type="text/javascript" src="js/jquery/plugins/jquery.tablesorter.min.js"></script>' . "\n";
  120. $this->header_code .= '<script type="text/javascript" src="js/jquery/plugins/jquery.quicksearch.js"></script>' . "\n";
  121. // Include our global JS
  122. $this->header_code .= '<script type="text/javascript" src="js/global.js"></script>' . "\n";
  123. if (file_exists($path . MODULES . "$module/$subpage.js")) {
  124. $this->header_code .= '<script type="text/javascript" src="' . $path . MODULES . $module.'/'.$subpage.'.js"></script>' . "\n";
  125. }
  126. $buffer = ob_get_contents();
  127. ob_end_clean();
  128. if ( !empty($this->refreshUrl) )
  129. {
  130. if ( $panel_settings['page_auto_refresh'] == "1" )
  131. {
  132. $topbody .= "<div id='refresh-manual'>";
  133. if($this->refreshUrl != "{CURRENT_PAGE}"){
  134. $topbody .= "<a href='".$this->refreshUrl."' class='redirectLink'>".get_lang('redirecting_in')." ".$this->refreshTime."s.</a>";
  135. }else{
  136. $url = "//{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}";
  137. $escaped_url = htmlspecialchars( $url, ENT_QUOTES, 'UTF-8' );
  138. $topbody .= "<a href='" . $escaped_url . "' class='redirectLink'>".get_lang('redirecting_in')." ".$this->refreshTime."s.</a>";
  139. }
  140. $topbody .= "</div>";
  141. $this->meta .= "<meta http-equiv='refresh' content='".$this->refreshTime.";";
  142. if($this->refreshUrl != "{CURRENT_PAGE}"){
  143. $this->meta .= "url=".$this->refreshUrl;
  144. }
  145. $this->meta .= "' />";
  146. }
  147. else
  148. {
  149. $topbody .= "<div id='refresh-manual'>";
  150. if($this->refreshUrl != "{CURRENT_PAGE}"){
  151. $topbody .= "<a href='" . $this->refreshUrl . "'>".get_lang('refresh_page')."</a>";
  152. }else{
  153. $url = "//{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}";
  154. $escaped_url = htmlspecialchars( $url, ENT_QUOTES, 'UTF-8' );
  155. $topbody .= "<a href='" . $escaped_url . "'>".get_lang('refresh_page')."</a>";
  156. }
  157. $topbody .= "</div>";
  158. }
  159. }
  160. $footer = "";
  161. if ( is_object($db) && array_key_exists( "OGPDatabase", class_parents($db) ) ) {
  162. $footer .= "<div class=\"footer center\">";
  163. $footer .= get_lang_f('cur_theme', !empty($_SESSION['users_theme']) ? $_SESSION['users_theme'] : @$panel_settings['theme']) . " - " . $db->getNbOfQueries()." ".get_lang('queries_executed');
  164. $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>";
  165. }
  166. else
  167. {
  168. $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>";
  169. }
  170. // Add our magnific popup holder to the page (hidden element):
  171. $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>';
  172. if (!isset($_GET['action']))
  173. {
  174. $filename = 'install.php';
  175. if ( !empty($_SESSION['users_theme']) ) $theme = $_SESSION['users_theme'];
  176. else $theme = $panel_settings['theme'];
  177. // Attempt to automatically delete the install file only if an admin user has already been created and exists
  178. if(is_object($db)){
  179. $admins = $db->getAdmins();
  180. if (file_exists($filename) && is_array($admins) && !empty($admins)) {
  181. unlink($filename);
  182. }
  183. }
  184. if (is_readable($filename))
  185. {
  186. if (is_readable($filename) AND $theme == "Modern")
  187. {
  188. $top = "<h4 class='failure'>".get_lang('remove_install')."</h4>".$top;
  189. }
  190. else
  191. {
  192. $topbody = "<h4 class='failure'>".get_lang('remove_install')."</h4>".$topbody;
  193. }
  194. }
  195. }
  196. if ( isset($panel_settings['maintenance_mode']) && $panel_settings['maintenance_mode'] == "1" )
  197. {
  198. if ( !empty($_SESSION['users_theme']) ) $theme = $_SESSION['users_theme'];
  199. else $theme = $panel_settings['theme'];
  200. if (@$_SESSION['users_group'] == "admin" AND $theme == "Modern")
  201. {
  202. $top = "<h4 class='failure'>".get_lang('maintenance_mode_on')."!</b></h4>".$top;
  203. }
  204. elseif (@$_SESSION['users_group'] == "admin")
  205. {
  206. $topbody = "<h4 class='failure'>".get_lang('maintenance_mode_on')."!</b></h4>".$topbody;
  207. }
  208. }
  209. if($cleared){
  210. $page = $buffer;
  211. }
  212. else
  213. {
  214. $page = str_replace("%meta%",$this->meta,$page);
  215. $top = str_replace("%logo%",$this->logo,$top);
  216. $topbody = str_replace("%bg_wrapper%",$this->bg_wrapper,$topbody);
  217. if ( !empty($_SESSION['users_theme']) )
  218. $theme = $_SESSION['users_theme'];
  219. else
  220. $theme = @$panel_settings['theme'];
  221. $page = str_replace("%bg_wrapper%",$this->bg_wrapper,$page);
  222. $page = str_replace("%title%",$this->title,$page);
  223. $page = str_replace("%header_code%",$this->header_code,$page);
  224. $page = str_replace("%charset%",$this->charset,$page);
  225. $page = str_replace("%body%",$buffer,$page);
  226. $page = str_replace("%top%",$top,$page);
  227. $page = str_replace("%topbody%",$topbody,$page);
  228. $page = str_replace("%botbody%",$botbody,$page);
  229. $page = str_replace("%bottom%",$bottom,$page);
  230. $page = str_replace("%footer%",$footer,$page);
  231. $page = str_replace("%notifications%",@$notifications,$page);
  232. }
  233. // Set the content-type header as this is needed by older browsers
  234. if($dataType == "html"){
  235. header("Content-type: text/html; charset=" . $this->charset);
  236. }else if($dataType == "json"){
  237. header("Content-type: application/json; charset=" . $this->charset);
  238. }
  239. // Print everything for the template.
  240. print $page;
  241. }
  242. function refresh($url,$time = "")
  243. {
  244. if ( !empty($time) || $time === 0 )
  245. $this->refreshTime = $time;
  246. $this->refreshUrl = $url;
  247. }
  248. function setTitle($title)
  249. {
  250. $this->title = $title;
  251. }
  252. function setCharset($charset)
  253. {
  254. $this->charset = $charset;
  255. ini_set('default_charset', $charset);
  256. }
  257. function setTimeZone($time_zone)
  258. {
  259. $time_zone = (!isset($time_zone) or $time_zone == "") ? "America/Chicago" : $time_zone;
  260. $this->time_zone = $time_zone;
  261. ini_set('date.timezone', $time_zone);
  262. $_SESSION['time_zone'] = $time_zone;
  263. }
  264. }
  265. ?>