A tumblelog CMS built on AJAX, PHP and MySQL.

index.php 19KB

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