You are here

助手函数

g089h515r806 的头像
Submitted by g089h515r806 on 星期三, 2009-08-19 10:35

老葛的Drupal培训班 Think in Drupal

当$op 为“process”时,每出现一次[juice!]标签你都要执行一个名为creativejuice_sentence()的助手函数。将这个函数也添加到creativejuice.module中。
 
/**
 * Generate a random sentence.
 */
function creativejuice_sentence() {
    $phrase[0][] = t('A majority of us believe');
    $phrase[0][] = t('Generally speaking,');
    $phrase[0][] = t('As times carry on');
    $phrase[0][] = t('Barren in intellect,');
    $phrase[0][] = t('Deficient in insight,');
    $phrase[0][] = t('As blazing blue sky poured down torrents of light,');
    $phrase[0][] = t('Aloof from the motley throng,');
 
    $phrase[1][] = t('life flowed in its accustomed stream');
    $phrase[1][] = t('he ransacked the vocabulary');
    $phrase[1][] = t('the grimaces and caperings of buffoonery');
    $phrase[1][] = t('the mind freezes at the thought');
    $phrase[1][] = t('reverting to another matter');
    $phrase[1][] = t('he lived as modestly as a hermit');
 
    $phrase[2][] = t('through the red tape of officialdom.');
    $phrase[2][] = t('as it set anew in some fresh and appealing form.');
    $phrase[2][] = t('supported by evidence.');
    $phrase[2][] = t('as fatal as the fang of the most venomous snake.');
    $phrase[2][] = t('as full of spirit as a gray squirrel.');
    $phrase[2][] = t('as dumb as a fish.');
    $phrase[2][] = t('like a damp-handed auctioneer.');
    $phrase[2][] = t('like a bald ferret.');
 
    foreach ($phrase as $key => $value) {
        $rand_key = array_rand($phrase[$key]);
        $sentence[] = $phrase[$key][$rand_key];
    }
 
    return implode(' ', $sentence);
}

Drupal版本: