ping Google and Bing when sitemap changed
This commit is contained in:
parent
389a400443
commit
01f4415ac3
|
@ -4,7 +4,7 @@ class TCP {
|
||||||
|
|
||||||
public static function http($url, $method='GET', $verifySSL=true, $timeOut=10, $followRedirections=true, $binary=true, $headers=false)
|
public static function http($url, $method='GET', $verifySSL=true, $timeOut=10, $followRedirections=true, $binary=true, $headers=false)
|
||||||
{
|
{
|
||||||
if( function_exists('curl_version') ) {
|
if (function_exists('curl_version')) {
|
||||||
$ch = curl_init();
|
$ch = curl_init();
|
||||||
curl_setopt($ch, CURLOPT_URL, $url);
|
curl_setopt($ch, CURLOPT_URL, $url);
|
||||||
curl_setopt($ch, CURLOPT_HEADER, $headers);
|
curl_setopt($ch, CURLOPT_HEADER, $headers);
|
||||||
|
@ -14,16 +14,15 @@ class TCP {
|
||||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, $verifySSL);
|
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, $verifySSL);
|
||||||
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeOut);
|
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeOut);
|
||||||
curl_setopt($ch, CURLOPT_TIMEOUT, $timeOut);
|
curl_setopt($ch, CURLOPT_TIMEOUT, $timeOut);
|
||||||
if($method=='POST') {
|
if ($method=='POST') {
|
||||||
curl_setopt($ch, CURLOPT_POST, true);
|
curl_setopt($ch, CURLOPT_POST, true);
|
||||||
}
|
}
|
||||||
$output = curl_exec($ch);
|
$output = curl_exec($ch);
|
||||||
if($output===false) {
|
if ($output===false) {
|
||||||
Log::set('Curl error: '.curl_error($ch));
|
Log::set('Curl error: '.curl_error($ch));
|
||||||
}
|
}
|
||||||
curl_close($ch);
|
curl_close($ch);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
$options = array(
|
$options = array(
|
||||||
'http'=>array(
|
'http'=>array(
|
||||||
'method'=>$method,
|
'method'=>$method,
|
||||||
|
|
|
@ -108,23 +108,30 @@ class pluginRemoteContent extends Plugin {
|
||||||
// For each page inside the pages directory
|
// For each page inside the pages directory
|
||||||
// Parse the page and add to the database
|
// Parse the page and add to the database
|
||||||
if (Filesystem::directoryExists($root.DS.'pages')) {
|
if (Filesystem::directoryExists($root.DS.'pages')) {
|
||||||
$pageList = Filesystem::listDirectories($root.DS.'pages'.DS);
|
$parentList = Filesystem::listDirectories($root.DS.'pages'.DS);
|
||||||
foreach ($pageList as $directory) {
|
foreach ($parentList as $parentDirectory) {
|
||||||
if (Filesystem::fileExists($directory.DS.'index.md')) {
|
$parentKey = basename($parentDirectory);
|
||||||
// Parse the page from the file
|
if (Filesystem::fileExists($parentDirectory.DS.'index.md')) {
|
||||||
$row = $this->parsePage($directory.DS.'index.md');
|
$row = $this->parsePage($parentDirectory.DS.'index.md');
|
||||||
|
$row['slug'] = $parentKey;
|
||||||
// Add the page to the database
|
|
||||||
$pages->add($row);
|
$pages->add($row);
|
||||||
|
}
|
||||||
|
|
||||||
// Call the plugins after page created
|
$childList = Filesystem::listDirectories($parentDirectory.DS);
|
||||||
Theme::plugins('afterPageCreate');
|
foreach ($childList as $childDirectory) {
|
||||||
|
$childKey = basename($childDirectory);
|
||||||
// Reindex databases
|
if (Filesystem::fileExists($childDirectory.DS.'index.md')) {
|
||||||
reindexCategories();
|
$row = $this->parsePage($childDirectory.DS.'index.md');
|
||||||
reindextags();
|
$row['slug'] = $childKey;
|
||||||
|
$row['parent'] = $parentKey;
|
||||||
|
$pages->add($row);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Theme::plugins('afterPageCreate');
|
||||||
|
reindexCategories();
|
||||||
|
reindextags();
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -4,5 +4,7 @@
|
||||||
"name": "Sitemap",
|
"name": "Sitemap",
|
||||||
"description": "This plugin generates a sitemap.xml file, which provides the list of pages on your website, this helps search engines organize and filter content from their website."
|
"description": "This plugin generates a sitemap.xml file, which provides the list of pages on your website, this helps search engines organize and filter content from their website."
|
||||||
},
|
},
|
||||||
"sitemap-url": "Sitemap URL"
|
"sitemap-url": "Sitemap URL",
|
||||||
|
"notifies-google-when-you-created": "Notifies Google when you created, modified or deleted content from your site.",
|
||||||
|
"notifies-bing-when-you-created": "Notifies Bing when you created, modified or deleted content from your site."
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,10 @@ class pluginSitemap extends Plugin {
|
||||||
|
|
||||||
public function init()
|
public function init()
|
||||||
{
|
{
|
||||||
$this->formButtons = false;
|
$this->dbFields = array(
|
||||||
|
'pingGoogle'=>false,
|
||||||
|
'pingBing'=>false
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Method called on the settings of the plugin on the admin area
|
// Method called on the settings of the plugin on the admin area
|
||||||
|
@ -21,6 +24,24 @@ class pluginSitemap extends Plugin {
|
||||||
$html .= '<a href="'.Theme::sitemapUrl().'">'.Theme::sitemapUrl().'</a>';
|
$html .= '<a href="'.Theme::sitemapUrl().'">'.Theme::sitemapUrl().'</a>';
|
||||||
$html .= '</div>';
|
$html .= '</div>';
|
||||||
|
|
||||||
|
$html .= '<div>';
|
||||||
|
$html .= '<label>Ping Google</label>';
|
||||||
|
$html .= '<select name="pingGoogle">';
|
||||||
|
$html .= '<option value="true" '.($this->getValue('pingGoogle')===true?'selected':'').'>'.$L->get('Enabled').'</option>';
|
||||||
|
$html .= '<option value="false" '.($this->getValue('pingGoogle')===false?'selected':'').'>'.$L->get('Disabled').'</option>';
|
||||||
|
$html .= '</select>';
|
||||||
|
$html .= '<span class="tip">'.$L->get('notifies-google-when-you-created').'</span>';
|
||||||
|
$html .= '</div>';
|
||||||
|
|
||||||
|
$html .= '<div>';
|
||||||
|
$html .= '<label>Ping Bing</label>';
|
||||||
|
$html .= '<select name="pingBing">';
|
||||||
|
$html .= '<option value="true" '.($this->getValue('pingBing')===true?'selected':'').'>'.$L->get('Enabled').'</option>';
|
||||||
|
$html .= '<option value="false" '.($this->getValue('pingBing')===false?'selected':'').'>'.$L->get('Disabled').'</option>';
|
||||||
|
$html .= '</select>';
|
||||||
|
$html .= '<span class="tip">'.$L->get('notifies-bing-when-you-created').'</span>';
|
||||||
|
$html .= '</div>';
|
||||||
|
|
||||||
return $html;
|
return $html;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,7 +63,7 @@ class pluginSitemap extends Plugin {
|
||||||
$onlyPublished = true;
|
$onlyPublished = true;
|
||||||
$list = $pages->getList($pageNumber, $numberOfItems, $onlyPublished);
|
$list = $pages->getList($pageNumber, $numberOfItems, $onlyPublished);
|
||||||
|
|
||||||
foreach($list as $pageKey) {
|
foreach ($list as $pageKey) {
|
||||||
try {
|
try {
|
||||||
// Create the page object from the page key
|
// Create the page object from the page key
|
||||||
$page = new Page($pageKey);
|
$page = new Page($pageKey);
|
||||||
|
@ -65,6 +86,19 @@ class pluginSitemap extends Plugin {
|
||||||
return $doc->save($this->workspace().'sitemap.xml');
|
return $doc->save($this->workspace().'sitemap.xml');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function ping()
|
||||||
|
{
|
||||||
|
if ($this->getValue('pingGoogle')) {
|
||||||
|
$url = 'https://www.google.com/webmasters/sitemaps/ping?sitemap='.Theme::sitemapUrl();
|
||||||
|
TCP::http($url, 'GET', true, 3);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->getValue('pingBing')) {
|
||||||
|
$url = 'https://www.bing.com/webmaster/ping.aspx?sitemap='.Theme::sitemapUrl();
|
||||||
|
TCP::http($url, 'GET', true, 3);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public function install($position=0)
|
public function install($position=0)
|
||||||
{
|
{
|
||||||
parent::install($position);
|
parent::install($position);
|
||||||
|
@ -83,16 +117,19 @@ class pluginSitemap extends Plugin {
|
||||||
public function afterPageCreate()
|
public function afterPageCreate()
|
||||||
{
|
{
|
||||||
$this->createXML();
|
$this->createXML();
|
||||||
|
$this->ping();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function afterPageModify()
|
public function afterPageModify()
|
||||||
{
|
{
|
||||||
$this->createXML();
|
$this->createXML();
|
||||||
|
$this->ping();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function afterPageDelete()
|
public function afterPageDelete()
|
||||||
{
|
{
|
||||||
$this->createXML();
|
$this->createXML();
|
||||||
|
$this->ping();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function beforeAll()
|
public function beforeAll()
|
||||||
|
|
Loading…
Reference in New Issue