/[drupal]/contributions/modules/abssrc/abssrc.module
ViewVC logotype

Contents of /contributions/modules/abssrc/abssrc.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.4 - (show annotations) (download) (as text)
Sun Sep 7 12:51:49 2008 UTC (14 months, 2 weeks ago) by jimyhuang
Branch: MAIN
CVS Tags: HEAD
Changes since 1.3: +9 -0 lines
File MIME type: text/x-php
teaser bug fix
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 }

  ViewVC Help
Powered by ViewVC 1.1.2