A tumblelog CMS built on AJAX, PHP and MySQL.

index.php 18KB

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