SimplePie::get_categories PHP Method

get_categories() public method

Uses , or
public get_categories ( ) : array | null
return array | null List of {@see \SimplePie_Category} objects
    public function get_categories()
    {
        $categories = array();
        foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'category') as $category) {
            $term = null;
            $scheme = null;
            $label = null;
            if (isset($category['attribs']['']['term'])) {
                $term = $this->sanitize($category['attribs']['']['term'], SIMPLEPIE_CONSTRUCT_TEXT);
            }
            if (isset($category['attribs']['']['scheme'])) {
                $scheme = $this->sanitize($category['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
            }
            if (isset($category['attribs']['']['label'])) {
                $label = $this->sanitize($category['attribs']['']['label'], SIMPLEPIE_CONSTRUCT_TEXT);
            }
            $categories[] = $this->registry->create('Category', array($term, $scheme, $label));
        }
        foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'category') as $category) {
            // This is really the label, but keep this as the term also for BC.
            // Label will also work on retrieving because that falls back to term.
            $term = $this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT);
            if (isset($category['attribs']['']['domain'])) {
                $scheme = $this->sanitize($category['attribs']['']['domain'], SIMPLEPIE_CONSTRUCT_TEXT);
            } else {
                $scheme = null;
            }
            $categories[] = $this->registry->create('Category', array($term, $scheme, null));
        }
        foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_11, 'subject') as $category) {
            $categories[] = $this->registry->create('Category', array($this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null));
        }
        foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_10, 'subject') as $category) {
            $categories[] = $this->registry->create('Category', array($this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null));
        }
        if (!empty($categories)) {
            return array_unique($categories);
        } else {
            return null;
        }
    }

Usage Example

Example #1
0
        ?>
            <?php 
        if ($contributor->get_link()) {
            ?>
                <uri><?php 
            echo $contributor->get_link();
            ?>
</uri>
            <?php 
        }
        ?>
        </contributor>
    <?php 
    }
}
if ($feed->get_categories()) {
    ?>
    <?php 
    foreach ($feed->get_categories() as $category) {
        ?>
        <category term="<?php 
        echo $category;
        ?>
"/>
    <?php 
    }
}
if ($feed->get_copyright()) {
    ?>
    <rights><?php 
    echo $feed->get_copyright();