'fieldset', '#title' => t('General'), '#collapsible' => TRUE, ); $form['general']['calais_store_rdf'] = array( '#type' => 'checkbox', '#title' => t('Store Calais RDF Locally'), '#default_value' => variable_get('calais_store_rdf', FALSE), '#description' => t('If checked, this will store the RDF data returned from Calais in the local RDF store. This data can be used to get a deeper view into the Calais results as the functionality is more fully developed. It also allows for future semantic applications to query and build upon this linked data, but it vastly increases the database size as there is a large amount of data saved. ENABLE THIS WITH CAUTION.'), ); calais_build_entity_settings($form); calais_build_nodetype_settings($form); $form = system_settings_form($form); $form['#submit'][] = 'calais_admin_settings_submit'; return $form; } /** * Build the Entity selector. Used for Entity suppression. */ function calais_build_entity_settings(&$form, $type = 'global', $name = 'Global', $allow_disable = FALSE) { $title = $name; $entities = array_keys(calais_get_entity_vocabularies()); sort($entities); $disabled = FALSE; if ($allow_disable) { $var_name = "calais_use_global_{$type}"; $disabled = variable_get($var_name, TRUE); $entity_options = array( TRUE => t('GLOBAL: use global setting from above'), FALSE => t("CUSTOM: pick the categories for this content type"), ); $form[$type][$var_name] = array( '#type' => 'radios', '#title' => t('Which tag categories (entities) do you want this type tagged with'), '#default_value' => $disabled, '#description' => t('Use the global settings specified above, or customize the tags applied for this content type.'), '#options' => $entity_options, '#attributes' => array('class' => "calais-use-global", 'data' => $type), ); $title = t('Customized categories for @name type', array('@name' => $name)); } $entity_attributes = array('class' => "calais-entity-settings-{$type}"); if ($disabled) { $entity_attributes['style'] = 'display:none'; } $form[$type]["calais_entity_settings_{$type}"] = array( '#type' => 'fieldset', '#title' => $title, '#attributes' => $entity_attributes, '#collapsible' => TRUE, '#collapsed' => !$allow_disable, ); $form[$type]["calais_entity_settings_{$type}"]["calais_applied_entities_{$type}"] = array( '#type' => 'checkboxes', '#title' => t('Which tag categories (entities) do you wish to use?'), '#default_value' => variable_get("calais_applied_entities_{$type}", $entities), '#options' => drupal_map_assoc($entities), '#description' => t('Choose which vocabularies should be included for term suggestions.'), ); } /** * Build the node type settings form for Calais integration. */ function calais_build_nodetype_settings(&$form) { node_types_rebuild(); $node_types = node_get_types('types', NULL, TRUE); $request_options = array( CALAIS_REQUEST_NO => t('NEVER: not processed by Calais'), CALAIS_REQUEST_MANUAL => t("MANUAL: initiate requests from the 'Calais' tab"), CALAIS_REQUEST_AUTO => t('AUTOMATIC: every time you save content'), ); $process_options = array( CALAIS_PROCESS_MANUAL => t('NEVER: suggest the terms, but let me tag the content'), CALAIS_PROCESS_AUTO_ONCE => t('ONCE: tag the content the first time I save'), CALAIS_PROCESS_AUTO => t('ALWAYS: tag the content on every save'), ); foreach ($node_types as $nt) { $key = drupal_strtolower($nt->type); $name = $nt->name; $form[$key] = array( '#type' => 'fieldset', '#title' => $name, '#collapsible' => TRUE, '#collapsed' => TRUE, '#nodetype' => $key, '#theme' => 'calais_nodetype_settings', ); $request = variable_get("calais_node_{$key}_request", CALAIS_REQUEST_NO); $form[$key]["calais_node_{$key}_request"] = array( '#type' => 'radios', '#parents' => array('calais_node_'. $key .'_request'), '#title' => t('Send Calais request'), '#default_value' => $request, '#options' => $request_options, '#attributes' => array('class' => "nodetype_toggle", 'data' => $key), ); $processing = variable_get("calais_node_{$key}_process", CALAIS_PROCESS_MANUAL); $form[$key]["calais_node_{$key}_process"] = array( '#type' => 'radios', '#parents' => array('calais_node_'. $key .'_process'), '#title' => t('Tag content'), '#default_value' => $processing, '#options' => $process_options, ); _calais_build_semanticproxy_config($form, $nt); $form[$key]["calais_threshold_{$key}"] = array( '#type' => 'textfield', '#size' => 5, '#title' => t('Minimum suggested tag relevancy'), '#default_value' => variable_get("calais_threshold_{$key}", 0.0), '#description' => t('Determine how relevant a term must be in order for Calais to suggest it for a particular node. Based on a 0.00-1.00 scale, with 0.00 being least relevant (i.e. many terms appear).'), ); calais_build_entity_settings($form, $key, $name, TRUE); } } /** * Configuration for Semantic Proxy integration. This will */ function _calais_build_semanticproxy_config(&$form, $node_type) { $spfields = array('' => "Don't process with SemanticProxy"); $docfields = array('' => "Don't store document text"); // If this content type is configured as a feed item if(module_exists('feedapi_node')) { $feed_types = feedapi_get_types(); foreach($feed_types as $type => $name) { $settings = feedapi_get_settings($type); if($settings['processors']['feedapi_node']['content_type'] == $node_type->type) { $spfields['calais_feedapi_node'] = t('Feed Item Original URL'); } } } if(module_exists('content')) { $content_type = content_types($node_type->type); $type_url_str = $content_type['url_str']; $fields = $content_type['fields']; if(is_array($fields) && !empty($fields)) { foreach($fields as $name => $field) { // Fields to submit to SemanticProxy if($field['type'] == 'link' || ($field['type'] == 'text' && $field['widget']['type'] == 'text_textfield')) { $spfields[$name] = $field['widget']['label'] . ' (' . $field['field_name'] . ')'; } // Fields to store document text if($field['type'] == 'text' && $field['widget']['type'] == 'text_textarea') { $docfields[$name] = $field['widget']['label'] . ' (' . $field['field_name'] . ')'; } } } } if(count($spfields) == 1) return; $key = drupal_strtolower($node_type->type); $form[$key]['semanticproxy'] = array( '#type' => 'fieldset', '#title' => t('Semantic Proxy'), '#collapsible' => TRUE, '#collapsed' => TRUE, ); $form[$key]['semanticproxy']["calais_semanticproxy_field_{$key}"] = array( '#type' => 'select', '#title' => t('Field that contains the URL to send to SemanticProxy'), '#options' => $spfields, '#default_value' => variable_get("calais_semanticproxy_field_{$key}", ''), '#description' => t('SemanticProxy submits the content of a URL to Calais for processing. You would use this if your content type is a node that has a short blurb/summary with the full content living on another site. This will ask SemanticProxy to get the contents of that URL and submit it to Calais for you. This field must contain a URL.'), ); $form[$key]['semanticproxy']["calais_semanticproxy_document_{$key}"] = array( '#type' => 'select', '#title' => t('Field to save document text from above URL'), '#options' => $docfields, '#default_value' => variable_get("calais_semanticproxy_document_{$key}", ''), '#description' => t('SemanticProxy submits the content at the above URL to Calais for processing. This is the field where you would like to save the document content that sent to Calais for processing. You can use this field to submit to to other services such as yahoo Terms, etc. You could use this field for display, but chances are it is not fit for presentation. You can hide this field from display !url', array('!url' => l('here', "admin/content/node-type/{$type_url_str}/display"))), ); } /** * Have to override so that we can manage vocabulary - node_type relationships. * This assumes the default submit handler (system_settings_form_submit) was already processed. * * @param $form_id * @param $form_state */ function calais_admin_settings_submit($form, &$form_state) { // Also, set vocabulary-node relationships $node_types = node_get_types('types', NULL, TRUE); $all_vocabularies = calais_get_entity_vocabularies(); foreach ($node_types as $nt) { $key = drupal_strtolower($nt->type); $request = calais_get_request_type($key); foreach ($all_vocabularies as $entity => $vid) { // Clean-up db_query("DELETE FROM {vocabulary_node_types} WHERE vid='%d' and type='%s'", $vid, $key); } if ($request != CALAIS_REQUEST_NO) { // assign all configured calais vocabs to this node type $node_vocabularies = calais_get_entity_vocabularies($key); if(!empty($node_vocabularies)) { foreach ($node_vocabularies as $entity => $vid) { db_query("INSERT INTO {vocabulary_node_types} (vid, type) values('%d','%s') ", $vid, $key); } } } } } /** * Theme function for nodetype settings. */ function theme_calais_nodetype_settings($form) { drupal_add_js(drupal_get_path("module", "calais") ."/calais.admin.js"); $type = $form['#nodetype']; $output = ''; $output .= drupal_render($form["calais_node_{$type}_request"]); $extra = $form["calais_node_{$type}_request"]['#value'] == CALAIS_REQUEST_NO ? "style='display:none;'" : ""; $output .= "