A tumblelog CMS built on AJAX, PHP and MySQL.

index.php 15KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  1. <?php
  2. if (!defined('entry')) {
  3. define('entry', true);
  4. }
  5. /* ===========================
  6. Sorbet CMS - A PHP based tumblelog CMS forked from Gelato CMS
  7. Sorbet CMS is a free software licensed under the GPL 3.0
  8. =========================== */
  9. ?>
  10. <?php
  11. // Received a valid request
  12. require_once('entry.php');
  13. global $user, $tumble, $conf;
  14. $theme = new themes;
  15. $util_class = new util();
  16. // Our first approach to MVC... our second? visit http://www.flavorphp.com
  17. if (isset($_SERVER['PATH_INFO'])) {
  18. $param_url = explode("/", $_SERVER['PATH_INFO']);
  19. }
  20. if (isset($_GET["post"])) {
  21. $id_post = $_GET["post"];
  22. if (!is_numeric($id_post) || $id_post < 1) {
  23. header("Location: index.php");
  24. }
  25. } else {
  26. if (isset($param_url[1]) && $param_url[1]=="post") {
  27. $id_post = (isset($param_url[2])) ? ((is_numeric($param_url[2])) ? $param_url[2] : null) : null;
  28. } else {
  29. $id_post = null;
  30. }
  31. }
  32. $theme->set('id_post', $id_post);
  33. $theme->set('error', '');
  34. if (isset($_GET["page"])) {
  35. $page_num = $_GET["page"];
  36. } else {
  37. if (isset($param_url[1]) && $param_url[1]=="page") {
  38. $page_num = (isset($param_url[2])) ? ((is_numeric($param_url[2])) ? $param_url[2] : null) : null;
  39. } else {
  40. $page_num = null;
  41. }
  42. }
  43. $feed_url = $conf->urlSorbet.($conf->urlFriendly?"/rss/":"/rss.php");
  44. $sorbet_includes = "<meta name=\"generator\" content=\"sorbet ".$util_class -> codeName()." (".$util_class -> version().")\" />\n";
  45. $sorbet_includes .= "\t<link rel=\"shortcut icon\" href=\"".$conf->urlSorbet."/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 = $util_class->trimString($register["description"], $page_title_len);
  54. } else {
  55. $page_title_data = $util_class->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('sorbet_includes');
  65. $theme->set('rssFeed', $feed_url);
  66. $theme->set('Sorbet_includes', $sorbet_includes);
  67. $theme->set('Title', $conf->title);
  68. $theme->set('Page_Title', $page_title);
  69. $theme->set('Description', $conf->description);
  70. $theme->set('URL_Tumble', $conf->urlSorbet);
  71. $theme->set('Template_name', $conf->template);
  72. $theme->set('allowComments', $conf->allowComments);
  73. $theme->set('isAuthenticated', $user->isAuthenticated());
  74. if ($user->isAuthenticated()) {
  75. $theme->set('User', $_SESSION["user_login"]);
  76. $theme->set('URL_Tumble', $conf->urlSorbet);
  77. }
  78. $rows = array();
  79. if (!$id_post) {
  80. $limit=$conf->postLimit;
  81. if (isset($page_num) && is_numeric($page_num) && $page_num>0) { // Is defined the page and is numeric?
  82. $from = (($page_num-1) * $limit);
  83. } else {
  84. $from = 0;
  85. }
  86. $rs = $tumble->getPosts($limit, $from);
  87. if ($db->contarRegistros()>0) {
  88. $dateTmp = null;
  89. while ($register = $rs->fetch()) {
  90. $formatedDate = gmdate("M d", strtotime($register["date"]) + $util_class->transform_offset($conf->offsetTime));
  91. if ($dateTmp != null && $formatedDate == $dateTmp) {
  92. $formatedDate = "";
  93. } else {
  94. $dateTmp = $formatedDate;
  95. }
  96. $permalink = $tumble->getPermalink($register["id_post"]);
  97. $conversation = $register["description"];
  98. $register["title"] = stripslashes($register["title"]);
  99. $register["description"] = stripslashes($register["description"]);
  100. $row['Date_Added'] = $formatedDate;
  101. $row['Permalink'] = $permalink;
  102. $row['postType'] = $util_class->type2Text($register["type"]);
  103. switch ($register['type']) {
  104. case "1":
  105. $row['Title'] = $register["title"];
  106. $row['Body'] = $register["description"];
  107. break;
  108. case "2":
  109. $fileName = "uploads/".$util_class->getFileName($register["url"]);
  110. $x = @getimagesize($fileName);
  111. if ($x[0] > 500) {
  112. $photoPath = $conf->urlSorbet."/classes/imgsize.php?w=500&img=".$register["url"];
  113. } else {
  114. $photoPath = str_replace("../", $conf->urlSorbet."/", $register["url"]);
  115. }
  116. $effect = " href=\"".str_replace("../", $conf->urlSorbet."/", $register["url"])."\" rel=\"lightbox\"";
  117. $row['PhotoURL'] = $photoPath;
  118. $row['PhotoAlt'] = strip_tags($register["description"]);
  119. $row['Caption'] = $register["description"];
  120. $row['Effect'] = $effect;
  121. break;
  122. case "3":
  123. $row['Quote'] = $register["description"];
  124. $row['Source'] = $register["title"];
  125. break;
  126. case "4":
  127. if ($conf->shorten_links) {
  128. $register["url"] = $util_class->_file_get_contents("http://api.abbrr.com/api.php?out=link&url=".$register["url"]);
  129. }
  130. $register["title"] = ($register["title"]=="")? $register["url"] : $register["title"];
  131. $row['URL'] = $register["url"];
  132. $row['Name'] = $register["title"];
  133. $row['Description'] = $register["description"];
  134. break;
  135. case "5":
  136. $row['Title'] = $register["title"];
  137. $row['Conversation'] = $tumble->formatConversation($conversation);
  138. break;
  139. case "6":
  140. $row['Video'] = $tumble->getVideoPlayer($register["url"]);
  141. $row['Caption'] = $register["description"];
  142. break;
  143. case "7":
  144. $row['Mp3'] = $tumble->getMp3Player($register["url"]);
  145. $row['Caption'] = $register["description"];
  146. break;
  147. }
  148. $comment = new comments();
  149. $noComments = $comment->countComments($register["id_post"]);
  150. $user = new user();
  151. $username = $user->getUserByID($register["id_user"]);
  152. $row['User'] = $username["name"];
  153. $row['Comments_Number'] = $noComments;
  154. $rows[] = $row;
  155. }
  156. $trigger->call('post_content');
  157. $theme->set('rows', $rows);
  158. $p = new pagination;
  159. $p->Items($tumble->getPostsNumber());
  160. $p->limit($limit);
  161. if ($conf->urlFriendly) {
  162. $p->urlFriendly('[...]');
  163. $p->target($conf->urlSorbet."/page/[...]");
  164. } else {
  165. $p->target($conf->urlSorbet);
  166. }
  167. $p->currentPage(isset($page_num) ? $page_num : 1);
  168. $theme->set('pagination', $p->getPagination());
  169. } else {
  170. $theme->set('error', 'No posts in this tumblelog.');
  171. }
  172. } else {
  173. $register = $tumble->getPost($id_post);
  174. $formatedDate = gmdate("M d", strtotime($register["date"]) + $util_class->transform_offset($conf->offsetTime));
  175. $permalink = $tumble->getPermalink($register["id_post"]);
  176. $conversation = $register["description"];
  177. $register["description"] = $register["description"];
  178. $register["title"] = stripslashes($register["title"]);
  179. $register["description"] = stripslashes($register["description"]);
  180. $row['Date_Added'] = $formatedDate;
  181. $row['Permalink'] = $permalink;
  182. $row['postType'] = $util_class->type2Text($register["type"]);
  183. switch ($register['type']) {
  184. case "1":
  185. $row['Title'] = $register["title"];
  186. $row['Body'] = $register["description"];
  187. break;
  188. case "2":
  189. $fileName = "uploads/".$util_class->getFileName($register["url"]);
  190. $x = @getimagesize($fileName);
  191. if ($x[0] > 500) {
  192. $photoPath = $conf->urlSorbet."/classes/imgsize.php?w=500&img=".$register["url"];
  193. } else {
  194. $photoPath = str_replace("../", $conf->urlSorbet."/", $register["url"]);
  195. }
  196. $effect = " href=\"".str_replace("../", $conf->urlSorbet."/", $register["url"])."\" rel=\"lightbox\"";
  197. $row['PhotoURL'] = $photoPath;
  198. $row['PhotoAlt'] = strip_tags($register["description"]);
  199. $row['Caption'] = $register["description"];
  200. $row['Effect'] = $effect;
  201. break;
  202. case "3":
  203. $row['Quote'] = $register["description"];
  204. $row['Source'] = $register["title"];
  205. break;
  206. case "4":
  207. if ($conf->shorten_links) {
  208. $register["url"] = $util_class->_file_get_contents("http://api.abbrr.com/api.php?out=link&url=".$register["url"]);
  209. }
  210. $row['URL'] = $register["url"];
  211. $row['Name'] = $register["title"];
  212. $row['Description'] = $register["description"];
  213. break;
  214. case "5":
  215. $row['Title'] = $register["title"];
  216. $row['Conversation'] = $tumble->formatConversation($conversation);
  217. break;
  218. case "6":
  219. $row['Video'] = $tumble->getVideoPlayer($register["url"]);
  220. $row['Caption'] = $register["description"];
  221. break;
  222. case "7":
  223. $row['Mp3'] = $tumble->getMp3Player($register["url"]);
  224. $row['Caption'] = $register["description"];
  225. break;
  226. }
  227. $user = new user();
  228. $username = $user->getUserByID($register["id_user"]);
  229. $row["User"] = $username["name"];
  230. if (empty($register["title"])) {
  231. if (!empty($register["description"])) {
  232. $postTitle = $util_class->trimString($register["description"]);
  233. } else {
  234. $postTitle = $util_class->type2Text($register["type"]);
  235. }
  236. } else {
  237. $postTitle = $register["title"];
  238. }
  239. $row["Post_Title"] = $postTitle;
  240. $comment = new comments();
  241. $row["Comments_Number"] = $comment->countComments($register["id_post"]);
  242. if ($conf->allowComments) {
  243. $rsComments = $comment->getComments($register["id_post"]);
  244. $comments = array();
  245. while ($rowComment = $rsComments->fetch()) {
  246. $commentAuthor = ($rowComment["web"]=="") ? $rowComment["username"] : "<a href=\"".$rowComment["web"]."\" rel=\"external\">".$rowComment["username"]."</a>";
  247. $answers['Id_Comment'] = $rowComment["id_comment"];
  248. $answers['Comment_Author'] = $commentAuthor;
  249. $answers['Date'] = gmdate("d.m.y", strtotime($rowComment["comment_date"]) + $util_class->transform_offset($conf->offsetTime));
  250. $answers['Comment'] = nl2br($rowComment["content"]);
  251. $comments[] = $answers;
  252. }
  253. $theme->set('comments', $comments);
  254. $whois['User_Cookie'] = isset($_COOKIE['cookie_sor_user'])?$_COOKIE['cookie_sor_user']:'';
  255. $whois['Email_Cookie'] = isset($_COOKIE['cookie_sor_email'])?$_COOKIE['cookie_sor_email']:'';
  256. $whois['Web_Cookie'] = isset($_COOKIE['cookie_sor_web'])?$_COOKIE['cookie_sor_web']:'';
  257. $whois['Id_Post'] = $register["id_post"];
  258. $theme->set('Date_Added', gmmktime());
  259. $theme->set('Form_Action', $conf->urlSorbet."/admin/comments.php");
  260. $theme->set('whois', $whois);
  261. }
  262. $rows[] = $row;
  263. $trigger->call('post_content');
  264. $theme->set('rows', $rows);
  265. }
  266. $theme->set('URL_Tumble', $conf->urlSorbet);
  267. $theme->display(Absolute_Path.'themes/'.$conf->template.'/index.htm');
  268. ?>