A tumblelog CMS built on AJAX, PHP and MySQL.

index.php 19KB

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