Example #1
0
 function fwp_xpathtest()
 {
     $xpath = MyPHP::request('xpath');
     $feed_id = MyPHP::request('feed_id');
     $post_id = MyPHP::request('post_id');
     $expr = new FeedWordPressParsedPostMeta($xpath);
     // Let's load up some data from the feed . . .
     $feed = $this->subscription($feed_id);
     $posts = $feed->live_posts();
     if (!is_wp_error($posts)) {
         if (strlen($post_id) == 0) {
             $post = $posts[0];
         } else {
             $post = null;
             foreach ($posts as $p) {
                 if ($p->get_id() == $post_id) {
                     $post = $p;
                 }
             }
         }
         $post = new SyndicatedPost($post, $feed);
         $meta = $expr->do_substitutions($post);
         $result = array("post_title" => $post->entry->get_title(), "post_link" => $post->permalink(), "guid" => $post->guid(), "expression" => $xpath, "results" => $meta);
     } else {
         $result = array("expression" => $xpath, "feed_id" => $feed_id, "post_id" => $post_id, "results" => $posts);
         header("HTTP/1.1 503 Bad Gateway");
     }
     header("Content-Type: application/json");
     echo json_encode($result);
     // This is an AJAX request, so close it out thus.
     die;
 }
        }
        if (strlen($var) > 0) {
            $ret[1] = $var;
        }
        return $ret;
    }
}
/* class FeedWordPressParsedPostMeta */
if (basename($_SERVER['SCRIPT_FILENAME']) == basename(__FILE__)) {
    $argv = $_SERVER['argv'];
    array_shift($argv);
    $N = reset($argv);
    if (is_numeric($N)) {
        array_shift($argv);
    } else {
        $N = 1;
    }
    $t0 = microtime(true);
    for ($i = 0; $i < $N; $i++) {
        $parse = new FeedWordPressParsedPostMeta(implode(" ", $argv));
        $voo = $parse->parse();
        unset($parse);
    }
    $t1 = microtime(true);
    echo "RESULT: ";
    var_dump($voo);
    echo "ELAPSED TIME: ";
    print number_format(1000.0 * ($t1 - $t0)) . "ms\n";
    echo "CONSUMED MEMORY: ";
    print number_format(memory_get_peak_usage() / 1024) . "KB\n";
}