host = $host; $this->username = $username; $this->password = $password; $this->db = $db; $this->connect(); $this->id = $this->get_id_from_key($key); $this->key = $key; } public function get_id_from_key($key){ $q = "SELECT * FROM pages WHERE pagekey='$key'"; $r = mysql_query($q); if ( $r !== false && mysql_num_rows($r) > 0 ) { $a = mysql_fetch_assoc($r); return $a['id']; } } /** deletes a page by its id */ public function delete_content(){ $id = $this->id; $q = "DELETE FROM pages WHERE id = '$id'"; return mysql_query($q); } /** returns the raw content for a page in an array keys are: title bodytext id */ public function get_content() { $q = "SELECT * FROM pages WHERE id=".$this->id; $r = mysql_query($q); if ( $r !== false && mysql_num_rows($r) > 0 ) { return mysql_fetch_assoc($r); } } /* returns a html formated body */ public function get_body() { $key = $this->key; $a = $this->get_content(); $body = $this->txt2html($a['bodytext']); if($_SESSION['access'] == admin) { $body .= "
Edit"; } return $body; } /* returns a non formated body */ public function get_title() { $a = $this->get_content(); return $a['title']; } /* This function will be used to edit a page */ public function display_editor() { $content = $this->get_content(); $id = $this->id; $key = $this->key; $title = $content['title']; $body = $content['bodytext']; return <<


ADMIN_FORM; } /* saves page information */ public function write($title, $body) { $title = mysql_real_escape_string(strip_tags($title)); $bodytext = mysql_real_escape_string($body); $key = $this->key; $updateStm = "UPDATE pages SET title='$title', bodytext='$body' WHERE pagekey='$key'"; mysql_query($updateStm); if(mysql_affected_rows()<=0){ $sql = "INSERT INTO pages (title, bodytext, pagekey)VALUES('$title','$bodytext','$key')"; mysql_query($sql); } } /** This function connects to the database */ public function connect() { mysql_connect($this->host,$this->username,$this->password) or die("Could not connect. " . mysql_error()); mysql_select_db($this->db) or die("Could not select database. " . mysql_error()); return $this->buildDB(); } private function buildDB() { $sql = <<$part ){ $parts[ $key ] = substr($string, $pos, strlen($part)); $pos += strlen($part) + strlen($find); } return( join( $replace, $parts ) ); } public function txt2html($txt) { // Transforms txt in html //Kills double spaces and spaces inside tags. while( !( strpos($txt,' ') === FALSE ) ) $txt = str_replace(' ',' ',$txt); $txt = str_replace(' >','>',$txt); $txt = str_replace('< ','<',$txt); //Transforms accents in html entities. $txt = htmlentities($txt); //We need some HTML entities back! $txt = str_replace('"','"',$txt); $txt = str_replace('<','<',$txt); $txt = str_replace('>','>',$txt); $txt = str_replace('&','&',$txt); //Ajdusts links - anything starting with HTTP opens in a new window $txt = $this->stri_replace("stri_replace("

",$txt).'

'; $html = str_replace("$eol","
\n",$html); $html = str_replace("

","

\n\n",$html); $html = str_replace("

","

 

",$html); //Wipes
after block tags (for when the user includes some html in the text). $wipebr = Array("table","tr","td","blockquote","ul","ol","li"); for($x = 0; $x < count($wipebr); $x++) { $tag = $wipebr[$x]; $html = $this->stri_replace("<$tag>
","<$tag>",$html); $html = $this->stri_replace("
","",$html); } return $html; } } ?>