| 1 |
<?php
|
| 2 |
// $Id: custom_links.admin.inc,v 1.1 2008/01/27 09:16:01 eaton Exp $
|
| 3 |
|
| 4 |
// Lists all current custom links, and provides a link to the edit page.
|
| 5 |
function custom_links_page() {
|
| 6 |
$links = _custom_links_load_all_links(TRUE);
|
| 7 |
|
| 8 |
$header = array(t('key'), t('link'), '');
|
| 9 |
|
| 10 |
$rows = array();
|
| 11 |
foreach ($links as $link) {
|
| 12 |
$row = array();
|
| 13 |
$row[] = $link->link_key;
|
| 14 |
$row[] = $link->title;
|
| 15 |
$row[] = l(t('edit'), 'admin/build/custom_links/edit/'. $link->lid);
|
| 16 |
$rows[] = $row;
|
| 17 |
}
|
| 18 |
if (count($rows) == 0) {
|
| 19 |
$rows[] = array(array('data' => t('No custom links have been defined.'), 'colspan' => 3));
|
| 20 |
}
|
| 21 |
|
| 22 |
$rows[] = array(array('data' => l(t('Add a new custom link'), 'admin/build/custom_links/add'), 'colspan' => 3));
|
| 23 |
|
| 24 |
|
| 25 |
return theme('table', $header, $rows);
|
| 26 |
}
|
| 27 |
|
| 28 |
|
| 29 |
// Displays an edit form for a custom link record.
|
| 30 |
function custom_links_form() {
|
| 31 |
global $base_url;
|
| 32 |
|
| 33 |
$lid = arg(4);
|
| 34 |
if (isset($lid)) {
|
| 35 |
$link = _custom_links_load_link($lid);
|
| 36 |
$form['lid'] = array(
|
| 37 |
'#type' => 'hidden',
|
| 38 |
'#value' => $lid,
|
| 39 |
);
|
| 40 |
}
|
| 41 |
|
| 42 |
$form['link'] = array(
|
| 43 |
'#type' => 'fieldset',
|
| 44 |
'#title' => t('Link details'),
|
| 45 |
);
|
| 46 |
|
| 47 |
$form['link']['link_key'] = array(
|
| 48 |
'#type' => 'textfield',
|
| 49 |
'#title' => t('Link key'),
|
| 50 |
'#description' => t('A unique string to identify this link. It will also be used as a CSS class when the link is output as HTML.'),
|
| 51 |
'#default_value' => $lid ? $link->link_key : NULL
|
| 52 |
);
|
| 53 |
|
| 54 |
$form['link']['title'] = array(
|
| 55 |
'#type' => 'textfield',
|
| 56 |
'#title' => t('Title'),
|
| 57 |
'#required' => TRUE,
|
| 58 |
'#description' => t("The visible text of the link seen by the user."),
|
| 59 |
'#default_value' => $lid ? $link->title : NULL
|
| 60 |
);
|
| 61 |
|
| 62 |
$form['link']['check_html'] = array(
|
| 63 |
'#type' => 'checkbox',
|
| 64 |
'#title' => t('Title uses HTML'),
|
| 65 |
'#return_value' => 1,
|
| 66 |
'#default_value' => $lid ? $link->check_html : 0
|
| 67 |
);
|
| 68 |
|
| 69 |
$form['link']['path'] = array(
|
| 70 |
'#type' => 'textfield',
|
| 71 |
'#title' => t('Path'),
|
| 72 |
'#description' => t("The Drupal path for the link. (!sample_url)", array('!sample_url' => $base_url .'/<u><b>node/1</b></u>#comment')),
|
| 73 |
'#default_value' => $lid ? $link->path : NULL
|
| 74 |
);
|
| 75 |
|
| 76 |
$form['link']['querystring'] = array(
|
| 77 |
'#type' => 'textfield',
|
| 78 |
'#title' => t('Querystring'),
|
| 79 |
'#description' => t("The optional querystring for the link. (!sample_url)", array('!sample_url' => $base_url .'/article?<u><b>id=1</b></u>')),
|
| 80 |
'#default_value' => $lid ? $link->query : NULL
|
| 81 |
);
|
| 82 |
|
| 83 |
$form['link']['fragment'] = array(
|
| 84 |
'#type' => 'textfield',
|
| 85 |
'#title' => t('Anchor'),
|
| 86 |
'#description' => t("The optional HTML anchor for the link. (!sample_url)", array('!sample_url' => $base_url .'/node/1<u><b>#comment</b></u>')),
|
| 87 |
'#default_value' => $lid ? $link->fragment : NULL
|
| 88 |
);
|
| 89 |
|
| 90 |
$form['help'] = array(
|
| 91 |
'#type' => 'fieldset',
|
| 92 |
'#collapsible' => TRUE,
|
| 93 |
'#collapsed' => TRUE,
|
| 94 |
'#title' => t('Placeholder tokens'),
|
| 95 |
'#description' => t("The following placeholder tokens can be used in paths, titles, querystrings, and anchors. they will be replaced with the appropriate values."),
|
| 96 |
);
|
| 97 |
|
| 98 |
if (module_exists('token')) {
|
| 99 |
$form['help']['tokens'] = array(
|
| 100 |
'#value' => theme('token_help', 'node'),
|
| 101 |
);
|
| 102 |
}
|
| 103 |
else {
|
| 104 |
$form['help']['#description'] = t("To use dynamic placeholder tokens in your paths and titles (the ID or title of the current node, for example), download and install the <a href='@token'>Token module</a> from Drupal.org.", array('@token' => 'http://www.drupal.org/project/token'));
|
| 105 |
$form['help']['#collapsible'] = FALSE;
|
| 106 |
$form['help']['#collapsed'] = FALSE;
|
| 107 |
}
|
| 108 |
|
| 109 |
$form['filters'] = array(
|
| 110 |
'#type' => 'fieldset',
|
| 111 |
'#title' => t('Link conditions'),
|
| 112 |
);
|
| 113 |
|
| 114 |
$modes = array(
|
| 115 |
0 => t('In full node views'),
|
| 116 |
1 => t('In teaser node views'),
|
| 117 |
2 => t('In both teaser and full node views'),
|
| 118 |
3 => t('In a sidebar block'),
|
| 119 |
);
|
| 120 |
$form['filters']['display'] = array(
|
| 121 |
'#type' => 'select',
|
| 122 |
'#title' => t('Display'),
|
| 123 |
'#options' => $modes,
|
| 124 |
'#default_value' => $lid ? $link->display : 2,
|
| 125 |
);
|
| 126 |
|
| 127 |
$options['*all*'] = t('All node types');
|
| 128 |
foreach (node_get_types('names') as $type => $name) {
|
| 129 |
$options[$type] = $name;
|
| 130 |
}
|
| 131 |
$form['filters']['node_type'] = array(
|
| 132 |
'#type' => 'select',
|
| 133 |
'#title' => t('Node type'),
|
| 134 |
'#options' => $options,
|
| 135 |
'#description' => t('If selected, the link will only be added to nodes of this type.'),
|
| 136 |
'#default_value' => $lid ? $link->node_type : NULL,
|
| 137 |
);
|
| 138 |
|
| 139 |
$form['filters']['author_perm'] = array(
|
| 140 |
'#type' => 'textfield',
|
| 141 |
'#title' => t('Author permission restriction'),
|
| 142 |
'#description' => t('A specific permission that the <i>author</i> of the node must have for the link to be added.'),
|
| 143 |
'#default_value' => $lid ? $link->author_perm : NULL
|
| 144 |
);
|
| 145 |
|
| 146 |
$form['filters']['viewer_perm'] = array(
|
| 147 |
'#type' => 'textfield',
|
| 148 |
'#title' => t('Viewer permission restriction'),
|
| 149 |
'#description' => t('A specific permission that the <i>viewer</i> of the node must have for the link to be added.'),
|
| 150 |
'#default_value' => $lid ? $link->viewer_perm : 'access content'
|
| 151 |
);
|
| 152 |
|
| 153 |
$form['buttons']['submit'] = array(
|
| 154 |
'#type' => 'submit',
|
| 155 |
'#value' => t('Submit'),
|
| 156 |
);
|
| 157 |
if ($lid) {
|
| 158 |
$form['buttons']['delete'] = array(
|
| 159 |
'#type' => 'submit',
|
| 160 |
'#value' => t('Delete'),
|
| 161 |
'#submit' => array('custom_links_form_delete'),
|
| 162 |
);
|
| 163 |
}
|
| 164 |
|
| 165 |
return $form;
|
| 166 |
}
|
| 167 |
|
| 168 |
function custom_links_form_validate($form, &$form_state) {
|
| 169 |
if (strpos($form_state['values']['link_key'], array(' ', '#', '.', '%', '^')) !== FALSE) {
|
| 170 |
form_set_error('link][link_key', t('The link key may not contain spaces or punctuation.'));
|
| 171 |
}
|
| 172 |
}
|
| 173 |
|
| 174 |
function custom_links_form_submit($form, &$form_state) {
|
| 175 |
$link = (object)$form_state['values'];
|
| 176 |
if ($link->node_type == '*all*') {
|
| 177 |
$link->node_type = '';
|
| 178 |
}
|
| 179 |
$link->query = $link->querystring;
|
| 180 |
_custom_links_save_link($link);
|
| 181 |
|
| 182 |
$form_state['redirect'] = 'admin/build/custom_links';
|
| 183 |
}
|
| 184 |
|
| 185 |
function custom_links_form_delete($form, &$form_state) {
|
| 186 |
_custom_links_delete_link($form_state['values']['lid']);
|
| 187 |
$form_state['redirect'] = 'admin/build/custom_links';
|
| 188 |
}
|