A tumblelog CMS built on AJAX, PHP and MySQL.

gelato.class.php 10KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. <?php
  2. if (!defined('entry') || !entry) {
  3. die('Not a valid page');
  4. }
  5. /* ===========================
  6. gelato CMS - A PHP based tumblelog CMS
  7. development version
  8. http://www.gelatocms.com/
  9. gelato CMS is a free software licensed under the GPL 2.0
  10. Copyright (C) 2007 by Pedro Santana <pecesama at gmail dot com>
  11. =========================== */
  12. $util_class = new util();
  13. class gelato
  14. {
  15. public $db;
  16. public $conf;
  17. public function __construct()
  18. {
  19. global $db;
  20. global $conf;
  21. $this->db = $db;
  22. $this->conf = $conf;
  23. }
  24. public function saveSettings($fieldsArray)
  25. {
  26. if ($this->db->modificarDeFormulario($this->conf->tablePrefix."config", $fieldsArray)) {
  27. header("Location: ".$this->conf->urlGelato."/admin/settings.php?modified=true");
  28. die();
  29. } else {
  30. header("Location: ".$this->conf->urlGelato."/admin/settings.php?error=1&des=".$this->db->merror);
  31. die();
  32. }
  33. }
  34. public function saveOption($value, $name)
  35. {
  36. $sqlStr = "UPDATE ".$this->conf->tablePrefix."options SET val='".$value."' WHERE name='".$name."' LIMIT 1";
  37. if ($this->db->ejecutarConsulta($sqlStr)) {
  38. return true;
  39. } else {
  40. return true;
  41. }
  42. }
  43. public function addPost($fieldsArray)
  44. {
  45. if ($this->db->insertarDeFormulario($this->conf->tablePrefix."data", $fieldsArray)) {
  46. return true;
  47. } else {
  48. return false;
  49. }
  50. }
  51. public function modifyPost($fieldsArray, $id_post)
  52. {
  53. if ($this->db->modificarDeFormulario($this->conf->tablePrefix."data", $fieldsArray, "id_post=$id_post")) {
  54. header("Location: ".$this->conf->urlGelato."/admin/index.php?modified=true");
  55. die();
  56. } else {
  57. header("Location: ".$this->conf->urlGelato."/admin/index.php?error=2&des=".$this->db->merror);
  58. die();
  59. }
  60. }
  61. public function deletePost($idPost)
  62. {
  63. $this->db->ejecutarConsulta("DELETE FROM ".$this->conf->tablePrefix."data WHERE id_post=".$idPost);
  64. }
  65. public function getPosts($limit="10", $from="0")
  66. {
  67. $sqlStr = "select * from ".$this->conf->tablePrefix."data ORDER BY date DESC LIMIT $from,$limit";
  68. $this->db->ejecutarConsulta($sqlStr);
  69. return $this->db->mid_consulta;
  70. }
  71. public function getPost($id="")
  72. {
  73. $this->db->ejecutarConsulta("select * from ".$this->conf->tablePrefix."data WHERE id_post=".$id);
  74. return $this->db->mid_consulta->fetch();
  75. }
  76. public function getPostsNumber()
  77. {
  78. $this->db->ejecutarConsulta("select count(*) as total from ".$this->conf->tablePrefix."data");
  79. $row = $this->db->mid_consulta->fetch();
  80. return $row['total'];
  81. }
  82. public function getType($id)
  83. {
  84. if ($this->db->ejecutarConsulta("select type from ".$this->conf->tablePrefix."data WHERE id_post=".$id)) {
  85. if ($this->db->contarRegistros()>0) {
  86. while ($registro = $this->db->mid_consulta->fetch()) {
  87. return $registro[0];
  88. }
  89. }
  90. } else {
  91. return "0";
  92. }
  93. }
  94. public function formatConversation($text)
  95. {
  96. $formatedText = "";
  97. $odd=true;
  98. $lines = explode("\n", $text);
  99. $formatedText .= "<ul>\n";
  100. foreach ($lines as $line) {
  101. $pos = strpos($line, ":") + 1;
  102. $label = substr($line, 0, $pos);
  103. $desc = substr($line, $pos, strlen($line));
  104. if ($odd) {
  105. $cssClass = "odd";
  106. } else {
  107. $cssClass = "even";
  108. }
  109. $odd=!$odd;
  110. $formatedText .= " <li class=\"".$cssClass."\">\n";
  111. $formatedText .= " <span class=\"label\">".$label."</span>\n";
  112. $formatedText .= " ".$desc."\n";
  113. $formatedText .= " </li>\n";
  114. }
  115. $formatedText .= "</ul>\n";
  116. return $formatedText;
  117. }
  118. public function formatApiConversation($text)
  119. {
  120. $formatedText = "";
  121. $lines = explode("\n", $text);
  122. foreach ($lines as $line) {
  123. $pos = strpos($line, ":") + 1;
  124. $name = substr($line, 0, $pos-1);
  125. $label = substr($line, 0, $pos);
  126. $desc = substr($line, $pos, strlen($line));
  127. $formatedText .= "<conversation-line name=\"".$name."\" label=\"".$label."\">".$desc."</conversation-line>\n";
  128. }
  129. return $formatedText;
  130. }
  131. public function saveMP3($remoteFileName)
  132. {
  133. if ($util_class->getMP3File($remoteFileName)) {
  134. return true;
  135. } else {
  136. return false;
  137. }
  138. }
  139. public function savePhoto($remoteFileName)
  140. {
  141. if ($util_class->getPhotoFile($remoteFileName)) {
  142. return true;
  143. } else {
  144. return false;
  145. }
  146. }
  147. public function getVideoPlayer($url)
  148. {
  149. $util_class = new util();
  150. if ($util_class->isYoutubeVideo($url)) {
  151. $id_video = $util_class->getYoutubeVideoUrl($url);
  152. 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";
  153. } elseif ($util_class->isVimeoVideo($url)) {
  154. $id_video = $util_class->getVimeoVideoUrl($url);
  155. 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";
  156. } elseif ($util_class->isDailymotionVideo($url)) {
  157. $id_video = $util_class->getDailymotionVideoUrl($url);
  158. 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";
  159. } elseif ($util_class->isYahooVideo($url)) {
  160. $id_video = $util_class->getYahooVideoCode($url);
  161. 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";
  162. } elseif ($util_class->isSlideSharePresentation($url)) {
  163. $id_video = $util_class->getSlideSharePresentationCode($url);
  164. 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";
  165. } elseif ($util_class->isGoogleVideoUrl($url)) {
  166. $id_video = $util_class->getGoogleVideoCode($url);
  167. 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";
  168. } elseif ($util_class->isMTVVideoUrl($url)) {
  169. $id_video = $util_class->getMTVVideoCode($url);
  170. 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";
  171. } else {
  172. return "This URL is not a supported video (YouTube, Google Video, Vimeo, DailyMotion, Yahoo Video, MTV or SlideShare)";
  173. }
  174. }
  175. public function getMp3Player($url)
  176. {
  177. if ($util_class->isMP3($url)) {
  178. $playerUrl = $conf->urlGelato."/admin/scripts/player.swf?soundFile=".$url;
  179. 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";
  180. } elseif ($util_class->isGoEar($url)) {
  181. 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_class->getGoEarCode($url)."\" /><param name=\"wmode\" value=\"transparent\" /></object>\n";
  182. } elseif ($util_class->isOdeo($url)) {
  183. 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_class->getOdeoCode($url)."\" /><param name=\"wmode\" value=\"transparent\" /></object>\n";
  184. } else {
  185. return "This URL is not an MP3 file.";
  186. }
  187. }
  188. public function getPermalink($post_id)
  189. {
  190. $strEnd = ($this->conf->urlFriendly) ? "/" : "";
  191. $out = $this->conf->urlGelato;
  192. $out .= ($this->conf->urlFriendly) ? "/post/" : "/index.php?post=";
  193. $out .= $post_id.$strEnd;
  194. return $out;
  195. }
  196. }