MagpieFromSimplePie::normalize PHP Method

normalize() public method

MagpieFromSimplePie::normalize
public normalize ( )
    function normalize()
    {
        do_action('feedwordpress_magpiefromsimplepie_normalize_pre', $this);
        if (!is_null($this->channel)) {
            // Normalize channel data
            if ($this->is_atom()) {
                // Atom 1.0 elements <=> Atom 0.3 elements (Thanks, o brilliant wordsmiths of the Atom 1.0 standard!)
                if ($this->feed_version() < 1.0) {
                    $this->normalize_element($this->channel, 'tagline', $this->channel, 'subtitle');
                    $this->normalize_element($this->channel, 'copyright', $this->channel, 'rights');
                    $this->normalize_element($this->channel, 'modified', $this->channel, 'updated');
                } else {
                    $this->normalize_element($this->channel, 'subtitle', $this->channel, 'tagline');
                    $this->normalize_element($this->channel, 'rights', $this->channel, 'copyright');
                    $this->normalize_element($this->channel, 'updated', $this->channel, 'modified');
                }
                $this->normalize_element($this->channel, 'author', $this->channel['dc'], 'creator', 'normalize_atom_person');
                $this->normalize_element($this->channel, 'contributor', $this->channel['dc'], 'contributor', 'normalize_atom_person');
                // Atom elements to RSS elements
                $this->normalize_element($this->channel, 'subtitle', $this->channel, 'description');
                if (isset($this->channel['logo'])) {
                    $this->normalize_element($this->channel, 'logo', $this->image, 'url');
                    $this->normalize_element($this->channel, 'link', $this->image, 'link');
                    $this->normalize_element($this->channel, 'title', $this->image, 'title');
                }
            } elseif ($this->is_rss()) {
                // Normalize image element from where stupid MagpieRSS puts it
                //$this->normalize_element($this->channel, 'image_title', $this->image, 'title');
                //$this->normalize_element($this->channel, 'image_link', $this->image, 'link');
                //$this->normalize_element($this->channel, 'image_url', $this->image, 'url');
                // ... and, gag, textInput
                //$this->normalize_element($this->channel, 'textinput_title', $this->textinput, 'title');
                //$this->normalize_element($this->channel, 'textinput_link', $this->textinput, 'link');
                //$this->normalize_element($this->channel, 'textinput_name', $this->textinput, 'name');
                //$this->normalize_element($this->channel, 'textinput_description', $this->textinput, 'description');
                // RSS elements to Atom elements
                $this->normalize_element($this->channel, 'description', $this->channel, 'tagline');
                // Atom 0.3
                $this->normalize_element($this->channel, 'description', $this->channel, 'subtitle');
                // Atom 1.0 (yay wordsmithing!)
                $this->normalize_element($this->image, 'url', $this->channel, 'logo');
            }
        }
        if (!is_null($this->items)) {
            // Now loop through and normalize item data
            for ($i = 0; $i < count($this->items); $i++) {
                $item = $this->items[$i];
                // if atom populate rss fields and normalize 0.3 and 1.0 feeds
                if ($this->is_atom()) {
                    // Atom 1.0 elements <=> Atom 0.3 elements
                    if ($this->feed_version() < 1.0) {
                        $this->normalize_element($item, 'modified', $item, 'updated');
                        $this->normalize_element($item, 'issued', $item, 'published');
                    } else {
                        $this->normalize_element($item, 'updated', $item, 'modified');
                        $this->normalize_element($item, 'published', $item, 'issued');
                    }
                    $this->normalize_author_inheritance($item, $this->originals[$i]);
                    // Atom elements to RSS elements
                    $this->normalize_element($item, 'author', $item['dc'], 'creator', 'normalize_atom_person');
                    $this->normalize_element($item, 'contributor', $item['dc'], 'contributor', 'normalize_atom_person');
                    $this->normalize_element($item, 'summary', $item, 'description');
                    $this->normalize_element($item, 'atom_content', $item['content'], 'encoded');
                    $this->normalize_element($item, 'link_enclosure', $item, 'enclosure', 'normalize_enclosure');
                    // Categories
                    if (isset($item['category#'])) {
                        // Atom 1.0 categories to dc:subject and RSS 2.0 categories
                        $this->normalize_element($item, 'category', $item['dc'], 'subject', 'normalize_category');
                    } elseif (isset($item['dc']['subject#'])) {
                        // dc:subject to Atom 1.0 and RSS 2.0 categories
                        $this->normalize_element($item['dc'], 'subject', $item, 'category', 'normalize_dc_subject');
                    }
                    // Normalized item timestamp
                    $item_date = isset($item['published']) ? $item['published'] : $item['updated'];
                } elseif ($this->is_rss()) {
                    // RSS elements to Atom elements
                    $this->normalize_element($item, 'description', $item, 'summary');
                    $this->normalize_element($item, 'enclosure', $item, 'link_enclosure', 'normalize_enclosure');
                    // Categories
                    if (isset($item['category#'])) {
                        // RSS 2.0 categories to dc:subject and Atom 1.0 categories
                        $this->normalize_element($item, 'category', $item['dc'], 'subject', 'normalize_category');
                    } elseif (isset($item['dc']['subject#'])) {
                        // dc:subject to Atom 1.0 and RSS 2.0 categories
                        $this->normalize_element($item['dc'], 'subject', $item, 'category', 'normalize_dc_subject');
                    }
                    // Normalized item timestamp
                    if (isset($item['pubdate'])) {
                        $item_date = $item['pubdate'];
                    } elseif (isset($item['dc']['date'])) {
                        $item_date = $item['dc']['date'];
                    } else {
                        $item_date = null;
                    }
                }
                if ($item_date) {
                    $date_timestamp = new FeedTime($item_date);
                    if (!$date_timestamp->failed()) {
                        $item['date_timestamp'] = $date_timestamp->timestamp();
                    }
                }
                $this->items[$i] = $item;
            }
        }
        do_action('feedwordpress_magpiefromsimplepie_normalize_post', $this);
    }