A tumblelog CMS built on AJAX, PHP and MySQL.

sorbet.class.php 10KB

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