A tumblelog CMS built on AJAX, PHP and MySQL.

index.php 14KB

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