<?php


    #
    #host info
    #
    
    $data = get('http://www.iplocationfinder.com/' . clean_url($url));
    preg_match('~ISP.*<~',$data,$isp);
    preg_match('~Region.*<~',$data,$region);
    preg_match('~Country.*<~',$data,$country);
    preg_match('~IP:.*<~',$data,$ip);


    $country = explode(':',strip_tags($country[0]));
    $country = trim(str_replace('Hide your IP address and Location here','',$country[1]));
    if($country == '') $country = 'Not provided';

    $region = explode(':',strip_tags($region[0]));
    $region = trim($region[1]);
    if($region == '') $region = 'Not provided';

    $isp = explode(':',strip_tags($isp[0]));
    $isp = trim($isp[1]);
    if($isp == '') $isp = 'Not provided';

    $ip  = $ip[0];
    $ip  = trim(str_replace(array('IP:','<','/label>','/th>td>','/td>'),'',$ip));
    if($ip == '') $ip = 'Not provided';
 

 

    #
    # end of host info
    #

    #
    # Domain info
    #

    if(function_exists('fsockopen')){
        $pagerank = getpr($url);
        if($pagerank == ''){
            $pagerank = 0;
        }
            
    }
    else{
        $pagerank = 'Not provided';
    }


    $alexa_rank = get_alexa_popularity($url);
    if($alexa_rank == NULL){
        $alexa_rank = 'Not provided';
    }

    $alexa_popularity = alexa_backlink($url);
    if($alexa_popularity == NULL){
        $alexa_popularity = 'Not provided';
    }


    #
    # End of domain info
    #

    

    //http response

    if($c_http == 'true'){ 
    
    $msg_httpcode = '';
    if($httpcode == 200 || $httpcode == 500 || $httpcode == 301 || $httpcode == 302 || $httpcode == 403){
       $msg_httpcode =  ' <span class="label label-important agreen"> '.$lang['general_ok'].' </span>';
    }
    else{
        $msg_httpcode =  ' <span class="label label-success ared" >'.$lang['general_nok'].'</span>';
    }  
    
    }

    //end of http response

    //robots.txt check

    if($c_robots == 'true'){

    $robotsurl = $url;
    $robotstats = '';
    if($robotsurl{strlen($robotsurl) - 1} != '/') $robotsurl .= '/';
    $robotsurl .= 'robots.txt';
    $headers = explode("\r\n",getHeaders($robotsurl));
    
    
    $msg_robots = '';
    if(!empty($headers[0])){
        $httpcode = httpcodextractor($headers[0]);
        if($httpcode == 200 || $httpcode == 500 || $httpcode == 301 || $httpcode == 302 || $httpcode == 403){
            $msg_robots = '<span class="label label-important agreen"> '.$lang['general_present'].' </span>';
            $sitemapcheck = strpos('sitemap.xml',get($robotsurl));
        }
        else{
            $msg_robots = ' <span class="label label-success ared"> '.$lang['general_notpresent'].'</span>';
        }
    }
    else{
        $msg_robots = ' <span class="label label-success ared"> '.$lang['general_notpresent'].'</span>';
    }
    if(!isset($sitemapcheck)){
        $sitemapcheck = 'abc';
    }

    }

    //end of robots check


    //sitemap check

   
    if($c_sitemap == 'true'){

        $msg_sitemapcheck = '';
        $robotsurl = $url;
        $robotstats = '';
        if($robotsurl{strlen($robotsurl) - 1} != '/') $robotsurl .= '/';
        $robotsurl .= 'sitemap.xml';
        $headers = explode("\r\n",getHeaders($robotsurl));

        if(!empty($headers[0])){
            $httpcode = httpcodextractor($headers[0]);
            if($httpcode == 200 || $httpcode == 500 || $httpcode == 301 || $httpcode == 302 || $httpcode == 403){
                 $msg_sitemapcheck = '<span class="label label-important agreen"> '.$lang['general_present'].' </span>';
            }
            elseif(is_int($sitemapcheck)){
                 $msg_sitemapcheck = '<span class="label label-important agreen"> '.$lang['general_present'].' </span>';
            }
            else{
                 $msg_sitemapcheck = ' <span class="label label-success ared" > '.$lang['general_present'].'</span>';
            }
        }
        elseif(is_int($sitemapcheck)){
                 $msg_sitemapcheck = '<span class="label label-important agreen" > '.$lang['general_present'].' </span>';
        }
        else{
            $msg_sitemapcheck = ' <span class="label label-success ared" > '.$lang['general_present'].'</span>';
        }

    }

    //end of sitemap check

    #
    # Head elements check
    #

    //grabing meta data

    $url_data = str_replace('<meta charset="utf-8" />','<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />',get($url));
    $doc = new DOMDocument();
    @$doc->loadHTML($url_data);
    $nodes = $doc->getElementsByTagName('title');

    //get and display what you need:
    $title = $nodes->item(0)->nodeValue;
    $metas = $doc->getElementsByTagName('meta');
    for ($i = 0; $i < $metas->length; $i++){
        $meta = $metas->item($i);
        if($meta->getAttribute('name') == 'description')
            $description = $meta->getAttribute('content');
    if($meta->getAttribute('name') == 'keywords')
            $keywords = $meta->getAttribute('content');
    }
    if(isset($keywords) && !empty($keywords)){
       $original_keywords = $keywords;
    }
    if(isset($_GET['keywords']) && !empty($_GET['keywords'])){
       $keywords = $_GET['keywords'];
    }

    if(!isset($title)){
        $title = 'Not present';
        
    }
    if(!isset($description)){
        $description = 'Not present';
    }
    if(!isset($keywords)){
        $keywords = 'Not present';
    }

// end of grabbing metadata

