1
0

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