inital git commit
[phpns.git] / inc / themecontrol.php
blob7ca9cc3030880ee27cc9ad3fb20c21396cca44d8
1 <?php
3 /* Copyright (c) 2007-08 Alec Henriksen
4 * phpns is free software; you can redistribute it and/or modify it under the
5 * terms of the GNU General Public Licence (GPL) as published by the Free
6 * Software Foundation; either version 2 of the Licence, or (at your option) any
7 * later version.
8 * Please see the GPL at http://www.gnu.org/copyleft/gpl.html for a complete
9 * understanding of what this license means and how to abide by it.
12 include("inc/page_desc.php"); //include the page descriptions
14 //connect to database.themes, and find selected theme
15 $themeres = general_query("SELECT * FROM ".$databaseinfo['prefix']."themes WHERE theme_selected='1' LIMIT 1");
17 //Set variables for paths
18 $admin = "admin.tpl.php";
19 $login = "login.tpl.php";
20 //help.php doesn't have a template.
22 //read the theme data, and get the contents of the selected theme
23 //through output buffering.
24 while ($trow = mysql_fetch_assoc($themeres)) {
25 //change file tread upon page type in global vars
26 if ($globalvars['pagetype'] == "admin") {
28 ob_start(); //start buffer
29 include($trow['theme_dir'].$admin);
30 $file = ob_get_contents(); //get buffer to "file"
31 ob_end_clean(); //end buffer, clean, nothing gets sent to browser, $file has it.
33 } elseif ($globalvars['pagetype'] == "login") {
35 ob_start(); //start buffer
36 include($trow['theme_dir'].$login);
37 $file = ob_get_contents(); //get buffer to "file"
38 ob_end_clean(); //end buffer, done
41 //if file is empty, kill script with error.
42 if (!$file) {
43 die('<p>Phpns could not fetch the '.$globalvars['pagetype'].'tpl.php file located at (in theory) "'.$trow['theme_dir'].'". This could be a problem with file permissions (PHP doesn\'t have permission to the file) or the file was accidentally deleted.</p>');
46 //modification of theme here (var replacement, img fix, ect ect)
47 $uri = $_SERVER['PHP_SELF'];
48 $rep_replace = 'themes/'.$trow['base_dir'].'/';
49 $uri = preg_replace($rep_patt,$rep_replace,$uri);
50 $file = str_replace('{prepath}','http://'.$_SERVER['SERVER_NAME'].$uri,$file); //fix problem.
52 if ($globalvars['pagetype'] == "admin") { //if page is "admin" replace admin vars
53 //admin configuration variables replaced with the system generated content
54 $phpns_logo = '<a href="index.php"><img src="images/logo.png" alt="phpns logo" border="0" /></a>';
55 $current_page_name = $globalvars['page_name'];
57 //generate wysiwyg setting, and act accordingly (to disable/enable)
58 $wysiwyg = load_config('wysiwyg');
60 //if the wysiwyg editor is enabled...
61 if ($wysiwyg['v1'] == 'yes') { $head_include = $head_data['wysiwyg']; }
63 //init tourId
64 if (!@$_GET['tourId']) { $_GET['tourId'] = FALSE; }
65 //if tour is activated through $_GET['tour']
66 if ($_GET['tourId']) {
67 $head_include .= $head_data['tour'];
68 $content .= $head_data['tour_text'];
71 //set the rest of the javascript, after wysiwyg
72 $head_include .= $head_data['other_js'];
74 //declare the variable for the current page image, 3 variations. automatic, custom, or none.
75 if (!$globalvars['page_image']) { //automatic
76 $page_image = '<img src="images/'. $globalvars['page_name'] . '.png" alt="'. $globalvars['page_name'] .'" alt="'.$globalvars['page_name'].' icon" title="'.$globalvars['page_name'].' icon" class="icon" />';
77 } elseif ($globalvars['page_image'] != 'none') { //custom
78 $page_image = '<img src="images/'. $globalvars['page_image'] . '.png" alt="'. $globalvars['page_name'] .'" title="'.$globalvars['page_name'].' icon" class="icon" />';
79 } elseif ($globalvars['page_image'] == 'none') {
80 $page_image = '';
83 //now, we'll actually replace the variables in the theme
84 $file = str_replace('{version}',$globalvars['version'],$file);
85 $file = str_replace('{username}',$_SESSION['username'],$file);
86 $file = str_replace('{head_data}',$head_include,$file);
87 $file = str_replace('{page_image}',$page_image,$file);
88 $file = str_replace('{content}',$content,$file);
89 $file = str_replace('{page_desc}',$page_desc[$globalvars['page_name']],$file);
90 $file = str_replace('{current_page_name}',$current_page_name,$file);
92 //load the global message
93 $global_message = load_config('global_message');
95 //if the trimmed (no whitespace only) global message isn't null, we'll display it.
96 if (trim($global_message['v3']) != NULL) {
97 $important_notice = '<div class="global_message"><div class="global_message_link"><a href="preferences.php?do=globalmessage">[Change Message]</a></div>'.decode_data($global_message['v3']).'</div>';
101 //if the user hasn't hidden messages, show them.
102 if ($_SESSION['hide_sessions'] != TRUE) {
103 //we're going to do a quick check to see if the 'install' directory is installed and
104 //the SQL file from a previous backup is removed. We don't limit the user, but just nag them. =D
105 //ADD TO GLOBAL MESSAGE
106 if (file_exists('install')) {
107 $important_notice .= '<div class="warning"><div class="delete_notice_link"><a href="etc.php?do=hide_warnings&return='.$globalvars['filename'].'">[Hide]</a> <a href="etc.php?do=delete_install&return='.$globalvars['filename'].'">[Attempt to delete]</a></div><strong>Important!</strong> The /install/ directory is still present. Please delete this as soon as possible to avoid security issues.</div>';
109 if (file_exists($databaseinfo['dbname'].'.sql')) {
110 $important_notice .= '<div class="warning"><div class="delete_notice_link"><a href="etc.php?do=hide_warnings&return='.$globalvars['filename'].'">[Hide]</a> <a href="etc.php?do=delete_backup&return='.$globalvars['filename'].'">[Attempt to delete]</a></div><strong>Important!</strong> Phpns has detected the .sql file you generated (/'.$databaseinfo['dbname'].'.sql). Please delete the file to aviod security issues.</div>';
114 //finally, insert all our notices into global_message.
115 $file = str_replace('{all_messages}',$important_notice,$file); //replace login message
117 } elseif ($globalvars['pagetype'] == "login") {
119 //grab the global message and replace vars
120 $global_message = load_config('global_message');
122 $file = str_replace('{content}',$error_message.$content,$file);
123 $file = str_replace('{logo}',$error_message.'<a href="index.php"><img src="images/logo.png" id="logo" class="logo" /></a>',$file);
124 $file = str_replace('{version}',$globalvars['version'],$file);
125 $file = str_replace('{current_page_name}',$current_page_name,$file);
126 $file = str_replace('{head_data}','<script language="javascript" type="text/javascript" src="inc/js/highlight.js"></script>',$file);
127 $file = str_replace('{page_image}','<img src="images/login.png" alt="login image" class="login_image" />',$file);
129 } //end modification of theme
131 echo $file; //output theme, decoded, and vars replaced. Basically the last step in the whole system.
133 //if no $file, display error
134 if ($file == NULL) { echo "<p>The phpns theme control isn't displaying the output of the file. This is probably because there was an error with the theming system.</p>"; }
136 } //end while statement. we're done.