A tumblelog CMS built on AJAX, PHP and MySQL.

index.php 15KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  1. <?php
  2. /* ===========================
  3. Sorbet CMS - A PHP based tumblelog CMS forked from Gelato CMS
  4. Sorbet CMS is a free software licensed under the GPL 3.0
  5. =========================== */
  6. if (!defined('entry')) {
  7. define('entry', true);
  8. }
  9. // Received a valid request
  10. require_once "entry.php";
  11. global $user, $tumble, $conf;
  12. $theme = new themes;
  13. $util_class = new util();
  14. // Our first approach to MVC... our second? visit http://www.flavorphp.com
  15. if (isset($_SERVER['PATH_INFO'])) {
  16. $param_url = explode("/", $_SERVER['PATH_INFO']);
  17. }
  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->urlSorbet.($conf->urlFriendly?"/rss/":"/rss.php");
  42. $sorbet_includes = "<meta name=\"generator\" content=\"sorbet ".$util_class -> codeName()." (".$util_class -> version().")\" />\n";
  43. $sorbet_includes .= "\t<link rel=\"shortcut icon\" href=\"".$conf->urlSorbet."/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 = $util_class->trimString($register["description"], $page_title_len);
  52. } else {
  53. $page_title_data = $util_class->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('sorbet_includes');
  63. $theme->set('rssFeed', $feed_url);
  64. $theme->set('Sorbet_includes', $sorbet_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->urlSorbet);
  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->urlSorbet);
  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 = $rs->fetch()) {
  88. $formatedDate = gmdate("M d", strtotime($register["date"]) + $util_class->transform_offset($conf->offsetTime));
  89. if ($dateTmp != null && $formatedDate == $dateTmp) {
  90. $formatedDate = "";
  91. } else {
  92. $dateTmp = $formatedDate;
  93. }
  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'] = $util_class->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/".$util_class->getFileName($register["url"]);
  108. $x = @getimagesize($fileName);
  109. if ($x[0] > 500) {
  110. $photoPath = $conf->urlSorbet."/classes/imgsize.php?w=500&img=".$register["url"];
  111. } else {
  112. $photoPath = str_replace("../", $conf->urlSorbet."/", $register["url"]);
  113. }
  114. $effect = " href=\"".str_replace("../", $conf->urlSorbet."/", $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"] = $util_class->_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. $trigger->call('post_content');
  155. $theme->set('rows', $rows);
  156. $p = new pagination;
  157. $p->Items($tumble->getPostsNumber());
  158. $p->limit($limit);
  159. if ($conf->urlFriendly) {
  160. $p->urlFriendly('[...]');
  161. $p->target($conf->urlSorbet."/page/[...]");
  162. } else {
  163. $p->target($conf->urlSorbet);
  164. }
  165. $p->currentPage(isset($page_num) ? $page_num : 1);
  166. $theme->set('pagination', $p->getPagination());
  167. } else {
  168. $theme->set('error', 'No posts in this tumblelog.');
  169. }
  170. } else {
  171. $register = $tumble->getPost($id_post);
  172. $formatedDate = gmdate("M d", strtotime($register["date"]) + $util_class->transform_offset($conf->offsetTime));
  173. $permalink = $tumble->getPermalink($register["id_post"]);
  174. $conversation = $register["description"];
  175. $register["description"] = $register["description"];
  176. $register["title"] = stripslashes($register["title"]);
  177. $register["description"] = stripslashes($register["description"]);
  178. $row['Date_Added'] = $formatedDate;
  179. $row['Permalink'] = $permalink;
  180. $row['postType'] = $util_class->type2Text($register["type"]);
  181. switch ($register['type']) {
  182. case "1":
  183. $row['Title'] = $register["title"];
  184. $row['Body'] = $register["description"];
  185. break;
  186. case "2":
  187. $fileName = "uploads/".$util_class->getFileName($register["url"]);
  188. $x = @getimagesize($fileName);
  189. if ($x[0] > 500) {
  190. $photoPath = $conf->urlSorbet."/classes/imgsize.php?w=500&img=".$register["url"];
  191. } else {
  192. $photoPath = str_replace("../", $conf->urlSorbet."/", $register["url"]);
  193. }
  194. $effect = " href=\"".str_replace("../", $conf->urlSorbet."/", $register["url"])."\" rel=\"lightbox\"";
  195. $row['PhotoURL'] = $photoPath;
  196. $row['PhotoAlt'] = strip_tags($register["description"]);
  197. $row['Caption'] = $register["description"];
  198. $row['Effect'] = $effect;
  199. break;
  200. case "3":
  201. $row['Quote'] = $register["description"];
  202. $row['Source'] = $register["title"];
  203. break;
  204. case "4":
  205. if ($conf->shorten_links) {
  206. $register["url"] = $util_class->_file_get_contents("http://api.abbrr.com/api.php?out=link&url=".$register["url"]);
  207. }
  208. $row['URL'] = $register["url"];
  209. $row['Name'] = $register["title"];
  210. $row['Description'] = $register["description"];
  211. break;
  212. case "5":
  213. $row['Title'] = $register["title"];
  214. $row['Conversation'] = $tumble->formatConversation($conversation);
  215. break;
  216. case "6":
  217. $row['Video'] = $tumble->getVideoPlayer($register["url"]);
  218. $row['Caption'] = $register["description"];
  219. break;
  220. case "7":
  221. $row['Mp3'] = $tumble->getMp3Player($register["url"]);
  222. $row['Caption'] = $register["description"];
  223. break;
  224. }
  225. $user = new user();
  226. $username = $user->getUserByID($register["id_user"]);
  227. $row["User"] = $username["name"];
  228. if (empty($register["title"])) {
  229. if (!empty($register["description"])) {
  230. $postTitle = $util_class->trimString($register["description"]);
  231. } else {
  232. $postTitle = $util_class->type2Text($register["type"]);
  233. }
  234. } else {
  235. $postTitle = $register["title"];
  236. }
  237. $row["Post_Title"] = $postTitle;
  238. $comment = new comments();
  239. $row["Comments_Number"] = $comment->countComments($register["id_post"]);
  240. if ($conf->allowComments) {
  241. $rsComments = $comment->getComments($register["id_post"]);
  242. $comments = array();
  243. while ($rowComment = $rsComments->fetch()) {
  244. $commentAuthor = ($rowComment["web"]=="") ? $rowComment["username"] : "<a href=\"".$rowComment["web"]."\" rel=\"external\">".$rowComment["username"]."</a>";
  245. $answers['Id_Comment'] = $rowComment["id_comment"];
  246. $answers['Comment_Author'] = $commentAuthor;
  247. $answers['Date'] = gmdate("d.m.y", strtotime($rowComment["comment_date"]) + $util_class->transform_offset($conf->offsetTime));
  248. $answers['Comment'] = nl2br($rowComment["content"]);
  249. $comments[] = $answers;
  250. }
  251. $theme->set('comments', $comments);
  252. $whois['User_Cookie'] = isset($_COOKIE['cookie_sor_user'])?$_COOKIE['cookie_sor_user']:'';
  253. $whois['Email_Cookie'] = isset($_COOKIE['cookie_sor_email'])?$_COOKIE['cookie_sor_email']:'';
  254. $whois['Web_Cookie'] = isset($_COOKIE['cookie_sor_web'])?$_COOKIE['cookie_sor_web']:'';
  255. $whois['Id_Post'] = $register["id_post"];
  256. $theme->set('Date_Added', time());
  257. $theme->set('Form_Action', $conf->urlSorbet."/admin/comments.php");
  258. $theme->set('whois', $whois);
  259. }
  260. $rows[] = $row;
  261. $trigger->call('post_content');
  262. $theme->set('rows', $rows);
  263. }
  264. $theme->set('URL_Tumble', $conf->urlSorbet);
  265. $theme->display(Absolute_Path.'themes/'.$conf->template.'/index.htm');