/components/com_rsform/rsform.class.php

https://github.com/shafiqissani/Jewelery-Ecommerce- · PHP · 175 lines · 122 code · 39 blank · 14 comment · 29 complexity · ddcd7943f8fe5584a90d59a935099ff5 MD5 · raw file

  1. <?php
  2. /**
  3. * @version 1.2.0
  4. * @package RSform!Pro 1.2.0
  5. * @copyright (C) 2007-2009 www.rsjoomla.com
  6. * @license Commercial License, http://www.rsjoomla.com/terms-and-conditions.html
  7. */
  8. // no direct access
  9. defined( '_JEXEC' ) or die( 'Restricted access' );
  10. ///////////////////////////////////////////////////// SUBMISSIONS /////////////////////////////////////////////////////
  11. include('submissions.class.php');
  12. ///////////////////////////////////////////////////// CAPTCHA /////////////////////////////////////////////////////
  13. include('captcha.class.php');
  14. ///////////////////////////////////////////////////// RSINSTALLER /////////////////////////////////////////////////////
  15. class RSinstaller {
  16. var $archivename = "";
  17. var $installDir = "";
  18. var $installFile = "";
  19. var $installType = "";
  20. var $unpackDir = "";
  21. var $xmldoc = null;
  22. var $msg = null;
  23. var $elementName = null;
  24. var $elementDir = null;
  25. function upload($filename = null)
  26. {
  27. $this->archivename = $filename;
  28. if ($this->extract()) {
  29. if(file_exists($this->installDir . '/install.xml'))
  30. {
  31. $this->setInstallFile($this->installDir . '/install.xml');
  32. return true;
  33. }
  34. else return false;
  35. } else {
  36. return false;
  37. }
  38. }
  39. function extract()
  40. {
  41. $RSadapter = $GLOBALS['RSadapter'];
  42. $base_Dir = $RSadapter->processPath( $RSadapter->config['absolute_path'] . '/media' );
  43. $archivename = $base_Dir . $this->archivename;
  44. $tmpdir = uniqid( 'rsinstall_' );
  45. $extractdir = $RSadapter->processPath( $base_Dir . $tmpdir );
  46. $archivename = $RSadapter->processPath( $archivename, false );
  47. $this->unpackDir = $extractdir ;
  48. if (eregi( '.zip$', $archivename )) {
  49. // Extract functions
  50. require_once( $RSadapter->config['absolute_path'] . '/administrator/includes/pcl/pclzip.lib.php' );
  51. require_once( $RSadapter->config['absolute_path'] . '/administrator/includes/pcl/pclerror.lib.php' );
  52. $zipfile = new PclZip( $archivename );
  53. if((substr(PHP_OS, 0, 3) == 'WIN')) {
  54. define('OS_WINDOWS',1);
  55. } else {
  56. define('OS_WINDOWS',0);
  57. }
  58. $ret = $zipfile->extract( PCLZIP_OPT_PATH, $extractdir );
  59. if($ret == 0) {
  60. $this->msg = 'Unrecoverable error "'.$zipfile->errorName(true).'"' ;
  61. return false;
  62. }
  63. } else {
  64. require_once( $RSadapter->config['absolute_path'] . '/includes/Archive/Tar.php' );
  65. $archive = new Archive_Tar( $archivename );
  66. $archive->setErrorHandling( PEAR_ERROR_PRINT );
  67. if (!$archive->extractModify( $extractdir, '' )) {
  68. $this->msg = 'Extract Error' ;
  69. return false;
  70. }
  71. }
  72. $this->installDir = $extractdir;
  73. // Try to find the correct install dir. in case that the package have subdirs
  74. // Save the install dir for later cleanup
  75. $filesindir = $RSadapter->readDirectory( $this->installDir, '' );
  76. if (count( $filesindir ) == 1) {
  77. if (is_dir( $extractdir . $filesindir[0] )) {
  78. $this->installDir = $RSadapter->processPath( $extractdir . $filesindir[0] ) ;
  79. }
  80. }
  81. return true;
  82. }
  83. function setInstallFile( $filename = null )
  84. {
  85. if(!is_null($filename)) {
  86. if((substr(PHP_OS, 0, 3) == 'WIN')) {
  87. $this->installFile = str_replace('/','\\',$filename);
  88. } else {
  89. $this->installFile = str_replace('\\','/',$filename);
  90. }
  91. }
  92. return $this->installFile;
  93. }
  94. function readInstall()
  95. {
  96. $this->xmldoc = new DOMIT_Lite_Document();
  97. $this->xmldoc->resolveErrors( true );
  98. if (!$this->xmldoc->loadXML( $this->installFile, false, true )) {
  99. return false;
  100. }
  101. $root = &$this->xmldoc->documentElement;
  102. // Check that it's an installation file
  103. if ($root->getTagName() != 'RSinstall') {
  104. $this->msg = 'File :"' . $this->installFile . '" is not a valid RSform!Pro installation file' ;
  105. return false;
  106. }
  107. $this->installType = $root->getAttribute( 'type' ) ;
  108. return true;
  109. }
  110. function cleanup( $userfile_name, $resultdir) {
  111. $RSadapter = $GLOBALS['RSadapter'];
  112. if (file_exists( $resultdir )) {
  113. $this->deldir( $resultdir );
  114. unlink( $RSadapter->processPath( $RSadapter->config['absolute_path'] . '/media/' . $userfile_name, false ) );
  115. }
  116. }
  117. function deldir( $dir ) {
  118. $RSadapter = $GLOBALS['RSadapter'];
  119. $current_dir = opendir( $dir );
  120. $old_umask = umask(0);
  121. while ($entryname = readdir( $current_dir )) {
  122. if ($entryname != '.' and $entryname != '..') {
  123. if (is_dir( $dir . $entryname )) {
  124. $this->deldir( $RSadapter->processPath( $dir . $entryname ) );
  125. } else {
  126. @chmod($dir . $entryname, 0777);
  127. unlink( $dir . $entryname );
  128. }
  129. }
  130. }
  131. umask($old_umask);
  132. closedir( $current_dir );
  133. return rmdir( $dir );
  134. }
  135. }
  136. ?>