Beispiel #1
0
 public static function generateSitemapWithoutPing()
 {
     global $SITEURL;
     $filenames = getFiles(GSDATAPAGESPATH);
     if (count($filenames)) {
         foreach ($filenames as $file) {
             if (isFile($file, GSDATAPAGESPATH, 'xml')) {
                 $data = getXML(GSDATAPAGESPATH . $file);
                 if ($data->url != '404' && $data->private != 'Y') {
                     $pagesArray[] = array('url' => (string) $data->url, 'parent' => (string) $data->parent, 'date' => (string) $data->pubDate, 'menuStatus' => (string) $data->menuStatus);
                 }
             }
         }
     }
     $pagesSorted = subval_sort($pagesArray, 'menuStatus');
     $languages = return_i18n_available_languages();
     $deflang = return_i18n_default_language();
     $xml = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?><urlset></urlset>');
     $xml->addAttribute('xsi:schemaLocation', 'http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd', 'http://www.w3.org/2001/XMLSchema-instance');
     $xml->addAttribute('xmlns', 'http://www.sitemaps.org/schemas/sitemap/0.9');
     if (count($pagesSorted)) {
         foreach ($pagesSorted as $page) {
             // set <loc>
             if (count($languages) > 1) {
                 $pos = strrpos($page['url'], '_');
                 if ($pos !== false) {
                     $pageLoc = find_i18n_url(substr($page['url'], 0, $pos), $page['parent'], substr($page['url'], $pos + 1));
                 } else {
                     $pageLoc = find_i18n_url($page['url'], $page['parent'], $deflang);
                 }
             } else {
                 $pageLoc = find_i18n_url($page['url'], $page['parent']);
             }
             // set <lastmod>
             $pageLastMod = makeIso8601TimeStamp(date("Y-m-d H:i:s", strtotime($page['date'])));
             // set <changefreq>
             $pageChangeFreq = 'weekly';
             // set <priority>
             $pagePriority = $page['menuStatus'] == 'Y' ? '1.0' : '0.5';
             //add to sitemap
             $url_item = $xml->addChild('url');
             $url_item->addChild('loc', htmlspecialchars($pageLoc));
             $url_item->addChild('lastmod', $pageLastMod);
             $url_item->addChild('changefreq', $pageChangeFreq);
             $url_item->addChild('priority', $pagePriority);
         }
     }
     //create xml file
     $file = GSROOTPATH . 'sitemap.xml';
     XMLsave($xml, $file);
 }
