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 check()
 {
     try {
         $this->file->open('rb');
         return true;
     } catch (Exception $e) {
     }
     return false;
 }
Example #3
0
 private function writeEmpty(Gpf_Io_File $file)
 {
     $file->open('w');
     $file->setFilePermissions(0777);
     $file->write('<?PHP /* */ ?>');
     $file->close();
 }
 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 '';
 }
Example #5
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;
 }
    /**
     *
     * @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;
    }
Example #7
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();
     }
 }
    public function generateManifest() {
        $file = new Gpf_Io_File(Gpf_Paths::getInstance()->getAccountConfigDirectoryPath() . self::getManifestFileName());
        $file->setFileMode('w');
        $file->open('w');

        if ($file->isOpened()) {
            $file->write('{"betaManifestVersion":1,"version":"' .
            Gpf_Application::getInstance()->getCode() . '_' .
            Gpf_Application::getInstance()->getInstalledVersion() . md5(rand()) .
            '","entries":[{"url":""}');

            //add js libraries
            $this->addJsLibraries($file);

            //add images, css and other theme resources
            $this->addImages($file);

            $file->write(']}');
            $file->close();
        }
    }
Example #9
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);
     }
 }
 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?>");
     }
 }
 private function checkAccountsWritable()
 {
     $requirement = new Gpf_Install_Requirement();
     $requirement->setPositiveName($this->_('Configuration directory is writable'));
     $requirement->setNegativeName($this->_('Configuration directory has to be writable'));
     $accountDirectory = Gpf_Paths::getInstance()->getAccountsPath();
     $result = @is_dir($accountDirectory) && is_writable($accountDirectory);
     if ($result) {
         $this->deleteIfExistsTestFilesAndDir($accountDirectory);
         $testFile = new Gpf_Io_File($accountDirectory . 'check');
         $subTestFile = new Gpf_Io_File($accountDirectory . 'check/subcheck');
         try {
             $testFile->open('w');
             $testFile->close();
             $testFile->delete();
         } catch (Exception $e) {
             $result = false;
             $requirement->setNegativeName($this->_('Could not create file inside %s directory', $accountDirectory));
         }
         try {
             $testFile->mkdir();
             $testFile->rmdir();
         } catch (Exception $e) {
             $result = false;
             $requirement->setNegativeName($this->_('Could not create directory inside %s directory', $accountDirectory));
         }
         try {
             $testFile->mkdir();
             $subTestFile->open('w');
             $subTestFile->close();
             $subTestFile->delete();
             $subTestFile->mkdir();
             $subTestFile->rmdir();
             $testFile->rmdir();
         } catch (Exception $e) {
             $result = false;
             $requirement->setNegativeName($this->_('Could not create file or directory inside %s subdirectory. Probably safe mode is not properly configured.', $accountDirectory));
         }
     }
     $requirement->setResult($result);
     $description = $this->_('Please make directory %s and all subdirectories writable by webserver.', $accountDirectory);
     if (stripos(PHP_OS, 'win') === false) {
         $description .= $this->_('On unix-like systems you can type "chmod -R 777 %s".', $accountDirectory);
     }
     $description .= $this->_('On any system you can set write permissions using your favourite FTP client.');
     $requirement->setFixDescription($description);
     $this->addRequirement($requirement);
 }
Example #12
0
 private function resetFile(Gpf_Io_File $file, $fileSize)
 {
     $file->open('w');
     $file->write('File was truncated after exceeding size ' . $fileSize . " bytes. Now continuing...\n");
     $file->close();
 }
 private function checkFileIsWritable()
 {
     $file = new Gpf_Io_File($this->fileName);
     $file->open('a');
 }
    /**
     * check if the given URL matches some of the approved DirectLink URLs. 
     * If yes, return userID to whom this URL belongs 
     */
    public function checkDirectLinkMatch($url) {
    	$realFileName = $this->settingsDirectory . self::FILE_NAME;
    	if(!file_exists($realFileName)) {
    		throw new Gpf_Exception("DirectLink config file '$realFileName' does not exist!");
    	}

    	$url = str_replace('https://', '', $url);
    	$url = str_replace('http://', '', $url);
    	
    	$file = new Gpf_Io_File($realFileName);
    	$file->open();
        while (!$file->isEof()) {
        	$buffer = $file->readLine(4065);
        	if($buffer[0] == '<' || $buffer[0] == '?') {
        		continue;
        	}

        	$buffer = trim($buffer);
        	$arr = explode('|', $buffer, 7);
        	if(!is_array($arr) || count($arr) != 7) {
        		continue; 
        	}
        	
        	$userid = $arr[0];
        	$substring = $arr[1];
        	$clearUrl = $arr[2];
        	$preg = $arr[3];
        	$channelid = $arr[4];
        	$campaignid = $arr[5];
        	$bannerid = $arr[6];
        	if($this->isMatch($url, $substring, $preg)) {
        		$file->close();
        		return array('userid' => $userid, 
        					 'url' => $clearUrl,
        					 'channelid' => $channelid,
        					 'campaignid' => $campaignid,
        		     		 'bannerid' => $bannerid,
        		);
        	}
        }
        
        $file->close();
        return false;
    }
 /**
  * @service template write
  * @param $fields
  * @return Gpf_Rpc_Action
  */
 public function createFile(Gpf_Rpc_Params $params)
 {
     $action = new Gpf_Rpc_Action($params);
     $templateName = $this->fixTemplateName($action->getParam("templatename"));
     $panelName = '';
     if ($params->exists("panelname")) {
         $panelName = $action->getParam("panelname");
     }
     if ($params->exists("theme") && $action->getParam("theme") != null && $action->getParam("theme") != "") {
         $theme = $action->getParam("theme");
     } else {
         throw new Gpf_Exception("Theme not set");
     }
     $commonTemplate = new Gpf_Templates_Template($templateName, $panelName, Gpf_Templates_Template::FETCH_FILE, trim(Gpf_Paths::DEFAULT_THEME, '/'));
     $commonTemplate->getTemplateSource();
     $paths = Gpf_Paths::getInstance()->clonePaths($theme);
     $templatePaths = $paths->getTemplateSearchPaths($panelName);
     $filePath = $templatePaths[0] . $templateName;
     $templateFile = new Gpf_Io_File($filePath);
     try {
         $templateFile->open('w');
     } catch (Gpf_Exception $e) {
         if (!$this->createDirectory($filePath)) {
             $action->setErrorMessage('Unable to create directory: ' . $directory);
             $action->addError();
             return $action;
         }
         $templateFile->open('w');
     }
     $templateFile->write($commonTemplate->getTemplateSource());
     $action->setInfoMessage($this->_("File added"));
     $action->addOk();
     return $action;
 }
Example #16
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);
     }
 }