common.php 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  1. <?php
  2. function printHeader()
  3. {
  4. require 'include/header-inc.php';
  5. }
  6. function printFooter()
  7. {
  8. require 'include/footer-inc.php';
  9. }
  10. function detectBrowser()
  11. {
  12. $user_agent = strtolower($_SERVER['HTTP_USER_AGENT']);
  13. if (strstr($user_agent, 'opera')) {
  14. return 'opera';
  15. } elseif (strstr($user_agent, 'msie')) {
  16. return 'msie';
  17. } elseif ((strstr($user_agent, 'konqueror')) || (strstr($user_agent, 'safari'))) {
  18. return 'khtml';
  19. } elseif (strstr($user_agent, 'gecko')) {
  20. return 'mozilla';
  21. } elseif (strstr($user_agent, 'mozilla/4')) {
  22. return 'ns4';
  23. } elseif (strstr($user_agent, 'lynx')) {
  24. return 'lynx';
  25. } elseif (strstr($user_agent, 'links')) {
  26. return 'links';
  27. } else {
  28. return false;
  29. }
  30. }
  31. function img($url, $alt, $wid, $hei, $id = '')
  32. {
  33. if ($wid != 0) $wid .= 'px'; if ($hei != 0) $hei .= 'px';
  34. return "<img src=\"images/$url\" alt=\"$alt\" style=\"width:$wid;height:$hei;\" " . (empty($id) ? '' : "id=\"$id\" ") . "/>";
  35. }
  36. function printBlock($text, $block_type = 'p')
  37. {
  38. echo "<$block_type>" . htmlentities($text) . "</$block_type>";
  39. }
  40. function getFileSize($file)
  41. {
  42. $size = filesize($file);
  43. for ($si = 0; $size >= 1024; $size /= 1024, $si++);
  44. return round($size, 1) . ' ' . trim(substr(' KMGT', $si, 1)) . 'B';
  45. }
  46. function getLinkToBug($id, $label) {
  47. return '<a href="http://sourceforge.net/p/freesynd/bugs/' . $id . '/">'. $label . '</a>';
  48. }
  49. function getLinkToFeature($id, $label) {
  50. return '<a href="http://sourceforge.net/p/freesynd/feature-requests/' . $id . '/">'. $label . '</a>';
  51. }
  52. function replaceLink($str) {
  53. $res = $str;
  54. $start = 0;
  55. $end = 0;
  56. while (($start = stripos($res,"[[")) !== false) {
  57. if (($end = stripos($res, "]]", $start)) !== false) {
  58. $href = trim(substr($res, $start + 2, $end - $start - 2));
  59. $label = $href;
  60. $pos = strpos($href, ' ');
  61. if ($pos !== false) {
  62. $label = trim(substr($href, $pos));
  63. $href = trim(substr($href, 0, $pos));
  64. }
  65. $link = '<a href="' . $href . '">'. $label . '</a>';
  66. $res = substr($res, 0, $start) . $link . substr($res, $end + 2);
  67. } else {
  68. return $str;
  69. }
  70. }
  71. return $res;
  72. }
  73. function replaceHTMLTag($str) {
  74. $res = $str;
  75. $start = 0;
  76. $end = 0;
  77. while (($start = stripos($res,'{{')) !== false) {
  78. if (($end = stripos($res, '}}', $start)) !== false) {
  79. $tag = ' <' . trim(substr($res, $start + 2, $end - $start - 2)) . '> ';
  80. $res = substr($res, 0, $start) . $tag . substr($res, $end + 2);
  81. } else {
  82. return $str;
  83. }
  84. }
  85. return $res;
  86. }
  87. function newsItem($title, $content, $submitter, $date, $id)
  88. {
  89. // News title
  90. echo '<a name="n' . $id . '">&nbsp;</a>';
  91. echo '<h3>' . htmlentities($title) . "</h3>\n";
  92. // News content
  93. $arr = explode("\n", $content);
  94. $openedPar = false;
  95. foreach ($arr as &$line) {
  96. $trimLine = trim($line);
  97. $trimLine = replaceLink($trimLine);
  98. $trimLine = replaceHTMLTag($trimLine);
  99. if (strlen($trimLine) == 0 && $openedPar == true) {
  100. echo "</p>\n";
  101. $openedPar = false;
  102. } else {
  103. if ($openedPar == false) {
  104. $openedPar = true;
  105. echo "<p>";
  106. }
  107. echo $trimLine . "\n";
  108. }
  109. }
  110. if ($openedPar == true) {
  111. echo "</p>\n";
  112. }
  113. // News submitter and date
  114. echo '<div class="rght_algn"><b> -- ' . htmlentities($submitter)
  115. . '</b><br />' . htmlentities($date) . "</div>\n\n";
  116. }
  117. function roadmapItem($id, $content, $status, $isBug)
  118. {
  119. $statusLabel = '';
  120. $style = '';
  121. switch( (String) $status) {
  122. case 'D': // Item completed
  123. $statusLabel = '(Done)';
  124. $style = ' style = "text-decoration:line-through"';
  125. break;
  126. case 'P': // Item postponed
  127. $statusLabel = '(Postponed)';
  128. $style = ' style = "text-decoration:line-through"';
  129. break;
  130. case 'C': // item canceled
  131. $statusLabel = '(Canceled)';
  132. $style = ' style = "text-decoration:line-through"';
  133. break;
  134. case 'T': // item is being tested
  135. $statusLabel = '(Testing)';
  136. $style = ' style = "text-decoration:underline"';
  137. break;
  138. case 'I': // item is being coded
  139. $statusLabel = '(Coding)';
  140. $style = ' style = "text-decoration:underline"';
  141. break;
  142. }
  143. if ($isBug) {
  144. echo '<li><span' . $style . '>' . getLinkToBug($id, $id) . '&nbsp;' . $content . '</span>&nbsp;' . $statusLabel . "</li>\n";
  145. } else {
  146. echo '<li><span' . $style . '>' . getLinkToFeature($id, $id) . '&nbsp;' . $content . '</span>&nbsp;' . $statusLabel . "</li>\n";
  147. }
  148. }
  149. function printRoadMap() {
  150. if (file_exists('data/roadmap.xml')) {
  151. $xml = simplexml_load_file('data/roadmap.xml');
  152. echo "<p><b>" . date("Y-m-d", filemtime('data/roadmap.xml')) . "</b> : " . $xml->status . "</p>\n";
  153. echo "<h4>Features :</h4>\n";
  154. echo " <ul>\n";
  155. foreach ($xml->features->feature as $feat) {
  156. roadmapItem($feat['id'], $feat, $feat['status'], false);
  157. }
  158. echo " </ul>\n";
  159. echo "<h4>Bugs :</h4>\n";
  160. echo " <ul>\n";
  161. foreach ($xml->bugs->bug as $bug) {
  162. roadmapItem($bug['id'], $bug, $bug['status'], true);
  163. }
  164. echo " </ul>\n";
  165. } else {
  166. echo "No roadmap defined.\n";
  167. }
  168. }
  169. function printNews() {
  170. if (file_exists('data/news.xml')) {
  171. $xml = simplexml_load_file('data/news.xml');
  172. foreach ($xml->item as $item) {
  173. newsItem($item['title'], $item, $item['author'], $item['date'], $item['id']);
  174. }
  175. } else {
  176. echo "No news defined.\n";
  177. }
  178. }
  179. function printStartTime()
  180. {
  181. $now = getdate();
  182. $tz = gettimeofday();
  183. $tz = -$tz['minuteswest'];
  184. $p = 'a';
  185. if ($now['hours'] >= 12) {
  186. $p = 'p';
  187. $now['hours'] -= 12;
  188. }
  189. if ($now['hours'] == 0) {
  190. $now['hours'] = 12;
  191. }
  192. $d = floor($now['hours'] / 10);
  193. $r = $now['hours'] % 10;
  194. echo img("clock/$d.png", $d, 8, 7, 'ho1');
  195. echo img("clock/$r.png", $r, 8, 7, 'ho0');
  196. echo img('clock/colon.png', ':', 5, 7);
  197. $d = floor($now['minutes'] / 10);
  198. $r = $now['minutes'] % 10;
  199. echo img("clock/$d.png", $d, 8, 7, 'mi1');
  200. echo img("clock/$r.png", $r, 8, 7, 'mi0');
  201. echo img('clock/colon.png', ':', 5, 7);
  202. $d = floor($now['seconds'] / 10);
  203. $r = $now['seconds'] % 10;
  204. echo img("clock/$d.png", $d, 8, 7, 'se1');
  205. echo img("clock/$r.png", $r, 8, 7, 'se0');
  206. echo img("clock/$p.png", $p, 6, 5, 'per');
  207. echo img('clock/m.png', 'm', 7, 5);
  208. if ($tz < 0) {
  209. echo img('clock/minus.png', '-', 7, 7, 'tzs');
  210. $tz = -$tz;
  211. } else {
  212. echo img('clock/plus.png', '+', 7, 7, 'tzs');
  213. }
  214. $t = floor($tz / 60);
  215. $d = floor($t / 10);
  216. $r = $t % 10;
  217. echo img("clock/$d.png", $d, 8, 7, 'tz3');
  218. echo img("clock/$r.png", $r, 8, 7, 'tz2');
  219. $t = $tz % 60;
  220. $d = floor($t / 10);
  221. $r = $t % 10;
  222. echo img("clock/$d.png", $d, 8, 7, 'tz1');
  223. echo img("clock/$r.png", $r, 8, 7, 'tz0');
  224. }
  225. function printStartDate()
  226. {
  227. $today = getdate();
  228. $t = floor($today['year'] / 100);
  229. $d = floor($t / 10);
  230. $r = $t % 10;
  231. echo img("clock/$d.png", $d, 8, 7, 'ye3');
  232. echo img("clock/$r.png", $r, 8, 7, 'ye2');
  233. $t = $today['year'] % 100;
  234. $d = floor($t / 10);
  235. $r = $t % 10;
  236. echo img("clock/$d.png", $d, 8, 7, 'ye1');
  237. echo img("clock/$r.png", $r, 8, 7, 'ye0');
  238. echo img('clock/colon.png', ':', 5, 7);
  239. $d = floor($today['mon'] / 10);
  240. $r = $today['mon'] % 10;
  241. echo img("clock/$d.png", $d, 8, 7, 'mo1');
  242. echo img("clock/$r.png", $r, 8, 7, 'mo0');
  243. echo img('clock/colon.png', ':', 5, 7);
  244. $d = floor($today['mday'] / 10);
  245. $r = $today['mday'] % 10;
  246. echo img("clock/$d.png", $d, 8, 7, 'da1');
  247. echo img("clock/$r.png", $r, 8, 7, 'da0');
  248. echo img('clock/nc.png', 'nc', 11, 5);
  249. }
  250. ?>