A tumblelog CMS built on AJAX, PHP and MySQL.

add.php 6.4KB

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