function dashboard_box($page, $box = NULL)
    {
        global $fwp_path;
        $links = FeedWordPress::syndicated_links(array("hide_invisible" => false));
        $sources = $this->sources('*');
        $visibility = 'Y';
        $hrefPrefix = $this->form_action();
        $activeHref = $hrefPrefix . '&visibility=Y';
        $inactiveHref = $hrefPrefix . '&visibility=N';
        $lastUpdate = get_option('feedwordpress_last_update_all', NULL);
        $automatic_updates = get_option('feedwordpress_automatic_updates', NULL);
        if ('init' == $automatic_updates) {
            $update_setting = 'automatically before page loads';
        } elseif ('shutdown' == $automatic_updates) {
            $update_setting = 'automatically after page loads';
        } else {
            $update_setting = 'using a cron job or manual check-ins';
        }
        // Hey ho, let's go...
        ?>
		<div style="float: left; background: #F5F5F5; padding-top: 5px; padding-right: 5px;"><a href="<?php 
        print $this->form_action();
        ?>
"><img src="<?php 
        print esc_html(plugins_url("/{$fwp_path}/feedwordpress.png"));
        ?>
" alt="" /></a></div>

		<p class="info" style="margin-bottom: 0px; border-bottom: 1px dotted black;">Managed by <a href="http://feedwordpress.radgeek.com/">FeedWordPress</a>
		<?php 
        print FEEDWORDPRESS_VERSION;
        ?>
.</p>
		<?php 
        if (FEEDWORDPRESS_BLEG) {
            ?>
		<p class="info" style="margin-top: 0px; font-style: italic; font-size: 75%; color: #666;">If you find this tool useful for your daily work, you can
		contribute to ongoing support and development with
		<a href="http://feedwordpress.radgeek.com/donate/">a modest donation</a>.</p>
		<br style="clear: left;" />
		<?php 
        }
        ?>

		<div class="feedwordpress-actions">
		<h4>Updates</h4>
		<ul class="options">
		<li><strong>Scheduled:</strong> <?php 
        print $update_setting;
        ?>
		(<a href="<?php 
        print $this->form_action('feeds-page.php');
        ?>
">change setting</a>)</li>

		<li><?php 
        if (!is_null($lastUpdate)) {
            ?>
		<strong>Last checked:</strong> <?php 
            print fwp_time_elapsed($lastUpdate);
            ?>
		<?php 
        } else {
            ?>
		<strong>Last checked:</strong> none yet
		<?php 
        }
        ?>
	</li>

		</ul>
		</div>
		
		<div class="feedwordpress-stats">
		<h4>Subscriptions</h4>
		<table>
		<tbody>
		<tr class="first">
		<td class="first b b-active"><a href="<?php 
        print esc_html($activeHref);
        ?>
"><?php 
        print count($sources['Y']);
        ?>
</a></td>
		<td class="t active"><a href="<?php 
        print esc_html($activeHref);
        ?>
">Active</a></td>
		</tr>
		
		<tr>
		<td class="b b-inactive"><a href="<?php 
        print esc_html($inactiveHref);
        ?>
"><?php 
        print count($sources['N']);
        ?>
</a></td>
		<td class="t inactive"><a href="<?php 
        print esc_html($inactiveHref);
        ?>
">Inactive</a></td>
		</tr>
		</table>
		</div>

		<div id="add-single-uri">
			<?php 
        if (count($sources['Y']) > 0) {
            ?>
			<form id="check-for-updates" action="<?php 
            print $this->form_action();
            ?>
" method="POST">
			<div class="container"><input type="submit" class="button-primary" name"update" value="<?php 
            print FWP_CHECK_FOR_UPDATES;
            ?>
" />
			<?php 
            FeedWordPressCompatibility::stamp_nonce('feedwordpress_feeds');
            ?>
			<input type="hidden" name="update_uri" value="*" /></div>
			</form>
			<?php 
        }
        ?>
		
		  <form id="syndicated-links" action="<?php 
        print $hrefPrefix;
        ?>
&amp;visibility=<?php 
        print $visibility;
        ?>
" method="post">
		  <div class="container"><?php 
        FeedWordPressCompatibility::stamp_nonce('feedwordpress_feeds');
        ?>
		  <label for="add-uri">Add:
		  <input type="text" name="lookup" id="add-uri" placeholder="Source URL"
		  value="Source URL" style="width: 55%;" /></label>
		
		  <?php 
        FeedWordPressSettingsUI::magic_input_tip_js('add-uri');
        ?>
		  <input type="hidden" name="action" value="<?php 
        print FWP_SYNDICATE_NEW;
        ?>
" />
		  <input style="vertical-align: middle;" type="image" src="<?php 
        print plugins_url('/' . $fwp_path . '/plus.png');
        ?>
" alt="<?php 
        print FWP_SYNDICATE_NEW;
        ?>
" /></div>
		  </form>
		</div> <!-- id="add-single-uri" -->
		
		<br style="clear: both;" />
		
		<?php 
    }
    function global_feeds_box($page, $box = NULL)
    {
        global $feedwordpress;
        $automatic_updates = $feedwordpress->automatic_update_hook(array('setting only' => true));
        $update_time_limit = (int) get_option('feedwordpress_update_time_limit');
        // Hey, ho, let's go...
        ?>

		<table class="edit-form">
		<?php 
        if ($page->for_default_settings()) {
            ?>

		<tr>
		<th scope="row">Updates:</th>
		<td><select id="automatic-updates-selector" name="automatic_updates" size="1" onchange="contextual_appearance('automatic-updates-selector', 'cron-job-explanation', null, 'no');">
		<option value="shutdown"<?php 
            echo $automatic_updates == 'shutdown' ? ' selected="selected"' : '';
            ?>
>automatically check for updates after pages load</option>
		<option value="init"<?php 
            echo $automatic_updates == 'init' ? ' selected="selected"' : '';
            ?>
>automatically check for updates before pages load</option>
		<option value="no"<?php 
            echo !$automatic_updates ? ' selected="selected"' : '';
            ?>
>cron job or manual updates</option>
		</select>
		<div id="cron-job-explanation" class="setting-description">
		<p><?php 
            $path = `which curl`;
            $opts = '--silent %s';
            if (is_null($path) or strlen(trim($path)) == 0) {
                $path = `which wget`;
                $opts = '-q -O - %s';
                if (is_null($path) or strlen(trim($path)) == 0) {
                    $path = '/usr/bin/curl';
                    $opts = '--silent %s';
                }
            }
            $path = preg_replace('/\\n+$/', '', $path);
            $crontab = `crontab -l`;
            $cmdline = $path . ' ' . sprintf($opts, get_bloginfo('url') . '?update_feedwordpress=1');
            ?>
If you want to use a cron job,
		you can perform scheduled updates by sending regularly-scheduled
		requests to <a href="<?php 
            bloginfo('url');
            ?>
?update_feedwordpress=1"><code><?php 
            bloginfo('url');
            ?>
?update_feedwordpress=1</code></a>
		For example, inserting the following line in your crontab:</p>
		<pre style="font-size: 0.80em"><code>*/10 * * * * <?php 
            print esc_html($cmdline);
            ?>
</code></pre>
		<p class="setting-description">will check in every 10 minutes
		and check for updates on any feeds that are ready to be polled for updates.</p>
		</div>
		</td>
		</tr>
		
		<?php 
        } else {
            /* Feed-specific settings */
            ?>

		<tr>
		<th scope="row"><?php 
            _e('Last update');
            ?>
:</th>
		<td><?php 
            if (isset($page->link->settings['update/last'])) {
                echo fwp_time_elapsed($page->link->settings['update/last']) . " ";
            } else {
                echo " none yet";
            }
            ?>
</td></tr>

		<tr><th><?php 
            _e('Next update');
            ?>
:</th>
		<td><?php 
            $holdem = isset($page->link->settings['update/hold']) ? $page->link->settings['update/hold'] : 'scheduled';
            ?>
		<select name="update_schedule">
		<option value="scheduled"<?php 
            echo $holdem == 'scheduled' ? ' selected="selected"' : '';
            ?>
>update on schedule <?php 
            echo " (";
            if (isset($page->link->settings['update/ttl']) and is_numeric($page->link->settings['update/ttl'])) {
                if (isset($page->link->settings['update/timed']) and $page->link->settings['update/timed'] == 'automatically') {
                    echo 'next: ';
                    $next = $page->link->settings['update/last'] + (int) $page->link->settings['update/ttl'] * 60;
                    if (strftime('%x', time()) != strftime('%x', $next)) {
                        echo strftime('%x', $next) . " ";
                    }
                    echo strftime('%X', $page->link->settings['update/last'] + (int) $page->link->settings['update/ttl'] * 60);
                } else {
                    echo "every " . $page->link->settings['update/ttl'] . " minute" . ($page->link->settings['update/ttl'] != 1 ? "s" : "");
                }
            } else {
                echo "next scheduled update";
            }
            echo ")";
            ?>
</option>
		<option value="next"<?php 
            echo $holdem == 'next' ? ' selected="selected"' : '';
            ?>
>update ASAP</option>
		<option value="ping"<?php 
            echo $holdem == 'ping' ? ' selected="selected"' : '';
            ?>
>update only when pinged</option>
		</select></td></tr>
		
		<?php 
        }
        ?>
		
		<tr>
		<th scope="row"><?php 
        print __('Update scheduling:');
        ?>
</th>
		<td><p style="margin-top:0px">How long should FeedWordPress wait between updates before it considers this feed ready to be polled for updates again?</p>
		<?php 
        $this->setting_radio_control('update/window', 'update_window', array(&$this, 'update_window_edit_box'), array('global-setting-default' => DEFAULT_UPDATE_PERIOD, 'default-input-name' => 'use_default_update_window', 'default-input-id' => 'use-default-update-window-yes', 'default-input-id-no' => 'use-default-update-window-no', 'labels' => array(&$this, 'update_window_currently')));
        ?>
</td>
		</tr>

		<tr>
		<th scope="row"><?php 
        print __('Minimum Interval:');
        ?>
</th>
		<td><p style="margin-top:0px">Some feeds include standard elements that
		request a specific update schedule. If the interval requested by the
		feed provider is <em>longer</em> than FeedWordPress's normal scheduling,
		FeedWordPress will always respect their request to slow down. But what
		should it do if the update interval is <em>shorter</em> than the schedule set above?</p>
		<?php 
        $this->setting_radio_control('update/minimum', 'update_minimum', array('no' => 'Speed up and accept the interval from the feed provider', 'yes' => 'Keep pace and use the longer scheduling from FeedWordPress'), array('setting-default' => NULL, 'global-setting-default' => 'no', 'default-input-value' => 'default'));
        ?>
		</td>
		</tr>
		
		<?php 
        if ($this->for_default_settings()) {
            ?>
		
		<tr>
		<th scope="row"><?php 
            print __('Time limit on updates');
            ?>
:</th>
		<td><select id="time-limit" name="update_time_limit" size="1" onchange="contextual_appearance('time-limit', 'time-limit-box', null, 'yes');">
		<option value="no"<?php 
            echo $update_time_limit > 0 ? '' : ' selected="selected"';
            ?>
>no time limit on updates</option>
		<option value="yes"<?php 
            echo $update_time_limit > 0 ? ' selected="selected"' : '';
            ?>
>limit updates to no more than...</option>
		</select>
		<span id="time-limit-box"><label><input type="text" name="time_limit_seconds" value="<?php 
            print $update_time_limit;
            ?>
" size="5" /> seconds</label></span>
		</tr>

		<?php 
        }
        ?>
		
		</table>
		
		<?php 
    }
示例#3
0
function fwp_syndication_manage_page_links_table_rows($links, $page, $visible = 'Y')
{
    $subscribed = 'Y' == strtoupper($visible);
    if ($subscribed or count($links) > 0) {
        ?>
	<table class="widefat<?php 
        if (!$subscribed) {
            ?>
 unsubscribed<?php 
        }
        ?>
">
	<thead>
	<tr>
	<th class="check-column" scope="col"><input type="checkbox" /></th>
	<th scope="col"><?php 
        _e('Name');
        ?>
</th>
	<th scope="col"><?php 
        _e('Feed');
        ?>
</th>
	<th scope="col"><?php 
        _e('Updated');
        ?>
</th>
	</tr>
	</thead>

	<tbody>
<?php 
        $alt_row = true;
        if (count($links) > 0) {
            foreach ($links as $link) {
                $trClass = array();
                // Prep: Get last updated timestamp
                $sLink = new SyndicatedLink($link->link_id);
                if (!is_null($sLink->setting('update/last'))) {
                    $lastUpdated = 'Last checked ' . fwp_time_elapsed($sLink->setting('update/last'));
                } else {
                    $lastUpdated = __('None yet');
                }
                // Prep: get last error timestamp, if any
                $fileSizeLines = array();
                if (is_null($sLink->setting('update/error'))) {
                    $errorsSince = '';
                    if (!is_null($sLink->setting('link/item count'))) {
                        $N = $sLink->setting('link/item count');
                        $fileSizeLines[] = sprintf($N == 1 ? __('%d item') : __('%d items'), $N);
                    }
                    if (!is_null($sLink->setting('link/filesize'))) {
                        $fileSizeLines[] = size_format($sLink->setting('link/filesize')) . ' total';
                    }
                } else {
                    $trClass[] = 'feed-error';
                    $theError = unserialize($sLink->setting('update/error'));
                    $errorsSince = "<div class=\"returning-errors\">" . "<p><strong>Returning errors</strong> since " . fwp_time_elapsed($theError['since']) . "</p>" . "<p>Most recent (" . fwp_time_elapsed($theError['ts']) . "):<br/><code>" . implode("</code><br/><code>", $theError['object']->get_error_messages()) . "</code></p>" . "</div>\n";
                }
                $nextUpdate = "<div style='max-width: 30.0em; font-size: 0.9em;'><div style='font-style:italic;'>";
                $ttl = $sLink->setting('update/ttl');
                if (is_numeric($ttl)) {
                    $next = $sLink->setting('update/last') + $sLink->setting('update/fudge') + (int) $ttl * 60;
                    if ('automatically' == $sLink->setting('update/timed')) {
                        if ($next < time()) {
                            $nextUpdate .= 'Ready and waiting to be updated since ';
                        } else {
                            $nextUpdate .= 'Scheduled for next update ';
                        }
                        $nextUpdate .= fwp_time_elapsed($next);
                        if (FEEDWORDPRESS_DEBUG) {
                            $nextUpdate .= " [" . ($next - time()) / 60 . " minutes]";
                        }
                    } else {
                        $lastUpdated .= " &middot; Next ";
                        if ($next < time()) {
                            $lastUpdated .= 'ASAP';
                        } elseif ($next - time() < 60) {
                            $lastUpdated .= fwp_time_elapsed($next);
                        } elseif ($next - time() < 60 * 60 * 24) {
                            $lastUpdated .= gmdate('g:ia', $next + get_option('gmt_offset') * 3600);
                        } else {
                            $lastUpdated .= gmdate('F j', $next + get_option('gmt_offset') * 3600);
                        }
                        $nextUpdate .= "Scheduled to be checked for updates every " . $ttl . " minute" . ($ttl != 1 ? "s" : "") . "</div><div style='size:0.9em; margin-top: 0.5em'>\tThis update schedule was requested by the feed provider";
                        if ($sLink->setting('update/xml')) {
                            $nextUpdate .= " using a standard <code style=\"font-size: inherit; padding: 0; background: transparent\">&lt;" . $sLink->setting('update/xml') . "&gt;</code> element";
                        }
                        $nextUpdate .= ".";
                    }
                } else {
                    $nextUpdate .= "Scheduled for update as soon as possible";
                }
                $nextUpdate .= "</div></div>";
                $fileSize = '';
                if (count($fileSizeLines) > 0) {
                    $fileSize = '<div>' . implode(" / ", $fileSizeLines) . "</div>";
                }
                unset($sLink);
                $alt_row = !$alt_row;
                if ($alt_row) {
                    $trClass[] = 'alternate';
                }
                ?>
	<tr<?php 
                echo count($trClass) > 0 ? ' class="' . implode(" ", $trClass) . '"' : '';
                ?>
>
	<th class="check-column" scope="row"><input type="checkbox" name="link_ids[]" value="<?php 
                echo $link->link_id;
                ?>
" /></th>
				<?php 
                $caption = strlen($link->link_rss) > 0 ? __('Switch Feed') : ($caption = __('Find Feed'));
                ?>
	<td>
	<strong><a href="<?php 
                print $page->admin_page_href('feeds-page.php', array(), $link);
                ?>
"><?php 
                print esc_html($link->link_name);
                ?>
</a></strong>
	<div class="row-actions"><?php 
                if ($subscribed) {
                    $page->display_feed_settings_page_links(array('before' => '<div><strong>Settings &gt;</strong> ', 'after' => '</div>', 'subscription' => $link));
                }
                ?>

	<div><strong>Actions &gt;</strong>
	<?php 
                if ($subscribed) {
                    ?>
	<a href="<?php 
                    print $page->admin_page_href('syndication.php', array('action' => 'feedfinder'), $link);
                    ?>
"><?php 
                    echo $caption;
                    ?>
</a>
	<?php 
                } else {
                    ?>
	<a href="<?php 
                    print $page->admin_page_href('syndication.php', array('action' => FWP_RESUB_CHECKED), $link);
                    ?>
"><?php 
                    _e('Re-subscribe');
                    ?>
</a>
	<?php 
                }
                ?>
	| <a href="<?php 
                print $page->admin_page_href('syndication.php', array('action' => 'Unsubscribe'), $link);
                ?>
"><?php 
                _e($subscribed ? 'Unsubscribe' : 'Delete permanently');
                ?>
</a>
	| <a href="<?php 
                print esc_html($link->link_url);
                ?>
"><?php 
                _e('View');
                ?>
</a></div>
	</div>
	</td>
				<?php 
                if (strlen($link->link_rss) > 0) {
                    ?>
	<td><a href="<?php 
                    echo esc_html($link->link_rss);
                    ?>
"><?php 
                    echo esc_html(feedwordpress_display_url($link->link_rss, 32));
                    ?>
</a></td>
				<?php 
                } else {
                    ?>
	<td class="feed-missing"><p><strong>no feed assigned</strong></p></td>
				<?php 
                }
                ?>

	<td><div style="float: right; padding-left: 10px">
	<input type="submit" class="button" name="update_uri[<?php 
                print esc_html($link->link_rss);
                ?>
]" value="<?php 
                _e('Update Now');
                ?>
" />
	</div>
	<?php 
                print $lastUpdated;
                ?>
	<?php 
                print $fileSize;
                ?>
	<?php 
                print $errorsSince;
                ?>
	<?php 
                print $nextUpdate;
                ?>
	</td>
	</tr>
			<?php 
            }
        } else {
            ?>
<tr><td colspan="4"><p>There are no websites currently listed for syndication.</p></td></tr>
<?php 
        }
        ?>
</tbody>
</table>
	<?php 
    }
}
    function global_feeds_box($page, $box = NULL)
    {
        $defaultUpdateWindow = get_option('feedwordpress_update_window');
        if (!is_numeric($defaultUpdateWindow)) {
            $defaultUpdateWindow = DEFAULT_UPDATE_PERIOD;
        } else {
            $defaultUpdateWindow = (int) $defaultUpdateWindow;
        }
        ?>
		
		<table class="edit-form">
		<?php 
        if ($page->for_default_settings()) {
            $automatic_updates = get_option('feedwordpress_automatic_updates');
            $update_time_limit = (int) get_option('feedwordpress_update_time_limit');
            ?>

		<tr>
		<th scope="row">Updates:</th>
		<td><select id="automatic-updates-selector" name="automatic_updates" size="1" onchange="contextual_appearance('automatic-updates-selector', 'cron-job-explanation', null, 'no');">
		<option value="shutdown"<?php 
            echo $automatic_updates == 'shutdown' ? ' selected="selected"' : '';
            ?>
>automatically check for updates after pages load</option>
		<option value="init"<?php 
            echo $automatic_updates == 'init' ? ' selected="selected"' : '';
            ?>
>automatically check for updates before pages load</option>
		<option value="no"<?php 
            echo !$automatic_updates ? ' selected="selected"' : '';
            ?>
>cron job or manual updates</option>
		</select>
		<div id="cron-job-explanation" class="setting-description">
		<p>If you want to use a cron job,
		you can perform scheduled updates by sending regularly-scheduled
		requests to <a href="<?php 
            bloginfo('url');
            ?>
?update_feedwordpress=1"><code><?php 
            bloginfo('url');
            ?>
?update_feedwordpress=1</code></a>
		For example, inserting the following line in your crontab:</p>
		<pre style="font-size: 0.80em"><code>*/10 * * * * /usr/bin/curl --silent <?php 
            bloginfo('url');
            ?>
?update_feedwordpress=1</code></pre>
		<p class="setting-description">will check in every 10 minutes
		and check for updates on any feeds that are ready to be polled for updates.</p>
		</div>
		</td>
		</tr>
		
		<tr>
		<th scope="row"><?php 
            print __('Update scheduling:');
            ?>
</th>
		<td><p style="margin-top:0px">How long should FeedWordPress wait between updates before it considers a feed ready to be polled for updates again?</p>
		<p style="font-style: italic; margin-left: 2.0em"><label>Wait <input type="text" name="update_window" value="<?php 
            print $defaultUpdateWindow;
            ?>
" size="4" /> minutes between polling.</label></p>
		<div class="setting-description">
		<p<?php 
            if ($defaultUpdateWindow < 50) {
                ?>
 style="color: white; background-color: #703030; padding: 1.0em;"<?php 
            }
            ?>
><strong>Recommendation.</strong> Unless you are positive that you have the webmaster's permission, you generally should not set FeedWordPress to poll feeds more frequently than once every 60 minutes. Many webmasters consider more frequent automated polling to be abusive, and may complain to your web host, or ban your IP address, as retaliation for hammering their servers too hard.</p>
		<p><strong>Note.</strong> This is a default setting that FeedWordPress uses to schedule updates when the feed does not provide any scheduling requests. If a feed does provide update scheduling information (through elements such as <code>&lt;rss:ttl&gt;</code> or <code>&lt;sy:updateFrequency&gt;</code>), FeedWordPress will respect the feed's request.</p>
		</div></td>
		</tr>
		
		<tr>
		<th scope="row"><?php 
            print __('Time limit on updates');
            ?>
:</th>
		<td><select id="time-limit" name="update_time_limit" size="1" onchange="contextual_appearance('time-limit', 'time-limit-box', null, 'yes');">
		<option value="no"<?php 
            echo $update_time_limit > 0 ? '' : ' selected="selected"';
            ?>
>no time limit on updates</option>
		<option value="yes"<?php 
            echo $update_time_limit > 0 ? ' selected="selected"' : '';
            ?>
>limit updates to no more than...</option>
		</select>
		<span id="time-limit-box"><label><input type="text" name="time_limit_seconds" value="<?php 
            print $update_time_limit;
            ?>
" size="5" /> seconds</label></span>
		</tr>

		<?php 
        } else {
            $useDefaultUpdateWindow = !isset($page->link->settings['update/window']);
            $updateWindow = isset($page->link->settings['update/window']) ? $page->link->settings['update/window'] : null;
            if (!is_numeric($updateWindow)) {
                $updateWindow = 60;
            } else {
                $updateWindow = (int) $updateWindow;
            }
            ?>

		<tr>
		<th scope="row"><?php 
            _e('Last update');
            ?>
:</th>
		<td><?php 
            if (isset($page->link->settings['update/last'])) {
                echo fwp_time_elapsed($page->link->settings['update/last']) . " ";
            } else {
                echo " none yet";
            }
            ?>
</td></tr>

		<tr><th><?php 
            _e('Next update');
            ?>
:</th>
		<td><?php 
            $holdem = isset($page->link->settings['update/hold']) ? $page->link->settings['update/hold'] : 'scheduled';
            ?>
		<select name="update_schedule">
		<option value="scheduled"<?php 
            echo $holdem == 'scheduled' ? ' selected="selected"' : '';
            ?>
>update on schedule <?php 
            echo " (";
            if (isset($page->link->settings['update/ttl']) and is_numeric($page->link->settings['update/ttl'])) {
                if (isset($page->link->settings['update/timed']) and $page->link->settings['update/timed'] == 'automatically') {
                    echo 'next: ';
                    $next = $page->link->settings['update/last'] + (int) $page->link->settings['update/ttl'] * 60;
                    if (strftime('%x', time()) != strftime('%x', $next)) {
                        echo strftime('%x', $next) . " ";
                    }
                    echo strftime('%X', $page->link->settings['update/last'] + (int) $page->link->settings['update/ttl'] * 60);
                } else {
                    echo "every " . $page->link->settings['update/ttl'] . " minute" . ($page->link->settings['update/ttl'] != 1 ? "s" : "");
                }
            } else {
                echo "next scheduled update";
            }
            echo ")";
            ?>
</option>
		<option value="next"<?php 
            echo $holdem == 'next' ? ' selected="selected"' : '';
            ?>
>update ASAP</option>
		<option value="ping"<?php 
            echo $holdem == 'ping' ? ' selected="selected"' : '';
            ?>
>update only when pinged</option>
		</select></td></tr>

		<tr>
		<th scope="row"><?php 
            print __('Update scheduling:');
            ?>
</th>
		<td><p style="margin-top:0px">How long should FeedWordPress wait between updates before it considers this feed ready to be polled for updates again?</p>
		<ul>
		<li><label><input type="radio" name="use_default_update_window" value="Yes" <?php 
            if ($useDefaultUpdateWindow) {
                ?>
checked="checked"<?php 
            }
            ?>
 /> Use site-wide setting (currently <?php 
            print $defaultUpdateWindow;
            ?>
 minutes)</li>
		<li><label><input type="radio" name="use_default_update_window" value="No" <?php 
            if (!$useDefaultUpdateWindow) {
                ?>
checked="checked"<?php 
            }
            ?>
 /> Wait <input type="text" name="update_window" value="<?php 
            print $updateWindow;
            ?>
" size="4" /> minutes between polling.</label></li>
		</ul>
		
		<div class="setting-description">
		<p<?php 
            if ($updateWindow < 50) {
                ?>
 style="color: white; background-color: #703030; padding: 1.0em;"<?php 
            }
            ?>
><strong>Recommendation.</strong> Unless you are positive that you have the webmaster's permission, you generally should not set FeedWordPress to poll feeds more frequently than once every 60 minutes. Many webmasters consider more frequent automated polling to be abusive, and may complain to your web host, or ban your IP address, as retaliation for hammering their servers too hard.</p>
		<p><strong>Note.</strong> This is a default setting that FeedWordPress uses to schedule updates when the feed does not provide any scheduling requests. If this feed does provide update scheduling information (through elements such as <code>&lt;rss:ttl&gt;</code> or <code>&lt;sy:updateFrequency&gt;</code>), FeedWordPress will respect the feed's request.</p>
		</div></td>
		</tr>
		<?php 
        }
        ?>


</table>
<script type="text/javascript">
contextual_appearance('automatic-updates-selector', 'cron-job-explanation', null, 'no');
contextual_appearance('time-limit', 'time-limit-box', null, 'yes');
</script>
<?php 
    }
