<?php



namespace App\Console\Commands;



use App\Models\Category;

use App\Models\News;

use App\Models\AgencyBotCategory;

use Illuminate\Console\Command;

use Illuminate\Support\Str;

use App\Models\Setting;



class GetWpBot extends Command

{


    protected $signature = 'command:getwpbot';


    protected $description = 'İha AJans Haber Verilerini Burada Çekiyoruz';



    public function __construct()

    {

        parent::__construct();

    }



    public function handle()

    {

        $curl = curl_init();

        curl_setopt_array($curl, array(
          CURLOPT_URL => 'https://kocaeliduysun.net/wp-admin/admin-ajax.php',
          CURLOPT_RETURNTRANSFER => true,
          CURLOPT_ENCODING => '',
          CURLOPT_MAXREDIRS => 10,
          CURLOPT_TIMEOUT => 0,
          CURLOPT_FOLLOWLOCATION => true,
          CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
          CURLOPT_CUSTOMREQUEST => 'POST',
          CURLOPT_POSTFIELDS => array('page' => '0','count' => '1376','action' => 'sunset_load_moreNews','cat' => '2','offset' => '0'),
          CURLOPT_HTTPHEADER => array(
            'Cookie: accessed=yes; accessed2=yes'
          ),
        ));

        $response = curl_exec($curl);

        curl_close($curl);

        $tekhaber=explode('<div data-page="1">',$response);
        $tekhaber=explode('</div>',$tekhaber[1]);

        $haberlink=explode('href="',$tekhaber[0]);
        $haberlink=explode('"',$haberlink[1]);

        $haberresim=explode('src="',$tekhaber[0]);
        $haberresim=explode('"',$haberresim[1]);

        $haberisim=explode('alt="',$tekhaber[0]);
        $haberisim=explode('"',$haberisim[1]);

        $haberic=file_get_contents($haberlink[0]);

        $haberresim=explode('<meta property="og:image" content="',$haberic);
        $haberresim=explode('"',$haberresim[1]);

        $kisaaciklama=explode('<meta name="description" content="', $haberic);
        $kisaaciklama=explode('"',$kisaaciklama[1]);

        $date=explode('<meta property="article:published_time" content="',$haberic);
        $date=explode('"',$date[1]);


        $haberdetay=explode('$("#newsRead .bottom .left .detail p").css("font-size", currentFont);',$haberic);
        $haberdetay=explode('</div>',$haberdetay[1]);

        $haberdetay[0]=str_replace('});', '', $haberdetay[0]);
        $haberdetay[0]=str_replace('</script>', '', $haberdetay[0]);

        echo $haberdetay[0];





        return Command::SUCCESS;

    }

}

