index.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. <?php
  2. /*
  3. TODO :
  4. - manage SSL detection because if library isn't loaded, some bridge crash !
  5. - factorize the annotation system
  6. - factorize to adapter : Format, Bridge, Cache (actually code is almost the same)
  7. - implement annotation cache for entrance page
  8. - Cache : I think logic must be change as least to avoid to reconvert object from json in FileCache case.
  9. - add namespace to avoid futur problem ?
  10. - see FIXME mentions in the code
  11. - implement header('X-Cached-Version: '.date(DATE_ATOM, filemtime($cachefile)));
  12. */
  13. date_default_timezone_set('UTC');
  14. error_reporting(0);
  15. //ini_set('display_errors','1'); error_reporting(E_ALL); // For debugging only.
  16. // FIXME : beta test UA spoofing, please report any blacklisting by PHP-fopen-unfriendly websites
  17. ini_set('user_agent', 'Mozilla/5.0 (X11; Linux x86_64; rv:30.0) Gecko/20121202 Firefox/30.0 (rss-bridge/0.1; +https://github.com/sebsauvage/rss-bridge)');
  18. // -------
  19. try{
  20. require_once __DIR__ . '/lib/RssBridge.php';
  21. Bridge::setDir(__DIR__ . '/bridges/');
  22. Format::setDir(__DIR__ . '/formats/');
  23. Cache::setDir(__DIR__ . '/caches/');
  24. if( isset($_REQUEST) && isset($_REQUEST['action']) ){
  25. switch($_REQUEST['action']){
  26. case 'display':
  27. if( isset($_REQUEST['bridge']) ){
  28. unset($_REQUEST['action']);
  29. $bridge = $_REQUEST['bridge'];
  30. unset($_REQUEST['bridge']);
  31. $format = $_REQUEST['format'];
  32. unset($_REQUEST['format']);
  33. $cache = Cache::create('FileCache');
  34. // Data retrieval
  35. $bridge = Bridge::create($bridge);
  36. $bridge
  37. ->setCache($cache) // Comment this lign for avoid cache use
  38. ->setDatas($_REQUEST);
  39. // Data transformation
  40. $format = Format::create($format);
  41. $format
  42. ->setDatas($bridge->getDatas())
  43. ->setExtraInfos(array(
  44. 'name' => $bridge->getName(),
  45. 'uri' => $bridge->getURI(),
  46. ))
  47. ->display();
  48. die;
  49. }
  50. break;
  51. }
  52. }
  53. }
  54. catch(HttpException $e){
  55. header('HTTP/1.1 ' . $e->getCode() . ' ' . Http::getMessageForCode($e->getCode()));
  56. header('Content-Type: text/plain');
  57. die($e->getMessage());
  58. }
  59. catch(\Exception $e){
  60. die($e->getMessage());
  61. }
  62. function getHelperButtonFormat($value, $name){
  63. return '<button type="submit" name="format" value="' . $value . '">' . $name . '</button>';
  64. }
  65. $bridges = Bridge::searchInformation();
  66. $formats = Format::searchInformation();
  67. ?>
  68. <!DOCTYPE html>
  69. <html lang="en">
  70. <head>
  71. <meta charset="utf-8">
  72. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  73. <meta name="description" content="Rss-bridge" />
  74. <title>RSS-Bridge</title>
  75. <link href="css/style.css" rel="stylesheet">
  76. <!--[if IE]>
  77. <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
  78. <![endif]-->
  79. </head>
  80. <body>
  81. <header>
  82. <h1>RSS-Bridge</h1>
  83. </header>
  84. <?php foreach($bridges as $bridgeReference => $bridgeInformations): ?>
  85. <section id="bridge-<?php echo $bridgeReference ?>" data-ref="<?php echo $bridgeReference ?>">
  86. <h2><?php echo $bridgeInformations['name'] ?></h2>
  87. <p class="description">
  88. <?php echo isset($bridgeInformations['description']) ? $bridgeInformations['description'] : 'No description provided' ?>
  89. </p>
  90. <?php if( isset($bridgeInformations['use']) && count($bridgeInformations['use']) > 0 ): ?>
  91. <ol class="list-use">
  92. <?php foreach($bridgeInformations['use'] as $anUseNum => $anUse): ?>
  93. <li data-use="<?php echo $anUseNum ?>">
  94. <form method="GET" action="?">
  95. <input type="hidden" name="action" value="display" />
  96. <input type="hidden" name="bridge" value="<?php echo $bridgeReference ?>" />
  97. <?php foreach($anUse as $argName => $argDescription): ?>
  98. <?php
  99. $idArg = 'arg-' . $bridgeReference . '-' . $anUseNum . '-' . $argName;
  100. ?>
  101. <input id="<?php echo $idArg ?>" type="text" value="" placeholder="<?php echo $argDescription; ?>" name="<?php echo $argName ?>" />
  102. <?php endforeach; ?>
  103. <?php foreach( $formats as $name => $infos ): ?>
  104. <?php if( isset($infos['name']) ){ echo getHelperButtonFormat($name, $infos['name']); } ?>
  105. <?php endforeach; ?>
  106. </form>
  107. </li>
  108. <?php endforeach; ?>
  109. </ol>
  110. <?php else: ?>
  111. <form method="GET" action="?">
  112. <input type="hidden" name="action" value="display" />
  113. <input type="hidden" name="bridge" value="<?php echo $bridgeReference ?>" />
  114. <?php foreach( $formats as $name => $infos ): ?>
  115. <?php if( isset($infos['name']) ){ echo getHelperButtonFormat($name, $infos['name']); } ?>
  116. <?php endforeach; ?>
  117. </form>
  118. <?php endif; ?>
  119. <?php echo isset($bridgeInformations['maintainer']) ? '<span class="maintainer">'.$bridgeInformations['maintainer'].'</span>' : '' ?>
  120. </section>
  121. <?php endforeach; ?>
  122. <footer>
  123. <a href="https://github.com/sebsauvage/rss-bridge">RSS-Bridge</a> alpha 0.1
  124. </footer>
  125. </body>
  126. </html>