A tumblelog CMS built on AJAX, PHP and MySQL.

index.php 17KB

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