public static function inlineFile($files, $theme = false) { if ($theme) { $theme = $theme === true || $theme == 1 ? OriginalConfig::inst()->get('SSViewer', 'theme') : $theme; if ($theme) { $theme = THEMES_DIR . '/' . $theme; } else { $theme = project(); } } $key = static::clean_cache_key($files, ['theme' => $theme]); $contents = singleton('require')->cache()->load($key); $isDev = CoreDirector::isDev(); if ($contents === false) { $files = explode(',', $files); foreach ($files as $file) { $file = $theme ? $theme . '/' . $file : $file; $file = CoreDirector::is_absolute_url($file) ? $file : CoreDirector::getAbsFile($file); if (CoreDirector::is_absolute_url($file) || @file_exists($file)) { $contents = @file_get_contents($file); if (!$isDev && $contents) { $contents = singleton('require')->minify_contents_according_to_type($contents, $file); } if (!$isDev) { singleton('require')->cache()->save($contents, $key); } break; } } } return DBField::create_field('HTMLText', $contents); }
protected function inlineFiles($inlines, $setVar = 'customCSS', $unsetVar = 'css', $replaceString = '%s', $id = 'Inline-CSS') { if (count($inlines)) { $this->removeIfFound($id, $setVar); $items = []; $isDev = Director::isDev(); foreach ($inlines as $file => $data) { if (!Director::is_absolute_url($file)) { $file = Director::getAbsFile($file); } $key = Utilities::clean_cache_key($file); $content = singleton('require')->cache()->load($key); if ($content === false) { $content = @file_get_contents($file); if ($content && !$isDev) { $content = singleton('require')->minify_contents_according_to_type($content, $file); } if (!$isDev) { singleton('require')->cache()->save($content, $key); } } if ($content) { $items[$file] = $content; $this->removeIfFound($id, $unsetVar); } } if (count($items)) { if ($setVar == 'customHeadTags') { $this->insertHeadTags(sprintf($replaceString, implode("\n\n", $items)), $id); } elseif ($setVar == 'customScript') { $this->customScript(sprintf($replaceString, implode("\n\n", $items)), $id); } elseif ($setVar == 'customCSS') { $this->customCSS(sprintf($replaceString, implode("\n\n", $items)), $id); } } } }
public static function utilities_js() { if (Director::isDev()) { $script = @file_get_contents(Director::getAbsFile(SS_MWM_DIR . '/js/mwm.utilities.js')); } else { $script = static::cache()->load('JS__utilities'); if (!$script) { require_once THIRDPARTY_PATH . DIRECTORY_SEPARATOR . 'jsmin' . DIRECTORY_SEPARATOR . 'jsmin.php'; $script = \JSMin::minify(@file_get_contents(\Director::getAbsFile(SS_MWM_DIR . '/js/mwm.utilities.js'))); static::cache()->save($script, 'JS__utilities'); } } static::insertHeadTags('<script>' . $script . '</script>', 'JS-MWM-Utilities'); }