[RFE] sitemap generator plugin: remove non-public posts

Discussion corner for Developers of Serendipity.
Post Reply
Anthem
Regular
Posts: 20
Joined: Wed Aug 03, 2005 10:28 pm

[RFE] sitemap generator plugin: remove non-public posts

Post by Anthem »

The sitemap generator plugin (currently v0.41) exports links to all blog entries. However sometimes it may be preferable to protect some entries and make them accessible to members only, or expire them altogether (eg. with the "Hide/delete entries for non-registered users after a specific timespan"-plugin).

The sitemap generator does not take this into account and will happily export all non-draft entries. Since it usually makes no sense that non-public entries show up in search engine results, (and sometimes you may not want to have others see the title of your blog postings), I hereby propose to remove these entries from the exported sitemap.

One way to achieve this is to change the SQL query in /plugins/serendipity_event_google_sitemap/serendipity_event_google_sitemap.php:

Code: Select all

    function add_entries(&$sitemap_xml) {
(..)
        $entries = serendipity_db_query(
                'SELECT
                    entries.id AS id,
                    entries.title AS title,
                    '.$sqlnullfunction.'(entries.last_modified,0) AS timestamp_1,
                    '.$sqlnullfunction.'(MAX(comments.timestamp),0) AS timestamp_2
                FROM '.$serendipity['dbPrefix'].'entries entries
                LEFT JOIN '.$serendipity['dbPrefix'].'comments comments
                ON entries.id = comments.entry_id
                WHERE entries.isdraft = \'false\'
                GROUP BY entries.id, entries.title, entries.last_modified
                ORDER BY entries.id',
            false, 'assoc');
could be replaced by:

Code: Select all

        $entries = serendipity_db_query(
                'SELECT
                    entries.id AS id,
                    entries.title AS title,
                    '.$sqlnullfunction.'(entries.last_modified,0) AS timestamp_1,
                    '.$sqlnullfunction.'(MAX(comments.timestamp),0) AS timestamp_2
                FROM '.$serendipity['dbPrefix'].'entries entries
                LEFT JOIN '.$serendipity['dbPrefix'].'comments comments
                ON entries.id = comments.entry_id
                LEFT JOIN '.$serendipity['dbPrefix'].'entryproperties ep
                ON entries.id = ep.entryid
                AND ep.property = "ep_access"
                WHERE entries.isdraft = \'false\'
                AND ep.value = "public"
                GROUP BY entries.id, entries.title, entries.last_modified
                ORDER BY entries.id',
            false, 'assoc');
Note: This code has only been tested in my current setup. It is based on the assumption that the entryproperties table always exists, and the value ep_access/public is always present for non-restricted entries.
2b || !2b
judebert
Regular
Posts: 2478
Joined: Sat Oct 15, 2005 6:57 am
Location: Orlando, FL
Contact:

Post by judebert »

This should work in all installations, within the restrictions you mentioned. Nice job!

However, this shows the problem with interacting plugins. It seems to me that the sitemap generator should use the fetchEntries call instead of its own SQL; that way other plugins could modify the available entries as required.

Either that, or perhaps it should trigger its own event hook so other entries can modify the site map.
Judebert
---
Website | Wishlist | PayPal
Post Reply