A tumblelog CMS built on AJAX, PHP and MySQL.

index.php 20KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  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. $page_title = $conf->title;
  48. $page_title_divisor = " &raquo; "; // it should be set in configuration
  49. $page_title_len = 50; // it should be set in configuration
  50. if ($id_post) {
  51. $register = $tumble->getPost($id_post);
  52. $textile = new Textile();
  53. if (empty($register["title"])) {
  54. if (!empty($register["description"])) {
  55. if (strlen($register["description"]) > $page_title_len) {
  56. $page_title_data = substr($register["description"], 0, $page_title_len)."...";
  57. }
  58. }
  59. } else {
  60. $page_title_data = $register["title"];
  61. }
  62. $page_title_data = strip_tags($textile->TextileThis($page_title_data));
  63. if (!empty($page_title_data)) {
  64. $page_title .= $page_title_divisor.stripslashes($page_title_data);
  65. }
  66. }
  67. $input = array("{Gelato_includes}","{Title}", "{Page_Title}", "{Description}", "{URL_Tumble}", "{Template_name}");
  68. $output = array($gelato_includes, $conf->title, $page_title, $conf->description, $conf->urlGelato, $conf->template);
  69. $template->cargarPlantilla($input, $output, "template_header");
  70. $template->mostrarPlantilla();
  71. if ($user->isAuthenticated()) {
  72. $input = array("{User}", "{URL_Tumble}");
  73. $output = array($_SESSION["user_login"], $conf->urlGelato);
  74. $template->cargarPlantilla($input, $output, "template_isadmin");
  75. $template->mostrarPlantilla();
  76. }
  77. if (!$id_post) {
  78. $limit=$conf->postLimit;
  79. if(isset($page_num) && is_numeric($page_num) && $page_num>0) { // Is defined the page and is numeric?
  80. $from = (($page_num-1) * $limit);
  81. } else {
  82. $from = 0;
  83. }
  84. $rs = $tumble->getPosts($limit, $from);
  85. if ($tumble->contarRegistros()>0) {
  86. $dateTmp = null;
  87. while($register = mysql_fetch_array($rs)) {
  88. $formatedDate = gmdate("M d", strtotime($register["date"])+transform_offset($conf->offsetTime));
  89. if ( $dateTmp != null && $formatedDate == $dateTmp ) { $formatedDate = ""; } else { $dateTmp = $formatedDate; }
  90. $strEnd=($conf->urlFriendly) ? "/" : "";
  91. $permalink = $conf->urlGelato.($conf->urlFriendly?"/post/":"/index.php?post=").$register["id_post"].$strEnd;
  92. $conversation = $register["description"];
  93. $textile = new Textile();
  94. $register["description"] = $textile->TextileThis($register["description"]);
  95. $register["title"] = stripslashes($register["title"]);
  96. $register["description"] = stripslashes($register["description"]);
  97. switch ($tumble->getType($register["id_post"])) {
  98. case "1":
  99. $input = array("{Date_Added}", "{Permalink}", "{Title}", "{Body}", "{URL_Tumble}");
  100. $output = array($formatedDate, $permalink, $register["title"], $register["description"], $conf->urlGelato);
  101. $template->cargarPlantilla($input, $output, "template_regular_post");
  102. $template->mostrarPlantilla();
  103. break;
  104. case "2":
  105. $fileName = "uploads/".getFileName($register["url"]);
  106. $x = @getimagesize($fileName);
  107. if ($x[0] > 500) {
  108. $photoPath = $conf->urlGelato."/classes/imgsize.php?w=500&img=".$register["url"];
  109. } else {
  110. $photoPath = str_replace("../", $conf->urlGelato."/", $register["url"]);
  111. }
  112. $effect = " href=\"".str_replace("../", $conf->urlGelato."/", $register["url"])."\" rel=\"lightbox\"";
  113. $input = array("{Date_Added}", "{Permalink}", "{PhotoURL}", "{PhotoAlt}", "{Caption}", "{Effect}", "{URL_Tumble}");
  114. $output = array($formatedDate, $permalink, $photoPath, strip_tags($register["description"]), $register["description"], $effect, $conf->urlGelato);
  115. $template->cargarPlantilla($input, $output, "template_photo");
  116. $template->mostrarPlantilla();
  117. break;
  118. case "3":
  119. $input = array("{Date_Added}", "{Permalink}", "{Quote}", "{Source}", "{URL_Tumble}");
  120. $output = array($formatedDate, $permalink, $register["description"], $register["title"], $conf->urlGelato);
  121. $template->cargarPlantilla($input, $output, "template_quote");
  122. $template->mostrarPlantilla();
  123. break;
  124. case "4":
  125. if($conf->shorten_links){
  126. $register["url"] = _file_get_contents("http://api.abbrr.com/api.php?out=link&url=".$register["url"]);
  127. }
  128. $register["title"] = ($register["title"]=="")? $register["url"] : $register["title"];
  129. $input = array("{Date_Added}", "{Permalink}", "{URL}", "{Name}", "{Description}", "{URL_Tumble}");
  130. $output = array($formatedDate, $permalink, $register["url"], $register["title"], $register["description"], $conf->urlGelato);
  131. $template->cargarPlantilla($input, $output, "template_url");
  132. $template->mostrarPlantilla();
  133. break;
  134. case "5":
  135. $input = array("{Date_Added}", "{Permalink}", "{Title}", "{Conversation}", "{URL_Tumble}");
  136. $output = array($formatedDate, $permalink, $register["title"], $tumble->formatConversation($conversation), $conf->urlGelato);
  137. $template->cargarPlantilla($input, $output, "template_conversation");
  138. $template->mostrarPlantilla();
  139. break;
  140. case "6":
  141. $input = array("{Date_Added}", "{Permalink}", "{Video}", "{Caption}", "{URL_Tumble}");
  142. $output = array($formatedDate, $permalink, $tumble->getVideoPlayer($register["url"]), $register["description"], $conf->urlGelato);
  143. $template->cargarPlantilla($input, $output, "template_video");
  144. $template->mostrarPlantilla();
  145. break;
  146. case "7":
  147. $input = array("{Date_Added}", "{Permalink}", "{Mp3}", "{Caption}", "{URL_Tumble}");
  148. $output = array($formatedDate, $permalink, $tumble->getMp3Player($register["url"]), $register["description"], $conf->urlGelato);
  149. $template->cargarPlantilla($input, $output, "template_mp3");
  150. $template->mostrarPlantilla();
  151. break;
  152. }
  153. }
  154. $p = new pagination;
  155. $p->Items($tumble->getPostsNumber());
  156. $p->limit($limit);
  157. if($conf->urlFriendly){
  158. $p->urlFriendly('[...]');
  159. $p->target($conf->urlGelato."/page/[...]");
  160. }else
  161. $p->target($conf->urlGelato);
  162. $p->currentPage(isset($page_num) ? $page_num : 1);
  163. $p->show();
  164. } else {
  165. $template->renderizaEtiqueta("No posts in this tumblelog.", "div","error");
  166. }
  167. } else {
  168. $register = $tumble->getPost($id_post);
  169. $formatedDate = gmdate("M d", strtotime($register["date"])+transform_offset($conf->offsetTime));
  170. $strEnd=($conf->urlFriendly) ? "/" : "";
  171. $permalink = $conf->urlGelato.($conf->urlFriendly?"/post/":"/index.php?post=").$register["id_post"].$strEnd;
  172. $conversation = $register["description"];
  173. $textile = new Textile();
  174. $register["description"] = $textile->TextileThis($register["description"]);
  175. $register["title"] = stripslashes($register["title"]);
  176. $register["description"] = stripslashes($register["description"]);
  177. switch ($tumble->getType($register["id_post"])) {
  178. case "1":
  179. $input = array("{Date_Added}", "{Permalink}", "{Title}", "{Body}", "{URL_Tumble}");
  180. $output = array($formatedDate, $permalink, $register["title"], $register["description"], $conf->urlGelato);
  181. $template->cargarPlantilla($input, $output, "template_regular_post");
  182. $template->mostrarPlantilla();
  183. break;
  184. case "2":
  185. $fileName = "uploads/".getFileName($register["url"]);
  186. $x = @getimagesize($fileName);
  187. if ($x[0] > 500) {
  188. $photoPath = $conf->urlGelato."/classes/imgsize.php?w=500&img=".$register["url"];
  189. } else {
  190. $photoPath = str_replace("../", $conf->urlGelato."/", $register["url"]);
  191. }
  192. $effect = " href=\"".str_replace("../", $conf->urlGelato."/", $register["url"])."\" rel=\"lightbox\"";
  193. $input = array("{Date_Added}", "{Permalink}", "{PhotoURL}", "{PhotoAlt}", "{Caption}", "{Effect}", "{URL_Tumble}");
  194. $output = array($formatedDate, $permalink, $photoPath, strip_tags($register["description"]), $register["description"], $effect, $conf->urlGelato);
  195. $template->cargarPlantilla($input, $output, "template_photo");
  196. $template->mostrarPlantilla();
  197. break;
  198. case "3":
  199. $input = array("{Date_Added}", "{Permalink}", "{Quote}", "{Source}", "{URL_Tumble}");
  200. $output = array($formatedDate, $permalink, $register["description"], $register["title"], $conf->urlGelato);
  201. $template->cargarPlantilla($input, $output, "template_quote");
  202. $template->mostrarPlantilla();
  203. break;
  204. case "4":
  205. if($conf->shorten_links){
  206. $register["url"] = _file_get_contents("http://api.abbrr.com/api.php?out=link&url=".$register["url"]);
  207. }
  208. $register["title"] = ($register["title"]=="")? $register["url"] : $register["title"];
  209. $input = array("{Date_Added}", "{Permalink}", "{URL}", "{Name}", "{Description}", "{URL_Tumble}");
  210. $output = array($formatedDate, $permalink, $register["url"], $register["title"], $register["description"], $conf->urlGelato);
  211. $template->cargarPlantilla($input, $output, "template_url");
  212. $template->mostrarPlantilla();
  213. break;
  214. case "5":
  215. $input = array("{Date_Added}", "{Permalink}", "{Title}", "{Conversation}", "{URL_Tumble}");
  216. $output = array($formatedDate, $permalink, $register["title"], $tumble->formatConversation($conversation), $conf->urlGelato);
  217. $template->cargarPlantilla($input, $output, "template_conversation");
  218. $template->mostrarPlantilla();
  219. break;
  220. case "6":
  221. $input = array("{Date_Added}", "{Permalink}", "{Video}", "{Caption}", "{URL_Tumble}");
  222. $output = array($formatedDate, $permalink, $tumble->getVideoPlayer($register["url"]), $register["description"], $conf->urlGelato);
  223. $template->cargarPlantilla($input, $output, "template_video");
  224. $template->mostrarPlantilla();
  225. break;
  226. case "7":
  227. $input = array("{Date_Added}", "{Permalink}", "{Mp3}", "{Caption}", "{URL_Tumble}");
  228. $output = array($formatedDate, $permalink, $tumble->getMp3Player($register["url"]), $register["description"], $conf->urlGelato);
  229. $template->cargarPlantilla($input, $output, "template_mp3");
  230. $template->mostrarPlantilla();
  231. break;
  232. }
  233. if ($conf->allowComments) {
  234. $comment = new comments();
  235. $rsComments = $comment->getComments($register["id_post"]);
  236. $textile = new Textile();
  237. if (empty($register["title"])) {
  238. if (!empty($register["description"])) {
  239. if (strlen($register["description"]) > 30) {
  240. $postTitle = substr($register["description"], 0, 30)."...";
  241. }
  242. }
  243. } else {
  244. $postTitle = $register["title"];
  245. }
  246. $postTitle = strip_tags($textile->TextileThis($postTitle));
  247. $input = array("{Comments_Number}", "{Post_Title}");
  248. $output = array($comment->countComments($register["id_post"]), $postTitle);
  249. $template->precargarPlantillaConBloque($input, $output, "template_comments", "comments");
  250. while($rowComment = mysql_fetch_assoc($rsComments)) {
  251. /*echo "<pre>";
  252. print_r($rowComment);
  253. echo "</pre>";*/
  254. $commentAuthor = ($rowComment["web"]=="") ? $rowComment["username"] : "<a href=\"".$rowComment["web"]."\" rel=\"external\">".$rowComment["username"]."</a>";
  255. $input = array("{Id_Comment}", "{Comment_Author}", "{Date}", "{Comment}");
  256. $output = array($rowComment["id_comment"], $commentAuthor, gmdate("d.m.y", strtotime($rowComment["comment_date"])+transform_offset($conf->offsetTime)), $rowComment["content"]);
  257. $template->cargarPlantillaConBloque($input, $output, "template_comments", "comments");
  258. }
  259. $template->mostrarPlantillaConBloque();
  260. $input = array("{User_Cookie}", "{Email_Cookie}", "{Web_Cookie}", "{Id_Post}", "{Form_Action}", "{Date_Added}");
  261. $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());
  262. $template->cargarPlantilla($input, $output, "template_comment_post");
  263. $template->mostrarPlantilla();
  264. }
  265. }
  266. $input = array("{URL_Tumble}");
  267. $output = array($conf->urlGelato);
  268. $template->cargarPlantilla($input, $output, "template_footer");
  269. $template->mostrarPlantilla();
  270. ?>