コード例 #1
0
function pugpig_get_atom_entry($d, $page, $edition)
{
    $entry = $d->createElement('entry');
    $entry->appendChild(newElement($d, 'title', strip_tags($page['title'])));
    $id = $page['id'];
    if (isset($page['id_prefix'])) {
        // we are explicitly setting the id_prefix ourselves, so don't add the atom tag
        $id = $page['id_prefix'] . $id;
    } else {
        $id = pugpig_get_atom_tag('page-' . $id);
    }
    $entry->appendChild(newElement($d, 'id', $id));
    if (empty($page['modified'])) {
        $page['modified'] = time();
    }
    $entry->appendChild(newElement($d, 'updated', pugpig_date3339($page['modified'])));
    if (empty($page['date'])) {
        $page['date'] = time();
    }
    $entry->appendChild(newElement($d, 'published', pugpig_date3339($page['date'])));
    // Author
    if (isset($page['author']) && !empty($page['author'])) {
        $page_authors = $page['author'];
        $authors = is_array($page_authors) ? $page_authors : array($page_authors);
        foreach ($authors as $author) {
            $author_element = $d->createElement('author');
            $author_element->appendChild($d->createElement('name', $author));
            $entry->appendChild($author_element);
        }
    }
    // Show draft editions
    if ($page['status'] != "published") {
        $appcontrol = $d->createElement('app:control');
        $appcontrol->appendChild($d->createElement('app:draft', 'yes'));
        $entry->appendChild($appcontrol);
    }
    $summary = newElement($d, 'summary', $page['summary']);
    $summary->setAttribute('type', 'text');
    $entry->appendChild($summary);
    // Categories should be first for the default client ToC to work normally
    if (isset($page['categories'])) {
        foreach ($page['categories'] as $cat) {
            _pugpig_create_atom_category($d, $entry, 'section', $cat);
        }
    }
    // access
    if (isset($page['access'])) {
        _pugpig_create_atom_category($d, $entry, 'access', $page['access']);
    }
    // Page Type
    if (empty($page['type'])) {
        $page['type'] = 'Page';
    }
    _pugpig_create_atom_category($d, $entry, 'pagetype', $page['type']);
    // Level
    if (isset($page['level'])) {
        if (empty($page['level'])) {
            $page['level'] = 1;
        }
        _pugpig_create_atom_category($d, $entry, 'level', $page['level']);
    }
    if (isset($page['custom_categories'])) {
        foreach ($page['custom_categories'] as $scheme => $val) {
            _pugpig_create_atom_category($d, $entry, $scheme, $val);
        }
    }
    _pugpig_create_xml_link($d, $entry, array('rel' => 'related', 'type' => 'text/cache-manifest', 'href' => $page['manifest']));
    _pugpig_create_xml_link($d, $entry, array('rel' => 'alternate', 'type' => 'text/html', 'href' => $page['url']));
    // Take the sharing link from the edition if it isn't on the page
    $sharing_link = '';
    if (isset($page['sharing_link'])) {
        $sharing_link = $page['sharing_link'];
    }
    if ($sharing_link == '' && isset($edition['sharing_link'])) {
        $sharing_link = $edition['sharing_link'];
    }
    if (!empty($sharing_link)) {
        _pugpig_create_xml_link($d, $entry, array('rel' => 'bookmark', 'type' => 'text/html', 'href' => $sharing_link));
    }
    // Enclosures
    if (isset($page['links'])) {
        foreach ($page['links'] as $link) {
            _pugpig_create_xml_link($d, $entry, $link);
        }
    }
    return $entry;
}
コード例 #2
0
function pugpig_get_atom_entry($d, $page, $edition)
{
    $entry = $d->createElement('entry');
    $entry->appendChild(newElement($d, 'title', strip_tags($page['title'])));
    $entry->appendChild(newElement($d, 'id', pugpig_get_atom_tag('page-' . $page['id'])));
    if (empty($page['modified'])) {
        $page['modified'] = time();
    }
    $entry->appendChild(newElement($d, 'updated', pugpig_date3339($page['modified'])));
    if (empty($page['date'])) {
        $page['date'] = time();
    }
    $entry->appendChild(newElement($d, 'published', pugpig_date3339($page['date'])));
    // Author
    if (isset($page['author']) && !empty($page['author'])) {
        $author = $d->createElement('author');
        $author->appendChild($d->createElement('name', $page['author']));
        $entry->appendChild($author);
    }
    // Show draft editions
    if ($page['status'] != "published") {
        $appcontrol = $d->createElement('app:control');
        $appcontrol->appendChild($d->createElement('app:draft', 'yes'));
        $entry->appendChild($appcontrol);
    }
    $summary = newElement($d, 'summary', $page['summary']);
    $summary->setAttribute('type', 'text');
    $entry->appendChild($summary);
    // Categories should be first for the default client ToC to work normally
    if (isset($page['categories'])) {
        foreach ($page['categories'] as $cat) {
            $category = $d->createElement('category');
            $category->setAttribute('scheme', 'http://schema.pugpig.com/section');
            $category->setAttribute('term', $cat);
            $entry->appendChild($category);
        }
    }
    // Page Type
    if (empty($page['type'])) {
        $page['type'] = 'Page';
    }
    $category = $d->createElement('category');
    $category->setAttribute('scheme', 'http://schema.pugpig.com/pagetype');
    $category->setAttribute('term', $page['type']);
    $entry->appendChild($category);
    // Level
    if (empty($page['level'])) {
        $page['level'] = 1;
    }
    $category = $d->createElement('category');
    $category->setAttribute('scheme', 'http://schema.pugpig.com/level');
    $category->setAttribute('term', $page['level']);
    $entry->appendChild($category);
    if (isset($page['custom_categories'])) {
        foreach ($page['custom_categories'] as $scheme => $val) {
            $category = $d->createElement('category');
            $category->setAttribute('scheme', "http://schema.pugpig.com/{$scheme}");
            $category->setAttribute('term', $val);
            $entry->appendChild($category);
        }
    }
    $link_man = $d->createElement('link');
    $link_man->setAttribute('rel', 'related');
    $link_man->setAttribute('type', 'text/cache-manifest');
    $link_man->setAttribute('href', $page['manifest']);
    $entry->appendChild($link_man);
    $link_man = $d->createElement('link');
    $link_man->setAttribute('rel', 'alternate');
    $link_man->setAttribute('type', 'text/html');
    $link_man->setAttribute('href', $page['url']);
    $entry->appendChild($link_man);
    // Take the sharing link from the edition if it isn't on the page
    $sharing_link = '';
    if (isset($page['sharing_link'])) {
        $sharing_link = $page['sharing_link'];
    }
    if ($sharing_link == '' && isset($edition['sharing_link'])) {
        $sharing_link = $edition['sharing_link'];
    }
    if (!empty($sharing_link)) {
        $link_man = $d->createElement('link');
        $link_man->setAttribute('rel', 'bookmark');
        $link_man->setAttribute('type', 'text/html');
        $link_man->setAttribute('href', $sharing_link);
        $entry->appendChild($link_man);
    }
    // Enclosures
    if (isset($page['links'])) {
        foreach ($page['links'] as $link) {
            $link_enc = $d->createElement('link');
            $link_enc->setAttribute('rel', $link['rel']);
            $link_enc->setAttribute('title', $link['title']);
            $link_enc->setAttribute('type', $link['type']);
            $link_enc->setAttribute('href', $link['href']);
            $entry->appendChild($link_enc);
        }
    }
    return $entry;
}