bensangeorge.com

Archive for the ‘drupal’ tag

skinet.com

without comments

skiingmag.com

A network of sites for the mountain sport enthusiast. skinet.com offers high-quality content for everyone who is in love with snow. Both skimag.com and skiingmag.com were finished within two months and was built in Drupal.

Written by bensan

September 19th, 2009 at 8:45 pm

Posted in portfolio

Tagged with

Drupal bits: Migrating remote files in Drupal

with 3 comments

Recently I had to import a set of remote image files from another server but was not absolutely clear on how to get this done the Drupal way. I found the really came up with a solution of my own with drupal_http_request() which accepts an incoming URL and then executes a HTTP client request. The function returns the data and the response code.

[code lang="php"]$binary_image = drupal_http_request($url);[/code]

After checking the response code to make sure it was successful, use the Drupal function file_save_data() to physically store the file into whatever directory you want to store the image file in.

[code lang="php"]
if ($binary_image->code == 200) {
$filepath = file_save_data($binary_image->data, $save_to, FILE_EXISTS_RENAME);
if ($filepath !== 0) {
// attach other relevant information as well
$fileinfo['filepath'] = $filepath;
$fileinfo['filesize'] = filesize($save_to);
$fileinfo = array_merge($fileinfo, getimagesize($save_to));
return $fileinfo;
}
[/code]

The physical file should be saved but just because you’ve saved the file in the directory does not mean that Drupal is aware of the file. In order for that to happen, you also need the mime type, the file size, and the filepath and manually insert into a node. Once you’ve got those, you can create a node and insert those values along with the rest into it.

[code lang="php"]

// create a node
// add the file's information into the node
$node['field_thumbnail'] = array(
array(
'list' => 1,
'data' => array(
'alt' => '',
'title' => '',
),
'fid' => $fid,
'uid' => $user->uid,
'filename' => $resource['logo_file'],
'filepath' => 'files/_thumbnails/'.$resource['logo_file'],
'filemime' => $info['mime'],
'filesize' => $info['filesize'],
'status' => 1,
'timestamp' => time(),
'alt' => '',
'title' => '',
'upload' => '',
),
[/code]

This will make Drupal recognize your files. Everything should be gravy. Hope this works for you.

By the way, for all of you already on Drupal 7(lucky you), file_save_data() saves the data and automatically updates the database with the file information.

Written by bensan

June 27th, 2009 at 10:45 pm

Drupal Bits: Views 2 Relationships

without comments

In around 8 minutes, I understood the concept of Views 2 Relationships by watching this video. Relationships helps you connect relate (duh) nodes to other nodes. In short, it is probably most helpful to think about this as a SQL join.

Check out this video from drewish.com for the screencast:

http://drewish.com/node/127

Written by bensan

June 16th, 2009 at 5:56 pm

Posted in bensangeorge

Tagged with ,

The future of Drupal (as envisioned by Lullabot!)

without comments

Fascinating glimpse into an alternate view of the enriched UI experienced spearheaded by Lullabot. This is a separate project than the “offical” Drupal 7UX project. I am excited at the prospect of Drupal having a very friendly user experience. Enjoy!

project buzzr

Written by bensan

April 14th, 2009 at 1:36 am

Posted in software

Tagged with