LinkPreviewPlugin.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. function onPluginVersion(array &$versions)
  31. {
  32. $versions[] = array('name' => 'LinkPreview',
  33. 'version' => GNUSOCIAL_VERSION,
  34. 'author' => 'Brion Vibber',
  35. 'homepage' => 'https://git.gnu.io/gnu/gnu-social/tree/master/plugins/LinkPreview',
  36. 'rawdescription' =>
  37. // TRANS: Plugin description.
  38. _m('UI extension for previewing thumbnails from links.'));
  39. return true;
  40. }
  41. /**
  42. * Load JS at runtime if we're logged in.
  43. *
  44. * @param Action $action
  45. * @return boolean hook result
  46. */
  47. function onEndShowScripts($action)
  48. {
  49. $user = common_current_user();
  50. if ($user && common_config('attachments', 'process_links')) {
  51. $action->script($this->path('js/linkpreview.js'));
  52. $data = json_encode(array(
  53. 'api' => common_local_url('oembedproxy'),
  54. 'width' => common_config('attachments', 'thumbwidth'),
  55. 'height' => common_config('attachments', 'thumbheight'),
  56. ));
  57. $action->inlineScript('$(function() {SN.Init.LinkPreview && SN.Init.LinkPreview('.$data.');})');
  58. }
  59. return true;
  60. }
  61. /**
  62. * Hook for RouterInitialized event.
  63. *
  64. * @param URLMapper $m URL mapper
  65. *
  66. * @return boolean hook return
  67. */
  68. public function onStartInitializeRouter(URLMapper $m)
  69. {
  70. $m->connect('main/oembed/proxy',
  71. array('action' => 'oembedproxy'));
  72. return true;
  73. }
  74. }