| 1 |
<?php
|
| 2 |
// $Id$
|
| 3 |
|
| 4 |
function _trackback_help($path, $arg) {
|
| 5 |
switch ($path) {
|
| 6 |
case 'admin/help#trackback':
|
| 7 |
$output = '<p>'. t('The trackback module allows users to give a blog post a contextual link to another. A context is made because the trackbacking poster is, in theory, writing about something mentioned on another blogger\'s trackbacked post. Using the trackback URL accompanying each post, another website can send a ping to your website. Once received, the trackback will show up on the trackback page accompanying the post. It also includes auto-discovery, spam moderation queues, and the ability to manually ping another site.') .'</p>';
|
| 8 |
$output .= '<p>'. t('If trackback autodisovery is enabled on your website, someone need only visit your post via a link from another website post to have trackback <em>discover</em> the linking site and create the trackback. Trackback auto-discovery also works internally within a website, automatically creating connections between pages which link to each other. To manually send a ping to another site, edit your post and use the trackback URL field at the bottom of the edit page to submit the trackback URL for the post on the other site. Once you enter submit, your website will ping the other site for you. With trackback autodiscovery enabled, your site will attempt to do this automatically without your intervention.') .'</p>';
|
| 9 |
$output .= '<p>'. t('To enable the moderation queue, go to the administer trackbacks page and select the configure tab. To view, approve, or delete trackbacks awaiting moderation, go to the administer trackbacks page and select the approval queue. To administer the trackback settings for a particular content type go to that content types administration page.') .'</p>';
|
| 10 |
$output .= '<p>'. t('For more information please read the configuration and customization handbook <a href="@trackback">Trackback page</a>.', array('@trackback' => 'http://www.drupal.org/handbook/modules/trackback')) .'</p>';
|
| 11 |
return $output;
|
| 12 |
}
|
| 13 |
}
|
| 14 |
|
| 15 |
/**
|
| 16 |
* Menu callback; present an administrative trackback listing.
|
| 17 |
*/
|
| 18 |
function trackback_admin_overview(&$form_state, $type = 'new') {
|
| 19 |
$operations = array();
|
| 20 |
if ($type == 'new') {
|
| 21 |
$operations['unpublish'] = t('Unpublish the selected trackbacks');
|
| 22 |
}
|
| 23 |
else {
|
| 24 |
$operations['publish'] = t('Publish the selected trackbacks');
|
| 25 |
}
|
| 26 |
if (TRACKBACK_WITH_SPAM) {
|
| 27 |
$operations['_trackback_as_spam'] = t('Mark the selected trackbacks as spam');
|
| 28 |
$operations['_trackback_as_notspam'] = t('Mark the selected trackbacks as not spam');
|
| 29 |
}
|
| 30 |
$operations['delete'] = t('Delete the selected trackbacks (no confirmation)');
|
| 31 |
|
| 32 |
$form = array();
|
| 33 |
$form['update'] = array(
|
| 34 |
'#type' => 'fieldset',
|
| 35 |
'#title' => t('Update options'),
|
| 36 |
'operations' => array('#type' => 'value', '#value' => $operations)
|
| 37 |
);
|
| 38 |
$form['update']['operation'] = array(
|
| 39 |
'#prefix' => '<div class="container-inline">',
|
| 40 |
'#type' => 'select',
|
| 41 |
'#options' => $operations
|
| 42 |
);
|
| 43 |
$form['update']['op'] = array(
|
| 44 |
'#type' => 'submit',
|
| 45 |
'#value' => t('Update'),
|
| 46 |
'#suffix' => '</div>'
|
| 47 |
);
|
| 48 |
|
| 49 |
$form['trackbacks'] = array('#theme' => 'trackback_admin_table');
|
| 50 |
$form['trackbacks']['header'] = array(
|
| 51 |
'#type' => 'value',
|
| 52 |
'#value' => trackback_admin_table_header($type)
|
| 53 |
);
|
| 54 |
|
| 55 |
$status = ($type == 'approval') ? 0 : 1;
|
| 56 |
if (TRACKBACK_WITH_SPAM) {
|
| 57 |
$spam_threshold = (int)variable_get('spam_threshold', 80);
|
| 58 |
$sql = 'SELECT tr.*, s.probability FROM {trackback_received} tr LEFT JOIN {spam_tracker} s ON s.source = \'trackback\' AND tr.trid = s.id WHERE '. ($type == 'spam' ? 's.probability >= '. $spam_threshold : 'tr.status = '. $status);
|
| 59 |
}
|
| 60 |
else {
|
| 61 |
$sql = 'SELECT tr.* FROM {trackback_received} tr WHERE tr.status = '. $status;
|
| 62 |
}
|
| 63 |
$sql .= tablesort_sql($form['trackbacks']['header']['#value']);
|
| 64 |
$result = pager_query($sql, 50);
|
| 65 |
|
| 66 |
$form['trackbacks']['status'] = array('#tree' => TRUE);
|
| 67 |
while ($trackback = db_fetch_object($result)) {
|
| 68 |
$form['trackbacks']['status'][$trackback->trid] = array('#type' => 'checkbox');
|
| 69 |
$form['trackbacks'][$trackback->trid] = array();
|
| 70 |
$form['trackbacks'][$trackback->trid][] = array('#value' => _trackback_path($trackback, $trackback->subject, array('attributes' => array('title' => truncate_utf8($trackback->excerpt, 128)))) .' '. theme('mark', node_mark($trackback->nid, $trackback->created)));
|
| 71 |
$form['trackbacks'][$trackback->trid][] = array('#value' => truncate_utf8($trackback->name, 15, FALSE, TRUE));
|
| 72 |
$form['trackbacks'][$trackback->trid][] = array('#value' => $trackback->site);
|
| 73 |
if (TRACKBACK_WITH_SPAM) {
|
| 74 |
if ($type == 'spam') {
|
| 75 |
$form['trackbacks'][$trackback->trid][] = array('#value' => $trackback->status != 0 ? t('Published') : t('Not published'));
|
| 76 |
}
|
| 77 |
else {
|
| 78 |
$form['trackbacks'][$trackback->trid][] = array('#value' => $trackback->probability >= $spam_threshold ? t('Spam') : t('Not Spam'));
|
| 79 |
}
|
| 80 |
}
|
| 81 |
$form['trackbacks'][$trackback->trid][] = array('#value' => format_date($trackback->created, 'small'));
|
| 82 |
$form['trackbacks'][$trackback->trid][] = array('#value' => l(t('edit'), 'trackback/edit/'. $trackback->trid));
|
| 83 |
$form['trackbacks'][$trackback->trid][] = array('#value' => l(t('delete'), 'trackback/delete/'. $trackback->trid));
|
| 84 |
}
|
| 85 |
$form['pager'] = array('#value' => theme('pager', NULL, 50, 0));
|
| 86 |
|
| 87 |
return $form;
|
| 88 |
}
|
| 89 |
|
| 90 |
function trackback_admin_overview_validate($form_id, $form_state) {
|
| 91 |
$status = array();
|
| 92 |
if (isset($form_state['values']['status'])) {
|
| 93 |
$status = array_diff((array)$form_state['values']['status'], array(0));
|
| 94 |
}
|
| 95 |
if (count($status) == 0) {
|
| 96 |
form_set_error('', t('Please select one or more trackbacks to perform the update on.'));
|
| 97 |
drupal_goto($_GET['q']);
|
| 98 |
}
|
| 99 |
}
|
| 100 |
|
| 101 |
function trackback_admin_overview_submit($form_id, $form_state) {
|
| 102 |
if (isset($form_state['values']['operations'][$form_state['values']['operation']])) {
|
| 103 |
foreach ($form_state['values']['status'] as $trid => $value) {
|
| 104 |
if ($value) {
|
| 105 |
_trackback_operation($form_state['values']['operation'], $trid, FALSE);
|
| 106 |
}
|
| 107 |
}
|
| 108 |
cache_clear_all();
|
| 109 |
drupal_set_message(t('The update has been performed.'));
|
| 110 |
}
|
| 111 |
}
|
| 112 |
|
| 113 |
function trackback_admin_table_header($type) {
|
| 114 |
$header = array();
|
| 115 |
$header[] = theme('table_select_header_cell');
|
| 116 |
$header[] = array('data' => t('Subject'), 'field' => 'tr.subject');
|
| 117 |
$header[] = array('data' => t('Author'), 'field' => 'tr.name');
|
| 118 |
$header[] = array('data' => t('Host'), 'field' => 'tr.site');
|
| 119 |
if (TRACKBACK_WITH_SPAM) {
|
| 120 |
if ($type == 'spam') {
|
| 121 |
$header[] = array('data' => t('Status'), 'field' => 'tr.status');
|
| 122 |
}
|
| 123 |
else {
|
| 124 |
$header[] = array('data' => t('Spam'), 'field' => 's.probability');
|
| 125 |
}
|
| 126 |
}
|
| 127 |
$header[] = array('data' => t('Time'), 'field' => 'created', 'sort' => 'desc');
|
| 128 |
$header[] = array('data' => t('Operations') , 'colspan' => '2');
|
| 129 |
return $header;
|
| 130 |
}
|
| 131 |
|
| 132 |
function theme_trackback_admin_table($form) {
|
| 133 |
$header = $form['header']['#value'];
|
| 134 |
$rows = array();
|
| 135 |
foreach (element_children($form['status']) as $key) {
|
| 136 |
$row = array(drupal_render($form['status'][$key]));
|
| 137 |
foreach (element_children($form[$key]) as $column_key) {
|
| 138 |
$row[] = drupal_render($form[$key][$column_key]);
|
| 139 |
}
|
| 140 |
$rows[] = $row;
|
| 141 |
}
|
| 142 |
if (count($rows) == 0) {
|
| 143 |
$rows[] = array(array('data' => t('No trackbacks available.'), 'colspan' => count($header)));
|
| 144 |
}
|
| 145 |
return theme('table', $header, $rows);
|
| 146 |
}
|
| 147 |
|
| 148 |
function trackback_configure() {
|
| 149 |
$form['trackback_auto_detection_enabled'] = array(
|
| 150 |
'#type' => 'radios',
|
| 151 |
'#title' => t('Auto-detection'),
|
| 152 |
'#default_value' => variable_get('trackback_auto_detection_enabled', 0),
|
| 153 |
'#options' => array(t('Disabled'), t('Enabled'), t('Run auto-detection on cron')),
|
| 154 |
'#description' => t('If auto-detection is enabled, each URL in any posted content (whether in textile, link, or plain-text form) will be checked for a trackback URL upon submission. For each URL in the body of the posted content, trackback will check to see if that URL accepts trackbacks from other sites. If a URL accepts trackbacks, trackback will ping the trackback URL found on that page if one has been posted at that URL.<br>*note: This has the potential to take a very long time depending on the amount of links you have in your posts. Using the \'Run auto-detection on cron\' option delays the most time consuming part of the process to when cron is run on the site. This speeds perfomance when editing and creating content, but delays trackbacks until cron is run.')
|
| 155 |
);
|
| 156 |
$form['trackback_link_only'] = array(
|
| 157 |
'#type' => 'checkbox',
|
| 158 |
'#title' => t('Link only'),
|
| 159 |
'#default_value' => variable_get('trackback_link_only', 0),
|
| 160 |
'#description' => t('If checked, auto-detection will check link only.')
|
| 161 |
);
|
| 162 |
$form['trackback_moderation'] = array(
|
| 163 |
'#type' => 'radios',
|
| 164 |
'#title' => t('Trackback moderation'),
|
| 165 |
'#default_value' => variable_get('trackback_moderation', 0),
|
| 166 |
'#options' => array(t('Disabled'), t('Enabled')),
|
| 167 |
'#description' => t('Enabling moderation forces every received trackback to be approved before it will appear on your site. The moderation queue can then be viewed on the !linked_page.', array('!linked_page' => l(t('trackback administration page'), 'admin/content/trackback/list/approval')))
|
| 168 |
);
|
| 169 |
$form['trackback_reject_oneway'] = array(
|
| 170 |
'#type' => 'radios',
|
| 171 |
'#title' => t('Reject one-way trackbacks'),
|
| 172 |
'#default_value' => variable_get('trackback_reject_oneway', 0),
|
| 173 |
'#options' => array(t('Disabled'), t('Enabled')),
|
| 174 |
'#description' => t('If enabled, trackbacks that the sender page does not refer to your site will be rejected.')
|
| 175 |
);
|
| 176 |
$form['trackback_view'] = array(
|
| 177 |
'#type' => 'radios',
|
| 178 |
'#title' => t('Location of received trackbacks'),
|
| 179 |
'#default_value' => variable_get('trackback_view', 0),
|
| 180 |
'#options' => array(t('Display below post'), t('Display on separate page'), t('Display in block'))
|
| 181 |
);
|
| 182 |
return system_settings_form($form);
|
| 183 |
}
|
| 184 |
|
| 185 |
function trackback_delete(&$form_state, $tb) {
|
| 186 |
return confirm_form(
|
| 187 |
array('trackback' => array('#type' => 'value', '#value' => $tb)),
|
| 188 |
t('Are you sure you want to delete the trackback %title?', array('%title' => $tb->subject)),
|
| 189 |
_trackback_path($tb), t('This action cannot be undone.'), t('Delete'), t('Cancel')
|
| 190 |
);
|
| 191 |
}
|
| 192 |
|
| 193 |
function trackback_delete_submit($form_id, &$form_state) {
|
| 194 |
$tb = $form_state['values']['trackback'];
|
| 195 |
_trackback_operation('delete', $tb);
|
| 196 |
$form_state['redirect'] = array(_trackback_path($tb), NULL, 'trackbacks');
|
| 197 |
}
|
| 198 |
|
| 199 |
function trackback_edit(&$form_state, $tb) {
|
| 200 |
$node = node_build_content(node_load($tb->nid), TRUE);
|
| 201 |
$node->teaser = drupal_render($node->content);
|
| 202 |
$form = array('trackback' => array('#type' => 'value', '#value' => $tb));
|
| 203 |
$form['preview'] = array(
|
| 204 |
'#prefix' => '<div class="preview">',
|
| 205 |
'#value' => theme('trackback', $tb, module_invoke_all('link', 'trackback', $tb, TRUE)),
|
| 206 |
'#suffix' => '</div>'
|
| 207 |
);
|
| 208 |
$form['status'] = array(
|
| 209 |
'#type' => 'radios',
|
| 210 |
'#title' => t('Status'),
|
| 211 |
'#default_value' => $tb->status,
|
| 212 |
'#options' => array(1 => t('Published'), 0 => t('Not published'))
|
| 213 |
);
|
| 214 |
$form['op'] = array('#type' => 'submit', '#value' => t('Save'));
|
| 215 |
$form['node'] = array(
|
| 216 |
'#value' => theme('box', t('This trackback is in response to: '), theme('node', $node, TRUE, FALSE))
|
| 217 |
);
|
| 218 |
return $form;
|
| 219 |
}
|
| 220 |
|
| 221 |
function trackback_edit_submit($form_id, &$form_state) {
|
| 222 |
$status = $form_state['values']['status'];
|
| 223 |
$tb = $form_state['values']['trackback'];
|
| 224 |
if ($status != $tb->status) {
|
| 225 |
if ($status) {
|
| 226 |
_trackback_operation('publish', $tb);
|
| 227 |
drupal_set_message(t('The trackback is now published.'));
|
| 228 |
}
|
| 229 |
else {
|
| 230 |
_trackback_operation('unpublish', $tb);
|
| 231 |
drupal_set_message(t('The trackback was unpublished.'));
|
| 232 |
}
|
| 233 |
}
|
| 234 |
$form_state['redirect'] = array(_trackback_path($tb), NULL, 'trackbacks');
|
| 235 |
}
|