/**
  * @throws Gpf_Exception
  * @param $fileUrl
  */
 private function checkFile($fileUrl)
 {
     $file = new Gpf_Io_File($fileUrl);
     if (!$file->isExists() && !Gpf_Common_UrlUtils::urlExists($fileUrl)) {
         throw new Gpf_Exception($this->_('File %s not exists', $fileUrl));
     }
 }
Beispiel #2
0
    /**
     * Load javascript library required for google gears
     *
     * @param Gpf_Contexts_Module $context
     */
    public function initJsResources(Gpf_Contexts_Module $context) {
        //install mode will not connect google gears
        if (Gpf_Paths::getInstance()->isInstallModeActive()) {
            return;
        }

        try {

            $file = new Gpf_Io_File(Gpf_Paths::getInstance()->getAccountConfigDirectoryPath() . GoogleGears_Definition::getManifestFileName());

            if (!$file->isExists()) {
                $def = new GoogleGears_Definition();
                $def->generateManifest();
            }

            $context->addJsResource(Gpf_Paths::getInstance()->getFrameworkPluginsDirectoryUrl() . 'GoogleGears/gears_init.js');

            $manifestUrl = Gpf_Paths::getInstance()->getBaseServerUrl() .
            Gpf_Paths::getInstance()->getAccountDirectoryRelativePath() .
            Gpf_Paths::CONFIG_DIR . GoogleGears_Definition::getManifestFileName();
            $context->addJsScript("try {
            var localServer = google.gears.factory.create('beta.localserver');
            var store = localServer.createManagedStore('GwtPHP');
            store.manifestUrl = '$manifestUrl';
            store.checkForUpdate();
            store.enabled = true;
            } catch (e) {}
        ");
        } catch (Gpf_Exception $e) {
        }
    }
    protected function saveUploadedFile() {
        
        $file = new Gpf_Db_File();
        $file->set('filename', $this->name);
        $file->set('filesize', $this->size);
        $file->set('filetype', $this->type);
        $file->save();
             
        $dir = new Gpf_Io_File($this->getZipFolderUrl().$file->getFileId().'/');
        if ($dir->isExists()) {
            $dir->delete();
        }
        $dir->mkdir();
        $tmpZip = new Gpf_Io_File($this->getZipFolderUrl().$file->getFileId().'/'.$file->getFileId().".zip");
        $dir->copy(new Gpf_Io_File($this->tmpName),$tmpZip);
        
        $archive = new PclZip($this->getZipFolderUrl().$file->getFileId().'/'.$file->getFileId().".zip");
        $err = $archive->extract($this->getZipFolderUrl().$file->getFileId().'/');
        if ($err <= 0) {
            throw new Gpf_Exception("code: ".$err);
        }

        $tmpZip->delete();
 
        return $file;
    }
