clean($value,'encode'); if(preg_match_all($regexlink,$value,$matches)) { // $value = ''.$value.''; $value = preg_replace("/".preg_quote($this->clean($matches[0][0],'encode'),'/')."/",''.$matches[0][0].'',$matches[0][0]); } return $value; } public function prepareMixedMedia($value) { if(($value != '') or ($value !=NULL)) { if(stristr(strtolower($value),'.mp3')) { return "
"; } elseif(stristr(strtolower($value),'.ogg') || stristr(strtolower($value),'.opus')) { return "
"; } else { return ""; } } } public function fetchHTML($url) { $channel = curl_init(); curl_setopt($channel, CURLOPT_URL, $url); curl_setopt($channel, CURLOPT_RETURNTRANSFER, 1); $result = curl_exec($channel); curl_close($channel); if($result) { return $result; } else { return false; } } public function prepareHTML($result) { if(strlen($result) > 1900) { return $this->clean(substr($value,'encode'),0,1900); } else { $value = $this->clean($result,'encode'); // bandcamp integration $bandcamp_url = 'PHP/bandcamp.php?embed='; $bandcamp_error = 'Bandcamp failed to load. Reload the page, or please contact support.'; // initialize an append value. $value_add = ''; if(preg_match_all('/https:\/\/[a-z0-9]+.bandcamp.com\/track\/[a-z0-9-_]+/i', $value, $matches)) { $gethtml = $this->fetchHTML($bandcamp_url . $this->clean($matches[0][0],'encode')); if($gethtml != false) { $value_add .= PHP_EOL; $value_add .= $gethtml; } else { $value_add .= '
'.$bandcamp_error.'
'; } } elseif (preg_match_all("/https:\/\/[a-z0-9]+.bandcamp.com\/album\/[a-z0-9-_]+/i",$value,$matches)) { $gethtml = $this->fetchHTML($bandcamp_url . $this->clean($matches[0][0],'encode')); if($gethtml != false) { $value_add .= PHP_EOL; $value_add .= $gethtml; } else { $value_add .= '
'.$bandcamp_error.'
'; } } else {} if(stristr($value,'http://') || stristr($value,'https://') ) { if(stristr(strtolower($value),'.gif') || stristr(strtolower($value),'.png') || stristr(strtolower($value),'.jpg') || stristr(strtolower($value),'.jpeg')) { // inline image processing $regex_image = "/\b(?:(?:https?)):\/\/[.a-zA-Z0-9]+[\/?][=_-~!@#$%^&*()_+a-zA-Z-0-9]+(.png|.jpg|.gif|.jpeg)/i"; if(preg_match_all($regex_image,$value,$matches)) { $value = preg_replace("/".preg_quote($this->clean($matches[0][0],'encode'),'/')."/", '', $value, count($matches[0]) ); } } // youtube matching // $regex_yt = "/.*youtube.com\/watch\?v=[a-z0-9]+/i"; // full url $regex_yt = "/https?:\/\/www\.youtube\.[a-z]+\/watch\?v=([a-z0-9-\_\-]+)/i"; if(preg_match_all($regex_yt,$value,$matches)) { $value = preg_replace("/".preg_quote($this->clean($matches[0][0],'encode'),'/')."/", '', $value, count($matches[0])); } $regex_yt = "/https?:\/\/youtu\.be\/([a-z0-9-\_\-]+)/i"; if(preg_match_all($regex_yt,$value,$matches)) { $value = preg_replace("/".preg_quote($this->clean($matches[0][0],'encode'),'/')."/", '', $value, count($matches[0])); } if(strstr($value,'clean($matches[0][$i],'encode'),'/')."/", ''.$this->clean($matches[0][$i],'encode').'', $value, count($matches[0]) ); } else { // process both image and links here if(!preg_match("/(?:src=\"https?):\/\/[.a-zA-Z0-9]+[\/?][=_-~!@#$%^&*()_+a-zA-Z-0-9]+/i",$value,$matchurl)) { $value = preg_replace("/".preg_quote($this->clean($matches[0][$i],'encode'),'/')."/", ''.$this->clean($matches[0][$i],'encode').'', $value, count($matches[0]) ); } } } } } } // hashtag integration $regex = "/\#[a-zA-Z0-9.]+[\s]{0,3}\s/i"; if(preg_match_all($regex,$value,$matches)) { $value = preg_replace('/\#[a-zA-Z0-9.]+[\s]{0,3}/i', ''.$this->clean('$0','encode').'', $value); } if(!preg_match_all("/\/\@[a-zA-Z0-9.]+[\s]{0,2}/i",$value)) { $regex = '/\@[a-zA-Z0-9.]+[\s]{0,2}/i'; if(preg_match_all($regex,$value,$matches)) { $cnt = count($matches[0]); $value = preg_replace('/\@[a-zA-Z0-9.]+[\s]{0,2}/i', ''.$this->clean('$0','encode').'', $value); } } $find = ['&#039;','&quot;',''','"','&lt;','&gt;','<','>','&amp;','*','?','(',')','+','&nbsp;','&nbsp;']; $replace = ['’','"','’','"','<','>','<','>','&','*','?','(',')','+',' ',' ']; $value = str_replace($find,$replace,$value); $value = str_replace('&#039;','’',$value); $findHTML = ['<br>','<br/>','<b>','</b>','<em>','</em>','<code>','</code>','<blockquote>','</blockquote>']; $replaceHTML = ['
','
','','','','','','','
','
']; $value = str_replace($findHTML,$replaceHTML,$value); $value .= $value_add; return utf8_decode($value); } } public function clean($string,$method='') { $dataresult = ''; switch($method) { case 'alpha': $dataresult = preg_replace('/[^a-zA-Z]/','', $string); break; case 'num': $dataresult = preg_replace('/[^0-9]/','', $string); break; case 'unicode': $dataresult = preg_replace("/[^[:alnum:][:space:]]/u", '', $string); break; case 'user': $dataresult = preg_replace("/[^[:alnum:]]/u", '', $string); break; case 'encode': if(is_null($string)) { $dataresult = htmlspecialchars($string,ENT_QUOTES,'UTF-8'); } else { $dataresult = htmlspecialchars($string,ENT_QUOTES,'UTF-8'); } break; case 'query': $search = ['`','"','\'',';']; $replace = ['','','','']; $dataresult = str_replace($search,$replace,$string); break; case 'cols': // comma is allowed for selecting multiple columns. $search = ['`','"','\'',';']; $replace = ['','','','']; $dataresult = str_replace($search,$replace,$string); break; case 'dir': $search = ['`','"',',','\'',';','..','../','.php','.css']; $replace = ['','','','','','','','','']; $dataresult = str_replace($search,$replace,$string); break; case 'table': $search = ['`','"',',','\'',';','.','$','%']; $replace = ['','','','','','','','']; $dataresult = str_replace($search,$replace,$string); break; case 'search': $search = ['`','"',',','\'',';','.','$','%']; $replace = ['','','','','','','','']; $string = str_replace($search,$replace,$string); $dataresult = preg_replace("/[^[:alnum:][:space:]]/u", '', $string); break; default: return $dataresult; } return $dataresult; } /** * name * @param * @return */ public function css($body,$text,$background=false) { $string = ""; $bodycolor = substr($body,0,7); $textcolor = substr($text,0,7); if($bodycolor == $textcolor) { $textcolor = '#fff'; } $dec = hexdec(str_replace('#','',$bodycolor)); if($dec > 0) { $div = (int)($dec / 2); $dec = (int)($dec + $div); $linecolor = '#'; $linecolor .= dechex($dec); } else { $linecolor = $bodycolor; } $string .= PHP_EOL; $string .=""; $string .= PHP_EOL; return $string; } } ?>