<?php

class scrapes
{	 	
	private $Go_Curl;

    public function __construct()
    {
        $this->Go_Curl = new Go_Curl();
    }
	
	public function scrape_web_info($sources) {	
		require_once get_template_directory().'/libs/addons/inc/ssl.php';
		
		@ini_set('user_agent', 'Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)');

		 
		global $opt_themes;
		 
		
		$url		= $_POST['wp_url'];		
		$arr		= array();
		
		//$links	= file_get_contents($url, false, stream_context_create($ssl)); 
		//$links	= $this->Go_Curl->geturl("${url}");	
		//$links	= scrape_site($url);	 
		$html		= file_get_contents($url);	 
		
		$arr['id_ps']		= $this->Go_Curl->match('/<link rel="alternate" href="(.*?)" hreflang="x-default">/ms', $html, 1);
		$arr['id_ps']		= $this->Go_Curl->validate_gplay_id($arr['id_ps']);

		$arr['title_id']	= $arr['id_ps'];
		$arr['title_id_2']	= $arr['id_ps'];
 		
		
        $gp_id 				= !empty($arr['id_ps']) ? $arr['id_ps'] : ($arr['title_id'] ?? $arr['title_id_2'] ?? '');
		
		$titleId 			= $gp_id; 
		$arr['GP_ID'] 		= $titleId; 
  
		if ( empty($titleId)) {
			$arr['error']			= NO_ID_PS;
			echo $arr['error'];
		} 
		
		if ( !empty($titleId) ) { 			
			require_once get_template_directory().'/libs/addons/includes/playstore.php';
		}
		
        return $arr;
	} 
 
 
} 