Source of file SeoHeroToolEditFile.php
Size: 3,326 Bytes - Last Modified: 2021-12-23T10:06:41+00:00
/var/www/docs.ssmods.com/process/src/src/models/SeoHeroToolEditFile.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118 | <?php namespace nomidi\SeoHeroTool; use SilverStripe\ORM\DataObject; use SilverStripe\Forms\TextareaField; use SilverStripe\Forms\LiteralField; use SilverStripe\Forms\GridField\GridField; use SilverStripe\Forms\GridField\GridFieldConfig_RecordEditor; use SilverStripe\ORM\DB; use SilverStripe\Security\Permission; class SeoHeroToolEditFile extends DataObject { private static $table_name = 'SeoHeroToolEditFile'; private static $has_many = array( 'SeoHeroToolRedirects' => 'SeoHeroToolRedirect', ); private static $singular_name = 'Robots Htaccess Editor'; public function getCMSFields() { $fields = parent::getCMSFields(); $content = $this->displayRobotsContent(); if ($content !== false) { $robotsField = new TextareaField('RobotsContent', _t('SeoHeroToolEditFile.RobotsContentField', 'Content of robots.txt'), $content); } else { $robotsField = new LiteralField('RobotsContent', _t('SeoHeroToolEditFile.Robotstxtchmod', 'Please check the access right to the file robots.txt')); } $fields->removeByName('SeoHeroToolRedirects'); $htaccessGrid = new GridField('SeoHeroToolRedirects', _t('SeoHeroToolEditFile.Redirect', '301 Weiterleitungen'), $this->SeoHeroToolRedirects()); $config = $htaccessGrid->getConfig(); $config = GridFieldConfig_RecordEditor::create(); $htaccessGrid->setConfig($config); $fields->addFieldToTab('Root.Main', $robotsField); $fields->addFieldToTab('Root.Main', $htaccessGrid); return $fields; } private function robotsPath() { return $_SERVER['DOCUMENT_ROOT'].'/robots.txt'; } private function displayRobotsContent() { if ((@fileperms($this->robotsPath()) & 0777) != 0777) { return false; } if (!file_exists($this->robotsPath())) { $this->writeFile($this->robotsPath(), ""); } $content = file_get_contents($this->robotsPath()); return $content; } private function writeFile($content = "") { @file_put_contents($this->robotsPath(), $content); } public function onBeforeWrite() { parent::onBeforeWrite(); $this->writeFile($this->RobotsContent); } public static function current_entry() { if ($entry = SeoHeroToolEditFile::get()->First()) { return $entry; } return self::make_site_config(); } public static function make_entry() { $config = SeoHeroToolEditFile::create(); $config->write(); return $config; } public function requireDefaultRecords() { parent::requireDefaultRecords(); $entry = SeoHeroToolEditFile::get()->first(); if (!$entry) { self::make_entry(); DB::alteration_message("Added default SeoHeroToolEditFile", "created"); } } public function canCreate($member = null, $context = []) { if (Permission::check('SUPERUSER')) { return false; } else { return false; } } public function canDelete($Member = null) { if (Permission::check('SUPERUSER')) { return false; } else { return false; } } } |