A tumblelog CMS built on AJAX, PHP and MySQL.

index.php 15KB

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