| 1 |
<?php
|
| 2 |
function abssrc_menu(){
|
| 3 |
$items = array();
|
| 4 |
$items['admin/settings/abssrc'] = array(
|
| 5 |
'title' => 'Absolute src',
|
| 6 |
'description' => 'Settings of absolute image src.',
|
| 7 |
'access arguments' => array('administer site configuration'),
|
| 8 |
'page callback' => 'drupal_get_form',
|
| 9 |
'page arguments' => array('abssrc_admin_settings'),
|
| 10 |
);
|
| 11 |
|
| 12 |
return $items;
|
| 13 |
}
|
| 14 |
function abssrc_admin_settings(){
|
| 15 |
$form = array();
|
| 16 |
$form['abssrc_enabled'] = array(
|
| 17 |
'#type' => 'checkbox',
|
| 18 |
'#title' => t('Enable absolute src of img'),
|
| 19 |
'#default_value' => variable_get('abssrc_enabled',0),
|
| 20 |
'#description' => t('Check to enable parse images in node body to absolute src.'),
|
| 21 |
);
|
| 22 |
$form['abssrc_custom'] = array(
|
| 23 |
'#type' => 'textfield',
|
| 24 |
'#title' => t('Custom prefix url'),
|
| 25 |
'#default_value' => variable_get('abssrc_custom', ''),
|
| 26 |
'#description' => t('Leave blank to use site wide url, or you can fill in url include http protocol (no trilling slash). ex: http://sample.com '),
|
| 27 |
);
|
| 28 |
|
| 29 |
return system_settings_form($form);
|
| 30 |
}
|
| 31 |
function abssrc_nodeapi(&$node, $op, $teaser = TRUE, $page = FALSE){
|
| 32 |
global $base_url, $base_path;
|
| 33 |
if($op == 'view' && variable_get('abssrc_enabled', 0)){
|
| 34 |
$url = variable_get('abssrc_custom', '') ? rtrim(variable_get('abssrc_custom', ''),'/') : $base_url;
|
| 35 |
$pattern = array(
|
| 36 |
"/".preg_quote('src="'.$base_path,'/')."/i",
|
| 37 |
"/".preg_quote('href="'.$base_path,'/')."/i",
|
| 38 |
);
|
| 39 |
$replace = array(
|
| 40 |
'src="'.$url.$base_path,
|
| 41 |
'href="'.$url.$base_path,
|
| 42 |
);
|
| 43 |
$node->content['body']['#value'] = preg_replace($pattern, $replace, $node->content['body']['#value']);
|
| 44 |
if($teaser){
|
| 45 |
$node->teaser = $node->content['body']['#value'];
|
| 46 |
}
|
| 47 |
else{
|
| 48 |
$node->body = $node->content['body']['#value'];
|
| 49 |
}
|
| 50 |
}
|
| 51 |
|
| 52 |
}
|