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)
|
||||
{
|
||||
if( function_exists('curl_version') ) {
|
||||
if (function_exists('curl_version')) {
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_URL, $url);
|
||||
curl_setopt($ch, CURLOPT_HEADER, $headers);
|
||||
@ -14,16 +14,15 @@ class TCP {
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, $verifySSL);
|
||||
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeOut);
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, $timeOut);
|
||||
if($method=='POST') {
|
||||
if ($method=='POST') {
|
||||
curl_setopt($ch, CURLOPT_POST, true);
|
||||
}
|
||||
$output = curl_exec($ch);
|
||||
if($output===false) {
|
||||
if ($output===false) {
|
||||
Log::set('Curl error: '.curl_error($ch));
|
||||
}
|
||||
curl_close($ch);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$options = array(
|
||||
'http'=>array(
|
||||
'method'=>$method,
|
||||
|
@ -108,23 +108,30 @@ class pluginRemoteContent extends Plugin {
|
||||
// For each page inside the pages directory
|
||||
// Parse the page and add to the database
|
||||
if (Filesystem::directoryExists($root.DS.'pages')) {
|
||||
$pageList = Filesystem::listDirectories($root.DS.'pages'.DS);
|
||||
foreach ($pageList as $directory) {
|
||||
if (Filesystem::fileExists($directory.DS.'index.md')) {
|
||||
// Parse the page from the file
|
||||
$row = $this->parsePage($directory.DS.'index.md');
|
||||
|
||||
// Add the page to the database
|
||||
$parentList = Filesystem::listDirectories($root.DS.'pages'.DS);
|
||||
foreach ($parentList as $parentDirectory) {
|
||||
$parentKey = basename($parentDirectory);
|
||||
if (Filesystem::fileExists($parentDirectory.DS.'index.md')) {
|
||||
$row = $this->parsePage($parentDirectory.DS.'index.md');
|
||||
$row['slug'] = $parentKey;
|
||||
$pages->add($row);
|
||||
}
|
||||
|
||||
// Call the plugins after page created
|
||||
Theme::plugins('afterPageCreate');
|
||||
|
||||
// Reindex databases
|
||||
reindexCategories();
|
||||
reindextags();
|
||||
$childList = Filesystem::listDirectories($parentDirectory.DS);
|
||||
foreach ($childList as $childDirectory) {
|
||||
$childKey = basename($childDirectory);
|
||||
if (Filesystem::fileExists($childDirectory.DS.'index.md')) {
|
||||
$row = $this->parsePage($childDirectory.DS.'index.md');
|
||||
$row['slug'] = $childKey;
|
||||
$row['parent'] = $parentKey;
|
||||
$pages->add($row);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Theme::plugins('afterPageCreate');
|
||||
reindexCategories();
|
||||
reindextags();
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -4,5 +4,7 @@
|
||||
"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."
|
||||
},
|
||||
"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()
|
||||
{
|
||||
$this->formButtons = false;
|
||||
$this->dbFields = array(
|
||||
'pingGoogle'=>false,
|
||||
'pingBing'=>false
|
||||
);
|
||||
}
|
||||
|
||||
// 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 .= '</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;
|
||||
}
|
||||
|
||||
@ -42,7 +63,7 @@ class pluginSitemap extends Plugin {
|
||||
$onlyPublished = true;
|
||||
$list = $pages->getList($pageNumber, $numberOfItems, $onlyPublished);
|
||||
|
||||
foreach($list as $pageKey) {
|
||||
foreach ($list as $pageKey) {
|
||||
try {
|
||||
// Create the page object from the page key
|
||||
$page = new Page($pageKey);
|
||||
@ -65,6 +86,19 @@ class pluginSitemap extends Plugin {
|
||||
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)
|
||||
{
|
||||
parent::install($position);
|
||||
@ -83,16 +117,19 @@ class pluginSitemap extends Plugin {
|
||||
public function afterPageCreate()
|
||||
{
|
||||
$this->createXML();
|
||||
$this->ping();
|
||||
}
|
||||
|
||||
public function afterPageModify()
|
||||
{
|
||||
$this->createXML();
|
||||
$this->ping();
|
||||
}
|
||||
|
||||
public function afterPageDelete()
|
||||
{
|
||||
$this->createXML();
|
||||
$this->ping();
|
||||
}
|
||||
|
||||
public function beforeAll()
|
||||
|
Loading…
Reference in New Issue
Block a user