123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228 |
- <?php
- function blast_ui_preprocess_show_blast_report(&$vars) {
-
- $path = drupal_get_path('module', 'blast_ui');
- drupal_add_css($path . '/theme/css/blast_report.css');
- drupal_add_js('https://code.jquery.com/jquery-1.12.4.min.js');
-
- $vars['blast_job'] = get_BLAST_job($vars['job_id']);
-
-
- $vars['blast_job']->blast_cmd = $vars['blast_job']->program;
- foreach($vars['blast_job']->options as $key => $value) {
- $vars['blast_job']->blast_cmd .= ' -' . $key. ' ' . $value ;
- }
-
-
- $vars['blast_form_url'] = 'blast/nucleotide/nucleotide';
- switch($vars['blast_job']->program) {
- case 'blastn':
- $vars['blast_form_url'] = 'blast/nucleotide/nucleotide';
- break;
- case 'blastx':
- $vars['blast_form_url'] = 'blast/nucleotide/protein';
- break;
- case 'tblastn':
- $vars['blast_form_url'] = 'blast/protein/nucleotide';
- break;
- case 'blastp':
- $vars['blast_form_url'] = 'blast/protein/protein';
- break;
- }
-
-
- $vars['xml'] = NULL;
- $full_path_xml = DRUPAL_ROOT . DIRECTORY_SEPARATOR . $vars['blast_job']->files->result->xml;
- if (is_readable($full_path_xml)) {
- $vars['xml'] = simplexml_load_file($full_path_xml);
- }
- }
- function blast_ui_theme_registry_alter(&$theme_registry) {
- $theme_registry_copy = $theme_registry;
- $module_path = drupal_get_path('module', 'blast_ui') . '/theme';
- _theme_process_registry($theme_registry_copy, 'phptemplate', 'theme_engine', 'my_custom_theme', $module_path);
- $theme_registry += array_diff_key($theme_registry_copy, $theme_registry);
-
- $hooks = array('page');
- foreach ($hooks as $hook) {
-
- if (!isset($theme_registry[$hook]['theme paths'])) {
- $theme_registry[$hook]['theme paths'] = array();
- }
-
- if (is_array($theme_registry[$hook]['theme paths'])) {
- $first_element = array_shift($theme_registry[$hook]['theme paths']);
- if ($first_element) {
- array_unshift($theme_registry[$hook]['theme paths'], $first_element, $module_path);
- }
- else {
- array_unshift($theme_registry[$hook]['theme paths'], $module_path);
- }
- }
- }
- }
- function blast_ui_make_secret($job_id) {
- $mapping = blast_ui_secret_mapping();
- $secret = str_replace(array_keys($mapping), $mapping, $job_id);
-
- return $secret;
- }
- function blast_ui_reveal_secret($secret) {
- $mapping = blast_ui_secret_mapping(TRUE);
- $job_id = str_replace(array_keys($mapping), $mapping, $secret);
-
-
- if (is_numeric($job_id)) {
- $exists = db_query('SELECT job_id FROM {tripal_jobs} WHERE job_id=:id', array(':id' => $job_id))->fetchField();
- if (!$exists) {
- tripal_report_error(
- 'blast_ui',
- TRIPAL_ERROR,
- 'Unable to decode the blast job_id from :id.',
- array(':id' => $secret)
- );
- }
- else {
- return $job_id;
- }
- }
-
- else {
- $job_id = base64_decode($secret);
- if (is_numeric($job_id)) {
- $exists = db_query('SELECT job_id FROM {tripal_jobs} WHERE job_id=:id', array(':id' => $job_id))->fetchField();
- if (!$exists) {
- tripal_report_error(
- 'blast_ui',
- TRIPAL_ERROR,
- 'Unable to decode the blast job_id from :id.',
- array(':id' => $secret)
- );
- }
- else {
- return $job_id;
- }
- }
- else {
- tripal_report_error(
- 'blast_ui',
- TRIPAL_ERROR,
- 'Unable to decode the blast job_id from :id.',
- array(':id' => $secret)
- );
- }
- }
-
- return FALSE;
- }
- function blast_ui_secret_mapping($reveal = FALSE) {
- $mapping = array(
- 1 => 'P',
- 2 => 'sA',
- 3 => 'b',
- 4 => 'Q',
- 5 => 'Hi',
- 6 => 'yt',
- 7 => 'f',
- 8 => 'zE',
- 9 => 'Km',
- 0 => 'jVo',
- );
-
-
-
-
-
-
-
-
-
- if (function_exists('private_make_mapping_ultra_secret')) {
- $mapping = private_make_mapping_ultra_secret($mapping);
- }
-
- if ($reveal) {
- return array_flip($mapping);
- }
- else {
- return $mapping;
- }
- }
- function blast_ui_test_secret_mapping($num_iterations = 10000) {
- $all_work = TRUE;
-
- for($i = 0; $i <= $num_iterations; $i++) {
- $job_id = mt_rand(0,100000);
-
- $secret = blast_ui_make_secret($job_id);
- $recovered_job_id = blast_ui_reveal_secret($secret);
-
- if ($job_id != $recovered_job_id) {
- drupal_set_message("Unable to recover job_id: $job_id; Secret: $secret.",'error');
- $all_work = FALSE;
- }
- }
-
- if ($all_work) {
- drupal_Set_message("Secret Mapping works over $num_iterations iterations with random integers.");
- }
-
- }
|