A tumblelog CMS built on AJAX, PHP and MySQL.

index.php 19KB

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