<?php if (! defined('BASEPATH')) {
exit('No direct script access allowed');
}
class Indexing extends CI_Model
{
public function __construct()
{
parent::__construct();
}
public function AddUrl($url)
{
require APPPATH . 'libraries/google/vendor/autoload.php';
$client = new Google_Client();
$client->setAuthConfig(APPPATH . 'xxxxxxxxxxxxxxxxx.json');
$client->addScope('https://www.googleapis.com/auth/indexing');
$httpClient = $client->authorize();
$endpoint = 'https://indexing.googleapis.com/v3/urlNotifications:publish';
$content = '{
"url": "' . $url . '",
"type": "URL_UPDATED"
}';
$response = $httpClient->post($endpoint, [ 'body' => $content ]);
$status_code = $response->getStatusCode();
return $status_code;
}
public function DelUrl($url)
{
require APPPATH . 'libraries/google/vendor/autoload.php';
$client = new Google_Client();
$client->setAuthConfig(APPPATH . 'xxxxxxxxxxxxxxxxx.json');
$client->addScope('https://www.googleapis.com/auth/indexing');
$httpClient = $client->authorize();
$endpoint = 'https://indexing.googleapis.com/v3/urlNotifications:publish';
$content = '{
"url": "' . $url . '",
"type": "URL_DELETED"
}';
$response = $httpClient->post($endpoint, [ 'body' => $content ]);
$status_code = $response->getStatusCode();
return $status_code;
}
public function StatusUrl($url)
{
require APPPATH . 'libraries/google/vendor/autoload.php';
$client = new Google_Client();
$client->setAuthConfig(APPPATH . 'xxxxxxxxxxxxxxxxx.json');
$client->addScope('https://www.googleapis.com/auth/indexing');
$httpClient = $client->authorize();
$endpoint = 'https://indexing.googleapis.com/v3/urlNotifications/metadata?url=' . $url;
$response = $httpClient->get($endpoint);
$status_code = $response->getStatusCode();
return $status_code;
}
}