A tumblelog CMS built on AJAX, PHP and MySQL.

index.php 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  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. switch ($tumble->getType($register["id_post"])) {
  85. case "1":
  86. $input = array("{Date_Added}", "{Permalink}", "{Title}", "{Body}", "{URL_Tumble}");
  87. $output = array($formatedDate, $permalink, $register["title"], $register["description"], $conf->urlGelato);
  88. $template->cargarPlantilla($input, $output, "template_regular_post");
  89. $template->mostrarPlantilla();
  90. break;
  91. case "2":
  92. $fileName = "uploads/".getFileName($register["url"]);
  93. $x = @getimagesize($fileName);
  94. if ($x[0] > 500) {
  95. $photoPath = $conf->urlGelato."/classes/imgsize.php?w=500&img=".$register["url"];
  96. } else {
  97. $photoPath = $register["url"];
  98. }
  99. $effect = " onclick=\"Lightbox.show('".$register["url"]."', '".strip_tags($register["description"])."');\" ";
  100. $input = array("{Date_Added}", "{Permalink}", "{PhotoURL}", "{PhotoAlt}", "{Caption}", "{Effect}", "{URL_Tumble}");
  101. $output = array($formatedDate, $permalink, $photoPath, strip_tags($register["description"]), $register["description"], $effect, $conf->urlGelato);
  102. $template->cargarPlantilla($input, $output, "template_photo");
  103. $template->mostrarPlantilla();
  104. break;
  105. case "3":
  106. $input = array("{Date_Added}", "{Permalink}", "{Quote}", "{Source}", "{URL_Tumble}");
  107. $output = array($formatedDate, $permalink, $register["description"], $register["title"], $conf->urlGelato);
  108. $template->cargarPlantilla($input, $output, "template_quote");
  109. $template->mostrarPlantilla();
  110. break;
  111. case "4":
  112. $input = array("{Date_Added}", "{Permalink}", "{URL}", "{Name}", "{Description}", "{URL_Tumble}");
  113. $output = array($formatedDate, $permalink, $register["url"], $register["title"], $register["description"], $conf->urlGelato);
  114. $template->cargarPlantilla($input, $output, "template_url");
  115. $template->mostrarPlantilla();
  116. break;
  117. case "5":
  118. $input = array("{Date_Added}", "{Permalink}", "{Title}", "{Conversation}", "{URL_Tumble}");
  119. $output = array($formatedDate, $permalink, $register["title"], $tumble->formatConversation($register["description"]), $conf->urlGelato);
  120. $template->cargarPlantilla($input, $output, "template_conversation");
  121. $template->mostrarPlantilla();
  122. break;
  123. case "6":
  124. $input = array("{Date_Added}", "{Permalink}", "{Video}", "{Caption}", "{URL_Tumble}");
  125. $output = array($formatedDate, $permalink, $tumble->getVideoPlayer($register["url"]), $register["description"], $conf->urlGelato);
  126. $template->cargarPlantilla($input, $output, "template_video");
  127. $template->mostrarPlantilla();
  128. break;
  129. case "7":
  130. $input = array("{Date_Added}", "{Permalink}", "{Mp3}", "{Caption}", "{URL_Tumble}");
  131. $output = array($formatedDate, $permalink, $tumble->getMp3Player($register["url"]), $register["description"], $conf->urlGelato);
  132. $template->cargarPlantilla($input, $output, "template_mp3");
  133. $template->mostrarPlantilla();
  134. break;
  135. }
  136. }
  137. $p = new pagination;
  138. $p->Items($tumble->getPostsNumber());
  139. $p->limit($limit);
  140. $p->urlFriendly('[...]');
  141. $p->target($conf->urlGelato."/index.php/page/[...]/");
  142. $p->currentPage(isset($page_num) ? $page_num : 1);
  143. $p->show();
  144. } else {
  145. $template->renderizaEtiqueta("No posts in this tumblelog.", "div","error");
  146. }
  147. } else {
  148. $register = $tumble->getPost($id_post);
  149. $formatedDate = date("M d", strtotime($register["date"]));
  150. $permalink = $conf->urlGelato."/index.php/post/".$register["id_post"]."/";
  151. $textile = new Textile;
  152. $register["description"] = $textile->process($register["description"]);
  153. switch ($tumble->getType($register["id_post"])) {
  154. case "1":
  155. $input = array("{Date_Added}", "{Permalink}", "{Title}", "{Body}", "{URL_Tumble}");
  156. $output = array($formatedDate, $permalink, $register["title"], $register["description"], $conf->urlGelato);
  157. $template->cargarPlantilla($input, $output, "template_regular_post");
  158. $template->mostrarPlantilla();
  159. break;
  160. case "2":
  161. $fileName = "uploads/".getFileName($register["url"]);
  162. $x = @getimagesize($fileName);
  163. if ($x[0] > 500) {
  164. $photoPath = $conf->urlGelato."/classes/imgsize.php?w=500&img=".$register["url"];
  165. } else {
  166. $photoPath = $register["url"];
  167. }
  168. $effect = " onclick=\"Lightbox.show('".$register["url"]."', '".strip_tags($register["description"])."');\" ";
  169. $input = array("{Date_Added}", "{Permalink}", "{PhotoURL}", "{PhotoAlt}", "{Caption}", "{Effect}", "{URL_Tumble}");
  170. $output = array($formatedDate, $permalink, $photoPath, strip_tags($register["description"]), $register["description"], $effect, $conf->urlGelato);
  171. $template->cargarPlantilla($input, $output, "template_photo");
  172. $template->mostrarPlantilla();
  173. break;
  174. case "3":
  175. $input = array("{Date_Added}", "{Permalink}", "{Quote}", "{Source}", "{URL_Tumble}");
  176. $output = array($formatedDate, $permalink, $register["description"], $register["title"], $conf->urlGelato);
  177. $template->cargarPlantilla($input, $output, "template_quote");
  178. $template->mostrarPlantilla();
  179. break;
  180. case "4":
  181. $input = array("{Date_Added}", "{Permalink}", "{URL}", "{Name}", "{Description}", "{URL_Tumble}");
  182. $output = array($formatedDate, $permalink, $register["url"], $register["title"], $register["description"], $conf->urlGelato);
  183. $template->cargarPlantilla($input, $output, "template_url");
  184. $template->mostrarPlantilla();
  185. break;
  186. case "5":
  187. $input = array("{Date_Added}", "{Permalink}", "{Title}", "{Conversation}", "{URL_Tumble}");
  188. $output = array($formatedDate, $permalink, $register["title"], $tumble->formatConversation($register["description"]), $conf->urlGelato);
  189. $template->cargarPlantilla($input, $output, "template_conversation");
  190. $template->mostrarPlantilla();
  191. break;
  192. case "6":
  193. $input = array("{Date_Added}", "{Permalink}", "{Video}", "{Caption}", "{URL_Tumble}");
  194. $output = array($formatedDate, $permalink, $tumble->getVideoPlayer($register["url"]), $register["description"], $conf->urlGelato);
  195. $template->cargarPlantilla($input, $output, "template_video");
  196. $template->mostrarPlantilla();
  197. break;
  198. case "7":
  199. $input = array("{Date_Added}", "{Permalink}", "{Mp3}", "{Caption}", "{URL_Tumble}");
  200. $output = array($formatedDate, $permalink, $tumble->getMp3Player($register["url"]), $register["description"], $conf->urlGelato);
  201. $template->cargarPlantilla($input, $output, "template_mp3");
  202. $template->mostrarPlantilla();
  203. break;
  204. }
  205. }
  206. $input = array("{URL_Tumble}");
  207. $output = array($conf->urlGelato);
  208. $template->cargarPlantilla($input, $output, "template_footer");
  209. $template->mostrarPlantilla();
  210. ?>