Public
snipts » drupal
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
-
∞ 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()) 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', 'pmsth'). $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'; ?>
-
∞ 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`;
-
∞ update to a newer version of Drupal
cvs update -dP -r DRUPAL-6-16
-
∞ 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
-
∞ 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(); ?>
-
∞ Embed a View
<?php //view name, display, argument(s) print views_embed_view('front_page','page_2','3');
-
∞ Get filepath from fid
<?php $filepath = db_result(db_query("SELECT filepath FROM {files} WHERE fid = %d", $fid));
-
∞ 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"
-
∞ Automatic node-[nid].tpl.php template suggestions
function phptemplate_preprocess_node(&$vars, $hook) { $node = $vars['node']; $vars['template_file'] = 'node-'. $node->nid; } -
∞ 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
-
∞ 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;} -
∞ 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;
-
∞ 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'), );



Using Drupal