3 * @copyright Copyright (C) 2020, Friendica
5 * @license GNU AGPL version 3 or any later version
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as
9 * published by the Free Software Foundation, either version 3 of the
10 * License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 namespace Friendica\Object;
27 * @see https://oembed.com/#section2.3
29 * @author Hypolite Petovan <hypolite@mrpetovan.com>
33 public $embed_url = '';
37 public $author_name = '';
38 public $author_url = '';
39 public $provider_name = '';
40 public $provider_url = '';
41 public $cache_age = '';
42 public $thumbnail_url = '';
43 public $thumbnail_width = '';
44 public $thumbnail_height = '';
50 public function __construct($embed_url)
52 $this->embed_url = $embed_url;
55 public function parseJSON($json_string)
57 $properties = json_decode($json_string, true);
59 if (empty($properties)) {
63 foreach ($properties as $key => $value) {
64 if (in_array($key, ['thumbnail_width', 'thumbnail_height', 'width', 'height'])) {
65 // These values should be numbers, so ensure that they really are numbers.
67 } elseif (is_array($value)) {
69 } elseif ($key != 'html') {
70 // Avoid being able to inject some ugly stuff through these fields.
71 $value = htmlentities($value);
73 /// @todo Add a way to sanitize the html as well, possibly with an <iframe>?
74 $value = mb_convert_encoding($value, 'HTML-ENTITIES', mb_detect_encoding($value));
77 if (property_exists(__CLASS__, $key)) {
78 $this->{$key} = $value;