<?php
function getAllSharedNotes($noteStore, $maxCount = null) {
    $noteFilter = new NoteFilter();
    $noteFilter->words = "sharedate:*";
    $sharedNotes = array();
    $offset = 0;
    if ($maxCount == null) {
        $maxCount = 500;
    }
    while (count($sharedNotes) < $maxCount) {
        try {
            $noteList = $noteStore->findNotes($noteFilter, $offset, 50);
            $sharedNotes += $noteList->notes;
        } catch (EDAMNotFoundException $e) {
            print "Error getting shared notes:";
            var_dump($e);
            return null;
        } catch (EDAMSystemException $e) {
            print "Error getting shared notes:";
            var_dump($e);
            return null;
        } catch (EDAMUserException $e) {
            print "Error getting shared notes:";
            var_dump($e);
            return null;
        }
 
        if (count($sharedNotes) % 50 != 0) {
            // We've retrieved all of the notes 
            break;
        } else {
            $offset += 50;
        }
    }
    return array_slice($sharedNotes, 0, $maxCount);
}
?>