--- flickr.module.orig	2008-02-05 13:34:24.000000000 -0500
+++ flickr.module	2008-02-05 13:41:11.000000000 -0500
@@ -10,7 +10,7 @@ require_once(drupal_get_path('module', '
 function flickr_help($section) {
   switch ($section) {
     case 'admin/settings/flickr':
-     return t("You will need a Flickr API key to use this module. You can apply for one at <a href='@link'>@link</a>", array('@link' => url('http://www.flickr.com/services/api/keys/apply/')));
+     return t("You will need a Flickr API key to use this module. You can apply for one at <a href='@flickr-api-link'>@flickr-api-link</a> . To create a flickr entry click <a href='@flickr-entry-create'>here</a>", array('@flickr-api-link' => url('http://www.flickr.com/services/api/keys/apply/'),'@flickr-entry-create' => url('admin/flickr/entry/create')));
     case 'admin/help#flickr':
       return t('The flickr module uses XML-RPC to connect to Flickr\'s API and retreive photo information.');
   }
@@ -33,28 +33,66 @@ function flickr_menu($may_cache) {
 
   if ($may_cache) {
     $items[] = array(
+      'path' => 'admin/flickr', 
+      'title' => t('Flickr'),
+      'callback' => 'flickr_admin',
+      'access' => user_access('administer site configuration'),
+      'type' => MENU_NORMAL_ITEM,
+      'description' => t('Flickr entries.')
+    ); 
+    $items[] = array(
+      'path' => 'admin/flickr/entry/create',
+      'title' => t('Create a Flickr entry'),
+      'callback' => 'drupal_get_form',
+      'callback arguments' => array('flickr_admin_entry_create_form'),
+      'access' => user_access('administer site configuration'),
+      'type' => MENU_CALLBACK,
+      'description' => t('Create a Flickr entry.')
+    );
+    $items[] = array(
       'path' => 'admin/settings/flickr', 'title' => t('Flickr'),
       'callback' => 'drupal_get_form',
       'callback arguments' => array('flickr_admin_settings'),
       'access' => user_access('administer site configuration'),
       'type' => MENU_NORMAL_ITEM,
-      'description' => t('Change settings for the flickr module.'));
-
+      'description' => t('Change settings for the flickr module.')
+    );
     $items[] = array(
       'path' => 'flickr',
       'title' => t('Flickr photos'),
       'access' => TRUE,
       'type' => MENU_CALLBACK,
       'callback' => 'flickr_photos',
-      'description' => t('Flickr photos of default user id.'));
-
+      'description' => t('Flickr photos of default user id.')
+    );
     $items[] = array(
       'path' => 'flickr/auth',
       'access' => TRUE,
       'type' => MENU_CALLBACK,
-      'callback' => 'flickr_auth_callback');
+      'callback' => 'flickr_auth_callback'
+    );
   }
-  else {
+  else {	
+    if (arg(0) == 'admin' && arg(1) == 'flickr' && arg(2) == 'entry' && arg(3) == 'delete' && is_numeric(arg(4))) { 
+      $items[] = array(
+        'path' => 'admin/flickr/entry/delete/'. arg(4), 
+        'title' => t('Are you sure you want to delete this flickr entry?'),
+        'callback' => 'drupal_get_form',
+        'callback arguments' => array('flickr_admin_entry_delete_form', arg(4)),
+        'access' => user_access('administer site configuration'),
+        'type' => MENU_CALLBACK
+      );                       
+    }
+    if (arg(0) == 'admin' && arg(1) == 'flickr' && arg(2) == 'entry' && arg(3) == 'edit' && is_numeric(arg(4))) {
+      $items[] = array(
+        'path' => 'admin/flickr/entry/edit/'. arg(4), 
+        'title' => t('Edit a flickr entry.'),
+        'callback' => 'drupal_get_form',
+        'callback arguments' => array('flickr_admin_entry_edit_form', arg(4)),
+        'access' => user_access('administer site configuration'),
+        'type' => MENU_CALLBACK
+      );                       
+    }
     if (arg(0) == 'flickr' && is_numeric(arg(1)) && arg(1) > 0) {
       $account = user_load(array('uid' => arg(1)));
       if ($account !== FALSE && isset($account->flickr['nsid'])) {
@@ -121,10 +159,10 @@ function flickr_admin_settings() {
   $ageoptions = drupal_map_assoc($times, 'format_interval');
   $form['flickr_cache_duration'] = array(
     '#type' => 'select',
-    '#title' => t('Cache for'),
+    '#title' => t('Update interval'),
     '#options' => $ageoptions,
     '#default_value' => variable_get('flickr_cache_duration', 3600),
-    '#description' => t("Results from Flickr API requests will be cached for at least this long."),
+    '#description' => t("The refresh interval indicating how often you want to check cached Flickr API calls are up to date."),
   );
 
   // we need an api key before we can verify usernames
@@ -154,7 +192,7 @@ function flickr_admin_settings_validate(
     else {
       $user = flickr_user_find_by_username($uid);
       if (!$user) {
-        form_set_error('flickr_default_userid', t('%uid is not a Flickr user id and it does not appear to be a valid user name. Flickr reported %error-message', array('%uid' => $uid, '%error-message' => $response['message'])));
+        form_set_error('flickr_default_userid', t('%uid is not a Flickr user id and it does not appear to be a valid user name.', array('%uid' => $uid)));
       }
     }
   }
@@ -317,3 +355,180 @@ function theme_flickr_photoset($ps, $own
   return l($img, $photo_url, array('title' => $title), NULL, NULL, TRUE, TRUE);
 }
 
+function flickr_admin_entry_create_form() {
+  $form['#validate'] = array('flickr_admin_entry_create_form_validate' => array()); 
+  $form['flickr_entry_name'] = array(    
+    '#type' => 'textfield',
+    '#title' => t('Flickr entry name'),
+    '#required' => TRUE,
+    '#description' => t("Flickr entry name eg. Birthday party."),
+  );
+  $form['flickr_entry_tags'] = array(    
+    '#type' => 'textfield',
+    '#title' => t('Flickr tags'),
+    '#required' => FALSE,
+    '#description' => t("Flickr tags eg. birthday,party."),
+  );  
+  $form['flickr_entry_genre'] = array(
+    '#type' => 'radios',
+    '#title' => t('Flickr photos that are'),
+    '#default_value' => 're',
+    '#options' => array('re' =>'recently added','ra' =>'randomly selected'),
+    '#description' => t("Flickr photos that are recently added or randomly selected."),
+  );
+  $form['flickr_entry_scope'] = array(
+    '#type' => 'radios',
+    '#title' => t('Flickr photos that are'),
+    '#default_value' => 'all',
+    '#options' => array('all' =>'selected from all flickr accounts','you' =>'selected from an individual flickr account'),
+    '#description' => t("Flickr photos that are selected for all or individual accounts.")
+  );
+  $form['flickr_entry_submit'] = array(
+    '#type' => 'submit',
+    '#value' => t('Create an flickr entry'),
+  );
+  return $form ;
+}
+
+function flickr_admin_entry_create_form_submit($form_id, $form_values) {
+  $flickr_entries = variable_get('flickr_entries', array());
+  $flickr_entry  = array(
+    'name' => $form_values['flickr_entry_name'],  
+    'tags' => $form_values['flickr_entry_tags'],  
+    'genre' => $form_values['flickr_entry_genre'], 
+    'scope' => $form_values['flickr_entry_scope'], 
+  );
+  array_push($flickr_entries, $flickr_entry);
+  variable_set('flickr_entries', $flickr_entries);
+  drupal_set_message("Flickr entry <em>" . $form_values['flickr_entry_name'] . "</em> has been posted");
+  return 'admin/flickr';
+}
+
+function flickr_admin_entry_edit_form($flickr_entry) {
+  $flickr_entries = variable_get('flickr_entries', array());
+  $flickr_entries[$flickr_entry]['name'];	
+  $form['#validate'] = array('flickr_admin_update_entry_form_validate' => array()); 
+  $form['flickr_entry_name'] = array(    
+    '#type' => 'textfield',
+    '#default_value' => $flickr_entries[$flickr_entry]['name'],
+    '#title' => t('Flickr entry name'),
+    '#required' => TRUE,
+    '#description' => t("Flickr entry name eg. Birthday party."),
+  );
+  $form['flickr_entry_tags'] = array(    
+    '#type' => 'textfield',
+    '#default_value' => $flickr_entries[$flickr_entry]['tags'],
+    '#title' => t('Flickr tags'),
+    '#required' => FALSE,
+    '#description' => t("Flickr tags eg. birthday,party."),
+  );  
+  $form['flickr_entry_genre'] = array(
+    '#type' => 'radios',
+    '#title' => t('Flickr photos that are'),
+    '#default_value' => $flickr_entries[$flickr_entry]['genre'],
+    '#options' => array('re' =>'recently added','ra' =>'randomly selected'),
+    '#description' => t("Flickr photos that are recently added or randomly selected."),
+  );
+  $form['flickr_entry_scope'] = array(
+    '#type' => 'radios',
+    '#title' => t('Flickr photos that are'),
+    '#default_value' => $flickr_entries[$flickr_entry]['scope'],
+    '#options' => array('all' =>'selected from all flickr accounts','you' =>'selected from an individual flickr account'),
+    '#description' => t("Flickr photos that are  selected for all or individual accounts.")
+  );
+  $form['flickr_entry'] = array(
+    '#type' => 'hidden',
+    '#value' => $flickr_entry,
+  );
+  $form['flickr_entry_submit'] = array(
+    '#type' => 'submit',
+    '#value' => t('Edit flickr entry'),
+  );
+  return $form ;
+}
+
+function flickr_admin_entry_edit_form_submit($form_id, $form_values) { 
+  $key = $form_values['flickr_entry'];  
+  $flickr_entry  = array(
+    'name' => $form_values['flickr_entry_name'],
+    'tags' => $form_values['flickr_entry_tags'],
+    'genre' => $form_values['flickr_entry_genre'],
+    'scope' => $form_values['flickr_entry_scope'],
+  ); 
+  $flickr_entries = variable_get('flickr_entries', array());
+  $flickr_entries[$key] = $flickr_entry;
+  variable_set('flickr_entries', $flickr_entries);
+  drupal_set_message("Flickr entry <em>" . $form_values['flickr_entry_name'] . "</em> has been updated.");
+  return 'flickr/admin';
+}
+ 
+function flickr_admin_entries_form() {	
+  $form['flickr-admin-entries']['header'] = array('#type' => 'value', '#value' => array(
+    array('data' => t('Name')),
+    array('data' => t('Tags')),
+    array('data' => t('Select')),
+    array('data' => t('From')),
+    array('data' => t('Edit')),
+    array('data' => t('Delete'))
+  ));  
+  $flickr_entries = variable_get('flickr_entries', array()); 
+  foreach ($flickr_entries as $key=>$flickr_entry){
+    $form['flickr-admin-entries']['name'][$key] = array('#value' => $flickr_entry['name']);
+    $form['flickr-admin-entries']['tags'][$key] = array('#value' => $flickr_entry['tags']);
+    $form['flickr-admin-entries']['select'][$key] = array('#value' => $flickr_entry['genre'] == 're' ? 'recent' : 'at random');
+    $form['flickr-admin-entries']['from'][$key] = array('#value' => $flickr_entry['scope'] == 'you' ? 'your account' : 'all accounts' );
+    $form['flickr-admin-entries']['edit'][$key] = array('#value' => l('edit', "admin/flickr/entry/edit/".$key));
+    $form['flickr-admin-entries']['delete'][$key] = array('#value' => l('delete', "admin/flickr/entry/delete/".$key));
+  }	  
+  return $form['flickr-admin-entries']; 		
+}
+
+function theme_flickr_admin_entries_form($form) { 
+  if (isset($form['name']) && is_array($form['name'])) {
+    foreach (element_children($form['name']) as $key) {
+      $row = array();
+      $row[] = drupal_render($form['name'][$key]);
+      $row[] = drupal_render($form['tags'][$key]);
+      $row[] = drupal_render($form['select'][$key]);
+      $row[] = drupal_render($form['from'][$key]);
+      $row[] = drupal_render($form['edit'][$key]);
+      $row[] = drupal_render($form['delete'][$key]);      
+      $rows[] = $row;
+    }
+  }
+  else {
+    $rows[] = array(array('data' => t('No flickr entries'), 'colspan' => '6'));
+  }
+  $output .= theme('table', $form['header']['#value'], $rows, array(), t('Entries'));
+  if ($form['pager']['#value']) {
+    $output .= drupal_render($form['pager']);
+  }
+  $output .= drupal_render($form);
+  return $output;
+} 
+
+function flickr_admin_entry_delete_form($flickr_entry) { 
+  $flickr_entries = variable_get('flickr_entries', array());
+  $name = $flickr_entries[$flickr_entry]['name'];  
+  $form['flickr_entry'] = array('#type' => 'hidden', '#value' => $flickr_entry);   
+  $form['name'] = array('#type' => 'value', '#value' => $name);
+  return confirm_form($form, t('Are you sure you want to delete the flickr entry "%name" ?', array('%name' => $name)), 'admin/flickr', 'This action cannot be undone.', t('Confirm'), t('Cancel'));           
+}
+
+function flickr_admin_entry_delete_form_submit($form_id, $form_values) { 	
+  $flickr_entry = $form_values['flickr_entry']; 
+  $name = $form_values['name'];
+  $flickr_entries = variable_get('flickr_entries', array());
+  unset($flickr_entries[$flickr_entry]);
+  variable_set('flickr_entries', $flickr_entries);
+  db_query("DELETE FROM {blocks} WHERE module = 'flickr' AND delta = %d",  $flickr_entry);
+  cache_clear_all();
+  drupal_set_message(t('Flickr entry "%name" has been deleted', array('%name' => $name)));
+  return "admin/flickr";  
+}
+
+function flickr_admin() {
+  $output = l('Create a flickr entry', "admin/flickr/entry/create");
+  $output .= drupal_get_form('flickr_admin_entries_form');
+  return $output;
+}	
