Source for file browser.php

Documentation is available at browser.php

  1. <?php
  2.  
  3. /**
  4.  * AVE.cms
  5.  *
  6.  * @package AVE.cms
  7.  * @subpackage admin
  8.  * @filesource
  9.  */
  10.  
  11.  
  12. define('BASE_DIR'str_replace("\\""/"substr(dirname(__FILE__)0-6)));
  13.  
  14. require(BASE_DIR '/inc/init.php');
  15.  
  16. if (!isset($_SESSION['user_id']))
  17. {
  18.     header('Location:index.php');
  19.     exit;
  20. }
  21.  
  22. define('ACP'1);
  23. define('SESSION'session_id());
  24. define('UPDIR'BASE_DIR '/uploads');
  25.  
  26. $tpl_dir ABS_PATH 'templates/' (empty($_SESSION['admin_theme']DEFAULT_ADMIN_THEME_FOLDER $_SESSION['admin_theme']);
  27.  
  28. $AVE_Template new AVE_Template($tpl_dir '/browser');
  29.  
  30. $AVE_Template->assign('tpl_dir'$tpl_dir);
  31. $AVE_Template->assign('sess'SESSION);
  32.  
  33. $AVE_Template->config_load(BASE_DIR '/admin/lang/' (empty($_SESSION['admin_language']$_SESSION['user_language'$_SESSION['admin_language']'/main.txt');
  34.  
  35. $mediapath '';
  36. $max_size  128// максимальный размер миниатюры
  37. $th_pref   'th_' $max_size '_'// префикс миниатюр
  38.  
  39. if (isset($_REQUEST['thumb']&& $_REQUEST['thumb']==1)
  40. {
  41.     $img_path str_replace(array('../''..''\'''//''./')''$_REQUEST['bild']);
  42.     $namepos strrpos($img_path'/');
  43.     if ($namepos 0)
  44.     {
  45.         $img_name substr($img_path++$namepos);
  46.         $img_dir  substr($img_path0$namepos);
  47.         if (substr($img_path01!= '/')
  48.         {
  49.             $img_dir '/' $img_dir;
  50.         }
  51.     }
  52.     else {
  53.         $img_name substr($img_path1);
  54.         $img_dir  '/';
  55.     }
  56.  
  57.     $thumb imagecreatetruecolor($max_size$max_size);
  58.  
  59.     $img_data getimagesize(UPDIR $img_path);
  60.     switch ($img_data[2])
  61.     {
  62.         case '1' :
  63.             if (function_exists('imagecreatefromgif'))
  64.             {
  65.                 $img_src imagecreatefromgif(UPDIR $img_path);
  66.                 $header  'image/gif';
  67.                 imagecolortransparent($thumbimagecolorallocate($thumb000));
  68.             }
  69.             else
  70.             {
  71.                 exit;
  72.             }
  73.             break;
  74.  
  75.         case '2' :
  76.             if (function_exists('imagecreatefromjpeg'))
  77.             {
  78.                 $img_src imagecreatefromjpeg(UPDIR $img_path);
  79.                 $header  'image/jpeg';
  80. //                imagefill($thumb, 0, 0, imagecolorallocate($thumb, 239, 243, 235));
  81.                 imagefill($thumb00imagecolorallocate($thumb255255255));
  82.             }
  83.             else
  84.             {
  85.                 exit;
  86.             }
  87.             break;
  88.  
  89.         case '3' :
  90.             if (function_exists('imagecreatefrompng'))
  91.             {
  92.                 $img_src imagecreatefrompng(UPDIR $img_path);
  93.                 $header 'image/png';
  94.                 imagecolortransparent($thumbimagecolorallocate($thumb000));
  95.             }
  96.             else
  97.             {
  98.                 exit;
  99.             }
  100.             break;
  101.     }
  102.  
  103.     $thumb_id $img_dir $th_pref $img_name;
  104.     if (file_exists(UPDIR $thumb_id))
  105.     {
  106.         header('Content-Type:' $headertrue);
  107.         readfile(UPDIR $thumb_id);
  108.         exit;
  109.     }
  110.  
  111.     if ($max_size max($img_data[0]$img_data[1]))
  112.     {
  113.         $new_width  $img_data[0];
  114.         $new_height $img_data[1];
  115.     }
  116.     elseif ($img_data[0]==$img_data[1])
  117.     {
  118.         $new_width  $max_size;
  119.         $new_height $max_size;
  120.     }
  121.     elseif ($img_data[0$img_data[1])
  122.     {
  123.         $new_width  $max_size;
  124.         $new_height round(($img_data[1]/$img_data[0]$max_size);
  125.     }
  126.     else {
  127.         $new_width  round(($img_data[0]/$img_data[1]$max_size);
  128.         $new_height $max_size;
  129.     }
  130.  
  131.     imagecopyresampled($thumb$img_srcround(($max_size-$new_width)/2)round(($max_size-$new_height)/2)00$new_width$new_height$img_data[0]$img_data[1]);
  132.  
  133.     header($_SERVER['SERVER_PROTOCOL'' 200 OK'true);
  134.     header('Date: ' gmdate("D, d M Y H:i:s"' GMT'true);
  135.     header('Content-Type:' $headertrue);
  136.  
  137.     ob_start();
  138.     switch ($img_data[2])
  139.     {
  140.         case '1' imagegif($thumb)break;
  141.         case '2' imagejpeg($thumb''70)break;
  142.         case '3' imagepng($thumb''7)break;
  143.     }
  144.     $a ob_get_contents();
  145.     ob_end_clean();
  146.     $fp fopen(UPDIR $thumb_id'wb+');
  147.     fwrite($fp$a);
  148.     fclose($fp);
  149.     @chmod(UPDIR $thumb_id0777);
  150.     echo $a;
  151.     imagedestroy($thumb);
  152. }
  153.  
  154. $_REQUEST['action'(isset($_REQUEST['action'])) $_REQUEST['action''';
  155.  
  156. if ($_REQUEST['action']=='upload')
  157. {
  158.     $AVE_Template->display('browser_upload.tpl');
  159.     exit;
  160. }
  161.  
  162. if ($_REQUEST['action']=='upload2')
  163. {
  164.     for ($i=0;$i<count($_FILES['upfile']['tmp_name']);$i++)
  165.     {
  166.         $d_name strtolower(trim($_FILES['upfile']['name'][$i]));
  167.         $d_name str_replace(' '''$d_name);
  168.         $d_tmp $_FILES['upfile']['tmp_name'][$i];
  169.         $endg strtolower(substr($d_namestrlen($d_name4));
  170.  
  171.         if ($_FILES['upfile']['type'][$i]=='image/pjpeg' ||
  172.             $_FILES['upfile']['type'][$i]=='image/jpeg' ||
  173.             $_FILES['upfile']['type'][$i]=='image/x-png' ||
  174.             $_FILES['upfile']['type'][$i]=='image/png')
  175.         {
  176.             if (file_exists(UPDIR $_REQUEST['pfad'$d_name ))
  177.             {
  178.                 $expl explode('.'$d_name);
  179.                 $d_name $expl[0date('dhi')'.' $expl[1];
  180.             }
  181.  
  182.             reportLog($_SESSION['user_name'' - загрузил изображение в ('stripslashes($_REQUEST['pfad']$d_name')'22);
  183.  
  184.             @move_uploaded_file($d_tmpUPDIR $_REQUEST['pfad'$d_name);
  185.             @chmod(UPDIR $_REQUEST['pfad'$d_name0777);
  186.             if (isset($_REQUEST['resize']&& $_REQUEST['resize']==1)
  187.             {
  188.                 $error 0;
  189.  
  190.                 if (function_exists('imagecreatetruecolor'))
  191.                 {
  192.                     $sowhat 'imagecreatetruecolor';
  193.                 }
  194.                 else
  195.                 {
  196.                     $sowhat 'imagecreate';
  197.                 }
  198.  
  199.                 $neues_bild $sowhat($_REQUEST['w']$_REQUEST['h']);
  200.                 if ($_FILES['upfile']['type'][$i]=='image/pjpeg' || $_FILES['upfile']['type'][$i]=='image/jpeg')
  201.                 {
  202.                     $altes_bild imagecreatefromjpeg(UPDIR $_REQUEST['pfad'$d_name);
  203.                 }
  204.  
  205.                 if ($_FILES['upfile']['type'][$i]=='image/png' || $_FILES['upfile']['type'][$i]=='x/png')
  206.                 {
  207.                     $altes_bild imagecreatefrompng(UPDIR $_REQUEST['pfad'$d_name);
  208.                 }
  209.  
  210.                 if ($_FILES['upfile']['type'][$i]=='image/gif')
  211.                 {
  212.                     $error 1;
  213.                 }
  214.  
  215.                 if (isset($altes_bild))
  216.                 {
  217.                     imagecopyresampled($neues_bild$altes_bild0000imagesx($neues_bild)imagesy($neues_bild)imagesx($altes_bild)imagesy($altes_bild));
  218.  
  219.                     if ($_FILES['upfile']['type'][$i]=='image/pjpeg' || $_FILES['upfile']['type'][$i]=='image/jpeg')
  220.                     {
  221.                         unlink(UPDIR $_REQUEST['pfad'$d_name);
  222.                         imagejpeg($neues_bildUPDIR $_REQUEST['pfad'$d_name95);
  223.                     }
  224.  
  225.                     if ($_FILES['upfile']['type'][$i]=='image/png' || $_FILES['upfile']['type'][$i]=='x/png')
  226.                     {
  227.                         unlink(UPDIR $_REQUEST['pfad'$d_name);
  228.                         imagepng($neues_bildUPDIR $_REQUEST['pfad'$d_name95);
  229.                     }
  230.                 }
  231.             }
  232.             else
  233.             {
  234.                 $d_tmp $_FILES['upfile']['tmp_name'];
  235.                 move_uploaded_file($d_tmpUPDIR $_REQUEST['pfad'$d_name);
  236.                 @chmod(UPDIR $_REQUEST['pfad'$d_name0777);
  237.             }
  238.         }
  239.         else
  240.         {
  241.             move_uploaded_file($d_tmpUPDIR $_REQUEST['pfad'$d_name);
  242.             @chmod(UPDIR $_REQUEST['pfad'$d_name0777);
  243.         }
  244.     }
  245.  
  246.     echo "<script language=\"javascript\"> \n",
  247.         "<!-- \n",
  248.         "window.opener.parent.frames['zf'].location.href = window.opener.parent.frames['zf'].location.href; \n",
  249.         "window.close(); \n",
  250.         "//--> \n",
  251.         "</script> \n";
  252.     exit();
  253. }
  254.  
  255. if ($_REQUEST['action']=='delfile')
  256. {
  257.     if (check_permission('mediapool_del'))
  258.     {
  259.         @copy(UPDIR $_REQUEST['file']BASE_DIR '/uploads/recycled/' $_REQUEST['df');
  260.         if (@unlink(UPDIR $_REQUEST['file']))
  261.         {
  262.             $error 0;
  263.             reportLog($_SESSION['user_name'' - удалил изображение (' stripslashes($_REQUEST['file'])  ')'22);
  264.  
  265.             $img_path $_REQUEST['file'];
  266.             $namepos strrpos($img_path'/');
  267.             if ($namepos 0)
  268.             {
  269.                 $img_name substr($img_path++$namepos);
  270.                 $img_dir  substr($img_path0$namepos);
  271.                 if (substr($img_path01!= '/')
  272.                 {
  273.                     $img_dir '/' $img_dir;
  274.                 }
  275.             }
  276.             else
  277.             {
  278.                 $img_name substr($img_path1);
  279.                 $img_dir  '/';
  280.             }
  281.             @unlink(UPDIR $img_dir $th_pref $img_name);
  282.  
  283.             $_REQUEST['file''';
  284.             $_REQUEST['action''';
  285.             echo "<script language=\"javascript\"> \n",
  286.                 "<!-- \n",
  287.                 "parent.frames['zf'].location.href=\"browser.php?typ="$_REQUEST['typ']"&dir="$_REQUEST['dir']"&cpengine="SESSION"&done=1\"; \n",
  288.                 "--> \n",
  289.                 "</script> \n";
  290.         }
  291.     }
  292.     else
  293.     {
  294.         echo "<script language=\"javascript\"> \n",
  295.             "<!-- \n",
  296.             "parent.frames['zf'].location.href=\"browser.php?typ="$_REQUEST['typ']"&dir="$_REQUEST['dir']"&cpengine="SESSION"&done=1\"; \n",
  297.             "--> \n",
  298.             "</script> \n";
  299.     }
  300.     $_REQUEST['action''list';
  301. }
  302.  
  303. $_REQUEST['done'(isset($_REQUEST['done']&& $_REQUEST['done']==1'';
  304. $dir (isset($_REQUEST['dir']&& $_REQUEST['dir'!= ''$_REQUEST['dir''';
  305. $dir (strpos($dir'//')!==false || substr($dir04)=='/../' '' $dir;
  306.  
  307. if ($_REQUEST['action']=='list' || $_REQUEST['done']==1)
  308. {
  309.     if (substr($dir-4== '/../')
  310.     {
  311.         $dir explode('/'substr($dir0-4));
  312.         array_pop($dir);
  313.         $dir implode('/'$dir);
  314.         $dir rtrim($dir'/''/';
  315.     }
  316.  
  317.     if (!($dir=='/'))
  318.     {
  319.         $AVE_Template->assign('dir'$dir);
  320.         $AVE_Template->assign('dirup'1);
  321.     }
  322.  
  323.     $resuld @mkdir(UPDIR $mediapath'' $dir $_REQUEST['newdir']);
  324.     $d @dir(UPDIR $mediapath'' $dir);
  325.  
  326.     while (false !== ($entry @$d->read()))
  327.     {
  328.         if ($entry != '.' &&
  329.             $entry != '..' &&
  330.             $entry != '.svn' &&
  331.             $entry != 'index.php' &&
  332.             $entry != 'thumbnail' &&
  333.             substr($entry0strlen($th_pref)) != $th_pref)
  334.         {
  335.             if (is_dir(UPDIR $mediapath'' $dir $entry))
  336.             {
  337.                 $elem['dir'][$entry;
  338.             }
  339.             else
  340.             {
  341.                 $elem['file'][$entry;
  342.             }
  343.         }
  344.     }
  345.     $d->close();
  346.  
  347.     @asort($elem['dir']);
  348.     $bfiles array();
  349.     while (list($key$val@each($elem['dir']))
  350.     {
  351.         unset($row);
  352.         $row->fileopen $_REQUEST['typ'"&amp;cpengine=" SESSION "&amp;dir=" $dir $val "/&amp;action=list";
  353.         $row->val $val;
  354.         array_push($bfiles$row);
  355.     }
  356.  
  357.     @asort($elem['file']);
  358.     $unable_delete 0;
  359.     $dats array();
  360.     while (list($key$val@each($elem['file']))
  361.     {
  362.         unset($row);
  363.         $endg strtolower(substr($valstrlen($val3));
  364.         $endg_r strtolower(substr($valstrlen($val4));
  365.         $end $endg;
  366.  
  367.         $file_allowed array(
  368.             '.swf''.fla''.rar''.zip''.pdf''.exe''.avi',
  369.             '.mov''r.gz''.doc''.wmf''.wmv''.mp3''.mp4',
  370.             '.mpg''.tif''.psd''.txt''.xls''.pps'
  371.         );
  372.         $allowed_images =  array('.jpg''jpeg''.png''.gif');
  373.  
  374.         if (isset($_REQUEST['target']&& $_REQUEST['target']=='link')
  375.         {
  376.             $allowed $file_allowed;
  377.         }
  378.  
  379.         $val_allowed substr($val-4);
  380.  
  381.         $row->gifends (file_exists($tpl_dir '/images/mediapool/' $endg '.gif')) $endg 'attach';
  382.         $row->gifend $row->gifends;
  383.         $row->datsize @round(@filesize('../uploads' $dir $val)/10242);
  384.         $row->val $val;
  385.         $row->moddate date("d.m.y, H:i"@filemtime('../uploads' $dir $val));
  386.         $row->rowval $dir $val;
  387.  
  388.         if (in_array($val_allowed,$allowed_images&& function_exists('getimagesize'&& function_exists('imagecreatetruecolor'))
  389.         {
  390.             $row->bild "<img border=\"0\" src=\"browser.php?thumb=1&bild=" $dir $val "\">";
  391.         }
  392.  
  393.         $unable_delete (strpos($dir'recycled')!==false0;
  394.         array_push($dats$row);
  395.         unset($row);
  396.     }
  397.  
  398.     $AVE_Template->assign('unable_delete'$unable_delete);
  399.     $AVE_Template->assign('dats'$dats);
  400.     $AVE_Template->assign('bfiles'$bfiles);
  401.     $AVE_Template->assign('dir'$dir);
  402.  
  403.     $_REQUEST['newdir'(isset($_REQUEST['newdir'])) $_REQUEST['newdir''';
  404.     if (!empty($_REQUEST['newdir']))
  405.     {
  406.         if ($resuld)
  407.         {
  408.             $oldumask umask(0);
  409.             chmod(UPDIR $dir $_REQUEST['newdir']0777);
  410.             umask($oldumask);
  411.         }
  412.         else
  413.         {
  414.             echo "<script language=\"JavaScript\" type=\"text/javascript\"> \n",
  415.             "alert(\"Ошибка! Невозможно создать директорию на сервере. Пожалуйста, проверьте ваши настройки.\"); \n",
  416.             "</script> \n";
  417.         }
  418.     }
  419.  
  420.     $AVE_Template->display('browser.tpl');
  421.  
  422. }
  423. else
  424. {
  425.     $sub_target @explode('__'$_REQUEST['target']);
  426.     if (is_array($sub_target)) $sub @$sub_target[1];
  427.  
  428.     $AVE_Template->assign('target_img'$sub_target[0]);
  429.     $AVE_Template->assign('pop_id'$sub);
  430.     $AVE_Template->assign('cppath'substr($_SERVER['PHP_SELF']0-18));
  431.     $AVE_Template->display('browser_2frames.tpl');
  432. }
  433.  
  434. ?>

Documentation generated on Fri, 04 Jun 2010 18:01:06 +0400 by phpDocumentor 1.4.3