view.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  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. $fc = array(
  137. $path . MODULES . $module."/".$subpage.".js",
  138. $path . MODULES . $module."/".$module.".js"
  139. );
  140. foreach($fc as $file_check){
  141. if(file_exists($file_check)){
  142. $this->header_code .= "<script type='text/javascript' src='".$file_check."'></script>\n";
  143. break;
  144. }
  145. }
  146. $buffer = ob_get_contents();
  147. ob_end_clean();
  148. if ( !empty($this->refreshUrl) )
  149. {
  150. if ( $panel_settings['page_auto_refresh'] == "1" )
  151. {
  152. $topbody .= "<div id='refresh-manual'>";
  153. if($this->refreshUrl != "{CURRENT_PAGE}"){
  154. $topbody .= "<a href='".$this->refreshUrl."' class='redirectLink'>".get_lang('redirecting_in')." ".$this->refreshTime."s.</a>";
  155. }else{
  156. $url = "//{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}";
  157. $escaped_url = htmlspecialchars( $url, ENT_QUOTES, 'UTF-8' );
  158. $topbody .= "<a href='" . $escaped_url . "' class='redirectLink'>".get_lang('redirecting_in')." ".$this->refreshTime."s.</a>";
  159. }
  160. $topbody .= "</div>";
  161. $this->meta .= "<meta http-equiv='refresh' content='".$this->refreshTime.";";
  162. if($this->refreshUrl != "{CURRENT_PAGE}"){
  163. $this->meta .= "url=".$this->refreshUrl;
  164. }
  165. $this->meta .= "' />";
  166. }
  167. else
  168. {
  169. $topbody .= "<div id='refresh-manual'>";
  170. if($this->refreshUrl != "{CURRENT_PAGE}"){
  171. $topbody .= "<a href='" . $this->refreshUrl . "'>".get_lang('refresh_page')."</a>";
  172. }else{
  173. $url = "//{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}";
  174. $escaped_url = htmlspecialchars( $url, ENT_QUOTES, 'UTF-8' );
  175. $topbody .= "<a href='" . $escaped_url . "'>".get_lang('refresh_page')."</a>";
  176. }
  177. $topbody .= "</div>";
  178. }
  179. }
  180. $footer = "";
  181. if ( is_object($db) && array_key_exists( "OGPDatabase", class_parents($db) ) ) {
  182. $footer .= "<div class=\"footer center\">";
  183. $footer .= get_lang_f('cur_theme', !empty($_SESSION['users_theme']) ? $_SESSION['users_theme'] : @$panel_settings['theme']) . " - " . $db->getNbOfQueries()." ".get_lang('queries_executed');
  184. $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>";
  185. }
  186. else
  187. {
  188. $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>";
  189. }
  190. // Add our magnific popup holder to the page (hidden element):
  191. $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>';
  192. if (!isset($_GET['action']))
  193. {
  194. $filename = 'install.php';
  195. if ( !empty($_SESSION['users_theme']) ) $theme = $_SESSION['users_theme'];
  196. else $theme = $panel_settings['theme'];
  197. // Attempt to automatically delete the install file only if an admin user has already been created and exists
  198. if(is_object($db)){
  199. $admins = $db->getAdmins();
  200. if (file_exists($filename) && is_array($admins) && !empty($admins)) {
  201. unlink($filename);
  202. }
  203. }
  204. if (is_readable($filename))
  205. {
  206. if (is_readable($filename) AND $theme == "Modern")
  207. {
  208. $top = "<h4 class='failure'>".get_lang('remove_install')."</h4>".$top;
  209. }
  210. else
  211. {
  212. $topbody = "<h4 class='failure'>".get_lang('remove_install')."</h4>".$topbody;
  213. }
  214. }
  215. }
  216. if ( isset($panel_settings['maintenance_mode']) && $panel_settings['maintenance_mode'] == "1" )
  217. {
  218. if ( !empty($_SESSION['users_theme']) ) $theme = $_SESSION['users_theme'];
  219. else $theme = $panel_settings['theme'];
  220. if (@$_SESSION['users_group'] == "admin" AND $theme == "Modern")
  221. {
  222. $top = "<h4 class='failure'>".get_lang('maintenance_mode_on')."!</b></h4>".$top;
  223. }
  224. elseif (@$_SESSION['users_group'] == "admin")
  225. {
  226. $topbody = "<h4 class='failure'>".get_lang('maintenance_mode_on')."!</b></h4>".$topbody;
  227. }
  228. }
  229. if($cleared){
  230. $page = $buffer;
  231. }
  232. else
  233. {
  234. $page = str_replace("%meta%",$this->meta,$page);
  235. $top = str_replace("%logo%",$this->logo,$top);
  236. $topbody = str_replace("%bg_wrapper%",$this->bg_wrapper,$topbody);
  237. if ( !empty($_SESSION['users_theme']) )
  238. $theme = $_SESSION['users_theme'];
  239. else
  240. $theme = @$panel_settings['theme'];
  241. $page = str_replace("%bg_wrapper%",$this->bg_wrapper,$page);
  242. $page = str_replace("%title%",$this->title,$page);
  243. $page = str_replace("%header_code%",$this->header_code,$page);
  244. $page = str_replace("%charset%",$this->charset,$page);
  245. $page = str_replace("%body%",$buffer,$page);
  246. $page = str_replace("%top%",$top,$page);
  247. $page = str_replace("%topbody%",$topbody,$page);
  248. $page = str_replace("%botbody%",$botbody,$page);
  249. $page = str_replace("%bottom%",$bottom,$page);
  250. $page = str_replace("%footer%",$footer,$page);
  251. $page = str_replace("%notifications%",@$notifications,$page);
  252. }
  253. // Set the content-type header as this is needed by older browsers
  254. if($dataType == "html"){
  255. header("Content-type: text/html; charset=" . $this->charset);
  256. }else if($dataType == "json"){
  257. header("Content-type: application/json; charset=" . $this->charset);
  258. }
  259. // Print everything for the template.
  260. print $page;
  261. }
  262. function refresh($url,$time = "")
  263. {
  264. if ( !empty($time) || $time === 0 )
  265. $this->refreshTime = $time;
  266. $this->refreshUrl = $url;
  267. }
  268. function setTitle($title)
  269. {
  270. $this->title = $title;
  271. }
  272. function setCharset($charset)
  273. {
  274. $this->charset = $charset;
  275. ini_set('default_charset', $charset);
  276. }
  277. function setTimeZone($time_zone)
  278. {
  279. $time_zone = (!isset($time_zone) or $time_zone == "") ? "America/Chicago" : $time_zone;
  280. $this->time_zone = $time_zone;
  281. ini_set('date.timezone', $time_zone);
  282. $_SESSION['time_zone'] = $time_zone;
  283. }
  284. }
  285. ?>