diff --git a/bl-kernel/helpers/tcp.class.php b/bl-kernel/helpers/tcp.class.php index 3278417d..47c30952 100644 --- a/bl-kernel/helpers/tcp.class.php +++ b/bl-kernel/helpers/tcp.class.php @@ -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, diff --git a/bl-plugins/remote-content/plugin.php b/bl-plugins/remote-content/plugin.php index 5f07d647..2b866117 100644 --- a/bl-plugins/remote-content/plugin.php +++ b/bl-plugins/remote-content/plugin.php @@ -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; diff --git a/bl-plugins/sitemap/languages/en.json b/bl-plugins/sitemap/languages/en.json index bb99c485..56af2a7c 100644 --- a/bl-plugins/sitemap/languages/en.json +++ b/bl-plugins/sitemap/languages/en.json @@ -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." } diff --git a/bl-plugins/sitemap/plugin.php b/bl-plugins/sitemap/plugin.php index 05daeb5b..988df30a 100644 --- a/bl-plugins/sitemap/plugin.php +++ b/bl-plugins/sitemap/plugin.php @@ -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 .= ''.Theme::sitemapUrl().''; $html .= ''; + $html .= '
'; + $html .= ''; + $html .= ''; + $html .= ''.$L->get('notifies-google-when-you-created').''; + $html .= '
'; + + $html .= '
'; + $html .= ''; + $html .= ''; + $html .= ''.$L->get('notifies-bing-when-you-created').''; + $html .= '
'; + 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()