//title check



    $msg_titlelenght = '';
    $msg_kwintitle   = '';
    $kwintitlests = '';

    if($title != 'Not present'){
    	if($h_t_length == 'true'){
            $lenght = strlen($title);
            if($lenght <= $h_t_length_d[0]){
                 $msg_titlelenght = '<span class="label label-success '.colorpick($h_t_length_c[0]).'">'.$lenght.' ('.$lang['general_notenough'].')</span>';
            }
            elseif($lenght >= $h_t_length_d[1] && $lenght <= $h_t_length_d[2]){
                 $msg_titlelenght = '<span class="label label-success '.colorpick($h_t_length_c[1]).'">'.$lenght.' ('.$lang['general_good'].')</span>';
            }
            elseif($lenght >= $h_t_length_d[3] && $lenght <= $h_t_length_d[4]){
                $msg_titlelenght = '<span class="label label-success '.colorpick($h_t_length_c[2]).'">'.$lenght.' ('.$lang['general_perfect'].')</span>';
            }
            elseif($lenght >= $h_t_length_d[5]){
                $msg_titlelenght = '<span class="label label-success '.colorpick($h_t_length_c[3]).'">'.$lenght.' ('.$lang['general_toomuch'].')</span>';
            }

        }

        if($h_t_stopwords == 'true'){

            $titlestopwords = stopwordscheck($title);
            $msg_titlestopwords = '';
            if($titlestopwords != null){
                $msg_titlestopwords = '<span class="label label-success ared">' . implode(',',$titlestopwords) . '</span>';
            }
            else{
                $msg_titlestopwords = '<span class="label label-success agreen">'.$lang['general_notpresent'].'</span>';
            }

        }

        if($keywords != 'Not present'){

            if($h_t_kwin == 'true'){

                $kwintitle = explode(',',$keywords);
                foreach($kwintitle as $kw){
                    if(!empty($kw)){
                        if(is_int(strpos(trim(strtolower($title)),trim(strtolower($kw))))){
                            $kwintitlests .= '1';
                        }
                        else{
                            $kwintitlests .= '0';
                        }
                    }
                }
                if(is_int(strpos($kwintitlests,'1'))){
                    $msg_kwintitle = '<span class="label label-success agreen">'.$lang['general_present'].'</span>';
                }else{
                    $msg_kwintitle = '<span class="label label-success ared">'.$lang['general_notpresent'].'</span>';
               
                }
            
            }

            //if($h_t_rel == 'true'){

                $msg_kw2titlerel = '';
                $count = 0;
                $titletemp = strtolower($title);
                 
                foreach(explode(',',$keywords) as $kw){
                    if(is_int(strpos($titletemp,  strtolower(trim($kw))))){
                        $count = $count + substr_count($titletemp,strtolower(trim($kw)));
                    }
                }
              
                $common = $count;
                $perc = 0;

                if($common == 0){
                   $perc = 0;       
                }
                elseif($common == 1){
                   $perc = 40;
                }
                elseif($common == 2){
                   $perc = 60;
                }
                elseif($common == 3){
                    $perc = 80;
                }
                elseif($common == 4){
                    $perc = 90;
                }
                elseif($common == 5 || $common > 5){
                    $perc = 100;
                }


                if($perc <= $h_t_rel_d[0]){
                    $msg_kw2titlerel = '<span class="label label-success '.colorpick($h_t_rel_c[0]).'">'.$perc.'% ('.$lang['general_bad'].')</span>';
                }
                elseif($perc >= $h_t_rel_d[1] && $perc <= $h_t_rel_d[2]){
                    $msg_kw2titlerel = '<span class="label label-success '.colorpick($h_t_rel_c[1]).'">'.$perc.'% ('.$lang['general_good'].')</span>';
                }
                elseif($perc > $h_t_rel_d[3]){
                    $msg_kw2titlerel = '<span class="label label-success '.colorpick($h_t_rel_c[2]).'">'.$perc.'% ('.$lang['general_perfect'].')</span>';
                }


           //}

         }
         else{
             $msg_kw2titlerel = '<span class="label label-success agrey">'.$lang['general_notcomputable'].'</span>';
             $msg_kwintitle   = '<span class="label label-success agrey">'.$lang['general_notcomputable'].'</span>';
         }



    }
    else{
        $msg_titlelenght    = '<span class="label label-success agrey">'.$lang['general_notcomputable'].'</span>';
        $msg_titlestopwords = '<span class="label label-success agrey">'.$lang['general_notcomputable'].'</span>';
        $msg_kwintitle      = '<span class="label label-success agrey">'.$lang['general_notcomputable'].'</span>';
        $msg_kw2titlerel    = '<span class="label label-success agrey">'.$lang['general_notcomputable'].'</span>';
    }




// end of title check



// meta keywords check

if(isset($original_keywords)){

    $msg_metakeywords = $original_keywords;
    
    if($h_k_count == 'true'){

            $count = count(explode(',',$original_keywords));
            $msg_keywordcountstats = '';
            //$count = 0;
            if($count <= $h_k_count_d[0]){
                $msg_keywordcountstats = '<span class="label label-success '.colorpick($h_k_count_c[0]).'">'. $count .' ('.$lang['general_notenough'].')</span>';
            }
            elseif($count > $h_k_count_d[1] && $count <= $h_k_count_d[2]){
                $msg_keywordcountstats = '<span class="label label-success '.colorpick($h_k_count_c[1]).'">'. $count .' ('.$lang['general_good'].')</span>';    
            }
            elseif($count > $h_k_count_d[3] && $count <= $h_k_count_d[4]){
                $msg_keywordcountstats = '<span class="label label-success '.colorpick($h_k_count_c[2]).'">'. $count .' ('.$lang['general_perfect'].')</span>';    
            }
            elseif($count > $h_k_count_d[5]){
                $msg_keywordcountstats = '<span class="label label-success '.colorpick($h_k_count_c[3]).'">'. $count .' ('.$lang['general_toomuch'].')</span>';    
            }
            else{
                $msg_keywordcountstats = '<span class="label label-success agrey">'.$lang['general_notcomputable'].'</span>';        
            }

    }
}
else{
    $msg_keywordcountstats = '<span class="label label-success agrey">'.$lang['general_notcomputable'].'</span>';
    $msg_metakeywords      = '<span class="label label-success ared">'.$lang['general_notpresent'].'</span>';
}


//relvance with site can be found below, under the "other calculations" comment


// meta keywords check


//meta description chech



