A tumblelog CMS built on AJAX, PHP and MySQL.

index.php 19KB

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