Skip to content

Commit

Permalink
Merge pull request #19 from Flynsarmy/master
Browse files Browse the repository at this point in the history
Lots of fixes to eliminate PHP notices, etc. Props to Flynsarmy.
  • Loading branch information
radgeek committed May 6, 2014
2 parents 706bade + 5b77985 commit 18ae764
Show file tree
Hide file tree
Showing 13 changed files with 701 additions and 696 deletions.
178 changes: 89 additions & 89 deletions admin-ui.php

Large diffs are not rendered by default.

94 changes: 48 additions & 46 deletions categories-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ function FeedWordPressCategoriesPage ($link = -1) {
if (is_numeric($link) and -1 == $link) :
$link = $this->submitted_link();
endif;

FeedWordPressAdminPage::FeedWordPressAdminPage('feedwordpresscategories', $link);
$this->dispatch = 'feedwordpress_admin_page_categories';
$this->pagenames = array(
Expand All @@ -16,19 +16,19 @@ function FeedWordPressCategoriesPage ($link = -1) {
);
$this->filename = __FILE__;
}

function unfamiliar_category_label ($name) {
if (preg_match('/^create:(.*)$/', $name, $refs)) :
$tax = get_taxonomy($refs[1]);
$name = sprintf(__('Create new %s to match them'), $tax->labels->name);
endif;
return $name;
}


function feed_categories_box ($page, $box = NULL) {
$link = $page->link;

$globalPostType = get_option('feedwordpress_syndicated_post_type', 'post');
if ($this->for_feed_settings()) :
$post_type = $link->setting('syndicated post type', 'syndicated_post_type', 'post');
Expand All @@ -42,7 +42,7 @@ function feed_categories_box ($page, $box = NULL) {
$tagLikeTaxonomies = array();
foreach ($taxonomies as $tax) :
$taxonomy = get_taxonomy($tax);

if (!$taxonomy->hierarchical) :
$tagLikeTaxonomies[] = $tax;
endif;
Expand All @@ -62,12 +62,12 @@ function feed_categories_box ($page, $box = NULL) {
);
endforeach;
endforeach;

foreach ($unmatched as $what => $um) :
$unmatched[$what]['null'] = array('label' => __('Don\'t create any matching terms'));
$unmatchedRadio[$what]['null'] = '';
endforeach;

$globalUnmatched = array(
'category' => FeedWordPress::on_unfamiliar('category'),
'post_tag' => FeedWordPress::on_unfamiliar('post_tag'),
Expand All @@ -77,21 +77,21 @@ function feed_categories_box ($page, $box = NULL) {
if ($value=='tag') : $value = 'create:post_tag'; endif;
$globalUnmatched[$what] = $value;
endforeach;

$globalMatch['cats'] = get_option('feedwordpress_match_cats', $taxonomies);
$globalMatch['tags'] = get_option('feedwordpress_match_tags', $tagLikeTaxonomies);
$globalMatch['filter'] = get_option('feedwordpress_match_filter', array());

$globalMatchLabels = array();
$nothingDoing = array('cats' => "won't try to match", 'tags' => "won't try to match", "filter" => "won't filter");

foreach ($globalMatch as $what => $domain) :
$labels = array(); $domain = array_filter($domain, 'remove_dummy_zero');
foreach ($domain as $tax) :
$tax = get_taxonomy($tax);
$labels[] = $tax->labels->name;
endforeach;

if (count($labels) > 0) :
$globalMatchLabels[$what] = implode(", ", $labels);
else :
Expand Down Expand Up @@ -126,30 +126,30 @@ function feed_categories_box ($page, $box = NULL) {
$unmatchedDefault[$what] = $opts[0];
$unmatchedColumns[$what] = array();
endif;

$ucKey[$what] = $link->setting("unfamiliar $what", NULL, NULL);
endforeach;

$match['cats'] = $this->link->setting('match/cats', NULL, NULL);
$match['tags'] = $this->link->setting('match/tags', NULL, NULL);
$match['filter'] = $this->link->setting('match/filter', NULL, NULL);
else :
foreach ($unmatched as $what => $um) :
$ucKey[$what] = FeedWordPress::on_unfamiliar($what);
$ucKey[$what] = FeedWordPress::on_unfamiliar($what);
endforeach;

$match = $globalMatch;
endif;

foreach ($ucKey as $what => $uck) :
if ($uck == 'tag') : $uck = 'create:post_tag'; endif;
if ($uck == 'create') : $uck = 'create:category'; endif;

if (!is_string($uck)) :
$uck = $unmatchedDefault[$what];
endif;
$ucKey[$what] = $uck;

if (!array_key_exists($uck, $unmatchedRadio[$what])) :
$obsoleteLi = array(
$uck => array(
Expand All @@ -159,12 +159,12 @@ function feed_categories_box ($page, $box = NULL) {
$unmatched[$what] = array_merge($obsoleteLi, $unmatched[$what]);
$unmatchedRadio[$what][$uck] = ' disabled="disabled"';
endif;

$unmatchedRadio[$what][$uck] .= ' checked="checked"';

$unmatchedColumns[$what][] = $unmatched[$what];
endforeach;

$defaulted = array();
foreach ($match as $what => $set) :
$defaulted[$what] = false;
Expand All @@ -175,7 +175,7 @@ function feed_categories_box ($page, $box = NULL) {
$match[$what] = $globalMatch[$what];
endif;
endif;

if (!$defaulted[$what] or $this->for_feed_settings()) :
foreach ($set as $against) :
if (array_key_exists($against, $matchUl[$what])) :
Expand Down Expand Up @@ -350,7 +350,7 @@ function feed_categories_box ($page, $box = NULL) {
<?php if ($page->for_feed_settings()) : ?>
<tr>
<th scope="row">Multiple categories:</th>
<td>
<td>
<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']); endif; ?>" />
<p class="setting-description">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
Expand All @@ -376,9 +376,11 @@ function term_setting_map () {
'post_tag' => 'tags',
);
}

function categories_box ($page, $box = NULL) {
$link = $page->link;
$dummy = null;
$syndicatedpost = new SyndicatedPost(null, $dummy);

if ($this->for_feed_settings()) :
$post_type = $link->setting('syndicated post type', 'syndicated_post_type', 'post');
Expand Down Expand Up @@ -417,7 +419,7 @@ function categories_box ($page, $box = NULL) {
$add_global_categories = $link->setting("add/$tax", NULL, 'yes');
$checked = array('yes' => '', 'no' => '');
$checked[$add_global_categories] = ' checked="checked"';

if (isset($setting_map[$tax])) :
$setting = $setting_map[$tax];
$cats = $link->setting($setting, NULL, NULL);
Expand All @@ -430,7 +432,7 @@ function categories_box ($page, $box = NULL) {
else :
$cats = $globalCats;
endif;

if ($page->for_feed_settings()) :
?>
<table class="twofer">
Expand All @@ -439,17 +441,17 @@ function categories_box ($page, $box = NULL) {
<td class="primary">
<?php
endif;
$dogs = SyndicatedPost::category_ids($cats, /*unfamiliar=*/ NULL, /*taxonomies=*/ array($tax));

$dogs = $syndicatedpost->category_ids($cats, /*unfamiliar=*/ NULL, /*taxonomies=*/ array($tax));

if ($taxonomy->hierarchical) : // Use a category-style checkbox
fwp_category_box($dogs, 'all '.$page->these_posts_phrase(), /*tags=*/ array(), /*params=*/ array('taxonomy' => $tax));
else : // Use a tag-style edit box
fwp_tags_box($cats, 'all '.$page->these_posts_phrase(), /*params=*/ array('taxonomy' => $tax));
endif;
$globalDogs = SyndicatedPost::category_ids($globalCats, /*unfamiliar=*/ 'create:'.$tax, /*taxonomies=*/ array($tax));

$globalDogs = $syndicatedpost->category_ids($globalCats, /*unfamiliar=*/ 'create:'.$tax, /*taxonomies=*/ array($tax));

$siteWideHref = $this->admin_page_href(basename(__FILE__));

if ($page->for_feed_settings()) :
Expand All @@ -472,7 +474,7 @@ function categories_box ($page, $box = NULL) {
Should <?php print $page->these_posts_phrase(); ?> be assigned
these <?php print $taxonomy->labels->name; ?> from the <a href="<?php print esc_html($siteWideHref); ?>">site-wide settings</a>, in
addition to the feed-specific <?php print $taxonomy->labels->name; ?> you set up here?</p>

<ul class="settings">
<li><p><label><input type="radio" name="add_global[<?php print $tax; ?>]" value="yes" <?php print $checked['yes']; ?> /> Yes. Place <?php print $page->these_posts_phrase(); ?> under all these categories.</label></p></li>
<li><p><label><input type="radio" name="add_global[<?php print $tax; ?>]" value="no" <?php print $checked['no']; ?> /> No. Only use the categories I set up on the left. Do not use the global defaults for <?php print $page->these_posts_phrase(); ?></label></p></li>
Expand All @@ -493,7 +495,7 @@ function categories_box ($page, $box = NULL) {
</table>
<?php
} /* FeedWordPressCategoriesPage::categories_box () */

function save_settings ($post) {
if (isset($post['match_categories'])) :
foreach ($post['match_categories'] as $what => $set) :
Expand All @@ -504,17 +506,17 @@ function save_settings ($post) {
and $post['match_default'][$what]=='yes') :
$set = NULL; // Defaulted!
endif;

$this->update_setting("match/$what", $set, NULL);
endforeach;
endif;
$optionMap = $this->term_option_map();
$settingMap = $this->term_setting_map();

$saveTerms = array(); $separateSaveTerms = array('category' => array(), 'post_tag' => array());

if (!isset($post['tax_input'])) : $post['tax_input'] = array(); endif;

// Merge in data from older-notation category check boxes
if (isset($post['post_category'])) :
// Just merging in for processing below.
Expand All @@ -537,7 +539,7 @@ function save_settings ($post) {
$saveTerms[$tax] = explode(",", $terms);
endif;
$saveTerms[$tax] = array_map('trim', $saveTerms[$tax]);

if (isset($optionMap[$tax])) :
$separateSaveTerms[$tax] = $saveTerms[$tax];
unset($saveTerms[$tax]);
Expand All @@ -546,10 +548,10 @@ function save_settings ($post) {

if (isset($post['post_category'])) :
foreach ($post['post_category'] as $cat) :
$separateSaveTerms['category'][] = '{category#'.$cat.'}';
$separateSaveTerms['category'][] = '{category#'.$cat.'}';
endforeach;
endif;

// Unmatched categories and tags
foreach (array('category', 'post_tag') as $what) :
if (isset($post["unfamiliar_{$what}"])) :
Expand All @@ -560,7 +562,7 @@ function save_settings ($post) {
);
endif;
endforeach;

// Categories and Tags
foreach ($separateSaveTerms as $tax => $terms) :
if ($this->for_feed_settings()) :
Expand All @@ -573,7 +575,7 @@ function save_settings ($post) {
endif;
endif;
endforeach;

// Other terms
$this->update_setting(array('feed'=>'terms', 'global'=>'syndication_terms'), $saveTerms, array());

Expand All @@ -582,7 +584,7 @@ function save_settings ($post) {
if (isset($post['cat_split'])) :
$this->link->update_setting('cat_split', trim($post['cat_split']), '');
endif;

// Treat global terms (cats, tags, etc.) as additional,
// or as defaults to be overridden and replaced?
if (isset($post['add_global'])) :
Expand All @@ -593,18 +595,18 @@ function save_settings ($post) {
endif;
parent::save_settings($post);
} /* FeedWordPressCategoriesPage::save_settings() */

function display () {
////////////////////////////////////////////////
// Display settings boxes //////////////////////
////////////////////////////////////////////////

$this->boxes_by_methods = array(
'feed_categories_box' => __('Feed Categories & Tags'),
'categories_box' => array('title' => __('Categories'), 'id' => 'categorydiv'),
);

parent::display();
parent::display();
}
}

Expand Down
Loading

0 comments on commit 18ae764

Please sign in to comment.