<?php 
/*#################################################################*\
|# Licence Number 0DT7-0122-0NW1-0210
|# -------------------------------------------------------------   #|
|# Copyright (c)2010 PHP Link Directory.                           #|
|# http://www.phplinkdirectory.com                                 #|
\*#################################################################*/
	 
      $showImport = 1;

      if (AJAX_CAT_SELECTION_METHOD == 0)
      {
         $categs = get_categs_tree();
         $tpl->assign('categs', $categs);
      }

      $importResults = array();

      	$fp = @ fopen ('../me_log.txt','w');
	
		@ fwrite ($fp, "\n\n");
		
		$import = $_REQUEST['import'];
		
		@ fwrite ($fp, $import."\n\n");
		
		//need to format imported string to array
		//string format looks like: title||url||content<end_line>
		
		$aux1 = array();
		$aux2 = array();
		$importResults = array();
		
		$aux1 = explode('[end_line]', $import);
		
		for ($i = 0; $i<count($aux1); $i++) {
			$aux2 = explode('||', $aux1[$i]);
			if ($aux1[$i] != '') {
				
				$importResults[$i]['TITLE'] = un_escape(clean_string($aux2[0]));
				
				$importResults[$i]['URL'] = parseDomain($aux2[2], 1);
				//Correct URL
	            if (strlen (trim ($importResults[$i]['URL'])) > 0 && !preg_match ('#^http[s]?:\/\/#i', $importResults[$i]['URL']))
	               $importResults[$i]['URL'] = "http://".$importResults[$i]['URL'];
				
	           	$importResults[$i]['DESCRIPTION'] = un_escape(clean_string($aux2[1]));
	           	
				$importResults[$i]['DOMAIN'] = parseDomain($aux2[2]);
				
				//Build author name [domain name??]
	            $importResults[$i]['OWNER_NAME'] = $importResults[$i]['DOMAIN'];
	            
	            //Build author email [webmaster@domain]
				$importResults[$i]['OWNER_EMAIL'] = 'webmaster@'.$importResults[$i]['DOMAIN'];
				
				$importResults[$i]['ID'] = $i;
				$db->Execute("INSERT INTO `".$tables['link_to_import']['name']."` (`ID`, `TITLE`, `DESCRIPTION`, `URL`, `DOMAIN`, `OWNER_EMAIL`) 
							VALUES ('', ".$db->qstr($importResults[$i]['TITLE']).", ".$db->qstr($importResults[$i]['DESCRIPTION']).",
							".$db->qstr($importResults[$i]['URL']).", ".$db->qstr($importResults[$i]['DOMAIN']).", ".$db->qstr($importResults[$i]['OWNER_EMAIL']).")");
				
			}
		}
		
		fwrite($fp,"--------".count($importResults));
		
		foreach($importResults as $key => $value){
			fwrite($fp,$key."\n\n");
			foreach($value as $k => $v){
				fwrite($fp,$k.": ".$v."\n\n");
			}
			fwrite($fp,"--------");
		}
      
      $tpl->assign('importResults', $importResults);
      
      $content = $tpl->fetch(ADMIN_TEMPLATE.'/spider.tpl');
	
?>