A tumblelog CMS built on AJAX, PHP and MySQL.

add.php 6.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. <?
  2. /* ===========================
  3. gelato CMS development version
  4. http://www.gelatocms.com/
  5. gelato CMS is a free software licensed under GPL (General public license)
  6. =========================== */
  7. ?>
  8. <?
  9. require_once('../config.php');
  10. include("../classes/user.class.php");
  11. include("../classes/gelato.class.php");
  12. include("../classes/templates.class.php");
  13. require_once("../classes/configuration.class.php");
  14. $user = new user();
  15. $tumble = new gelato();
  16. $conf = new configuration();
  17. $template = new plantillas("admin");
  18. if ($user->isAdmin()) {
  19. if(isset($_POST["btnAdd"])) {
  20. unset($_POST["btnAdd"]);
  21. if ($_POST["type"]=="2") { // is Photo type
  22. if (isset($_POST["url"]) && $_POST["url"]!="") {
  23. $photoName = getFileName($_POST["url"]);
  24. if (!$tumble->savePhoto($_POST["url"])) {
  25. header("Location: ".$conf->urlGelato."/admin/index.php?photo=false");
  26. die();
  27. }
  28. $_POST["url"] = $conf->urlGelato."/uploads/".$photoName;
  29. }
  30. if ( move_uploaded_file( $_FILES['photo']['tmp_name'], "../uploads/".$_FILES['photo']['name'] ) ) {
  31. $_POST["url"] = $conf->urlGelato."/uploads/".$_FILES['photo']['name'];
  32. }
  33. unset($_POST["photo"]);
  34. unset($_POST["MAX_FILE_SIZE"]);
  35. }
  36. if ($_POST["type"]=="7") { // is MP3 type
  37. set_time_limit(300);
  38. $mp3Name = getFileName($_POST["url"]);
  39. if (!$tumble->saveMP3($_POST["url"])) {
  40. header("Location: ".$conf->urlGelato."/admin/index.php?mp3=false");
  41. die();
  42. }
  43. $_POST["url"] = $conf->urlGelato."/uploads/".$mp3Name;
  44. }
  45. if (get_magic_quotes_gpc()) {
  46. $_POST["title"] = htmlspecialchars(stripslashes($_POST["title"]));
  47. $_POST["description"] = htmlspecialchars(stripslashes($_POST["description"]));
  48. } else {
  49. $_POST["title"] = htmlspecialchars($_POST["title"]);
  50. $_POST["description"] = htmlspecialchars($_POST["description"]);
  51. }
  52. $_POST["title"] = strip_tags($_POST["title"]);
  53. $_POST["description"] = strip_tags($_POST["description"]);
  54. if (isset($_POST["id_post"])) {
  55. //$tumble->modifyPost($_POST, $_POST["id_post"]);
  56. } else {
  57. if ($tumble->addPost($_POST)) {
  58. header("Location: ".$conf->urlGelato."/admin/index.php?added=true");
  59. die();
  60. } else {
  61. header("Location: ".$conf->urlGelato."/admin/index.php?error=2&des=".$this->merror);
  62. die();
  63. }
  64. }
  65. } elseif (isset($_GET["new"])) {
  66. ?>
  67. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
  68. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  69. <head>
  70. <title>gelato</title>
  71. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  72. <link rel="shortcut icon" href="<?=$conf->urlGelato;?>/images/favicon.ico" />
  73. <script language="javascript" type="text/javascript" src="<?=$conf->urlGelato;?>/admin/scripts/tools.js"></script>
  74. <script language="javascript" type="text/javascript" src="<?=$conf->urlGelato;?>/admin/scripts/mootools.js"></script>
  75. <style type="text/css" media="screen">
  76. @import "<?=$conf->urlGelato;?>/admin/css/style-codice.css";
  77. </style>
  78. </head>
  79. <body>
  80. <div id="div-process" style="display:none;">Processing request...</div>
  81. <div id="titulo">
  82. <img src="<?=$conf->urlGelato;?>/images/logo.jpg" alt="gelato CMS" title="gelato CMS" />
  83. </div>
  84. <div id="menuContenedor">
  85. <ul>
  86. <li id="active"><a href="#" id="current">Posts</a></li>
  87. <ul>
  88. <li id="subactive"><a href="#" id="subcurrent">Add</a></li>
  89. </ul>
  90. </li>
  91. <li><a href="index.php">Control Panel</a></li>
  92. </ul>
  93. </div>
  94. <div id="contenido">
  95. <div class="center">
  96. <div class="ventana">
  97. <p class="titulo"><span class="handle">Add content</span></p>
  98. <div id="formulario">
  99. <form action="add.php" method="post" <?=($_GET["new"]=="photo") ? "enctype=\"multipart/form-data\"" : ""?> name="frmAdd">
  100. <fieldset>
  101. <?
  102. switch ($_GET["new"]) {
  103. case "post":
  104. $input = array("{type}", "{date}", "{id_user}");
  105. $output = array("1", time(), $_SESSION['user_id']);
  106. $template->cargarPlantilla($input, $output, "template_add_post");
  107. $template->mostrarPlantilla();
  108. break;
  109. case "photo":
  110. $input = array("{type}", "{date}", "{id_user}");
  111. $output = array("2", time(), $_SESSION['user_id']);
  112. $template->cargarPlantilla($input, $output, "template_add_photo");
  113. $template->mostrarPlantilla();
  114. break;
  115. case "quote":
  116. $input = array("{type}", "{date}", "{id_user}");
  117. $output = array("3", time(), $_SESSION['user_id']);
  118. $template->cargarPlantilla($input, $output, "template_add_quote");
  119. $template->mostrarPlantilla();
  120. break;
  121. case "url":
  122. $input = array("{type}", "{date}", "{id_user}");
  123. $output = array("4", time(), $_SESSION['user_id']);
  124. $template->cargarPlantilla($input, $output, "template_add_link");
  125. $template->mostrarPlantilla();
  126. break;
  127. case "conversation":
  128. $input = array("{type}", "{date}", "{id_user}");
  129. $output = array("5", time(), $_SESSION['user_id']);
  130. $template->cargarPlantilla($input, $output, "template_add_conversation");
  131. $template->mostrarPlantilla();
  132. break;
  133. case "video":
  134. $input = array("{type}", "{date}", "{id_user}");
  135. $output = array("6", time(), $_SESSION['user_id']);
  136. $template->cargarPlantilla($input, $output, "template_add_video");
  137. $template->mostrarPlantilla();
  138. break;
  139. case "mp3":
  140. $input = array("{type}", "{date}", "{id_user}");
  141. $output = array("7", time(), $_SESSION['user_id']);
  142. $template->cargarPlantilla($input, $output, "template_add_mp3");
  143. $template->mostrarPlantilla();
  144. break;
  145. default:
  146. echo "<div class=\"error\">The specified type is not valid.</div>";
  147. break;
  148. }
  149. ?>
  150. <p>
  151. <input class="submit" type="submit" name="btnAdd" value="Create post" />&nbsp;&nbsp;
  152. <a href="#" onclick="if (confirm('Cancel editing this post? All changes will be lost.'))
  153. {location.href='index.php';}; return false;">Cancel</a>
  154. </p>
  155. </fieldset>
  156. </form>
  157. </div>
  158. </div>
  159. </div>
  160. <div id="pie">
  161. <p>
  162. <a href="http://www.gelatocms.com/" title="gelato CMS" target="_blank">gelato CMS</a> :: PHP/MySQL Tumblelog Content Management System.
  163. </p>
  164. </div>
  165. </div>
  166. </body>
  167. </html>
  168. <?
  169. }
  170. } else {
  171. header("Location: ".$conf->urlGelato."/login.php");
  172. }
  173. ?>