A tumblelog CMS built on AJAX, PHP and MySQL.

index.php 18KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  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. // Received a valid request, better start setting globals we'll need throughout the app in entry.php
  13. require_once('entry.php');
  14. global $user, $tumble, $conf, $db;
  15. $template = new plantillas($conf->template);
  16. // My approach to MVC
  17. if(isset($_SERVER['PATH_INFO'])) $param_url = explode("/",$_SERVER['PATH_INFO']);
  18. if (isset($_GET["post"])) {
  19. $id_post = $_GET["post"];
  20. if (!is_numeric($id_post) && $id_post < 1 ){
  21. header("Location: index.php");
  22. }
  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 = "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/>\n";
  40. $gelato_includes .= "\t<meta name=\"generator\" content=\"gelato cms ".version()."\" />\n";
  41. $gelato_includes .= "\t<link rel=\"shortcut icon\" href=\"".$conf->urlGelato."/images/favicon.ico\" />\n";
  42. $gelato_includes .= "\t<link rel=\"alternate\" type=\"application/rss+xml\" title=\"RSS\" href=\"".$conf->urlGelato.($conf->urlFriendly?"/rss/":"/rss.php")."\"/>\n";
  43. $gelato_includes .= "\t<link rel=\"stylesheet\" type=\"text/css\" href=\"".$conf->urlGelato."/themes/".$conf->template."/style.css\"/>\n";
  44. $gelato_includes .= "\t<link rel=\"stylesheet\" type=\"text/css\" href=\"".$conf->urlGelato."/admin/css/slimbox.css\" />\n";
  45. $gelato_includes .= "\t<script language=\"javascript\" type=\"text/javascript\" src=\"".$conf->urlGelato."/admin/scripts/mootools.js\"></script>\n";
  46. $gelato_includes .= "\t<script language=\"javascript\" type=\"text/javascript\" src=\"".$conf->urlGelato."/admin/scripts/slimbox.js\"></script>";
  47. $input = array("{Gelato_includes}","{Title}", "{Description}", "{URL_Tumble}", "{Template_name}");
  48. $output = array($gelato_includes, $conf->title, $conf->description, $conf->urlGelato, $conf->template);
  49. $template->cargarPlantilla($input, $output, "template_header");
  50. $template->mostrarPlantilla();
  51. if ($user->isAuthenticated()) {
  52. $input = array("{User}", "{URL_Tumble}");
  53. $output = array($_SESSION["user_login"], $conf->urlGelato);
  54. $template->cargarPlantilla($input, $output, "template_isadmin");
  55. $template->mostrarPlantilla();
  56. }
  57. if (!$id_post) {
  58. $limit=$conf->postLimit;
  59. if(isset($page_num) && is_numeric($page_num) && $page_num>0) { // Is defined the page and is numeric?
  60. $from = (($page_num-1) * $limit);
  61. } else {
  62. $from = 0;
  63. }
  64. $rs = $tumble->getPosts($limit, $from);
  65. if ($tumble->contarRegistros()>0) {
  66. $dateTmp = null;
  67. while($register = mysql_fetch_array($rs)) {
  68. $formatedDate = date("M d", strtotime($register["date"])+transform_offset($conf->offsetTime));
  69. if ( $dateTmp != null && $formatedDate == $dateTmp ) { $formatedDate = ""; } else { $dateTmp = $formatedDate; }
  70. $strEnd=($conf->urlFriendly) ? "/" : "";
  71. $permalink = $conf->urlGelato.($conf->urlFriendly?"/post/":"/index.php?post=").$register["id_post"].$strEnd;
  72. $textile = new Textile();
  73. $register["description"] = $textile->TextileThis($register["description"]);
  74. $register["title"] = stripslashes($register["title"]);
  75. $register["description"] = stripslashes($register["description"]);
  76. switch ($tumble->getType($register["id_post"])) {
  77. case "1":
  78. $input = array("{Date_Added}", "{Permalink}", "{Title}", "{Body}", "{URL_Tumble}");
  79. $output = array($formatedDate, $permalink, $register["title"], $register["description"], $conf->urlGelato);
  80. $template->cargarPlantilla($input, $output, "template_regular_post");
  81. $template->mostrarPlantilla();
  82. break;
  83. case "2":
  84. $fileName = "uploads/".getFileName($register["url"]);
  85. $x = @getimagesize($fileName);
  86. if ($x[0] > 500) {
  87. $photoPath = $conf->urlGelato."/classes/imgsize.php?w=500&img=".$register["url"];
  88. } else {
  89. $photoPath = str_replace("../", $conf->urlGelato."/", $register["url"]);
  90. }
  91. $effect = " onclick=\"Lightbox.show('".str_replace("../", $conf->urlGelato."/", $register["url"])."', '".strip_tags($register["description"])."');\" ";
  92. $input = array("{Date_Added}", "{Permalink}", "{PhotoURL}", "{PhotoAlt}", "{Caption}", "{Effect}", "{URL_Tumble}");
  93. $output = array($formatedDate, $permalink, $photoPath, strip_tags($register["description"]), $register["description"], $effect, $conf->urlGelato);
  94. $template->cargarPlantilla($input, $output, "template_photo");
  95. $template->mostrarPlantilla();
  96. break;
  97. case "3":
  98. $input = array("{Date_Added}", "{Permalink}", "{Quote}", "{Source}", "{URL_Tumble}");
  99. $output = array($formatedDate, $permalink, $register["description"], $register["title"], $conf->urlGelato);
  100. $template->cargarPlantilla($input, $output, "template_quote");
  101. $template->mostrarPlantilla();
  102. break;
  103. case "4":
  104. $register["title"] = ($register["title"]=="")? $register["url"] : $register["title"];
  105. $input = array("{Date_Added}", "{Permalink}", "{URL}", "{Name}", "{Description}", "{URL_Tumble}");
  106. $output = array($formatedDate, $permalink, $register["url"], $register["title"], $register["description"], $conf->urlGelato);
  107. $template->cargarPlantilla($input, $output, "template_url");
  108. $template->mostrarPlantilla();
  109. break;
  110. case "5":
  111. $input = array("{Date_Added}", "{Permalink}", "{Title}", "{Conversation}", "{URL_Tumble}");
  112. $output = array($formatedDate, $permalink, $register["title"], $tumble->formatConversation($register["description"]), $conf->urlGelato);
  113. $template->cargarPlantilla($input, $output, "template_conversation");
  114. $template->mostrarPlantilla();
  115. break;
  116. case "6":
  117. $input = array("{Date_Added}", "{Permalink}", "{Video}", "{Caption}", "{URL_Tumble}");
  118. $output = array($formatedDate, $permalink, $tumble->getVideoPlayer($register["url"]), $register["description"], $conf->urlGelato);
  119. $template->cargarPlantilla($input, $output, "template_video");
  120. $template->mostrarPlantilla();
  121. break;
  122. case "7":
  123. $input = array("{Date_Added}", "{Permalink}", "{Mp3}", "{Caption}", "{URL_Tumble}");
  124. $output = array($formatedDate, $permalink, $tumble->getMp3Player($register["url"]), $register["description"], $conf->urlGelato);
  125. $template->cargarPlantilla($input, $output, "template_mp3");
  126. $template->mostrarPlantilla();
  127. break;
  128. }
  129. }
  130. $p = new pagination;
  131. $p->Items($tumble->getPostsNumber());
  132. $p->limit($limit);
  133. if($conf->urlFriendly){
  134. $p->urlFriendly('[...]');
  135. $p->target($conf->urlGelato."/page/[...]");
  136. }else
  137. $p->target($conf->urlGelato);
  138. $p->currentPage(isset($page_num) ? $page_num : 1);
  139. $p->show();
  140. } else {
  141. $template->renderizaEtiqueta("No posts in this tumblelog.", "div","error");
  142. }
  143. } else {
  144. $register = $tumble->getPost($id_post);
  145. $formatedDate = date("M d", strtotime($register["date"])+transform_offset($conf->offsetTime));
  146. $strEnd=($conf->urlFriendly) ? "/" : "";
  147. $permalink = $conf->urlGelato.($conf->urlFriendly?"/post/":"/index.php?post=").$register["id_post"].$strEnd;
  148. $textile = new Textile();
  149. $register["description"] = $textile->TextileThis($register["description"]);
  150. $register["title"] = stripslashes($register["title"]);
  151. $register["description"] = stripslashes($register["description"]);
  152. switch ($tumble->getType($register["id_post"])) {
  153. case "1":
  154. $input = array("{Date_Added}", "{Permalink}", "{Title}", "{Body}", "{URL_Tumble}");
  155. $output = array($formatedDate, $permalink, $register["title"], $register["description"], $conf->urlGelato);
  156. $template->cargarPlantilla($input, $output, "template_regular_post");
  157. $template->mostrarPlantilla();
  158. break;
  159. case "2":
  160. $fileName = "uploads/".getFileName($register["url"]);
  161. $x = @getimagesize($fileName);
  162. if ($x[0] > 500) {
  163. $photoPath = $conf->urlGelato."/classes/imgsize.php?w=500&img=".$register["url"];
  164. } else {
  165. $photoPath = str_replace("../", $conf->urlGelato."/", $register["url"]);
  166. }
  167. $effect = " onclick=\"Lightbox.show('".str_replace("../", $conf->urlGelato."/", $register["url"])."', '".strip_tags($register["description"])."');\" ";
  168. $input = array("{Date_Added}", "{Permalink}", "{PhotoURL}", "{PhotoAlt}", "{Caption}", "{Effect}", "{URL_Tumble}");
  169. $output = array($formatedDate, $permalink, $photoPath, strip_tags($register["description"]), $register["description"], $effect, $conf->urlGelato);
  170. $template->cargarPlantilla($input, $output, "template_photo");
  171. $template->mostrarPlantilla();
  172. break;
  173. case "3":
  174. $input = array("{Date_Added}", "{Permalink}", "{Quote}", "{Source}", "{URL_Tumble}");
  175. $output = array($formatedDate, $permalink, $register["description"], $register["title"], $conf->urlGelato);
  176. $template->cargarPlantilla($input, $output, "template_quote");
  177. $template->mostrarPlantilla();
  178. break;
  179. case "4":
  180. $register["title"] = ($register["title"]=="")? $register["url"] : $register["title"];
  181. $input = array("{Date_Added}", "{Permalink}", "{URL}", "{Name}", "{Description}", "{URL_Tumble}");
  182. $output = array($formatedDate, $permalink, $register["url"], $register["title"], $register["description"], $conf->urlGelato);
  183. $template->cargarPlantilla($input, $output, "template_url");
  184. $template->mostrarPlantilla();
  185. break;
  186. case "5":
  187. $input = array("{Date_Added}", "{Permalink}", "{Title}", "{Conversation}", "{URL_Tumble}");
  188. $output = array($formatedDate, $permalink, $register["title"], $tumble->formatConversation($register["description"]), $conf->urlGelato);
  189. $template->cargarPlantilla($input, $output, "template_conversation");
  190. $template->mostrarPlantilla();
  191. break;
  192. case "6":
  193. $input = array("{Date_Added}", "{Permalink}", "{Video}", "{Caption}", "{URL_Tumble}");
  194. $output = array($formatedDate, $permalink, $tumble->getVideoPlayer($register["url"]), $register["description"], $conf->urlGelato);
  195. $template->cargarPlantilla($input, $output, "template_video");
  196. $template->mostrarPlantilla();
  197. break;
  198. case "7":
  199. $input = array("{Date_Added}", "{Permalink}", "{Mp3}", "{Caption}", "{URL_Tumble}");
  200. $output = array($formatedDate, $permalink, $tumble->getMp3Player($register["url"]), $register["description"], $conf->urlGelato);
  201. $template->cargarPlantilla($input, $output, "template_mp3");
  202. $template->mostrarPlantilla();
  203. break;
  204. }
  205. if ($conf->allowComments) {
  206. $comment = new comments();
  207. $rsComments = $comment->getComments($register["id_post"]);
  208. $input = array("{Comments_Number}", "{Post_Title}");
  209. $output = array($comment->countComments($register["id_post"]), $register["title"]);
  210. $template->precargarPlantillaConBloque($input, $output, "template_comments", "comments");
  211. while($rowComment = mysql_fetch_array($rsComments)) {
  212. $commentAuthor = ($rowComment["web"]=="") ? $rowComment["username"] : "<a href=\"".$rowComment["web"]."\" rel=\"external\">".$rowComment["username"]."</a>";
  213. $input = array("{Id_Comment}", "{Comment_Author}", "{Date}", "{Comment}");
  214. $output = array($rowComment["id_comment"], $commentAuthor, date("d.m.y", strtotime($rowComment["comment_date"])), $rowComment["content"]);
  215. $template->cargarPlantillaConBloque($input, $output, "template_comments", "comments");
  216. }
  217. $template->mostrarPlantillaConBloque();
  218. $input = array("{User_Cookie}", "{Email_Cookie}", "{Web_Cookie}", "{Id_Post}", "{Form_Action}", "{Date_Added}");
  219. $output = array($_COOKIE['cookie_gel_user'], $_COOKIE['cookie_gel_email'], $_COOKIE['cookie_gel_web'], $register["id_post"], $conf->urlGelato."/admin/comments.php", gmmktime());
  220. $template->cargarPlantilla($input, $output, "template_comment_post");
  221. $template->mostrarPlantilla();
  222. }
  223. }
  224. $input = array("{URL_Tumble}");
  225. $output = array($conf->urlGelato);
  226. $template->cargarPlantilla($input, $output, "template_footer");
  227. $template->mostrarPlantilla();
  228. ?>