Example #1
0
 public function __construct()
 {
     parent::__construct('SettingsGeneral');
     $availableSeps = array(array('item' => '-'), array('item' => '—'), array('item' => '·'), array('item' => '•'), array('item' => '*'), array('item' => '⋆'), array('item' => '|'), array('item' => '~'), array('item' => '«'), array('item' => '»'), array('item' => '<'), array('item' => '>'));
     foreach ($availableSeps as &$sep) {
         $sep['selected'] = $sep['item'] === $this->options['titleseparator'];
     }
     $this->setTalData('availableSeps', $availableSeps);
     // Get posttypes
     $postTypes = get_post_types(array('public' => true), 'objects');
     foreach ($postTypes as &$postType) {
         // Unentitiy labels because default translations contain entities
         $postType->label = html_entity_decode($postType->label, ENT_QUOTES, "UTF-8");
     }
     // Get taxonomies
     $taxonomyTypes = get_taxonomies(array('public' => true), 'objects');
     foreach ($taxonomyTypes as &$taxonomy) {
         // Unentitiy labels because default translations contain entities
         $taxonomy->label = html_entity_decode($taxonomy->label, ENT_QUOTES, "UTF-8");
     }
     $translate = \NextBuzz\SEO\Translate\Translate::factory();
     $this->setTalData('siteIsMultilingual', $translate->siteIsMultilingual());
     $this->setTalData(array('postTypes' => $postTypes, 'taxonomyTypes' => $taxonomyTypes, 'additionalArchives' => array('author' => array('name' => 'author', 'label' => __("Author", "buzz-seo")), 'date' => array('name' => 'date', 'label' => __("Date", "buzz-seo"))), 'archiveTranslation' => __("archive", "buzz-seo")));
 }
