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

/admin228c4ef56/filemanager/ajax_calls.php

https://gitlab.com/staging06/myproject
PHP | 253 lines | 224 code | 21 blank | 8 comment | 36 complexity | 82d57fe3b7cebaefd1816e4dea69d92b MD5 | raw file
  1. <?php
  2. include('config/config.php');
  3. if ($_SESSION['verify'] != 'RESPONSIVEfilemanager') {
  4. die('forbiden');
  5. }
  6. include('include/utils.php');
  7. if (isset($_GET['action'])) {
  8. switch ($_GET['action']) {
  9. case 'view':
  10. if (isset($_GET['type'])) {
  11. $_SESSION['view_type'] = $_GET['type'];
  12. } else {
  13. die('view type number missing');
  14. }
  15. break;
  16. case 'sort':
  17. if (isset($_GET['sort_by'])) {
  18. $_SESSION['sort_by'] = $_GET['sort_by'];
  19. }
  20. if (isset($_GET['descending'])) {
  21. $_SESSION['descending'] = $_GET['descending'] === 'true';
  22. }
  23. break;
  24. case 'image_size':
  25. if (realpath(dirname(_PS_ROOT_DIR_.$_POST['path'])) != realpath(_PS_ROOT_DIR_.$upload_dir)) {
  26. die();
  27. }
  28. $pos = strpos($_POST['path'], $upload_dir);
  29. if ($pos !== false) {
  30. $info = getimagesize(substr_replace($_POST['path'], $current_path, $pos, strlen($upload_dir)));
  31. echo json_encode($info);
  32. }
  33. break;
  34. case 'save_img':
  35. $info = pathinfo($_POST['name']);
  36. if (strpos($_POST['path'], '/') === 0
  37. || strpos($_POST['path'], '../') !== false
  38. || strpos($_POST['path'], './') === 0
  39. || strpos($_POST['url'], 'http://featherfiles.aviary.com/') !== 0
  40. || $_POST['name'] != fix_filename($_POST['name'], $transliteration)
  41. || !in_array(strtolower($info['extension']), array('jpg', 'jpeg', 'png'))
  42. ) {
  43. die('wrong data');
  44. }
  45. $image_data = get_file_by_url($_POST['url']);
  46. if ($image_data === false) {
  47. die('file could not be loaded');
  48. }
  49. $put_contents_path = $current_path;
  50. if (isset($_POST['path'])) {
  51. $put_contents_path .= str_replace("\0", "", $_POST['path']);
  52. }
  53. if (isset($_POST['name'])) {
  54. $put_contents_path .= str_replace("\0", "", $_POST['name']);
  55. }
  56. file_put_contents($put_contents_path, $image_data);
  57. //new thumb creation
  58. //try{
  59. create_img_gd($current_path.$_POST['path'].$_POST['name'], $thumbs_base_path.$_POST['path'].$_POST['name'], 122, 91);
  60. new_thumbnails_creation($current_path.$_POST['path'], $current_path.$_POST['path'].$_POST['name'], $_POST['name'], $current_path, $relative_image_creation, $relative_path_from_current_pos, $relative_image_creation_name_to_prepend, $relative_image_creation_name_to_append, $relative_image_creation_width, $relative_image_creation_height, $fixed_image_creation, $fixed_path_from_filemanager, $fixed_image_creation_name_to_prepend, $fixed_image_creation_to_append, $fixed_image_creation_width, $fixed_image_creation_height);
  61. /*} catch (Exception $e) {
  62. $src_thumb=$mini_src="";
  63. }*/
  64. break;
  65. case 'extract':
  66. if (strpos($_POST['path'], '/') === 0 || strpos($_POST['path'], '../') !== false || strpos($_POST['path'], './') === 0) {
  67. die('wrong path');
  68. }
  69. $path = $current_path.$_POST['path'];
  70. $info = pathinfo($path);
  71. $base_folder = $current_path.fix_dirname($_POST['path']).'/';
  72. switch ($info['extension']) {
  73. case 'zip':
  74. $zip = new ZipArchive;
  75. if ($zip->open($path) === true) {
  76. //make all the folders
  77. for ($i = 0; $i < $zip->numFiles; $i++) {
  78. $OnlyFileName = $zip->getNameIndex($i);
  79. $FullFileName = $zip->statIndex($i);
  80. if ($FullFileName['name'][strlen($FullFileName['name']) - 1] == '/') {
  81. create_folder($base_folder.$FullFileName['name']);
  82. }
  83. }
  84. //unzip into the folders
  85. for ($i = 0; $i < $zip->numFiles; $i++) {
  86. $OnlyFileName = $zip->getNameIndex($i);
  87. $FullFileName = $zip->statIndex($i);
  88. if (!($FullFileName['name'][strlen($FullFileName['name']) - 1] == '/')) {
  89. $fileinfo = pathinfo($OnlyFileName);
  90. if (in_array(strtolower($fileinfo['extension']), $ext)) {
  91. copy('zip://'.$path.'#'.$OnlyFileName, $base_folder.$FullFileName['name']);
  92. }
  93. }
  94. }
  95. $zip->close();
  96. } else {
  97. echo 'failed to open file';
  98. }
  99. break;
  100. case 'gz':
  101. $p = new PharData($path);
  102. $p->decompress(); // creates files.tar
  103. break;
  104. case 'tar':
  105. // unarchive from the tar
  106. $phar = new PharData($path);
  107. $phar->decompressFiles();
  108. $files = array();
  109. check_files_extensions_on_phar($phar, $files, '', $ext);
  110. $phar->extractTo($current_path.fix_dirname($_POST['path']).'/', $files, true);
  111. break;
  112. }
  113. break;
  114. case 'media_preview':
  115. $preview_file = $_GET['file'];
  116. $info = pathinfo($preview_file);
  117. ?>
  118. <div id="jp_container_1" class="jp-video " style="margin:0 auto;">
  119. <div class="jp-type-single">
  120. <div id="jquery_jplayer_1" class="jp-jplayer"></div>
  121. <div class="jp-gui">
  122. <div class="jp-video-play">
  123. <a href="javascript:;" class="jp-video-play-icon" tabindex="1">play</a>
  124. </div>
  125. <div class="jp-interface">
  126. <div class="jp-progress">
  127. <div class="jp-seek-bar">
  128. <div class="jp-play-bar"></div>
  129. </div>
  130. </div>
  131. <div class="jp-current-time"></div>
  132. <div class="jp-duration"></div>
  133. <div class="jp-controls-holder">
  134. <ul class="jp-controls">
  135. <li><a href="javascript:;" class="jp-play" tabindex="1">play</a></li>
  136. <li><a href="javascript:;" class="jp-pause" tabindex="1">pause</a></li>
  137. <li><a href="javascript:;" class="jp-stop" tabindex="1">stop</a></li>
  138. <li><a href="javascript:;" class="jp-mute" tabindex="1" title="mute">mute</a></li>
  139. <li><a href="javascript:;" class="jp-unmute" tabindex="1" title="unmute">unmute</a>
  140. </li>
  141. <li><a href="javascript:;" class="jp-volume-max" tabindex="1" title="max volume">max
  142. volume</a></li>
  143. </ul>
  144. <div class="jp-volume-bar">
  145. <div class="jp-volume-bar-value"></div>
  146. </div>
  147. <ul class="jp-toggles">
  148. <li><a href="javascript:;" class="jp-full-screen" tabindex="1" title="full screen">full
  149. screen</a></li>
  150. <li>
  151. <a href="javascript:;" class="jp-restore-screen" tabindex="1" title="restore screen">restore
  152. screen</a></li>
  153. <li><a href="javascript:;" class="jp-repeat" tabindex="1" title="repeat">repeat</a>
  154. </li>
  155. <li><a href="javascript:;" class="jp-repeat-off" tabindex="1" title="repeat off">repeat
  156. off</a></li>
  157. </ul>
  158. </div>
  159. <div class="jp-title" style="display:none;">
  160. <ul>
  161. <li></li>
  162. </ul>
  163. </div>
  164. </div>
  165. </div>
  166. <div class="jp-no-solution">
  167. <span>Update Required</span>
  168. To play the media you will need to either update your browser to a recent version or update your
  169. <a href="http://get.adobe.com/flashplayer/" class="_blank">Flash plugin</a>.
  170. </div>
  171. </div>
  172. </div>
  173. <?php
  174. if (in_array(strtolower($info['extension']), $ext_music)) {
  175. ?>
  176. <script type="text/javascript">
  177. $(document).ready(function () {
  178. $("#jquery_jplayer_1").jPlayer({
  179. ready: function () {
  180. $(this).jPlayer("setMedia", {
  181. title: "<?php Tools::safeOutput($_GET['title']);
  182. ?>",
  183. mp3: "<?php echo Tools::safeOutput($preview_file);
  184. ?>",
  185. m4a: "<?php echo Tools::safeOutput($preview_file);
  186. ?>",
  187. oga: "<?php echo Tools::safeOutput($preview_file);
  188. ?>",
  189. wav: "<?php echo Tools::safeOutput($preview_file);
  190. ?>"
  191. });
  192. },
  193. swfPath: "js",
  194. solution: "html,flash",
  195. supplied: "mp3, m4a, midi, mid, oga,webma, ogg, wav",
  196. smoothPlayBar: true,
  197. keyEnabled: false
  198. });
  199. });
  200. </script>
  201. <?php
  202. } elseif (in_array(strtolower($info['extension']), $ext_video)) {
  203. ?>
  204. <script type="text/javascript">
  205. $(document).ready(function () {
  206. $("#jquery_jplayer_1").jPlayer({
  207. ready: function () {
  208. $(this).jPlayer("setMedia", {
  209. title: "<?php Tools::safeOutput($_GET['title']);
  210. ?>",
  211. m4v: "<?php echo Tools::safeOutput($preview_file);
  212. ?>",
  213. ogv: "<?php echo Tools::safeOutput($preview_file);
  214. ?>"
  215. });
  216. },
  217. swfPath: "js",
  218. solution: "html,flash",
  219. supplied: "mp4, m4v, ogv, flv, webmv, webm",
  220. smoothPlayBar: true,
  221. keyEnabled: false
  222. });
  223. });
  224. </script>
  225. <?php
  226. }
  227. break;
  228. }
  229. } else {
  230. die('no action passed');
  231. }
  232. ?>