A tumblelog CMS built on AJAX, PHP and MySQL.

index.php 14KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  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. // My approach to MVC
  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. $textile = new Textile();
  55. if (empty($register["title"])) {
  56. if (!empty($register["description"])) {
  57. if (strlen($register["description"]) > $page_title_len) {
  58. $page_title_data = substr($register["description"], 0, $page_title_len)."...";
  59. }
  60. }
  61. } else {
  62. $page_title_data = $register["title"];
  63. }
  64. $page_title_data = strip_tags($textile->TextileThis($page_title_data));
  65. if (!empty($page_title_data)) {
  66. $page_title .= $page_title_divisor.stripslashes($page_title_data);
  67. }
  68. }
  69. $theme->set('Gelato_includes',$gelato_includes);
  70. $theme->set('Title',$conf->title);
  71. $theme->set('Page_Title',$page_title);
  72. $theme->set('Description',$conf->description);
  73. $theme->set('URL_Tumble',$conf->urlGelato);
  74. $theme->set('Template_name',$conf->template);
  75. $theme->set('isAuthenticated',$user->isAuthenticated());
  76. if($user->isAuthenticated()){
  77. $theme->set('User',$_SESSION["user_login"]);
  78. $theme->set('URL_Tumble',$conf->urlGelato);
  79. }
  80. $rows = array();
  81. if(!$id_post){
  82. $limit=$conf->postLimit;
  83. if(isset($page_num) && is_numeric($page_num) && $page_num>0) { // Is defined the page and is numeric?
  84. $from = (($page_num-1) * $limit);
  85. } else {
  86. $from = 0;
  87. }
  88. $rs = $tumble->getPosts($limit, $from);
  89. if ($tumble->contarRegistros()>0) {
  90. $dateTmp = null;
  91. while($register = mysql_fetch_assoc($rs)) {
  92. $formatedDate = gmdate("M d", strtotime($register["date"])+transform_offset($conf->offsetTime));
  93. if ( $dateTmp != null && $formatedDate == $dateTmp ) { $formatedDate = ""; } else { $dateTmp = $formatedDate; }
  94. $strEnd=($conf->urlFriendly) ? "/" : "";
  95. $permalink = $conf->urlGelato.($conf->urlFriendly?"/post/":"/index.php?post=").$register["id_post"].$strEnd;
  96. $conversation = $register["description"];
  97. $register["description"] = $register["description"];
  98. $register["title"] = stripslashes($register["title"]);
  99. $register["description"] = stripslashes($register["description"]);
  100. $postType = $tumble->getType($register["id_post"]);
  101. $row['Date_Added'] = $formatedDate;
  102. $row['Permalink'] = $permalink;
  103. $row['postType'] = $postType;
  104. switch ($postType){
  105. case "1":
  106. $row['Title'] = $register["title"];
  107. $row['Body'] = $register["description"];
  108. break;
  109. case "2":
  110. $fileName = "uploads/".getFileName($register["url"]);
  111. $x = @getimagesize($fileName);
  112. if ($x[0] > 500) {
  113. $photoPath = $conf->urlGelato."/classes/imgsize.php?w=500&img=".$register["url"];
  114. } else {
  115. $photoPath = str_replace("../", $conf->urlGelato."/", $register["url"]);
  116. }
  117. $effect = " href=\"".str_replace("../", $conf->urlGelato."/", $register["url"])."\" rel=\"lightbox\"";
  118. $row['PhotoURL'] = $photoPath;
  119. $row['PhotoAlt'] = strip_tags($register["description"]);
  120. $row['Caption'] = $register["description"];
  121. $row['Effect'] = $effect;
  122. break;
  123. case "3":
  124. $row['Quote'] = $register["description"];
  125. $row['Source'] = $register["title"];
  126. break;
  127. case "4":
  128. if($conf->shorten_links){
  129. $register["url"] = _file_get_contents("http://api.abbrr.com/api.php?out=link&url=".$register["url"]);
  130. }
  131. $register["title"] = ($register["title"]=="")? $register["url"] : $register["title"];
  132. $row['URL'] = $register["url"];
  133. $row['Name'] = $register["title"];
  134. $row['Description'] = $register["description"];
  135. break;
  136. case "5":
  137. $row['Title'] = $register["title"];
  138. $row['Conversation'] = $tumble->formatConversation($conversation);
  139. break;
  140. case "6":
  141. $row['Video'] = $tumble->getVideoPlayer($register["url"]);
  142. $row['Caption'] = $register["description"];
  143. break;
  144. case "7":
  145. $row['Mp3'] = $tumble->getMp3Player($register["url"]);
  146. $row['Caption'] = $register["description"];
  147. break;
  148. }
  149. $comment = new comments();
  150. $noComments = $comment->countComments($register["id_post"]);
  151. $user = new user();
  152. $username = $user->getUserByID($register["id_user"]);
  153. $row['User'] = $username["name"];
  154. $row['Comments_Number'] = $noComments;
  155. $rows[] = $row;
  156. }
  157. $theme->set('rows',$rows);
  158. $p = new pagination;
  159. $p->Items($tumble->getPostsNumber());
  160. $p->limit($limit);
  161. if($conf->urlFriendly){
  162. $p->urlFriendly('[...]');
  163. $p->target($conf->urlGelato."/page/[...]");
  164. }else
  165. $p->target($conf->urlGelato);
  166. $p->currentPage(isset($page_num) ? $page_num : 1);
  167. $theme->set('pagination',$p->getPagination());
  168. } else {
  169. $theme->set('error','No posts in this tumblelog.');
  170. }
  171. } else {
  172. $register = $tumble->getPost($id_post);
  173. $formatedDate = gmdate("M d", strtotime($register["date"])+transform_offset($conf->offsetTime));
  174. $strEnd=($conf->urlFriendly) ? "/" : "";
  175. $permalink = $conf->urlGelato.($conf->urlFriendly?"/post/":"/index.php?post=").$register["id_post"].$strEnd;
  176. $conversation = $register["description"];
  177. $register["description"] = $register["description"];
  178. $register["title"] = stripslashes($register["title"]);
  179. $register["description"] = stripslashes($register["description"]);
  180. $row['Date_Added'] = $formatedDate;
  181. $row['Permalink'] = $permalink;
  182. $postType = $tumble->getType($register["id_post"]);
  183. $row['postType'] = $postType;
  184. switch ($postType) {
  185. case "1":
  186. $row['Title'] = $register["title"];
  187. $row['Body'] = $register["description"];
  188. break;
  189. case "2":
  190. $fileName = "uploads/".getFileName($register["url"]);
  191. $x = @getimagesize($fileName);
  192. if ($x[0] > 500) {
  193. $photoPath = $conf->urlGelato."/classes/imgsize.php?w=500&img=".$register["url"];
  194. } else {
  195. $photoPath = str_replace("../", $conf->urlGelato."/", $register["url"]);
  196. }
  197. $effect = " href=\"".str_replace("../", $conf->urlGelato."/", $register["url"])."\" rel=\"lightbox\"";
  198. $row['PhotoURL'] = $photoPath;
  199. $row['PhotoAlt'] = strip_tags($register["description"]);
  200. $row['Caption'] = $register["description"];
  201. $row['Effect'] = $effect;
  202. break;
  203. case "3":
  204. $row['Quote'] = $register["description"];
  205. $row['Source'] = $register["title"];
  206. break;
  207. case "4":
  208. if($conf->shorten_links){
  209. $register["url"] = _file_get_contents("http://api.abbrr.com/api.php?out=link&url=".$register["url"]);
  210. }
  211. $row['URL'] = $register["url"];
  212. $row['Name'] = $register["title"];
  213. $row['Description'] = $register["description"];
  214. break;
  215. case "5":
  216. $row['Title'] = $register["title"];
  217. $row['Conversation'] = $tumble->formatConversation($conversation);
  218. break;
  219. case "6":
  220. $row['Video'] = $tumble->getVideoPlayer($register["url"]);
  221. $row['Caption'] = $register["description"];
  222. break;
  223. case "7":
  224. $row['Mp3'] = $tumble->getMp3Player($register["url"]);
  225. $row['Caption'] = $register["description"];
  226. break;
  227. }
  228. if ($conf->allowComments) {
  229. $comment = new comments();
  230. $rsComments = $comment->getComments($register["id_post"]);
  231. $user = new user();
  232. $username = $user->getUserByID($register["id_user"]);
  233. $row['User'] = $username["name"];
  234. $textile = new Textile();
  235. if (empty($register["title"])) {
  236. if (!empty($register["description"])) {
  237. if (strlen($register["description"]) > 30) {
  238. $postTitle = substr($register["description"], 0, 30)."...";
  239. }
  240. }
  241. } else {
  242. $postTitle = $register["title"];
  243. }
  244. $postTitle = strip_tags($textile->TextileThis($postTitle));
  245. $row['Post_Title'] = $postTitle;
  246. $row['Comments_Number'] = $comment->countComments($register["id_post"]);
  247. $rows[] = $row;
  248. $theme->set('rows',$rows);
  249. $comments = array();
  250. while($rowComment = mysql_fetch_assoc($rsComments)) {
  251. $commentAuthor = ($rowComment["web"]=="") ? $rowComment["username"] : "<a href=\"".$rowComment["web"]."\" rel=\"external\">".$rowComment["username"]."</a>";
  252. $answers['Id_Comment'] = $rowComment["id_comment"];
  253. $answers['Comment_Author'] = $commentAuthor;
  254. $answers['Date'] = gmdate("d.m.y", strtotime($rowComment["comment_date"])+transform_offset($conf->offsetTime));
  255. $answers['Comment'] = $rowComment["content"];
  256. $comments[] = $answers;
  257. }
  258. $theme->set('comments',$comments);
  259. $whois['User_Cookie'] = isset($_COOKIE['cookie_gel_user'])?$_COOKIE['cookie_gel_user']:'';
  260. $whois['Email_Cookie'] = isset($_COOKIE['cookie_gel_email'])?$_COOKIE['cookie_gel_email']:'';
  261. $whois['Web_Cookie'] = isset($_COOKIE['cookie_gel_web'])?$_COOKIE['cookie_gel_web']:'';
  262. $whois['Id_Post'] = $register["id_post"];
  263. $theme->set('Date_Added',gmmktime());
  264. $theme->set('Form_Action',$conf->urlGelato."/admin/comments.php");
  265. $theme->set('whois',$whois);
  266. }
  267. }
  268. $theme->set('URL_Tumble',$conf->urlGelato);
  269. $theme->display(Absolute_Path.'themes/'.$conf->template.'/index.htm');
  270. ?>