Example #2
0
 /**
  * Render the xml output if requested.
  *
  * Note: currently priorities and change frequencies are added like this:
  * - frontpage:  1.0, daily
  * - homepage:   1.0, daily
  * - posts:      0.8, monthly
  * - pages:      0.8, monthly
  * - archives:   0.8, weekly
  * - taxonomies: 0.6, weekly (at least 10 posts)
  *               0.4, weekly (at least 3 posts)
  *               0.2, weekly (lower number of posts)
  * - author      0.8, weekly
  *
  * Note: the lastmod dates of the sitemapindex are not entirely correct for:
  * - taxonomies
  * - authors
  *
  * They simply get the latest timestamp which can be fixed at a later point in time.
  */
 public function checkRenderSitemap($query)
 {
     // If not the main query, we don't need to check if output is requested
     if (!$query->is_main_query()) {
         return;
     }
     // Detect if we are requesting a sitemap xml page
     $type = get_query_var('buzz_sitemap');
     if (empty($type)) {
         return;
     }
     // Set some headers
     if (!headers_sent()) {
         header($this->getHTTPProtocol() . ' 200 OK', true, 200);
         // Prevent indexing the sitemaps
         header('X-Robots-Tag: noindex, follow', true);
         header('Content-Type: text/xml');
     }
     // Get the page number
     $page = intval(get_query_var('buzz_sitemap_page'));
     if ($page === 0) {
         $page = 1;
     }
     // Get sitemap data and set some default options
     $options = get_option('_settingsSettingsXML', array('itemsperpage' => 250));
     $itemsperpage = $options['itemsperpage'];
     // Set xsl stylesheet
     $options['xslstylesheet'] = '<?xml-stylesheet type="text/xsl" href="' . plugins_url('/css/sitemap.xsl.php', dirname(dirname(__FILE__))) . '"?>';
     // Get default language
     $Translate = \NextBuzz\SEO\Translate\Translate::factory();
     $defaultLanguage = $Translate->getDefaultLanguage();
     $talData = array();
     $baseurl = home_url('/');
     if ($type === "1") {
         // Build the sitemapindex
         // Get all data
         if (isset($options['posttypes']) && is_array($options['posttypes'])) {
             foreach ($options['posttypes'] as $posttype => $value) {
                 // Get pagination count for post type (and just return ids, since we just want a count)
                 $numposts = count(get_posts(array('post_type' => $posttype, 'posts_per_page' => -1, 'cache_results' => false, 'fields' => 'ids', 'lang' => $defaultLanguage)));
                 $pages = ceil($numposts / $itemsperpage);
                 for ($p = 1; $p <= $pages; $p++) {
                     $talData[] = array('loc' => $baseurl . 'sitemap-' . $posttype . '-' . $p . '.xml', 'lastmod' => $this->getLastModifiedDate($posttype, $p, $itemsperpage), 'alternative' => false);
                 }
             }
         }
         if (isset($options['taxonomies']) && is_array($options['taxonomies'])) {
             foreach ($options['taxonomies'] as $taxonomy => $value) {
                 // Get taxonomies
                 $numposts = wp_count_terms($taxonomy, array('hide_empty' => true));
                 $pages = ceil($numposts / $itemsperpage);
                 for ($p = 1; $p <= $pages; $p++) {
                     $talData[] = array('loc' => $baseurl . 'sitemap-' . $taxonomy . '-' . $p . '.xml', 'lastmod' => $this->getLastModifiedDateTax($taxonomy, $p, $itemsperpage), 'alternative' => false);
                 }
             }
         }
         // Add author map
         if (isset($options['includeauthor']) && $options['includeauthor']) {
             $authors = get_users(array('who' => 'authors'));
             $users = wp_list_pluck($authors, 'ID');
             $latestUserStamp = max(wp_list_pluck($authors, 'user_registered'));
             $numusers = count($users);
             $pages = ceil($numusers / $itemsperpage);
             for ($p = 1; $p <= $pages; $p++) {
                 $talData[] = array('loc' => $baseurl . 'sitemap-author-' . $p . '.xml', 'lastmod' => \NextBuzz\SEO\Date\Timezone::dateFromTimestamp($latestUserStamp), 'alternative' => false);
             }
         }
         // Render
         \NextBuzz\SEO\PHPTAL\XML::factory('XMLSitemapIndex')->setTalData($options)->setTalData('sitemaps', $talData)->render();
     } else {
         if (isset($options['includeauthor']) && $options['includeauthor'] && $type === 'author') {
             // Build author map
             // Get all data
             $users = get_users(array('who' => 'authors'));
             $users = array_splice($users, ($page - 1) * $itemsperpage, $itemsperpage);
             foreach ($users as $user) {
                 $latestPost = get_posts(array('posts_per_page' => '1', 'author' => $user->ID, 'orderby' => 'modified', 'order' => 'DESC', 'lang' => $defaultLanguage));
                 $modified = is_array($latestPost) && isset($latestPost[0]) ? $latestPost[0]->post_modified_gmt : $user->user_registered;
                 $talData[] = array('loc' => get_author_posts_url($user->ID), 'lastmod' => \NextBuzz\SEO\Date\Timezone::dateFromTimestamp($modified), 'changefreq' => 'weekly', 'priority' => 0.8, 'alternative' => false);
             }
             // Render
             \NextBuzz\SEO\PHPTAL\XML::factory('XMLSitemap')->setTalData($options)->setTalData('urls', $talData)->render();
         } else {
             // Build the sitemap
             // Get all data
             $postTypes = get_post_types();
             if (in_array($type, $postTypes)) {
                 // Get post type posts
                 $posts = get_posts(array('post_type' => $type, 'posts_per_page' => $itemsperpage, 'paged' => $page, 'orderby' => 'modified', 'order' => 'DESC', 'lang' => function_exists('pll_default_language') ? pll_default_language() : ''));
                 $frontId = intval(get_option('page_on_front', -1));
                 $blogId = intval(get_option('page_for_posts', -1));
                 foreach ($posts as $post) {
                     // If polylang, get alternative languages if polylang
                     $alternatives = $Translate->getTranslatedPosts($post->ID);
                     foreach ($alternatives as &$alternative) {
                         $alternative = get_permalink($alternative);
                     }
                     $talData[] = array('loc' => get_permalink($post->ID), 'lastmod' => \NextBuzz\SEO\Date\Timezone::dateFromTimestamp($post->post_modified_gmt), 'changefreq' => $post->ID === $frontId || $post->ID === $blogId ? 'daily' : 'monthly', 'priority' => $post->ID === $frontId || $post->ID === $blogId ? 1.0 : 0.8, 'alternative' => $alternatives);
                 }
             } else {
                 // Get taxonomy posts
                 $terms = get_terms($type);
                 $terms = array_splice($terms, ($page - 1) * $itemsperpage, $itemsperpage);
                 foreach ($terms as $term) {
                     // If polylang, get alternative languages if polylang
                     $alternatives = $Translate->getTranslatedTerms($term->term_id);
                     foreach ($alternatives as &$alternative) {
                         $alternative = get_term_link($alternative);
                     }
                     $priority = 0.2;
                     if ($term->count >= 3) {
                         $priority = 0.4;
                     }
                     if ($term->count >= 10) {
                         $priority = 0.6;
                     }
                     $talData[] = array('loc' => get_term_link($term->term_id), 'lastmod' => $this->getLastModifiedDateTerm($type, $term->term_id), 'changefreq' => 'weekly', 'priority' => $priority, 'alternative' => $alternatives);
                 }
             }
             // Render
             \NextBuzz\SEO\PHPTAL\XML::factory('XMLSitemap')->setTalData($options)->setTalData('urls', $talData)->render();
         }
     }
     // Make sure WordPress does not output any footer content
     remove_all_actions('wp_footer');
     exit;
 }
