diff --git a/README.markdown b/README.markdown deleted file mode 100644 index 40cab2f..0000000 --- a/README.markdown +++ /dev/null @@ -1,10 +0,0 @@ -Ding Campaign -============= - -Simple context-sensitive campaign/ad module for [Drupal][]. - -A part of the [Artesis][] project. - -[Drupal]: http://drupal.org/ -[Artesis]: http://github.com/ding2 - diff --git a/css/ding_campaign.admin.css b/css/ding_campaign.admin.css new file mode 100644 index 0000000..e6a7c0b --- /dev/null +++ b/css/ding_campaign.admin.css @@ -0,0 +1,24 @@ +#ding-campaign-campaign-content-type-edit-form > div > div, +#ding-campaign-campaign-content-type-edit-form > div > div.form-type-select.form-item-context-2 { + clear: both; +} + +#ding-campaign-campaign-content-type-edit-form > div > div.form-type-select, +#ding-campaign-campaign-content-type-edit-form > div > div.form-type-textfield { + width: 25em; + float: left; + clear: none; +} + +#ding-campaign-campaign-content-type-edit-form > div > div.form-item-ding-campaign-image-style { + float: none; + clear: both; +} + +#ding-campaign-campaign-content-type-edit-form > div > div.form-type-select label, +#ding-campaign-campaign-content-type-edit-form > div > div.form-type-textfield label { + display: block; + width: 12em; + float: left; + font-weight: bold +} diff --git a/ding_campaign.admin.inc b/ding_campaign.admin.inc index f7134af..314eee6 100644 --- a/ding_campaign.admin.inc +++ b/ding_campaign.admin.inc @@ -1,5 +1,4 @@ array( - 'autocompleteUrl' => url('ding_campaign/autocomplete/'), - )), 'setting'); + 'autocompleteUrl' => url('ding_campaign/autocomplete/'), + )), 'setting'); return drupal_get_form('ding_campaign_edit_rules_form', $node); } @@ -116,6 +107,11 @@ function ding_campaign_edit_rules_form($form, &$form_state, $node = NULL) { $form['#submit'] = array('ding_campaign_campaign_rule_form_submit'); + drupal_add_js( + drupal_get_path('module', 'ding_campaign') . '/js/ding_campaign_scripts.js', + array('weight' => 10) + ); + return $form; } @@ -140,25 +136,30 @@ function ding_campaign_add_rule($form, $form_state) { */ function ding_campaign_campaign_rule_form_submit($form, &$form_state) { $c = count($form_state['input']['rule_type']); + $nid = $form_state['build_info']['args'][0]->nid; if ($c > 0) { // Delete existing rules. db_delete('ding_campaign_rules') - ->condition('cid', $form_state['build_info']['args'][0]->nid) + ->condition('cid', $nid) ->execute(); + entity_get_controller('node')->resetCache(array($nid)); + // Add new rules. for ($i = 0; $i < $c; $i++) { if ($form_state['input']['rule_value'][$i] != '' || $form_state['input']['rule_type'][$i] == 'rule_generic') { $nid = NULL; - if ($form_state['input']['rule_type'][$i] == 'rule_page' || $form_state['input']['rule_type'][$i] == 'rule_taxonomy' || $form_state['input']['rule_type'][$i] == 'rule_library') { - $nid = array(); - preg_match('/\d{1,9}/', $form_state['input']['rule_value'][$i], $nid); + if (in_array($form_state['input']['rule_type'][$i], array('rule_page', 'rule_news', 'rule_event', 'rule_taxonomy', 'rule_library'))) { + preg_match('/\d{1,9}/', $form_state['input']['rule_value'][$i], $matches); + if (!empty($matches[0])) { + $nid = $matches[0]; + } } $dt = array( - 'nid' => isset($nid[0]) ? $nid[0] : NULL, + 'nid' => $nid, 'cid' => $form_state['build_info']['args'][0]->nid, 'rule' => ($form_state['input']['rule_type'][$i] == 'rule_generic') ? '' : $form_state['input']['rule_value'][$i], 'type' => $form_state['input']['rule_type'][$i], @@ -184,12 +185,16 @@ function ding_campaign_campaign_rule_form_submit($form, &$form_state) { * Rule fields structure. */ function ding_campaign_rule_form($rule = NULL, $type = NULL) { + $form = array(); + $form['rule_type[]'] = array( '#type' => 'select', '#title' => t('Rule type'), '#default_value' => ($type) ? $type : 'rule_page', '#options' => array( 'rule_page' => 'Page', + 'rule_event' => 'Event', + 'rule_news' => 'News', 'rule_path' => 'Path', 'rule_term' => 'Search term', 'rule_taxonomy' => 'Taxonomy term', @@ -204,17 +209,13 @@ function ding_campaign_rule_form($rule = NULL, $type = NULL) { '#type' => 'textfield', '#title' => t('Rule value'), '#default_value' => ($rule) ? $rule : '', - '#size' => 24, - '#maxlength' => 24, + '#size' => 64, + '#maxlength' => 255, '#prefix' => '
', '#suffix' => '
', - // '#autocomplete_path' => 'ding_campaign/autocomplete/567', + '#autocomplete_path' => 'ding_campaign/autocomplete/' . $type, ); - if ($type == 'rule_page' || $type == 'rule_taxonomy') { - $form['rule_value[]']['#autocomplete_path'] = 'ding_campaign/autocomplete/' . $type; - } - return $form; } @@ -237,6 +238,7 @@ function ding_campaign_admin_autocomplete($type, $input) { $matches['[nid:' . $v->nid . ']'] = $v->title; } break; + case 'rule_taxonomy': $q = db_query_range("SELECT tid, name FROM {taxonomy_term_data} WHERE name LIKE(:term)", 0, 5, array(':term' => '%%' . $input . '%%'))->fetchAll(); @@ -244,8 +246,25 @@ function ding_campaign_admin_autocomplete($type, $input) { $matches['[tid:' . $v->tid . ']'] = $v->name; } break; + case 'rule_library': - $q = db_query_range("SELECT nid, title FROM {node} WHERE type='library' AND title LIKE(:term)", 0, 5, array(':term' => '%%' . $input . '%%'))->fetchAll(); + $q = db_query_range("SELECT nid, title FROM {node} WHERE type='ding_library' AND title LIKE(:term)", 0, 5, array(':term' => '%%' . $input . '%%'))->fetchAll(); + + foreach ($q as $k => $v) { + $matches['[nid:' . $v->nid . ']'] = $v->title; + } + break; + + case 'rule_event': + $q = db_query_range("SELECT nid, title FROM {node} WHERE type='ding_event' AND title LIKE(:term)", 0, 5, array(':term' => '%%' . $input . '%%'))->fetchAll(); + + foreach ($q as $k => $v) { + $matches['[nid:' . $v->nid . ']'] = $v->title; + } + break; + + case 'rule_news': + $q = db_query_range("SELECT nid, title FROM {node} WHERE type='ding_news' AND title LIKE(:term)", 0, 5, array(':term' => '%%' . $input . '%%'))->fetchAll(); foreach ($q as $k => $v) { $matches['[nid:' . $v->nid . ']'] = $v->title; diff --git a/ding_campaign.features.field_base.inc b/ding_campaign.features.field_base.inc new file mode 100644 index 0000000..9c5b515 --- /dev/null +++ b/ding_campaign.features.field_base.inc @@ -0,0 +1,278 @@ + 1, + 'cardinality' => -1, + 'deleted' => 0, + 'entity_types' => array(), + 'field_name' => 'ding_campaign_group_ref', + 'foreign keys' => array( + 'node' => array( + 'columns' => array( + 'target_id' => 'nid', + ), + 'table' => 'node', + ), + ), + 'indexes' => array( + 'target_id' => array( + 0 => 'target_id', + ), + ), + 'locked' => 0, + 'module' => 'entityreference', + 'settings' => array( + 'handler' => 'og', + 'handler_settings' => array( + 'behaviors' => array( + 'og_behavior' => array( + 'status' => TRUE, + ), + 'views-select-list' => array( + 'status' => 0, + ), + ), + 'membership_type' => 'og_membership_type_default', + 'sort' => array( + 'direction' => 'ASC', + 'property' => 'title', + 'type' => 'property', + ), + 'target_bundles' => array( + 'ding_group' => 'ding_group', + 'ding_library' => 'ding_library', + ), + ), + 'handler_submit' => 'Change handler', + 'profile2_private' => FALSE, + 'target_type' => 'node', + ), + 'translatable' => 0, + 'type' => 'entityreference', + ); + + // Exported field_base: 'field_camp_behavior' + $field_bases['field_camp_behavior'] = array( + 'active' => 1, + 'cardinality' => 1, + 'deleted' => 0, + 'entity_types' => array(), + 'field_name' => 'field_camp_behavior', + 'foreign keys' => array(), + 'indexes' => array( + 'value' => array( + 0 => 'value', + ), + ), + 'locked' => 0, + 'module' => 'list', + 'settings' => array( + 'allowed_values' => array( + 0 => '', + 1 => '', + ), + 'allowed_values_function' => '', + 'profile2_private' => FALSE, + ), + 'translatable' => 0, + 'type' => 'list_boolean', + ); + + // Exported field_base: 'field_camp_image' + $field_bases['field_camp_image'] = array( + 'active' => 1, + 'cardinality' => 1, + 'deleted' => 0, + 'entity_types' => array(), + 'field_name' => 'field_camp_image', + 'foreign keys' => array( + 'fid' => array( + 'columns' => array( + 'fid' => 'fid', + ), + 'table' => 'file_managed', + ), + ), + 'indexes' => array( + 'fid' => array( + 0 => 'fid', + ), + ), + 'locked' => 0, + 'module' => 'image', + 'settings' => array( + 'default_image' => 0, + 'uri_scheme' => 'public', + ), + 'translatable' => 0, + 'type' => 'image', + ); + + // Exported field_base: 'field_camp_link' + $field_bases['field_camp_link'] = array( + 'active' => 1, + 'cardinality' => 1, + 'deleted' => 0, + 'entity_types' => array(), + 'field_name' => 'field_camp_link', + 'foreign keys' => array( + 'format' => array( + 'columns' => array( + 'format' => 'format', + ), + 'table' => 'filter_format', + ), + ), + 'indexes' => array( + 'format' => array( + 0 => 'format', + ), + ), + 'locked' => 0, + 'module' => 'text', + 'settings' => array( + 'max_length' => 255, + ), + 'translatable' => 0, + 'type' => 'text', + ); + + // Exported field_base: 'field_camp_settings' + $field_bases['field_camp_settings'] = array( + 'active' => 1, + 'cardinality' => 1, + 'deleted' => 0, + 'entity_types' => array(), + 'field_name' => 'field_camp_settings', + 'foreign keys' => array(), + 'indexes' => array( + 'value' => array( + 0 => 'value', + ), + ), + 'locked' => 0, + 'module' => 'list', + 'settings' => array( + 'allowed_values' => array( + 'full' => 'WYSIWYG', + 'image' => 'Image', + 'plain' => 'Plain text', + ), + 'allowed_values_function' => '', + ), + 'translatable' => 0, + 'type' => 'list_text', + ); + + // Exported field_base: 'field_camp_text_full' + $field_bases['field_camp_text_full'] = array( + 'active' => 1, + 'cardinality' => 1, + 'deleted' => 0, + 'entity_types' => array(), + 'field_name' => 'field_camp_text_full', + 'foreign keys' => array( + 'format' => array( + 'columns' => array( + 'format' => 'format', + ), + 'table' => 'filter_format', + ), + ), + 'indexes' => array( + 'format' => array( + 0 => 'format', + ), + ), + 'locked' => 0, + 'module' => 'text', + 'settings' => array(), + 'translatable' => 0, + 'type' => 'text_long', + ); + + // Exported field_base: 'field_camp_text_plain' + $field_bases['field_camp_text_plain'] = array( + 'active' => 1, + 'cardinality' => 1, + 'deleted' => 0, + 'entity_types' => array(), + 'field_name' => 'field_camp_text_plain', + 'foreign keys' => array( + 'format' => array( + 'columns' => array( + 'format' => 'format', + ), + 'table' => 'filter_format', + ), + ), + 'indexes' => array( + 'format' => array( + 0 => 'format', + ), + ), + 'locked' => 0, + 'module' => 'text', + 'settings' => array(), + 'translatable' => 0, + 'type' => 'text_long', + ); + + // Exported field_base: 'field_camp_weight' + $field_bases['field_camp_weight'] = array( + 'active' => 1, + 'cardinality' => 1, + 'deleted' => 0, + 'entity_types' => array(), + 'field_name' => 'field_camp_weight', + 'foreign keys' => array(), + 'indexes' => array( + 'value' => array( + 0 => 'value', + ), + ), + 'locked' => 0, + 'module' => 'list', + 'settings' => array( + 'allowed_values' => array( + -10 => -10, + -9 => -9, + -8 => -8, + -7 => -7, + -6 => -6, + -5 => -5, + -4 => -4, + -3 => -3, + -2 => -2, + -1 => -1, + 0 => 0, + 1 => 1, + 2 => 2, + 3 => 3, + 4 => 4, + 5 => 5, + 6 => 6, + 7 => 7, + 8 => 8, + 9 => 9, + 10 => 10, + ), + 'allowed_values_function' => '', + ), + 'translatable' => 0, + 'type' => 'list_integer', + ); + + return $field_bases; +} diff --git a/ding_campaign.features.field_instance.inc b/ding_campaign.features.field_instance.inc new file mode 100644 index 0000000..9fc4396 --- /dev/null +++ b/ding_campaign.features.field_instance.inc @@ -0,0 +1,493 @@ + 'ding_campaign', + 'default_value' => NULL, + 'deleted' => 0, + 'description' => '', + 'display' => array( + 'default' => array( + 'label' => 'above', + 'module' => 'og_ui', + 'settings' => array(), + 'type' => 'og_list_default', + 'weight' => 7, + ), + 'full' => array( + 'label' => 'above', + 'settings' => array(), + 'type' => 'hidden', + 'weight' => 0, + ), + 'teaser' => array( + 'label' => 'above', + 'settings' => array(), + 'type' => 'hidden', + 'weight' => 0, + ), + 'teaser_highlight' => array( + 'label' => 'above', + 'settings' => array(), + 'type' => 'hidden', + 'weight' => 0, + ), + ), + 'entity_type' => 'node', + 'field_name' => 'ding_campaign_group_ref', + 'label' => 'Libraries and Groups', + 'required' => 0, + 'settings' => array( + 'behaviors' => array( + 'og_widget' => array( + 'admin' => array( + 'widget_type' => 'entityreference_autocomplete', + ), + 'default' => array( + 'widget_type' => 'options_select', + ), + 'status' => TRUE, + ), + ), + 'user_register_form' => FALSE, + ), + 'view modes' => array( + 'full' => array( + 'custom settings' => FALSE, + 'label' => 'Full', + 'type' => 'og_list_default', + ), + 'teaser' => array( + 'custom settings' => FALSE, + 'label' => 'Teaser', + 'type' => 'og_list_default', + ), + ), + 'widget' => array( + 'active' => 0, + 'module' => 'options', + 'settings' => array(), + 'type' => 'options_select', + 'weight' => 6, + ), + ); + + // Exported field_instance: 'node-ding_campaign-field_camp_behavior' + $field_instances['node-ding_campaign-field_camp_behavior'] = array( + 'bundle' => 'ding_campaign', + 'default_value' => array( + 0 => array( + 'value' => 0, + ), + ), + 'deleted' => 0, + 'description' => 'If set, the clicked campaign will open in a new tab/window', + 'display' => array( + 'default' => array( + 'label' => 'above', + 'module' => 'list', + 'settings' => array(), + 'type' => 'list_default', + 'weight' => 8, + ), + 'full' => array( + 'label' => 'above', + 'settings' => array(), + 'type' => 'hidden', + 'weight' => 0, + ), + 'teaser' => array( + 'label' => 'above', + 'settings' => array(), + 'type' => 'hidden', + 'weight' => 0, + ), + 'teaser_highlight' => array( + 'label' => 'above', + 'settings' => array(), + 'type' => 'hidden', + 'weight' => 0, + ), + ), + 'entity_type' => 'node', + 'field_name' => 'field_camp_behavior', + 'label' => 'Open in new tab/window', + 'required' => 0, + 'settings' => array( + 'user_register_form' => FALSE, + ), + 'widget' => array( + 'active' => 1, + 'module' => 'options', + 'settings' => array( + 'display_label' => 1, + ), + 'type' => 'options_onoff', + 'weight' => 7, + ), + ); + + // Exported field_instance: 'node-ding_campaign-field_camp_image' + $field_instances['node-ding_campaign-field_camp_image'] = array( + 'bundle' => 'ding_campaign', + 'deleted' => 0, + 'description' => '', + 'display' => array( + 'default' => array( + 'label' => 'above', + 'module' => 'image', + 'settings' => array( + 'image_link' => '', + 'image_style' => '', + ), + 'type' => 'image', + 'weight' => 2, + ), + 'full' => array( + 'label' => 'above', + 'module' => 'image', + 'settings' => array( + 'image_link' => '', + 'image_style' => '', + ), + 'type' => 'image', + 'weight' => 2, + ), + 'teaser' => array( + 'label' => 'above', + 'settings' => array(), + 'type' => 'hidden', + 'weight' => 0, + ), + 'teaser_highlight' => array( + 'label' => 'above', + 'settings' => array(), + 'type' => 'hidden', + 'weight' => 0, + ), + ), + 'entity_type' => 'node', + 'field_name' => 'field_camp_image', + 'label' => 'Campaign image', + 'required' => 0, + 'settings' => array( + 'alt_field' => 0, + 'default_image' => 0, + 'file_directory' => '', + 'file_extensions' => 'png gif jpg jpeg', + 'max_filesize' => '', + 'max_resolution' => '', + 'min_resolution' => '', + 'title_field' => 0, + 'user_register_form' => FALSE, + ), + 'widget' => array( + 'active' => 1, + 'module' => 'media', + 'settings' => array( + 'allowed_schemes' => array( + 0 => 'public', + 1 => 'private', + ), + 'allowed_types' => array( + 0 => 'image', + ), + 'browser_plugins' => array(), + 'preview_image_style' => 'thumbnail', + 'progress_indicator' => 'throbber', + ), + 'type' => 'media_generic', + 'weight' => 4, + ), + ); + + // Exported field_instance: 'node-ding_campaign-field_camp_link' + $field_instances['node-ding_campaign-field_camp_link'] = array( + 'bundle' => 'ding_campaign', + 'default_value' => NULL, + 'deleted' => 0, + 'description' => '', + 'display' => array( + 'default' => array( + 'label' => 'above', + 'module' => 'text', + 'settings' => array(), + 'type' => 'text_default', + 'weight' => 4, + ), + 'full' => array( + 'label' => 'above', + 'module' => 'text', + 'settings' => array(), + 'type' => 'text_default', + 'weight' => 4, + ), + 'teaser' => array( + 'label' => 'above', + 'settings' => array(), + 'type' => 'hidden', + 'weight' => 0, + ), + 'teaser_highlight' => array( + 'label' => 'above', + 'settings' => array(), + 'type' => 'hidden', + 'weight' => 0, + ), + ), + 'entity_type' => 'node', + 'field_name' => 'field_camp_link', + 'label' => 'Campaign link', + 'required' => 0, + 'settings' => array( + 'text_processing' => 0, + 'user_register_form' => FALSE, + ), + 'widget' => array( + 'active' => 1, + 'module' => 'text', + 'settings' => array( + 'size' => 60, + ), + 'type' => 'text_textfield', + 'weight' => 6, + ), + ); + + // Exported field_instance: 'node-ding_campaign-field_camp_settings' + $field_instances['node-ding_campaign-field_camp_settings'] = array( + 'bundle' => 'ding_campaign', + 'default_value' => array( + 0 => array( + 'value' => 'plain', + ), + ), + 'deleted' => 0, + 'description' => '', + 'display' => array( + 'default' => array( + 'label' => 'above', + 'module' => 'list', + 'settings' => array(), + 'type' => 'list_default', + 'weight' => 0, + ), + 'full' => array( + 'label' => 'above', + 'module' => 'list', + 'settings' => array(), + 'type' => 'list_default', + 'weight' => 0, + ), + 'teaser' => array( + 'label' => 'above', + 'settings' => array(), + 'type' => 'hidden', + 'weight' => 0, + ), + 'teaser_highlight' => array( + 'label' => 'above', + 'settings' => array(), + 'type' => 'hidden', + 'weight' => 0, + ), + ), + 'entity_type' => 'node', + 'field_name' => 'field_camp_settings', + 'label' => 'Campaign settings', + 'required' => 0, + 'settings' => array( + 'user_register_form' => FALSE, + ), + 'widget' => array( + 'active' => 1, + 'module' => 'options', + 'settings' => array(), + 'type' => 'options_buttons', + 'weight' => 2, + ), + ); + + // Exported field_instance: 'node-ding_campaign-field_camp_text_full' + $field_instances['node-ding_campaign-field_camp_text_full'] = array( + 'bundle' => 'ding_campaign', + 'default_value' => NULL, + 'deleted' => 0, + 'description' => '', + 'display' => array( + 'default' => array( + 'label' => 'above', + 'module' => 'text', + 'settings' => array(), + 'type' => 'text_default', + 'weight' => 3, + ), + 'full' => array( + 'label' => 'above', + 'module' => 'text', + 'settings' => array(), + 'type' => 'text_default', + 'weight' => 3, + ), + 'teaser' => array( + 'label' => 'above', + 'settings' => array(), + 'type' => 'hidden', + 'weight' => 0, + ), + 'teaser_highlight' => array( + 'label' => 'above', + 'settings' => array(), + 'type' => 'hidden', + 'weight' => 0, + ), + ), + 'entity_type' => 'node', + 'field_name' => 'field_camp_text_full', + 'label' => 'Campaign text', + 'required' => 0, + 'settings' => array( + 'text_processing' => 1, + 'user_register_form' => FALSE, + ), + 'widget' => array( + 'active' => 1, + 'module' => 'text', + 'settings' => array( + 'rows' => 5, + ), + 'type' => 'text_textarea', + 'weight' => 5, + ), + ); + + // Exported field_instance: 'node-ding_campaign-field_camp_text_plain' + $field_instances['node-ding_campaign-field_camp_text_plain'] = array( + 'bundle' => 'ding_campaign', + 'default_value' => NULL, + 'deleted' => 0, + 'description' => '', + 'display' => array( + 'default' => array( + 'label' => 'above', + 'module' => 'text', + 'settings' => array(), + 'type' => 'text_default', + 'weight' => 1, + ), + 'full' => array( + 'label' => 'above', + 'module' => 'text', + 'settings' => array(), + 'type' => 'text_default', + 'weight' => 1, + ), + 'teaser' => array( + 'label' => 'above', + 'settings' => array(), + 'type' => 'hidden', + 'weight' => 0, + ), + 'teaser_highlight' => array( + 'label' => 'above', + 'settings' => array(), + 'type' => 'hidden', + 'weight' => 0, + ), + ), + 'entity_type' => 'node', + 'field_name' => 'field_camp_text_plain', + 'label' => 'Campaign text', + 'required' => 0, + 'settings' => array( + 'text_processing' => 0, + 'user_register_form' => FALSE, + ), + 'widget' => array( + 'active' => 1, + 'module' => 'text', + 'settings' => array( + 'rows' => 5, + ), + 'type' => 'text_textarea', + 'weight' => 4, + ), + ); + + // Exported field_instance: 'node-ding_campaign-field_camp_weight' + $field_instances['node-ding_campaign-field_camp_weight'] = array( + 'bundle' => 'ding_campaign', + 'default_value' => array( + 0 => array( + 'value' => 0, + ), + ), + 'deleted' => 0, + 'description' => '', + 'display' => array( + 'default' => array( + 'label' => 'above', + 'module' => 'list', + 'settings' => array(), + 'type' => 'list_default', + 'weight' => 6, + ), + 'full' => array( + 'label' => 'above', + 'module' => 'list', + 'settings' => array(), + 'type' => 'list_default', + 'weight' => 6, + ), + 'teaser' => array( + 'label' => 'above', + 'settings' => array(), + 'type' => 'hidden', + 'weight' => 0, + ), + 'teaser_highlight' => array( + 'label' => 'above', + 'settings' => array(), + 'type' => 'hidden', + 'weight' => 0, + ), + ), + 'entity_type' => 'node', + 'field_name' => 'field_camp_weight', + 'label' => 'Weight', + 'required' => 0, + 'settings' => array( + 'user_register_form' => FALSE, + ), + 'widget' => array( + 'active' => 1, + 'module' => 'options', + 'settings' => array(), + 'type' => 'options_select', + 'weight' => 5, + ), + ); + + // Translatables + // Included for use with string extractors like potx. + t('Campaign image'); + t('Campaign link'); + t('Campaign settings'); + t('Campaign text'); + t('If set, the clicked campaign will open in a new tab/window'); + t('Libraries and Groups'); + t('Open in new tab/window'); + t('Weight'); + + return $field_instances; +} diff --git a/ding_campaign.features.inc b/ding_campaign.features.inc new file mode 100644 index 0000000..c8c743f --- /dev/null +++ b/ding_campaign.features.inc @@ -0,0 +1,280 @@ + "1"); + } +} + +/** + * Implements hook_image_default_styles(). + */ +function ding_campaign_image_default_styles() { + $styles = array(); + + // Exported image style: ding_campaign_p_100. + $styles['ding_campaign_p_100'] = array( + 'name' => 'ding_campaign_p_100', + 'label' => 'Campaign (100% - 1200px)', + 'effects' => array( + 7 => array( + 'label' => 'Scale', + 'help' => 'Scaling will maintain the aspect-ratio of the original image. If only a single dimension is specified, the other dimension will be calculated.', + 'effect callback' => 'image_scale_effect', + 'dimensions callback' => 'image_scale_dimensions', + 'form callback' => 'image_scale_form', + 'summary theme' => 'image_scale_summary', + 'module' => 'image', + 'name' => 'image_scale', + 'data' => array( + 'width' => 1200, + 'height' => '', + 'upscale' => 1, + ), + 'weight' => 1, + ), + ), + ); + + // Exported image style: ding_campaign_p_25. + $styles['ding_campaign_p_25'] = array( + 'name' => 'ding_campaign_p_25', + 'label' => 'Campaign (25% - 280px)', + 'effects' => array( + 1 => array( + 'label' => 'Scale', + 'help' => 'Scaling will maintain the aspect-ratio of the original image. If only a single dimension is specified, the other dimension will be calculated.', + 'effect callback' => 'image_scale_effect', + 'dimensions callback' => 'image_scale_dimensions', + 'form callback' => 'image_scale_form', + 'summary theme' => 'image_scale_summary', + 'module' => 'image', + 'name' => 'image_scale', + 'data' => array( + 'width' => 280, + 'height' => '', + 'upscale' => 1, + ), + 'weight' => 1, + ), + ), + ); + + // Exported image style: ding_campaign_p_33. + $styles['ding_campaign_p_33'] = array( + 'name' => 'ding_campaign_p_33', + 'label' => 'Campaign (33% - 380px)', + 'effects' => array( + 3 => array( + 'label' => 'Scale', + 'help' => 'Scaling will maintain the aspect-ratio of the original image. If only a single dimension is specified, the other dimension will be calculated.', + 'effect callback' => 'image_scale_effect', + 'dimensions callback' => 'image_scale_dimensions', + 'form callback' => 'image_scale_form', + 'summary theme' => 'image_scale_summary', + 'module' => 'image', + 'name' => 'image_scale', + 'data' => array( + 'width' => 380, + 'height' => '', + 'upscale' => 1, + ), + 'weight' => 1, + ), + ), + ); + + // Exported image style: ding_campaign_p_50. + $styles['ding_campaign_p_50'] = array( + 'name' => 'ding_campaign_p_50', + 'label' => 'Campaign (50% - 580px)', + 'effects' => array( + 4 => array( + 'label' => 'Scale', + 'help' => 'Scaling will maintain the aspect-ratio of the original image. If only a single dimension is specified, the other dimension will be calculated.', + 'effect callback' => 'image_scale_effect', + 'dimensions callback' => 'image_scale_dimensions', + 'form callback' => 'image_scale_form', + 'summary theme' => 'image_scale_summary', + 'module' => 'image', + 'name' => 'image_scale', + 'data' => array( + 'width' => 580, + 'height' => '', + 'upscale' => 1, + ), + 'weight' => 1, + ), + ), + ); + + // Exported image style: ding_campaign_p_66. + $styles['ding_campaign_p_66'] = array( + 'name' => 'ding_campaign_p_66', + 'label' => 'Campaign (66% - 780px)', + 'effects' => array( + 5 => array( + 'label' => 'Scale', + 'help' => 'Scaling will maintain the aspect-ratio of the original image. If only a single dimension is specified, the other dimension will be calculated.', + 'effect callback' => 'image_scale_effect', + 'dimensions callback' => 'image_scale_dimensions', + 'form callback' => 'image_scale_form', + 'summary theme' => 'image_scale_summary', + 'module' => 'image', + 'name' => 'image_scale', + 'data' => array( + 'width' => 780, + 'height' => '', + 'upscale' => 1, + ), + 'weight' => 1, + ), + ), + ); + + // Exported image style: ding_campaign_p_75. + $styles['ding_campaign_p_75'] = array( + 'name' => 'ding_campaign_p_75', + 'label' => 'Campaign (75% - 880px)', + 'effects' => array( + 6 => array( + 'label' => 'Scale', + 'help' => 'Scaling will maintain the aspect-ratio of the original image. If only a single dimension is specified, the other dimension will be calculated.', + 'effect callback' => 'image_scale_effect', + 'dimensions callback' => 'image_scale_dimensions', + 'form callback' => 'image_scale_form', + 'summary theme' => 'image_scale_summary', + 'module' => 'image', + 'name' => 'image_scale', + 'data' => array( + 'width' => 880, + 'height' => '', + 'upscale' => 1, + ), + 'weight' => 1, + ), + ), + ); + + // Exported image style: ding_campaign_w_180. + $styles['ding_campaign_w_180'] = array( + 'name' => 'ding_campaign_w_180', + 'effects' => array( + 3 => array( + 'label' => 'Scale', + 'help' => 'Scaling will maintain the aspect-ratio of the original image. If only a single dimension is specified, the other dimension will be calculated.', + 'effect callback' => 'image_scale_effect', + 'dimensions callback' => 'image_scale_dimensions', + 'form callback' => 'image_scale_form', + 'summary theme' => 'image_scale_summary', + 'module' => 'image', + 'name' => 'image_scale', + 'data' => array( + 'width' => 180, + 'height' => '', + 'upscale' => 1, + ), + 'weight' => 1, + ), + ), + 'label' => 'ding_campaign_w_180', + ); + + // Exported image style: ding_campaign_w_280. + $styles['ding_campaign_w_280'] = array( + 'name' => 'ding_campaign_w_280', + 'effects' => array( + 4 => array( + 'label' => 'Scale', + 'help' => 'Scaling will maintain the aspect-ratio of the original image. If only a single dimension is specified, the other dimension will be calculated.', + 'effect callback' => 'image_scale_effect', + 'dimensions callback' => 'image_scale_dimensions', + 'form callback' => 'image_scale_form', + 'summary theme' => 'image_scale_summary', + 'module' => 'image', + 'name' => 'image_scale', + 'data' => array( + 'width' => 280, + 'height' => '', + 'upscale' => 1, + ), + 'weight' => 1, + ), + ), + 'label' => 'ding_campaign_w_280', + ); + + // Exported image style: ding_campaign_w_380. + $styles['ding_campaign_w_380'] = array( + 'name' => 'ding_campaign_w_380', + 'effects' => array( + 5 => array( + 'label' => 'Scale', + 'help' => 'Scaling will maintain the aspect-ratio of the original image. If only a single dimension is specified, the other dimension will be calculated.', + 'effect callback' => 'image_scale_effect', + 'dimensions callback' => 'image_scale_dimensions', + 'form callback' => 'image_scale_form', + 'summary theme' => 'image_scale_summary', + 'module' => 'image', + 'name' => 'image_scale', + 'data' => array( + 'width' => 380, + 'height' => '', + 'upscale' => 1, + ), + 'weight' => 1, + ), + ), + 'label' => 'ding_campaign_w_380', + ); + + // Exported image style: ding_campaign_w_480. + $styles['ding_campaign_w_480'] = array( + 'name' => 'ding_campaign_w_480', + 'effects' => array( + 6 => array( + 'label' => 'Scale', + 'help' => 'Scaling will maintain the aspect-ratio of the original image. If only a single dimension is specified, the other dimension will be calculated.', + 'effect callback' => 'image_scale_effect', + 'dimensions callback' => 'image_scale_dimensions', + 'form callback' => 'image_scale_form', + 'summary theme' => 'image_scale_summary', + 'module' => 'image', + 'name' => 'image_scale', + 'data' => array( + 'width' => 480, + 'height' => '', + 'upscale' => 1, + ), + 'weight' => 1, + ), + ), + 'label' => 'ding_campaign_w_480', + ); + + return $styles; +} + +/** + * Implements hook_node_info(). + */ +function ding_campaign_node_info() { + $items = array( + 'ding_campaign' => array( + 'name' => t('Campaign'), + 'base' => 'node_content', + 'description' => t('Create a new campaign that based on different rules will be shown in a given context on the site.'), + 'has_title' => '1', + 'title_label' => t('Campaign name'), + 'help' => '', + ), + ); + return $items; +} diff --git a/ding_campaign.info b/ding_campaign.info index 9db43ef..c3c3d61 100644 --- a/ding_campaign.info +++ b/ding_campaign.info @@ -1,12 +1,69 @@ -name = Ding campaign -description = Campaign system. Displays context-sensitive, ad-like campaigns. -package = Ding! -version = "7.x-0.4" -core = 7.x -configure = admin/config/ding/campaign -dependencies[] = field -dependencies[] = image -dependencies[] = features -dependencies[] = ctools -;stylesheets[all][] = css/ding_campaign.css -scripts[] = js/ding_campaign_scripts.js +name = Ding campaign +description = Campaign system. Displays context-sensitive, ad-like campaigns. +core = 7.x +package = Ding! +version = 7.x-2.3.1+easy +project = ding_campaign +dependencies[] = ctools +dependencies[] = entityreference +dependencies[] = features +dependencies[] = image +dependencies[] = list +dependencies[] = media +dependencies[] = og_ui +dependencies[] = scheduler +dependencies[] = strongarm +dependencies[] = text +configure = admin/config/ding/campaign +features[ctools][] = strongarm:strongarm:1 +features[features_api][] = api:2 +features[field_base][] = ding_campaign_group_ref +features[field_base][] = field_camp_behavior +features[field_base][] = field_camp_image +features[field_base][] = field_camp_link +features[field_base][] = field_camp_settings +features[field_base][] = field_camp_text_full +features[field_base][] = field_camp_text_plain +features[field_base][] = field_camp_weight +features[field_instance][] = node-ding_campaign-ding_campaign_group_ref +features[field_instance][] = node-ding_campaign-field_camp_behavior +features[field_instance][] = node-ding_campaign-field_camp_image +features[field_instance][] = node-ding_campaign-field_camp_link +features[field_instance][] = node-ding_campaign-field_camp_settings +features[field_instance][] = node-ding_campaign-field_camp_text_full +features[field_instance][] = node-ding_campaign-field_camp_text_plain +features[field_instance][] = node-ding_campaign-field_camp_weight +features[image][] = ding_campaign_p_100 +features[image][] = ding_campaign_p_25 +features[image][] = ding_campaign_p_33 +features[image][] = ding_campaign_p_50 +features[image][] = ding_campaign_p_66 +features[image][] = ding_campaign_p_75 +features[image][] = ding_campaign_w_180 +features[image][] = ding_campaign_w_280 +features[image][] = ding_campaign_w_380 +features[image][] = ding_campaign_w_480 +features[node][] = ding_campaign +features[variable][] = comment_anonymous_ding_campaign +features[variable][] = comment_default_mode_ding_campaign +features[variable][] = comment_default_per_page_ding_campaign +features[variable][] = comment_ding_campaign +features[variable][] = comment_form_location_ding_campaign +features[variable][] = comment_preview_ding_campaign +features[variable][] = comment_subject_field_ding_campaign +features[variable][] = field_bundle_settings_node__ding_campaign +features[variable][] = language_content_type_ding_campaign +features[variable][] = menu_options_ding_campaign +features[variable][] = menu_parent_ding_campaign +features[variable][] = node_options_ding_campaign +features[variable][] = node_preview_ding_campaign +features[variable][] = node_submitted_ding_campaign +features[variable][] = scheduler_publish_enable_ding_campaign +features[variable][] = scheduler_publish_required_ding_campaign +features[variable][] = scheduler_publish_revision_ding_campaign +features[variable][] = scheduler_publish_touch_ding_campaign +features[variable][] = scheduler_unpublish_enable_ding_campaign +features[variable][] = scheduler_unpublish_required_ding_campaign +features[variable][] = scheduler_unpublish_revision_ding_campaign +features_exclude[dependencies][options] = options +mtime = 1431613941 diff --git a/ding_campaign.install b/ding_campaign.install index a7da26d..43ffc8e 100644 --- a/ding_campaign.install +++ b/ding_campaign.install @@ -8,6 +8,8 @@ * Implements hook_schema(). */ function ding_campaign_schema() { + $schema = array(); + $schema['ding_campaign'] = array( 'description' => 'Table holding campaign types types for easier access', 'fields' => array( @@ -88,10 +90,43 @@ function ding_campaign_uninstall() { } /** - * Implements hook_update_N(). * Remove column 'theme' from table 'ding_campaign' */ function ding_campaign_update_7001(&$sandbox) { - return db_drop_field('ding_campaign','theme'); + return db_drop_field('ding_campaign', 'theme'); +} + +/** + * Implements hook_update_N(). + * + * Add pane_id column to table 'ding_campaign' + */ +function ding_campaign_update_7002(&$sandbox) { + return db_add_field('ding_campaign', 'pane_id', array( + 'type' => 'int', + 'not null' => TRUE, + 'default' => 0, + )); +} + +/** + * Implements hook_update_N(). + * + * Remove column 'pane_id' from table 'ding_campaign' + */ +function ding_campaign_update_7003(&$sandbox) { + return db_drop_field('ding_campaign', 'pane_id'); +} + +/** + * Expand the rule column max length. + */ +function ding_campaign_update_7004() { + $new_def = array( + 'type' => 'varchar', + 'length' => 255, + ); + + db_change_field('ding_campaign_rules', 'rule', 'rule', $new_def); } diff --git a/ding_campaign.make b/ding_campaign.make index 2a5a817..c143f47 100644 --- a/ding_campaign.make +++ b/ding_campaign.make @@ -1,9 +1,10 @@ -api = 2 core = 7.x +api = 2 +; Projects projects[ctools][subdir] = "contrib" -projects[ctools][version] = "1.1" +projects[ctools][version] = "1.9" -projects[features][subdir] = contrib -projects[features][version] = "1.0" +projects[features][subdir] = "contrib" +projects[features][version] = "2.0" diff --git a/ding_campaign.module b/ding_campaign.module index ee673a8..f03023f 100644 --- a/ding_campaign.module +++ b/ding_campaign.module @@ -4,8 +4,7 @@ * Provides campaign feature to various node types in Ding. */ -define('DING_CAMPAIGN_PATH', drupal_get_path('module', 'ding_campaign')); -define('DING_CAMPAIGN_DEFAULT_COUNT', 3); +include_once 'ding_campaign.features.inc'; /** * Implements hook_menu(). @@ -13,12 +12,12 @@ define('DING_CAMPAIGN_DEFAULT_COUNT', 3); function ding_campaign_menu() { $items = array(); - $items['admin/config/ding/campaign'] = array( - 'title' => 'Ding! Campaign', - 'description' => 'Configure the Ding! campaign system.', + $items['admin/config/ding/campaigns'] = array( + 'title' => 'Campaigns', + 'description' => 'Configure the campaigns.', 'page callback' => 'drupal_get_form', - 'page arguments' => array('ding_campaign_configure'), - 'access arguments' => array('access administration pages'), + 'page arguments' => array('ding_campaign_admin_settings'), + 'access arguments' => array('administer site configuration'), 'file' => 'ding_campaign.admin.inc', ); @@ -28,9 +27,9 @@ function ding_campaign_menu() { 'page callback' => 'ding_campaign_rules_admin', 'page arguments' => array(1), 'access arguments' => array(1), + 'access callback' => 'ding_campaign_rules_access', 'file' => 'ding_campaign.admin.inc', 'type' => MENU_LOCAL_TASK, - 'access callback' => 'ding_campaign_node_access', 'weight' => 2, ); @@ -39,7 +38,7 @@ function ding_campaign_menu() { 'description' => 'Autocomplete field for campaign rule values.', 'page callback' => 'ding_campaign_admin_autocomplete', 'page arguments' => array(2), - 'access arguments' => array('access administration pages'), + 'access arguments' => array('access campaign rules'), 'file' => 'ding_campaign.admin.inc', 'type' => MENU_CALLBACK, ); @@ -48,92 +47,195 @@ function ding_campaign_menu() { } /** - * Implements hook_admin_paths(). + * Custom access callback. + * + * Used to define access to ding campaign rules. Limits the menu item only for + * ding_campaign node types. + * + * @param entity $node + * The node loaded in the menu callback. + * + * @return bool + * TRUE or FALSE value. */ -function ding_campaign_admin_paths() { - $paths = array( - 'node/*/campaign_rules' => TRUE, - ); - return $paths; +function ding_campaign_rules_access($node) { + if ($node->type == 'ding_campaign') { + return TRUE; + } + + return FALSE; } /** - * Implements hook_node_access(). + * Implements hook_permission(). */ -function ding_campaign_node_access($node) { +function ding_campaign_permission() { + return array( + 'access campaign rules' => array( + 'title' => t('Access campaign rules'), + 'description' => t('Enable access to campaign nodes display rules'), + ), + ); +} - if ( isset($node->type) && $node->type == 'ding_campaign') { - return TRUE; - } - return FALSE; +/** + * Implements hook_admin_paths(). + * + * Ensures that the paths given is handled in the administration overlay. + */ +function ding_campaign_admin_paths() { + return array( + 'node/*/campaign_rules' => TRUE, + ); } /** * Implements hook_theme(). */ function ding_campaign_theme($existing, $type, $theme, $path) { - $hooks = array(); - - $hooks['ding_campaign'] = array( - 'variables' => array('content' => NULL), - 'template' => 'ding_campaign', - 'path' => DING_CAMPAIGN_PATH . '/templates/', + return array( + 'ding_campaign_wrapper' => array( + 'variables' => array( + 'content' => NULL, + ), + 'template' => 'ding-campaign-wrapper', + 'path' => $path . '/templates', + ), + 'ding_campaign' => array( + 'variables' => array( + 'type' => NULL, + 'link' => NULL, + 'image' => NULL, + 'text' => NULL, + ), + 'template' => 'ding-campaign', + 'path' => $path . '/templates', + ), ); +} - return $hooks; +/** + * Implements hook_preprocess_ding_campaign(). + * + * Add template suggestions that can be used by the base theme. + */ +function template_preprocess_ding_campaign(&$variables) { + $variables['theme_hook_suggestions'][] = 'ding_campaign__' . $variables['type']; } /** - * Displays certain campaigns. + * Create a render array campaigns to display in a given context. * - * @param $context - * Display context used. - * @param $count - * Count of campaigns to display. - * @param $offset + * @param array $context + * Defines the context that the campaign should be displayed in. + * @param int $count + * The number of campaigns to display. + * @param int $offset * Offset of the first campaign in the database. + * @param string $style + * The image style to use for the campaigns. * - * @return - * HTML formatted string. + * @return array + * Render array with the campaigns found. */ -function ding_campaign_display($context, $count, $offset) { +function ding_campaign_display($context, $count, $offset, $style = 'medium') { + $content = array(); + + // Get node id's for the campaign nodes matching the context. $campaigns = ding_campaign_get_campaigns($context, $count, $offset); - // There is at least one result. - if (is_array($campaigns) && count($campaigns) > 0) { - $block = ''; + // If any campaigns where found. + if (!empty($campaigns)) { + // Set outer wrapper. + $content = array( + '#theme' => 'ding_campaign_wrapper', + '#content' => array(), + ); + + // Load campaign nodes (use entity load to utilize entity cache). + $campaigns = entity_load('node', array_values($campaigns)); // Loop through campaigns. - foreach ($campaigns as $k => $v) { - $node = node_load($v); - $content = ''; - - $camp_settings = field_get_items('node', $node, 'field_camp_settings'); - - $base_class = 'ding-campaign-item'; - // Select the display for campaign type. - switch ($camp_settings[0]['value']) { - case 'plain': - $camp_link = field_get_items('node', $node, 'field_camp_link'); - $camp_text_plain = field_get_items('node', $node, 'field_camp_text_plain'); - $content = '
' . $camp_text_plain[0]['value'] . '
'; - break; - case 'image': - $camp_link = field_get_items('node', $node, 'field_camp_link'); - $camp_image = field_get_items('node', $node, 'field_camp_image'); - $content = '
'; - break; - case 'full': - $camp_text_full = field_get_items('node', $node, 'field_camp_text_full'); - $content = '
' . $camp_text_full[0]['safe_value'] . '
'; - break; + foreach ($campaigns as $campaign) { + // User entity wrapper to access fields. + $wrapper = entity_metadata_wrapper('node', $campaign); + + // Get campaign type. + $type = $wrapper->field_camp_settings->value(); + + // Default render array. + $current = array( + '#theme' => 'ding_campaign', + '#type' => $type, + '#weight' => 0, + ); + + // Get link value. + $link = $wrapper->field_camp_link->value(); + + if (!empty($link)) { + $current['#link'] = array( + '#theme' => 'link', + '#text' => $campaign->title, + '#path' => $link, + '#options' => array( + 'attributes' => array( + 'class' => array( + 'ding-campaing--link', + ), + ), + 'html' => FALSE, + 'absolute' => TRUE, + ), + ); + + if ($wrapper->field_camp_behavior->value()) { + $current['#link']['#options']['attributes']['target'] = '_blank'; + } + } + + // Get text both plain and full. + $text = $wrapper->field_camp_text_plain->value(); + $text = (!empty($text)) ? $text : $wrapper->field_camp_text_full->value(); + if (!empty($text)) { + $current['#text'] = array( + '#markup' => (is_array($text) && isset($text['safe_value'])) ? $text['safe_value'] : $text, + ); + unset($current['#link']); } - $theme = 'ding_campaign'; - $block .= theme($theme, array('content' => $content)); + // Get image. + $image = $wrapper->field_camp_image->value(); + if (!empty($image)) { + $current['#image'] = array( + '#theme' => 'image_style', + '#style_name' => $style, + '#path' => $image['uri'], + '#title' => isset($image['title']) ? $image['title'] : $campaign->title, + '#alt' => isset($image['alt']) ? $image['alt'] : $campaign->title, + ); + + // Check if a link around the image is possible. + if (!empty($link)) { + // Sadly the link theme function do not generate children. + $image = $current['#image']; + $current['#image'] = (isset($current['#link'])) ? $current['#link'] : NULL; + $current['#image']['#text'] = drupal_render($image); + $current['#image']['#options']['html'] = TRUE; + } + } + // Get weight. + $weight = $wrapper->field_camp_weight->value(); + if (!empty($weight)) { + $current['#weight'] = $weight; + } + + // Add current campaign to content array. + $content['#content'][] = $current; } - return $block; } + + return $content; } /** @@ -148,8 +250,48 @@ function ding_campaign_display($context, $count, $offset) { function ding_campaign_get_campaigns($context, $limit, $offset) { $campaigns = array(); + // @todo add cache based on the three parameters given. + + // Process event campaigns. + if ($context['page'] != NULL && isset($context['page']->nid) && $context['page']->type == 'ding_event') { + $nid = $context['page']->nid; + + $result = db_query('SELECT r.cid + FROM {ding_campaign_rules} r, {ding_campaign} d, {node} n + WHERE r.nid = :nid + AND r.type = \'rule_event\' + AND n.status = 1 + AND r.cid = d.cid + AND r.cid = n.nid + ORDER BY d.weight DESC', array(':nid' => (int) $nid)) + ->fetchAll(); + + foreach ($result as $key => $value) { + @$campaigns[$value->cid] += 11; + } + } + + // Process news campaigns. + if ($context['page'] != NULL && isset($context['page']->nid) && $context['page']->type == 'ding_news') { + $nid = $context['page']->nid; + + $result = db_query('SELECT r.cid + FROM {ding_campaign_rules} r, {ding_campaign} d, {node} n + WHERE r.nid = :nid + AND r.type = \'rule_news\' + AND n.status = 1 + AND r.cid = d.cid + AND r.cid = n.nid + ORDER BY d.weight DESC', array(':nid' => (int) $nid)) + ->fetchAll(); + + foreach ($result as $key => $value) { + @$campaigns[$value->cid] += 10; + } + } + // Process page campaigns. - if ($context['page'] != NULL && isset($context['page']->nid)) { + if ($context['page'] != NULL && isset($context['page']->nid)) { $nid = $context['page']->nid; $result = db_query('SELECT r.cid @@ -159,11 +301,11 @@ function ding_campaign_get_campaigns($context, $limit, $offset) { AND n.status = 1 AND r.cid = d.cid AND r.cid = n.nid - ORDER BY d.weight DESC', array(':nid' => (int)$nid)) + ORDER BY d.weight DESC', array(':nid' => (int) $nid)) ->fetchAll(); - foreach ($result as $k => $v) { - @$campaigns[$v->cid] += 9; + foreach ($result as $key => $value) { + @$campaigns[$value->cid] += 9; } } @@ -178,22 +320,21 @@ function ding_campaign_get_campaigns($context, $limit, $offset) { ->fetchAll(); $path = drupal_get_path_alias($_GET['q']); - foreach ($result as $k => $v) { - $page_match = drupal_match_path($path, $v->rule); + foreach ($result as $key => $value) { + $page_match = drupal_match_path($path, $value->rule); if ($path != $_GET['q']) { - $page_match = $page_match || drupal_match_path($_GET['q'], $v->rule); + $page_match = $page_match || drupal_match_path($_GET['q'], $value->rule); } if ($page_match) { - @$campaigns[$v->cid] += 8; + @$campaigns[$value->cid] += 8; } } // Process search campaigns. if ($context['search_term'] != NULL) { $terms = trim(drupal_strtolower(check_plain($context['search_term']))); - $condition = ''; // Multiple keywords, comma and/or space separated. if (strpos($terms, ',') || strpos($terms, ' ')) { @@ -216,14 +357,14 @@ function ding_campaign_get_campaigns($context, $limit, $offset) { ORDER BY d.weight DESC') ->fetchAll(); - foreach ($result as $k => $v) { - @$campaigns[$v->cid] += 7; + foreach ($result as $key => $value) { + @$campaigns[$value->cid] += 7; } } // Process library campaigns. - if ($context['library'] != NULL && isset($context['library']->nid) && $context['library']->type == 'ding_library' ) { - $nid = $context['library']->nid; + if ($context['page'] != NULL && isset($context['page']->nid) && $context['page']->type == 'ding_library') { + $nid = $context['page']->nid; $result = db_query('SELECT r.cid FROM {ding_campaign_rules} r, {ding_campaign} d, {node} n @@ -232,11 +373,11 @@ function ding_campaign_get_campaigns($context, $limit, $offset) { AND n.status = 1 AND r.cid = d.cid AND r.cid = n.nid - ORDER BY d.weight DESC', array(':nid' => (int)$nid)) + ORDER BY d.weight DESC', array(':nid' => (int) $nid)) ->fetchAll(); - foreach ($result as $k => $v) { - @$campaigns[$v->cid] += 5; + foreach ($result as $key => $value) { + @$campaigns[$value->cid] += 5; } } @@ -251,11 +392,11 @@ function ding_campaign_get_campaigns($context, $limit, $offset) { AND n.status = 1 AND r.cid = d.cid AND r.cid = n.nid - ORDER BY d.weight DESC', array(':tid' => (int)$tid)) + ORDER BY d.weight DESC', array(':tid' => (int) $tid)) ->fetchAll(); - foreach ($result as $k => $v) { - @$campaigns[$v->cid] += 3; + foreach ($result as $key => $value) { + @$campaigns[$value->cid] += 3; } } @@ -269,9 +410,9 @@ function ding_campaign_get_campaigns($context, $limit, $offset) { ORDER BY d.weight DESC') ->fetchAll(); - foreach ($result as $k => $v) { - if (!isset($campaigns[$v->cid]) || $campaigns[$v->cid] == 0) { - $campaigns[$v->cid] = (mt_rand(1, 10) / 10); + foreach ($result as $key => $value) { + if (!isset($campaigns[$value->cid]) || $campaigns[$value->cid] == 0) { + $campaigns[$value->cid] = (mt_rand(1, 10) / 10); } } @@ -285,9 +426,9 @@ function ding_campaign_get_campaigns($context, $limit, $offset) { function ding_campaign_form_alter(&$form, &$form_state, $form_id) { // Alter the Campaign addition form. if ($form_id == 'ding_campaign_node_form') { - // Remove the 'N/A' type radiobox. + // Remove the 'N/A' type radio box. unset($form['field_camp_settings'][$form['field_camp_settings']['#language']]['#options']['_none']); - // Remove the 'None' value from weight dropdown. + // Remove the 'None' value from weight drop-down. unset($form['field_camp_weight'][$form['field_camp_weight']['#language']]['#options']['_none']); $form['#validate'] = array('ding_campaign_campaign_node_form_validate'); @@ -312,6 +453,47 @@ function ding_campaign_form_alter(&$form, &$form_state, $form_id) { } } +/** + * Implements hook_form_FORM_ID_alter(). + */ +function ding_campaign_form_ding_campaign_node_form_alter(&$form, &$form_state) { + // Add states for form elements based on Campaign settings selected options. + $form['field_camp_text_full']['#states'] = array( + 'visible' => array( + ':input[name="field_camp_settings[und]"]' => array('value' => 'full'), + ), + ); + $form['field_camp_text_plain']['#states'] = array( + 'visible' => array( + ':input[name="field_camp_settings[und]"]' => array('value' => 'plain'), + ), + ); + $form['field_camp_image']['#states'] = array( + 'visible' => array( + ':input[name="field_camp_settings[und]"]' => array('value' => 'image'), + ), + ); + array_unshift($form['actions']['submit']['#submit'], 'ding_campaign_form_ding_campaign_node_form_submit'); +} + +function ding_campaign_form_ding_campaign_node_form_submit(&$form, &$form_state) { + $field_camp_settings = $form_state['values']['field_camp_settings'][LANGUAGE_NONE][0]['value']; + switch ($field_camp_settings) { + case 'full': + $form_state['values']['field_camp_text_plain'][LANGUAGE_NONE][0]['value'] = ''; + $form_state['values']['field_camp_image'][LANGUAGE_NONE][0]['fid'] = ''; + break; + case 'plain': + $form_state['values']['field_camp_text_full'][LANGUAGE_NONE][0]['value'] = ''; + $form_state['values']['field_camp_image'][LANGUAGE_NONE][0]['fid'] = ''; + break; + case 'image': + $form_state['values']['field_camp_text_full'][LANGUAGE_NONE][0]['value'] = ''; + $form_state['values']['field_camp_text_plain'][LANGUAGE_NONE][0]['value'] = ''; + break; + } +} + /** * Implements hook_node_insert(). */ @@ -337,14 +519,15 @@ function ding_campaign_node_insert($node) { $enabled_types = variable_get('ding_campaign_node_types', array()); // Process other types of nodes (selected in backend). - if (isset($enabled_types[$node->form_id]) && $enabled_types[$node->form_id] === $node->form_id) { + if (isset($node->form_id) && isset($enabled_types[$node->form_id]) && $enabled_types[$node->form_id] === $node->form_id) { if (isset($node->ding_campaigns) && is_array($node->ding_campaigns)) { foreach ($node->ding_campaigns as $k => $v) { + $type = _ding_campaign_rule_by_type($node->type); $data = array( 'nid' => $node->nid, 'cid' => $v, 'rule' => '[nid:' . $node->nid . ']', - 'type' => ($node->type == 'library') ? 'rule_library' : 'rule_page', + 'type' => $type, ); // Skip the unused campaigns. @@ -366,6 +549,7 @@ function ding_campaign_node_update($node) { if ($node->type == 'ding_campaign') { $node_type = field_get_items('node', $node, 'field_camp_settings'); $node_weight = field_get_items('node', $node, 'field_camp_weight'); + // Update campaign fields. $data = array( 'type' => $node_type[0]['value'], @@ -391,11 +575,13 @@ function ding_campaign_node_update($node) { ->execute(); foreach ($node->ding_campaigns as $k => $v) { + $type = _ding_campaign_rule_by_type($node->type); + $data = array( 'nid' => $node->nid, 'cid' => $v, 'rule' => '[nid:' . $node->nid . ']', - 'type' => ($node->type == 'library') ? 'rule_library' : 'rule_page', + 'type' => $type, ); // Skip the unused campaigns. @@ -438,7 +624,7 @@ function ding_campaign_node_load($node) { // Process other types of nodes (selected in backend). if (isset($enabled_types[$node[$nids[0]]->type . '_node_form']) && $enabled_types[$node[$nids[0]]->type . '_node_form'] === $node[$nids[0]]->type . '_node_form') { $nids = array_keys($node); - $or = db_or()->condition('type', 'rule_library')->condition('type', 'rule_page'); + $or = db_or()->condition('type', 'rule_library')->condition('type', 'rule_page')->condition('type', 'rule_news')->condition('type', 'rule_event'); $result = db_select('ding_campaign_rules') ->fields('ding_campaign_rules', array('cid')) ->condition('nid', $node[$nids[0]]->nid) @@ -480,7 +666,7 @@ function ding_campaign_node_delete($node) { /** * Fetch available campaigns. * - * @return + * @return array * Array of campaigns with ids and titles. */ function ding_campaign_get_list() { @@ -515,4 +701,35 @@ function ding_campaign_campaign_node_form_validate($form, &$form_state) { } } } +/** + * Get rule name by node type. + * + * @param string $node_type + * Node type. + * + * @return string + * Rule name. + */ +function _ding_campaign_rule_by_type($node_type) { + // Set rule type. + switch ($node_type) { + case 'library': + $type = 'rule_library'; + break; + + case 'ding_event': + $type = 'rule_event'; + break; + + case 'ding_news': + $type = 'rule_news'; + break; + + default: + $type = 'rule_page'; + break; + } + + return $type; +} diff --git a/ding_campaign.strongarm.inc b/ding_campaign.strongarm.inc new file mode 100644 index 0000000..078fc1a --- /dev/null +++ b/ding_campaign.strongarm.inc @@ -0,0 +1,198 @@ +disabled = FALSE; /* Edit this to true to make a default strongarm disabled initially */ + $strongarm->api_version = 1; + $strongarm->name = 'comment_anonymous_ding_campaign'; + $strongarm->value = 0; + $export['comment_anonymous_ding_campaign'] = $strongarm; + + $strongarm = new stdClass(); + $strongarm->disabled = FALSE; /* Edit this to true to make a default strongarm disabled initially */ + $strongarm->api_version = 1; + $strongarm->name = 'comment_default_mode_ding_campaign'; + $strongarm->value = 0; + $export['comment_default_mode_ding_campaign'] = $strongarm; + + $strongarm = new stdClass(); + $strongarm->disabled = FALSE; /* Edit this to true to make a default strongarm disabled initially */ + $strongarm->api_version = 1; + $strongarm->name = 'comment_default_per_page_ding_campaign'; + $strongarm->value = '50'; + $export['comment_default_per_page_ding_campaign'] = $strongarm; + + $strongarm = new stdClass(); + $strongarm->disabled = FALSE; /* Edit this to true to make a default strongarm disabled initially */ + $strongarm->api_version = 1; + $strongarm->name = 'comment_ding_campaign'; + $strongarm->value = '1'; + $export['comment_ding_campaign'] = $strongarm; + + $strongarm = new stdClass(); + $strongarm->disabled = FALSE; /* Edit this to true to make a default strongarm disabled initially */ + $strongarm->api_version = 1; + $strongarm->name = 'comment_form_location_ding_campaign'; + $strongarm->value = 0; + $export['comment_form_location_ding_campaign'] = $strongarm; + + $strongarm = new stdClass(); + $strongarm->disabled = FALSE; /* Edit this to true to make a default strongarm disabled initially */ + $strongarm->api_version = 1; + $strongarm->name = 'comment_preview_ding_campaign'; + $strongarm->value = '0'; + $export['comment_preview_ding_campaign'] = $strongarm; + + $strongarm = new stdClass(); + $strongarm->disabled = FALSE; /* Edit this to true to make a default strongarm disabled initially */ + $strongarm->api_version = 1; + $strongarm->name = 'comment_subject_field_ding_campaign'; + $strongarm->value = 0; + $export['comment_subject_field_ding_campaign'] = $strongarm; + + $strongarm = new stdClass(); + $strongarm->disabled = FALSE; /* Edit this to true to make a default strongarm disabled initially */ + $strongarm->api_version = 1; + $strongarm->name = 'field_bundle_settings_node__ding_campaign'; + $strongarm->value = array( + 'view_modes' => array( + 'full' => array( + 'custom_settings' => TRUE, + ), + 'teaser' => array( + 'custom_settings' => TRUE, + ), + 'teaser_highlight' => array( + 'custom_settings' => TRUE, + ), + 'rss' => array( + 'custom_settings' => FALSE, + ), + 'search_index' => array( + 'custom_settings' => FALSE, + ), + 'search_result' => array( + 'custom_settings' => FALSE, + ), + 'token' => array( + 'custom_settings' => FALSE, + ), + ), + 'extra_fields' => array( + 'form' => array( + 'title' => array( + 'weight' => '0', + ), + 'path' => array( + 'weight' => '4', + ), + ), + 'display' => array(), + ), + ); + $export['field_bundle_settings_node__ding_campaign'] = $strongarm; + + $strongarm = new stdClass(); + $strongarm->disabled = FALSE; /* Edit this to true to make a default strongarm disabled initially */ + $strongarm->api_version = 1; + $strongarm->name = 'language_content_type_ding_campaign'; + $strongarm->value = '0'; + $export['language_content_type_ding_campaign'] = $strongarm; + + $strongarm = new stdClass(); + $strongarm->disabled = FALSE; /* Edit this to true to make a default strongarm disabled initially */ + $strongarm->api_version = 1; + $strongarm->name = 'menu_options_ding_campaign'; + $strongarm->value = array(); + $export['menu_options_ding_campaign'] = $strongarm; + + $strongarm = new stdClass(); + $strongarm->disabled = FALSE; /* Edit this to true to make a default strongarm disabled initially */ + $strongarm->api_version = 1; + $strongarm->name = 'menu_parent_ding_campaign'; + $strongarm->value = 'main-menu:0'; + $export['menu_parent_ding_campaign'] = $strongarm; + + $strongarm = new stdClass(); + $strongarm->disabled = FALSE; /* Edit this to true to make a default strongarm disabled initially */ + $strongarm->api_version = 1; + $strongarm->name = 'node_options_ding_campaign'; + $strongarm->value = array( + 0 => 'status', + ); + $export['node_options_ding_campaign'] = $strongarm; + + $strongarm = new stdClass(); + $strongarm->disabled = FALSE; /* Edit this to true to make a default strongarm disabled initially */ + $strongarm->api_version = 1; + $strongarm->name = 'node_preview_ding_campaign'; + $strongarm->value = '0'; + $export['node_preview_ding_campaign'] = $strongarm; + + $strongarm = new stdClass(); + $strongarm->disabled = FALSE; /* Edit this to true to make a default strongarm disabled initially */ + $strongarm->api_version = 1; + $strongarm->name = 'node_submitted_ding_campaign'; + $strongarm->value = 0; + $export['node_submitted_ding_campaign'] = $strongarm; + + $strongarm = new stdClass(); + $strongarm->disabled = FALSE; /* Edit this to true to make a default strongarm disabled initially */ + $strongarm->api_version = 1; + $strongarm->name = 'scheduler_publish_enable_ding_campaign'; + $strongarm->value = 1; + $export['scheduler_publish_enable_ding_campaign'] = $strongarm; + + $strongarm = new stdClass(); + $strongarm->disabled = FALSE; /* Edit this to true to make a default strongarm disabled initially */ + $strongarm->api_version = 1; + $strongarm->name = 'scheduler_publish_required_ding_campaign'; + $strongarm->value = 0; + $export['scheduler_publish_required_ding_campaign'] = $strongarm; + + $strongarm = new stdClass(); + $strongarm->disabled = FALSE; /* Edit this to true to make a default strongarm disabled initially */ + $strongarm->api_version = 1; + $strongarm->name = 'scheduler_publish_revision_ding_campaign'; + $strongarm->value = 0; + $export['scheduler_publish_revision_ding_campaign'] = $strongarm; + + $strongarm = new stdClass(); + $strongarm->disabled = FALSE; /* Edit this to true to make a default strongarm disabled initially */ + $strongarm->api_version = 1; + $strongarm->name = 'scheduler_publish_touch_ding_campaign'; + $strongarm->value = 1; + $export['scheduler_publish_touch_ding_campaign'] = $strongarm; + + $strongarm = new stdClass(); + $strongarm->disabled = FALSE; /* Edit this to true to make a default strongarm disabled initially */ + $strongarm->api_version = 1; + $strongarm->name = 'scheduler_unpublish_enable_ding_campaign'; + $strongarm->value = 1; + $export['scheduler_unpublish_enable_ding_campaign'] = $strongarm; + + $strongarm = new stdClass(); + $strongarm->disabled = FALSE; /* Edit this to true to make a default strongarm disabled initially */ + $strongarm->api_version = 1; + $strongarm->name = 'scheduler_unpublish_required_ding_campaign'; + $strongarm->value = 0; + $export['scheduler_unpublish_required_ding_campaign'] = $strongarm; + + $strongarm = new stdClass(); + $strongarm->disabled = FALSE; /* Edit this to true to make a default strongarm disabled initially */ + $strongarm->api_version = 1; + $strongarm->name = 'scheduler_unpublish_revision_ding_campaign'; + $strongarm->value = 0; + $export['scheduler_unpublish_revision_ding_campaign'] = $strongarm; + + return $export; +} diff --git a/ding_campaign_ctype/ding_campaign_ctype.features.field.inc b/ding_campaign_ctype/ding_campaign_ctype.features.field.inc deleted file mode 100644 index beb384a..0000000 --- a/ding_campaign_ctype/ding_campaign_ctype.features.field.inc +++ /dev/null @@ -1,522 +0,0 @@ - array( - 'active' => '1', - 'cardinality' => '1', - 'deleted' => '0', - 'entity_types' => array(), - 'field_name' => 'field_camp_image', - 'foreign keys' => array( - 'fid' => array( - 'columns' => array( - 'fid' => 'fid', - ), - 'table' => 'file_managed', - ), - ), - 'indexes' => array( - 'fid' => array( - 0 => 'fid', - ), - ), - 'module' => 'image', - 'settings' => array( - 'default_image' => 0, - 'uri_scheme' => 'public', - ), - 'translatable' => '0', - 'type' => 'image', - ), - 'field_instance' => array( - 'bundle' => 'ding_campaign', - 'deleted' => '0', - 'description' => '', - 'display' => array( - 'default' => array( - 'label' => 'above', - 'module' => 'image', - 'settings' => array( - 'image_link' => '', - 'image_style' => '', - ), - 'type' => 'image', - 'weight' => 2, - ), - 'teaser' => array( - 'label' => 'above', - 'settings' => array(), - 'type' => 'hidden', - 'weight' => 0, - ), - ), - 'entity_type' => 'node', - 'field_name' => 'field_camp_image', - 'label' => 'Campaign image', - 'required' => 0, - 'settings' => array( - 'alt_field' => 0, - 'file_directory' => '', - 'file_extensions' => 'png gif jpg jpeg', - 'max_filesize' => '', - 'max_resolution' => '', - 'min_resolution' => '', - 'title_field' => 0, - 'user_register_form' => FALSE, - ), - 'widget' => array( - 'active' => 1, - 'module' => 'image', - 'settings' => array( - 'preview_image_style' => 'thumbnail', - 'progress_indicator' => 'throbber', - ), - 'type' => 'image_image', - 'weight' => '-2', - ), - ), - ); - - // Exported field: node-ding_campaign-field_camp_link. - $fields['node-ding_campaign-field_camp_link'] = array( - 'field_config' => array( - 'active' => '1', - 'cardinality' => '1', - 'deleted' => '0', - 'entity_types' => array(), - 'field_name' => 'field_camp_link', - 'foreign keys' => array( - 'format' => array( - 'columns' => array( - 'format' => 'format', - ), - 'table' => 'filter_format', - ), - ), - 'indexes' => array( - 'format' => array( - 0 => 'format', - ), - ), - 'module' => 'text', - 'settings' => array( - 'max_length' => '255', - ), - 'translatable' => '0', - 'type' => 'text', - ), - 'field_instance' => array( - 'bundle' => 'ding_campaign', - 'default_value' => NULL, - 'deleted' => '0', - 'description' => '', - 'display' => array( - 'default' => array( - 'label' => 'above', - 'module' => 'text', - 'settings' => array(), - 'type' => 'text_default', - 'weight' => 4, - ), - 'teaser' => array( - 'label' => 'above', - 'settings' => array(), - 'type' => 'hidden', - 'weight' => 0, - ), - ), - 'entity_type' => 'node', - 'field_name' => 'field_camp_link', - 'label' => 'Campaign link', - 'required' => 0, - 'settings' => array( - 'text_processing' => '0', - 'user_register_form' => FALSE, - ), - 'widget' => array( - 'active' => 1, - 'module' => 'text', - 'settings' => array( - 'size' => '60', - ), - 'type' => 'text_textfield', - 'weight' => '0', - ), - ), - ); - - // Exported field: node-ding_campaign-field_camp_settings. - $fields['node-ding_campaign-field_camp_settings'] = array( - 'field_config' => array( - 'active' => '1', - 'cardinality' => '1', - 'deleted' => '0', - 'entity_types' => array(), - 'field_name' => 'field_camp_settings', - 'foreign keys' => array(), - 'indexes' => array( - 'value' => array( - 0 => 'value', - ), - ), - 'module' => 'list', - 'settings' => array( - 'allowed_values' => array( - 'full' => 'WYSIWYG', - 'image' => 'Image', - 'plain' => 'Plain text', - ), - 'allowed_values_function' => '', - ), - 'translatable' => '0', - 'type' => 'list_text', - ), - 'field_instance' => array( - 'bundle' => 'ding_campaign', - 'default_value' => array( - 0 => array( - 'value' => 'plain', - ), - ), - 'deleted' => '0', - 'description' => '', - 'display' => array( - 'default' => array( - 'label' => 'above', - 'module' => 'list', - 'settings' => array(), - 'type' => 'list_default', - 'weight' => 0, - ), - 'teaser' => array( - 'label' => 'above', - 'settings' => array(), - 'type' => 'hidden', - 'weight' => 0, - ), - ), - 'entity_type' => 'node', - 'field_name' => 'field_camp_settings', - 'label' => 'Campaign settings', - 'required' => 0, - 'settings' => array( - 'user_register_form' => FALSE, - ), - 'widget' => array( - 'active' => 1, - 'module' => 'options', - 'settings' => array(), - 'type' => 'options_buttons', - 'weight' => '-4', - ), - ), - ); - - // Exported field: node-ding_campaign-field_camp_text_full. - $fields['node-ding_campaign-field_camp_text_full'] = array( - 'field_config' => array( - 'active' => '1', - 'cardinality' => '1', - 'deleted' => '0', - 'entity_types' => array(), - 'field_name' => 'field_camp_text_full', - 'foreign keys' => array( - 'format' => array( - 'columns' => array( - 'format' => 'format', - ), - 'table' => 'filter_format', - ), - ), - 'indexes' => array( - 'format' => array( - 0 => 'format', - ), - ), - 'module' => 'text', - 'settings' => array(), - 'translatable' => '0', - 'type' => 'text_long', - ), - 'field_instance' => array( - 'bundle' => 'ding_campaign', - 'default_value' => NULL, - 'deleted' => '0', - 'description' => '', - 'display' => array( - 'default' => array( - 'label' => 'above', - 'module' => 'text', - 'settings' => array(), - 'type' => 'text_default', - 'weight' => 3, - ), - 'teaser' => array( - 'label' => 'above', - 'settings' => array(), - 'type' => 'hidden', - 'weight' => 0, - ), - ), - 'entity_type' => 'node', - 'field_name' => 'field_camp_text_full', - 'label' => 'Campaign text', - 'required' => 0, - 'settings' => array( - 'text_processing' => '1', - 'user_register_form' => FALSE, - ), - 'widget' => array( - 'active' => 1, - 'module' => 'text', - 'settings' => array( - 'rows' => '5', - ), - 'type' => 'text_textarea', - 'weight' => '-1', - ), - ), - ); - - // Exported field: node-ding_campaign-field_camp_text_plain. - $fields['node-ding_campaign-field_camp_text_plain'] = array( - 'field_config' => array( - 'active' => '1', - 'cardinality' => '1', - 'deleted' => '0', - 'entity_types' => array(), - 'field_name' => 'field_camp_text_plain', - 'foreign keys' => array( - 'format' => array( - 'columns' => array( - 'format' => 'format', - ), - 'table' => 'filter_format', - ), - ), - 'indexes' => array( - 'format' => array( - 0 => 'format', - ), - ), - 'module' => 'text', - 'settings' => array(), - 'translatable' => '0', - 'type' => 'text_long', - ), - 'field_instance' => array( - 'bundle' => 'ding_campaign', - 'default_value' => NULL, - 'deleted' => '0', - 'description' => '', - 'display' => array( - 'default' => array( - 'label' => 'above', - 'module' => 'text', - 'settings' => array(), - 'type' => 'text_default', - 'weight' => 1, - ), - 'teaser' => array( - 'label' => 'above', - 'settings' => array(), - 'type' => 'hidden', - 'weight' => 0, - ), - ), - 'entity_type' => 'node', - 'field_name' => 'field_camp_text_plain', - 'label' => 'Campaign text', - 'required' => 0, - 'settings' => array( - 'text_processing' => '0', - 'user_register_form' => FALSE, - ), - 'widget' => array( - 'active' => 1, - 'module' => 'text', - 'settings' => array( - 'rows' => '5', - ), - 'type' => 'text_textarea', - 'weight' => '-3', - ), - ), - ); - -/* #588 Campaign theme skal fjernes fra Campaign sidetypen, fordi kampagnerne nu følger designet - // Exported field: node-ding_campaign-field_camp_theme. - $fields['node-ding_campaign-field_camp_theme'] = array( - 'field_config' => array( - 'active' => '1', - 'cardinality' => '1', - 'deleted' => '0', - 'entity_types' => array(), - 'field_name' => 'field_camp_theme', - 'foreign keys' => array(), - 'indexes' => array( - 'value' => array( - 0 => 'value', - ), - ), - 'module' => 'list', - 'settings' => array( - 'allowed_values' => array( - 'theme_blue' => 'Blue', - 'theme_green' => 'Green', - 'theme_orange' => 'Orange', - 'theme_pink' => 'Pink', - ), - 'allowed_values_function' => '', - ), - 'translatable' => '0', - 'type' => 'list_text', - ), - 'field_instance' => array( - 'bundle' => 'ding_campaign', - 'default_value' => array( - 0 => array( - 'value' => 'theme_orange', - ), - ), - 'deleted' => '0', - 'description' => '', - 'display' => array( - 'default' => array( - 'label' => 'above', - 'module' => 'list', - 'settings' => array(), - 'type' => 'list_default', - 'weight' => 5, - ), - 'teaser' => array( - 'label' => 'above', - 'settings' => array(), - 'type' => 'hidden', - 'weight' => 0, - ), - ), - 'entity_type' => 'node', - 'field_name' => 'field_camp_theme', - 'label' => 'Campaign theme', - 'required' => 0, - 'settings' => array( - 'user_register_form' => FALSE, - ), - 'widget' => array( - 'active' => 1, - 'module' => 'options', - 'settings' => array(), - 'type' => 'options_select', - 'weight' => '1', - ), - ), - ); -*/ - - // Exported field: node-ding_campaign-field_camp_weight. - $fields['node-ding_campaign-field_camp_weight'] = array( - 'field_config' => array( - 'active' => '1', - 'cardinality' => '1', - 'deleted' => '0', - 'entity_types' => array(), - 'field_name' => 'field_camp_weight', - 'foreign keys' => array(), - 'indexes' => array( - 'value' => array( - 0 => 'value', - ), - ), - 'module' => 'list', - 'settings' => array( - 'allowed_values' => array( - -10 => '-10', - -9 => '-9', - -8 => '-8', - -7 => '-7', - -6 => '-6', - -5 => '-5', - -4 => '-4', - -3 => '-3', - -2 => '-2', - -1 => '-1', - 0 => '0', - 1 => '1', - 2 => '2', - 3 => '3', - 4 => '4', - 5 => '5', - 6 => '6', - 7 => '7', - 8 => '8', - 9 => '9', - 10 => '10', - ), - 'allowed_values_function' => '', - ), - 'translatable' => '0', - 'type' => 'list_integer', - ), - 'field_instance' => array( - 'bundle' => 'ding_campaign', - 'default_value' => array( - 0 => array( - 'value' => '0', - ), - ), - 'deleted' => '0', - 'description' => '', - 'display' => array( - 'default' => array( - 'label' => 'above', - 'module' => 'list', - 'settings' => array(), - 'type' => 'list_default', - 'weight' => 6, - ), - 'teaser' => array( - 'label' => 'above', - 'settings' => array(), - 'type' => 'hidden', - 'weight' => 0, - ), - ), - 'entity_type' => 'node', - 'field_name' => 'field_camp_weight', - 'label' => 'Weight', - 'required' => 0, - 'settings' => array( - 'user_register_form' => FALSE, - ), - 'widget' => array( - 'active' => 1, - 'module' => 'options', - 'settings' => array(), - 'type' => 'options_select', - 'weight' => '2', - ), - ), - ); - - // Translatables - included for use with string extractors like potx. - t('Campaign image'); - t('Campaign link'); - t('Campaign settings'); - t('Campaign text'); - t('Campaign theme'); - t('Weight'); - - return $fields; -} diff --git a/ding_campaign_ctype/ding_campaign_ctype.features.inc b/ding_campaign_ctype/ding_campaign_ctype.features.inc deleted file mode 100644 index 97e8ef7..0000000 --- a/ding_campaign_ctype/ding_campaign_ctype.features.inc +++ /dev/null @@ -1,32 +0,0 @@ - "1"); - } -} - -/** - * Implements hook_node_info(). - */ -function ding_campaign_ctype_node_info() { - $items = array( - 'ding_campaign' => array( - 'name' => t('Campaign'), - 'base' => 'node_content', - 'description' => '', - 'has_title' => '1', - 'title_label' => t('Campaign name'), - 'help' => '', - ), - ); - return $items; -} diff --git a/ding_campaign_ctype/ding_campaign_ctype.info b/ding_campaign_ctype/ding_campaign_ctype.info deleted file mode 100644 index 80a5c2f..0000000 --- a/ding_campaign_ctype/ding_campaign_ctype.info +++ /dev/null @@ -1,20 +0,0 @@ -core = "7.x" -dependencies[] = "features" -dependencies[] = "image" -dependencies[] = "list" -dependencies[] = "strongarm" -description = "Ding Campaign Content type" -features[ctools][] = "strongarm:strongarm:1" -features[field][] = "node-ding_campaign-field_camp_image" -features[field][] = "node-ding_campaign-field_camp_link" -features[field][] = "node-ding_campaign-field_camp_settings" -features[field][] = "node-ding_campaign-field_camp_text_full" -features[field][] = "node-ding_campaign-field_camp_text_plain" -// features[field][] = "node-ding_campaign-field_camp_theme" -features[field][] = "node-ding_campaign-field_camp_weight" -features[node][] = "ding_campaign" -features[variable][] = "language_content_type_ding_campaign" -features[variable][] = "node_options_ding_campaign" -name = "Ding Campaign" -package = "Ding!" -php = "5.2.4" diff --git a/ding_campaign_ctype/ding_campaign_ctype.module b/ding_campaign_ctype/ding_campaign_ctype.module deleted file mode 100644 index 2e8a6af..0000000 --- a/ding_campaign_ctype/ding_campaign_ctype.module +++ /dev/null @@ -1,8 +0,0 @@ -disabled = FALSE; /* Edit this to true to make a default strongarm disabled initially */ - $strongarm->api_version = 1; - $strongarm->name = 'language_content_type_ding_campaign'; - $strongarm->value = '1'; - $export['language_content_type_ding_campaign'] = $strongarm; - - $strongarm = new stdClass; - $strongarm->disabled = FALSE; /* Edit this to true to make a default strongarm disabled initially */ - $strongarm->api_version = 1; - $strongarm->name = 'node_options_ding_campaign'; - $strongarm->value = array( - 0 => 'status', - ); - $export['node_options_ding_campaign'] = $strongarm; - - return $export; -} diff --git a/js/ding_campaign_scripts.js b/js/ding_campaign_scripts.js index 24197ed..7da8944 100644 --- a/js/ding_campaign_scripts.js +++ b/js/ding_campaign_scripts.js @@ -1,61 +1,68 @@ (function ($) { - campaign_content_click = function(type) { - $('#edit-field-camp-text-plain, #edit-field-camp-image, #edit-field-camp-text-full, #edit-field-camp-link').hide(); - - switch(type) { - case 'plain': - $('#edit-field-camp-text-plain, #edit-field-camp-link').show(); - break; - case 'image': - $('#edit-field-camp-image, #edit-field-camp-link').show(); - break; - case 'full': - $('#edit-field-camp-text-full').show(); - break; - } - } Drupal.behaviors.ding_campaing_init = { - bindAutocomplete: function(obj, type) { - $(obj).find('input.autocomplete') + bindAutocomplete: function(obj, type) { + // Add autocomplete behavior to 'rule value' input. + $(obj).find('input.autocomplete') .val(Drupal.settings.ding_campaing_init.autocompleteUrl + type) .removeClass('autocomplete-processed') - .end() + .end() .find('input.form-text') .addClass('form-autocomplete'); - Drupal.attachBehaviors($(obj)); - }, - attach: function(context) { - campaign_content_click($('.node-ding_campaign-form #edit-field-camp-settings input[type=radio]:checked').attr('value')); - - $('.node-ding_campaign-form #edit-field-camp-settings input[type=radio]').click(function() { - var type = $(this).attr('value'); - campaign_content_click(type); - }); - - $('.ding-campaign-rule select').change(function() { - if ($(this).selected().attr('value') == 'rule_generic') { - $(this).parent().parent().parent().find('.rule-value').hide(); - } - else { - $(this).parent().parent().parent().find('.rule-value').show(); - var select_value = $(this).selected().attr('value'); - if (select_value == 'rule_path' || select_value == 'rule_term' || select_value == 'rule_generic') { - $(this).parent().parent().parent().find('input.form-text').unbind().removeClass('form-autocomplete'); - } else { - Drupal.behaviors.ding_campaing_init.bindAutocomplete( - $(this).parent().parent().parent(), - select_value); - } + Drupal.attachBehaviors($(obj)); + }, + + rebuildAutocomplete: function ($context, value) { + var $obj = $('input.form-text', $context); + $obj.unbind().removeClass('form-autocomplete').addClass('autocomplete-processed'); + + // Remove span element (will be recreated). + $('#' + $obj.attr('id') + '-autocomplete-aria-live', $context).remove(); + + if (value == undefined) { + value = $('select option:selected', $context).val(); } - $(this).parent().parent().parent().find('input.form-text').val(''); - }); - $('#ding-campaign-rules .ding-campaign-rule').each(function() { - if ($(this).find('.rule-type select').selected().attr('value') == 'rule_generic') { - $(this).find('.rule-value').hide(); + if (value == 'rule_page' || value == 'rule_event' || value == 'rule_news' || value == 'rule_taxonomy' || value == 'rule_library') { + // Add autocomplete. + Drupal.behaviors.ding_campaing_init.bindAutocomplete($context, value); } - }); - } - } + }, + + attach: function (context, settings) { + // OnLoad actions. + $('.ding-campaign-rule', context).once('ding_campaign_init_start').each(function(){ + var $context = $(this); + // Rebuild autocomplete. + Drupal.behaviors.ding_campaing_init.rebuildAutocomplete($context); + + // Hide rule value for generic type. + if ($('select option:selected', $context).val() == 'rule_generic') { + $('.rule-value', $context).hide(); + } + }); + + // OnChange event for 'rule type' dropdown. + $('.ding-campaign-rule select', context).once('ding_campaign_init').change(function () { + var $context = $(this).parent().parent().parent(); + var value = $(this).selected().val(); + if (value == 'rule_generic') { + // Generic does not need a 'rule value'. + $('.rule-value', $context).hide(); + } + else { + // Add/remove autocomplete for 'rule value'. + $('.rule-value', $context).show(); + + // Remove autocomplete. + // Needed to prevent duplicating autocomplete behavior. + Drupal.behaviors.ding_campaing_init.rebuildAutocomplete($context, value); + } + + // Clear rule value on rule type change. + $('input.form-text', $context).val(''); + }); + } + }; + })(jQuery); diff --git a/plugins/content_types/campaign.inc b/plugins/content_types/campaign.inc index 114e14b..e11d045 100644 --- a/plugins/content_types/campaign.inc +++ b/plugins/content_types/campaign.inc @@ -9,12 +9,16 @@ $plugin = array( 'title' => t('Relevant campaigns'), 'description' => t('Display ad-like campaigns'), 'single' => TRUE, - 'defaults' => array('ding_campaign_count' => 3, 'ding_campaign_offset' => 0), + 'defaults' => array( + 'ding_campaign_count' => 3, + 'ding_campaign_offset' => 0, + ), 'required context' => array( - new ctools_context_optional(t('Page node'), 'node'), - new ctools_context_optional(t('Related library'), 'node'), - new ctools_context_optional(t('Search term'), 'string'), - new ctools_context_optional(t('Taxonomy terms'), 'terms')), + new ctools_context_optional(t('Page node'), 'node'), + new ctools_context_optional(t('Related library'), 'node'), + new ctools_context_optional(t('Search term'), 'string'), + new ctools_context_optional(t('Taxonomy term'), array('entity:taxonomy_term', 'taxonomy_term')), + ), 'category' => t('Ding!'), ); @@ -31,8 +35,10 @@ function ding_campaign_campaign_content_type_render($subtype, $conf, $panel_args ); $count = $conf['ding_campaign_count']; $offset = $conf['ding_campaign_offset']; + // Set default value if it was not set in panel settings. + $style = (!empty($conf['ding_campaign_image_style'])) ? $conf['ding_campaign_image_style'] : 'medium'; - $block->content = ding_campaign_display($context_data, $count, $offset); + $block->content = ding_campaign_display($context_data, $count, $offset, $style); return $block; } @@ -46,7 +52,7 @@ function ding_campaign_campaign_content_type_edit_form($form, &$form_state) { '#type' => 'textfield', '#title' => t('Campaign count'), '#description' => t('The maximum number of campaigns to display'), - '#default_value' => (isset($form_state['conf']['ding_campaign_count'])) ? $form_state['conf']['ding_campaign_count'] : DING_CAMPAIGN_DEFAULT_COUNT, + '#default_value' => (isset($form_state['conf']['ding_campaign_count'])) ? $form_state['conf']['ding_campaign_count'] : 3, '#size' => 2, '#maxlength' => 2, ); @@ -60,6 +66,24 @@ function ding_campaign_campaign_content_type_edit_form($form, &$form_state) { '#maxlength' => 3, ); + $form['ding_campaign_image_style'] = array( + '#type' => 'select', + '#title' => t('Campaign image width'), + '#description' => t('Applicable for image campaigns. Image will be resized to selected width, height will be selected automatically.'), + '#options' => array( + 'ding_campaign_p_25' => t('25% (280px)'), + 'ding_campaign_p_33' => t('33% (380px)'), + 'ding_campaign_p_50' => t('50% (580px)'), + 'ding_campaign_p_66' => t('66% (780px)'), + 'ding_campaign_p_75' => t('75% (880px)'), + 'ding_campaign_p_100' => t('100% (1200px)'), + + ), + '#default_value' => (isset($form_state['conf']['ding_campaign_image_style'])) ? $form_state['conf']['ding_campaign_image_style'] : 'ding_campaign_p_25', + ); + + drupal_add_css(drupal_get_path('module', 'ding_campaign') . '/css/ding_campaign.admin.css'); + return $form; } @@ -68,14 +92,17 @@ function ding_campaign_campaign_content_type_edit_form($form, &$form_state) { */ function ding_campaign_campaign_content_type_edit_form_validate($form, &$form_state) { // Sanitise the submitted values. - $values = array('ding_campaign_count' => 1, 'ding_campaign_offset' => 0); + $values = array( + 'ding_campaign_count' => 1, + 'ding_campaign_offset' => 0, + ); foreach ($values as $value => $min_value) { $val = trim($form_state['values'][$value]); $count = intval($val); // Give an error if a value less than 1 was entered. if (!empty($val) && $count < $min_value) { - form_set_error($value, t('%value must be a number larger than zero.', array('%value' => ucfirst(str_replace('_', ' ', $value))))); + form_set_error($value, t('%value must be a number larger than zero.', array('%value' => drupal_ucfirst(str_replace('_', ' ', $value))))); } // Otherwise, store the sanitised value in the form state. else { @@ -90,4 +117,5 @@ function ding_campaign_campaign_content_type_edit_form_validate($form, &$form_st function ding_campaign_campaign_content_type_edit_form_submit($form, &$form_state) { $form_state['conf']['ding_campaign_count'] = $form_state['values']['ding_campaign_count']; $form_state['conf']['ding_campaign_offset'] = $form_state['values']['ding_campaign_offset']; + $form_state['conf']['ding_campaign_image_style'] = $form_state['values']['ding_campaign_image_style']; } diff --git a/templates/ding-campaign-wrapper.tpl.php b/templates/ding-campaign-wrapper.tpl.php new file mode 100644 index 0000000..b2fdc57 --- /dev/null +++ b/templates/ding-campaign-wrapper.tpl.php @@ -0,0 +1,9 @@ + +
+ +
diff --git a/templates/ding-campaign.tpl.php b/templates/ding-campaign.tpl.php new file mode 100644 index 0000000..ba0bf4f --- /dev/null +++ b/templates/ding-campaign.tpl.php @@ -0,0 +1,26 @@ + +
+ + + + + + + + + +
diff --git a/templates/ding_campaign.tpl.php b/templates/ding_campaign.tpl.php deleted file mode 100644 index 21e1683..0000000 --- a/templates/ding_campaign.tpl.php +++ /dev/null @@ -1,10 +0,0 @@ - - -