if($description != 'Not present'){



    $msg_metakwindesc = '';
    $msg_metadescrel  = '';
    $msg_metadesctext = '';

    $msg_metadesctext = $description;


    if($h_d_length == 'true'){

        $msg_descleng = strlen($description);
        $tmp = $msg_descleng;
        if($tmp < $h_d_length_d[0]){
            $msg_descleng = '<span class="label label-success '.colorpick($h_d_length_c[0]).'">'.$tmp.' ('.$lang['general_notenough'].')</span>';
        }
        elseif($tmp >= $h_d_length_d[1] && $tmp <= $h_d_length_d[2]){
          $msg_descleng = '<span class="label label-success '.colorpick($h_d_length_c[1]).'">'.$tmp.' ('.$lang['general_good'].')</span>'; 
        }
        elseif($tmp >= $h_d_length_d[3] && $tmp <= $h_d_length_d[4]){
          $msg_descleng = '<span class="label label-success '.colorpick($h_d_length_c[2]).'">'.$tmp.' ('.$lang['general_perfect'].')</span>'; 
        }
        elseif($tmp > $h_d_length_d[5]){
            $msg_descleng = '<span class="label label-success '.colorpick($h_d_length_c[3]).'">'.$tmp.' ('.$lang['general_toomuch'].')</span>'; 
        }


    }

    if($h_d_rel == 'true'){

        $count = 0;   
        $desctemp = strtolower($description);
             

            foreach(explode(',',$keywords) as $kw){
                if(is_int(strpos($desctemp,  strtolower(trim($kw))))){
                    $count = $count + substr_count($desctemp,strtolower(trim($kw)));
                }
            } 
          
         $common = $count;

         if($common == 0){
                $msg_metadescrel = 0;     
            }
            elseif($common == 1){
                    $msg_metadescrel = 40;
            }
            elseif($common == 2){
                    $msg_metadescrel = 60;
            }
            elseif($common == 3){
                    $msg_metadescrel = 80;
            }
            elseif($common == 4){
                    $msg_metadescrel = 90;
            }
            elseif($common == 5 || $common > 5){
                    $msg_metadescrel = 100;
            }

           if($msg_metadescrel <= $h_d_rel_d[0]){
               $msg_metadescrel = '<span class="label label-success '.colorpick($h_t_rel_c[0]).'">'.$msg_metadescrel.'% ('.$lang['general_bad'].')</span>';
           }
           elseif($msg_metadescrel >= $h_d_rel_d[1] && $msg_metadescrel <= $h_d_rel_d[2]){
               $msg_metadescrel = '<span class="label label-success '.colorpick($h_t_rel_c[1]).'">'.$msg_metadescrel.'% ('.$lang['general_good'].')</span>';
           }
           elseif($msg_metadescrel > $h_d_rel_d[3]){
               $msg_metadescrel = '<span class="label label-success '.colorpick($h_t_rel_c[2]).'">'.$msg_metadescrel.'% ('.$lang['general_perfect'].')</span>';
           }
        
        }

        if($h_d_kwin == 'true'){

            $tmpstr = '';
            $tmp = 0;
            $tmpdesc = strtolower($description);
            foreach(explode(',',$keywords) as $kw){
                if(is_int(strpos($tmpdesc,trim(strtolower($kw))))){
                    $tmp .= '1';
                }
            else{
                    $tmp .= '0';
               }
            }
                    
            if(is_int(strpos($tmp,'1'))){
               $msg_metakwindesc = '<span class="label label-success agreen">'.$lang['general_present'].'</span>';
            }
            else{
               $msg_metakwindesc = '<span class="label label-success ared">'.$lang['general_notpresent'].'</span>';
            }

        }

        
}
else{
     $msg_metakwindesc = '<span class="label label-success agrey">'.$lang['general_notcomputable'] .'</span>';
     $msg_metadesctext = '<span class="label label-success ared">'.$lang['general_notpresent'].'</span>'; 
     $msg_descleng = '<span class="label label-success agrey">'.$lang['general_notcomputable'] .'</span>';     
}



    
    
    
    
    
    
