Просмотр файла mc-2.7.0/modules/lib/helpers/lib.php

Размер файла: 3.5Kb
  1. <?php
  2.  
  3. /**
  4. * MobileCMS
  5. *
  6. * Open source content management system for mobile sites
  7. *
  8. * @author MobileCMS Team <support@mobilecms.pro>
  9. * @copyright Copyright (c) 2011-2019, MobileCMS Team
  10. * @link https://mobilecms.pro Official site
  11. * @license MIT license
  12. */
  13. defined('IN_SYSTEM') or die('<b>403<br />Запрет доступа!</b>');
  14.  
  15. //---------------------------------------------
  16.  
  17. /**
  18. * Хелпер библиотеки
  19. */
  20. class lib {
  21.  
  22. /**
  23. * Получение реального пути к папке
  24. */
  25. public static function get_path($directory_id, $db, $directory_path = array(), $i = 0) {
  26. $parent = $db->get_row("SELECT * FROM #__lib_directories WHERE
  27. directory_id = (SELECT parent_id FROM #__lib_directories WHERE directory_id = '" . intval($directory_id) . "')
  28. ");
  29. $i++;
  30. if ($parent['directory_id'] != 0) {
  31. $directory_path[$i]['directory_id'] = $parent['directory_id'];
  32. $directory_path[$i]['name'] = $parent['name'];
  33. $directory_path = self::get_path($parent['directory_id'], $db, $directory_path, $i);
  34. }
  35. return $directory_path;
  36. }
  37.  
  38. /**
  39. * Получение полного пути к папке
  40. */
  41. public static function get_realpath($directories_array) {
  42. if (empty($directories_array))
  43. return;
  44.  
  45. foreach ($directories_array AS $directory) {
  46. $directory_path[] = $directory['directory_id'];
  47. }
  48. if (count($directory_path) > 1) {
  49. $realpath = array_reverse($directory_path);
  50. $realpath = implode('/', $realpath);
  51. } else {
  52. $realpath = $directory_path[0];
  53. }
  54.  
  55. return $realpath;
  56. }
  57.  
  58. /**
  59. * @desc получение полного пути к папке
  60. * @param $array
  61. */
  62. public static function get_namepath($directories_array, $delim = '/', $admin = FALSE) {
  63. if (empty($directories_array)) {
  64. return;
  65. }
  66.  
  67. $segment = $admin ? 'lib/admin' : 'lib';
  68.  
  69. foreach ($directories_array AS $directory) {
  70. $directory_path[] = '<a href="' . a_url($segment, 'directory_id=' . $directory['directory_id']) . '">' . $directory['name'] . '</a>';
  71. }
  72. if (count($directory_path) > 1) {
  73. $realpath = array_reverse($directory_path);
  74. $realpath = implode($delim, $realpath);
  75. } else {
  76. $realpath = $directory_path[0];
  77. }
  78.  
  79. return $realpath;
  80. }
  81.  
  82. /**
  83. * Функция рекурсивного копирования
  84. * @param string $source
  85. * @param string $dest
  86. */
  87. public static function r_copy($source, $dest) {
  88. # Simple copy for a file
  89. if (is_file($source)) {
  90. return copy($source, $dest);
  91. }
  92.  
  93. # Make destination directory
  94. if (!is_dir($dest)) {
  95. mkdir($dest);
  96. }
  97.  
  98. # If the source is a symlink
  99. if (is_link($source)) {
  100. $link_dest = readlink($source);
  101. return symlink($link_dest, $dest);
  102. }
  103.  
  104. # Loop through the folder
  105. $dir = dir($source);
  106. while (false !== $entry = $dir->read()) {
  107. // Skip pointers
  108. if ($entry == '.' || $entry == '..') {
  109. continue;
  110. }
  111.  
  112. // Deep copy directories
  113. if ($dest !== "$source/$entry") {
  114. self::r_copy("$source/$entry", "$dest/$entry");
  115. }
  116. }
  117.  
  118. // Clean up
  119. $dir->close();
  120. return true;
  121. }
  122.  
  123. }
  124.  
  125. ?>