A tumblelog CMS built on AJAX, PHP and MySQL.

gelato.class.php 5.6KB

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