Beispiel #4
0
 /**
  * @param Gpf_Io_File
  */
 public function unlock(Gpf_Io_File $file)
 {
     if (!$file->isExists()) {
         return;
     }
     flock($file->getFileHandler(), LOCK_UN);
 }
 private function clearTempDirectory($path)
 {
     foreach (new Gpf_Io_DirectoryIterator($path) as $fullFileName => $file) {
         $file = new Gpf_Io_File($fullFileName);
         $file->delete();
     }
 }
 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);
 }
    /**
     * @service theme write
     *
     * @return Gpf_Rpc_Action
     */
    public function save(Gpf_Rpc_Params $params) {
        $form = new Gpf_Rpc_Form($params);
        $newThemeId = str_replace(' ', '_', $form->getFieldValue('name'));
        $srcTheme = new Gpf_Desktop_Theme($form->getFieldValue('Id')
        , $form->getFieldValue('panelName'));
        $srcPath = $srcTheme->getThemePath();
        $targetPath = new Gpf_Io_File($srcPath->getParent().$newThemeId);
        try{
            $targetPath->mkdir();
            $srcPath->recursiveCopy($targetPath);

            $newTheme = new Gpf_Desktop_Theme($newThemeId
            , $form->getFieldValue('panelName'));
            $newTheme->load();
            $newTheme->setName($form->getFieldValue('name'));
            $newTheme->setAuthor($form->getFieldValue('author'));
            $newTheme->setUrl($form->getFieldValue('url'));
            $newTheme->setDescription($form->getFieldValue('description'));
            $newTheme->setBuiltIn(false);
            $newTheme->save();
        }catch(Gpf_Exception $ex){
            $form->setErrorMessage($ex->getMessage());
        }
        $form->setField('themeId', $newThemeId);
        return $form;
    }
 public function createEmpty()
 {
     $file = new Gpf_Io_File($this->getSettingFileName());
     $file->setFileMode('w');
     $file->setFilePermissions(0777);
     $file->write('');
     $file->close();
 }
 public static function clear(){
     $session = Gpf_Session::getInstance();
     $data =  $session->getVar(self::SESSION_VAR);
     if(!$data) return;
     $uploadFile = new Gpf_Io_File($data->getFile());
     $uploadFile->delete();
     $session->setVar(self::SESSION_VAR, null);
 }
Beispiel #10
0
 public function execute() {
     $dir = new Gpf_Io_DirectoryIterator(Gpf_Paths::getInstance()->getAccountsPath(), '', true);
     foreach ($dir as $fullPath => $filename) {
     	if ($filename == 'engineconfig.php') {
     	    $file = new Gpf_Io_File($fullPath);
     	    $file->delete();
     	}
     }
 }
 private function deleteDirectories($directory)
 {
     foreach (new Gpf_Io_DirectoryIterator($directory, '', false, true) as $fullFileName => $fileName) {
         $this->checkInterruption();
         $this->deleteDirectories($fullFileName);
         $file = new Gpf_Io_File($fullFileName);
         $file->rmdir();
     }
 }
 public function onActivate() {
     $zipDir = new Gpf_Io_File(Gpf_Paths::getInstance()->getFullAccountPath().Pap_Features_ZipBanner_Unziper::ZIP_DIR);
     if ($zipDir->isExists() === false) {
         $zipDir->mkdir();
     }
     $cacheZipDir = new Gpf_Io_File(Gpf_Paths::getInstance()->getCacheAccountDirectory().'zip/');
     if ($cacheZipDir->isExists() === false) {
         $cacheZipDir->mkdir();
     }
 }
 private function importRowsToImportFile(Gpf_Io_File $importFile)
 {
     while ($row = $this->file->readCsv($this->delimiter)) {
         if ($row[0] != null) {
             $importFile->write($row[0]);
         } else {
             break;
         }
     }
 }
 private function getFilesData($fileUrl)
 {
     $filesData = array();
     $filesData['count'] = 0;
     $filesData['size'] = 0;
     foreach (new Gpf_Io_DirectoryIterator($fileUrl) as $fullFileName => $file) {
         $file = new Gpf_Io_File($fullFileName);
         $filesData['count']++;
         $filesData['size'] += $file->getSize();
     }
     return $filesData;
 }
Beispiel #15
0
 public function read() {
     $file = new Gpf_Io_File($this->path);
     if (!$file->isExists()) {
         throw new Gpf_Exception("File '".$this->path."' does not exist");
     }
     $file->open();
     if (!$countries = $file->readLine()) {
         $countries = '';
     }
     $file->close();
     
     return $countries;
 }
