Wednesday, November 9, 2011

Paypal all documentation

http://help.wildapricot.com/display/DOC/Requesting+PayPal+API+Signature

Wednesday, November 2, 2011

Drupal autocomplete suggestion click track

What I'm not sure how to do and can't seem to find online is have the form submit when a user clicks a suggestion instead of simply completing that field.

$(document).ready(function(){
Drupal.jsAC.prototype.select = function (node) {
this.input.value = $(node).data('autocompleteValue');
if(jQuery(this.input).hasClass('auto_submit')){
this.input.form.submit();
}
};
})

then on your form item add:

'#attributes' => array('class'=> array('auto_submit')),

Tuesday, September 20, 2011

Drupal Create Free order

global $user;

$trial_id = variable_get('ls_free_trial_product', NULL);
$error_msg = FALSE;
if (!$trial_id)
$error_msg = 'The free trial product is not yet configured. Please contact an administrator.';

$node = node_load($trial_id);
$product = uc_product_load($node);
if (!$product)
$error_msg = 'There was an error finding the free trial product. Please contact an administrator.';
$product->nid = $node->nid; //we need to do this in order for the file downloads to work
$product->qty = 1;
$product->title = $node->title;

// Create the order and gather user information
$order = uc_order_new($user->uid, 'completed');
$order_id = $order->order_id;
if (!$user->uid) {
$names = split(' ', $form_state['values']['full_name']);
$last_name = array_pop($names);
$first_names = join(' ', $names);
$email = $form_state['values']['email'];
$company = $form_state['values']['company'];
} else {
$aid = _uc_addresses_get_default_address_id($user->uid);
$address = _uc_addresses_db_get_address($user->uid, $aid);
$first_names = $address->first_name;
$last_name = $address->last_name;
$email = $user->mail;
$company = $address->company;
}
// Populate the order
$order->products[] = $product;
$order->payment_method = 'free_order';
if (!isset($order->primary_email))
$order->primary_email = $email;
$order->billing_first_name = $first_names;
$order->billing_last_name = $last_name;
$order->billing_company = $company;
if (!$user->uid)
$order->data['new_user']['pass'] = $form_state['values']['password'];

// Complete the sale
uc_order_save($order);
uc_cart_complete_sale($order, TRUE);

// Submit the payment
uc_payment_enter($order->order_id, 'free_order', 0, 0, NULL, t('Checkout completed for a free order.'));

$order = uc_order_load($order_id);
if ($order->order_status == 'payment_received') {
$url = url('user/me/purchased-files');
drupal_set_message(t("Your free purchase has been processed. Go to My Downloads to find the link to your product."));
drupal_goto('user/me/purchased-files');
}

Friday, July 22, 2011

Drupal 6 Set different custom message on node creation/update/delete

User the following module
Custom Submit Messages
http://drupal.org/project/csm

Thursday, July 21, 2011

Image gallery with 2 caurasol

User http://galleria.aino.se/

