public static function getInstallerList() { // This is a static cache which persists between subsequent calls, but not // between successive page loads. static $installer_list = array(); // Try to serve cached data first if(!empty($installer_list) && is_array($installer_list)) { if(count($installer_list) > 0) return $installer_list; } // Find absolute path to normal and plugins directories $ds = DIRECTORY_SEPARATOR; $path_list = array( AEPlatform::get_installer_images_path() ); // Initialize the array where we store our data $installer_list = array(); // Loop for the paths where engines can be found foreach($path_list as $path) { if(is_dir($path)) { if(is_readable($path)) { if( $handle = @opendir($path) ) { while(false !== $filename = @readdir($handle)) { if( (strtolower(substr($filename, -4)) == '.ini') && @is_file($path.$ds.$filename) ) { $data = AEUtilINI::parse_ini_file($path.$ds.$filename, true); foreach($data as $key => $values) { $installer_list[$key] = array(); foreach($values as $key2 => $value) { $installer_list[$key][$key2]=$value; } } } } // while readdir @closedir($handle); } // if opendir } // if readable } // if is_dir } return $installer_list; }
/** * Transforms a JPA archive (containing an installer) to the native archive format * of the class. It actually extracts the source JPA in memory and instructs the * class to include each extracted file. * * @param int $offset The source JPA archive's offset to use * @return boolean False if an error occured, true otherwise */ public final function transformJPA( $offset ) { // Do we have to open the file? if(!$this->_xform_fp) { // Get the source path $registry =& AEFactory::getConfiguration(); $embedded_installer = $registry->get('akeeba.advanced.embedded_installer'); // Fetch the name of the installer image $installerDescriptors = AEUtilInihelper::getInstallerList(); $xform_source = AEPlatform::get_installer_images_path().DIRECTORY_SEPARATOR. 'foobar.jpa'; // We need this as a "safe fallback" if(array_key_exists($embedded_installer, $installerDescriptors)) { $package = $installerDescriptors[$embedded_installer]['package']; if(empty($package)) { // No installer package specified. Pretend we are done! $retArray = array( "filename" => '', // File name extracted "data" => '', // File data "offset" => 0, // Offset in ZIP file "skip" => false, // Skip this? "done" => true, // Are we done yet? "filesize" => 0 ); return $retArray; } else { // A package is specified, use it! $xform_source = AEPlatform::get_installer_images_path().DIRECTORY_SEPARATOR. $package; } } // 2.3: Try to use sane default if the indicated installer doesn't exist if( !file_exists($xform_source) && (basename($xform_source) != 'abi.jpa') ) { $this->setWarning(__CLASS__ . ":: Selected embedded installer not found, using ABI instead"); $xform_source = dirname($xform_source).DS.'abi.jpa'; } // Try opening the file if( file_exists($xform_source) ) { $this->_xform_fp = @fopen( $xform_source, 'r'); if( $this->_xform_fp === false ) { $this->setError(__CLASS__ . ":: Can't seed archive with installer package ".$xform_source); return false; } } else { $this->setError(__CLASS__ . ":: Installer package ".$xform_source." does not exist!"); return false; } } if(!$offset) { // First run detected! AEUtilLogger::WriteLog(_AE_LOG_DEBUG, 'Initializing with JPA package '); $offset = 0; // Skip over the header and check no problem exists $offset = $this->_xformReadHeader(); if($offset === false) { $this->setError('JPA package file was not read'); return false; // Oops! The package file doesn't exist or is corrupt } } $ret =& $this->_xformExtract($offset); if(is_array($ret)) { $offset = $ret['offset']; if(!$ret['skip'] && !$ret['done']) { AEUtilLogger::WriteLog(_AE_LOG_DEBUG, ' Adding '.$ret['filename'] . '; Next offset:'.$offset); $this->addVirtualFile($ret['filename'], '', $ret['data']); if($this->getError()) return false; } else { $reason = $ret['done'] ? 'Done' : ' Skipping '.$ret['filename']; AEUtilLogger::WriteLog(_AE_LOG_DEBUG, $reason); } } else { $this->setError('JPA extraction returned FALSE'); return false; } if($ret['done']) { // We are finished! Close the file fclose($this->_xform_fp); AEUtilLogger::WriteLog(_AE_LOG_DEBUG, 'Initializing with JPA package has finished'); } $ret['filesize'] = @filesize($xform_source); return $ret; }