A tumblelog CMS built on AJAX, PHP and MySQL.

gelato.class.php 5.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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("configuration.class.php");
  10. require_once("functions.php");
  11. class gelato extends Conexion_Mysql {
  12. var $conf;
  13. function gelato() {
  14. parent::Conexion_Mysql(DB_name, DB_Server, DB_User, DB_Password);
  15. $this->conf = new configuration();
  16. }
  17. function addPost($fieldsArray) {
  18. if ($this->insertarDeFormulario($this->conf->tablePrefix."data", $fieldsArray)) {
  19. return true;
  20. } else {
  21. return false;
  22. }
  23. }
  24. function getPosts($limit="10", $from="0") {
  25. $sqlStr = "select * from ".$this->conf->tablePrefix."data ORDER BY date DESC LIMIT $from,$limit";
  26. $this->ejecutarConsulta($sqlStr);
  27. return $this->mid_consulta;
  28. }
  29. function getPost($id="") {
  30. $this->ejecutarConsulta("select * from ".$this->conf->tablePrefix."data WHERE id_post=".$id);
  31. return mysql_fetch_array($this->mid_consulta);
  32. }
  33. function getPostsNumber() {
  34. $this->ejecutarConsulta("select count(*) as total from ".$this->conf->tablePrefix."data");
  35. $row = mysql_fetch_assoc($this->mid_consulta);
  36. return $row['total'];
  37. }
  38. function getType($id) {
  39. if ($this->ejecutarConsulta("select type from ".$this->conf->tablePrefix."data WHERE id_post=".$id)) {
  40. if ($this->contarRegistros()>0) {
  41. while($registro = mysql_fetch_array($this->mid_consulta)) {
  42. return $registro[0];
  43. }
  44. }
  45. } else {
  46. return "0";
  47. }
  48. }
  49. function formatConversation($text) {
  50. $formatedText = "";
  51. $odd=true;
  52. $lines = explode("\n", $text);
  53. $formatedText .= "<ul>\n";
  54. foreach ($lines as $line) {
  55. $pos = strpos($line, ":") + 1;
  56. $label = substr($line, 0, $pos);
  57. $desc = substr($line, $pos, strlen($line));
  58. if ($odd) {
  59. $cssClass = "odd";
  60. } else {
  61. $cssClass = "even";
  62. }
  63. $odd=!$odd;
  64. $formatedText .= " <li class=\"".$cssClass."\">\n";
  65. $formatedText .= " <span class=\"label\">".$label."</span>\n";
  66. $formatedText .= " ".$desc."\n";
  67. $formatedText .= " </li>\n";
  68. }
  69. $formatedText .= "</ul>\n";
  70. return $formatedText;
  71. }
  72. function saveMP3($remoteFileName) {
  73. if (getMP3File($remoteFileName)) {
  74. return true;
  75. } else {
  76. return false;
  77. }
  78. }
  79. function savePhoto($remoteFileName) {
  80. if (getPhotoFile($remoteFileName)) {
  81. return true;
  82. } else {
  83. return false;
  84. }
  85. }
  86. function getVideoPlayer($url) {
  87. if (isYoutubeVideo($url)) {
  88. $id_video = getYoutubeVideoUrl($url);
  89. 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";
  90. } elseif (isVimeoVideo($url)) {
  91. $id_video = getVimeoVideoUrl($url);
  92. 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";
  93. } elseif (isGoogleVideo($url)) {
  94. $html = trim(_file_get_contents($url));
  95. $start_code = strpos($html, "var flashObj =\n \"");
  96. $end_code = strpos($html, "\";\n flashObj = flashObj.replace");
  97. $start_code = $start_code + strlen("var flashObj =\n \"");
  98. $video_code = substr($html, $start_code, $end_code - $start_code);
  99. $video_code = str_replace("\u003c", "<", $video_code);
  100. $video_code = str_replace("\u003d", "=", $video_code);
  101. $video_code = str_replace("\\\"", "\"", $video_code);
  102. $video_code = str_replace("width:100%;height:100%;", "width:500px;height:393px", $video_code);
  103. $video_code = str_replace("/googleplayer.swf", "http://video.google.com/googleplayer.swf", $video_code);
  104. $video_code = str_replace("embed", "object", $video_code);
  105. $video_code = str_replace("src=", "data=", $video_code);
  106. $video_code = str_replace('align="middle"', "", $video_code);
  107. $video_code = str_replace('allowScriptAccess="always"', "", $video_code);
  108. $video_code = str_replace('quality="best"', "", $video_code);
  109. $video_code = str_replace('bgcolor="#ffffff"', "", $video_code);
  110. $video_code = str_replace('scale="noScale"', "", $video_code);
  111. $video_code = str_replace('salign="TL"', "", $video_code);
  112. $video_code = str_replace('FlashVars="playerMode=normal&autoPlay=true&docid=-2519555829449987448&clickUrl="', "", $video_code);
  113. $video_code = str_replace(' \\', " /", $video_code);
  114. $video_code = str_replace('\></object\>', ' ></object>', $video_code);
  115. $video_code = str_replace("id=\"VideoPlayback\"", "", $video_code);
  116. $video_code = str_replace("&", "&amp;", $video_code);
  117. return $video_code;
  118. } else {
  119. return "This URL is not a supported video (YouTube, Vimeo or Google Video)";
  120. }
  121. }
  122. function getMp3Player($url) {
  123. if (isMP3($url)) {
  124. $playerUrl = $this->conf->urlGelato."/admin/scripts/player.swf?soundFile=".$url;
  125. 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";
  126. } else {
  127. return "This URL is not a supported video (YouTube or Vimeo)";
  128. }
  129. }
  130. }
  131. ?>