本文整理汇总了PHP中CSSJanus类的典型用法代码示例。如果您正苦于以下问题:PHP CSSJanus类的具体用法?PHP CSSJanus怎么用?PHP CSSJanus使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CSSJanus类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getStyles
/**
* @param $context ResourceLoaderContext
* @return array
*/
public function getStyles(ResourceLoaderContext $context)
{
global $wgAllowUserCssPrefs, $wgUser;
if ($wgAllowUserCssPrefs) {
$options = $wgUser->getOptions();
// Build CSS rules
$rules = array();
// Underline: 2 = browser default, 1 = always, 0 = never
if ($options['underline'] < 2) {
$rules[] = "a { text-decoration: " . ($options['underline'] ? 'underline' : 'none') . "; }";
} else {
# The scripts of these languages are very hard to read with underlines
$rules[] = 'a:lang(ar), a:lang(ckb), a:lang(fa),a:lang(kk-arab), ' . 'a:lang(mzn), a:lang(ps), a:lang(ur) { text-decoration: none; }';
}
if ($options['justify']) {
$rules[] = "#article, #bodyContent, #mw_content { text-align: justify; }\n";
}
if (!$options['showtoc']) {
$rules[] = "#toc { display: none; }\n";
}
if (!$options['editsection']) {
$rules[] = ".editsection { display: none; }\n";
}
if ($options['editfont'] !== 'default') {
$rules[] = "textarea { font-family: {$options['editfont']}; }\n";
}
$style = implode("\n", $rules);
if ($this->getFlip($context)) {
$style = CSSJanus::transform($style, true, false);
}
return array('all' => $style);
}
return array();
}
示例2: getStyles
/**
* @param ResourceLoaderContext $context
* @return array
*/
public function getStyles(ResourceLoaderContext $context)
{
global $wgUser;
if (!$this->getConfig()->get('AllowUserCssPrefs')) {
return array();
}
$options = $wgUser->getOptions();
// Build CSS rules
$rules = array();
// Underline: 2 = browser default, 1 = always, 0 = never
if ($options['underline'] < 2) {
$rules[] = "a { text-decoration: " . ($options['underline'] ? 'underline' : 'none') . "; }";
} else {
# The scripts of these languages are very hard to read with underlines
$rules[] = 'a:lang(ar), a:lang(kk-arab), a:lang(mzn), ' . 'a:lang(ps), a:lang(ur) { text-decoration: none; }';
}
if ($options['editfont'] !== 'default') {
// Double-check that $options['editfont'] consists of safe characters only
if (preg_match('/^[a-zA-Z0-9_, -]+$/', $options['editfont'])) {
$rules[] = "textarea { font-family: {$options['editfont']}; }\n";
}
}
$style = implode("\n", $rules);
if ($this->getFlip($context)) {
$style = CSSJanus::transform($style, true, false);
} else {
$style = CSSJanus::nullTransform($style);
}
return array('all' => $style);
}
示例3: setupSkinUserCss
/**
*
*/
function setupSkinUserCss(OutputPage $out)
{
global $wgContLang;
$qb = $this->qbSetting();
$rules = array();
if (2 == $qb) {
# Right
$rules[] = "#quickbar { position: absolute; top: 4px; right: 4px; border-left: 2px solid #000000; }";
$rules[] = "#article, #mw-data-after-content { margin-left: 4px; margin-right: 152px; }";
} elseif (1 == $qb || 3 == $qb) {
$rules[] = "#quickbar { position: absolute; top: 4px; left: 4px; border-right: 1px solid gray; }";
$rules[] = "#article, #mw-data-after-content { margin-left: 152px; margin-right: 4px; }";
if (3 == $qb) {
$rules[] = "#quickbar { position: fixed; padding: 4px; }";
}
} elseif (4 == $qb) {
$rules[] = "#quickbar { position: fixed; right: 0px; top: 0px; padding: 4px;}";
$rules[] = "#quickbar { border-right: 1px solid gray; }";
$rules[] = "#article, #mw-data-after-content { margin-right: 152px; margin-left: 4px; }";
}
$style = implode("\n", $rules);
if ($wgContLang->getDir() === 'rtl') {
$style = CSSJanus::transform($style, true, false);
}
$out->addInlineStyle($style);
parent::setupSkinUserCss($out);
}
示例4: getStyles
/**
* @param ResourceLoaderContext $context
* @return array
*/
public function getStyles(ResourceLoaderContext $context)
{
if (!$this->getConfig()->get('AllowUserCssPrefs')) {
return [];
}
$options = $context->getUserObj()->getOptions();
// Build CSS rules
$rules = [];
// Underline: 2 = skin default, 1 = always, 0 = never
if ($options['underline'] < 2) {
$rules[] = "a { text-decoration: " . ($options['underline'] ? 'underline' : 'none') . "; }";
}
$style = implode("\n", $rules);
if ($this->getFlip($context)) {
$style = CSSJanus::transform($style, true, false);
}
return ['all' => $style];
}
示例5: setupSkinUserCss
function setupSkinUserCss(OutputPage $out)
{
parent::setupSkinUserCss($out);
$out->addModuleStyles('skins.simple');
/* Add some userprefs specific CSS styling */
global $wgUser, $wgContLang;
$rules = array();
$underline = "";
if ($wgUser->getOption('underline') < 2) {
$underline = "text-decoration: " . $wgUser->getOption('underline') ? 'underline' : 'none' . ";";
}
/* Also inherits from resourceloader */
if (!$wgUser->getOption('highlightbroken')) {
$rules[] = "a.new, a.stub { color: inherit; text-decoration: inherit;}";
$rules[] = "a.new:after { color: #CC2200; {$underline};}";
$rules[] = "a.stub:after { {$underline}; }";
}
$style = implode("\n", $rules);
if ($wgContLang->getDir() === 'rtl') {
$style = CSSJanus::transform($style, true, false);
}
$out->addInlineStyle($style);
}
示例6: getStyles
/**
* @param ResourceLoaderContext $context
* @return array
*/
public function getStyles(ResourceLoaderContext $context)
{
if (!$this->getConfig()->get('AllowUserCssPrefs')) {
return [];
}
$options = $context->getUserObj()->getOptions();
// Build CSS rules
$rules = [];
// Underline: 2 = skin default, 1 = always, 0 = never
if ($options['underline'] < 2) {
$rules[] = "a { text-decoration: " . ($options['underline'] ? 'underline' : 'none') . "; }";
}
if ($options['editfont'] !== 'default') {
// Double-check that $options['editfont'] consists of safe characters only
if (preg_match('/^[a-zA-Z0-9_, -]+$/', $options['editfont'])) {
$rules[] = "textarea { font-family: {$options['editfont']}; }\n";
}
}
$style = implode("\n", $rules);
if ($this->getFlip($context)) {
$style = CSSJanus::transform($style, true, false);
}
return ['all' => $style];
}
示例7: fn_merge_styles
//.........这里部分代码省略.........
$m_prefix = '';
$m_suffix = '';
if (!empty($src['media'])) {
$m_prefix = "\n@media " . $src['media'] . " {\n";
$m_suffix = "\n}\n";
}
if (strpos($src['file'], '.css') !== false) {
$output .= "\n" . $m_prefix . fn_get_contents($src['file']) . $m_suffix;
} elseif ($area != 'C' || empty($theme_manifest['converted_to_css'])) {
$less_output_chunk = '';
if (file_exists($src['file'])) {
if ($area == 'C' && (empty($theme_manifest['parent_theme']) || $theme_manifest['parent_theme'] == 'basic')) {
$less_output_chunk = "\n" . $m_prefix . fn_get_contents($src['file']) . $m_suffix;
} else {
$less_output_chunk = "\n" . $m_prefix . '@import "' . str_replace($relative_path . '/', '', $src['relative']) . '";' . $m_suffix;
}
}
if (!empty($params['reflect_less'])) {
if (preg_match('{/addons/([^/]+)/}is', $src['relative'], $m)) {
$less_reflection['output']['addons'][$m[1]] .= $less_output_chunk;
} else {
$less_reflection['output']['main'] .= $less_output_chunk;
}
}
$less_output .= $less_output_chunk;
}
}
$header = str_replace('[files]', implode("\n", $names), Registry::get('config.js_css_cache_msg'));
if (!empty($styles)) {
$less_output .= $styles;
}
// Prepend all styles with prefix
if (!empty($prepend_prefix)) {
$less_output = $output . "\n" . $less_output;
$output = '';
}
if (!empty($output)) {
$compiled_css = Less::parseUrls($output, Storage::instance('assets')->getAbsolutePath($relative_path), fn_get_theme_path('[themes]/[theme]/media', $area));
}
if (!empty($theme_manifest['converted_to_css']) && $area == 'C') {
$theme_css_path = fn_get_theme_path('[themes]/[theme]', $area) . '/css';
$pcl_filepath = $theme_css_path . '/' . Themes::$compiled_less_filename;
if (file_exists($pcl_filepath)) {
$compiled_css .= fn_get_contents($pcl_filepath);
}
list($installed_addons) = fn_get_addons(array('type' => 'active'));
foreach ($installed_addons as $addon) {
$addon_pcl_filpath = $theme_css_path . "/addons/{$addon['addon']}/" . Themes::$compiled_less_filename;
if (file_exists($pcl_filepath)) {
$compiled_css .= fn_get_contents($addon_pcl_filpath);
}
}
}
if (!empty($less_output)) {
$less = new Less();
if (!empty($params['compressed'])) {
$less->setFormatter('compressed');
}
$less->setImportDir($relative_path);
try {
$compiled_less = $less->customCompile($less_output, Storage::instance('assets')->getAbsolutePath($relative_path), array(), $prepend_prefix, $area);
} catch (Exception $e) {
$skip_save = true;
$shift = 4;
$message = '<div style="border: 2px solid red; padding: 5px;">LESS ' . $e->getMessage();
if (preg_match("/line: (\\d+)/", $message, $m)) {
$lo = explode("\n", $less_output);
$message .= '<br /><br /><pre>' . implode("\n", array_splice($lo, intval($m[1]) - $shift, $shift * 2)) . '</pre>';
}
$message .= '</div>';
fn_set_notification('E', __('error'), $message);
}
}
if (empty($skip_save)) {
$compiled_content = $compiled_css . "\n" . $compiled_less;
// Move all @import links to the Top of the file.
if (preg_match_all('/@import url.*?;/', $compiled_content, $imports)) {
$compiled_content = preg_replace('/@import url.*?;/', '', $compiled_content);
foreach ($imports[0] as $import_link) {
$compiled_content = $import_link . "\n" . $compiled_content;
}
}
if ($make_rtl) {
$compiled_content = \CSSJanus::transform($compiled_content);
$compiled_content = "body {\ndirection: rtl;\n}\n" . $compiled_content;
}
Storage::instance('assets')->put($relative_path . '/' . $filename, array('contents' => $header . $compiled_content, 'compress' => false, 'caching' => true));
if (!empty($params['use_scheme'])) {
fn_put_contents(fn_get_cache_path(false) . 'theme_editor/' . $filename, $output . '#LESS#' . $less_output);
}
if (!empty($params['reflect_less'])) {
$less_reflection['import_dirs'] = array($relative_path);
fn_put_contents(fn_get_cache_path(false) . 'less_reflection.json', json_encode($less_reflection));
}
}
Debugger::checkpoint('After styles compilation');
}
$url = Storage::instance('assets')->getUrl($relative_path . '/' . $filename);
return $url;
}
示例8: getStyles
/**
* @param $context ResourceLoaderContext
* @return array
*/
public function getStyles(ResourceLoaderContext $context)
{
global $wgScriptPath;
$styles = array();
foreach ($this->getPages($context) as $titleText => $options) {
if ($options['type'] !== 'style') {
continue;
}
$title = Title::newFromText($titleText);
if (!$title || $title->isRedirect()) {
continue;
}
$media = isset($options['media']) ? $options['media'] : 'all';
$style = $this->getContent($title);
if (strval($style) === '') {
continue;
}
if ($this->getFlip($context)) {
$style = CSSJanus::transform($style, true, false);
}
$style = CSSMin::remap($style, false, $wgScriptPath, true);
if (!isset($styles[$media])) {
$styles[$media] = array();
}
if (strpos($titleText, '*/') === false) {
$style = "/* {$titleText} */\n" . $style;
}
$styles[$media][] = $style;
}
return $styles;
}
示例9: readStyleFile
/**
* Reads a style file.
*
* This method can be used as a callback for array_map()
*
* @param $path String: File path of style file to read
* @param $flip bool
*
* @return String: CSS data in script file
* @throws MWException if the file doesn't exist
*/
protected function readStyleFile($path, $flip)
{
$localPath = $this->getLocalPath($path);
if (!file_exists($localPath)) {
$msg = __METHOD__ . ": style file not found: \"{$localPath}\"";
wfDebugLog('resourceloader', $msg);
throw new MWException($msg);
}
$style = file_get_contents($localPath);
if ($flip) {
$style = CSSJanus::transform($style, true, false);
}
$dirname = dirname($path);
if ($dirname == '.') {
// If $path doesn't have a directory component, don't prepend a dot
$dirname = '';
}
$dir = $this->getLocalPath($dirname);
$remoteDir = $this->getRemotePath($dirname);
// Get and register local file references
$this->localFileRefs = array_merge($this->localFileRefs, CSSMin::getLocalFileReferences($style, $dir));
return CSSMin::remap($style, $dir, $remoteDir, true);
}
示例10: readStyleFile
/**
* Reads a style file.
*
* This method can be used as a callback for array_map()
*
* @param $path String: File path of style file to read
* @param $flip bool
*
* @return String: CSS data in script file
* @throws MWException if the file doesn't exist
*/
protected function readStyleFile($path, $flip, ResourceLoaderContext $context)
{
$localPath = $this->getLocalPath($path);
if (!file_exists($localPath)) {
throw new MWException(__METHOD__ . ": style file not found: \"{$localPath}\"");
}
// Wikia - change begin - @author: wladek
$style = self::getFileContents($localPath, $context);
// Wikia - change end
if ($flip) {
$style = CSSJanus::transform($style, true, false);
}
$dirname = dirname($path);
if ($dirname == '.') {
// If $path doesn't have a directory component, don't prepend a dot
$dirname = '';
}
$dir = $this->getLocalPath($dirname);
$remoteDir = $this->getRemotePath($dirname, $context);
// Get and register local file references
$this->localFileRefs = array_merge($this->localFileRefs, CSSMin::getLocalFileReferences($style, $dir));
return CSSMin::remap($style, $dir, $remoteDir, true, $this->localBasePath);
}
示例11: getStyles
/**
* @param $context ResourceLoaderContext
* @return array
*/
public function getStyles(ResourceLoaderContext $context)
{
global $wgAllowUserCssPrefs;
if ($wgAllowUserCssPrefs) {
$options = $this->contextUserOptions($context);
// Build CSS rules
$rules = array();
if ($options['underline'] < 2) {
$rules[] = "a { text-decoration: " . ($options['underline'] ? 'underline' : 'none') . "; }";
} else {
# The scripts of these languages are very hard to read with underlines
$rules[] = 'a:lang(ar), a:lang(ckb), a:lang(fa),a:lang(kk-arab), ' . 'a:lang(mzn), a:lang(ps), a:lang(ur) { text-decoration: none; }';
}
if ($options['highlightbroken']) {
$rules[] = "a.new, #quickbar a.new { color: #ba0000; }\n";
} else {
$rules[] = "a.new, #quickbar a.new, a.stub, #quickbar a.stub { color: inherit; }";
$rules[] = "a.new:after, #quickbar a.new:after { content: '?'; color: #ba0000; }";
$rules[] = "a.stub:after, #quickbar a.stub:after { content: '!'; color: #772233; }";
}
if ($options['justify']) {
$rules[] = "#article, #bodyContent, #mw_content { text-align: justify; }\n";
}
if (!$options['showtoc']) {
$rules[] = "#toc { display: none; }\n";
}
if (!$options['editsection']) {
$rules[] = ".editsection { display: none; }\n";
}
if ($options['editfont'] !== 'default') {
$rules[] = "textarea { font-family: {$options['editfont']}; }\n";
}
$style = implode("\n", $rules);
if ($this->getFlip($context)) {
$style = CSSJanus::transform($style, true, false);
}
return array('all' => $style);
}
return array();
}
示例12: buildExemptModules
/**
* Build exempt modules and legacy non-ResourceLoader styles.
*
* @return string|WrappedStringList HTML
*/
protected function buildExemptModules()
{
global $wgContLang;
$resourceLoader = $this->getResourceLoader();
$chunks = [];
// Things that go after the ResourceLoaderDynamicStyles marker
$append = [];
// Exempt 'user' styles module (may need 'excludepages' for live preview)
if ($this->isUserCssPreview()) {
$append[] = $this->makeResourceLoaderLink('user.styles', ResourceLoaderModule::TYPE_STYLES, ['excludepage' => $this->getTitle()->getPrefixedDBkey()]);
// Load the previewed CSS. Janus it if needed.
// User-supplied CSS is assumed to in the wiki's content language.
$previewedCSS = $this->getRequest()->getText('wpTextbox1');
if ($this->getLanguage()->getDir() !== $wgContLang->getDir()) {
$previewedCSS = CSSJanus::transform($previewedCSS, true, false);
}
$append[] = Html::inlineStyle($previewedCSS);
}
// We want site, private and user styles to override dynamically added styles from
// general modules, but we want dynamically added styles to override statically added
// style modules. So the order has to be:
// - page style modules (formatted by ResourceLoaderClientHtml::getHeadHtml())
// - dynamically loaded styles (added by mw.loader before ResourceLoaderDynamicStyles)
// - ResourceLoaderDynamicStyles marker
// - site/private/user styles
// Add legacy styles added through addStyle()/addInlineStyle() here
$chunks[] = implode('', $this->buildCssLinksArray()) . $this->mInlineStyles;
$chunks[] = Html::element('meta', ['name' => 'ResourceLoaderDynamicStyles', 'content' => '']);
foreach ($this->rlExemptStyleModules as $group => $moduleNames) {
$chunks[] = $this->makeResourceLoaderLink($moduleNames, ResourceLoaderModule::TYPE_STYLES);
}
return self::combineWrappedStrings(array_merge($chunks, $append));
}
示例13: getCSS
/**
* Get the raw vector CSS, flipping if needed
*
* @todo Possibly get rid of this function and use ResourceLoader in the manner it was
* designed to be used in, rather than just grabbing a list of filenames from it,
* and not properly handling such details as media types in module definitions.
*
* @param string $dir 'ltr' or 'rtl'
* @return String
*/
public function getCSS($dir)
{
// All CSS files these modules reference will be concatenated in sequence
// and loaded as one file.
$moduleNames = array('mediawiki.legacy.shared', 'skins.common.interface', 'skins.vector.styles', 'mediawiki.legacy.config');
$prepend = '';
$css = '';
$resourceLoader = new ResourceLoader();
foreach ($moduleNames as $moduleName) {
/** @var ResourceLoaderFileModule $module */
$module = $resourceLoader->getModule($moduleName);
$cssFileNames = $module->getAllStyleFiles();
wfSuppressWarnings();
foreach ($cssFileNames as $cssFileName) {
if (!file_exists($cssFileName)) {
$prepend .= ResourceLoader::makeComment("Unable to find {$cssFileName}.");
continue;
}
if (!is_readable($cssFileName)) {
$prepend .= ResourceLoader::makeComment("Unable to read {$cssFileName}. " . "Please check file permissions.");
continue;
}
try {
if (preg_match('/\\.less$/', $cssFileName)) {
// Run the LESS compiler for *.less files (bug 55589)
$compiler = ResourceLoader::getLessCompiler();
$cssFileContents = $compiler->compileFile($cssFileName);
} else {
// Regular CSS file
$cssFileContents = file_get_contents($cssFileName);
}
if ($cssFileContents) {
// Rewrite URLs, though don't bother embedding images. While static image
// files may be cached, CSS returned by this function is definitely not.
$cssDirName = dirname($cssFileName);
$css .= CSSMin::remap($cssFileContents, $cssDirName, '..' . str_replace(array($GLOBALS['IP'], DIRECTORY_SEPARATOR), array('', '/'), $cssDirName), false);
} else {
$prepend .= ResourceLoader::makeComment("Unable to read {$cssFileName}.");
}
} catch (Exception $e) {
$prepend .= ResourceLoader::formatException($e);
}
$css .= "\n";
}
wfRestoreWarnings();
}
$css = $prepend . $css;
if ($dir == 'rtl') {
$css = CSSJanus::transform($css, true);
}
return $css;
}
示例14: getCSS
/**
* Get the raw vector CSS, flipping if needed
* @param $dir String 'ltr' or 'rtl'
* @return String
*/
public function getCSS($dir)
{
$skinDir = dirname(dirname(dirname(__FILE__))) . '/skins';
$vectorCssFile = "{$skinDir}/vector/screen.css";
$configCssFile = "{$skinDir}/common/config.css";
$css = '';
wfSuppressWarnings();
$vectorCss = file_get_contents($vectorCssFile);
$configCss = file_get_contents($configCssFile);
wfRestoreWarnings();
if (!$vectorCss || !$configCss) {
$css = "/** Your webserver cannot read {$vectorCssFile} or {$configCssFile}, please check file permissions */";
}
$css .= str_replace('images/', '../skins/vector/images/', $vectorCss) . "\n" . str_replace('images/', '../skins/common/images/', $configCss);
if ($dir == 'rtl') {
$css = CSSJanus::transform($css, true);
}
return $css;
}
示例15: testTransform
/**
* @dataProvider provideData
*/
public function testTransform($input, $settings, $output, $name)
{
$this->assertEquals($output, CSSJanus::transform($input, $settings['swapLtrRtlInUrl'], $settings['swapLeftRightInUrl']), $name);
}