Sign up to create your own snipts, or login.

Public snipts » drupal The latest public drupal snipts.

showing 1-20 of 93 snipts for drupal
  • 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())
    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', 'pmsth'). $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
  • Truncate Cache tables
    TRUNCATE `cache`;
    TRUNCATE `cache_block`;
    TRUNCATE `cache_content`;
    TRUNCATE `cache_filter`;
    TRUNCATE `cache_form`;
    TRUNCATE `cache_menu`;
    TRUNCATE `cache_page`;
    TRUNCATE `cache_update`;
    TRUNCATE `cache_views`;
    TRUNCATE `cache_views_data`;
    TRUNCATE `search_dataset`;
    TRUNCATE `search_index`;
    TRUNCATE `search_node_links`;
    TRUNCATE `search_total`;
    TRUNCATE `views_object_cache`;
    TRUNCATE `watchdog`;
    

    copy | embed

    0 comments - tagged in  posted by pazzypunk on Jan 25, 2010 at 5:10 p.m. EST
  • update to a newer version of Drupal
    cvs update -dP -r DRUPAL-6-16
    

    copy | embed

    0 comments - tagged in  posted by carsonblack on Jan 22, 2010 at 8:03 a.m. EST
  • Check out Drupal from CVS repository
    cvs -z6 -d :pserver:anonymous:anonymous@cvs.drupal.org:/cvs/drupal co -d /WHATEVER DIRECTORY YOU WANT THIS IN -r DRUPAL-6-15 drupal
    

    copy | embed

    0 comments - tagged in  posted by carsonblack on Jan 22, 2010 at 8:00 a.m. EST
  • add drupal permission for certain role
    <?
    $perm = db_result(db_query("SELECT perm from {permission} where rid=5"));
        $perm_arr = explode(',', $perm);
        $perm_arr[] = 'schedule (un)publishing of nodes';
        $ret[] = update_sql("UPDATE {permission} SET perm='" . implode(',', $perm_arr) .  "' where rid=5");
    
        cache_clear_all();
    ?>
    

    copy | embed

    0 comments - tagged in  posted by sbatman on Jan 20, 2010 at 6:00 a.m. EST
  • Embed a View
    <?php
     //view name, display, argument(s)
     print views_embed_view('front_page','page_2','3'); 
    

    copy | embed

    0 comments - tagged in  posted by markbgh on Jan 13, 2010 at 7:50 p.m. EST
  • Get filepath from fid
    <?php
    $filepath = db_result(db_query("SELECT filepath FROM {files} WHERE fid = %d", $fid));
    

    copy | embed

    0 comments - tagged in  posted by markbgh on Jan 13, 2010 at 5:30 p.m. EST
  • outdated drupal module with svn
    ## In a nutshell, how to update a module from Drupal contrib, 
    ## on a production site that is under revision control (subversion).
    
    # If you turn on a module (that just happens to already be
    # present in the list on admin/build/modules), then you MUST
    # 1)  go to the update status page
    # 2)  find out if the module you just turned on is up to date
    # 3)  if it is,  fine (your done! stop here),  
    # 4)  if there are updates... then go to the drupal.org site first
    #     to see if there are any "gotchas" for the upgrade.  As you'll
    #     be turning the module on for the first time on a new site,
    #     then you shouldnt have to worry too much.
    # 5)  To run the updates: login via ssh
    
    ssh username@server.com
    
    # 6) go to the right folder and execute drush update
    
    cd domains/example.com/public_html/sites/all/modules
    drush --uri=example.com update modulename
    
    # 7) confirm that the update was successful on the site
    # 8) then check in the code
    
    svn commit -u username -m "updated modulename to the latest version"
    

    copy | embed

    0 comments - tagged in  posted by jrguitar21 on Dec 23, 2009 at 4:49 p.m. EST
  • Automatic node-[nid].tpl.php template suggestions
    function phptemplate_preprocess_node(&$vars, $hook) {
      $node = $vars['node'];
      $vars['template_file'] = 'node-'. $node->nid;
    }
    

    copy | embed

    0 comments - tagged in  posted by noussh on Dec 14, 2009 at 2:23 a.m. EST
  • update drupal from subversion tags
    # Update a Drupal minor revision using a patch file.
    # Creating a patch file between cvs tags on the server proved to be 
    # impossible. I've found a way to do this with a subversion mirror
    # of Drupal core.
    
    cd ~/path/to/local/drupal
    
    # What is current version of Drupal?
    cat CHANGELOG.txt | grep Drupal | head -1
    ## Drupal 6.13, 2009-07-01
    
    # I'm using a Subversion mirror of Drupal core to create the patch.
    # (Thanks to the guys at subversible.com!)
    svn diff http://subversible.com/svn/drupal/tags/DRUPAL-6-13 \ 
             http://subversible.com/svn/drupal/tags/DRUPAL-6-14 > d6-14.patch 
    
    # The local version of drupal was created from a tarball, and the date 
    # format inside the $Id$ (from CVS) is: YYYY/mm/dd HH:MM:SS,  but in the 
    # subversion patch it was YYYY-mm-dd HH:MM:SS.  So I had to this quick 
    # find/replace in order to get the patch to apply cleanly.
    perl -pi -e 's/(\d{4})-(\d{2})-(\d{2})\s(\d{2})/\1\/\2\/\3 \4/g' d6-14.patch
    
    
    # Check to see if you have any outstanding uncommitted local changes. If
    # there are some changes then execute the commit (commented out below).
    svn status
    #svn commit -m "latest changes prior to drupal core update"
    
    # Apply the patch.  The patch from svn diff command should be in 
    # unified diff format (-u) and the paths should be taken as they are so 
    # files in subfolders are matched (-p0).
    patch -p0 -u <d6-14.patch
    
    
    #dont forget to commit the updates...
    svn commit -m "updated core drupal"
    
    #optionally, tag the updated code in the repository
    

    copy | embed

    0 comments - tagged in  posted by jrguitar21 on Dec 11, 2009 at 7:45 p.m. EST
  • views argument by taxonomy id.
    $node = node_load(arg(1));
    if ($node){
    foreach($node->taxonomy as $term){$terms[]=$term->tid;}
    return implode('+',$terms);
    }else{return;}
    

    copy | embed

    0 comments - tagged in  posted by noussh on Dec 04, 2009 at 11:40 a.m. EST
  • Adding column in Drupal Solr
    Modify the schema.xml to add a field:
    <field name="layer" type="integer" indexed="true" stored="true"/>
    
    
    
    apachesolr_search.module:
    function apachesolr_search_basic_params($query) {
      $params = array(
        'fl' => 'id,nid,title,comment_count,type,created,changed,score,path,url,uid,name,layer',
        'rows' => variable_get('apachesolr_rows', 10),
        'facet' => 'true',
        'facet.mincount' => 1,
        'facet.sort' => 'true'
      );
      return $params;
    }
    
    
    
    apachesolr_views_handler_field_layer.inc:
    <?php
    // $Id: apachesolr_views_handler_field_layer.inc,v 1.1 2009/04/03 17:28:59 scottreynolds Exp $
    
    /**
     * @file
     * Views handler to handle the layer field. Will not add anything to the query
     */
    class apachesolr_views_handler_field_layer extends views_handler_field_numeric {
      function construct() {
        parent::construct();
        $this->definition['float'] = TRUE;
      }
      function query() {
        $this->field_alias = $this->query->add_field('layer');
      }
    }
    
    
    
    apachesolr_views.views.inc:
    'apachesolr_views_handler_field_layer' => array(
        'parent' => 'views_handler_field_numeric',
    ),
    
    
    $data['apachesolr']['layer'] = array(
        'title' => t('Layer'),
        'help' => t('The layer'),
        'sort' => array(
          'handler' => 'apachesolr_views_handler_sort',
        ),
        'field' => array(
          'handler' => 'apachesolr_views_handler_field_layer'
        ),
      );
    
    
    
    apachesolr.index.inc:
        $layer = 0; //anything you want ex: rand(0,9)
        $document->layer = $layer;
    

    copy | embed

    0 comments - tagged in  posted by briandorval on Dec 02, 2009 at 11:51 a.m. EST
  • Drupal check all checkbox
    //add javascript to the page to handle the select all checkbox
    drupal_add_js("function toggleSelectAll(cbx){
      if(\$(cbx).attr('checked') == true){
        \$(\$(cbx).parents('form').get(0)).find('input[@type=checkbox]').each(function(){
          if(!this.checked){
            this.checked = true;
          }
        });
      }
      else{
        \$(\$(cbx).parents('form').get(0)).find('input[@type=checkbox]').each(function(){
          if(this.checked){
            this.checked = false;
          }
        });
      }
    }
    //Only show the select all box if javascript is working
    \$(document).ready(function(){\$('#edit-select-all-0').show();});
    ",'inline');
    
    //add the select all checkbox to the form
    $form['select_all'] = array(
      '#type' => 'checkboxes',
      '#options' => array(0 => "Select All"),
      '#attributes' => array('onchange' => "toggleSelectAll(this);", 'style' => 'display : none'),
    );
    

    copy | embed

    0 comments - tagged in  posted by asdflars on Nov 15, 2009 at 7:36 p.m. EST
Sign up to create your own snipts, or login.