A tumblelog CMS built on AJAX, PHP and MySQL.

api.php 5.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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. $tumble = new gelato();
  15. $conf = new configuration();
  16. echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
  17. ?>
  18. <gelato version="1.0">
  19. <?php
  20. if (isset($_GET["action"]) && $_GET["action"] == "read") {
  21. if (isset($_GET["start"])) { $start = $_GET["start"]; } else { $start = 0; }
  22. if (isset($_GET["total"])) { $total = $_GET["total"]; } else { $total = 20; }
  23. if (isset($_GET["type"])) { $hasType = true; } else { $hasType = false; }
  24. if ($total > 50) { $total = 50; }
  25. ?>
  26. <tumblelog name="<?php echo $_SESSION["user_login"];?>" timezone="<?php echo $conf->offsetCity;?>" title="<?php echo $conf->title;?>"><?php echo $conf->description;?></tumblelog>
  27. <?php
  28. switch ($hasType) {
  29. case "post":
  30. $_GET["type"] = "1";
  31. break;
  32. case "photo":
  33. $_GET["type"] = "2";
  34. break;
  35. case "quote":
  36. $_GET["type"] = "3";
  37. break;
  38. case "url":
  39. $_GET["type"] = "4";
  40. break;
  41. case "conversation":
  42. $_GET["type"] = "5";
  43. break;
  44. case "video":
  45. $_GET["type"] = "6";
  46. break;
  47. case "mp3":
  48. $_GET["type"] = "7";
  49. break;
  50. }
  51. $rs = $tumble->getPosts($total, $start);
  52. if ($tumble->contarRegistros()>0) {
  53. ?>
  54. <posts start="<?php echo $start; ?>" total="<?php echo $total; ?>">
  55. <?php
  56. while($register = mysql_fetch_array($rs)) {
  57. $desc = $register["description"];
  58. $url = $conf->urlGelato."/index.php?post=".$register["id_post"];
  59. $formatedDate = gmdate("D, d M Y H:i:s", strtotime($register["date"])+transform_offset($conf->offsetTime));
  60. switch ($register["type"]) {
  61. case "1":
  62. $tit = ($register["title"]=="") ? $register["description"] : $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 = ($register["description"]=="") ? "Photo" : $register["description"];
  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 $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 $register["title"]; ?></quote-source>
  87. </post>
  88. <?php
  89. break;
  90. case "4":
  91. $tit = ($register["title"]=="") ? $register["url"] : $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", $register["description"]);
  101. $line = $lines[0];
  102. $tit = ($register["title"]=="") ? $line : $register["title"];
  103. $desc = $tumble->formatConversation($register["description"]);
  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 $register["description"]; ?></conversation-text>
  108. <?php echo $tumble->formatApiConversation($register["description"]); ?>
  109. </post>
  110. <?php
  111. break;
  112. /*
  113. case "6":
  114. $tit = ($register["description"]=="") ? "Video" : $register["description"];
  115. $desc = $tumble->getVideoPlayer($register["url"]);
  116. break;
  117. case "7":
  118. $tit = ($register["description"]=="") ? "MP3" : $register["description"];
  119. $desc = $tumble->getMp3Player($register["url"]);
  120. break;
  121. */
  122. }
  123. $url = $conf->urlGelato."/index.php/post/".$register["id_post"]."/";
  124. $formatedDate = gmdate("D, d M Y H:i:s", strtotime($register["date"])+transform_offset($conf->offsetTime));
  125. }
  126. ?>
  127. </posts>
  128. <?php
  129. }
  130. }
  131. ?>
  132. </gelato>