PageRenderTime 65ms CodeModel.GetById 13ms RepoModel.GetById 1ms app.codeStats 0ms

/includes/class_style.php

http://thehostingtool.googlecode.com/
PHP | 163 lines | 139 code | 10 blank | 14 comment | 21 complexity | e375a463787ea373d1c9234c50739723 MD5 | raw file
Possible License(s): GPL-3.0, LGPL-2.1
  1. <?php
  2. //////////////////////////////
  3. // The Hosting Tool
  4. // Database (MySQL) Class
  5. // By Jonny H
  6. // Released under the GNU-GPL
  7. //////////////////////////////
  8. //Check if called by script
  9. if(THT != 1){die();}
  10. //Create the class
  11. class style {
  12. # Start the functions #
  13. private function error($name, $template, $func) { #Shows a SQL error from main class
  14. if(INSTALL){
  15. $error['Error'] = $name;
  16. $error['Function'] = $func;
  17. $error['Template'] = $mysqlerror;
  18. global $main;
  19. $main->error($error);
  20. }
  21. }
  22. private function getFile($name, $prepare = 1, $override = 0) { # Returns the content of a file
  23. global $db;
  24. $link = LINK ."../themes/". THEME . "/" . $name;
  25. if(!file_exists($link) || $override != 0) {
  26. $link = LINK . $name;
  27. }
  28. if(!file_exists($link) && INSTALL) {
  29. $error['Error'] = "File doesn't exist!";
  30. $error['Path'] = $link;
  31. global $main;
  32. //$main->error($error);
  33. }
  34. else {
  35. if($prepare) {
  36. return $this->prepare(file_get_contents($link));
  37. }
  38. else {
  39. return file_get_contents($link);
  40. }
  41. }
  42. }
  43. public function prepare($data) { # Returns the content with the THT variables replaced
  44. include(LINK . "variables.php");
  45. return $data;
  46. }
  47. private function prepareCSS($data) { # Returns the CSS with all tags removed
  48. include(LINK . "css_variables.php");
  49. return $data;
  50. }
  51. public function get($template) { # Fetch a template
  52. return $this->getFile($template);
  53. }
  54. public function css() { # Fetches the CSS and prepares it
  55. global $db;
  56. $css = '<style type="text/css">';
  57. $css .= $this->prepareCSS($this->getFile("style.css", 0, 0));
  58. $css .= '</style>' . "\n";
  59. if(FOLDER != "install" && FOLDER != "includes") {
  60. $css .= '<link rel="stylesheet" href="'.URL.'includes/css/'.(INSTALL?$db->config('ui-theme'):'cupertino').'/jquery-ui.css" type="text/css" />';
  61. }
  62. return $css;
  63. }
  64. public function replaceVar($template, $array = 0, $style = 0) { #Fetches a template then replaces all the variables in it with that key
  65. $data = $this->getFile($template, 0, $style);
  66. if($array) {
  67. foreach($array as $key => $value) {
  68. $data = preg_replace("/%". $key ."%/si", $value, $data);
  69. }
  70. }
  71. return $data;
  72. }
  73. public function javascript() { # Returns the HTML code for the header that includes all the JS in the javascript folder
  74. $folder = LINK ."javascript/";
  75. $html .= "<script type=\"text/javascript\" src='".URL."includes/javascript/jquery.js'></script>\n";
  76. if ($handle = opendir($folder)) { # Open the folder
  77. while (false !== ($file = readdir($handle))) { # Read the files
  78. if($file != "." && $file != ".." && $file != "jquery.js" && $file != "simpletip.js") { # Check aren't these names
  79. $base = explode(".", $file); # Explode the file name, for checking
  80. if($base[count($base)-1] == "js") { # Is it a JS?
  81. $html .= "<script type=\"text/javascript\" src='".URL."includes/javascript/{$file}'></script>\n"; # Creates the HTML
  82. }
  83. }
  84. }
  85. }
  86. $html .= "<script type=\"text/javascript\" src='".URL."includes/tinymce/jscripts/tiny_mce/tiny_mce.js'></script>";
  87. closedir($handle); #Close the folder
  88. return $html;
  89. }
  90. public function notice($good, $message) {
  91. if($good) {
  92. //Cool! Everything's OK.
  93. $color = "green";
  94. }
  95. else {
  96. //Oh no! It's a bad message!
  97. $color = "red";
  98. }
  99. $notice = '<strong><em style="color: '. $color .';">';
  100. $notice .= $message;
  101. $notice .= '</em></strong>';
  102. return $notice;
  103. }
  104. // Returns a form input element according to the parameters given
  105. public function createInput($type, $name, $value = "", $extra = array(), $options = array()) {
  106. $type = strtolower(trim($type));
  107. $extraHtml = "";
  108. foreach($extra as $k => $v) {
  109. $extraHtml .= $k.'="'.$v.'" ';
  110. }
  111. switch($type) {
  112. case "textarea":
  113. return '<textarea name="'.$name.'" '.$extraHtml.'>'.htmlspecialchars($value).'</textarea>';
  114. break;
  115. case "select":
  116. $return = '<select name="'.$name.'" '.$extraHtml.'>';
  117. foreach($options as $o) {
  118. if(array_key_exists("disabled", $o) && $o["disabled"]) { $d = " disabled"; } else { $d = ""; }
  119. if(array_key_exists("selected", $o) && $o["selected"]) { $s = " selected"; } else { $s = ""; }
  120. $return .= '<option value="'.$o["value"].'"'.$d.$s.'>'.$o["text"].'</option>';
  121. }
  122. $return .= '</select>';
  123. return $return;
  124. break;
  125. default:
  126. return '<input type="'.$type.'" name="'.$name.'" value="'.$value.'" '.$extraHtml.'/>';
  127. break;
  128. }
  129. }
  130. //Obsolete Functions...
  131. public function update($template, $code) { # Updates a template
  132. global $db;
  133. $query = $db->query("SELECT * FROM `<PRE>templates` WHERE `name` = '{$db->strip($template)}'");
  134. if($db->num_rows($query) == 0) {
  135. $this->error("Template not found!", $template, __FUNCTION__);
  136. }
  137. else {
  138. $db->query("UPDATE `<PRE>templates` SET `code` = '{$db->strip($code)}' WHERE `name` = '{$db->strip($template)}'");
  139. }
  140. }
  141. public function delete($template) { # Gets a query and returns the rows/columns as array
  142. global $db;
  143. $query = $db->query("DELETE * FROM `<PRE>templates` WHERE `name` = '{$db->strip($template)}'");
  144. }
  145. }
  146. //End Template
  147. ?>