A tumblelog CMS built on AJAX, PHP and MySQL.

api.php 5.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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 ($db->contarRegistros()>0) {
  52. ?>
  53. <posts start="<?php echo $start; ?>" total="<?php echo $total; ?>">
  54. <?php
  55. while($register = mysql_fetch_array($rs)) {
  56. $desc = util::trimString($register["description"]);
  57. $strEnd = ($conf->urlFriendly) ? "/" : "";
  58. $url = $conf->urlGelato.($conf->urlFriendly ? "/post/" : "/index.php?post=").$register["id_post"].$strEnd;
  59. $formatedDate = gmdate("D, d M Y H:i:s", strtotime($register["date"]) + util::transform_offset($conf->offsetTime));
  60. switch ($register["type"]) {
  61. case "1":
  62. $tit = (empty($register["title"])) ? $desc : strip_tags($register["title"]);
  63. ?>
  64. <post id="<?php echo $register["id_post"]; ?>" url="<?php echo $url;?>" type="regular" date="<?php echo $formatedDate;?>">
  65. <regular-title><?php echo $tit;?></regular-title>
  66. <regular-body><?php echo $desc;?></regular-body>
  67. </post>
  68. <?php
  69. break;
  70. case "2":
  71. $tit = (empty($register["description"])) ? "Photo" : $desc;
  72. ?>
  73. <post id="<?php echo $register["id_post"]; ?>" url="<?php echo $url;?>" type="photo" date="<?php echo $formatedDate;?>">
  74. <?php
  75. $photoPath = str_replace("../", $conf->urlGelato."/", $register["url"]);
  76. ?>
  77. <photo-caption><?php echo stripslashes($tit);?></photo-caption>
  78. <photo-url><?php echo $photoPath;?></photo-url>
  79. </post>
  80. <?php
  81. break;
  82. case "3":
  83. ?>
  84. <post id="<?php echo $register["id_post"]; ?>" url="<?php echo $url;?>" type="quote" date="<?php echo $formatedDate;?>">
  85. <quote-text><?php echo $desc; ?></quote-text>
  86. <quote-source><?php echo strip_tags($register["title"]); ?></quote-source>
  87. </post>
  88. <?php
  89. break;
  90. case "4":
  91. $tit = (empty($register["title"])) ? $register["url"] : strip_tags($register["title"]);
  92. ?>
  93. <post id="<?php echo $register["id_post"]; ?>" url="<?php echo $url;?>" type="link" date="<?php echo $formatedDate;?>">
  94. <link-text><?php echo $tit; ?></link-text>
  95. <link-url><?php echo $register["url"]; ?></link-url>
  96. </post>
  97. <?php
  98. break;
  99. case "5":
  100. $lines = explode("\n", $desc);
  101. $line = $lines[0];
  102. $tit = (empty($register["title"])) ? trimString($line) : $register["title"];
  103. $desc = $tumble->formatConversation($desc);
  104. ?>
  105. <post id="<?php echo $register["id_post"]; ?>" url="<?php echo $url;?>" type="conversation" date="<?php echo $formatedDate;?>">
  106. <conversation-title><?php echo $tit; ?></conversation-title>
  107. <conversation-text><?php echo $desc; ?></conversation-text>
  108. <?php echo $tumble->formatApiConversation($desc); ?>
  109. </post>
  110. <?php
  111. break;
  112. case "6":
  113. $tit = (empty($register["description"])) ? "Video" : $desc;
  114. $desc = $tumble->getVideoPlayer($register["url"]);
  115. ?>
  116. <post id="<?php echo $register["id_post"]; ?>" url="<?php echo $url;?>" type="video" date="<?php echo $formatedDate;?>">
  117. <video-caption><?php echo $tit; ?></video-caption>
  118. <video-source><?php echo $register["url"]; ?></video-source>
  119. <video-player><?php echo htmlspecialchars($desc); ?></video-player>
  120. </post>
  121. <?php
  122. break;
  123. case "7":
  124. $tit = (empty($register["description"])) ? "Audio" : $desc;
  125. $desc = $tumble->getMp3Player($register["url"]);
  126. ?>
  127. <post id="<?php echo $register["id_post"]; ?>" url="<?php echo $url;?>" type="audio" date="<?php echo $formatedDate;?>">
  128. <audio-caption><?php echo $tit; ?></audio-caption>
  129. <audio-player><?php echo htmlspecialchars($desc); ?></audio-player>
  130. </post>
  131. <?php
  132. break;
  133. }
  134. }
  135. ?>
  136. </posts>
  137. <?php
  138. }
  139. }
  140. ?>
  141. </gelato>