Beispiel #2
0
function im_sitemap_include()
{
    global $page, $xml, $SITEURL;
    if (strval($page['url']) == ITEMPAGE) {
        $dir_handle = @opendir(ITEMSDATA);
        while ($filename = readdir($dir_handle)) {
            if (strrpos($filename, '.xml') === strlen($filename) - 4) {
                $data = getXML(ITEMSDATA . $filename);
                if ($data->visible == true) {
                    $url = $SITEURL . ITEMPAGE . "/?item=" . $data->slug;
                    $file = IMITEMPATH . "{$data->slug}.xml";
                    $date = makeIso8601TimeStamp(date("Y-m-d H:i:s", filemtime($file)));
                    $item = $xml->addChild('url');
                    $item->addChild('loc', $url);
                    $item->addChild('lastmod', $date);
                    $item->addChild('changefreq', 'monthly');
                    $item->addChild('priority', '0.5');
                }
            }
        }
    }
}
Beispiel #3
0
function makeUrlTag($url, $modifiedDateTime, $changeFrequency, $priority)
{
    global $newLine;
    global $indent;
    global $isoLastModifiedSite;
    $urlOpen = "{$indent}<url>{$newLine}";
    $urlValue = "";
    $urlClose = "{$indent}</url>{$newLine}";
    $locOpen = "{$indent}{$indent}<loc>";
    $locValue = "";
    $locClose = "</loc>{$newLine}";
    $lastmodOpen = "{$indent}{$indent}<lastmod>";
    $lastmodValue = "";
    $lastmodClose = "</lastmod>{$newLine}";
    $changefreqOpen = "{$indent}{$indent}<changefreq>";
    $changefreqValue = "";
    $changefreqClose = "</changefreq>{$newLine}";
    $priorityOpen = "{$indent}{$indent}<priority>";
    $priorityValue = "";
    $priorityClose = "</priority>{$newLine}";
    $urlTag = $urlOpen;
    $urlValue = $locOpen . makeUrlString("{$url}") . $locClose;
    if ($modifiedDateTime) {
        $urlValue .= $lastmodOpen . makeIso8601TimeStamp($modifiedDateTime) . $lastmodClose;
        if (!$isoLastModifiedSite) {
            // last modification of web site
            $isoLastModifiedSite = makeIso8601TimeStamp($modifiedDateTime);
        }
    }
    if ($changeFrequency) {
        $urlValue .= $changefreqOpen . $changeFrequency . $changefreqClose;
    }
    if ($priority) {
        $urlValue .= $priorityOpen . $priority . $priorityClose;
    }
    $urlTag .= $urlValue;
    $urlTag .= $urlClose;
    return $urlTag;
}
Beispiel #4
0
             $count++;
         }
     }
 }
 $pagesSorted = subval_sort($pagesArray, 'menuStatus');
 if (count($pagesSorted) != 0) {
     $xml = @new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?><urlset></urlset>');
     $xml->addAttribute('xsi:schemaLocation', 'http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd', 'http://www.w3.org/2001/XMLSchema-instance');
     $xml->addAttribute('xmlns', 'http://www.sitemaps.org/schemas/sitemap/0.9');
     foreach ($pagesSorted as $page) {
         if ($page['private'] != 'Y') {
             // set <loc>
             $pageLoc = find_url($page['url'], $page['parent']);
             // set <lastmod>
             $tmpDate = date("Y-m-d H:i:s", strtotime($page['date']));
             $pageLastMod = makeIso8601TimeStamp($tmpDate);
             // set <changefreq>
             $pageChangeFreq = 'weekly';
             // set <priority>
             if ($page['menuStatus'] == 'Y') {
                 $pagePriority = '1.0';
             } else {
                 $pagePriority = '0.5';
             }
             //add to sitemap
             $url_item = $xml->addChild('url');
             $url_item->addChild('loc', $pageLoc);
             $url_item->addChild('lastmod', $pageLastMod);
             $url_item->addChild('changefreq', $pageChangeFreq);
             $url_item->addChild('priority', $pagePriority);
             exec_action('sitemap-additem');
/**
 * Creates Sitemap
 *
 * Creates sitemap.xml in the site's root.
 * Pending: read the content path (xml's)
 */
function generate_sitemap()
{
    // Variable settings
    global $SITEURL;
    $path = GSDATAPAGESPATH;
    $count = "0";
    $filenames = getFiles($path);
    if (count($filenames) != 0) {
        foreach ($filenames as $file) {
            if (isFile($file, $path, 'xml')) {
                $data = getXML($path . $file);
                if ($data->url != '404') {
                    $status = $data->menuStatus;
                    $pagesArray[$count]['url'] = $data->url;
                    $pagesArray[$count]['parent'] = $data->parent;
                    $pagesArray[$count]['date'] = $data->pubDate;
                    $pagesArray[$count]['private'] = $data->private;
                    $pagesArray[$count]['menuStatus'] = $data->menuStatus;
                    $count++;
                }
            }
        }
    }
    $pagesSorted = subval_sort($pagesArray, 'menuStatus');
    if (count($pagesSorted) != 0) {
        $xml = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?><urlset></urlset>');
        $xml->addAttribute('xsi:schemaLocation', 'http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd', 'http://www.w3.org/2001/XMLSchema-instance');
        $xml->addAttribute('xmlns', 'http://www.sitemaps.org/schemas/sitemap/0.9');
        foreach ($pagesSorted as $page) {
            if ($page['private'] != 'Y') {
                // set <loc>
                $pageLoc = find_url($page['url'], $page['parent']);
                // set <lastmod>
                $tmpDate = date("Y-m-d H:i:s", strtotime($page['date']));
                $pageLastMod = makeIso8601TimeStamp($tmpDate);
                // set <changefreq>
                $pageChangeFreq = 'weekly';
                // set <priority>
                if ($page['menuStatus'] == 'Y') {
                    $pagePriority = '1.0';
                } else {
                    $pagePriority = '0.5';
                }
                //add to sitemap
                $url_item = $xml->addChild('url');
                $url_item->addChild('loc', $pageLoc);
                $url_item->addChild('lastmod', $pageLastMod);
                $url_item->addChild('changefreq', $pageChangeFreq);
                $url_item->addChild('priority', $pagePriority);
                exec_action('sitemap-additem');
            }
        }
        //create xml file
        $file = GSROOTPATH . 'sitemap.xml';
        exec_action('save-sitemap');
        XMLsave($xml, $file);
    }
    if (!defined('GSDONOTPING')) {
        if (file_exists(GSROOTPATH . 'sitemap.xml')) {
            if (200 === ($status = pingGoogleSitemaps($SITEURL . 'sitemap.xml'))) {
                #sitemap successfully created & pinged
                return true;
            } else {
                error_log(i18n_r('SITEMAP_ERRORPING'));
                return i18n_r('SITEMAP_ERRORPING');
            }
        } else {
            error_log(i18n_r('SITEMAP_ERROR'));
            return i18n_r('SITEMAP_ERROR');
        }
    } else {
        #sitemap successfully created - did not ping
        return true;
    }
}
/**
 * Creates Sitemap
 *
 * Creates GSSITEMAPFILE (sitemap.xml) in the site's root.
 */
function generate_sitemap()
{
    if (getDef('GSNOSITEMAP', true)) {
        return;
    }
    global $pagesArray;
    // Variable settings
    $SITEURL = getSiteURL(true);
    $path = GSDATAPAGESPATH;
    getPagesXmlValues(false);
    $pagesSorted = subval_sort($pagesArray, 'menuStatus');
    if (count($pagesSorted) > 0) {
        $xml = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?><urlset></urlset>');
        $xml->addAttribute('xsi:schemaLocation', 'http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd', 'http://www.w3.org/2001/XMLSchema-instance');
        $xml->addAttribute('xmlns', 'http://www.sitemaps.org/schemas/sitemap/0.9');
        foreach ($pagesSorted as $page) {
            if ($page['url'] != '404') {
                if ($page['private'] != 'Y') {
                    // set <loc>
                    $pageLoc = find_url($page['url'], $page['parent'], 'full');
                    // set <lastmod>
                    $tmpDate = date("Y-m-d H:i:s", strtotime($page['pubDate']));
                    $pageLastMod = makeIso8601TimeStamp($tmpDate);
                    // set <changefreq>
                    $pageChangeFreq = 'weekly';
                    // set <priority>
                    if ($page['menuStatus'] == 'Y') {
                        $pagePriority = '1.0';
                    } else {
                        $pagePriority = '0.5';
                    }
                    //add to sitemap
                    $url_item = $xml->addChild('url');
                    $url_item->addChild('loc', $pageLoc);
                    $url_item->addChild('lastmod', $pageLastMod);
                    $url_item->addChild('changefreq', $pageChangeFreq);
                    $url_item->addChild('priority', $pagePriority);
                }
            }
        }
        //create xml file
        $file = GSROOTPATH . GSSITEMAPFILE;
        $xml = exec_filter('sitemap', $xml);
        // @filter sitemap (obj) filter the sitemap $xml obj
        $status = XMLsave($xml, $file);
        exec_action('sitemap-aftersave');
        // @hook sitemap-aftersave after a sitemap data file was saved
        #sitemap successfully created
        return $status;
    } else {
        return true;
    }
}
Beispiel #7
0
function nm_update_sitemap_xml($xml)
{
    if (!defined('NMNOSITEMAP') || !NMNOSITEMAP) {
        $posts = nm_get_posts();
        $tags = array();
        $excludetags = defined('NMSITEMAPEXCLUDETAGS') && (NMSITEMAPEXCLUDETAGS === true || NMSITEMAPEXCLUDETAGS === 1);
        foreach ($posts as $post) {
            $url = nm_get_url('post') . $post->slug;
            $file = NMPOSTPATH . $post->slug . '.xml';
            $date = makeIso8601TimeStamp(date('Y-m-d H:i:s', strtotime($post->date)));
            $item = $xml->addChild('url');
            $item->addChild('loc', $url);
            $item->addChild('lastmod', $date);
            $item->addChild('changefreq', 'monthly');
            $item->addChild('priority', '0.5');
            if (!$excludetags && !empty($post->tags)) {
                foreach (explode(',', nm_lowercase_tags(strip_decode($post->tags))) as $tag) {
                    if (substr($tag, 0, 1) != '_') {
                        if (!in_array($tag, $tags)) {
                            $url = nm_get_url('tag') . rawurlencode($tag);
                            $item = $xml->addChild('url');
                            $item->addChild('loc', $url);
                            $item->addChild('lastmod', $date);
                            $item->addChild('changefreq', 'monthly');
                            $item->addChild('priority', '0.5');
                            $tags[] = $tag;
                        }
                    }
                }
            }
        }
    }
    return $xml;
}
function bm_sitemap_include()
{
    global $BMPAGEURL, $page, $xml;
    if (strval($page['url']) == $BMPAGEURL) {
        $books = bm_get_books();
        foreach ($books as $book) {
            $url = bm_get_url('book') . $book->slug;
            $file = BMBOOKPATH . "{$book->slug}.xml";
            $date = makeIso8601TimeStamp(date("Y-m-d H:i:s", filemtime($file)));
            $item = $xml->addChild('url');
            $item->addChild('loc', $url);
            $item->addChild('lastmod', $date);
            $item->addChild('changefreq', 'monthly');
            $item->addChild('priority', '0.5');
        }
    }
}