A tumblelog CMS built on AJAX, PHP and MySQL.

index.php 19KB

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