LinkPreviewPlugin.php 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. /*
  3. * StatusNet - the distributed open-source microblogging tool
  4. * Copyright (C) 2010, StatusNet, Inc.
  5. *
  6. * This program is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU Affero General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU Affero General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Affero General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. if (!defined('STATUSNET')) {
  20. exit(1);
  21. }
  22. /**
  23. * Some UI extras for now...
  24. *
  25. * @package LinkPreviewPlugin
  26. * @maintainer Brion Vibber <brion@status.net>
  27. */
  28. class LinkPreviewPlugin extends Plugin
  29. {
  30. const PLUGIN_VERSION = '2.0.0';
  31. public function onPluginVersion(array &$versions): bool
  32. {
  33. $versions[] = array('name' => 'LinkPreview',
  34. 'version' => self::PLUGIN_VERSION,
  35. 'author' => 'Brion Vibber',
  36. 'homepage' => GNUSOCIAL_ENGINE_REPO_URL . 'tree/master/plugins/LinkPreview',
  37. 'rawdescription' =>
  38. // TRANS: Plugin description.
  39. _m('UI extension for previewing thumbnails from links.'));
  40. return true;
  41. }
  42. /**
  43. * Load JS at runtime if we're logged in.
  44. *
  45. * @param Action $action
  46. * @return boolean hook result
  47. */
  48. function onEndShowScripts($action)
  49. {
  50. $user = common_current_user();
  51. if ($user && common_config('attachments', 'process_links')) {
  52. $action->script($this->path('js/linkpreview.js'));
  53. $data = json_encode(array(
  54. 'api' => common_local_url('oembedproxy'),
  55. 'width' => common_config('attachments', 'thumbwidth'),
  56. 'height' => common_config('attachments', 'thumbheight'),
  57. ));
  58. $action->inlineScript('$(function() {SN.Init.LinkPreview && SN.Init.LinkPreview('.$data.');})');
  59. }
  60. return true;
  61. }
  62. /**
  63. * Hook for RouterInitialized event.
  64. *
  65. * @param URLMapper $m URL mapper
  66. *
  67. * @return boolean hook return
  68. */
  69. public function onStartInitializeRouter(URLMapper $m)
  70. {
  71. $m->connect('main/oembed/proxy',
  72. array('action' => 'oembedproxy'));
  73. return true;
  74. }
  75. }