A tumblelog CMS built on AJAX, PHP and MySQL.

index.php 14KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  1. <?php
  2. if(!defined('entry'))define('entry', true);
  3. /* ===========================
  4. gelato CMS - A PHP based tumblelog CMS
  5. development version
  6. http://www.gelatocms.com/
  7. gelato CMS is a free software licensed under the GPL 2.0
  8. Copyright (C) 2007 by Pedro Santana <pecesama at gmail dot com>
  9. =========================== */
  10. ?>
  11. <?php
  12. // Received a valid request, better start setting globals we'll need throughout the app in entry.php
  13. require_once('entry.php');
  14. global $user, $tumble, $conf;
  15. $theme = new themes;
  16. // Our first approach to MVC... ¿our second? visit http://www.flavorphp.com
  17. if(isset($_SERVER['PATH_INFO'])) $param_url = explode("/",$_SERVER['PATH_INFO']);
  18. if (isset($_GET["post"])) {
  19. $id_post = $_GET["post"];
  20. if (!is_numeric($id_post) || $id_post < 1 ){
  21. header("Location: index.php");
  22. }
  23. } else {
  24. if (isset($param_url[1]) && $param_url[1]=="post") {
  25. $id_post = (isset($param_url[2])) ? ((is_numeric($param_url[2])) ? $param_url[2] : NULL) : NULL;
  26. } else {
  27. $id_post = NULL;
  28. }
  29. }
  30. $theme->set('id_post',$id_post);
  31. $theme->set('error','');
  32. if (isset($_GET["page"])) {
  33. $page_num = $_GET["page"];
  34. } else {
  35. if (isset($param_url[1]) && $param_url[1]=="page") {
  36. $page_num = (isset($param_url[2])) ? ((is_numeric($param_url[2])) ? $param_url[2] : NULL) : NULL;
  37. } else {
  38. $page_num = NULL;
  39. }
  40. }
  41. $gelato_includes = "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/>\n";
  42. $gelato_includes .= "\t<meta name=\"generator\" content=\"gelato ".codeName()." (".version().")\" />\n";
  43. $gelato_includes .= "\t<link rel=\"shortcut icon\" href=\"".$conf->urlGelato."/images/favicon.ico\" />\n";
  44. $gelato_includes .= "\t<link rel=\"alternate\" type=\"application/rss+xml\" title=\"RSS\" href=\"".$conf->urlGelato.($conf->urlFriendly?"/rss/":"/rss.php")."\"/>\n";
  45. $gelato_includes .= "\t<link rel=\"stylesheet\" type=\"text/css\" href=\"".$conf->urlGelato."/themes/".$conf->template."/style.css\"/>\n";
  46. $gelato_includes .= "\t<link rel=\"stylesheet\" type=\"text/css\" href=\"".$conf->urlGelato."/admin/css/lightbox.css\" />\n";
  47. $gelato_includes .= "\t<script language=\"javascript\" type=\"text/javascript\" src=\"".$conf->urlGelato."/admin/scripts/jquery.js\"></script>\n";
  48. $gelato_includes .= "\t<script language=\"javascript\" type=\"text/javascript\" src=\"".$conf->urlGelato."/admin/scripts/lightbox.js\"></script>";
  49. $page_title = $conf->title;
  50. $page_title_divisor = " &raquo; "; // it should be set in configuration
  51. $page_title_len = 50; // it should be set in configuration
  52. if ($id_post) {
  53. $register = $tumble->getPost($id_post);
  54. if (empty($register["title"])) {
  55. if (!empty($register["description"])) {
  56. $page_title_data = trimString($register["description"], $page_title_len);
  57. } else {
  58. $page_title_data = type2Text($register["type"]);
  59. }
  60. } else {
  61. $page_title_data = $register["title"];
  62. }
  63. if (!empty($page_title_data)) {
  64. $page_title .= $page_title_divisor.stripslashes($page_title_data);
  65. }
  66. }
  67. $theme->set('Gelato_includes',$gelato_includes);
  68. $theme->set('Title',$conf->title);
  69. $theme->set('Page_Title',$page_title);
  70. $theme->set('Description',$conf->description);
  71. $theme->set('URL_Tumble',$conf->urlGelato);
  72. $theme->set('Template_name',$conf->template);
  73. $theme->set('isAuthenticated',$user->isAuthenticated());
  74. if($user->isAuthenticated()){
  75. $theme->set('User',$_SESSION["user_login"]);
  76. $theme->set('URL_Tumble',$conf->urlGelato);
  77. }
  78. $rows = array();
  79. if(!$id_post){
  80. $limit=$conf->postLimit;
  81. if(isset($page_num) && is_numeric($page_num) && $page_num>0) { // Is defined the page and is numeric?
  82. $from = (($page_num-1) * $limit);
  83. } else {
  84. $from = 0;
  85. }
  86. $rs = $tumble->getPosts($limit, $from);
  87. if ($tumble->contarRegistros()>0) {
  88. $dateTmp = null;
  89. while($register = mysql_fetch_assoc($rs)) {
  90. $formatedDate = gmdate("M d", strtotime($register["date"])+transform_offset($conf->offsetTime));
  91. if ( $dateTmp != null && $formatedDate == $dateTmp ) { $formatedDate = ""; } else { $dateTmp = $formatedDate; }
  92. $strEnd=($conf->urlFriendly) ? "/" : "";
  93. $permalink = $conf->urlGelato.($conf->urlFriendly?"/post/":"/index.php?post=").$register["id_post"].$strEnd;
  94. $conversation = $register["description"];
  95. $register["description"] = $register["description"];
  96. $register["title"] = stripslashes($register["title"]);
  97. $register["description"] = stripslashes($register["description"]);
  98. $postType = $tumble->getType($register["id_post"]);
  99. $row['Date_Added'] = $formatedDate;
  100. $row['Permalink'] = $permalink;
  101. $row['postType'] = $postType;
  102. switch ($postType){
  103. case "1":
  104. $row['Title'] = $register["title"];
  105. $row['Body'] = $register["description"];
  106. break;
  107. case "2":
  108. $fileName = "uploads/".getFileName($register["url"]);
  109. $x = @getimagesize($fileName);
  110. if ($x[0] > 500) {
  111. $photoPath = $conf->urlGelato."/classes/imgsize.php?w=500&img=".$register["url"];
  112. } else {
  113. $photoPath = str_replace("../", $conf->urlGelato."/", $register["url"]);
  114. }
  115. $effect = " href=\"".str_replace("../", $conf->urlGelato."/", $register["url"])."\" rel=\"lightbox\"";
  116. $row['PhotoURL'] = $photoPath;
  117. $row['PhotoAlt'] = strip_tags($register["description"]);
  118. $row['Caption'] = $register["description"];
  119. $row['Effect'] = $effect;
  120. break;
  121. case "3":
  122. $row['Quote'] = $register["description"];
  123. $row['Source'] = $register["title"];
  124. break;
  125. case "4":
  126. if($conf->shorten_links){
  127. $register["url"] = _file_get_contents("http://api.abbrr.com/api.php?out=link&url=".$register["url"]);
  128. }
  129. $register["title"] = ($register["title"]=="")? $register["url"] : $register["title"];
  130. $row['URL'] = $register["url"];
  131. $row['Name'] = $register["title"];
  132. $row['Description'] = $register["description"];
  133. break;
  134. case "5":
  135. $row['Title'] = $register["title"];
  136. $row['Conversation'] = $tumble->formatConversation($conversation);
  137. break;
  138. case "6":
  139. $row['Video'] = $tumble->getVideoPlayer($register["url"]);
  140. $row['Caption'] = $register["description"];
  141. break;
  142. case "7":
  143. $row['Mp3'] = $tumble->getMp3Player($register["url"]);
  144. $row['Caption'] = $register["description"];
  145. break;
  146. }
  147. $comment = new comments();
  148. $noComments = $comment->countComments($register["id_post"]);
  149. $user = new user();
  150. $username = $user->getUserByID($register["id_user"]);
  151. $row['User'] = $username["name"];
  152. $row['Comments_Number'] = $noComments;
  153. $rows[] = $row;
  154. }
  155. $theme->set('rows',$rows);
  156. $p = new pagination;
  157. $p->Items($tumble->getPostsNumber());
  158. $p->limit($limit);
  159. if($conf->urlFriendly){
  160. $p->urlFriendly('[...]');
  161. $p->target($conf->urlGelato."/page/[...]");
  162. }else
  163. $p->target($conf->urlGelato);
  164. $p->currentPage(isset($page_num) ? $page_num : 1);
  165. $theme->set('pagination',$p->getPagination());
  166. } else {
  167. $theme->set('error','No posts in this tumblelog.');
  168. }
  169. } else {
  170. $register = $tumble->getPost($id_post);
  171. $formatedDate = gmdate("M d", strtotime($register["date"])+transform_offset($conf->offsetTime));
  172. $strEnd=($conf->urlFriendly) ? "/" : "";
  173. $permalink = $conf->urlGelato.($conf->urlFriendly?"/post/":"/index.php?post=").$register["id_post"].$strEnd;
  174. $conversation = $register["description"];
  175. $register["description"] = $register["description"];
  176. $register["title"] = stripslashes($register["title"]);
  177. $register["description"] = stripslashes($register["description"]);
  178. $row['Date_Added'] = $formatedDate;
  179. $row['Permalink'] = $permalink;
  180. $postType = $tumble->getType($register["id_post"]);
  181. $row['postType'] = $postType;
  182. switch ($postType) {
  183. case "1":
  184. $row['Title'] = $register["title"];
  185. $row['Body'] = $register["description"];
  186. break;
  187. case "2":
  188. $fileName = "uploads/".getFileName($register["url"]);
  189. $x = @getimagesize($fileName);
  190. if ($x[0] > 500) {
  191. $photoPath = $conf->urlGelato."/classes/imgsize.php?w=500&img=".$register["url"];
  192. } else {
  193. $photoPath = str_replace("../", $conf->urlGelato."/", $register["url"]);
  194. }
  195. $effect = " href=\"".str_replace("../", $conf->urlGelato."/", $register["url"])."\" rel=\"lightbox\"";
  196. $row['PhotoURL'] = $photoPath;
  197. $row['PhotoAlt'] = strip_tags($register["description"]);
  198. $row['Caption'] = $register["description"];
  199. $row['Effect'] = $effect;
  200. break;
  201. case "3":
  202. $row['Quote'] = $register["description"];
  203. $row['Source'] = $register["title"];
  204. break;
  205. case "4":
  206. if($conf->shorten_links){
  207. $register["url"] = _file_get_contents("http://api.abbrr.com/api.php?out=link&url=".$register["url"]);
  208. }
  209. $row['URL'] = $register["url"];
  210. $row['Name'] = $register["title"];
  211. $row['Description'] = $register["description"];
  212. break;
  213. case "5":
  214. $row['Title'] = $register["title"];
  215. $row['Conversation'] = $tumble->formatConversation($conversation);
  216. break;
  217. case "6":
  218. $row['Video'] = $tumble->getVideoPlayer($register["url"]);
  219. $row['Caption'] = $register["description"];
  220. break;
  221. case "7":
  222. $row['Mp3'] = $tumble->getMp3Player($register["url"]);
  223. $row['Caption'] = $register["description"];
  224. break;
  225. }
  226. if ($conf->allowComments) {
  227. $comment = new comments();
  228. $rsComments = $comment->getComments($register["id_post"]);
  229. $user = new user();
  230. $username = $user->getUserByID($register["id_user"]);
  231. $row["User"] = $username["name"];
  232. if (empty($register["title"])) {
  233. if (!empty($register["description"])) {
  234. $postTitle = trimString($register["description"]);
  235. } else {
  236. $postTitle = type2Text($register["type"]);
  237. }
  238. } else {
  239. $postTitle = $register["title"];
  240. }
  241. $row["Post_Title"] = $postTitle;
  242. $row["Comments_Number"] = $comment->countComments($register["id_post"]);
  243. $rows[] = $row;
  244. $theme->set('rows',$rows);
  245. $comments = array();
  246. while($rowComment = mysql_fetch_assoc($rsComments)) {
  247. $commentAuthor = ($rowComment["web"]=="") ? $rowComment["username"] : "<a href=\"".$rowComment["web"]."\" rel=\"external\">".$rowComment["username"]."</a>";
  248. $answers['Id_Comment'] = $rowComment["id_comment"];
  249. $answers['Comment_Author'] = $commentAuthor;
  250. $answers['Date'] = gmdate("d.m.y", strtotime($rowComment["comment_date"])+transform_offset($conf->offsetTime));
  251. $answers['Comment'] = $rowComment["content"];
  252. $comments[] = $answers;
  253. }
  254. $theme->set('comments',$comments);
  255. $whois['User_Cookie'] = isset($_COOKIE['cookie_gel_user'])?$_COOKIE['cookie_gel_user']:'';
  256. $whois['Email_Cookie'] = isset($_COOKIE['cookie_gel_email'])?$_COOKIE['cookie_gel_email']:'';
  257. $whois['Web_Cookie'] = isset($_COOKIE['cookie_gel_web'])?$_COOKIE['cookie_gel_web']:'';
  258. $whois['Id_Post'] = $register["id_post"];
  259. $theme->set('Date_Added',gmmktime());
  260. $theme->set('Form_Action',$conf->urlGelato."/admin/comments.php");
  261. $theme->set('whois',$whois);
  262. }
  263. }
  264. $theme->set('URL_Tumble',$conf->urlGelato);
  265. $theme->display(Absolute_Path.'themes/'.$conf->template.'/index.htm');
  266. ?>