FeedWordPressSyndicationPage::multiadd_box PHP Method

multiadd_box() public method

public multiadd_box ( $page, $box = NULL )
    function multiadd_box($page, $box = NULL)
    {
        global $fwp_post;
        $localData = NULL;
        if (isset($_FILES['opml_upload']['name']) and strlen($_FILES['opml_upload']['name']) > 0) {
            $in = 'tag:localhost';
            /*FIXME: check whether $_FILES['opml_upload']['error'] === UPLOAD_ERR_OK or not...*/
            $localData = file_get_contents($_FILES['opml_upload']['tmp_name']);
            $merge_all = true;
        } elseif (isset($fwp_post['multilookup'])) {
            $in = $fwp_post['multilookup'];
            $merge_all = false;
        } elseif (isset($fwp_post['opml_lookup'])) {
            $in = $fwp_post['opml_lookup'];
            $merge_all = true;
        } else {
            $in = '';
            $merge_all = false;
        }
        if (strlen($in) > 0) {
            $lines = preg_split("/\\s+/", $in, -1, PREG_SPLIT_NO_EMPTY);
            $i = 0;
            ?>
			<form id="multiadd-form" action="<?php 
            print $this->form_action();
            ?>
" method="post">
			<div><?php 
            FeedWordPressCompatibility::stamp_nonce('feedwordpress_feeds');
            ?>
			<input type="hidden" name="multiadd" value="<?php 
            print FWP_SYNDICATE_NEW;
            ?>
" />
			<input type="hidden" name="confirm" value="multiadd" />

			<input type="hidden" name="multiadd" value="<?php 
            print FWP_SYNDICATE_NEW;
            ?>
" />
			<input type="hidden" name="confirm" value="multiadd" /></div>

			<div id="multiadd-status">
			<p><img src="<?php 
            print esc_url(admin_url('images/wpspin_light.gif'));
            ?>
" alt="" />
			Looking up feed information...</p>
			</div>

			<div id="multiadd-buttons">
			<input type="submit" class="button" name="cancel" value="<?php 
            _e(FWP_CANCEL_BUTTON);
            ?>
" />
			<input type="submit" class="button-primary" value="<?php 
            print _e('Subscribe to selected sources →');
            ?>
" />
			</div>
			
			<p><?php 
            _e('Here are the feeds that FeedWordPress has discovered from the addresses that you provided. To opt out of a subscription, unmark the checkbox next to the feed.');
            ?>
</p>
			
			<?php 
            print "<ul id=\"multiadd-list\">\n";
            flush();
            foreach ($lines as $line) {
                $url = trim($line);
                if (strlen($url) > 0) {
                    // First, use FeedFinder to check the URL.
                    if (is_null($localData)) {
                        $finder = new FeedFinder($url, false, 1);
                    } else {
                        $finder = new FeedFinder('tag:localhost', false, 1);
                        $finder->upload_data($localData);
                    }
                    $feeds = array_values(array_unique($finder->find()));
                    $found = false;
                    if (count($feeds) > 0) {
                        foreach ($feeds as $feed) {
                            $pie = FeedWordPress::fetch($feed);
                            if (!is_wp_error($pie)) {
                                $found = true;
                                $short_feed = esc_html(feedwordpress_display_url($feed));
                                $feed = esc_html($feed);
                                $title = esc_html($pie->get_title());
                                $checked = ' checked="checked"';
                                $link = esc_html($pie->get_link());
                                $this->display_multiadd_line(array('feed' => $feed, 'title' => $pie->get_title(), 'link' => $pie->get_link(), 'checked' => ' checked="checked"', 'i' => $i));
                                $i++;
                                // Increment field counter
                                if (!$merge_all) {
                                    // Break out after first find
                                    break;
                                }
                            }
                        }
                    }
                    if (!$found) {
                        $this->display_multiadd_line(array('feed' => $url, 'title' => feedwordpress_display_url($url), 'extra' => " [FeedWordPress couldn't detect any feeds for this URL.]", 'link' => NULL, 'checked' => '', 'i' => $i));
                        $i++;
                        // Increment field counter
                    }
                }
            }
            print "</ul>\n";
            ?>
			</form>
			
			<script type="text/javascript">
				jQuery(document).ready( function () {
					// Hide it now that we're done.
					jQuery('#multiadd-status').fadeOut(500 /*ms*/);
				} );
			</script>
			<?php 
        }
        $this->_sources = NULL;
        // Force reload of sources list
        return true;
        // Continue
    }