db_type); function add($title=NULL, $link=NULL, $pic=NULL, $tags=NULL, $desc=NULL,$type=NULL,$category=NULL,$userID=NULL) { $conf = Settings::GetInstance(); $db = Database::Factory($conf->db_type); $content=array(); $sort = 'date'; $limit = '10'; $from = '1'; $type = NULL; $query = "INSERT INTO bookmarks "; if($title && preg_match("/[a-zA-Zа-яА-Я0-9]/",$title)) { $query.="SET title='".addslashes($title)."', "; $content['title']=$title; } else { $content['title']="wrong"; } if($link && preg_match("/[a-zA-Zа-яА-Я0-9]/is",$link)) { if (! preg_match("/^http:\/\//isu",$link)) { $link = "http://".$link; } $query.="link='".addslashes($link)."', "; $content['link']=$link; } else { $content['link']="wrong"; } if($desc && preg_match("/[a-zA-Zа-яА-Я0-9]/",$desc)) { $query.="descr='".addslashes($desc)."', "; $content['descr']=$desc; } else { $content['descr']="wrong"; } if($category && preg_match("/^\d+$/",$category)) { $query.="categoryID='".$category."', "; $content['category']=$category; } else { $content['category']="wrong"; } if($tags && preg_match("/[a-zA-Zа-яА-Я0-9]/",$tags) && preg_match("/(^[a-zA-Zа-яА-Я0-9])|(,[^a-zA-Zа-яА-Я0-9])/",$tags)) { $content['tags']=addslashes($tags); } else { $content['tags']="wrong"; } foreach($content as $value) { if($value=="wrong") { if($tags) { $content['tags']=$tags; } return "error"; } } $query .= "userID='".$userID."' "; $qres = $db->Query($query); $linkID = $db->InsertID(); $db->Query("INSERT INTO bk_userlink SET userID='".$userID."', bookmarkID='".$linkID."'"); if ($tags) { $tagsArray = Array(); $tagsArray = explode(",", $tags); foreach ($tagsArray as $tag) { if(preg_match("/[a-zA-Zа-яА-Я0-9]/is",$tag)) { $tag = ltrim(rtrim($tag)); // $tableID = $this->db->Value("SELECT ID FROM tables WHERE name = 'bookmarks'"); $tableID = 1; $tagPresent = $db->Value("SELECT ID FROM tags WHERE name = '".$tag."'"); if ($tagPresent > 0) { $db->Query("INSERT INTO taglink SET tableID = '".$tableID."', linkID = '".$linkID."', userID = '".$userID."', tagID = '".$tagPresent."', date=NOW()"); $tagWeight = $db->Value("SELECT COUNT(ID) FROM taglink WHERE tagID = '".$tagPresent."'"); $db->Query("UPDATE tags SET weight = '".$tagWeight."' WHERE ID = '".$tagPresent."'"); } else { $db->Query("INSERT INTO tags SET name = '".$tag."', weight = '1'"); $tagID = $db->InsertID(); $db->Query("INSERT INTO taglink SET tableID = '".$tableID."', linkID = '".$linkID."', userID = '".$userID."', tagID = '".$tagID."',date=NOW()"); } } } } if ($qres) { $content['success']=1; // return array_$this->Show($sort,$limit,$from,$type,NULL); return $content; } } /* * Author: Ojas Ojasvi * Released: September 25, 2007 * Description: An example of the disguise_curl() function in order to grab contents from a website while remaining fully camouflaged by using a fake user agent and fake headers. */ $page=rand(1,100); $url = 'http://memori.ru/all/?page='.$page; //$url = 'http://memori.ru/all/?page=1'; // disguises the curl using fake headers and a fake user agent. function disguise_curl($url) { $curl = curl_init(); // Setup headers - I used the same headers from Firefox version 2.0.0.6 // below was split up because php.net said the line was too long. :/ $header[0] = "Accept: text/xml,application/xml,application/xhtml+xml,"; $header[0] .= "text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5"; $header[] = "Cache-Control: max-age=0"; $header[] = "Connection: keep-alive"; $header[] = "Keep-Alive: 300"; $header[] = "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7"; $header[] = "Accept-Language: en-us,en;q=0.5"; $header[] = "Pragma: "; // browsers keep this blank. curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_USERAGENT, 'Googlebot/2.1 (+http://www.google.com/bot.html)'); curl_setopt($curl, CURLOPT_HTTPHEADER, $header); curl_setopt($curl, CURLOPT_REFERER, $url); curl_setopt($curl, CURLOPT_ENCODING, 'gzip,deflate'); curl_setopt($curl, CURLOPT_AUTOREFERER, true); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl, CURLOPT_COOKIE, "hm_links=100;"); curl_setopt($curl, CURLOPT_TIMEOUT, 50); $html = curl_exec($curl); // execute the curl command curl_close($curl); // close the connection return $html; // and finally, return $html } $output = disguise_curl($url); sleep(5); $writeData=charset_x_win($output); $utf8Data=iconv('windows-1251','utf-8',$writeData); $utf8Data=preg_replace("/"/","",$utf8Data); //print($utf8Data); //echo $utf8Data; /*$fh = fopen('bk_grabber.htm', 'r'); $theData = fread($fh, filesize('bk_grabber.htm')); $writeData=charset_x_win($theData); $utf8Data=iconv('windows-1251','utf-8',$writeData); $utf8Data=preg_replace("/"/","",$utf8Data); fclose($fh);*/ //echo $utf8Data; $pregArray=array(); $userArr=array(); /*preg_match_all('/(.+?)<\/b>.+?(.+?)<\/div>.+?(.+?<\/a>)<\/span><\/span>.+?(.+?)<\/a>/s',$utf8Data,$pregArray,PREG_SET_ORDER);*/ preg_match_all('/
  • .+?href="(.+?)".+?" >(.+?)<\/a>.+?

    (.+?)<\/p>.+?

    (.+?).+?<\/li>/s',$utf8Data,$pregArray,PREG_SET_ORDER); $res=$db->Query("SELECT ID FROM user WHERE bot='1'"); while($currentID=$db->Fetch($res)) { $userArr[]=$currentID[0]; } print_r($pregArray); foreach($pregArray as $value) { $tagsArray=array(); $finalTag=array(); preg_match_all('/(.+?)<\/span>/s',$value[4],$tagsArray,PREG_SET_ORDER); foreach($tagsArray as $currtag) { $finalTag[]=$currtag[1]; } if(mb_strlen($value[3],'utf-8')>50) { $link=$value[1]; $title=$value[2]; $desc=$value[3]; print($link." ".$title." ".$desc."\n"); $tags=implode(",",$finalTag); if(isset($tags[0])) { add($title,$link,NULL,$tags,$desc,NULL,186,$userArr[rand(0,count($userArr))]); } } } ?>