public function search($searchtext, $page = 0) {

        $response = $this->flickr->call('photos.search', [
            'user_id' => 'me',
            'per_page' => 24,
            'extras' => 'original_format,url_sq,url_o,date_upload,owner_name',
            'page' => $page,
            'text' => $searchtext,
        ]);

        if ($response === false) {
            $this->logout();
            return [];
        }

        // Convert the response to the format expected by the filepicker.

        $ret = [
            'manage' => 'https://www.flickr.com/photos/organize',
            'list' => [],
            'pages' => $response->photos->pages,
            'total' => $response->photos->total,
            'perpage' => $response->photos->perpage,
            'page' => $response->photos->page,
        ];

        if (!empty($response->photos->photo)) {
            foreach ($response->photos->photo as $p) {
                if (empty($p->title)) {
                    $p->title = get_string('notitle', 'repository_flickr');
                }

                if (isset($p->originalformat)) {
                    $format = $p->originalformat;
                } else {
                    $format = 'jpg';
                }
                $format = '.'.$format;

                // Append extension to the file name.
                if (substr($p->title, strlen($p->title) - strlen($format)) != $format) {
                    $p->title .= $format;
                }

                $ret['list'][] = [
                    'title' => $p->title,
                    'source' => $p->id,
                    'id' => $p->id,
                    'thumbnail' => $p->url_sq,
                    'thumbnail_width' => $p->width_sq,
                    'thumbnail_height' => $p->height_sq,
                    'date' => $p->dateupload,
                    'url' => $p->url_o,
                    'author' => $p->ownername,
                    'size' => null,
                    'license' => '',
                ];
            }
        }

        // Filter file listing to display specific types only.
        $ret['list'] = array_filter($ret['list'], array($this, 'filter'));

        return $ret;
    }