A tumblelog CMS built on AJAX, PHP and MySQL.

api.php 5.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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(dirname(__FILE__)."/config.php");
  15. include("classes/configuration.class.php");
  16. $conf = new configuration();
  17. include("classes/gelato.class.php");
  18. $tumble = new gelato();
  19. echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
  20. ?>
  21. <gelato version="1.0">
  22. <?php
  23. if (isset($_GET["action"]) && $_GET["action"] == "read") {
  24. if (isset($_GET["start"])) { $start = $_GET["start"]; } else { $start = 0; }
  25. if (isset($_GET["total"])) { $total = $_GET["total"]; } else { $total = 20; }
  26. if (isset($_GET["type"])) { $hasType = true; } else { $hasType = false; }
  27. if ($total > 50) { $total = 50; }
  28. ?>
  29. <tumblelog name="<?php echo $_SESSION["user_login"];?>" timezone="<?php echo $conf->offsetCity;?>" title="<?php echo $conf->title;?>"><?php echo $conf->description;?></tumblelog>
  30. <?php
  31. switch ($hasType) {
  32. case "post":
  33. $_GET["type"] = "1";
  34. break;
  35. case "photo":
  36. $_GET["type"] = "2";
  37. break;
  38. case "quote":
  39. $_GET["type"] = "3";
  40. break;
  41. case "url":
  42. $_GET["type"] = "4";
  43. break;
  44. case "conversation":
  45. $_GET["type"] = "5";
  46. break;
  47. case "video":
  48. $_GET["type"] = "6";
  49. break;
  50. case "mp3":
  51. $_GET["type"] = "7";
  52. break;
  53. }
  54. $rs = $tumble->getPosts($total, $start);
  55. if ($tumble->contarRegistros()>0) {
  56. ?>
  57. <posts start="<?php echo $start; ?>" total="<?php echo $total; ?>">
  58. <?php
  59. while($register = mysql_fetch_array($rs)) {
  60. $desc = htmlspecialchars($register["description"]);
  61. $url = $conf->urlGelato."/index.php?post=".$register["id_post"];
  62. $formatedDate = gmdate("D, d M Y H:i:s", strtotime($register["date"])+transform_offset($conf->offsetTime));
  63. switch ($register["type"]) {
  64. case "1":
  65. $tit = ($register["title"]=="") ? $desc : $register["title"];
  66. ?>
  67. <post id="<?php echo $register["id_post"]; ?>" url="<?php echo $url;?>" type="regular" date="<?php echo $formatedDate;?>">
  68. <regular-title><?php echo $tit;?></regular-title>
  69. <regular-body><?php echo $desc;?></regular-body>
  70. </post>
  71. <?php
  72. break;
  73. case "2":
  74. $tit = ($register["description"]=="") ? "Photo" : $desc;
  75. ?>
  76. <post id="<?php echo $register["id_post"]; ?>" url="<?php echo $url;?>" type="photo" date="<?php echo $formatedDate;?>">
  77. <?php
  78. $photoPath = str_replace("../", $conf->urlGelato."/", $register["url"]);
  79. ?>
  80. <photo-caption><?php echo $tit;?></photo-caption>
  81. <photo-url><?php echo $photoPath;?></photo-url>
  82. </post>
  83. <?php
  84. break;
  85. case "3":
  86. ?>
  87. <post id="<?php echo $register["id_post"]; ?>" url="<?php echo $url;?>" type="quote" date="<?php echo $formatedDate;?>">
  88. <quote-text><?php echo $desc; ?></quote-text>
  89. <quote-source><?php echo $register["title"]; ?></quote-source>
  90. </post>
  91. <?php
  92. break;
  93. case "4":
  94. $tit = ($register["title"]=="") ? $register["url"] : $register["title"];
  95. ?>
  96. <post id="<?php echo $register["id_post"]; ?>" url="<?php echo $url;?>" type="link" date="<?php echo $formatedDate;?>">
  97. <link-text><?php echo $tit; ?></link-text>
  98. <link-url><?php echo $register["url"]; ?></link-url>
  99. </post>
  100. <?php
  101. break;
  102. case "5":
  103. $lines = explode("\n", $desc);
  104. $line = $lines[0];
  105. $tit = ($register["title"]=="") ? $line : $register["title"];
  106. $desc = $tumble->formatConversation($desc);
  107. ?>
  108. <post id="<?php echo $register["id_post"]; ?>" url="<?php echo $url;?>" type="conversation" date="<?php echo $formatedDate;?>">
  109. <conversation-title><?php echo $tit; ?></conversation-title>
  110. <conversation-text><?php echo $desc; ?></conversation-text>
  111. <?php echo $tumble->formatApiConversation($desc); ?>
  112. </post>
  113. <?php
  114. break;
  115. case "6":
  116. $tit = ($register["description"]=="") ? "Video" : $desc;
  117. $desc = $tumble->getVideoPlayer($register["url"]);
  118. ?>
  119. <post id="<?php echo $register["id_post"]; ?>" url="<?php echo $url;?>" type="video" date="<?php echo $formatedDate;?>">
  120. <video-caption><?php echo $tit; ?></video-caption>
  121. <video-source><?php echo $register["url"]; ?></video-source>
  122. <video-player><?php echo htmlspecialchars($desc); ?></video-player>
  123. </post>
  124. <?php
  125. break;
  126. case "7":
  127. $tit = ($register["description"]=="") ? "Audio" : $desc;
  128. $desc = $tumble->getMp3Player($register["url"]);
  129. ?>
  130. <post id="<?php echo $register["id_post"]; ?>" url="<?php echo $url;?>" type="audio" date="<?php echo $formatedDate;?>">
  131. <audio-caption><?php echo $tit; ?></audio-caption>
  132. <audio-player><?php echo htmlspecialchars($desc); ?></audio-player>
  133. </post>
  134. <?php
  135. break;
  136. }
  137. $url = $conf->urlGelato."/index.php/post/".$register["id_post"]."/";
  138. $formatedDate = gmdate("D, d M Y H:i:s", strtotime($register["date"])+transform_offset($conf->offsetTime));
  139. }
  140. ?>
  141. </posts>
  142. <?php
  143. }
  144. }
  145. ?>
  146. </gelato>