A tumblelog CMS built on AJAX, PHP and MySQL.

functions.php 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. <?
  2. /* ===========================
  3. gelato CMS development version
  4. http://www.gelatocms.com/
  5. gelato CMS is a free software licensed under GPL (General public license)
  6. =========================== */
  7. ?>
  8. <?
  9. function beginsWith($str, $sub) {
  10. return (strpos($str, $sub) === 0);
  11. }
  12. function endsWith($str, $sub) {
  13. return (substr($str, strlen($str) - strlen($sub)) == $sub);
  14. }
  15. function getFileName($fileUrl) {
  16. $path = explode('/', $fileUrl);
  17. return $path[count($path)-1];
  18. }
  19. function isMP3($fileUrl) {
  20. if (endsWith($fileUrl, ".mp3")) {
  21. return true;
  22. } else {
  23. return false;
  24. }
  25. }
  26. function getMP3File($remoteFileName) {
  27. if (isMP3($remoteFileName)) {
  28. if (getFile($remoteFileName)) {
  29. return true;
  30. } else {
  31. return false;
  32. }
  33. } else {
  34. return false;
  35. }
  36. }
  37. function isImageFile($photoUrl) {
  38. if (endsWith($photoUrl, ".jpg")) { return true; }
  39. elseif (endsWith($photoUrl, ".gif")) { return true; }
  40. elseif (endsWith($photoUrl, ".png")) { return true; }
  41. else { return false; }
  42. }
  43. function getPhotoFile($remoteFileName) {
  44. if (isImageFile($remoteFileName)) {
  45. if (getFile($remoteFileName)) {
  46. return true;
  47. } else {
  48. return false;
  49. }
  50. } else {
  51. return false;
  52. }
  53. }
  54. function getFile($remoteFileName) {
  55. $fileName = "../uploads/".getFileName($remoteFileName);
  56. $str = file_get_contents($remoteFileName);
  57. if (!$handle = fopen($fileName, 'w')) {
  58. return false;
  59. }
  60. if (fwrite($handle, $str) === FALSE) {
  61. return false;
  62. }
  63. fclose($handle);
  64. return true;
  65. }
  66. function isVimeoVideo($videoUrl) {
  67. if (beginsWith($videoUrl, "http://vimeo.com/clip:") || beginsWith($videoUrl, "http://www.vimeo.com/clip:"))
  68. return true;
  69. else
  70. return false;
  71. }
  72. function getVimeoVideoUrl($videoUrl) {
  73. return array_pop(explode("clip:",$videoUrl));
  74. }
  75. function isYoutubeVideo($videoUrl) {
  76. if (beginsWith($videoUrl, "http://youtube.com/watch?v=") || beginsWith($videoUrl, "http://www.youtube.com/watch?v="))
  77. return true;
  78. else
  79. return false;
  80. }
  81. function getYoutubeVideoUrl($videoUrl) {
  82. $params = explode("?v=", $videoUrl);
  83. $params2 = explode("&",$params[1]);
  84. return $params2[0];
  85. }
  86. function isVideo($url) {
  87. if (isYoutubeVideo($url)) { return true; }
  88. elseif (isVimeoVideo($url)) { return true; }
  89. else { return false; }
  90. }
  91. function sendMail($to, $title, $body, $from) {
  92. $rp = trim($from);
  93. $org = "gelato CMS";
  94. $mailer = "gelato CMS Mailer";
  95. $head = '';
  96. $head .= "Content-Type: text/html \r\n";
  97. $head .= "Date: ". date('r'). " \r\n";
  98. $head .= "Return-Path: $rp \r\n";
  99. $head .= "From: $from \r\n";
  100. $head .= "Sender: $from \r\n";
  101. $head .= "Reply-To: $from \r\n";
  102. $head .= "Organization: $org \r\n";
  103. $head .= "X-Sender: $from \r\n";
  104. $head .= "X-Priority: 3 \r\n";
  105. $head .= "X-Mailer: $mailer \r\n";
  106. $body = str_replace("\r\n", "\n", $body);
  107. $body = str_replace("\n", "\r\n", $body);
  108. return @mail($to, $title, $body, $head);
  109. }
  110. function getThemes() {
  111. $themes_dir = "themes";
  112. $dirs = array();
  113. $path = getcwd();
  114. $dir = (substr(PHP_OS, 0, 3) == 'WIN') ? $path."\\".$themes_dir : $path."/".$themes_dir;
  115. $dir = str_replace("admin\\", "", $dir);
  116. $handle = opendir($dir);
  117. $i=0;
  118. while($filename = readdir($handle)) {
  119. if($filename != "." && $filename != "..") {
  120. $dirs[$i]=trim($filename);
  121. $i++;
  122. }
  123. }
  124. closedir($handle);
  125. return $dirs;
  126. }
  127. ?>