A tumblelog CMS built on AJAX, PHP and MySQL.

index.php 15KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  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. require '../entry.php';
  12. global $user, $conf, $tumble;
  13. #$template = new plantillas("admin");
  14. $theme = new themes;
  15. $isEdition = (isset($_GET["edit"])) ? true : false;
  16. $postId = ($isEdition) ? $_GET["edit"] : null;
  17. $theme->set('isEdition', $isEdition);
  18. $theme->set('postId', $postId);
  19. $theme->set('pagination', '');
  20. if (get_magic_quotes_gpc()) {
  21. foreach ($_GET as $k=>$get) {
  22. $_GET[$k]=stripslashes($get);
  23. }
  24. }
  25. $util_class = new util();
  26. if ($user->isAuthenticated()) {
  27. if (isset($_GET["delete"])) {
  28. $tumble->deletePost($_GET['delete']);
  29. header("Location: index.php?deleted=true");
  30. die();
  31. }
  32. if (isset($_POST["btnAdd"])) {
  33. unset($_POST["btnAdd"]);
  34. $_POST['type'] = $util_class->type2Number($_POST['type']);
  35. if ($_POST["type"]=="2") { // is Photo type
  36. if (isset($_POST["url"]) && $_POST["url"]!="") {
  37. $photoName = $util_class->getFileName($_POST["url"]);
  38. if (!$tumble->savePhoto($_POST["url"])) {
  39. header("Location: ".$conf->urlSorbet."/admin/index.php?photo=false");
  40. die();
  41. }
  42. $_POST["url"] = "../uploads/".$util_class->sanitizeName($photoName);
  43. }
  44. if (move_uploaded_file($_FILES['photo']['tmp_name'], "../uploads/".$util_class->sanitizeName($_FILES['photo']['name']))) {
  45. $_POST["url"] = "../uploads/".$util_class->sanitizeName($_FILES['photo']['name']);
  46. }
  47. unset($_POST["photo"]);
  48. unset($_POST["MAX_FILE_SIZE"]);
  49. }
  50. if ($_POST["type"]=="7") { // is MP3 type
  51. set_time_limit(300);
  52. if (isset($_POST["url"]) && $_POST["url"]!="") {
  53. $mp3Name = $util_class->getFileName($_POST["url"]);
  54. if (!$tumble->saveMP3($_POST["url"])) {
  55. header("Location: ".$conf->urlSorbet."/admin/index.php?mp3=false");
  56. die();
  57. }
  58. $_POST["url"] = $conf->urlSorbet."/uploads/".$mp3Name;
  59. }
  60. if (move_uploaded_file($_FILES['mp3']['tmp_name'], "../uploads/".$util_class->sanitizeName($_FILES['mp3']['name']))) {
  61. $_POST["url"] = $conf->urlSorbet."/uploads/".$util_class->sanitizeName($_FILES['mp3']['name']);
  62. }
  63. unset($_POST["mp3"]);
  64. unset($_POST["MAX_FILE_SIZE"]);
  65. }
  66. if (!get_magic_quotes_gpc()) {
  67. $_POST["title"] = addslashes($_POST["title"]);
  68. $_POST["description"] = addslashes($_POST["description"]);
  69. }
  70. /*
  71. $textile = new Textile();
  72. $_POST["title"] = $textile->TextileThis(removeBadTags($_POST["title"],true));
  73. $_POST["description"] = $textile->TextileThis(removeBadTags($_POST["description"]));
  74. */
  75. $_POST["title"] = $util_class->removeBadTags($_POST["title"], true);
  76. $_POST["description"] = $util_class->removeBadTags($_POST["description"]);
  77. if (isset($_POST["id_post"]) and is_numeric($_POST["id_post"]) and $_POST["id_post"]>0) {
  78. $tumble->modifyPost($_POST, $_POST["id_post"]);
  79. } else {
  80. if ($tumble->addPost($_POST)) {
  81. header("Location: ".$conf->urlSorbet."/admin/index.php?added=true");
  82. die();
  83. } else {
  84. header("Location: ".$conf->urlSorbet."/admin/index.php?error=2&des=".$tumble->merror);
  85. die();
  86. }
  87. }
  88. } else {
  89. if ($isEdition) {
  90. $post = $tumble->getPost($postId);
  91. }
  92. $admin_includes = "";
  93. $trigger->call('admin_includes');
  94. $theme->set('admin_includes', $admin_includes);
  95. $theme->set('version', $util_class->version());
  96. $theme->set('conf', array(
  97. 'urlSorbet'=>$conf->urlSorbet,
  98. 'richText'=>$conf->richText
  99. ));
  100. $theme->set('new', isset($_GET['new'])?$_GET['new']:'');
  101. $theme->set('information', false);
  102. $theme->set('error', false);
  103. if ($conf->check_version) {
  104. $present = $util_class->version();
  105. $lastest = "1.0";//$util_class->_file_get_contents("");
  106. if ($present < $lastest) {
  107. $theme->set('information', __("A new version has been released and is ready for download."));
  108. }
  109. }
  110. $actions = array(
  111. 'deleted'=>false,
  112. 'modified'=>false,
  113. 'added'=>false
  114. );
  115. if (isset($_GET['deleted']) and $_GET['deleted']=='true') {
  116. $theme->set('exito', __("The post has been eliminated successfully."));
  117. $actions['deleted'] = true;
  118. }
  119. if (isset($_GET["modified"]) and $_GET["modified"]==true) {
  120. $theme->set('exito', __("The post has been modified successfully."));
  121. $actions['modified']=true;
  122. }
  123. if (isset($_GET["added"]) and $_GET["added"]==true) {
  124. $theme->set('exito', __("The post has been added successfully."));
  125. $actions['added']=true;
  126. }
  127. $theme->set('action', $actions);
  128. if (isset($_GET["error"]) and $_GET["error"]==2) {
  129. $theme->set('error', __("Error on the database server:")." </strong>".$_GET["des"]);
  130. }
  131. if (isset($_GET["mp3"]) and $_GET["mp3"]=='false') {
  132. $theme->set('error', __("Not an MP3 file or an upload problem."));
  133. }
  134. if (isset($_GET["photo"]) and $_GET["photo"]=='false') {
  135. $theme->set('error', __("Not a photo file or an upload problem."));
  136. }
  137. if ($isEdition) {
  138. switch ($post["type"]) {
  139. case "1": $_GET["new"] = "post"; break;
  140. case "2": $_GET["new"] = "photo"; break;
  141. case "3": $_GET["new"] = "quote"; break;
  142. case "4": $_GET["new"] = "url"; break;
  143. case "5": $_GET["new"] = "conversation"; break;
  144. case "6": $_GET["new"] = "video"; break;
  145. case "7": $_GET["new"] = "mp3"; break;
  146. }
  147. }
  148. $date = ($isEdition) ? strtotime($post["date"]) : time();
  149. $title = ($isEdition) ? htmlspecialchars(stripslashes($post["title"])) : "";
  150. $body = ($isEdition) ? stripslashes($post["description"]) : "";
  151. $url = ($isEdition) ? $post["url"] : "";
  152. if (!isset($_GET['new'])) {
  153. $_GET['new'] = 'post';
  154. }
  155. $form = new themes;
  156. $form->set('date', $date);
  157. $form->set('id_user', $_SESSION['user_id']);
  158. $form->set('type', $_GET["new"]);
  159. $form->set('editBody', $body);
  160. switch ($_GET["new"]) {
  161. case "post":
  162. $form->set('editTitle', $title);
  163. $theme->set('form', $form->fetch(Absolute_Path.'admin/themes/admin/template_add_post.htm'));
  164. break;
  165. case "photo":
  166. $url = str_replace("../", $conf->urlSorbet."/", $url);
  167. $form->set('editUrl', $url);
  168. $theme->set('form', $form->fetch(Absolute_Path.'admin/themes/admin/template_add_photo.htm'));
  169. break;
  170. case "quote":
  171. $form->set('editTitle', $title);
  172. $theme->set('form', $form->fetch(Absolute_Path.'admin/themes/admin/template_add_quote.htm'));
  173. break;
  174. case "url":
  175. $form->set('editTitle', $title);
  176. $form->set('editUrl', $url);
  177. $theme->set('form', $form->fetch(Absolute_Path.'admin/themes/admin/template_add_link.htm'));
  178. break;
  179. case "conversation":
  180. $form->set('editTitle', $title);
  181. $theme->set('form', $form->fetch(Absolute_Path.'admin/themes/admin/template_add_conversation.htm'));
  182. break;
  183. case "video":
  184. $form->set('editUrl', $url);
  185. $theme->set('form', $form->fetch(Absolute_Path.'admin/themes/admin/template_add_video.htm'));
  186. break;
  187. case "mp3":
  188. $form->set('editUrl', $url);
  189. $theme->set('form', $form->fetch(Absolute_Path.'admin/themes/admin/template_add_mp3.htm'));
  190. break;
  191. }
  192. if (!$isEdition) {
  193. if (isset($_GET["page"])) {
  194. $page_num = $_GET["page"];
  195. } else {
  196. $page_num = null;
  197. }
  198. $limit=$conf->postLimit;
  199. if (isset($page_num) && is_numeric($page_num) && $page_num>0) {// Is defined the page and is numeric?
  200. $from = (($page_num-1) * $limit);
  201. } else {
  202. $from = 0;
  203. }
  204. $rs = $tumble->getPosts($limit, $from);
  205. $theme->set('Posts_Number', $db->contarRegistros());
  206. $rows = array();
  207. if ($db->contarRegistros()>0) {
  208. while ($register = $rs->fetch()) {
  209. $row['postType'] = $util_class->type2Text($tumble->getType($register["id_post"]));
  210. $formatedDate = gmdate("M d", strtotime($register["date"]) + $util_class->transform_offset($conf->offsetTime));
  211. $strEnd=($conf->urlFriendly) ? "/" : "";
  212. $permalink = $conf->urlSorbet.($conf->urlFriendly?"/post/":"/index.php?post=").$register["id_post"].$strEnd;
  213. $register["title"] = stripslashes($register["title"]);
  214. $register["description"] = stripslashes($register["description"]);
  215. $row['Id_Post'] = $register["id_post"];
  216. $row['Date_Added'] = $formatedDate;
  217. $row['Permalink'] = $permalink;
  218. switch ($tumble->getType($register["id_post"])) {
  219. case "1":
  220. $row['Title'] = $register["title"];
  221. $row['Body'] = $register["description"];
  222. break;
  223. case "2":
  224. $fileName = "../uploads/".$util_class->getFileName($register["url"]);
  225. $x = @getimagesize($fileName);
  226. if ($x[0] > 100) {
  227. $photoPath = $conf->urlSorbet."/classes/imgsize.php?w=100&img=".$register["url"];
  228. } else {
  229. $photoPath = $register["url"];
  230. }
  231. $effect = " href=\"".str_replace("../", $conf->urlSorbet."/", $register["url"])."\" rel=\"lightbox\"";
  232. $row['PhotoURL'] = $photoPath;
  233. $row['PhotoAlt'] = strip_tags($register["description"]);
  234. $row['Caption'] = $register["description"];
  235. $row['Effect'] = $effect;
  236. break;
  237. case "3":
  238. $row['Quote'] = $register["description"];
  239. $row['Source'] = $register["title"];
  240. break;
  241. case "4":
  242. if ($conf->shorten_links) {
  243. $register["url"] = $util_class->_file_get_contents("http://api.abbrr.com/api.php?out=link&url=".$register["url"]);
  244. }
  245. $register["title"] = ($register["title"]=="")? $register["url"] : $register["title"];
  246. $row['URL'] = $register["url"];
  247. $row['Name'] = $register["title"];
  248. $row['Description'] = $register["description"];
  249. break;
  250. case "5":
  251. $row['Title'] = $register["title"];
  252. $row['Conversation'] = $tumble->formatConversation($register["description"]);
  253. break;
  254. case "6":
  255. $row['Video'] = $tumble->getVideoPlayer($register["url"]);
  256. $row['Caption'] = $register["description"];
  257. break;
  258. case "7":
  259. $row['Mp3'] = $tumble->getMp3Player($register["url"]);
  260. $row['Caption'] = $register["description"];
  261. break;
  262. }
  263. $rows[] = $row;
  264. }
  265. $p = new pagination;
  266. $p->items($tumble->getPostsNumber());
  267. $p->limit($limit);
  268. $p->currentPage(isset($page_num) ? $page_num : 1);
  269. $theme->set('pagination', $p->getPagination());
  270. $theme->set('rows', $rows);
  271. } else {
  272. $theme->set('error', __("No posts in this tumblelog."));
  273. }
  274. }
  275. $theme->display(Absolute_Path.'admin/themes/admin/index.htm');
  276. }
  277. } else {
  278. header("Location: ".$conf->urlSorbet."/login.php");
  279. }