function fwp_linkedit_page()
{
    global $wpdb, $wp_db_version;
    check_admin_referer();
    // Make sure we arrived here from the Dashboard
    $special_settings = array('cats', 'cat_split', 'hardcode name', 'hardcode url', 'hardcode description', 'hardcode categories', 'post status', 'comment status', 'ping status', 'unfamiliar author', 'unfamliar categories', 'unfamiliar category', 'map authors', 'tags', 'update/.*', 'feed/.*', 'link/.*');
    if (!current_user_can('manage_links')) {
        die(__("Cheatin' uh ?"));
    } elseif (isset($_REQUEST['feedfinder'])) {
        return fwp_feedfinder_page();
        // re-route to Feed Finder page
    } else {
        $link_id = (int) $_REQUEST['link_id'];
        $link =& new SyndicatedLink($link_id);
        if ($link->found()) {
            if (isset($GLOBALS['fwp_post']['save'])) {
                $alter = array();
                // custom feed settings first
                foreach ($GLOBALS['fwp_post']['notes'] as $mn) {
                    $mn['key0'] = trim($mn['key0']);
                    $mn['key1'] = trim($mn['key1']);
                    if (preg_match("^((" . implode(')|(', $special_settings) . "))\$i", $mn['key1'])) {
                        $mn['key1'] = 'user/' . $mn['key1'];
                    }
                    if (strlen($mn['key0']) > 0) {
                        unset($link->settings[$mn['key0']]);
                        // out with the old
                    }
                    if ($mn['action'] == 'update' and strlen($mn['key1']) > 0) {
                        $link->settings[$mn['key1']] = $mn['value'];
                        // in with the new
                    }
                }
                // now stuff through the web form
                // hardcoded feed info
                if (isset($GLOBALS['fwp_post']['hardcode_name'])) {
                    $link->settings['hardcode name'] = $GLOBALS['fwp_post']['hardcode_name'];
                    if (FeedWordPress::affirmative($link->settings, 'hardcode name')) {
                        $alter[] = "link_name = '" . $wpdb->escape($GLOBALS['fwp_post']['name']) . "'";
                    }
                }
                if (isset($GLOBALS['fwp_post']['hardcode_description'])) {
                    $link->settings['hardcode description'] = $GLOBALS['fwp_post']['hardcode_description'];
                    if (FeedWordPress::affirmative($link->settings, 'hardcode description')) {
                        $alter[] = "link_description = '" . $wpdb->escape($GLOBALS['fwp_post']['description']) . "'";
                    }
                }
                if (isset($GLOBALS['fwp_post']['hardcode_url'])) {
                    $link->settings['hardcode url'] = $GLOBALS['fwp_post']['hardcode_url'];
                    if (FeedWordPress::affirmative($link->settings, 'hardcode url')) {
                        $alter[] = "link_url = '" . $wpdb->escape($GLOBALS['fwp_post']['linkurl']) . "'";
                    }
                }
                // Update scheduling
                if (isset($GLOBALS['fwp_post']['update_schedule'])) {
                    $link->settings['update/hold'] = $GLOBALS['fwp_post']['update_schedule'];
                }
                // Categories
                if (isset($GLOBALS['fwp_post']['post_category'])) {
                    $link->settings['cats'] = array();
                    foreach ($GLOBALS['fwp_post']['post_category'] as $cat_id) {
                        $link->settings['cats'][] = '{#' . $cat_id . '}';
                    }
                } else {
                    unset($link->settings['cats']);
                }
                // Tags
                if (isset($GLOBALS['fwp_post']['tags_input'])) {
                    $link->settings['tags'] = array();
                    foreach (explode(',', $GLOBALS['fwp_post']['tags_input']) as $tag) {
                        $link->settings['tags'][] = trim($tag);
                    }
                }
                // Post status, comment status, ping status
                foreach (array('post', 'comment', 'ping') as $what) {
                    $sfield = "feed_{$what}_status";
                    if (isset($GLOBALS['fwp_post'][$sfield])) {
                        if ($GLOBALS['fwp_post'][$sfield] == 'site-default') {
                            unset($link->settings["{$what} status"]);
                        } else {
                            $link->settings["{$what} status"] = $GLOBALS['fwp_post'][$sfield];
                        }
                    }
                }
                // Unfamiliar author, unfamiliar categories
                foreach (array("author", "category") as $what) {
                    $sfield = "unfamiliar_{$what}";
                    if (isset($GLOBALS['fwp_post'][$sfield])) {
                        if ('site-default' == $GLOBALS['fwp_post'][$sfield]) {
                            unset($link->settings["unfamiliar {$what}"]);
                        } elseif ('newuser' == $GLOBALS['fwp_post'][$sfield]) {
                            $newuser_name = trim($GLOBALS['fwp_post']["{$sfield}_newuser"]);
                            if (strlen($newuser_name) > 0) {
                                $userdata = array();
                                $userdata['ID'] = NULL;
                                $userdata['user_login'] = sanitize_user($newuser_name);
                                $userdata['user_login'] = apply_filters('pre_user_login', $userdata['user_login']);
                                $userdata['user_nicename'] = sanitize_title($newuser_name);
                                $userdata['user_nicename'] = apply_filters('pre_user_nicename', $userdata['user_nicename']);
                                $userdata['display_name'] = $wpdb->escape($newuser_name);
                                $newuser_id = wp_insert_user($userdata);
                                if (is_numeric($newuser_id)) {
                                    $link->settings["unfamiliar {$what}"] = $newuser_id;
                                } else {
                                    // TODO: Add some error detection and reporting
                                }
                            } else {
                                // TODO: Add some error reporting
                            }
                        } else {
                            $link->settings["unfamiliar {$what}"] = $GLOBALS['fwp_post'][$sfield];
                        }
                    }
                }
                // Handle author mapping rules
                if (isset($GLOBALS['fwp_post']['author_rules_name']) and isset($GLOBALS['fwp_post']['author_rules_action'])) {
                    unset($link->settings['map authors']);
                    foreach ($GLOBALS['fwp_post']['author_rules_name'] as $key => $name) {
                        // Normalize for case and whitespace
                        $name = strtolower(trim($name));
                        $author_action = strtolower(trim($GLOBALS['fwp_post']['author_rules_action'][$key]));
                        if (strlen($name) > 0) {
                            if ('newuser' == $author_action) {
                                $newuser_name = trim($GLOBALS['fwp_post']['author_rules_newuser'][$key]);
                                if (strlen($newuser_name) > 0) {
                                    $userdata = array();
                                    $userdata['ID'] = NULL;
                                    $userdata['user_login'] = sanitize_user($newuser_name);
                                    $userdata['user_login'] = apply_filters('pre_user_login', $userdata['user_login']);
                                    $userdata['user_nicename'] = sanitize_title($newuser_name);
                                    $userdata['user_nicename'] = apply_filters('pre_user_nicename', $userdata['user_nicename']);
                                    $userdata['display_name'] = $wpdb->escape($newuser_name);
                                    $newuser_id = wp_insert_user($userdata);
                                    if (is_numeric($newuser_id)) {
                                        $link->settings['map authors']['name'][$name] = $newuser_id;
                                    } else {
                                        // TODO: Add some error detection and reporting
                                    }
                                } else {
                                    // TODO: Add some error reporting
                                }
                            } else {
                                $link->settings['map authors']['name'][$name] = $author_action;
                            }
                        }
                    }
                }
                if (isset($GLOBALS['fwp_post']['add_author_rule_name']) and isset($GLOBALS['fwp_post']['add_author_rule_action'])) {
                    $name = strtolower(trim($GLOBALS['fwp_post']['add_author_rule_name']));
                    $author_action = strtolower(trim($GLOBALS['fwp_post']['add_author_rule_action']));
                    if (strlen($name) > 0) {
                        if ('newuser' == $author_action) {
                            $newuser_name = trim($GLOBALS['fwp_post']['add_author_rule_newuser']);
                            if (strlen($newuser_name) > 0) {
                                $userdata = array();
                                $userdata['ID'] = NULL;
                                $userdata['user_login'] = sanitize_user($newuser_name);
                                $userdata['user_login'] = apply_filters('pre_user_login', $userdata['user_login']);
                                $userdata['user_nicename'] = sanitize_title($newuser_name);
                                $userdata['user_nicename'] = apply_filters('pre_user_nicename', $userdata['user_nicename']);
                                $userdata['display_name'] = $wpdb->escape($newuser_name);
                                $newuser_id = wp_insert_user($userdata);
                                if (is_numeric($newuser_id)) {
                                    $link->settings['map authors']['name'][$name] = $newuser_id;
                                } else {
                                    // TODO: Add some error detection and reporting
                                }
                            } else {
                                // TODO: Add some error reporting
                            }
                        } else {
                            $link->settings['map authors']['name'][$name] = $author_action;
                        }
                    }
                }
                if (isset($GLOBALS['fwp_post']['cat_split'])) {
                    if (strlen(trim($GLOBALS['fwp_post']['cat_split'])) > 0) {
                        $link->settings['cat_split'] = trim($GLOBALS['fwp_post']['cat_split']);
                    } else {
                        unset($link->settings['cat_split']);
                    }
                }
                $alter[] = "link_notes = '" . $wpdb->escape($link->settings_to_notes()) . "'";
                $alter_set = implode(", ", $alter);
                // issue update query
                $result = $wpdb->query("\n\t\t\t\tUPDATE {$wpdb->links}\n\t\t\t\tSET {$alter_set}\n\t\t\t\tWHERE link_id='{$link_id}'\n\t\t\t\t");
                $updated_link = true;
                // reload link information from DB
                if (function_exists('clean_bookmark_cache')) {
                    clean_bookmark_cache($link_id);
                }
                $link =& new SyndicatedLink($link_id);
            } else {
                $updated_link = false;
            }
            $db_link = $link->link;
            $link_url = wp_specialchars($db_link->link_url, 1);
            $link_name = wp_specialchars($db_link->link_name, 1);
            $link_description = wp_specialchars($db_link->link_description, 'both');
            $link_rss_uri = wp_specialchars($db_link->link_rss, 'both');
            $post_status_global = get_option('feedwordpress_syndicated_post_status');
            $comment_status_global = get_option('feedwordpress_syndicated_comment_status');
            $ping_status_global = get_option('feedwordpress_syndicated_ping_status');
            $status['post'] = array('publish' => '', 'private' => '', 'draft' => '', 'site-default' => '');
            if (SyndicatedPost::use_api('post_status_pending')) {
                $status['post']['pending'] = '';
            }
            $status['comment'] = array('open' => '', 'closed' => '', 'site-default' => '');
            $status['ping'] = array('open' => '', 'closed' => '', 'site-default' => '');
            foreach (array('post', 'comment', 'ping') as $what) {
                if (isset($link->settings["{$what} status"])) {
                    $status[$what][$link->settings["{$what} status"]] = ' checked="checked"';
                } else {
                    $status[$what]['site-default'] = ' checked="checked"';
                }
            }
            $unfamiliar['author'] = array('create' => '', 'default' => '', 'filter' => '');
            $unfamiliar['category'] = array('create' => '', 'tag' => '', 'default' => '', 'filter' => '');
            foreach (array('author', 'category') as $what) {
                if (is_string($link->settings["unfamiliar {$what}"]) and array_key_exists($link->settings["unfamiliar {$what}"], $unfamiliar[$what])) {
                    $key = $link->settings["unfamiliar {$what}"];
                } else {
                    $key = 'site-default';
                }
                $unfamiliar[$what][$key] = ' checked="checked"';
            }
            if (is_array($link->settings['cats'])) {
                $cats = $link->settings['cats'];
            } else {
                $cats = array();
            }
            $dogs = SyndicatedPost::category_ids($cats, NULL);
        } else {
            die(__('Link not found.'));
        }
        ?>
<script type="text/javascript">
	function flip_hardcode (item) {
		ed=document.getElementById('basics-'+item+'-edit');
		view=document.getElementById('basics-'+item+'-view');
		
		o = document.getElementById('basics-hardcode-'+item);
		if (o.value=='yes') { ed.style.display='inline'; view.style.display='none'; }
		else { ed.style.display='none'; view.style.display='inline'; }
	}
	function flip_newuser (item) {
		rollup=document.getElementById(item);
		newuser=document.getElementById(item+'-newuser');
		sitewide=document.getElementById(item+'-default');
		if (rollup) {
			if ('newuser'==rollup.value) {
				if (newuser) newuser.style.display='block';
				if (sitewide) sitewide.style.display='none';
			} else if ('site-default'==rollup.value) {
				if (newuser) newuser.style.display='none';
				if (sitewide) sitewide.style.display='block';
			} else {
				if (newuser) newuser.style.display='none';
				if (sitewide) sitewide.style.display='none';
			}
		}
	}
</script>

<?php 
        if ($updated_link) {
            ?>
<div class="updated"><p>Syndicated feed settings updated.</p></div>
<?php 
        }
        ?>

<form action="admin.php?page=<?php 
        print $GLOBALS['fwp_path'];
        ?>
/<?php 
        echo basename(__FILE__);
        ?>
" method="post">
<div class="wrap">
<input type="hidden" name="link_id" value="<?php 
        echo $link_id;
        ?>
" />
<input type="hidden" name="action" value="linkedit" />
<input type="hidden" name="save" value="link" />

<h2>Edit a syndicated feed:</h2>
<div id="poststuff">
<?php 
        fwp_linkedit_single_submit($status);
        ?>

<div id="post-body">
<?php 
        fwp_option_box_opener('Feed Information', 'feedinformationdiv');
        ?>
	<table class="editform" width="100%" cellspacing="2" cellpadding="5">
	<tr>
	<th scope="row" width="20%"><?php 
        _e('Feed URI:');
        ?>
</th>
	<td width="60%"><a href="<?php 
        echo wp_specialchars($link_rss_uri, 'both');
        ?>
"><?php 
        echo $link_rss_uri;
        ?>
</a>
	(<a href="<?php 
        echo FEEDVALIDATOR_URI;
        ?>
?url=<?php 
        echo urlencode($link_rss_uri);
        ?>
"
	title="Check feed &lt;<?php 
        echo wp_specialchars($link_rss_uri, 'both');
        ?>
&gt; for validity">validate</a>)
	</td>
	<td width="20%"><input type="submit" name="feedfinder" value="switch &rarr;" style="font-size:smaller" /></td>
	</tr>
	<tr>
	<th scope="row" width="20%"><?php 
        _e('Link Name:');
        ?>
</th>
	<td width="60%"><input type="text" id="basics-name-edit" name="name"
	value="<?php 
        echo $link_name;
        ?>
" style="width: 95%" />
	<span id="basics-name-view"><strong><?php 
        echo $link_name;
        ?>
</strong></span>
	</td>
	<td>
	<select id="basics-hardcode-name" onchange="flip_hardcode('name')" name="hardcode_name">
	<option value="no" <?php 
        echo $link->hardcode('name') ? '' : 'selected="selected"';
        ?>
>update automatically</option>
	<option value="yes" <?php 
        echo $link->hardcode('name') ? 'selected="selected"' : '';
        ?>
>edit manually</option>
	</select>
	</td>
	</tr>
	<tr>
	<th scope="row" width="20%"><?php 
        _e('Short description:');
        ?>
</th>
	<td width="60%">
	<input id="basics-description-edit" type="text" name="description" value="<?php 
        echo $link_description;
        ?>
" style="width: 95%" />
	<span id="basics-description-view"><strong><?php 
        echo $link_description;
        ?>
</strong></span>
	</td>
	<td>
	<select id="basics-hardcode-description" onchange="flip_hardcode('description')"
	name="hardcode_description">
	<option value="no" <?php 
        echo $link->hardcode('description') ? '' : 'selected="selected"';
        ?>
>update automatically</option>
	<option value="yes" <?php 
        echo $link->hardcode('description') ? 'selected="selected"' : '';
        ?>
>edit manually</option>
	</select></td>
	</tr>
	<tr>
	<th width="20%" scope="row"><?php 
        _e('Homepage:');
        ?>
</th>
	<td width="60%">
	<input id="basics-url-edit" type="text" name="linkurl" value="<?php 
        echo $link_url;
        ?>
" style="width: 95%;" />
	<a id="basics-url-view" href="<?php 
        echo $link_url;
        ?>
"><?php 
        echo $link_url;
        ?>
</a></td>
	<td>
	<select id="basics-hardcode-url" onchange="flip_hardcode('url')" name="hardcode_url">
	<option value="no"<?php 
        echo $link->hardcode('url') ? '' : ' selected="selected"';
        ?>
>update automatically</option>
	<option value="yes"<?php 
        echo $link->hardcode('url') ? ' selected="selected"' : '';
        ?>
>edit manually</option>
	</select></td></tr>
	
	<tr>
	<th width="20%"><?php 
        _e('Last update');
        ?>
:</th>
	<td colspan="2"><?php 
        if (isset($link->settings['update/last'])) {
            echo fwp_time_elapsed($link->settings['update/last']) . " ";
        } else {
            echo " none yet";
        }
        ?>
</td></tr>
	<tr><th width="20%">Next update:</th>
	<td colspan="2"><?php 
        $holdem = isset($link->settings['update/hold']) ? $link->settings['update/hold'] : 'scheduled';
        ?>
	<select name="update_schedule">
	<option value="scheduled"<?php 
        echo $holdem == 'scheduled' ? ' selected="selected"' : '';
        ?>
>update on schedule <?php 
        echo " (";
        if (isset($link->settings['update/ttl']) and is_numeric($link->settings['update/ttl'])) {
            if (isset($link->settings['update/timed']) and $link->settings['update/timed'] == 'automatically') {
                echo 'next: ';
                $next = $link->settings['update/last'] + (int) $link->settings['update/ttl'] * 60;
                if (strftime('%x', time()) != strftime('%x', $next)) {
                    echo strftime('%x', $next) . " ";
                }
                echo strftime('%X', $link->settings['update/last'] + (int) $link->settings['update/ttl'] * 60);
            } else {
                echo "every " . $link->settings['update/ttl'] . " minute" . ($link->settings['update/ttl'] != 1 ? "s" : "");
            }
        } else {
            echo "next scheduled update";
        }
        echo ")";
        ?>
</option>
	<option value="next"<?php 
        echo $holdem == 'next' ? ' selected="selected"' : '';
        ?>
>update ASAP</option>
	<option value="ping"<?php 
        echo $holdem == 'ping' ? ' selected="selected"' : '';
        ?>
>update only when pinged</option>
	</select></tr>
	</table>
<?php 
        fwp_option_box_closer();
        ?>

<script type="text/javascript">
flip_hardcode('name');
flip_hardcode('description');
flip_hardcode('url');
</script>

<?php 
        fwp_linkedit_periodic_submit();
        ?>

<?php 
        if (!(isset($wp_db_version) and $wp_db_version >= FWP_SCHEMA_25)) {
            fwp_option_box_opener('Syndicated Posts', 'syndicatedpostsdiv', 'postbox');
            ?>
<table class="editform" width="75%" cellspacing="2" cellpadding="5">
<tr><th width="27%" scope="row" style="vertical-align:top">Publication:</th>
<td width="73%" style="vertical-align:top"><ul style="margin:0; list-style:none">
<li><label><input type="radio" name="feed_post_status" value="site-default"
<?php 
            echo $status['post']['site-default'];
            ?>
 /> Use site-wide setting from <a href="admin.php?page=<?php 
            print $GLOBALS['fwp_path'];
            ?>
/syndication-options.php">Syndication Options</a>
(currently: <strong><?php 
            echo $post_status_global ? $post_status_global : 'publish';
            ?>
</strong>)</label></li>
<li><label><input type="radio" name="feed_post_status" value="publish"
<?php 
            echo $status['post']['publish'];
            ?>
 /> Publish posts from this feed immediately</label></li>

<?php 
            if (SyndicatedPost::use_api('post_status_pending')) {
                ?>
<li><label><input type="radio" name="feed_post_status" value="pending"
<?php 
                echo $status['post']['pending'];
                ?>
/> Hold posts from this feed for review; mark as Pending</label></li>
<?php 
            }
            ?>

<li><label><input type="radio" name="feed_post_status" value="draft"
<?php 
            echo $status['post']['draft'];
            ?>
 /> Save posts from this feed as drafts</label></li>
<li><label><input type="radio" name="feed_post_status" value="private"
<?php 
            echo $status['post']['private'];
            ?>
 /> Save posts from this feed as private posts</label></li>
</ul></td>
</tr>
</table>
<?php 
            fwp_option_box_closer();
            fwp_linkedit_periodic_submit();
        }
        fwp_option_box_opener(__('Categories'), 'categorydiv', 'postbox');
        fwp_category_box($dogs, 'all syndicated posts from this feed');
        ?>
<table>
<tr>
<th width="20%" scope="row" style="vertical-align:top">Unfamiliar categories:</th>
<td width="80%"><p>When one of the categories on a syndicated post is a category that FeedWordPress has not encountered before ...</p>

<ul style="margin: 0; list-style:none">
<li><label><input type="radio" name="unfamiliar_category" value="site-default"<?php 
        echo $unfamiliar['category']['site-default'];
        ?>
 /> use the site-wide setting from <a href="admin.php?page=<?php 
        print $GLOBALS['fwp_path'];
        ?>
/syndication-options.php">Syndication Options</a>
(currently <strong><?php 
        echo FeedWordPress::on_unfamiliar('category');
        ?>
</strong>)</label></li>
<li><label><input type="radio" name="unfamiliar_category" value="create"<?php 
        echo $unfamiliar['category']['create'];
        ?>
 /> create a new category</label></li>
<?php 
        if (fwp_test_wp_version(FWP_SCHEMA_23)) {
            ?>
<li><label><input type="radio" name="unfamiliar_category" value="tag"<?php 
            echo $unfamiliar['category']['tag'];
            ?>
/> create a new tag</label></li>
<?php 
        }
        ?>
<li><label><input type="radio" name="unfamiliar_category" value="default"<?php 
        echo $unfamiliar['category']['default'];
        ?>
 /> don't create new categories<?php 
        if (fwp_test_wp_version(FWP_SCHEMA_23)) {
            ?>
 or tags<?php 
        }
        ?>
</label></li>
<li><label><input type="radio" name="unfamiliar_category" value="filter"<?php 
        echo $unfamiliar['category']['filter'];
        ?>
 /> don't create new categories<?php 
        if (fwp_test_wp_version(FWP_SCHEMA_23)) {
            ?>
 or tags<?php 
        }
        ?>
 and don't syndicate posts unless they match at least one familiar category</label></li>
</ul></td>
</tr>

<tr>
<th width="20%" scope="row" style="vertical-align:top">Multiple categories:</th>
<td width="80%"> 
<input type="text" size="20" id="cat_split" name="cat_split" value="<?php 
        if (isset($link->settings['cat_split'])) {
            echo htmlspecialchars($link->settings['cat_split']);
        }
        ?>
" /><br/>
Enter a <a href="http://us.php.net/manual/en/reference.pcre.pattern.syntax.php">Perl-compatible regular expression</a> here if the feed provides multiple
categories in a single category element. The regular expression should match
the characters used to separate one category from the next. If the feed uses
spaces (like <a href="http://del.icio.us/">del.icio.us</a>), use the pattern "\s".
If the feed does not provide multiple categories in a single element, leave this
blank.</td>
</tr>
</table>
<?php 
        fwp_option_box_closer();
        fwp_linkedit_periodic_submit();
        if (isset($wp_db_version) and $wp_db_version >= FWP_SCHEMA_25) {
            fwp_tags_box($link->settings['tags']);
            fwp_linkedit_periodic_submit();
        }
        ?>

<?php 
        fwp_option_box_opener('Syndicated Authors', 'authordiv', 'postbox');
        $authorlist = fwp_author_list();
        ?>
<table>
<tr><th colspan="3" style="text-align: left; padding-top: 1.0em; border-bottom: 1px dotted black;">For posts by authors that haven't been syndicated before:</th></tr>
<tr>
  <th style="text-align: left">Posts by new authors</th>
  <td> 
  <select id="unfamiliar-author" name="unfamiliar_author" onchange="flip_newuser('unfamiliar-author');">
    <option value="site-default"<?php 
        if (!isset($link->settings['unfamiliar author'])) {
            ?>
selected="selected"<?php 
        }
        ?>
>are handled using site-wide settings</option>
    <option value="create"<?php 
        if ('create' == $link->settings['unfamiliar author']) {
            ?>
selected="selected"<?php 
        }
        ?>
>create a new author account</option>
    <?php 
        foreach ($authorlist as $author_id => $author_name) {
            ?>
      <option value="<?php 
            echo $author_id;
            ?>
"<?php 
            if ($author_id == $link->settings['unfamiliar author']) {
                ?>
selected="selected"<?php 
            }
            ?>
>are assigned to <?php 
            echo $author_name;
            ?>
</option>
    <?php 
        }
        ?>
    <option value="newuser">will be assigned to a new user...</option>
    <option value="filter"<?php 
        if ('filter' == $link->settings['unfamiliar author']) {
            ?>
selected="selected"<?php 
        }
        ?>
>get filtered out</option>
  </select>
  </td>
  <td>
  <div id="unfamiliar-author-default">Site-wide settings can be set in <a href="admin.php?page=<?php 
        print $GLOBALS['fwp_path'];
        ?>
/syndication-options.php">Syndication Options</a></div>
  <div id="unfamiliar-author-newuser">named <input type="text" name="unfamiliar_author_newuser" value="" /></div>
  </td>
</tr>

<tr><th colspan="3" style="text-align: left; padding-top: 1.0em; border-bottom: 1px dotted black;">For posts by specific authors. Blank out a name to delete the rule.</th></tr>

<?php 
        if (isset($link->settings['map authors'])) {
            $i = 0;
            foreach ($link->settings['map authors'] as $author_rules) {
                foreach ($author_rules as $author_name => $author_action) {
                    $i++;
                    ?>
<tr>
  <th style="text-align: left">Posts by <input type="text" name="author_rules_name[]" value="<?php 
                    echo htmlspecialchars($author_name);
                    ?>
" /></th>
  <td>
  <select id="author-rules-<?php 
                    echo $i;
                    ?>
" name="author_rules_action[]" onchange="flip_newuser('author-rules-<?php 
                    echo $i;
                    ?>
');">
    <?php 
                    foreach ($authorlist as $local_author_id => $local_author_name) {
                        ?>
    <option value="<?php 
                        echo $local_author_id;
                        ?>
"<?php 
                        if ($local_author_id == $author_action) {
                            echo ' selected="selected"';
                        }
                        ?>
>are assigned to <?php 
                        echo $local_author_name;
                        ?>
</option>
    <?php 
                    }
                    ?>
    <option value="newuser">will be assigned to a new user...</option>
    <option value="filter"<?php 
                    if ('filter' == $author_action) {
                        echo ' selected="selected"';
                    }
                    ?>
>get filtered out</option>
  </select>
  </td>
  <td><div id="author-rules-<?php 
                    echo $i;
                    ?>
-newuser">named <input type="text" name="author_rules_newuser[]" value="" /></div></td>
</tr>
<?php 
                }
            }
        }
        ?>

<tr><th colspan="3" style="text-align: left; padding-top: 1.0em; border-bottom: 1px dotted black;">Fill in to set up a new rule:</th></tr>

<tr>
  <th style="text-align: left">Posts by <input type="text" name="add_author_rule_name" /></th>
  <td>
    <select id="add-author-rule" name="add_author_rule_action" onchange="flip_newuser('add-author-rule');">
      <?php 
        foreach ($authorlist as $author_id => $author_name) {
            ?>
      <option value="<?php 
            echo $author_id;
            ?>
">are assigned to <?php 
            echo $author_name;
            ?>
</option>
      <?php 
        }
        ?>
      <option value="newuser">will be assigned to a new user...</option>
      <option value="filter">get filtered out</option>
    </select>
  </td>
  <td><div id="add-author-rule-newuser">named <input type="text" name="add_author_rule_newuser" value="" /></div></td>
</tr>

</table>
<?php 
        fwp_option_box_closer();
        ?>

<script>
	flip_newuser('unfamiliar-author');
<?php 
        for ($j = 1; $j <= $i; $j++) {
            ?>
	flip_newuser('author-rules-<?php 
            echo $j;
            ?>
');
<?php 
        }
        ?>
	flip_newuser('add-author-rule');
</script>

<?php 
        fwp_linkedit_periodic_submit();
        fwp_option_box_opener('Comments & Pings', 'commentstatusdiv', 'postbox');
        ?>
<table class="editform" width="75%" cellspacing="2" cellpadding="5">
<tr><th width="27%" scope="row" style="vertical-align:top"><?php 
        print __('Comments');
        ?>
:</th>
<td width="73%"><ul style="margin:0; list-style:none">
<li><label><input type="radio" name="feed_comment_status" value="site-default"
<?php 
        echo $status['comment']['site-default'];
        ?>
 /> Use site-wide setting from <a href="admin.php?page=<?php 
        print $GLOBALS['fwp_path'];
        ?>
/syndication-options.php">Syndication Options</a>
(currently: <strong><?php 
        echo $comment_status_global ? $comment_status_global : 'closed';
        ?>
)</strong></label></li>
<li><label><input type="radio" name="feed_comment_status" value="open"
<?php 
        echo $status['comment']['open'];
        ?>
 /> Allow comments on syndicated posts from this feed</label></li>
<li><label><input type="radio" name="feed_comment_status" value="closed"
<?php 
        echo $status['comment']['closed'];
        ?>
 /> Don't allow comments on syndicated posts from this feed</label></li>
</ul></td></tr>

<tr><th width="27%" scope="row" style="vertical-align:top"><?php 
        print __('Pings');
        ?>
:</th>
<td width="73%"><ul style="margin:0; list-style:none">
<li><label><input type="radio" name="feed_ping_status" value="site-default"
<?php 
        echo $status['ping']['site-default'];
        ?>
 /> Use site-wide setting from <a href="admin.php?page=<?php 
        print $GLOBALS['fwp_path'];
        ?>
/syndication-options.php">Syndication Options</a>
(currently: <strong><?php 
        echo $ping_status_global ? $ping_status_global : 'closed';
        ?>
)</strong></label></li>
<li><label><input type="radio" name="feed_ping_status" value="open"
<?php 
        echo $status['ping']['open'];
        ?>
 /> Accept pings on syndicated posts from this feed</label></li>
<li><label><input type="radio" name="feed_ping_status" value="closed"
<?php 
        echo $status['ping']['closed'];
        ?>
 /> Don't accept pings on syndicated posts from this feed</label></li>
</ul></td></tr>

</table>
<?php 
        fwp_option_box_closer();
        fwp_linkedit_periodic_submit();
        ?>

<?php 
        fwp_option_box_opener('Custom Settings (for use in templates)', 'postcustom', 'postbox');
        ?>
<div id="postcustomstuff">
<table id="meta-list" cellpadding="3">
	<tr>
	<th>Key</th>
	<th>Value</th>
	<th>Action</th>
	</tr>

<?php 
        $i = 0;
        foreach ($link->settings as $key => $value) {
            if (!preg_match("^((" . implode(')|(', $special_settings) . "))\$i", $key)) {
                ?>
			<tr style="vertical-align:top">
			<th width="30%" scope="row"><input type="hidden" name="notes[<?php 
                echo $i;
                ?>
][key0]" value="<?php 
                echo wp_specialchars($key, 'both');
                ?>
" />
			<input id="notes-<?php 
                echo $i;
                ?>
-key" name="notes[<?php 
                echo $i;
                ?>
][key1]" value="<?php 
                echo wp_specialchars($key, 'both');
                ?>
" /></th>
			<td width="60%"><textarea rows="2" cols="40" id="notes-<?php 
                echo $i;
                ?>
-value" name="notes[<?php 
                echo $i;
                ?>
][value]"><?php 
                echo wp_specialchars($value, 'both');
                ?>
</textarea></td>
			<td width="10%"><select name="notes[<?php 
                echo $i;
                ?>
][action]">
			<option value="update">save changes</option>
			<option value="delete">delete this setting</option>
			</select></td>
			</tr>
<?php 
                $i++;
            }
        }
        ?>
	<tr>
	<th scope="row"><input type="text" size="10" name="notes[<?php 
        echo $i;
        ?>
][key1]" value="" /></th>
	<td><textarea name="notes[<?php 
        echo $i;
        ?>
][value]" rows="2" cols="40"></textarea></td>
	<td><em>add new setting...</em><input type="hidden" name="notes[<?php 
        echo $i;
        ?>
][action]" value="update" /></td>
	</tr>
