aufumy's blog

Moderate posts using Actions and Workflow

There are many options for moderating posts in Drupal. A tried and true method is with the use of the modr8 module.

I used Drupal's core trigger module, the contributed workflow module and a custom action to accomplish a similar functionality.

I enabled the workflow module, and created the "course queue" workflow, with states "accepted", "pending" and "declined".

Sending mail with drupal mail

To send a mail out in your drupal module, use drupal_mail($module, $key, $to, $language, $params, $from, $send)

$module is the name of your module, $key is the identifier of your mail, to specify different mail templates.

e.g.

$params['!firstName'] = $node->field_firstname[0]['value'];
$params['!lastName'] = $node->field_lastname[0]['value'];
$params['!todaydate'] = date('m-d-Y');

Ecommerce with Beanstream

Ecommerce can be a complicated topic because it is expected to take into account the company's method of selling, marketing, inventory and processing cash.

The basics of communicating with an e-commerce gateway such as Beanstream, who also happens to reside in Victoria, Canada, is to provide a bunch of information that gets encoded to https://www.beanstream.com/scripts/process_transaction.asp via curl.


$merchant_id = '000000000'; // Replace with your merchant id
$sBeanstream = "requestType=BACKEND";

Credit Card validation

If you need a simple ready-made solution for credit card validation, there is Analysis and Solution Company's Credit card validation script.

Included with be the main logic ccvs.inc.php, and a language folder containing translations of text.

Here is a sample of code calling the validation function:

// Credit card validation
include("ccvs.inc.php");
$ccn = new CreditCardValidationSolution;
if (!$ccn->validateCreditCard($credit_card_number, 'en')) {

CVSing back your drupal site.

The benefits of using source control are great. It is like working with another developer, to review your code changes, even if you are all by yourself, not to mention being able to rollback any changes that you have made.

When using drupal, I like to grab core, modules and themes using cvs rather than downloading files. I find it easier to keep core and modules up-to-date while maintaining the patches I might have applied to a module.

Getting started with Drupal recipe on MacOSX

Install AMP server for MacOSX

  1. Download MAMP
  2. move it to Applications
  3. make a mysql configuration change
  4. [mysqld]
    max_allowed_packet=64M
    
  5. check php.ini that memory_limit is 32M or more

Download Drupal with drush

  1. download and extract drush from http://drupal.org/project/drush

  2. wget http://ftp.drupal.org/files/projects/drush-All-Versions-2.1.tar.gz
    tar zxvf drush-All-Versions-2.1.tar.gz

Where is the drupal omnifunc for vim?

Recently I tried out omni complete in vim, and I love it. It is included in vim 7. This adds a function lookup for php, html, python, javascript, css, xml, sql and c amongst others.

To enable under your home directory in the ".vimrc" file add one line
:autocmd FileType php set omnifunc=phpcomplete#CompletePHP

Syntax Highlighting

In "~/.vimrc"

:syntax enable
:colors pyte
:syntax on

Pushing out your own tokens

If you are in need of custom tokens, here is an example of how to create custom token for a specific vocabulary.


/**
* Implementation of hook_token_values()
*/
function csm_support_token_values($type, $object = NULL, $options = array()) {
if ($type == 'node') {
$tokens['term-media-type'] = '';
$termArray = $object->taxonomy;
$tid_media_type = $termArray[15];
$term_obj = taxonomy_get_term($tid_media_type);
$tokens['term-media-type-tid'] = $term_obj->tid;
$tokens['term-media-type'] = strtolower($term_obj->name);
return $tokens;
}
}

Migrating from Bricolage to Drupal

If a customer has a Bricolage site, and wants to use some of the features of drupal, they can try out the Bricolage Integration module: http://drupal.org/project/bricolage

Otherwise, it is also possible to migrate from a Bricolage project entirely to drupal. To migrate data, I analyzed the database, to get unique ids (story__id) and the directory structure of the generated html files. Taxonomy and/or content type was determined from the directory structure, and main content was parsed from the html files.

Database Migration Part II

In the first blog on Database Migration this post skimmed some info on starting the journey. This blog posts is a little drier, and more detailed, listing some major steps of database import and a few code samples. Shown below is my partner in crime for the second project, Harry. The current methods used are always open to new methods of improvement.


Image courtesy of Steve Krueger