clsItemDB(); $this->tablename=GetTablePrefix()."Censorship"; $this->id_field = "CensorshipId"; $this->NoResourceId=1; if($id) $this->LoadFromDatabase($id); } function LoadFromDatabase($Id) { global $Errors; if(!isset($Id)) { $Errors->AddError("error.AppError",NULL,'Internal error: LoadFromDatabase id',"",get_class($this),"LoadFromDatabase"); return false; } $sql = sprintf("SELECT * FROM ".$this->tablename." WHERE ".$this->IdField()." = '%s'",$Id); $result = $this->adodbConnection->Execute($sql); if ($result === false) { $Errors->AddError("error.DatabaseError",NULL,$this->adodbConnection->ErrorMsg(),"",get_class($this),"LoadFromDatabase"); return false; } $data = $result->fields; $this->SetFromArray($data); $this->Clean(); return true; } } class clsCensorship extends clsItemCollection { var $Page; var $PerPageVar; var $Loaded = 0; function clsCensorship() { global $objSession; $this->clsItemCollection(); $this->classname = "clsCensorWord"; $this->SourceTable = GetTablePrefix()."Censorship"; $this->Page = 1; $this->PerPageVar = "Perpage_Censorship"; $this->AdminSearchFields = array("BadWord","Replacement"); } function LoadCensorship($where=NULL,$orderBy=NULL) { if($this->Loaded) return $this->Items; $this->Clear(); $sql = "SELECT * FROM ".$this->SourceTable; if(strlen(trim($where))>0) $sql .= " WHERE $where"; if(strlen(trim($orderBy))>0) $sql .= " ORDER BY $orderBy"; $this->Loaded = 1; return $this->Query_Item($sql); } function AddWord($BadWord,$Replacement) { $c = new clsCensorWord(); $c->Set("BadWord",$BadWord); $c->Set("Replacement",$Replacement); $c->Create(); return $c; } function EditWord($WordId,$BadWord,$Replacement) { $c = $this->GetItem($WordId); $c->Set("BadWord",$BadWord); $c->Set("Replacement",$Replacement); $c->Update(); return $c; } function DeleteWord($WordId) { $c = $this->GetItem($WordId); $c->Delete(); } function CensorText($text) { $this->LoadCensorship(); foreach($this->Items as $w) { $b = $w->Get("BadWord"); $r = $w->Get("Replacement"); $text = str_ireplace($b,$r,$text); } return $text; } } ?>