atrsimilar.module

<?php
// $Id: atrsimilar.module,v 1.1.2.10 2009/10/07 00:35:06 xano Exp $

/**
 * @file
 *   Hook implementations and general funcions.
 */

/**
 * Implementation of hook_theme().
 */
function atrsimilar_theme() {
  return array(
    'atrsimilar_token_old' => array(
      'arguments' => array(
        'token' => array(),
      ),
      'file' => 'atrsimilar.result.inc',
      'path' => drupal_get_path('module', 'atrsimilar') . '/includes',
    ),
    'atrsimilar_token_new' => array(
      'arguments' => array(
        'token' => array(),
      ),
      'file' => 'atrsimilar.result.inc',
      'path' => drupal_get_path('module', 'atrsimilar') . '/includes',
    ),
  );
}

/**
 * Implementation of hook_atr_method_info().
 */
function atrsimilar_atr_method_info() {
  return array(
    'similar' => array(
      '#title' => t('Similarity review'),
      '#description' => t('Compare all texts to eachother and list all that are similar. To reduce the amount of different texts, similar ones can be merged. To reduce the amount of words, pieces of text that are often used within other texts may be split.'),
      '#result_callback' => array(
        '#callback' => 'atrsimilar_result',
        '#module' => 'atrsimilar',
        '#file' => 'includes/atrsimilar.result.inc',
      ),
      '#result_count_callback' => array(
        '#callback' => 'atrsimilar_result_count',
        '#module' => 'atrsimilar',
        '#file' => 'includes/atrsimilar.result.inc',
      ),
      '#review_callback' => array(
        'zxx' => array(
          '#callback' => 'atrsimilar_review',
          '#module' => 'atrsimilar',
          '#file' => 'includes/atrsimilar.review.inc',
        ),
      ),
    ),
  );
}

/**
 * Implementation of hook_form_FORM_ID_alter().
 */
function atrsimilar_form_atr_form_profile_alter(&$form, &$form_state) {
  $profile = $form['profile']['#value'];

  $form['#submit'][] = 'atrsimilar_atr_form_profile_submit';
  $percentages = range(0, 100);
  foreach ($percentages as &$percentage) {
    $percentage .= '%';
  }
  $form['similar']['settings']['similar_threshold'] = array(
    '#type' => 'select',
    '#title' => t('Threshold'),
    '#options' => $percentages,
    '#description' => t('How similar two texts should be to be considered entirely similar.'),
    '#default_value' => variable_get('atrsimilar_profile_' . $profile->pid . '_threshold', 90),
  );
  $form['similar']['settings']['similar_ignore'] = array(
    '#type' => 'textarea',
    '#title' => t('Ignore list'),
    '#description' => t('Any words or phrases that should be ignored during the similarity check. Put every word or phrase on a new line.'),
    '#default_value' => implode("\n", variable_get('atrsimilar_profile_' . $profile->pid . '_ignore', array())),
  );
}

/**
 * Implementation of hook_atr_profile_delete().
 */
function atrsimilar_atr_profile_delete($pid) {
  variable_del('atrsimilar_profile_' . $pid . '_threshold');
  variable_del('atrsimilar_profile_' . $pid . '_ignore');
}

/**
 * Implementation of hook_atr_review_delete().
 */
function atrsimilar_atr_review_delete($rid) {
  db_query("DELETE FROM {atrsimilar_string} WHERE sid_a IN (SELECT sid FROM {atr_string} s WHERE rid = %d)", $rid);
}

/**
 * Form submit handler for atr_form_profile().
 */
function atrsimilar_atr_form_profile_submit($form, &$form_state) {
  $values = $form_state['values'];
  $profile = $values['profile'];

  variable_set('atrsimilar_profile_' . $profile->pid . '_threshold', $values['similar_threshold']);
  variable_set('atrsimilar_profile_' . $profile->pid . '_ignore', preg_split("#[\r\n]+#", $values['similar_ignore']));
}