free keyword script

Discussion in 'Keywords' started by NickD, Feb 27, 2007.

  1. #1
    I figured i'd share, il keep the thread updated as i work on it
    <?php
    class ErrorManager
    //ErrorManager.inc
    //author: nick from www.blakhatt.com
    {
    	var $errorFilePointer;
    	var $errorFileName = "error_log.txt";
    	
    	function ErrorManager()
    	{
    		$errorFilePointer = fopen($this->errorFileName,"a+");
    		if (!is_resource($this->errorFilePointer))
    		{
    			echo "Could not create error log file, try creating \"".$this->errorFileName."\" and setting the appropriate permissions.";
    			exit;
    		}
    	}	
    	function addError($errorString)
    	{
    		fwrite($this->errorFilePointer,$errorString);
    	}
    	function getLastError()
    	{
    	 	if (is_readable($this->errorFileName))
    	 	{
    			$errorData = file_get_contents($this->errorFileName);
    			$errorArray = explode("\n",$errorData);
    			return $errorArray[count($errorArray)];
    		} else
    		{
    			return 0;
    		}
    	}
    	function printErrors()
    	{
    	 	if (is_readable($this->errorFileName))
    	 	{
    			$errorData = file_get_contents($this->errorFileName);
    			$errorArray = explode("\n",$errorData);
    			foreach ($errorArray as $error)
    			{
    				echo "ERROR:".$error."<br>";
    			}
    		} else
    		{
    			return 0;
    		}		
    	}
    }
    ?>
    Code (markup):
    <?php
    //KeywordManager.inc
    include "ErrorManager.inc";
    class KeywordManager
    {
     	//class variables
     	var $keywordArray = array();
    
    	function KeywordManager()
    	{
    		//init function
    		$errorManager = new ErrorManager(); //create error manager object
    	}
    	function saveKeywordFile($fileName)
    	{
    	 	/*
    	 	saves file with specified array of keywords and file name
    	 	example: saveKeywordFile("saveas.txt",$keywordArray)
    		*/
    		$keywordArray = $this->keywordArray;
    		if (count($keywordArray) > 0)
    		{
    		 	if (file_exists($fileName))
    		 	{
    				$errorManager->addError("Filename already in use in function saveKeywordFile()");
    				return 0;
    			}
    			$filePointer = fopen($fileName,"w");
    			if (!is_resource($filePointer))
    			{
    				$errorManager->addError("Error creating file in function saveKeywordFile()");
    				return 0;
    			}
    			foreach ($keywordArray as $keyword)
    			{
    				fwrite($filePointer,$keyword."\n");
    			}
    			return 1;
    		} else
    		{
    			$errorManager->addError("The keyword array is empty in function saveKeywordFile()");
    			return 0;
    		}
    	}
    
    	function loadKeywordFile($fileName)
    	{
    		/*
    		loads a keyword file, returns array on success and 0 on failure
    		example: loadKeywordFile("keywords.txt");
    		*/
    		if (is_readable($fileName))
    		{
    			$filePointer = fopen($fileName,"r");
    			if (!is_resource($filePointer))
    			{
    				$errorManager->addError("Couldn't create file resource in loadKeywordFile()");
    				return 0;
    			}
    			while (!feof($filePointer))
    			{
    				$fileData .= fgets($filePointer,128);
    			}
    			$keywordArray = explode("\n",$fileData);
    			foreach ($keywordArray[0] as $keyword)
    			{
    				array_push ($this->keywordArray,$keyword);
    			}
    			return ($this->keywordArray);	
    		} else 
    		{
    		 	$errorManager->addError("The file isn't readable in loadKeywordFile()");
    			return 0;
    		}
    	}
    
    	function overtureKeywordSuggestions ($baseKeyword)
    	{
    		$curlHandle = curl_init();
    		curl_setopt($curlHandle,CURLOPT_URL,"http://inventory.uk.overture.com/d/searchinventory/suggestion/");
    		curl_setopt($curlHandle,CURLOPT_USERAGENT,"Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.2) Gecko/20070219 Firefox/2.0.0.2");
    		curl_setopt($curlHandle,CURLOPT_RETURNTRANSFER,1);
    		curl_setopt($curlHandle,CURLOPT_REFERER,"http://inventory.uk.overture.com/d/searchinventory/suggestion/");
    		curl_setopt($curlHandle,CURLOPT_POST,1);
    		curl_setopt($curlHandle,CURLOPT_POSTFIELDS,"mkt=uk&lang=en_GB&term=".urlencode($baseKeyword)."&x=11&y=5");
    		$returnedHtml = curl_exec($curlHandle);
    		preg_match_all("|<font face=\"verdana,sans-serif\" size=1 color=#000000>(.*)</a></td>|U",$returnedHtml,$keywordMatches);
    		foreach ($keywordMatches[1] as $keyword)
    		{
    		 	if (array_search($keyword,$this->keywordArray)==0)
    		 	{
    				array_push($this->keywordArray,$keyword);
    			} else
    			{
    				$errorManager->addError("Keyword already exist in array in function overtureKeywordSuggestions()");
    				return 0;
    			}				
    		}
    		return $this->keywordArray;
    	}
    }
    ?>
    Code (markup):

     
    NickD, Feb 27, 2007 IP
    Your Content likes this.
  2. Your Content

    Your Content Banned

    Messages:
    1,096
    Likes Received:
    45
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Thanks for sharing it, I will give it a try tonight :)
     
    Your Content, Feb 27, 2007 IP
  3. jjoshua

    jjoshua Well-Known Member

    Messages:
    257
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    118
    #3
    Sorry, but what exactly does the keyword script does? Anyway thanks for sharing it.
     
    jjoshua, Feb 28, 2007 IP
  4. NickD

    NickD Well-Known Member

    Messages:
    262
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    130
    #4
    It takes a base keyword and gets all the suggestions from overture, you can save to a file or load from a file. You can setup a loop to dig for deeper keywords after you get the first list also.
     
    NickD, Feb 28, 2007 IP
  5. Your Content

    Your Content Banned

    Messages:
    1,096
    Likes Received:
    45
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Indeed, tested and returning a list of keywords.

    Thank you.
     
    Your Content, Feb 28, 2007 IP
  6. dam_sid

    dam_sid Banned

    Messages:
    241
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #6
    thanks for sharing.
     
    dam_sid, Mar 2, 2007 IP
  7. Jona

    Jona Well-Known Member

    Messages:
    319
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    110
    #7
    How did u run these tho .inc files ???
    What functions to call to get it going ?
     
    Jona, Jun 3, 2007 IP
  8. sniperx

    sniperx Banned

    Messages:
    614
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    0
    #8
    thanks for shareing.
     
    sniperx, Jun 3, 2007 IP
  9. themanbeast9

    themanbeast9 Active Member

    Messages:
    1,665
    Likes Received:
    68
    Best Answers:
    0
    Trophy Points:
    90
    #9
    Thank you for this.
     
    themanbeast9, Jun 3, 2007 IP
  10. muiomuio

    muiomuio Active Member

    Messages:
    225
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    83
    #10
    It would be nice to know how to use it!
    Could someone please help out.

    thanks
     
    muiomuio, Sep 2, 2007 IP
  11. life31

    life31 Active Member

    Messages:
    1,024
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    78
    #11
    thanks will check it out soon.
     
    life31, Sep 2, 2007 IP
  12. NickD

    NickD Well-Known Member

    Messages:
    262
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    130
    #12
    Forgot i had posted this, :)
     
    NickD, Sep 5, 2007 IP
  13. amanamission

    amanamission Notable Member

    Messages:
    1,936
    Likes Received:
    138
    Best Answers:
    0
    Trophy Points:
    210
    #13
    Did you make any more progress on the script?
     
    amanamission, Sep 5, 2007 IP
  14. NickD

    NickD Well-Known Member

    Messages:
    262
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    130
    #14
    I will be posting an updated script on my blog.
     
    NickD, Sep 5, 2007 IP
  15. FUNNYBIRD

    FUNNYBIRD Peon

    Messages:
    76
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #15
    I am NEW here, let me ask how to run this scripts

    thanks
     
    FUNNYBIRD, Sep 5, 2007 IP
  16. Luke Jones

    Luke Jones Peon

    Messages:
    427
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #16
    Hello,
    I need some guidlines on how to use this script.
    I've tried changing $filename to saveas.txt and keywords.txt , but it didn't work.
    Without a few instructions, it doesn't work.
     
    Luke Jones, Sep 18, 2007 IP
  17. Luke Jones

    Luke Jones Peon

    Messages:
    427
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #17
    Indomeso,
    As you're site is in Turkish (I think), could you give me the link to the download?
    Does it do the same thing - getting keywords from Overture?
     
    Luke Jones, Sep 19, 2007 IP
  18. rainmaks

    rainmaks Guest

    Messages:
    12
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #18
    thanks for keyword script.
    The experiment
     
    rainmaks, Sep 19, 2007 IP