Wordpress社交板插件修改的XML Feed

时间:2016-01-27 14:33:24

标签: php xml wordpress wordpress-plugin

在工作中,我的任务是通过复制其RSS Feed功能来修改Wordpress Social Board plugin,以显示特定于我们的日历系统的XML Feed。

例如,这就是我们的XML Feed输出:

<?xml version="1.0"?>
<events>
<event>
<eventid>1449080815796</eventid>
<sponsorid>14</sponsorid>
<inputsponsor>Administration</inputsponsor>
<displayedsponsor>Lesbian, Gay, Bisexual, and Transgender (LGBT) Resource Center, The Division of Student Affairs</displayedsponsor>
<displayedsponsorurl></displayedsponsorurl>
<date>2016-01-25</date>
<timebegin>18:00</timebegin>
<timeend>20:00</timeend>
<repeat_vcaldef></repeat_vcaldef>
<repeat_startdate></repeat_startdate>
<repeat_enddate></repeat_enddate>
<categoryid>119</categoryid>
<category>Diversity</category>
<title>New 2 &apos;Quse Discussion Group</title>
<description>New 2 &apos;Quse is a discussion group for students who are new to SU/ESF and the lesbian, gay, bisexual, transgender, queer, asexual, and ally (LGBTQA) campus communities.</description>
<location>LGBT Resource Center (750 Ostrom)</location>
<price></price>
<contact_name>Abby Fite</contact_name>
<contact_phone>443-3983</contact_phone>
<contact_email>alfite@syr.edu</contact_email>
<url>http://lgbt.syr.edu</url>
<recordchangedtime>2015-12-02 13:26:55</recordchangedtime>
<recordchangeduser>dsalgbt2</recordchangeduser>
</event>
</events>

代码中有一个地方实际上格式化了他们的RSS提要:

