Example #1
0
function atomGenerateBaseTags($atomOperation)
{
    global $officialDatabaseName;
    // these variables are specified in 'ini.inc.php'
    global $databaseBaseURL;
    global $feedbackEmail;
    global $contentTypeCharset;
    global $convertExportDataToUTF8;
    global $logoImageURL;
    global $faviconImageURL;
    global $query;
    $atomCollection = new XML("feed");
    $atomCollection->setTagAttribute("xmlns", "http://www.w3.org/2005/Atom");
    $atomCollection->setTagAttribute("xmlns:opensearch", "http://a9.com/-/spec/opensearch/1.1/");
    $atomCollection->setTagAttribute("xmlns:unapi", "http://unapi.info/");
    // NOTE: is the unAPI namespace ok? Or should we use "http://unapi.info/specs/", or maybe something like "http://purl.org/unapi/ns/" ?
    $atomCollection->setTagAttribute("xmlns:dc", "http://purl.org/dc/elements/1.1/");
    $atomCollection->setTagAttribute("xmlns:dcterms", "http://purl.org/dc/terms/");
    $atomCollection->setTagAttribute("xmlns:prism", "http://prismstandard.org/namespaces/1.2/basic/");
    $officialDatabaseNameConv = encodeHTMLspecialchars($officialDatabaseName);
    // function 'encodeHTMLspecialchars()' is defined in 'include.inc.php'
    if ($atomOperation != "Error") {
        // convert database name to UTF-8:
        // (if '$convertExportDataToUTF8' is set to "yes" in 'ini.inc.php' and character encoding is not UTF-8 already)
        if ($convertExportDataToUTF8 == "yes" and $contentTypeCharset != "UTF-8") {
            $officialDatabaseNameConv = convertToCharacterEncoding("UTF-8", "IGNORE", $officialDatabaseNameConv);
        }
        // function 'convertToCharacterEncoding()' is defined in 'include.inc.php'
    }
    // ----------------------------------------------------------
    // Add feed-level tags:
    // (not yet used: category, contributor, rights)
    // - 'title':
    addNewBranch($atomCollection, "title", array("type" => "text"), $officialDatabaseNameConv);
    // - 'subtitle':
    if ($atomOperation == "Error") {
        addNewBranch($atomCollection, "subtitle", array(), "Search error!");
    } else {
        // ...extract the 'WHERE' clause from the SQL query to include a natural-language version (well, sort of) within the 'subtitle' element:
        $queryWhereClause = extractWHEREclause($query);
        // function 'extractWHEREclause()' is defined in 'include.inc.php'
        // construct a meaningful feed description based on the actual 'WHERE' clause:
        // TODO: For Atom XML, the query string should not get HTML encoded!
        $subTitle = "Displays records where " . encodeHTML(explainSQLQuery($queryWhereClause));
        // functions 'encodeHTML()' and 'explainSQLQuery()' are defined in 'include.inc.php'
        addNewBranch($atomCollection, "subtitle", array(), $subTitle);
    }
    // - 'updated':
    //    (TODO: the timestamp in the 'updated' element should really only get updated if any of the matching records was updated, right?)
    addNewBranch($atomCollection, "updated", array(), generateISO8601TimeStamp());
    // function 'generateISO8601TimeStamp()' is defined in 'include.inc.php'
    // - 'author':
    $authorBranch = new XMLBranch("author");
    $authorBranch->setTagContent($officialDatabaseNameConv, "author/name");
    $authorBranch->setTagContent($feedbackEmail, "author/email");
    $authorBranch->setTagContent($databaseBaseURL, "author/uri");
    $atomCollection->addXMLBranch($authorBranch);
    // - 'generator', 'icon', 'logo':
    addNewBranch($atomCollection, "generator", array("uri" => "http://www.refbase.net/", "version" => "0.9.5"), "Web Reference Database (http://refbase.sourceforge.net)");
    addNewBranch($atomCollection, "icon", array(), $databaseBaseURL . $faviconImageURL);
    addNewBranch($atomCollection, "logo", array(), $databaseBaseURL . $logoImageURL);
    // - 'link' (more links will be added in function 'atomCollection()'):
    //   - link to OpenSearch Description file:
    atomLink($atomCollection, $databaseBaseURL . "opensearch.php?operation=explain", "search", "OpenSearch", $officialDatabaseNameConv);
    //   - link to unAPI server:
    atomLink($atomCollection, $databaseBaseURL . "unapi.php", "unapi:unapi-server", "unAPI", "unAPI");
    return $atomCollection;
}
Example #2
0
function openSearchDiagnostics($diagCode, $diagDetails, $exportStylesheet)
{
    global $contentTypeCharset;
    // defined in 'ini.inc.php'
    // Map SRU/W diagnostic numbers to their corresponding messages:
    // (i.e., for OpenSearch diagnostics, we simply re-use the SRU/W diagnostics)
    $diagMessages = mapSRWDiagnostics();
    // function 'mapSRWDiagnostics()' is defined in 'webservice.inc.php'
    if (isset($diagMessages[$diagCode])) {
        $diagMessage = $diagMessages[$diagCode];
    } else {
        $diagMessage = "Unknown error";
    }
    $atomCollectionDoc = new XMLDocument();
    $atomCollectionDoc->setEncoding($contentTypeCharset);
    $atomCollection = openSearchGenerateBaseTags("Error");
    // add feed-level tags:
    // - 'id':
    addNewBranch($atomCollection, "id", array(), "info:srw/diagnostic/1/");
    // could something else be used as diagnostics feed ID instead?
    // - OpenSearch elements:
    addNewBranch($atomCollection, "opensearch:totalResults", array(), "1");
    addNewBranch($atomCollection, "openSearch:startIndex", array(), "1");
    addNewBranch($atomCollection, "openSearch:itemsPerPage", array(), "1");
    $diagnosticsBranch = new XMLBranch("entry");
    // add entry-level tags:
    addNewBranch($diagnosticsBranch, "title", array(), $diagMessage);
    //		addNewBranch($atomCollection, "link", array("href" => ""), ""); // TODO (what could be used as link for a diagnostics entry?)
    addNewBranch($diagnosticsBranch, "updated", array(), generateISO8601TimeStamp());
    // function 'generateISO8601TimeStamp()' is defined in 'include.inc.php'
    addNewBranch($diagnosticsBranch, "id", array(), "info:srw/diagnostic/1/" . $diagCode);
    $diagContent = $diagMessage;
    if (!empty($diagDetails)) {
        $diagContent .= ": " . $diagDetails;
    }
    addNewBranch($diagnosticsBranch, "content", array("type" => "text"), "Error " . $diagCode . ": " . $diagContent);
    // TODO: I18n
    $atomCollection->addXMLBranch($diagnosticsBranch);
    $atomCollectionDoc->setXML($atomCollection);
    $atomCollectionString = $atomCollectionDoc->getXMLString();
    return $atomCollectionString;
}
Example #3
0
echo '<?xml version="1.0" encoding="UTF-8"?>' . "\n";
echo '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">' . "\n";
echo "  <url>\n";
echo "    <loc>" . $databaseBaseURL . "index.php</loc>\n";
echo "    <changefreq>monthly</changefreq>\n";
// liberal, based on nucapt's history (not total records)
echo "  </url>\n";
// (3) RUN QUERY, (4) DISPLAY EXPORT FILE OR HEADER & RESULTS
// (3) RUN the query on the database through the connection:
$result = queryMySQLDatabase($query);
// function 'queryMySQLDatabase()' is defined in 'include.inc.php'
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
    echo "  <url>\n";
    echo "    <loc>" . $databaseBaseURL . "show.php?record=" . $row['serial'] . "</loc>\n";
    if (!empty($row['modified_date'])) {
        $datemod = "    <lastmod>" . generateISO8601TimeStamp($row['modified_date'], $row['modified_time']) . "</lastmod>\n";
        echo $datemod;
    } else {
        $datemod = "";
    }
    echo "  </url>\n";
    if ($fileVisibility == "everyone" or !empty($fileVisibilityException) and preg_match($fileVisibilityException[1], $row[$fileVisibilityException[0]])) {
        if (!empty($row["file"])) {
            // if the 'file' field is NOT empty
            if (!preg_match("#^(https?|ftp|file)://#i", $row["file"])) {
                // if the 'file' field does not contain a full URL (starting with "http://", "https://", "ftp://" or "file://")
                echo "  <url>\n";
                echo "    <loc>" . $databaseBaseURL . $filesBaseURL . $row["file"] . "</loc>\n";
                if (!empty($datemod)) {
                    echo $datemod;
                }