view.php 13 KB

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