A tumblelog CMS built on AJAX, PHP and MySQL.

gelato.class.php 8.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  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 formatApiConversation($text) {
  105. $formatedText = "";
  106. $lines = explode("\n", $text);
  107. foreach ($lines as $line) {
  108. $pos = strpos($line, ":") + 1;
  109. $name = substr($line, 0, $pos-1);
  110. $label = substr($line, 0, $pos);
  111. $desc = substr($line, $pos, strlen($line));
  112. $formatedText .= "<conversation-line name=\"".$name."\" label=\"".$label."\">".$desc."</conversation-line>\n";
  113. }
  114. return $formatedText;
  115. }
  116. function saveMP3($remoteFileName) {
  117. if (getMP3File($remoteFileName)) {
  118. return true;
  119. } else {
  120. return false;
  121. }
  122. }
  123. function savePhoto($remoteFileName) {
  124. if (getPhotoFile($remoteFileName)) {
  125. return true;
  126. } else {
  127. return false;
  128. }
  129. }
  130. function getVideoPlayer($url) {
  131. if (isYoutubeVideo($url)) {
  132. $id_video = getYoutubeVideoUrl($url);
  133. 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";
  134. } elseif (isVimeoVideo($url)) {
  135. $id_video = getVimeoVideoUrl($url);
  136. 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";
  137. } elseif (isDailymotionVideo($url)) {
  138. $id_video = getDailymotionVideoUrl($url);
  139. 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";
  140. } elseif (isYahooVideo($url)) {
  141. $id_video = getYahooVideoCode($url);
  142. 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";
  143. } elseif (isSlideSharePresentation($url)) {
  144. $id_video = getSlideSharePresentationCode($url);
  145. 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";
  146. } elseif (isGoogleVideoUrl($url)) {
  147. $id_video = getGoogleVideoCode($url);
  148. 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";
  149. } else {
  150. return "This URL is not a supported video (YouTube, Google Video, Vimeo, DailyMotion, Yahoo Video or SlideShare)";
  151. }
  152. }
  153. function getMp3Player($url) {
  154. if (isMP3($url)) {
  155. $playerUrl = $this->conf->urlGelato."/admin/scripts/player.swf?soundFile=".$url;
  156. 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";
  157. } elseif (isGoEar($url)) {
  158. 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=".getGoEarCode($url)."\" /><param name=\"wmode\" value=\"transparent\" /></object>\n";
  159. } elseif (isOdeo($url)) {
  160. 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=".getOdeoCode($url)."\" /><param name=\"wmode\" value=\"transparent\" /></object>\n";
  161. } else {
  162. return "This URL is not an MP3 file.";
  163. }
  164. }
  165. function getPermalink($post_id){
  166. $strEnd = ($this->conf->urlFriendly) ? "/" : "";
  167. $out = $this->conf->urlGelato;
  168. $out .= ($this->conf->urlFriendly) ? "/post/" : "/index.php?post=";
  169. $out .= $post_id.$strEnd;
  170. return $out;
  171. }
  172. function getPermalink($post_id){
  173. $strEnd = ($this->conf->urlFriendly) ? "/" : "";
  174. $out = $this->conf->urlGelato;
  175. $out .= ($this->conf->urlFriendly) ? "/post/" : "/index.php?post=";
  176. $out .= $post_id.$strEnd;
  177. return $out;
  178. }
  179. }
  180. ?>