Public feed #892193

Stuff

public text v1 · immutable
Raw Edit
·published 2008-02-05 05:41 UTC
rendered paste body
	function mozBookmarkDump(){
		$parsed = array();
		
		$file = "/home/eljimbo/www/socialsoop/controller/bookmarks.html";
		$input = fopen($file, "r");
		$line = "";
		
		echo "Begin mozBookmark: " . memory_get_usage() . "<br>";
		while(!feof($input)){
			// Is it a link line?
			$dt = strpos($line, '<DT><A HREF="');
			if($dt != false){
				// Make array for this
				$entry = array();
				
				$start = strpos($line, '"', $dt+1) + 1; 
				$stop = strpos($line, '"', $start);
				$link = substr($line, $start, $stop-$start);
				array_push(&$entry, $link);
				
				// Find title
				$stop = strpos($line, '</A>', $stop);
				for($j=$stop;$j>0;$j--){
					if($line[$j] == ">"){
						$j++;
						array_push(&$entry, substr($line, $j, $stop-$j));
						break;
					}
				}
				
				// Check if description
				$line = fgets($input);				// GOTO next line
				$dd = strpos($line, '<DD>');

				if($dd !== false){
					$dd = $dd + 4;
					$dsc = substr($line, $dd, strlen($line)-4);
					array_push(&$entry, $dsc);
				}

				
				// Save entry
				array_push(&$parsed, $entry);
			} else {
				// GOTO nextline
				$line = fgets($input);
			}
		}
		fclose($input);
		unset($file);
		unset($line);
		unset($entry);
		// See if its an article or blog
		echo "End mozBookmark: " . memory_get_usage() . "<br>";
		enterMassData($parsed);
	}
//	function enterMassData(){
	function enterMassData($parsed){
		echo "Begin enterMassData: " . memory_get_usage() . "<br>";
		//require_once(HELPERS . 'Sanitize.php');
		require_once(DTOS . 'Blogs_dto.class.php');
		require_once(HELPERS . 'Simplepie.inc.php');
		require_once(MODEL . 'Items.inc.php');

	/*	$parsed = array(array('www.google.com', 'Google', 'some description'),
			array('www.google.com', 'Google', 'some description'),
			array('www.google.com', 'Google', 'some description'),
			array('www.google.com', 'Google', 'some description'),
			array('www.google.com', 'Google', 'some description'),
			array('www.google.com', 'Google', 'some description'),
			array('www.google.com', 'Google', 'some description'),
			array('www.google.com', 'Google', 'some description'),
			array('www.google.com', 'Google', 'some description'),
			array('www.google.com', 'Google', 'some description'),
			array('www.google.com', 'Google', 'some description'),
			array('www.google.com', 'Google', 'some description'),
			array('www.google.com', 'Google', 'some description'),
			array('www.google.com', 'Google', 'some description'),
			array('www.google.com', 'Google', 'some description'),
			array('www.google.com', 'Google', 'some description'),
			array('www.google.com', 'Google', 'some description'),
			array('www.google.com', 'Google', 'some description'),
			array('www.google.com', 'Google', 'some description'),
			array('www.google.com', 'Google', 'some description'),
			array('www.google.com', 'Google', 'some description'),
			array('www.google.com', 'Google', 'some description'),
			array('www.google.com', 'Google', 'some description'),
			array('www.google.com', 'Google', 'some description'),
			array('www.google.com', 'Google', 'some description'),
			array('www.google.com', 'Google', 'some description'),
			array('www.google.com', 'Google', 'some description'),
			array('www.google.com', 'Google', 'some description'),
			array('www.google.com', 'Google', 'some description'),
			array('www.google.com', 'Google', 'some description'),
			array('www.google.com', 'Google', 'some description'),
			array('www.google.com', 'Google', 'some description'),
			array('www.google.com', 'Google', 'some description'),
			array('www.google.com', 'Google', 'some description'),
			array('www.google.com', 'Google', 'some description'),
			array('www.google.com', 'Google', 'some description'),
			array('www.google.com', 'Google', 'some description'),
			array('www.google.com', 'Google', 'some description'),
			array('www.google.com', 'Google', 'some description'),
			array('www.google.com', 'Google', 'some description'),
			array('www.google.com', 'Google', 'some description'),
			array('www.google.com', 'Google', 'some description'),
			array('www.google.com', 'Google', 'some description'),
			array('www.google.com', 'Google', 'some description'),
			array('www.google.com', 'Google', 'some description'),
			array('www.google.com', 'Google', 'some description'),
			array('www.google.com', 'Google', 'some description'),
			array('www.google.com', 'Google', 'some description'),
			array('www.google.com', 'Google', 'some description'),
			array('www.google.com', 'Google', 'some description'),
			array('www.google.com', 'Google', 'some description'),
			array('www.google.com', 'Google', 'some description'),
			array('www.google.com', 'Google', 'some description'),
			array('www.google.com', 'Google', 'some description'),
			array('www.google.com', 'Google', 'some description'),
			array('www.google.com', 'Google', 'some description'),
			array('www.google.com', 'Google', 'some description'),
			array('www.google.com', 'Google', 'some description')
		);
	*/	
		session(); $userId = $_SESSION['user']['id'];
		$undecided = array();
		$feed = new SimplePie();
		$feed->set_cache_location(HELPERS.'cache');
		$feed->set_stupidly_fast(true);
		$itemDb = new Items();
		
		$dto = new Blogs_dto(array(
			'url'=>'', 
			'name'=>'', 
			'rss_url'=>'',
			'description'=>''
		));
		
		// Determine if its article or blog
		foreach($parsed as $entry) {
			echo "loop - " . ": " . memory_get_usage() . "<br>";
			// Check for a feed
			$feed->set_feed_url($entry[0]);
			$feed->init();
			$feed->handle_content_type();
			
			//$feed->handle_content_type();
		
			$rss= $feed->subscribe_url();
			
			// Check databases
			$dto->data['url']=$entry[0];
			$dto->data['name']=$entry[1];
			$dto->data['rss_url']=$rss;
			$dto->data['description']=$entry[2];
			 
			echo $entry[1] . " - ";
			
			$rs = $itemDb->selectItemsAll($dto);
//			echo $row[0] . " - " . $row[1] . " - ";
//			return;
			if($rs == false){
				// Not in the database
				if(strlen($rss) < 5){
					// If no feed, must be article
					//addArticle($dto);
					echo "addarticle<br>";
				} else {
					// Anyones guess?
					echo "anyoneguess<br>";
					array_push(&$undecided, $entry);
				}
			} else {
				// In the database
				$row = $rs->FetchRow();
				echo $row[0] . " - ";
				if( $row != false){
					// subscribe user
					//addUserToItem($row[0], $userId);
					echo "insystem<br>";
				}
			}
		}
		
		print_r($undecided); return;
	}