private function writeEmpty(Gpf_Io_File $file) { $file->open('w'); $file->setFilePermissions(0777); $file->write('<?PHP /* */ ?>'); $file->close(); }
public function createEmpty() { $file = new Gpf_Io_File($this->getSettingFileName()); $file->setFileMode('w'); $file->setFilePermissions(0777); $file->write(''); $file->close(); }
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; }
private function writeSettingToFile(Gpf_Io_File $file) { $file->setFilePermissions(0777); if (defined('ENABLE_ENGINECONFIG_LOG')) { Gpf_Log::info('(writeSettingsValues - before write) file ' . @$file->getFileName() . ' size: ' . @$file->getSize() . ', permissions: ' . @$file->getFilePermissions() . ', owner: ' . @$file->getFileOwner()); } $file->open('w'); $text = '<?php /*' . "\n"; foreach ($this->parameters as $key => $value) { $text .= $key . '=' . $value . "\r\n"; } $text .= '*/ ?>'; $file->write($text); $file->close(); if (defined('ENABLE_ENGINECONFIG_LOG')) { Gpf_Log::info('(writeSettingsValues - after write) file ' . @$file->getFileName() . ' size: ' . @$file->getSize() . ', permissions: ' . @$file->getFilePermissions() . ', owner: ' . @$file->getFileOwner()); } }
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?>"); } }
public function close() { $this->file->close(); }
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); }
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(); }
/** * 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; }
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(); }