/** * Get the XML representation of the sitemap item. * * @return The XML representation. */ public function toXML() { $result = ' <url>' . NL . ' <loc>' . hsc($this->url) . '</loc>' . NL . ' <lastmod>' . date_iso8601($this->lastmod) . '</lastmod>' . NL; if ($this->changefreq !== NULL) { $result .= ' <changefreq>' . hsc($this->changefreq) . '</changefreq>' . NL; } if ($this->priority !== NULL) { $result .= ' <priority>' . hsc($this->priority) . '</priority>' . NL; } $result .= ' </url>' . NL; return $result; }
/** * Simple reporter log and display information about the queue. * * @param int $worker * Worker number. * @param object $item * The $item which was stored in the cron queue. */ protected function reportWork($worker, $item) { if ($this->state->get('cron_example_show_status_message')) { drupal_set_message($this->t('Queue @worker worker processed item with sequence @sequence created at @time', ['@worker' => $worker, '@sequence' => $item->sequence, '@time' => date_iso8601($item->created)])); } $this->logger->get('cron_example')->info('Queue @worker worker processed item with sequence @sequence created at @time', ['@worker' => $worker, '@sequence' => $item->sequence, '@time' => date_iso8601($item->created)]); }
/** * {@inheritdoc} */ public function buildForm(array $form, FormStateInterface $form_state) { $config = $this->configFactory->get('examples.cron'); $form['status'] = ['#type' => 'details', '#title' => $this->t('Cron status information'), '#open' => TRUE]; $form['status']['intro'] = ['#type' => 'item', '#markup' => $this->t('The cron example demonstrates hook_cron() and hook_queue_info() processing. If you have administrative privileges you can run cron from this page and see the results.')]; $next_execution = $config->get('next_execution'); $next_execution = !empty($next_execution) ? $next_execution : REQUEST_TIME; $args = ['%time' => date_iso8601($config->get('next_execution')), '%seconds' => $next_execution - REQUEST_TIME]; $form['status']['last'] = ['#type' => 'item', '#markup' => $this->t('cron_example_cron() will next execute the first time cron runs after %time (%seconds seconds from now)', $args)]; if ($this->currentUser->hasPermission('administer site configuration')) { $form['cron_run'] = ['#type' => 'details', '#title' => $this->t('Run cron manually'), '#open' => TRUE]; $form['cron_run']['cron_reset'] = ['#type' => 'checkbox', '#title' => $this->t('Run cron_example\'s cron regardless of whether interval has expired.'), '#default_value' => FALSE]; $form['cron_run']['cron_trigger']['actions'] = ['#type' => 'actions']; $form['cron_run']['cron_trigger']['actions']['sumbit'] = ['#type' => 'submit', '#value' => $this->t('Run cron now'), '#submit' => [[$this, 'cronRun']]]; } $form['cron_queue_setup'] = ['#type' => 'details', '#title' => $this->t('Cron queue setup (for hook_cron_queue_info(), etc.)'), '#open' => TRUE]; $queue_1 = $this->queue->get('cron_example_queue_1'); $queue_2 = $this->queue->get('cron_example_queue_2'); $args = ['%queue_1' => $queue_1->numberOfItems(), '%queue_2' => $queue_2->numberOfItems()]; $form['cron_queue_setup']['current_cron_queue_status'] = ['#type' => 'item', '#markup' => $this->t('There are currently %queue_1 items in queue 1 and %queue_2 items in queue 2', $args)]; $form['cron_queue_setup']['num_items'] = ['#type' => 'select', '#title' => $this->t('Number of items to add to queue'), '#options' => array_combine([1, 5, 10, 100, 1000], [1, 5, 10, 100, 1000]), '#default_value' => 5]; $form['cron_queue_setup']['queue'] = ['#type' => 'radios', '#title' => $this->t('Queue to add items to'), '#options' => ['cron_example_queue_1' => $this->t('Queue 1'), 'cron_example_queue_2' => $this->t('Queue 2')], '#default_value' => 'cron_example_queue_1']; $form['cron_queue_setup']['actions'] = ['#type' => 'actions']; $form['cron_queue_setup']['actions']['submit'] = ['#type' => 'submit', '#value' => $this->t('Add jobs to queue'), '#submit' => [[$this, 'addItems']]]; $form['configuration'] = ['#type' => 'details', '#title' => $this->t('Configuration of cron_example_cron()'), '#open' => TRUE]; $form['configuration']['cron_example_interval'] = ['#type' => 'select', '#title' => $this->t('Cron interval'), '#description' => $this->t('Time after which cron_example_cron will respond to a processing request.'), '#default_value' => $config->get('interval'), '#options' => [60 => $this->t('1 minute'), 300 => $this->t('5 minutes'), 3600 => $this->t('1 hour'), 86400 => $this->t('1 day')]]; return parent::buildForm($form, $form_state); }
/** * {@inheritdoc} */ public function get_entity_paths($entity_type, $bundles) { $i = 0; foreach ($bundles as $bundle => $bundle_settings) { if (!$bundle_settings['index']) { continue; } foreach ($this->get_entity_bundle_paths($bundle) as $id => $path) { $this->entity_paths[$i]['path'] = $path['path']; $this->entity_paths[$i]['priority'] = !empty($path['priority']) ? $path['priority'] : $bundle_settings['priority']; $this->entity_paths[$i]['lastmod'] = !empty($path['lastmod']) ? date_iso8601($path['lastmod']) : NULL; $i++; } } return $this->entity_paths; }
/** * Generates and returns the sitemap index for all sitemap chunks. * * @param array $chunks * All sitemap chunks keyed by the chunk ID. * * @return string sitemap index */ public function generateSitemapIndex($chunks) { $writer = new XMLWriter(); $writer->openMemory(); $writer->setIndent(TRUE); $writer->startDocument(self::XML_VERSION, self::ENCODING); $writer->writeComment(self::GENERATED_BY); $writer->startElement('sitemapindex'); $writer->writeAttribute('xmlns', self::XMLNS); foreach ($chunks as $chunk_id => $chunk_data) { $writer->startElement('sitemap'); $writer->writeElement('loc', $GLOBALS['base_url'] . '/sitemaps/' . $chunk_id . '/' . 'sitemap.xml'); $writer->writeElement('lastmod', date_iso8601($chunk_data->sitemap_created)); $writer->endElement(); } $writer->endElement(); $writer->endDocument(); return $writer->outputMemory(); }
/** * Builds a Google Sitemap of all public pages known to the indexer * * The map is placed in the root directory named sitemap.xml.gz - This * file needs to be writable! * * @author Andreas Gohr * @link https://www.google.com/webmasters/sitemaps/docs/en/about.html */ function runSitemapper() { global $conf; print "runSitemapper(): started" . NL; if (!$conf['sitemap']) { return false; } if ($conf['compression'] == 'bz2' || $conf['compression'] == 'gz') { $sitemap = 'sitemap.xml.gz'; } else { $sitemap = 'sitemap.xml'; } print "runSitemapper(): using {$sitemap}" . NL; if (@file_exists(DOKU_INC . $sitemap)) { if (!is_writable(DOKU_INC . $sitemap)) { return false; } } else { if (!is_writable(DOKU_INC)) { return false; } } if (@filesize(DOKU_INC . $sitemap) && @filemtime(DOKU_INC . $sitemap) > time() - $conf['sitemap'] * 60 * 60 * 24) { print 'runSitemapper(): Sitemap up to date' . NL; return false; } $pages = file($conf['indexdir'] . '/page.idx'); print 'runSitemapper(): creating sitemap using ' . count($pages) . ' pages' . NL; // build the sitemap ob_start(); print '<?xml version="1.0" encoding="UTF-8"?>' . NL; print '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">' . NL; foreach ($pages as $id) { $id = trim($id); $file = wikiFN($id); //skip hidden, non existing and restricted files if (isHiddenPage($id)) { continue; } $date = @filemtime($file); if (!$date) { continue; } if (auth_aclcheck($id, '', '') < AUTH_READ) { continue; } print ' <url>' . NL; print ' <loc>' . wl($id, '', true) . '</loc>' . NL; print ' <lastmod>' . date_iso8601($date) . '</lastmod>' . NL; print ' </url>' . NL; } print '</urlset>' . NL; $data = ob_get_contents(); ob_end_clean(); //save the new sitemap io_saveFile(DOKU_INC . $sitemap, $data); //ping search engines... $http = new DokuHTTPClient(); $http->timeout = 8; //ping google print 'runSitemapper(): pinging google' . NL; $url = 'http://www.google.com/webmasters/sitemaps/ping?sitemap='; $url .= urlencode(DOKU_URL . $sitemap); $resp = $http->get($url); if ($http->error) { print 'runSitemapper(): ' . $http->error . NL; } print 'runSitemapper(): ' . preg_replace('/[\\n\\r]/', ' ', strip_tags($resp)) . NL; //ping yahoo print 'runSitemapper(): pinging yahoo' . NL; $url = 'http://search.yahooapis.com/SiteExplorerService/V1/updateNotification?appid=dokuwiki&url='; $url .= urlencode(DOKU_URL . $sitemap); $resp = $http->get($url); if ($http->error) { print 'runSitemapper(): ' . $http->error . NL; } print 'runSitemapper(): ' . preg_replace('/[\\n\\r]/', ' ', strip_tags($resp)) . NL; //ping microsoft print 'runSitemapper(): pinging microsoft' . NL; $url = 'http://www.bing.com/webmaster/ping.aspx?siteMap='; $url .= urlencode(DOKU_URL . $sitemap); $resp = $http->get($url); if ($http->error) { print 'runSitemapper(): ' . $http->error . NL; } print 'runSitemapper(): ' . preg_replace('/[\\n\\r]/', ' ', strip_tags($resp)) . NL; print 'runSitemapper(): finished' . NL; return true; }
/** * Tests output for comment properties on nodes in full page view mode. * * @param \EasyRdf_Graph $graph * The EasyRDF graph object. */ protected function assertRdfaNodeCommentProperties($graph) { // Relationship between node and comment. $expected_value = array('type' => 'uri', 'value' => $this->articleCommentUri); $this->assertTrue($graph->hasProperty($this->articleUri, 'http://schema.org/comment', $expected_value), 'Relationship between node and comment found (schema:comment).'); // Comment type. $this->assertEqual($graph->type($this->articleCommentUri), 'schema:Comment', 'Comment type was found (schema:Comment).'); // Comment title. $expected_value = array('type' => 'literal', 'value' => $this->articleComment->get('subject')->value, 'lang' => 'en'); $this->assertTrue($graph->hasProperty($this->articleCommentUri, 'http://schema.org/name', $expected_value), 'Article comment title was found (schema:name).'); // Comment created date. $expected_value = array('type' => 'literal', 'value' => date_iso8601($this->articleComment->get('created')->value), 'lang' => 'en'); $this->assertTrue($graph->hasProperty($this->articleCommentUri, 'http://schema.org/dateCreated', $expected_value), 'Article comment created date was found (schema:dateCreated).'); // Comment body. $text = $this->articleComment->get('comment_body')->value; $expected_value = array('type' => 'literal', 'value' => "{$text}\n", 'lang' => 'en'); $this->assertTrue($graph->hasProperty($this->articleCommentUri, 'http://schema.org/text', $expected_value), 'Article comment body was found (schema:text).'); // Comment uid. $expected_value = array('type' => 'uri', 'value' => $this->commenterUri); $this->assertTrue($graph->hasProperty($this->articleCommentUri, 'http://schema.org/author', $expected_value), 'Article comment author was found (schema:author).'); // Comment author type. $this->assertEqual($graph->type($this->commenterUri), 'schema:Person', 'Comment author type was found (schema:Person).'); // Comment author name. $expected_value = array('type' => 'literal', 'value' => $this->webUser->getUsername()); $this->assertTrue($graph->hasProperty($this->commenterUri, 'http://schema.org/name', $expected_value), 'Comment author name was found (schema:name).'); }
/** * Batch function which generates urls to custom paths. * * @param array $custom_paths * @param array $batch_info * @param array &$context * * @see https://api.drupal.org/api/drupal/core!includes!form.inc/group/batch/8 */ public static function generateCustomUrls($custom_paths, $batch_info, &$context) { $languages = \Drupal::languageManager()->getLanguages(); $anon_user = User::load(self::ANONYMOUS_USER_ID); // Initialize batch if not done yet. if (self::needsInitialization($context)) { self::initializeBatch($batch_info, count($custom_paths), $context); } foreach ($custom_paths as $i => $custom_path) { if (self::isBatch($batch_info)) { self::setCurrentId($i, $context); } if (!\Drupal::service('path.validator')->isValid($custom_path['path'])) { //todo: Change to different function, as this also checks if current user has access. The user however varies depending if process was started from the web interface or via cron/drush. self::registerError(self::PATH_DOES_NOT_EXIST_OR_NO_ACCESS, ['@path' => $custom_path['path']], 'warning'); continue; } $url_object = Url::fromUserInput($custom_path['path'], ['absolute' => TRUE]); if (!$url_object->access($anon_user)) { continue; } $path = $url_object->getInternalPath(); if ($batch_info['remove_duplicates'] && self::pathProcessed($path, $context)) { continue; } // Load entity object if this is an entity route. $route_parameters = $url_object->getRouteParameters(); $entity = !empty($route_parameters) ? \Drupal::entityTypeManager()->getStorage(key($route_parameters))->load($route_parameters[key($route_parameters)]) : NULL; $path_data = ['path' => $path, 'lastmod' => method_exists($entity, 'getChangedTime') ? date_iso8601($entity->getChangedTime()) : NULL, 'priority' => isset($custom_path['priority']) ? $custom_path['priority'] : NULL]; if (!is_null($entity)) { $path_data['entity_info'] = ['entity_type' => $entity->getEntityTypeId(), 'id' => $entity->id()]; } $alternate_urls = []; foreach ($languages as $language) { $langcode = $language->getId(); if (!$batch_info['skip_untranslated'] || is_null($entity) || $entity->hasTranslation($langcode) || $language->isDefault()) { $url_object->setOption('language', $language); $alternate_urls[$langcode] = $url_object->toString(); } } foreach ($alternate_urls as $langcode => $url) { $context['results']['generate'][] = $path_data + ['langcode' => $langcode, 'url' => $url, 'alternate_urls' => $alternate_urls]; } } if (self::isBatch($batch_info)) { self::setProgressInfo($context); } self::processSegment($context, $batch_info); }
/** * Converts a date entity field array into an ISO 8601 timestamp string. * * @param array $data * The array containing the 'value' element. * * @return string * Returns the ISO 8601 timestamp. */ public static function dateIso8601Value($data) { return date_iso8601($data['value']); }