blogger auto-poster

I needed to get my new linkdirectory’s pages indexed and crawled and google needs some stimulation.

So I take a blogger subdomain,
and a 700 category php link directory
and make a table PLD_TAGCLOUD(CAT_ID, POSTED, TAG, FULLPATH)

CREATE TABLE `PLD_TAGCLOUD` (
`ID` BIGINT( 11 ) NOT NULL ,
`CAT_ID` DOUBLE NOT NULL ,
`POSTED` DOUBLE NOT NULL ,
`LEVEL` DOUBLE NOT NULL ,
`TAG` VARCHAR( 250 ) NOT NULL ,
`FULLPATH` VARCHAR( 250 ) NOT NULL ,
PRIMARY KEY ( `ID` )
) ENGINE = MYISAM

I fill the table with a recursive tree traversal on the category table where “tag” is the ‘title’ field,
and I get the FULLPATH url by using the domain root and the path generated by traversing the tree :

  1.  
  2. function connect() {
  3.  $DB_USER =  "";
  4.  $DB_PASSWORD = "";
  5.  $DB_HOST = "";
  6.  $DB_DATA = "";
  7.  $link =  mysql_connect($DB_HOST, $DB_USER, $DB_PASSWORD) or $error = mysql_error();
  8.  if (!$link) {
  9.      echo $error;
  10.   exit;
  11.  } else {
  12.     mysql_select_db($DB_DATA, $link) or $error = mysql_error();
  13.  return $link;
  14.  }
  15. }
  16.  
  17. $link = connect();
  18. $del="DELETE FROM `PLD_TAGCLOUD`";
  19. $mydel = mysql_query($del, $link) or die(mysql_error());
  20. @mysql_close($link);
  21.  
  22. $root='http://links.trismegistos.net';
  23. $content .= read(0, $root, 1);
  24.  
  25. function read($rootid, $pathid, $thislevel) {
  26.  $link = connect();
  27.  $myqry = "SELECT * FROM `PLD_CATEGORY` WHERE `PARENT_ID`='".$rootid."'";
  28.  $myres = mysql_query($myqry, $link) or die(mysql_error());
  29.  if(mysql_num_rows($myres)<1) return;
  30.  while($row=mysql_fetch_assoc($myres)) {  
  31.   $thispath= $pathid ."/".$row['TITLE_URL'];
  32.   $link2 = connect();
  33.   $add="INSERT INTO `PLD_TAGCLOUD` (`CAT_ID`, `LEVEL`, `TAG`, `FULLPATH`) VALUES ('".$row['ID']."', '".$thislevel."', '".htmlentities($row['TITLE'], ENT_QUOTES)."' ,'".$thispath."/')";
  34.   $addit = mysql_query($add, $link2) or die(mysql_error());
  35.   @mysql_close($link2);
  36.   read($row['ID'], $thispath, $thislevel+1);
  37.  }
  38.  @mysql_close($link);
  39. }

note : I also use a field level to store the depth of a category-page (o for root, 1 for main categories and mine goes down to 4)

Then we make a simple routine to grab the first record for posted=0,
grab the url
grab the title
grab 3 posts off of google-blogsearch on the TITLE, add em to an email,
add a link to the category page url,
mail(email, subject, message-body, headers)

