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

/admin/browser.php

http://avecms.googlecode.com/
PHP | 322 lines | 252 code | 60 blank | 10 comment | 51 complexity | 9948e19f37aa1ab5157783b95d7a7939 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. @date_default_timezone_set('Europe/Moscow');
  10. ob_start();
  11. define('BASE_DIR', str_replace("\\", "/", dirname(dirname(__FILE__))));
  12. define('MEDIAPATH', 'uploads');
  13. $max_size = 128; // ???????????? ?????? ?????????
  14. define('TH_PREF', 'thumbnail/th_' . $max_size . '_'); // ??????? ????????
  15. define('UPDIR', BASE_DIR . '/' . MEDIAPATH);
  16. if (isset($_REQUEST['thumb']) && $_REQUEST['thumb']==1)
  17. {
  18. $img_path = str_replace(array('../', './', '..', '\'', '//'), '', $_REQUEST['bild']);
  19. $img_path = '/' . ltrim($img_path, '/');
  20. $img_dir = rtrim(dirname($img_path), '/') . '/';
  21. $img_name = basename($img_path);
  22. require(BASE_DIR . '/class/class.thumbnail.php');
  23. $img = new Image_Toolbox(UPDIR . $img_path);
  24. $img->newOutputSize($max_size, $max_size, 2, false, '#EFF3EB');
  25. // $img->newOutputSize($max_size, $max_size, 2, false, '#FFFFFF');
  26. $img->output();
  27. // ????????? ??????? ????? ??? ???????? ? ???? ?? ??? - ???????
  28. if (! file_exists(UPDIR . $img_dir . '/thumbnail'))
  29. {
  30. $oldumask = umask(0);
  31. @mkdir(UPDIR . $img_dir . '/thumbnail', 0777);
  32. umask($oldumask);
  33. }
  34. $img->save(UPDIR . $img_dir . TH_PREF . $img_name);
  35. $oldumask = umask(0);
  36. chmod(UPDIR . $img_dir . TH_PREF . $img_name, 0644);
  37. umask($oldumask);
  38. exit;
  39. }
  40. require(BASE_DIR . '/inc/init.php');
  41. if (!isset($_SESSION['user_id']))
  42. {
  43. header('Location:index.php');
  44. exit;
  45. }
  46. define('ACP', 1);
  47. define('SESSION', session_id());
  48. $tpl_dir = 'templates/' . (empty($_SESSION['admin_theme']) ? DEFAULT_ADMIN_THEME_FOLDER : $_SESSION['admin_theme']);
  49. $AVE_Template = new AVE_Template($tpl_dir . '/browser');
  50. $AVE_Template->assign('tpl_dir', $tpl_dir);
  51. $AVE_Template->assign('sess', SESSION);
  52. $AVE_Template->config_load(BASE_DIR . '/admin/lang/' . (empty($_SESSION['admin_language']) ? $_SESSION['user_language'] : $_SESSION['admin_language']) . '/main.txt');
  53. $_REQUEST['action'] = (isset($_REQUEST['action'])) ? $_REQUEST['action'] : '';
  54. if ($_REQUEST['action']=='upload')
  55. {
  56. $AVE_Template->display('browser_upload.tpl');
  57. exit;
  58. }
  59. if ($_REQUEST['action']=='upload2')
  60. {
  61. for ($i=0;$i<count($_FILES['upfile']['tmp_name']);$i++)
  62. {
  63. $d_name = strtolower(trim($_FILES['upfile']['name'][$i]));
  64. $d_name = str_replace(' ', '', $d_name);
  65. $d_tmp = $_FILES['upfile']['tmp_name'][$i];
  66. if ($_FILES['upfile']['type'][$i]=='image/pjpeg' ||
  67. $_FILES['upfile']['type'][$i]=='image/jpeg' ||
  68. $_FILES['upfile']['type'][$i]=='image/x-png' ||
  69. $_FILES['upfile']['type'][$i]=='image/png')
  70. {
  71. if (file_exists(UPDIR . $_REQUEST['pfad'] . $d_name ))
  72. {
  73. $expl = explode('.', $d_name);
  74. $d_name = $expl[0] . date('dhi'). '.' . $expl[1];
  75. }
  76. reportLog($_SESSION['user_name'] . ' - ???????? ??????????? ? ('. stripslashes($_REQUEST['pfad']) . $d_name. ')', 2, 2);
  77. @move_uploaded_file($d_tmp, UPDIR . $_REQUEST['pfad'] . $d_name);
  78. @chmod(UPDIR . $_REQUEST['pfad'] . $d_name, 0777);
  79. if (isset($_REQUEST['resize']) && $_REQUEST['resize']==1)
  80. {
  81. $error = 0;
  82. if (function_exists('imagecreatetruecolor'))
  83. {
  84. $sowhat = 'imagecreatetruecolor';
  85. }
  86. else
  87. {
  88. $sowhat = 'imagecreate';
  89. }
  90. $neues_bild = $sowhat($_REQUEST['w'], $_REQUEST['h']);
  91. if ($_FILES['upfile']['type'][$i]=='image/pjpeg' || $_FILES['upfile']['type'][$i]=='image/jpeg')
  92. {
  93. $altes_bild = imagecreatefromjpeg(UPDIR . $_REQUEST['pfad'] . $d_name);
  94. }
  95. if ($_FILES['upfile']['type'][$i]=='image/png' || $_FILES['upfile']['type'][$i]=='x/png')
  96. {
  97. $altes_bild = imagecreatefrompng(UPDIR . $_REQUEST['pfad'] . $d_name);
  98. }
  99. if ($_FILES['upfile']['type'][$i]=='image/gif')
  100. {
  101. $error = 1;
  102. }
  103. if (isset($altes_bild))
  104. {
  105. imagecopyresampled($neues_bild, $altes_bild, 0, 0, 0, 0, imagesx($neues_bild), imagesy($neues_bild), imagesx($altes_bild), imagesy($altes_bild));
  106. if ($_FILES['upfile']['type'][$i]=='image/pjpeg' || $_FILES['upfile']['type'][$i]=='image/jpeg')
  107. {
  108. unlink(UPDIR . $_REQUEST['pfad'] . $d_name);
  109. imagejpeg($neues_bild, UPDIR . $_REQUEST['pfad'] . $d_name, 95);
  110. }
  111. if ($_FILES['upfile']['type'][$i]=='image/png' || $_FILES['upfile']['type'][$i]=='x/png')
  112. {
  113. unlink(UPDIR . $_REQUEST['pfad'] . $d_name);
  114. imagepng($neues_bild, UPDIR . $_REQUEST['pfad'] . $d_name, 95);
  115. }
  116. }
  117. }
  118. else
  119. {
  120. $d_tmp = $_FILES['upfile']['tmp_name'];
  121. move_uploaded_file($d_tmp, UPDIR . $_REQUEST['pfad'] . $d_name);
  122. @chmod(UPDIR . $_REQUEST['pfad'] . $d_name, 0777);
  123. }
  124. }
  125. else
  126. {
  127. move_uploaded_file($d_tmp, UPDIR . $_REQUEST['pfad'] . $d_name);
  128. @chmod(UPDIR . $_REQUEST['pfad'] . $d_name, 0777);
  129. }
  130. }
  131. echo "<script language=\"javascript\"> \n",
  132. "<!-- \n",
  133. "window.opener.parent.frames['zf'].location.href = window.opener.parent.frames['zf'].location.href; \n",
  134. "window.close(); \n",
  135. "//--> \n",
  136. "</script> \n";
  137. exit;
  138. }
  139. if ($_REQUEST['action']=='delfile')
  140. {
  141. if (check_permission('mediapool_del'))
  142. {
  143. @copy(UPDIR . $_REQUEST['file'], BASE_DIR . '/' . MEDIAPATH . '/recycled/' . $_REQUEST['df'] );
  144. if (@unlink(UPDIR . $_REQUEST['file']))
  145. {
  146. $error = 0;
  147. reportLog($_SESSION['user_name'] . ' - ?????? ??????????? (' . stripslashes($_REQUEST['file']) . ')', 2, 2);
  148. $img_path = $_REQUEST['file'];
  149. $namepos = strrpos($img_path, '/');
  150. if ($namepos > 0)
  151. {
  152. $img_name = substr($img_path, ++$namepos);
  153. $img_dir = substr($img_path, 0, $namepos);
  154. if (substr($img_path, 0, 1) != '/')
  155. {
  156. $img_dir = '/' . $img_dir;
  157. }
  158. }
  159. else
  160. {
  161. $img_name = substr($img_path, 1);
  162. $img_dir = '/';
  163. }
  164. @unlink(UPDIR . $img_dir . TH_PREF . $img_name);
  165. $_REQUEST['file'] = '';
  166. $_REQUEST['action'] = '';
  167. }
  168. }
  169. echo "<script language=\"javascript\"> \n",
  170. "<!-- \n",
  171. "parent.frames['zf'].location.href=\"browser.php?typ=", $_REQUEST['typ'], "&dir=", $_REQUEST['dir'], "&cpengine=", SESSION, "&done=1\"; \n",
  172. "--> \n",
  173. "</script> \n";
  174. $_REQUEST['action'] = 'list';
  175. }
  176. $_REQUEST['done'] = (isset($_REQUEST['done']) && $_REQUEST['done']==1) ? 1 : '';
  177. $dir = (!empty($_REQUEST['dir'])) ? $_REQUEST['dir'] : '';
  178. $dir = (strpos($dir, '//')!==false || substr($dir, 0, 4)=='/../' ) ? '' : $dir;
  179. if ($_REQUEST['action']=='list' || $_REQUEST['done']==1)
  180. {
  181. if (substr($dir, -4) == '/../')
  182. {
  183. $dir = explode('/', substr($dir, 0, -4));
  184. array_pop($dir);
  185. $dir = implode('/', $dir);
  186. $dir = rtrim($dir, '/') . '/';
  187. }
  188. $current_dir = UPDIR . $dir;
  189. $new_dir = $current_dir . (isset($_REQUEST['newdir']) ? $_REQUEST['newdir'] : '');
  190. $new_dir_created = file_exists($new_dir) ? 0 : @mkdir($new_dir, 0777);
  191. $d = @dir($current_dir);
  192. $elem = array('dir'=>array(), 'file'=>array());
  193. while (false !== ($entry = @$d->read()))
  194. {
  195. if (substr($entry, 0, 1) == '.' || $entry == 'thumbnail' || $entry == 'index.php') continue;
  196. if (is_dir($current_dir . $entry))
  197. {
  198. $elem['dir'][] = $entry;
  199. }
  200. else
  201. {
  202. $elem['file'][] = $entry;
  203. }
  204. }
  205. $d->close();
  206. asort($elem['dir']);
  207. $bfiles = array();
  208. while (list($key, $dir_name) = each($elem['dir']))
  209. {
  210. $row = new stdClass();
  211. $row->fileopen = $_REQUEST['typ'] . "&amp;cpengine=" . SESSION . "&amp;dir=" . $dir . $dir_name . "/&amp;action=list";
  212. $row->val = $dir_name;
  213. array_push($bfiles, $row);
  214. }
  215. $allowed_images = array('.jpg', 'jpeg', '.png', '.gif');
  216. asort($elem['file']);
  217. $unable_delete = 0;
  218. $dats = array();
  219. while (list($key, $file_name) = each($elem['file']))
  220. {
  221. $file_type = strtolower(substr($file_name, strlen($file_name) - 3));
  222. $row = new stdClass();
  223. $row->gifend = (file_exists($tpl_dir . '/images/mediapool/' . $file_type . '.gif')) ? $file_type : 'attach';
  224. $row->datsize = @round(@filesize($current_dir . $file_name)/1024, 2);
  225. $row->val = $file_name;
  226. $row->moddate = date("d.m.y, H:i", @filemtime($current_dir . $file_name));
  227. // if (in_array(substr($file_name, -4), $allowed_images) && function_exists('getimagesize') && function_exists('imagecreatetruecolor'))
  228. if (in_array(substr($file_name, -4), $allowed_images))
  229. {
  230. if (file_exists($current_dir . TH_PREF . $file_name))
  231. {
  232. $row->bild = "<img border=\"0\" src=\"../" . MEDIAPATH . $dir . TH_PREF . $file_name . "\">";
  233. }
  234. else
  235. {
  236. $row->bild = "<img border=\"0\" src=\"browser.php?thumb=1&bild=" . $dir . $file_name . "\">";
  237. }
  238. }
  239. $unable_delete = (strpos($dir, 'recycled')!==false) ? 1 : 0;
  240. array_push($dats, $row);
  241. }
  242. if (!empty($_REQUEST['newdir']) && !$new_dir_created && !file_exists($new_dir))
  243. {
  244. echo '<script>alert("??????! ?????????? ??????? ?????????? ?? ???????. ??????????, ????????? ???? ?????????.");</script>';
  245. }
  246. $AVE_Template->assign('unable_delete', $unable_delete);
  247. $AVE_Template->assign('dats', $dats);
  248. $AVE_Template->assign('bfiles', $bfiles);
  249. $AVE_Template->assign('dir', $dir);
  250. $AVE_Template->assign('dirup', ($dir != '/') ? 1 : 0);
  251. $AVE_Template->assign('mediapath', MEDIAPATH);
  252. $AVE_Template->display('browser.tpl');
  253. exit;
  254. }
  255. $sub_target = @explode('__', $_REQUEST['target']);
  256. if (is_array($sub_target)) $sub = @$sub_target[1];
  257. $AVE_Template->assign('target_img', $sub_target[0]);
  258. $AVE_Template->assign('pop_id', $sub);
  259. $AVE_Template->assign('cppath', substr($_SERVER['PHP_SELF'], 0, -18));
  260. $AVE_Template->assign('mediapath', MEDIAPATH);
  261. $AVE_Template->display('browser_2frames.tpl');
  262. ?>