PageRenderTime 49ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/htdocs/lib/fortissimo.php

https://github.com/zorkian/fortissimo
PHP | 329 lines | 277 code | 27 blank | 25 comment | 26 complexity | d447737df704a0e0478d3c4d7a7fbccd MD5 | raw file
  1. <?php
  2. # include needful things
  3. require_once("config.php"); # better be in the same path as us...!
  4. # bring in object classes
  5. require_once("EVEObject.php");
  6. require_once("EVERegion.php");
  7. require_once("EVEConstellation.php");
  8. require_once("EVESystem.php");
  9. # extra things we need to run
  10. require_once("db.php");
  11. require_once("user.php");
  12. require_once("eveheader.php");
  13. require_once("session.php");
  14. require_once("parser.php");
  15. require_once("universe.php");
  16. # now bring in Smarty library
  17. require_once("$_INC_PATH/Smarty.class.php");
  18. # setup a custom smarty object
  19. class Fortissimo extends Smarty {
  20. var $dbh = null;
  21. var $eve = null;
  22. function Fortissimo() {
  23. global $_APP_PATH, $_INC_PATH, $_WEB_URL;
  24. # basically we are a Smarty
  25. $this->Smarty();
  26. $this->debugging = false; # FIXME DISABLE THIS XXX FIXME TODO LOLLERSKATES FIXME
  27. # setup paths
  28. $this->template_dir = "$_APP_PATH/_ft_templates/";
  29. $this->compile_dir = "$_APP_PATH/_ft_templates_c/";
  30. $this->config_dir = "$_APP_PATH/_ft_configs/";
  31. $this->cache_dir = "$_APP_PATH/_ft_cache/";
  32. # other options
  33. $this->caching = false; # TODO: TRUE eventually?
  34. # parses out EVE IGB information
  35. $this->eve = new EVEHeader;
  36. # jump out early if need be
  37. if ($this->eve->usingIGB() && ! strstr($_SERVER['SCRIPT_NAME'], '/igb')) {
  38. # they aren't on the igb page and they are in the igb, redirect them
  39. $this->redirect($_WEB_URL . "/igb.php");
  40. exit;
  41. }
  42. # get a database
  43. $this->dbh = new DBH();
  44. # set some default options
  45. $this->title("(untitled page)");
  46. $this->assign('SITEROOT', $_WEB_URL);
  47. }
  48. # custom page display with header/footer templates
  49. function makepage($resource_name, $cache_id = null, $compile_id = null) {
  50. $this->assign('links', get_sorted_links());
  51. $this->display("header.tpl");
  52. $this->display($resource_name . ".tpl", $cache_id, $compile_id);
  53. $this->display("footer.tpl");
  54. return;
  55. }
  56. # just assign an error message
  57. function error($errmsg = null) {
  58. if (is_null($errmsg)) {
  59. $errmsg = "Sorry, we ran into an error we couldn't identify. Please try your action again.";
  60. }
  61. $this->assign('error', $errmsg);
  62. return;
  63. }
  64. # display a generic error page
  65. function errorpage($errmsg = null, $page = null) {
  66. if (is_null($errmsg)) {
  67. $errmsg = "Sorry, an unknown error occurred.";
  68. }
  69. if (is_null($page)) {
  70. $page = 'error';
  71. }
  72. $this->error($errmsg);
  73. $this->assign('error', $errmsg);
  74. $this->makepage($page);
  75. return;
  76. }
  77. function igberrorpage($errmsg = null) {
  78. if (is_null($errmsg)) {
  79. $errmsg = "Sorry, an unknown error occurred.";
  80. }
  81. echo("<html><body>$errmsg</body></html>");
  82. return;
  83. }
  84. # set the page title
  85. function message($message = null) {
  86. if (is_null($message)) {
  87. $message = "The server had a message for you, but didn't specify what it was.";
  88. }
  89. $this->assign('message', $message);
  90. }
  91. # set the page title
  92. function title($title) {
  93. $this->assign('title', "Fortissimo - $title");
  94. }
  95. # sets up a redirect
  96. function redirect($url) {
  97. header("Location: $url");
  98. return true;
  99. }
  100. function setup_session() {
  101. # see if the user is logged in
  102. $this->session = new Session();
  103. $this->assign('remote', $this->session->user);
  104. if ($this->session->user) {
  105. $this->assign('admin', $this->session->user->admin());
  106. } else {
  107. $this->assign('admin', false);
  108. }
  109. }
  110. function config($key) {
  111. $val = $this->dbh->_select_one('SELECT cval FROM tbl:config WHERE ckey = ?', array($key));
  112. return $val;
  113. }
  114. function set_config($key, $val) {
  115. $this->dbh->_do_query("REPLACE INTO tbl:config (ckey, cval) VALUES (?, ?)",
  116. array($key, $val));
  117. }
  118. }
  119. # functions we use
  120. function left_box_start($params, &$ft) {
  121. global $_WEB_URL;
  122. $title = $params["title"];
  123. $short = $params["name"];
  124. return '<table align="center" border="0" cellpadding="6" cellspacing="1" class="tborder" width="100%">' .
  125. '<thead><tr><td class="tcatbl smallfont" style="font-weight: bold;">' .
  126. # '<a style="float: right" href="#" onclick="return toggle_collapse(\'forumhome_' . $short . '\')">' .
  127. # '<img id="collapseimg_forumhome_' . $short . '" src="' . $_WEB_URL . '/img/collapse_thead.gif" ' .
  128. # 'width="13" height="13" border="0" alt="Collapse/Expand" /></a>' .
  129. '&raquo;&nbsp; ' . $title .
  130. '</td></tr></thead><tfoot style="display: none;"><tr><td></td></tr></tfoot><tbody ' .
  131. 'id="collapseobj_forumhome_' . $short . '"><tr style=""><td class="alt2">' .
  132. '<table border="0" cellpadding="0" cellspacing="0" width="100%">';
  133. }
  134. function left_box_end($params, &$ft) {
  135. return "</table></td></tr></tbody></table><br />";
  136. }
  137. function left_box_link($params, &$ft) {
  138. $url = $params["url"];
  139. if (substr($url, 0, 1) == '/') {
  140. global $_WEB_URL;
  141. $url = $_WEB_URL . $url;
  142. }
  143. $text = $params["text"];
  144. $extra = $params["extra"];
  145. return '<tr><td height="17" valign="bottom" class="row1">&nbsp;&raquo;&nbsp; ' .
  146. '<a href="' . $url . '">' . $text . '</a> ' . $extra . '</td>';
  147. }
  148. function commify($str) {
  149. $n = strlen($str);
  150. if ($n <= 3) {
  151. $return = $str;
  152. } else {
  153. $pre = substr($str,0,$n-3);
  154. $post = substr($str,$n-3,3);
  155. $pre = commify($pre);
  156. $return = "$pre,$post";
  157. }
  158. return $return;
  159. }
  160. function standings($str) {
  161. $num = $str+0;
  162. $num = sprintf("%0.1f", $num/10);
  163. return $num;
  164. }
  165. function security($str) {
  166. $num = $str+0;
  167. if ($num < 0) {
  168. return "0.0";
  169. } elseif ($num >= 1000000) {
  170. return "1.0";
  171. } else {
  172. return sprintf("%0.1f", $num / 1000000);
  173. }
  174. }
  175. function security_color($str) {
  176. $str = security($str);
  177. $arr = array(
  178. '0.0' => '#ff0000',
  179. '0.1' => '#ff2200',
  180. '0.2' => '#ff4400',
  181. '0.3' => '#ff6600',
  182. '0.4' => '#ff8800',
  183. '0.5' => '#ffaa00',
  184. '0.6' => '#ffcc00',
  185. '0.7' => '#ffff00',
  186. '0.8' => '#aaff00',
  187. '0.9' => '#44ff00',
  188. '1.0' => '#00ff00',
  189. );
  190. return $arr[$str];
  191. }
  192. function maxlen20($str) {
  193. if (strlen($str) > 20) {
  194. $str = substr($str, 0, 17);
  195. $str .= '...';
  196. }
  197. return $str;
  198. }
  199. function isk($str) {
  200. $str = $str+0;
  201. if (preg_match("/^(\d+)\.(\d+)$/", $str, $matches)) {
  202. return commify($matches[1]) . '.' . $matches[2] . ' ISK';
  203. }
  204. return commify($str+0) . " ISK";
  205. }
  206. function minsecs($str) {
  207. return date("H:i", $str);
  208. }
  209. function ymd($str) {
  210. return date("Y-m-d", $str);
  211. }
  212. function this_week() {
  213. $week = date("W", time());
  214. $year = date("Y", time());
  215. return $week + ($year * 100);
  216. }
  217. function this_month() {
  218. $month = date("m", time());
  219. $year = date("Y", time());
  220. return $month + ($year * 100);
  221. }
  222. function this_year() {
  223. return date("Y", time());
  224. }
  225. function how_long_ago($str) {
  226. $n = time() - ($str+0);
  227. if ($n < 60) {
  228. return $n . " secs";
  229. } elseif ($n < 60*60) {
  230. $val = (int)($n / 60);
  231. return $val . " mins";
  232. } elseif ($n < 24*60*60) {
  233. $val = (int)($n / (60*60));
  234. return $val . " hours";
  235. } elseif ($n < 7*24*60*60) {
  236. $val = (int)($n / (24*60*60));
  237. return $val . " days";
  238. } elseif ($n < 365*24*60*60) {
  239. $val = (int)($n / (7*24*60*60));
  240. return $val . " weeks";
  241. } else {
  242. return "ages";
  243. }
  244. }
  245. function hide_location($k) {
  246. if (is_null($k)) {
  247. return 0;
  248. }
  249. $since = time() - $k->killtime;
  250. if ($since < 0) {
  251. $since = 1;
  252. }
  253. $warmode = get_corp_warmode($k->killer->corp_id);
  254. if ($warmode > 0) {
  255. if ($since > ($warmode*60*60)) {
  256. return 0;
  257. } else {
  258. return 1;
  259. }
  260. }
  261. $warmode = get_corp_warmode($k->victim->corp_id);
  262. if ($warmode > 0) {
  263. if ($since > ($warmode*60*60)) {
  264. return 0;
  265. } else {
  266. return 1;
  267. }
  268. } else {
  269. return 0;
  270. }
  271. return 1;
  272. }
  273. function cisort($a, $b) {
  274. $la = strtolower($a);
  275. $lb = strtolower($b);
  276. if ($la == $lb) {
  277. return 0;
  278. }
  279. return ($la > $lb) ? 1 : -1;
  280. }
  281. # now we create a basic object for them to use
  282. global $ft;
  283. $ft = new Fortissimo;
  284. $ft->setup_session();
  285. # now give them a global remote object
  286. global $remote;
  287. $remote = $ft->session->user;
  288. # and now define some functions we're going to need later, perhaps
  289. $ft->register_function("left_box_start", "left_box_start");
  290. $ft->register_function("left_box_end", "left_box_end");
  291. $ft->register_function("left_box_link", "left_box_link");
  292. $ft->register_modifier("commify", "commify");
  293. $ft->register_modifier("isk", "isk");
  294. $ft->register_modifier("standings", "standings");
  295. $ft->register_modifier("security", "security");
  296. $ft->register_modifier("security_color", "security_color");
  297. $ft->register_modifier("minsecs", "minsecs");
  298. $ft->register_modifier("how_long_ago", "how_long_ago");
  299. $ft->register_modifier("maxlen20", "maxlen20");
  300. ?>