コード例 #1
0
function is_allowed_media($media_list)
{
    // Now we've got the list of media this style can be applied to;
    // check if at least one of this media types is being used by the script
    //
    $allowed_media = config_get_allowed_media();
    $allowed_found = false;
    foreach ($media_list as $media) {
        $allowed_found |= array_search($media, $allowed_media) !== false;
    }
    return $allowed_found;
}
コード例 #2
0
function is_allowed_media($media_list)
{
    // Now we've got the list of media this style can be applied to;
    // check if at least one of this media types is being used by the script
    //
    $allowed_media = config_get_allowed_media();
    $allowed_found = false;
    // Note that media names should be case-insensitive;
    // it is not guaranteed that $media_list contains lower-case variants,
    // as well as it is not guaranteed that configuration data contains them.
    // Thus, media name lists should be explicitly converted to lowercase
    $media_list = array_map('strtolower', $media_list);
    $allowed_media = array_map('strtolower', $allowed_media);
    foreach ($media_list as $media) {
        $allowed_found |= array_search($media, $allowed_media) !== false;
    }
    return $allowed_found;
}
コード例 #3
0
function parse_css($css, &$pipeline, $baseindex = 0)
{
    $allowed_media = implode("|", config_get_allowed_media());
    // remove the UTF8 byte-order mark from the beginning of the file (several high-order symbols at the beginning)
    $pos = 0;
    $len = strlen($css);
    while (ord($css[$pos]) > 127 && $pos < $len) {
        $pos++;
    }
    $css = substr($css, $pos);
    // Process @media rules;
    // basic syntax is:
    // @media <media>(,<media>)* { <rules> }
    //
    while (preg_match("/^(.*?)@media([^{]+){(.*)\$/s", $css, $matches)) {
        $head = $matches[1];
        $media = $matches[2];
        $rest = $matches[3];
        // Process CSS rules placed before the first @media declaration - they should be applied to
        // all media types
        //
        $this->parse_css_media($head, $pipeline, $baseindex);
        // Extract the media content
        if (!preg_match("/^((?:[^{}]*{[^{}]*})*)[^{}]*\\s*}(.*)\$/s", $rest, $matches)) {
            die("CSS media syntax error\n");
        } else {
            $content = $matches[1];
            $tail = $matches[2];
        }
        // Check if this media is to be processed
        if (preg_match("/" . $allowed_media . "/i", $media)) {
            $this->parse_css_media($content, $pipeline, $baseindex);
        }
        // Process the rest of CSS file
        $css = $tail;
    }
    // The rest of CSS file belogs to common media, process it too
    $this->parse_css_media($css, $pipeline, $baseindex);
}