A tumblelog CMS built on AJAX, PHP and MySQL.

index.php 19KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  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 ".codeName()." (".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/lightbox.css\" />\n";
  45. $gelato_includes .= "\t<script language=\"javascript\" type=\"text/javascript\" src=\"".$conf->urlGelato."/admin/scripts/jquery.js\"></script>\n";
  46. $gelato_includes .= "\t<script language=\"javascript\" type=\"text/javascript\" src=\"".$conf->urlGelato."/admin/scripts/lightbox.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 = gmdate("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. $conversation = $register["description"];
  73. $textile = new Textile();
  74. $register["description"] = $textile->TextileThis($register["description"]);
  75. $register["title"] = stripslashes($register["title"]);
  76. $register["description"] = stripslashes($register["description"]);
  77. switch ($tumble->getType($register["id_post"])) {
  78. case "1":
  79. $input = array("{Date_Added}", "{Permalink}", "{Title}", "{Body}", "{URL_Tumble}");
  80. $output = array($formatedDate, $permalink, $register["title"], $register["description"], $conf->urlGelato);
  81. $template->cargarPlantilla($input, $output, "template_regular_post");
  82. $template->mostrarPlantilla();
  83. break;
  84. case "2":
  85. $fileName = "uploads/".getFileName($register["url"]);
  86. $x = @getimagesize($fileName);
  87. if ($x[0] > 500) {
  88. $photoPath = $conf->urlGelato."/classes/imgsize.php?w=500&img=".$register["url"];
  89. } else {
  90. $photoPath = str_replace("../", $conf->urlGelato."/", $register["url"]);
  91. }
  92. $effect = " href=\"".str_replace("../", $conf->urlGelato."/", $register["url"])."\" rel=\"lightbox\"";
  93. $input = array("{Date_Added}", "{Permalink}", "{PhotoURL}", "{PhotoAlt}", "{Caption}", "{Effect}", "{URL_Tumble}");
  94. $output = array($formatedDate, $permalink, $photoPath, strip_tags($register["description"]), $register["description"], $effect, $conf->urlGelato);
  95. $template->cargarPlantilla($input, $output, "template_photo");
  96. $template->mostrarPlantilla();
  97. break;
  98. case "3":
  99. $input = array("{Date_Added}", "{Permalink}", "{Quote}", "{Source}", "{URL_Tumble}");
  100. $output = array($formatedDate, $permalink, $register["description"], $register["title"], $conf->urlGelato);
  101. $template->cargarPlantilla($input, $output, "template_quote");
  102. $template->mostrarPlantilla();
  103. break;
  104. case "4":
  105. if($conf->shorten_links){
  106. $register["url"] = _file_get_contents("http://api.abbrr.com/api.php?out=link&url=".$register["url"]);
  107. }
  108. $register["title"] = ($register["title"]=="")? $register["url"] : $register["title"];
  109. $input = array("{Date_Added}", "{Permalink}", "{URL}", "{Name}", "{Description}", "{URL_Tumble}");
  110. $output = array($formatedDate, $permalink, $register["url"], $register["title"], $register["description"], $conf->urlGelato);
  111. $template->cargarPlantilla($input, $output, "template_url");
  112. $template->mostrarPlantilla();
  113. break;
  114. case "5":
  115. $input = array("{Date_Added}", "{Permalink}", "{Title}", "{Conversation}", "{URL_Tumble}");
  116. $output = array($formatedDate, $permalink, $register["title"], $tumble->formatConversation($conversation), $conf->urlGelato);
  117. $template->cargarPlantilla($input, $output, "template_conversation");
  118. $template->mostrarPlantilla();
  119. break;
  120. case "6":
  121. $input = array("{Date_Added}", "{Permalink}", "{Video}", "{Caption}", "{URL_Tumble}");
  122. $output = array($formatedDate, $permalink, $tumble->getVideoPlayer($register["url"]), $register["description"], $conf->urlGelato);
  123. $template->cargarPlantilla($input, $output, "template_video");
  124. $template->mostrarPlantilla();
  125. break;
  126. case "7":
  127. $input = array("{Date_Added}", "{Permalink}", "{Mp3}", "{Caption}", "{URL_Tumble}");
  128. $output = array($formatedDate, $permalink, $tumble->getMp3Player($register["url"]), $register["description"], $conf->urlGelato);
  129. $template->cargarPlantilla($input, $output, "template_mp3");
  130. $template->mostrarPlantilla();
  131. break;
  132. }
  133. }
  134. $p = new pagination;
  135. $p->Items($tumble->getPostsNumber());
  136. $p->limit($limit);
  137. if($conf->urlFriendly){
  138. $p->urlFriendly('[...]');
  139. $p->target($conf->urlGelato."/page/[...]");
  140. }else
  141. $p->target($conf->urlGelato);
  142. $p->currentPage(isset($page_num) ? $page_num : 1);
  143. $p->show();
  144. } else {
  145. $template->renderizaEtiqueta("No posts in this tumblelog.", "div","error");
  146. }
  147. } else {
  148. $register = $tumble->getPost($id_post);
  149. $formatedDate = gmdate("M d", strtotime($register["date"])+transform_offset($conf->offsetTime));
  150. $strEnd=($conf->urlFriendly) ? "/" : "";
  151. $permalink = $conf->urlGelato.($conf->urlFriendly?"/post/":"/index.php?post=").$register["id_post"].$strEnd;
  152. $conversation = $register["description"];
  153. $textile = new Textile();
  154. $register["description"] = $textile->TextileThis($register["description"]);
  155. $register["title"] = stripslashes($register["title"]);
  156. $register["description"] = stripslashes($register["description"]);
  157. switch ($tumble->getType($register["id_post"])) {
  158. case "1":
  159. $input = array("{Date_Added}", "{Permalink}", "{Title}", "{Body}", "{URL_Tumble}");
  160. $output = array($formatedDate, $permalink, $register["title"], $register["description"], $conf->urlGelato);
  161. $template->cargarPlantilla($input, $output, "template_regular_post");
  162. $template->mostrarPlantilla();
  163. break;
  164. case "2":
  165. $fileName = "uploads/".getFileName($register["url"]);
  166. $x = @getimagesize($fileName);
  167. if ($x[0] > 500) {
  168. $photoPath = $conf->urlGelato."/classes/imgsize.php?w=500&img=".$register["url"];
  169. } else {
  170. $photoPath = str_replace("../", $conf->urlGelato."/", $register["url"]);
  171. }
  172. $effect = " href=\"".str_replace("../", $conf->urlGelato."/", $register["url"])."\" rel=\"lightbox\"";
  173. $input = array("{Date_Added}", "{Permalink}", "{PhotoURL}", "{PhotoAlt}", "{Caption}", "{Effect}", "{URL_Tumble}");
  174. $output = array($formatedDate, $permalink, $photoPath, strip_tags($register["description"]), $register["description"], $effect, $conf->urlGelato);
  175. $template->cargarPlantilla($input, $output, "template_photo");
  176. $template->mostrarPlantilla();
  177. break;
  178. case "3":
  179. $input = array("{Date_Added}", "{Permalink}", "{Quote}", "{Source}", "{URL_Tumble}");
  180. $output = array($formatedDate, $permalink, $register["description"], $register["title"], $conf->urlGelato);
  181. $template->cargarPlantilla($input, $output, "template_quote");
  182. $template->mostrarPlantilla();
  183. break;
  184. case "4":
  185. if($conf->shorten_links){
  186. $register["url"] = _file_get_contents("http://api.abbrr.com/api.php?out=link&url=".$register["url"]);
  187. }
  188. $register["title"] = ($register["title"]=="")? $register["url"] : $register["title"];
  189. $input = array("{Date_Added}", "{Permalink}", "{URL}", "{Name}", "{Description}", "{URL_Tumble}");
  190. $output = array($formatedDate, $permalink, $register["url"], $register["title"], $register["description"], $conf->urlGelato);
  191. $template->cargarPlantilla($input, $output, "template_url");
  192. $template->mostrarPlantilla();
  193. break;
  194. case "5":
  195. $input = array("{Date_Added}", "{Permalink}", "{Title}", "{Conversation}", "{URL_Tumble}");
  196. $output = array($formatedDate, $permalink, $register["title"], $tumble->formatConversation($conversation), $conf->urlGelato);
  197. $template->cargarPlantilla($input, $output, "template_conversation");
  198. $template->mostrarPlantilla();
  199. break;
  200. case "6":
  201. $input = array("{Date_Added}", "{Permalink}", "{Video}", "{Caption}", "{URL_Tumble}");
  202. $output = array($formatedDate, $permalink, $tumble->getVideoPlayer($register["url"]), $register["description"], $conf->urlGelato);
  203. $template->cargarPlantilla($input, $output, "template_video");
  204. $template->mostrarPlantilla();
  205. break;
  206. case "7":
  207. $input = array("{Date_Added}", "{Permalink}", "{Mp3}", "{Caption}", "{URL_Tumble}");
  208. $output = array($formatedDate, $permalink, $tumble->getMp3Player($register["url"]), $register["description"], $conf->urlGelato);
  209. $template->cargarPlantilla($input, $output, "template_mp3");
  210. $template->mostrarPlantilla();
  211. break;
  212. }
  213. if ($conf->allowComments) {
  214. $comment = new comments();
  215. $rsComments = $comment->getComments($register["id_post"]);
  216. $input = array("{Comments_Number}", "{Post_Title}");
  217. $output = array($comment->countComments($register["id_post"]), $register["title"]);
  218. $template->precargarPlantillaConBloque($input, $output, "template_comments", "comments");
  219. while($rowComment = mysql_fetch_assoc($rsComments)) {
  220. /*echo "<pre>";
  221. print_r($rowComment);
  222. echo "</pre>";*/
  223. $commentAuthor = ($rowComment["web"]=="") ? $rowComment["username"] : "<a href=\"".$rowComment["web"]."\" rel=\"external\">".$rowComment["username"]."</a>";
  224. $input = array("{Id_Comment}", "{Comment_Author}", "{Date}", "{Comment}");
  225. $output = array($rowComment["id_comment"], $commentAuthor, gmdate("d.m.y", strtotime($rowComment["comment_date"])+transform_offset($conf->offsetTime)), $rowComment["content"]);
  226. $template->cargarPlantillaConBloque($input, $output, "template_comments", "comments");
  227. }
  228. $template->mostrarPlantillaConBloque();
  229. $input = array("{User_Cookie}", "{Email_Cookie}", "{Web_Cookie}", "{Id_Post}", "{Form_Action}", "{Date_Added}");
  230. $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());
  231. $template->cargarPlantilla($input, $output, "template_comment_post");
  232. $template->mostrarPlantilla();
  233. }
  234. }
  235. $input = array("{URL_Tumble}");
  236. $output = array($conf->urlGelato);
  237. $template->cargarPlantilla($input, $output, "template_footer");
  238. $template->mostrarPlantilla();
  239. ?>