index.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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. try{
  17. require_once __DIR__ . '/lib/RssBridge.php';
  18. Bridge::setDir(__DIR__ . '/bridges/');
  19. Format::setDir(__DIR__ . '/formats/');
  20. Cache::setDir(__DIR__ . '/caches/');
  21. if( isset($_REQUEST) && isset($_REQUEST['action']) ){
  22. switch($_REQUEST['action']){
  23. case 'display':
  24. if( isset($_REQUEST['bridge']) ){
  25. unset($_REQUEST['action']);
  26. $bridge = $_REQUEST['bridge'];
  27. unset($_REQUEST['bridge']);
  28. $format = $_REQUEST['format'];
  29. unset($_REQUEST['format']);
  30. // FIXME : necessary ?
  31. // ini_set('user_agent', 'Mozilla/5.0 (X11; Linux x86_64; rv:20.0) Gecko/20100101 Firefox/20.0');
  32. $cache = Cache::create('FileCache');
  33. // Data retrieval
  34. $bridge = Bridge::create($bridge);
  35. $bridge
  36. ->setCache($cache) // Comment this lign for avoid cache use
  37. ->setDatas($_REQUEST);
  38. // Data transformation
  39. $format = Format::create($format);
  40. $format
  41. ->setDatas($bridge->getDatas())
  42. ->setExtraInfos(array(
  43. 'name' => $bridge->getName(),
  44. 'uri' => $bridge->getURI(),
  45. ))
  46. ->display();
  47. die;
  48. }
  49. break;
  50. }
  51. }
  52. }
  53. catch(HttpException $e){
  54. header('HTTP/1.1 ' . $e->getCode() . ' ' . Http::getMessageForCode($e->getCode()));
  55. header('Content-Type: text/plain');
  56. die($e->getMessage());
  57. }
  58. catch(\Exception $e){
  59. die($e->getMessage());
  60. }
  61. function getHelperButtonFormat($value, $name){
  62. return '<button type="submit" name="format" value="' . $value . '">' . $name . '</button>';
  63. }
  64. $bridges = Bridge::searchInformation();
  65. $formats = Format::searchInformation();
  66. ?>
  67. <!DOCTYPE html>
  68. <html lang="en">
  69. <head>
  70. <meta charset="utf-8">
  71. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  72. <meta name="description" content="Rss-bridge" />
  73. <title>RSS-Bridge</title>
  74. <link href="css/style.css" rel="stylesheet">
  75. <!--[if IE]>
  76. <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
  77. <![endif]-->
  78. </head>
  79. <body>
  80. <header>
  81. <h1>RSS-Bridge</h1>
  82. </header>
  83. <?php foreach($bridges as $bridgeReference => $bridgeInformations): ?>
  84. <section id="bridge-<?php echo $bridgeReference ?>" data-ref="<?php echo $bridgeReference ?>">
  85. <h2><?php echo $bridgeInformations['name'] ?></h2>
  86. <p class="description">
  87. <?php echo isset($bridgeInformations['description']) ? $bridgeInformations['description'] : 'No description provided' ?>
  88. </p>
  89. <?php if( isset($bridgeInformations['use']) && count($bridgeInformations['use']) > 0 ): ?>
  90. <ol class="list-use">
  91. <?php foreach($bridgeInformations['use'] as $anUseNum => $anUse): ?>
  92. <li data-use="<?php echo $anUseNum ?>">
  93. <form method="GET" action="?">
  94. <input type="hidden" name="action" value="display" />
  95. <input type="hidden" name="bridge" value="<?php echo $bridgeReference ?>" />
  96. <?php foreach($anUse as $argName => $argDescription): ?>
  97. <?php
  98. $idArg = 'arg-' . $bridgeReference . '-' . $anUseNum . '-' . $argName;
  99. ?>
  100. <input id="<?php echo $idArg ?>" type="text" value="" placeholder="<?php echo $argDescription; ?>" name="<?php echo $argName ?>" placeholder="<?php echo $argDescription ?>" />
  101. <?php endforeach; ?>
  102. <?php foreach( $formats as $name => $infos ): ?>
  103. <?php if( isset($infos['name']) ){ echo getHelperButtonFormat($name, $infos['name']); } ?>
  104. <?php endforeach; ?>
  105. </form>
  106. </li>
  107. <?php endforeach; ?>
  108. </ol>
  109. <?php else: ?>
  110. <form method="GET" action="?">
  111. <input type="hidden" name="action" value="display" />
  112. <input type="hidden" name="bridge" value="<?php echo $bridgeReference ?>" />
  113. <?php foreach( $formats as $name => $infos ): ?>
  114. <?php if( isset($infos['name']) ){ echo getHelperButtonFormat($name, $infos['name']); } ?>
  115. <?php endforeach; ?>
  116. </form>
  117. <?php endif; ?>
  118. </section>
  119. <?php endforeach; ?>
  120. <footer>
  121. <a href="https://github.com/sebsauvage/rss-bridge">RSS-Bridge</a> alpha 0.1
  122. </footer>
  123. </body>
  124. </html>