A tumblelog CMS built on AJAX, PHP and MySQL.

add.php 6.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  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/tiny_mce/tiny_mce.js"></script>
  74. <script language="javascript" type="text/javascript" src="<?=$conf->urlGelato;?>/admin/scripts/tools.js"></script>
  75. <script language="javascript" type="text/javascript" src="<?=$conf->urlGelato;?>/admin/scripts/mootools.js"></script>
  76. <style type="text/css" media="screen">
  77. @import "<?=$conf->urlGelato;?>/admin/css/style-codice.css";
  78. </style>
  79. </head>
  80. <body>
  81. <div id="div-process" style="display:none;">Processing request...</div>
  82. <div id="titulo">
  83. <img src="<?=$conf->urlGelato;?>/images/logo.jpg" alt="gelato CMS" title="gelato CMS" />
  84. </div>
  85. <div id="menuContenedor">
  86. <ul>
  87. <li id="active"><a href="#" id="current">Posts</a></li>
  88. <ul>
  89. <li id="subactive"><a href="#" id="subcurrent">Add</a></li>
  90. </ul>
  91. </li>
  92. <li><a href="index.php">Control Panel</a></li>
  93. </ul>
  94. </div>
  95. <div id="contenido">
  96. <div class="center">
  97. <div class="ventana">
  98. <p class="titulo"><span class="handle">Add content</span></p>
  99. <div id="formulario">
  100. <form action="add.php" method="post" <?=($_GET["new"]=="photo") ? "enctype=\"multipart/form-data\"" : ""?> name="frmAdd">
  101. <fieldset>
  102. <?
  103. switch ($_GET["new"]) {
  104. case "post":
  105. $input = array("{type}", "{date}", "{id_user}");
  106. $output = array("1", time(), $_SESSION['user_id']);
  107. $template->cargarPlantilla($input, $output, "template_add_post");
  108. $template->mostrarPlantilla();
  109. break;
  110. case "photo":
  111. $input = array("{type}", "{date}", "{id_user}");
  112. $output = array("2", time(), $_SESSION['user_id']);
  113. $template->cargarPlantilla($input, $output, "template_add_photo");
  114. $template->mostrarPlantilla();
  115. break;
  116. case "quote":
  117. $input = array("{type}", "{date}", "{id_user}");
  118. $output = array("3", time(), $_SESSION['user_id']);
  119. $template->cargarPlantilla($input, $output, "template_add_quote");
  120. $template->mostrarPlantilla();
  121. break;
  122. case "url":
  123. $input = array("{type}", "{date}", "{id_user}");
  124. $output = array("4", time(), $_SESSION['user_id']);
  125. $template->cargarPlantilla($input, $output, "template_add_link");
  126. $template->mostrarPlantilla();
  127. break;
  128. case "conversation":
  129. $input = array("{type}", "{date}", "{id_user}");
  130. $output = array("5", time(), $_SESSION['user_id']);
  131. $template->cargarPlantilla($input, $output, "template_add_conversation");
  132. $template->mostrarPlantilla();
  133. break;
  134. case "video":
  135. $input = array("{type}", "{date}", "{id_user}");
  136. $output = array("6", time(), $_SESSION['user_id']);
  137. $template->cargarPlantilla($input, $output, "template_add_video");
  138. $template->mostrarPlantilla();
  139. break;
  140. case "mp3":
  141. $input = array("{type}", "{date}", "{id_user}");
  142. $output = array("7", time(), $_SESSION['user_id']);
  143. $template->cargarPlantilla($input, $output, "template_add_mp3");
  144. $template->mostrarPlantilla();
  145. break;
  146. default:
  147. echo "<div class=\"error\">The specified type is not valid.</div>";
  148. break;
  149. }
  150. ?>
  151. <p>
  152. <input class="submit" type="submit" name="btnAdd" value="Create post" />&nbsp;&nbsp;
  153. <a href="#" onclick="if (confirm('Cancel editing this post? All changes will be lost.'))
  154. {location.href='index.php';}; return false;">Cancel</a>
  155. </p>
  156. </fieldset>
  157. </form>
  158. </div>
  159. </div>
  160. </div>
  161. <div id="pie">
  162. <p>
  163. <a href="http://www.gelatocms.com/" title="gelato CMS" target="_blank">gelato CMS</a> :: PHP/MySQL Tumblelog Content Management System.
  164. </p>
  165. </div>
  166. </div>
  167. </body>
  168. </html>
  169. <?
  170. }
  171. } else {
  172. header("Location: ".$conf->urlGelato."/login.php");
  173. }
  174. ?>