A tumblelog CMS built on AJAX, PHP and MySQL.

index.php 10KB

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