/**
* Return a set of blocks available for the current user.
* Add a per-region template override option
*/
function ogt_blocks($region) {
$output = '';
if ($list = block_list($region)) {
$function = 'region_'. $region;
if ($theme_function = theme_get_function($function)) {
$blocks = array($list);
//leave the buidling to the dedicated function
$output = call_user_func_array($theme_function, $blocks);
}
else {
foreach ($list as $key => $block) {
//Build the string ourselves.
$output .= theme('block', $block);
}
}
}
// Add any content assigned to this region through drupal_set_content() calls.
$output .= drupal_get_content($region);
return $output;
}
/**
* Template/theme for the region named "siteinfo" (footer)
*
* @return void
**/
function ogt_region_siteinfo($blocks) {
return _phptemplate_callback('region_siteinfo', array('blocks' => $blocks));
}
//-- in a templatefile region_siteinfo.tpl.php, put something like this:
<?php foreach ($blocks as $block => $block) : ?>
<?php print theme('block', $block); ?>
<?php endforeach; ?>
# Erik Kastner 2008-02-13 iterative merge sort in ruby
require 'rubygems'
require 'activesupport'
# iterative merge sort. given [10,9,8,7,6,5,4,3,2,1], first loop would do
# [10,9] => [9,10], [8,7] => [7,8]... etc second loop
# [9,10,7,8] => [7,8,9,10]... etc
def merge_sort(a)
# a one element array is already sorted
return a unless a.size > 1
# first groups are like [[10], [9]]...
merge_size = 2
# loop until merge_size > array.size
# you can also find the nearst power of 2, for 10 thats 16
# that's (log(a.size) / log(2))**2
loop do
offset = 0
a.in_groups_of(merge_size) do |sub_array|
subs = sub_array.in_groups_of(merge_size / 2)
sub_array.size.times do |i|
next if i+offset >= a.size
# after the sub elemnts are shifted off, sub arrays might be empty
# or have nil elements
if (subs[0].empty? || subs[0].first.nil?)
a[i+offset] = subs[1].shift; next
end
if (subs[1].empty? || subs[1].first.nil?)
a[i+offset] = subs[0].shift; next
end
# set a[i+offset] to the lesser of the first elements of the sub arrays
# shift that off the sub array
a[i+offset] = (subs[0].first < subs[1].first) ? subs[0].shift : subs[1].shift
end
offset += sub_array.size
end
break if merge_size > a.size
merge_size *= 2
end
a
end
a = [10,9,8,7,6,5,4,3,2,1]
# a = (1..8).map{rand(200)}
puts "before: #{a.inspect}"
puts "after: " + merge_sort(a).inspect
<?xml version="1.0" ?>
<rss version="2.0">
<channel>
<title>This is my first RSS feed!</title>
<link>http://www.myWebSite.com</link>
<description>I am testing out creating an RSS feed...</description>
<item>
<title>The First Item to Check Out</title>
<link>http://www.myWebSite.com/story1.htm</link>
<description>This is the first article on my Web site!</description>
</item>
<item>
<title>The Second Item to Check Out</title>
<link>http://www.myWebSite.com/story1.htm</link>
<description>This is the second article on my Web site!</description>
</item>
...
</channel>
</rss>
sub date_mysql2sec {
#takes: date in "yyyy-mm-dd hh:mm:ss" format (with some freedom)
#returns: date in seconds since 1970 format
use Time::Local;# 'timelocal_nocheck';
my $mysqldate = shift;
$mysqldate =~ /(\d{4}).(\d{2}).(\d{2}).(\d{2}).(\d{2}).(\d{2})/;
my ($sec,$min,$hour,$mday,$mon,$year) = ($6,$5,$4,$3,$2,$1);
if ($mon != 0) {$mon--};
return timelocal($sec,$min,$hour,$mday,$mon,$year);
}
sub date_sec2mysql {
#takes: date in seconds since 1970 format
#returns: date in yyyy-mm-dd hh:mm:ss format
my $secdate = shift;
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday) = localtime($secdate);
$year += 1900;
$mon++;
$mon = $mon < 10 ? "0$mon" : $mon;
$mday = $mday < 10 ? "0$mday" : $mday;
$sec = $sec < 10 ? "0$sec" : $sec;
$min = $min < 10 ? "0$min" : $min;
$hour = $hour < 10 ? "0$hour" : $hour;
return qq{$year-$mon-$mday $hour:$min:$sec};
}
sub date_mysql_now {
#Takes: nothing
#Returns: current date and time in yyyy-mm-dd hh:mm:ss format
return date_sec2mysql(time);
}
sub db_connect {
my ($dbname, $dbuser, $dbpass) = @_;
my $dbh = DBI->connect("DBI:mysql:$dbname",$dbuser,$dbpass);
#$dbh->do(qq{set character set 'utf8';});
return $dbh;
}
sub do_sql {
# Takes: $dbh, $sql
# Returns: status
my $dbh = shift || die "Database not connected!\n";
my $sql = shift || die "Missing SQL statement???\n";
return $dbh->do($sql);
}
sub execute_sql {
# Takes: $dbh, $sql
# Returns: $result_arrayref
my $dbh = shift || die "Database not connected!\n";
my $sql = shift || die "Missing SQL statement???\n";
my $sth = $dbh->prepare($sql);
$sth->execute;
my $result = $sth->fetchall_arrayref({}); # {} => Return arrayref of hashrefs
return $result;
}
sub do_insert {
#takes: $dbh, $table, $datahash
#returns: status
my $dbh = shift || die "Database not connected!\n";
my $table = shift || die "Missing table!\n";
my $datahash = shift || die "Nothing to insert!\n";
my $insert = "INSERT INTO $table (" . join(',', keys %$datahash) . ') VALUES (' . join(',', values %$datahash) . ');';
return &do_sql($dbh, $insert);
}