A tumblelog CMS built on AJAX, PHP and MySQL.

index.php 17KB

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