? .DS_Store
? .dat383d.253
? extraction_00.patch
? multiple_reviews_01.patch
? reviews.patch
? separate_modules_00.patch
? text_sources_00.patch
? text_sources_01.patch
? includes/.DS_Store
? modules/.DS_Store
? modules/atraspell
? modules/atrcode/.DS_Store
? modules/atrcode/includes/.DS_Store
? modules/atrpo/.DS_Store
? modules/atrpo/includes/.DS_Store
? modules/atrsimilar/.DS_Store
? modules/atrsimilar/includes/.DS_Store
Index: atr.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/atr/Attic/atr.module,v
retrieving revision 1.1.2.23
diff -u -p -r1.1.2.23 atr.module
--- atr.module 2 Aug 2009 21:29:55 -0000 1.1.2.23
+++ atr.module 18 Aug 2009 17:36:12 -0000
@@ -145,10 +145,17 @@ function atr_theme() {
'profile' => new stdclass(),
),
),
- 'atr_form_review' => array(
- 'arguments' => array(
- 'form' => array(),
- ),
+ );
+}
+
+/**
+ * Implementation of hook_elements().
+ */
+function atr_elements() {
+ return array(
+ 'atr_file' => array(
+ '#input' => TRUE,
+ '#process' => array('atr_file_process'),
),
);
}
@@ -287,15 +294,15 @@ function atr_callback_execute($callback)
}
/**
- * Check if the operating system supports CLI tar.
+ * Check if the operating system has an application installed.
*
* @return
* Boolean.
*/
-function atr_tar_exists() {
+function atr_app_exists($app) {
$code;
$output;
- exec('tar --help', $output, $code);
+ exec("which $app", $output, $code);
return $code == 0;
}
@@ -344,6 +351,10 @@ function atr_review_save($review) {
*/
function atr_review_load($rid) {
if ($review = db_fetch_object(db_query("SELECT * FROM {atr_review} WHERE rid = %d", $rid))) {
+ // TODO: Make sure titles are always set and remove this workaround.
+ if (!$review->title) {
+ $review->title = $review->rid;
+ }
$review->methods = array();
$result = db_query("SELECT method FROM {atr_review_method} WHERE rid = %d", $rid);
while ($method = db_result($result)) {
@@ -399,4 +410,63 @@ function atr_tmp_dir() {
watchdog('atr', "Automated Text Review has insufficient permissions to write to your system's temporary directory (%directory)", array('%directory' => sys_get_temp_dir()), WATCHDOG_ERROR);
return FALSE;
}
+}
+
+/**
+ * Form process handler for 'atr_file'.
+ */
+function atr_file_process($element, $form_state) {
+ $tar = atr_app_exists('tar') ? ' ' . t('!tar files are supported.', array('!tar' => '*.tar.gz
')) : NULL;
+ $element[$element['#name'] . '_online'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Online file'),
+ '#description' => t('The directory or file that needs to be reviewed. Files may be located on another website.') . $tar,
+ // We trigger validation for the entire 'atr_file' element through this
+ // textfield.
+ '#element_validate' => array('atr_file_validate'),
+ );
+ $element[$element['#name'] . '_upload'] = array(
+ '#type' => 'file',
+ '#title' => t('File upload'),
+ '#description' => $tar,
+ );
+ // Unset the wrapper element's type. Otherwise the child elements won't be rendered.
+ unset($element['#type']);
+
+ return $element;
+}
+
+/**
+ * Form validate handler for 'atr_file'.
+ */
+function atr_file_validate($element, &$form_state) {
+ $paths = array();
+ $parents = array_reverse($element['#array_parents']);
+ $parent = $parents[1];
+ // Process the online file.
+ // TODO: Throw an error if the path cannot be read.
+ if ($element['#value']) {
+ // Make sure the path doesn't start with a slash, but only ends with one.
+ $paths['online'] = trim($element['#value'], ' /');
+ // Check if the source is a directory.
+ if (strpos($paths['online'], '.', strrpos($paths['online'], '/')) === FALSE) {
+ $paths['online'] .= '/';
+ }
+ else {
+ module_load_include('inc', 'atr', 'includes/atr.extract');
+ atr_file_get($paths['online'], basename($paths['online']));
+ }
+ }
+ // Process the uploaded file.
+ if ($path_upload = $_FILES['files']['tmp_name'][$parent . '_upload']) {
+ $paths['upload'] = $path_upload;
+ module_load_include('inc', 'atr', 'includes/atr.extract');
+ atr_file_get($paths['upload'], $_FILES['files']['name'][$parent . '_upload']);
+ }
+
+ // Save the paths as the 'atr_file' element's value.
+ $atr_file_element = array(
+ '#parents' => array($parent),
+ );
+ form_set_value($atr_file_element, $paths, $form_state);
}
\ No newline at end of file
Index: css/atr.css
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/atr/css/Attic/atr.css,v
retrieving revision 1.1.2.4
diff -u -p -r1.1.2.4 atr.css
--- css/atr.css 14 Jun 2009 23:19:08 -0000 1.1.2.4
+++ css/atr.css 18 Aug 2009 17:36:12 -0000
@@ -1,6 +1,3 @@
-.atr-settings {
- margin-left: 25px;
-}
html ul.atr-locations li {
background: url(../images/file.png) left 4px no-repeat;
display: block;
Index: includes/atr.admin.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/atr/includes/Attic/atr.admin.inc,v
retrieving revision 1.1.2.24
diff -u -p -r1.1.2.24 atr.admin.inc
--- includes/atr.admin.inc 2 Aug 2009 21:29:55 -0000 1.1.2.24
+++ includes/atr.admin.inc 18 Aug 2009 17:36:12 -0000
@@ -14,74 +14,38 @@ function atr_form_review() {
drupal_add_css(drupal_get_path('module', 'atr') . '/css/atr.css');
$form = array(
- '#theme' => 'atr_form_review',
+ // The form may contain file uploads.
'#attributes' => array('enctype' => "multipart/form-data"),
);
- // Source selectors.
- $form['source'] = array(
- '#type' => 'radios',
- '#title' => t('Text source'),
- '#default_value' => 'online',
- '#options' => array(
- 'online' => t('Online file'),
- 'upload' => t('Local file'),
- ),
- '#attributes' => array(
- 'class' => 'atr-settings-toggle',
- ),
- );
- $tar = atr_tar_exists() ? t('!tar files are supported.', array('!tar' => '*.tar.gz
')) : NULL;
- $form['online'] = array(
- '#type' => 'textfield',
- '#title' => t('Path'),
- '#default_value' => variable_get('atr_source_online', ''),
- '#description' => t('The directory or file that needs to be reviewed. Files may be located on another website.') . ' ' . $tar,
- '#prefix' => '
',
- '#suffix' => '
',
- );
- $form['upload'] = array(
- '#type' => 'file',
- '#title' => t('File'),
- '#prefix' => '',
- '#suffix' => '
',
- );
+ // If certain conditions haven't been met, disable the submit button.
+ $disabled = FALSE;
- // File types selector.
- if (module_exists('potx')) {
- $form['file_types'] = array(
- '#type' => 'checkboxes',
- '#title' => t('File types to review'),
- '#options' => array(
- 'code' => t('Code files'),
- 'po' => t('Translations'),
- ),
- '#required' => TRUE,
- '#attributes' => array(
- 'class' => 'atr-settings-toggle',
- ),
- );
- $form['api_version'] = array(
- '#type' => 'select',
- '#title' => t('API version'),
- '#options' => array(
- 5 => 'Drupal 5',
- 6 => 'Drupal 6',
- 7 => 'Drupal 7',
- ),
- '#prefix' => '',
- '#suffix' => '
',
- );
+ // Source selector.
+ $source_info = module_invoke_all('atr_source_info');
+ if (count($source_info)) {
+ // Render a fieldset and checkbox for every text source.
+ foreach ($source_info as $name => $source) {
+ $form[$name] = array(
+ '#type' => 'fieldset',
+ '#title' => $source,
+ );
+ $form[$name][$name . '_toggle'] = array(
+ '#type' => 'checkbox',
+ '#title' => t('Extract texts from @text_source.', array('@text_source' => $source)),
+ '#attributes' => array(
+ 'class' => 'atr-settings-toggle',
+ ),
+ );
+ $form[$name]['settings'] = array(
+ '#prefix' => '',
+ '#suffix' => '
',
+ );
+ }
}
else {
- $form['file_types']['code'] = array(
- '#type' => 'value',
- '#value' => FALSE,
- );
- $form['file_types']['po'] = array(
- '#type' => 'value',
- '#value' => 'po',
- );
+ drupal_set_message(t('You have yet no text sources to use for this review. Please enable modules that provide them.', array('!modules' => url('admin/build/modules'))), 'warning');
+ $disabled = TRUE;
}
// Settings profile selector.
@@ -114,12 +78,13 @@ function atr_form_review() {
}
else {
drupal_set_message(t('You have yet no settings profile to use for this review.', array('@profile_add' => url('atr/profile/add'))), 'warning');
+ $disabled = TRUE;
}
$form['start'] = array(
'#type' => 'submit',
'#value' => t('Start review'),
- '#disabled' => $count == 0,
+ '#disabled' => $disabled,
);
return $form;
@@ -131,88 +96,34 @@ function atr_form_review() {
function atr_form_review_submit($form, &$form_state) {
global $atr_strings;
- $values = $form_state['values'];
-
- // Process the text source.
- module_load_include('inc', 'atr', 'includes/atr.extract');
- $source = $values['source'];
- if ($source == 'upload') {
- $path = $_FILES['files']['tmp_name']['upload'];
- $is_file = TRUE;
- }
- elseif($source == 'online') {
- $path = $values['online'];
- variable_set('atr_source_online', $path);
- // Make sure the path doesn't start with a slash, but only ends with one.
- $path = trim($path, ' /');
- // Check if the source is a directory.
- if (strpos($path, '.', strrpos($path, '/')) === FALSE) {
- $path .= '/';
- $is_file = FALSE;
- }
- else {
- $is_file = TRUE;
+ // Proceed with the review only if strings have been extracted (by other
+ // submit handlers).
+ if (count($atr_strings)) {
+ $profile = atr_profile_load((int) $form_state['values']['pid']);
+ $review = new ATRReview('', array_keys($profile->methods));
+
+ // Store the extracted strings.
+ module_load_include('inc', 'atr', 'includes/atr.extract');
+ atr_store($review->rid, $atr_strings);
+
+ // Save review statistics.
+ $review->string_count = count($atr_strings);
+ foreach (array_keys($atr_strings) as $string) {
+ $review->word_count += count(preg_split('#\s#', $string));
}
- }
- // We use $path for $review->title, but because untarring files changes $path,
- // we create the title here.
- $review_title = $is_file ? basename($path) : $path;
- // Untar *.tar.gz files.
- if (substr($path, -7) == '.tar.gz' && !atr_tar_extract($path)) {
- $path = FALSE;
- }
+ atr_review_save($review);
- // Proceed with the review only if the text source has been succesfully processed.
- if ($path) {
- // Extract strings.
- if ($values['file_types']['code']) {
- atr_extract_code($path, $values['api_version']);
- }
- if ($values['file_types']['code']) {
- atr_extract_po($path);
- }
-
- if (count($atr_strings)) {
- $profile = atr_profile_load((int) $values['pid']);
- $review = new ATRReview($review_title, array_keys($profile->methods));
-
- // Store the extracted strings.
- atr_filepath($atr_strings, $path);
- atr_store($review->rid, $atr_strings);
-
- // Save review statistics.
- $review->string_count = count($atr_strings);
- foreach (array_keys($atr_strings) as $string) {
- $review->word_count += count(preg_split('#\s#', $string));
- }
- atr_review_save($review);
-
- // Execute the actual review
- module_load_include('inc', 'atr', 'includes/atr.review');
- atr_review($review, $profile);
- drupal_set_message(t('The texts have been reviewed.') . ' ' . l(t('View results'), 'atr/review/' . $review->rid));
- }
- else {
- drupal_set_message(t('No texts have been found.'), 'warning');
- }
+ // Execute the actual review.
+ module_load_include('inc', 'atr', 'includes/atr.review');
+ atr_review($review, $profile);
+ drupal_set_message(t('The texts have been reviewed.') . ' ' . l(t('View results'), 'atr/review/' . $review->rid));
}
else {
- drupal_set_message(t('The texts have not been reviewed because the text source could not be read.'), 'error');
+ drupal_set_message(t('No texts have been found.'), 'warning');
}
}
/**
- * Form theme handler for atr_form_review().
- */
-function theme_atr_form_review($form) {
- $form['source']['online']['#suffix'] = drupal_render($form['online']);
- $form['source']['upload']['#suffix'] = drupal_render($form['upload']);
- $form['file_types']['code']['#suffix'] = drupal_render($form['api_version']);
-
- return drupal_render($form);
-}
-
-/**
* List all settings profiles.
*/
function atr_profile_list() {
Index: includes/atr.extract.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/atr/includes/Attic/atr.extract.inc,v
retrieving revision 1.1.2.11
diff -u -p -r1.1.2.11 atr.extract.inc
--- includes/atr.extract.inc 2 Aug 2009 21:29:55 -0000 1.1.2.11
+++ includes/atr.extract.inc 18 Aug 2009 17:36:12 -0000
@@ -7,132 +7,6 @@
*/
/**
- * Extract texts from code files.
- *
- * @param $path
- * The path to the code files.
- * @param $api_version
- * The verison of Drupal core the code is compatible with.
- */
-function atr_extract_code($path, $api_version) {
- module_load_include('inc', 'potx', 'potx');
- $versions = array(
- 5 => POTX_API_5,
- 6 => POTX_API_6,
- 7 => POTX_API_7,
- );
- potx_status('set', POTX_STATUS_SILENT);
- $code_files = _potx_explore_dir($path);
- foreach ($code_files as $code_file) {
- _potx_process_file($code_file, 0, '_atr_potx_save_string', '_atr_potx_save_version', $versions[$api_version]);
- }
-}
-
-/**
- * Default $save_callback of POTX' _potx_process_file(). Saves values to global
- * arrays to reduce memory consumption problems when passing around big chunks
- * of values.
- *
- * @param $string
- * The string that should be saved.
- * @param $file
- * The name of the file where the string was found.
- * @param $line
- * Line number where the string was found.
- * @param $string_mode
- * String mode: POTX_STRING_INSTALLER, POTX_STRING_RUNTIME
- * or POTX_STRING_BOTH.
- */
-function _atr_potx_save_string($string, $file, $line = 0, $string_mode = POTX_STRING_RUNTIME) {
- global $atr_strings;
-
- $atr_strings[$string][] = array(
- 'file' => $file,
- 'line' => $line,
- );
-}
-
-/**
- * Default $version_callback of POTX' _potx_process_file().
- *
- * @param $version
- * $file's CVS version number.
- * @param $file
- * Name of file where the version information was found.
- */
-function _atr_potx_save_version($version = NULL, $file = NULL) {
-}
-
-/**
- * Extract strings from *.po files.
- *
- * @param $path
- * The path to the *.po files.
- */
-function atr_extract_po($path) {
- $po_files = atr_po_files($path);
- foreach ($po_files as $po_file) {
- atr_po_file_process($po_file);
- }
-}
-
-/**
- * Find all *.po files in a certain directory.
- *
- * @param $path
- * The path from the Drupal root to the directory ATR should find strings in.
- * Leading slashes are illegal. A trailing slash is required.
- *
- * @return
- * An array containing all *.po files (path and file name).
- */
-function atr_po_files($path) {
- $files = glob($path . '*.po');
-
- // Grab subdirectories.
- $dirs = glob($path .'*', GLOB_ONLYDIR);
- if (is_array($dirs)) {
- foreach ($dirs as $dir) {
- if (!preg_match('#(^|.+/)(CVS|.svn|.git)$#', $dir)) {
- $files = array_merge($files, atr_po_files($dir . '/'));
- }
- }
- }
-
- return $files;
-}
-
-/**
- * Extract and save strings from a *.po file.
- *
- * @param $file
- * The *.po file to process.
- */
-function atr_po_file_process($filepath) {
- global $atr_strings;
-
- require_once './includes/locale.inc';
-
- // Locale takes Drupal file objects. We haven't uploaded a file, so we create
- // a dummy object with only required properties.
- $file = (object) array(
- 'filename' => basename($filepath),
- 'filepath' => $filepath,
- );
- _locale_import_read_po('mem-store', $file);
-
- $strings = _locale_import_one_string('mem-report');
- foreach ($strings as $msgid => $string) {
- if($msgid) {
- $atr_strings[$string][] = array(
- 'file' => $filepath,
- 'line' => 0,
- );
- }
- }
-}
-
-/**
* Store strings for a review.
*
* @param $rid
@@ -171,27 +45,40 @@ function atr_store($rid, $strings) {
}
/**
- * Get, extract and delete a *.tar.gz file.
+ * Extract and delete a *.tar.gz archive.
*
* @param $path
* The path to the file.
*/
-function atr_tar_extract(&$path) {
- if (atr_tar_exists() && $dir = atr_tmp_dir()) {
- // Get the file and store it locally.
- $dest = $dir . basename($path);
- $stream = fopen($path, 'r');
- file_put_contents($dest, $stream);
- fclose($stream);
- // Untar and remove the file.
- exec('tar xfz ' . $dest . ' -C ' . dirname($dest));
- unlink($dest);
- $path = dirname($dest);
+function atr_tar_extract($path) {
+ if (atr_app_exists('tar')) {
+ $dir = dirname($path);
+ exec('tar xfz ' . $path . ' -C ' . $dir);
+ unlink($path);
return TRUE;
}
- else {
- drupal_set_message(t('Could not extract the *.tar.gz file.'), 'error');
- return FALSE;
+
+ drupal_set_message(t('Could not extract the *.tar.gz file.'), 'error');
+ return FALSE;
+}
+
+/**
+ * Get a file and put it in a temporary directory.
+ *
+ * @param $path
+ * The path to the file.
+ * @param $filename
+ * The name of the file.
+ */
+function atr_file_get(&$path, $filename) {
+ if (is_file($path) && $dir = atr_tmp_dir()) {
+ $dest = "$dir/$filename";
+ $file = @fopen($path, 'rb');
+ file_put_contents($dest, $file);
+ if (substr($filename, -7) == '.tar.gz' && !atr_tar_extract($dest)) {
+ unset($path);
+ }
+ $path = $dir;
}
}
Index: modules/atrcode/atrcode.info
===================================================================
RCS file: modules/atrcode/atrcode.info
diff -N modules/atrcode/atrcode.info
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ modules/atrcode/atrcode.info 18 Aug 2009 17:36:12 -0000
@@ -0,0 +1,7 @@
+; $Id$
+name = Drupal code
+description = ATR text source. Allows Drupal code to be reviewed.
+dependencies[] = atr
+dependencies[] = potx
+package = Automated Text Review
+core = 6.x
\ No newline at end of file
Index: modules/atrcode/atrcode.module
===================================================================
RCS file: modules/atrcode/atrcode.module
diff -N modules/atrcode/atrcode.module
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ modules/atrcode/atrcode.module 18 Aug 2009 17:36:12 -0000
@@ -0,0 +1,50 @@
+ t('Drupal code files'),
+ );
+}
+
+/**
+ * Implementation of hook_form_FORM_ID_alter().
+ */
+function atrcode_form_atr_form_review_alter(&$form, &$form_state) {
+ array_unshift($form['#submit'], 'atrcode_atr_form_review_submit');
+ $form['atrcode']['settings']['atrcode_files'] = array(
+ '#type' => 'atr_file',
+ '#title' => t('Files'),
+ '#default_value' => NULL,
+ );
+ $form['atrcode']['settings']['atrcode_api_version'] = array(
+ '#type' => 'select',
+ '#title' => t('API version'),
+ '#options' => array(
+ 5 => 'Drupal 5',
+ 6 => 'Drupal 6',
+ 7 => 'Drupal 7',
+ ),
+ );
+}
+
+/**
+ * Form submit handler for atr_form_review().
+ */
+function atrcode_atr_form_review_submit($form, &$form_state) {
+ $values = $form_state['values'];
+ if ($values['atrcode_toggle']) {
+ module_load_include('inc', 'atrcode', 'includes/atrcode.extract');
+ foreach ($values['atrcode_files'] as $path) {
+ atrcode_extract($path, $values['atrcode_api_version']);
+ }
+ }
+}
\ No newline at end of file
Index: modules/atrcode/includes/atrcode.extract.inc
===================================================================
RCS file: modules/atrcode/includes/atrcode.extract.inc
diff -N modules/atrcode/includes/atrcode.extract.inc
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ modules/atrcode/includes/atrcode.extract.inc 18 Aug 2009 17:36:12 -0000
@@ -0,0 +1,69 @@
+ $file,
+ 'line' => $line,
+ );
+}
+
+/**
+ * Default $version_callback of POTX' _potx_process_file().
+ *
+ * @param $version
+ * $file's CVS version number.
+ * @param $file
+ * Name of file where the version information was found.
+ */
+function _atrcode_potx_save_version($version = NULL, $file = NULL) {
+}
\ No newline at end of file
Index: modules/atrpo/atrpo.info
===================================================================
RCS file: modules/atrpo/atrpo.info
diff -N modules/atrpo/atrpo.info
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ modules/atrpo/atrpo.info 18 Aug 2009 17:36:12 -0000
@@ -0,0 +1,6 @@
+; $Id$
+name = GNU gettext translations
+description = ATR text source. Allows GNU gettext translations (*.po files) to be reviewed.
+dependencies[] = atr
+package = Automated Text Review
+core = 6.x
\ No newline at end of file
Index: modules/atrpo/atrpo.module
===================================================================
RCS file: modules/atrpo/atrpo.module
diff -N modules/atrpo/atrpo.module
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ modules/atrpo/atrpo.module 18 Aug 2009 17:36:12 -0000
@@ -0,0 +1,41 @@
+ t('GNU gettext translations (*.po files)'),
+ );
+}
+
+/**
+ * Implementation of hook_form_FORM_ID_alter().
+ */
+function atrpo_form_atr_form_review_alter(&$form, &$form_state) {
+ array_unshift($form['#submit'], 'atrpo_atr_form_review_submit');
+ $form['atrpo']['settings']['atrpo_files'] = array(
+ '#type' => 'atr_file',
+ '#title' => t('Files'),
+ '#default_value' => NULL,
+ );
+}
+
+/**
+ * Form submit handler for atr_form_review().
+ */
+function atrpo_atr_form_review_submit($form, &$form_state) {
+ $values = $form_state['values'];
+ if ($values['atrpo_toggle']) {
+ module_load_include('inc', 'atrpo', 'includes/atrpo.extract');
+ foreach ($values['atrpo_files'] as $path) {
+ atrpo_extract($path);
+ }
+ }
+}
\ No newline at end of file
Index: modules/atrpo/includes/atrpo.extract.inc
===================================================================
RCS file: modules/atrpo/includes/atrpo.extract.inc
diff -N modules/atrpo/includes/atrpo.extract.inc
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ modules/atrpo/includes/atrpo.extract.inc 18 Aug 2009 17:36:12 -0000
@@ -0,0 +1,89 @@
+ basename($filepath),
+ 'filepath' => $filepath,
+ );
+ _locale_import_read_po('mem-store', $file);
+
+ $strings = _locale_import_one_string('mem-report');
+ foreach ($strings as $msgid => $string) {
+ if($msgid) {
+ // Locale converts singular and plural forms of the same string to arrays
+ // with two items.
+ foreach ((array) $string as $string) {
+ $atr_strings[$string][] = array(
+ 'file' => $filepath,
+ 'line' => 0,
+ );
+ }
+ }
+ }
+}
\ No newline at end of file