1<?php
2
3/*
4 * vim:set softtabstop=4 shiftwidth=4 expandtab:
5 *
6 *  LICENSE: GNU Affero General Public License, version 3 (AGPL-3.0-or-later)
7 * Copyright 2001 - 2020 Ampache.org
8 *
9 * This program is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU Affero General Public License as published by
11 * the Free Software Foundation, either version 3 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 * GNU Affero General Public License for more details.
18 *
19 * You should have received a copy of the GNU Affero General Public License
20 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
21 *
22 */
23
24declare(strict_types=0);
25
26namespace Ampache\Module\Api\Method;
27
28use Ampache\Config\AmpConfig;
29use Ampache\Module\Api\Api;
30use Ampache\Module\Api\Json_Data;
31use Ampache\Module\Api\Xml_Data;
32use Ampache\Module\System\Session;
33
34/**
35 * Class ShareMethod
36 * @package Lib\ApiMethods
37 */
38final class ShareMethod
39{
40    private const ACTION = 'share';
41
42    /**
43     * share
44     * MINIMUM_API_VERSION=420000
45     *
46     * Get the share from it's id.
47     *
48     * @param array $input
49     * filter = (integer) Share ID number
50     * @return boolean
51     */
52    public static function share(array $input)
53    {
54        if (!AmpConfig::get('share')) {
55            Api::error(T_('Enable: share'), '4703', self::ACTION, 'system', $input['api_format']);
56
57            return false;
58        }
59        if (!Api::check_parameter($input, array('filter'), self::ACTION)) {
60            return false;
61        }
62        $share = array((int) $input['filter']);
63
64        ob_end_clean();
65        switch ($input['api_format']) {
66            case 'json':
67                echo Json_Data::shares($share, false);
68                break;
69            default:
70                echo Xml_Data::shares($share);
71        }
72        Session::extend($input['auth']);
73
74        return true;
75    }
76}
77