Example #1
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) {
        }
    }
 /**
  * @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));
     }
 }
Example #3
0
    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;
    }
Example #4
0
 /**
  * @param Gpf_Io_File
  */
 public function unlock(Gpf_Io_File $file)
 {
     if (!$file->isExists()) {
         return;
     }
     flock($file->getFileHandler(), LOCK_UN);
 }
 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();
     }
 }
Example #6
0
 /**
  * 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();
     }
 }
    private function copyFilesToCacheZipFolder($unpackedZipFolderPath, $cacheZipFolderPath) {
        $unpackedZipFolder = new Gpf_Io_File($unpackedZipFolderPath);
        $cacheZipFolder =  new Gpf_Io_File($cacheZipFolderPath);

        if ($cacheZipFolder->isExists()) {
            $cacheZipFolder->emptyFiles(true);
            $cacheZipFolder->rmdir();
        }
        $cacheZipFolder->mkdir();
        
        $unpackedZipFolder->recursiveCopy($cacheZipFolder);
    }
Example #8
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;
 }
 /**
  * @param String $fileName
  * @return array
  */
 private function getFileData($fileName)
 {
     $path = Gpf_Paths::getInstance()->getAccountDirectoryPath() . Gpf_Csv_ImportExportService::EXPORT_DIRECTORY;
     $file = new Gpf_Io_File($path . $fileName);
     $array = array();
     if ($file->isExists()) {
         $array[] = $fileName;
         $array[] = $file->getSize();
         return $array;
     }
     $array[] = $this->_('file not exist');
     return $array;
 }
 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 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');
 }
Example #12
0
 private function checkCompilePanelDirectory()
 {
     $baseCompileDir = Gpf_Templates_Smarty::getCompileDir();
     $panelDir = new Gpf_Io_File($baseCompileDir . $this->panel . '/');
     if (!$panelDir->isExists()) {
         $panelDir->mkdir(true);
     }
 }
 private function exportServerCacheFile($dirName)
 {
     $file = new Gpf_Io_File($this->getCacheFileName($dirName, true));
     $file->setFileMode('w');
     if (!$file->isExists()) {
         $file->setFilePermissions(0777);
     }
     $file->write("<?php\n");
     $file->write("// DON'T CHANGE THIS FILE !!!\n\n\$_code='" . $this->getCode() . "';\n\$_name='" . $this->getMetaValue(self::LANG_NAME) . "';\n\$_engName='" . $this->getMetaValue(self::LANG_ENG_NAME) . "';\n\$_author='" . $this->getMetaValue(self::LANG_AUTHOR) . "';\n\$_version='" . $this->getMetaValue(self::LANG_VERSION) . "';\n\$_dateFormat='" . $this->getMetaValue(self::LANG_DATE_FORMAT) . "';\n\$_timeFormat='" . $this->getMetaValue(self::LANG_TIME_FORMAT) . "';\n\$_thousandsSeparator='" . $this->getMetaValue(self::LANG_THOUSANDS_SEPARATOR) . "';\n\$_decimalSeparator='" . $this->getMetaValue(self::LANG_DECIMAL_SEPARATOR) . "';\n");
     $file->write("\$_dict=array(\n");
     foreach ($this->translations as $translation) {
         if ($translation->getType() == Gpf_Lang_Parser_Translation::TYPE_SERVER || $translation->getType() == Gpf_Lang_Parser_Translation::TYPE_BOTH) {
             if ($translation->getStatus() != 'D') {
                 $file->write('\'' . addcslashes($translation->getSourceMessage(), "'") . '\'=>\'' . addcslashes($translation->getDestinationMessage(), "'") . "',\n");
             }
         }
     }
     $file->write("'_dateFormat'=>'" . $this->getMetaValue(self::LANG_DATE_FORMAT) . "',\n'_timeFormat'=>'" . $this->getMetaValue(self::LANG_TIME_FORMAT) . "',\n'_thousandsSeparator'=>'" . $this->getMetaValue(self::LANG_THOUSANDS_SEPARATOR) . "',\n'_decimalSeparator'=>'" . $this->getMetaValue(self::LANG_DECIMAL_SEPARATOR) . "');\n");
     $file->write("?>");
     $file->close();
 }
 private function getFileUrl($fileName)
 {
     $filePath = Gpf_Paths::getInstance()->getAccountDirectoryPath() . Gpf_Csv_ImportExportService::EXPORT_DIRECTORY . $fileName;
     $file = new Gpf_Io_File($filePath);
     if (!$file->isExists()) {
         throw new Gpf_Exception($this->_('File not exist'));
     }
     return $filePath;
 }
