GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — 2.9 ( 9a1a51...6c05fc )
by Thorsten
14:18
created

sitemap.xml.php ➔ buildSitemapNode()   A

Complexity

Conditions 4
Paths 8

Size

Total Lines 18
Code Lines 13

Duplication

Lines 0
Ratio 0 %
Metric Value
cc 4
eloc 13
nc 8
nop 4
dl 0
loc 18
rs 9.2
1
<?php
2
3
/**
4
 * The dynamic Google Sitemap builder.
5
 *
6
 * http://[...]/sitemap.xml.php
7
 * http://[...]/sitemap.xml.php?gz=1
8
 * http://[...]/sitemap.xml
9
 * http://[...]/sitemap.gz
10
 * http://[...]/sitemap.xml.gz
11
 *
12
 * The Google Sitemap protocol is described here:
13
 * http://www.google.com/webmasters/sitemaps/docs/en/protocol.html
14
 *
15
 * PHP Version 5.5
16
 *
17
 * This Source Code Form is subject to the terms of the Mozilla Public License,
18
 * v. 2.0. If a copy of the MPL was not distributed with this file, You can
19
 * obtain one at http://mozilla.org/MPL/2.0/.
20
 *
21
 * @category  phpMyFAQ
22
 *
23
 * @author    Matteo Scaramuccia <[email protected]>
24
 * @copyright 2006-2016 phpMyFAQ Team
25
 * @license   http://www.mozilla.org/MPL/2.0/ Mozilla Public License Version 2.0
26
 *
27
 * @link      http://www.phpmyfaq.de
28
 * @since     2006-06-26
29
 */
30
define('PMF_SITEMAP_GOOGLE_CHANGEFREQ_ALWAYS', 'always');
31
define('PMF_SITEMAP_GOOGLE_CHANGEFREQ_HOURLY', 'hourly');
32
define('PMF_SITEMAP_GOOGLE_CHANGEFREQ_DAILY', 'daily');
33
define('PMF_SITEMAP_GOOGLE_CHANGEFREQ_WEEKLY', 'weekly');
34
define('PMF_SITEMAP_GOOGLE_CHANGEFREQ_MONTHLY', 'monthly');
35
define('PMF_SITEMAP_GOOGLE_CHANGEFREQ_YEARLY', 'yearly');
36
define('PMF_SITEMAP_GOOGLE_CHANGEFREQ_NEVER', 'never');
37
define('PMF_SITEMAP_GOOGLE_MAX_URL_LENGTH', 2048);
38
define('PMF_SITEMAP_GOOGLE_MAX_URLS', 50000);
39
define('PMF_SITEMAP_GOOGLE_MAX_FILE_LENGTH', 10485760); // 10MB
40
define('PMF_SITEMAP_GOOGLE_PRIORITY_MIN', '0.0');
41
define('PMF_SITEMAP_GOOGLE_PRIORITY_MAX', '1.0');
42
define('PMF_SITEMAP_GOOGLE_PRIORITY_DEFAULT', '0.5');
43
44
define('PMF_SITEMAP_GOOGLE_GET_GZIP', 'gz');
45
define('PMF_SITEMAP_GOOGLE_GET_INDEX', 'idx');
46
define('PMF_SITEMAP_GOOGLE_FILENAME', 'sitemap.xml');
47
define('PMF_SITEMAP_GOOGLE_FILENAME_GZ', 'sitemap.xml.gz');
48
define('PMF_SITEMAP_GOOGLE_INDEX_FILENAME', 'sitemap_index.xml');
49
50
define('PMF_ROOT_DIR', __DIR__);
51
define('IS_VALID_PHPMYFAQ', null);
52
53
//
54
// Bootstrapping
55
//
56
require 'inc/Bootstrap.php';
57
58
//
59
// Initalizing static string wrapper
60
//
61
PMF_String::init('en');
62
63
// {{{ Functions
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
64
function buildSitemapNode($location, $lastmod = null, $changeFreq = null, $priority = null)
65
{
66
    if (!isset($lastmod)) {
67
        $lastmod = PMF_Date::createIsoDate($_SERVER['REQUEST_TIME'], DATE_W3C, false);
68
    }
69
    if (!isset($changeFreq)) {
70
        $changeFreq = PMF_SITEMAP_GOOGLE_CHANGEFREQ_DAILY;
71
    }
72
    $node =
73
         '<url>'
74
        .'<loc>'.PMF_String::htmlspecialchars($location).'</loc>'
75
        .'<lastmod>'.$lastmod.'</lastmod>'
76
        .'<changefreq>'.$changeFreq.'</changefreq>'
77
        .(isset($priority) ? '<priority>'.$priority.'</priority>' : '')
78
        .'</url>';
79
80
    return $node;
81
}
82
83
//
84
// Future improvements
85
// WHEN a User PMF Sitemap will be:
86
//   a. bigger than 10MB (!)
87
//   b. w/ more than 50K URLs (!)
88
// we'll manage this issue using a Sitemap Index Files produced by this PHP code
89
// including Sitemap URLs always produced by this same PHP code (see PMF_SITEMAP_GOOGLE_GET_INDEX)
90
//
91
92
$oFaq = new PMF_Faq($faqConfig);
93
// Load the faq
94
$items = $oFaq->getTopTenData(PMF_SITEMAP_GOOGLE_MAX_URLS - 1);
95
$visitsMax = 0;
96
$visitMin = 0;
97
if (count($items) > 0) {
98
    $visitsMax = $items[0]['visits'];
99
    $visitMin = $items[count($items) - 1]['visits'];
100
}
101
102
// Sitemap header
103
$sitemap =
104
     '<?xml version="1.0" encoding="UTF-8"?>'
