A tumblelog CMS built on AJAX, PHP and MySQL.

index.php 15KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  1. <?php
  2. if (!defined('entry')) {
  3. define('entry', true);
  4. }
  5. /* ===========================
  6. gelato CMS - A PHP based tumblelog CMS
  7. development version
  8. http://www.gelatocms.com/
  9. gelato CMS is a free software licensed under the GPL 2.0
  10. Copyright (C) 2007 by Pedro Santana <pecesama at gmail dot com>
  11. =========================== */
  12. ?>
  13. <?php
  14. // Received a valid request
  15. require_once('entry.php');
  16. global $user, $tumble, $conf;
  17. $theme = new themes;
  18. $util_class = new util();
  19. // Our first approach to MVC... our second? visit http://www.flavorphp.com
  20. if (isset($_SERVER['PATH_INFO'])) {
  21. $param_url = explode("/", $_SERVER['PATH_INFO']);
  22. }
  23. if (isset($_GET["post"])) {
  24. $id_post = $_GET["post"];
  25. if (!is_numeric($id_post) || $id_post < 1) {
  26. header("Location: index.php");
  27. }
  28. } else {
  29. if (isset($param_url[1]) && $param_url[1]=="post") {
  30. $id_post = (isset($param_url[2])) ? ((is_numeric($param_url[2])) ? $param_url[2] : null) : null;
  31. } else {
  32. $id_post = null;
  33. }
  34. }
  35. $theme->set('id_post', $id_post);
  36. $theme->set('error', '');
  37. if (isset($_GET["page"])) {
  38. $page_num = $_GET["page"];
  39. } else {
  40. if (isset($param_url[1]) && $param_url[1]=="page") {
  41. $page_num = (isset($param_url[2])) ? ((is_numeric($param_url[2])) ? $param_url[2] : null) : null;
  42. } else {
  43. $page_num = null;
  44. }
  45. }
  46. $feed_url = $conf->urlGelato.($conf->urlFriendly?"/rss/":"/rss.php");
  47. $gelato_includes = "<meta name=\"generator\" content=\"gelato ".$util_class -> codeName()." (".$util_class -> version().")\" />\n";
  48. $gelato_includes .= "\t<link rel=\"shortcut icon\" href=\"".$conf->urlGelato."/images/favicon.ico\" />";
  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 = $util_class->trimString($register["description"], $page_title_len);
  57. } else {
  58. $page_title_data = $util_class->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('rssFeed', $feed_url);
  69. $theme->set('Gelato_includes', $gelato_includes);
  70. $theme->set('Title', $conf->title);
  71. $theme->set('Page_Title', $page_title);
  72. $theme->set('Description', $conf->description);
  73. $theme->set('URL_Tumble', $conf->urlGelato);
  74. $theme->set('Template_name', $conf->template);
  75. $theme->set('allowComments', $conf->allowComments);
  76. $theme->set('isAuthenticated', $user->isAuthenticated());
  77. if ($user->isAuthenticated()) {
  78. $theme->set('User', $_SESSION["user_login"]);
  79. $theme->set('URL_Tumble', $conf->urlGelato);
  80. }
  81. $rows = array();
  82. if (!$id_post) {
  83. $limit=$conf->postLimit;
  84. if (isset($page_num) && is_numeric($page_num) && $page_num>0) { // Is defined the page and is numeric?
  85. $from = (($page_num-1) * $limit);
  86. } else {
  87. $from = 0;
  88. }
  89. $rs = $tumble->getPosts($limit, $from);
  90. if ($db->contarRegistros()>0) {
  91. $dateTmp = null;
  92. while ($register = mysql_fetch_assoc($rs)) {
  93. $formatedDate = gmdate("M d", strtotime($register["date"]) + $util_class->transform_offset($conf->offsetTime));
  94. if ($dateTmp != null && $formatedDate == $dateTmp) {
  95. $formatedDate = "";
  96. } else {
  97. $dateTmp = $formatedDate;
  98. }
  99. $permalink = $tumble->getPermalink($register["id_post"]);
  100. $conversation = $register["description"];
  101. $register["title"] = stripslashes($register["title"]);
  102. $register["description"] = stripslashes($register["description"]);
  103. $row['Date_Added'] = $formatedDate;
  104. $row['Permalink'] = $permalink;
  105. $row['postType'] = $util_class->type2Text($register["type"]);
  106. switch ($register['type']) {
  107. case "1":
  108. $row['Title'] = $register["title"];
  109. $row['Body'] = $register["description"];
  110. break;
  111. case "2":
  112. $fileName = "uploads/".$util_class->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"] = $util_class->_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. $trigger->call('post_content');
  160. $theme->set('rows', $rows);
  161. $p = new pagination;
  162. $p->Items($tumble->getPostsNumber());
  163. $p->limit($limit);
  164. if ($conf->urlFriendly) {
  165. $p->urlFriendly('[...]');
  166. $p->target($conf->urlGelato."/page/[...]");
  167. } else {
  168. $p->target($conf->urlGelato);
  169. }
  170. $p->currentPage(isset($page_num) ? $page_num : 1);
  171. $theme->set('pagination', $p->getPagination());
  172. } else {
  173. $theme->set('error', 'No posts in this tumblelog.');
  174. }
  175. } else {
  176. $register = $tumble->getPost($id_post);
  177. $formatedDate = gmdate("M d", strtotime($register["date"]) + $util_class->transform_offset($conf->offsetTime));
  178. $permalink = $tumble->getPermalink($register["id_post"]);
  179. $conversation = $register["description"];
  180. $register["description"] = $register["description"];
  181. $register["title"] = stripslashes($register["title"]);
  182. $register["description"] = stripslashes($register["description"]);
  183. $row['Date_Added'] = $formatedDate;
  184. $row['Permalink'] = $permalink;
  185. $row['postType'] = $util_class->type2Text($register["type"]);
  186. switch ($register['type']) {
  187. case "1":
  188. $row['Title'] = $register["title"];
  189. $row['Body'] = $register["description"];
  190. break;
  191. case "2":
  192. $fileName = "uploads/".$util_class->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"] = $util_class->_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. $user = new user();
  231. $username = $user->getUserByID($register["id_user"]);
  232. $row["User"] = $username["name"];
  233. if (empty($register["title"])) {
  234. if (!empty($register["description"])) {
  235. $postTitle = $util_class->trimString($register["description"]);
  236. } else {
  237. $postTitle = $util_class->type2Text($register["type"]);
  238. }
  239. } else {
  240. $postTitle = $register["title"];
  241. }
  242. $row["Post_Title"] = $postTitle;
  243. $comment = new comments();
  244. $row["Comments_Number"] = $comment->countComments($register["id_post"]);
  245. if ($conf->allowComments) {
  246. $rsComments = $comment->getComments($register["id_post"]);
  247. $comments = array();
  248. while ($rowComment = mysql_fetch_assoc($rsComments)) {
  249. $commentAuthor = ($rowComment["web"]=="") ? $rowComment["username"] : "<a href=\"".$rowComment["web"]."\" rel=\"external\">".$rowComment["username"]."</a>";
  250. $answers['Id_Comment'] = $rowComment["id_comment"];
  251. $answers['Comment_Author'] = $commentAuthor;
  252. $answers['Date'] = gmdate("d.m.y", strtotime($rowComment["comment_date"]) + $util_class->transform_offset($conf->offsetTime));
  253. $answers['Comment'] = nl2br($rowComment["content"]);
  254. $comments[] = $answers;
  255. }
  256. $theme->set('comments', $comments);
  257. $whois['User_Cookie'] = isset($_COOKIE['cookie_gel_user'])?$_COOKIE['cookie_gel_user']:'';
  258. $whois['Email_Cookie'] = isset($_COOKIE['cookie_gel_email'])?$_COOKIE['cookie_gel_email']:'';
  259. $whois['Web_Cookie'] = isset($_COOKIE['cookie_gel_web'])?$_COOKIE['cookie_gel_web']:'';
  260. $whois['Id_Post'] = $register["id_post"];
  261. $theme->set('Date_Added', gmmktime());
  262. $theme->set('Form_Action', $conf->urlGelato."/admin/comments.php");
  263. $theme->set('whois', $whois);
  264. }
  265. $rows[] = $row;
  266. $trigger->call('post_content');
  267. $theme->set('rows', $rows);
  268. }
  269. $theme->set('URL_Tumble', $conf->urlGelato);
  270. $theme->display(Absolute_Path.'themes/'.$conf->template.'/index.htm');
  271. ?>