A tumblelog CMS built on AJAX, PHP and MySQL.

api.php 6.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. <?php
  2. if(!defined('entry')) define('entry',true);
  3. /* ===========================
  4. gelato CMS - A PHP based tumblelog CMS
  5. development version
  6. http://www.gelatocms.com/
  7. gelato CMS is a free software licensed under the GPL 2.0
  8. Copyright (C) 2007 by Pedro Santana <pecesama at gmail dot com>
  9. =========================== */
  10. ?>
  11. <?php
  12. header("Content-type: text/xml; charset=utf-8");
  13. $isFeed = true;
  14. require('entry.php');
  15. global $user, $conf, $tumble;
  16. $f = new feeds();
  17. echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
  18. ?>
  19. <gelato version="1.0">
  20. <?php
  21. if (isset($_GET["action"]) && $_GET["action"] == "read") {
  22. if (isset($_GET["start"])) { $start = $_GET["start"]; } else { $start = 0; }
  23. if (isset($_GET["total"])) { $total = $_GET["total"]; } else { $total = 20; }
  24. if (isset($_GET["type"])) { $hasType = true; } else { $hasType = false; }
  25. if ($total > 50) { $total = 50; }
  26. $user = new user();
  27. $userData = $user->getUserByID(1);
  28. $username = ($userData["name"] == "") ? "gelato" : $userData["name"];
  29. ?>
  30. <tumblelog name="<?php echo $username;?>" timezone="<?php echo $conf->offsetCity;?>" title="<?php echo $conf->title;?>">
  31. <?php
  32. echo "\n\t".$conf->description."\n";
  33. ?>
  34. <feeds>
  35. <?php
  36. $actual_feeds = $f->getFeedList();
  37. foreach($actual_feeds as $feed){
  38. $error_text = ($feed["error"]>0) ? "false" : "true";
  39. ?>
  40. <feed id="<?php echo $feed["id_feed"];?>" url="<?php echo htmlspecialchars($feed["url"]);?>" import-type="<?php echo type2Text($feed["type"]);?>" next-update-in-seconds="<? echo $f->getNextUpdate($feed["id_feed"]);?>" title="<?php echo htmlspecialchars($feed["title"]);?>" error-text="<? echo $error_text;?>"/>
  41. <?php
  42. }
  43. ?>
  44. </feeds>
  45. </tumblelog>
  46. <?php
  47. if ($hasType) {
  48. $postType = type2Number($_GET["type"]);
  49. }
  50. $rs = $tumble->getPosts($total, $start);
  51. if ($tumble->contarRegistros()>0) {
  52. ?>
  53. <posts start="<?php echo $start; ?>" total="<?php echo $total; ?>">
  54. <?php
  55. while($register = mysql_fetch_array($rs)) {
  56. $desc = htmlspecialchars($register["description"]);
  57. $url = $conf->urlGelato."/index.php?post=".$register["id_post"];
  58. $formatedDate = gmdate("D, d M Y H:i:s", strtotime($register["date"])+transform_offset($conf->offsetTime));
  59. switch ($register["type"]) {
  60. case "1":
  61. $tit = ($register["title"]=="") ? $desc : $register["title"];
  62. ?>
  63. <post id="<?php echo $register["id_post"]; ?>" url="<?php echo $url;?>" type="regular" date="<?php echo $formatedDate;?>">
  64. <regular-title><?php echo $tit;?></regular-title>
  65. <regular-body><?php echo $desc;?></regular-body>
  66. </post>
  67. <?php
  68. break;
  69. case "2":
  70. $tit = ($register["description"]=="") ? "Photo" : $desc;
  71. ?>
  72. <post id="<?php echo $register["id_post"]; ?>" url="<?php echo $url;?>" type="photo" date="<?php echo $formatedDate;?>">
  73. <?php
  74. $photoPath = str_replace("../", $conf->urlGelato."/", $register["url"]);
  75. ?>
  76. <photo-caption><?php echo $tit;?></photo-caption>
  77. <photo-url><?php echo $photoPath;?></photo-url>
  78. </post>
  79. <?php
  80. break;
  81. case "3":
  82. ?>
  83. <post id="<?php echo $register["id_post"]; ?>" url="<?php echo $url;?>" type="quote" date="<?php echo $formatedDate;?>">
  84. <quote-text><?php echo $desc; ?></quote-text>
  85. <quote-source><?php echo $register["title"]; ?></quote-source>
  86. </post>
  87. <?php
  88. break;
  89. case "4":
  90. $tit = ($register["title"]=="") ? $register["url"] : $register["title"];
  91. ?>
  92. <post id="<?php echo $register["id_post"]; ?>" url="<?php echo $url;?>" type="link" date="<?php echo $formatedDate;?>">
  93. <link-text><?php echo $tit; ?></link-text>
  94. <link-url><?php echo $register["url"]; ?></link-url>
  95. </post>
  96. <?php
  97. break;
  98. case "5":
  99. $lines = explode("\n", $desc);
  100. $line = $lines[0];
  101. $tit = ($register["title"]=="") ? $line : $register["title"];
  102. $desc = $tumble->formatConversation($desc);
  103. ?>
  104. <post id="<?php echo $register["id_post"]; ?>" url="<?php echo $url;?>" type="conversation" date="<?php echo $formatedDate;?>">
  105. <conversation-title><?php echo $tit; ?></conversation-title>
  106. <conversation-text><?php echo $desc; ?></conversation-text>
  107. <?php echo $tumble->formatApiConversation($desc); ?>
  108. </post>
  109. <?php
  110. break;
  111. case "6":
  112. $tit = ($register["description"]=="") ? "Video" : $desc;
  113. $desc = $tumble->getVideoPlayer($register["url"]);
  114. ?>
  115. <post id="<?php echo $register["id_post"]; ?>" url="<?php echo $url;?>" type="video" date="<?php echo $formatedDate;?>">
  116. <video-caption><?php echo $tit; ?></video-caption>
  117. <video-source><?php echo $register["url"]; ?></video-source>
  118. <video-player><?php echo htmlspecialchars($desc); ?></video-player>
  119. </post>
  120. <?php
  121. break;
  122. case "7":
  123. $tit = ($register["description"]=="") ? "Audio" : $desc;
  124. $desc = $tumble->getMp3Player($register["url"]);
  125. ?>
  126. <post id="<?php echo $register["id_post"]; ?>" url="<?php echo $url;?>" type="audio" date="<?php echo $formatedDate;?>">
  127. <audio-caption><?php echo $tit; ?></audio-caption>
  128. <audio-player><?php echo htmlspecialchars($desc); ?></audio-player>
  129. </post>
  130. <?php
  131. break;
  132. }
  133. $url = $conf->urlGelato."/index.php/post/".$register["id_post"]."/";
  134. $formatedDate = gmdate("D, d M Y H:i:s", strtotime($register["date"])+transform_offset($conf->offsetTime));
  135. }
  136. ?>
  137. </posts>
  138. <?php
  139. }
  140. }
  141. ?>
  142. </gelato>