Location: PHPKode > scripts > Text For Reading Class > text-for-reading-class/TextForRead.class.php
<?
class TextForRead {
######################################################################################
##																					##
##	File Name	: TextForRead.php													##
##	Author		: Murat Küçükosman													##
##	e-Mail		: hide@address.com												##
##	Version		: v1.0																##
##																					##
##This is a part of TextForRead Class												##
##FileMan is free software; you can redistribute it and/or modify					##
##it under the terms of the GNU General Public License as published by				##
##the Free Software Foundation; either version 2 of the License, or					##
##(at your option) any later version.												##
##																					##
##This program is distributed in the hope that it will be useful,					##
##but WITHOUT ANY WARRANTY; without even the implied warranty of					##
##MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the						##
##GNU General Public License for more details.										##
##																					##
##You should have received a copy of the GNU General Public License					##
##along with this program; if not, write to the Free Software						##
##Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA		##
##																					##
##																					##
##This General Public License does not permit incorporating your program into		##
##proprietary programs.  If your program is a subroutine library, you may			##
##consider it more useful to permit linking proprietary applications with the		##
##library.  If this is what you want to do, use the GNU Lesser General				##
##Public License instead of this License.											##
######################################################################################
	
	var $text;
	var $imageType = "jpg|jpeg|gif|png|JPG|GIF|PNG";
	var $SmileyDirectory = "smiley";
	var $out;
	var $SetSmiley = array(
	"\:\)"=>"smile.gif",
	"\:\("=>"sad.gif",
	"\:\|"=>"gape.gif",
	"\:kalp\:"=>"heart.gif",
	"\:deli\:"=>"crazy.gif",
	"\:D"=>"grin.gif",
	"\:p"=>"raspberry.gif",
	"\:angry\:"=>"angry.gif",
	"\:ash\:"=>"ashamed.gif",
	"\:cicek\:"=>"chromakode.gif",
	"\:\'\("=>"crying.gif",
	"\:karisikkafa\:"=>"curious.gif",
	"\:olu\:"=>"dead.gif",
	"\^\^"=>"ftripoff.gif",
	"\:\}"=>"halfsmile.gif",
	"\:hahaha\:"=>"laughing.gif",
	"\:love\:"=>"love.gif",
	"\:kek\:"=>"muffin.gif",
	"\:ninja\:"=>"ninja.gif",
	"\:o"=>"shocked.gif",
	"\:zzzz\:"=>"sleeping.gif",
	"\|\("=>"sulk.gif",
	"\:ufo\:"=>"ufo.gif",
	"\;\)"=>"wink.gif");

	private function textToLink() {
		$this->text = eregi_replace("([ \t]|^)www\.", " http://www.", $this->text);
		$this->text = eregi_replace("([ \t]|^)www\.", " http://www.", $this->text);
		$this->text = eregi_replace("([ \t]|^)ftp\.", " ftp://ftp.", $this->text);
		$this->text = eregi_replace('(((f|ht){1}tp://)[-a-zA-Z0-9@:%_+.~#?&//=]+)', '<a href="\1" target="_blank">\1</a>', $this->text);
		$this->text = eregi_replace('([[:space:]()[{}])(www.[-a-zA-Z0-9@:%_+.~#?&//=]+)', '\1<a href="http://\2" target="_blank">\2</a>', $this->text);
		$this->text = eregi_replace('([_.0-9a-z-]+@([0-9a-z][0-9a-z-]+.)+[a-z]{2,3})','<a href="mailto:\1">\1</a>', $this->text);

		return $this->text;
	}

	private function imageViewnLinkFirst() {
		preg_match_all("/([h][tps]{2,4}:\/\/[^ \t\n\r]+\.(jpg|jpeg|gif|png|JPG))/i",$this->text, $this->out);

		$ImageLinkCount = count($this->out[0])-1;

		for ($i=0;$i<=$ImageLinkCount;$i++) {
			$this->out['0'][$i] = "##RESIM0".$i."##";
		}

		$f=0;
		foreach ($this->out['0'] as $resimAdi) {
			$this->text = eregi_replace($this->out['1'][$f],$resimAdi,$this->text);
			$f++;
		}

		return $this->text;
	}

	private function imageViewLinkLast() {
		preg_match_all("/([##RESIM][^ \t\n\r]+([0-9])[##])/i",$this->text, $in);

		$ImageAliasCount = count($in['0'])-1;

		$z=0;
		for ($i=0;$i<=$ImageAliasCount;$i++) {
			$this->text = eregi_replace($in['0'][$z]."#",$this->out['1'][$z],$this->text);
			$z++;
		}

		$this->text = preg_replace('/([h][tps]{2,4}:\/\/[^ \t\n\r]+\.('.$this->imageType.'))/',
		'<a href="$1" target="_blank" class="ImageHolder"><img src="$1" border=\"0\"/></a>', $this->text);

		return $this->text;
	}

	function SmileyView() {
			foreach ($this->SetSmiley as $KisaYol => $smiley) {
				$this->text = eregi_replace($KisaYol, "&nbsp;<img src=\"".$this->SmileyDirectory."/$smiley\" border=\"0\">&nbsp;", $this->text);		
		}
		return $this->text;
	}


	function ReturnValue() {
		$this->imageViewnLinkFirst();
		$this->textToLink();
		$this->imageViewLinkLast();
		$a = $this->SmileyView();
		return nl2br($a);
	}
}

/* EXAM
$text = new TextForRead();
$text->text = "adsf dskfl :) \njdsfkl http://www.google.com/logos/Logo_25wht.gif kldf jkld jkl http://www.berlin-life.com/ kdsjkl lk www.morad.info  \n\r http://192.168.2.7/morad_yeni/i/logo.gif    \nyufbuyfhjbfj jgf   gjf gf hgf gh fhgfghfresre http://network2.tv/channelimg/daryl_hannah_s_love_life.png es oıfu0weu80w  joıw jıoejjıo jnklcm visşd şi ls http://z.about.com/d/cameras/1/0/e/4/Baby_Love.JPG  dşskjf ksdjfkls dlflksd ds ds ";

echo $text->ReturnValue();

This General Public License does not permit incorporating your program into
proprietary programs.  If your program is a subroutine library, you may
consider it more useful to permit linking proprietary applications with the
library.  If this is what you want to do, use the GNU Lesser General
Public License instead of this License.
*/
?>
Return current item: Text For Reading Class