You are here

function push_notifications_admin_form in Push Notifications 7

Form callback for Push Notifications Settings.

1 string reference to 'push_notifications_admin_form'
push_notifications_menu in ./push_notifications.module
Implements of hook_menu().

File

includes/push_notifications.admin.inc, line 104
Admin files for Push Notifications module.

Code

function push_notifications_admin_form($form_state) {
  $form = array();

  // Add JavaScript for Google push notification selector.
  drupal_add_js(drupal_get_path('module', 'push_notifications') . '/scripts/push_notifications_admin.js');
  $form['configuration_general'] = array(
    '#type' => 'fieldset',
    '#title' => t('General Push Notifications Settings'),
  );
  $form['configuration_general']['push_notifications_require_enabled_language'] = array(
    '#type' => 'checkbox',
    '#title' => t('Only allow enabled languages'),
    '#description' => t('When setting a device token, only allow languages that are enabled on this site (instead of all valid langauges)'),
    '#default_value' => variable_get('push_notifications_require_enabled_language', 0),
  );
  $replacements_privatemsg = array(
    '!privatemsg' => l('PrivateMSG', 'http://drupal.org/project/privatemsg/', array(
      'html' => true,
      'attributes' => array(
        'target' => '_blank',
      ),
    )),
    '!privatemsg_status' => module_exists('privatemsg') ? 'successfully installed' : 'not installed',
  );
  $form['configuration_general']['push_notifications_privatemsg_integration'] = array(
    '#type' => 'checkbox',
    '#title' => t('Enable integration with PrivateMSG module'),
    '#description' => t('Check this to deliver messages sent through the !privatemsg module to all recipients with at least one valid device token. Requires !privatemsg module 7.x-1.x (status: !privatemsg_status)', $replacements_privatemsg),
    '#default_value' => variable_get('push_notifications_privatemsg_integration', 0),
  );
  $configuration_apns_replacements = array(
    '!link' => l(t('this tutorial'), 'http://blog.boxedice.com/2009/07/10/how-to-build-an-apple-push-notification-provider-server-tutorial/', array(
      'attributes' => array(
        'target' => '_blank',
      ),
    )),
    '!cert_name_development' => 'apns-development' . PUSH_NOTIFICATIONS_APNS_CERTIFICATE_RANDOM . '.pem',
    '!cert_name_production' => 'apns-production' . PUSH_NOTIFICATIONS_APNS_CERTIFICATE_RANDOM . '.pem',
  );
  $form['configuration_apns'] = array(
    '#type' => 'fieldset',
    '#title' => t('Apple Push Notifications'),
    '#description' => t('Configure Push Notifications for Apple\'s Push Notification Server. Select your environment. Both environments require the proper certificates in the \'certificates\' folder of this module.<br />The filename for the development certificate should be \'!cert_name_development\', the production certificate should be \'!cert_name_production\'. See !link for instructions on creating certificates.', $configuration_apns_replacements),
  );
  if (variable_get('push_notifications_apns_certificate_random', '') == '') {
    $regenerate_certificate_string_description = t('Your certificate name is currently set to the default. To increase security, click here to create a custom name for your APNS certificates. Please note that you will have to change the filenames for both certificate files afterwards.');
  }
  else {
    $regenerate_certificate_string_description = t('You are already using a random certificate name. Click here to create a new random name for your APNS certificates. Please note that you will have to update the filenames for both certificate files accordingly.');
  }
  $form['configuration_apns']['regenerate_certificate_string_description'] = array(
    '#type' => 'item',
    '#title' => t('APNS Certificate Name'),
    '#markup' => $regenerate_certificate_string_description,
  );
  $form['configuration_apns']['regenerate_certificate_string'] = array(
    '#type' => 'submit',
    '#value' => t('Generate new certificate string'),
    '#submit' => array(
      'push_notifications_regenerate_certificate_string_submit',
    ),
  );
  $form['configuration_apns']['push_notifications_apns_environment'] = array(
    '#type' => 'select',
    '#title' => t('APNS Environment'),
    '#description' => t('Select the active APNS Environment. Please note that development certificates do not work with apps released in the Apple app store; production certificates only work with apps released in the app store.'),
    '#options' => array(
      0 => 'Development',
      1 => 'Production',
    ),
    '#default_value' => variable_get('push_notifications_apns_environment', 0),
  );
  $form['configuration_apns']['stream_context_limit'] = array(
    '#type' => 'select',
    '#title' => t('Stream Context Limit'),
    '#description' => t('Defines the amount of messages sent per stream limit, i.e. how many notifications are sent per connection created with Apple\'s servers. The higher the limit, the faster the message delivery. If the limit is too high, messages might not get delivered at all. Unclear (to me) what Apple\'s <em>actual</em> limit is.'),
    '#options' => drupal_map_assoc(array(
      1,
      5,
      10,
      25,
      50,
    )),
    '#default_value' => variable_get('push_notifications_apns_stream_context_limit', 1),
  );
  $form['configuration_apns']['passphrase'] = array(
    '#type' => 'textfield',
    '#title' => t('Passphrase'),
    '#description' => t('If your APNS certificate has a passphrase, enter it here. Otherwise, leave this field blank.'),
    '#default_value' => variable_get('push_notifications_apns_passphrase', ''),
  );
  $form['configuration_apns']['push_notifications_apns_certificate_folder'] = array(
    '#type' => 'textfield',
    '#title' => t('APNS Certificate Folder Path'),
    '#description' => t('The preferred location for the certificate files is a folder outside of your web root, i.e. a folder not accessible through the Internet. Specify the full path here, e.g. \'/users/danny/drupal_install/certificates/\'. If you are using the \'certificates\' folder within the module directory, leave this field blank.'),
    '#default_value' => variable_get('push_notifications_apns_certificate_folder', ''),
  );
  $form['configuration_apns']['push_notifications_set_entrust_certificate'] = array(
    '#type' => 'checkbox',
    '#title' => t('Set Entrust root certificate'),
    '#description' => t('If APNS does not work and you are getting errors like %php_error_string your server might be missing the Entrust root certificate. Enable this to explicitely add it when establishing a connection to APNS. See more in this !link_kb and the !link_entrust.', array(
      '%php_error_string' => 'Warning: stream_socket_client() [...]',
      '!link_entrust' => l('Entrust Root Certificate Downloads', 'https://www.entrust.com/get-support/ssl-certificate-support/root-certificate-downloads/', array(
        'attributes' => array(
          'target' => '_blank',
        ),
      )),
      '!link_kb' => l('Knowledgebase Article', 'http://stackoverflow.com/questions/4817520/why-ssl-of-entrust-ssl-certificate-is-required-for-apns', array(
        'attributes' => array(
          'target' => '_blank',
        ),
      )),
    )),
    '#default_value' => variable_get('push_notifications_set_entrust_certificate', 0),
  );
  $form['configuration_c2dm'] = array(
    '#type' => 'fieldset',
    '#title' => t('Google Push Notifications'),
    '#description' => t('Requires a valid Google Cloud Messaging or C2DM account. !signup for Google Cloud Messaging. Google does not accept new signups for C2DM.', array(
      '!signup' => l(t('Signup here'), 'http://developer.android.com/guide/google/gcm/gs.html', array(
        'attributes' => array(
          'target' => '_blank',
        ),
      )),
    )),
  );
  $form['configuration_c2dm']['push_notifications_google_type'] = array(
    '#type' => 'radios',
    '#title' => t('Google Push Notifications Type'),
    '#description' => t('Google\'s GCM service (Google Cloud Messaging) is being replaced by the Firebase Cloud Messaging Service (FCM). Google\'s C2DM service (Cloud 2 Device Messaging) was replaced by the Google Cloud Messaging Service (GCM). Each services requires a different authentication method. '),
    '#default_value' => PUSH_NOTIFICATIONS_GOOGLE_TYPE,
    '#options' => array(
      PUSH_NOTIFICATIONS_GOOGLE_TYPE_C2DM => 'Cloud 2 Device Messaging',
      PUSH_NOTIFICATIONS_GOOGLE_TYPE_GCM => 'Google Cloud Messaging',
      PUSH_NOTIFICATIONS_GOOGLE_TYPE_FCM => 'Firebase Cloud Messaging',
    ),
  );
  $c2dm_credentials_visible = PUSH_NOTIFICATIONS_GOOGLE_TYPE == PUSH_NOTIFICATIONS_GOOGLE_TYPE_C2DM;
  $form['configuration_c2dm']['c2dm_credentials'] = array(
    '#type' => 'fieldset',
    '#title' => t('Cloud 2 Device Messaging Settings'),
    '#description' => t('Enter your C2DM credentials.'),
    '#attributes' => array(
      'style' => PUSH_NOTIFICATIONS_GOOGLE_TYPE != PUSH_NOTIFICATIONS_GOOGLE_TYPE_C2DM ? 'display:none' : '',
    ),
  );
  $form['configuration_c2dm']['c2dm_credentials']['push_notifications_c2dm_username'] = array(
    '#type' => 'textfield',
    '#title' => t('C2DM Username'),
    '#description' => t('Enter the username for your C2DM Google Account'),
    '#default_value' => variable_get('push_notifications_c2dm_username', ''),
  );
  $form['configuration_c2dm']['c2dm_credentials']['push_notifications_c2dm_password'] = array(
    '#type' => 'textfield',
    '#title' => t('C2DM Password'),
    '#description' => t('Enter the password for your C2DM Google Account'),
    '#default_value' => variable_get('push_notifications_c2dm_password', ''),
  );
  $form['configuration_c2dm']['gcm_credentials'] = array(
    '#type' => 'fieldset',
    '#title' => t('Google Cloud Messaging'),
    '#description' => t('Enter your Google Cloud Messaging details'),
    '#attributes' => array(
      'style' => PUSH_NOTIFICATIONS_GOOGLE_TYPE != PUSH_NOTIFICATIONS_GOOGLE_TYPE_GCM ? 'display:none' : '',
    ),
  );
  $form['configuration_c2dm']['gcm_credentials']['push_notifications_gcm_api_key'] = array(
    '#type' => 'textfield',
    '#title' => t('Google Cloud Messaging API Key'),
    '#description' => t('Enter the API key for your Google Cloud project'),
    '#default_value' => variable_get('push_notifications_gcm_api_key', ''),
  );
  $form['configuration_c2dm']['fcm_credentials'] = array(
    '#type' => 'fieldset',
    '#title' => t('Firebase Cloud Messaging'),
    '#description' => t('Enter your Firebase Cloud Messaging details'),
    '#attributes' => array(
      'style' => PUSH_NOTIFICATIONS_GOOGLE_TYPE != PUSH_NOTIFICATIONS_GOOGLE_TYPE_FCM ? 'display:none' : '',
    ),
  );
  $form['configuration_c2dm']['fcm_credentials']['push_notifications_fcm_cloud_messaging_token'] = array(
    '#type' => 'textfield',
    '#title' => t('Firebase Cloud Messaging token'),
    '#description' => t('Enter the token for your Firebase project'),
    '#default_value' => variable_get('push_notifications_fcm_cloud_messaging_token', ''),
    '#maxlength' => 255,
  );
  $form['configuration_c2dm']['fcm_credentials']['push_notifications_fcm_server_key'] = array(
    '#type' => 'textfield',
    '#title' => t('Server key'),
    '#description' => t('Enter the Server key for your Firebase project'),
    '#default_value' => variable_get('push_notifications_fcm_server_key', ''),
  );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => 'Save Configuration',
  );
  return $form;
}