protected function parse_selector($selector_string)
{
global $debugObject;
if (is_object($debugObject)) {
$debugObject->debugLogEntry(1);
}
// pattern of CSS selectors, modified from mootools
// Paperg: Add the colon to the attrbute, so that it properly finds <tag attr:ibute="something" > like google does.
// Note: if you try to look at this attribute, yo MUST use getAttribute since $dom->x:y will fail the php syntax check.
// Notice the \[ starting the attbute? and the @? following? This implies that an attribute can begin with an @ sign that is not captured.
// This implies that an html attribute specifier may start with an @ sign that is NOT captured by the expression.
// farther study is required to determine of this should be documented or removed.
// $pattern = "/([\w-:\*]*)(?:\#([\w-]+)|\.([\w-]+))?(?:\[@?(!?[\w-]+)(?:([!*^$]?=)[\"']?(.*?)[\"']?)?\])?([\/, ]+)/is";
$pattern = "/([\\w-:\\*]*)(?:\\#([\\w-]+)|\\.([\\w-]+))?(?:\\[@?(!?[\\w-:]+)(?:([!*^\$]?=)[\"']?(.*?)[\"']?)?\\])?([\\/, ]+)/is";
preg_match_all($pattern, trim($selector_string) . ' ', $matches, PREG_SET_ORDER);
if (is_object($debugObject)) {
$debugObject->debugLog(2, "Matches Array: ", $matches);
}
$selectors = array();
$result = array();
//print_r($matches);
foreach ($matches as $m) {
$m[0] = trim($m[0]);
if ($m[0] === '' || $m[0] === '/' || $m[0] === '//') {
continue;
}
// for browser generated xpath
if ($m[1] === 'tbody') {
continue;
}
list($tag, $key, $val, $exp, $no_key) = array($m[1], null, null, '=', false);
if (!empty($m[2])) {
$key = 'id';
$val = $m[2];
}
if (!empty($m[3])) {
$key = 'class';
$val = $m[3];
}
if (!empty($m[4])) {
$key = $m[4];
}
if (!empty($m[5])) {
$exp = $m[5];
}
if (!empty($m[6])) {
$val = $m[6];
}
// convert to lowercase
if ($this->dom->lowercase) {
$tag = strtolower($tag);
$key = strtolower($key);
}
//elements that do NOT have the specified attribute
if (isset($key[0]) && $key[0] === '!') {
$key = substr($key, 1);
$no_key = true;
}
$result[] = array($tag, $key, $val, $exp, $no_key);
if (trim($m[7]) === ',') {
$selectors[] = $result;
$result = array();
}
}
if (count($result) > 0) {
$selectors[] = $result;
}
return $selectors;
}