внешние ссылки

Discussion in 'PHP' started by Serg0007, 15 Jun 2010.

  1. Serg0007

    Serg0007 New Member

    Joined:
    13 Mar 2009
    Messages:
    10
    Likes Received:
    1
    Reputations:
    0
    Поделитесь кто-нибудь функцией которая смотрит количество внешних ссылок на странице. Чтобы отслеживало ссылки с nofollow и noindex. Наверняка есть уже готовое решение
     
    #1 Serg0007, 15 Jun 2010
    Last edited: 15 Jun 2010
  2. Solker

    Solker Elder - Старейшина

    Joined:
    4 May 2006
    Messages:
    175
    Likes Received:
    53
    Reputations:
    18
    http://metrika.yandex.ru/
     
  3. Serg0007

    Serg0007 New Member

    Joined:
    13 Mar 2009
    Messages:
    10
    Likes Received:
    1
    Reputations:
    0
    и чем это мне поможет?
     
  4. Serg0007

    Serg0007 New Member

    Joined:
    13 Mar 2009
    Messages:
    10
    Likes Received:
    1
    Reputations:
    0
    PHP:
    function check_outlinks($page)
    {
        
    $content_page = file_get_contents($page) or die ("<font color=red>Îøèáêà çàïðîñà ñòðàíèöû!</font>");
        
    $content_page = preg_replace("!<NOINDEX>!i", "<noindex>", $content_page);
        
    $content_page = preg_replace("!</NOINDEX>!i", "</noindex>", $content_page);

        if (
    preg_match_all("!<noindex>!Ui", $content_page, $noindex_count))
        {
            
    preg_match_all("!</noindex>!Ui", $content_page, $noindexe_count);
            
    $full_count = count($noindex_count[0]) + count($noindexe_count[0]) + 1;
            
    //if (!is_float($full_count/2)) echo "<font color=red>Ñóùåñòâóþò îäèíî÷íûå òýãè <noindex>, âîçìîæíà íåêîððåêòíàÿ ðàáîòà!</font><br><br>";

            
    $noindex = 0;
            
    $n_out = 0;
            for (
    $i=0; $i<$full_count; $i++)
            {
                
    $pozition_begin = strpos($content_page, "<noindex>");
                
    $pozition_end = strpos($content_page, "</noindex>");
                if (
    $pozition_end == true && $pozition_begin == true && $pozition_begin < $pozition_end) 
                {
                    
    $content_parts[] = array(substr($content_page, 0, $pozition_begin), $noindex);
                    
    $noindex = 1;
                    
    $pozition_default = $pozition_begin+9;
                    
    $content_page = substr($content_page, $pozition_default);
                    
    $n_out++;
                }
                elseif ((
    $pozition_end == true && $pozition_begin == true && $pozition_end < $pozition_begin) || ($pozition_end == true && $pozition_begin == false))
                {
                    
    $content_parts[] = array(substr($content_page, 0, $pozition_end), $noindex);
                    if (--
    $n_out == 0) $noindex = 0;
                    
    $pozition_default = $pozition_end+10;
                    
    $content_page = substr($content_page, $pozition_default);
                }
                elseif (
    $pozition_end == false && $pozition_begin == false)
                {
                    
    $content_parts[] = array($content_page, $noindex);
                }
            }
        }
        else
            
    $content_parts[] = array($content_page);

        
    $url_real_edit = preg_replace("!http://|https://|www\.!Ui", "", $page);
        if (
    strpos($url_real_edit, "/") == true) $url_real_edit = substr($url_real_edit, 0, strpos($url_real_edit, "/"));

        for (
    $i=0; $i<count($content_parts); $i++)
        {
            
    preg_match_all("!<a[^>]+href\s*=\s*[\"']?([^\"']+)[\"']?[^>]*>(.+?)</a>!i", $content_parts[$i][0], $links);
            for (
    $r=0; $r<count($links[0]); $r++)
            {
                if (
    preg_match("!^(?:http://|https://)(?:www\.|)(.*)$!i", $links[1][$r], $url_parts))
                {
                    if (
    preg_match('!^' . $url_real_edit . '!i', $url_parts[1])) continue;
                    
    // Îïðåäåëåÿåì ññûëêó è àíêîð
                    
    $link = trim($url_parts[0]);
                    
    $ankor = $links[2][$r];

                    
    // Åñëè êàðòèíêà
                    
    if (preg_match ("!<img[^>]+src=[\"']?([^\"']+)[\"']?[^>]*>!i", $links[2][$r], $image_parts))
                        
    $ankor = $image_parts[1];
                    
                    
    // Äîáàâëÿåì ññûëêó â îñíîâíîé ìàññèâ èñõîäÿùèõ ññûëîê
                    
    $result['out'][] = Array($link, $ankor);

                    
    // Äîáàâëÿåì ññûëêó â ìàññèâ nofollow
                    
    if (preg_match("![\"'\s=]nofollow[\"'\s>]!Ui", $links[0][$r]))
                        
    $result['nofollow'][] = Array($link, $ankor);
                    
                    
    // Äîáàâëÿåì ññûëêó â ìàññèâ noindex
                    
    if ($content_parts[$i][1] == 1)
                        
    $result['noindex'][] = Array($link, $ankor);
                }
            }
        }
        return 
    $result;
    }

    if (
    $_POST['submit'] && $_POST['url_path'] != "")
        
    print_r (check_outlinks($_POST['url_path']));