and ofcourse the coupe-de-grace, the cronjob, 700 posts, 4 per hour, so in about 170 hours my entire site is listed on a nice juicy blog. Just for the hell of it i put the links of the blogsearch on ‘follow’ so my poor victims get a link as well.

  1.  
  2. function connect() {
  3.  $DB_USER =  "";
  4.  $DB_PASSWORD = "";
  5.  $DB_HOST = "";
  6.  $DB_DATA = "";
  7.  $link =  mysql_connect($DB_HOST, $DB_USER, $DB_PASSWORD) or $error = mysql_error();
  8.  if (!$link) {
  9.      echo $error;
  10.   exit;
  11.  } else {
  12.     mysql_select_db($DB_DATA, $link) or $error = mysql_error();
  13.  return $link;
  14.  }
  15. }
  16.  
  17.  $link = connect();
  18.  $myqry = "SELECT * FROM `PLD_TAGCLOUD` WHERE `POSTED`='0' ORDER BY ID DESC";
  19.  $myres = mysql_query($myqry, $link) or die(mysql_error());
  20.  if(mysql_num_rows($myres)<1) return;
  21.  while($row=mysql_fetch_assoc($myres)) {  
  22.   $myurl = $row['FULLPATH'];
  23.   $mykey = urlencode($row['TAG']);
  24.   $link2 = connect();
  25.   $add="UPDATE `PLD_TAGCLOUD` SET `POSTED`='1' WHERE `ID`='".$row['ID']."'";
  26.   $addit = mysql_query($add, $link2) or die(mysql_error());
  27.   @mysql_close($link2);
  28.   break;
  29.  }
  30.  @mysql_close($link);
  31.  
  32.  
  33. $xmlSource="http://blogsearch.google.com/blogsearch_feeds?hl=en&c2coff=1&lr=&safe=active&as_drrb=q&as_qdr=d&q=".$mykey."&ie=utf-8&num=3&output=rss";
  34. $title="";
  35. $link="";
  36. $description="";
  37. $author="";
  38. $pubDate="";
  39. $currentElement="";
  40. $nieuwsitems = array();
  41.  
  42. function startElement($parser,$name,$attr){
  43.  if(strcmp($name,"item")==0){
  44.  $GLOBALS['title']="";
  45.  $GLOBALS['link']="";
  46.  $GLOBALS['description']="";
  47.  $GLOBALS['author']="";
  48.  $GLOBALS['pubDate']="";
  49.  }
  50.  $GLOBALS['currentElement']=$name;
  51.  if(strcmp($name,"link")==0){ $GLOBALS['href']=$attr["href"]; }
  52.  
  53. }
  54.  
  55. function endElement($parser,$name){
  56.  $elements=array('title','link','description','author','pubDate');    
  57.  if(strcmp($name,"item")==0){
  58.   foreach($elements as $element){
  59.    $temp[$element] = $GLOBALS[$element];      
  60.   }
  61.  $GLOBALS['nieuwsitems'][]=$temp;
  62.  $GLOBALS['title']="";
  63.  $GLOBALS['link']="";
  64.  $GLOBALS['description']="";
  65.  $GLOBALS['author']="";
  66.  $GLOBALS['pubDate']="";
  67.  }
  68.  if(strcmp($name,"item")==0){
  69.   $GLOBALS['title']="";
  70.   $GLOBALS['link']="";
  71.   $GLOBALS['description']="";
  72.   $GLOBALS['author']="";
  73.   $GLOBALS['pubDate']="";
  74.  }
  75. }
  76.  
  77. function characterData($parser, $data) {
  78.  $elements = array ('title', 'link', 'description','author','pubDate');
  79.  foreach ($elements as $element) {
  80.   if ($GLOBALS["currentElement"] == $element) {
  81.    $GLOBALS[$element] .= $data;
  82.   }
  83.  }
  84. }
  85.  
  86. function parseFile(){
  87.  global $xmlSource,$nieuwsitems;
  88.  $xml_parser=xml_parser_create();
  89.  xml_set_element_handler($xml_parser,"startElement","endElement");
  90.  xml_set_character_data_handler($xml_parser,"characterData");
  91.  xml_parser_set_option($xml_parser,XML_OPTION_CASE_FOLDING,false);
  92.  if(!($fp=fopen($xmlSource,"r"))){
  93.   die("Cannot open  $xmlSource  ");
  94.  }
  95.  while(($data=fread($fp,4096))){
  96.   if(!xml_parse($xml_parser,$data,feof($fp))){
  97.    die(sprintf("XML error at line %d column %d ",
  98.    xml_get_current_line_number($xml_parser),
  99.    xml_get_current_column_number($xml_parser)));
  100.   }
  101.  }
  102.  xml_parser_free($xml_parser);
  103.  return $nieuwsitems;
  104. }
  105.  
  106. $result = parseFile();
  107.  
  108. foreach($result as $arr){
  109.  $strResult .= '< hr />';
  110.  $strResult .= '< h4>'.$arr["title"].'< /h4>'.$arr["description"].'< br /><a href="'.$arr["link"].'" title="'.$arr["title"].' ('.parse_url($arr["link"], PHP_URL_HOST).')">"'.$arr["title"].' ('.parse_url($arr["link"], PHP_URL_HOST).')</a>< br />< br />';
  111. }
  112.  
  113. $strResult .= '< br /> < a href="'.$myurl.'" title="'.$mykey.'">trismegistos links : '.$mykey.'< /a>< br />';
  114.  
  115. $email='juustout.linkdirectory@blogger.com';
  116. $subject = $mykey;
  117. mail($email,$subject,$strResult, "MIME-Version: 1.0\n"."Content-type: text/html; charset=iso-8859-1");
  118.  
  119. echo $strResult;

(note the html markup in the last lines is < br />, if you cut and paste it, remove the space or you get a mess, also note the extra header in the php mail function, makes it possible to post html-marked up text (otherwise you get flat text posted and your site looks like ****).

Posted in links, php, seo and tagged , , .

2 Comments

  1. I create a php script like this but using Blogger API, so i can post via email with image attachment and add some label. Your script can’t post label.

  2. Pingback: parsefile

Leave a Reply

Your email address will not be published. Required fields are marked *