A tumblelog CMS built on AJAX, PHP and MySQL.

gelato.class.php 5.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. <?php
  2. if(!defined('entry') || !entry) die('Not a valid page');
  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_once("configuration.class.php");
  13. require_once("functions.php");
  14. class gelato extends Conexion_Mysql {
  15. var $conf;
  16. function gelato() {
  17. parent::Conexion_Mysql(DB_name, DB_Server, DB_User, DB_Password);
  18. $this->conf = new configuration();
  19. }
  20. function saveSettings($fieldsArray) {
  21. if ($this->modificarDeFormulario($this->conf->tablePrefix."config", $fieldsArray)) {
  22. header("Location: ".$this->conf->urlGelato."/admin/settings.php?modified=true");
  23. die();
  24. } else {
  25. header("Location: ".$this->conf->urlGelato."/admin/settings.php?error=1&des=".$this->merror);
  26. die();
  27. }
  28. }
  29. function saveOption($value, $name) {
  30. $sqlStr = "UPDATE ".$this->conf->tablePrefix."options SET val='".$value."' WHERE name='".$name."' LIMIT 1";
  31. if ($this->ejecutarConsulta($sqlStr)) {
  32. return true;
  33. } else {
  34. return true;
  35. }
  36. }
  37. function addPost($fieldsArray) {
  38. if ($this->insertarDeFormulario($this->conf->tablePrefix."data", $fieldsArray)) {
  39. return true;
  40. } else {
  41. return false;
  42. }
  43. }
  44. function modifyPost($fieldsArray, $id_post) {
  45. if ($this->modificarDeFormulario($this->conf->tablePrefix."data", $fieldsArray, "id_post=$id_post")) {
  46. header("Location: ".$this->conf->urlGelato."/admin/index.php?modified=true");
  47. die();
  48. } else {
  49. header("Location: ".$this->conf->urlGelato."/admin/index.php?error=2&des=".$this->merror);
  50. die();
  51. }
  52. }
  53. function deletePost($idPost) {
  54. $this->ejecutarConsulta("DELETE FROM ".$this->conf->tablePrefix."data WHERE id_post=".$idPost);
  55. }
  56. function getPosts($limit="10", $from="0") {
  57. $sqlStr = "select * from ".$this->conf->tablePrefix."data ORDER BY date DESC LIMIT $from,$limit";
  58. $this->ejecutarConsulta($sqlStr);
  59. return $this->mid_consulta;
  60. }
  61. function getPost($id="") {
  62. $this->ejecutarConsulta("select * from ".$this->conf->tablePrefix."data WHERE id_post=".$id);
  63. return mysql_fetch_array($this->mid_consulta);
  64. }
  65. function getPostsNumber() {
  66. $this->ejecutarConsulta("select count(*) as total from ".$this->conf->tablePrefix."data");
  67. $row = mysql_fetch_assoc($this->mid_consulta);
  68. return $row['total'];
  69. }
  70. function getType($id) {
  71. if ($this->ejecutarConsulta("select type from ".$this->conf->tablePrefix."data WHERE id_post=".$id)) {
  72. if ($this->contarRegistros()>0) {
  73. while($registro = mysql_fetch_array($this->mid_consulta)) {
  74. return $registro[0];
  75. }
  76. }
  77. } else {
  78. return "0";
  79. }
  80. }
  81. function formatConversation($text) {
  82. $formatedText = "";
  83. $odd=true;
  84. $lines = explode("\n", $text);
  85. $formatedText .= "<ul>\n";
  86. foreach ($lines as $line) {
  87. $pos = strpos($line, ":") + 1;
  88. $label = substr($line, 0, $pos);
  89. $desc = substr($line, $pos, strlen($line));
  90. if ($odd) {
  91. $cssClass = "odd";
  92. } else {
  93. $cssClass = "even";
  94. }
  95. $odd=!$odd;
  96. $formatedText .= " <li class=\"".$cssClass."\">\n";
  97. $formatedText .= " <span class=\"label\">".$label."</span>\n";
  98. $formatedText .= " ".$desc."\n";
  99. $formatedText .= " </li>\n";
  100. }
  101. $formatedText .= "</ul>\n";
  102. // Ugly path fix it ASAP
  103. $formatedText = str_replace("<p>","", $formatedText);
  104. $formatedText = str_replace("</p>","", $formatedText);
  105. return $formatedText;
  106. }
  107. function saveMP3($remoteFileName) {
  108. if (getMP3File($remoteFileName)) {
  109. return true;
  110. } elseif (isGoEar($remoteFileName)) {
  111. return true;
  112. } else {
  113. return false;
  114. }
  115. }
  116. function savePhoto($remoteFileName) {
  117. if (getPhotoFile($remoteFileName)) {
  118. return true;
  119. } else {
  120. return false;
  121. }
  122. }
  123. function getVideoPlayer($url) {
  124. if (isYoutubeVideo($url)) {
  125. $id_video = getYoutubeVideoUrl($url);
  126. return "\t\t\t<object type=\"application/x-shockwave-flash\" style=\"width:500px;height:393px\" data=\"http://www.youtube.com/v/".$id_video."\"><param name=\"movie\" value=\"http://www.youtube.com/v/".$id_video."\" /></object>\n";
  127. } elseif (isVimeoVideo($url)) {
  128. $id_video = getVimeoVideoUrl($url);
  129. return "\t\t\t<object type=\"application/x-shockwave-flash\" style=\"width:500px;height:393px\" data=\"http://www.vimeo.com/moogaloop.swf?clip_id=".$id_video."\"><param name=\"movie\" value=\"http://www.vimeo.com/moogaloop.swf?clip_id=".$id_video."\" /></object>\n";
  130. } else {
  131. return "This URL is not a supported video (YouTube or Vimeo)";
  132. }
  133. }
  134. function getMp3Player($url) {
  135. if (isMP3($url)) {
  136. $playerUrl = $this->conf->urlGelato."/admin/scripts/player.swf?soundFile=".$url;
  137. return "\t\t\t<object type=\"application/x-shockwave-flash\" data=\"" . $playerUrl . "\" width=\"290\" height=\"24\"><param name=\"movie\" value=\"" . $playerUrl . "\" /><param name=\"quality\" value=\"high\" /><param name=\"menu\" value=\"false\" /><param name=\"wmode\" value=\"transparent\" /></object>\n";
  138. } elseif (isGoEar($url)) {
  139. return "\t\t\t<object type=\"application/x-shockwave-flash\" data=\"http://www.goear.com/files/localplayer.swf\" width=\"366\" height=\"75\"><param name=\"movie\" value=\"http://www.goear.com/files/localautoplayer.swf\" /><param name=\"quality\" value=\"high\" /><param name=\"FlashVars\" value=\"file=".getGoEarCode($url)."\" /></object>\n";
  140. } else {
  141. return "This URL is not an MP3 file.";
  142. }
  143. }
  144. }
  145. ?>