view.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338
  1. <?php
  2. /*
  3. *
  4. * OGP - Open Game Panel
  5. * Copyright (C) 2008 - 2018 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, $OGPLangPre;
  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. $fc = array(
  103. $path . MODULES . $module."/".$subpage.".css",
  104. $path . MODULES . $module."/".$module.".css",
  105. MODULES . $module."/".$subpage.".css",
  106. MODULES . $module."/".$module.".css"
  107. );
  108. foreach($fc as $file_check){
  109. if(file_exists($file_check)){
  110. $this->header_code .= "<link rel='stylesheet' href='".$file_check."'>\n";
  111. break;
  112. }
  113. }
  114. $module_name = isset($_GET['m']) ? get_lang($_GET['m']) : "";
  115. $page_name = isset($_GET['p']) ? get_lang($_GET['p']) : "";
  116. $title = $page_name == "" ? $module_name : "$module_name - $page_name";
  117. $title = str_replace("_", " ", $title);
  118. $this->title = $title == "" ? $this->title : $this->title . " [$title]";
  119. // Include jQuery, jQuery UI, and our global CSS file in the header code
  120. $this->header_code .= '<link rel="stylesheet" href="js/jquery/ui/jquery-ui.min.css">' . "\n";
  121. $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";
  122. // Include magnific popup
  123. $this->header_code .= '<script type="text/javascript" src="js/magnific/magnific.js"></script>' . "\n";
  124. $this->header_code .= '<link rel="stylesheet" href="js/magnific/magnific.css">' . "\n";
  125. // Include tablesorter, table collapse, and quick search
  126. $this->header_code .= '<script type="text/javascript" src="js/jquery/plugins/jquery.tablesorter.collapsible.js"></script>' . "\n";
  127. $this->header_code .= '<script type="text/javascript" src="js/jquery/plugins/jquery.tablesorter.min.js"></script>' . "\n";
  128. $this->header_code .= '<script type="text/javascript" src="js/jquery/plugins/jquery.quicksearch.js"></script>' . "\n";
  129. // Dump defined constants to json (for language javascript)
  130. $jsonStrConsts = getOGPLangConstantsJSON();
  131. if($jsonStrConsts !== false){
  132. $this->header_code .= '<script type="text/javascript">var langConsts = ' . $jsonStrConsts . ';' . "\n" . 'var langConstPrefix = "' . $OGPLangPre . '";</script>' . "\n";
  133. }
  134. // Include our global JS
  135. $this->header_code .= '<script type="text/javascript" src="js/global.js"></script>' . "\n";
  136. if ($db->isModuleInstalled('tickets')) {
  137. $this->header_code .= '<script type="text/javascript" src="modules/tickets/js/notifications.js"></script>' . "\n";
  138. }
  139. $fc = array(
  140. $path . MODULES . $module."/".$subpage.".js",
  141. $path . MODULES . $module."/".$module.".js"
  142. );
  143. foreach($fc as $file_check){
  144. if(file_exists($file_check)){
  145. $this->header_code .= "<script type='text/javascript' src='".$file_check."'></script>\n";
  146. break;
  147. }
  148. }
  149. $buffer = ob_get_contents();
  150. ob_end_clean();
  151. if ( !empty($this->refreshUrl) )
  152. {
  153. if ( $panel_settings['page_auto_refresh'] == "1" )
  154. {
  155. $topbody .= "<div id='refresh-manual'>";
  156. if($this->refreshUrl != "{CURRENT_PAGE}"){
  157. $topbody .= "<a href='".$this->refreshUrl."' class='redirectLink'>".get_lang('redirecting_in')." ".$this->refreshTime."s.</a>";
  158. }else{
  159. $url = "//{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}";
  160. $escaped_url = htmlspecialchars( $url, ENT_QUOTES, 'UTF-8' );
  161. $topbody .= "<a href='" . $escaped_url . "' class='redirectLink'>".get_lang('redirecting_in')." ".$this->refreshTime."s.</a>";
  162. }
  163. $topbody .= "</div>";
  164. $this->meta .= "<meta http-equiv='refresh' content='".$this->refreshTime.";";
  165. if($this->refreshUrl != "{CURRENT_PAGE}"){
  166. $this->meta .= "url=".$this->refreshUrl;
  167. }
  168. $this->meta .= "' />";
  169. }
  170. else
  171. {
  172. $topbody .= "<div id='refresh-manual'>";
  173. if($this->refreshUrl != "{CURRENT_PAGE}"){
  174. $topbody .= "<a href='" . $this->refreshUrl . "'>".get_lang('refresh_page')."</a>";
  175. }else{
  176. $url = "//{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}";
  177. $escaped_url = htmlspecialchars( $url, ENT_QUOTES, 'UTF-8' );
  178. $topbody .= "<a href='" . $escaped_url . "'>".get_lang('refresh_page')."</a>";
  179. }
  180. $topbody .= "</div>";
  181. }
  182. }
  183. $footer = "";
  184. if ( is_object($db) && array_key_exists( "OGPDatabase", class_parents($db) ) ) {
  185. $footer .= "<div class=\"footer center\">";
  186. $footer .= get_lang_f('cur_theme', !empty($_SESSION['users_theme']) ? $_SESSION['users_theme'] : @$panel_settings['theme']) . " - " . $db->getNbOfQueries()." ".get_lang('queries_executed');
  187. $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' lang='" . get_lang('copied') . "'></span></div></div>";
  188. }
  189. else
  190. {
  191. $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>";
  192. }
  193. // Add our magnific popup holder to the page (hidden element):
  194. $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>';
  195. if (!isset($_GET['action']))
  196. {
  197. $filename = 'install.php';
  198. if ( !empty($_SESSION['users_theme']) ) $theme = $_SESSION['users_theme'];
  199. else $theme = $panel_settings['theme'];
  200. // Attempt to automatically delete the install file only if an admin user has already been created and exists
  201. if(is_object($db)){
  202. $admins = $db->getAdmins();
  203. if (file_exists($filename) && is_array($admins) && !empty($admins)) {
  204. unlink($filename);
  205. }
  206. }
  207. if (is_readable($filename))
  208. {
  209. if (is_readable($filename) AND $theme == "Modern")
  210. {
  211. $top = "<h4 class='failure'>".get_lang('remove_install')."</h4>".$top;
  212. }
  213. else
  214. {
  215. $topbody = "<h4 class='failure'>".get_lang('remove_install')."</h4>".$topbody;
  216. }
  217. }
  218. }
  219. if ( isset($panel_settings['maintenance_mode']) && $panel_settings['maintenance_mode'] == "1" )
  220. {
  221. if ( !empty($_SESSION['users_theme']) ) $theme = $_SESSION['users_theme'];
  222. else $theme = $panel_settings['theme'];
  223. if (@$_SESSION['users_group'] == "admin" AND $theme == "Modern")
  224. {
  225. $top = "<h4 class='failure'>".get_lang('maintenance_mode_on')."!</b></h4>".$top;
  226. }
  227. elseif (@$_SESSION['users_group'] == "admin")
  228. {
  229. $topbody = "<h4 class='failure'>".get_lang('maintenance_mode_on')."!</b></h4>".$topbody;
  230. }
  231. }
  232. if($cleared){
  233. $page = $buffer;
  234. }
  235. else
  236. {
  237. $page = str_replace("%meta%",$this->meta,$page);
  238. $top = str_replace("%logo%",$this->logo,$top);
  239. $topbody = str_replace("%bg_wrapper%",$this->bg_wrapper,$topbody);
  240. if ( !empty($_SESSION['users_theme']) )
  241. $theme = $_SESSION['users_theme'];
  242. else
  243. $theme = @$panel_settings['theme'];
  244. $page = str_replace("%bg_wrapper%",$this->bg_wrapper,$page);
  245. $page = str_replace("%title%",$this->title,$page);
  246. $page = str_replace("%header_code%",$this->header_code,$page);
  247. $page = str_replace("%charset%",$this->charset,$page);
  248. $page = str_replace("%body%",$buffer,$page);
  249. $page = str_replace("%top%",$top,$page);
  250. $page = str_replace("%topbody%",$topbody,$page);
  251. $page = str_replace("%botbody%",$botbody,$page);
  252. $page = str_replace("%bottom%",$bottom,$page);
  253. $page = str_replace("%footer%",$footer,$page);
  254. $page = str_replace("%notifications%",@$notifications,$page);
  255. }
  256. // Set the content-type header as this is needed by older browsers
  257. if($dataType == "html"){
  258. header("Content-type: text/html; charset=" . $this->charset);
  259. }else if($dataType == "json"){
  260. header("Content-type: application/json; charset=" . $this->charset);
  261. }
  262. // Print everything for the template.
  263. print $page;
  264. }
  265. function refresh($url,$time = "")
  266. {
  267. if ( !empty($time) || $time === 0 )
  268. $this->refreshTime = $time;
  269. $this->refreshUrl = $url;
  270. }
  271. function setTitle($title)
  272. {
  273. $this->title = $title;
  274. }
  275. function setCharset($charset)
  276. {
  277. $this->charset = $charset;
  278. ini_set('default_charset', $charset);
  279. }
  280. function setTimeZone($time_zone)
  281. {
  282. $time_zone = (!isset($time_zone) or $time_zone == "") ? "America/Chicago" : $time_zone;
  283. $this->time_zone = $time_zone;
  284. ini_set('date.timezone', $time_zone);
  285. $_SESSION['time_zone'] = $time_zone;
  286. }
  287. }
  288. ?>