//meta description chech    
    
    
    
    
    
    


    #
    # content check
    #


    


    $pageData = $url_data;

    //Language detection

    if($ct_lang == 'true' || $u_gram == 'true'){
        if(!isset($fatallang)){
            require_once('langdetect/autoload.php');;
            $detect = LanguageDetector\Detect::initByPath('datafile.php');
            $c_lang = $detect->detect($pageData);

            if(is_string($c_lang)){
                $language = $c_lang;
            }
            else{
                $all_langs = array();
                foreach($c_lang as $v){
                    $all_langs[$v['lang']] = $v['score'];
                }
                $language = array_search(max($all_langs),$all_langs);
            }
            if($language == 'english'){
                $lcode = 'en-US';
            }
            elseif($language == 'french'){
                $lcode = 'fr';
            }
            elseif($language == 'german'){
                $lcode = 'de-DE';
            }
            elseif($language == 'catalan'){
                $lcode = 'ca-ES';
            }
            elseif($language == 'danish'){
                $lcode = 'da-DK';
            }
            elseif($language == 'dutch'){
                $lcode = 'nl';
            }
            elseif($language == 'italian'){
                $lcode = 'it';
            }
            elseif($language == 'portuguese'){
                $lcode = 'pt-PT';
            }
            elseif($language == 'romanian'){
                $lcode = 'ro-RO';
            }
            elseif($language == 'spanish'){
                $lcode = 'es';
            }
            elseif($language == 'swedish'){
                $lcode = 'sv';
            }
            else{
                $lcode = false;
            }
            $msg_lang = ucfirst($language);
        }
        else{
            $msg_lang = $lang['general_notcomputable'];
            $lcode = false;
        }

        



        }

    $str = $pageData;
    $str = preg_replace('#<script(.*?)>(.*?)</script>#is', '', $str);
    $str = str_replace(array("\r","\rn","\n"),'',$str);
    $str = strip_tags($str);
    $str = preg_replace("/[^A-Za-z0-9 .,\"]/", '', $str);
    $strtemp = array();
    foreach(explode(' ',$str) as $word){
        if(strlen($word) != 0){

            $strtemp[] = $word;

        }
    }

    $pageData = implode(' ',$strtemp);

    if(isset($pageData) && !empty($pageData)){
        
		$contentlenght = strlen($pageData);
        $contentwords  = str_word_count($pageData);
        $kwincontent   = '';

		
		if($ct_chars == 'true'){
		
			if($contentlenght < $ct_chars_d[0]){
				$contentlenght = '<span class="label label-success '.colorpick($ct_chars_c[0]).'">'. $contentlenght .' ('.$lang['general_notenough'].')</span>';
			}
			 elseif($contentlenght >= $ct_chars_d[1] && $contentlenght <= $ct_chars_d[2]){
				$contentlenght = '<span class="label label-success '.colorpick($ct_chars_c[1]).'">'. $contentlenght .' ('.$lang['general_good'].')</span>';
			}
			elseif($contentlenght >= $ct_chars_d[3] && $contentlenght <= $ct_chars_d[4]){
				$contentlenght = '<span class="label label-success '.colorpick($ct_chars_c[2]).'">'. $contentlenght .' ('.$lang['general_perfect'].')</span>';
			}
			elseif($contentlenght > $ct_chars_d[5]){
				 $contentlenght = '<span class="label label-success '.colorpick($ct_chars_c[3]).'">'. $contentlenght .' ('.$lang['general_toomuch'].')</span>'; 
			}

		}
	
		if($ct_words == 'true'){
			if($contentwords < $ct_words_d[0]){
				$contentwords = '<span class="label label-success '.colorpick($ct_words_c[0]).'"> '. $contentwords .' ('.$lang['general_notenough'].')</span>';
			}
			elseif($contentwords >= $ct_words_d[1] && $contentwords <= $ct_words_d[2]){
				$contentwords = '<span class="label label-success '.colorpick($ct_words_c[1]).'"> '. $contentwords .' ('.$lang['general_good'].')</span>';
			}
			elseif($contentwords >= $ct_words_d[3] && $contentwords <= $ct_words_d[4]){
				$contentwords = '<span class="label label-success '.colorpick($ct_words_c[2]).'"> '. $contentwords .' ('.$lang['general_perfect'].')</span>';
			}
			elseif($contentwords > $ct_words_d[5]){
			 $contentwords = '<span class="label label-success '.colorpick($ct_words_c[3]).'"> '. $contentwords .' ('.$lang['general_toomuch'].')</span>';  
			}
			
		}
		
		if($ct_kwin == 'true'){

             if($keywords != 'Not present'){
					$kwintitle = explode(',',$keywords);
					foreach($kwintitle as $kw){
					if(!empty($kw)){
						if(is_int(strpos(trim(strtolower($pageData)),trim(strtolower($kw))))){
							$kwincontent .= '1';
						}
						else{
							$kwincontent .= '0';
						}
					}
				}
				if(is_int(strpos($kwincontent,'1'))){
					$kwincontent = '<span class="label label-success agreen">'.$lang['general_present'].'</span>';
				}else{
					 $kwincontent = '<span class="label label-success ared">'.$lang['general_notpresent'].'</span>';
				}

			}
			else{
				$kwincontent = '<span class="label label-success ared">'.$lang['general_notpresent'].'</span>';
			}
        

        $count = 0;
        foreach($kwintitle as $kw){
            if(is_int(strpos($pageData,  strtolower(trim($kw))))){
                $count = $count + substr_count($pageData,strtolower(trim($kw)));
            }
        }


        if($ct_rel == 'true'){
           $common = $count;
            if($common == 0){
                $contentrelevance = 0;       
            }
            elseif($common >= 1 && $common <= 5){
               $contentrelevance = 20;  
            }
           
            elseif($common > 5 && $common <= 11){
                    $contentrelevance = 40;
            }
            elseif($common > 11 && $common <= 16){
                    $contentrelevance = 60;
            }
            elseif($common > 16 && $common <= 21){
                    $contentrelevance = 80;
            }
            elseif($common > 21 && $common <= 26){
                    $contentrelevance = 90;
            }
            elseif($common > 26){
                    $contentrelevance = 100;
            }


            if($contentrelevance <= $ct_rel_d[0]){
                $contentrelevance = '<span class="label label-success '.colorpick($ct_rel_c[0]).'">'.$contentrelevance.'% ('.$lang['general_bad'].')</span>';
            }
            elseif($contentrelevance >= $ct_rel_d[1] && $contentrelevance <= $ct_rel_d[2]){
                $contentrelevance = '<span class="label label-success '.colorpick($ct_rel_c[1]).'">'.$contentrelevance.'% ('.$lang['general_good'].')</span>';
            }
            elseif($contentrelevance > $ct_rel_d[3]){
                $contentrelevance = '<span class="label label-success '.colorpick($ct_rel_c[2]).'">'.$contentrelevance.'% ('.$lang['general_perfect'].')</span>';
            }

        }

         }
         else{
            $contentrelevance = '<span class="label label-success agrey">'.$lang['general_notcomputable'].'</span>';
            $kwincontent = '<span class="label label-success agrey">'.$lang['general_notcomputable'].'</span>';
         }
		 
    }  
    else{
        $contentlenght = '<span class="label label-success agrey"> '.$lang['general_notcomputable'].'</span>'; 
        $kwincontent = '<span class="label label-success ared">'.$lang['general_notpresent'].'</span>';
        $contentwords = '<span class="label label-success agrey">'.$lang['general_notcomputable'].'</span>';
        $contentrelevance = '<span class="label label-success agrey">'.$lang['general_notcomputable'].'</span>';
    }

    
    
    // checking for italic elements 
    
    
    if($ct_kwini == 'true'){

    $tmp = '';
    $msg_contentitalics = '';
    preg_match_all('#<i>(.+?)</i>#', $url_data, $italics);
    if(!empty($italics[0])){
            $italics = trim(strtolower(implode('',$italics[0])));
            if($keywords != 'Not present'){
                foreach(explode(',',$keywords) as $kw){
                    if(is_int(strpos($italics,trim(strtolower($kw))))){
                      $tmp .= '1';  
                    }
                    else{
                        $tmp .= '0';
                    }
                            
                }
                if(is_int(strpos($tmp,'1'))){
                    $msg_contentitalics = '<span class="label label-success agreen">'.$lang['general_present'].'</span>';
                }
                else{
                    $msg_contentitalics = '<span class="label label-success ared">'.$lang['general_notpresent'].'</span>';
                }
            }
            else{
                  $msg_contentitalics = '<span class="label label-success agrey">'.$lang['general_notcomputable'].'</span>';
            }
        }
        else{
             $msg_contentitalics = '<span class="label label-success ared">'.$lang['general_notpresent'].'</span>';
        }   

    }
    // end of checking for italic elements 
    
    //bold checkings
    
    if($ct_kwinb == 'true'){
        $tmp = '';
        $msg_contentbold = '';
        preg_match_all('#<b>(.+?)</b>#', $url_data, $bolds);
        preg_match_all('#<strong>(.+?)</strong>#', $url_data, $bolds2);

        $bolds = array_merge($bolds[0],$bolds2[0]);

        if(!empty($bolds)){
                $bolds = trim(strtolower(implode('',$bolds)));
                if($keywords != 'Not present'){
                    foreach(explode(',',$keywords) as $kw){
                        if(is_int(strpos($bolds,trim(strtolower($kw))))){
                          $tmp .= '1';  
                        }
                        else{
                            $tmp .= '0';
                        }
                                
                    }
                    if(is_int(strpos($tmp,'1'))){
                        $msg_contentbold = '<span class="label label-success agreen">'.$lang['general_present'].'</span>';
                    }
                    else{
                        $msg_contentbold  = '<span class="label label-success ared">'.$lang['general_notpresent'] .'</span>';
                    }
                }
                else{
                     $msg_contentbold = '<span class="label label-success agrey">'.$lang['general_notcomputable'].'</span>';
                }
            }
            else{
                $msg_contentbold = '<span class="label label-success ared">'.$lang['general_notpresent'] .'</span>';
            }  
    }    
    
    // end of bold chekcings
    
    
    
    //headings check
    
    if($ct_headings == 'true'){
        preg_match_all('/<h\d>([^<]*)<\/h\d>/iU', $url_data, $headings);
        $msg_contentheadings = '';
        $_1 = 0;
        $_2 = 0;
        $_3 = 0;
        $_4 = 0;
        $_5 = 0;
        $_6 = 0;
        if(!empty($headings[0])){
            foreach($headings[0] as $head){
                if(is_int(strpos(trim(strtolower($head)),'<h1>'))){
                    $_1++;
                }
                if(is_int(strpos(trim(strtolower($head)),'<h2>'))){
                    $_2++;
                }
                if(is_int(strpos(trim(strtolower($head)),'<h3>'))){
                    $_3++;
                }
                if(is_int(strpos(trim(strtolower($head)),'<h4>'))){
                    $_4++;
                }
                if(is_int(strpos(trim(strtolower($head)),'<h5>'))){
                    $_5++;
                }
                if(is_int(strpos(trim(strtolower($head)),'<h6>'))){
                    $_6++;
                }
            }
            $msg_contentheadings = '<span class="label label-success agrey"><strong>h1:</strong>' . $_1 . ' - <strong>h2:</strong>' . $_2 .' - <strong>h3:</strong>' . $_3 . ' - <strong>h4:</strong>' . $_4. ' - <strong>h5:</strong>' . $_5. ' - <strong>h6:</strong>' . $_6 . '</span>';
        }
        else{
            $msg_contentheadings = '<span class="label label-success ared">'.$lang['general_notpresent'].'</span>';
        }
    }
    
    //end of headings check
    
    
    // iframe checking

    if($ct_iframes == 'true'){
        $msg_contentframes = '';
        preg_match('/<iframe.*src=\"(.*)\".*><\/iframe>/isU', $url_data, $matches);
        if(empty($matches[0])){
            $msg_contentframes = '<span class="label label-success agreen">'.$lang['general_present'].'</span>';
        }
        else{
            $msg_contentframes = '<span class="label label-success ared">'.$lang['general_notpresent'].'</span>';    
        }
    }
    
    // end of iframe checkings
    
    
    #
    # end of content check
    #
    



    #
    # url structure check
    #




    $msg_urldomain = strtolower(clean_url($url));

    if($ul_sub == 'true'){
        $msg_urlsubdomain = '';
        if(count(explode('.',$msg_urldomain)) > 2){
            $msg_urlsubdomain = '<span class="label label-success ared">'.$lang['general_present'].'</span>';
        }
        else{
             $msg_urlsubdomain = '<span class="label label-success agreen">'.$lang['general_notpresent'].'</span>';
        }
    }


    if($ul_kwin == 'true'){
        $tmp = '';
        $msg_kwinurl = '';
        if($keywords != 'Not present'){
            foreach(explode(',',$keywords) as $kw){
                    if(is_int(strpos($msg_urldomain,trim(strtolower($kw))))){
                        $tmp .= '1';
                    }
                    else{
                        $tmp .= '0';
                    }
                }
                if(is_int(strpos($tmp,'1'))){
                $msg_kwinurl = '<span class="label label-success agreen">'.$lang['general_present'].'</span>';
            }
            else{
                $msg_kwinurl = '<span class="label label-success ared">'.$lang['general_notpresent'].'</span>';
            }
        }
        else{
             $msg_kwinurl = '<span class="label label-success ared">'.$lang['general_notpresent'].'</span>';

        }
    }
    

    if($ul_length == 'true'){
        $msg_urldomainlenght = '';
        $tmp = strlen($msg_urldomain);
        if($tmp <= $ul_length_d[0]){
            $msg_urldomainlenght = '<span class="label label-success '.colorpick($ul_length_c[0]).'" >' . $tmp . ' ('.$lang['general_perfect'].')</span>';
        }
        elseif($tmp >= $ul_length_d[1] && $tmp <= $ul_length_d[2]){
                 $msg_urldomainlenght = '<span class="label label-success '.colorpick($ul_length_c[1]).'" >' . $tmp . ' ('.$lang['general_good'].')</span>';
        }
        elseif($tmp > $ul_length_d[3]){
            $msg_urldomainlenght = '<span class="label label-success '.colorpick($ul_length_c[2]).'" >' . $tmp . ' ('.$lang['general_bad'].')</span>';
        }
   }

       

    #
    # end of url structure check
    #


    #
    # links check (& UX: feedback page)
    #



    $feedbackpage = false;
    $feedbackpages = array(
                    'contact.php',
                    'contact.html',
                    'contact.htm',
                    'contact.asp',
                    'contact.aspx',
                    'contact.jsp',
                    'contact',
                    'contact-us.php',
                    'contact_us.htm',
                    'contact_us.html',
                    'contact-us',
                    'contact_us',
                    'support',
                    'support.php',
                    'support.html',
                    'support.htm',
                    'support.asp',
                    'support.aspx',
                    'support.jsp',
                    'feedback',
                    'feedback.php',
                    'feedback.html',
                    'feedback.htm',
                    'feedback.asp',
                    'feedback.aspx',
                    'feedback.jsp'
                    );

    if($l_ilinks == 'true' || $e_ilinks == 'true' || $u_fb == 'true'){

        $doc = new DOMDocument();
        $doc->loadHTML($url_data);
        $xpath = new DOMXPath($doc);
        $urls = array();
        $nodeList = $xpath->query('//a/@href');
        for ($i = 0; $i < $nodeList->length; $i++) {
            $urls[] = $nodeList->item($i)->value . "<br/>\n";
        }
        $tmp = 0;

        foreach($urls as $url){

            //feed back page check

            if($u_fb == 'true'){
                if($feedbackpage != true){
                    foreach($feedbackpages as $page){
                        if(is_int(strpos(strtolower($url),strtolower($page)))){
                            $feedbackpage = true;
                        }
                    }
                }
            }
            //end of feedback page check

            if(is_int(strpos($url,'http')) || is_int(strpos($url,'www'))){
                if(!is_int(strpos($url,$msg_urldomain))){
                    $tmp++;
                }
            }
        }
        $msg_externalinks = $tmp;
        $msg_internalinks = count($urls) - $tmp ;


        //int

        if($msg_internalinks <= $l_ilinks_d[0]){
            $msg_internalinks = '<span class="label label-success '.colorpick($l_ilinks_c[0]).'"> '. $msg_internalinks .' ('.$lang['general_notenough'].')</span>';
        }
        elseif($msg_internalinks >= $l_ilinks_d[1] && $msg_internalinks <= $l_ilinks_d[2]){
            $msg_internalinks = '<span class="label label-success '.colorpick($l_ilinks_c[1]).'"> '. $msg_internalinks .' ('.$lang['general_good'].')</span>';
        }
        elseif($msg_internalinks >= $l_ilinks_d[3] && $msg_internalinks <= $l_ilinks_d[4]){
            $msg_internalinks = '<span class="label label-success '.colorpick($l_ilinks_c[2]).'"> '. $msg_internalinks .' ('.$lang['general_perfect'].')</span>';
        }
        elseif($msg_internalinks > $l_ilinks_d[5]){
         $msg_internalinks = '<span class="label label-success '.colorpick($l_ilinks_c[3]).'"> '. $msg_internalinks .' ('.$lang['general_toomuch'].')</span>';  
        }

        //ext

        if($msg_externalinks <= $l_elinks_d[0]){
            $msg_externalinks = '<span class="label label-success '.colorpick($l_elinks_c[0]).'"> '. $msg_externalinks .' ('.$lang['general_notenough'].')</span>';
        }
        elseif($msg_externalinks >= $l_elinks_d[1] && $msg_externalinks <= $l_elinks_d[2]){
            $msg_externalinks = '<span class="label label-success '.colorpick($l_elinks_c[1]).'"> '. $msg_externalinks .' ('.$lang['general_good'].')</span>';
        }
        elseif($msg_externalinks >= $l_elinks_d[3] && $msg_externalinks <= $l_elinks_d[4]){
            $msg_externalinks = '<span class="label label-success '.colorpick($l_elinks_c[2]).'"> '. $msg_externalinks .' ('.$lang['general_perfect'].')</span>';
        }
        elseif(($msg_externalinks >= $l_elinks_d[4] && $msg_externalinks <= $l_elinks_d[5]) || $msg_externalinks > $l_elinks_d[5]){
         $msg_externalinks = '<span class="label label-success '.colorpick($l_elinks_c[3]).'"> '. $msg_externalinks .' ('.$lang['general_toomuch'].')</span>';  
        }

      
    }

    #
    # end of links check
    # 

    #
    # other calculations
    #

    if(isset($original_keywords)){
        if($h_k_count == 'true'){
            $msg_metakeywordsrel = '';
            $tmp = (extractint(strip_tags($msg_kw2titlerel)) + extractint(strip_tags($contentrelevance)) ) / 2 + $msg_metakeywordsrel + 25;
            if($tmp > 100){
                $tmp = 100;
            }
            if(is_int($tmp)){
               if($tmp < $h__k_rel_d[0]){
                $msg_metakeywordsrel = '<span class="label label-success '.colorpick($h__k_rel_c[0]).'">' . $tmp . '% ('.$lang['general_bad'].')</span>';
               }
               elseif($tmp >= $h__k_rel_d[1] && $tmp <= $h__k_rel_d[2]){
                 $msg_metakeywordsrel = '<span class="label label-success '.colorpick($h__k_rel_c[1]).'">' . $tmp . '% ('.$lang['general_good'].')</span>';
               }
                elseif($tmp > $h__k_rel_d[3]){
                 $msg_metakeywordsrel = '<span class="label label-success '.colorpick($h__k_rel_c[2]).'">' . $tmp . '% ('.$lang['general_perfect'].')</span>';
               }

            }
            else{
               $msg_metakeywordsrel = '<span class="label label-success agrey">'.$lang['general_notcomputable'].'</span>';
            }
        }
    }
    else{
        $msg_metakeywordsrel = '<span class="label label-success agrey">'.$lang['general_notcomputable'].'</span>';
    }
    
    
    
    //some double checkings
    
    if(!isset($msg_metakeywordsrel) || empty($msg_metakeywordsrel)){
        $msg_metakeywordsrel = '<span class="label label-success agrey">'.$lang['general_notcomputable'].'</span>';
    }
    if(!isset($msg_metadescrel) || empty($msg_metadescrel)){
        $msg_metadescrel = '<span class="label label-success agrey">'.$lang['general_notcomputable'].'</span>';
    }
    



    $msg_title = '';
    if($title == 'Not present'){
       $msg_title = '<span class="label label-success ared">'.$lang['general_notpresent'].'</span>'; 
    }
    else{
        $msg_title = $title;
    }

   



    #
    # User experience Check
    # 

    //page speed

    $pagespeed_apikey = 'AIzaSyDuqDtFMAIVGGDgr40qLKuQ4WjxklxHors';

    if($u_speed == 'true'){

        $url = 'http://' . clean_url($original_url);

        $data = json_decode(get('https://www.googleapis.com/pagespeedonline/v1/runPagespeed?url='. $url .'&key=' . $pagespeed_apikey));
        $score = $data->score;
        $score = 98;
        if($score != null){

            if($score <= $u_speed_d[0]){
                $msg_speed = '<span class="label label-success '.colorpick($u_speed_c[0]).'"> '. $score .' ('.$lang['general_notenough'].')</span>';
            }
            elseif($score >= $u_speed_d[1] && $score <= $u_speed_d[2]){
                $msg_speed = '<span class="label label-success '.colorpick($u_speed_c[1]).'"> '. $score .' ('.$lang['general_good'].')</span>';
            }
            elseif($score >= $u_speed_d[3] && $score <= $u_speed_d[4]){
                $msg_speed = '<span class="label label-success '.colorpick($u_speed_c[2]).'"> '. $score .' ('.$lang['general_perfect'].')</span>';
            }
            elseif($score > $u_speed_d[5]){
             $msg_speed = '<span class="label label-success '.colorpick($u_speed_c[3]).'"> '. $score .' ('.$lang['general_toomuch'].')</span>';  
            }

        }
        else{
            $msg_speed = '<span class="label label-success agrey">'.$lang['general_notcomputable'].'</span>';
        }

    }

    //grammar erros

    if($u_gram == 'true'){
        if($lcode != false){

            $pageData = str_replace(' ', '+', $pageData);
            $spelling = get('https://languagetool.org:8081/?language='.$lcode.'&text='. urlencode($pageData));
            if(!is_int(strpos($spelling,'too many requests. Allowed maximum requests: 20 requests per 60 seconds'))){
           
                $score = substr_count($spelling, '<error');

                 if($score <= $u_gram_d[0]){
                      $msg_spelling = '<span class="label label-success '.colorpick($u_gram_c[0]).'"> '. $score .' ('.$lang['general_perfect'].')</span>';
                 }
                 elseif($score >= $u_gram_d[1] && $score <= $u_gram_d[2]){
                      $msg_spelling = '<span class="label label-success '.colorpick($u_gram_c[1]).'"> '. $score .' ('.$lang['general_good'].')</span>';
                 }
                 elseif($score > $u_gram_d[3]){
                   $msg_spelling = '<span class="label label-success '.colorpick($u_gram_c[2]).'"> '. $score .' ('.$lang['general_bad'].')</span>';  
                 }

            }
            else{
                $msg_spelling = '<span class="label label-success agrey">'.$lang['general_lang_unavailable'].'</span>';
            }

        }
        else{
            $msg_spelling = '<span class="label label-success agrey">'.$lang['general_lang_notsup'].'</span>';
        }
    }


    //responsive check

    if($u_res == 'true'){

        $doc = new DOMDocument();
        $doc->loadHTML($url_data);
        $xml = simplexml_import_dom($doc);
        $result = $xml->xpath('//link[@rel="stylesheet"]');
        $files = array();
        foreach($result as $node) { 
            $link = $node->attributes()->href;
            if (substr($link, 0, 4) == 'http') {
            } else if (substr($link, 0, 1) == '/') {
                $link = $url_parts['scheme'] .  $link;
            } else {
                $link = $url_parts['scheme'] .  dirname($url_parts['scheme']) .  $link;
            }

            $files[] = $link;

        }


        $url = explode('/',clean_url($url));
        if(count($url) != 1){
            unset($url[count($url) - 1]);
        }
        $url = implode('/',$url);

        $check = false;

        foreach($files as $file){


            if(is_int(strpos($file,'http://')) || is_int(strpos($file,'https://')) || is_int(strpos($file,'www.'))){
                $data = get($file);
                //print '<a href="'. $file . '">'. $file .'</a><br />';
            }
            else{
                $data = get($url . '/' . $file);
                //print '<a href="http://'. $url . '/' . $file . '">'. $url . '/' . $file . '</a><br />';
            }
            

            if(is_int(strpos($data,'@media'))){
                $check = true;
               break;
            }

        }

        if($check == true){
            $msg_responsive = '<span class="label label-success agreen" >'.$lang['general_resp'].'</span>';
        }else{
            $msg_responsive = '<span class="label label-success ared" >'.$lang['genral_notresp'].'</span>';
        }

    }

    //Contact page



    if($feedbackpage == true){
        $msg_feedback = '<span class="label label-success agreen">'.$lang['general_present'] .'</span>';
    }else{
        $msg_feedback = '<span class="label label-success ared">'.$lang['general_notpresent'].'</span>';
    }

    #
    # End of User experience Check
    # 




    #
    # Calculating points
    #


    $max_score = 0;
    $got_score = 0;

    if($c_http == 'true'){
      $max_score++;
      if(!is_int(strpos($msg_httpcode,$lang['general_nok']))){
        $got_score++;
      }
    }
    if($c_robots == 'true'){
        $max_score++;
        if(!is_int(strpos($msg_robots,$lang['general_notpresent']))){
            $got_score++;
        }
    }
    if($c_sitemap == 'true'){
        $max_score++;
        if(!is_int(strpos($msg_sitemapcheck,$lang['general_notpresent']))){
            $got_score++;
        } 
    }


    if($h_t_length == 'true'){
        $max_score += 2;
        if(is_int(strpos($msg_titlelenght,$lang['general_good']))){
            $got_score++;
        }
        elseif(is_int(strpos($msg_titlelenght,$lang['general_perfect']))){
            $got_score += 2;
        }
    }
    if($h_t_stopwords == 'true'){
        $max_score++;
        if(is_int(strpos($msg_titlestopwords,$lang['general_notpresent']))){
            $got_score++;
        } 
    }
    if($h_t_kwin == 'true'){
        $max_score++;
        if(!is_int(strpos($msg_kwintitle,$lang['general_notpresent']))){
            $got_score++;
        } 
    }
    if($h_t_rel == 'true'){
        $max_score += 2;
        if(is_int(strpos($msg_kw2titlerel,$lang['general_good']))){
            $got_score++;
        }
        elseif(is_int(strpos($msg_kw2titlerel,$lang['general_perfect']))){
            $got_score += 2;
        }
    }
    if($h_k_count == 'true'){
        $max_score += 2;
        if(is_int(strpos($msg_keywordcountstats,$lang['general_good']))){
            $got_score++;
        }
        elseif(is_int(strpos($msg_keywordcountstats,$lang['general_perfect']))){
            $got_score += 2;
        }
    }
    if($h_k_rel == 'true'){
        $max_score += 2;
        if(is_int(strpos($msg_metakeywordsrel,$lang['general_good']))){
            $got_score++;
        }
        elseif(is_int(strpos($msg_metakeywordsrel,$lang['general_perfect']))){
            $got_score += 2;
        }
    }
    if($h_d_length == 'true'){
        $max_score += 2;
        if(is_int(strpos($msg_descleng,$lang['general_good']))){
            $got_score++;
        }
        elseif(is_int(strpos($msg_descleng,$lang['general_perfect']))){
            $got_score += 2;
        }
    }
    if($h_t_kwin == 'true'){
        $max_score++;
        if(!is_int(strpos($msg_metakwindesc,$lang['general_notpresent']))){
            $got_score++;
        } 
    }
    if($h_d_rel == 'true'){
        $max_score += 2;
        if(is_int(strpos($msg_metadescrel,$lang['general_good']))){
            $got_score++;
        }
        elseif(is_int(strpos($msg_metadescrel,$lang['general_perfect']))){
            $got_score += 2;
        }
    }


    if($ct_chars == 'true'){
        $max_score += 2;
        if(is_int(strpos($contentlenght,$lang['general_good']))){
            $got_score++;
        }
        elseif(is_int(strpos($contentlenght,$lang['general_perfect']))){
            $got_score += 2;
        }
    }
    if($ct_words == 'true'){
        $max_score += 2;
        if(is_int(strpos($contentwords,$lang['general_good']))){
            $got_score++;
        }
        elseif(is_int(strpos($contentwords,$lang['general_perfect']))){
            $got_score += 2;
        }
    }
    if($ct_kwin == 'true'){
        $max_score++;
        if(!is_int(strpos($kwincontent,$lang['general_notpresent']))){
            $got_score++;
        } 
    }
    if($ct_rel == 'true'){
        $max_score += 2;
        if(is_int(strpos($contentrelevance,$lang['general_good']))){
            $got_score++;
        }
        elseif(is_int(strpos($contentrelevance,$lang['general_perfect']))){
            $got_score += 2;
        }
    }
    if($ct_kwini == 'true'){
        $max_score++;
        if(!is_int(strpos($msg_contentitalics,$lang['general_notpresent']))){
            $got_score++;
        } 
    }
    if($ct_kwinb == 'true'){
        $max_score++;
        if(!is_int(strpos($msg_contentbold,$lang['general_notpresent']))){
            $got_score++;
        } 
    }
    if($ct_iframes == 'true'){
        if(is_int(strpos($msg_contentframes,$lang['general_notpresent']))){
            $got_score++;
        } 
        $max_score++;
    }


    if($ul_kwin == 'true'){
        $max_score++;
        if(!is_int(strpos($msg_kwinurl,$lang['general_notpresent']))){
            $got_score++;
        } 
    }
    if($ul_length == 'true'){
        $max_score += 2;
        if(is_int(strpos($msg_urldomainlenght,$lang['general_good']))){
            $got_score++;
        }
        elseif(is_int(strpos($msg_urldomainlenght,$lang['general_perfect']))){
            $got_score += 2;
        }
    }
    if($ul_sub == 'true'){
        $max_score++;
        if(is_int(strpos($msg_urlsubdomain,$lang['general_notpresent']))){
            $got_score++;
        } 
    }


    if($l_ilinks == 'true'){
        $max_score += 2;
        if(is_int(strpos($msg_internalinks,$lang['general_good']))){
            $got_score++;
        }
        elseif(is_int(strpos($msg_internalinks,$lang['general_perfect']))){
            $got_score += 2;
        }
    }
    if($l_elinks == 'true'){
        $max_score += 2;
        if(is_int(strpos($msg_externalinks,$lang['general_good']))){
            $got_score++;
        }
        elseif(is_int(strpos($msg_externalinks,$lang['general_perfect']))){
            $got_score += 2;
        }
    }



    if($u_speed == 'true'){
        $max_score += 2;
        if(is_int(strpos($msg_speed,$lang['general_good']))){
            $got_score++;
        }
        elseif(is_int(strpos($msg_speed,$lang['general_perfect']))){
            $got_score += 2;
        }
    }
    if($u_gram == 'true'){
        $max_score += 2;
        if(is_int(strpos($msg_spelling,$lang['general_good']))){
            $got_score++;
        }
        elseif(is_int(strpos($msg_spelling,$lang['general_perfect']))){
            $got_score += 2;
        }
    }
    if($u_res == 'true'){
        $max_score++;
        if(!is_int(strpos($msg_responsive,$lang['genral_notresp']))){
            $got_score++;
        } 
    }
    if($u_fb == 'true'){
        $max_score++;
        if(!is_int(strpos($msg_feedback,$lang['general_notpresent']))){
            $got_score++;
        } 
    }

    $final_score = round(($got_score / $max_score) * 100 );

    #
    # End of Calculating points
    #

    //ending the timer

    $time = microtime();
    $time = explode(' ', $time);
    $time = $time[1] + $time[0];
    $finish = $time;
    $total_time = round(($finish - $start));