A tumblelog CMS built on AJAX, PHP and MySQL.

index.php 14KB

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