tripal_core.module 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717
  1. <?php
  2. /**
  3. * @file
  4. * The Tripal Core module
  5. */
  6. /**
  7. * @defgroup tripal_core Tripal Core Module
  8. * @ingroup tripal_modules
  9. * @{
  10. * Functionality useful for all other Tripal modules including the Tripal jobs, files,
  11. * materialized views and custom table functions.
  12. * @}
  13. */
  14. // APPLICATION PROGRAMMER INTERFACE -------------
  15. // Chado API
  16. require_once 'api/tripal_core.chado_general.api.inc';
  17. require_once 'api/tripal_core.chado_query.api.inc';
  18. require_once 'api/tripal_core.chado_variables.api.inc';
  19. require_once 'api/tripal_core.chado_schema.api.inc';
  20. require_once 'api/tripal_core.chado_nodes.api.inc';
  21. require_once 'api/tripal_core.chado_nodes.properties.api.inc';
  22. require_once 'api/tripal_core.chado_nodes.dbxrefs.api.inc';
  23. require_once 'api/tripal_core.chado_nodes.relationships.api.inc';
  24. // Table API
  25. require_once 'api/tripal_core.custom_tables.api.inc';
  26. require_once 'api/tripal_core.mviews.api.inc';
  27. // Miscellaneous API
  28. require_once 'api/tripal_core.files.api.inc';
  29. require_once 'api/tripal_core.jobs.api.inc';
  30. require_once 'api/tripal_core.tripal.api.inc';
  31. require_once 'api/tripal_core.DEPRECATED.inc';
  32. // INCLUDES -------------------------------------
  33. require_once 'includes/jobs.inc';
  34. require_once 'includes/mviews.inc';
  35. require_once 'includes/custom_tables.inc';
  36. require_once 'includes/chado_install.inc';
  37. require_once 'includes/form_elements.inc';
  38. tripal_core_set_globals();
  39. /**
  40. * This function is used to set the global Chado variables
  41. *
  42. * @ingroup tripal_core
  43. */
  44. function tripal_core_set_globals() {
  45. // these global variables are meant to be accessed by all Tripal
  46. // modules to find the chado version installed and if Chado is local.
  47. // these variables are stored as globals rather than using the drupal_set_variable
  48. // functions because the Drupal functions make databaes queries and for long
  49. // running loaders we don't want those queries repeatedly.
  50. $GLOBALS["chado_is_installed"] = chado_is_installed();
  51. if ($GLOBALS["chado_is_installed"]) {
  52. $GLOBALS["chado_is_local"] = chado_is_local();
  53. $GLOBALS["chado_version"] = chado_get_version();
  54. $GLOBALS["exact_chado_version"] = chado_get_version(TRUE);
  55. }
  56. }
  57. /**
  58. * Implements hook_init().
  59. * Used to set the search_path, create default content and set default variables.
  60. *
  61. * @ingroup tripal_core
  62. */
  63. function tripal_core_init() {
  64. global $base_url;
  65. // create the 'tripal' controlled volcabulary in chado but only if it doesn't already exist, and
  66. // only if the chado database is present.
  67. if ($GLOBALS["chado_is_installed"]) {
  68. // if the Tripal cv is missing then add
  69. $results = chado_query("SELECT * FROM {cv} WHERE name = 'tripal'");
  70. $tripal_cv = $results->fetchObject();
  71. if (!$tripal_cv) {
  72. $results = chado_query(
  73. "INSERT INTO {cv} (name,definition) " .
  74. "VALUES ('tripal', 'Terms used by Tripal for modules to manage data such as that stored in property tables like featureprop, analysisprop, etc')"
  75. );
  76. }
  77. // if the Tripal db is missing then add it
  78. $results = chado_query("SELECT * FROM {db} WHERE name = 'tripal'");
  79. $tripal_db = $results->fetchObject();
  80. if (!$tripal_db) {
  81. $results = chado_query(
  82. "INSERT INTO {db} (name,description) " .
  83. "VALUES ('tripal', 'Used as a database placeholder for tripal defined objects such as tripal cvterms')"
  84. );
  85. }
  86. }
  87. // add some variables for all javasript to use for building URLs
  88. $theme_dir = drupal_get_path('theme', 'tripal');
  89. $clean_urls = variable_get('clean_url', 0);
  90. drupal_add_js(
  91. " var baseurl = '$base_url';
  92. var themedir = '$theme_dir';
  93. var isClean = $clean_urls;",
  94. 'inline', 'header');
  95. // make sure the date time settings are the way Tripal will insert them
  96. // otherwise PostgreSQL version that may have a different datestyle setting
  97. // will fail when inserting or updating a date column in a table.
  98. db_query("SET DATESTYLE TO :style", array(':style' => 'MDY'));
  99. // If we want AHAH elements on the node forms (e.g. chado_pub form) then we need to include
  100. // the node.pages file. Otherwise this error message is given:
  101. //
  102. // warning: call_user_func_array() expects parameter 1 to be a valid callback,
  103. // function 'node_form' not found or invalid function name
  104. // in /var/www/includes/form.inc on line 382.
  105. module_load_include('inc', 'node', 'node.pages');
  106. }
  107. /**
  108. * Implements hook_menu().
  109. * Defines all menu items needed by Tripal Core
  110. *
  111. * @ingroup tripal_core
  112. */
  113. function tripal_core_menu() {
  114. $items = array();
  115. // Triapl setting groups
  116. $items['admin/tripal'] = array(
  117. 'title' => 'Tripal',
  118. 'description' => "Manage the behavior or Tripal and its various modules.",
  119. 'weight' => -8,
  120. 'page callback' => 'system_admin_menu_block_page',
  121. 'access arguments' => array('administer tripal'),
  122. 'file' => 'system.admin.inc',
  123. 'file path' => drupal_get_path('module', 'system'),
  124. );
  125. $items['admin/tripal/schema'] = array(
  126. 'title' => 'Chado Schema',
  127. 'description' => "Tools to extend the chado schema through custom tables & materialized views.",
  128. 'weight' => -2,
  129. 'access arguments' => array('administer tripal'),
  130. );
  131. $items['admin/tripal/chado'] = array(
  132. 'title' => 'Chado Modules',
  133. 'description' => 'Configuration for specific chado data types such as Vocabularies, Features, etc.',
  134. 'access arguments' => array('administer tripal'),
  135. 'type' => MENU_NORMAL_ITEM,
  136. 'weight' => -6
  137. );
  138. $items['admin/tripal/loaders'] = array(
  139. 'title' => 'Chado Data Loaders',
  140. 'description' => 'Tools facilitating loading data into the chado database. Includes a generic tab-delimited loader (Bulk Loader).',
  141. 'access arguments' => array('administer tripal'),
  142. 'type' => MENU_NORMAL_ITEM,
  143. 'weight' => -4
  144. );
  145. $items['admin/tripal/extension'] = array(
  146. 'title' => 'Extension Modules',
  147. 'description' => 'Configuration for Tripal extension modules.',
  148. 'access arguments' => array('administer tripal'),
  149. 'type' => MENU_NORMAL_ITEM,
  150. 'weight' => 0
  151. );
  152. // Tripal Setup
  153. $items['admin/tripal/setup'] = array(
  154. 'title' => 'Setup Tripal',
  155. 'description' => 'Tools for initial setup of Tripal',
  156. 'access arguments' => array('administer tripal'),
  157. 'weight' => -8
  158. );
  159. $items['admin/tripal/setup/customize'] = array(
  160. 'title' => 'Customize Tripal',
  161. 'description' => 'Information on how to customize tripal',
  162. 'page callback' => 'theme',
  163. 'page arguments' => array('tripal_core_customize'),
  164. 'access arguments' => array('administer tripal'),
  165. 'weight' => 10
  166. );
  167. $items['admin/tripal/setup/chado_install'] = array(
  168. 'title' => 'Install Chado Schema',
  169. 'description' => 'Installs the Chado database tables, views, etc., inside the current Drupal database',
  170. 'page callback' => 'drupal_get_form',
  171. 'page arguments' => array('tripal_core_chado_load_form'),
  172. 'access arguments' => array('install chado'),
  173. 'type' => MENU_NORMAL_ITEM,
  174. 'weight' => -10
  175. );
  176. // Jobs Management
  177. $items['admin/tripal/tripal_jobs'] = array(
  178. 'title' => 'Jobs',
  179. 'description' => 'Jobs managed by Tripal',
  180. 'page callback' => 'tripal_jobs_admin_view',
  181. 'access arguments' => array('administer tripal'),
  182. 'type' => MENU_NORMAL_ITEM,
  183. 'weight' => -10
  184. );
  185. $items['admin/tripal/tripal_jobs/help'] = array(
  186. 'title' => 'Help',
  187. 'description' => 'Help for the tripal job management system',
  188. 'page callback' => 'theme',
  189. 'page arguments' => array('tripal_core_job_help'),
  190. 'access arguments' => array('administer tripal'),
  191. 'type' => MENU_LOCAL_TASK,
  192. 'weight' => 10
  193. );
  194. $items['admin/tripal/tripal_jobs/cancel/%'] = array(
  195. 'title' => 'Jobs',
  196. 'description' => 'Cancel a pending job',
  197. 'page callback' => 'tripal_cancel_job',
  198. 'page arguments' => array(4),
  199. 'access arguments' => array('administer tripal'),
  200. 'type' => MENU_CALLBACK,
  201. );
  202. $items['admin/tripal/tripal_jobs/rerun/%'] = array(
  203. 'title' => 'Jobs',
  204. 'description' => 'Re-run an existing job.',
  205. 'page callback' => 'tripal_rerun_job',
  206. 'page arguments' => array(4),
  207. 'access arguments' => array('administer tripal'),
  208. 'type' => MENU_CALLBACK,
  209. );
  210. $items['admin/tripal/tripal_jobs/view/%'] = array(
  211. 'title' => 'Jobs Details',
  212. 'description' => 'View job details.',
  213. 'page callback' => 'tripal_jobs_view',
  214. 'page arguments' => array(4),
  215. 'access arguments' => array('administer tripal'),
  216. 'type' => MENU_CALLBACK,
  217. );
  218. $items['admin/tripal/tripal_jobs/views/jobs/enable'] = array(
  219. 'title' => 'Enable Jobs Administrative View',
  220. 'page callback' => 'tripal_views_admin_enable_view',
  221. 'page arguments' => array('tripal_core_admin_jobs', 'admin/tripal/tripal_jobs'),
  222. 'access arguments' => array('administer tripal'),
  223. 'type' => MENU_CALLBACK,
  224. );
  225. // Materialized Views
  226. $items['admin/tripal/schema/mviews'] = array(
  227. 'title' => 'Materialized Views',
  228. 'description' => 'Materialized views are used to improve speed of large or complex queries.',
  229. 'page callback' => 'tripal_mview_admin_view',
  230. 'access arguments' => array('administer tripal'),
  231. 'type' => MENU_NORMAL_ITEM,
  232. 'weight' => -10
  233. );
  234. $items['admin/tripal/schema/mviews/help'] = array(
  235. 'title' => 'Help',
  236. 'description' => 'Help for the materialized views management system',
  237. 'page callback' => 'theme',
  238. 'page arguments' => array('tripal_core_mviews_help'),
  239. 'access arguments' => array('administer tripal'),
  240. 'type' => MENU_LOCAL_TASK,
  241. 'weight' => 10
  242. );
  243. /**
  244. $items['admin/tripal/schema/mviews/list'] = array(
  245. 'title' => 'List Materialized Views',
  246. 'description' => 'A list of existing materialized views with the ability to edit & delete existing materialized views.',
  247. 'page callback' => 'tripal_mviews_report',
  248. 'access arguments' => array('administer tripal'),
  249. 'type' => MENU_NORMAL_ITEM,
  250. 'weight' => -10
  251. );
  252. */
  253. $items['admin/tripal/schema/mviews/report/%'] = array(
  254. 'title' => 'Materialized View',
  255. 'description' => 'Materialized views are used to improve speed of large or complex queries. These are database views as compared to Drupal views.',
  256. 'page callback' => 'tripal_mview_report',
  257. 'page arguments' => array(5),
  258. 'access arguments' => array('administer tripal'),
  259. 'type' => MENU_CALLBACK,
  260. );
  261. $items['admin/tripal/schema/mviews/new'] = array(
  262. 'title' => 'Create Materialized View',
  263. 'description' => 'Create a new materialized view.',
  264. 'page callback' => 'drupal_get_form',
  265. 'page arguments' => array('tripal_mviews_form'),
  266. 'access arguments' => array('administer tripal'),
  267. 'type' => MENU_CALLBACK,
  268. );
  269. $items['admin/tripal/schema/mviews/edit/%'] = array(
  270. 'title' => 'Edit Materialized View',
  271. 'page callback' => 'drupal_get_form',
  272. 'page arguments' => array('tripal_mviews_form', 5),
  273. 'access arguments' => array('administer tripal'),
  274. 'type' => MENU_CALLBACK,
  275. );
  276. $items['admin/tripal/schema/mviews/action/update/%'] = array(
  277. 'title' => 'Create Materialized View',
  278. 'description' => 'Materialized views are used to improve speed of large or complex queries.',
  279. 'page callback' => 'tripal_add_populate_mview',
  280. 'page arguments' => array(6, "1"),
  281. 'access arguments' => array('administer tripal'),
  282. 'type' => MENU_CALLBACK,
  283. );
  284. $items['admin/tripal/schema/mviews/action/delete/%'] = array(
  285. 'title' => 'Create Materialized View',
  286. 'description' => 'Materialized views are used to improve speed of large or complex queries.',
  287. 'page callback' => 'tripal_delete_mview',
  288. 'page arguments' => array(6, "1"),
  289. 'access arguments' => array('administer tripal'),
  290. 'type' => MENU_CALLBACK,
  291. );
  292. // Custom Tables
  293. $items['admin/tripal/schema/custom_tables'] = array(
  294. 'title' => 'Custom Tables',
  295. 'description' => 'Creation of custom tables that are added to Chado database.',
  296. 'page callback' => 'tripal_custom_table_admin_view',
  297. 'access arguments' => array('administer tripal'),
  298. 'type' => MENU_NORMAL_ITEM,
  299. 'weight' => -10
  300. );
  301. $items['admin/tripal/schema/custom_tables/help'] = array(
  302. 'title' => 'Help',
  303. 'description' => 'Help for the tripal job management system',
  304. 'page callback' => 'theme',
  305. 'page arguments' => array('tripal_core_job_help'),
  306. 'access arguments' => array('administer tripal'),
  307. 'type' => MENU_LOCAL_TASK,
  308. 'weight' => 10
  309. );
  310. /**
  311. $items['admin/tripal/schema/custom_tables/list'] = array(
  312. 'title' => 'List of Custom Tables',
  313. 'description' => 'Provides a list of all custom tables created by Tripal and allows for editing or removing existing custom tables.',
  314. 'page callback' => 'tripal_custom_tables_list',
  315. 'access arguments' => array('administer tripal'),
  316. 'type' => MENU_NORMAL_ITEM,
  317. 'weight' => -10
  318. );
  319. */
  320. $items['admin/tripal/schema/custom_tables/view/%'] = array(
  321. 'title' => 'Custom Tables',
  322. 'description' => 'Custom tables are added to Chado.',
  323. 'page callback' => 'tripal_custom_table_view',
  324. 'page arguments' => array(4),
  325. 'access arguments' => array('administer tripal'),
  326. 'type' => MENU_CALLBACK,
  327. );
  328. $items['admin/tripal/schema/custom_tables/new'] = array(
  329. 'title' => 'Create Custom Table',
  330. 'description' => 'An interface for creating your own custom tables.',
  331. 'page callback' => 'tripal_custom_table_new_page',
  332. 'access arguments' => array('administer tripal'),
  333. 'type' => MENU_CALLBACK,
  334. );
  335. $items['admin/tripal/schema/custom_tables/edit/%'] = array(
  336. 'title' => 'Edit Custom Table',
  337. 'page callback' => 'drupal_get_form',
  338. 'page arguments' => array('tripal_custom_tables_form', 4),
  339. 'access arguments' => array('administer tripal'),
  340. 'type' => MENU_CALLBACK,
  341. );
  342. $items['admin/tripal/schema/custom_tables/action/%/%'] = array(
  343. 'title' => 'Create Custom Table',
  344. 'description' => 'Custom tables are added to Chado.',
  345. 'page callback' => 'tripal_custom_tables_action',
  346. 'page arguments' => array(4, 5, "1"),
  347. 'access arguments' => array('administer tripal'),
  348. 'type' => MENU_CALLBACK,
  349. );
  350. $items['admin/tripal/schema/custom_tables/views/tables/enable'] = array(
  351. 'title' => 'Enable Custom Tables Administrative View',
  352. 'page callback' => 'tripal_views_admin_enable_view',
  353. 'page arguments' => array('tripal_core_admin_custom_table', 'admin/tripal/schema/custom_tables'),
  354. 'access arguments' => array('administer tripal'),
  355. 'type' => MENU_CALLBACK,
  356. );
  357. // Relationshi API autocomplete callback
  358. $items['tripal_ajax/relationship_nodeform/%/%/name_to_id'] = array(
  359. 'page callback' => 'chado_node_relationships_name_to_id_callback',
  360. 'page arguments' => array(2,3),
  361. 'access arguments' => array('access content'),
  362. 'type' => MENU_CALLBACK
  363. );
  364. return $items;
  365. }
  366. /**
  367. * Implements hook_permission().
  368. *
  369. * Set the permission types that the chado module uses. Essentially we
  370. * want permissionis that protect creation, editing and deleting of chado
  371. * data objects
  372. *
  373. * @ingroup tripal_core
  374. */
  375. function tripal_core_permission() {
  376. return array(
  377. 'install chado' => array(
  378. 'title' => t('Install Chado'),
  379. 'description' => t('Allow the user to install or upgrade a Chado database in the existing Drupal database.')
  380. ),
  381. 'administer tripal' => array(
  382. 'title' => t('Administer Tripal'),
  383. 'description' => t('Allow the user to access administrative pages of Tripal.')
  384. ),
  385. );
  386. }
  387. /**
  388. * Implements hook_theme().
  389. * Registers template files/functions used by this module.
  390. *
  391. * @ingroup tripal_core
  392. */
  393. function tripal_core_theme($existing, $type, $theme, $path) {
  394. return array(
  395. 'tripal_core_customize' => array(
  396. 'arguments' => array('job_id' => NULL),
  397. 'template' => 'tripal_core_customize',
  398. 'path' => "$path/theme"
  399. ),
  400. 'theme_file_upload_combo' => array(
  401. 'render element' => 'element',
  402. ),
  403. 'theme_sequence_combo' => array(
  404. 'render element' => 'element',
  405. ),
  406. 'tripal_core_jobs_help' => array(
  407. 'template' => 'tripal_core_jobs_help',
  408. 'variables' => array(NULL),
  409. 'path' => "$path/theme"
  410. ),
  411. 'tripal_core_customtables_help' => array(
  412. 'template' => 'tripal_core_customtables_help',
  413. 'variables' => array(NULL),
  414. 'path' => "$path/theme"
  415. ),
  416. // Chado Node API Themes
  417. // --------------------------------
  418. // Properties Node Form
  419. 'chado_node_properties_form_table' => array(
  420. 'function' => 'theme_chado_add_node_form_properties',
  421. 'render element' => 'element',
  422. ),
  423. // Additional Dbxrefs Nore Form
  424. 'chado_node_additional_dbxrefs_form_table' => array(
  425. 'function' => 'theme_chado_add_node_form_dbxrefs_table',
  426. 'render element' => 'element',
  427. ),
  428. // Relationships Nore Form
  429. 'chado_node_relationships_form_table' => array(
  430. 'function' => 'theme_chado_add_node_form_relationships_tables',
  431. 'render element' => 'element',
  432. ),
  433. // Admin messages theme
  434. // --------------------------------
  435. 'tripal_admin_message' => array(
  436. 'function' => 'theme_tripal_admin_message',
  437. 'variables' => array('message' => NULL),
  438. )
  439. );
  440. }
  441. /**
  442. * Implements hook_job_describe_args().
  443. * Describes the arguements for the tripal_populate_mview job to allow for greater
  444. * readability in the jobs details pages.
  445. *
  446. * @param $callback
  447. * The callback of the current tripal job (this is the function that will be executed
  448. * when tripal_launch_jobs.php is run.
  449. * @param $args
  450. * An array of arguments passed in when the job was registered.
  451. *
  452. * @return
  453. * A more readable $args array
  454. *
  455. * @ingroup tripal_core
  456. */
  457. function tripal_core_job_describe_args($callback, $args) {
  458. $new_args = array();
  459. if ($callback == 'tripal_populate_mview') {
  460. // get this mview details
  461. $sql = "SELECT * FROM {tripal_mviews} WHERE mview_id = :mview_id ";
  462. $results = db_query($sql, array(':mview_id' => $args[0]));
  463. $mview = $results->fetchObject();
  464. $new_args['View Name'] = $mview->name;
  465. }
  466. elseif ($callback == 'tripal_core_install_chado') {
  467. $new_args['Action'] = $args[0];
  468. }
  469. return $new_args;
  470. }
  471. /**
  472. * this is just a wrapper for backwards compatibility with a naming mistake.
  473. * it can go away in the future as it only is useful for jobs created by v0.3b
  474. *
  475. * @todo remove this function
  476. */
  477. function tripal_core_load_gff3($gff_file, $organism_id, $analysis_id, $add_only = 0,
  478. $update = 0, $refresh = 0, $remove = 0, $job = NULL) {
  479. tripal_feature_load_gff3($gff_file, $organism_id, $analysis_id, $add_only,
  480. $update, $refresh, $remove, $job);
  481. }
  482. /**
  483. * Implements hook_coder_ignore().
  484. * Defines the path to the file (tripal_core.coder_ignores.txt) where ignore rules for coder are stored
  485. */
  486. function tripal_core_coder_ignore() {
  487. return array(
  488. 'path' => drupal_get_path('module', 'tripal_core'),
  489. 'line prefix' => drupal_get_path('module', 'tripal_core'),
  490. );
  491. }
  492. /**
  493. * Implements hook_views_api()
  494. * Purpose: Essentially this hook tells drupal that there is views support for
  495. * for this module which then includes tripal_db.views.inc where all the
  496. * views integration code is
  497. *
  498. * @ingroup tripal_organism
  499. */
  500. function tripal_core_views_api() {
  501. return array(
  502. 'api' => 3.0,
  503. );
  504. }
  505. /**
  506. * After the node is built, we want to add instructions to each
  507. * content section letting the administrator know which template
  508. * they can customize
  509. *
  510. * @param unknown $build
  511. */
  512. function tripal_core_node_view_alter(&$build) {
  513. global $theme;
  514. //dpm($build);
  515. // if the $build['tripal_toc'] element is not present, then this is not
  516. // a full node view so we do not want to alter
  517. if (!array_key_exists('tripal_toc', $build)) {
  518. return;
  519. }
  520. $cache = cache_get("theme_registry:$theme", 'cache');
  521. $node = $build['#node'];
  522. $toc = array();
  523. $toc_html = '';
  524. // if we are looking at a Tripal node template then we want to
  525. // make some changes to each block of content so that we can associate
  526. // a table of contents and add administrator and curator messages
  527. if (preg_match('/chado_/', $node->type)) {
  528. // iterate through all the elements of the $build array and for those
  529. // that are wanting to provide content for this node
  530. $markup = array();
  531. foreach ($build as $key => $value) {
  532. // examine elements without a '#' prefix as these should be adding
  533. // contents to the page. Skip the table of contents and links as those
  534. // will be placed elsewhere
  535. if (!preg_match('/^#/', $key) and $key != 'tripal_toc' and $key != 'links') {
  536. //-----------------------
  537. // INITIALIZE THE CONTENT VARIABLES
  538. //-----------------------
  539. $toc_item_title = $key;
  540. $toc_item_id = $key;
  541. $toc_item_link = '';
  542. // get the title for the table of contents. Tripal templates should
  543. // have a '#tripal_toc_title' element in the build array
  544. if (array_key_exists('#tripal_toc_title', $build[$key])) {
  545. $toc_item_title = $build[$key]['#tripal_toc_title'];
  546. }
  547. // other elements in the $build array may just have a '#title' element,
  548. if (array_key_exists('#title', $build[$key])) {
  549. $toc_item_title = $build[$key]['#title'];
  550. }
  551. $toc_item_title = ucwords($toc_item_title);
  552. if (array_key_exists('#tripal_toc_id', $build[$key])) {
  553. $toc_item_id = $build[$key]['#tripal_toc_id'];
  554. }
  555. $toc_item_link = "<div class=\"tripal_toc_list_item\"><a id=\"$toc_item_id\" class=\"tripal_toc_list_item_link\" href=\"?block=$toc_item_id\">$toc_item_title</a></div>";
  556. //-----------------------
  557. // GET THE MARKUP FOR EACH ELEMENT
  558. //-----------------------
  559. $markup = '';
  560. // find the markup. Some fields will have a '#markup' and others, such
  561. // as CCK elements may have a set of '#markup' elements organized by
  562. // numerical keys.
  563. if (array_key_exists('#markup', $build[$key]) and trim($build[$key]['#markup'])) {
  564. $markup = $build[$key]['#markup'];
  565. }
  566. // For backwards copmatibility we should support the '#value' element as well.
  567. elseif (array_key_exists('#value', $build[$key]) and trim($build[$key]['#value'])) {
  568. $markup = $build[$key]['#markup'];
  569. }
  570. // if we have no '#markup' field then this element has not yet
  571. // been rendered. Let's render it and substitute that for markup
  572. if (!$markup) {
  573. $markup = trim(render($build[$key]));
  574. $build[$key] = array(
  575. '#markup' => $markup,
  576. );
  577. }
  578. // if we still don't have markup then skip this one
  579. if (!$markup) {
  580. continue;
  581. }
  582. //-----------------------
  583. // FIND THE TEMPLATE PATH
  584. //-----------------------
  585. // get the template path so we can put it in an admin message box
  586. $path = '';
  587. if (array_key_exists($key, $cache->data) and array_key_exists('path', $cache->data[$key])) {
  588. $path = $cache->data[$key]['path'] . '/' . $key . '.tpl.php';
  589. $path = tripal_set_message("Administrators, you can
  590. customize the way the content above is presented. Tripal provides a template
  591. file for each block of content. To customize, copy the template file to your
  592. site's default theme, edit then " .
  593. l('clear the Drupal cache', 'admin/config/development/performance', array('attributes' => array('target' => '_blank'))) . ".
  594. Currently, the content above is provided by this template: <br><br>$path",
  595. TRIPAL_INFO, array('return_html' => 1)
  596. );
  597. }
  598. //-----------------------
  599. // SET THE WEIGHTS FOR THE TOC ELEMENTS
  600. //-----------------------
  601. // set the weight of the TOC item and add it to our $toc array
  602. // for building of the TOC below
  603. $weight = 0;
  604. if (array_key_exists('#weight', $build[$key])) {
  605. $weight = $build[$key]['#weight'];
  606. }
  607. $toc[$weight][$toc_item_title] = $toc_item_link;
  608. //-----------------------
  609. // CREATE THE DATA BLOCK
  610. //-----------------------
  611. // add a surrounding <div> box around the content
  612. $updated_markup = "
  613. <div id=\"$toc_item_id-tripal-data-block\" class=\"tripal-data-block\">
  614. <div class=\"$toc_item_id-tripal-data-block-title tripal-data-block-title\">$toc_item_title</div>
  615. $markup
  616. $path
  617. </div>
  618. </div>
  619. ";
  620. $build[$key]['#markup'] = $updated_markup;
  621. $build[$key]['#weight'] = $weight;
  622. }
  623. }
  624. }
  625. //-----------------------
  626. // BUILD THE TABLE OF CONTENTS LINKS
  627. //-----------------------
  628. // first sort the links numerically by their weight
  629. ksort($toc, SORT_NUMERIC);
  630. $toc_html = '';
  631. foreach ($toc as $weight => $links) {
  632. // for links in the same weight, sort them alphabetically
  633. ksort($links);
  634. foreach ($links as $toc_item_title => $toc_item_link) {
  635. $toc_html .= $toc_item_link;
  636. }
  637. }
  638. $build['tripal_toc']['#markup'] = "<div id=\"$node->type-tripal-toc-block\" class=\"tripal-toc-block\">$toc_html</div>";
  639. //dpm($cache);
  640. //dpm($build);
  641. }
  642. /**
  643. *
  644. * @ingroup tripal_core
  645. */
  646. function tripal_core_node_view($node, $view_mode, $langcode) {
  647. // if this node type is a chado-based node (i.e. Tripal node)
  648. // the we want to add a table of contents to it's content list
  649. // this table of contents will be an empty
  650. if (preg_match('/^chado_/', $node->type)) {
  651. // Show feature browser and counts
  652. if ($view_mode == 'full') {
  653. $node->content['tripal_toc'] = array(
  654. '#markup' => "<div id=\"$node->type-tripal-toc-block\" class=\"tripal-toc-block\"></div>",
  655. );
  656. }
  657. }
  658. }