PageRenderTime 38ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/lib/func/misc.func.php

http://domuslink.googlecode.com/
PHP | 160 lines | 92 code | 11 blank | 57 comment | 22 complexity | 4644483d687adc06104c28020fc626d3 MD5 | raw file
  1. <?php
  2. /*
  3. * domus.Link :: PHP Web-based frontend for Heyu (X10 Home Automation)
  4. * Copyright (c) 2007, Istvan Hubay Cebrian (istvan.cebrian@domus.link.co.pt)
  5. * Project's homepage: http://domus.link.co.pt
  6. * Project's dev. homepage: http://domuslink.googlecode.com
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope's that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details. You should have
  17. * received a copy of the GNU General Public License along with
  18. * this program; if not, write to the Free Software Foundation,
  19. * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  20. */
  21. /**
  22. * List dir contents - be it directories or files
  23. *
  24. * Description: List's a specified directories contents, while excluding README files, ., .., and .svn
  25. *
  26. * @param $dir to get listing from
  27. */
  28. function list_dir_content($dir) {
  29. $dn = opendir($dir);
  30. $exclude = array("README", ".", "..", ".svn");
  31. while($fn = readdir($dn)) {
  32. if ($fn == $exclude[0] || $fn == $exclude[1] || $fn == $exclude[2] || $fn == $exclude[3]) continue;
  33. $files[] = $fn;
  34. }
  35. sort($files);
  36. closedir($dn);
  37. return $files;
  38. }
  39. /**
  40. * Label Parse
  41. *
  42. * Description: Parses labels so that underscores (_) are either removed or added in substituition of spaces.
  43. * Letters are also converted to lowercase or first letter is capitilized.
  44. *
  45. * @param $str represent string to parse
  46. * @param $add boolean if true add "_" and change case to lower case, if false remove "_" and capitalize first letter of each word)
  47. */
  48. function label_parse($str, $add = false) {
  49. if ($add) {
  50. $strf2 = str_replace(" ", "_", $str);
  51. // $strf2 = strtolower($strf1);
  52. }
  53. else {
  54. $strf1 = str_replace("_", " ", $str);
  55. $strf1a = str_replace(".", " ", $strf1);
  56. $strf2 = str_replace("-", " ", $strf1a);
  57. // $strf2 = ucwords($strf1);
  58. }
  59. return $strf2;
  60. }
  61. /**
  62. * Uptime
  63. *
  64. * Description: Return the result for the uptime command
  65. *
  66. */
  67. function uptime() {
  68. try {
  69. $rs = execute_cmd("uptime", true);
  70. return $rs[0];
  71. }
  72. catch(Exception $e) {
  73. return "";
  74. }
  75. }
  76. /**
  77. * Description: Generate error page.
  78. *
  79. * @param $cmd represent command being executed (if any)
  80. * @param $rs represents an array with error messages
  81. */
  82. function gen_error($cmd, $rs) {
  83. global $config;
  84. if (!is_array($rs)) $rs = array($rs);
  85. if ($cmd) array_push($rs, "Exec: ".$cmd);
  86. $_SESSION['errors'] = array_reverse($rs);
  87. header("Location: ".$config['url_path']."/error.php");
  88. }
  89. function yesnoopt($value) {
  90. if (strtoupper($value) == "YES") {
  91. return "<option selected value='YES'>YES</option>\n" .
  92. "<option value='NO'>NO</option>\n";
  93. }
  94. else {
  95. return "<option value='YES'>YES</option>\n" .
  96. "<option selected value='NO'>NO</option>\n";
  97. }
  98. }
  99. function dawnduskopt($value) {
  100. if (strtoupper($value) == "FIRST") {
  101. return "<option selected value='FIRST'>FIRST</option>\n" .
  102. "<option value='EARLIEST'>EARLIEST</option>\n" .
  103. "<option value='LATEST'>LATEST</option>\n" .
  104. "<option value='AVERAGE'>AVERAGE</option>\n" .
  105. "<option value='MEDIAN'>MEDIAN</option>\n";
  106. }
  107. elseif (strtoupper($value) == "EARLIEST") {
  108. return "<option value='FIRST'>FIRST</option>\n" .
  109. "<option selected value='EARLIEST'>EARLIEST</option>\n" .
  110. "<option value='LATEST'>LATEST</option>\n" .
  111. "<option value='AVERAGE'>AVERAGE</option>\n" .
  112. "<option value='MEDIAN'>MEDIAN</option>\n";
  113. }
  114. elseif (strtoupper($value) == "LATEST") {
  115. return "<option value='FIRST'>FIRST</option>\n" .
  116. "<option value='EARLIEST'>EARLIEST</option>\n" .
  117. "<option selected value='LATEST'>LATEST</option>\n" .
  118. "<option value='AVERAGE'>AVERAGE</option>\n" .
  119. "<option value='MEDIAN'>MEDIAN</option>\n";
  120. }
  121. elseif (strtoupper($value) == "AVERAGE") {
  122. return "<option value='FIRST'>FIRST</option>\n" .
  123. "<option value='EARLIEST'>EARLIEST</option>\n" .
  124. "<option value='LATEST'>LATEST</option>\n" .
  125. "<option selected value='AVERAGE'>AVERAGE</option>\n" .
  126. "<option value='MEDIAN'>MEDIAN</option>\n";
  127. }
  128. elseif (strtoupper($value) == "MEDIAN") {
  129. return "<option value='FIRST'>FIRST</option>\n" .
  130. "<option value='EARLIEST'>EARLIEST</option>\n" .
  131. "<option value=LATEST>LATEST</option>\n" .
  132. "<option value='AVERAGE'>AVERAGE</option>\n" .
  133. "<option selected value='MEDIAN'>MEDIAN</option>\n";
  134. }
  135. }
  136. /**
  137. * Description: Checks if function mb_substr exists and if not create a mb_substr function
  138. *
  139. * @param $str The string being checked.
  140. * @param $start The first position used in str .
  141. * @param $length The maximum length of the returned string
  142. * @param $enconding The encoding parameter is the character encoding.
  143. */
  144. if (!function_exists("mb_substr")) {
  145. function mb_substr ($str,$start,$length='',$encoding='') {
  146. return substr($str,$start,$length);
  147. }
  148. }
  149. ?>