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(); }
private function importRowsToImportFile(Gpf_Io_File $importFile) { while ($row = $this->file->readCsv($this->delimiter)) { if ($row[0] != null) { $importFile->write($row[0]); } else { break; } } }
/** * * @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; }
/** * Add images urls to manifest * * @param Gpf_Io_File $file */ private function addImages(Gpf_Io_File $file) { $dir = new Gpf_Io_DirectoryIterator(Gpf_Paths::getInstance()->getAccountDirectoryPath() . Gpf_Paths::TEMPLATES_DIR, '', true); foreach ($dir as $fullName => $fileName) { $info = pathinfo($fullName); if(isset($info['extension'])) { switch($info['extension']) { case 'png': case 'jpg': case 'gif': case 'ico': case 'css': $file->write(',{"url":"../../' . $fullName . '"}' . "\n"); break; default: } } } }
protected function log($time, $message, $logLevel, $logGroup, $ip, $file, $line, $type = null) { $timeString = strftime($this->timeFormat, $time); $str = $this->lineFormat; $str = str_replace('{GROUP}', $logGroup, $str); $str = str_replace('{LEVEL}', $this->getLogLevelAsText($logLevel), $str); $str = str_replace('{TIME}', $timeString, $str); $str = str_replace('{MESSAGE}', $message, $str); $str = str_replace('{IP}', $ip, $str); $str = str_replace('{FILE}', $file, $str); $str = str_replace('{LINE}', $line, $str); $str = str_replace('{TYPE}', $type, $str); if ($message == "") { $str = " "; } $file = new Gpf_Io_File($this->fileName); try { $file->open('a'); $file->write($str); } catch (Exception $e) { throw new Gpf_Log_Exception("File logging error: " . $e->getMessage()); } }
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?>"); } }
/** * @param String $string */ public function writeRawString($string) { $this->file->write($string); }
public function saveTemplateToFile($templateContent) { $file = new Gpf_Io_File($this->paths->getTemplatePath($this->name, $this->panel)); $file->setFileMode("w"); $file->write($templateContent); $this->deleteCacheFile(); }
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(); }
/** * @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; }
/** * @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); } }
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(); }