PageRenderTime 44ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/admin/functions/func.admin.common.php

http://avecms.googlecode.com/
PHP | 355 lines | 283 code | 44 blank | 28 comment | 30 complexity | d4f49e031c3fd6400288efbc7e5b2529 MD5 | raw file
Possible License(s): GPL-3.0, BSD-3-Clause, BSD-2-Clause, Apache-2.0, LGPL-2.1
  1. <?php
  2. /**
  3. * AVE.cms
  4. *
  5. * @package AVE.cms
  6. * @subpackage admin
  7. * @filesource
  8. */
  9. /**
  10. * ??????????????? ????? ???????
  11. *
  12. * @param int $file_size ??????
  13. * @return string ????????????? ?????? ? ???????? ?????????
  14. */
  15. function format_size($file_size)
  16. {
  17. if ($file_size >= 1073741824)
  18. {
  19. $file_size = round($file_size / 1073741824 * 100) / 100 . ' Gb';
  20. }
  21. elseif ($file_size >= 1048576)
  22. {
  23. $file_size = round($file_size / 1048576 * 100) / 100 . ' Mb';
  24. }
  25. elseif ($file_size >= 1024)
  26. {
  27. $file_size = round($file_size / 1024 * 100) / 100 . ' Kb';
  28. }
  29. else
  30. {
  31. $file_size = $file_size . ' b';
  32. }
  33. return $file_size;
  34. }
  35. /**
  36. * ?????????? ?? ?? ?????????? ?? ???????? ??????????? ???????
  37. *
  38. */
  39. function get_ave_info()
  40. {
  41. global $AVE_DB, $AVE_Template;
  42. $cnts = array();
  43. $cnts['templates'] = $AVE_DB->Query("SELECT COUNT(*) FROM " . PREFIX . "_templates")->GetCell();
  44. $cnts['documents'] = $AVE_DB->Query("SELECT COUNT(*) FROM " . PREFIX . "_documents")->GetCell();
  45. $cnts['request'] = $AVE_DB->Query("SELECT COUNT(*) FROM " . PREFIX . "_request") ->GetCell();
  46. $cnts['rubrics'] = $AVE_DB->Query("SELECT COUNT(*) FROM " . PREFIX . "_rubrics") ->GetCell();
  47. $sql = $AVE_DB->Query("
  48. SELECT
  49. `Status`,
  50. COUNT(`Status`) AS cntStatus
  51. FROM " . PREFIX . "_module
  52. GROUP BY `Status`
  53. ");
  54. while ($row = $sql->FetchRow())
  55. {
  56. $cnts['modules_' . $row->Status] = $row->cntStatus;
  57. }
  58. $sql = $AVE_DB->Query("
  59. SELECT
  60. status,
  61. COUNT(status) AS cntStatus
  62. FROM " . PREFIX . "_users
  63. GROUP BY status
  64. ");
  65. while ($row = $sql->FetchRow())
  66. {
  67. $cnts['users_' . $row->status] = $row->cntStatus;
  68. }
  69. $AVE_Template->assign('cnts', $cnts);
  70. }
  71. /**
  72. * ?????? ??????????
  73. *
  74. * @param string $directory ???????????? ??????????
  75. * @return int
  76. */
  77. function get_dir_size($directory)
  78. {
  79. if (!is_dir($directory)) return -1;
  80. $size = 0;
  81. if ($DIR = opendir($directory))
  82. {
  83. while (($dirfile = readdir($DIR)) !== false)
  84. {
  85. if (@is_link($directory . '/' . $dirfile) || $dirfile == '.' || $dirfile == '..') continue;
  86. if (@is_file($directory . '/' . $dirfile))
  87. {
  88. $size += filesize($directory . '/' . $dirfile);
  89. }
  90. elseif (@is_dir($directory . '/' . $dirfile))
  91. {
  92. $dirSize = get_dir_size($directory . '/' . $dirfile);
  93. if ($dirSize >= 0)
  94. {
  95. $size += $dirSize;
  96. }
  97. else
  98. {
  99. return -1;
  100. }
  101. }
  102. }
  103. closedir($DIR);
  104. }
  105. return $size;
  106. }
  107. /**
  108. * ?????? ???? ??????
  109. *
  110. * @return int
  111. */
  112. function get_mysql_size()
  113. {
  114. global $AVE_DB;
  115. $mysql_size = 0;
  116. $sql = $AVE_DB->Query("SHOW TABLE STATUS LIKE '" . PREFIX . "_%'");
  117. while ($row = $sql->FetchAssocArray())
  118. {
  119. $mysql_size += $row['Data_length'] + $row['Index_length'];
  120. }
  121. return format_size($mysql_size);
  122. }
  123. function get_ave_tags($srcfile)
  124. {
  125. if (@include_once($srcfile))
  126. {
  127. reset ($vorlage);
  128. $vl = array();
  129. while (list($key, $value) = each($vorlage))
  130. {
  131. $tag = new stdClass;
  132. $tag->cp_tag = $key;
  133. $tag->cp_desc = $value;
  134. array_push($vl, $tag);
  135. unset($tag);
  136. }
  137. return $vl;
  138. }
  139. return null;
  140. }
  141. function get_all_templates()
  142. {
  143. global $AVE_DB;
  144. static $templates = null;
  145. if ($templates == null)
  146. {
  147. $templates = array();
  148. $sql = $AVE_DB->Query("
  149. SELECT
  150. Id,
  151. template_title
  152. FROM " . PREFIX . "_templates
  153. ");
  154. while ($row = $sql->FetchRow())
  155. {
  156. array_push($templates, $row);
  157. }
  158. }
  159. return $templates;
  160. }
  161. function get_editable_module()
  162. {
  163. global $AVE_DB, $AVE_Template;
  164. $modules = array();
  165. $sql = $AVE_DB->Query("
  166. SELECT
  167. ModulName,
  168. ModulPfad
  169. FROM " . PREFIX . "_module
  170. WHERE `Status` = '1'
  171. AND `AdminEdit` = '1'
  172. ORDER BY ModulName ASC
  173. ");
  174. while ($row = $sql->FetchRow())
  175. {
  176. if (check_permission('mod_' . $row->ModulPfad))
  177. {
  178. array_push($modules, $row);
  179. }
  180. }
  181. $AVE_Template->assign('modules', $modules);
  182. }
  183. function get_mime_type($file)
  184. {
  185. $file_extension = strtolower(mb_substr(strrchr($file, '.'), 1));
  186. switch ($file_extension)
  187. {
  188. case 'psd': $ctype = 'image/x-photoshop'; break;
  189. case 'rar': $ctype = 'application/x-rar-compressed'; break;
  190. case 'zip': $ctype = 'application/x-zip-compressed'; break;
  191. case 'pdf': $ctype = 'application/pdf'; break;
  192. case 'bz2': $ctype = 'application/bzip2'; break;
  193. case 'doc':
  194. case 'dot':
  195. case 'wiz':
  196. case 'wzs': $ctype = 'application/msword'; break;
  197. case 'eps': $ctype = 'application/postscript'; break;
  198. case 'pot':
  199. case 'ppa':
  200. case 'pps':
  201. case 'ppt':
  202. case 'pwz': $ctype = 'application/vnd.ms-powerpoint'; break;
  203. case 'rtf': $ctype = 'application/rtf'; break;
  204. case 'rnx': $ctype = 'application/vnd.rn-realmedia'; break;
  205. case 'hlp': $ctype = 'hlp'; break;
  206. case 'gtar': $ctype = 'application/x-gtar'; break;
  207. case 'gzip':
  208. case 'tgz': $ctype = 'application/x-gzip'; break;
  209. case 'lnx': $ctype = 'application/x-latex'; break;
  210. case 'exe': $ctype = 'application/x-msdownload'; break;
  211. case 'swf': $ctype = 'application/x-shockwafe-flash'; break;
  212. case 'xml': $ctype = 'application/xml'; break;
  213. case 'midi': $ctype = 'audio/midi'; break;
  214. case 'mp3':
  215. case 'mp2':
  216. case 'mpga': $ctype = 'audio/mpeg'; break;
  217. case 'wav': $ctype = 'audio/wav'; break;
  218. case 'bmp': $ctype = 'audio/wav'; break;
  219. case 'gif': $ctype = 'image/gif'; break;
  220. case 'jpeg':
  221. case 'jpg':
  222. case 'jpe': $ctype = 'image/jpeg'; break;
  223. case 'png': $ctype = 'image/png'; break;
  224. case 'tif':
  225. case 'tiff': $ctype = 'image/tiff'; break;
  226. case 'ico': $ctype = 'image/x-icon'; break;
  227. case 'csv': $ctype = 'text/comma-separated-values'; break;
  228. case 'css': $ctype = 'text/css'; break;
  229. case 'htm':
  230. case 'html':
  231. case 'shtml': $ctype = 'text/html'; break;
  232. case 'txt':
  233. case 'klp':
  234. case 'tex':
  235. case 'php':
  236. case 'asp':
  237. case 'aspx':
  238. case 'php3':
  239. case 'php4':
  240. case 'php5':
  241. case 'sql': $ctype = 'text/plain'; break;
  242. case 'xml': $ctype = 'text/xml'; break;
  243. case 'xhtm': $ctype = 'text/xhtml'; break;
  244. case 'wml': $ctype = 'text/wml'; break;
  245. case 'mpeg':
  246. case 'mpg':
  247. case 'mpe':
  248. case 'mlv':
  249. case 'mpa':
  250. case 'wma':
  251. case 'wmv': $ctype = 'video/mpeg'; break;
  252. case 'avi': $ctype = 'video/x-msvideo'; break;
  253. case 'mov': $ctype = 'video/quicktime'; break;
  254. case 'xls': $ctype = 'application/vnd.ms-excel'; break;
  255. case 'ai': $ctype = 'application/postscript'; break;
  256. case 'rm': $ctype = 'application/vnd.rn-realmedia'; break;
  257. case 'gz': $ctype = 'application/x-gzip'; break;
  258. case 'js': $ctype = 'application/x-javascript'; break;
  259. case 'pl':
  260. case 'cc': $ctype = 'text/plain'; break;
  261. case 'qt': $ctype = 'video/quicktime'; break;
  262. default : $ctype='application/force-download';
  263. }
  264. return $ctype;
  265. }
  266. function file_download($filename, $retbytes = true)
  267. {
  268. $chunksize = 1*(1024*1024);
  269. $buffer = '';
  270. $cnt = 0;
  271. $handle = fopen($filename, 'rb');
  272. if ($handle === false) return false;
  273. while (!feof($handle))
  274. {
  275. $buffer = fread($handle, $chunksize);
  276. echo $buffer;
  277. flush();
  278. if ($retbytes) $cnt += strlen($buffer);
  279. }
  280. $status = fclose($handle);
  281. if ($retbytes && $status) return $cnt;
  282. return $status;
  283. }
  284. function is_php_code($check_code)
  285. {
  286. $check_code = stripslashes($check_code);
  287. $check_code = str_replace(' ', '', $check_code);
  288. $check_code = strtolower($check_code);
  289. if (strpos($check_code, '<?php') !== false ||
  290. strpos($check_code, '<?') !== false ||
  291. strpos($check_code, '<? ') !== false ||
  292. strpos($check_code, '<?=') !== false ||
  293. strpos($check_code, '<script language="php">') !== false ||
  294. strpos($check_code, 'language="php"') !== false ||
  295. strpos($check_code, "language='php'") !== false ||
  296. strpos($check_code, 'language=php') !== false)
  297. {
  298. return true;
  299. }
  300. return false;
  301. }
  302. function check_permission_acp($perm)
  303. {
  304. if (!check_permission($perm))
  305. {
  306. if (!defined('NOPERM')) define('NOPERM', 1);
  307. return false;
  308. }
  309. return true;
  310. }
  311. ?>