User the following module
Custom Submit Messages
http://drupal.org/project/csm
Friday, July 22, 2011
Thursday, July 21, 2011
Friday, July 15, 2011
D6 converts URLs (http, ftp, email, ...) into hyperlinks.
$text field will contain the raw data which we need to convert into links.
$urlfilter_length = 72;
$text = $node_details->field_selling_external_prop_link[0]['value'];
$text = ' ' . $text . ' ';
$text = preg_replace_callback("!(|
|[ \n\r\t\(])((http://|https://|ftp://|mailto:|smb://|afp://|file://|gopher://|news://|ssl://|sslv2://|sslv3://|tls://|tcp://|udp://)([a-zA-Z0-9@:%_+*~#?&=.,/;-]*[a-zA-Z0-9@:%_+*~#&=/;-]))([.,?]?)(?=(| |
|[ \n\r\t\)]))!i", 'urlfilter_replace1', $text);
$text = preg_replace("!(|
|[ \n\r\t\(])([A-Za-z0-9._-]+@[A-Za-z0-9._+-]+\.[A-Za-z]{2,4})([.,?]?)(?=(| |
|[ \n\r\t\)]))!i", '\1\2\3', $text);
$text = preg_replace_callback("!(|[ \n\r\t\(])(www\.[a-zA-Z0-9@:%_+*~#?&=.,/;-]*[a-zA-Z0-9@:%_+~#\&=/;-])([.,?]?)(?=(| |
|[ \n\r\t\)]))!i", 'urlfilter_replace2', $text);
$text = substr($text, 1, -1);
$text will contain the converted values.
Define below 3 function
function urlfilter_replace1($match) {
$match[2] = decode_entities($match[2]);
$caption = check_plain(urlfilter_trim($match[2]));
$match[2] = check_url($match[2]);
return $match[1] . ''. $caption .''. $match[5];
}
function urlfilter_replace2($match) {
$match[2] = decode_entities($match[2]);
$caption = check_plain(urlfilter_trim($match[2]));
$match[2] = check_plain($match[2]);
return $match[1] . ''. $caption .''. $match[3];
}
function urlfilter_trim($text) {
$urlfilter_length = 72;
return (strlen($text) > $urlfilter_length) ? substr($text, 0, $urlfilter_length) .'...' : $text;
}
$urlfilter_length = 72;
$text = $node_details->field_selling_external_prop_link[0]['value'];
$text = ' ' . $text . ' ';
$text = preg_replace_callback("!(
|
|[ \n\r\t\(])((http://|https://|ftp://|mailto:|smb://|afp://|file://|gopher://|news://|ssl://|sslv2://|sslv3://|tls://|tcp://|udp://)([a-zA-Z0-9@:%_+*~#?&=.,/;-]*[a-zA-Z0-9@:%_+*~#&=/;-]))([.,?]?)(?=(|
|[ \n\r\t\)]))!i", 'urlfilter_replace1', $text);
$text = preg_replace("!(
|
|[ \n\r\t\(])([A-Za-z0-9._-]+@[A-Za-z0-9._+-]+\.[A-Za-z]{2,4})([.,?]?)(?=(|
|[ \n\r\t\)]))!i", '\1\2\3', $text);
$text = preg_replace_callback("!(
|
|[ \n\r\t\)]))!i", 'urlfilter_replace2', $text);
$text = substr($text, 1, -1);
$text will contain the converted values.
Define below 3 function
function urlfilter_replace1($match) {
$match[2] = decode_entities($match[2]);
$caption = check_plain(urlfilter_trim($match[2]));
$match[2] = check_url($match[2]);
return $match[1] . ''. $caption .''. $match[5];
}
function urlfilter_replace2($match) {
$match[2] = decode_entities($match[2]);
$caption = check_plain(urlfilter_trim($match[2]));
$match[2] = check_plain($match[2]);
return $match[1] . ''. $caption .''. $match[3];
}
function urlfilter_trim($text) {
$urlfilter_length = 72;
return (strlen($text) > $urlfilter_length) ? substr($text, 0, $urlfilter_length) .'...' : $text;
}
Friday, July 8, 2011
Drupal 6 - Display a GMAP for a Location CCK field custom
My cck location filed is $node_details->field_map_location;
$lid = $node_details->field_map_location['0']['lid'];
if (is_numeric($lid)) {
$loc = location_load_location($lid);
$markertypes = variable_get('gmap_node_markers', array());
$markers = array();
$count = 0;
if (location_has_coordinates($loc)) {
$count++;
$markername = isset($markertypes[$node_details->type]) ? $markertypes[$node_details->type] : 'drupal';
if (module_exists('gmap_taxonomy')) {
$t = db_result(db_query('SELECT marker FROM {gmap_taxonomy_node} WHERE vid = %d', $node->vid));
if (!empty($t)) {
$markername = $t;
}
}
$markertitle = $node_details->title;
if (!empty($loc['name'])) {
$markertitle = $loc['name'];
}
$markers[] = array(
'latitude' => $loc['latitude'],
'longitude' => $loc['longitude'],
'markername' => $markername,
'offset' => $count-1,
'opts' => array('title' => $markertitle),
);
}
if (!empty($markers)) {
$macro = variable_get('gmap_location_block_macro_'. $node_details->type, '');
if (empty($macro)) {
$macro = variable_get('gmap_location_block_macro', '[gmap |width=100% |height=200px |control=None |behavior=+autozoom +notype]');
}
$map = gmap_parse_macro($macro);
$map['width'] = '100%';
$map['height'] = '300px';
$map['latitude'] = $node_details->location['latitude'];
$map['longitude'] = $node_details->location['longitude'];
$map['markers'] = $markers;
}
}
theme('gmap', array('#settings' => $map));
This will return the gmap with location marker.
$lid = $node_details->field_map_location['0']['lid'];
if (is_numeric($lid)) {
$loc = location_load_location($lid);
$markertypes = variable_get('gmap_node_markers', array());
$markers = array();
$count = 0;
if (location_has_coordinates($loc)) {
$count++;
$markername = isset($markertypes[$node_details->type]) ? $markertypes[$node_details->type] : 'drupal';
if (module_exists('gmap_taxonomy')) {
$t = db_result(db_query('SELECT marker FROM {gmap_taxonomy_node} WHERE vid = %d', $node->vid));
if (!empty($t)) {
$markername = $t;
}
}
$markertitle = $node_details->title;
if (!empty($loc['name'])) {
$markertitle = $loc['name'];
}
$markers[] = array(
'latitude' => $loc['latitude'],
'longitude' => $loc['longitude'],
'markername' => $markername,
'offset' => $count-1,
'opts' => array('title' => $markertitle),
);
}
if (!empty($markers)) {
$macro = variable_get('gmap_location_block_macro_'. $node_details->type, '');
if (empty($macro)) {
$macro = variable_get('gmap_location_block_macro', '[gmap |width=100% |height=200px |control=None |behavior=+autozoom +notype]');
}
$map = gmap_parse_macro($macro);
$map['width'] = '100%';
$map['height'] = '300px';
$map['latitude'] = $node_details->location['latitude'];
$map['longitude'] = $node_details->location['longitude'];
$map['markers'] = $markers;
}
}
theme('gmap', array('#settings' => $map));
This will return the gmap with location marker.
Tuesday, June 28, 2011
Displaying Views' exposed filters in a custom area
User the following function
$view = views_get_view('your_view_name');
$view->set_display('default');
$view->init_handlers();
$form_state = array(
'view' => $view,
'display' => $view->display_handler->display,
'method' => 'get',
'rerender' => TRUE,
'no_redirect' => TRUE,
);
$output = drupal_build_form('views_exposed_form', $form_state);
return $output;
$view = views_get_view('your_view_name');
$view->set_display('default');
$view->init_handlers();
$form_state = array(
'view' => $view,
'display' => $view->display_handler->display,
'method' => 'get',
'rerender' => TRUE,
'no_redirect' => TRUE,
);
$output = drupal_build_form('views_exposed_form', $form_state);
return $output;
Monday, June 27, 2011
PHP – parse a string between two strings
function get_string_between($string, $start, $end){
$string = " ".$string;
$ini = strpos($string,$start);
if ($ini == 0) return "";
$ini += strlen($start);
$len = strpos($string,$end,$ini) - $ini;
return substr($string,$ini,$len);
}
$fullstring = "this is my [tag]dog[/tag]";
$parsed = get_string_between($fullstring, "[tag]", "[/tag]");
echo $parsed; // (result = dog)
$string = " ".$string;
$ini = strpos($string,$start);
if ($ini == 0) return "";
$ini += strlen($start);
$len = strpos($string,$end,$ini) - $ini;
return substr($string,$ini,$len);
}
$fullstring = "this is my [tag]dog[/tag]";
$parsed = get_string_between($fullstring, "[tag]", "[/tag]");
echo $parsed; // (result = dog)
Friday, June 24, 2011
Customizing the user profile layout
Step 1 - is to override the default User Profile page layout by uploading a custom user-profile.tpl.php* file to your active theme folder.
Drupal will automatically detect the presence of your custom user-profile.tpl.php and override the default user profile layout. To make this happen, you need to rebuild the theme registry, which you can do by clearing the caches (for example using the button on the admin/settings/performance page), or simply by visiting the admin/build/modules page.
* note that in Drupal 6.x, your custom user profile layout file name uses a hyphen, instead of an underscore.
Step 2 - is to customize your user-profile.tpl.php layout file.
By default, all user profile data is printed out with the $user_profile variable. If there is a need to break it up you can use $profile instead.
As an example, the following snippet inserted in your custom user-profile.tpl.php will display the default user profile layout.
Available variables:
$user_profile: All user profile data. Ready for print.
$profile: Keyed array of profile categories and their items or other data provided by modules.
To check for all available data within $profile, insert the following snippet at the bottom of your custom user-profile.tpl.php.
Step 3 - Load profile variables
If you want to load the profile variables (profile module) you can use this code in user-profile.tpl.php
profile_load_profile($account);
// now you can call the profile field like profile_firstname
echo $account->profile_firstname;
Drupal will automatically detect the presence of your custom user-profile.tpl.php and override the default user profile layout. To make this happen, you need to rebuild the theme registry, which you can do by clearing the caches (for example using the button on the admin/settings/performance page), or simply by visiting the admin/build/modules page.
* note that in Drupal 6.x, your custom user profile layout file name uses a hyphen, instead of an underscore.
Step 2 - is to customize your user-profile.tpl.php layout file.
By default, all user profile data is printed out with the $user_profile variable. If there is a need to break it up you can use $profile instead.
As an example, the following snippet inserted in your custom user-profile.tpl.php will display the default user profile layout.
Available variables:
$user_profile: All user profile data. Ready for print.
$profile: Keyed array of profile categories and their items or other data provided by modules.
To check for all available data within $profile, insert the following snippet at the bottom of your custom user-profile.tpl.php.
Available variables
The following is a list of variables that is available to your custom user-profile.tpl.php.
print ''. check_plain(print_r($profile, 1)) .'';
Step 3 - Load profile variables
If you want to load the profile variables (profile module) you can use this code in user-profile.tpl.php
profile_load_profile($account);
// now you can call the profile field like profile_firstname
echo $account->profile_firstname;
Subscribe to:
Posts (Atom)