This will fulfill all needs.

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;
    }

    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.

    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;

    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)

    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.




    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;

    Thursday, June 23, 2011

    Displaying exposed filter form for views in Drupal 6

    $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;

    Change Views Exposed Filter Form Select Element To A List Of Checkboxes

    Three steps for doing this.
    /**
    * Implementation of HOOK_theme.
    *
    * @return array An array of theme hooks.
    */
    function mymodule_hooks_theme() {
    return array(
    'select_as_checkboxes' => array(
    'function' => 'theme_select_as_checkboxes'
    ),
    );
    }

    /**
    * Implementation of HOOK_form_alter().
    *
    * @param array $form The form
    * @param string $form_state The current state of the form.
    */
    function mymodule_hooks_form_views_exposed_form_alter(&$form, &$form_state)
    {
    // We only want to change a certain form, so stop Drupal looking at any
    // other exposed view form
    if ($form['#id'] == 'views-exposed-form-myview-page-1') {
    // Make the select box appear as a list of checkboxes
    $form['formelement']['#theme'] = 'select_as_checkboxes';
    $form['anotherformelement']['#theme'] = 'select_as_checkboxes';
    }
    }

    function theme_select_as_checkboxes($element) {
    $output = '';

    $selected_options = (array) $element['#post'][$element['#name']]; // the selected keys from #options

    foreach($element['#options'] as $key => $value) {

    $id = $element['#id'] . '-' . $key; // custom

    // is this option selected?
    $selected = (array_search($key, $selected_options) !== false); // (returns key or false)

    $checkbox = '';

    $output .= '' . "\n";
    }
    return theme_form_element($element, $output); // wraps it neatly
    }

    Wednesday, June 22, 2011

    user_external_login Perform standard Drupal login operations for a user object.

    D6 user_external_login($account, $edit = array())

    Perform standard Drupal login operations for a user object.

    The user object must already be authenticated. This function verifies that the user account is not blocked/denied and then performs the login, updates the login timestamp in the database, invokes hook_user('login'), and regenerates the session.

    Make sticky tableheaders optional

    Drupal 6:

    // Sticky tableheaders always enabled.
    $table = theme('table', $headers, $rows, array(), NULL, array());

    Drupal 7:
    // With sticky tableheaders.
    theme('table', array('header' => $header, 'rows' => $rows));
    // Without sticky tableheaders.
    theme('table', array('header' => $header, 'rows' => $rows, 'sticky' => FALSE));

    Inline cascading stylesheets from drupal_add_css()

    Drupal 6.x:

    $color = variable_get('backgroundcolor', '#FFFFFF');
    drupal_set_html_head("");

    Drupal 7.x:
    $color = variable_get('backgroundcolor', '#FFFFFF');
    drupal_add_css("body {background-color: $color}", 'inline');

    Friday, June 17, 2011

    How to theme a form

    function vs. file
    Well, assuming the form doesn't add already a theme implementation, you have 2 ways to override the form rendering with hook_theme:

    function in your template.php
    file in your template directory

    To add a function you can either specify a 'function' value in the array or leave empty (according hook_theme)

    function: If specified, this will be the function name to invoke for this implementation. If neither file nor function is specified, a default function name will be assumed. For example, if a module registers the 'node' theme hook, 'theme_node' will be assigned to its function. If the chameleon theme registers the node hook, it will be assigned 'chameleon_node' as its function.

    So this is the code:

    array(
    'arguments' => array('form' => NULL),
    ),
    );
    }

    function MYTHEME_MYFORM_form($form) {
    $form['#title'] = 'New form title'; // minimal change but you can do anything here
    return drupal_render($form);
    }
    ?>

    BTW changes like the one above would be better handled on a form_alter hook...

    On the other hand if you want to play with a file you should enter a value for the 'template' key:

    template: If specified, this theme implementation is a template, and this is the template file without an extension. Do not put .tpl.php on this file; that extension will be added automatically by the default rendering engine (which is PHPTemplate). If 'path', above, is specified, the template should also be in this path.

    So the code would be:

    array(
    'arguments' => array('form' => NULL),
    'template' => MYFORM,
    ),
    );
    }
    ?>

    Then the template file would be MYFORM.tpl.php.

    Monday, June 6, 2011

    Drupal An illegal choice has been detected. Please contact the site administrator

    If you see in the core it this message will find in the form validate function. With this drupal say's that "you tried to submit this form with select, checkbox or radio button option that wasn't included in the original form definition! That's not allowed."So, make sure you have not changed the original values of these form elements.

    Monday, May 23, 2011

    l() with ImageCache and/or Lightbox2 D:6

    Simple:

    l('', $filepath, $options = array('html' => TRUE));?>
    With ImageCache module:

    l(theme('imagecache', $preset, $filepath, $alt, $title, $attributes = array()), $filepath$options = array('html' => TRUE));?>
    With ImageCache module and Lightbox2 module:

    l(theme('imagecache', $preset, $filepath, $alt, $title, $attributes = array()), $filepath, array('attributes' => array('rel' => 'lightbox[roadtrip]'), 'html' => TRUE));#ImageCache provides a formatter function which does the same. To my mind this one here is more simple...?>

    Monday, April 4, 2011

    Drupal - How can I remove the 'All Day' text that is sometimes displayed at the end of a date?

    The Date module allows you to use a date field in your CCK types. When you create a date field you can specify its granularity, i.e. the precision to which it stores and manipulates date data. If you specify a granularity that includes time (Hour, Minute & Second) then the date field will contain, manage and display time along with the date.
    The problem arises when you enter a date into such a date field but don't bother to specify a time - you leave it blank. In this case when the date is displayed, the text '(All Day)' will be displayed after it - this can be a real pain if you want the option of time in your date but don't want this text if the user doesn't specify a time!
    So, you want time in your date format but don't want this label how do you get rid of it? You might expect there to be a setting to switch this off, but it seems that there isn't, the subject is discussed in some detail here:
    http://drupal.org/node/367842
    and here:
    http://drupal.org/node/367842
    To summarise, it seems that a good way to turn it off (altogether) is just to override a theme function. Edit you template.php and add the following code:
    function _date_all_day_label() {
    return '';
    }
    This themes the all_day label to nothing. This code is taken directly from the above posts - hats off to yee lads! Make sure to replace with your theme's name, and after making the change remember to clear your cache.
    I wash there was a setting for this, but is seems there isn't, this theme change worked well for me! If anybody knows of a better way of handling this please let us know!!