/i', '', $snippet); return $snippet; } function closeTags($html) { $tags = array('strong', 'i', 'b', 'em'); for($i=0;$i'); $closing = substr_count(strtolower($html), ''); if($opening > $closing) { $html = $html . ''; } } return $html; } function urlName($name) { $name = str_replace("_", " ", $name); $name = str_replace("/", " ", $name); $name = preg_replace("/[^\d\s\w]+/", "", $name); $name = trim($name); $name = preg_replace("/ +/", "-", $name); return strtolower($name); } function getStaticPage($id) { global $db; $db->query("SELECT name, articletext FROM staticpages WHERE id=".$db->esc($id)); if($row = $db->nextRow()) { return array ( 'name' => $row->name, 'articletext' => $row->articletext ); } else { return false; } } function cutShort($text, $pos) { $text = @strip_tags($text); $cut = @strpos($text, ' ', $pos); if(!$cut) $cut = @strlen($text); return @substr($text, 0 , $cut).'...'; } function createPages($baseurl, $offset, $totalcount, $perpage, $noshown) { if($offset>0) { if(($offset-$perpage)>0) { $pages['prev'] = $baseurl.($offset-$perpage); } else { $pages['prev'] = $baseurl.'0'; } } if(($offset+$perpage)<$totalcount) { $pages['next'] = $baseurl.($offset+$perpage); } $curpage = round($offset / $perpage, 0); if($curpage'; } $pages['links'][] = array( 'link' => $baseurl.($perpage*$i), 'pageno' => $pageno ); } if(sizeof($pages['links'])>1) { return $pages; } return false; } ?> link = mysql_connect($host, $username, $password); mysql_select_db($database, $this->link); } function query($query) { $this->result = mysql_query($query, $this->link); /* if(mysql_error()) { echo "Query ".$this->querycount.": ".$query."
"; echo "Error: ".mysql_error()."
"; } */ if($this->debug) { echo "Query ".$this->querycount.": ".$query."
"; } $this->querycount++; if($this->result) { return true; } return false; } function nextRow($type="object") { switch ($type) { case "array": $row = mysql_fetch_row($this->result); break; case "assoc": $row = mysql_fetch_assoc($this->result); break; default: $row = mysql_fetch_object($this->result); break; } return $row; } function size() { return mysql_num_rows($this->result); } function insertid() { return mysql_insert_id(); } function affected() { return mysql_affected_rows(); } function insertFromAssoc($table, $myArr, $escape=true) { if($escape) { $myArr = $this->cleanArray($myArr); } $query = 'INSERT INTO '.$table.' ('.join(array_keys($myArr), ', ').') VALUES (\''. join($myArr, "', '").'\')'; if($this->query($query)) { return $this->insertid(); } return false; } function updateFromAssoc($table, $myArr, $myID, $limit=1, $escape=true) { if($escape) { $myArr = $this->cleanArray($myArr); $myID = $this->cleanArray($myID); } $query = 'UPDATE '.$table.' SET '; foreach($myArr as $key => $value) { $query = $query . $key . '=\'' . $value . '\', '; } $query = substr($query, 0, strlen($query)-2); $query = $query . ' WHERE '.array_pop(array_keys($myID)) . '=\'' . array_pop($myID) . '\''; if($limit) { $query = $query . ' LIMIT ' . $limit; } return $this->query($query); } function deleteRow($table, $myID, $limit=1, $escape=true) { if($escape) { $myID = $this->cleanArray($myID); } $query = 'DELETE FROM ' . $table . ' WHERE ' .array_pop(array_keys($myID)) . '=\'' . array_pop($myID) . '\''; if($limit) { $query = $query . ' LIMIT ' . $limit; } return $this->query($query); } function cleanArray($myArr) { foreach($myArr as $key => $value) { if(get_magic_quotes_gpc()) { $myArr[$key] = stripslashes($myArr[$key]); } $myArr[mysql_real_escape_string($key, $this->link)] = mysql_real_escape_string($myArr[$key], $this->link); } return $myArr; } function toggleDebug() { $this->debug = !$this->debug; } function esc($str) { return mysql_real_escape_string($str, $this->link); } } ?>