diff --git a/mailchimp_panels/README.txt b/mailchimp_panels/README.txt new file mode 100644 index 0000000..6496c14 --- /dev/null +++ b/mailchimp_panels/README.txt @@ -0,0 +1,27 @@ +Mailchimp Panels ( mailchimp_panels ) +a MailChimp and Panels 3 Integration + +DESCRIPTION +----------- + +Mailchimp Panels provides a page override for the display of user facing pages built by the MailChimp module (http://drupal.org/project/mailchimp). + +User Pages involve: + +/user/%/mailchimp +/mailchimp/subscribe +/mailchimp/unsubscribe + +REQUIREMENTS +------------ + +Mailchimp Panels requires +a.) Panels and CTools Page Manager. +b.) Mailchimp module + +INSTALLATION +------------ + +1. Copy the mailchimp_panels directory to a drupal modules directory. +2. Enable Ctools Page Manager and Mailchimp +2. Login as an administrator and enable the MailChimp Panels ( mailchimp_panels ) module. diff --git a/mailchimp_panels/mailchimp_panels.info b/mailchimp_panels/mailchimp_panels.info new file mode 100644 index 0000000..4c6df3d --- /dev/null +++ b/mailchimp_panels/mailchimp_panels.info @@ -0,0 +1,10 @@ +; $Id: mailchimp_panels.info,v 1.0 2014/03/20 14:15:07 chriscalip Exp $ +name = Mailchimp Panels +description = Mailchimp Panels provides a page override for the display of user facing pages built by the MailChimp module (See README.txt) +dependencies[] = mailchimp +dependencies[] = panels +dependencies[] = page_manager +package = MailChimp +core = 6.x + + diff --git a/mailchimp_panels/mailchimp_panels.module b/mailchimp_panels/mailchimp_panels.module new file mode 100644 index 0000000..652cae4 --- /dev/null +++ b/mailchimp_panels/mailchimp_panels.module @@ -0,0 +1,18 @@ + TRUE, + 'title' => t('Mailchimp Subscription Page Form(s).'), + 'description' => t('Mailchimp Suitable Subscription Form(s) based on user., the subscription forms that will appear based on mailchimp preferences. '), + 'category' => array(t('Miscellaneous'), -8) + ); +} + +/** + * Render the custom content type. + */ +function mailchimp_panels_mcsubscribe_content_type_render($subtype, $conf, $panel_args, $context) { + // Build the content type block. + $block = new stdClass(); + $block->module = 'form'; + $block->title = mailchimp_subscribe_page_title(); + $block->content = mailchimp_subscribe_page(); + return $block; +} + +/** + * Returns an edit form for custom type settings. + */ +function mailchimp_panels_mcsubscribe_content_type_edit_form(&$form, &$form_state) { + // @todo placeholder stuff for now +} + +/** + * Submit handler for contact form. + */ +function mailchimp_panels_mcsubscribe_content_type_edit_form_submit(&$form, &$form_state) { + // @todo placeholder stuff for now +} + +/** + * Returns the administrative title for a type. + */ +function mailchimp_panels_mcsubscribe_content_type_admin_title($subtype, $conf, $context) { + return t('Mailchimp Subscription Page Form(s).'); +} diff --git a/mailchimp_panels/plugins/content_types/mcunsubscribe.inc b/mailchimp_panels/plugins/content_types/mcunsubscribe.inc new file mode 100644 index 0000000..93e94ed --- /dev/null +++ b/mailchimp_panels/plugins/content_types/mcunsubscribe.inc @@ -0,0 +1,52 @@ + TRUE, + 'title' => t('Mailchimp Unsubscribe Form.'), + 'description' => t('Display the form generated by Mailchimp Unsubscribe Page.'), + 'category' => array(t('Miscellaneous'), -8) + ); +} + +/** + * Render the custom content type. + */ +function mailchimp_panels_mcunsubscribe_content_type_render($subtype, $conf, $panel_args, $context) { + // Build the content type block. + $block = new stdClass(); + $block->title = mailchimp_unsubscribe_page_title(); + $block->module = 'form'; + $block->content = drupal_get_form('mailchimp_unsubscribe_form'); + return $block; +} + +/** + * Returns an edit form for custom type settings. + */ +function mailchimp_panels_mcunsubscribe_content_type_edit_form(&$form, &$form_state) { + // @todo placeholder stuff for now +} + +/** + * Submit handler for contact form. + */ +function mailchimp_panels_mcunsubscribe_content_type_edit_form_submit(&$form, &$form_state) { + // @todo placeholder stuff for now +} + +/** + * Returns the administrative title for a type. + */ +function mailchimp_panels_mcunsubscribe_content_type_admin_title($subtype, $conf, $context) { + return t('Mailchimp unsubscribe form.'); +} diff --git a/mailchimp_panels/plugins/tasks/mcoverrides.inc b/mailchimp_panels/plugins/tasks/mcoverrides.inc new file mode 100644 index 0000000..e291142 --- /dev/null +++ b/mailchimp_panels/plugins/tasks/mcoverrides.inc @@ -0,0 +1,133 @@ + 'page', + + 'title' => t('User Mailchimp Subscribe Page'), + 'admin title' => t('User Mailchimp Subscribe Page'), + 'admin description' => t('when enabled, this overrides the default Drupal behavior of the Mailchimp Subscribe page at user/%uid/mailchimp'), + 'admin path' => 'user/%uid/mailchimp', + + // Menu hooks so that we can alter the /user/%uid/mailchimp menu entry to point to us. + 'hook menu' => 'mailchimp_panels_mcoverrides_menu', + 'hook menu alter' => 'mailchimp_panels_mcoverrides_menu_alter', + + // This is task uses 'context' handlers and must implement these to give the + // handler data it needs. + 'handler type' => 'context', + 'get arguments' => 'mailchimp_panels_mcoverrides_get_arguments', + 'get context placeholders' => 'mailchimp_panels_mcoverrides_get_contexts', + + // Allow this to be enabled or disabled: + 'disabled' => variable_get('mailchimp_panels_mcoverrides_disabled', TRUE), + 'enable callback' => 'mailchimp_panels_mcoverrides_enable', + ); +} + +/** + * Callback defined by mailchimp_panels_mcoverrides_page_manager_tasks(). + * + * Alter the FAQ page with terms so that the FAQ page comes to us rather than the + * normal FAQ process. + * Menus to be altered are only the list faq display (faq,faq/%,faq/%/list,faq/list). + */ +function mailchimp_panels_mcoverrides_menu_alter(&$items, $task) { + if (variable_get('mailchimp_panels_mcoverrides_disabled', TRUE)) { + return; + } + + $callback = $items['user/%user/mailchimp']['page callback']; + // Override the faq term handler for our purpose. + if ($callback == 'drupal_get_form' || variable_get('page_manager_override_anyway', FALSE)) { + $items['user/%user/mailchimp']['page callback'] = 'mailchimp_panels_mcoverrides'; + $items['user/%user/mailchimp']['file path'] = $task['path']; + $items['user/%user/mailchimp']['file'] = $task['file']; + } + else { + variable_set('mailchimp_panels_mcoverrides_disabled', TRUE); + if (!empty($GLOBALS['mailchimp_panels_enabling_mcoverrides'])) { + drupal_set_message(t('Page manager module is unable to enable user/%uid/mailchimp because some other module already has overridden with %callback.', array('%callback' => $callback)), 'warning'); + } + + } + + return; +} + +/** + * Entry point for our overridden cck email generated contact form page. + * + * This function asks its assigned handlers who, if anyone, would like + * to run with it. If no one does, it passes through to CCK email field, which is email_mail_page(). + */ +function mailchimp_panels_mcoverrides($form_type, $user) { + // Load my task plugin + $task = page_manager_get_task('mcoverrides'); + ctools_include('context'); + ctools_include('context-task-handler'); + $contexts = mailchimp_panels_mcoverrides_get_contexts($task, '', array($user)); + $args = array($user->uid); + $output = ctools_context_handler_render($task, '', $contexts, $args); + if ($output !== FALSE) { + return $output; + } + $function = 'drupal_get_form'; + foreach (module_implements('page_manager_override') as $module) { + $call = $module . '_page_manager_override'; + if (($rc = $call('mcoverrides')) && function_exists($rc)) { + $function = $rc; + break; + } + } + // Otherwise, fall back. + return $function($form_type, $user, TRUE, NULL); +} + +/** + * Callback to get arguments provided by this task handler. + * + * Since this is the node edit and there is no UI on the arguments, we + * create dummy arguments that contain the needed data. + */ +function mailchimp_panels_mcoverrides_get_arguments($task, $subtask_id) { + return array( + array( + 'keyword' => 'user', + 'identifier' => t('User'), + 'id' => 1, + 'name' => 'uid', + 'settings' => array(), + ), + ); +} + +/** + * Callback to get context placeholders provided by this handler. + */ +function mailchimp_panels_mcoverrides_get_contexts($task, $subtask_id) { + return ctools_context_get_placeholders_from_argument(mailchimp_panels_mcoverrides_get_arguments($task, $subtask_id)); +} + +/** + * Callback to enable/disable the page from the UI. + */ +function mailchimp_panels_mcoverrides_enable($cache, $status) { + variable_set('mailchimp_panels_mcoverrides_disabled', $status); + // Set a global flag so that the menu routine knows it needs + // to set a message if enabling cannot be done. + if (!$status) { + $GLOBALS['mailchimp_panels_enabling_mcoverrides'] = TRUE; + } +} \ No newline at end of file diff --git a/mailchimp_panels/plugins/tasks/mctsubscribe.inc b/mailchimp_panels/plugins/tasks/mctsubscribe.inc new file mode 100644 index 0000000..4fa13eb --- /dev/null +++ b/mailchimp_panels/plugins/tasks/mctsubscribe.inc @@ -0,0 +1,129 @@ + 'page', + + 'title' => t('Mailchimp Subscribe Page'), + 'admin title' => t('Mailchimp Subscribe Page'), + 'admin description' => t('when enabled, this overrides the default Drupal behavior of the Mailchimp Subscribe page at mailchimp/subscribe'), + 'admin path' => 'mailchimp/subscribe', + + // Menu hooks so that we can alter the /user/%uid/mailchimp menu entry to point to us. + 'hook menu' => 'mailchimp_panels_mctsubscribe_menu', + 'hook menu alter' => 'mailchimp_panels_mctsubscribe_menu_alter', + + // This is task uses 'context' handlers and must implement these to give the + // handler data it needs. + 'handler type' => 'context', + 'get arguments' => 'mailchimp_panels_mctsubscribe_get_arguments', + 'get context placeholders' => 'mailchimp_panels_mctsubscribe_get_contexts', + + // Allow this to be enabled or disabled: + 'disabled' => variable_get('mailchimp_panels_mctsubscribe_disabled', TRUE), + 'enable callback' => 'mailchimp_panels_mctsubscribe_enable', + ); +} + +/** + * Callback defined by mailchimp_panels_mctsubscribe_page_manager_tasks(). + * + * Alter the FAQ page with terms so that the FAQ page comes to us rather than the + * normal FAQ process. + * Menus to be altered are only the list faq display (faq,faq/%,faq/%/list,faq/list). + */ +function mailchimp_panels_mctsubscribe_menu_alter(&$items, $task) { + if (variable_get('mailchimp_panels_mctsubscribe_disabled', TRUE)) { + return; + } + + $callback = $items['mailchimp/subscribe']['page callback']; + // Override the faq term handler for our purpose. + if ($callback == 'mailchimp_subscribe_page' || variable_get('page_manager_override_anyway', FALSE)) { + $items['mailchimp/subscribe']['page callback'] = 'mailchimp_panels_mctsubscribe'; + $items['mailchimp/subscribe']['file path'] = $task['path']; + $items['mailchimp/subscribe']['file'] = $task['file']; + } + else { + variable_set('mailchimp_panels_mctsubscribe_disabled', TRUE); + if (!empty($GLOBALS['mailchimp_panels_enabling_mctsubscribe'])) { + drupal_set_message(t('Page manager module is unable to enable mailchimp/subscribe because some other module already has overridden with %callback.', array('%callback' => $callback)), 'warning'); + } + + } + + return; +} + +/** + * Entry point for our overridden cck email generated contact form page. + * + * This function asks its assigned handlers who, if anyone, would like + * to run with it. If no one does, it passes through to CCK email field, which is email_mail_page(). + */ +function mailchimp_panels_mctsubscribe() { + // Load my task plugin + $task = page_manager_get_task('mctsubscribe'); + ctools_include('context'); + ctools_include('context-task-handler'); + $contexts = mailchimp_panels_mctsubscribe_get_contexts($task, '', array($user)); + $args = array($user->uid); + $output = ctools_context_handler_render($task, '', $contexts, $args); + if ($output !== FALSE) { + return $output; + } + $function = 'mailchimp_subscribe_page'; + foreach (module_implements('page_manager_override') as $module) { + $call = $module . '_page_manager_override'; + if (($rc = $call('mctsubscribe')) && function_exists($rc)) { + $function = $rc; + break; + } + } + // Otherwise, fall back. + return $function(); +} + +/** + * Callback to get arguments provided by this task handler. + * + * Since this is the node edit and there is no UI on the arguments, we + * create dummy arguments that contain the needed data. + */ +function mailchimp_panels_mctsubscribe_get_arguments($task, $subtask_id) { + return array( + array( + 'settings' => array(), + ), + ); +} + +/** + * Callback to get context placeholders provided by this handler. + */ +function mailchimp_panels_mctsubscribe_get_contexts($task, $subtask_id) { + return ctools_context_get_placeholders_from_argument(mailchimp_panels_mctsubscribe_get_arguments($task, $subtask_id)); +} + +/** + * Callback to enable/disable the page from the UI. + */ +function mailchimp_panels_mctsubscribe_enable($cache, $status) { + variable_set('mailchimp_panels_mctsubscribe_disabled', $status); + // Set a global flag so that the menu routine knows it needs + // to set a message if enabling cannot be done. + if (!$status) { + $GLOBALS['mailchimp_panels_enabling_mctsubscribe'] = TRUE; + } +} \ No newline at end of file diff --git a/mailchimp_panels/plugins/tasks/mctunsubscribe.inc b/mailchimp_panels/plugins/tasks/mctunsubscribe.inc new file mode 100644 index 0000000..26f6936 --- /dev/null +++ b/mailchimp_panels/plugins/tasks/mctunsubscribe.inc @@ -0,0 +1,129 @@ + 'page', + + 'title' => t('Mailchimp unsubscribe page'), + 'admin title' => t('Mailchimp unsubscribe page'), + 'admin description' => t('when enabled, this overrides the default Drupal behavior of the Mailchimp Subscribe page at mailchimp/unsubscribe'), + 'admin path' => 'mailchimp/unsubscribe', + + // Menu hooks so that we can alter the /user/%uid/mailchimp menu entry to point to us. + 'hook menu' => 'mailchimp_panels_mctunsubscribe_menu', + 'hook menu alter' => 'mailchimp_panels_mctunsubscribe_menu_alter', + + // This is task uses 'context' handlers and must implement these to give the + // handler data it needs. + 'handler type' => 'context', + 'get arguments' => 'mailchimp_panels_mctunsubscribe_get_arguments', + 'get context placeholders' => 'mailchimp_panels_mctunsubscribe_get_contexts', + + // Allow this to be enabled or disabled: + 'disabled' => variable_get('mailchimp_panels_mctunsubscribe_disabled', TRUE), + 'enable callback' => 'mailchimp_panels_mctunsubscribe_enable', + ); +} + +/** + * Callback defined by mailchimp_panels_mctunsubscribe_page_manager_tasks(). + * + * Alter the FAQ page with terms so that the FAQ page comes to us rather than the + * normal FAQ process. + * Menus to be altered are only the list faq display (faq,faq/%,faq/%/list,faq/list). + */ +function mailchimp_panels_mctunsubscribe_menu_alter(&$items, $task) { + if (variable_get('mailchimp_panels_mctunsubscribe_disabled', TRUE)) { + return; + } + + $callback = $items['mailchimp/unsubscribe']['page callback']; + // Override the faq term handler for our purpose. + if ($callback == 'drupal_get_form' || variable_get('page_manager_override_anyway', FALSE)) { + $items['mailchimp/unsubscribe']['page callback'] = 'mailchimp_panels_mctunsubscribe'; + $items['mailchimp/unsubscribe']['file path'] = $task['path']; + $items['mailchimp/unsubscribe']['file'] = $task['file']; + } + else { + variable_set('mailchimp_panels_mctunsubscribe_disabled', TRUE); + if (!empty($GLOBALS['mailchimp_panels_enabling_mctunsubscribe'])) { + drupal_set_message(t('Page manager module is unable to enable mailchimp/unsubscribe because some other module already has overridden with %callback.', array('%callback' => $callback)), 'warning'); + } + + } + + return; +} + +/** + * Entry point for our overridden cck email generated contact form page. + * + * This function asks its assigned handlers who, if anyone, would like + * to run with it. If no one does, it passes through to CCK email field, which is email_mail_page(). + */ +function mailchimp_panels_mctunsubscribe() { + // Load my task plugin + $task = page_manager_get_task('mctunsubscribe'); + ctools_include('context'); + ctools_include('context-task-handler'); + $contexts = mailchimp_panels_mctunsubscribe_get_contexts($task, '', array($user)); + $args = array($user->uid); + $output = ctools_context_handler_render($task, '', $contexts, $args); + if ($output !== FALSE) { + return $output; + } + $function = 'drupal_get_form'; + foreach (module_implements('page_manager_override') as $module) { + $call = $module . '_page_manager_override'; + if (($rc = $call('mctunsubscribe')) && function_exists($rc)) { + $function = $rc; + break; + } + } + // Otherwise, fall back. + return $function('mailchimp_unsubscribe_form'); +} + +/** + * Callback to get arguments provided by this task handler. + * + * Since this is the node edit and there is no UI on the arguments, we + * create dummy arguments that contain the needed data. + */ +function mailchimp_panels_mctunsubscribe_get_arguments($task, $subtask_id) { + return array( + array( + 'settings' => array(), + ), + ); +} + +/** + * Callback to get context placeholders provided by this handler. + */ +function mailchimp_panels_mctunsubscribe_get_contexts($task, $subtask_id) { + return ctools_context_get_placeholders_from_argument(mailchimp_panels_mctunsubscribe_get_arguments($task, $subtask_id)); +} + +/** + * Callback to enable/disable the page from the UI. + */ +function mailchimp_panels_mctunsubscribe_enable($cache, $status) { + variable_set('mailchimp_panels_mctunsubscribe_disabled', $status); + // Set a global flag so that the menu routine knows it needs + // to set a message if enabling cannot be done. + if (!$status) { + $GLOBALS['mailchimp_panels_enabling_mctunsubscribe'] = TRUE; + } +} \ No newline at end of file