Ejemplo n.º 1
0
 /**
  * Finds @groups within the css and returns
  * an array with the values, and groups.
  *
  * @author Anthony Short
  * @param $group string
  * @param $css string
  */
 public function find_at_group($group, $remove = true)
 {
     $found = array();
     $regex = "/\n\t\t\t# Group name\n\t\t\t@{$group}\n\t\t\t\n\t\t\t# Flag\n\t\t\t(?:\n\t\t\t\t\\(( [^)]*? )\\)\n\t\t\t)?\n\t\t\t\n\t\t\t[^{]*?\n\n\t\t\t(\n\t\t\t\t([0-9a-zA-Z\\_\\-\\@*&]*?)\\s*\n\t\t\t\t\\{\t\n\t\t\t\t\t( (?: [^{}]+ | (?2) )*)\n\t\t\t\t\\}\n\t\t\t)\n\n\t\t/ixs";
     if (preg_match_all($regex, $this->string, $matches)) {
         $found['groups'] = $matches[0];
         $found['flag'] = $matches[1];
         $found['content'] = $matches[4];
         foreach ($matches[4] as $key => $value) {
             // Remove comments to prevent breaking it
             $value = $this->remove_comments($value);
             foreach (explode(";", substr($value, 0, -1)) as $value) {
                 // Encode any colons inside quotations
                 if (preg_match_all('/[\'"](.*?\\:.*?)[\'"]/', $value, $m)) {
                     $value = str_replace($m[0][0], str_replace(':', '#COLON#', $m[0][0]), $value);
                 }
                 $value = explode(":", $value);
                 // Make sure it's set
                 if (isset($value[1])) {
                     $found['values'][trim($value[0])] = str_replace('#COLON#', ':', Scaffold::unquote($value[1]));
                 }
             }
         }
         // Remove the found @ groups
         if ($remove === true) {
             $this->string = str_replace($found['groups'], array(), $this->string);
         }
         return $found;
     }
     return false;
 }