Advertisement
Guest User

Untitled

a guest
Apr 21st, 2014
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.27 KB | None | 0 0
  1. function add_link_to_array($url_page)
  2. {
  3.  
  4.     global $log;
  5.     global $dots;
  6.     global $dots_open;
  7.     global $bad_links;
  8.     global $bad_open;
  9.     global $root;
  10.     global $all_links;
  11.     global $index;
  12.     global $root_index;
  13.     global $root_links;
  14.     global $pic_types;
  15.     global $old_cat;
  16.     global $now_cat;
  17.     global $links_find_log;
  18.  
  19.     fwrite($log, "\r\n".date("d.m.y H:i:s")." add_link_to_array from ".$url_page);
  20.  
  21.     $page = get_page($url_page);
  22.     if ($page['code'] == 200)
  23.         $html = str_get_html($page['page']);
  24.     else
  25.         return ;
  26.     if (!$html)
  27.         return;
  28.     foreach($html->find('a') as $a)
  29.     {
  30.         fwrite($links_find_log, "\r\n".date("d.m.y H:i:s")." find link: ".$url_page);
  31.         $link = $a->href;
  32.         $if_err_back_up_link = $link;
  33.         //if (!strcmp($link, $begin)) continue;
  34.         if ($link == NULL)
  35.             continue;
  36.         if ((strncasecmp($link, "mailto:",7) == 0) || ($link[0] == '#'))
  37.         {
  38.             echo 'link: '.$link.'<br />';
  39.             continue;
  40.         }
  41.         if (!(strncasecmp($link, '../', 3)))
  42.         {
  43.             if ($dots_open === FALSE)
  44.             {
  45.                 $dots = fopen("dots_links.txt","w");
  46.                 $t = fwrite($dots,"what\twhere\r\n");
  47.                 $dots_open = true;
  48.             }
  49.             $t = fwrite($dots, $link."\t".$url_page."\r\n");
  50.         }
  51.  
  52.         if ($link[0] == '/')
  53.             $link = $root.$link;
  54.         $u_arr = explode('#',$link);
  55.         $link = $u_arr[0];
  56.         $now_cat = return_correct_cat($url_page);
  57.         if ((!strcmp($begin, $url_page)) || (!strcmp($root, $url_page)))
  58.             $now_cat = $begin;
  59.         $pic_flag = false;
  60.         $ifpic = array();
  61.         $ifpic = explode('.',$link);
  62.         if (in_array( strtolower($ifpic[count($ifpic) - 1]),$pic_types))
  63.         {
  64.  
  65.             fwrite($log, '\r\nPIC!');
  66.             $pic_flag = true;
  67.             $code_rv = get_page($link);
  68.             $code = $code_rv['code'];
  69.             if ((($code >= 400) && ($code <600))|| ($code == 0))
  70.             {
  71.                 if ($bad_open === FALSE)
  72.                 {
  73.                     $bad_links = fopen('badlinks.txt', "w");
  74.                     $f = fwrite($bad_links,"link\tfinded link(on page, with out changing)\tcode\twhere find\r\n");
  75.                     $bad_open = true;
  76.                 }
  77.                 $f = fwrite($bad_links,$link."\t".$if_err_back_up_link."\n".$code."\t".$url_page."\r\n");
  78.             }
  79.         }
  80.         if ($pic_flag == TRUE) continue;
  81.  
  82.         $https = false;
  83.         if (strncasecmp($link, "https://", 8) === 0)
  84.         {
  85.             $https = true;
  86.             $code_rv = get_page($link);
  87.             $code = $code_rv['code'];
  88.             if (($code >= 400) || ($code == 0))
  89.             {
  90.                 if ($bad_open === FALSE)
  91.                 {
  92.                     $bad_links = fopen('badlinks.txt', "w");
  93.                     $f = fwrite($bad_links,"link\tfinded link(on page, with out changing)\tcode\twhere find\r\n");
  94.                     $bad_open = true;
  95.                 }
  96.                 $f = fwrite($bad_links,$link."\t".$code."\t".$url_page."\r\n");
  97.             }
  98.         }
  99.         if ($https) continue;
  100.         if ((strncasecmp($link, "http://", 7) != 0) && ($link[0] != '/'))
  101.             $link = $now_cat.$link;
  102.  
  103.         if (in_array($link, $all_links[0]) === FALSE)
  104.         {
  105.             $code_rv = get_page($link);
  106.             $all_links[0][$index] = $link;
  107.             $all_links[1][$index] = $code_rv['code'];
  108.             $all_links[2][$index] = FALSE;
  109.             if (strncasecmp($all_links[0][$index], $root, strlen($root) - 1) != 0)
  110.                 $all_links[2][$index] = TRUE;
  111.             else
  112.             {
  113.                 if ($all_links[1][$index] == 200)
  114.                 {
  115.                     $root_links[$root_index] = $link;
  116.                     $root_index++;
  117.                 }
  118.             }
  119.  
  120.             if ((($all_links[1][$index] >= 400) && ($all_links[1][$index] < 600))
  121.                     || ($all_links[1][$index] == 0))
  122.             {
  123.                 if ($bad_open === FALSE)
  124.                 {
  125.                     $bad_links = fopen('badlinks.txt', "w");
  126.                     $f = fwrite($bad_links,"link\tfinded link(on page, with out changing)\tcode\twhere find\r\n");
  127.                     $bad_open = true;
  128.                 }
  129.                 $f = fwrite($bad_links, $all_links[0][$index]."\t".$if_err_back_up_link."\t".$all_links[1][$index]."\t".$url_page."\r\n");
  130.             }
  131.             $index ++;
  132.         }
  133.     }
  134.  
  135. $html->clear();
  136. unset($html);
  137. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement