Commit 8c174608 authored by paul booker's avatar paul booker

First development release of Drupal 7

parent dce4709c
Name:
----
flickr http://drupal.org/project/flickr
flickr http://drupal.org/project/flickr
(Unfinished/Incomplete)
Requirements:
------------
This module requires Drupal 6.X and a Flickr API key.
This module requires Drupal 7.X and a Flickr API key.
Overview:
--------
......@@ -15,13 +15,12 @@ that you can enable as well.
Installation and configuration:
------------------------------
1.) Simply extract the download package in your modules directory '/modules'
or '/sites/all/modlues'.
2.) Enable the module in 'admin/build/modules/'.
3.) Configure the API Key '/admin/settings/flickr'.
4.) Add the flickr filter to one of your input formats by following
the configure link 'admin/settings/filters'.
5.) Allow permissions '/admin/user/access'.
1.) Simply extract the download package in your modules directory, e.g. '/sites/all/modules'.
2.) Enable the module in 'admin/modules'.
3.) Configure the API Key '/admin/config/media/flickr'.
4.) Add the flickr filter to one of your input formats by following
the configure link 'admin/config/content/formats'.
5.) Allow permissions '/admin/people/permissions'.
Usage:
------
......
; $Id$
name = Flickr Block
description = Flickr Block for inserting photos into content.
description = Adds capability to display Flickr photos and sets into blocks.
dependencies[] = flickr
package = Flickr
core = 6.x
core = 7.x
files[] = flickr_block.module
\ No newline at end of file
<?php
// $Id$
function flickr_block_uninstall() {
foreach (range(0, 6) as $delta) {
variable_del("flickr_block_{$delta}");
}
}
/**
* Move all the block settings into a single variable per block.
* @file
* The Flickr uninstall hook
*/
function flickr_block_update_1() {
function flickr_block_uninstall() {
foreach (range(0, 6) as $delta) {
$user = variable_get("flickr_block_{$delta}_user_id", FALSE);
$show = variable_get("flickr_block_{$delta}_show_n", FALSE);
$size = variable_get("flickr_block_{$delta}_size", FALSE);
if ($user || $show || $size) {
variable_set('flickr_block_'. $delta, array(
'user_id' => $user,
'show_n' => (int) $show,
'size' => $size,
));
}
variable_del("flickr_block_{$delta}_user_id");
variable_del("flickr_block_{$delta}_show_n");
variable_del("flickr_block_{$delta}_size");
variable_del("flickr_block_{$delta}");
}
return array();
}
......@@ -2,60 +2,65 @@
// $Id$
/**
* Implementation of hook_block().
* Implements hook_block_info().
*/
function flickr_block($op = 'list', $delta = 0, $edit = array()) {
switch ($op) {
case 'list':
// User base blocks
$blocks[0]['info'] = t("Flickr user page recent photos");
$blocks[1]['info'] = t("Flickr user page photosets");
$blocks[2]['info'] = t("Flickr user page random photos");
function flickr_block_info() {
// User base blocks
$blocks[0]['info'] = t("Flickr user page recent photos");
$blocks[1]['info'] = t("Flickr user page photosets");
$blocks[2]['info'] = t("Flickr user page random photos");
// Site wide blocks
$blocks[3]['info'] = t('Flickr recent photos');
$blocks[4]['info'] = t('Flickr recent photosets');
$blocks[5]['info'] = t('Flickr random photos');
$blocks[6]['info'] = t('Flickr group photos');
$blocks[7]['info'] = t('Flickr random photos from photoset');
return $blocks;
// Site wide blocks
$blocks[3]['info'] = t('Flickr recent photos');
$blocks[4]['info'] = t('Flickr recent photosets');
$blocks[5]['info'] = t('Flickr random photos');
$blocks[6]['info'] = t('Flickr group photos');
case 'configure':
$count_options = array(1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5', 6 => '6', 7 => '7', 8 => '8', 9 => '9', 10 => '10', 15 => '15', 20 => '20', 25 => '25', 30 => '30');
// remove the large and original sizes
$size_options = array();
foreach (flickr_photo_sizes() as $size => $info) {
$size_options[$size] = $info['label'] . ' - ' . $info['description'];
}
unset($size_options['b']);
unset($size_options['o']);
// Photoset blocks
$blocks[7]['info'] = t('Flickr random photo from photoset');
return $blocks;
}
$settings = variable_get('flickr_block_'. $delta, array('user_id' => '', 'show_n' => 4, 'size' => 's', 'photoset_id' => ''));
/**
* Implements hook_block_configure().
*/
function flickr_block_configure($delta = '') {
$count_options = array(1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5', 6 => '6', 7 => '7', 8 => '8', 9 => '9', 10 => '10', 15 => '15', 20 => '20', 25 => '25', 30 => '30');
// remove the large and original sizes
$size_options = array();
foreach (flickr_photo_sizes() as $size => $info) {
$size_options[$size] = $info['label'] . ' - ' . $info['description'];
}
unset($size_options['b']);
unset($size_options['o']);
$form = array();
$form["flickr_block_{$delta}_user_id"] = array(
'#type' => 'textfield',
'#title' => t('Flickr User ID'),
'#default_value' => $settings['user_id'],
'#description' => t("The user id of a Flickr user. If this is left blank, the site's default user will be used. Current default id is @default_id", array('@default_id' => variable_get('flickr_default_userid','')))
);
$form["flickr_block_{$delta}_show_n"] = array(
'#type' => 'select',
'#options' => $count_options,
'#title' => t('Show <em>n</em> photos'),
'#default_value' => $settings['show_n'],
'#description' => t("The block will display this many photos.")
);
$form["flickr_block_{$delta}_size"] = array(
'#type' => 'select',
'#options' => $size_options,
'#title' => t('Size of photos'),
'#default_value' => $settings['size'],
'#description' => t("Select the size of photos you'd like to display in the block.")
);
$settings = variable_get('flickr_block_' . $delta, array('user_id' => '', 'show_n' => 4, 'size' => 's', 'photoset_id' => ''));
switch ($delta) {
$form = array();
$form["flickr_block_{$delta}_user_id"] = array(
'#type' => 'textfield',
'#title' => t('Flickr User Id'),
'#default_value' => $settings['user_id'],
'#description' => t("The user id of a Flickr user. If this is left blank, the sites's default user will be used. Current default id is " . variable_get('flickr_default_userid', '')),
);
$form["flickr_block_{$delta}_show_n"] = array(
'#type' => 'select',
'#options' => $count_options,
'#title' => t('Show <em>n</em> photos'),
'#default_value' => $settings['show_n'],
'#description' => t("The block will display this many photos.")
);
$form["flickr_block_{$delta}_size"] = array(
'#type' => 'select',
'#options' => $size_options,
'#title' => t('Size of photos'),
'#default_value' => $settings['size'],
'#description' => t("Select the size of photos you'd like to display in the block.")
);
switch ($delta) {
case 0: // user page, recent
unset($form["flickr_block_{$delta}_user_id"]);
break;
......@@ -68,83 +73,93 @@ function flickr_block($op = 'list', $delta = 0, $edit = array()) {
case 2: // user page, random
unset($form["flickr_block_{$delta}_user_id"]);
break;
case 3: // sitewide, recent
break;
case 4: // sitewide photoset, not photos
case 4: // sitewite photoset, not photos
$form["flickr_block_{$delta}_show_n"]['#title'] = t('Show the last <em>n</em> photosets');
$form["flickr_block_{$delta}_show_n"]['#description'] = t("The block will show this many of the user's photosets.");
break;
case 5: // sitewide, random
break;
case 6: // sitewide, group
$form["flickr_block_{$delta}_user_id"]['#title'] = t('Flickr Group ID');
$form["flickr_block_{$delta}_user_id"]['#description'] = t('The block will show photos from this group');
$form["flickr_block_{$delta}_user_id"]['#title'] = t('Show photos from this Group ID');
$form["flickr_block_{$delta}_user_id"]['#description'] = t('Will select photos from this group pool');
$form["flickr_block_{$delta}_user_id"]['#required'] = TRUE;
break;
case 7: // sitewide, random
$form["flickr_block_{$delta}_photoset"] = array(
'#type' => 'textfield',
'#title' => t('Flickr Photoset ID'),
'#default_value' => $settings['photoset_id'],
'#description' => t("The id of a Flickr photoset."),
'#title' => t('Flickr Photoset Id'),
'#default_value' => $settings['photoset_id'],
'#description' => t("The id of a Flickr photoset."),
'#required' => TRUE,
);
break;
}
return $form;
case 'save':
}
return $form;
}
switch ($delta) {
/**
* Implements hook_block_save().
*/
function flickr_block_save($delta = '', $edit = array()) {
switch ($delta) {
case 0:
case 1:
case 2:
variable_set('flickr_block_'. $delta, array(
variable_set('flickr_block_' . $delta, array(
'show_n' => (int) $edit["flickr_block_{$delta}_show_n"],
'size' => $edit["flickr_block_{$delta}_size"],
));
break;
case 3:
case 4:
case 5:
case 6:
variable_set('flickr_block_'. $delta, array(
variable_set('flickr_block_' . $delta, array(
'user_id' => $edit["flickr_block_{$delta}_user_id"],
'show_n' => (int) $edit["flickr_block_{$delta}_show_n"],
'size' => $edit["flickr_block_{$delta}_size"],
));
break;
case 7:
variable_set('flickr_block_'. $delta, array(
'user_id' => $edit["flickr_block_{$delta}_user_id"],
'show_n' => (int) $edit["flickr_block_{$delta}_show_n"],
'size' => $edit["flickr_block_{$delta}_size"],
'photoset_id' => $edit["flickr_block_{$delta}_photoset"],
));
}
break;
case 7:
variable_set('flickr_block_' . $delta, array(
'user_id' => $edit["flickr_block_{$delta}_user_id"],
'show_n' => (int) $edit["flickr_block_{$delta}_show_n"],
'size' => $edit["flickr_block_{$delta}_size"],
'photoset_id' => $edit["flickr_block_{$delta}_photoset"],
));
break;
}
}
case 'view': default:
drupal_add_css(drupal_get_path('module', 'flickr') .'/flickr.css');
$settings = variable_get('flickr_block_' . $delta, array(
'user_id' => '',
'show_n' => 4,
'size' => 's',
));
// Get the default user id as a fallback
if ($settings['user_id'] == "") {
$settings['user_id'] = variable_get('flickr_default_userid', ''); // TODO: better name would be flickr_default_identifier
}
$settings['user_id'] = flickr_user_find_by_identifier($settings['user_id']);
/**
* Implements hook_block_view().
*/
function flickr_block_view($delta = '') {
drupal_add_css(drupal_get_path('module', 'flickr') . '/flickr.css');
$settings = variable_get('flickr_block_' . $delta, array(
'user_id' => '',
'show_n' => 4,
'size' => 's',
));
$block = array();
// Get the default user id as a fallback
if (empty($settings['user_id'])) {
$settings['user_id'] = variable_get('flickr_default_userid');
}
$settings['user_id'] = flickr_user_find_by_identifier($settings['user_id']);
$block = array();
// Get per user nsid if necessary
if ($delta < 3) {
switch ($delta) {
case 0:
case 1:
case 2:
// Get per user nsid if necessary
if (arg(0) == 'user' && ($uid = (int) arg(1))) {
if ($user = user_load(array('uid' => $uid))) {
if ($user = user_load($uid)) {
if (!empty($user->flickr['nsid'])) {
if ($delta == 0) {
$block['subject'] = t("%username's recent Flickr photos", array('%username' => $user->name));
......@@ -161,37 +176,36 @@ function flickr_block($op = 'list', $delta = 0, $edit = array()) {
}
}
}
}
elseif ($delta == 3) {
break;
case 3:
$block['subject'] = t('Flickr recent photos');
$block['content'] = _flickr_block_recent($settings['user_id'], $settings['show_n'], $settings['size']);
}
elseif ($delta == 4) {
break;
case 4:
$block['subject'] = t('Flickr recent photosets');
$block['content'] = _flickr_block_photosets($settings['user_id'], $settings['show_n'], $settings['size']);
}
elseif ($delta == 5) {
break;
case 5:
$block['subject'] = t('Flickr random photos');
$block['content'] = _flickr_block_random($settings['user_id'], $settings['show_n'], $settings['size']);
}
elseif ($delta == 6) {
break;
case 6:
$block['subject'] = t('Flickr Group photos');
$block['content'] = _flickr_block_group_recent($settings['user_id'], $settings['show_n'], $settings['size']);
}
elseif ($delta == 7) {
break;
case 7:
$block['subject'] = t('Flickr random photoset photos');
$block['content'] = _flickr_block_photoset_random($settings['user_id'], $settings['show_n'], $settings['size'], $settings['photoset_id']);
}
return $block;
break;
}
}
return $block;
}
function _flickr_block_recent($nsid, $show_n, $size) {
$output = '';
if ($photos = flickr_photos_search($nsid, 1, array('per_page' => $show_n))) {
foreach ($photos['photo'] as $photo) {
$output .= theme('flickr_block_photo
', $photo, $size);
$output .= theme('flickr_block_photo', array('photo' => $photo, 'size' => $size));
}
}
return $output;
......@@ -202,7 +216,7 @@ function _flickr_block_photosets($nsid, $show_n, $size) {
$output = '';
$to = min($show_n, count($photosets));
for ($i = 0; $i < $to; $i++) {
$output .= theme('flickr_block_photoset', $photosets[$i], $nsid, $size);
$output .= theme('flickr_block_photoset', array('photoset' => $photosets[$i], 'owner' => $nsid, 'size' => $size));
}
return $output;
}
......@@ -227,7 +241,7 @@ function _flickr_block_random($nsid, $show_n, $size) {
}
else {
$random_photos[] = $photo_id;
$output .= theme('flickr_block_photo', $photos['photo'][$index], $size);
$output .= theme('flickr_block_photo', array('photo' => $photos['photo'][$index], 'size' => $size));
}
}
}
......@@ -241,8 +255,14 @@ function _flickr_block_photoset_random($nsid, $show_n, $size, $photoset_id) {
return;
}
$repsonse = flickr_photoset_get_photos($photoset_id);
// Get a list of "all" the photos in the photoset. This is cached.
$response = flickr_request('flickr.photosets.getPhotos',
array(
'photoset_id' => $photoset_id,
'per_page' => 500, // get as many images as possible
'extras' => 'owner',
)
);
if (!$response) {
return;
}
......@@ -257,7 +277,7 @@ function _flickr_block_photoset_random($nsid, $show_n, $size, $photoset_id) {
for ($i = 0; $i < $to; $i++) {
//insert owner into $photo because theme_flickr_photo needs it
$photos[$i]['owner'] = $info['owner'];
$output .= theme('flickr_block_photo', $photos[$i], $size);
$output .= theme('flickr_block_photo', array('photo' => $photos[$i], 'size' => $size));
}
return $output;
}
......@@ -265,34 +285,39 @@ function _flickr_block_photoset_random($nsid, $show_n, $size, $photoset_id) {
/*
* This renders a block with photos from the selected groupid
*/
function _flickr_block_group_recent($group_id, $show_n, $size) {
function _flickr_block_group_recent($groupid, $show_n, $size) {
$output = '';
if ($photos = flickr_get_group_photos($group_id, 1, array('per_page' => $show_n))) {
if ($photos = flickr_get_group_photos($groupid, 1, array('per_page' => $show_n))) {
foreach ($photos['photo'] as $photo) {
$output .= theme('flickr_block_photo', $photo, $size);
$output .= theme('flickr_block_photo', array('photo' => $photo, 'size' => $size));
}
}
return $output;
}
/**
* Implementation of hook_theme().
* Implements hook_theme().
*/
function flickr_block_theme() {
return array(
'flickr_block_photo' => array(
'arguments' => array('p', 'size' => NULL),
'variables' => array('photo', 'size' => NULL),
),
'flickr_block_photoset' => array(
'arguments' => array('ps', 'owner', 'size'),
'variables' => array('photoset', 'owner', 'size'),
),
);
}
function theme_flickr_block_photo($photo, $size = NULL) {
return theme('flickr_photo', $photo, $size);
function theme_flickr_block_photo($variables) {
$photo = $variables['photo'];
$size = $variables['size'];
return theme('flickr_photo', array('photo' => $photo, 'size' => $size));
}
function theme_flickr_block_photoset($photoset, $owner, $size) {
return theme('flickr_photoset', $photoset, $owner, $size);
function theme_flickr_block_photoset($variables) {
$photoset = $variables['photoset'];
$owner = $variables['owner'];
$size = $variables['size'];
return theme('flickr_photoset', array('photoset' => $photoset, 'owner' => $owner, 'size' => $size));
}
; $Id$
name = Flickr Filter
description = Flickr Filter for inserting photos into content.
description = Adds a filter to insert Flickr photos and sets into content.
dependencies[] = flickr
package = Flickr
core = 6.x
core = 7.x
files[] = flickr_filter.module
\ No newline at end of file
<?php
// $Id$
require_once(drupal_get_path('module', 'flickr') .'/flickr.inc');
require_once(drupal_get_path('module', 'flickr') . '/flickr.inc');
function flickr_filter_tips($delta, $format, $long = FALSE) {
switch ($delta) {
case 0:
$output = t('Insert Flickr images: [flickr-photo:id=230452326,size=s] or [flickr-photoset:id=72157594262419167,size=m].');
if ($long) {
$output .= t('The size parameter can be one of the following:');
$items = array();
foreach (flickr_photo_sizes() as $key => $text) {
$items[] = "<code>$key</code> &mdash; (". $text['label'] .') '. $text['description'];
}
$output .= theme('item_list', $items);
}
return $output;
}
/**
* Implements hook_filter_info().
*/
function flickr_filter_info() {
$filters['filter_flickr'] = array(
'title' => t('Flickr linker'),
'description' => t('Allows you to Insert Flickr images: [flickr-photo:id=230452326,size=s] or [flickr-photoset:id=72157594262419167,size=m]'),
'process callback' => '_filter_flickr',
'tips callback' => '_filter_flickr_tips',
);
return $filters;
}
function flickr_filter($op, $delta = 0, $format = -1, $text = '') {
if ($op == 'list') {
return array(0 => t('Flickr linker'));
/**
* Returns the filter information for the filter help page
*/
function _filter_flickr_tips($filter, $format, $long = FALSE) {
$output = t('Insert Flickr images: [flickr-photo:id=230452326,size=s] or [flickr-photoset:id=72157594262419167,size=m].');
if ($long) {
$output .= ' ' . t('The size parameter can be one of the following:');
$items = array();
foreach (flickr_photo_sizes() as $key => $text) {
$items[] = "<code>$key</code> &mdash; (" . $text['label'] . ') ' . $text['description'];
}
$output .= theme('item_list', array('items' => $items));
}
return $output;
}
switch ($delta) {
case 0:
switch ($op) {
case 'description':
return t('Allows you to Insert Flickr images: [flickr-photo:id=230452326,size=s] or [flickr-photoset:id=72157594262419167,size=m]');
case 'no cache':
// TODO: only return true when testing the filter
// return TRUE;
return FALSE;
case 'prepare':
return $text;
case 'process':
$text = preg_replace_callback('/\[flickr-photo:(.+?)\]/', 'flickr_filter_callback_photo', $text);
$text = preg_replace_callback('/\[flickr-photoset:(.+?)\]/', 'flickr_filter_callback_photoset', $text);
return $text;
}
break;
}
/**
* Processes the flickr filter
*/
function _filter_flickr($text, $filter) {
$text = preg_replace_callback('/\[flickr-photo:(.+?)\]/', 'flickr_filter_callback_photo', $text);
$text = preg_replace_callback('/\[flickr-photoset:(.+?)\]/', 'flickr_filter_callback_photoset', $text);
return $text;
}
/**
......@@ -79,10 +73,9 @@ function flickr_filter_split_config($string) {
*/
function flickr_filter_callback_photo($matches) {
list($config, $attribs) = flickr_filter_split_config($matches[1]);
if (isset($config['id'])) {
if ($photo = flickr_photo_get_info($config['id'])) {
return theme('flickr_filter_photo', $photo, $config['size'], $attribs);
return theme('flickr_filter_photo', array('photo' => $photo, 'size' => $config['size'], 'attribs' => $attribs));
}
}
return '';
......@@ -96,30 +89,30 @@ function flickr_filter_callback_photoset($matches) {
if (isset($config['id'])) {
if ($photoset = flickr_photoset_get_info($config['id'])) {
return theme('flickr_filter_photoset', $photoset, $photoset['owner'], $config['size'], $attribs);
return theme('flickr_filter_photoset', array('photoset' => $photoset, 'owner' => $photoset['owner'], 'size' => $config['size'], 'attribs' => $attribs));
}
}
return '';
}
/**
* Implementation of hook_theme().
* Implements hook_theme().
*/
function flickr_filter_theme() {
return array(
'flickr_filter_photo' => array(
'arguments' => array('p', 'size', 'attribs'),
'variables' => array('photo', 'size', 'attribs'),
),
'flickr_filter_photoset' => array(
'arguments' => array('ps', 'owner', 'size', 'attribs'),
'variables' => array('photoset', 'owner', 'size', 'attribs'),
),