. * * @category Plugin * @package GNUsocial * @author Diogo Cordeiro * @author Daniel Supernault * @copyright 2015 Free Software Foundaction, Inc. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 * @link https://gnu.io/social */ if (!defined('GNUSOCIAL')) { exit(1); } class apActorLikedCollectionAction extends ManagedAction { protected $needLogin = false; protected $canPost = true; protected function handle() { $nickname = $this->trimmed('nickname'); try { $user = User::getByNickname($nickname); $profile = $user->getProfile(); $url = $profile->profileurl; } catch (Exception $e) { throw new \Exception('Invalid username'); } // TODO: Implement query parameters as per the doc $total_faves = Fave::countByProfile ($profile); $fave = Fave::byProfile ($user->getID(), 0, $total_faves); $faves = []; while ($fave->fetch()) { $faves[] = $this->pretty_fave (clone($fave)); } $res = [ '@context' => [ "https://www.w3.org/ns/activitystreams", [ "@language" => "en" ] ], 'id' => "{$url}/liked.json", 'type' => 'OrderedCollection', 'totalItems' => $total_faves, 'orderedItems' => $faves ]; header('Content-Type: application/json'); echo json_encode($res, JSON_UNESCAPED_SLASHES | (isset($_GET["pretty"]) ? JSON_PRETTY_PRINT : null)); } protected function pretty_fave ($fave_object) { $res = array ("uri" => $fave_object->uri, "created" => $fave_object->created, "object" => Activitypub_notice::noticeToObject(Notice::getByID($fave_object->notice_id))); return $res; } }