A tumblelog CMS built on AJAX, PHP and MySQL.

index.php 11KB

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