105
    .'<urlset xmlns="http://www.google.com/schemas/sitemap/0.84"'
106
    .' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"'
107
    .' xsi:schemaLocation="http://www.google.com/schemas/sitemap/0.84'
108
    .' http://www.google.com/schemas/sitemap/0.84/sitemap.xsd">';
109
// 1st entry: the faq server itself
110
$sitemap .= buildSitemapNode(
111
    $faqConfig->getDefaultUrl(),
112
    PMF_Date::createIsoDate($_SERVER['REQUEST_TIME'], DATE_W3C, false),
113
    PMF_SITEMAP_GOOGLE_CHANGEFREQ_DAILY,
114
    PMF_SITEMAP_GOOGLE_PRIORITY_MAX
115
);
116
117
// nth entry: each faq
118
foreach ($items as $item) {
119
    $priority = PMF_SITEMAP_GOOGLE_PRIORITY_DEFAULT;
120
    if (($visitsMax - $visitMin) > 0) {
121
        $priority = sprintf('%.1f', PMF_SITEMAP_GOOGLE_PRIORITY_DEFAULT * (1 + (($item['visits'] - $visitMin) / ($visitsMax - $visitMin))));
122
    }
123
    // a. We use plain PMF urls w/o any SEO schema
124
    $link = str_replace($_SERVER['SCRIPT_NAME'], '/index.php', $item['url']);
125
    // b. We use SEO PMF urls
126 View Code Duplication
    if (PMF_SITEMAP_GOOGLE_USE_SEO) {
127
        if (isset($item['thema'])) {
128
            $oL = new PMF_Link($link, $faqConfig);
129
            $oL->itemTitle = $item['thema'];
130
            $link = $oL->toString();
131
        }
132
    }
133
    $sitemap .= buildSitemapNode(
134
        $faqConfig->getDefaultUrl().$link,
135
        PMF_Date::createIsoDate($item['date'], DATE_W3C),
136
        // @todo: manage changefreq node with the info provided by faqchanges,
137
        // if this will not add a big load to the server (+1 query/faq)
138
        PMF_SITEMAP_GOOGLE_CHANGEFREQ_DAILY,
139
        $priority
140
    );
141
}
142
143
$sitemap .= '</urlset>';
144
145
$getgezip = PMF_Filter::filterInput(INPUT_GET, PMF_SITEMAP_GOOGLE_GET_GZIP, FILTER_VALIDATE_INT);
146
if (!is_null($getgezip) && (1 == $getgezip)) {
147
    if (function_exists('gzencode')) {
148
        $sitemapGz = gzencode($sitemap);
149
        header('Content-Type: application/x-gzip');
150
        header('Content-Disposition: attachment; filename="'.PMF_SITEMAP_GOOGLE_FILENAME_GZ.'"');
151
        header('Content-Length: '.strlen($sitemapGz));
152
        print $sitemapGz;
153
    } else {
154
        $http = new PMF_Helper_Http();
155
        $http->sendStatus(404);
156
    }
157
} else {
158
    header('Content-Type: text/xml');
159
    header('Content-Disposition: inline; filename="'.PMF_SITEMAP_GOOGLE_FILENAME.'"');
160
    header('Content-Length: '.PMF_String::strlen($sitemap));
161
    print $sitemap;
162
}
163
164
$faqConfig->getDb()->close();
165