A tumblelog CMS built on AJAX, PHP and MySQL.

index.php 17KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436
  1. <?php
  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. <?php
  9. require_once('../config.php');
  10. include("../classes/functions.php");
  11. include("../classes/user.class.php");
  12. include("../classes/pagination.php");
  13. include("../classes/gelato.class.php");
  14. include("../classes/textile.class.php");
  15. include("../classes/templates.class.php");
  16. require_once("../classes/configuration.class.php");
  17. $user = new user();
  18. $tumble = new gelato();
  19. $conf = new configuration();
  20. $template = new plantillas("admin");
  21. $isEdition = isset($_GET["edit"]);
  22. $postId = ($isEdition) ? $_GET["edit"] : NULL;
  23. if ($user->isAdmin()) {
  24. if (isset($_GET["delete"])) {
  25. $tumble->deletePost($_GET['delete']);
  26. header("Location: index.php?deleted=true");
  27. die();
  28. }
  29. if(isset($_POST["btnAdd"])) {
  30. unset($_POST["btnAdd"]);
  31. if ($_POST["type"]=="2") { // is Photo type
  32. if (isset($_POST["url"]) && $_POST["url"]!="") {
  33. $photoName = getFileName($_POST["url"]);
  34. if (!$tumble->savePhoto($_POST["url"])) {
  35. header("Location: ".$conf->urlGelato."/admin/index.php?photo=false");
  36. die();
  37. }
  38. $_POST["url"] = $conf->urlGelato."/uploads/".$photoName;
  39. }
  40. if ( move_uploaded_file( $_FILES['photo']['tmp_name'], "../uploads/".$_FILES['photo']['name'] ) ) {
  41. $_POST["url"] = $conf->urlGelato."/uploads/".$_FILES['photo']['name'];
  42. }
  43. unset($_POST["photo"]);
  44. unset($_POST["MAX_FILE_SIZE"]);
  45. }
  46. if ($_POST["type"]=="7") { // is MP3 type
  47. set_time_limit(300);
  48. $mp3Name = getFileName($_POST["url"]);
  49. if (!$tumble->saveMP3($_POST["url"])) {
  50. header("Location: ".$conf->urlGelato."/admin/index.php?mp3=false");
  51. die();
  52. }
  53. if (isMP3($remoteFileName)) {
  54. $_POST["url"] = $conf->urlGelato."/uploads/".$mp3Name;
  55. }
  56. }
  57. if (get_magic_quotes_gpc()) {
  58. $_POST["title"] = stripslashes($_POST["title"]);
  59. $_POST["description"] = stripslashes($_POST["description"]);
  60. }
  61. $_POST["title"] = strip_tags($_POST["title"]);
  62. $_POST["description"] = strip_tags($_POST["description"]);
  63. if (isset($_POST["id_post"])) {
  64. $tumble->modifyPost($_POST, $_POST["id_post"]);
  65. } else {
  66. if ($tumble->addPost($_POST)) {
  67. header("Location: ".$conf->urlGelato."/admin/index.php?added=true");
  68. die();
  69. } else {
  70. header("Location: ".$conf->urlGelato."/admin/index.php?error=2&des=".$this->merror);
  71. die();
  72. }
  73. }
  74. } else {
  75. if ($isEdition) {
  76. $post = $tumble->getPost($postId);
  77. }
  78. ?>
  79. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  80. <html xmlns="http://www.w3.org/1999/xhtml">
  81. <head>
  82. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  83. <title>gelato :: 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/tools.js"></script>
  86. <script language="javascript" type="text/javascript" src="<?php echo $conf->urlGelato;?>/admin/scripts/mootools.js"></script>
  87. <script language="javascript" type="text/javascript" src="<?php echo $conf->urlGelato;?>/admin/scripts/slimbox.js"></script>
  88. <script language="javascript" type="text/javascript">
  89. <!--
  90. function exit(el, path) {
  91. el = $(el);
  92. el.style.display="block";
  93. el.setHTML('Processing request...');
  94. new Ajax(path, {
  95. onComplete:function(e) {
  96. el.setHTML(e).effect('opacity').custom(0,1);
  97. window.location='../login.php';
  98. }
  99. }).request();
  100. return false;
  101. }
  102. window.onload = function() {
  103. contenedor = new Fx.Style('divMessages', 'opacity', {duration: 5000, onComplete:
  104. function() {
  105. document.getElementById('divMessages').style.display="none";
  106. }
  107. });
  108. contenedor.custom(1,0);
  109. }
  110. -->
  111. </script>
  112. <style type="text/css" media="screen">
  113. @import "<?php echo $conf->urlGelato;?>/admin/css/style.css";
  114. @import "<?php echo $conf->urlGelato;?>/admin/css/slimbox.css";
  115. </style>
  116. </head>
  117. <body>
  118. <div id="div-process" style="display:none;">Processing request...</div>
  119. <div id="cont">
  120. <div id="head">
  121. <h1><a href="<?php echo $conf->urlGelato;?>/admin/index.php" title="gelato :: home">gelato cms</a></h1>
  122. <ul id="nav">
  123. <li><a href="<?php echo $conf->urlGelato;?>/" title="Take me to the tumblelog">View Tumblelog</a></li>
  124. <li><a href="close.php" title="Log off" onclick="return exit('div-process','<?php echo $conf->urlGelato;?>/admin/ajax.php?action=close');">Log out</a></li>
  125. </ul>
  126. </div>
  127. <div id="main">
  128. <div class="box">
  129. <ul class="menu">
  130. <h3>New Post</h3>
  131. <li<?php echo ($_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" /> Chat</a></li>
  132. <li<?php echo ($_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" /> Quote</a></li>
  133. <li<?php echo ($_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" /> Link</a></li>
  134. <li<?php echo ($_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" /> Audio</a></li>
  135. <li<?php echo ($_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" /> Video</a></li>
  136. <li<?php echo ($_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" /> Picture</a></li>
  137. <li<?php echo ($_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" /> Regular</a></li>
  138. </ul>
  139. <p>&nbsp;</p>
  140. <?php
  141. $present = version();
  142. $lastest = _file_get_contents("http://www.gelatocms.com/vgel.txt");
  143. if ($present < $lastest) {
  144. 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>";
  145. }
  146. if (isset($_GET["deleted"])) {
  147. if ($_GET["deleted"]=="true") {
  148. echo "<div class=\"exito\" id=\"divMessages\">The post has been eliminated successfully.</div>";
  149. }
  150. }
  151. if (isset($_GET["modified"])) {
  152. if ($_GET["modified"]=="true") {
  153. echo "<div class=\"exito\" id=\"divMessages\">The post has been modified successfully.</div>";
  154. }
  155. }
  156. if (isset($_GET["added"])) {
  157. if ($_GET["added"]=="true") {
  158. echo "<div class=\"exito\" id=\"divMessages\">The post has been added successfully.</div>";
  159. }
  160. }
  161. if (isset($_GET["error"])) {
  162. if ($_GET["error"]==2) {
  163. echo "<div class=\"error\"><strong>Error on the database server: </strong>".$_GET["des"]."</div>";
  164. }
  165. }
  166. if (isset($_GET["mp3"])) {
  167. if ($_GET["mp3"]=="false") {
  168. echo "<div class=\"error\" id=\"divMessages\">Not an MP3 file or an upload problem.</div>";
  169. }
  170. }
  171. if (isset($_GET["photo"])) {
  172. if ($_GET["photo"]=="false") {
  173. echo "<div class=\"error\" id=\"divMessages\">Not a photo file or an upload problem.</div>";
  174. }
  175. }
  176. ?>
  177. <form action="index.php" method="post" <?php echo ($_GET["new"]=="photo") ? "enctype=\"multipart/form-data\"" : ""?> name="frmAdd" class="newpost">
  178. <fieldset>
  179. <?php
  180. if ($isEdition) {
  181. ?>
  182. <input type="hidden" name="id_post" id="id_post" value="<?php echo $postId;?>" />
  183. <?php
  184. switch ($post["type"]) {
  185. case "1":
  186. $_GET["new"] = "post";
  187. break;
  188. case "2":
  189. $_GET["new"] = "photo";
  190. break;
  191. case "3":
  192. $_GET["new"] = "quote";
  193. break;
  194. case "4":
  195. $_GET["new"] = "url";
  196. break;
  197. case "5":
  198. $_GET["new"] = "conversation";
  199. break;
  200. case "6":
  201. $_GET["new"] = "video";
  202. break;
  203. case "7":
  204. $_GET["new"] = "mp3";
  205. break;
  206. }
  207. }
  208. $date = ($isEdition) ? strtotime($post["date"]) : time();
  209. $title = ($isEdition) ? $post["title"] : "";
  210. $body = ($isEdition) ? $post["description"] : "";
  211. $url = ($isEdition) ? $post["url"] : "";
  212. switch ($_GET["new"]) {
  213. case "post":
  214. $input = array("{type}", "{date}", "{id_user}", "{editTitle}", "{editBody}");
  215. $output = array("1", $date, $_SESSION['user_id'], $title, $body);
  216. $template->cargarPlantilla($input, $output, "template_add_post");
  217. $template->mostrarPlantilla();
  218. break;
  219. case "photo":
  220. $input = array("{type}", "{date}", "{id_user}", "{editUrl}", "{editBody}");
  221. $output = array("2", $date, $_SESSION['user_id'], $url, $body);
  222. $template->cargarPlantilla($input, $output, "template_add_photo");
  223. $template->mostrarPlantilla();
  224. break;
  225. case "quote":
  226. $input = array("{type}", "{date}", "{id_user}", "{editTitle}", "{editBody}");
  227. $output = array("3", $date, $_SESSION['user_id'], $title, $body);
  228. $template->cargarPlantilla($input, $output, "template_add_quote");
  229. $template->mostrarPlantilla();
  230. break;
  231. case "url":
  232. $input = array("{type}", "{date}", "{id_user}", "{editTitle}", "{editUrl}", "{editBody}");
  233. $output = array("4", $date, $_SESSION['user_id'], $title, $url, $body);
  234. $template->cargarPlantilla($input, $output, "template_add_link");
  235. $template->mostrarPlantilla();
  236. break;
  237. case "conversation":
  238. $input = array("{type}", "{date}", "{id_user}", "{editTitle}", "{editBody}");
  239. $output = array("5", $date, $_SESSION['user_id'], $title, $body);
  240. $template->cargarPlantilla($input, $output, "template_add_conversation");
  241. $template->mostrarPlantilla();
  242. break;
  243. case "video":
  244. $input = array("{type}", "{date}", "{id_user}", "{editUrl}", "{editBody}");
  245. $output = array("6", $date, $_SESSION['user_id'], $url, $body);
  246. $template->cargarPlantilla($input, $output, "template_add_video");
  247. $template->mostrarPlantilla();
  248. break;
  249. case "mp3":
  250. $input = array("{type}", "{date}", "{id_user}", "{editUrl}", "{editBody}");
  251. $output = array("7", $date, $_SESSION['user_id'], $url, $body);
  252. $template->cargarPlantilla($input, $output, "template_add_mp3");
  253. $template->mostrarPlantilla();
  254. break;
  255. default:
  256. $input = array("{type}", "{date}", "{id_user}", "{editTitle}", "{editBody}");
  257. $output = array("1", $date, $_SESSION['user_id'], $title, $body);
  258. $template->cargarPlantilla($input, $output, "template_add_post");
  259. $template->mostrarPlantilla();
  260. break;
  261. }
  262. ?>
  263. <p>
  264. <span style="color: rgb(136, 136, 136); margin-bottom: 10px; font-size: 10px;"><a href="http://hobix.com/textile/">Textile</a> syntax is supported.</span>
  265. </p>
  266. <p>
  267. <input class="btn" type="submit" name="btnAdd" value="<?php echo ($isEdition) ? "Modify" : "Create"; ?> post" />
  268. </p>
  269. </fieldset>
  270. </form>
  271. <div class="footer-box">&nbsp;</div>
  272. </div>
  273. <?php
  274. if (!$isEdition) {
  275. ?>
  276. <div class="box">
  277. <ul class="menu manage">
  278. <h3>Manage</h3>
  279. <li><a href="<?php echo $conf->urlGelato;?>/admin/settings.php">Settings</a></li>
  280. <li><a href="<?php echo $conf->urlGelato;?>/admin/admin.php">Users</a></li>
  281. <li class="selected"><a>Posts</a></li>
  282. </ul>
  283. <?php
  284. if (isset($_GET["page"])) {
  285. $page_num = $_GET["page"];
  286. } else {
  287. $page_num = NULL;
  288. }
  289. $limit=$conf->postLimit;
  290. if(isset($page_num) && is_numeric($page_num) && $page_num>0) { // Is defined the page and is numeric?
  291. $from = (($page_num-1) * $limit);
  292. } else {
  293. $from = 0;
  294. }
  295. $rs = $tumble->getPosts($limit, $from);
  296. if ($tumble->contarRegistros()>0) {
  297. while($register = mysql_fetch_array($rs)) {
  298. $formatedDate = date("M d", strtotime($register["date"]));
  299. $permalink = $conf->urlGelato."/index.php/post/".$register["id_post"]."/";
  300. $textile = new Textile;
  301. $register["description"] = $textile->process($register["description"]);
  302. switch ($tumble->getType($register["id_post"])) {
  303. case "1":
  304. $input = array("{Id_Post}", "{Date_Added}", "{Permalink}", "{Title}", "{Body}", "{URL_Tumble}");
  305. $output = array($register["id_post"], $formatedDate, $permalink, $register["title"], $register["description"], $conf->urlGelato);
  306. $template->cargarPlantilla($input, $output, "template_regular_post");
  307. $template->mostrarPlantilla();
  308. break;
  309. case "2":
  310. $fileName = "../uploads/".getFileName($register["url"]);
  311. $x = @getimagesize($fileName);
  312. if ($x[0] > 100) {
  313. $photoPath = $conf->urlGelato."/classes/imgsize.php?w=100&img=".$register["url"];
  314. } else {
  315. $photoPath = $register["url"];
  316. }
  317. $effect = " style=\"cursor: pointer;\" onclick=\"Lightbox.show('".$register["url"]."', '".strip_tags($register["description"])."');\" ";
  318. $input = array("{Id_Post}", "{Date_Added}", "{Permalink}", "{PhotoURL}", "{PhotoAlt}", "{Caption}", "{Effect}", "{URL_Tumble}");
  319. $output = array($register["id_post"], $formatedDate, $permalink, $photoPath, strip_tags($register["description"]), $register["description"], $effect, $conf->urlGelato);
  320. $template->cargarPlantilla($input, $output, "template_photo");
  321. $template->mostrarPlantilla();
  322. break;
  323. case "3":
  324. $input = array("{Id_Post}", "{Date_Added}", "{Permalink}", "{Quote}", "{Source}", "{URL_Tumble}");
  325. $output = array($register["id_post"], $formatedDate, $permalink, $register["description"], $register["title"], $conf->urlGelato);
  326. $template->cargarPlantilla($input, $output, "template_quote");
  327. $template->mostrarPlantilla();
  328. break;
  329. case "4":
  330. $input = array("{Id_Post}", "{Date_Added}", "{Permalink}", "{URL}", "{Name}", "{Description}", "{URL_Tumble}");
  331. $output = array($register["id_post"], $formatedDate, $permalink, $register["url"], $register["title"], $register["description"], $conf->urlGelato);
  332. $template->cargarPlantilla($input, $output, "template_url");
  333. $template->mostrarPlantilla();
  334. break;
  335. case "5":
  336. $input = array("{Id_Post}", "{Date_Added}", "{Permalink}", "{Title}", "{Conversation}", "{URL_Tumble}");
  337. $output = array($register["id_post"], $formatedDate, $permalink, $register["title"], $tumble->formatConversation($register["description"]), $conf->urlGelato);
  338. $template->cargarPlantilla($input, $output, "template_conversation");
  339. $template->mostrarPlantilla();
  340. break;
  341. case "6":
  342. $input = array("{Id_Post}", "{Date_Added}", "{Permalink}", "{Video}", "{Caption}", "{URL_Tumble}");
  343. $output = array($register["id_post"], $formatedDate, $permalink, $tumble->getVideoPlayer($register["url"]), $register["description"], $conf->urlGelato);
  344. $template->cargarPlantilla($input, $output, "template_video");
  345. $template->mostrarPlantilla();
  346. break;
  347. case "7":
  348. $input = array("{Id_Post}", "{Date_Added}", "{Permalink}", "{Mp3}", "{Caption}", "{URL_Tumble}");
  349. $output = array($register["id_post"], $formatedDate, $permalink, $tumble->getMp3Player($register["url"]), $register["description"], $conf->urlGelato);
  350. $template->cargarPlantilla($input, $output, "template_mp3");
  351. $template->mostrarPlantilla();
  352. break;
  353. }
  354. }
  355. echo pagination($tumble->getPostsNumber(), $limit, isset($page_num) ? $page_num : 1, "index.php", 2);
  356. } else {
  357. $template->renderizaEtiqueta("No posts in this tumblelog.", "div","error");
  358. }
  359. ?>
  360. <div class="footer-box">&nbsp;</div>
  361. </div>
  362. </div>
  363. <?php
  364. }
  365. ?>
  366. <div id="foot">
  367. <a href="http://www.gelatocms.com/" title="gelato CMS">gelato CMS</a> :: PHP/MySQL Tumblelog Content Management System.
  368. </div>
  369. </div>
  370. </body>
  371. </html>
  372. <?php
  373. }
  374. } else {
  375. header("Location: ".$conf->urlGelato."/login.php");
  376. }
  377. ?>