index.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>Twitter2rss</title>
  6. <link rel="stylesheet" type="text/css" href="twitter2rss.css" />
  7. </head>
  8. <body>
  9. <?php
  10. define("FEED_LIST", "twitter_users");
  11. $user = "";
  12. $userErr = "";
  13. header('Content-Type: text/html; charset=utf-8');
  14. $locale='en_EN.UTF-8';
  15. setlocale(LC_ALL,$locale);
  16. putenv('LC_ALL='.$locale);
  17. function invalid_characters($string) {
  18. if (!preg_match("/^[a-zA-Z0-9_]*$/",$string)) {
  19. return true;
  20. }
  21. else {
  22. return false;
  23. }
  24. }
  25. function user_exist($string) {
  26. $fh = fopen(FEED_LIST, 'r') or die("I couldn't read the file.");
  27. $res = false;
  28. while (!feof($fh) && !$res) {
  29. $line = fgets($fh, 4096);
  30. if ( strcasecmp($string . "\n" , $line) == 0 ) {
  31. $res = true;
  32. }
  33. }
  34. fclose($fh);
  35. return $res;
  36. }
  37. function on_twitter($string) {
  38. $tURL = "https://twitter.com/" . $string;
  39. $headers = get_headers($tURL);
  40. if ( intval(substr($headers[0], 9, 3)) < 400 ) {
  41. return true;
  42. } else {
  43. return false;
  44. }
  45. }
  46. if ($_SERVER["REQUEST_METHOD"] == "POST") {
  47. if (empty($_POST["user"])) {
  48. $userErr = "It's necessary to add a user.";
  49. } elseif (invalid_characters($_POST["user"])) {
  50. $userErr = "Invalid characters.";
  51. } elseif (user_exist($_POST["user"])) {
  52. $userErr = "The user was added before.\nYou can find it <a href='http://$_SERVER[HTTP_HOST]/feeds/$_POST[user].xml'>here</a>";
  53. } elseif (!on_twitter($_POST["user"])) {
  54. $userErr = "The user doesn't exist on Twitter.";
  55. } else {
  56. $fh = fopen(FEED_LIST, 'a') or die("I couldn't write in the file.");
  57. $stringData = $_POST["user"] . "\n";
  58. fwrite($fh, $stringData);
  59. fclose($fh);
  60. $user = $_POST["user"];
  61. exec("python3 twitter2rss.py ".escapeshellarg($user));
  62. }
  63. }
  64. ?>
  65. <div class="content">
  66. <form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
  67. <h1>twitter2rss<span>Add Twitter users and receive it\'s feed</span></h2>
  68. <p>
  69. <label>
  70. <span>User:</span>
  71. <input type="text" name="user" value="<?php echo $user;?>">
  72. </label>
  73. <label>
  74. <span>&nbsp;</span>
  75. <input class="button" type="submit" name="submit" value="Añadir">
  76. </label></p>
  77. </form>
  78. <?php if (!empty($userErr)): ?>
  79. <span class="error"><?php echo $userErr;?></span>
  80. <?php endif; ?>
  81. <?php if (!empty($user)): ?>
  82. <span class="success">User <?php echo $user;?> added.<br />
  83. <?php echo "<a href='http://$_SERVER[HTTP_HOST]/feeds/$_POST[user].xml'>Here</a>"; ?></span>
  84. <?php endif; ?>
  85. <br>
  86. <div>
  87. <!-- If twitter2rss is in a folder, you should add that folder behind http://$_SERVER[HTTP_HOST]/ -->
  88. <div margin="10px" float="left"><?php echo "<a href='feeds'>Existing feeds</a>" ?></div>
  89. <div text-align="center" float="center"><?php echo "<a href='http://daemons.cf/cgit/twitter2rss/about/'>About</a>"?></div>
  90. <div text-align="right" float="right"><?php echo "<a href='http://daemons.cf/cgit/twitter2rss'>Git Repository</a>" ?></div>
  91. </div>
  92. </div>
  93. </body>
  94. </html>