tripal_core.module 25 KB

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