A tumblelog CMS built on AJAX, PHP and MySQL.

gelato.class.php 9.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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. class gelato {
  11. var $db;
  12. var $conf;
  13. function gelato() {
  14. global $db;
  15. global $conf;
  16. $this->db = $db;
  17. $this->conf = $conf;
  18. }
  19. function saveSettings($fieldsArray) {
  20. if ($this->db->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->db->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->db->ejecutarConsulta($sqlStr)) {
  31. return true;
  32. } else {
  33. return true;
  34. }
  35. }
  36. function addPost($fieldsArray) {
  37. if ($this->db->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->db->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->db->merror);
  49. die();
  50. }
  51. }
  52. function deletePost($idPost) {
  53. $this->db->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->db->ejecutarConsulta($sqlStr);
  58. return $this->db->mid_consulta;
  59. }
  60. function getPost($id="") {
  61. $this->db->ejecutarConsulta("select * from ".$this->conf->tablePrefix."data WHERE id_post=".$id);
  62. return mysql_fetch_array($this->db->mid_consulta);
  63. }
  64. function getPostsNumber() {
  65. $this->db->ejecutarConsulta("select count(*) as total from ".$this->conf->tablePrefix."data");
  66. $row = mysql_fetch_assoc($this->db->mid_consulta);
  67. return $row['total'];
  68. }
  69. function getType($id) {
  70. if ($this->db->ejecutarConsulta("select type from ".$this->conf->tablePrefix."data WHERE id_post=".$id)) {
  71. if ($this->db->contarRegistros()>0) {
  72. while($registro = mysql_fetch_array($this->db->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 formatApiConversation($text) {
  104. $formatedText = "";
  105. $lines = explode("\n", $text);
  106. foreach ($lines as $line) {
  107. $pos = strpos($line, ":") + 1;
  108. $name = substr($line, 0, $pos-1);
  109. $label = substr($line, 0, $pos);
  110. $desc = substr($line, $pos, strlen($line));
  111. $formatedText .= "<conversation-line name=\"".$name."\" label=\"".$label."\">".$desc."</conversation-line>\n";
  112. }
  113. return $formatedText;
  114. }
  115. function saveMP3($remoteFileName) {
  116. if (util::getMP3File($remoteFileName)) {
  117. return true;
  118. } else {
  119. return false;
  120. }
  121. }
  122. function savePhoto($remoteFileName) {
  123. if (util::getPhotoFile($remoteFileName)) {
  124. return true;
  125. } else {
  126. return false;
  127. }
  128. }
  129. function getVideoPlayer($url) {
  130. if (util::isYoutubeVideo($url)) {
  131. $id_video = util::getYoutubeVideoUrl($url);
  132. 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."\" /><param name=\"wmode\" value=\"transparent\" /></object>\n";
  133. } elseif (util::isVimeoVideo($url)) {
  134. $id_video = util::getVimeoVideoUrl($url);
  135. 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."\" /><param name=\"wmode\" value=\"transparent\" /></object>\n";
  136. } elseif (util::isDailymotionVideo($url)) {
  137. $id_video = util::getDailymotionVideoUrl($url);
  138. return "\t\t\t<object type=\"application/x-shockwave-flash\" style=\"width:500px;height:393px\" data=\"http://www.dailymotion.com/swf/".$id_video."\"><param name=\"movie\" value=\"http://www.dailymotion.com/swf/".$id_video."\" /><param name=\"wmode\" value=\"transparent\" /></object>\n";
  139. } elseif (util::isYahooVideo($url)) {
  140. $id_video = util::getYahooVideoCode($url);
  141. return "\t\t\t<object type=\"application/x-shockwave-flash\" style=\"width:500px;height:393px\" data=\"http://d.yimg.com/static.video.yahoo.com/yep/YV_YEP.swf\"><param name=\"quality\" value=\"high\" /><param name=\"FlashVars\" value=\"event_function=YAHOO.yv.Player.SWFInterface&amp;id=".$id_video[1]."&amp;vid=".$id_video[0]."&amp;onsite=1&amp;site=video.yahoo.com&amp;page=792730258&amp;lang=en-US&amp;intl=us\" /><param name=\"wmode\" value=\"transparent\" /></object>\n";
  142. } elseif (util::isSlideSharePresentation($url)) {
  143. $id_video = util::getSlideSharePresentationCode($url);
  144. return "\t\t\t<object type=\"application/x-shockwave-flash\" style=\"width:500px;height:393px\" data=\"http://www.slideshare.net/swf/player.swf?presentationId=".$id_video[0]."&amp;doc=".$id_video[1]."&amp;inContest=0&amp;startSlide=1\"><param name=\"quality\" value=\"high\" /><param name=\"wmode\" value=\"transparent\" /></object>\n";
  145. } elseif (util::isGoogleVideoUrl($url)) {
  146. $id_video = util::getGoogleVideoCode($url);
  147. return "\t\t\t<object type=\"application/x-shockwave-flash\" style=\"width:500px;height:393px\" data=\"http://video.google.com/googleplayer.swf?docid=".$id_video."&amp;hl=es&amp;fs=true\"><param name=\"movie\" value=\"http://video.google.com/googleplayer.swf?docid=".$id_video."&amp;hl=es&amp;fs=true\" /><param name=\"allowFullScreen\" value=\"true\" /><param name=\"allowScriptAccess\" value=\"always\" /><param name=\"wmode\" value=\"transparent\" /></object>\n";
  148. } elseif (util::isMTVVideoUrl($url)) {
  149. $id_video = util::getMTVVideoCode($url);
  150. return "\t\t\t<object type=\"application/x-shockwave-flash\" style=\"width:500px;height:393px\" data=\"http://media.mtvnservices.com/mgid:uma:video:mtvmusic.com:".$id_video."\"><param name=\"movie\" value=\"http://media.mtvnservices.com/mgid:uma:video:mtvmusic.com:".$id_video."\" /><param name=\"allowFullScreen\" value=\"true\" /><param name=\"allowScriptAccess\" value=\"never\" /><param name=\"wmode\" value=\"transparent\" /></object>\n";
  151. } else {
  152. return "This URL is not a supported video (YouTube, Google Video, Vimeo, DailyMotion, Yahoo Video, MTV or SlideShare)";
  153. }
  154. }
  155. function getMp3Player($url) {
  156. if (util::isMP3($url)) {
  157. $playerUrl = $conf->urlGelato."/admin/scripts/player.swf?soundFile=".$url;
  158. 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";
  159. } elseif (util::isGoEar($url)) {
  160. return "\t\t\t<object type=\"application/x-shockwave-flash\" data=\"http://www.goear.com/files/external.swf\" width=\"366\" height=\"130\"><param name=\"movie\" value=\"http://www.goear.com/files/external.swf\" /><param name=\"quality\" value=\"high\" /><param name=\"FlashVars\" value=\"file=".util::getGoEarCode($url)."\" /><param name=\"wmode\" value=\"transparent\" /></object>\n";
  161. } elseif (util::isOdeo($url)) {
  162. return "\t\t\t<object type=\"application/x-shockwave-flash\" data=\"http://media.odeo.com/flash/odeo_player.swf?v=3\" width=\"366\" height=\"75\"><param name=\"quality\" value=\"high\" /><param name=\"FlashVars\" value=\"type=audio&amp;id=".util::getOdeoCode($url)."\" /><param name=\"wmode\" value=\"transparent\" /></object>\n";
  163. } else {
  164. return "This URL is not an MP3 file.";
  165. }
  166. }
  167. function getPermalink($post_id){
  168. $strEnd = ($this->conf->urlFriendly) ? "/" : "";
  169. $out = $this->conf->urlGelato;
  170. $out .= ($this->conf->urlFriendly) ? "/post/" : "/index.php?post=";
  171. $out .= $post_id.$strEnd;
  172. return $out;
  173. }
  174. }
  175. ?>