A tumblelog CMS built on AJAX, PHP and MySQL.

index.php 20KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465
  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. $isEdition = (isset($_GET["edit"])) ? true : false;
  16. $postId = ($isEdition) ? $_GET["edit"] : NULL;
  17. if ($user->isAuthenticated()) {
  18. if (isset($_GET["delete"])) {
  19. $tumble->deletePost($_GET['delete']);
  20. header("Location: index.php?deleted=true");
  21. die();
  22. }
  23. if(isset($_POST["btnAdd"])) {
  24. unset($_POST["btnAdd"]);
  25. if ($_POST["type"]=="2") { // is Photo type
  26. if (isset($_POST["url"]) && $_POST["url"]!="") {
  27. $photoName = getFileName($_POST["url"]);
  28. if (!$tumble->savePhoto($_POST["url"])) {
  29. header("Location: ".$conf->urlGelato."/admin/index.php?photo=false");
  30. die();
  31. }
  32. $_POST["url"] = "../uploads/".sanitizeName($photoName);
  33. }
  34. if ( move_uploaded_file( $_FILES['photo']['tmp_name'], "../uploads/".sanitizeName($_FILES['photo']['name']) ) ) {
  35. $_POST["url"] = "../uploads/".sanitizeName($_FILES['photo']['name']);
  36. }
  37. unset($_POST["photo"]);
  38. unset($_POST["MAX_FILE_SIZE"]);
  39. }
  40. if ($_POST["type"]=="7") { // is MP3 type
  41. set_time_limit(300);
  42. $mp3Name = getFileName($_POST["url"]);
  43. if (!$tumble->saveMP3($_POST["url"])) {
  44. header("Location: ".$conf->urlGelato."/admin/index.php?mp3=false");
  45. die();
  46. }
  47. if (isMP3($remoteFileName)) {
  48. $_POST["url"] = $conf->urlGelato."/uploads/".$mp3Name;
  49. }
  50. }
  51. if (!get_magic_quotes_gpc()) {
  52. $_POST["title"] = addslashes($_POST["title"]);
  53. $_POST["description"] = addslashes($_POST["description"]);
  54. }
  55. /*
  56. $textile = new Textile();
  57. $_POST["title"] = $textile->TextileThis(removeBadTags($_POST["title"],true));
  58. $_POST["description"] = $textile->TextileThis(removeBadTags($_POST["description"]));
  59. */
  60. $_POST["title"] = removeBadTags($_POST["title"],true);
  61. $_POST["description"] = removeBadTags($_POST["description"]);
  62. if (isset($_POST["id_post"])) {
  63. $tumble->modifyPost($_POST, $_POST["id_post"]);
  64. } else {
  65. if ($tumble->addPost($_POST)) {
  66. header("Location: ".$conf->urlGelato."/admin/index.php?added=true");
  67. die();
  68. } else {
  69. header("Location: ".$conf->urlGelato."/admin/index.php?error=2&des=".$this->merror);
  70. die();
  71. }
  72. }
  73. } else {
  74. if ($isEdition) {
  75. $post = $tumble->getPost($postId);
  76. }
  77. ?>
  78. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  79. <html xmlns="http://www.w3.org/1999/xhtml">
  80. <head>
  81. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  82. <meta name="generator" content="gelato cms <?php echo version();?>" />
  83. <title>gelato :: <?php echo __("control panel")?></title>
  84. <link rel="shortcut icon" href="<?php echo $conf->urlGelato;?>/images/favicon.ico" />
  85. <script language="javascript" type="text/javascript" src="<?php echo $conf->urlGelato;?>/admin/scripts/jquery.js"></script>
  86. <script language="javascript" type="text/javascript" src="<?php echo $conf->urlGelato;?>/admin/scripts/tools.js"></script>
  87. <script language="javascript" type="text/javascript" src="<?php echo $conf->urlGelato;?>/admin/scripts/lightbox.js"></script>
  88. <script language="javascript" type="text/javascript" src="<?php echo $conf->urlGelato;?>/admin/scripts/jquery.validate.min.js"></script>
  89. <script language="javascript" type="text/javascript">
  90. $(document).ready(function(){
  91. $("#divMessages").fadeOut(5000,function(){
  92. $("#divMessages").css({display:"none"});
  93. });
  94. });
  95. Lightbox.fileLoadingImage = "css/images/loading.gif";
  96. Lightbox.fileBottomNavCloseImage = "css/images/closelabel.gif";
  97. </script>
  98. <?php
  99. if($conf->richText) {
  100. ?>
  101. <script src="<?php echo $conf->urlGelato;?>/admin/scripts/nicEdit.js" type="text/javascript"></script>
  102. <script type="text/javascript">
  103. bkLib.onDomLoaded(nicEditors.allTextAreas);
  104. </script>
  105. <?php
  106. } else {
  107. ?>
  108. <script type="text/javascript" src="<?php echo $conf->urlGelato;?>/admin/scripts/markitup/jquery.markitup.pack.js"></script>
  109. <script type="text/javascript" src="<?php echo $conf->urlGelato;?>/admin/scripts/markitup/sets/html/set.js"></script>
  110. <link rel="stylesheet" type="text/css" href="<?php echo $conf->urlGelato;?>/admin/scripts/markitup/skins/simple/style.css" />
  111. <link rel="stylesheet" type="text/css" href="<?php echo $conf->urlGelato;?>/admin/scripts/markitup/sets/html/style.css" />
  112. <script type="text/javascript" >
  113. $(document).ready(function() {
  114. $("#description").markItUp(my_html);
  115. });
  116. </script>
  117. <?php
  118. }
  119. ?>
  120. <style type="text/css" media="screen">
  121. @import "<?php echo $conf->urlGelato;?>/admin/css/style.css";
  122. @import "<?php echo $conf->urlGelato;?>/admin/css/lightbox.css";
  123. </style>
  124. </head>
  125. <body>
  126. <div id="div-process" style="display:none;"><?php echo __("Processing request&hellip;")?></div>
  127. <div id="cont">
  128. <div id="head">
  129. <h1><a href="<?php echo $conf->urlGelato;?>/admin/index.php" title="gelato :: <?php echo __("home")?>">gelato cms</a></h1>
  130. <ul id="nav">
  131. <li><a href="<?php echo $conf->urlGelato;?>/" title="<?php echo __("Take me to the tumblelog")?>"><?php echo __("View Tumblelog")?></a></li>
  132. <li><a href="close.php" title="Log off" ><?php echo __("Log out")?></a></li>
  133. </ul>
  134. </div>
  135. <div id="main">
  136. <div class="box">
  137. <ul class="menu">
  138. <h3><?php echo __("New Post")?></h3>
  139. <li<?php echo (isset($_GET["new"]) && $_GET["new"]=="conversation") ? " class=\"selected\"" : ""; ?>><a href="<?php echo $conf->urlGelato;?>/admin/index.php?new=conversation"><img src="css/images/comments.png" alt="New chat" /> <?php echo __("Chat")?></a></li>
  140. <li<?php echo (isset($_GET["new"]) && $_GET["new"]=="quote") ? " class=\"selected\"" : ""; ?>><a href="<?php echo $conf->urlGelato;?>/admin/index.php?new=quote"><img src="css/images/quote.png" alt="New qoute" /> <?php echo __("Quote")?></a></li>
  141. <li<?php echo (isset($_GET["new"]) && $_GET["new"]=="url") ? " class=\"selected\"" : ""; ?>><a href="<?php echo $conf->urlGelato;?>/admin/index.php?new=url"><img src="css/images/world.png" alt="New link" /> <?php echo __("Link")?></a></li>
  142. <li<?php echo (isset($_GET["new"]) && $_GET["new"]=="mp3") ? " class=\"selected\"" : ""; ?>><a href="<?php echo $conf->urlGelato;?>/admin/index.php?new=mp3"><img src="css/images/music.png" alt="New audio" /> <?php echo __("Audio")?></a></li>
  143. <li<?php echo (isset($_GET["new"]) && $_GET["new"]=="video") ? " class=\"selected\"" : ""; ?>><a href="<?php echo $conf->urlGelato;?>/admin/index.php?new=video"><img src="css/images/film.png" alt="New video" /> <?php echo __("Video")?></a></li>
  144. <li<?php echo (isset($_GET["new"]) && $_GET["new"]=="photo") ? " class=\"selected\"" : ""; ?>><a href="<?php echo $conf->urlGelato;?>/admin/index.php?new=photo"><img src="css/images/image.png" alt="New picture" /> <?php echo __("Picture")?></a></li>
  145. <li<?php echo (isset($_GET["new"]) && $_GET["new"]=="post") ? " class=\"selected\"" : ""; echo (!isset($_GET["new"])) ? " class=\"selected\"" : ""; ?>><a href="<?php echo $conf->urlGelato;?>/admin/index.php?new=post"><img src="css/images/page.png" alt="New post" /> <?php echo __("Regular")?></a></li>
  146. </ul>
  147. <p>&nbsp;</p>
  148. <?php
  149. $present = version();
  150. $lastest = _file_get_contents("http://www.gelatocms.com/vgel.txt");
  151. if ($present < $lastest) {
  152. echo "<div class=\"information\" id=\"update\">".__("A new gelato version has been released and is ready <a href=\"http://www.gelatocms.com/\">for download</a>.")."</div><br />";
  153. }
  154. if (isset($_GET["deleted"])) {
  155. if ($_GET["deleted"]=="true") {
  156. echo "<div class=\"exito\" id=\"divMessages\">".__("The post has been eliminated successfully.")."</div>";
  157. }
  158. }
  159. if (isset($_GET["modified"])) {
  160. if ($_GET["modified"]=="true") {
  161. echo "<div class=\"exito\" id=\"divMessages\">".__("The post has been modified successfully.")."</div>";
  162. }
  163. }
  164. if (isset($_GET["added"])) {
  165. if ($_GET["added"]=="true") {
  166. echo "<div class=\"exito\" id=\"divMessages\">".__("The post has been added successfully.")."</div>";
  167. }
  168. }
  169. if (isset($_GET["error"])) {
  170. if ($_GET["error"]==2) {
  171. echo "<div class=\"error\"><strong>".__("Error on the database server:")." </strong>".$_GET["des"]."</div>";
  172. }
  173. }
  174. if (isset($_GET["mp3"])) {
  175. if ($_GET["mp3"]=="false") {
  176. echo "<div class=\"error\" id=\"divMessages\">".__("Not an MP3 file or an upload problem.")."</div>";
  177. }
  178. }
  179. if (isset($_GET["photo"])) {
  180. if ($_GET["photo"]=="false") {
  181. echo "<div class=\"error\" id=\"divMessages\">".__("Not a photo file or an upload problem.")."</div>";
  182. }
  183. }
  184. ?>
  185. <form action="index.php" method="post" <?php echo (isset($_GET["new"]) && $_GET["new"]=="photo") ? "enctype=\"multipart/form-data\"" : ""?> name="frmAdd" id="autosave" class="newpost">
  186. <fieldset>
  187. <?php
  188. if ($isEdition) {
  189. ?>
  190. <input type="hidden" name="id_post" id="id_post" value="<?php echo $postId;?>" />
  191. <?php
  192. switch ($post["type"]) {
  193. case "1":
  194. $_GET["new"] = "post";
  195. break;
  196. case "2":
  197. $_GET["new"] = "photo";
  198. break;
  199. case "3":
  200. $_GET["new"] = "quote";
  201. break;
  202. case "4":
  203. $_GET["new"] = "url";
  204. break;
  205. case "5":
  206. $_GET["new"] = "conversation";
  207. break;
  208. case "6":
  209. $_GET["new"] = "video";
  210. break;
  211. case "7":
  212. $_GET["new"] = "mp3";
  213. break;
  214. }
  215. }
  216. $date = ($isEdition) ? strtotime($post["date"]) : gmmktime();
  217. $title = ($isEdition) ? htmlspecialchars(stripslashes($post["title"])) : "";
  218. $body = ($isEdition) ? stripslashes($post["description"]) : "";
  219. $url = ($isEdition) ? $post["url"] : "";
  220. if (!isset($_GET['new'])) $_GET['new'] = 'default';
  221. switch ($_GET["new"]) {
  222. case "post":
  223. $input = array("{type}", "{date}", "{id_user}", "{editTitle}", "{editBody}");
  224. $output = array("1", $date, $_SESSION['user_id'], $title, $body);
  225. $template->cargarPlantilla($input, $output, "template_add_post");
  226. $template->mostrarPlantilla();
  227. break;
  228. case "photo":
  229. $url = str_replace("../", $conf->urlGelato."/", $url);
  230. $input = array("{type}", "{date}", "{id_user}", "{editUrl}", "{editBody}");
  231. $output = array("2", $date, $_SESSION['user_id'], $url, $body);
  232. $template->cargarPlantilla($input, $output, "template_add_photo");
  233. $template->mostrarPlantilla();
  234. break;
  235. case "quote":
  236. $input = array("{type}", "{date}", "{id_user}", "{editTitle}", "{editBody}");
  237. $output = array("3", $date, $_SESSION['user_id'], $title, $body);
  238. $template->cargarPlantilla($input, $output, "template_add_quote");
  239. $template->mostrarPlantilla();
  240. break;
  241. case "url":
  242. $input = array("{type}", "{date}", "{id_user}", "{editTitle}", "{editUrl}", "{editBody}");
  243. $output = array("4", $date, $_SESSION['user_id'], $title, $url, $body);
  244. $template->cargarPlantilla($input, $output, "template_add_link");
  245. $template->mostrarPlantilla();
  246. break;
  247. case "conversation":
  248. $input = array("{type}", "{date}", "{id_user}", "{editTitle}", "{editBody}");
  249. $output = array("5", $date, $_SESSION['user_id'], $title, $body);
  250. $template->cargarPlantilla($input, $output, "template_add_conversation");
  251. $template->mostrarPlantilla();
  252. break;
  253. case "video":
  254. $input = array("{type}", "{date}", "{id_user}", "{editUrl}", "{editBody}");
  255. $output = array("6", $date, $_SESSION['user_id'], $url, $body);
  256. $template->cargarPlantilla($input, $output, "template_add_video");
  257. $template->mostrarPlantilla();
  258. break;
  259. case "mp3":
  260. $input = array("{type}", "{date}", "{id_user}", "{editUrl}", "{editBody}");
  261. $output = array("7", $date, $_SESSION['user_id'], $url, $body);
  262. $template->cargarPlantilla($input, $output, "template_add_mp3");
  263. $template->mostrarPlantilla();
  264. break;
  265. default:
  266. $input = array("{type}", "{date}", "{id_user}", "{editTitle}", "{editBody}");
  267. $output = array("1", $date, $_SESSION['user_id'], $title, $body);
  268. $template->cargarPlantilla($input, $output, "template_add_post");
  269. $template->mostrarPlantilla();
  270. break;
  271. }
  272. ?>
  273. <p>
  274. <span style="color: rgb(136, 136, 136); margin-bottom: 10px; font-size: 10px;">
  275. <?php echo __("Some HTML allowed")?>:<br />
  276. &nbsp;&nbsp;&nbsp;&nbsp;
  277. <code>
  278. &lt;strong&gt; &lt;em&gt; &lt;del&gt; &lt;ul&gt; &lt;ol&gt; &lt;li&gt; &lt;a&gt;
  279. <br />
  280. &nbsp;&nbsp;&nbsp;&nbsp;&lt;blockquote&gt;
  281. &lt;code&gt; &lt;pre&gt; &lt;img&gt;
  282. <code>
  283. <br />
  284. Bookmarklet - <a href="javascript:var w; setTimeout('w.focus()',100);w=window.open('<?php echo $conf->urlGelato; ?>/admin/bm.php?url='+encodeURIComponent(location.href)+'&sel='+encodeURIComponent(window.getSelection()),'bookmarklet','toolbar=0,resizable=0,status=1,width=650,height=460,dependent=yes' ); w.focus();"><?php echo __("add to gelato")?></a> </span> </p>
  285. <p>
  286. <input class="btn" type="submit" name="btnAdd" value="<?php echo ($isEdition) ? "Modify" : "Create"; ?> post" />
  287. </p>
  288. </fieldset>
  289. </form>
  290. <div class="footer-box">&nbsp;</div>
  291. </div>
  292. <?php
  293. if (!$isEdition) {
  294. ?>
  295. <div class="box">
  296. <ul class="menu manage">
  297. <h3>Manage</h3>
  298. <li><a href="<?php echo $conf->urlGelato;?>/admin/settings.php"><?php echo __("Settings")?></a></li>
  299. <li><a href="<?php echo $conf->urlGelato;?>/admin/options.php"><?php echo __("Options")?></a></li>
  300. <li><a href="<?php echo $conf->urlGelato;?>/admin/feeds.php"><?php echo __("Feeds")?></a></li>
  301. <li><a href="<?php echo $conf->urlGelato;?>/admin/admin.php"><?php echo __("Users")?></a></li>
  302. <li><a href="<?php echo $conf->urlGelato;?>/admin/comments.php"><?php echo __("Comments")?></a></li>
  303. <li class="selected"><a><?php echo __("Posts")?></a></li>
  304. </ul>
  305. <?php
  306. if (isset($_GET["page"])) {
  307. $page_num = $_GET["page"];
  308. } else {
  309. $page_num = NULL;
  310. }
  311. $limit=$conf->postLimit;
  312. if(isset($page_num) && is_numeric($page_num) && $page_num>0) { // Is defined the page and is numeric?
  313. $from = (($page_num-1) * $limit);
  314. } else {
  315. $from = 0;
  316. }
  317. $rs = $tumble->getPosts($limit, $from);
  318. if ($tumble->contarRegistros()>0) {
  319. while($register = mysql_fetch_array($rs)) {
  320. $formatedDate = gmdate("M d", strtotime($register["date"])+transform_offset($conf->offsetTime));
  321. $permalink = $conf->urlGelato."/index.php/post/".$register["id_post"]."/";
  322. $register["title"] = stripslashes($register["title"]);
  323. $register["description"] = stripslashes($register["description"]);
  324. switch ($tumble->getType($register["id_post"])) {
  325. case "1":
  326. $input = array("{Id_Post}", "{Date_Added}", "{Permalink}", "{Title}", "{Body}", "{URL_Tumble}");
  327. $output = array($register["id_post"], $formatedDate, $permalink, $register["title"], $register["description"], $conf->urlGelato);
  328. $template->cargarPlantilla($input, $output, "template_regular_post");
  329. $template->mostrarPlantilla();
  330. break;
  331. case "2":
  332. $fileName = "../uploads/".getFileName($register["url"]);
  333. $x = @getimagesize($fileName);
  334. if ($x[0] > 100) {
  335. $photoPath = $conf->urlGelato."/classes/imgsize.php?w=100&img=".$register["url"];
  336. } else {
  337. $photoPath = $register["url"];
  338. }
  339. $effect = " href=\"".str_replace("../", $conf->urlGelato."/", $register["url"])."\" rel=\"lightbox\"";
  340. $input = array("{Id_Post}", "{Date_Added}", "{Permalink}", "{PhotoURL}", "{PhotoAlt}", "{Caption}", "{Effect}", "{URL_Tumble}");
  341. $output = array($register["id_post"], $formatedDate, $permalink, $photoPath, strip_tags($register["description"]), $register["description"], $effect, $conf->urlGelato);
  342. $template->cargarPlantilla($input, $output, "template_photo");
  343. $template->mostrarPlantilla();
  344. break;
  345. case "3":
  346. $input = array("{Id_Post}", "{Date_Added}", "{Permalink}", "{Quote}", "{Source}", "{URL_Tumble}");
  347. $output = array($register["id_post"], $formatedDate, $permalink, $register["description"], $register["title"], $conf->urlGelato);
  348. $template->cargarPlantilla($input, $output, "template_quote");
  349. $template->mostrarPlantilla();
  350. break;
  351. case "4":
  352. if($conf->shorten_links){
  353. $register["url"] = _file_get_contents("http://api.abbrr.com/api.php?out=link&url=".$register["url"]);
  354. }
  355. $register["title"] = ($register["title"]=="")? $register["url"] : $register["title"];
  356. $input = array("{Id_Post}", "{Date_Added}", "{Permalink}", "{URL}", "{Name}", "{Description}", "{URL_Tumble}");
  357. $output = array($register["id_post"], $formatedDate, $permalink, $register["url"], $register["title"], $register["description"], $conf->urlGelato);
  358. $template->cargarPlantilla($input, $output, "template_url");
  359. $template->mostrarPlantilla();
  360. break;
  361. case "5":
  362. $input = array("{Id_Post}", "{Date_Added}", "{Permalink}", "{Title}", "{Conversation}", "{URL_Tumble}");
  363. $output = array($register["id_post"], $formatedDate, $permalink, $register["title"], $tumble->formatConversation($register["description"]), $conf->urlGelato);
  364. $template->cargarPlantilla($input, $output, "template_conversation");
  365. $template->mostrarPlantilla();
  366. break;
  367. case "6":
  368. $input = array("{Id_Post}", "{Date_Added}", "{Permalink}", "{Video}", "{Caption}", "{URL_Tumble}");
  369. $output = array($register["id_post"], $formatedDate, $permalink, $tumble->getVideoPlayer($register["url"]), $register["description"], $conf->urlGelato);
  370. $template->cargarPlantilla($input, $output, "template_video");
  371. $template->mostrarPlantilla();
  372. break;
  373. case "7":
  374. $input = array("{Id_Post}", "{Date_Added}", "{Permalink}", "{Mp3}", "{Caption}", "{URL_Tumble}");
  375. $output = array($register["id_post"], $formatedDate, $permalink, $tumble->getMp3Player($register["url"]), $register["description"], $conf->urlGelato);
  376. $template->cargarPlantilla($input, $output, "template_mp3");
  377. $template->mostrarPlantilla();
  378. break;
  379. }
  380. }
  381. $p = new pagination;
  382. $p->items($tumble->getPostsNumber());
  383. $p->limit($limit);
  384. $p->currentPage(isset($page_num) ? $page_num : 1);
  385. $p->show();
  386. } else {
  387. $template->renderizaEtiqueta(__("No posts in this tumblelog."), "div","error");
  388. }
  389. ?>
  390. <div class="footer-box">&nbsp;</div>
  391. </div>
  392. </div>
  393. <?php
  394. }
  395. ?>
  396. <div id="foot">
  397. <a href="http://www.gelatocms.com/" title="gelato CMS">gelato CMS</a> :: PHP/MySQL Tumblelog Content Management System.
  398. </div>
  399. </div>
  400. </body>
  401. </html>
  402. <?php
  403. }
  404. } else {
  405. header("Location: ".$conf->urlGelato."/login.php");
  406. }
  407. ?>