</table>
<?php 
        fwp_option_box_closer();
        ?>

<?php 
        fwp_linkedit_periodic_submit();
        fwp_linkedit_single_submit_closer();
        ?>
</div> <!-- id="post-body" -->
</div> <!-- id="poststuff" -->
</div>
	<?php 
    }
    return false;
    // Don't continue
}
function fwp_syndication_manage_page_links_table_rows($links, $visible = 'Y')
{
    $subscribed = 'Y' == strtoupper($visible);
    if ($subscribed or count($links) > 0) {
        ?>
	<table class="widefat<?php 
        if (!$subscribed) {
            ?>
 unsubscribed<?php 
        }
        ?>
">
	<thead>
	<tr>
	<th class="check-column" scope="col"><input type="checkbox" /></th>
	<th scope="col"><?php 
        _e('Name');
        ?>
</th>
	<th scope="col"><?php 
        _e('Feed');
        ?>
</th>
	<th scope="col"><?php 
        _e('Updated');
        ?>
</th>
	</tr>
	</thead>

	<tbody>
<?php 
        $alt_row = true;
        if (count($links) > 0) {
            foreach ($links as $link) {
                $trClass = array();
                // Prep: Get last updated timestamp
                $sLink = new SyndicatedLink($link->link_id);
                if (!is_null($sLink->setting('update/last'))) {
                    $lastUpdated = fwp_time_elapsed($sLink->setting('update/last'));
                } else {
                    $lastUpdated = __('None yet');
                }
                // Prep: get last error timestamp, if any
                if (is_null($sLink->setting('update/error'))) {
                    $errorsSince = '';
                } else {
                    $trClass[] = 'feed-error';
                    $theError = unserialize($sLink->setting('update/error'));
                    $errorsSince = "<div class=\"returning-errors\">" . "<p><strong>Returning errors</strong> since " . fwp_time_elapsed($theError['since']) . "</p>" . "<p>Most recent (" . fwp_time_elapsed($theError['ts']) . "):<br/><code>" . implode("</code><br/><code>", $theError['object']->get_error_messages()) . "</code></p>" . "</div>\n";
                }
                $nextUpdate = "<div style='font-style:italic;size:0.9em'>Ready for next update ";
                if (isset($sLink->settings['update/ttl']) and is_numeric($sLink->settings['update/ttl'])) {
                    if (isset($sLink->settings['update/timed']) and $sLink->settings['update/timed'] == 'automatically') {
                        $next = $sLink->settings['update/last'] + (int) $sLink->settings['update/ttl'] * 60;
                        $nextUpdate .= fwp_time_elapsed($next);
                    } else {
                        $nextUpdate .= "every " . $sLink->settings['update/ttl'] . " minute" . ($sLink->settings['update/ttl'] != 1 ? "s" : "");
                    }
                } else {
                    $nextUpdate .= "as soon as possible";
                }
                $nextUpdate .= "</div>";
                unset($sLink);
                $alt_row = !$alt_row;
                if ($alt_row) {
                    $trClass[] = 'alternate';
                }
                ?>
	<tr<?php 
                echo count($trClass) > 0 ? ' class="' . implode(" ", $trClass) . '"' : '';
                ?>
>
	<th class="check-column" scope="row"><input type="checkbox" name="link_ids[]" value="<?php 
                echo $link->link_id;
                ?>
" /></th>
				<?php 
                $hrefPrefix = "admin.php?link_id={$link->link_id}&amp;page=";
                $caption = strlen($link->link_rss) > 0 ? __('Switch Feed') : ($caption = __('Find Feed'));
                ?>
	<td>
	<strong><a href="<?php 
                echo $hrefPrefix . FWP_FEEDS_PAGE_SLUG;
                ?>
"><?php 
                print esc_html($link->link_name);
                ?>
</a></strong>
	<div class="row-actions"><?php 
                if ($subscribed) {
                    ?>
	<div><strong>Settings &gt;</strong>
	<a href="<?php 
                    echo $hrefPrefix . FWP_FEEDS_PAGE_SLUG;
                    ?>
"><?php 
                    _e('Feed');
                    ?>
</a>
	| <a href="<?php 
                    echo $hrefPrefix . FWP_POSTS_PAGE_SLUG;
                    ?>
"><?php 
                    _e('Posts');
                    ?>
</a>
	| <a href="<?php 
                    echo $hrefPrefix . FWP_AUTHORS_PAGE_SLUG;
                    ?>
"><?php 
                    _e('Authors');
                    ?>
</a>
	| <a href="<?php 
                    echo $hrefPrefix . FWP_CATEGORIES_PAGE_SLUG;
                    ?>
"><?php 
                    print htmlspecialchars(__('Categories' . FEEDWORDPRESS_AND_TAGS));
                    ?>
</a></div>
	<?php 
                }
                ?>

	<div><strong>Actions &gt;</strong>
	<?php 
                if ($subscribed) {
                    ?>
	<a href="<?php 
                    echo $hrefPrefix . FWP_SYNDICATION_PAGE_SLUG;
                    ?>
&amp;action=feedfinder"><?php 
                    echo $caption;
                    ?>
</a>
	<?php 
                } else {
                    ?>
	<a href="<?php 
                    echo $hrefPrefix . FWP_SYNDICATION_PAGE_SLUG;
                    ?>
&amp;action=<?php 
                    print FWP_RESUB_CHECKED;
                    ?>
"><?php 
                    _e('Re-subscribe');
                    ?>
</a>
	<?php 
                }
                ?>
	| <a href="<?php 
                echo $hrefPrefix . FWP_SYNDICATION_PAGE_SLUG;
                ?>
&amp;action=Unsubscribe"><?php 
                _e($subscribed ? 'Unsubscribe' : 'Delete permanently');
                ?>
</a>
	| <a href="<?php 
                print esc_html($link->link_url);
                ?>
"><?php 
                _e('View');
                ?>
</a></div>
	</div>
	</td>
				<?php 
                if (strlen($link->link_rss) > 0) {
                    ?>
	<td><a href="<?php 
                    echo esc_html($link->link_rss);
                    ?>
"><?php 
                    echo esc_html(feedwordpress_display_url($link->link_rss, 32));
                    ?>
</a></td>
				<?php 
                } else {
                    ?>
	<td class="feed-missing"><p><strong>no feed assigned</strong></p></td>
				<?php 
                }
                ?>

	<td><?php 
                print $lastUpdated;
                ?>
	<?php 
                print $errorsSince;
                ?>
	<?php 
                print $nextUpdate;
                ?>
	</td>
	</tr>
			<?php 
            }
        } else {
            ?>
<tr><td colspan="4"><p>There are no websites currently listed for syndication.</p></td></tr>
<?php 
        }
        ?>
</tbody>
</table>
	<?php 
    }
}