PageRenderTime 44ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/components/admin/extplorer/include/extract.php

https://code.google.com/p/mwenhanced/
PHP | 108 lines | 52 code | 12 blank | 44 comment | 7 complexity | cc2eff75298b7426d068bee02633acac MD5 | raw file
Possible License(s): LGPL-2.1, AGPL-3.0, AGPL-1.0, GPL-2.0, MPL-2.0-no-copyleft-exception
  1. <?php
  2. // ensure this file is being included by a parent file
  3. if( ! defined( '_JEXEC' ) && ! defined( '_VALID_MOS' ) )
  4. die( 'Restricted access' ) ;
  5. /**
  6. * @version $Id: extract.php 115 2009-01-10 11:18:58Z soeren $
  7. * @package eXtplorer
  8. * @copyright soeren 2007
  9. * @author The eXtplorer project (http://sourceforge.net/projects/extplorer)
  10. * @author The The QuiX project (http://quixplorer.sourceforge.net)
  11. *
  12. * @license
  13. * The contents of this file are subject to the Mozilla Public License
  14. * Version 1.1 (the "License"); you may not use this file except in
  15. * compliance with the License. You may obtain a copy of the License at
  16. * http://www.mozilla.org/MPL/
  17. *
  18. * Software distributed under the License is distributed on an "AS IS"
  19. * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
  20. * License for the specific language governing rights and limitations
  21. * under the License.
  22. *
  23. * Alternatively, the contents of this file may be used under the terms
  24. * of the GNU General Public License Version 2 or later (the "GPL"), in
  25. * which case the provisions of the GPL are applicable instead of
  26. * those above. If you wish to allow use of your version of this file only
  27. * under the terms of the GPL and not to allow others to use
  28. * your version of this file under the MPL, indicate your decision by
  29. * deleting the provisions above and replace them with the notice and
  30. * other provisions required by the GPL. If you do not delete
  31. * the provisions above, a recipient may use your version of this file
  32. * under either the MPL or the GPL."
  33. *
  34. *
  35. */
  36. /**
  37. * Allows to extract archives on the server
  38. *
  39. */
  40. class ext_Extract extends ext_Action {
  41. function execAction( $dir, $item ) {
  42. global $mosConfig_absolute_path ;
  43. if( ! ext_isArchive( $item ) ) {
  44. ext_Result::sendResult( 'archive', false, ext_Lang::err( 'extract_noarchive' ) ) ;
  45. } else {
  46. $archive_name = realpath( get_abs_item( $dir, $item ) ) ;
  47. $file_info = pathinfo( $archive_name ) ;
  48. if( empty( $dir ) ) {
  49. $extract_dir = realpath( $GLOBALS['home_dir'] ) ;
  50. } else {
  51. $extract_dir = realpath( $GLOBALS['home_dir'] . "/" . $dir ) ;
  52. }
  53. $ext = $file_info["extension"] ;
  54. switch( $ext) {
  55. case "zip" :
  56. require_once (_EXT_PATH . "/libraries/Zip.php") ;
  57. $extract_dir = str_replace('\\', '/', $extract_dir );
  58. $zip = new Archive_Zip( $archive_name ) ;
  59. $res = $zip->extract( array( 'add_path' => $extract_dir) ) ;
  60. if( $res == 0 ) {
  61. ext_Result::sendResult( 'extract', false, ext_Lang::err( 'extract_failure' ).' ('.$zip->errorInfo(true).')');
  62. } else
  63. ext_Result::sendResult( 'extract', false, ext_Lang::msg( 'extract_success' ));
  64. break ;
  65. case "gz" : // a
  66. case "bz" : // lot
  67. case "bz2" : // of
  68. case "bzip2" : // fallthroughs,
  69. case "tbz" : // don't
  70. case "tar" : // wonder
  71. require_once (_EXT_PATH . "/libraries/Tar.php") ;
  72. $archive = new Archive_Tar( $archive_name ) ;
  73. if( $archive->extract( $extract_dir ) )
  74. ext_Result::sendResult( 'extract', true, ext_Lang::msg( 'extract_success' ));
  75. else
  76. ext_Result::sendResult( 'extract', false, ext_Lang::err( 'extract_failure' ));
  77. break ;
  78. default :
  79. ext_Result::sendResult( 'extract', false, ext_Lang::err( 'extract_unknowntype' ));
  80. break ;
  81. }
  82. /*
  83. require_once (_EXT_PATH . "/libraries/Archive/archive.php") ;
  84. $result = extArchive::extract( $archive_name, $extract_dir ) ;
  85. if( PEAR::isError( $result ) ) {
  86. ext_Result::sendResult( 'extract', false, ext_Lang::err( 'extract_failure' ) . ': ' . $result->getMessage() ) ;
  87. }
  88. */
  89. ext_Result::sendResult( 'extract', true, ext_Lang::msg( 'extract_success' ) ) ;
  90. }
  91. }
  92. }
  93. ?>