PrivateBin\Data\Filesystem::readComments PHP Метод

readComments() публичный Метод

Read all comments of paste.
public readComments ( string $pasteid ) : array
$pasteid string
Результат array
    public function readComments($pasteid)
    {
        $comments = array();
        $discdir = self::_dataid2discussionpath($pasteid);
        if (is_dir($discdir)) {
            // Delete all files in discussion directory
            $dir = dir($discdir);
            while (false !== ($filename = $dir->read())) {
                // Filename is in the form pasteid.commentid.parentid:
                // - pasteid is the paste this reply belongs to.
                // - commentid is the comment identifier itself.
                // - parentid is the comment this comment replies to (It can be pasteid)
                if (is_file($discdir . $filename)) {
                    $comment = json_decode(file_get_contents($discdir . $filename));
                    $items = explode('.', $filename);
                    // Add some meta information not contained in file.
                    $comment->id = $items[1];
                    $comment->parentid = $items[2];
                    // Store in array
                    $key = $this->getOpenSlot($comments, (int) $comment->meta->postdate);
                    $comments[$key] = $comment;
                }
            }
            $dir->close();
            // Sort comments by date, oldest first.
            ksort($comments);
        }
        return $comments;
    }