Example #3
0
 /**
  * Update the title parts as set in the admin interface
  *
  * @param array $title
  * @return array
  */
 public function filterTitleParts($title)
 {
     $options = get_option('_settingsSettingsGeneral', true);
     if (!isset($options['showtitletagline']) && isset($title['tagline'])) {
         unset($title['tagline']);
     }
     if (!isset($options['showtitlepagination']) && isset($title['page'])) {
         unset($title['page']);
     }
     if (!isset($options['showtitlesitename']) && isset($title['site'])) {
         unset($title['site']);
     }
     // Update archive title if archive
     if (!is_singular()) {
         $translate = \NextBuzz\SEO\Translate\Translate::factory();
         if ($translate->siteIsMultilingual()) {
             foreach ($options['taxonomies'] as $cat => $items) {
                 foreach ($items as $key => $value) {
                     if (empty($value)) {
                         continue;
                     }
                     $options['taxonomies'][$cat][$key] = $translate->translate($value);
                     $options['taxonomies'][$cat][$key] = $translate->translate($value);
                 }
             }
             foreach ($options['archives'] as $cat => $items) {
                 foreach ($items as $key => $value) {
                     if (empty($value)) {
                         continue;
                     }
                     $options['archives'][$cat][$key] = $translate->translate($value);
                     $options['archives'][$cat][$key] = $translate->translate($value);
                 }
             }
             foreach ($options['posttypes'] as $cat => $items) {
                 foreach ($items as $key => $value) {
                     if (empty($value)) {
                         continue;
                     }
                     $options['posttypes'][$cat][$key] = $translate->translate($value);
                     $options['posttypes'][$cat][$key] = $translate->translate($value);
                 }
             }
         }
         if (is_category()) {
             $title['title'] = @trim($options['taxonomies']['category']['titleprefix'] . ' ' . $title['title'] . ' ' . $options['taxonomies']['category']['titlesuffix']);
         } else {
             if (is_tag()) {
                 $title['title'] = @trim($options['taxonomies']['post_tag']['titleprefix'] . ' ' . $title['title'] . ' ' . $options['taxonomies']['post_tag']['titlesuffix']);
             } else {
                 if (is_date()) {
                     $title['title'] = @trim($options['archives']['date']['titleprefix'] . ' ' . $title['title'] . ' ' . $options['archives']['date']['titlesuffix']);
                 } else {
                     if (is_author()) {
                         $title['title'] = @trim($options['archives']['author']['titleprefix'] . ' ' . $title['title'] . ' ' . $options['archives']['author']['titlesuffix']);
                     } else {
                         if (is_tax()) {
                             $tax = get_queried_object();
                             if (isset($options['taxonomies'][$tax->taxonomy])) {
                                 $title['title'] = @trim($options['taxonomies'][$tax->taxonomy]['titleprefix'] . ' ' . $title['title'] . ' ' . $options['taxonomies'][$tax->taxonomy]['titlesuffix']);
                             }
                         } else {
                             $posttype = get_post_type();
                             if (isset($options['posttypes'][$posttype])) {
                                 $title['title'] = @trim($options['posttypes'][$posttype]['titleprefix'] . ' ' . $title['title'] . ' ' . $options['posttypes'][$posttype]['titlesuffix']);
                             }
                         }
                     }
                 }
             }
         }
     }
     return $title;
 }