A tumblelog CMS built on AJAX, PHP and MySQL.

index.php 19KB

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