protected function execute()
 {
     $this->loadParams();
     $archive = new PclZip($this->zipFile->getFileName());
     $listContent = $archive->listContent();
     $allFilesCount = count($listContent);
     $processedFiles = -self::UNZIP_STEP;
     while ($processedFiles < $allFilesCount) {
         $processedFiles += self::UNZIP_STEP;
         if ($this->isDone($processedFiles, $this->_('%s%% files unzipped', round($processedFiles / $allFilesCount * 100, 0)))) {
             continue;
         }
         $this->changePermissions($archive->extractByIndex($processedFiles . '-' . ($processedFiles + self::UNZIP_STEP - 1), $this->outputDirectory->getFileName()));
         $this->setDone($processedFiles);
     }
 }
 private function copyFile(Gpf_Io_File $source, Gpf_Io_File $target)
 {
     if ($this->isPending(md5($source->getFileName()), $this->_('Copying file'))) {
         $this->copy($source, $target);
         $this->setDone();
     }
 }
 protected function checkFile($fileName, $checkSum)
 {
     if (time() - $this->startTime > 24) {
         $_SESSION['corruptedFiles'] = $this->corruptedFiles;
         $this->echoMessage($this->getCheckingMessage(), $this->getRedirectUrl($this->filesCheckedSoFar));
         exit;
     }
     $this->filesCheckedSoFar++;
     if ($this->filesCheckedSoFar <= $this->progress) {
         return;
     }
     $file = new Gpf_Io_File('../' . $fileName);
     try {
         if ($file->getCheckSum() != $checkSum) {
             $this->corruptedFiles[ltrim($file->getFileName(), '\\.\\.\\/')] = $this->_('CORRUPTED');
         }
     } catch (Gpf_Exception $e) {
         $this->corruptedFiles[ltrim($file->getFileName(), '\\.\\.\\/')] = $this->_('MISSING');
     }
 }
 private function importDataToImportFile(Gpf_Io_File $importFile)
 {
     $fileName = $importFile->getFileName() . "\n";
     $this->file->rewind();
     while ($line = $this->file->readLine()) {
         if ($line == $fileName) {
             $importFile->setFileMode("w");
             $this->importRowsToImportFile($importFile);
             break;
         }
     }
 }
Exemple #5
0
    /**
     * Load into Location object all available data
     *
     * @param GeoIp_Location $location
     */
    public function loadLocation(GeoIp_Location $location) {
        require_once "Net/GeoIP.php";
        $flag = Net_GeoIP::STANDARD;
//TODO: on some hostings it failed to work (e.g. mosso.com), so we will disable option of shared memory until it will be solved
//        if (Gpf_Php::isFunctionEnabled('shmop_open')) {
//            $flag = Net_GeoIP::SHARED_MEMORY;
//        }

        $geoip = Net_GeoIP::getInstance($this->file->getFileName(), $flag);
        if ($geoipLocation = @$geoip->lookupLocation($location->getIpString())) {
            $location->setCountryCode($geoipLocation->countryCode);
            $location->setCity($geoipLocation->city);
            $location->setAreaCode($geoipLocation->areaCode);
            $location->setCountryName($geoipLocation->countryName);
            $location->setDmaCode($geoipLocation->dmaCode);
            $location->setLatitude($geoipLocation->latitude);
            $location->setLongitude($geoipLocation->longitude);
            $location->setPostalCode($geoipLocation->postalCode);
            $location->setRegion($geoipLocation->region);
        } else {
            throw new Gpf_Exception($this->_('Ip address %s is not in geoip database.', $location->getIpString()));
        }
    }
Exemple #6
0
 public function getModule(Gpf_Io_File $file) {
     
     $fileName = str_replace(strtolower(Gpf_Paths::getInstance()->getTopPath()), '', 
     strtolower($file->getFileName()));
     
     if (strpos($fileName, 'merchant') !== false) {
         return 'merchant';
     }
     if (strpos($fileName, 'affiliate') !== false) {
         return 'affiliate';
     }
     
     return '';
 }
 /**
  * Save content of uploaded file to database
  *
  * @param string $filename
  * @param Gpf_Db_File $file
  */
 private function uploadContent($filename, Gpf_Db_File $file)
 {
     $contentId = 1;
     $tmpFile = new Gpf_Io_File(get_cfg_var('upload_tmp_dir') . $filename);
     if (!$tmpFile->isExists()) {
         $tmpFile->setFileName($filename);
     }
     if (!$tmpFile->isExists()) {
         throw new Gpf_Exception("File not found " . $tmpFile->getFileName());
     }
     $tmpFile->open();
     while ($data = $tmpFile->read(500000)) {
         $fileContent = new Gpf_Db_FileContent();
         $fileContent->set('fileid', $file->get('fileid'));
         $fileContent->set('contentid', $contentId++);
         $fileContent->set('content', $data);
         $fileContent->save();
     }
 }
 protected function getLogFileName()
 {
     $logDir = new Gpf_Io_File(Gpf_Paths::getInstance()->getAccountsPath());
     return $logDir->getFileName() . 'benchmark.log';
 }
 public function load(Gpf_Lang_Language $language)
 {
     $file = new Gpf_Io_File($this->getFilename());
     try {
         $file->open('r');
     } catch (Exception $e) {
         try {
             $this->regenerateLanguageCacheFiles();
             $file->open('r');
         } catch (Exception $e2) {
             throw new Gpf_Exception($this->_('Could not open language file %s', $e2->getMessage()));
         }
     }
     $_name = '';
     $_engName = '';
     $_author = '';
     $_version = '';
     $_dict = '';
     $_dateFormat = '';
     $_timeFormat = '';
     $_thousandsSeparator = '';
     $_decimalSeparator = '';
     if (@eval(str_replace(array('<?php', '?>'), '', $file->getContents())) === false) {
         throw new Gpf_Exception($this->_('Corrupted language file %s', $file->getFileName()));
     }
     @$language->setName($_name);
     @$language->setEnglishName($_engName);
     @$language->setAuthor($_author);
     @$language->setVersion($_version);
     @$language->setDictionary($_dict);
     @$language->setDateFormat($_dateFormat);
     @$language->setTimeFormat($_timeFormat);
     @$language->setThousandsSeparator($_thousandsSeparator);
     @$language->setDecimalSeparator($_decimalSeparator);
 }
 protected function getFileName()
 {
     return basename($this->file->getFileName());
 }
