social_content.admin.inc in Social Content 7
Same filename and directory in other branches
Social Content administration area. Provides menu callbacks for the Social Content administration area.
File
social_content.admin.incView source
<?php
/**
* @file
* Social Content administration area.
* Provides menu callbacks for the Social Content administration area.
*/
/**
* Menu callback for admin/config/services/social-content.
*
* Displays a table with all social content types.
*/
function social_content_overview_types() {
$types = social_content_get_types();
$header = array(
t('Name'),
t('Enabled'),
t('Run Import'),
t('Settings'),
);
$rows = array();
foreach ($types as $key => $type) {
$settings = social_content_get_settings($type);
$destination = drupal_get_destination();
$run_link = l(t('Run import'), 'admin/config/services/social-content/' . $type['name'] . '/run', array(
'query' => $destination,
));
$edit_link = l(t('Edit'), 'admin/config/services/social-content/' . $type['name'] . '/edit', array(
'query' => $destination,
));
$rows[] = array(
$type['title'],
$settings['enabled'] ? t('Yes') : t('No'),
$run_link,
$edit_link,
);
}
$build['node_table'] = array(
'#theme' => 'table',
'#header' => $header,
'#rows' => $rows,
'#empty' => t('No social content types enabled, you must enable a social content type module first.'),
);
return $build;
}
/**
* Form handler for social content type settings.
*
* Menu callback for
* admin/config/services/social-content/%social_content_type/edit.
* Builds a form from default settings and module specific settings.
*/
function social_content_form($form, &$form_state, $social_content_type = NULL) {
$settings = social_content_get_settings($social_content_type);
$form = array();
// Setup the fieldset.
$fieldset_name = 'social_content_' . $social_content_type['name'];
$form[$fieldset_name] = array(
'#type' => 'fieldset',
'#title' => t('Social Content !social_content_type', array(
'!social_content_type' => $social_content_type['title'],
)),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
'#tree' => TRUE,
);
// Grab the module specific settings.
if (function_exists($social_content_type['settings_form'])) {
$social_content_type['settings_form']($form[$fieldset_name], $social_content_type, $settings);
}
$form[$fieldset_name]['limit'] = array(
'#type' => 'textfield',
'#title' => t('Import limit'),
'#size' => 10,
'#description' => t('Set the maximum number of posts to import each time. Leave blank for no limit.'),
'#default_value' => $settings['limit'],
'#required' => FALSE,
'#element_validate' => array(
'element_validate_number',
),
);
$form[$fieldset_name]['auto_publish'] = array(
'#type' => 'checkbox',
'#title' => t('Publish !social_content_type nodes', array(
'!social_content_type' => $social_content_type['title'],
)),
'#description' => t('Set all !social_content_type nodes to be published by default.
Disabling this will allow content to be moderated.', array(
'!social_content_type' => $social_content_type['title'],
)),
'#default_value' => $settings['auto_publish'],
'#required' => FALSE,
);
$form[$fieldset_name]['enabled'] = array(
'#type' => 'checkbox',
'#title' => t('Enabled on cron'),
'#description' => t('Enable !social_content_type posts to be imported on cron runs.', array(
'!social_content_type' => $social_content_type['title'],
)),
'#default_value' => $settings['enabled'],
'#required' => FALSE,
);
return system_settings_form($form);
}
/**
* Form callback for running a social content import.
*
* Provides a simple confirm form.
*/
function social_content_import_run_form($form, &$form_state, $social_content_type = NULL) {
$form['description'] = array(
'#markup' => '<p>' . t('Run the !social_content_type_name import. Note that only new items will be imported.', array(
'!social_content_type_name' => $social_content_type['title'],
)) . '</p>',
);
$form['#storage']['social_content_type'] = $social_content_type;
$form['run_import'] = array(
'#title' => t('Run Import'),
'#value' => t('Run Import'),
'#type' => 'submit',
);
return $form;
}
/**
* Submit handler for social_content_import_run_form().
*
* Run the selected import (regardless of whether it's enabled on cron).
* Report back results to the user.
*
* NOTE: This should really be in a batch job, but because cron doesn't
* currently run on batch it was decided to simulate the request here.
*/
function social_content_import_run_form_submit($form, &$form_state, $social_content_type = NULL) {
if (isset($form['#storage']) && isset($form['#storage']['social_content_type'])) {
$social_content_type = $form['#storage']['social_content_type'];
$settings = social_content_get_settings($social_content_type);
$result = social_content_run_import($social_content_type, $settings);
if ($result !== FALSE) {
$args = array(
'!social_content_type_name' => $social_content_type['title'],
'!number' => (int) $result,
);
drupal_set_message(t('!social_content_type_name run successfully, imported !number nodes', $args));
}
else {
$args = array(
'!social_content_type_name' => $social_content_type['title'],
'!logs_link' => l(t('logs'), 'admin/reports/dblog'),
);
if (module_exists('dblog')) {
$message = t('Errors running !social_content_type_name import. Please check the !logs_link for more information.', $args);
}
else {
$message = t('Errors running !social_content_type_name import. Enable the Database logging module to view the errors.', $args);
}
drupal_set_message($message, 'error');
}
}
}
Functions
Name![]() |
Description |
---|---|
social_content_form | Form handler for social content type settings. |
social_content_import_run_form | Form callback for running a social content import. |
social_content_import_run_form_submit | Submit handler for social_content_import_run_form(). |
social_content_overview_types | Menu callback for admin/config/services/social-content. |