PageRenderTime 55ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

/core/Pliki.class.php

https://bitbucket.org/ydk2/littlecms
PHP | 198 lines | 145 code | 10 blank | 43 comment | 27 complexity | 210cf55374e1391475717abdcfd01655 MD5 | raw file
  1. <?php
  2. /**
  3. *
  4. */
  5. namespace CMS;
  6. class Pliki {
  7. public function __construct($path = '') {
  8. session_start();
  9. ob_start();
  10. static $NAZWA;
  11. $praca = getcwd();
  12. $this->DOM= $_SERVER['DOCUMENT_ROOT'];
  13. $this->URI= 'http://' . $_SERVER['HTTP_HOST'];
  14. $this->TEN= 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['SCRIPT_NAME'];
  15. $this->TU= $_SERVER['REQUEST_URI'];
  16. $this->NAZWA = $_SERVER['SERVER_NAME'];
  17. $this->LINK= $_SERVER['PATH_INFO'];
  18. $this->PRACA = $praca;
  19. $konfig = parse_ini_file($this->PRACA . "/konfig/konfig.ini", true);
  20. $this -> konfig = $konfig;
  21. if ($path == '') {
  22. $path = $this -> konfig['core']['home'].DIRECTORY_SEPARATOR.$_SESSION['name'];
  23. }
  24. if ($_SESSION['name']=='admin') {
  25. $path = $this -> konfig['core']['home'];
  26. }
  27. if (!file_exists($path)) { ?>
  28. <!DOCTYPE HTML>
  29. <html>
  30. <head>
  31. <meta content="text/html; charset=UTF-8" http-equiv="content-type"/>
  32. <link href="<?=dirname(TEN);?>/style/style.css" rel="stylesheet" type="text/css" />
  33. </head>
  34. <body>
  35. <?php
  36. echo "Brak lokalizacji <a href=\"http://".dirname($_SERVER[HTTP_HOST].$_SERVER[SCRIPT_NAME])."/login.php\"><button>Wróć</button></a></body></html>";
  37. exit;
  38. }
  39. if (!isset($_SESSION['lang']) or $_SESSION['lang'] == '') {
  40. $langl = $this -> konfig['core']['lang'];
  41. $_SESSION['lang'] = $this -> konfig['core']['lang'];
  42. } elseif ($_REQUEST['lang'] != '') {
  43. $langl = $_REQUEST['lang'];
  44. } else {
  45. $langl = $_SESSION['lang'];
  46. }
  47. $langs = parse_ini_file($this->PRACA . "/langs/$langl.lang", TRUE);
  48. $lang = $langs[$langl];
  49. $this -> lang = $lang;
  50. $path = realpath($path);
  51. $this -> path = $path;
  52. $this -> plik = $this -> path . $this->LINK;
  53. $this->arr_lista=NULL;
  54. chdir($this -> path);
  55. }
  56. public function __destruct() {
  57. foreach ($this as $key => $value) {
  58. unset($this -> $key);
  59. }
  60. clearstatcache();
  61. ob_end_flush();
  62. }
  63. public function koniec() {
  64. exit ($this->__destruct());
  65. }
  66. public function langLista($lang = '') {
  67. $path = ($this->LINK) ? $this->TEN . $this->LINK : $this->TEN;
  68. if (empty($lang)) {
  69. If (!isset($_REQUEST['lang']) or $_REQUEST['lang'] == '') {
  70. $lang = $this -> konfig['core']['lang'];
  71. } else {
  72. $_SESSION['lang'] = $_REQUEST['lang'];
  73. }
  74. }
  75. $form = array("<form action=\"$path\" method=\"POST\">",
  76. "<select name=\"lang\">",
  77. "<option value=\"$list\">$list_f</option>",
  78. "</select>",
  79. "<input type=\"submit\" name=\"wybierz\" value=\"{$this->lang['zmień']} {$this->lang['język']}\" />\n",
  80. "</form>"
  81. );
  82. $opcje = $form[0] . $form[1];
  83. foreach (glob($this->PRACA.'/langs/*.lang') as $list) {
  84. $list_n = pathinfo($list, PATHINFO_FILENAME);
  85. $list_f = parse_ini_file($list);
  86. $opcje .= "<option value=\"$list_n\">{$list_f['lang']}</option>";
  87. }
  88. $opcje .= $form[3] . $form[4] . $form[5];
  89. return "$opcje";
  90. }
  91. public function lista($path = '') {
  92. $path = realpath($path);
  93. if ($path == '' or $path < $this -> path) {
  94. $path = $this -> path;
  95. }
  96. $p = "{" . $path . "/*," . $path . "/.*}";
  97. foreach (glob("$p",GLOB_BRACE) as $plik) {
  98. if (basename($plik) != '..' && basename($plik) != '.') {
  99. $info[basename(realpath($plik))] .= realpath($plik);
  100. }
  101. }
  102. /*if ($lista = opendir($path)) {
  103. while (false !== ($plik = readdir($lista))) {
  104. if ($plik != "." && $plik != "..") {
  105. $info[basename(realpath($path.DIRECTORY_SEPARATOR.$plik))] .= realpath($path.DIRECTORY_SEPARATOR.$plik);
  106. }
  107. }
  108. closedir($lista);
  109. }*/
  110. return $info;
  111. }
  112. public function rekursywnie($path = '') {
  113. $a=array();
  114. $path = realpath($path);
  115. if ($path == '' or $path < $this -> path) {
  116. $path = $this -> path;
  117. }
  118. $dir[] = $path;
  119. while (count($dir) != 0) {
  120. $v = array_shift($dir);
  121. foreach (glob($v) as $item) {
  122. if (is_dir($item)) {
  123. $dir[] = $item . "/*";
  124. $a[$item] .= basename($item);
  125. } elseif (is_file($item)) {
  126. $a[$item] .= basename($item);
  127. }
  128. }
  129. }
  130. return $a;
  131. }
  132. public function toURI($path = '') {
  133. $path = realpath($path);
  134. if ($path == '' or $path < $this -> path) {
  135. $path = $this -> path;
  136. }
  137. $co = "/" . str_replace('/', '\/', $this->DOM) . "/A";
  138. if (preg_match($co, $this->PRACA)) {
  139. $path = str_replace($this->DOM, $this->URI, $path);
  140. } elseif (!preg_match($co, $path)) {
  141. $end=$this->URI . $this->TU;
  142. $path = str_replace($this->PRACA, dirname($this->TEN), $path);
  143. }
  144. return str_replace(" ", "%20", $path);
  145. /*
  146. * pozmieniać i weryfikować wykonane;
  147. */
  148. }
  149. public function splitPath($path = '') {
  150. if (empty($path)) {
  151. $path = (is_dir($this -> plik)) ? $this -> plik : dirname($this -> plik);
  152. }
  153. $a = explode('/', $path);
  154. $end = "<ul>";
  155. $e = '';
  156. foreach ($a as $key => $val) {
  157. $e .= $val . DIRECTORY_SEPARATOR;
  158. if ($e >= $this -> path and file_exists($e)) {
  159. $end .= "<li ><a href=\"" . $this->TEN . substr($e, strlen($this -> path), -1) . "\"> $val </a></li> ";
  160. } else {
  161. continue;
  162. }
  163. }
  164. $end .= "</ul>";
  165. return $end;
  166. }
  167. function queryString($params, $name = null) {
  168. $ret = "";
  169. foreach ($params as $key => $val) {
  170. if (is_array($val)) {
  171. if ($name == null)
  172. $ret .= queryString($val, $key);
  173. else
  174. $ret .= queryString($val, $name . "[$key]");
  175. } else {
  176. if ($name != null)
  177. $ret .= $name . "[$key]" . "=$val&";
  178. else
  179. $ret .= "$key=$val&";
  180. }
  181. }
  182. return $ret;
  183. }
  184. }
  185. ?>