protected function getOptions() { $plugin = JchPlatformPlugin::getPlugin(); $pluginParams = new JRegistry(); $pluginParams->loadString($plugin->params); $pluginParams->set('sprite-path', JchPlatformPaths::spriteDir()); $CssSpriteGenClass = 'JchOptimize\\CssSpriteGen'; $CssSpriteGen = new $CssSpriteGenClass(JchOptimizeSpriteGenerator::getImageLibrary(), $pluginParams); $aSpriteFormats = $CssSpriteGen->GetSpriteFormats(); $this->default = $aSpriteFormats[0]; $options = array(); foreach ($aSpriteFormats as $sSpriteFormat) { $option = JHtml::_('select.option', $sSpriteFormat, $sSpriteFormat, 'value', 'text'); $options[] = $option; } reset($options); return $options; }
/** * Generates sprite image and return background positions for image replaced with sprite * * @param array $aMatches Array of css declarations and image url to be included in sprite * @param object $oSpriteGen Object of sprite generator * @return array */ public function generateSprite($aMatches, $oSpriteGen) { $aDeclaration = $aMatches[0]; $aImages = $aMatches[1]; $oSpriteGen->CreateSprite($aImages); $aSpriteCss = $oSpriteGen->GetCssBackground(); $aPatterns = array(); $aPatterns[0] = '#background-image:#'; // Background image declaration regex $aPatterns[1] = '#(background:[^;}]*)\\b' . '((?:top|bottom|left|right|center|-?[0-9]+(?:%|[c-x]{2})?)' . '\\s(?:top|bottom|left|right|center|-?[0-9]+(?:%|[c-x]{2})?))([^;}]*[;}])#'; $aPatterns[2] = '#url\\((?=[^\\)]+\\.(?:png|gif|jpe?g))[^\\)]+\\)#'; //Background image regex $aPatterns[3] = '#background-position:[^;}]+;?#'; //Background position declaration regex $sSpriteName = $oSpriteGen->GetSpriteFilename(); $aSearch = array(); for ($i = 0; $i < count($aSpriteCss); $i++) { if (isset($aSpriteCss[$i])) { $aSearch['needles'][] = $aDeclaration[$i]; $spritepath = JchOptimizeHelper::cookieLessDomain($this->params) . JchPlatformPaths::spriteDir(TRUE) . $sSpriteName; $aReplacements = array(); $aReplacements[0] = 'background:'; $aReplacements[1] = '$1$3'; $aReplacements[2] = 'url(' . $spritepath . ') ' . $aSpriteCss[$i]; $aReplacements[3] = ''; $sReplacement = preg_replace($aPatterns, $aReplacements, $aDeclaration[$i]); if (is_null($sReplacement)) { throw new Exception(JchPlatformUtility::translate('Error finding replacements for sprite background positions')); } $aSearch['replacements'][] = $sReplacement; } } return $aSearch; }