Bug fixed with the Offset in trimString function.

master
Victor De la Rocha 2008-10-26 23:32:55 +00:00
parent ac111d5348
commit 87a8876594
1 changed files with 64 additions and 62 deletions

View File

@ -1,5 +1,5 @@
<?php <?php
if(!defined('entry') || !entry) die('Not a valid page'); if(!defined('entry') || !entry) die('Not a valid page');
/* =========================== /* ===========================
gelato CMS - A PHP based tumblelog CMS gelato CMS - A PHP based tumblelog CMS
@ -15,32 +15,32 @@ if(!defined('entry') || !entry) die('Not a valid page');
function version() { function version() {
return "1.0"; return "1.0";
} }
function codeName() { function codeName() {
return "vaniglia RC1"; return "vaniglia RC1";
} }
function beginsWith($str, $sub) { function beginsWith($str, $sub) {
return (strpos($str, $sub) === 0); return (strpos($str, $sub) === 0);
} }
function endsWith($str, $sub) { function endsWith($str, $sub) {
return (substr($str, strlen($str) - strlen($sub)) == $sub); return (substr($str, strlen($str) - strlen($sub)) == $sub);
} }
function getFileName($fileUrl) { function getFileName($fileUrl) {
$path = explode('/', $fileUrl); $path = explode('/', $fileUrl);
return $path[count($path)-1]; return $path[count($path)-1];
} }
function isMP3($fileUrl) { function isMP3($fileUrl) {
if (endsWith($fileUrl, ".mp3")) { if (endsWith($fileUrl, ".mp3")) {
return true; return true;
} else { } else {
return false; return false;
} }
} }
function getMP3File($remoteFileName) { function getMP3File($remoteFileName) {
if (isMP3($remoteFileName)) { if (isMP3($remoteFileName)) {
if (getFile($remoteFileName)) { if (getFile($remoteFileName)) {
@ -51,48 +51,48 @@ if(!defined('entry') || !entry) die('Not a valid page');
} elseif (isGoEar($remoteFileName)) { } elseif (isGoEar($remoteFileName)) {
return true; return true;
} elseif (isOdeo($remoteFileName)) { } elseif (isOdeo($remoteFileName)) {
return true; return true;
} else { } else {
return false; return false;
} }
} }
function getGoEarCode($songUrl) { function getGoEarCode($songUrl) {
$pos = strpos($songUrl, "?v="); $pos = strpos($songUrl, "?v=");
$lon = strlen($songUrl); $lon = strlen($songUrl);
$str = substr($songUrl, $pos + 3, $lon); $str = substr($songUrl, $pos + 3, $lon);
return $str; return $str;
} }
function isGoEar($songUrl) { function isGoEar($songUrl) {
if (beginsWith($songUrl, "http://www.goear.com/listen.php?v=") || beginsWith($songUrl, "http://goear.com/listen.php?v=")) if (beginsWith($songUrl, "http://www.goear.com/listen.php?v=") || beginsWith($songUrl, "http://goear.com/listen.php?v="))
return true; return true;
else else
return false; return false;
} }
function isOdeo($songUrl){ function isOdeo($songUrl){
if (beginsWith($songUrl, "http://odeo.com/audio/") || beginsWith($songUrl, "http://www.odeo.com/audio/")) if (beginsWith($songUrl, "http://odeo.com/audio/") || beginsWith($songUrl, "http://www.odeo.com/audio/"))
return true; return true;
else else
return false; return false;
} }
function getOdeoCode($songUrl) { function getOdeoCode($songUrl) {
$params = explode("audio/", $songUrl); $params = explode("audio/", $songUrl);
$params2 = explode("/",$params[1]); $params2 = explode("/",$params[1]);
return $params2[0]; return $params2[0];
} }
function isImageFile($photoUrl) { function isImageFile($photoUrl) {
if (endsWith($photoUrl, ".jpg")) { return true; } if (endsWith($photoUrl, ".jpg")) { return true; }
elseif (endsWith($photoUrl, ".gif")) { return true; } elseif (endsWith($photoUrl, ".gif")) { return true; }
elseif (endsWith($photoUrl, ".png")) { return true; } elseif (endsWith($photoUrl, ".png")) { return true; }
else { return false; } else { return false; }
} }
function getPhotoFile($remoteFileName) { function getPhotoFile($remoteFileName) {
if (isImageFile($remoteFileName)) { if (isImageFile($remoteFileName)) {
if (getFile($remoteFileName)) { if (getFile($remoteFileName)) {
return true; return true;
} else { } else {
@ -102,37 +102,37 @@ if(!defined('entry') || !entry) die('Not a valid page');
return false; return false;
} }
} }
function getFile($remoteFileName) { function getFile($remoteFileName) {
$fileName = "../uploads/".sanitizeName(getFileName($remoteFileName)); $fileName = "../uploads/".sanitizeName(getFileName($remoteFileName));
$str = _file_get_contents($remoteFileName); $str = _file_get_contents($remoteFileName);
if (!$handle = fopen($fileName, 'w')) { if (!$handle = fopen($fileName, 'w')) {
//die("no se abrio de escritura"); //die("no se abrio de escritura");
return false; return false;
} }
if (fwrite($handle, $str) === FALSE) { if (fwrite($handle, $str) === FALSE) {
//die("no se escribio"); //die("no se escribio");
return false; return false;
} }
fclose($handle); fclose($handle);
return true; return true;
} }
function isVimeoVideo($videoUrl) { function isVimeoVideo($videoUrl) {
if (beginsWith($videoUrl, "http://vimeo.com/") || beginsWith($videoUrl, "http://www.vimeo.com/")) if (beginsWith($videoUrl, "http://vimeo.com/") || beginsWith($videoUrl, "http://www.vimeo.com/"))
return true; return true;
else else
return false; return false;
} }
function getVimeoVideoUrl($videoUrl) { function getVimeoVideoUrl($videoUrl) {
if(substr_count($videoUrl,"clip:")==1) if(substr_count($videoUrl,"clip:")==1)
return array_pop(explode("clip:",$videoUrl)); return array_pop(explode("clip:",$videoUrl));
else else
return array_pop(explode("/",$videoUrl)); return array_pop(explode("/",$videoUrl));
} }
function isYoutubeVideo($videoUrl) { function isYoutubeVideo($videoUrl) {
$url = explode("?", $videoUrl); $url = explode("?", $videoUrl);
if((beginsWith($url[0], "http://") && endsWith($url[0], ".youtube.com/watch")) || beginsWith($url[0], "http://youtube.com/watch")) if((beginsWith($url[0], "http://") && endsWith($url[0], ".youtube.com/watch")) || beginsWith($url[0], "http://youtube.com/watch"))
@ -140,14 +140,14 @@ if(!defined('entry') || !entry) die('Not a valid page');
else else
return false; return false;
} }
function isYahooVideo($videoUrl){ function isYahooVideo($videoUrl){
if (beginsWith($videoUrl, "http://video.yahoo.com/watch/") || beginsWith($videoUrl, "http://www.video.yahoo.com/watch/")) if (beginsWith($videoUrl, "http://video.yahoo.com/watch/") || beginsWith($videoUrl, "http://www.video.yahoo.com/watch/"))
return true; return true;
else else
return false; return false;
} }
function getYahooVideoCode($videoUrl){ function getYahooVideoCode($videoUrl){
$params = explode("http://video.yahoo.com/watch/", $videoUrl); $params = explode("http://video.yahoo.com/watch/", $videoUrl);
$params2 = explode("/",$params[1]); $params2 = explode("/",$params[1]);
@ -160,7 +160,7 @@ if(!defined('entry') || !entry) die('Not a valid page');
$params2 = explode("&",$params[1]); $params2 = explode("&",$params[1]);
return $params2[0]; return $params2[0];
} }
function isGoogleVideoUrl($videoUrl){ function isGoogleVideoUrl($videoUrl){
if (beginsWith($videoUrl, "http://video.google.com/videoplay?")){ if (beginsWith($videoUrl, "http://video.google.com/videoplay?")){
return true; return true;
@ -168,13 +168,13 @@ if(!defined('entry') || !entry) die('Not a valid page');
return false; return false;
} }
} }
function getGoogleVideoCode($videoUrl){ function getGoogleVideoCode($videoUrl){
$params = explode("?docid=", $videoUrl); $params = explode("?docid=", $videoUrl);
$params2 = explode("&",$params[1]); $params2 = explode("&",$params[1]);
return $params2[0]; return $params2[0];
} }
function isDailymotionVideo($videoUrl) { function isDailymotionVideo($videoUrl) {
if (beginsWith($videoUrl, "http://www.dailymotion.com/video/") || beginsWith($videoUrl, "http://dailymotion.com/video/")) if (beginsWith($videoUrl, "http://www.dailymotion.com/video/") || beginsWith($videoUrl, "http://dailymotion.com/video/"))
return true; return true;
@ -187,21 +187,21 @@ if(!defined('entry') || !entry) die('Not a valid page');
$params2 = explode("_",$params[1]); $params2 = explode("_",$params[1]);
return $params2[0]; return $params2[0];
} }
function isSlideSharePresentation($videoUrl) { function isSlideSharePresentation($videoUrl) {
if (beginsWith($videoUrl, "[slideshare id=")) if (beginsWith($videoUrl, "[slideshare id="))
return true; return true;
else else
return false; return false;
} }
function getSlideSharePresentationCode($videoUrl) { function getSlideSharePresentationCode($videoUrl) {
$videoUrl = str_replace("[slideshare id=", "", $videoUrl); $videoUrl = str_replace("[slideshare id=", "", $videoUrl);
$videoUrl = str_replace("&doc=", " ", $videoUrl); $videoUrl = str_replace("&doc=", " ", $videoUrl);
$videoUrl = str_replace("&w=", " ", $videoUrl); $videoUrl = str_replace("&w=", " ", $videoUrl);
return explode(" ",$videoUrl); return explode(" ",$videoUrl);
} }
function isVideo($url) { function isVideo($url) {
if (isYoutubeVideo($url)) { return true; } if (isYoutubeVideo($url)) { return true; }
elseif (isVimeoVideo($url)) { return true; } elseif (isVimeoVideo($url)) { return true; }
@ -211,12 +211,12 @@ if(!defined('entry') || !entry) die('Not a valid page');
elseif (isGoogleVideoUrl($url)) { return true; } elseif (isGoogleVideoUrl($url)) { return true; }
else { return false; } else { return false; }
} }
function sendMail($to, $title, $body, $from) { function sendMail($to, $title, $body, $from) {
$rp = trim($from); $rp = trim($from);
$org = "gelato CMS"; $org = "gelato CMS";
$mailer = "gelato CMS Mailer"; $mailer = "gelato CMS Mailer";
$head = ''; $head = '';
$head .= "Content-Type: text/html \r\n"; $head .= "Content-Type: text/html \r\n";
$head .= "Date: ". date('r'). " \r\n"; $head .= "Date: ". date('r'). " \r\n";
@ -228,13 +228,13 @@ if(!defined('entry') || !entry) die('Not a valid page');
$head .= "X-Sender: $from \r\n"; $head .= "X-Sender: $from \r\n";
$head .= "X-Priority: 3 \r\n"; $head .= "X-Priority: 3 \r\n";
$head .= "X-Mailer: $mailer \r\n"; $head .= "X-Mailer: $mailer \r\n";
$body = str_replace("\r\n", "\n", $body); $body = str_replace("\r\n", "\n", $body);
$body = str_replace("\n", "\r\n", $body); $body = str_replace("\n", "\r\n", $body);
return @mail($to, $title, $body, $head); return @mail($to, $title, $body, $head);
} }
function getThemes() { function getThemes() {
$themes_dir = "themes"; $themes_dir = "themes";
$dirs = array(); $dirs = array();
@ -262,20 +262,20 @@ if(!defined('entry') || !entry) die('Not a valid page');
//HACK: We need to rework the regular expression to allow the dot //HACK: We need to rework the regular expression to allow the dot
$ext = substr($name, strlen($name)-3, strlen($name)); $ext = substr($name, strlen($name)-3, strlen($name));
$body = substr($name, 0, strlen($name)-4); $body = substr($name, 0, strlen($name)-4);
$name = $body.".".$ext; $name = $body.".".$ext;
return $name; return $name;
} }
function _file_get_contents($path) { function _file_get_contents($path) {
// Modified function from: // Modified function from:
// http://work.dokoku.net/Anieto2k/_file_get_contents.phps // http://work.dokoku.net/Anieto2k/_file_get_contents.phps
// http://www.anieto2k.com/2007/02/09/file_get_contents-y-dreamhost/ // http://www.anieto2k.com/2007/02/09/file_get_contents-y-dreamhost/
if (!preg_match('/^http/i', $path)) { if (!preg_match('/^http/i', $path)) {
if ($fp = fopen($path, 'r')) { if ($fp = fopen($path, 'r')) {
return fread($fp, 1024); return fread($fp, 1024);
} else { } else {
return false; return false;
} }
} else { } else {
@ -297,7 +297,7 @@ if(!defined('entry') || !entry) die('Not a valid page');
if (!$data['host'] || $data['scheme'] != "http") { if (!$data['host'] || $data['scheme'] != "http") {
return false; return false;
} }
$f = @fsockopen($data['host'], ($data['port']) ? $data['port'] : 80, $e1, $e2, 3); $f = @fsockopen($data['host'], ($data['port']) ? $data['port'] : 80, $e1, $e2, 3);
if (!$f) { if (!$f) {
return false; return false;
@ -307,17 +307,17 @@ if(!defined('entry') || !entry) die('Not a valid page');
$q .= "Host: " . $data['host'] . "\r\n"; $q .= "Host: " . $data['host'] . "\r\n";
$q .= "Connection: close\r\n"; $q .= "Connection: close\r\n";
$q .= "Referer: http://www.gelatocms.com/\r\n\r\n"; $q .= "Referer: http://www.gelatocms.com/\r\n\r\n";
$recv = ""; $recv = "";
fwrite($f, $q); fwrite($f, $q);
while (!feof($f)) { while (!feof($f)) {
$recv .= fread($f, 1024); $recv .= fread($f, 1024);
} }
$request = $q; $request = $q;
$response = substr($recv, 0, strpos($recv, "\r\n\r\n")); $response = substr($recv, 0, strpos($recv, "\r\n\r\n"));
$body = substr($recv, strpos($recv, "\r\n\r\n") + 4); $body = substr($recv, strpos($recv, "\r\n\r\n") + 4);
if (preg_match('/http\/1\\.[0|1] ([0-9]{3})/i', $response, $res)) { if (preg_match('/http\/1\\.[0|1] ([0-9]{3})/i', $response, $res)) {
if ($res[1][0] != "2") { if ($res[1][0] != "2") {
return false; return false;
@ -325,7 +325,7 @@ if(!defined('entry') || !entry) die('Not a valid page');
} else { } else {
return false; return false;
} }
if (preg_match('/transfer-encoding:\s*chunked/i', $response)) { if (preg_match('/transfer-encoding:\s*chunked/i', $response)) {
$tmp_body = $body; $tmp_body = $body;
$new = ""; $new = "";
@ -344,12 +344,12 @@ if(!defined('entry') || !entry) die('Not a valid page');
} }
} }
$body = $new; $body = $new;
} }
return $body; return $body;
} }
} }
} }
function get_curl_version() { function get_curl_version() {
$curl = 0; $curl = 0;
if (is_array(curl_version())) { if (is_array(curl_version())) {
@ -363,7 +363,7 @@ if(!defined('entry') || !entry) die('Not a valid page');
} }
return $curl; return $curl;
} }
function transform_offset($offset){ function transform_offset($offset){
$sp = strpos($offset , ".")? explode("." , $offset) : false; $sp = strpos($offset , ".")? explode("." , $offset) : false;
if(is_array($sp)){ if(is_array($sp)){
@ -376,7 +376,7 @@ if(!defined('entry') || !entry) die('Not a valid page');
} }
return $off; return $off;
} }
function getLangs() { function getLangs() {
$langs_dir = "languages"; $langs_dir = "languages";
$dirs = array(); $dirs = array();
@ -388,7 +388,7 @@ if(!defined('entry') || !entry) die('Not a valid page');
$cls_lang_dir = @ dir($dir); $cls_lang_dir = @ dir($dir);
while (($directory = $cls_lang_dir->read()) !== false) { while (($directory = $cls_lang_dir->read()) !== false) {
if($directory != "." && $directory != "..") { if($directory != "." && $directory != "..") {
$dir2 = (substr(PHP_OS, 0, 3) == 'WIN') ? $path."\\".$langs_dir."\\".$directory : $path."/".$langs_dir."/".$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);
$dir2 = str_replace("admin/", "", $dir2); $dir2 = str_replace("admin/", "", $dir2);
@ -423,14 +423,14 @@ if(!defined('entry') || !entry) die('Not a valid page');
$source = strip_tags($source, $validTags); $source = strip_tags($source, $validTags);
return preg_replace('/<(.*?)>/ie', "'<'.removeBadAtributes('\\1').'>'", $source); return preg_replace('/<(.*?)>/ie', "'<'.removeBadAtributes('\\1').'>'", $source);
} }
function removeBadAtributes($sourceTag) { function removeBadAtributes($sourceTag) {
$badAtributes = 'javascript:|onclick|ondblclick|onmousedown|onmouseup|onmouseover|onmousemove|onmouseout|onkeypress|onkeydown|onkeyup'; $badAtributes = 'javascript:|onclick|ondblclick|onmousedown|onmouseup|onmouseover|onmousemove|onmouseout|onkeypress|onkeydown|onkeyup';
$sourceTag = stripslashes($sourceTag); $sourceTag = stripslashes($sourceTag);
$sourceTag = preg_replace("/$badAtributes/i", "niceTry", $sourceTag); $sourceTag = preg_replace("/$badAtributes/i", "niceTry", $sourceTag);
return $sourceTag; return $sourceTag;
} }
function type2Text($number) { function type2Text($number) {
$tmpStr = ""; $tmpStr = "";
switch ($number) { switch ($number) {
@ -438,7 +438,7 @@ if(!defined('entry') || !entry) die('Not a valid page');
$tmpStr = "post"; $tmpStr = "post";
break; break;
case "2": case "2":
$tmpStr = "photo"; $tmpStr = "photo";
break; break;
case "3": case "3":
$tmpStr = "quote"; $tmpStr = "quote";
@ -454,11 +454,11 @@ if(!defined('entry') || !entry) die('Not a valid page');
break; break;
case "7": case "7":
$tmpStr = "mp3"; $tmpStr = "mp3";
break; break;
} }
return $tmpStr; return $tmpStr;
} }
function type2Number($string) { function type2Number($string) {
$tmpStr = ""; $tmpStr = "";
switch ($string) { switch ($string) {
@ -466,7 +466,7 @@ if(!defined('entry') || !entry) die('Not a valid page');
$tmpStr = "1"; $tmpStr = "1";
break; break;
case "photo": case "photo":
$tmpStr = "2"; $tmpStr = "2";
break; break;
case "quote": case "quote":
$tmpStr = "3"; $tmpStr = "3";
@ -482,14 +482,16 @@ if(!defined('entry') || !entry) die('Not a valid page');
break; break;
case "mp3": case "mp3":
$tmpStr = "7"; $tmpStr = "7";
break; break;
} }
return $tmpStr; return $tmpStr;
} }
function trimString($string, $len = "") { function trimString($string, $len = "") {
if($len>strlen($string) or $len<1)
return $string;
$string = strip_tags($string); $string = strip_tags($string);
$len = (empty($len)) ? "50" : $len ; $len = (empty($len)) ? "50" : $len ;
return ( strpos($string, " ", $len) ) ? substr_replace($string, "...", $len) : $string ; return ( strpos($string, " ", $len) ) ? substr_replace($string, "...", $len) : $string ;
} }
?> ?>