tripal.module 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578
  1. <?php
  2. /**
  3. * @file
  4. * The Tripal Core module
  5. */
  6. // Import the full Tripal API into scope.
  7. tripal_import_api();
  8. require_once "includes/tripal.field_storage.inc";
  9. require_once "includes/tripal.fields.inc";
  10. require_once "includes/tripal.entity.inc";
  11. require_once "includes/TripalVocab.inc";
  12. require_once "includes/TripalVocabController.inc";
  13. require_once "includes/TripalVocabViewsController.inc";
  14. require_once "includes/TripalTerm.inc";
  15. require_once "includes/TripalTermController.inc";
  16. require_once "includes/TripalTermViewsController.inc";
  17. require_once "includes/TripalEntity.inc";
  18. require_once "includes/TripalEntityController.inc";
  19. require_once "includes/TripalEntityUIController.inc";
  20. require_once "includes/TripalEntityViewsController.inc";
  21. require_once "includes/TripalBundle.inc";
  22. require_once "includes/TripalBundleController.inc";
  23. require_once "includes/TripalBundleUIController.inc";
  24. require_once "includes/TripalField.inc";
  25. require_once "includes/TripalFieldWidget.inc";
  26. require_once "includes/TripalFieldFormatter.inc";
  27. require_once "includes/TripalFieldQuery.inc";
  28. /**
  29. * @defgroup tripal Tripal Core Module
  30. * @ingroup tripal_modules
  31. * @{
  32. * Functionality useful for all other Tripal modules including the Tripal jobs, files,
  33. * materialized views and custom table functions.
  34. * @}
  35. */
  36. /**
  37. * Implements hook_views_api().
  38. */
  39. function tripal_views_api() {
  40. return array(
  41. 'api' => 3,
  42. );
  43. }
  44. /**
  45. * Implements hook_init().
  46. * Used to set the search_path, create default content and set default variables.
  47. *
  48. * @ingroup tripal
  49. */
  50. function tripal_init() {
  51. global $base_url;
  52. // add some variables for all javasript to use for building URLs
  53. $clean_urls = variable_get('clean_url', 0);
  54. $tripal_path = url(drupal_get_path('module', 'tripal'));
  55. drupal_add_js("
  56. var baseurl = '$base_url';
  57. var isClean = $clean_urls;
  58. var tripal_path = '$tripal_path';",
  59. 'inline', 'header');
  60. // make sure the date time settings are the way Tripal will insert them
  61. // otherwise PostgreSQL version that may have a different datestyle setting
  62. // will fail when inserting or updating a date column in a table.
  63. db_query("SET DATESTYLE TO :style", array(':style' => 'MDY'));
  64. }
  65. /**
  66. * Implements hook_menu().
  67. * Defines all menu items needed by Tripal Core
  68. *
  69. * @ingroup tripal
  70. */
  71. function tripal_menu() {
  72. $items = array();
  73. // Tripal setting groups
  74. $items['admin/tripal'] = array(
  75. 'title' => 'Tripal',
  76. 'description' => t("Manage the behavior or Tripal and its various modules."),
  77. 'weight' => -8,
  78. 'page callback' => 'system_admin_menu_block_page',
  79. 'access arguments' => array('administer tripal'),
  80. 'file' => 'system.admin.inc',
  81. 'file path' => drupal_get_path('module', 'system'),
  82. );
  83. $items['admin/tripal/tripal_jobs'] = array(
  84. 'title' => 'Jobs',
  85. 'description' => t('Provides tools for managing jobs submitted to Tripal. In some
  86. cases, long-running tasks are too slow to complete within a single
  87. browser session. The Tripal jobs system allows long-running tasks
  88. to be submitted to a queue that can be executed manually by the
  89. site admin or automatically using a module such as the ') .
  90. l('Tripal Daemon', 'https://www.drupal.org/project/tripal_daemon', array('attributes' => array('target' => '_blank'))) .
  91. ' extension module.',
  92. 'page callback' => 'tripal_jobs_admin_view',
  93. 'access arguments' => array('administer tripal'),
  94. 'type' => MENU_NORMAL_ITEM,
  95. 'weight' => 0,
  96. 'file' => 'includes/tripal.jobs.inc',
  97. 'file path' => drupal_get_path('module', 'tripal'),
  98. );
  99. $items['admin/tripal/storage'] = array(
  100. 'title' => 'Data Storage',
  101. 'description' => t("Tripal is designed to access biological
  102. data in any data storage back-end. A storage back-end must have a
  103. module that can be installed that interfaces with Tripal. By default
  104. the base Tripal package provides The Tripal Chado module for storing
  105. data in the GMOD Chado database schema. All available storage backends
  106. and their administrative tools are found here."),
  107. 'weight' => 8,
  108. 'access arguments' => array('administer tripal'),
  109. );
  110. $items['admin/tripal/terms'] = array(
  111. 'title' => 'Vocabularies',
  112. 'description' => t("Vocabulary terms are essential to creating content
  113. in Tripal. This allows data to be shared more easily with others
  114. using technologies such as the semantic web and web services.
  115. Before creating content you must have loaded vocabularies and their
  116. terms."),
  117. 'weight' => 8,
  118. 'access arguments' => array('administer tripal'),
  119. );
  120. $items['admin/tripal/terms/import'] = array(
  121. 'title' => 'Import Vocabulary',
  122. 'description' => t("Import vocabularies and terms in OBO format."),
  123. 'access arguments' => array('administer tripal'),
  124. 'page callback' => 'drupal_get_form',
  125. 'page arguments' => array('tripal_vocabulary_import_form'),
  126. 'file' => 'includes/tripal.admin.inc',
  127. 'file path' => drupal_get_path('module', 'tripal'),
  128. 'type' => MENU_NORMAL_ITEM,
  129. );
  130. $items['admin/tripal/extension'] = array(
  131. 'title' => 'Extensions',
  132. 'description' => t("Configuration and management pages for Tripal extension modules."),
  133. 'weight' => 8,
  134. 'access arguments' => array('administer tripal'),
  135. );
  136. // Menu items for facilitating import of extension modules.
  137. $items['admin/tripal/extension/available'] = array(
  138. 'title' => 'Available Extensions',
  139. 'description' => t('Look for extensions to add new functionality to this
  140. site. Tripal can be extended with new functionality developed
  141. by other Tripal site developers. These include modules with new or
  142. different functionality, bulk loading templates, or materialized
  143. views. Anyone can create new extensions and share those for
  144. others to use. Once shared they will appear in this list.'),
  145. 'access arguments' => array('administer tripal'),
  146. 'page callback' => 'drupal_get_form',
  147. 'page arguments' => array('tripal_extensions_form'),
  148. 'type' => MENU_NORMAL_ITEM,
  149. 'file' => 'includes/tripal.extensions.inc',
  150. 'file path' => drupal_get_path('module', 'tripal'),
  151. 'weight' => -100
  152. );
  153. // $items['admin/tripal/extension/import'] = array(
  154. // 'title' => 'Import Extensions',
  155. // 'description' => 'Provides a list of the available extensions that are registered at the tripal.info site. From this page you can easily import or install extensions to your site.',
  156. // 'page callback' => 'drupal_get_form',
  157. // 'page arguments' => array('tripal_extensions_form'),
  158. // 'access arguments' => array('administer tripal'),
  159. // 'type' => MENU_NORMAL_ITEM,
  160. // 'file' => 'includes/tripal.extensions.inc',
  161. // 'file path' => drupal_get_path('module', 'tripal'),
  162. // 'weight' => -100,
  163. // );
  164. /*
  165. $items['admin/tripal/setup/customize'] = array(
  166. 'title' => 'Customize Tripal',
  167. 'description' => t('Information on how to customize tripal'),
  168. 'page callback' => 'theme',
  169. 'page arguments' => array('tripal_customize'),
  170. 'access arguments' => array('administer tripal'),
  171. 'weight' => 10
  172. );
  173. */
  174. // Jobs Management
  175. $items['admin/tripal/tripal_jobs/help'] = array(
  176. 'title' => 'Help',
  177. 'description' => t('Help for the tripal job management system'),
  178. 'page callback' => 'theme',
  179. 'page arguments' => array('tripal_job_help'),
  180. 'access arguments' => array('administer tripal'),
  181. 'type' => MENU_LOCAL_TASK,
  182. 'weight' => 10
  183. );
  184. $items['admin/tripal/tripal_jobs/cancel/%'] = array(
  185. 'title' => 'Jobs',
  186. 'description' => t('Cancel a pending job'),
  187. 'page callback' => 'tripal_cancel_job',
  188. 'page arguments' => array(4),
  189. 'access arguments' => array('administer tripal'),
  190. 'type' => MENU_CALLBACK,
  191. );
  192. $items['admin/tripal/tripal_jobs/rerun/%'] = array(
  193. 'title' => 'Jobs',
  194. 'description' => t('Re-run an existing job.'),
  195. 'page callback' => 'tripal_rerun_job',
  196. 'page arguments' => array(4),
  197. 'access arguments' => array('administer tripal'),
  198. 'type' => MENU_CALLBACK,
  199. );
  200. $items['admin/tripal/tripal_jobs/view/%'] = array(
  201. 'title' => 'Jobs Details',
  202. 'description' => t('View job details.'),
  203. 'page callback' => 'tripal_jobs_view',
  204. 'page arguments' => array(4),
  205. 'access arguments' => array('administer tripal'),
  206. 'type' => MENU_CALLBACK,
  207. );
  208. $items['admin/tripal/tripal_jobs/views/jobs/enable'] = array(
  209. 'title' => 'Enable Jobs Administrative View',
  210. 'page callback' => 'tripal_enable_view',
  211. 'page arguments' => array('tripal_admin_jobs', 'admin/tripal/tripal_jobs'),
  212. 'access arguments' => array('administer tripal'),
  213. 'type' => MENU_CALLBACK,
  214. );
  215. /*
  216. * AJAX Callbacks.
  217. */
  218. $items['bio_data/ajax/field_attach/%'] = array(
  219. 'page callback' => 'tripal_ajax_attach_field',
  220. 'page arguments' => array(3),
  221. 'access arguments' => array('access content'),
  222. 'type' => MENU_CALLBACK,
  223. 'file' => 'includes/tripal.entity.inc',
  224. 'file path' => drupal_get_path('module', 'tripal'),
  225. );
  226. /*
  227. * Term Lookup
  228. */
  229. $items['cv/lookup'] = array(
  230. 'title' => 'Vocabulary Lookup',
  231. 'description' => t("Provides a tool to discover controlled vocabularies and their terms used by this site."),
  232. 'access arguments' => array('access content'),
  233. 'page callback' => 'drupal_get_form',
  234. 'page arguments' => array('tripal_vocabulary_lookup_form'),
  235. 'file' => 'includes/tripal.term_lookup.inc',
  236. 'file path' => drupal_get_path('module', 'tripal'),
  237. 'type' => MENU_NORMAL_ITEM,
  238. );
  239. $items['cv/lookup/%/%'] = array(
  240. 'title' => 'Vocabulary Lookup',
  241. 'description' => t("Provides a tool to discover controlled vocabularies and their terms used by this site."),
  242. 'access arguments' => array('access content'),
  243. 'page callback' => 'tripal_vocabulary_lookup_term_page',
  244. 'page arguments' => array(2, 3),
  245. 'file' => 'includes/tripal.term_lookup.inc',
  246. 'file path' => drupal_get_path('module', 'tripal'),
  247. 'type' => MENU_CALLBACK,
  248. );
  249. return $items;
  250. }
  251. /**
  252. * Implements hook_permission().
  253. */
  254. function tripal_permission() {
  255. return array(
  256. 'administer tripal' => array(
  257. 'title' => t('Administer Tripal'),
  258. 'description' => t('Allow the user to access administrative pages of Tripal.')
  259. ),
  260. 'view dev helps' => array(
  261. 'title' => t('View Developer Hints'),
  262. 'description' => t('Tripal will provide blue shaded boxes that provide
  263. instructions for how to customize or setup specific pages on a
  264. site. This permission should be enabled for developers. But can
  265. be disabled once developers are accustomed to these hints.'),
  266. 'restrict access' => TRUE,
  267. ),
  268. 'administer tripal data types' => array(
  269. 'title' => t('Administer Tripal data types'),
  270. 'description' => t('Create and delete fields for Tripal data types, and set their permissions.'),
  271. ),
  272. 'administer tripal data' => array(
  273. 'title' => t('Administer Tripal data'),
  274. 'description' => t('Edit and delete all tripal data'),
  275. ),
  276. 'administer controlled vocabularies' => array(
  277. 'title' => t('Administer controlled vocabularies (CVs).'),
  278. 'description' => t('Allow a user to add, edit and delete controlled vocabularies as well as add and edit terms.')
  279. ),
  280. );
  281. }
  282. /**
  283. * Implements hook_theme().
  284. * Registers template files/functions used by this module.
  285. *
  286. * @ingroup tripal
  287. */
  288. function tripal_theme($existing, $type, $theme, $path) {
  289. $themes = array(
  290. 'tripal_customize' => array(
  291. 'arguments' => array('job_id' => NULL),
  292. 'template' => 'tripal_customize',
  293. 'path' => "$path/theme/templates"
  294. ),
  295. 'theme_file_upload_combo' => array(
  296. 'render element' => 'element',
  297. ),
  298. 'theme_sequence_combo' => array(
  299. 'render element' => 'element',
  300. ),
  301. 'tripal_jobs_help' => array(
  302. 'template' => 'tripal_jobs_help',
  303. 'variables' => array(NULL),
  304. 'path' => "$path/theme/templates"
  305. ),
  306. 'tripal_customtables_help' => array(
  307. 'template' => 'tripal_customtables_help',
  308. 'variables' => array(NULL),
  309. 'path' => "$path/theme/templates"
  310. ),
  311. // Admin messages theme
  312. 'tripal_admin_message' => array(
  313. 'function' => 'theme_tripal_admin_message',
  314. 'variables' => array('message' => NULL),
  315. ),
  316. 'tripal_entity' => array(
  317. 'render element' => 'elements',
  318. 'template' => 'tripal_entity',
  319. 'path' => "$path/theme/templates"
  320. ),
  321. 'tripal_add_list' => array(
  322. 'variables' => array('content' => NULL),
  323. ),
  324. );
  325. return $themes;
  326. }
  327. /**
  328. * Implements hook_coder_ignore().
  329. * Defines the path to the file (tripal.coder_ignores.txt) where ignore rules for coder are stored
  330. */
  331. function tripal_coder_ignore() {
  332. return array(
  333. 'path' => drupal_get_path('module', 'tripal'),
  334. 'line prefix' => drupal_get_path('module', 'tripal'),
  335. );
  336. }
  337. /**
  338. * Implements hook_libraries_info().
  339. */
  340. function tripal_libraries_info() {
  341. $libraries = array();
  342. $libraries['d3'] = array(
  343. 'name' => 'D3.js',
  344. 'vendor url' => 'http://d3js.org/',
  345. 'download url' => 'https://github.com/mbostock/d3',
  346. 'version arguments' => array(
  347. 'file' => 'd3.js',
  348. 'pattern' => '/\s*version: "(\d+\.\d+\.\d+)"/',
  349. ),
  350. 'files' => array(
  351. 'js' => array(
  352. 'd3.min.js',
  353. ),
  354. ),
  355. );
  356. return $libraries;
  357. }
  358. /**
  359. * Implements hook_admin_paths().
  360. * Define administrative paths.
  361. */
  362. function tripal_admin_paths() {
  363. if (variable_get('node_admin_theme')) {
  364. $paths = array(
  365. 'bio_data/*/edit' => TRUE,
  366. 'bio_data/*/delete' => TRUE,
  367. 'bio_data/add' => TRUE,
  368. 'bio_data/add/*' => TRUE,
  369. );
  370. return $paths;
  371. }
  372. }
  373. /**
  374. * Implements hook_menu_local_tasks_alter().
  375. *
  376. * Used to add action links to pages.
  377. */
  378. function tripal_menu_local_tasks_alter(&$data, $router_item, $root_path) {
  379. // Add an "Add Tripal Content" action link to the Admin >> Content >>
  380. // Biological Content page.
  381. if ($root_path == 'admin/content/bio_data') {
  382. $item = menu_get_item('bio_data/add');
  383. if ($item['access']) {
  384. $data['actions']['output'][] = array(
  385. '#theme' => 'menu_local_action',
  386. '#link' => $item,
  387. );
  388. }
  389. }
  390. }
  391. /**
  392. * Implements hook_shortcut_default_set().
  393. * Modify the shortcut menu to include Biological content links.
  394. *
  395. * @param object $account
  396. * The user account whose default shortcut set will be returned. If not provided, the
  397. * function will return the currently logged-in user's default shortcut set.
  398. *
  399. * @return
  400. * An object representing the default shortcut set.
  401. */
  402. function tripal_shortcut_default_set($account) {
  403. $sets = shortcut_sets();
  404. $found = FALSE;
  405. foreach ($sets as $set) {
  406. if ($set->title == 'TripalDefault') {
  407. $found = TRUE;
  408. }
  409. }
  410. if (!$found) {
  411. $t = get_t();
  412. // Create an initial default shortcut set.
  413. $shortcut_set = new stdClass();
  414. $shortcut_set->title = $t('TripalDefault');
  415. $shortcut_set->links = array(
  416. array(
  417. 'link_path' => 'node/add',
  418. 'link_title' => $t('Add content'),
  419. 'weight' => -35,
  420. ),
  421. array(
  422. 'link_path' => 'bio_data/add',
  423. 'link_title' => 'Add Tripal Content',
  424. 'weight' => -30,
  425. ),
  426. array(
  427. 'link_path' => 'admin/content',
  428. 'link_title' => $t('Find content'),
  429. 'weight' => -25,
  430. ),
  431. array(
  432. 'link_path' => 'admin/content/bio_data',
  433. 'link_title' => 'Find Tripal Content',
  434. 'weight' => -20,
  435. ),
  436. );
  437. shortcut_set_save($shortcut_set);
  438. }
  439. $sets = shortcut_sets();
  440. foreach ($sets as $set) {
  441. if ($set->title == 'TripalDefault') {
  442. return $set->set_name;
  443. }
  444. }
  445. }
  446. /**
  447. * Menu argument loader; Load a tripal data type by string.
  448. *
  449. * This function is not meant to be used as an API function. It is only meant
  450. * for use in the menu to resolve the %tripal_bundle wildcard.
  451. *
  452. * @param $type
  453. * The machine-readable name of a tripal data type to load.
  454. * @return
  455. * A tripal data type array or FALSE if $type does not exist.
  456. */
  457. function TripalBundle_load($bundle_type, $reset = FALSE) {
  458. // Get the type of entity by the ID.
  459. $bundle = db_select('tripal_bundle', 'tdt')
  460. ->fields('tdt')
  461. ->condition('name', $bundle_type)
  462. ->execute()
  463. ->fetchObject();
  464. if ($bundle) {
  465. $entity = entity_load('TripalBundle', array($bundle->id), array(), $reset);
  466. return reset($entity);
  467. }
  468. return FALSE;
  469. }
  470. /**
  471. * Allows the menu system to use a wildcard to fetch the entity.
  472. *
  473. * Make sure that the wildcard you choose in the tripal_entity entity
  474. * definition fits the function name here.
  475. *
  476. * This function is not meant to be used as an API function. It is only meant
  477. * for use in the menu to resolve the %tripal_entity wildcard.
  478. *
  479. * @param $id
  480. * Integer specifying the tripal_entity id.
  481. * @param $reset
  482. * A boolean indicating that the internal cache should be reset.
  483. * @return
  484. * A fully-loaded $tripal_entity object or FALSE if it cannot be loaded.
  485. *
  486. * @see tripal_entity_load_multiple()
  487. */
  488. function TripalEntity_load($id, $reset = TRUE) {
  489. // $entity = entity_load('TripalEntity', array($id), array(), $reset);
  490. $entity = tripal_load_entity('TripalEntity', array($id), $reset);
  491. return reset($entity);
  492. }
  493. /**
  494. * Implements hook_menu_alter().
  495. */
  496. function tripal_menu_alter(&$items) {
  497. // We don't want to allow deletion of fields added by the storage backend.
  498. // TODO: this shouldn't be hardcoded here. These settings
  499. // should be part of the field and handled by the tripal_entity module.
  500. $items['admin/structure/bio_data/manage/%TripalBundle/fields/%field_ui_menu/delete']['page callback'] = 'tripal_field_no_delete';
  501. $items['admin/structure/bio_data/manage/%TripalBundle/fields/%field_ui_menu/delete']['page arguments'] = array();
  502. }
  503. /**
  504. * Imports all of the Tripal API into scope.
  505. *
  506. * Typically this function call is not necessary as all of the API is
  507. * automaticaly included by the tripal module. However this function can
  508. * be useful in the .install files during a site upgrade when the tripal
  509. * module is not enabld.
  510. *
  511. * Example usage:
  512. * @code
  513. * module_load_include('module', 'tripal', 'tripal');
  514. * tripal_import_api();
  515. * @endcode
  516. *
  517. */
  518. function tripal_import_api() {
  519. module_load_include('inc', 'tripal', 'api/tripal.d3js.api');
  520. module_load_include('inc', 'tripal', 'api/tripal.fields.api');
  521. module_load_include('inc', 'tripal', 'api/tripal.terms.api');
  522. module_load_include('inc', 'tripal', 'api/tripal.entities.api');
  523. module_load_include('inc', 'tripal', 'api/tripal.files.api');
  524. module_load_include('inc', 'tripal', 'api/tripal.jobs.api');
  525. module_load_include('inc', 'tripal', 'api/tripal.notice.api');
  526. module_load_include('inc', 'tripal', 'api/tripal.variables.api');
  527. }
  528. /**
  529. * Implements hook_form_alter().
  530. */
  531. function tripal_form_alter(&$form, $form_state, $form_id) {
  532. // If this i the field_ui_field_edit_form (i.e. the form that appears
  533. // when editing a field that is attached to an entity). Then we want
  534. // to add semantic web settings.
  535. if ($form_id == 'field_ui_field_edit_form') {
  536. tripal_field_instance_settings_form_alter($form, $form_state);
  537. }
  538. }