Skip to content

Commit

Permalink
Sanity checks on campaign count values.
Browse files Browse the repository at this point in the history
In some instances, a campaign count may not be set on the content pane. Use the default value in that case. ding_campaign_get_relevant() now returns an empty array for bogus values of $max_count.
  • Loading branch information
mikl committed Apr 13, 2010
1 parent 5c9b8b5 commit 66e9d04
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
6 changes: 6 additions & 0 deletions ding_campaign.module
Expand Up @@ -476,6 +476,12 @@ function ding_campaign_rule_element_validate($element, &$form_state) {
* Array of node ids of relevant campaigns, sorted by relevancy.
*/
function ding_campaign_get_relevant($context, $max_count = DING_CAMPAIGN_DEFAULT_COUNT) {
// Make sure we have a positive number before we proceed.
$max_count = (integer) $max_count;
if ($max_count < 1) {
return array();
}

$campaigns = array();
if (isset($context['page']) && !empty($context['page'])) {
if ($context['page'] instanceof stdClass) {
Expand Down
4 changes: 1 addition & 3 deletions plugins/content_types/relevant.inc
Expand Up @@ -35,6 +35,7 @@ function ding_campaign_relevant_content_type_render($subtype, $conf, $panel_args
'library' => isset($context[1]->data) ? drupal_clone($context[1]->data) : NULL,
'search_term' => isset($context[2]->data) ? check_plain($context[2]->data) : NULL,
);
$count = ($conf['campaign_count']) ? $conf['campaign_count'] : DING_CAMPAIGN_DEFAULT_COUNT;
$block = new stdClass();
$block->content = theme('ding_campaign_relevant_campaigns', $campaign_context, $conf['campaign_count']);
return $block;
Expand All @@ -49,9 +50,6 @@ function ding_campaign_relevant_content_type_admin_title($subtype, $conf, $conte

/**
* Returns an edit form for the content type.
*
* We're not actually doing anything here, but we need to have this hook
* for this content type to work.
*/
function ding_campaign_relevant_content_type_edit_form(&$form, &$form_state) {
$form['campaign_count'] = array(
Expand Down

0 comments on commit 66e9d04

Please sign in to comment.