Txt Based CMS(Flat-File) + Smiley system

Posts 1–4 of 4 · Page 1 of 1
Txt Based CMS(Flat-File) + Smiley system
Easy as pie.

first make this .txt file called updates.txt
Code:
downloadx.org update #2
nextupdate :)
Code:
<?

function replace($content) {
$content = ereg_replace("\n","<br>", $content); 
$content = ereg_replace(":)","<img src=smile.png>", $content); 
return $content;
}
$rawr = file_get_contents("updates.txt");

echo replace($rawr);

?>
now just do this
Code:
js/cssetchere
htmlhtmlhtml
htmlhtmlhtml
<? include("news.php"); ?>
htmlhtmlhtml
htmlhtmlhtml
owned

posted on rune-server.dot.org by me
This is crap!

Try a better example (this may in a class or function):

class.ubb.php
Code:
<?php
class Ubb {
	
	public $text;
	public $smilies = array( 
	':)'    =>     "smile.gif", 
	':('    =>     "sad.gif", 
	':D'    =>     "biggrin.gif", 
	':d'    =>     "biggrin.gif",                 
	':p'    =>     "tongue.gif", 
	':P'    =>     "tongue.gif", 
	':-)'    =>     "unsure.gif", 
	'(A)'    =>     "angel.gif", 
	'(a)'    =>     "angel.gif", 
	':s'    =>     "blink.gif", 
	':S'    =>     "blink.gif", 
	':$'    =>     "blush.gif", 
	'(h)'    =>     "cool.gif", 
	'(H)'    =>     "cool.gif", 
	':\'('    =>     "cry.gif", 
	'--'    =>     "dry.gif", 
	'-_-'    =>     "dry.gif", 
	'^^'    =>     "happy.gif", 
	'^_^'    =>     "happy.gif", 
	':|'    =>     "huh.gif", 
	';d'    =>     "laugh.gif", 
	';D'    =>     "laugh.gif", 
	':@'    =>     "mad.gif", 
	':o'    =>     "ohmy.gif", 
	':O'    =>     "ohmy.gif", 
	':0'    =>     "ohmy.gif", 
	'8S'    =>     "woot.gif", 
	'8s'    =>     "woot.gif", 
	'8)'    =>     "wacko.gif", 
	';)'    =>     "wink.gif", 
	);
	
	public function __construct($text) {
		
		$this->text = $text;
	}
	
	public function addCodes() {
	
		$text = $this->text;
		
		# Change characters in html
		$text = htmlspecialchars($text);
		
		# Add enters
		$text = nl2br($text); 
		
		# Run all possibilities
		foreach($this->smilies AS $find => $replace) 
    {
	    # Creates an image for each smiley
    	$text = str_replace(htmlentities($find), '<img src="http://www.mpgh.net/forum/images/smileys/'.$replace.'" alt="smileys" />', $text);   
  	}
  	# Add your own image
  	$text = preg_replace('#\[img\](http(s)?://)([a-zA-Z0-9\-\.,\?!%\*_\#:;~\\&$@\/=\+]+)\[/img\]#', '<img src="\\1\\3" alt="" />', $text);
  	
  	# Makes colored characters
  	$text = preg_replace('#\[color=(\#[0-9A-F]{6}|[a-z\-]+)\](.*?)\[/color\]#si', '<font color="\\1">\\2</font>', $text);
  	
  	return $text;
	}
}
?>
How to use?

Set at the top of your document
Code:
<?php
require_once('class.ubb.php');

$file = file_get_contents("updates.txt");
$text = new Ubb($file);
?>
And this where you want the text:
Code:
<?php
$text-> addCodes();
?>
Quote Originally Posted by yearupie View Post
This is crap!

Try a better example (this may in a class or function):

class.ubb.php
Code:
<?php
class Ubb {
	
	public $text;
	public $smilies = array( 
	':)'    =>     "smile.gif", 
	':('    =>     "sad.gif", 
	':D'    =>     "biggrin.gif", 
	':d'    =>     "biggrin.gif",                 
	':p'    =>     "tongue.gif", 
	':P'    =>     "tongue.gif", 
	':-)'    =>     "unsure.gif", 
	'(A)'    =>     "angel.gif", 
	'(a)'    =>     "angel.gif", 
	':s'    =>     "blink.gif", 
	':S'    =>     "blink.gif", 
	':$'    =>     "blush.gif", 
	'(h)'    =>     "cool.gif", 
	'(H)'    =>     "cool.gif", 
	':\'('    =>     "cry.gif", 
	'--'    =>     "dry.gif", 
	'-_-'    =>     "dry.gif", 
	'^^'    =>     "happy.gif", 
	'^_^'    =>     "happy.gif", 
	':|'    =>     "huh.gif", 
	';d'    =>     "laugh.gif", 
	';D'    =>     "laugh.gif", 
	':@'    =>     "mad.gif", 
	':o'    =>     "ohmy.gif", 
	':O'    =>     "ohmy.gif", 
	':0'    =>     "ohmy.gif", 
	'8S'    =>     "woot.gif", 
	'8s'    =>     "woot.gif", 
	'8)'    =>     "wacko.gif", 
	';)'    =>     "wink.gif", 
	);
	
	public function __construct($text) {
		
		$this->text = $text;
	}
	
	public function addCodes() {
	
		$text = $this->text;
		
		# Change characters in html
		$text = htmlspecialchars($text);
		
		# Add enters
		$text = nl2br($text); 
		
		# Run all possibilities
		foreach($this->smilies AS $find => $replace) 
    {
	    # Creates an image for each smiley
    	$text = str_replace(htmlentities($find), '<img src="http://www.mpgh.net/forum/images/smileys/'.$replace.'" alt="smileys" />', $text);   
  	}
  	# Add your own image
  	$text = preg_replace('#\[img\](http(s)?://)([a-zA-Z0-9\-\.,\?!%\*_\#:;~\\&$@\/=\+]+)\[/img\]#', '<img src="\\1\\3" alt="" />', $text);
  	
  	# Makes colored characters
  	$text = preg_replace('#\[color=(\#[0-9A-F]{6}|[a-z\-]+)\](.*?)\[/color\]#si', '<font color="\\1">\\2</font>', $text);
  	
  	return $text;
	}
}
?>
How to use?

Set at the top of your document
Code:
<?php
require_once('class.ubb.php');

$file = file_get_contents("updates.txt");
$text = new Ubb($file);
?>
And this where you want the text:
Code:
<?php
$text-> addCodes();
?>
Ill be posting my cms later, it uses a similar bbc system
Bit of a bump there.
Posts 1–4 of 4 · Page 1 of 1

Post a Reply

Similar Threads

Tags for this Thread

None

Talk with us