'Import APK', 'description' => 'Import APK packages', 'page callback' => 'apk_browser_import_apk', 'access arguments' => array('access apk browser'), ); $items['admin/config/apk_browser'] = array( 'title' => 'Package browser', 'description' => 'Configure package browser', 'page callback' => 'system_admin_menu_block_page', 'access arguments' => array('access apk browser'), //system_admin_menu_block_page needs admin inc 'file' => 'system.admin.inc', 'file path' => drupal_get_path('module', 'system'), ); $items['admin/config/apk_browser/settings'] = array( 'title' => 'Settings', 'description' => 'Configure global APK browser settings', 'page callback' => 'drupal_get_form', 'page arguments' => array('apk_browser_settings'), 'access arguments' => array('access apk browser'), ); $items['admin/config/apk_browser/repositories/add'] = array( 'title' => 'Add repository', 'description' => 'Add repositoriy', 'page callback' => 'drupal_get_form', 'page arguments' => array('apk_browser_repository_edit_form'), 'access arguments' => array('access apk browser'), ); $items['admin/config/apk_browser/repositories'] = array( 'title' => 'Repositories', 'description' => 'Configure APK repositories', 'page callback' => 'apk_browser_repositories_list', 'access arguments' => array('access apk browser'), ); return $items; } function apk_browser_permission() { return array( 'access apk browser' => array( 'title' => t('Access APK browser'), 'description' => t('Access permissions for APK browser'), ), ); } function apk_browser_settings($form) { $form['settings'] = array( '#type' => 'fieldset', '#title' => t('APK browser settings'), ); $form['settings']['apk_import_debug'] = array( '#type' => 'checkbox', '#title' => t('Import debugging'), '#description' => t('Write import debugging to watchdog'), '#default_value' => variable_get('apk_import_debug', '0') ); return system_settings_form($form); } /* * function apk_browser_settings_validate($form, &$form_state) { * if (!valid_url($form_state['values']['apk_repo_url'], TRUE)) { * form_set_error('apk_repo_url', t('Please specify a valid URL!')); * } * } */ function apk_browser_repository_edit_form($form, &$form_state) { $repo = taxonomy_vocabulary_machine_name_load('apk_repo'); $repo_tree = taxonomy_get_tree($repo->vid); $arch = taxonomy_vocabulary_machine_name_load('apk_arch'); $arch_tree = taxonomy_get_tree($arch->vid); if (empty($arch_tree) || empty($repo_tree)) { $form['warning'] = array( '#type' => 'item', '#markup' => '
Please add terms to you your repositories and architectures
' . l('Manage Taxonomy', 'admin/structure/taxonomy') ); } else { $form['settings'] = array( '#type' => 'fieldset', '#title' => t('Repository settings'), ); $form['settings']['apk_repo_url'] = array( '#type' => 'textfield', '#title' => t('Repository URL'), '#size' => '100', '#default_value' => '', '#description' => t('Link to the APKINDEX.tar.gz file inside the repository'), '#required' => TRUE, ); foreach ($repo_tree as $key => $term) { $repo_options[$term->tid] = $term->name; } //generate a form item to select terms $form['settings']['repo'] = array( '#type' => 'select', '#options' => $repo_options, '#title' => 'Select repository', '#description' => t('Please make sure you select the correct repository. Preventing to do so will break package listing') ); foreach ($arch_tree as $key => $term) { $arch_options[$term->tid] = $term->name; } $form['settings']['arch'] = array( '#type' => 'select', '#options' => $arch_options, '#title' => 'Select architecture', '#description' => t('Please make sure you select the correct architecture. Preventing to dox so will break package listing') ); $form['submit'] = array( '#type' => 'submit', '#value' => t('Add repository') ); } return $form; } function apk_browser_repository_edit_form_validate($form, &$form_state) { if (!valid_url($form_state['values']['apk_repo_url'], TRUE)) { form_set_error('apk_repo_url', t('Please specify a valid URL!')); } foreach (variable_get('apk_repositories', array()) as $repo) { if ($form_state['values']['apk_repo_url'] == $repo['url']) { form_set_error('apk_repo_url', t('You are trying to add a double url')); } } } function apk_browser_repository_edit_form_submit($form, &$form_state) { $repos[] = array( 'url' => $form_state['values']['apk_repo_url'], 'arch' => $form_state['values']['arch'], 'repo' => $form_state['values']['repo'] ); $current_repos = variable_get('apk_repositories', array()); //$result = (empty($current_repos)) ? $repos : array_merge($repos, $current_repos); variable_set('apk_repositories', array_merge($current_repos, $repos)); $form_state['redirect'] = 'admin/config/apk_browser/repositories'; drupal_set_message(t('Repositories are saved')); //drupal_set_message(t('Submitting values: @values', array('@values' => var_export($result, TRUE)))); } function apk_browser_repositories_list() { $terms = ''; $header = array('ID', 'URL', 'Repo', 'Arch', array('data' => 'Manage', 'colspan' => '2')); $add = l('', 'admin/config/apk_browser/repositories/add', array('html' => TRUE)); foreach (variable_get('apk_repositories', array()) as $key => $repo) { $edit = l('', 'somelink', array('html' => TRUE)); $delete = l('', 'somelink', array('html' => TRUE)); $terms = '