Source for file admin.media.php

Documentation is available at admin.media.php

  1. <?php
  2. /**
  3. @package Mambo
  4. @subpackage Massmail
  5. @copyright  Refer to copyright.php
  6. @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
  7. @author Mambo Foundation Inc see README.php
  8. */
  9.  
  10. /** ensure this file is being included by a parent file */
  11. defined'_VALID_MOS' or die'Direct Access to this location is not allowed.' );
  12.  
  13. // ensure user has access to this function
  14. if (!($acl->acl_check'administration''edit''users'$my->usertype'components''all' )
  15.         | $acl->acl_check'administration''edit''users'$my->usertype'components''com_media' ))) {
  16.     mosRedirect'index2.php'T_('You are not authorized to view this resource.') );
  17. }
  18.  
  19. require_once$mainframe->getPath'admin_html' ) );
  20. //require_once( $mainframe->getPath( 'class' ) );
  21.  
  22. $cid mosGetParam$_POST'cid'array(0) );
  23. $foldername mosGetParam($_POST'foldername''');
  24. $listdir mosGetParam($_REQUEST'listdir''');
  25. $dirPath mosGetParam($_POST'dirPath''');
  26. $task mosGetParam($_REQUEST'task''');
  27.  
  28.  
  29. if (!is_array$cid )) {
  30.     $cid array(0);
  31. }
  32.  
  33. if (is_int(strpos ($listdir"..")) && $listdir<>''{
  34.     mosRedirect"index2.php?option=com_media&listdir=".$_POST['dirPath']T_("NO HACKING PLEASE") );
  35.     }
  36.  
  37. switch ($task{
  38.  
  39.     case "upload":
  40.         upload();
  41.         showMedia($dirPath);
  42.         break;
  43.  
  44.     case "newdir":
  45.         if (ini_get('safe_mode')=="On"{
  46.             mosRedirect"index2.php?option=com_media&listdir=".$_POST['dirPath']T_("Directory creation not allowed while running in SAFE MODE as this can cause problems.") );
  47.             }
  48.         else {
  49.             create_folder($foldername,$dirPath);
  50.         }
  51.         showMedia($dirPath);
  52.         break;
  53.  
  54.     case "delete":
  55.         delete_file($delFile,$listdir);
  56.         showMedia($listdir);
  57.         break;
  58.  
  59.     case "deletefolder":
  60.         delete_folder($delFolder,$listdir);
  61.         showMedia($listdir);
  62.         break;
  63.  
  64.     case "list":
  65.         listImages($listdir);
  66.         break;
  67.  
  68.     default:
  69.         showMedia($listdir);
  70.         break;
  71. }
  72.  
  73.  
  74.  
  75.  
  76. function delete_file($delfile$listdir)
  77. {
  78.     global $mosConfig_absolute_path;
  79.     $del_image $mosConfig_absolute_path."/images/stories".$listdir."/".$delfile;
  80.     unlink($del_image);
  81. }
  82.  
  83. function create_folder($folder_name,$dirPath)
  84. {
  85.     global $mosConfig_absolute_path;
  86.  
  87.     if(strlen($folder_name>0)
  88.     {
  89.         if (eregi("[^0-9a-zA-Z_]"$folder_name)) {
  90.             mosRedirect"index2.php?option=com_media&listdir=".$_POST['dirPath']T_("Directory name must only contain alphanumeric characters and no spaces please.") );
  91.         }
  92.         $folder $mosConfig_absolute_path."/images/stories".$dirPath."/".$folder_name;
  93.         if(!is_dir($folder&& !is_file($folder))
  94.         {
  95.             mosMakePath($folder);
  96.             $fp fopen($folder."/index.html""w" );
  97.             fwrite$fp"<html>\n<body bgcolor=\"#FFFFFF\">\n</body>\n</html>" );
  98.             fclose$fp );
  99.             mosChmod($folder."/index.html");
  100.             $refresh_dirs true;
  101.         }
  102.     }
  103. }
  104.  
  105. function delete_folder($delFolder,$listdir)
  106. {
  107.     global $mosConfig_absolute_path;
  108.  
  109.     $del_html $mosConfig_absolute_path.'/images/stories'.$listdir.$delFolder.'/index.html';
  110.     $del_folder $mosConfig_absolute_path.'/images/stories'.$listdir.$delFolder;
  111.  
  112.     $entry_count 0;
  113.     $dir opendir$del_folder );
  114.     while $entry readdir$dir ))
  115.     {
  116.         if$entry != "." $entry != ".." strtolower($entry!= "index.html" )
  117.         $entry_count++;
  118.     }
  119.     closedir$dir );
  120.  
  121.     if$entry_count )
  122.     {
  123.         @unlink($del_html);
  124.         rmdir($del_folder);
  125.     else {
  126.         echo '<font color="red">'.T_('Unable to delete: not empty!').'</font>';
  127.     }
  128. }
  129.  
  130. function upload(){
  131.  
  132.     global $mosConfig_absolute_path;
  133.  
  134.     if(isset($_FILES['upload']&& is_array($_FILES['upload']&& isset($_POST['dirPath']))
  135.     {
  136.         $dirPathPost $_POST['dirPath'];
  137.  
  138.         if(strlen($dirPathPost0)
  139.         {
  140.             if(substr($dirPathPost,0,1)=='/')
  141.                 $IMG_ROOT .= $dirPathPost;
  142.             else
  143.                 $IMG_ROOT $dirPathPost;
  144.         }
  145.  
  146.         if(strrpos($IMG_ROOT'/')!= strlen($IMG_ROOT)-1)
  147.             $IMG_ROOT .= '/';
  148.  
  149.     do_upload$_FILES['upload']$mosConfig_absolute_path.'/images/stories/'.$dirPathPost.'/');
  150.     }
  151. }
  152.  
  153. function do_upload($file$dest_dir)
  154. {
  155.     global $clearUploads;
  156.  
  157.         if (file_exists($dest_dir.$file['name'])) {
  158.             mosRedirect"index2.php?option=com_media&listdir=".$_POST['dirPath']T_("Upload FAILED. File already exists") );
  159.         }
  160.  
  161.         if ((strcasecmp(substr($file['name'],-4),".gif")) && (strcasecmp(substr($file['name'],-4),".jpg")) && (strcasecmp(substr($file['name'],-4),".png")) && (strcasecmp(substr($file['name'],-4),".bmp")) &&(strcasecmp(substr($file['name'],-4),".doc")) && (strcasecmp(substr($file['name'],-4),".xls")) && (strcasecmp(substr($file['name'],-4),".ppt")) && (strcasecmp(substr($file['name'],-4),".swf")) && (strcasecmp(substr($file['name'],-4),".pdf"))) {
  162.             mosRedirect"index2.php?option=com_media&listdir=".$_POST['dirPath']T_("Only files of type gif, png, jpg, bmp, pdf, swf, doc, xls or ppt can be uploaded") );
  163.         }
  164.  
  165.         if (!move_uploaded_file($file['tmp_name']$dest_dir.strtolower($file['name']))){
  166.             mosRedirect"index2.php?option=com_media&listdir=".$_POST['dirPath']T_("Upload FAILED") );
  167.             }
  168.         else {
  169.             mosChmod($dest_dir.strtolower($file['name']));
  170.             mosRedirect"index2.php?option=com_media&listdir=".$_POST['dirPath']T_("Upload complete") );
  171.         }
  172.  
  173.     $clearUploads true;
  174. }
  175.  
  176. function recursive_listdir($base{
  177.     static $filelist array();
  178.     static $dirlist array();
  179.  
  180.     if(is_dir($base)) {
  181.        $dh opendir($base);
  182.        while (false !== ($dir readdir($dh))) {
  183.            if (is_dir($base ."/"$dir&& $dir !== '.' && $dir !== '..' && strtolower($dir!== 'cvs'{
  184.                 $subbase $base ."/"$dir;
  185.                 $dirlist[$subbase;
  186.                 $subdirlist recursive_listdir($subbase);
  187.             }
  188.         }
  189.         closedir($dh);
  190.     }
  191.     return $dirlist;
  192.  }
  193.  
  194.  
  195. /**
  196. * Show media manager
  197. @param string The image directory to display
  198. */
  199. function showMedia($listdir{
  200.  
  201.     global $mosConfig_absolute_path$mosConfig_live_site;
  202.  
  203.     // get list of directories
  204.     $imgFiles recursive_listdir$mosConfig_absolute_path."/images/stories" );
  205.     $images array();
  206.     $folders array();
  207.     $folders[mosHTML::makeOption"/" );
  208.     foreach ($imgFiles as $file{
  209.             $folders[mosHTML::makeOptionsubstr($file,strlen($mosConfig_absolute_path."/images/stories")) );
  210.     }
  211.     if (is_array($folders)) {
  212.         sort$folders );
  213.     }
  214.     // create folder selectlist
  215.     $dirPath mosHTML::selectList$folders'dirPath'"class=\"inputbox\" size=\"1\" "
  216.     ."onchange=\"goUpDir()\" ",
  217.     'value''text'$listdir );
  218.  
  219.     HTML_Media::showMedia($dirPath,$listdir);
  220. }
  221.  
  222.  
  223. /**
  224. * Build imagelist
  225. @param string The image directory to display
  226. */
  227. function listImages($listdir{
  228.     global $mosConfig_absolute_path$mosConfig_live_site;
  229.  
  230.     // get list of images
  231.     $d @dir($mosConfig_absolute_path."/images/stories/".$listdir);
  232.  
  233.     if($d)
  234.     {
  235.  
  236.     //var_dump($d);
  237.     $images array();
  238.     $folders array();
  239.     $docs array();
  240.  
  241.     while (false !== ($entry $d->read()))
  242.     {
  243.         $img_file $entry;
  244.         if(is_file($mosConfig_absolute_path."/images/stories".$listdir.'/'.$img_file&& substr($entry,0,1!= '.' && strtolower($entry!== 'index.html')
  245.         {
  246.             if (eregi"bmp|gif|jpg|png"$img_file )) {
  247.                 $image_info @getimagesize($mosConfig_absolute_path."/images/stories/".$listdir.'/'.$img_file);
  248.                 $file_details['file'$mosConfig_absolute_path."/images/stories".$listdir."/".$img_file;
  249.                 $file_details['img_info'$image_info;
  250.                 $file_details['size'filesize($mosConfig_absolute_path."/images/stories".$listdir."/".$img_file);
  251.                 $images[$entry$file_details;
  252.             }
  253.             else {
  254.                 // file is document
  255.                 $docs[$entry$img_file;
  256.             }
  257.         }
  258.         else if(is_dir($mosConfig_absolute_path."/images/stories/".$listdir.'/'.$img_file&& substr($entry,0,1!= '.' && strtolower($entry!== 'cvs')
  259.         {
  260.             $folders[$entry$img_file;
  261.         }
  262.     }
  263.     $d->close();
  264.  
  265.     HTML_Media::imageStyle($listdir);
  266.  
  267.     if(count($images|| count($folders|| count($docs0)
  268.     {
  269.         //now sort the folders and images by name.
  270.         ksort($images);
  271.         ksort($folders);
  272.         ksort($docs);
  273.  
  274.  
  275.         HTML_Media::draw_table_header();
  276.  
  277.         for($i=0$i<count($folders)$i++)
  278.         {
  279.             $folder_name key($folders);
  280.             HTML_Media::show_dir('/'.$folders[$folder_name]$folder_name,$listdir);
  281.             next($folders);
  282.         }
  283.         for($i=0$i<count($docs)$i++)
  284.         {
  285.             $doc_name key($docs);
  286.             $iconfile$mosConfig_absolute_path."/administrator/components/com_media/images/".substr($doc_name,-3)."_16.png";
  287.             if (file_exists($iconfile))    {
  288.                 $icon "components/com_media/images/".(substr($doc_name,-3))."_16.png"    }
  289.             else {
  290.                 $icon "components/com_media/images/con_info.png";
  291.             }
  292.             HTML_Media::show_doc($docs[$doc_name]$listdir$icon);
  293.             next($docs);
  294.         }
  295.         for($i=0$i<count($images)$i++)
  296.         {
  297.             $image_name key($images);
  298.             HTML_Media::show_image($images[$image_name]['file']$image_name$images[$image_name]['img_info']$images[$image_name]['size'],$listdir);
  299.             next($images);
  300.         }
  301.         HTML_Media::draw_table_footer();
  302.     }
  303.     else
  304.     {
  305.         HTML_Media::draw_no_results();
  306.     }
  307. }
  308. else
  309. {
  310. }
  311.  
  312.  
  313.  
  314. function rm_all_dir($dir)
  315. {
  316.     //$dir = dir_name($dir);
  317.     //echo "OPEN:".$dir.'<Br>';
  318.     if(is_dir($dir))
  319.     {
  320.         $d @dir($dir);
  321.  
  322.         while (false !== ($entry $d->read()))
  323.         {
  324.             //echo "#".$entry.'<br>';
  325.             if($entry != '.' && $entry != '..')
  326.             {
  327.                 $node $dir.'/'.$entry;
  328.                 //echo "NODE:".$node;
  329.                 if(is_file($node)) {
  330.                     //echo " - is file<br>";
  331.                     unlink($node);
  332.                 }
  333.                 else if(is_dir($node)) {
  334.                     //echo " -    is Dir<br>";
  335.                     rm_all_dir($node);
  336.                 }
  337.             }
  338.         }
  339.         $d->close();
  340.  
  341.         rmdir($dir);
  342.     }
  343.     //echo "RM: $dir <br>";
  344. }
  345.  
  346.  
  347.  
  348.  
  349.  
  350. }
  351.  
  352.  
  353.  
  354.  
  355. ?>

Documentation generated on Mon, 05 May 2008 16:15:30 +0400 by phpDocumentor 1.4.0