Source files of fsfe.org, pdfreaders.org, freeyourandroid.org, ilovefs.org, drm.info, and test.fsfe.org. Contribute: https://fsfe.org/contribute/web/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

share.php 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <?php
  2. /*
  3. * share-buttons: Share buttons for many social networks and services
  4. * Copyright (C) 2018 Max Mehl <max.mehl@fsfe.org>, Paul Hänsch <paul@fsfe.org>
  5. *
  6. * This program is free software: you can redistribute it and/or modify it under
  7. * the terms of the GNU Affero General Public License as published by the Free
  8. * Software Foundation, either version 3 of the License, or (at your option) any
  9. * later version.
  10. *
  11. * This program is distributed in the hope that it will be useful, but WITHOUT
  12. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  13. * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
  14. * details <http://www.gnu.org/licenses/>.
  15. */
  16. // Change these variables
  17. $gnusocialuser = "@fsfe@quitter.no";
  18. $mastodonuser = "@fsfe@mastodon.social";
  19. $twitteruser = "fsfe";
  20. $flattruser = "fsfe";
  21. $supporturl = "https://fsfe.org/donate?share";
  22. // Don't change below here
  23. $service = isset($_GET['service']) ? $_GET['service'] : false;
  24. $url = isset($_GET['url']) ? $_GET['url'] : false;
  25. $title = isset($_GET['title']) ? $_GET['title'] : false;
  26. $ref = isset($_GET['ref']) ? $_GET['ref'] : false;
  27. $diasporapod = isset($_GET['diasporapod']) ? $_GET['diasporapod'] : false;
  28. $gnusocialpod = isset($_GET['gnusocialpod']) ? $_GET['gnusocialpod'] : false;
  29. $mastodonpod = isset($_GET['mastodonpod']) ? $_GET['mastodonpod'] : false;
  30. if(empty($service) || empty($url)) {
  31. echo 'At least one required variable is empty. You have to define at least service and url';
  32. } else {
  33. $service = htmlspecialchars($service);
  34. $diasporapod = htmlspecialchars($diasporapod);
  35. $gnusocialpod = htmlspecialchars($gnusocialpod);
  36. $mastodonpod = htmlspecialchars($mastodonpod);
  37. $url = urlencode($url);
  38. $title = urlencode($title);
  39. /* Special referrers for FSFE campaigns */
  40. if($ref == "pmpc-side" || $ref == "pmpc-spread") {
  41. $via_gs = "";
  42. $via_ma = "";
  43. $via_tw = "";
  44. $supporturl = "https://fsfe.org/donate?pmpc";
  45. } else {
  46. $via_gs = " via " . $gnusocialuser;
  47. $via_ma = " via " . $mastodonuser;
  48. $via_tw = "&via=" . $twitteruser;
  49. }
  50. if ($service === "diaspora") {
  51. $diasporapod = validateurl($diasporapod);
  52. header("Location: " . $diasporapod . "/bookmarklet?url=" . $url . "&title=" . $title);
  53. die();
  54. } elseif($service === "gnusocial") {
  55. $gnusocialpod = validateurl($gnusocialpod);
  56. header("Location: " . $gnusocialpod . "/notice/new?status_textarea=" . $title . " " . $url . $via_gs);
  57. die();
  58. } elseif($service === "mastodon") {
  59. $mastodonpod = validateurl($mastodonpod);
  60. header("Location: " . $mastodonpod . "/share?text=" . $title . " " . $url . $via_ma);
  61. die();
  62. } elseif($service === "reddit") {
  63. header("Location: https://reddit.com/submit?url=" . $url . "&title=" . $title);
  64. die();
  65. } elseif($service === "flattr") {
  66. header("Location: https://flattr.com/submit/auto?user_id=" . $flattruser . "&url=" . $url . "&title=" . $title);
  67. die();
  68. } elseif($service === "hnews") {
  69. header("Location: https://news.ycombinator.com/submitlink?u=" . $url . "&t=" . $title);
  70. die();
  71. } elseif($service === "twitter") {
  72. header("Location: https://twitter.com/share?url=" . $url . "&text=" . $title . $via_tw);
  73. die();
  74. } elseif($service === "facebook") {
  75. header("Location: https://www.facebook.com/sharer/sharer.php?u=" . $url);
  76. die();
  77. } elseif($service === "gplus") {
  78. header("Location: https://plus.google.com/share?url=" . $url);
  79. die();
  80. } elseif($service === "support") {
  81. header("Location: " . $supporturl);
  82. die();
  83. } else {
  84. echo 'Social network unknown.';
  85. }
  86. }
  87. // If diaspora/GS/Mastodon pod has been typed without http(s):// prefix, add it
  88. function validateurl($url) {
  89. if (preg_match('#^https?://#i', $url) === 0) {
  90. return 'https://' . $url;
  91. } else {
  92. return $url;
  93. }
  94. }
  95. ?>