A tumblelog CMS built on AJAX, PHP and MySQL.

index.php 14KB

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