You are here

private function OSMTemplate::writeCSS in MediaFront 7

Same name and namespace in other branches
  1. 6.2 players/osmplayer/player/OSMTemplate.php \OSMTemplate::writeCSS()
  2. 6 players/osmplayer/player/OSMTemplate.php \OSMTemplate::writeCSS()

Writes the contents of one CSS file to another, but also replaces all the id's and class names to take into account the prefix ( id ) of the media player.

1 call to OSMTemplate::writeCSS()
OSMTemplate::createCSS in players/osmplayer/player/OSMTemplate.php
Create the CSS files for this media player. This will dynamically rename all the id's and class names within the master CSS files ( theme and template ), and then create a cached version of them within the css folder.

File

players/osmplayer/player/OSMTemplate.php, line 229

Class

OSMTemplate
Copyright (c) 2010 Alethia Inc, http://www.alethia-inc.com Developed by Travis Tidwell | travist at alethia-inc.com

Code

private function writeCSS($css, $handle) {

  // Get the file contents and length.
  $contents = file_get_contents(dirname(__FILE__) . '/' . $css);

  // Change all of the images to the correct path...
  $playerPath = $this->playerSettings['playerPath'] ? $this->playerSettings['playerPath'] : '../';
  $contents = str_replace('images/', $playerPath . str_replace(basename($css), '', $css) . 'images/', $contents);

  // Locate all of the z-index elements.
  $contents = preg_replace_callback('/z-index\\s*:\\s*([0-9]+)/', create_function('$match', '$zIndex = intval($match[1]);
       return $zIndex ? "z-index:" . (' . $this->playerSettings['zIndex'] . ' + $zIndex) : $zIndex;'), $contents);

  // Get the length of the contents.
  $len = strlen($contents);

  // Make sure we don't overwrite anything within brackets...
  $match = 0;
  $matches = array();
  preg_match_all('/\\{.*\\}/sU', $contents, $matches, PREG_OFFSET_CAPTURE);
  if (count($matches[0]) > 0) {
    $match_len = strlen($matches[0][$match][0]);
  }

  // Iterate through all the characters.
  for ($i = 0; $i < $len; $i++) {

    // See if we need to increment the current match.
    if (isset($matches[0][$match + 1]) && $i > $matches[0][$match + 1][1]) {
      $match++;
      $match_len = strlen($matches[0][$match][0]);
    }

    // Get the char at this index.
    $char = $contents[$i];

    // If this is a class or an id, and is not within brackets...
    if (($char == '#' || $char == '.') && !($i > $matches[0][$match][1] && $i <= $matches[0][$match][1] + $match_len)) {
      fwrite($handle, $char . $this->playerSettings['id'] . '_');
    }
    else {
      fwrite($handle, $char);
    }
  }
}