FeedDiscussionsPlugin::Controller_AddFeed PHP Метод

Controller_AddFeed() публичный Метод

Add a feed.
public Controller_AddFeed ( $Sender )
$Sender
    public function Controller_AddFeed($Sender)
    {
        $Categories = CategoryModel::Categories();
        $Sender->SetData('Categories', $Categories);
        // Do addfeed stuff here;
        if ($Sender->Form->AuthenticatedPostback()) {
            // Grab posted values and merge with defaults
            $FormPostValues = $Sender->Form->FormValues();
            $Defaults = array('Historical' => 1, 'Refresh' => '1d', 'Category' => -1);
            $FormPostValues = array_merge($Defaults, $FormPostValues);
            try {
                $FeedURL = GetValue('FeedURL', $FormPostValues, NULL);
                if (empty($FeedURL)) {
                    throw new Exception("You must supply a valid Feed URL");
                }
                if ($this->HaveFeed($FeedURL, FALSE)) {
                    throw new Exception("The Feed URL you supplied is already part of an Active Feed");
                }
                $FeedCategoryID = GetValue('Category', $FormPostValues);
                if (!array_key_exists($FeedCategoryID, $Categories)) {
                    throw new Exception("You need to select a Category");
                }
                // Check feed is valid RSS:
                $Pr = new ProxyRequest();
                $FeedRSS = $Pr->Request(array('URL' => $FeedURL));
                if (!$FeedRSS) {
                    throw new Exception("The Feed URL you supplied is not available");
                }
                $RSSData = simplexml_load_string($FeedRSS);
                if (!$RSSData) {
                    throw new Exception("The Feed URL you supplied is not valid XML");
                }
                $Channel = GetValue('channel', $RSSData, FALSE);
                if (!$Channel) {
                    throw new Exception("The Feed URL you supplied is not an RSS stream");
                }
                $this->AddFeed($FeedURL, array('Historical' => $FormPostValues['Historical'], 'Refresh' => $FormPostValues['Refresh'], 'Category' => $FeedCategoryID, 'Added' => date('Y-m-d H:i:s'), 'LastImport' => "never"));
                $Sender->InformMessage(sprintf(T("Feed has been added"), $FeedURL));
                $Sender->Form->ClearInputs();
            } catch (Exception $e) {
                $Sender->Form->AddError(T($e->getMessage()));
            }
        }
        // Redirect('/plugin/feeddiscussions/');
        $this->Controller_Index($Sender);
    }