dbFields = array( 'pingGoogle'=>false, 'pingBing'=>false ); } // Method called on the settings of the plugin on the admin area public function form() { global $L; $html = ''; $html .= '
'; $html .= ''; $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; } private function createXML() { global $site; global $pages; $xml = ''; $xml .= ''; $xml .= ''; $xml .= ''.$site->url().''; $xml .= ''; $published = $pages->getPublishedDB(); $statics = $pages->getStaticDB(); $list = array_merge($published, $statics); foreach ($list as $pageKey) { try { // Create the page object from the page key $page = new Page($pageKey); $xml .= ''; $xml .= ''.$page->permalink().''; $xml .= ''.$page->date(SITEMAP_DATE_FORMAT).''; $xml .= 'daily'; $xml .= ''; } catch (Exception $e) { // Continue } } $xml .= ''; // New DOM document $doc = new DOMDocument(); $doc->formatOutput = true; $doc->loadXML($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) { parent::install($position); return $this->createXML(); } public function post() { parent::post(); return $this->createXML(); } public function afterPageCreate() { $this->createXML(); $this->ping(); } public function afterPageModify() { $this->createXML(); $this->ping(); } public function afterPageDelete() { $this->createXML(); $this->ping(); } public function beforeAll() { $webhook = 'sitemap.xml'; if( $this->webhook($webhook) ) { // Send XML header header('Content-type: text/xml'); $doc = new DOMDocument(); // Workaround for a bug https://bugs.php.net/bug.php?id=62577 libxml_disable_entity_loader(false); // Load XML $doc->load($this->workspace().'sitemap.xml'); libxml_disable_entity_loader(true); // Print the XML echo $doc->saveXML(); // Terminate the run successfully exit(0); } } }