EmbedModule.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637
  1. <?php
  2. // This file is part of GNU social - https://www.gnu.org/software/social
  3. //
  4. // GNU social is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU Affero General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // GNU social is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU Affero General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU Affero General Public License
  15. // along with GNU social. If not, see <http://www.gnu.org/licenses/>.
  16. /**
  17. * OEmbed and OpenGraph implementation for GNU social
  18. *
  19. * @package GNUsocial
  20. * @author Stephen Paul Weber
  21. * @author hannes
  22. * @author Mikael Nordfeldth
  23. * @author Diogo Cordeiro <diogo@fc.up.pt>
  24. * @author Miguel Dantas <biodantasgs@gmail.com>
  25. * @copyright 2019 Free Software Foundation, Inc http://www.fsf.org
  26. * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
  27. */
  28. defined('GNUSOCIAL') || die();
  29. use Embed\Embed;
  30. /**
  31. * Base class for the Embed module that does most of the heavy lifting to get
  32. * and display representations for remote content.
  33. *
  34. * @copyright 2019 Free Software Foundation, Inc http://www.fsf.org
  35. * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
  36. */
  37. class EmbedModule extends Module
  38. {
  39. const MODULE_VERSION = '0.1.0';
  40. // settings which can be set in config.php with addPlugin('Embed', ['param'=>'value', ...]);
  41. // WARNING, these are _regexps_ (slashes added later). Always escape your dots and end ('$') your strings
  42. public $domain_whitelist = [
  43. // hostname => service provider
  44. '^i\d*\.ytimg\.com$' => 'YouTube',
  45. '^i\d*\.vimeocdn\.com$' => 'Vimeo',
  46. ];
  47. public $append_whitelist = []; // fill this array as domain_whitelist to add more trusted sources
  48. public $check_whitelist = false; // security/abuse precaution
  49. public $thumbnail_width = 128;
  50. public $thumbnail_height = 128;
  51. public $thumbnail_crop = true;
  52. protected $imgData = [];
  53. /**
  54. * Initialize the Embed plugin and set up the environment it needs for it.
  55. * Returns true if it initialized properly, the exception object if it
  56. * doesn't.
  57. */
  58. public function initialize()
  59. {
  60. parent::initialize();
  61. $this->domain_whitelist = array_merge($this->domain_whitelist, $this->append_whitelist);
  62. }
  63. /**
  64. * The code executed on GNU social checking the database schema, which in
  65. * this case is to make sure we have the plugin table we need.
  66. *
  67. * @return bool true if it ran successfully, the exception object if it doesn't.
  68. */
  69. public function onCheckSchema()
  70. {
  71. $this->onEndUpgrade(); // Ensure rename
  72. $schema = Schema::get();
  73. $schema->ensureTable('file_embed', File_embed::schemaDef());
  74. return true;
  75. }
  76. public function onEndUpgrade()
  77. {
  78. $schema = Schema::get();
  79. return $schema->renameTable('file_oembed', 'file_embed');
  80. }
  81. /**
  82. * This code executes when GNU social creates the page routing, and we hook
  83. * on this event to add our action handler for Embed.
  84. *
  85. * @param $m URLMapper the router that was initialized.
  86. * @return void true if successful, the exception object if it isn't.
  87. * @throws Exception
  88. */
  89. public function onRouterInitialized(URLMapper $m)
  90. {
  91. $m->connect('main/oembed', ['action' => 'oembed']);
  92. }
  93. /**
  94. * This event executes when GNU social encounters a remote URL we then decide
  95. * to interrogate for metadata. Embed gloms onto it to see if we have an
  96. *
  97. * @param $url string the remote URL we're looking at
  98. * @param $dom DOMDocument the document we're getting metadata from
  99. * @param $metadata stdClass class representing the metadata
  100. * @return bool true if successful, the exception object if it isn't.
  101. */
  102. public function onGetRemoteUrlMetadataFromDom($url, DOMDocument $dom, stdClass &$metadata)
  103. {
  104. try {
  105. common_log(LOG_INFO, "Trying to find Embed data for {$url} with 'oscarotero/Embed'");
  106. $info = Embed::create($url);
  107. $metadata->version = '1.0'; // Yes.
  108. $metadata->provider_name = $info->authorName;
  109. $metadata->title = $info->title;
  110. $metadata->html = common_purify($info->description);
  111. $metadata->type = $info->type;
  112. $metadata->url = $info->url;
  113. $metadata->thumbnail_url = $info->image;
  114. $metadata->thumbnail_height = $info->imageHeight;
  115. $metadata->thumbnail_width = $info->imageWidth;
  116. } catch (Exception $e) {
  117. common_log(LOG_INFO, "Failed to find Embed data for {$url} with 'oscarotero/Embed'");
  118. }
  119. if (isset($metadata->thumbnail_url)) {
  120. // sometimes sites serve the path, not the full URL, for images
  121. // let's "be liberal in what you accept from others"!
  122. // add protocol and host if the thumbnail_url starts with /
  123. if ($metadata->thumbnail_url[0] == '/') {
  124. $thumbnail_url_parsed = parse_url($metadata->url);
  125. $metadata->thumbnail_url = "{$thumbnail_url_parsed['scheme']}://".
  126. "{$thumbnail_url_parsed['host']}{$metadata->thumbnail_url}";
  127. }
  128. // some wordpress opengraph implementations sometimes return a white blank image
  129. // no need for us to save that!
  130. if ($metadata->thumbnail_url == 'https://s0.wp.com/i/blank.jpg') {
  131. unset($metadata->thumbnail_url);
  132. }
  133. // FIXME: this is also true of locally-installed wordpress so we should watch out for that.
  134. }
  135. return true;
  136. }
  137. public function onEndShowHeadElements(Action $action)
  138. {
  139. switch ($action->getActionName()) {
  140. case 'attachment':
  141. $url = common_local_url('attachment', ['attachment' => $action->attachment->getID()]);
  142. break;
  143. case 'shownotice':
  144. if (!$action->notice->isLocal()) {
  145. return true;
  146. }
  147. try {
  148. $url = $action->notice->getUrl();
  149. } catch (InvalidUrlException $e) {
  150. // The notice is probably a share or similar, which don't
  151. // have a representational URL of their own.
  152. return true;
  153. }
  154. break;
  155. }
  156. if (isset($url)) {
  157. foreach (['xml', 'json'] as $format) {
  158. $action->element(
  159. 'link',
  160. ['rel' =>'alternate',
  161. 'type' => "application/{$format}+oembed",
  162. 'href' => common_local_url(
  163. 'oembed',
  164. [],
  165. ['format' => $format, 'url' => $url]
  166. ),
  167. 'title' => 'oEmbed']
  168. );
  169. }
  170. }
  171. return true;
  172. }
  173. public function onEndShowStylesheets(Action $action)
  174. {
  175. $action->cssLink($this->path('css/embed.css'));
  176. return true;
  177. }
  178. /**
  179. * Save embedding information for a File, if applicable.
  180. *
  181. * Normally this event is called through File::saveNew()
  182. *
  183. * @param File $file The newly inserted File object.
  184. *
  185. * @return boolean success
  186. */
  187. public function onEndFileSaveNew(File $file)
  188. {
  189. $fe = File_embed::getKV('file_id', $file->getID());
  190. if ($fe instanceof File_embed) {
  191. common_log(LOG_WARNING, "Strangely, a File_embed object exists for new file {$file->getID()}", __FILE__);
  192. return true;
  193. }
  194. if (isset($file->mimetype)
  195. && (('text/html' === substr($file->mimetype, 0, 9) ||
  196. 'application/xhtml+xml' === substr($file->mimetype, 0, 21)))) {
  197. try {
  198. $embed_data = File_embed::getEmbed($file->url);
  199. if ($embed_data === false) {
  200. throw new Exception("Did not get Embed data from URL {$file->url}");
  201. }
  202. $file->setTitle($embed_data->title);
  203. } catch (Exception $e) {
  204. common_log(LOG_WARNING, sprintf(
  205. __METHOD__.': %s thrown when getting embed data: %s',
  206. get_class($e),
  207. _ve($e->getMessage())
  208. ));
  209. return true;
  210. }
  211. File_embed::saveNew($embed_data, $file->getID());
  212. }
  213. return true;
  214. }
  215. public function onEndShowAttachmentLink(HTMLOutputter $out, File $file)
  216. {
  217. $embed = File_embed::getKV('file_id', $file->getID());
  218. if (empty($embed->author_name) && empty($embed->provider)) {
  219. return true;
  220. }
  221. $out->elementStart('div', ['id'=>'oembed_info', 'class'=>'e-content']);
  222. foreach (['author_name' => ['class' => ' author', 'url' => 'author_url'],
  223. 'provider' => ['class' => '', 'url' => 'provider_url']]
  224. as $field => $options) {
  225. if (!empty($embed->{$field})) {
  226. $out->elementStart('div', "fn vcard" . $options['class']);
  227. if (empty($embed->{$options['url']})) {
  228. $out->text($embed->{$field});
  229. } else {
  230. $out->element(
  231. 'a',
  232. ['href' => $embed->{$options['url']},
  233. 'class' => 'url'],
  234. $embed->{$field}
  235. );
  236. }
  237. }
  238. }
  239. $out->elementEnd('div');
  240. }
  241. public function onFileEnclosureMetadata(File $file, &$enclosure)
  242. {
  243. // Never treat generic HTML links as an enclosure type!
  244. // But if we have embed info, we'll consider it golden.
  245. $embed = File_embed::getKV('file_id', $file->getID());
  246. if (!$embed instanceof File_embed || !in_array($embed->type, ['photo', 'video'])) {
  247. return true;
  248. }
  249. foreach (['mimetype', 'url', 'title', 'modified', 'width', 'height'] as $key) {
  250. if (isset($embed->{$key}) && !empty($embed->{$key})) {
  251. $enclosure->{$key} = $embed->{$key};
  252. }
  253. }
  254. return true;
  255. }
  256. public function onStartShowAttachmentRepresentation(HTMLOutputter $out, File $file)
  257. {
  258. try {
  259. $embed = File_embed::getByFile($file);
  260. } catch (NoResultException $e) {
  261. return true;
  262. }
  263. // Show thumbnail as usual if it's a photo.
  264. if ($embed->type === 'photo') {
  265. return true;
  266. }
  267. $out->elementStart('article', ['class'=>'h-entry embed']);
  268. $out->elementStart('header');
  269. try {
  270. $thumb = $file->getThumbnail($this->thumbnail_width, $this->thumbnail_height);
  271. $out->element('img', $thumb->getHtmlAttrs(['class'=>'u-photo embed']));
  272. unset($thumb);
  273. } catch (FileNotFoundException $e) {
  274. // Nothing to show
  275. } catch (Exception $e) {
  276. $out->element('div', ['class'=>'error'], $e->getMessage());
  277. }
  278. $out->elementStart('h5', ['class'=>'p-name embed']);
  279. $out->element('a', ['class'=>'u-url', 'href'=>$file->getUrl()], common_strip_html($embed->title));
  280. $out->elementEnd('h5');
  281. $out->elementStart('div', ['class'=>'p-author embed']);
  282. if (!empty($embed->author_name)) {
  283. // TRANS: text before the author name of embed attachment representation
  284. // FIXME: The whole "By x from y" should be i18n because of different language constructions.
  285. $out->text(_('By '));
  286. $attrs = ['class'=>'h-card p-author'];
  287. if (!empty($embed->author_url)) {
  288. $attrs['href'] = $embed->author_url;
  289. $tag = 'a';
  290. } else {
  291. $tag = 'span';
  292. }
  293. $out->element($tag, $attrs, $embed->author_name);
  294. }
  295. if (!empty($embed->provider)) {
  296. // TRANS: text between the embed author name and provider url
  297. // FIXME: The whole "By x from y" should be i18n because of different language constructions.
  298. $out->text(_(' from '));
  299. $attrs = ['class'=>'h-card'];
  300. if (!empty($embed->provider_url)) {
  301. $attrs['href'] = $embed->provider_url;
  302. $tag = 'a';
  303. } else {
  304. $tag = 'span';
  305. }
  306. $out->element($tag, $attrs, $embed->provider);
  307. }
  308. $out->elementEnd('div');
  309. $out->elementEnd('header');
  310. $out->elementStart('div', ['class'=>'p-summary embed']);
  311. $out->raw(common_purify($embed->html));
  312. $out->elementEnd('div');
  313. $out->elementStart('footer');
  314. $out->elementEnd('footer');
  315. $out->elementEnd('article');
  316. return false;
  317. }
  318. public function onShowUnsupportedAttachmentRepresentation(HTMLOutputter $out, File $file)
  319. {
  320. try {
  321. $embed = File_embed::getByFile($file);
  322. } catch (NoResultException $e) {
  323. return true;
  324. }
  325. // the 'photo' type is shown through ordinary means, using StartShowAttachmentRepresentation!
  326. switch ($embed->type) {
  327. case 'video':
  328. case 'link':
  329. if (!empty($embed->html)
  330. && (GNUsocial::isAjax() || common_config('attachments', 'show_html'))) {
  331. require_once INSTALLDIR.'/extlib/HTMLPurifier/HTMLPurifier.auto.php';
  332. $purifier = new HTMLPurifier();
  333. // FIXME: do we allow <object> and <embed> here? we did that when we used htmLawed,
  334. // but I'm not sure anymore...
  335. $out->raw($purifier->purify($embed->html));
  336. }
  337. return false;
  338. }
  339. return true;
  340. }
  341. /**
  342. * This event executes when GNU social is creating a file thumbnail entry in
  343. * the database. We glom onto this to create proper information for Embed
  344. * object thumbnails.
  345. *
  346. * @param $file File the file of the created thumbnail
  347. * @param &$imgPath string = the path to the created thumbnail
  348. * @return bool true if it succeeds (including non-action
  349. * states where it isn't oEmbed data, so it doesn't mess up the event handle
  350. * for other things hooked into it), or the exception if it fails.
  351. */
  352. public function onCreateFileImageThumbnailSource(File $file, &$imgPath, $media)
  353. {
  354. // If we are on a private node, we won't do any remote calls (just as a precaution until
  355. // we can configure this from config.php for the private nodes)
  356. if (common_config('site', 'private')) {
  357. return true;
  358. }
  359. // All our remote Embed images lack a local filename property in the File object
  360. if (!is_null($file->filename)) {
  361. common_debug(sprintf('Filename of file id==%d is not null (%s), so nothing Embed '.
  362. 'should handle.', $file->getID(), _ve($file->filename)));
  363. return true;
  364. }
  365. try {
  366. // If we have proper Embed data, there should be an entry in the File_thumbnail table.
  367. // If not, we're not going to do anything.
  368. $thumbnail = File_thumbnail::byFile($file);
  369. } catch (NoResultException $e) {
  370. // Not Embed data, or at least nothing we either can or want to use.
  371. common_debug('No Embed data found for file id=='.$file->getID());
  372. return true;
  373. }
  374. try {
  375. $this->storeRemoteFileThumbnail($thumbnail);
  376. } catch (AlreadyFulfilledException $e) {
  377. // aw yiss!
  378. } catch (Exception $e) {
  379. common_debug(sprintf(
  380. 'Embed encountered an exception (%s) for file id==%d: %s',
  381. get_class($e),
  382. $file->getID(),
  383. _ve($e->getMessage())
  384. ));
  385. throw $e;
  386. }
  387. // Out
  388. $imgPath = $thumbnail->getPath();
  389. return !file_exists($imgPath);
  390. }
  391. /**
  392. * @return bool false on no check made, provider name on success
  393. * @throws ServerException if check is made but fails
  394. */
  395. protected function checkWhitelist($url)
  396. {
  397. if (!$this->check_whitelist) {
  398. return false; // indicates "no check made"
  399. }
  400. $host = parse_url($url, PHP_URL_HOST);
  401. foreach ($this->domain_whitelist as $regex => $provider) {
  402. if (preg_match("/$regex/", $host)) {
  403. return $provider; // we trust this source, return provider name
  404. }
  405. }
  406. throw new ServerException(sprintf(_('Domain not in remote thumbnail source whitelist: %s'), $host));
  407. }
  408. /**
  409. * Check the file size of a remote file using a HEAD request and checking
  410. * the content-length variable returned. This isn't 100% foolproof but is
  411. * reliable enough for our purposes.
  412. *
  413. * @return string|bool the file size if it succeeds, false otherwise.
  414. */
  415. private function getRemoteFileSize($url, $headers = null)
  416. {
  417. try {
  418. if ($headers === null) {
  419. if (!common_valid_http_url($url)) {
  420. common_log(LOG_ERR, "Invalid URL in Embed::getRemoteFileSize()");
  421. return false;
  422. }
  423. $head = (new HTTPClient())->head($url);
  424. $headers = $head->getHeader();
  425. $headers = array_change_key_case($headers, CASE_LOWER);
  426. }
  427. return isset($headers['content-length']) ? $headers['content-length'] : false;
  428. } catch (Exception $err) {
  429. common_log(LOG_ERR, __CLASS__.': getRemoteFileSize on URL : '._ve($url).
  430. ' threw exception: '.$err->getMessage());
  431. return false;
  432. }
  433. }
  434. /**
  435. * A private helper function that uses a CURL lookup to check the mime type
  436. * of a remote URL to see it it's an image.
  437. *
  438. * @return bool true if the remote URL is an image, or false otherwise.
  439. */
  440. private function isRemoteImage($url, $headers = null)
  441. {
  442. if (empty($headers)) {
  443. if (!common_valid_http_url($url)) {
  444. common_log(LOG_ERR, "Invalid URL in Embed::isRemoteImage()");
  445. return false;
  446. }
  447. $head = (new HTTPClient())->head($url);
  448. $headers = $head->getHeader();
  449. $headers = array_change_key_case($headers, CASE_LOWER);
  450. }
  451. return !empty($headers['content-type']) && common_get_mime_media($headers['content-type']) === 'image';
  452. }
  453. /**
  454. * Function to create and store a thumbnail representation of a remote image
  455. *
  456. * @param $thumbnail File_thumbnail object containing the file thumbnail
  457. * @return bool true if it succeeded, the exception if it fails, or false if it
  458. * is limited by system limits (ie the file is too large.)
  459. */
  460. protected function storeRemoteFileThumbnail(File_thumbnail $thumbnail)
  461. {
  462. if (!empty($thumbnail->filename) && file_exists($thumbnail->getPath())) {
  463. throw new AlreadyFulfilledException(
  464. sprintf('A thumbnail seems to already exist for remote file with id==%u', $thumbnail->file_id)
  465. );
  466. }
  467. $url = $thumbnail->getUrl();
  468. $this->checkWhitelist($url);
  469. $head = (new HTTPClient())->head($url);
  470. $headers = $head->getHeader();
  471. $headers = array_change_key_case($headers, CASE_LOWER);
  472. try {
  473. $isImage = $this->isRemoteImage($url, $headers);
  474. if ($isImage==true) {
  475. $max_size = common_get_preferred_php_upload_limit();
  476. $file_size = $this->getRemoteFileSize($url, $headers);
  477. if (($file_size!=false) && ($file_size > $max_size)) {
  478. common_debug("Went to store remote thumbnail of size " . $file_size .
  479. " but the upload limit is " . $max_size . " so we aborted.");
  480. return false;
  481. }
  482. }
  483. } catch (Exception $err) {
  484. common_debug("Could not determine size of remote image, aborted local storage.");
  485. return $err;
  486. }
  487. // First we download the file to memory and test whether it's actually an image file
  488. // FIXME: To support remote video/whatever files, this needs reworking.
  489. common_debug(sprintf(
  490. 'Downloading remote thumbnail for file id==%u with thumbnail URL: %s',
  491. $thumbnail->file_id,
  492. $url
  493. ));
  494. $imgData = HTTPClient::quickGet($url);
  495. $info = @getimagesizefromstring($imgData);
  496. // array indexes documented on php.net:
  497. // https://php.net/manual/en/function.getimagesize.php
  498. if ($info === false) {
  499. throw new UnsupportedMediaException(_('Remote file format was not identified as an image.'), $url);
  500. } elseif (!$info[0] || !$info[1]) {
  501. throw new UnsupportedMediaException(_('Image file had impossible geometry (0 width or height)'));
  502. }
  503. $filehash = hash(File::FILEHASH_ALG, $imgData);
  504. $width = min($info[0], $this->thumbnail_width);
  505. $height = min($info[1], $this->thumbnail_height);
  506. try {
  507. $original_name = HTTPClient::get_filename($url, $headers);
  508. $filename = MediaFile::encodeFilename($original_name, $filehash);
  509. $fullpath = File_thumbnail::path($filename);
  510. // Write the file to disk. Throw Exception on failure
  511. if (!file_exists($fullpath)) {
  512. if (strpos($fullpath, INSTALLDIR) !== 0 || file_put_contents($fullpath, $imgData) === false) {
  513. throw new ServerException(_('Could not write downloaded file to disk.'));
  514. }
  515. if (common_get_mime_media(MediaFile::getUploadedMimeType($fullpath)) !== 'image') {
  516. @unlink($fullpath);
  517. throw new UnsupportedMediaException(
  518. _('Remote file format was not identified as an image.'),
  519. $url
  520. );
  521. }
  522. // If the image is not of the desired size, resize it
  523. if ($info[0] !== $this->thumbnail_width || $info[1] !== $this->thumbnail_height) {
  524. // Temporary object, not stored in DB
  525. $img = new ImageFile(-1, $fullpath);
  526. $box = $img->scaleToFit($width, $height, $this->thumbnail_crop);
  527. $outpath = $img->resizeTo($fullpath, $box);
  528. $filename = basename($outpath);
  529. if ($fullpath !== $outpath) {
  530. @unlink($fullpath);
  531. }
  532. }
  533. } else {
  534. throw new AlreadyFulfilledException('A thumbnail seems to already exist for remote file with id==' .
  535. $thumbnail->file_id . ' at path ' . $fullpath);
  536. }
  537. } catch (AlreadyFulfilledException $e) {
  538. // Carry on
  539. } catch (Exception $err) {
  540. common_log(LOG_ERR, "Went to write a thumbnail to disk in EmbedModule::storeRemoteThumbnail " .
  541. "but encountered error: {$err}");
  542. return $err;
  543. } finally {
  544. unset($imgData);
  545. }
  546. try {
  547. // Update our database for the file record
  548. $orig = clone($thumbnail);
  549. $thumbnail->filename = $filename;
  550. $thumbnail->width = $width;
  551. $thumbnail->height = $height;
  552. // Throws exception on failure.
  553. $thumbnail->updateWithKeys($orig);
  554. } catch (Exception $err) {
  555. common_log(LOG_ERR, "Went to write a thumbnail entry to the database in " .
  556. "EmbedModule::storeRemoteThumbnail but encountered error: ".$err);
  557. return $err;
  558. }
  559. return true;
  560. }
  561. /**
  562. * Event raised when GNU social polls the plugin for information about it.
  563. * Adds this plugin's version information to $versions array
  564. *
  565. * @param &$versions array inherited from parent
  566. * @return bool true hook value
  567. */
  568. public function onModuleVersion(array &$versions)
  569. {
  570. $versions[] = ['name' => 'Embed',
  571. 'version' => self::MODULE_VERSION,
  572. 'author' => 'Mikael Nordfeldth',
  573. 'homepage' => 'http://gnu.io/social/',
  574. 'description' =>
  575. // TRANS: Module description.
  576. _m('Module for using and representing oEmbed, OpenGraph and other data.')];
  577. return true;
  578. }
  579. }