$data_connection = Data::GetConnection();
$reddit = new Reddit(REDDIT_USERNAME, REDDIT_PASSWORD);
$reddit->Login();
// Get collections of subreddits that we should be monitoring.
$query = "SELECT rec_id, name FROM Subreddit WHERE active=1";
$result = $data_connection->query($query);
$subreddit = array();
while ($row = $result->fetch_assoc()) {
    $subreddit[$row['name']] = $row['rec_id'];
}
// Get list of locations that we should look for.
$query = "SELECT name FROM Location";
$result = $data_connection->query($query);
$location = array();
while ($row = $result->fetch_assoc()) {
    array_push($location, "\\b({$row['name']})\\b");
}
// Create a regular expression based on the locations array.
$locations_regex = "/" . implode('|', $location) . "/i";
// Get list of posts that we need to parse for each subreddit we monitor.
foreach ($subreddit as $key => $value) {
    $posts = $reddit->GetSubredditPosts($key);
    foreach ($posts[data]->children as $post) {
        $action = new Action($post, $reddit, $data_connection, $value);
        $action->FindMatches($locations_regex);
        $action->PerformAction();
    }
}
// Handle username mentions.
$mention = new MentionAction($post, $reddit, $data_connection, $value);
$mention->PerformAction();