elseif ( $feed_class == 'rss' ) {
                $rss_output = (@$this->sboption['section_rss']['rss_output']) ? $this->sboption['section_rss']['rss_output'] : array('title' => true, 'thumb' => true, 'text' => true, 'user' => true, 'tags' => false, 'share' => true, 'info' => true);
                $iframe = @$this->sboption['section_rss']['rss_iframe'];
                $fcount = 0;
                if ( $channel = @$feed->channel ) { // rss
                    if (@$channel->item)
                    foreach($channel->item as $item) {
                        $link = @$item->link;
                        if ( $this->make_remove($link) ) {
                        $fcount++;

                        $thumb = $url = '';
                        foreach($item->children('media', true)->thumbnail as $thumbnail) {
                            $thumb = $thumbnail->attributes()->url;
                        }
                        if ( ! $thumb) {
                            foreach($item->children('media', true)->content as $content) {
                                $thumb = $content->children('media', true)->thumbnail->attributes()->url;
                                if (@$content->attributes()->type == 'image/jpeg')
                                    $url = @$content->attributes()->url;
                            }
                        }
                        if ( ! $thumb) {
                            if (@$item->enclosure->attributes()->type == 'image/jpeg')
                                $thumb = @$item->enclosure->attributes()->url;
                        }

                        if (@$item->category && @$rss_output['tags'])
                        foreach($item->category as $category) {
                            $cats[] = (string) $category;
                        }

                        // set Snippet or Full Text
                        $text = $description = '';
                        if (@$this->sboption['section_rss']['rss_text'])
                            $description = $item->description;
                        else
                            $description = (@$item->children("content", true)->encoded) ? $item->children("content", true)->encoded : $item->description;

                        if (@$description) {
                            $description = preg_replace("/<script.*?\/script>/s", "", $description);
                            if (@$attr['words']) {
                                if ( ! $thumb) {
                                    $thumb = sb_getsrc($description);
                                }
                                $text = $this->word_limiter($description, $link);
                            } else {
                                $text = $description;
                            }
                        }
                        if ($iframe) {
                            if ( ! $url)
                                $url = (@$thumb) ? $thumb : '';
                        }

                        $sbi = $this->make_timestr($item->pubDate, $link);
                        $itemdata = array(
                        'thumb' => (@$thumb) ? $thumb : '',
                        'thumburl' => $url,
                        'title' => '<a href="' . $link . '"'.$target.'>' . (@$attr['titles'] ? $this->title_limiter($item->title) : $item->title) . '</a>',
                        'text' => $text,
                        'tags' => @implode(', ', $cats),
                        'url' => $link,
                        'iframe' => $iframe ? 'icbox' : '',
                        'date' => $item->pubDate,
                        'user' => array(
                            'name' => $channel->title,
                            'url' => $channel->link,
                            'image' => @$channel->image->url
                            ),
                        'type' => 'pencil',
                        'icon' => array(@$themeoption['social_icons'][12], @$themeoption['type_icons'][0])
                        );
                        $final[$sbi] = $layoutobj->sb_create_item($feed_class, $itemdata, $attr, $rss_output, $sbi);
                        if ( isset($slideshow) ) {
                            $itemdata['text'] = @$this->format_text($description);
                            if ($url)
                                $itemdata['thumb'] = $url;
                            $finalslide[$sbi] = $slidelayoutobj->sb_create_slideitem($feed_class, $itemdata, $attr, $rss_output, $sbi);
                        }

                        if ( $fcount >= $results ) break;
                        }
                    }
                } elseif ( $entry = @$feed->entry ) { // atom
                    // get feed link
                    foreach($feed->link as $link) {
                        if ($link->attributes()->rel == 'alternate')
                            $user_url = $link->attributes()->href;
                    }
                    foreach($feed->entry as $item) {
                        $link = @$item->link[0]->attributes()->href;
                        if ( $this->make_remove($link) ) {
                        $fcount++;

                        $title = (string) $item->title;
                        $thumb = $url = '';
                        foreach($item->media as $thumbnail) {
                            $thumb = $thumbnail->attributes()->url;
                        }
                        if ( ! $thumb) {
                            foreach($item->link as $linkitem) {
                                if (@$linkitem->attributes()->rel == 'enclosure') {
                                    if (@$linkitem->attributes()->type == 'image/jpeg')
                                        $thumb = @$content->attributes()->url;
                                }
                            }
                        }

                        $cats = '';
                        if (@$item->category && @$rss_output['tags']) {
                            foreach($item->category as $category) {
                                $cats .= $category->attributes()->term.', ';
                            }
                            $cats = rtrim($cats, ", ");
                        }

                        // set Snippet or Full Text
                        $text = $description = '';
                        if (@$this->sboption['section_rss']['rss_text']) {
                            $description = (string) $item->summary;
                        } else {
                            $content = (string) @$item->content;
                            $description = ($content) ? $content : (string) $item->summary;
                        }

                        if (@$description) {
                            if (@$attr['words']) {
                                if ( ! $thumb) {
                                    $thumb = sb_getsrc($description);
                                }
                                $text = $this->word_limiter($description, $link);
                            }
                            else {
                                $text = $description;
                            }
                        }
                        if ($iframe)
                            $url = (@$thumb) ? $thumb : '';

                        $sbi = $this->make_timestr($item->published, $link);
                        $itemdata = array(
                        'thumb' => @$thumb,
                        'thumburl' => $url,
                        'title' => '<a href="' . $link . '"'.$target.'>' . (@$attr['titles'] ? $this->title_limiter($title) : $title) . '</a>',
                        'text' => @$text,
                        'tags' => @$cats,
                        'url' => $link,
                        'iframe' => $iframe ? 'icbox' : '',
                        'date' => $item->published,
                        'user' => array(
                            'name' => $feed->title,
                            'url' => @$user_url,
                            'image' => @$feed->logo
                            ),
                        'type' => 'pencil',
                        'icon' => array(@$themeoption['social_icons'][12], @$themeoption['type_icons'][0])
                        );
                        $final[$sbi] = $layoutobj->sb_create_item($feed_class, $itemdata, $attr, $rss_output, $sbi);
                        if ( isset($slideshow) ) {
                            $itemdata['text'] = @$this->format_text($description);
                            if ($url)
                                $itemdata['thumb'] = $url;
                            $finalslide[$sbi] = $slidelayoutobj->sb_create_slideitem($feed_class, $itemdata, $attr, $rss_output, $sbi);
                        }

                        if ( $fcount >= $results ) break;
                        }
                    }
                }
            }

