init.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. class MailTo extends Plugin {
  3. private $host;
  4. function about() {
  5. return array(1.0,
  6. "Share article via email (using mailto: links, invoking your mail client)",
  7. "fox");
  8. }
  9. function init($host) {
  10. $this->host = $host;
  11. $host->add_hook($host::HOOK_ARTICLE_BUTTON, $this);
  12. }
  13. function get_js() {
  14. return file_get_contents(dirname(__FILE__) . "/init.js");
  15. }
  16. function hook_article_button($line) {
  17. return "<img src=\"plugins/mailto/mail.png\"
  18. class='tagsPic' style=\"cursor : pointer\"
  19. onclick=\"mailtoArticle(".$line["id"].")\"
  20. alt='Zoom' title='".__('Forward by email')."'>";
  21. }
  22. function emailArticle() {
  23. $ids = explode(",", $_REQUEST['param']);
  24. $ids_qmarks = arr_qmarks($ids);
  25. require_once "lib/MiniTemplator.class.php";
  26. $tpl = new MiniTemplator;
  27. $tpl->readTemplateFromFile("templates/email_article_template.txt");
  28. $tpl->setVariable('USER_NAME', $_SESSION["name"], true);
  29. //$tpl->setVariable('USER_EMAIL', $user_email, true);
  30. $tpl->setVariable('TTRSS_HOST', $_SERVER["HTTP_HOST"], true);
  31. $sth = $this->pdo->prepare("SELECT DISTINCT link, content, title
  32. FROM ttrss_user_entries, ttrss_entries WHERE id = ref_id AND
  33. id IN ($ids_qmarks) AND owner_uid = ?");
  34. $sth->execute(array_merge($ids, [$_SESSION['uid']]));
  35. if (count($ids) > 1) {
  36. $subject = __("[Forwarded]") . " " . __("Multiple articles");
  37. } else {
  38. $subject = "";
  39. }
  40. while ($line = $sth->fetch()) {
  41. if (!$subject)
  42. $subject = __("[Forwarded]") . " " . htmlspecialchars($line["title"]);
  43. $tpl->setVariable('ARTICLE_TITLE', strip_tags($line["title"]));
  44. $tpl->setVariable('ARTICLE_URL', strip_tags($line["link"]));
  45. $tpl->addBlock('article');
  46. }
  47. $tpl->addBlock('email');
  48. $content = "";
  49. $tpl->generateOutputToString($content);
  50. $mailto_link = htmlspecialchars("mailto:?subject=".rawurlencode($subject).
  51. "&body=".rawurlencode($content));
  52. print __("Clicking the following link to invoke your mail client:");
  53. print "<div class=\"tagCloudContainer\">";
  54. print "<a target=\"_blank\" href=\"$mailto_link\">".
  55. __("Forward selected article(s) by email.")."</a>";
  56. print "</div>";
  57. print __("You should be able to edit the message before sending in your mail client.");
  58. print "<p>";
  59. print "<div style='text-align : center'>";
  60. print "<button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('emailArticleDlg').hide()\">".__('Close this dialog')."</button>";
  61. print "</div>";
  62. //return;
  63. }
  64. function api_version() {
  65. return 2;
  66. }
  67. }