datadir=$datadir; $this->images_dir=$images_dir; $this->start_page=$start_page; $this->db_category=$db_category; $this->number_of_links_to_pages=$number_of_links_to_pages; $this->number_of_footer_links=$number_of_footer_links; $this->ebayTemplate=$ebayTemplate; $this->googleNewsTemplate=$googleNewsTemplate; $this->rssFetcherTemplate=$rssFetcherTemplate; $this->flickrTemplate=$flickrTemplate; $this->bingImages=$bingImages; $this->mainTemplate=$mainTemplate; $this->liveCode=$liveCode; $this->source_url=$source_url; $this->menuTemplate=$menuTemplate; $this->footerLinksTemplate=$footerLinksTemplate; $this->source_parsing=$source_parsing; $this->advertcodes=$advertcodes; //echo $_SERVER['DOCUMENT_ROOT']; //echo '
'; //echo $_SERVER['HTTP_HOST']; $temp=explode('.',$_SERVER['DOCUMENT_ROOT']); $this->dir_root=strrchr($temp[0],'/'); //echo $this->dir_root; $this->dir_root=str_replace($this->dir_root,'/',$temp[0]); unset($start_page,$db_category,$number_of_links_to_pages,$ebayTemplate,$googleNewsTemplate, $rssFetcherTemplate,$flickrTemplate,$bingImages,$mainTemplate,$liveCode,$images_dir,$source_url, $menuTemplate,$footerLinksTemplate,$number_of_footer_links,$source_parsing,$advertcodes); } function ConnectToDB() { $this->db_link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD) or die("Could not connect"); // print ("Connected successfully"); mysql_selectdb(DB_NAME) or die("Could not select ".DB_NAME." database"); } function DisconnectFromDB() { mysql_close($this->db_link); } function MakeDbQuery($query="") { $result = mysql_query($query,$this->db_link); //or die ("Invalid query"); //echo mysql_errno() . ": " . mysql_error(). "\n"; $i=0; $res_array=array(); while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { //printf ("ID: %s Name: %s Slug: %s
", $row[0], $row[1],$row[2]); $res_array[$i++]=$row; //$res_array[$i]['name']=$row[1]; //$res_array[$i++]['slug']=$row[2]; } //print_r($res_array); return $res_array; } //возвращаем все ключи из бд function GetAllKeysFromDB() { $this->ConnectToDB(); $this->all_categories=$this->MakeDbQuery('SELECT id,name,slug FROM `brush_keyword` WHERE `c_id`='.$this->db_category.' LIMIT 1000'); $this->DisconnectFromDB(); // print_r($this->all_categories); } //читаем из бд весь контент для данного ключа function GetContentFromDB() { $this->ConnectToDB(); $k_id=$this->current_key['id']; $rezult['Ebay']=$this->MakeDbQuery('SELECT * FROM `brush_content` WHERE `k_id`='.$this->current_key['id'].' AND plugin_id="Ebay" LIMIT 1000'); $rezult['GoogleNews']=$this->MakeDbQuery('SELECT * FROM `brush_content` WHERE `k_id`='.$this->current_key['id'].' AND plugin_id="GoogleNews" LIMIT 1000'); $rezult['RSSFetcher']=$this->MakeDbQuery('SELECT * FROM `brush_content` WHERE `k_id`='.$this->current_key['id'].' AND plugin_id="RSSFetcher" LIMIT 1000'); $rezult['Flickr']=$this->MakeDbQuery('SELECT * FROM `brush_content` WHERE `k_id`='.$this->current_key['id'].' AND plugin_id="Flickr" LIMIT 1000'); $rezult['BingImages']=$this->MakeDbQuery('SELECT * FROM `brush_content` WHERE `k_id`='.$this->current_key['id'].' AND plugin_id="BingImages" LIMIT 1000'); $this->DisconnectFromDB(); //print_r($rezult); $this->current_content=$rezult; } //выводим результаты ебей function ShowEbay() { $rez=""; //global $ebayTemplate; $template=file_get_contents($this->ebayTemplate); if(isset($this->current_content['Ebay']) and is_array($this->current_content['Ebay'])) foreach($this->current_content['Ebay'] as $ebay) { $temp=str_replace('{url}',str_replace("http://","#",$ebay['ourl']),$template); $temp=str_replace('{title}',$ebay['title'],$temp); $temp=str_replace('{img_url}',$ebay['img'],$temp); $temp=str_replace('{price}',$ebay['price'],$temp); $rez.=$temp; } // print($rez); return $rez; } //выводим результаты ГуглНьюс function ShowGoogleNews() { $rez=""; //global $ebayTemplate; $template=file_get_contents($this->googleNewsTemplate); $temp_template=$this->Repeater($template); // print_r($this->current_content['GoogleNews']); if(isset($this->current_content['GoogleNews']) and is_array($this->current_content['GoogleNews'])) foreach($this->current_content['GoogleNews'] as $gNews) { //$extra=unserialize($gNews['extra']); //print_r($extra); preg_match('/"date":([0-9]+)/',$gNews['extra'],$matches); $temp=str_replace('{url}',str_replace("http://","#",$gNews['ourl']),$temp_template[1]); $temp=str_replace('{title}',$gNews['title'],$temp); $temp=str_replace('{img_url}',$this->CopyImages($gNews['img']),$temp); $temp=str_replace('{text}',$gNews['description'],$temp); $temp=str_replace('{date}',date("Y-M-d",$matches[1]),$temp); $rez.=$temp; } //print($rez); if($rez<>"") $rez=str_replace($temp_template[0],$rez,$template); return $rez; } //выводим результаты rssfetcher function ShowRssFetcher() { $rez=""; //global $ebayTemplate; $template=file_get_contents($this->rssFetcherTemplate); $temp_template=$this->Repeater($template); if(isset($this->current_content['RSSFetcher']) and is_array($this->current_content['RSSFetcher'])) foreach($this->current_content['RSSFetcher'] as $rssFetcher) { $extra=unserialize($rssFetcher['extra']); // print_r($extra); $temp=str_replace('{url}',str_replace("http://","#",$rssFetcher['ourl']),$temp_template[1]); $temp=str_replace('{title}',$rssFetcher['title'],$temp); //$temp=str_replace('{img_url}','http://go-worthwhile.com'.$rssFetcher['img'],$temp); $temp=str_replace('{text}',$rssFetcher['description'],$temp); //$temp=str_replace('{date}',$rssFetcher['date'],$temp); $rez.=$temp; } // print($rez); if($rez<>"") $rez=str_replace($temp_template[0],$rez,$template); return $rez; } //выводим результаты BingImages function ShowBingImages() { $rez=""; //global $ebayTemplate; $template=file_get_contents($this->bingImages); if(isset($this->current_content['BingImages']) and is_array($this->current_content['BingImages'])) foreach($this->current_content['BingImages'] as $bing) { $extra=unserialize($rssFetcher['extra']); // print_r($extra); $temp=str_replace('{url}',str_replace("http://","#",$bing['ourl']),$template); $temp=str_replace('{title}',$bing['title'],$temp); $temp=str_replace('{img_url}',$this->CopyImages($bing['img']),$temp); $temp=str_replace('{text}',$bing['description'],$temp); //$temp=str_replace('{date}',$rssFetcher['date'],$temp); $rez.=$temp; } //print($rez); return $rez; } //формируем вывод из шаблона с повторением и обрамлением function Repeater($template) { preg_match('/{repeater}([^\^]+){\/repeater}/',$template,$matches); //print_r($matches); //echo str_replace($matches[0],'Hello',$template); return $matches; } //копируем картинки в папку на серваке function CopyImages($from) { if(!is_dir($this->images_dir)) mkdir($this->images_dir); //echo $this->dir_root; $to=str_replace('/','_',$from); if(!file_exists($this->images_dir.$to)) copy($this->dir_root.$this->source_url.$from,$this->images_dir.$to); return($this->images_dir.$to); } //выводим результаты flickr function ShowFlickr() { $rez=""; //global $ebayTemplate; $template=file_get_contents($this->flickrTemplate); $temp_template=$this->Repeater($template); if(isset($this->current_content['Flickr']) and is_array($this->current_content['Flickr'])) foreach($this->current_content['Flickr'] as $flickr) { //$extra=unserialize($rssFetcher['extra']); //print_r($extra); preg_match('/"author":"([^"]+)"/',$flickr['extra'],$extra); $temp=str_replace('{url}',str_replace("http://","#",$flickr['ourl']),$temp_template[1]); $temp=str_replace('{title}',$flickr['title'],$temp); $temp=str_replace('{img_url}',$flickr['img'],$temp); $temp=str_replace('{text}',$flickr['description'],$temp); $temp=str_replace('{author}',$extra[1],$temp); //$temp=str_replace('{date}',$rssFetcher['date'],$temp); $rez.=$temp; } // print($rez); if($rez<>"") $rez=str_replace($temp_template[0],$rez,$template); return $rez; } //возвращаем ключ и его номер по слагу function GetKeyWithSlug($slug) { $this->ConnectToDB(); $rezult=$this->MakeDbQuery('SELECT id,name,slug FROM `brush_keyword` WHERE `slug`="'.$slug.'" LIMIT 1'); $this->DisconnectFromDB(); //print_r($rezult); $this->current_key=$rezult[0]; } //формируем меню ссылок на страницы function GetLinksToPages($is_footer=false) { //echo substr($_SERVER['REQUEST_URI'],1); //echo "
"; $this->GetAllKeysFromDB(); shuffle($this->all_categories); if($is_footer) { $template=file_get_contents($this->footerLinksTemplate); $number_of_links=$this->number_of_footer_links; }else { $template=file_get_contents($this->menuTemplate); $number_of_links=$this->number_of_links_to_pages; } $temp_template=$this->Repeater($template); $rez=""; for($i=0;$i<$number_of_links;$i++) { //$rez.= "".$this->all_categories[$i]['name']."
"; $tmp=str_replace("{url}",'/'.$this->all_categories[$i]['slug'],$temp_template[1]); $rez.=str_replace("{name}",$this->all_categories[$i]['name'],$tmp); } $rez=str_replace($temp_template[0],$rez,$template); return $rez; } //формируем страницу с помощью БД function CreatePageFromDB() { $links=$this->GetLinksToPages(); $this->GetKeyWithSlug(substr($_SERVER['REQUEST_URI'],1)); if($this->source_parsing) $txt=file_get_contents('http://'.$this->source_url.'/cotton'.$_SERVER['REQUEST_URI'].'-'.$this->current_key['id'].'.html'); // print_r($this->current_key['id']); $this->GetContentFromDB(); $template=file_get_contents($this->mainTemplate); $live=file_get_contents($this->liveCode); $adv1=file_get_contents($this->advertcodes[0]); $adv2=file_get_contents($this->advertcodes[1]); $adv3=file_get_contents($this->advertcodes[2]); /*$center=$this->ShowEbay(); $center.=$this->ShowGoogleNews(); $right=$this->ShowFlickr(); $right.=$links; $right.=$this->ShowRssFetcher(); $center.=$this->ShowBingImages();*/ $template=str_replace("{title}",$this->current_key['name'],$template); $template=str_replace("{ebay}",$this->ShowEbay(),$template); $template=str_replace("{bingimages}",$this->ShowBingImages(),$template); $template=str_replace("{flickr}",$this->ShowFlickr(),$template); $template=str_replace("{googlenews}",$this->ShowGoogleNews(),$template); $template=str_replace("{mainmenu}",$this->GetLinksToPages(),$template); $template=str_replace("{rssfetcher}",$this->ShowRssFetcher(),$template); $template=str_replace("{adv_code1}",$adv1,$template); $template=str_replace("{adv_code2}",$adv2,$template); $template=str_replace("{adv_code3}",$adv3,$template); $template=str_replace("{live}",$live,$template); echo $template; //$this->CopyImages(); } function GetPage() { if($_SERVER['REQUEST_URI']<>"/") { if(file_exists($this->datadir.$_SERVER['REQUEST_URI'])) { $this->text=file_get_contents($this->datadir.$_SERVER['REQUEST_URI']); }else { //echo "Fail ne nayden"; //$this->GetAllKeysFromDB(); $this->CreatePageFromDB(); return false; } }else if(file_exists($this->datadir."/".$this->start_page)) $this->text=file_get_contents($this->datadir."/".$this->start_page); return true; } function PageCorrection() { $live=file_get_contents($this->liveCode); $adv1=file_get_contents($this->advertcodes[0]); $adv2=file_get_contents($this->advertcodes[1]); $this->text=str_replace('',$live.'',$this->text); $this->text=str_replace("{adv_code1}",$adv1,$this->text); $this->text=str_replace("{adv_code2}",$adv2,$this->text); //$template=str_replace("{adv_code2}",$adv2,$template); $this->text=str_replace('src="','src="'.$this->datadir."/",$this->text); $this->text=str_replace('href="css','href="'.$this->datadir,$this->text); $links=str_replace('
',' ',$this->GetLinksToPages(true)); $this->text=str_replace('color="#FFFFFF">All','color="#FFFFFF">'.$links.'
All',$this->text); } function ShowPage() { echo $this->text; } } // echo $_SERVER['REQUEST_URI']; $myWebSite=new WebSite; $myWebSite->GetPage(); $myWebSite->PageCorrection(); $myWebSite->ShowPage(); ?>