| 1 |
<?php
|
| 2 |
/**
|
| 3 |
* Helper function builds the settings page for ulink_settings for all types on behalf of ulink default implementation
|
| 4 |
*/
|
| 5 |
function _ulink_ulink_settings_builder($type) {
|
| 6 |
|
| 7 |
if ($type != 'others') {
|
| 8 |
$options[1] = t('Default (Simple)').l(' : configure','admin/settings/ulink/'.$type.'/ulink_1','',drupal_get_destination());
|
| 9 |
}
|
| 10 |
else {
|
| 11 |
$options[1] = t('Default (Simple)');
|
| 12 |
}
|
| 13 |
|
| 14 |
if (module_exists('token')) {
|
| 15 |
$options[2] = t('Macro substitution (Tokens) ').l(' : configure','admin/settings/ulink/'.$type.'/ulink_2','',drupal_get_destination());
|
| 16 |
}
|
| 17 |
else {
|
| 18 |
drupal_set_message('If token module is installed, ulink provides support for token substitution. You can download it <a href="http://drupal.org/project/token" >here </a>','error','error');
|
| 19 |
}
|
| 20 |
$options[3] = t('PHP code '.l(' : configure','admin/settings/ulink/'.$type.'/ulink_3','',drupal_get_destination()));
|
| 21 |
|
| 22 |
$form['ulink_'.$type.'_settings_option'] = array(
|
| 23 |
'#type' => 'radios',
|
| 24 |
'#title' => t('Implementation desired'),
|
| 25 |
'#options' => $options,
|
| 26 |
'#default_value' => variable_get('ulink_'.$type.'_settings_option', 1),
|
| 27 |
);
|
| 28 |
return $form;
|
| 29 |
}
|
| 30 |
/**
|
| 31 |
* Helper function provides the implemenation for ulink_xxx for all types on behalf of ulink default implementation
|
| 32 |
*/
|
| 33 |
function _ulink_ulink_xxx($type, $link, $object = NULL){
|
| 34 |
$path = $link['path'];
|
| 35 |
$text = $link['text'];
|
| 36 |
$attributes = $link['attributes'];
|
| 37 |
switch ($type) {
|
| 38 |
case 'node':
|
| 39 |
$str = '$object->type';
|
| 40 |
$str1 = '[title]';
|
| 41 |
break;
|
| 42 |
case 'comment':
|
| 43 |
$str1 = '[comment-subject]';
|
| 44 |
$str = '$object->subject';
|
| 45 |
break;
|
| 46 |
case 'user':
|
| 47 |
$str1 = '[user]';
|
| 48 |
$str = '$object->name';
|
| 49 |
break;
|
| 50 |
case 'files':
|
| 51 |
$str1 = '[files-filename]';
|
| 52 |
$str = '$object->filename';
|
| 53 |
break;
|
| 54 |
default:
|
| 55 |
$str1 = 'external to [site-name]';
|
| 56 |
$str = 'external file';
|
| 57 |
}
|
| 58 |
|
| 59 |
switch (variable_get('ulink_'.$type.'_settings_option', 1)) {
|
| 60 |
case 1:
|
| 61 |
default:
|
| 62 |
$text = $text ? $text : _ulink_get_defaulttag($type, variable_get('ulink_'.$type.'_1_option', 2), $object, $path);
|
| 63 |
return l($text, $path, $attributes);
|
| 64 |
case 2:
|
| 65 |
if (module_exists('token')) {
|
| 66 |
$tokentext = token_replace(variable_get('ulink_'.$type.'_2_text', $str1), 'ulink', $link);
|
| 67 |
$tokentext = token_replace($tokentext, $type, $object);
|
| 68 |
$link['text'] = $link['text'] ? $link['text'] : $tokentext;
|
| 69 |
if (!$object ) {
|
| 70 |
$ouput = token_replace(variable_get('ulink_'.$type.'_2_brokenlink', '<a href="[ulink-path]" [ulink-attributes-string]>[ulink-text] ('.$type.' not available)</a>'), 'ulink', $link);
|
| 71 |
return token_replace($ouput, $type, $object);
|
| 72 |
}
|
| 73 |
else {
|
| 74 |
$ouput = token_replace(variable_get('ulink_'.$type.'_2_tag', '<a href="[ulink-path]" [ulink-attributes-string]>[ulink-text]</a>'), 'ulink', $link);
|
| 75 |
return token_replace($ouput, $type, $object);
|
| 76 |
}
|
| 77 |
}
|
| 78 |
else {
|
| 79 |
return $text;
|
| 80 |
}
|
| 81 |
case 3:
|
| 82 |
return eval(variable_get('ulink_'.$type.'_3_code', 'return l($text." ( ".'.$str.'." )", $path, $link["attributes"]);'));
|
| 83 |
}
|
| 84 |
}
|
| 85 |
/**
|
| 86 |
* helper function gives the default tag when the user text is empty for the type given in $type
|
| 87 |
*/
|
| 88 |
function _ulink_get_defaulttag($type, $option, $object, $path) {
|
| 89 |
if (!$object || !$option)
|
| 90 |
return NULL;
|
| 91 |
else if ($option == 1)
|
| 92 |
return $path;
|
| 93 |
else if ($option == 2) {
|
| 94 |
switch ($type) {
|
| 95 |
case 'node':
|
| 96 |
return $object->title;
|
| 97 |
case 'comment':
|
| 98 |
return $object->subject;
|
| 99 |
case 'files':
|
| 100 |
return $object->filename;
|
| 101 |
case 'user':
|
| 102 |
return $object->name;
|
| 103 |
}
|
| 104 |
}
|
| 105 |
}
|
| 106 |
function _ulink_xxx_settings_1($type) {
|
| 107 |
switch ($type) {
|
| 108 |
case 'others':
|
| 109 |
default:
|
| 110 |
return NULL;
|
| 111 |
case 'node':
|
| 112 |
$options = array ( 0 => t('None'), 1 => t('Node path'), 2 => t('Node title'));
|
| 113 |
break;
|
| 114 |
case 'comment':
|
| 115 |
$options = array ( 0 => t('None'), 1 => t('Comment path'), 2 => t('Comment title'));
|
| 116 |
break;
|
| 117 |
case 'user':
|
| 118 |
$options = array ( 0 => t('None'), 1 => t('User path'), 2 => t('User name'));
|
| 119 |
break;
|
| 120 |
case 'files':
|
| 121 |
$options = array ( 0 => t('None'), 1 => t('File path'), 2 => t('File name'));
|
| 122 |
break;
|
| 123 |
}
|
| 124 |
|
| 125 |
$form['settings'] = array(
|
| 126 |
'#type' => 'fieldset',
|
| 127 |
'#title' => t('settings'),
|
| 128 |
'#collapsible' => FALSE,
|
| 129 |
);
|
| 130 |
$form['settings']['ulink_'.$type.'_1_option'] = array(
|
| 131 |
'#type' => 'radios',
|
| 132 |
'#title' => t('Use this when text is empty'),
|
| 133 |
'#options' => $options,
|
| 134 |
'#default_value' => variable_get('ulink_'.$type.'_1_option', 2),
|
| 135 |
);
|
| 136 |
|
| 137 |
return $form;
|
| 138 |
}
|
| 139 |
function _ulink_xxx_settings_2($type) {
|
| 140 |
switch ($type) {
|
| 141 |
case 'node':
|
| 142 |
$str1 = '[title]';
|
| 143 |
break;
|
| 144 |
case 'comment':
|
| 145 |
$str1 = '[comment-subject]';
|
| 146 |
break;
|
| 147 |
case 'user':
|
| 148 |
$str1 = '[user]';
|
| 149 |
break;
|
| 150 |
case 'files':
|
| 151 |
$str1 = '[files-filename]';
|
| 152 |
break;
|
| 153 |
default:
|
| 154 |
$str1 = 'external to [site-name]';
|
| 155 |
}
|
| 156 |
|
| 157 |
$form['settings'] = array(
|
| 158 |
'#type' => 'fieldset',
|
| 159 |
'#title' => t('Macro mode settings'),
|
| 160 |
'#collapsible' => FALSE,
|
| 161 |
);
|
| 162 |
if (!module_exists('token')) {
|
| 163 |
drupal_set_message('If token module is installed, ulink provides support for token substitution. You can download it <a href="http://ftp.osuosl.org/pub/drupal/files/projects/token-5.x-1.7.tar.gz" >here </a>','error','error');
|
| 164 |
return system_settings_form($form);
|
| 165 |
}
|
| 166 |
|
| 167 |
$form['settings']['ulink_'.$type.'_2_text'] = array(
|
| 168 |
'#type' => 'textfield',
|
| 169 |
'#title' => t('Use this when text is empty'),
|
| 170 |
'#default_value' => variable_get('ulink_'.$type.'_2_text', $str1),
|
| 171 |
);
|
| 172 |
$form['settings']['ulink_'.$type.'_2_tag'] = array(
|
| 173 |
'#type' => 'textarea',
|
| 174 |
'#title' => t('Token tag to be rendered'),
|
| 175 |
'#rows' => 1,
|
| 176 |
'#default_value' => variable_get('ulink_'.$type.'_2_tag', '<a href="[ulink-path]" [ulink-attributes-string]>[ulink-text]</a>'),
|
| 177 |
'#description' => t('Refer to the token help for assistance'),
|
| 178 |
);
|
| 179 |
|
| 180 |
if ($type != 'others') {
|
| 181 |
$form['settings']['ulink_'.$type.'_2_brokenlink'] = array(
|
| 182 |
'#type' => 'textarea',
|
| 183 |
'#title' => t('Token tag to be rendered if the object is not available'),
|
| 184 |
'#rows' => 1,
|
| 185 |
'#default_value' => variable_get('ulink_'.$type.'_2_brokenlink', '<a href="[ulink-path]" [ulink-attributes-string]>[ulink-text] ('.$type.' not available)</a>'),
|
| 186 |
'#description' => t('Refer to the token help for assistance'),
|
| 187 |
);
|
| 188 |
}
|
| 189 |
$form['settings']['token_help'] = array(
|
| 190 |
'#type' => 'fieldset',
|
| 191 |
'#title' => t('Token help'),
|
| 192 |
'#collapsible' => TRUE,
|
| 193 |
'#collapsed' => TRUE,
|
| 194 |
);
|
| 195 |
$form['settings']['token_help']['a']['div-tag'] = array('#type' => 'markup', '#value' => theme('token_help',$type ));
|
| 196 |
$form['settings']['token_help']['b']['div-tag'] = array('#type' => 'markup', '#value' => theme('token_help','ulink'));
|
| 197 |
return $form;
|
| 198 |
}
|
| 199 |
function _ulink_xxx_settings_3($type) {
|
| 200 |
$form['settings'] = array(
|
| 201 |
'#type' => 'fieldset',
|
| 202 |
'#title' => t('PHP mode settings'),
|
| 203 |
'#collapsible' => FALSE,
|
| 204 |
);
|
| 205 |
switch ($type) {
|
| 206 |
case 'node':
|
| 207 |
$str = '$object->type';
|
| 208 |
break;
|
| 209 |
case 'comment':
|
| 210 |
$str = '$object->subject';
|
| 211 |
break;
|
| 212 |
case 'user':
|
| 213 |
$str = '$object->name';
|
| 214 |
break;
|
| 215 |
case 'files':
|
| 216 |
$str = '$object->filename';
|
| 217 |
break;
|
| 218 |
default:
|
| 219 |
$str = 'external file';
|
| 220 |
}
|
| 221 |
$form['settings']['ulink_'.$type.'_3_code'] = array(
|
| 222 |
'#type' => 'textarea',
|
| 223 |
'#title' => t('PHP code to be rendered'),
|
| 224 |
'#rows' => 1,
|
| 225 |
'#default_value' => variable_get('ulink_'.$type.'_3_code', 'return l($text." ( ".'.$str.'." )", $path, $link["attributes"]);'),
|
| 226 |
'#description' => t('Refer to the variables help for assistance'),
|
| 227 |
);
|
| 228 |
$form['settings']['Variables help'] = array(
|
| 229 |
'#type' => 'fieldset',
|
| 230 |
'#title' => t('PHP help'),
|
| 231 |
'#collapsible' => TRUE,
|
| 232 |
'#collapsed' => TRUE,
|
| 233 |
);
|
| 234 |
$form['settings']['Variables help']['div-tag'] = array(
|
| 235 |
'#type' => 'markup',
|
| 236 |
'#value' => '<table class="description"><thead><tr><th>Variable</th><th>Description</th></tr></thead><tbody>
|
| 237 |
<tr class="odd"><td class="region" colspan="2">variables that can be directly used</td> </tr>
|
| 238 |
<tr class="even"><td>$path</td><td>the targets url</td> </tr>
|
| 239 |
<tr class="odd"><td>$text</td><td>text to be referenced</td> </tr>
|
| 240 |
<tr class="even"><td>$object</td><td>'.$type.' object (not available in others type)</td> </tr>
|
| 241 |
<tr class="odd"><td>$attributes</td><td>attributes array</td> </tr>
|
| 242 |
<tr class="odd"><td class="region" colspan="2">Variables available in the array $link</td> </tr>
|
| 243 |
<tr class="even"><td>path</td><td>the targets url</td> </tr>
|
| 244 |
<tr class="odd"><td>text</td><td>text to be referenced</td> </tr>
|
| 245 |
<tr class="even"><td>'.$type.'</td><td>'.$type.' object (not available in others type)</td> </tr>
|
| 246 |
<tr class="odd"><td>attributes</td><td>attributes array</td> </tr>
|
| 247 |
<tr class="even"><td>attr</td><td>attributes string</td> </tr>
|
| 248 |
</tbody></table>
|
| 249 |
' );
|
| 250 |
return $form;
|
| 251 |
}
|