View source
<?php
function linkedin_status_linkedin_admin_page() {
$form = array();
$form['linkedin_status'] = array(
'#description' => t('Enable users to update their LinkedIn user status when performing following actions.'),
'#title' => t('Status update'),
'#type' => 'fieldset',
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$form['linkedin_status']['node_types'] = array(
'#description' => t('Let users update their status when creating/editing nodes of these types.'),
'#title' => t('Node types'),
'#type' => 'fieldset',
);
$types = node_get_types();
foreach ($types as $type) {
$form['linkedin_status']['node_types']['linkedin_status_enabled_' . $type->type] = array(
'#type' => 'checkbox',
'#prefix' => '<div class="linkedin-checkbox-toggle">',
'#suffix' => '</div>',
'#title' => $type->name,
'#default_value' => variable_get('linkedin_status_enabled_' . $type->type, '0'),
);
$form['linkedin_status']['node_types']['linkedin_status_default_format_' . $type->type] = array(
'#type' => 'textfield',
'#prefix' => '<div class="linkedin-hidden">',
'#suffix' => '</div>',
'#title' => t('Default format string'),
'#maxlength' => 140,
'#description' => t('Text that will be posted to Linked In. You can use !url, !title, !user, and !site as replacement text.'),
'#default_value' => variable_get('linkedin_status_default_format_' . $type->type, 'Posted "!title" on !site'),
);
}
if (module_exists('signup')) {
$form['linkedin_status']['event_signup'] = array(
'#description' => t('Let users update their status when signing up to events.'),
'#title' => t('Users signup'),
'#type' => 'fieldset',
);
$form['linkedin_status']['event_signup']['linkedin_status_enabled_event_signup'] = array(
'#type' => 'checkbox',
'#title' => 'Enable',
'#default_value' => variable_get('linkedin_status_enabled_event_signup', '0'),
);
$form['linkedin_status']['event_signup']['linkedin_status_default_format_event_signup'] = array(
'#type' => 'textfield',
'#title' => t('Default format string'),
'#maxlength' => 140,
'#description' => t('Text that will be posted to Linked In. You can use !url, !title, !user, and !site as replacement text.'),
'#default_value' => variable_get('linkedin_status_default_format_event_signup', 'Posted "!title" on !site'),
);
}
if (module_exists('comment')) {
$form['linkedin_status']['comment'] = array(
'#description' => t('Let users update their status when adding comments to a Linkedin enabled node.'),
'#title' => t('Comments'),
'#type' => 'fieldset',
);
$form['linkedin_status']['comment']['linkedin_status_enabled_comment'] = array(
'#type' => 'checkbox',
'#title' => 'Enable',
'#default_value' => variable_get('linkedin_status_enabled_comment', '0'),
);
$form['linkedin_status']['comment']['linkedin_status_default_format_comment'] = array(
'#type' => 'textfield',
'#title' => t('Default format string'),
'#maxlength' => 140,
'#description' => t('Text that will be posted to Linked In. You can use !url, !title, !user, and !site as replacement text.'),
'#default_value' => variable_get('linkedin_status_default_format_comment', 'Commented on "!title" on !site'),
);
}
return $form;
}
function linkedin_status_update_form($form_state, $user, $node) {
if ($user->linkedin_status_enabled_by_default == 1 && !isset($node->nid)) {
$checked = 1;
}
else {
$checked = 0;
}
$form['linkedin_status'] = array(
'#type' => 'fieldset',
'#collapsible' => TRUE,
'#title' => t('Post to LinkedIn'),
'#tree' => TRUE,
);
$form['linkedin_status']['posting'] = array(
'#type' => 'checkbox',
'#id' => 'linkedin-status-posting',
'#default_value' => $checked,
);
$form['linkedin_status']['posting']['#title'] = t('Announce on LinkedIn');
$check = linkedin_get_profile_fields($user->uid, array(
'id',
));
if (!isset($check['id'])) {
$form['linkedin_status']['posting']['#disabled'] = TRUE;
$form['linkedin_status']['posting']['#prefix'] = '<p>' . t('You must first authorize this feature in your user profile : !url', array(
'!url' => l($user->name, 'user/' . $user->uid . '/edit/linkedin'),
)) . '</p>';
}
else {
if (user_access('use custom status text')) {
drupal_add_js(drupal_get_path('module', 'linkedin_status') . '/linkedin_status.js', 'module');
$form['linkedin_status']['status'] = array(
'#type' => 'textfield',
'#default_value' => variable_get('linkedin_status_default_format_' . $node->type, ''),
'#description' => t('This text will be set as your current status on linkedin. You can use !title, !url, !user and !site as replacement text.'),
'#id' => 'linkedin-status-textfield',
);
}
else {
$form['linkedin_status']['status'] = array(
'#type' => 'hidden',
'#value' => variable_get('linkedin_status_default_format_' . $node->type, ''),
);
}
}
return $form;
}
function linkedin_status_update_form_submit($form, &$form_state) {
if (isset($form_state['values']['status']) && $form_state['values']['status'] == 0) {
return;
}
if ($form_state['values']['linkedin_status']['posting'] == '1' && !empty($form_state['values']['linkedin_status']['status']) && user_access('update LinkedIn status')) {
if ($form['linkedin']) {
$prefix = $form['linkedin'];
}
elseif ($form['collapse']['signup_user_form']['linkedin']) {
$prefix = $form['collapse']['signup_user_form']['linkedin'];
}
else {
drupal_set_message('Linkedin module has a serious problem! Please file an issue at http://drupal.org/project/linkedin');
return;
}
if (!empty($form_state['values']['nid'])) {
$node = node_load($form_state['values']['nid']);
linkedin_status_set_status($form_state['values']['linkedin_status']['status'], $node);
}
}
}