# HG changeset patch # User Franck Deroche # Date 1279543580 -7200 # Node ID fd5fb845d0bc71f0d3f3f6d28c748be6c29de380 # Parent 2a63a6e15166802ecd1751c015f4b8bc69bead8c Add an auto-import admin screen diff -r 2a63a6e15166 -r fd5fb845d0bc scald_dailymotion.admin.inc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scald_dailymotion.admin.inc Mon Jul 19 14:46:20 2010 +0200 @@ -0,0 +1,113 @@ + t('User'), 'tag' => t('Tag')); + if (count($imports)) { + $form['imports'] = array( + '#type' => 'fieldset', + '#title' => t('Current imports'), + '#tree' => TRUE, + '#theme' => 'scald_dailymotion_imports_table' + ); + foreach ($imports as $key => $import) { + $form['imports'][$key] = array( + 'type' => array( + '#type' => 'select', + '#title' => t('Type'), + '#options' => array('delete' => t('')) + $types, + '#default_value' => $import['type'] + ), + 'value' => array( + '#type' => 'textfield', + '#title' => t('Identifier'), + '#default_value' => $import['value'] + ), + ); + } + } + $form['add'] = array( + '#type' => 'fieldset', + '#title' => t('Add import'), + '#collapsible' => TRUE, + '#collapsed' => count($imports) + ); + $form['add']['type'] = array( + '#type' => 'select', + '#title' => t('Type'), + '#options' => $types, + ); + $form['add']['value'] = array( + '#type' => 'textfield', + '#title' => t('Identifier'), + '#description' => t('This field value meaning depends on the Type + field defined above. For a User import, put the username + whose videos you\'d loke to import here, for a tag import, use the + tag name.') + ); + $form['add']['submit'] = array( + '#type' => 'submit', + '#value' => t('Add this import'), + '#submit' => array('scald_dailymotion_imports_form_add') + ); + + $form['submit'] = array( + '#type' => 'submit', + '#value' => t('Save configuration') + ); + return $form; +} + +/** + * Handles the submission of the form that adds a new import. + */ +function scald_dailymotion_imports_form_add($form, &$form_state) { + $imports = variable_get('scald_dailymotion_imports', array()); + $values = $form_state['values']; + $key = $values['type'] . '-' . $values['value']; + $imports[$key] = array('type' => $values['type'], 'value' => $values['value']); + variable_set('scald_dailymotion_imports', $imports); + drupal_set_message(t('Import added')); +} + +/** + * Handles the submission of the whole form. + */ +function scald_dailymotion_imports_form_submit($form, &$form_state) { + drupal_set_message(t('The configuration options have been saved.')); + $imports = array(); + foreach ($form_state['values']['imports'] as $key => $import) { + if ($import['type'] != 'delete') { + $imports[$key] = $import; + } + } + variable_set('scald_dailymotion_imports', $imports); +} + +/** + * Themes the current imports form. + */ +function theme_scald_dailymotion_imports_table($form) { + $headers = array(t('Type'), t('Identifier')); + $rows = array(); + foreach (element_children($form) as $key) { + // Unset per widget titles, they're already in the column title + $form[$key]['type']['#title'] = $form[$key]['value']['#title'] = ''; + // Render our row + $row = array(); + $row[] = drupal_render($form[$key]['type']); + $row[] = drupal_render($form[$key]['value']); + // And add it to the list of table rows. + $rows[] = $row; + } + return theme('table', $headers, $rows); +} diff -r 2a63a6e15166 -r fd5fb845d0bc scald_dailymotion.module --- a/scald_dailymotion.module Mon Jul 19 14:45:25 2010 +0200 +++ b/scald_dailymotion.module Mon Jul 19 14:46:20 2010 +0200 @@ -1,4 +1,9 @@ array( 'arguments' => array('video' => NULL, 'thumbnail' => NULL), 'template' => 'scald_dailymotion_player' + ), + 'scald_dailymotion_imports_table' => array( + 'arguments' => array('form' => NULL), + 'file' => 'scald_dailymotion.admin.inc' ) ); } /** + * Implements hook_perm. + */ +function scald_dailymotion_perm() { + return array('administer dailymotion imports'); +} + +/** + * Implements hook_cron. + */ +function scald_dailymotion_cron() { + $imports = variable_get('scald_dailymotion_imports', array()); + foreach ($imports as $import) { + $items = scald_dailymotion_feed($import['type'], $import['value']); + foreach ($items as $item) { + scald_dailymotion_register($item); + } + } +} + +/** + * Implements hook_menu. + */ +function scald_dailymotion_menu() { + $items = array(); + $items['admin/settings/scald_dailymotion'] = array( + 'title' => 'DailyMotion imports', + 'page callback' => 'drupal_get_form', + 'page arguments' => array('scald_dailymotion_imports_form'), + 'access arguments' => array('administer dailymotion imports'), + 'description' => 'Configure the videos that should be automatically imported from DailyMotion', + 'file' => 'scald_dailymotion.admin.inc' + ); + return $items; +} + +/** * Creates an atom based on a DailyMotion video id or an object * containing the video informations.. * @param $video