TRUE, 'user/*' => TRUE, ); } /** * Implements hook_admin_paths_alter(). * * A trick to enforce page refresh when theme is changed from an overlay. */ function drop_jobs_admin_paths_alter(&$paths) { $paths['admin/appearance/default*'] = FALSE; } /** * Set Drop Jobs as default install profile. * * Must use system as the hook module because drop_jobs is not active yet */ function system_form_install_select_profile_form_alter(&$form, $form_state) { foreach($form['profile'] as $key => $element) { $form['profile'][$key]['#value'] = 'drop_jobs'; } } /** * Implements hook_form_FORM_ID_alter(). * * Alter the site configuration form. */ function drop_jobs_form_install_configure_form_alter(&$form, $form_state) { // Many modules set messages during installation that are very annoying. // Yeah, we're looking at you Date and iToggle. // Let's clear these messages to avoid the false impression that something // went wrong when it didn't. drupal_get_messages('status'); drupal_get_messages('warning'); drupal_add_css(drupal_get_path('profile', 'drop_jobs') . '/drop_jobs_install.css'); // Warn about settings.php permissions risk $settings_dir = conf_path(); $settings_file = $settings_dir . '/settings.php'; // Check that $_POST is empty so we only show this message when the form is // first displayed, not on the next page after it is submitted. (We do not // want to repeat it multiple times because it is a general warning that is // not related to the rest of the installation process; it would also be // especially out of place on the last page of the installer, where it would // distract from the message that the Drupal installation has completed // successfully.) if (empty($_POST) && (!drupal_verify_install_file(DRUPAL_ROOT . '/' . $settings_file, FILE_EXIST | FILE_READABLE | FILE_NOT_WRITABLE) || !drupal_verify_install_file(DRUPAL_ROOT . '/' . $settings_dir, FILE_NOT_WRITABLE, 'dir'))) { drupal_set_message(st('All necessary changes to %dir and %file have been made, so you should remove write permissions to them now in order to avoid security risks. If you are unsure how to do so, consult the online handbook.', array('%dir' => $settings_dir, '%file' => $settings_file, '@handbook_url' => 'http://drupal.org/server-permissions')), 'warning'); } // Pre-populate some fields. $form['site_information']['site_name']['#default_value'] = 'Drop Jobs'; // We don't use t() intentionally. $form['site_information']['site_mail']['#default_value'] = 'admin@' . $_SERVER['HTTP_HOST']; $form['admin_account']['account']['name']['#default_value'] = 'admin'; $form['admin_account']['account']['mail']['#default_value'] = 'admin@' . $_SERVER['HTTP_HOST']; // Add checkbox for example content. $form['drop_jobs'] = array( '#type' => 'fieldset', '#collapsible' => FALSE, '#title' => t('Drop Jobs'), ); $form['drop_jobs']['drop_jobs_demo_content'] = array( '#type' => 'checkbox', '#title' => t('Install demo content'), '#description' => t('Check this option to enable demonstration content for Drop Jobs to get your site up and running quickly.'), '#default_value' => TRUE, ); // Add select box for search provider. $form['drop_jobs']['drop_jobs_search_provider'] = array( '#type' => 'select', '#title' => t('Search provider'), '#description' => t("Apache Solr is recommended but if you don't have it available, things will break!. You might be better off installing with Database search, getting a Solr instance up and running and then switching to Solr search later using the Drop Jobs settings page."), '#options' => drop_jobs_get_search_providers(), '#default_value' => 'drop_jobs_solr', ); // Add checkboxes for submodules. $form['drop_jobs']['drop_jobs_features'] = array( '#type' => 'fieldset', '#title' => t('Features'), '#description' => t('Enable additional Drop Jobs Features'), '#collapsible' => FALSE, '#tree' => TRUE, ); // Exclude core features. $exclude = drop_jobs_core_features(); // Demo module gets special treatment so exclude it from this list. $exclude[] = 'drop_jobs_demo'; // These are not so commonly used and get disabled by default. $disabled = array( 'drop_jobs_dev', ); // Add feature form items. foreach (drop_jobs_get_features() as $module => $info) { // Exclude certain modules. if (!in_array($module, $exclude)) { $form['drop_jobs']['drop_jobs_features'][$module] = array( '#type' => 'checkbox', '#title' => $info->info['name'], '#description' => $info->info['description'], '#default_value' => !in_array($module, $disabled), ); } } $form['#submit'][] = 'drop_jobs_install_configure_form_submit'; } /** * Submit callback. * * Installs Drop Jobs demonstration content. */ function drop_jobs_install_configure_form_submit(&$form, &$form_state) { // Alias for convenience. $values =& $form_state['values']; // Enable additional modules. if ($values['drop_jobs_features']) { $modules = array(); foreach ($values['drop_jobs_features'] as $module => $modulesd) { if ($modulesd) { $modules[] = $module; } } } // Enable search provider. $modules[] = $form_state['values']['drop_jobs_search_provider']; // Set variable to enable additional modules. variable_set('drop_jobs_install_extra_modules', $modules); // Set variable to install or not demo content. variable_set('drop_jobs_install_demo_content', $values['drop_jobs_demo_content']); // For whatever reason we can't rely on roles always being created in the // same order and receiving the same IDs, therefore find the role IDs and set // them as variables we'll use throughout. $employer_rid = reset( db_select('role', 'r') ->fields('r', array('rid')) ->condition('name', DROP_JOBS_TYPE_EMPLOYER, '=') ->execute() ->fetchCol()); variable_set('drop_jobs_role_employer', $employer_rid); $candidate_rid = reset( db_select('role', 'r') ->fields('r', array('rid')) ->condition('name', DROP_JOBS_TYPE_CANDIDATE, '=') ->execute() ->fetchCol()); variable_set('drop_jobs_role_candidate', $candidate_rid); $admin_rid = reset( db_select('role', 'r') ->fields('r', array('rid')) ->condition('name', 'administrator', '=') ->execute() ->fetchCol()); variable_set('drop_jobs_role_admin', $admin_rid); $webmaster_rid = reset( db_select('role', 'r') ->fields('r', array('rid')) ->condition('name', 'webmaster', '=') ->execute() ->fetchCol()); variable_set('drop_jobs_role_webmaster', $webmaster_rid); } /** * Implements hook_block_info(). */ function drop_jobs_block_info() { return array( 'powered-by' => array( 'info' => t('Powered by Drop Jobs'), 'weight' => '10', 'cache' => DRUPAL_CACHE_GLOBAL, ), ); } /** * Implements hook_block_view(). */ function drop_jobs_block_view($delta = '') { if ($delta === 'powered-by') { return array( 'subject' => NULL, 'content' => '' . t('Powered by Drop Jobs, a Drupal distribution by Alex and friends.', array('@drop_jobs' => 'http://drupal.org/project/drop_jobs', '@drupal' => 'http://drupal.org', '@alex' => 'http://alexweber.com.br', '@friends' => 'http://groups.drupal.org/drop-jobs-distribution')) . '', ); } } /** * Returns an array of Drop Jobs modules (features) that are considered "core". * * @return array * An array of the core modules' machine names. */ function drop_jobs_core_features() { $core_features = array( 'drop_jobs_admin', 'drop_jobs_core', 'drop_jobs_candidate', 'drop_jobs_employer', 'drop_jobs_job', 'drop_jobs_organization', ); // Allow list of core features to be altered. drupal_alter('drop_jobs_core_features', $core_features); return $core_features; } /** * Returns an array of Drop Jobs "Features" that can be turned on or off. * These are Drop Jobs submodules, excluding those considered to be "core" * by Drop Jobs or excluded by other modules. * * @return array * An array of available modules, keyed by machine name. */ function drop_jobs_get_features() { $core_features = drop_jobs_core_features(); // Add search providers to list of core features. $search_providers = array_keys(drop_jobs_get_search_providers()); $filtered_features = array_merge($core_features, $search_providers); // Build list of features. $features = array(); foreach (system_rebuild_module_data() as $module => $info) { if (strpos($module, 'drop_jobs_') === 0 && !in_array($module, $filtered_features)) { $features[$module] = $info; } } return $features; } /** * Returns a list of Drop Jobs Search providers that can be used. * * @return array * An array of available module names. */ function drop_jobs_get_search_providers() { $search_providers = &drupal_static(__FUNCTION__, NULL); if (!isset($search_providers)) { // Hard-coded because these are part of Drop Jobs Core. $search_providers = array( 'drop_jobs_db' => t('Database search'), 'drop_jobs_solr' => t('Apache Solr'), ); // Allow other modules to change this. drupal_alter('drop_jobs_search_providers', $search_providers); } return $search_providers; } /** * Returns the active Drop Jobs Search provider. */ function drop_jobs_search_provider() { $providers = drop_jobs_get_search_providers(); $modules = module_list(); return array_intersect($modules, array_keys($providers)); } /** * Implements hook_form_FORMID_alter(). * * Adds a checkbox for controlling field view access to certain fields added to * profiles and job nodes. */ function drop_jobs_form_field_ui_field_edit_form_alter(&$form, &$form_state) { if ($form['instance']['entity_type']['#value'] == 'profile2' || ($form['instance']['entity_type']['#value'] === 'node' && $form['instance']['bundle']['#value'] === 'job')) { // Add hidden field option. $form['field']['settings']['drop_jobs_hidden'] = array( '#type' => 'checkbox', '#title' => t('Make the content of this field hidden.'), '#default_value' => !empty($form['#field']['settings']['drop_jobs_hidden']), '#description' => t('If checked, the content of this field is only shown to administrators.'), ); // Change Profile2 private field description. if (isset($form['field']['settings']['profile2_private'])) { $form['field']['settings']['profile2_private']['#description'] = t('If checked, the content of this field is only shown to the profile owner, administrators and employers with active subscriptions.'); } } else { // Add the value to the form so it isn't lost. $form['field']['settings']['drop_jobs_hidden'] = array( '#type' => 'value', '#value' => !empty($form['#field']['settings']['drop_jobs_hidden']), ); } } /** * Implements hook_field_access(). */ function drop_jobs_field_access($op, $field, $entity_type, $entity = NULL, $account = NULL) { if ($op == 'view' && ($entity_type == 'profile2' || ($entity_type === 'node' && isset($entity) && $entity->type === 'job')) && !empty($field['settings']['drop_jobs_hidden']) && !user_access('administer drop_jobs', $account)) { return FALSE; } } /** * Determine whether a user has a particular role. * If no user is specified we use the current user. * * @param mixed * The role, can be either the numeric id or the machine name. * @param int * The user, if none is specified checks against the current user. * @return boolean * TRUE if the user has that role, FALSE otherwise. */ function drop_jobs_user_has_role($rid, $uid = NULL) { $user = user_uid_optional_load($uid); // Make sure we have a valid user object. if (is_object($user) && isset($user->roles) && is_array($user->roles)) { return (is_numeric($rid)) ? in_array($rid, array_keys($user->roles)) : in_array($rid, $user->roles); } return FALSE; }