Exemplo n.º 1
0
/**
 * Pull notifications from remotes
 * @return array Notifications
 */
function get_notifications()
{
    global $config;
    $obj = array();
    foreach ($config['notifications'] as $name => $url) {
        echo '[ ' . date('r') . ' ] ' . $url . ' ';
        $feed = json_decode(json_encode(simplexml_load_string(file_get_contents($url))), true);
        if (isset($feed['channel'])) {
            $feed = parse_rss($feed);
        } else {
            $feed = parse_atom($feed);
        }
        array_walk($feed, function (&$items, $key, $url) {
            $items['source'] = $url;
        }, $url);
        $obj = array_reverse(array_merge($obj, $feed));
        echo '(' . sizeof($obj) . ')' . PHP_EOL;
    }
    return $obj;
}
Exemplo n.º 2
0
/**
 * seq ::= ( atom [ '...' ] )* ;
 */
function parse_seq($tokens, \ArrayIterator $options)
{
    $result = array();
    $not = array(null, '', ']', ')', '|');
    while (!in_array($tokens->current(), $not, true)) {
        $atom = parse_atom($tokens, $options);
        if ($tokens->current() == '...') {
            $atom = array(new OneOrMore($atom));
            $tokens->move();
        }
        if ($atom instanceof \ArrayIterator) {
            $atom = $atom->getArrayCopy();
        }
        if ($atom) {
            $result = array_merge($result, $atom);
        }
    }
    return $result;
}
Exemplo n.º 3
0
function parse_expression($expression, $variables)
{
    $expression = trim($expression);
    //echo "E: ".$expression."\n";
    if ($expression[0] == '&') {
        $result = true;
        $expression = trim(substr($expression, 2, strlen($expression) - 3));
        while ($result && strlen($expression) > 0) {
            if ($expression[0] == '|' || $expression[0] == '&') {
                $subexpression = subexpression($expression);
                $result &= parse_expression($subexpression, $variables);
                $expression = trim(substr($expression, strlen($subexpression) + 1));
            } else {
                $atom = substr($expression, 0, strpos($expression, ")") + 1);
                $expression = trim(substr($expression, strlen($atom) + 1));
                $result &= parse_atom($atom, $variables);
            }
            if (strlen($expression) && $expression[0] == ',') {
                //echo "C: ".$expression."\n";
                $expression = trim(substr($expression, 1));
                //echo "D: ".$expression."\n";
            }
        }
        return $result;
    } else {
        if ($expression[0] == '|') {
            $result = false;
            $expression = trim(substr($expression, 2, strlen($expression) - 3));
            while (!$result && strlen($expression) > 0) {
                if ($expression[0] == '|' || $expression[0] == '&') {
                    $subexpression = subexpression($expression);
                    $result |= parse_expression($subexpression, $variables);
                    $expression = trim(substr($expression, strlen($subexpression) + 1));
                } else {
                    $atom = substr($expression, 0, strpos($expression, ")") + 1);
                    $expression = trim(substr($expression, strlen($atom) + 1));
                    $result |= parse_atom($atom, $variables);
                }
                if (strlen($expression) && $expression[0] == ',') {
                    $expression = trim(substr($expression, 1));
                }
            }
            return $result;
        } else {
            return parse_atom($expression, $variables);
            //echo "\n".$expression."\n";
        }
    }
}
Exemplo n.º 4
0
if (file_exists(FEED_HISTORY_FILE) == True) {
    $data = file_get_contents(FEED_HISTORY_FILE);
    if ($data !== False) {
        $feed_history = explode(PHP_EOL, $data);
    }
}
$results = array();
$new_history = array();
for ($i = 0; $i < count($feed_list); $i++) {
    $feed = $feed_list[$i];
    term_echo("processing " . $feed["name"] . " " . $feed["type"] . " feed @ \"" . $feed["url"] . "\"");
    $response = wget($feed["host"], $feed["uri"], $feed["port"]);
    $html = strip_headers($response);
    $items = array();
    if ($feed["type"] == "atom") {
        $items = parse_atom($html);
    } elseif ($feed["type"] == "rss") {
        $items = parse_rss($html);
    }
    if ($items === False) {
        term_echo("feed parse error");
        continue;
    }
    term_echo("feed items for " . $feed["name"] . ": " . count($items));
    for ($j = 0; $j < count($items); $j++) {
        $item = $items[$j];
        if (in_array($item["url"], $feed_history) == False) {
            $new_history[] = $item["url"];
            $delim1 = "<![CDATA[";
            $delim2 = "]]>";
            if (strtoupper(substr($item["title"], 0, strlen($delim1))) == $delim1) {