/admin/views/setup/manager/functions.php

https://github.com/Asherontas/Active-CMS · PHP · 167 lines · 135 code · 21 blank · 11 comment · 39 complexity · 24059bb008b96ef152826a8293e63d6a MD5 · raw file

  1. <?php
  2. /**
  3. * Functions
  4. *
  5. * @package CMS Pro
  6. * @author wojoscripts.com
  7. * @copyright 2010
  8. * @version $Id: functions.php,v 1.00 2010-07-20 10:12:05 gewa Exp $
  9. */
  10. function isimage($str)
  11. {
  12. $image_file = array("gif", "jpg", "jpeg", "png", "GIF", "JPG", "JPEG", "PNG");
  13. for ($f = 0; $f < count($image_file); $f++) {
  14. if ($str == $image_file[$f])
  15. return true;
  16. }
  17. return false;
  18. }
  19. function iseditable($str)
  20. {
  21. $edit_file = array("php", "txt", "htm", "html", "php3", "asp", "xml", "css", "inc", "js");
  22. for ($f = 0; $f < count($edit_file); $f++) {
  23. if ($str == $edit_file[$f])
  24. return true;
  25. }
  26. return false;
  27. }
  28. function isviewable($str)
  29. {
  30. $edit_file = array("php", "txt", "htm", "html", "php3", "asp", "xml", "css", "inc", "js");
  31. for ($f = 0; $f < count($edit_file); $f++) {
  32. if ($str == $edit_file[$f])
  33. return true;
  34. }
  35. return false;
  36. }
  37. function getPerms($in_Perms)
  38. {
  39. $sP = '';
  40. // owner
  41. $sP .= (($in_Perms & 0x0100) ? 'r' : '&minus;') . (($in_Perms & 0x0080) ? 'w' : '&minus;') . (($in_Perms & 0x0040) ? (($in_Perms & 0x0800) ? 's' : 'x') : (($in_Perms & 0x0800) ? 'S' : '&minus;'));
  42. // group
  43. $sP .= (($in_Perms & 0x0020) ? 'r' : '&minus;') . (($in_Perms & 0x0010) ? 'w' : '&minus;') . (($in_Perms & 0x0008) ? (($in_Perms & 0x0400) ? 's' : 'x') : (($in_Perms & 0x0400) ? 'S' : '&minus;'));
  44. // world
  45. $sP .= (($in_Perms & 0x0004) ? 'r' : '&minus;') . (($in_Perms & 0x0002) ? 'w' : '&minus;') . (($in_Perms & 0x0001) ? (($in_Perms & 0x0200) ? 't' : 'x') : (($in_Perms & 0x0200) ? 'T' : '&minus;'));
  46. return $sP;
  47. }
  48. function purge($dir)
  49. {
  50. $handle = opendir($dir);
  51. while (false !== ($file = readdir($handle))) {
  52. if ($file != "." && $file != "..") {
  53. if (is_dir($dir . $file)) {
  54. purge($dir . $file . "/");
  55. rmdir($dir . $file);
  56. } else {
  57. unlink($dir . $file);
  58. }
  59. }
  60. }
  61. closedir($handle);
  62. }
  63. function chmoddir($dir, $perm)
  64. {
  65. $handle = opendir($dir);
  66. while (false !== ($file = readdir($handle))) {
  67. if ($file != "." && $file != "..") {
  68. if (is_dir($dir . $file)) {
  69. chmoddir($dir . $file . "/", $perm);
  70. chmod($dir . $file, $perm);
  71. } else {
  72. chmod($dir . $file, $perm);
  73. }
  74. }
  75. }
  76. closedir($handle);
  77. }
  78. function xcopy($basedir, $txtFolderName, $action)
  79. {
  80. if ($handle = @opendir($basedir)) {
  81. while (false !== ($dir = readdir($handle))) {
  82. if ($dir != '.' && $dir != '..') {
  83. if (is_dir($basedir . "/" . $dir)) {
  84. $mkSuccess = mkdir($txtFolderName . "/" . $dir);
  85. xcopy($basedir . "/" . $dir, $txtFolderName . "/" . $dir, $action);
  86. if ($action == "cut")
  87. purge($basedir . "/" . $dir);
  88. } else {
  89. copy($basedir . "/" . $dir, $txtFolderName . "/" . $dir);
  90. if ($action == "cut")
  91. unlink($basedir . "/" . $dir);
  92. }
  93. }
  94. }
  95. closedir($handle);
  96. }
  97. }
  98. function get_sourcecode($filename, $first_line_num = 1, $num_color = "#1DA4F3")
  99. {
  100. $html_code = highlight_file($filename, true);
  101. if (substr($html_code, 0, 6) == "<code>") {
  102. $html_code = substr($html_code, 6, strlen($html_code));
  103. }
  104. $xhtml_convmap = array('<font' => '<span', '</font>' => '</span>', 'color="' => 'style="color:');
  105. $html_code = strtr($html_code, $xhtml_convmap);
  106. $arr_html_code = explode("<br />", $html_code);
  107. $total_lines = count($arr_html_code);
  108. $retval = "";
  109. $line_counter = 0;
  110. $last_line_num = $first_line_num + $total_lines;
  111. foreach ($arr_html_code as $html_line) {
  112. $current_line = $first_line_num + $line_counter;
  113. $retval .= str_repeat("&nbsp;", strlen($last_line_num) - strlen($current_line)) . "<span style=\"color:{$num_color}\">{$current_line}: </span>" . $html_line . "<br />";
  114. $line_counter++;
  115. }
  116. $retval = "<code>" . $retval;
  117. return $retval;
  118. }
  119. function getSize($size, $precision = 2, $long_name = false, $real_size = true)
  120. {
  121. $base = $real_size ? 1024 : 1000;
  122. $pos = 0;
  123. while ($size > $base) {
  124. $size /= $base;
  125. $pos++;
  126. }
  127. $prefix = _getSizePrefix($pos);
  128. @$size_name = ($long_name) ? $prefix . "bytes" : $prefix[0] . "B";
  129. return round($size, $precision) . ' ' . ucfirst($size_name);
  130. }
  131. function _getSizePrefix($pos)
  132. {
  133. switch ($pos) {
  134. case 00:
  135. return "";
  136. case 01:
  137. return "kilo";
  138. case 02:
  139. return "mega";
  140. case 03:
  141. return "giga";
  142. default:
  143. return "?-";
  144. }
  145. }
  146. ?>