public function parseStyleSheet($file, $styles = false) { if (file_exists($this->getThemeDirectory() . '/' . $file)) { $fh = Loader::helper('file'); $contents = $fh->getContents($this->getThemeDirectory() . '/' . $file); // replace all url( instances with url starting with path to theme $contents = str_replace('url(', 'url(' . $this->getThemeURL() . '/', $contents); // load up all tokens from the db for this stylesheet. // if a replacement style array is passed then we use that instead of the database (as is the case when previewing) if (!is_array($styles)) { $db = Loader::db(); $ptes = $db->GetAll("select ptsHandle, ptsValue, ptsType from PageThemeStyles where ptID = ?", $this->getThemeID()); $styles = array(); foreach($ptes as $p) { $pts = new PageThemeEditableStyle($p['ptsValue']); $pts->setPropertiesFromArray($p); $styles[] = $pts; } } $replacements = array(); $searches = array(); foreach($styles as $p) { if ($p->getType() == PageThemeEditableStyle::TSTYPE_CUSTOM) { $contents = preg_replace("/\/\*[\s]?customize_" . $p->getHandle() . "[\s]?\*\/(.*)\/\*[\s]?customize_" . $p->getHandle() . "[\s]?\*\//i", "/* customize_" . $p->getHandle() . " */ " . $p->getValue() . " /* customize_" . $p->getHandle() . " */" , $contents); } else { $contents = preg_replace("/\/\*[\s]?customize_" . $p->getHandle() . "[\s]?\*\/[\s]?" . $p->getProperty() . "(.*)\/\*[\s]?customize_" . $p->getHandle() . "[\s]?\*\//i", "/* customize_" . $p->getHandle() . " */ " . $p->getValue() . " /* customize_" . $p->getHandle() . " */" , $contents); } } return $contents; } }
public function parseStyleSheet($file, $styles = false) { $env = Environment::get(); $themeRec = $env->getUncachedRecord(DIRNAME_THEMES . '/' . $this->getThemeHandle() . '/' . $file, $this->getPackageHandle()); if ($themeRec->exists()) { $fh = Loader::helper('file'); $contents = $fh->getContents($themeRec->file); // replace all url( instances with url starting with path to theme $contents = preg_replace('/(url\\(\')([^\\)]*)/', '$1' . $this->getThemeURL() . '/$2', $contents); $contents = preg_replace('/(url\\(")([^\\)]*)/', '$1' . $this->getThemeURL() . '/$2', $contents); $contents = preg_replace('/(url\\((?![\'"]))([^\\)]*)/', '$1' . $this->getThemeURL() . '/$2', $contents); $contents = str_replace('url(' . $this->getThemeURL() . '/data:image', 'url(data:image', $contents); // load up all tokens from the db for this stylesheet. // if a replacement style array is passed then we use that instead of the database (as is the case when previewing) if (!is_array($styles)) { $db = Loader::db(); $ptes = $db->GetAll("select ptsHandle, ptsValue, ptsType from PageThemeStyles where ptID = ?", $this->getThemeID()); $styles = array(); foreach ($ptes as $p) { $pts = new PageThemeEditableStyle($p['ptsValue']); $pts->setPropertiesFromArray($p); $styles[] = $pts; } } $replacements = array(); $searches = array(); foreach ($styles as $p) { if ($p->getType() == PageThemeEditableStyle::TSTYPE_CUSTOM) { $contents = preg_replace("/\\/\\*[\\s]?customize_" . $p->getHandle() . "[\\s]?\\*\\/(.*)\\/\\*[\\s]?customize_" . $p->getHandle() . "[\\s]?\\*\\//i", "/* customize_" . $p->getHandle() . " */ " . $p->getValue() . " /* customize_" . $p->getHandle() . " */", $contents); } else { $contents = preg_replace("/\\/\\*[\\s]?customize_" . $p->getHandle() . "[\\s]?\\*\\/[\\s]?" . $p->getProperty() . "(.*)\\/\\*[\\s]?customize_" . $p->getHandle() . "[\\s]?\\*\\//i", "/* customize_" . $p->getHandle() . " */ " . $p->getValue() . " /* customize_" . $p->getHandle() . " */", $contents); } } return $contents; } }