IMPORTANT!

Snipt is going open source. We've toyed with this idea for quite a while, and have finally decided it's the right way to move forward.

A few things:
  • The entire Snipt source code will be released on GitHub under the 3-clause BSD License on Friday, September 10th.
  • While we'd like to think we're perfect, we realize we're only human. By open sourcing the software that runs this website, certain bugs or security flaws may be discovered that could compromise the privacy of your snipts.
  • Only the Lion Burger team will be able to push commits to the Snipt.net site. Contributors should send a pull request to add new features or submit patches.
  • By using this site, you agree not to be too angry or take any legal action against Lion Burger should this whole thing go up in flames some day.
  • Follow us on Twitter for updates.
I agree, close this message
Sign up to create your own snipts, or login.

Latest 100 public snipts » drupal The latest public drupal snipts.

showing 1-20 of 105 snipts for drupal
  • Updates drupal & modules (see http://drupal.org/node/859426)
    (sudo) drush pm-update drupal
    

    copy | embed

    0 comments - tagged in  posted by lukasnick on Aug 18, 2010 at 7:32 a.m. EDT
  • 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];
    }
    

    copy | embed

    0 comments - tagged in  posted by jrguitar21 on Aug 04, 2010 at 9:38 p.m. EDT
  • 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
    

    copy | embed

    0 comments - tagged in  posted by zachharkey on May 24, 2010 at 8:47 a.m. EDT
  • Get Node Type from filtered text
    <?php
      node_get_types('name', 'example_filtered_type');
    

    copy | embed

    0 comments - tagged in  posted by markbgh on May 20, 2010 at 11:36 a.m. EDT
  • 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;
    }
    ?>
    

    copy | embed

    0 comments - tagged in  posted by sbatman on May 19, 2010 at 7:09 a.m. EDT
  • 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
    

    copy | embed

    0 comments - tagged in  posted by jrguitar21 on May 04, 2010 at 6:50 p.m. EDT
  • Get path alias from NID
    <?php 
      print(drupal_get_path_alias("node/".$data->nid))
    

    copy | embed

    0 comments - tagged in  posted by markbgh on Apr 28, 2010 at 10:18 a.m. EDT
  • 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;
    

    copy | embed

    0 comments - tagged in  posted by markbgh on Apr 27, 2010 at 2:16 p.m. EDT
  • 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}";
      }
      }
    

    copy | embed

    0 comments - tagged in  posted by markbgh on Apr 26, 2010 at 12:04 p.m. EDT
  • Drupal 6 Node Load
    <?php
     //reference http://api.drupal.org/api/function/node_load
     $variable = node_lode(nid);
    

    copy | embed

    0 comments - tagged in  posted by markbgh on Apr 13, 2010 at 11:38 a.m. EDT
  • 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);    
    

    copy | embed

    0 comments - tagged in  posted by zachharkey on Apr 06, 2010 at 12:53 a.m. EDT
  • Image Cache Push
    <?php 
    print theme('imagecache','cache_name', 'imagepath.jpg', 'alt');
    

    copy | embed

    0 comments - tagged in  posted by markbgh on Mar 23, 2010 at 11:48 a.m. EDT
  • 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
    

    copy | embed

    0 comments - tagged in  posted by jrguitar21 on Mar 05, 2010 at 11:38 a.m. EST
  • 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();
    ?>
    

    copy | embed

    0 comments - tagged in  posted by abecker on Mar 04, 2010 at 6:55 p.m. EST
  • 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>);
    

    copy | embed

    0 comments - tagged in  posted by markbgh on Feb 22, 2010 at 1:38 p.m. EST
  • 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' );
    

    copy | embed

    0 comments - tagged in  posted by markbgh on Feb 17, 2010 at 12:51 p.m. EST
  • 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));
    
    ?>
    

    copy | embed

    0 comments - tagged in  posted by allaterza on Feb 06, 2010 at 6:24 a.m. EST
  • image
    <? 
    $path = "images/arr_leggi_blu.gif"; 
    $theme_name = 'pmsth';
    
    print theme('image',  drupal_get_path('theme', $theme_name). "/$path");
    ?>
    

    copy | embed

    0 comments - tagged in  posted by allaterza on Feb 06, 2010 at 6:13 a.m. EST
  • link
    <? 
    $anchor = "anchor text";
    $drupal_path = "node/47";
    print l($anchor, $drupal_path);
    ?>
    

    copy | embed

    0 comments - tagged in  posted by allaterza on Feb 06, 2010 at 6:04 a.m. EST
  • view the lastest video file in flashvideo
    <?php
    // add after flashvideo.module line 1267
    $sql .= ' ORDER BY fv.fid DESC';
    ?>
    

    copy | embed

    0 comments - tagged in  posted by daaquan on Jan 27, 2010 at 4:41 a.m. EST
Sign up to create your own snipts, or login.