Beispiel #16
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 '';
 }
 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 existTemplate($templateName)
 {
     foreach (Gpf_Paths::getInstance()->getTemplateSearchPaths() as $templateDir) {
         if (Gpf_Io_File::isFileExists($templateDir . $templateName . ".tpl")) {
             return true;
         }
     }
     return false;
 }
    /**
     *
     * @service banners_categories add
     * @param $fields
     * @return Gpf_Rpc_Form
     */
    public function add(Gpf_Rpc_Params $params) {
        $form = parent::add($params);

        if ($form->isSuccessful() && $form->getFieldValue("code") == "Custom-Page") {
            try {
                $templatePaths = Gpf_Paths::getInstance()->getTemplateSearchPaths("affiliates", "", true);
                $fileName = $templatePaths[0] . $form->getFieldValue("templateName").".tpl";
                $file = new Gpf_Io_File($fileName);
                $file->open('w');
                $file->write($form->getFieldValue("templateName").".tpl");
                $file->close();
            } catch (Exception $e) {
                $form->setErrorMessage($e->getMessage());
                return $form;
            }
        }
        return $form;
    }
 public function getMethodComment($methodName)
 {
     try {
         $this->file->open();
         $source = $this->file->getContents();
     } catch (Exception $e) {
         return '';
     }
     $pattern = '|\\s+function\\s*' . $methodName . '\\s*\\(|ims';
     if (preg_match_all($pattern, $source, $matches, PREG_PATTERN_ORDER | PREG_OFFSET_CAPTURE) > 0) {
         foreach ($matches as $match) {
             $comment = $this->getComment(substr($source, 0, $match[0][1]));
             if ($comment !== false) {
                 return $comment;
             }
         }
     }
     return '';
 }
 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');
     }
 }
Beispiel #22
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()));
        }
    }
