db = $db; } function __destruct() { unset($this->tables_info); unset($this->data); } function addTable($loc,$priority,$lastmod,$changefreq,$table,$field, $where = "1=1", $update = 0){ array_push($this->tables_info,array('loc'=>$loc,'priority'=>$priority,'lastmod'=>$lastmod,'changefreq'=>$changefreq,'table'=>$table,'field'=>$field, 'where'=>$where, 'update'=>$update)); } function viewTablesData(){ print_r($this->data); } private function addData($res,$url){ foreach($res as $row){ $this->addUrl($this->sprint_f($url['loc'],$row),$url['priority'],$url['lastmod'],$url['changefreq']); } } function sprint_f($str,$vars = array()){ $eval = "\$r = sprintf(\$str,"; for($i=1;$idata,array('loc'=>$loc,'priority'=>$priority,'lastmod'=>$lastmod,'changefreq'=>$changefreq)); } function start(){ foreach($this->tables_info as $row){ print $sql = "select ".implode(",",$row['field'])." from ".$row['table']." where ".$row['where']; $res = $this->db->getAll($sql,array()); //if($row['update']==1){$this->updateTable($res,$row);} $this->addData($res, $row); } } function updateTable($res,$row){ foreach($res as $r){ $fields_values = array('sitemap'=>1); $where = sprintf("id='%d'", $r[0]); $a = $this->db->autoExecute($row['table'], $fields_values, DB_AUTOQUERY_UPDATE,$where); if (PEAR::isError($a)) die($a->getMessage()); } } private function save($file,$xml){ $handle = fopen($file, "w"); fwrite($handle,$xml); fclose($handle); } function saveXML($file){ $xml = ''; $xml .= ''; $xml .= ''; foreach($this->data as $row){ $xml .= ""; $xml .= sprintf("%s", $this->escapeLoc($row['loc'])); $xml .= sprintf("%s", $row['lastmod']); $xml .= sprintf("%s", $row['changefreq']); $xml .= sprintf("%s", $row['priority']); $xml .= ""; } $xml .= ''; $this->save($file,$xml); $this->saveHeadFotter($file); } private function saveHeadFotter($file){ } private function escapeLoc($loc){ $patterns = array(); $patterns[0] = '/&/'; $patterns[1] = '/\'/'; $patterns[2] = '/"/'; $patterns[3] = '/>/'; $patterns[4] = '/