Source of file StyleSheet_SiteConfigExtension.php
Size: 2,110 Bytes - Last Modified: 2018-07-02T11:52:19+00:00
/var/www/docs.ssmods.com/process/src/code/StyleSheet_SiteConfigExtension.php
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 | <?php class StyleSheet_SiteConfigExtension extends DataExtension { /** * FIELDS */ private static $db = array( 'StyleSheetCustomCSS' => 'Text' ); /** * CMS FIELDS */ public function updateCMSFields(FieldList $fields) { /** * APPEARANCE TAB */ $tab = 'Root.Appearance.StyleSheet'; $field = new TextareaField('StyleSheetCustomCSS', 'Custom CSS'); $fields->addFieldToTab($tab, $field); $html = $this->owner->renderWith('StyleSheet_CMS_Preview'); $field = new LiteralField('Preview', $html); $fields->addFieldToTab($tab, $field); } public function onAfterWrite() { $this->ExportStyleSheet(); } public function ExportStyleSheet() { //create file $data = $this->RenderStyleSheet(); $this->forceFilePutContents(STYLESHEET_CSS_SAVE_PATH, $data); } /** * create file with content, and create folder structure if doesn't exist * @param String $filepath * @param String $message */ public function forceFilePutContents($filepath, $message) { try { $isInFolder = preg_match("/^(.*)\/([^\/]+)$/", $filepath, $filepathMatches); if ($isInFolder) { $folderName = $filepathMatches[1]; $fileName = $filepathMatches[2]; if (!is_dir($folderName)) { mkdir($folderName, 0777, true); } } file_put_contents($filepath, $message); } catch (Exception $e) { echo "ERR: error writing '$message' to '$filepath', ". $e->getMessage(); } } public function RenderStyleSheet($minify = true) { $data = $this->owner->renderWith('StyleSheet'); //minify CSS if ($minify) { $data = str_replace(' ', '', $data); //removes spaces $data = str_replace("\r\n", '', $data); //removes new lines $data = str_replace("\t", '', $data); //removes tabs } return $data; } public function getStyleObjects() { $data = DataObject::get('StyleObject'); return $data; } } |