=========================== */ ?> endsWith($fileUrl, ".mp3")) { return true; } else { return false; } } public function getMP3File($remoteFileName) { $util_class = new util(); if ($util_class->isMP3($remoteFileName)) { if ($util_class->getFile($remoteFileName)) { return true; } else { return false; } } elseif ($util_class->isGoEar($remoteFileName)) { return true; } elseif ($util_class->isOdeo($remoteFileName)) { return true; } else { return false; } } public function getGoEarCode($songUrl) { $pos = strpos($songUrl, "?v="); $lon = strlen($songUrl); $str = substr($songUrl, $pos + 3, $lon); return $str; } public function isGoEar($songUrl) { $util_class = new util(); if ($util_class->beginsWith($songUrl, "http://www.goear.com/listen.php?v=") || $util_class->beginsWith($songUrl, "http://goear.com/listen.php?v=")) { return true; } else { return false; } } public function isOdeo($songUrl) { $util_class = new util(); if ($util_class->beginsWith($songUrl, "http://odeo.com/audio/") || $util_class->beginsWith($songUrl, "http://www.odeo.com/audio/")) { return true; } else { return false; } } public function getOdeoCode($songUrl) { $params = explode("audio/", $songUrl); $params2 = explode("/", $params[1]); return $params2[0]; } public function isImageFile($photoUrl) { $util_class = new util(); if ($util_class->endsWith($photoUrl, ".jpg")) { return true; } elseif ($util_class->endsWith($photoUrl, ".gif")) { return true; } elseif ($util_class->endsWith($photoUrl, ".png")) { return true; } else { return false; } } public function getPhotoFile($remoteFileName) { $util_class = new util(); if ($util_class->isImageFile($remoteFileName)) { if ($util_class->getFile($remoteFileName)) { return true; } else { return false; } } else { return false; } } public function getFile($remoteFileName) { $util_class = new util(); $fileName = "../uploads/".$util_class->sanitizeName($util_class->getFileName($remoteFileName)); $str = $util_class->_file_get_contents($remoteFileName); if (!$handle = fopen($fileName, 'w')) { //die("no se abrio de escritura"); return false; } if (fwrite($handle, $str) === false) { //die("no se escribio"); return false; } fclose($handle); return true; } public function isVimeoVideo($videoUrl) { $util_class = new util(); if ($util_class->beginsWith($videoUrl, "http://vimeo.com/") || $util_class->beginsWith($videoUrl, "http://www.vimeo.com/")) { return true; } else { return false; } } public function getVimeoVideoUrl($videoUrl) { if (substr_count($videoUrl, "clip:")==1) { return array_pop(explode("clip:", $videoUrl)); } else { return array_pop(explode("/", $videoUrl)); } } public function isYoutubeVideo($videoUrl) { $url = explode("?", $videoUrl); $util_class = new util(); if (($util_class->beginsWith($url[0], "https://") && $util_class->endsWith($url[0], ".youtube.com/watch")) || $util_class->beginsWith($url[0], "https://youtube.com/watch")) { return true; } else { return false; } } public function getYoutubeVideoUrl($videoUrl) { $params = explode("?v=", $videoUrl); $params2 = explode("&", $params[1]); return $params2[0]; } public function isYahooVideo($videoUrl) { $util_class = new util(); if ($util_class->beginsWith($videoUrl, "http://video.yahoo.com/watch/") || $util_class->beginsWith($videoUrl, "http://www.video.yahoo.com/watch/")) { return true; } else { return false; } } public function getYahooVideoCode($videoUrl) { $params = explode("http://video.yahoo.com/watch/", $videoUrl); $params2 = explode("/", $params[1]); $values[0] = $params2[0]; $values[1] = $params2[1]; return $values; } public function isGoogleVideoUrl($videoUrl) { $util_class = new util(); if ($util_class->beginsWith($videoUrl, "http://video.google.com/videoplay?")) { return true; } else { return false; } } public function getGoogleVideoCode($videoUrl) { $params = explode("?docid=", $videoUrl); $params2 = explode("&", $params[1]); return $params2[0]; } public function isMTVVideoUrl($videoUrl) { $util_class = new util(); if ($util_class->beginsWith($videoUrl, "http://www.mtvmusic.com/video/?id=") || $util_class->beginsWith($videoUrl, "http://mtvmusic.com/video/?id=")) { return true; } else { return false; } } public function getMTVVideoCode($videoUrl) { $params = explode("?id=", $videoUrl); $params2 = explode("&", $params[1]); return $params2[0]; } public function isDailymotionVideo($videoUrl) { $util_class = new util(); if ($util_class->beginsWith($videoUrl, "http://www.dailymotion.com/video/") || $util_class->beginsWith($videoUrl, "http://dailymotion.com/video/")) { return true; } else { return false; } } public function getDailymotionVideoUrl($videoUrl) { $params = explode("video/", $videoUrl); $params2 = explode("_", $params[1]); return $params2[0]; } public function isSlideSharePresentation($videoUrl) { $util_class = new util(); if ($util_class->beginsWith($videoUrl, "[slideshare id=")) { return true; } else { return false; } } public function getSlideSharePresentationCode($videoUrl) { $videoUrl = str_replace("[slideshare id=", "", $videoUrl); $videoUrl = str_replace("&doc=", " ", $videoUrl); $videoUrl = str_replace("&w=", " ", $videoUrl); return explode(" ", $videoUrl); } public function isVideo($url) { $util_class = new util(); if ($util_class->isYoutubeVideo($url)) { return true; } elseif ($util_class->isVimeoVideo($url)) { return true; } elseif ($util_class->isDailymotionVideo($url)) { return true; } elseif ($util_class->isYahooVideo($url)) { return true; } elseif ($util_class->isSlideSharePresentation($url)) { return true; } elseif ($util_class->isGoogleVideoUrl($url)) { return true; } elseif ($util_class->isMTVVideoUrl($url)) { return true; } else { return false; } } public function sendMail($to, $title, $body, $from) { $rp = trim($from); $org = "gelato CMS"; $mailer = "gelato CMS Mailer"; $head = ''; $head .= "Content-Type: text/html \r\n"; $head .= "Date: ". date('r'). " \r\n"; $head .= "Return-Path: $rp \r\n"; $head .= "From: $from \r\n"; $head .= "Sender: $from \r\n"; $head .= "Reply-To: $from \r\n"; $head .= "Organization: $org \r\n"; $head .= "X-Sender: $from \r\n"; $head .= "X-Priority: 3 \r\n"; $head .= "X-Mailer: $mailer \r\n"; $body = str_replace("\r\n", "\n", $body); $body = str_replace("\n", "\r\n", $body); return @mail($to, $title, $body, $head); } public function getThemes() { $themes_dir = "themes"; $dirs = array(); $path = getcwd(); $dir = (substr(PHP_OS, 0, 3) == 'WIN') ? $path."\\".$themes_dir : $path."/".$themes_dir; $dir = str_replace("admin\\", "", $dir); $dir = str_replace("admin/", "", $dir); $handle = opendir($dir); $i=0; while ($filename = readdir($handle)) { if ($filename != "." && $filename != ".." && $filename != ".svn") { $dirs[$i]=trim($filename); $i++; } } closedir($handle); return $dirs; } public function sanitizeName($name) { $name = preg_replace('/[\'"]/', '', $name); $name = preg_replace('/[^a-zA-Z0-9]+/', '-', $name); $name = trim($name, '-'); $name = strtolower($name); //HACK: We need to rework the regular expression to allow the dot $ext = substr($name, strlen($name)-3, strlen($name)); $body = substr($name, 0, strlen($name)-4); $name = $body.".".$ext; return $name; } public function _file_get_contents($path) { $util_class = new util(); // Modified function from: // http://work.dokoku.net/Anieto2k/_file_get_contents.phps // http://www.anieto2k.com/2007/02/09/file_get_contents-y-dreamhost/ if (!preg_match('/^http/i', $path)) { if ($fp = fopen($path, 'r')) { return fread($fp, 1024); } else { return false; } } else { if (extension_loaded('curl') && version_compare($util_class->get_curl_version(), '7.10.5', '>=')) { $ch = curl_init(); $timeout = 5; curl_setopt($ch, CURLOPT_URL, $path); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout); $file_contents = curl_exec($ch); curl_close($ch); if (is_string($file_contents)) { return $file_contents; } else { return false; } } else { $data = parse_url($path); if (!$data['host'] || $data['scheme'] != "http") { return false; } $f = @fsockopen($data['host'], ($data['port']) ? $data['port'] : 80, $e1, $e2, 3); if (!$f) { return false; } $q = "GET " . $data['path'] . (isset($data['query'])?'?'.$data['query']:'') . " HTTP/1.1\r\n"; $q .= "Host: " . $data['host'] . "\r\n"; $q .= "Connection: close\r\n"; $q .= "Referer: http://www.gelatocms.com/\r\n\r\n"; $recv = ""; fwrite($f, $q); while (!feof($f)) { $recv .= fread($f, 1024); } $request = $q; $response = substr($recv, 0, strpos($recv, "\r\n\r\n")); $body = substr($recv, strpos($recv, "\r\n\r\n") + 4); if (preg_match('/http\/1\\.[0|1] ([0-9]{3})/i', $response, $res)) { if ($res[1][0] != "2") { return false; } } else { return false; } if (preg_match('/transfer-encoding:\s*chunked/i', $response)) { $tmp_body = $body; $new = ""; $exit = false; while (!$exit) { if (preg_match('/^([0-9a-f]+).*?\r\n/i', $tmp_body, $res)) { $len = hexdec($res[1]); if ($len == "0") { $exit = true; break; } $new .= substr($tmp_body, strlen($res[0]), $len); $tmp_body = substr($tmp_body, strlen($res[0]) + $len + strlen("\r\n")); } else { $exit = true; } } $body = $new; } return $body; } } } public function get_curl_version() { $curl = 0; if (is_array(curl_version())) { $curl = curl_version(); $curl = $curl['version']; } else { $curl = curl_version(); $curl = explode(' ', $curl); $curl = explode('/', $curl[0]); $curl = $curl[1]; } return $curl; } public function transform_offset($offset) { $sp = strpos($offset, ".")? explode(".", $offset) : false; if (is_array($sp)) { $minutes = strval($sp[1]); $off_h = $sp[0]*3600; $off_m = (($minutes*60)/100)*60; $off = $off_h+$off_m; } else { $off = ($offset*3600); } return $off; } public function getLangs() { $langs_dir = "languages"; $dirs = array(); $path = getcwd(); $dir = (substr(PHP_OS, 0, 3) == 'WIN') ? $path."\\".$langs_dir : $path."/".$langs_dir; $dir = str_replace("admin\\", "", $dir); $dir = str_replace("admin/", "", $dir); $i=0; $cls_lang_dir = @ dir($dir); while (($directory = $cls_lang_dir->read()) !== false) { if ($directory != "." && $directory != "..") { $dir2 = (substr(PHP_OS, 0, 3) == 'WIN') ? $path."\\".$langs_dir."\\".$directory : $path."/".$langs_dir."/".$directory; $dir2 = str_replace("admin\\", "", $dir2); $dir2 = str_replace("admin/", "", $dir2); if (is_dir($dir2)) { $cls_lang_dir2 = @ dir($dir2); while (($directory2 = $cls_lang_dir2->read()) !== false) { if ($directory2 != "." && $directory2 != "..") { if (preg_match('|^\.+$|', $directory2)) { continue; } if (preg_match('|\.mo$|', $directory2)) { if (!in_array($directory2, $dirs)) { $dirs[$directory]=$util_class->displayLanguage(trim($directory)); $i++; } } } } } } } $dirs = array_unique($dirs); return $dirs; } public function removeBadTags($source, $secure=false) { $util_class = new util(); if ($secure) { $validTags ='
'; } else { $validTags ='