我已将代码复制到另一个Feed类并进行了修改,但它似乎没有提取任何值:

    elseif ( $feed_class == 'dsa' ) {
                $rss_output = (@$this->sboption['section_dsa']['dsa_output']) ? $this->sboption['section_dsa']['dsa_output'] : array('title' => true, 'thumb' => true, 'text' => true, 'user' => true, 'tags' => false, 'share' => true, 'info' => true);
                $iframe = @$this->sboption['section_dsa']['dsa_iframe'];
                $fcount = 0;
                if ( $channel = @$feed->events ) { // rss
                    if (@$channel->event)
                    foreach($channel->event as $item) {
                        $link = @$item->displayedsponsorurl;
                        if ( $this->make_remove($link) ) {
                        $fcount++;

                        $thumb = $url = '';
                        foreach($item->children('media', true)->thumbnail as $thumbnail) {
                            $thumb = $thumbnail->attributes()->url;
                        }
                        if ( ! $thumb) {
                            foreach($item->children('media', true)->content as $content) {
                                $thumb = $content->children('media', true)->thumbnail->attributes()->url;
                                if (@$content->attributes()->type == 'image/jpeg')
                                    $url = @$content->attributes()->url;
                            }
                        }
                        if ( ! $thumb) {
                            if (@$item->enclosure->attributes()->type == 'image/jpeg')
                                $thumb = @$item->enclosure->attributes()->url;
                        }

                        if (@$item->category && @$rss_output['tags'])
                        foreach($item->category as $category) {
                            $cats[] = (string) $category;
                        }

                        // set Snippet or Full Text
                        $text = $description = '';
                        if (@$this->sboption['section_dsa']['dsa_text'])
                            $description = $item->description;
                        else
                            $description = (@$item->children("content", true)->encoded) ? $item->children("content", true)->encoded : $item->description;

                        if (@$description) {
                            $description = preg_replace("/<script.*?\/script>/s", "", $description);
                            if (@$attr['words']) {
                                if ( ! $thumb) {
                                    $thumb = sb_getsrc($description);
                                }
                                $text = $this->word_limiter($description, $link);
                            } else {
                                $text = $description;
                            }
                        }
                        if ($iframe) {
                            if ( ! $url)
                                $url = (@$thumb) ? $thumb : '';
                        }

                        $sbi = $this->make_timestr($item->pubDate, $link);
                        $itemdata = array(
                        'thumb' => (@$thumb) ? $thumb : '',
                        'thumburl' => $url,
                        'title' => '<a href="' . $link . '"'.$target.'>' . (@$attr['titles'] ? $this->title_limiter($item->title) : $item->title) . '</a>',
                        'text' => $text,
                        'tags' => @implode(', ', $cats),
                        'url' => $link,
                        'iframe' => $iframe ? 'icbox' : '',
                        'date' => $item->date,
                        'user' => array(
                            'name' => $channel->title,
                            'url' => $channel->link,
                            'image' => @$channel->image->url
                            ),
                        'type' => 'pencil',
                        'icon' => array(@$themeoption['social_icons'][12], @$themeoption['type_icons'][0])
                        );
                        $final[$sbi] = $layoutobj->sb_create_item($feed_class, $itemdata, $attr, $rss_output, $sbi);
                        if ( isset($slideshow) ) {
                            $itemdata['text'] = @$this->format_text($description);
                            if ($url)
                                $itemdata['thumb'] = $url;
                            $finalslide[$sbi] = $slidelayoutobj->sb_create_slideitem($feed_class, $itemdata, $attr, $rss_output, $sbi);
                        }

                        if ( $fcount >= $results ) break;
                        }
                    }
                } elseif ( $entry = @$feed->entry ) { // atom
                    // get feed link
                    foreach($feed->link as $link) {
                        if ($link->attributes()->rel == 'alternate')
                            $user_url = $link->attributes()->href;
                    }
                    foreach($feed->entry as $item) {
                        $link = @$item->link[0]->attributes()->href;
                        if ( $this->make_remove($link) ) {
                        $fcount++;

                        $title = (string) $item->title;
                        $thumb = $url = '';
                        foreach($item->media as $thumbnail) {
                            $thumb = $thumbnail->attributes()->url;
                        }
                        if ( ! $thumb) {
                            foreach($item->link as $linkitem) {
                                if (@$linkitem->attributes()->rel == 'enclosure') {
                                    if (@$linkitem->attributes()->type == 'image/jpeg')
                                        $thumb = @$content->attributes()->url;
                                }
                            }
                        }

                        $cats = '';
                        if (@$item->category && @$rss_output['tags']) {
                            foreach($item->category as $category) {
                                $cats .= $category->attributes()->term.', ';
                            }
                            $cats = rtrim($cats, ", ");
                        }

                        // set Snippet or Full Text
                        $text = $description = '';
                        if (@$this->sboption['section_dsa']['dsa_text']) {
                            $description = (string) $item->summary;
                        } else {
                            $content = (string) @$item->content;
                            $description = ($content) ? $content : (string) $item->summary;
                        }

                        if (@$description) {
                            if (@$attr['words']) {
                                if ( ! $thumb) {
                                    $thumb = sb_getsrc($description);
                                }
                                $text = $this->word_limiter($description, $link);
                            }
                            else {
                                $text = $description;
                            }
                        }
                        if ($iframe)
                            $url = (@$thumb) ? $thumb : '';

                        $sbi = $this->make_timestr($item->published, $link);
                        $itemdata = array(
                        'thumb' => @$thumb,
                        'thumburl' => $url,
                        'title' => '<a href="' . $link . '"'.$target.'>' . (@$attr['titles'] ? $this->title_limiter($title) : $title) . '</a>',
                        'text' => @$text,
                        'tags' => @$cats,
                        'url' => $link,
                        'iframe' => $iframe ? 'icbox' : '',
                        'date' => $item->published,
                        'user' => array(
                            'name' => $feed->title,
                            'url' => @$user_url,
                            'image' => @$feed->logo
                            ),
                        'type' => 'pencil',
                        'icon' => array(@$themeoption['social_icons'][12], @$themeoption['type_icons'][0])
                        );
                        $final[$sbi] = $layoutobj->sb_create_item($feed_class, $itemdata, $attr, $rss_output, $sbi);
                        if ( isset($slideshow) ) {
                            $itemdata['text'] = @$this->format_text($description);
                            if ($url)
                                $itemdata['thumb'] = $url;
                            $finalslide[$sbi] = $slidelayoutobj->sb_create_slideitem($feed_class, $itemdata, $attr, $rss_output, $sbi);
                        }

                        if ( $fcount >= $results ) break;
                        }
                    }
                }
            }

我为这是一个非常具体的问题而道歉。我对PHP缺乏经验,特别是对于Wordpress插件,我的任务是尽快让这个工作......

我是否只是缺少与运营商没有牵引价值的东西?我还没有设置所有的值,我只是修改已经存在的值,然后再添加任何东西。

我的日志没有直接错误,所以我认为它没有提取正确的值,但我不确定如何解决这个问题。

0 个答案:

没有答案