A tumblelog CMS built on AJAX, PHP and MySQL.

index.php 9.8KB

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