A tumblelog CMS built on AJAX, PHP and MySQL.

index.php 18KB

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