A tumblelog CMS built on AJAX, PHP and MySQL.

index.php 13KB

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