A tumblelog CMS built on AJAX, PHP and MySQL.

index.php 19KB

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