Exemple #11
0
 public function getFileName()
 {
     return $this->file->getFileName();
 }
 private function setAndCheckCompileDir()
 {
     $this->checkCompilePanelDirectory();
     $baseCompileDir = Gpf_Templates_Smarty::getCompileDir();
     $dir = new Gpf_Io_File($baseCompileDir . $this->panel . '/' . $this->theme . '/');
     if (!$dir->isExists()) {
         $dir->mkdir(true);
     }
     $this->smarty->compile_dir = $dir->getFileName();
 }
 /**
  * Check if file can be cached. Files containing word nocache will not be cached
  *
  * @param Gpf_Io_File $file
  * @return boolean
  */
 private function isCacheableFile(Gpf_Io_File $file)
 {
     if (strpos($file->getFileName(), 'nocache') !== false) {
         return false;
     }
     return true;
 }
 protected function copyFile(Gpf_Io_File $source, Gpf_Io_File $target, $mode = null)
 {
     $target->open('w');
     $target->write($source->getContents());
     if ($mode !== null) {
         @chmod($target->getFileName(), $mode);
     }
 }
 private static function resolveCompileDirInInstallMode()
 {
     $tempDir = new Gpf_Io_File(str_replace('\\', '/', self::getSysTempDir()));
     if ($tempDir->isDirectory() && $tempDir->isWritable()) {
         return $tempDir->getFileName();
     }
     $accountsDir = new Gpf_Io_File(Gpf_Paths::getInstance()->getFullBaseServerPath() . Gpf_Paths::ACCOUNTS_DIR);
     if ($accountsDir->isDirectory() && $accountsDir->isWritable()) {
         return self::getTempInAccountsDir();
     }
     return self::INSTALL_STREAM . '://:';
 }
 private function isCustomPageTemplate(Gpf_Io_File $templateFile)
 {
     if (strstr($templateFile->getFileName(), Gpf_Paths::DEFAULT_THEME . 'custom/')) {
         return true;
     }
     return false;
 }
 private function findIndexFiles(Gpf_Io_File $directory, $files) {
     foreach ($files as $fileName) {
         $file = new Gpf_Io_File($directory->getFileName().$fileName);
         if ($file->isExists()) {
             return $file;
         }
     }
     throw new Gpf_Exception('not found');
 }
 private function copy($name)
 {
     $source = new Gpf_Io_File(Gpf_Paths::getInstance()->getInstallDirectoryPath() . $name);
     $target = new Gpf_Io_File(Gpf_Paths::getInstance()->getAccountsPath() . $this->account->getId() . '/' . $name);
     try {
         $task = new Gpf_Install_CopyDirectoryTask($source, $target, 0777);
         $task->run($this->maxRunTime);
     } catch (Gpf_Tasks_LongTaskInterrupt $e) {
         throw $e;
     } catch (Exception $e) {
         throw new Gpf_Exception($this->_('Error during creating account directory %s (%s). Please delete it and try again.', $target->getFileName(), $e->getMessage()));
     }
 }
 /**
  * Add parsed message to list of found messages
  *
  * @param string $sourceMessage
  * @param Gpf_Io_File $file
  * @param $type Type of message (server/client/both)
  */
 private function addMessage($sourceMessage, Gpf_Io_File $file, $type)
 {
     if (in_array($file->getExtension(), array('java', 'php'))) {
         @eval("\$sourceMessage = {$sourceMessage};");
     }
     if (!strlen($sourceMessage)) {
         throw new Gpf_Exception($this->_('Source message can\'t be empty in file %s', $file->getFileName()));
     }
     $translation = new Gpf_Lang_Parser_Translation();
     $translation->setSourceMessage($sourceMessage);
     if (array_key_exists($translation->getId(), $this->sourceTranslations)) {
         $translation = $this->sourceTranslations[$translation->getId()];
     }
     $translation->setCustomerSpecific(false);
     $translation->setType($type);
     $translation->addModule($this->handler->getModule($file));
     $this->sourceTranslations[$translation->getId()] = $translation;
 }
Exemple #20
0
 /**
  * @throws Gpf_Exception
  */
 public static function copy(Gpf_Io_File $source, Gpf_Io_File $target, $mode = null)
 {
     if (Gpf_Php::isFunctionEnabled('copy')) {
         if (false === @copy($source->getFileName(), $target->getFileName())) {
             throw new Gpf_Exception('Could not copy ' . $source->getFileName() . ' to ' . $target->getFileName());
         }
     } else {
         $target->open('w');
         $target->write($source->getContents());
     }
     if ($mode !== null) {
         @chmod($target->getFileName(), $mode);
     }
 }