View source
<?php
function heartbeat_admin_settings() {
$form['heartbeat_enabled'] = array(
'#title' => t('Do you want to enable the heatbeat?'),
'#type' => 'checkbox',
'#size' => 5,
'#default_value' => variable_get('heartbeat_enabled', 1),
);
return system_settings_form($form);
}
function heartbeat_messages_overview() {
global $base_url;
rules_clear_cache();
$intro = '';
$info = heartbeat_gather_messages();
$messages = heartbeat_messages('all', true, true);
if (!empty($info)) {
drupal_set_message(t('New messages were added to heartbeat.'));
}
if (count($messages) <= 0) {
return t('Sorry, no heartbeat messages yet');
}
foreach ($messages as $message) {
if (module_exists('locale')) {
$languages = locale_language_list();
$message->description .= '<div style="display: none;">';
foreach ($languages as $lang => $human_language) {
$message->description .= $human_language . ': ' . t($message->message, array(), $lang) . '<br />';
$message->description .= $human_language . ': ' . t($message->message_concat, array(), $lang) . '<br />';
}
$message->description .= '</div>';
$report = array();
foreach ($languages as $lang => $human_language) {
if ($lang != 'en') {
if (t($message->message, array(), $lang) == t($message->message, array(), 'en')) {
$label = t('translate message in @human_language', array(
'@human_language' => strip_tags($human_language),
));
$options = array(
'query' => 'op=Search&string=' . str_replace(" ", "+", $message->message),
);
$report[] = l($label, 'admin/build/translate/search', $options);
}
if (t($message->message_concat, array(), $lang) == t($message->message_concat, array(), 'en')) {
$label = t('translate grouping message in @human_language', array(
'@human_language' => strip_tags($human_language),
));
$options = array(
'query' => 'op=Search&string=' . str_replace(" ", "+", $message->message_concat),
);
$report[] = l($label, 'admin/build/translate/search', $options);
}
if (eregi("#", $message->variables_string)) {
$report[] = '<small>' . t('In at least one of the messages a part must be translated separately') . '</small>';
}
}
}
if ($report != array()) {
$message->description .= '<br />' . implode(', ', $report);
}
}
$rows[] = array(
$message->event,
$message->description,
$message->karma_index,
l(t('edit'), $base_url . "/admin/settings/heartbeat/messages/" . $message->event),
);
}
$headers = array(
t('Event'),
t('Description'),
t('Karma index'),
t('Operations'),
);
$intro .= '<h2>Modules that describe heartbeat messages.</h2>';
$intro .= '<p>The messages that go with this event are passed to the t-function when parsed to view.';
$intro .= '</p>';
if (module_exists('locale')) {
$intro .= '<p>';
$intro .= 'This means that once they are viewed, they are available for you to translate.';
$intro .= 'Altering these messages will clear the rules cache and the altered message ';
$intro .= 'will need translation if you are dealing with a multilingual site. The links show only the untranslated messages.';
$intro .= '</p>';
}
return t($intro) . theme('table', $headers, $rows);
}
function heartbeat_messages_edit(&$form_state, $event = '', $edit = array()) {
$form = array();
$form[$event] = array(
'#type' => 'fieldset',
'#title' => t($event),
'#collapsible' => true,
'#collapsed' => FALSE,
'#prefix' => '<p><strong>You can use the token replacements in your message.</strong></p>',
);
$result = db_query("SELECT * FROM {heartbeat_messages} WHERE event = '%s' LIMIT 1", $event);
$message = db_fetch_object($result);
$variables = heartbeat_decode_message_variables($message->variables);
$form[$event]['message'] = array(
'#type' => 'textarea',
'#title' => t($message->description),
'#cols' => 10,
'#rows' => 1,
'#default_value' => empty($edit['message']) ? $message->message : $edit['message'],
'#prefix' => '<p>' . t('<strong>Token replacements</strong>: <br />') . str_replace("#", "@", implode(', ', array_keys($variables))) . '.</p>',
);
$form[$event]['message_concat'] = array(
'#type' => 'textarea',
'#cols' => 10,
'#rows' => 1,
'#default_value' => empty($edit['message_concat']) ? $message->message_concat : $edit['message_concat'],
);
$form[$event]['karma_index'] = array(
'#type' => 'textfield',
'#title' => t('karma index'),
'#required' => TRUE,
'#default_value' => empty($edit['karma_index']) ? $message->karma_index : $edit['karma_index'],
);
$form[$event]['event'] = array(
'#type' => 'hidden',
'#default_value' => empty($edit['event']) ? $event : $edit['event'],
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Save'),
);
if (isset($edit['event'])) {
$form['delete'] = array(
'#type' => 'submit',
'#value' => t('Delete'),
);
$form['event'] = array(
'#type' => 'value',
'#value' => $event,
);
}
return $form;
}
function heartbeat_messages_edit_submit($form, &$form_state) {
if ($form_state['clicked_button']['#value'] == t('Save')) {
db_query("UPDATE {heartbeat_messages} SET message ='%s', message_concat ='%s', karma_index = %d \n WHERE event = '%s'", $form_state['values']['message'], $form_state['values']['message_concat'], $form_state['values']['karma_index'], $form_state['values']['event']);
}
rules_clear_cache();
drupal_set_message('Settings updated');
return;
}