Beispiel #1
0
function showATOM()
{
    header('Content-Type: application/atom+xml; charset=utf-8');
    // $usepermalink : If true, use permalink instead of final link.
    // User just has to add 'permalink' in URL parameters. e.g. http://mysite.com/shaarli/?do=atom&permalinks
    $usepermalinks = isset($_GET['permalinks']) || !$GLOBALS['config']['ENABLE_RSS_PERMALINKS'];
    // Cache system
    $query = $_SERVER["QUERY_STRING"];
    $cache = new CachedPage($GLOBALS['config']['PAGECACHE'], pageUrl(), startsWith($query, 'do=atom') && !isLoggedIn());
    $cached = $cache->cachedVersion();
    if (!empty($cached)) {
        echo $cached;
        exit;
    }
    // If cached was not found (or not usable), then read the database and build the response:
    // Read links from database (and filter private links if used it not logged in).
    $LINKSDB = new LinkDB($GLOBALS['config']['DATASTORE'], isLoggedIn() || $GLOBALS['config']['OPEN_SHAARLI'], $GLOBALS['config']['HIDE_PUBLIC_LINKS']);
    // Optionally filter the results:
    $linksToDisplay = array();
    if (!empty($_GET['searchterm'])) {
        $linksToDisplay = $LINKSDB->filterFulltext($_GET['searchterm']);
    } else {
        if (!empty($_GET['searchtags'])) {
            $linksToDisplay = $LINKSDB->filterTags(trim($_GET['searchtags']));
        } else {
            $linksToDisplay = $LINKSDB;
        }
    }
    $nblinksToDisplay = 50;
    // Number of links to display.
    if (!empty($_GET['nb'])) {
        $nblinksToDisplay = $_GET['nb'] == 'all' ? count($linksToDisplay) : max($_GET['nb'] + 0, 1);
    }
    $pageaddr = escape(indexUrl());
    $latestDate = '';
    $entries = '';
    $i = 0;
    $keys = array();
    foreach ($linksToDisplay as $key => $value) {
        $keys[] = $key;
    }
    // No, I can't use array_keys().
    while ($i < $nblinksToDisplay && $i < count($keys)) {
        $link = $linksToDisplay[$keys[$i]];
        $guid = $pageaddr . '?' . smallHash($link['linkdate']);
        $iso8601date = linkdate2iso8601($link['linkdate']);
        $latestDate = max($latestDate, $iso8601date);
        $absurl = $link['url'];
        if (startsWith($absurl, '?')) {
            $absurl = $pageaddr . $absurl;
        }
        // make permalink URL absolute
        $entries .= '<entry><title>' . $link['title'] . '</title>';
        if ($usepermalinks === true) {
            $entries .= '<link href="' . $guid . '" /><id>' . $guid . '</id>';
        } else {
            $entries .= '<link href="' . $absurl . '" /><id>' . $guid . '</id>';
        }
        if (!$GLOBALS['config']['HIDE_TIMESTAMPS'] || isLoggedIn()) {
            $entries .= '<updated>' . escape($iso8601date) . '</updated>';
        }
        // Add permalink in description
        $descriptionlink = '(<a href="' . $guid . '">Permalink</a>)';
        // If user wants permalinks first, put the final link in description
        if ($usepermalinks === true) {
            $descriptionlink = '(<a href="' . $absurl . '">Link</a>)';
        }
        if (strlen($link['description']) > 0) {
            $descriptionlink = '<br>' . $descriptionlink;
        }
        $entries .= '<content type="html"><![CDATA[' . nl2br(keepMultipleSpaces(text2clickable($link['description']))) . $descriptionlink . "]]></content>\n";
        if ($link['tags'] != '') {
            foreach (explode(' ', $link['tags']) as $tag) {
                $entries .= '<category scheme="' . $pageaddr . '" term="' . $tag . '" />' . "\n";
            }
        }
        $entries .= "</entry>\n";
        $i++;
    }
    $feed = '<?xml version="1.0" encoding="UTF-8"?><feed xmlns="http://www.w3.org/2005/Atom">';
    $feed .= '<title>' . $GLOBALS['title'] . '</title>';
    if (!$GLOBALS['config']['HIDE_TIMESTAMPS'] || isLoggedIn()) {
        $feed .= '<updated>' . escape($latestDate) . '</updated>';
    }
    $feed .= '<link rel="self" href="' . escape(serverUrl() . $_SERVER["REQUEST_URI"]) . '" />';
    if (!empty($GLOBALS['config']['PUBSUBHUB_URL'])) {
        $feed .= '<!-- PubSubHubbub Discovery -->';
        $feed .= '<link rel="hub" href="' . escape($GLOBALS['config']['PUBSUBHUB_URL']) . '" />';
        $feed .= '<!-- End Of PubSubHubbub Discovery -->';
    }
    $feed .= '<author><name>' . $pageaddr . '</name><uri>' . $pageaddr . '</uri></author>';
    $feed .= '<id>' . $pageaddr . '</id>' . "\n\n";
    // Yes, I know I should use a real IRI (RFC3987), but the site URL will do.
    $feed .= $entries;
    $feed .= '</feed><!-- Cached version of ' . escape(pageUrl()) . ' -->';
    echo $feed;
    $cache->cache(ob_get_contents());
    ob_end_flush();
    exit;
}
Beispiel #2
0
function showATOM()
{
    header('Content-Type: application/atom+xml; charset=utf-8');
    // Cache system
    $query = $_SERVER["QUERY_STRING"];
    $cache = new pageCache(pageUrl(), startsWith($query, 'do=atom') && !isLoggedIn());
    $cached = $cache->cachedVersion();
    if (!empty($cached)) {
        echo $cached;
        exit;
    }
    // If cached was not found (or not usable), then read the database and build the response:
    $LINKSDB = new linkdb(isLoggedIn() || $GLOBALS['config']['OPEN_SHAARLI']);
    // Read links from database (and filter private links if used it not logged in).
    // Optionnaly filter the results:
    $linksToDisplay = array();
    if (!empty($_GET['searchterm'])) {
        $linksToDisplay = $LINKSDB->filterFulltext($_GET['searchterm']);
    } elseif (!empty($_GET['searchtags'])) {
        $linksToDisplay = $LINKSDB->filterTags(trim($_GET['searchtags']));
    } else {
        $linksToDisplay = $LINKSDB;
    }
    $pageaddr = htmlspecialchars(indexUrl());
    $latestDate = '';
    $entries = '';
    $i = 0;
    $keys = array();
    foreach ($linksToDisplay as $key => $value) {
        $keys[] = $key;
    }
    // No, I can't use array_keys().
    while ($i < 50 && $i < count($keys)) {
        $link = $linksToDisplay[$keys[$i]];
        $guid = $pageaddr . '?' . smallHash($link['linkdate']);
        $iso8601date = linkdate2iso8601($link['linkdate']);
        $latestDate = max($latestDate, $iso8601date);
        $absurl = htmlspecialchars($link['url']);
        if (startsWith($absurl, '?')) {
            $absurl = $pageaddr . $absurl;
        }
        // make permalink URL absolute
        $entries .= '<entry><title>' . htmlspecialchars($link['title']) . '</title><link href="' . $absurl . '" /><id>' . $guid . '</id>';
        if (!$GLOBALS['config']['HIDE_TIMESTAMPS'] || isLoggedIn()) {
            $entries .= '<updated>' . htmlspecialchars($iso8601date) . '</updated>';
        }
        $entries .= '<content type="html">' . htmlspecialchars(nl2br(keepMultipleSpaces(text2clickable(htmlspecialchars($link['description']))))) . "</content>\n";
        if ($link['tags'] != '') {
            foreach (explode(' ', $link['tags']) as $tag) {
                $entries .= '<category scheme="' . htmlspecialchars($pageaddr, ENT_QUOTES) . '" term="' . htmlspecialchars($tag, ENT_QUOTES) . '" />' . "\n";
            }
        }
        $entries .= "</entry>\n";
        $i++;
    }
    $feed = '<?xml version="1.0" encoding="UTF-8"?><feed xmlns="http://www.w3.org/2005/Atom">';
    $feed .= '<title>' . htmlspecialchars($GLOBALS['title']) . '</title>';
    if (!$GLOBALS['config']['HIDE_TIMESTAMPS'] || isLoggedIn()) {
        $feed .= '<updated>' . htmlspecialchars($latestDate) . '</updated>';
    }
    $feed .= '<link rel="self" href="' . htmlspecialchars(serverUrl() . $_SERVER["REQUEST_URI"]) . '" />';
    if (!empty($GLOBALS['config']['PUBSUBHUB_URL'])) {
        $feed .= '<!-- PubSubHubbub Discovery -->';
        $feed .= '<link rel="hub" href="' . htmlspecialchars($GLOBALS['config']['PUBSUBHUB_URL']) . '" />';
        $feed .= '<!-- End Of PubSubHubbub Discovery -->';
    }
    $feed .= '<author><name>' . htmlspecialchars($pageaddr) . '</name><uri>' . htmlspecialchars($pageaddr) . '</uri></author>';
    $feed .= '<id>' . htmlspecialchars($pageaddr) . '</id>' . "\n\n";
    // Yes, I know I should use a real IRI (RFC3987), but the site URL will do.
    $feed .= $entries;
    $feed .= '</feed>';
    echo $feed;
    $cache->cache(ob_get_contents());
    ob_end_flush();
    exit;
}
Beispiel #3
0
function displayXML()
{
    header('Content-type: application/rss+xml; charset=utf-8');
    echo '<?xml version="1.0" encoding="UTF-8" ?>
	<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><link>' . serverUrl(true) . '</link>';
    echo '<atom:link href="' . serverUrl(true) . '/?rss" rel="self" type="application/rss+xml"/><title>Projet Autoblog' . (strlen(HEAD_TITLE) > 0 ? ' | ' . HEAD_TITLE : '') . '</title><description>Projet Autoblog - RSS : Ajouts et changements de disponibilité.</description>';
    if (file_exists(RESOURCES_FOLDER . 'rss.json')) {
        $json = json_decode(file_get_contents(RESOURCES_FOLDER . 'rss.json'), true);
        rsort($json);
        foreach ($json as $uitem) {
            $item = array();
            foreach ($uitem as $Key => $Value) {
                $item[$Key] = escape($Value);
            }
            $description = displayXMLstatus($item['status'], $item['response_code'], $item['autoblog_url'], $item['autoblog_title'], $item['autoblog_sourceurl'], $item['autoblog_sourcefeed']);
            $link = serverUrl(true) . $item['autoblog_url'];
            $date = date(DATE_RSS, $item['timestamp']);
            print <<<EOT

<item>
\t<title>{$item['autoblog_title']}</title>
\t<description><![CDATA[{$description}]]></description>
\t<link>{$link}</link>
\t<guid isPermaLink="false">{$item['timestamp']}</guid>
\t<dc:creator>Autoblog</dc:creator>
\t<pubDate>{$date}</pubDate>
</item>
EOT;
        }
    }
    echo '</channel></rss>';
}
Beispiel #4
0
<?php 
    }
    if (ALLOW_NEW_AUTOBLOGS_BY_BUTTON == TRUE) {
        ?>
      <section class="form" id="add_bookmark">
        <header>
          <h3>Marque page</h3>
        </header>
        
        <p>
            Pour ajouter facilement un autoblog d'un site web, glissez ce bouton dans votre barre de marque-pages &rarr;
            <a class="bouton" onclick=
                "alert('Glissez ce bouton dans votre barre de marque-pages (ou clic-droit > marque-page sur ce lien)');
                return false;"
            href="javascript:(function(){var%20autoblog_url=&quot;<?php 
        echo serverUrl() . $_SERVER["REQUEST_URI"];
        ?>
&quot;;var%20popup=window.open(&quot;&quot;,&quot;Add%20autoblog&quot;,'height=180,width=670');popup.document.writeln('<html><head></head><body><form%20action=&quot;'+autoblog_url+'&quot;%20method=&quot;GET&quot;>');popup.document.write('Url%20feed%20%20:%20<br/>');var%20feed_links=new%20Array();var%20links=document.getElementsByTagName('link');if(links.length>0){for(var%20i=0;i<links.length;i++){if(links[i].rel==&quot;alternate&quot;){popup.document.writeln('<label%20for=&quot;feed_'+i+'&quot;><input%20id=&quot;feed_'+i+'&quot;%20type=&quot;radio&quot;%20name=&quot;rssurl&quot;%20value=&quot;'+links[i].href+'&quot;/>'+links[i].title+&quot;%20(%20&quot;+links[i].href+&quot;%20)</label><br/>&quot;);}}}popup.document.writeln(&quot;<input%20id='number'%20type='hidden'%20name='number'%20value='17'>&quot;);popup.document.writeln(&quot;<input%20type='hidden'%20name='via_button'%20value='1'>&quot;);popup.document.writeln(&quot;<br/><input%20type='submit'%20value='Vérifier'%20name='Ajouter'%20>&quot;);popup.document.writeln(&quot;</form></body></html>&quot;);})();">Projet Autoblog</a>
      </section>
<?php 
    }
    ?>
    </section>
<?php 
}
$fichierCache = DOCS_CACHE_FILENAME;
// si la page n'existe pas dans le cache ou si elle a expiré (durée paramétrable)
// on lance la génération de la page et on la stoke dans un fichier
if (@filemtime($fichierCache) < time() - DOCS_CACHE_DURATION) {
    // on démarre la bufferisation : rien n'est envoyé au navigateur
    ob_start();