A tumblelog CMS built on AJAX, PHP and MySQL.

index.php 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  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\" />\n";
  53. $gelato_includes .= "\t<link rel=\"stylesheet\" type=\"text/css\" href=\"".$conf->urlGelato."/themes/".$conf->template."/style.css\"/>\n";
  54. $gelato_includes .= "\t<link rel=\"alternate\" type=\"application/rss+xml\" title=\"RSS\" href=\"".$conf->urlGelato."/rss.php\"/>";
  55. $input = array("{Gelato_includes}","{Title}", "{Description}", "{URL_Tumble}", "{Template_name}");
  56. $output = array($gelato_includes, $conf->title, $conf->description, $conf->urlGelato, $conf->template);
  57. $template->cargarPlantilla($input, $output, "template_header");
  58. $template->mostrarPlantilla();
  59. if ($user->isAdmin()) {
  60. $input = array("{User}", "{URL_Tumble}");
  61. $output = array($_SESSION["user_login"], $conf->urlGelato);
  62. $template->cargarPlantilla($input, $output, "template_isadmin");
  63. $template->mostrarPlantilla();
  64. }
  65. if (!$id_post) {
  66. $limit=$conf->postLimit;
  67. if(isset($page_num) && is_numeric($page_num) && $page_num>0) { // Is defined the page and is numeric?
  68. $from = (($page_num-1) * $limit);
  69. } else {
  70. $from = 0;
  71. }
  72. $rs = $tumble->getPosts($limit, $from);
  73. if ($tumble->contarRegistros()>0) {
  74. $fecha = null;
  75. while($register = mysql_fetch_array($rs)) {
  76. $formatedDate = date("M d", strtotime($register["date"]));
  77. if ( $fecha != null && $formatedDate == $fecha ) { $formatedDate = ""; } else { $fecha = $formatedDate; }
  78. $permalink = $conf->urlGelato."/index.php/post/".$register["id_post"]."/";
  79. $textile = new Textile;
  80. $register["description"] = $textile->process($register["description"]);
  81. switch ($tumble->getType($register["id_post"])) {
  82. case "1":
  83. $input = array("{Date_Added}", "{Permalink}", "{Title}", "{Body}", "{URL_Tumble}");
  84. $output = array($formatedDate, $permalink, $register["title"], $register["description"], $conf->urlGelato);
  85. $template->cargarPlantilla($input, $output, "template_regular_post");
  86. $template->mostrarPlantilla();
  87. break;
  88. case "2":
  89. $fileName = "uploads/".getFileName($register["url"]);
  90. $x = @getimagesize($fileName);
  91. if ($x[0] > 500) {
  92. $photoPath = $conf->urlGelato."/classes/imgsize.php?w=500&img=".$register["url"];
  93. } else {
  94. $photoPath = $register["url"];
  95. }
  96. $effect = " onclick=\"Lightbox.show('".$register["url"]."', '".strip_tags($register["description"])."');\" ";
  97. $input = array("{Date_Added}", "{Permalink}", "{PhotoURL}", "{PhotoAlt}", "{Caption}", "{Effect}", "{URL_Tumble}");
  98. $output = array($formatedDate, $permalink, $photoPath, strip_tags($register["description"]), $register["description"], $effect, $conf->urlGelato);
  99. $template->cargarPlantilla($input, $output, "template_photo");
  100. $template->mostrarPlantilla();
  101. break;
  102. case "3":
  103. $input = array("{Date_Added}", "{Permalink}", "{Quote}", "{Source}", "{URL_Tumble}");
  104. $output = array($formatedDate, $permalink, $register["description"], $register["title"], $conf->urlGelato);
  105. $template->cargarPlantilla($input, $output, "template_quote");
  106. $template->mostrarPlantilla();
  107. break;
  108. case "4":
  109. $input = array("{Date_Added}", "{Permalink}", "{URL}", "{Name}", "{Description}", "{URL_Tumble}");
  110. $output = array($formatedDate, $permalink, $register["url"], $register["title"], $register["description"], $conf->urlGelato);
  111. $template->cargarPlantilla($input, $output, "template_url");
  112. $template->mostrarPlantilla();
  113. break;
  114. case "5":
  115. $input = array("{Date_Added}", "{Permalink}", "{Title}", "{Conversation}", "{URL_Tumble}");
  116. $output = array($formatedDate, $permalink, $register["title"], $tumble->formatConversation($register["description"]), $conf->urlGelato);
  117. $template->cargarPlantilla($input, $output, "template_conversation");
  118. $template->mostrarPlantilla();
  119. break;
  120. case "6":
  121. $input = array("{Date_Added}", "{Permalink}", "{Video}", "{Caption}", "{URL_Tumble}");
  122. $output = array($formatedDate, $permalink, $tumble->getVideoPlayer($register["url"]), $register["description"], $conf->urlGelato);
  123. $template->cargarPlantilla($input, $output, "template_video");
  124. $template->mostrarPlantilla();
  125. break;
  126. case "7":
  127. $input = array("{Date_Added}", "{Permalink}", "{Mp3}", "{Caption}", "{URL_Tumble}");
  128. $output = array($formatedDate, $permalink, $tumble->getMp3Player($register["url"]), $register["description"], $conf->urlGelato);
  129. $template->cargarPlantilla($input, $output, "template_mp3");
  130. $template->mostrarPlantilla();
  131. break;
  132. }
  133. }
  134. echo pagination($tumble->getPostsNumber(), $limit, isset($page_num) ? $page_num : 1, array($conf->urlGelato."/index.php/page/[...]/","[...]"), 2);
  135. } else {
  136. $template->renderizaEtiqueta("No posts in this tumblelog.", "div","error");
  137. }
  138. } else {
  139. $register = $tumble->getPost($id_post);
  140. $formatedDate = date("M d", strtotime($register["date"]));
  141. $permalink = $conf->urlGelato."/index.php/post/".$register["id_post"]."/";
  142. $textile = new Textile;
  143. $register["description"] = $textile->process($register["description"]);
  144. switch ($tumble->getType($register["id_post"])) {
  145. case "1":
  146. $input = array("{Date_Added}", "{Permalink}", "{Title}", "{Body}", "{URL_Tumble}");
  147. $output = array($formatedDate, $permalink, $register["title"], $register["description"], $conf->urlGelato);
  148. $template->cargarPlantilla($input, $output, "template_regular_post");
  149. $template->mostrarPlantilla();
  150. break;
  151. case "2":
  152. $fileName = "uploads/".getFileName($register["url"]);
  153. $x = @getimagesize($fileName);
  154. if ($x[0] > 500) {
  155. $photoPath = $conf->urlGelato."/classes/imgsize.php?w=500&img=".$register["url"];
  156. } else {
  157. $photoPath = $register["url"];
  158. }
  159. $effect = " onclick=\"Lightbox.show('".$register["url"]."', '".strip_tags($register["description"])."');\" ";
  160. $input = array("{Date_Added}", "{Permalink}", "{PhotoURL}", "{PhotoAlt}", "{Caption}", "{Effect}", "{URL_Tumble}");
  161. $output = array($formatedDate, $permalink, $photoPath, strip_tags($register["description"]), $register["description"], $effect, $conf->urlGelato);
  162. $template->cargarPlantilla($input, $output, "template_photo");
  163. $template->mostrarPlantilla();
  164. break;
  165. case "3":
  166. $input = array("{Date_Added}", "{Permalink}", "{Quote}", "{Source}", "{URL_Tumble}");
  167. $output = array($formatedDate, $permalink, $register["description"], $register["title"], $conf->urlGelato);
  168. $template->cargarPlantilla($input, $output, "template_quote");
  169. $template->mostrarPlantilla();
  170. break;
  171. case "4":
  172. $input = array("{Date_Added}", "{Permalink}", "{URL}", "{Name}", "{Description}", "{URL_Tumble}");
  173. $output = array($formatedDate, $permalink, $register["url"], $register["title"], $register["description"], $conf->urlGelato);
  174. $template->cargarPlantilla($input, $output, "template_url");
  175. $template->mostrarPlantilla();
  176. break;
  177. case "5":
  178. $input = array("{Date_Added}", "{Permalink}", "{Title}", "{Conversation}", "{URL_Tumble}");
  179. $output = array($formatedDate, $permalink, $register["title"], $tumble->formatConversation($register["description"]), $conf->urlGelato);
  180. $template->cargarPlantilla($input, $output, "template_conversation");
  181. $template->mostrarPlantilla();
  182. break;
  183. case "6":
  184. $input = array("{Date_Added}", "{Permalink}", "{Video}", "{Caption}", "{URL_Tumble}");
  185. $output = array($formatedDate, $permalink, $tumble->getVideoPlayer($register["url"]), $register["description"], $conf->urlGelato);
  186. $template->cargarPlantilla($input, $output, "template_video");
  187. $template->mostrarPlantilla();
  188. break;
  189. case "7":
  190. $input = array("{Date_Added}", "{Permalink}", "{Mp3}", "{Caption}", "{URL_Tumble}");
  191. $output = array($formatedDate, $permalink, $tumble->getMp3Player($register["url"]), $register["description"], $conf->urlGelato);
  192. $template->cargarPlantilla($input, $output, "template_mp3");
  193. $template->mostrarPlantilla();
  194. break;
  195. }
  196. }
  197. $input = array("{URL_Tumble}");
  198. $output = array($conf->urlGelato);
  199. $template->cargarPlantilla($input, $output, "template_footer");
  200. $template->mostrarPlantilla();
  201. ?>