You are here

function socialmedia_admin_settings in Social media 7

Builds and returns the socialmedia settings form.

1 string reference to 'socialmedia_admin_settings'
socialmedia_menu in ./socialmedia.module
Implements hook_menu().

File

./socialmedia.admin.inc, line 12
Admin page callback for the socialmedia module.

Code

function socialmedia_admin_settings() {
  drupal_add_css(drupal_get_path('module', 'socialmedia') . '/socialmedia.admin.css');
  $form = array();
  $form['platforms'] = array(
    '#type' => 'fieldset',
    '#title' => t('Platforms'),
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
    '#description' => t('Select which social media platforms you want to enable on your site.'),
  );
  $platforms = socialmedia_platform_definitions();
  $options = array();
  $extra = array();
  foreach ($platforms as $platform_name => $platform) {
    $options[$platform_name] = $platform['title'];
  }
  $defaults = array_keys($options);
  $form['platforms']['socialmedia_platforms_site'] = array(
    '#type' => 'checkboxes',
    '#title' => t('Site platforms'),
    '#default_value' => variable_get('socialmedia_platforms_site', $defaults),
    '#description' => t('Select the platforms you want active for site wide profiles.'),
    '#options' => $options,
  );
  $form['platforms']['socialmedia_platforms_user'] = array(
    '#type' => 'checkboxes',
    '#title' => t('User platforms'),
    '#default_value' => variable_get('socialmedia_platforms_user', $defaults),
    '#description' => t('Select the platforms you want active for user level profiles. Only users with the !permissions permission will be able to add user profiles.', array(
      '!permissions' => l(t('Administer own social profiles'), 'admin/people/permissions'),
    )),
    '#options' => $options,
    '#multicolumn' => array(
      'width' => 2,
    ),
  );
  $form['appearance'] = array(
    '#type' => 'fieldset',
    '#title' => t('Default widget appearance'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
    '#description' => t('Default settings for widget appearance.'),
  );
  $form['appearance']['socialmedia_default_width'] = array(
    '#type' => 'textfield',
    '#title' => t('Width'),
    '#size' => 4,
    '#field_suffix' => t('px'),
    '#default_value' => variable_get('socialmedia_default_width', SOCIALMEDIA_WIDTH_DEFAULT),
  );
  $form['appearance']['socialmedia_default_height'] = array(
    '#type' => 'textfield',
    '#title' => t('Height'),
    '#size' => 4,
    '#field_suffix' => t('px'),
    '#default_value' => variable_get('socialmedia_default_height', SOCIALMEDIA_HEIGHT_DEFAULT),
  );
  $form['appearance']['socialmedia_default_color_body_background'] = array(
    '#type' => 'textfield',
    '#title' => t('Body background color'),
    '#size' => 8,
    '#default_value' => variable_get('socialmedia_default_color_body_background', SOCIALMEDIA_COLOR_BODY_BACKGROUND_DEFAULT),
  );
  $form['appearance']['socialmedia_default_color_body_text'] = array(
    '#type' => 'textfield',
    '#title' => t('Body text color'),
    '#size' => 8,
    '#default_value' => variable_get('socialmedia_default_color_body_text', SOCIALMEDIA_COLOR_BODY_TEXT_DEFAULT),
  );
  $form['appearance']['socialmedia_default_color_body_linktext'] = array(
    '#type' => 'textfield',
    '#title' => t('Body linktext color'),
    '#size' => 8,
    '#default_value' => variable_get('socialmedia_default_color_body_linktext', SOCIALMEDIA_COLOR_BODY_LINKTEXT_DEFAULT),
  );
  $form['appearance']['socialmedia_default_color_header_background'] = array(
    '#type' => 'textfield',
    '#title' => t('Header background color'),
    '#size' => 8,
    '#default_value' => variable_get('socialmedia_default_color_header_background', SOCIALMEDIA_COLOR_HEADER_BACKGROUND_DEFAULT),
  );
  $form['appearance']['socialmedia_default_color_header_text'] = array(
    '#type' => 'textfield',
    '#title' => t('Header text color'),
    '#size' => 8,
    '#default_value' => variable_get('socialmedia_default_color_header_text', SOCIALMEDIA_COLOR_HEADER_TEXT_DEFAULT),
  );
  $form['appearance']['socialmedia_default_color_border'] = array(
    '#type' => 'textfield',
    '#title' => t('Border color'),
    '#size' => 8,
    '#default_value' => variable_get('socialmedia_default_color_border', SOCIALMEDIA_COLOR_BORDER_DEFAULT),
  );
  $form['link_attributes'] = array(
    '#type' => 'fieldset',
    '#title' => t('Default link attributes'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
    '#description' => t('Default settings link attributes.'),
  );
  $form['link_attributes']['socialmedia_default_link_target_profile'] = array(
    '#type' => 'textfield',
    '#title' => t('Profile target'),
    '#default_value' => variable_get('socialmedia_default_link_target_profile', SOCIALMEDIA_LINK_TARGET_PROFILE_DEFAULT),
    '#description' => t('Sets the default target= attribute on profile widget links. Set to <none> to remove attribute.'),
  );
  $options = array(
    '<none>' => t('Remove rel attribute'),
    'nofollow' => t('Set rel="nofollow"'),
  );
  $form['link_attributes']['socialmedia_default_link_rel_profile'] = array(
    '#type' => 'select',
    '#title' => t('Profile rel'),
    '#options' => $options,
    '#default_value' => variable_get('socialmedia_default_link_rel_profile', SOCIALMEDIA_LINK_REL_PROFILE_DEFAULT),
    '#description' => t('Sets the default rel= attribute on profile widget links.'),
  );
  $form['link_attributes']['socialmedia_default_link_class_profile'] = array(
    '#type' => 'textfield',
    '#title' => t('Profile class'),
    '#default_value' => variable_get('socialmedia_default_link_class_profile', SOCIALMEDIA_LINK_CLASS_PROFILE_DEFAULT),
    '#description' => t('Use to add css class attributes to links.'),
  );
  $form['link_attributes']['socialmedia_default_link_target_sharing'] = array(
    '#type' => 'textfield',
    '#title' => t('Sharing target'),
    '#default_value' => variable_get('socialmedia_default_link_target_sharing', SOCIALMEDIA_LINK_TARGET_SHARING_DEFAULT),
    '#description' => t('Sets the default target= attribute on sharing widget links. Set to &lt;none&gt; to remove attribute.'),
  );
  $options = array(
    '<none>' => t('Remove rel attribute'),
    'nofollow' => t('Set rel="nofollow"'),
  );
  $form['link_attributes']['socialmedia_default_link_rel_sharing'] = array(
    '#type' => 'select',
    '#title' => t('Sharing rel'),
    '#options' => $options,
    '#default_value' => variable_get('socialmedia_default_link_rel_sharing', SOCIALMEDIA_LINK_REL_SHARING_DEFAULT),
    '#description' => t('Sets the default rel= attribute on sharing widget links.'),
  );
  $form['link_attributes']['socialmedia_default_link_class_sharing'] = array(
    '#type' => 'textfield',
    '#title' => t('Sharing class'),
    '#default_value' => variable_get('socialmedia_default_link_class_sharing', SOCIALMEDIA_LINK_CLASS_SHARING_DEFAULT),
    '#description' => t('Use to add css class attributes to links.'),
  );
  $form['iconsets'] = array(
    '#type' => 'fieldset',
    '#title' => t('Icon sets'),
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
  );
  $options = socialmedia_icon_style_options(FALSE);
  $form['iconsets']['socialmedia_icon_default_style'] = array(
    '#type' => 'select',
    '#title' => t('Default icon style'),
    '#default_value' => variable_get('socialmedia_icon_default_style', SOCIALMEDIA_ICON_DEFAULT_STYLE_DEFAULT),
    //'#description' => t('The name is used in URLs for generated images. Use only lowercase alphanumeric characters, underscores (_), and hyphens (-).'),
    '#options' => $options,
  );
  $examples = socialmedia_icon_platforms(TRUE);
  $header = array(
    array(
      'data' => t('Icon set'),
      'style' => 'width: 150px;',
    ),
    t('Styles'),
  );
  foreach ($examples as $ekey => $ename) {
    $header[] = '';
  }
  $rows = array();
  $icons = socialmedia_iconset_info();

  //$examples = array('twitter', 'facebook', 'stumbleupon', 'youtube');
  foreach ($icons as $iconset_name => $iconset) {
    $name = isset($iconset['download']) ? l($iconset['name'], $iconset['download'], array(
      'attributes' => array(
        'target' => '_blank',
      ),
    )) : $iconset['name'];
    if (isset($iconset['publisher'])) {
      $name .= '<br />by ' . (isset($iconset['publisher url']) ? l($iconset['publisher'], $iconset['publisher url'], array(
        'attributes' => array(
          'target' => '_blank',
        ),
      )) : $iconset['publisher']);
    }
    $row = array(
      $name,
      implode('<br />', $iconset['styles']),
    );
    if (socialmedia_iconset_is_installed($iconset_name)) {
      foreach ($examples as $pkey => $pname) {
        if (isset($iconset['path callback'])) {
          $vars = array(
            'path' => call_user_func($iconset['path callback'], $pkey),
            //'alt' => $pname,
            'title' => $pname,
          );
          $row[] = theme('image', $vars) . ' ';
        }
        else {
          if (isset($iconset['markup callback'])) {
            $row[] = ' ';
          }
          else {
            $row[] = ' ';
          }
        }
      }
    }
    else {
      if (isset($iconset['download'])) {
        $str = t('<strong>Not installed.</strong><br />To install: !download and install into %dir.', array(
          '!download' => l(t('download'), $iconset['download'], array(
            'attributes' => array(
              'target' => '_blank',
            ),
          )),
          '%dir' => drupal_get_path('module', 'socialmedia') . '/icons/' . $iconset_name . '/',
        ));
      }
      else {
        $str = '';
      }
      if (isset($iconset['additional instructions'])) {
        $str .= ' ' . $iconset['additional instructions'];
      }
      $row[] = array(
        'data' => $str,
        'colspan' => count($examples),
      );
    }
    $rows[] = $row;
    $vars = array(
      'header' => $header,
      'rows' => $rows,
      'attributes' => array(
        'id' => 'socialmedia-iconsets',
      ),
    );
    $form['iconsets']['installed'] = array(
      '#markup' => theme('table', $vars),
    );
  }
  $form['#submit'][] = 'socialmedia_admin_settings_submit';
  return system_settings_form($form);
}