A tumblelog CMS built on AJAX, PHP and MySQL.

index.php 9.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. <?
  2. /* ===========================
  3. gelato CMS development version
  4. http://www.gelatocms.com/
  5. gelato CMS is a free software licensed under GPL (General public license)
  6. =========================== */
  7. ?>
  8. <?
  9. // My approach to MVC
  10. require(dirname(__FILE__)."/config.php");
  11. include("classes/configuration.class.php");
  12. include("classes/gelato.class.php");
  13. include("classes/templates.class.php");
  14. include("classes/pagination.php");
  15. include("classes/user.class.php");
  16. $user = new user();
  17. $conf = new configuration();
  18. $tumble = new gelato();
  19. $template = new plantillas($conf->template);
  20. $param_url = explode("/",$_SERVER['PATH_INFO']);
  21. if (isset($_GET["post"])) {
  22. $id_post = $_GET["post"];
  23. } else {
  24. if (isset($param_url[1]) && $param_url[1]=="post") {
  25. $id_post = (isset($param_url[2])) ? ((is_numeric($param_url[2])) ? $param_url[2] : NULL) : NULL;
  26. } else {
  27. $id_post = NULL;
  28. }
  29. }
  30. if (isset($_GET["page"])) {
  31. $page_num = $_GET["page"];
  32. } else {
  33. if (isset($param_url[1]) && $param_url[1]=="page") {
  34. $page_num = (isset($param_url[2])) ? ((is_numeric($param_url[2])) ? $param_url[2] : NULL) : NULL;
  35. } else {
  36. $page_num = NULL;
  37. }
  38. }
  39. $gelato_includes = "<script language=\"javascript\" type=\"text/javascript\" src=\"".$conf->urlGelato."/admin/scripts/mootools.js\"></script>\n";
  40. $gelato_includes .= "\t<script language=\"javascript\" type=\"text/javascript\" src=\"".$conf->urlGelato."/admin/scripts/slimbox.js\"></script>\n";
  41. $gelato_includes .= "\t<link rel=\"stylesheet\" type=\"text/css\" href=\"".$conf->urlGelato."/admin/css/slimbox.css\" />\n";
  42. $gelato_includes .= "\t<link rel=\"shortcut icon\" href=\"".$conf->urlGelato."/images/favicon.ico\" />";
  43. $input = array("{Gelato_includes}","{Title}", "{Description}", "{URL_Tumble}");
  44. $output = array($gelato_includes, $conf->title, $conf->description, $conf->urlGelato);
  45. $template->cargarPlantilla($input, $output, "template_header");
  46. $template->mostrarPlantilla();
  47. if ($user->isAdmin()) {
  48. $input = array("{User}", "{URL_Tumble}");
  49. $output = array($_SESSION["user_login"], $conf->urlGelato);
  50. $template->cargarPlantilla($input, $output, "template_isadmin");
  51. $template->mostrarPlantilla();
  52. }
  53. if (!$id_post) {
  54. $limit=$conf->postLimit;
  55. if(isset($page_num) && is_numeric($page_num) && $page_num>0) { // Is defined the page and is numeric?
  56. $from = (($page_num-1) * $limit);
  57. } else {
  58. $from = 0;
  59. }
  60. $rs = $tumble->getPosts($limit, $from);
  61. if ($tumble->contarRegistros()>0) {
  62. while($register = mysql_fetch_array($rs)) {
  63. $formatedDate = date("M d", strtotime($register["date"]));
  64. $permalink = $conf->urlGelato."/index.php/post/".$register["id_post"]."/";
  65. switch ($tumble->getType($register["id_post"])) {
  66. case "1":
  67. $input = array("{Date_Added}", "{Permalink}", "{Title}", "{Body}", "{URL_Tumble}");
  68. $output = array($formatedDate, $permalink, $register["title"], $register["description"], $conf->urlGelato);
  69. $template->cargarPlantilla($input, $output, "template_regular_post");
  70. $template->mostrarPlantilla();
  71. break;
  72. case "2":
  73. $fileName = "uploads/".getFileName($register["url"]);
  74. $x = @getimagesize($fileName);
  75. if ($x[0] > 500) {
  76. $photoPath = $conf->urlGelato."/classes/imgsize.php?w=500&img=".$register["url"];
  77. } else {
  78. $photoPath = $register["url"];
  79. }
  80. $effect = " onclick=\"Lightbox.show('".$register["url"]."', '".strip_tags(htmlentities($register["description"]))."');\" ";
  81. $input = array("{Date_Added}", "{Permalink}", "{PhotoURL}", "{PhotoAlt}", "{Caption}", "{Effect}", "{URL_Tumble}");
  82. $output = array($formatedDate, $permalink, $photoPath, strip_tags(htmlentities($register["description"])), $register["description"], $effect, $conf->urlGelato);
  83. $template->cargarPlantilla($input, $output, "template_photo");
  84. $template->mostrarPlantilla();
  85. break;
  86. case "3":
  87. $input = array("{Date_Added}", "{Permalink}", "{Quote}", "{Source}", "{URL_Tumble}");
  88. $output = array($formatedDate, $permalink, $register["description"], $register["title"], $conf->urlGelato);
  89. $template->cargarPlantilla($input, $output, "template_quote");
  90. $template->mostrarPlantilla();
  91. break;
  92. case "4":
  93. $input = array("{Date_Added}", "{Permalink}", "{URL}", "{Name}", "{Description}", "{URL_Tumble}");
  94. $output = array($formatedDate, $permalink, $register["url"], $register["title"], $register["description"], $conf->urlGelato);
  95. $template->cargarPlantilla($input, $output, "template_url");
  96. $template->mostrarPlantilla();
  97. break;
  98. case "5":
  99. $input = array("{Date_Added}", "{Permalink}", "{Title}", "{Conversation}", "{URL_Tumble}");
  100. $output = array($formatedDate, $permalink, $register["title"], $tumble->formatConversation($register["description"]), $conf->urlGelato);
  101. $template->cargarPlantilla($input, $output, "template_conversation");
  102. $template->mostrarPlantilla();
  103. break;
  104. case "6":
  105. $input = array("{Date_Added}", "{Permalink}", "{Video}", "{Caption}", "{URL_Tumble}");
  106. $output = array($formatedDate, $permalink, $tumble->getVideoPlayer($register["url"]), $register["description"], $conf->urlGelato);
  107. $template->cargarPlantilla($input, $output, "template_video");
  108. $template->mostrarPlantilla();
  109. break;
  110. case "7":
  111. $input = array("{Date_Added}", "{Permalink}", "{Mp3}", "{Caption}", "{URL_Tumble}");
  112. $output = array($formatedDate, $permalink, $tumble->getMp3Player($register["url"]), $register["description"], $conf->urlGelato);
  113. $template->cargarPlantilla($input, $output, "template_mp3");
  114. $template->mostrarPlantilla();
  115. break;
  116. }
  117. }
  118. echo pagination($tumble->getPostsNumber(), $limit, isset($page_num) ? $page_num : 1, array($conf->urlGelato."/index.php/page/[...]/","[...]"), 2);
  119. } else {
  120. $template->renderizaEtiqueta("No posts in this tumblelog.", "div","error");
  121. }
  122. } else {
  123. $register = $tumble->getPost($id_post);
  124. $formatedDate = date("M d", strtotime($register["date"]));
  125. $permalink = $conf->urlGelato."/index.php/post/".$register["id_post"]."/";
  126. switch ($tumble->getType($register["id_post"])) {
  127. case "1":
  128. $input = array("{Date_Added}", "{Permalink}", "{Title}", "{Body}", "{URL_Tumble}");
  129. $output = array($formatedDate, $permalink, $register["title"], $register["description"], $conf->urlGelato);
  130. $template->cargarPlantilla($input, $output, "template_regular_post");
  131. $template->mostrarPlantilla();
  132. break;
  133. case "2":
  134. $fileName = "uploads/".getFileName($register["url"]);
  135. $x = @getimagesize($fileName);
  136. if ($x[0] > 500) {
  137. $photoPath = $conf->urlGelato."/classes/imgsize.php?w=500&img=".$register["url"];
  138. } else {
  139. $photoPath = $register["url"];
  140. }
  141. $effect = " onclick=\"Lightbox.show('".$register["url"]."', '".strip_tags(htmlentities($register["description"]))."');\" ";
  142. $input = array("{Date_Added}", "{Permalink}", "{PhotoURL}", "{PhotoAlt}", "{Caption}", "{Effect}", "{URL_Tumble}");
  143. $output = array($formatedDate, $permalink, $photoPath, strip_tags(htmlentities($register["description"])), $register["description"], $effect, $conf->urlGelato);
  144. $template->cargarPlantilla($input, $output, "template_photo");
  145. $template->mostrarPlantilla();
  146. break;
  147. case "3":
  148. $input = array("{Date_Added}", "{Permalink}", "{Quote}", "{Source}", "{URL_Tumble}");
  149. $output = array($formatedDate, $permalink, $register["description"], $register["title"], $conf->urlGelato);
  150. $template->cargarPlantilla($input, $output, "template_quote");
  151. $template->mostrarPlantilla();
  152. break;
  153. case "4":
  154. $input = array("{Date_Added}", "{Permalink}", "{URL}", "{Name}", "{Description}", "{URL_Tumble}");
  155. $output = array($formatedDate, $permalink, $register["url"], $register["title"], $register["description"], $conf->urlGelato);
  156. $template->cargarPlantilla($input, $output, "template_url");
  157. $template->mostrarPlantilla();
  158. break;
  159. case "5":
  160. $input = array("{Date_Added}", "{Permalink}", "{Title}", "{Conversation}", "{URL_Tumble}");
  161. $output = array($formatedDate, $permalink, $register["title"], $tumble->formatConversation($register["description"]), $conf->urlGelato);
  162. $template->cargarPlantilla($input, $output, "template_conversation");
  163. $template->mostrarPlantilla();
  164. break;
  165. case "6":
  166. $input = array("{Date_Added}", "{Permalink}", "{Video}", "{Caption}", "{URL_Tumble}");
  167. $output = array($formatedDate, $permalink, $tumble->getVideoPlayer($register["url"]), $register["description"], $conf->urlGelato);
  168. $template->cargarPlantilla($input, $output, "template_video");
  169. $template->mostrarPlantilla();
  170. break;
  171. case "7":
  172. $input = array("{Date_Added}", "{Permalink}", "{Mp3}", "{Caption}", "{URL_Tumble}");
  173. $output = array($formatedDate, $permalink, $tumble->getMp3Player($register["url"]), $register["description"], $conf->urlGelato);
  174. $template->cargarPlantilla($input, $output, "template_mp3");
  175. $template->mostrarPlantilla();
  176. break;
  177. }
  178. }
  179. $input = array("{URL_Tumble}");
  180. $output = array($conf->urlGelato);
  181. $template->cargarPlantilla($input, $output, "template_footer");
  182. $template->mostrarPlantilla();
  183. ?>