A tumblelog CMS built on AJAX, PHP and MySQL.

gelato.class.php 5.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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. return $formatedText;
  103. }
  104. function saveMP3($remoteFileName) {
  105. if (getMP3File($remoteFileName)) {
  106. return true;
  107. } elseif (isGoEar($remoteFileName)) {
  108. return true;
  109. } else {
  110. return false;
  111. }
  112. }
  113. function savePhoto($remoteFileName) {
  114. if (getPhotoFile($remoteFileName)) {
  115. return true;
  116. } else {
  117. return false;
  118. }
  119. }
  120. function getVideoPlayer($url) {
  121. if (isYoutubeVideo($url)) {
  122. $id_video = getYoutubeVideoUrl($url);
  123. 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";
  124. } elseif (isVimeoVideo($url)) {
  125. $id_video = getVimeoVideoUrl($url);
  126. 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";
  127. } else {
  128. return "This URL is not a supported video (YouTube or Vimeo)";
  129. }
  130. }
  131. function getMp3Player($url) {
  132. if (isMP3($url)) {
  133. $playerUrl = $this->conf->urlGelato."/admin/scripts/player.swf?soundFile=".$url;
  134. 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";
  135. } elseif (isGoEar($url)) {
  136. 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";
  137. } else {
  138. return "This URL is not an MP3 file.";
  139. }
  140. }
  141. }
  142. ?>