Latest 100 public
snipts » drupal
showing 1-20 of 105 snipts for drupal
-
∞ Updates drupal & modules (see http://drupal.org/node/859426)
(sudo) drush pm-update drupal -
∞ drupal_get_machinename
<?php /** * Most machine names are generated as-you-type via Javascript helpers on the * client side. This helper function automates server-side conversions from * regular text strings into valid Drupal machine names. * * Machine names must contain only lowercase alpha-numerics and underscores. * Non-alphanumeric characters are converted to underscores, and sequential * underscore characters are trimmed to a single character. * * Additionally, if the transliteration module is enabled, then it will be * used to first convert non-ascii Unicode characters to standard Roman ASCII * characters on a best-effort basis, and replacing all unknown characters * with underscores. * * @param $text * A string of characters to be converted. * * @return * A string containing the valid Drupal machine name for the specified text. * Returns the empty string if invalid input was provided. * * @see * See the transliteration module in the drupal contrib repository for more * information on non-ascii character transliterations. */ function drupal_get_machinename($text) { // Cache machine name conversions locally for performance boost. static $texts; // If the input string is not valid, return an empty string. if (empty($text) || !is_string($text)) { return ''; } // Setup the local static variable cache if it doesnt exist. if (!is_array($texts)) { $texts = array(); } // Save the machine name conversion to the static cache if it doesnt exist. if (!isset($texts[$text])) { $out = $text; if (module_exists('transliteration')) { $out = transliteration_get($out, '_'); } $out = strtolower($out); $out = preg_replace('/[^a-z0-9]/', '_', $out); $out = preg_replace('/_+/', '_', $out); $texts[$text] = $out; } return $texts[$text]; }
-
∞ On a Unix-like system, the following shell command can strip data out of a database dump which generally shouldn’t be migrated when moving a Drupal database from one site to another.
# src: http://drupal.org/node/257026 sed -E -e "/^INSERT INTO \`(cache|watchdog|sessions)/d" < /path/to/dump.sql > /path/to/dump-stripped.sql
-
∞ Get Node Type from filtered text
<?php node_get_types('name', 'example_filtered_type');
-
∞ Get cck field info
<? /******************************** * EXAMPLE 1) Get all cck field ********************************/ // @see content_existing_field_options() function _imagefield_viewer_field_options() { $type = content_types($type_name); $fields = content_fields(); $field_types = _content_field_types(); $options = array(); foreach ($fields as $field) { $field_type = $field_types[$field['type']]; $text = t('@type: @field (@label)', array('@type' => t($field_type['label']), '@label' => t($field['widget']['label']), '@field' => $field['field_name'])); $options[$field['field_name']] = (drupal_strlen($text) > 80) ? truncate_utf8($text, 77) . '...' : $text; } // Sort the list by type, then by field name, then by label. asort($options); return $options; } /*************************************************** * EXAMPLE 2) Get all cck field of a certain type ***************************************************/ function _en_gmap_allowed_nodereference_options() { $type = content_types(); $fields = content_fields(); $options = array(); foreach ($fields as $field) { if($field['type'] == 'nodereference') { $referenceable_types = array_filter($field['referenceable_types']); foreach ($referenceable_types as $ref_type) { $settings = variable_get("location_settings_node_$ref_type", FALSE); if ((isset($settings['multiple']['max']) && $settings['multiple']['max']) || variable_get("location_maxnum_$ref_type", 0)) { //this node type uses locations. It can be added to options array $options[$field['field_name']] = $field['field_name'] . " usato in " . $field['type_name']; } } } } // Sort the list by type, then by field name, then by label. asort($options); return $options; } ?>
-
∞ drupal files folder svn externals
# go to working copy cd ~/public_html/sites/default/ # take a backup tar zcvf files.tar.gz --exclude=.svn files # move drupal files folder out of trunk, and replace with externals, to keep trunk lightweight. svn mv http://svn/project/trunk/sites/default/files http://svn/project/assets/files -m "moved files folder out of trunk to assets" # delete files on working copy svn up # setup the external reference svn propset svn:externals 'files http://svn/project/assets/files' . # fetch external file svn up
-
∞ Get path alias from NID
<?php print(drupal_get_path_alias("node/".$data->nid))
-
∞ Simple Caching in Drupal
<?php //source http://www.lullabot.com/articles/a_beginners_guide_to_caching_data <?php $voteup_widget = cache_get('voteup_widget_data'); $voteup_widget = $voteup_widget->data; if(!$voteup_widget) { $voteup_widget = drupal_http_request('http://voteupny.com/content/vote-represent'); $voteup_widget = $voteup_widget->data; cache_set('voteup_widget_data',$voteup_widget, 'cache', CACHE_TEMPORARY); print '<!-- VOTEUP UNCACHED -->'; } print $voteup_widget;
-
∞ Node type preprocess for template.php
<?php function phptemplate_preprocess_page(&$vars) { global $user; // provide page-nodetype.tpl.php as a template suggestion if($node = menu_get_object()) { $vars['template_files'][] = "page-{$node->nid}"; $vars['template_files'][] = "page-{$node->type}"; } }
-
∞ Drupal 6 Node Load
<?php //reference http://api.drupal.org/api/function/node_load $variable = node_lode(nid);
-
∞ Convert Markdown fields to Full HTML
<?php /** * Example 1: * Renders the body field as format_id '4' (i.e., Markdown) then saves as format_id '3' (i.e, Full HTML). */ // Run all enabled filters for format_id '4' on the body field. $object->body = check_markup($object->body, 4); // Change $format to format_id '3'. $object->format = 3; node_save($object); /** * Example 2: * Renders several CCK fields as format_id '4' (i.e., Markdown) then saves as format_id '3' (i.e, Full HTML). */ // Run all enabled filters for format_id '4' on $field_notes, $field_description and $field_dimensions. $object->field_notes[0]['format'] = check_markup($object->field_notes[0]['value'], 4, TRUE); $object->field_description[0]['format'] = check_markup($object->field_description[0]['value'], 4, TRUE); $object->field_dimensions[0]['format'] = check_markup($object->field_dimensions[0]['value'], 4, TRUE); // Change $format to format_id '3' for all three fields. $object->field_notes[0]['format'] = 3; $object->field_description[0]['format'] = 3; $object->field_dimensions[0]['format'] = 3; node_save($object); /** * Example 3: * Simultaneously renders CCK field $field_description and migrates the new value to the default body field. */ $object->body = check_markup($object->field_description[0]['value'], 4, TRUE); node_save($object);
-
∞ Image Cache Push
<?php print theme('imagecache','cache_name', 'imagepath.jpg', 'alt');
-
∞ install Drush from CVS HEAD on any unix server
## ## Installs Drush (the Drupal Shell command line utility) from CVS HEAD ## on any UNIX machine, such that all users that have /usr/local/bin in ## their $PATH can use Drush (granted they have access to a Drupal install). ## ## cd /usr/local/src cvs -z6 -d:pserver:anonymous:anonymous@cvs.drupal.org:/cvs/drupal-contrib checkout -d drush-HEAD contributions/modules/drush/ curl -O http://download.pear.php.net/package/Console_Table-1.1.3.tgz tar zxvf Console_Table-1.1.3.tgz cp Console_Table-1.1.3/Table.php drush-HEAD/includes/table.inc ln -s /usr/local/src/drush-HEAD/drush /usr/local/bin/drush ## ## now any user that has /usr/local/bin in their $PATH can use Drush. ## ## ## ... later on, to keep drush up to date, run the following: #cd /usr/local/src/drush-HEAD #cvs update -dPA
-
∞ Clear Drupal Cache
Drupal cache clearing methods http://drupal.org/node/42055 Add the code below to a file and save it as clear.php. Then run clear.php and make sure to remove the page when you are done. This will clear the Drupal cache. <?php include_once './includes/bootstrap.inc'; drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL); drupal_flush_all_caches(); ?>
-
∞ Drupal Link Function
<?php //reference http://api.drupal.org/api/function/l/6 //l($text, $path, $options = array()) //options array explanation http://groups.drupal.org/node/11554 l('Front page',<front>);
-
∞ Drupal Date Format
<?php // reference http://php.net/manual/en/function.date.php for date formatting // 'small','large',or 'medium' can replace custom to use Drupal's default settings for those time formats format_date($timestamp, 'custom', 'D, j M, Y \a\\t G:i' );
-
∞ image link
<? $img_path = "images/arr_leggi_blu.gif"; $link_path = "node/47"; $theme_name = 'pmsth'; $img = theme('image', drupal_get_path('theme', $theme_name). "/$img_path"); print l($img, $link_path, array('html' => true)); ?>
-
∞ image
<? $path = "images/arr_leggi_blu.gif"; $theme_name = 'pmsth'; print theme('image', drupal_get_path('theme', $theme_name). "/$path"); ?>
-
∞ link
<? $anchor = "anchor text"; $drupal_path = "node/47"; print l($anchor, $drupal_path); ?>
-
∞ view the lastest video file in flashvideo
<?php // add after flashvideo.module line 1267 $sql .= ' ORDER BY fv.fid DESC'; ?>