Example #15
0
 /**
  * @param string $moduleName
  * @return string path to to compiled javascript code of module
  */
 public function getGwtModuleUrl($moduleName, $gzipped = false)
 {
     $suffix = '.nocache.js';
     if ($gzipped) {
         $suffix = '.g.nocache.js';
     }
     foreach ($this->clientPaths as $clientPath) {
         if ($this->isDevelopementVersion()) {
             $fileName = $clientPath . 'www/' . $moduleName . '/' . $moduleName . $suffix;
         } else {
             $fileName = $this->scriptRelativePath . $this->scriptPath . 'js/' . $moduleName . $suffix;
         }
         $file = new Gpf_Io_File($fileName);
         if ($file->isExists()) {
             return $this->pathToUrl($fileName);
         }
     }
     throw new Gpf_Exception($fileName . ' file does not exist.');
 }
 /**
  * If exists language with this code in account directory already, backup translation file
  *
  * @param $language
  */
 private function backupOriginalTranslation(Gpf_Lang_CsvLanguage $language)
 {
     $origFileName = Gpf_Lang_CsvLanguage::getAccountCsvFileName($language->getCode());
     $file = new Gpf_Io_File($origFileName);
     if ($file->isExists()) {
         Gpf_Io_File::copy($file, new Gpf_Io_File($origFileName . '.v' . str_replace('.', '', Gpf_Application::getInstance()->getVersion()) . '_' . date("YmdHis")));
     }
 }
Example #17
0
 /**
  * Delete csv file from account directory
  */
 private function deleteLanguageFilesFromAccount()
 {
     //delete csv file from account
     $fileName = Gpf_Lang_CsvLanguage::getAccountCsvFileName($this->getCode());
     $file = new Gpf_Io_File($fileName);
     if ($file->isExists()) {
         $file->delete();
     }
     //TODO delete also cache language files from account
 }
 private function computeEtag(Gpf_Io_File $file)
 {
     if (!$file->isExists()) {
         return '';
     }
     return md5($file->getSize() . '|' . $file->getInodeChangeTime());
 }
Example #19
0
 public function isActive() {
     return $this->file->isExists();
 }
 protected function createDirectory(Gpf_Io_File $directory)
 {
     if ($directory->isExists() && !$directory->isWritable()) {
         throw new Gpf_Exception($this->_('Directory %s is not writable by web server user. Please remove it or set write permissions.', $directory->getFileName()));
     }
     if (!$directory->isExists()) {
         $directory->mkdir(true);
     }
 }
 private function loadFiles(array &$files, array &$dirs, $folder, $filter){
     $file = new Gpf_Io_File($folder);
     if (!$file->isExists()) {
         return;
     }
     foreach (new Gpf_Io_DirectoryIterator($file, '', false, true) as $fullName => $name) {
         $dirs[$name] = $fullName;
     }
     foreach (new Gpf_Io_DirectoryIterator($file) as $fullName => $name) {
         if($this->acceptsFilter($fullName, $name, $filter)){
             $files[$name] = $fullName;
         }
     }
 }
Example #22
0
 private function readSettingsValues(Gpf_Io_File $file = null)
 {
     if (is_null($file)) {
         $file = new Gpf_Io_File($this->settingsFile);
     }
     if (!$file->isExists()) {
         return array();
     }
     $file->open();
     $values = array();
     $lines = $this->readFileAsArray($file);
     foreach ($lines as $line) {
         if (false !== strpos($line, '<?') || false !== strpos($line, '?>')) {
             continue;
         }
         $pos = strpos($line, '=');
         if ($pos === false) {
             continue;
         }
         $name = substr($line, 0, $pos);
         $value = substr($line, $pos + 1);
         $values[$name] = rtrim($value);
     }
     return $values;
 }
 protected function getRealFileName()
 {
     $count = 0;
     while (true) {
         $relativeName = $this->relativeUploadPath . $this->generateFileName($count);
         $file = new Gpf_Io_File(Gpf_Paths::getInstance()->getTopPath() . $relativeName);
         if (!$file->isExists()) {
             return '../' . $relativeName;
         }
         if ($count > 100) {
             throw new Gpf_Exception("Cannot generate unique file name");
         }
         $count++;
     }
 }