A tumblelog CMS built on AJAX, PHP and MySQL.

sorbet.class.php 9.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  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. $util_class = new util();
  131. if ($util_class->getMP3File($remoteFileName)) {
  132. return true;
  133. } else {
  134. return false;
  135. }
  136. }
  137. public function savePhoto($remoteFileName)
  138. {
  139. $util_class = new util();
  140. if ($util_class->getPhotoFile($remoteFileName)) {
  141. return true;
  142. } else {
  143. return false;
  144. }
  145. }
  146. public function getVideoPlayer($url)
  147. {
  148. $util_class = new util();
  149. if ($util_class->isYoutubeVideo($url)) {
  150. $id_video = $util_class->getYoutubeVideoUrl($url);
  151. return "\t\t\t<iframe width=\"640\" height=\"360\" src=\"https://www.youtube.com/embed/".$id_video."\" frameborder=\"0\" allowfullscreen></iframe>\n";
  152. } elseif ($util_class->isVimeoVideo($url)) {
  153. $id_video = $util_class->getVimeoVideoUrl($url);
  154. return "\t\t\t<iframe src=\"https://player.vimeo.com/video/".$id_video."\" width=\"640\" height=\"360\" frameborder=\"0\" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>\n";
  155. } elseif ($util_class->isDailymotionVideo($url)) {
  156. $id_video = $util_class->getDailymotionVideoUrl($url);
  157. return "\t\t\t<iframe frameborder=\"0\" width=\"640\" height=\"360\" src=\"//www.dailymotion.com/embed/video/".$id_video."\" allowfullscreen></iframe><br />\n";
  158. } elseif ($util_class->isYahooVideo($url)) {
  159. $id_video = $util_class->getYahooVideoCode($url);
  160. 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";
  161. } elseif ($util_class->isSlideSharePresentation($url)) {
  162. $id_video = $util_class->getSlideSharePresentationCode($url);
  163. 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";
  164. } elseif ($util_class->isGoogleVideoUrl($url)) {
  165. $id_video = $util_class->getGoogleVideoCode($url);
  166. 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";
  167. } elseif ($util_class->isMTVVideoUrl($url)) {
  168. $id_video = $util_class->getMTVVideoCode($url);
  169. 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";
  170. } else {
  171. return "This URL is not a supported video (YouTube, Google Video, Vimeo, DailyMotion, Yahoo Video, MTV or SlideShare)";
  172. }
  173. }
  174. public function getMp3Player($url)
  175. {
  176. $util_class = new util();
  177. $global_url = $this->conf->urlSorbet;
  178. if ($util_class->isMP3($url)) {
  179. return "\t\t\t<audio src=\"".$url."\" title=\"Track Name\" data-artist=\"Artist\" controls>Your browser does not support the <code>audio</code> element.</audio>\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->urlSorbet;
  192. $out .= ($this->conf->urlFriendly) ? "/post/" : "/index.php?post=";
  193. $out .= $post_id.$strEnd;
  194. return $out;
  195. }
  196. }