Drupal

Who says Drupal doesn't scale, Acquia provided 3 million pages an hour without problems

http://acquia.com/blog/acquia-hosting-customer-hits-700-pagessecond-or-w...

Here's a list of many famous Drupal sites: http://buytaert.net/tag/drupal-sites

list includes:

Nike
Yahoo
Intel
AT&T
Reuters
CNN
Mattel
Sony
Playboy
MTV
NATO
Warner Brothers
NASA
Even the United States White House!

Open Flash Charts 2 API

After looking to get open flash charts version 2 working for quite a while here are working directions.

http://drupal.org/node/423046#comment-3362858

Then in the node the directions on this page above were in fact wrong for testing the installation.

use this instead as I posted on this nodes page above.

<?php
//just the out of the box example
print open_flash_chart_api_render();

//now I'll try my own small variation, you can make your own graph with the code below:

  // create new chart object
  $chart = ofc_api_chart();

  // set chart title
  $title = "Open Flash Chart 2 API\nSample Chart";
  if ( !is_null($callback_params) ) {

    $title .= "\nARG1=" . $callback_params[1];
  }
  $chart->set('title', array(
    'text' => $title,
    'style' => '{font-size: 12px; font-family: Verdana, Arial, sans-serif; text-align: center;}',
  ));

  // create new bar_sketch element and set its attributes
  $bar = ofc_api_element('bar_sketch');
  $bar->set('colour', '#81ac00');
  $bar->set('outline-colour', '#567300');
  $bar->set('offset', 7);
  $bar->set('values', array(5, 1, 4, 3, 2, 26));
  $bar->set('tip', 'Value: #val#');

  // add bar_sketch element to the chart
  $chart->add('element', $bar);



print open_flash_chart_api_render($chart);
?>

Drush Commands

I'll add notes to this at a later time.

To download a module (masquerade in this case) using drush type in:

drush dl masquerade

Print out a page without the template header, footer, blocks, etc.

http://www.drupalcoder.com/story/718-how-to-define-page-callbacks-that-d...

I haven't tried it yet, but this was a good post on Drupal Planet. I haven't needed to do this yet, but I know I will :)


/**
 * Implementation of hook_menu().
 */
function my_module_menu() {
  $items['hello'] = array(
    'title' => 'Hello world',
    'page callback' => 'my_module_page',
    'access callback' => TRUE,
  );
}

function my_module_page() {
  return t('Hello world');
  return null;
}



Writing secure Drupal code link/reference

http://drupal.org/writing-secure-code

Just a link for a refresher on making sure you're writing secure code.

Theming blocks in drupal

Create a custom block for Drupal with a module using hook_block

<?php

// $Id$

/**
* A module to create a basic block to be available from the drupal blocks menu page
*
*
*
*
*/




function latest_block($op='list',$delta=array(),$edit=array())
{
      switch ($op)
     {

        case 'list':
                       $blocks[0]['info'] = t('Latest CTL Content');
                       return $blocks;
                       break;
         case 'view':
  

          $content = 'hello world';
          $blocks['subject'] = t('Latest CTL Content');
          $blocks['content'] = $content;
       return $blocks;
       break;
      }
}

Replace the corresponding function above with whats below to get recent posts in your drupal block

function latest_block($op='list',$delta=array(),$edit=array())
{
      switch ($op)
     {

        case 'list':
                       $blocks[0]['info'] = t('Latest CTL Content');
                       return $blocks;
                       break;
         case 'view':
           ob_start();
         $num_nodes = 5;

$result = db_query_range(db_rewrite_sql('SELECT n.nid, n.title, n.type FROM {node} n WHERE n.status = 1 AND n.type <> "forum" ORDER BY n.changed DESC'), 0, $num_nodes);

$output = node_title_list($result);
$output .= l('More...', 'tracker');
          //$content = 'hello world';
          $content = $output;
          $blocks['subject'] = t('Latest CTL Content');
          $blocks['content'] = $content;
       return $blocks;
       break;
      }
}

And here is an example with multiple blocks in the same module:

function latest_block($op='list',$delta=array(),$edit=array())
{
      switch ($op)
     {

        case 'list':
                       $blocks[0]['info'] = t('Latest CTL Content Block');
                       $blocks[1]['info'] = t('Partner Block');
                       return $blocks;
                       break;
         case 'view':
           switch ($delta) {
           case 0:
              //ob_start();
              $num_nodes = 2;

              $result = db_query_range(db_rewrite_sql('SELECT n.nid, n.title, n.type FROM {node} n WHERE n.status = 1 AND n.type = "Biography" ORDER B
Y n.changed DESC'), 0, $num_nodes);
              $result2 = db_query_range(db_rewrite_sql('SELECT n.nid, n.title, n.type FROM {node} n WHERE n.status = 1 AND n.type = "page" ORDER BY n.
changed DESC'), 0, $num_nodes);
              $result3 = db_query_range(db_rewrite_sql('SELECT n.nid, n.title, n.type FROM {node} n WHERE n.status = 1 AND n.type = "news" ORDER BY n.
changed DESC'), 0, $num_nodes);

              $output = node_title_list($result);
              $output .= node_title_list($result2);
              $output .= node_title_list($result3);
//$output .= l('More...', 'tracker');
              //$content = 'hello world';
              $content = $output;
              $blocks['subject'] = t('Latest CTL Content');
              $blocks['content'] = $content;
              //return $blocks;
              break;
           case 1:
              $blocks['subject']=t('Parnter Block');
              $blocks['content']="put the link to the content here";
              break;

         }
         return $blocks;


}
}

also check out http://drupal.org/node/60528

Write your own sql to override the sql in your Drupal view

Here's a module that may do it http://drupal.org/project/views_modify_query, or use the code below:

Here is the module I wrote:
removedups_view.module is listed below

the query for the view news_events_rss is re-written prior to being executed. There were duplicate titles being listed so I used GROUP BY aggregator_item
_title to remove duplicates. The sql generated by the views module wasn't what was expected, so it had to go. I may make this into a module to submit to drupal.org. It is a module for developers like myself who found writing their own sql simpler, back during simpler times. This is a sql nostagia module. Retro.

<?php
function removedups_view_views_pre_execute(&$view) {
  watchdog('alert','tried to use views_pre_execute');
  if ($view->name \=\= 'news_events_rss') {
  //echo '<pre>'; print_r($view->build_info['query']); echo '</pre>'; 
$view->build_info['query'] = "SELECT aggregator_item.iid AS iid, aggregator_item.title AS aggregator_item_title, aggregator_item.link AS aggregator_item_link, aggregator_item.description AS aggregator_item_description, aggregator_item.timestamp AS aggregator_item_timestamp FROM aggregator_item aggregator_item  LEFT JOIN aggregator_category_feed aggregator_category_feed ON aggregator_item.fid = aggregator_category_feed.fid LEFT JOIN aggregator_category aggregator_category ON aggregator_category_feed.cid = aggregator_category.cid WHERE aggregator_category.cid in ('%s') GROUP BY aggregator_item
_title ORDER BY aggregator_item_timestamp DESC";
  //watchdog('alert','got here tried to use views_pre_execute');
}}

Note the ('%s') .... even though I ignore the views query builder in drupal, I still can use the variable set via the query builder! Very useful.

I just read a drupal planet article and the consultants did this differently: http://www.dynamiteheads.com/blog/jakub-suchy/optimizing-views-queries-m...

Manipulating the $query object

http://drupal.org/node/310075

took me forever to find this.