A tumblelog CMS built on AJAX, PHP and MySQL.

index.php 19KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  1. <?php
  2. /* ===========================
  3. gelato CMS - A PHP based tumblelog CMS
  4. development version
  5. http://www.gelatocms.com/
  6. gelato CMS is a free software licensed under the GPL 2.0
  7. Copyright (C) 2007 by Pedro Santana <pecesama at gmail dot com>
  8. =========================== */
  9. ?>
  10. <?php
  11. // My approach to MVC
  12. $configFile = dirname(__FILE__).DIRECTORY_SEPARATOR."config.php";
  13. if (!file_exists($configFile)) {
  14. $mensaje = "
  15. <h3 class=\"important\">Error reading configuration file</h3>
  16. <p>There doesn't seem to be a <code>config.php</code> file. I need this before we can get started.</p>
  17. <p>This either means that you did not rename the <code>config-sample.php</code> file to <code>config.php</code>.</p>";
  18. die($mensaje);
  19. } else {
  20. require(dirname(__FILE__).DIRECTORY_SEPARATOR."config.php");
  21. }
  22. include("classes/configuration.class.php");
  23. include("classes/textile.class.php");
  24. include("classes/gelato.class.php");
  25. include("classes/templates.class.php");
  26. include("classes/pagination.class.php");
  27. include("classes/user.class.php");
  28. include("classes/comments.class.php");
  29. $user = new user();
  30. $conf = new configuration();
  31. $tumble = new gelato();
  32. $template = new plantillas($conf->template);
  33. if(isset($_SERVER['PATH_INFO'])) $param_url = explode("/",$_SERVER['PATH_INFO']);
  34. if (isset($_GET["post"])) {
  35. $id_post = $_GET["post"];
  36. } else {
  37. if (isset($param_url[1]) && $param_url[1]=="post") {
  38. $id_post = (isset($param_url[2])) ? ((is_numeric($param_url[2])) ? $param_url[2] : NULL) : NULL;
  39. } else {
  40. $id_post = NULL;
  41. }
  42. }
  43. if (isset($_GET["page"])) {
  44. $page_num = $_GET["page"];
  45. } else {
  46. if (isset($param_url[1]) && $param_url[1]=="page") {
  47. $page_num = (isset($param_url[2])) ? ((is_numeric($param_url[2])) ? $param_url[2] : NULL) : NULL;
  48. } else {
  49. $page_num = NULL;
  50. }
  51. }
  52. $gelato_includes = "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/>\n";
  53. $gelato_includes .= "\t<meta name=\"generator\" content=\"gelato cms ".version()."\" />\n";
  54. $gelato_includes .= "\t<link rel=\"shortcut icon\" href=\"".$conf->urlGelato."/images/favicon.ico\" />\n";
  55. $gelato_includes .= "\t<link rel=\"alternate\" type=\"application/rss+xml\" title=\"RSS\" href=\"".$conf->urlGelato.($conf->urlFriendly?"/rss/":"/rss.php")."\"/>\n";
  56. $gelato_includes .= "\t<link rel=\"stylesheet\" type=\"text/css\" href=\"".$conf->urlGelato."/themes/".$conf->template."/style.css\"/>\n";
  57. $gelato_includes .= "\t<link rel=\"stylesheet\" type=\"text/css\" href=\"".$conf->urlGelato."/admin/css/slimbox.css\" />\n";
  58. $gelato_includes .= "\t<script language=\"javascript\" type=\"text/javascript\" src=\"".$conf->urlGelato."/admin/scripts/mootools.js\"></script>\n";
  59. $gelato_includes .= "\t<script language=\"javascript\" type=\"text/javascript\" src=\"".$conf->urlGelato."/admin/scripts/slimbox.js\"></script>";
  60. $input = array("{Gelato_includes}","{Title}", "{Description}", "{URL_Tumble}", "{Template_name}");
  61. $output = array($gelato_includes, $conf->title, $conf->description, $conf->urlGelato, $conf->template);
  62. $template->cargarPlantilla($input, $output, "template_header");
  63. $template->mostrarPlantilla();
  64. if ($user->isAdmin()) {
  65. $input = array("{User}", "{URL_Tumble}");
  66. $output = array($_SESSION["user_login"], $conf->urlGelato);
  67. $template->cargarPlantilla($input, $output, "template_isadmin");
  68. $template->mostrarPlantilla();
  69. }
  70. if (!$id_post) {
  71. $limit=$conf->postLimit;
  72. if(isset($page_num) && is_numeric($page_num) && $page_num>0) { // Is defined the page and is numeric?
  73. $from = (($page_num-1) * $limit);
  74. } else {
  75. $from = 0;
  76. }
  77. $rs = $tumble->getPosts($limit, $from);
  78. if ($tumble->contarRegistros()>0) {
  79. $dateTmp = null;
  80. while($register = mysql_fetch_array($rs)) {
  81. $formatedDate = date("M d", strtotime($register["date"])+transform_offset($conf->offsetTime));
  82. if ( $dateTmp != null && $formatedDate == $dateTmp ) { $formatedDate = ""; } else { $dateTmp = $formatedDate; }
  83. $strEnd=($conf->urlFriendly) ? "/" : "";
  84. $permalink = $conf->urlGelato.($conf->urlFriendly?"/post/":"/index.php?post=").$register["id_post"].$strEnd;
  85. $textile = new Textile();
  86. $register["description"] = $textile->TextileThis($register["description"]);
  87. $register["title"] = stripslashes($register["title"]);
  88. $register["description"] = stripslashes($register["description"]);
  89. switch ($tumble->getType($register["id_post"])) {
  90. case "1":
  91. $input = array("{Date_Added}", "{Permalink}", "{Title}", "{Body}", "{URL_Tumble}");
  92. $output = array($formatedDate, $permalink, $register["title"], $register["description"], $conf->urlGelato);
  93. $template->cargarPlantilla($input, $output, "template_regular_post");
  94. $template->mostrarPlantilla();
  95. break;
  96. case "2":
  97. $fileName = "uploads/".getFileName($register["url"]);
  98. $x = @getimagesize($fileName);
  99. if ($x[0] > 500) {
  100. $photoPath = $conf->urlGelato."/classes/imgsize.php?w=500&img=".$register["url"];
  101. } else {
  102. $photoPath = str_replace("../", $conf->urlGelato."/", $register["url"]);
  103. }
  104. $effect = " onclick=\"Lightbox.show('".str_replace("../", $conf->urlGelato."/", $register["url"])."', '".strip_tags($register["description"])."');\" ";
  105. $input = array("{Date_Added}", "{Permalink}", "{PhotoURL}", "{PhotoAlt}", "{Caption}", "{Effect}", "{URL_Tumble}");
  106. $output = array($formatedDate, $permalink, $photoPath, strip_tags($register["description"]), $register["description"], $effect, $conf->urlGelato);
  107. $template->cargarPlantilla($input, $output, "template_photo");
  108. $template->mostrarPlantilla();
  109. break;
  110. case "3":
  111. $input = array("{Date_Added}", "{Permalink}", "{Quote}", "{Source}", "{URL_Tumble}");
  112. $output = array($formatedDate, $permalink, $register["description"], $register["title"], $conf->urlGelato);
  113. $template->cargarPlantilla($input, $output, "template_quote");
  114. $template->mostrarPlantilla();
  115. break;
  116. case "4":
  117. $input = array("{Date_Added}", "{Permalink}", "{URL}", "{Name}", "{Description}", "{URL_Tumble}");
  118. $output = array($formatedDate, $permalink, $register["url"], $register["title"], $register["description"], $conf->urlGelato);
  119. $template->cargarPlantilla($input, $output, "template_url");
  120. $template->mostrarPlantilla();
  121. break;
  122. case "5":
  123. $input = array("{Date_Added}", "{Permalink}", "{Title}", "{Conversation}", "{URL_Tumble}");
  124. $output = array($formatedDate, $permalink, $register["title"], $tumble->formatConversation($register["description"]), $conf->urlGelato);
  125. $template->cargarPlantilla($input, $output, "template_conversation");
  126. $template->mostrarPlantilla();
  127. break;
  128. case "6":
  129. $input = array("{Date_Added}", "{Permalink}", "{Video}", "{Caption}", "{URL_Tumble}");
  130. $output = array($formatedDate, $permalink, $tumble->getVideoPlayer($register["url"]), $register["description"], $conf->urlGelato);
  131. $template->cargarPlantilla($input, $output, "template_video");
  132. $template->mostrarPlantilla();
  133. break;
  134. case "7":
  135. $input = array("{Date_Added}", "{Permalink}", "{Mp3}", "{Caption}", "{URL_Tumble}");
  136. $output = array($formatedDate, $permalink, $tumble->getMp3Player($register["url"]), $register["description"], $conf->urlGelato);
  137. $template->cargarPlantilla($input, $output, "template_mp3");
  138. $template->mostrarPlantilla();
  139. break;
  140. }
  141. }
  142. $p = new pagination;
  143. $p->Items($tumble->getPostsNumber());
  144. $p->limit($limit);
  145. $p->urlFriendly('[...]');
  146. $p->target($conf->urlGelato.($conf->urlFriendly?"/page/":"/index.php?page=")."[...]");
  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 = date("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. $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($register["description"]), $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_array($rsComments)) {
  220. $commentAuthor = ($rowComment["web"]=="") ? $rowComment["username"] : "<a href=\"".$rowComment["web"]."\" rel=\"external\">".$rowComment["username"]."</a>";
  221. $input = array("{Id_Comment}", "{Comment_Author}", "{Date}", "{Comment}");
  222. $output = array($rowComment["id_comment"], $commentAuthor, date("d.m.y", strtotime($rowComment["comment_date"])), $rowComment["content"]);
  223. $template->cargarPlantillaConBloque($input, $output, "template_comments", "comments");
  224. }
  225. $template->mostrarPlantillaConBloque();
  226. $input = array("{User_Cookie}", "{Email_Cookie}", "{Web_Cookie}", "{Id_Post}", "{Form_Action}", "{Date_Added}");
  227. $output = array($_COOKIE['cookie_gel_user'], $_COOKIE['cookie_gel_email'], $_COOKIE['cookie_gel_web'], $register["id_post"], $conf->urlGelato."/admin/comments.php", gmmktime());
  228. $template->cargarPlantilla($input, $output, "template_comment_post");
  229. $template->mostrarPlantilla();
  230. }
  231. }
  232. $input = array("{URL_Tumble}");
  233. $output = array($conf->urlGelato);
  234. $template->cargarPlantilla($input, $output, "template_footer");
  235. $template->mostrarPlantilla();
  236. ?>