A tumblelog CMS built on AJAX, PHP and MySQL.

index.php 11KB

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