Beispiel #23
0
 /**
  * Csf files handler
  *
  * @param string $fileName Csv file name
  * @param string $delimiter Set the field delimiter (one character only). Defaults as a comma
  * @param string $enclosure Set the field enclosure character (one character only). Defaults as a double quotation mark.
  * @param string $escapeChar Set the escape character (one character only). Defaults as a backslash (\)
  * @param array $defaultHeaders Array of defaylt headers. If false, read headers from first line of csv file.
  */
 public function __construct($fileName, $delimiter = ';', $enclosure = '"', $defaultHeaders = false)
 {
     parent::__construct($fileName);
     if (!$this->isExists()) {
         throw new Gpf_Exception($this->_('Could not open csv file.'));
     }
     $this->delimiter = $delimiter;
     $this->enclosure = $enclosure;
     if ($defaultHeaders) {
         $this->headers = new Gpf_Data_RecordHeader($defaultHeaders);
         $this->defaultHeaders = $defaultHeaders;
     } else {
         $this->headers = new Gpf_Data_RecordHeader();
     }
     $this->rewind();
 }
 /**
  * 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 copy(Gpf_Io_File $source, Gpf_Io_File $target)
 {
     $this->resourceOverwritten = false;
     if ($target->isExists() && $this->isFileChanged($source, $target)) {
         try {
             Gpf_Io_File::copy($target, new Gpf_Io_File($target->getFileName() . '.v' . str_replace('.', '_', Gpf_Application::getInstance()->getVersion())), $this->mode);
             $this->resourceOverwritten = true;
         } catch (Gpf_Exception $e) {
             $message = $this->_('Could not backup changed theme resource file %s (%s)', $target->getFileName(), $e->getMessage());
             Gpf_Log::error($message);
             throw new Gpf_Exception($message);
         }
     }
     try {
         Gpf_Io_File::copy($source, $target, $this->mode);
     } catch (Gpf_Exception $e) {
         $message = $this->_('Could not install new theme resource (%s) file.  Make sure that file is writable by webserver.', $target->getFileName());
         Gpf_Log::error($message);
         throw new Gpf_Exception($message);
     }
 }
 private function renderPrivileges($className, $privilegeList, $privilegeTypes, $hasParentClass)
 {
     if ($fileName = Gpf::existsClass($className)) {
         $file = new Gpf_Io_File($fileName);
         $file->setFileMode('r');
         $content = $file->getContents();
         $file->close();
         if (($pos = strpos($content, self::TAG)) === false) {
             throw new Gpf_Exception('Missing tag ' . self::TAG . ' in privileges class ' . $className . ' !');
         }
         $file = new Gpf_Io_File($fileName);
         $file->open('w');
         $file->write(substr($content, 0, $pos + strlen(self::TAG)) . "\n\n");
         $file->write("\t// Privilege types\n");
         foreach ($privilegeTypes as $privilege) {
             $file->write("\t" . 'const ' . $this->formatPrivilegeType($privilege) . ' = "' . $privilege . '";' . "\n");
         }
         $file->write("\n");
         $file->write("\t// Privilege objects\n");
         foreach ($privilegeList as $object => $privileges) {
             ksort($privileges);
             $privilegeTypeComments = '// ';
             foreach ($privileges as $privilege) {
                 $privilegeTypeComments .= $this->formatPrivilegeType($privilege) . ', ';
             }
             $privilegeTypeComments = rtrim($privilegeTypeComments, ", ");
             $file->write("\t" . 'const ' . strtoupper($object) . ' = "' . $object . '"; ' . $privilegeTypeComments . "\n");
         }
         $file->write("\t\n\n\tprotected function initObjectRelation() {\n\t\t");
         if ($hasParentClass) {
             $file->write('$objectRelation = array_merge_recursive(parent::initObjectRelation(), array(');
         } else {
             $file->write('return array(');
         }
         $comma = "\n\t\t";
         foreach ($privilegeList as $object => $privileges) {
             $file->write($comma . "self::" . strtoupper($object) . "=>array(");
             ksort($privileges);
             $privilegeTypes = '';
             foreach ($privileges as $privilege) {
                 $privilegeTypes .= 'self::' . $this->formatPrivilegeType($privilege) . ', ';
             }
             $file->write(rtrim($privilegeTypes, ", ") . ")");
             $comma = ",\n\t\t";
         }
         $file->write("\n\t\t)" . ($hasParentClass ? ");\r\r\t\tforeach (\$objectRelation as \$key => \$value) {\r\t\t\t\$objectRelation[\$key] = array_unique(\$value);\r\t\t}\r\t\treturn \$objectRelation;" : ';') . "\r\t}\n");
         $file->write("\n}\n?>");
     }
 }
 protected function getContent()
 {
     fpassthru($this->file->getFileHandler());
     flush();
 }
Beispiel #28
0
 public function insert() {
     parent::insert();
     $file = new Gpf_Io_File(Gpf_Paths::getInstance()->getAccountDirectoryPath() . Pap_Features_SiteReplication_Replicator::SITES_DIR . $this->getId());
     $file->mkdir();
 }
Beispiel #29
0
 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);
     }
 }
 /**
  * Delete uploaded file from database or files directory
  *
  * @service uploaded_file delete
  * @param Gpf_Rpc_Params $params
  * @return Gpf_Rpc_Action
  */
 public function deleteFile(Gpf_Rpc_Params $params)
 {
     $action = new Gpf_Rpc_Action($params);
     if ($action->existsParam('fileid') && $action->getParam('fileid') != '') {
         $dbRow = new Gpf_Db_File();
         $dbRow->setFileId($action->getParam('fileid'));
         try {
             $dbRow->load();
         } catch (Gpf_DbEngine_NoRow $e) {
             throw new Exception($this->_("Failed to delete file. File doesn't exist in database."));
         }
         try {
             $dbRow->delete();
         } catch (Gpf_Exception $e) {
             $action->addError();
             $action->setErrorMessage($this->_('Failed to delete file from database.'));
             return $action;
         }
     } else {
         $fileUrl = $action->getParam('fileurl');
         $fileName = substr($fileUrl, strrpos($fileUrl, '/') + 1);
         $file = new Gpf_Io_File(Gpf_Paths::getInstance()->getAccountDirectoryPath() . Gpf_Paths::FILES_DIRECTORY . $fileName);
         if (!$file->delete()) {
             $action->addError();
             $action->setErrorMessage($this->_('Failed to delete file.'));
         }
     }
     $action->addOk();
     return $action;
 }