A tumblelog CMS built on AJAX, PHP and MySQL.

gelato.class.php 5.4KB

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