isso.php 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. /**
  3. * Plugin Isso.
  4. */
  5. use Shaarli\Config\ConfigManager;
  6. /**
  7. * Display an error everywhere if the plugin is enabled without configuration.
  8. *
  9. * @param $conf ConfigManager instance
  10. *
  11. * @return mixed - linklist data with Isso plugin.
  12. */
  13. function isso_init($conf)
  14. {
  15. $issoUrl = $conf->get('plugins.ISSO_SERVER');
  16. if (empty($issoUrl)) {
  17. $error = t('Isso plugin error: '.
  18. 'Please define the "ISSO_SERVER" setting in the plugin administration page.');
  19. return array($error);
  20. }
  21. }
  22. /**
  23. * Render linklist hook.
  24. * Will only display Isso comments on permalinks.
  25. *
  26. * @param $data array List of links
  27. * @param $conf ConfigManager instance
  28. *
  29. * @return mixed - linklist data with Isso plugin.
  30. */
  31. function hook_isso_render_linklist($data, $conf)
  32. {
  33. $issoUrl = $conf->get('plugins.ISSO_SERVER');
  34. if (empty($issoUrl)) {
  35. return $data;
  36. }
  37. // Only display comments for permalinks.
  38. if (count($data['links']) == 1 && empty($data['search_tags']) && empty($data['search_term'])) {
  39. $link = reset($data['links']);
  40. $issoHtml = file_get_contents(PluginManager::$PLUGINS_PATH . '/isso/isso.html');
  41. $isso = sprintf($issoHtml, $issoUrl, $issoUrl, $link['id'], $link['id']);
  42. $data['plugin_end_zone'][] = $isso;
  43. } else {
  44. $button = '<span><a href="?%s#isso-thread">';
  45. // For the default theme we use a FontAwesome icon which is better than an image
  46. if ($conf->get('resource.theme') === 'default') {
  47. $button .= '<i class="linklist-plugin-icon fa fa-comment"></i>';
  48. } else {
  49. $button .= '<img class="linklist-plugin-icon" src="plugins/isso/comment.png" ';
  50. $button .= 'title="Comment on this shaare" alt="Comments" />';
  51. }
  52. $button .= '</a></span>';
  53. foreach ($data['links'] as &$value) {
  54. $commentLink = sprintf($button, $value['shorturl']);
  55. $value['link_plugin'][] = $commentLink;
  56. }
  57. }
  58. return $data;
  59. }
  60. /**
  61. * When linklist is displayed, include isso CSS file.
  62. *
  63. * @param array $data - header data.
  64. *
  65. * @return mixed - header data with isso CSS file added.
  66. */
  67. function hook_isso_render_includes($data)
  68. {
  69. if ($data['_PAGE_'] == Router::$PAGE_LINKLIST) {
  70. $data['css_files'][] = PluginManager::$PLUGINS_PATH . '/isso/isso.css';
  71. }
  72. return $data;
  73. }
  74. /**
  75. * This function is never called, but contains translation calls for GNU gettext extraction.
  76. */
  77. function isso_dummy_translation()
  78. {
  79. // meta
  80. t('Let visitor comment your shaares on permalinks with Isso.');
  81. t('Isso server URL (without \'http://\')');
  82. }