tripal.module 52 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576
  1. <?php
  2. /**
  3. * @file
  4. * The core Tripal module
  5. */
  6. /**
  7. * @defgroup tripal Tripal Module
  8. * @ingroup tripal_modules
  9. * @{
  10. * The core Tripal module provides functionality useful for all other Tripal
  11. * modules and extension modules.
  12. * @}
  13. */
  14. /**
  15. * @defgroup tripal_api Tripal API
  16. * @ingroup tripal
  17. * @{
  18. * Tripal provides an application programming interface (API) to support
  19. * customizations and creation of new extensions.
  20. * @}
  21. */
  22. // Import the full Tripal API into scope.
  23. tripal_import_api();
  24. require_once "includes/tripal.field_storage.inc";
  25. require_once "includes/tripal.fields.inc";
  26. require_once "includes/tripal.entity.inc";
  27. require_once "includes/TripalVocab.inc";
  28. require_once "includes/TripalVocabController.inc";
  29. require_once "includes/TripalVocabViewsController.inc";
  30. require_once "includes/TripalTerm.inc";
  31. require_once "includes/TripalTermController.inc";
  32. require_once "includes/TripalTermViewsController.inc";
  33. require_once "includes/TripalEntity.inc";
  34. require_once "includes/TripalEntityController.inc";
  35. require_once "includes/TripalEntityUIController.inc";
  36. require_once "includes/TripalEntityViewsController.inc";
  37. require_once "includes/TripalBundle.inc";
  38. require_once "includes/TripalBundleController.inc";
  39. require_once "includes/TripalBundleUIController.inc";
  40. require_once "includes/TripalBundleViewsController.inc";
  41. require_once "includes/TripalFields/TripalField.inc";
  42. require_once "includes/TripalFields/TripalFieldWidget.inc";
  43. require_once "includes/TripalFields/TripalFieldFormatter.inc";
  44. require_once "includes/TripalFieldQuery.inc";
  45. require_once "includes/TripalJob.inc";
  46. require_once "includes/TripalImporter.inc";
  47. require_once "includes/TripalEntityCollection.inc";
  48. require_once "includes/TripalFieldDownloaders/TripalFieldDownloader.inc";
  49. /**
  50. * Implements hook_views_api().
  51. */
  52. function tripal_views_api() {
  53. return array(
  54. 'api' => 3,
  55. );
  56. }
  57. /**
  58. * Implements hook_init().
  59. *
  60. * @ingroup tripal
  61. */
  62. function tripal_init() {
  63. global $base_url;
  64. // add some variables for all javasript to use for building URLs
  65. $clean_urls = variable_get('clean_url', 0);
  66. $tripal_path = url(drupal_get_path('module', 'tripal'));
  67. drupal_add_js("
  68. var baseurl = '$base_url';
  69. var isClean = $clean_urls;
  70. var tripal_path = '$tripal_path';",
  71. 'inline', 'header');
  72. // make sure the date time settings are the way Tripal will insert them
  73. // otherwise PostgreSQL version that may have a different datestyle setting
  74. // will fail when inserting or updating a date column in a table.
  75. db_query("SET DATESTYLE TO :style", array(':style' => 'MDY'));
  76. }
  77. function tripal_menu_alter(&$items) {
  78. }
  79. /**
  80. * Implements hook_menu().
  81. * Defines all menu items needed by Tripal Core
  82. *
  83. * @ingroup tripal
  84. */
  85. function tripal_menu() {
  86. $items = array();
  87. // Tripal setting groups
  88. $items['admin/tripal'] = array(
  89. 'title' => 'Tripal',
  90. 'description' => t("Manage the behavior or Tripal and its various modules."),
  91. 'weight' => -8,
  92. 'page callback' => 'system_admin_menu_block_page',
  93. 'access arguments' => array('administer tripal'),
  94. 'file' => 'system.admin.inc',
  95. 'file path' => drupal_get_path('module', 'system'),
  96. );
  97. /**
  98. * Tripal Extensions
  99. */
  100. $items['admin/tripal/storage'] = array(
  101. 'title' => 'Data Storage',
  102. 'description' => t("Tripal is designed to access biological
  103. data in any data storage back-end. A storage back-end must have a
  104. module that can be installed that interfaces with Tripal. By default
  105. the base Tripal package provides The Tripal Chado module for storing
  106. data in the GMOD Chado database schema. All available storage backends
  107. and their administrative tools are found here."),
  108. 'weight' => 8,
  109. 'access arguments' => array('administer tripal'),
  110. );
  111. $items['admin/tripal/extension'] = array(
  112. 'title' => 'Extensions',
  113. 'description' => t("Configuration and management pages for Tripal extension modules."),
  114. 'weight' => 8,
  115. 'access arguments' => array('administer tripal'),
  116. );
  117. /**
  118. * Jobs Management
  119. */
  120. $items['admin/tripal/tripal_jobs'] = array(
  121. 'title' => 'Jobs',
  122. 'description' => t('Provides tools for managing jobs submitted to Tripal. In some
  123. cases, long-running tasks are too slow to complete within a single
  124. browser session. The Tripal jobs system allows long-running tasks
  125. to be submitted to a queue that can be executed manually by the
  126. site admin or automatically using a module such as the ') .
  127. l('Tripal Daemon', 'https://www.drupal.org/project/tripal_daemon', array('attributes' => array('target' => '_blank'))) .
  128. ' extension module.',
  129. 'page callback' => 'tripal_jobs_admin_view',
  130. 'access arguments' => array('administer tripal'),
  131. 'type' => MENU_NORMAL_ITEM,
  132. 'weight' => 0,
  133. 'file' => 'includes/tripal.jobs.inc',
  134. );
  135. $items['admin/tripal/tripal_jobs/help'] = array(
  136. 'title' => 'Help',
  137. 'description' => t('Help for the tripal job management system'),
  138. 'page callback' => 'theme',
  139. 'page arguments' => array('tripal_job_help'),
  140. 'access arguments' => array('administer tripal'),
  141. 'type' => MENU_LOCAL_TASK,
  142. 'weight' => 10
  143. );
  144. $items['admin/tripal/tripal_jobs/cancel/%'] = array(
  145. 'title' => 'Jobs',
  146. 'description' => t('Cancel a pending job'),
  147. 'page callback' => 'tripal_cancel_job',
  148. 'page arguments' => array(4),
  149. 'access arguments' => array('administer tripal'),
  150. 'type' => MENU_CALLBACK,
  151. 'file' => 'api/tripal.jobs.api.inc',
  152. );
  153. $items['admin/tripal/tripal_jobs/status/%'] = array(
  154. 'page callback' => 'tripal_jobs_status_view',
  155. 'page arguments' => array(4),
  156. 'access arguments' => array('administer tripal'),
  157. 'type' => MENU_CALLBACK,
  158. 'file' => 'includes/tripal.jobs.inc',
  159. );
  160. $items['admin/tripal/tripal_jobs/rerun/%'] = array(
  161. 'title' => 'Jobs',
  162. 'description' => t('Re-run an existing job.'),
  163. 'page callback' => 'tripal_rerun_job',
  164. 'page arguments' => array(4),
  165. 'access arguments' => array('administer tripal'),
  166. 'type' => MENU_CALLBACK,
  167. 'file' => 'includes/tripal.jobs.inc',
  168. );
  169. $items['admin/tripal/tripal_jobs/view/%'] = array(
  170. 'title' => 'Jobs Details',
  171. 'description' => t('View job details.'),
  172. 'page callback' => 'tripal_jobs_view',
  173. 'page arguments' => array(4),
  174. 'access arguments' => array('administer tripal'),
  175. 'type' => MENU_CALLBACK,
  176. 'file' => 'includes/tripal.jobs.inc',
  177. );
  178. $items['admin/tripal/tripal_jobs/views/jobs/enable'] = array(
  179. 'title' => 'Enable Jobs Administrative View',
  180. 'page callback' => 'tripal_enable_view',
  181. 'page arguments' => array('tripal_admin_jobs', 'admin/tripal/tripal_jobs'),
  182. 'access arguments' => array('administer tripal'),
  183. 'type' => MENU_CALLBACK,
  184. 'file' => 'includes/tripal.jobs.inc',
  185. );
  186. $items['admin/tripal/tripal_jobs/execute/%'] = array(
  187. 'title' => 'Jobs',
  188. 'description' => t('Execute an existing job'),
  189. 'page callback' => 'tripal_execute_job',
  190. 'page arguments' => array(4),
  191. 'access arguments' => array('administer tripal'),
  192. 'type' => MENU_CALLBACK,
  193. );
  194. /*
  195. * AJAX Callbacks.
  196. */
  197. $items['bio_data/ajax/field_attach/%'] = array(
  198. 'page callback' => 'tripal_ajax_attach_field',
  199. 'page arguments' => array(3),
  200. 'access arguments' => array('access content'),
  201. 'type' => MENU_CALLBACK,
  202. 'file' => 'includes/tripal.entity.inc',
  203. 'file path' => drupal_get_path('module', 'tripal'),
  204. );
  205. /*
  206. * Dashboard Action Item callbacks.
  207. */
  208. $items['admin/disable/notification/%'] = array(
  209. 'page callback' => 'tripal_disable_admin_notification',
  210. 'page arguments' => array(3),
  211. 'access arguments' => array('access content'),
  212. 'type' => MENU_CALLBACK,
  213. 'file' => 'includes/tripal.admin_blocks.inc',
  214. 'file path' => drupal_get_path('module', 'tripal'),
  215. );
  216. $items['admin/import/field/%/%/%/%'] = array(
  217. 'page callback' => 'tripal_admin_notification_import_field',
  218. 'page arguments' => array(3, 4, 5, 6),
  219. 'access arguments' => array('access content'),
  220. 'type' => MENU_CALLBACK,
  221. 'file' => 'includes/tripal.admin_blocks.inc',
  222. 'file path' => drupal_get_path('module', 'tripal'),
  223. );
  224. /*
  225. * Term Lookup
  226. */
  227. $items['cv/lookup'] = array(
  228. 'title' => 'Controlled Vocabularies',
  229. 'description' => t("A tool to explore the controlled vocabularies that are used on this site."),
  230. 'access arguments' => array('access content'),
  231. 'page callback' => 'tripal_vocabulary_lookup_page',
  232. 'file' => 'includes/tripal.term_lookup.inc',
  233. 'file path' => drupal_get_path('module', 'tripal'),
  234. 'type' => MENU_NORMAL_ITEM,
  235. );
  236. $items['cv/lookup/%'] = array(
  237. 'title' => 'Vocabulary Details',
  238. 'description' => t("Provides a tool to discover controlled vocabularies"),
  239. 'access arguments' => array('access content'),
  240. 'page callback' => 'tripal_vocabulary_lookup_vocab_page',
  241. 'page arguments' => array(2),
  242. 'file' => 'includes/tripal.term_lookup.inc',
  243. 'file path' => drupal_get_path('module', 'tripal'),
  244. 'type' => MENU_CALLBACK,
  245. );
  246. $items['cv/lookup/%/%'] = array(
  247. 'title' => 'Vocabulary Term Lookup',
  248. 'description' => t("Provides a tool to discover controlled vocabularies terms used by this site."),
  249. 'access arguments' => array('access content'),
  250. 'page callback' => 'tripal_vocabulary_lookup_term_page',
  251. 'page arguments' => array(2, 3),
  252. 'file' => 'includes/tripal.term_lookup.inc',
  253. 'file path' => drupal_get_path('module', 'tripal'),
  254. 'type' => MENU_CALLBACK,
  255. );
  256. $items['cv/lookup/%/%/children'] = array(
  257. 'access arguments' => array('access content'),
  258. 'page callback' => 'tripal_vocabulary_lookup_term_children_ajax',
  259. 'page arguments' => array(2, 3),
  260. 'file' => 'includes/tripal.term_lookup.inc',
  261. 'file path' => drupal_get_path('module', 'tripal'),
  262. 'type' => MENU_CALLBACK,
  263. );
  264. // Adds a +Check for new fields link on the 'Tripal Content Types' page.
  265. $items['admin/structure/bio_data/manage/%/fields/check'] = array(
  266. 'title' => 'Check for new fields',
  267. 'description' => t('Check if new fields should be added to this content type.'),
  268. 'page callback' => 'tripal_check_new_fields',
  269. 'page arguments' => array(4),
  270. 'access arguments' => array('administer tripal'),
  271. 'file' => 'api/tripal.entities.api.inc',
  272. 'file path' => drupal_get_path('module', 'tripal'),
  273. 'type' => MENU_LOCAL_ACTION,
  274. );
  275. $items['tripal/upload'] = array(
  276. 'page callback' => 'tripal_file_upload',
  277. 'access arguments' => array('upload files'),
  278. 'file' => '/includes/tripal.upload.inc',
  279. 'type' => MENU_CALLBACK,
  280. );
  281. /*
  282. * Data Loaders (TripalImporter)
  283. */
  284. $items['admin/tripal/loaders'] = array(
  285. 'title' => 'Data Loaders',
  286. 'description' => t('Tools facilitating data import.'),
  287. 'access arguments' => array('administer tripal'),
  288. 'type' => MENU_NORMAL_ITEM,
  289. 'weight' => 6
  290. );
  291. // Add in the loaders
  292. $importers = tripal_get_importers();
  293. foreach ($importers as $class_name) {
  294. tripal_load_include_importer_class($class_name);
  295. if (class_exists($class_name)) {
  296. $machine_name = $class_name::$machine_name;
  297. $menu_path = 'admin/tripal/loaders/' . $machine_name;
  298. $callback = $class_name::$callback;
  299. $callback_path = $class_name::$callback_path;
  300. $callback_module = $class_name::$callback_module;
  301. $page_args = [];
  302. if ($class_name::$menu_path) {
  303. $menu_path = $class_name::$menu_path;
  304. }
  305. if (!$callback) {
  306. $callback = 'drupal_get_form';
  307. $page_args = ['tripal_get_importer_form', $class_name];
  308. }
  309. if (!$callback_path) {
  310. $callback_path = 'includes/tripal.importer.inc';
  311. }
  312. $file_path = drupal_get_path('module', 'tripal');
  313. if ($callback_path and $callback_module) {
  314. $file_path = drupal_get_path('module', $callback_module);
  315. }
  316. $items[$menu_path] = array(
  317. 'title' => $class_name::$name,
  318. 'description' => $class_name::$description,
  319. 'page callback' => $callback,
  320. 'page arguments' => $page_args,
  321. 'access arguments' => array('use ' . $machine_name . ' importer'),
  322. 'type' => MENU_NORMAL_ITEM,
  323. 'file' => $callback_path,
  324. 'file path' => $file_path,
  325. );
  326. }
  327. }
  328. /**
  329. * Data Collections
  330. */
  331. $items['user/%/data-collections/%/delete'] = array (
  332. 'title' => 'Delete a Collections',
  333. 'description' => 'Deletes a data collection.',
  334. 'page callback' => 'drupal_get_form',
  335. 'page arguments' => array('tripal_user_collections_delete_form', 1, 3),
  336. 'access callback' => 'tripal_accesss_user_collections',
  337. 'access arguments' => array(1),
  338. 'type' => MENU_CALLBACK,
  339. 'file' => 'includes/tripal.collections.inc',
  340. 'file path' => drupal_get_path('module', 'tripal'),
  341. );
  342. $items['user/%/data-collections/%/view'] = array (
  343. 'title' => 'View a Collections',
  344. 'description' => 'Views a data collection.',
  345. 'page callback' => 'tripal_user_collections_view_page',
  346. 'page arguments' => array(1, 3),
  347. 'access callback' => 'tripal_accesss_user_collections',
  348. 'access arguments' => array(1),
  349. 'type' => MENU_CALLBACK,
  350. 'file' => 'includes/tripal.collections.inc',
  351. 'file path' => drupal_get_path('module', 'tripal'),
  352. );
  353. $items['user/%/data-collections/generate/%'] = array (
  354. 'title' => 'Generate a file for download of a Collections',
  355. 'description' => 'Generates a data collection file for download.',
  356. 'page callback' => 'drupal_get_form',
  357. 'page arguments' => array('tripal_user_collections_generate_file_form', 1, 4),
  358. 'access callback' => 'tripal_accesss_user_collections',
  359. 'access arguments' => array(1),
  360. 'type' => MENU_CALLBACK,
  361. 'file' => 'includes/tripal.collections.inc',
  362. 'file path' => drupal_get_path('module', 'tripal'),
  363. );
  364. $items['admin/tripal/data-collections'] = array(
  365. 'title' => 'Data Collections',
  366. 'description' => t('Site-wide settings for data collections'),
  367. 'page callback' => 'drupal_get_form',
  368. 'page arguments' => array('tripal_admin_data_collection_form'),
  369. 'access arguments' => array('administer tripal'),
  370. 'type' => MENU_NORMAL_ITEM,
  371. 'weight' => 0,
  372. 'file' => 'includes/tripal.admin.inc',
  373. 'file path' => drupal_get_path('module', 'tripal'),
  374. );
  375. //
  376. // USER FILE MANAGEMENT
  377. //
  378. $items['admin/tripal/files'] = [
  379. 'title' => 'User File Management',
  380. 'description' => 'Set maximum upload sizes, quotas and view usage.',
  381. 'page callback' => 'drupal_get_form',
  382. 'page arguments' => ['tripal_admin_manage_files_form'],
  383. 'access arguments' => ['administer tripal'],
  384. 'type' => MENU_NORMAL_ITEM,
  385. 'file' => 'includes/tripal.admin_files.inc',
  386. 'file path' => drupal_get_path('module', 'tripal'),
  387. 'weight' => 30,
  388. ];
  389. $items['admin/tripal/files/quota'] = [
  390. 'title' => 'User Quotas',
  391. 'description' => 'Set default quota, expiration date, and custom quotas',
  392. 'page callback' => 'drupal_get_form',
  393. 'page arguments' => ['tripal_admin_manage_quota_form'],
  394. 'access arguments' => ['administer tripal'],
  395. 'type' => MENU_LOCAL_TASK,
  396. 'file' => 'includes/tripal.admin_files.inc',
  397. 'file path' => drupal_get_path('module', 'tripal'),
  398. 'weight' => 10,
  399. ];
  400. // Admin remove user quota
  401. $items['admin/tripal/files/quota/remove/%'] = [
  402. 'title' => 'Remove custom user quota',
  403. 'description' => "Revert's a user's quota and expiration of files to the site wide defaults.",
  404. 'page callback' => 'drupal_get_form',
  405. 'page arguments' => ['tripal_admin_remove_quota_form', 5],
  406. 'access arguments' => ['administer tripal'],
  407. 'type' => MENU_CALLBACK,
  408. 'file' => 'includes/tripal.admin_files.inc',
  409. 'file path' => drupal_get_path('module', 'tripal'),
  410. ];
  411. // Add user quota
  412. $items['admin/tripal/files/quota/add'] = [
  413. 'title' => 'Add Custom Quota',
  414. 'description' => 'Gives the user a new quota and expiration date',
  415. 'page callback' => 'drupal_get_form',
  416. 'page arguments' => ['tripal_admin_add_custom_form'],
  417. 'access arguments' => ['administer tripal'],
  418. // TODO: Ask Stephen is this is fine as a link at the top of the form
  419. // as well as a link in the table
  420. 'type' => MENU_CALLBACK,
  421. 'file' => 'includes/tripal.admin_files.inc',
  422. 'file path' => drupal_get_path('module', 'tripal'),
  423. ];
  424. // Autocomplete path for the users on the site
  425. $items['admin/tripal/files/quota/user/autocomplete'] = [
  426. 'title' => 'Autocomplete for existing users',
  427. 'description' => 'Provide a list of existing users on the site.',
  428. 'page callback' => 'tripal_users_autocomplete',
  429. 'access arguments' => ['administer tripal'],
  430. 'type' => MENU_CALLBACK,
  431. 'file' => 'includes/tripal.admin_files.inc',
  432. 'file path' => drupal_get_path('module', 'tripal'),
  433. ];
  434. // Edit user quota
  435. $items['admin/tripal/files/quota/edit/%'] = [
  436. 'title' => 'Edit Custom Quota',
  437. 'description' => 'Edit an existing user\'s quota and/or expiration date.',
  438. 'page callback' => 'drupal_get_form',
  439. 'page arguments' => ['tripal_admin_edit_quota_form', 5],
  440. 'access arguments' => ['administer tripal'],
  441. 'type' => MENU_CALLBACK,
  442. 'file' => 'includes/tripal.admin_files.inc',
  443. 'file path' => drupal_get_path('module', 'tripal'),
  444. ];
  445. $items['admin/tripal/files/usage'] = [
  446. 'title' => 'File Usage',
  447. 'description' => 'Set default quota, expiration date, and custom quotas',
  448. 'page callback' => 'drupal_get_form',
  449. 'page arguments' => ['tripal_admin_file_usage_page'],
  450. 'access arguments' => ['administer tripal'],
  451. 'type' => MENU_LOCAL_TASK,
  452. 'file' => 'includes/tripal.admin_files.inc',
  453. 'file path' => drupal_get_path('module', 'tripal'),
  454. 'weight' => 15
  455. ];
  456. //
  457. // USER FILES
  458. //
  459. // User view quota (Tab)
  460. $items['user/%/files'] = [
  461. 'title' => 'Files',
  462. 'description' => 'Monitors what files that have been uploaded by user through the tripal module',
  463. 'page callback' => 'tripal_user_files_page',
  464. 'page arguments' => [1],
  465. 'access callback' => 'tripal_access_user_files',
  466. 'access arguments' => ['view', 1],
  467. 'type' => MENU_LOCAL_TASK,
  468. 'file' => 'includes/tripal.user.inc',
  469. 'file path' => drupal_get_path('module', 'tripal'),
  470. 'weight' => 10,
  471. ];
  472. $items['user/%/files/%'] = [
  473. 'title' => 'File Details',
  474. 'description' => "View details about the file",
  475. 'page callback' => 'tripal_view_file',
  476. 'page arguments' => [1, 3],
  477. 'access callback' => 'tripal_access_user_files',
  478. 'access arguments' => ['renew', 1, 3],
  479. 'type' => MENU_CALLBACK,
  480. 'file' => 'includes/tripal.user.inc',
  481. 'file path' => drupal_get_path('module', 'tripal'),
  482. ];
  483. // User file renew.
  484. $items['user/%/files/%/renew'] = [
  485. 'title' => 'Renew File',
  486. 'description' => "Renew a user's file",
  487. 'page callback' => 'tripal_renew_file',
  488. 'page arguments' => [3],
  489. 'access callback' => 'tripal_access_user_files',
  490. 'access arguments' => ['renew', 1, 3],
  491. 'type' => MENU_CALLBACK,
  492. 'file' => 'includes/tripal.user.inc',
  493. 'file path' => drupal_get_path('module', 'tripal'),
  494. ];
  495. // User file download.
  496. $items['user/%/files/%/download'] = [
  497. 'title' => 'Download File',
  498. 'description' => "Download a user's file based off of the link clicked in the table",
  499. 'page callback' => 'tripal_download_file',
  500. 'page arguments' => [3],
  501. 'access arguments' => ['download', 1, 3],
  502. 'access callback' => 'tripal_access_user_files',
  503. 'type' => MENU_CALLBACK,
  504. 'file' => 'includes/tripal.user.inc',
  505. 'file path' => drupal_get_path('module', 'tripal'),
  506. ];
  507. // User file delete.
  508. $items['user/%/files/%/delete'] = [
  509. 'title' => 'Delete File',
  510. 'description' => "Delete a user's file based on either user action or expired file",
  511. 'page callback' => 'drupal_get_form',
  512. 'page arguments' => ['tripal_delete_file_form', 1, 3],
  513. 'access callback' => 'tripal_access_user_files',
  514. 'access arguments' => ['delete', 1, 3],
  515. 'type' => MENU_CALLBACK,
  516. 'file' => 'includes/tripal.user.inc',
  517. 'file path' => drupal_get_path('module', 'tripal'),
  518. ];
  519. return $items;
  520. }
  521. /**
  522. * Checks if the current user has permissions to perform an action on a file.
  523. *
  524. * @param $op
  525. * The operation to perform. These include 'view', 'download', 'renew' and
  526. * 'delete'
  527. * @param $uid
  528. * The user ID of the user's account that owns the file.
  529. * @param $fid
  530. * The file ID.
  531. */
  532. function tripal_access_user_files($op, $uid, $fid = NULL) {
  533. global $user;
  534. // The site admin can do anything.
  535. if (in_array('administrator', $user->roles)) {
  536. return TRUE;
  537. }
  538. // Only the user that owns the files can see them.
  539. if ($uid != $user->uid) {
  540. return FALSE;
  541. }
  542. // If no file ID is provided and the user wants to view then
  543. // this is the case where the user wants to see all the files.
  544. if (!$fid and $op == 'view') {
  545. return TRUE;
  546. }
  547. $file = file_load($fid);
  548. switch ($op) {
  549. case 'view':
  550. case 'download':
  551. case 'renew':
  552. case 'delete':
  553. if ($user->uid == $file->uid) {
  554. return TRUE;
  555. }
  556. break;
  557. }
  558. return FALSE;
  559. }
  560. /**
  561. * An access function for data collections.
  562. *
  563. * @return boolean
  564. */
  565. function tripal_accesss_user_collections($uid) {
  566. if (!tripal_access_user_data($uid)) {
  567. return FALSE;
  568. }
  569. $collections_enabled = variable_get('tripal_data_collections_enabled', 1);
  570. if (!$collections_enabled) {
  571. return FALSE;
  572. }
  573. return TRUE;
  574. }
  575. /**
  576. * Autocomplete function for listing existing users on the site.
  577. *
  578. * @return json array of users that match the query in the textfield
  579. **/
  580. function tripal_users_autocomplete($string) {
  581. $matches = [];
  582. $result = db_select('users', 'u')
  583. ->fields('u', ['name'])
  584. ->condition('name', '%' . db_like($string) . '%', 'LIKE')
  585. ->execute();
  586. foreach ($result as $row) {
  587. $matches[$row->name] = check_plain($row->name);
  588. }
  589. drupal_json_output($matches);
  590. }
  591. /**
  592. * Access callback for accessing a user's Tripal-added private data.
  593. *
  594. * The User account being accessed must match the ID of the current user. This
  595. * function can be used to check access for any type of user-specfic data
  596. * added by any Tripal module.
  597. *
  598. * @param $uid
  599. * The UID of the user's account to access.
  600. * @return boolean
  601. */
  602. function tripal_access_user_data($uid) {
  603. global $user;
  604. if ($uid == $user->uid) {
  605. return TRUE;
  606. }
  607. return FALSE;
  608. }
  609. /**
  610. * Implements hook_permission().
  611. */
  612. function tripal_permission() {
  613. $permissions = array(
  614. 'administer tripal' => array(
  615. 'title' => t('Administer Tripal'),
  616. 'description' => t('Allow the user to access administrative pages of Tripal. This includes management of jobs, the storage systems, extensions and the controlled vocabularies.'),
  617. 'restrict access' => TRUE,
  618. ),
  619. 'access tripal content overview' => array(
  620. 'title' => t('Access the Tripal content overview page'),
  621. 'description' => t('Get an overview of all Tripal content'),
  622. 'restrict access' => TRUE,
  623. ),
  624. 'manage tripal content types' => array(
  625. 'title' => t('Manage Tripal content types'),
  626. 'description' => t('Allows the user to create, update and delete Tripal content types.'),
  627. 'restrict access' => TRUE,
  628. ),
  629. 'publish tripal content' => array(
  630. 'title' => t('Publish Tripal content types'),
  631. 'description' => t('Allows the user to publish Tripal content for online access.'),
  632. 'restrict access' => TRUE,
  633. ),
  634. 'upload files' => array(
  635. 'title' => t('Upload Files'),
  636. 'description' => t('Allows the user to upload files using Tripal\'s HTML5 loader.'),
  637. ),
  638. 'view dev helps' => array(
  639. 'title' => t('View Developer Hints'),
  640. 'description' => t('Tripal will provide blue shaded boxes that provide
  641. instructions for how to customize or setup specific pages on a
  642. site. This permission should be enabled for developers. But can
  643. be disabled once developers are accustomed to these hints.'),
  644. 'restrict access' => TRUE,
  645. ),
  646. );
  647. // Add permissions for each content type.
  648. $bundles = tripal_get_content_types();
  649. foreach ($bundles as $bundle) {
  650. $permissions['view ' . $bundle->name] = array(
  651. 'title' => t('%label: View Content', array('%label' => $bundle->label)),
  652. 'description' => t('Allow the user to view %label content', array('%label' => $bundle->label)),
  653. );
  654. $permissions['create ' . $bundle->name] = array(
  655. 'title' => t('%label: Create Content', array('%label' => $bundle->label)),
  656. 'description' => t('Allow the user to create %label content', array('%label' => $bundle->label)),
  657. 'restrict access' => TRUE,
  658. );
  659. $permissions['edit ' . $bundle->name] = array(
  660. 'title' => t('%label: Edit Content', array('%label' => $bundle->label)),
  661. 'description' => t('Allow the user to edit %label content', array('%label' => $bundle->label)),
  662. 'restrict access' => TRUE,
  663. );
  664. $permissions['delete ' . $bundle->name] = array(
  665. 'title' => t('%label: Delete Content', array('%label' => $bundle->label)),
  666. 'description' => t('Allow the user to delete %label content', array('%label' => $bundle->label)),
  667. 'restrict access' => TRUE,
  668. );
  669. }
  670. // Add permissions for each Importer
  671. $importers = tripal_get_importers();
  672. foreach ($importers as $class_name) {
  673. tripal_load_include_importer_class($class_name);
  674. if (class_exists($class_name)) {
  675. $machine_name = $class_name::$machine_name;
  676. $name = $class_name::$name;
  677. $permissions['use ' . $machine_name . ' importer'] = array(
  678. 'title' => t('Importer: Use the %label', array('%label' => $name)),
  679. 'description' => t('Allow the user to import data using the %label. Note: you may also need to give the "Upload Files" permission for importers to work.', array('%label' => $name)),
  680. 'restrict access' => TRUE,
  681. );
  682. }
  683. }
  684. return $permissions;
  685. }
  686. /**
  687. * Implements hook_theme().
  688. * Registers template files/functions used by this module.
  689. *
  690. * @ingroup tripal
  691. */
  692. function tripal_theme($existing, $type, $theme, $path) {
  693. $themes = array(
  694. // Admin messages theme
  695. 'tripal_admin_message' => array(
  696. 'function' => 'theme_tripal_admin_message',
  697. 'variables' => array('message' => NULL),
  698. ),
  699. 'tripal_entity' => array(
  700. 'render element' => 'elements',
  701. 'template' => 'tripal_entity',
  702. 'path' => "$path/theme/templates"
  703. ),
  704. 'tripal_add_list' => array(
  705. 'variables' => array('content' => NULL),
  706. ),
  707. // Themeing for all fields.
  708. 'tripal_field_default' => array(
  709. 'render element' => 'element',
  710. 'file' => 'includes/tripal.fields.inc',
  711. ),
  712. // Themed forms
  713. 'tripal_views_handler_area_collections_fields_fset' => array(
  714. 'render element' => 'form',
  715. 'file' => 'views_handlers/tripal_views_handler_area_collections.inc',
  716. ),
  717. );
  718. return $themes;
  719. }
  720. /**
  721. * Implements hook_coder_ignore().
  722. * Defines the path to the file (tripal.coder_ignores.txt) where ignore rules for coder are stored
  723. */
  724. function tripal_coder_ignore() {
  725. return array(
  726. 'path' => drupal_get_path('module', 'tripal'),
  727. 'line prefix' => drupal_get_path('module', 'tripal'),
  728. );
  729. }
  730. /**
  731. * Implements hook_libraries_info().
  732. */
  733. function tripal_libraries_info() {
  734. $libraries = array();
  735. $libraries['d3'] = array(
  736. 'name' => 'D3.js',
  737. 'vendor url' => 'http://d3js.org/',
  738. 'download url' => 'https://github.com/mbostock/d3',
  739. 'version arguments' => array(
  740. 'file' => 'd3.js',
  741. 'pattern' => '/\s*version: "(\d+\.\d+\.\d+)"/',
  742. ),
  743. 'files' => array(
  744. 'js' => array(
  745. 'd3.min.js',
  746. ),
  747. ),
  748. );
  749. return $libraries;
  750. }
  751. /**
  752. * Implements hook_admin_paths().
  753. * Define administrative paths.
  754. */
  755. function tripal_admin_paths() {
  756. $paths = array();
  757. if (variable_get('node_admin_theme')) {
  758. $paths = array(
  759. 'bio_data/*/edit' => TRUE,
  760. 'bio_data/*/delete' => TRUE,
  761. 'bio_data/add' => TRUE,
  762. 'bio_data/add/*' => TRUE,
  763. );
  764. }
  765. $paths['cv/lookup/*/*'] = TRUE;
  766. return $paths;
  767. }
  768. /**
  769. * Implements hook_menu_local_tasks_alter().
  770. *
  771. * Used to add action links to pages.
  772. */
  773. function tripal_menu_local_tasks_alter(&$data, $router_item, $root_path) {
  774. // Add an "Add Tripal Content" action link to the Admin >> Content >>
  775. // Biological Content page.
  776. if ($root_path == 'admin/content/bio_data') {
  777. $item = menu_get_item('bio_data/add');
  778. if ($item['access']) {
  779. $data['actions']['output'][] = array(
  780. '#theme' => 'menu_local_action',
  781. '#link' => $item,
  782. );
  783. }
  784. }
  785. }
  786. /**
  787. * Implements hook_shortcut_default_set().
  788. * Modify the shortcut menu to include Biological content links.
  789. *
  790. * @param object $account
  791. * The user account whose default shortcut set will be returned. If not provided, the
  792. * function will return the currently logged-in user's default shortcut set.
  793. *
  794. * @return
  795. * An object representing the default shortcut set.
  796. */
  797. function tripal_shortcut_default_set($account) {
  798. $sets = shortcut_sets();
  799. $found = FALSE;
  800. foreach ($sets as $set) {
  801. if ($set->title == 'TripalDefault') {
  802. $found = TRUE;
  803. }
  804. }
  805. if (!$found) {
  806. $t = get_t();
  807. // Create an initial default shortcut set.
  808. $shortcut_set = new stdClass();
  809. $shortcut_set->title = $t('TripalDefault');
  810. $shortcut_set->links = array(
  811. array(
  812. 'link_path' => 'node/add',
  813. 'link_title' => $t('Add content'),
  814. 'weight' => -35,
  815. ),
  816. array(
  817. 'link_path' => 'bio_data/add',
  818. 'link_title' => 'Add Tripal Content',
  819. 'weight' => -30,
  820. ),
  821. array(
  822. 'link_path' => 'admin/content',
  823. 'link_title' => $t('Find content'),
  824. 'weight' => -25,
  825. ),
  826. array(
  827. 'link_path' => 'admin/content/bio_data',
  828. 'link_title' => 'Find Tripal Content',
  829. 'weight' => -20,
  830. ),
  831. );
  832. shortcut_set_save($shortcut_set);
  833. }
  834. $sets = shortcut_sets();
  835. foreach ($sets as $set) {
  836. if ($set->title == 'TripalDefault') {
  837. return $set->set_name;
  838. }
  839. }
  840. }
  841. /**
  842. * Menu argument loader; Load a tripal data type by string.
  843. *
  844. * This function is not meant to be used as an API function. It is only meant
  845. * for use in the menu to resolve the %tripal_bundle wildcard.
  846. *
  847. * @param $type
  848. * The machine-readable name of a tripal data type to load.
  849. * @return
  850. * A tripal data type array or FALSE if $type does not exist.
  851. */
  852. function TripalBundle_load($bundle_type, $reset = FALSE) {
  853. // Get the type of entity by the ID.
  854. $bundle = db_select('tripal_bundle', 'tdt')
  855. ->fields('tdt')
  856. ->condition('name', $bundle_type)
  857. ->execute()
  858. ->fetchObject();
  859. if ($bundle) {
  860. $entity = entity_load('TripalBundle', array($bundle->id), array(), $reset);
  861. return reset($entity);
  862. }
  863. return FALSE;
  864. }
  865. /**
  866. * Allows the menu system to use a wildcard to fetch the entity.
  867. *
  868. * Make sure that the wildcard you choose in the tripal_entity entity
  869. * definition fits the function name here.
  870. *
  871. * This function is not meant to be used as an API function. It is only meant
  872. * for use in the menu to resolve the %tripal_entity wildcard.
  873. *
  874. * @param $id
  875. * Integer specifying the tripal_entity id.
  876. * @param $reset
  877. * A boolean indicating that the internal cache should be reset.
  878. * @return
  879. * A fully-loaded $tripal_entity object or FALSE if it cannot be loaded.
  880. *
  881. * @see tripal_entity_load_multiple()
  882. */
  883. function TripalEntity_load($id, $reset = FALSE) {
  884. // $entity = entity_load('TripalEntity', array($id), array(), $reset);
  885. $entity = tripal_load_entity('TripalEntity', array($id), $reset);
  886. return reset($entity);
  887. }
  888. /**
  889. * Imports all of the Tripal API into scope.
  890. *
  891. * Typically this function call is not necessary as all of the API is
  892. * automaticaly included by the tripal module. However this function can
  893. * be useful in the .install files during a site upgrade when the tripal
  894. * module is not enabld.
  895. *
  896. * Example usage:
  897. * @code
  898. * module_load_include('module', 'tripal', 'tripal');
  899. * tripal_import_api();
  900. * @endcode
  901. *
  902. */
  903. function tripal_import_api() {
  904. module_load_include('inc', 'tripal', 'api/tripal.d3js.api');
  905. module_load_include('inc', 'tripal', 'api/tripal.fields.api');
  906. module_load_include('inc', 'tripal', 'api/tripal.importer.api');
  907. module_load_include('inc', 'tripal', 'api/tripal.terms.api');
  908. module_load_include('inc', 'tripal', 'api/tripal.entities.api');
  909. module_load_include('inc', 'tripal', 'api/tripal.files.api');
  910. module_load_include('inc', 'tripal', 'api/tripal.jobs.api');
  911. module_load_include('inc', 'tripal', 'api/tripal.notice.api');
  912. module_load_include('inc', 'tripal', 'api/tripal.variables.api');
  913. module_load_include('inc', 'tripal', 'api/tripal.upload.api');
  914. module_load_include('inc', 'tripal', 'api/tripal.collections.api');
  915. module_load_include('inc', 'tripal', 'api/tripal.quotas.api');
  916. module_load_include('inc', 'tripal', 'api/tripal.DEPRECATED.api');
  917. }
  918. /**
  919. *
  920. * Implements hook_form_FORM_ID_alter().
  921. *
  922. * The field_ui_field_edit_form is used for customizing the settings of
  923. * a field attached to an entity.
  924. *
  925. * This alter function disables some of the form widgets when the storage
  926. * backend indicates they are not appropriate.
  927. */
  928. function tripal_form_field_ui_field_edit_form_alter(&$form, &$form_state, $form_id) {
  929. // If this is the field_ui_field_edit_form (i.e. the form that appears
  930. // when editing a field that is attached to an entity). Then we want
  931. // to add term settings for any field attached to a TripalEntity
  932. // content type.
  933. if ($form['#instance']['entity_type'] == 'TripalEntity') {
  934. // Add the form elements for setting the vocabulary terms.
  935. tripal_field_instance_settings_form_alter($form, $form_state);
  936. // Make sure we preserve the auto_attach settings.
  937. $auto_attach = TRUE;
  938. if (array_key_exists('auto_attach', $form['#instance']['settings'])) {
  939. $auto_attach = $form['#instance']['settings']['auto_attach'];
  940. }
  941. $form['instance']['settings']['auto_attach'] = array(
  942. '#type' => 'value',
  943. '#value' => $auto_attach,
  944. );
  945. }
  946. }
  947. /**
  948. * Implements hook_form_alter().
  949. */
  950. function tripal_form_alter(&$form, $form_state, $form_id) {
  951. // Remove fields that have no form. It's just a bit too confusing to have
  952. // widgets appear in the form but without any form elements inside them.
  953. if ($form_id == 'tripal_entity_form') {
  954. $children = element_children($form);
  955. foreach ($children as $child) {
  956. // Count the number of form elements.
  957. if (array_key_exists('und', $form[$child])) {
  958. $total_widgets = 0;
  959. // Some fields with cardinality of one that aren't TripalFields
  960. // may not have an array, so we need to catch those.
  961. if (array_key_exists('#type', $form[$child]['und'])) {
  962. $total_widgets++;
  963. }
  964. foreach ($form[$child]['und'] as $delta => $element) {
  965. if (is_numeric($delta)) {
  966. $total_widgets += count(element_children($element));
  967. // Ignore the weight column
  968. if (array_key_exists('_weight', $element)) {
  969. $total_widgets--;
  970. }
  971. // Ignore a hidden value column
  972. if (array_key_exists('value', $element) and $element['value']['#type'] == 'value') {
  973. $total_widgets--;
  974. }
  975. // Some form elements don't have a 'value' and they don't have any
  976. // widgets (i.e image field and description field. We don't
  977. // want to loose those, so add one to the widget count.
  978. if (!array_key_exists('value', $element)) {
  979. $total_widgets++;
  980. }
  981. }
  982. }
  983. // If we have no widgets then here's not a form for this field so just
  984. // remove it.
  985. if ($total_widgets == 0) {
  986. unset($form[$child]);
  987. }
  988. }
  989. }
  990. }
  991. }
  992. function tripal_check_new_fields($bundle_name) {
  993. $bundle = tripal_load_bundle_entity(array('name' => $bundle_name));
  994. $term = tripal_load_term_entity(array('term_id' => $bundle->term_id));
  995. $added = tripal_create_bundle_fields($bundle, $term);
  996. if (count($added) == 0) {
  997. drupal_set_message('No new fields were added');
  998. }
  999. foreach ($added as $field_name) {
  1000. drupal_set_message('Added field: ' . $field_name);
  1001. }
  1002. drupal_goto("admin/structure/bio_data/manage/$bundle_name/fields");
  1003. }
  1004. /**
  1005. * Implements hook_block_info().
  1006. */
  1007. function tripal_block_info() {
  1008. $blocks = array();
  1009. $admin_theme = 'seven';
  1010. $blocks['notifications_block'] = array(
  1011. 'info' => t('Dashboard Notifications'),
  1012. 'visibility' => BLOCK_VISIBILITY_LISTED,
  1013. 'pages' => 'admin/dashboard',
  1014. 'status' => TRUE,
  1015. 'theme' => $admin_theme,
  1016. 'region' => 'dashboard_main',
  1017. 'properties' => array(
  1018. 'administrative' => TRUE,
  1019. ),
  1020. );
  1021. $blocks['content_type_barchart'] = array(
  1022. 'info' => t('Published Tripal Content'),
  1023. 'visibility' => BLOCK_VISIBILITY_LISTED,
  1024. 'pages' => 'admin/dashboard',
  1025. 'status' => TRUE,
  1026. 'theme' => $admin_theme,
  1027. 'region' => 'dashboard_main',
  1028. 'properties' => array(
  1029. 'administrative' => TRUE,
  1030. ),
  1031. );
  1032. $blocks['powered_by_tripal'] = array(
  1033. 'info' => t('Powered by Tripal'),
  1034. 'cache' => DRUPAL_NO_CACHE,
  1035. );
  1036. return $blocks;
  1037. }
  1038. /**
  1039. * Implements hook_block_view().
  1040. */
  1041. function tripal_block_view($delta = ''){
  1042. global $base_path;
  1043. $block = array();
  1044. // The $delta parameter tells us which block is being requested.
  1045. switch ($delta) {
  1046. case 'powered_by_tripal':
  1047. $size = variable_get('powered_by_tripal_size', 'small');
  1048. $type = variable_get('powered_by_tripal_type', 'bw');
  1049. $image = 'powered_by_tripal_bw_small.png';
  1050. if ($size == 'small' and $type == 'col') {
  1051. $image = 'powered_by_tripal_small.png';
  1052. }
  1053. if ($size == 'large' and $type == 'bw') {
  1054. $image = 'powered_by_tripal_bw.png';
  1055. }
  1056. if ($size == 'large' and $type == 'col') {
  1057. $image = 'powered_by_tripal.png';
  1058. }
  1059. $block['title'] = '';
  1060. $block['content'] = array(
  1061. '#markup' => '<a href="http://tripal.info"><img border="0" src="' . $base_path . drupal_get_path('module', 'tripal') . '/theme/images/' . $image . '"></a>',
  1062. );
  1063. break;
  1064. case 'content_type_barchart':
  1065. // The number of content types
  1066. $entity_types = db_select('tripal_bundle', 'tb')
  1067. ->fields('tb')
  1068. ->execute()
  1069. ->fetchAll();
  1070. $entity_count_listing = array();
  1071. // The number of entities per content type.
  1072. foreach($entity_types as $entity_types => $entity_type){
  1073. $result = db_select('chado_' . $entity_type->name, 'et')
  1074. ->fields('et')
  1075. ->execute();
  1076. $number_of_entities = $result->rowCount();
  1077. $entity_count_listing[$entity_types] = array(
  1078. 'name' => $entity_type->label,
  1079. 'count' => $number_of_entities,
  1080. );
  1081. }
  1082. tripal_add_d3js();
  1083. drupal_add_js(drupal_get_path ('module', 'tripal') . '/theme/js/tripal.dashboard.js');
  1084. drupal_add_css(drupal_get_path ('module', 'tripal') . '/theme/css/tripal.dashboard.css');
  1085. drupal_add_library('system', 'drupal.collapse');
  1086. drupal_add_js("var entityCountListing = " . json_encode($entity_count_listing) . ";", array('type' => 'inline'));
  1087. $output = "<div id=\"tripal-entity-types\" class=\"tripal-entity-types-pane\">
  1088. <p>A list of the published Tripal content types and the number of each.</p>
  1089. <div id=\"tripal-entity-type-chart\"></div>
  1090. </div>";
  1091. $block['title'] = '';
  1092. $block['content'] = array(
  1093. '#markup' => $output,
  1094. );
  1095. break;
  1096. case 'notifications_block':
  1097. // Create your block content here
  1098. $block['content'] = '';
  1099. // Prepare table header
  1100. $header = array(
  1101. 'title' => array('data' => t('Title')),
  1102. 'details' => array('data' => t('Details')),
  1103. 'type' => array('data' => t('Type'), 'field' => 'tan.type'),
  1104. 'actions' => array('data' => t('Actions'))
  1105. );
  1106. $query = db_select('tripal_admin_notfications', 'tan')
  1107. ->extend('TableSort');
  1108. $results = $query->fields('tan')
  1109. ->condition('enabled', 1, '=')
  1110. ->orderByHeader($header)
  1111. ->execute()->fetchAll();
  1112. $rows = array();
  1113. foreach($results as $result){
  1114. $data['operation'] = ' | ';
  1115. $data['operation'] .= l(t('Dismiss Notification'), 'admin/disable/notification/' . $result->note_id);
  1116. $actions = unserialize($result->actions);
  1117. foreach($actions as $action){
  1118. $label = key($actions);
  1119. $link = $action;
  1120. }
  1121. $rows[] = array(
  1122. 'Title' => $result->title,
  1123. 'Details' => $result->details,
  1124. 'Type' => $result->type,
  1125. 'Actions' => l(t($label), $link) . $data['operation'],
  1126. );
  1127. }
  1128. if(!empty($rows)) {
  1129. //Number of records shown in per page
  1130. $per_page = 10;
  1131. $current_page = pager_default_initialize(count($rows), $per_page);
  1132. $chunks = array_chunk($rows, $per_page, TRUE);
  1133. // Output of table with the paging
  1134. $table = theme('table',
  1135. array(
  1136. "header" => $header,
  1137. "rows" => $chunks[ $current_page ],
  1138. "attributes" => array(),
  1139. "sticky" => TRUE,
  1140. "caption" => "",
  1141. "colgroups" => array(),
  1142. "empty" => t("No notifications.")
  1143. )
  1144. );
  1145. $table .= theme('pager', array('quantity', count($rows)));
  1146. $fieldset_table = array(
  1147. '#title' => t('Notifications'),
  1148. '#collapsed' => FALSE,
  1149. '#collapsible' => TRUE,
  1150. '#attributes' => array('class' => array('collapsible')),
  1151. '#children' => $table,
  1152. );
  1153. //return pager with limited number of records.
  1154. $block['content'] = theme('fieldset', array('element' => $fieldset_table));
  1155. }
  1156. else {
  1157. $block['content'] = 'There are no notifications at this time.';
  1158. }
  1159. $block['title'] = 'Tripal Administrative Notifications';
  1160. break;
  1161. }
  1162. return $block;
  1163. }
  1164. /**
  1165. * Implements hook_block_save().
  1166. */
  1167. function tripal_block_save($delta = '', $edit = array()) {
  1168. switch ($delta) {
  1169. case 'powered_by_tripal':
  1170. if (!empty($edit['logo_size'])) {
  1171. variable_set('powered_by_tripal_size', $edit['logo_size']);
  1172. }
  1173. if (!empty($edit['logo_type'])) {
  1174. variable_set('powered_by_tripal_type', $edit['logo_type']);
  1175. }
  1176. }
  1177. }
  1178. /**
  1179. * Implements hook_block_configure().
  1180. */
  1181. function tripal_block_configure($delta = '') {
  1182. $form = array();
  1183. switch ($delta) {
  1184. case 'powered_by_tripal':
  1185. $form['logo_size'] = array(
  1186. '#type' => 'radios',
  1187. '#title' => t('Logo Size'),
  1188. '#default_value' => variable_get('powered_by_tripal_size', 'small'),
  1189. '#options' => array(
  1190. 'large' => t('Large'),
  1191. 'small' => t('Small')
  1192. ),
  1193. '#description' => t('Select if you would like a small or large "Powered by Tripal" logo.'),
  1194. );
  1195. $form['logo_type'] = array(
  1196. '#type' => 'radios',
  1197. '#title' => t('Logo Type'),
  1198. '#default_value' => variable_get('powered_by_tripal_type', 'bw'),
  1199. '#options' => array(
  1200. 'bw' => t('Gray scale'),
  1201. 'col' => t('Colored')
  1202. ),
  1203. '#description' => t('Select if you would like a black and white or colored "Powered by Tripal" logo.'),
  1204. );
  1205. }
  1206. return $form;
  1207. }
  1208. /**
  1209. * Implements hook_cron().
  1210. */
  1211. function tripal_cron() {
  1212. // Add jobs to the Tripal queue for commong tasks.
  1213. $args = [];
  1214. $includes = [];
  1215. if (variable_get('tripal_admin_notification_creation_during_cron', TRUE)) {
  1216. $modules = module_implements('tripal_cron_notification');
  1217. foreach ($modules as $module) {
  1218. $function = $module . '_tripal_cron_notification';
  1219. tripal_add_job("Cron: Checking for '$module' notifications.", 'tripal', // Module Name
  1220. $function, $args, 1, 1, $includes, TRUE);
  1221. }
  1222. }
  1223. // Check for expired collections.
  1224. tripal_add_job('Cron: Checking expired collections', 'tripal',
  1225. 'tripal_expire_collections', $args, 1, 1, $includes, TRUE);
  1226. tripal_add_job('Cron: Checking expired files', 'tripal',
  1227. 'tripal_expire_files', $args, 1, 1, $includes, TRUE);
  1228. }
  1229. /**
  1230. * Implements hook_element_info().
  1231. *
  1232. * Used for creating new form API elements.
  1233. */
  1234. function tripal_element_info() {
  1235. // Element for uploading large files. This form element
  1236. // accepts the following keys when using in a form:
  1237. // - #title: The title that will appear above the element.
  1238. // - #description: The description that will appear below the element.
  1239. // - #usage_type: Required. The type of file. This will be stored in
  1240. // the 'type' column of the file_usage table.
  1241. // - #usage_id: Required. A unique numeric ID representing an entity, node
  1242. // or some other record identifier. This can be any identifier that
  1243. // makes sense to the module that implements a form that uses this
  1244. // element.
  1245. // -#usage_module: The module that will be using the file. This will be
  1246. // stored in the 'module' column of the file_usage table.
  1247. // -#allowed_types: An array of file extensions that are allowed for
  1248. // to be uploaded.
  1249. // -#cardinality: A numeric value indicating the number of files the
  1250. // user can upload. Set to 0 for unlimited.
  1251. $elements['html5_file'] = array(
  1252. '#input' => 'TRUE',
  1253. '#process' => array('tripal_html5_file_process'),
  1254. '#element_validate' => array('tripal_html5_file_validate'),
  1255. '#value_callback' => 'tripal_html5_file_value',
  1256. );
  1257. return $elements;
  1258. }
  1259. /**
  1260. * The process function for the html5_file form element.
  1261. */
  1262. function tripal_html5_file_process($element, $form_state, $complete_form) {
  1263. $module = array_key_exists('#usage_module', $element) ? $element['#usage_module'] : 'tripal';
  1264. $type = $element['#usage_id'] . '-' . $element['#usage_type'] . '-' . $module;
  1265. $type_var_name = 'uploader_' . $element['#usage_id'] . '_' . $element['#usage_type'] . '_' . $module;
  1266. $name = $element['#name'];
  1267. $name = preg_replace('/[^\w]/', '_', $name);
  1268. $allowed_types = array_key_exists('#allowed_types', $element) ? $element['#allowed_types'] : array();
  1269. $cardinality = array_key_exists('#cardinality', $element) ? $element['#cardinality'] : 1;
  1270. $paired = array_key_exists('#paired', $element) ? $element['#paired'] : FALSE;
  1271. if ($paired) {
  1272. $headers = array(
  1273. array('data' => 'File #1'),
  1274. array('data' => 'Size', 'width' => '10%'),
  1275. array('data' => 'Upload Progress', 'width' => '20%'),
  1276. array('data' => 'Action', 'width' => '10%'),
  1277. array('data' => 'File #2'),
  1278. array('data' => 'Size', 'width' => '10%'),
  1279. array('data' => 'Upload Progress', 'width' => '20%'),
  1280. array('data' => 'Action', 'width' => '10%')
  1281. );
  1282. }
  1283. else {
  1284. $headers = array(
  1285. array('data' => 'File'),
  1286. array('data' => 'Size', 'width' => '10%'),
  1287. array('data' => 'Upload Progress', 'width' => '20%'),
  1288. array('data' => 'Action', 'width' => '10%'),
  1289. );
  1290. }
  1291. $rows = array();
  1292. $table_vars = array(
  1293. 'header' => $headers,
  1294. 'rows' => $rows,
  1295. 'attributes' => array(
  1296. 'class' => array('tripal-html5-file-upload-table'),
  1297. 'id' => 'tripal-html5-file-upload-table-' . $type
  1298. ),
  1299. 'sticky' => TRUE,
  1300. 'colgroups' => array(),
  1301. 'empty' => t('There are currently no files.'),
  1302. );
  1303. $element['html5_file_table_key'] = array(
  1304. '#type' => 'hidden',
  1305. '#value' => $type,
  1306. '#attributes' => array(
  1307. 'class' => array('tripal-html5-file-upload-table-key')
  1308. )
  1309. );
  1310. $element['html5_file_table'] = array(
  1311. '#type' => 'item',
  1312. '#title' => $element['#title'] ? $element['#title'] : 'File Upload',
  1313. '#description' => $element['#description'],
  1314. '#markup' => theme('table', $table_vars)
  1315. );
  1316. $element[$name] = array(
  1317. '#type' => 'hidden',
  1318. '#attributes' => array('id' => 'tripal-html5-upload-fid-' . $type),
  1319. '#default_value' => $element['#value'],
  1320. );
  1321. $element['html5_file_submit'] = array(
  1322. '#type' => 'submit',
  1323. '#value' => 'Upload File',
  1324. '#name' => 'tripal_html5_file_upload_submit-' . $type,
  1325. // We don't want this button to submit as the file upload
  1326. // is handled by the JavaScript code.
  1327. '#attributes' => array(
  1328. 'id' => 'tripal-html5-file-upload-submit-' . $type,
  1329. 'onclick' => 'return (false);'
  1330. )
  1331. );
  1332. if (!$paired) {
  1333. $categories = array($element['#usage_id'] . '-' . $element['#usage_type']);
  1334. }
  1335. else {
  1336. $categories = array(
  1337. $element['#usage_id'] . '-' . $element['#usage_type'] . '-f',
  1338. $element['#usage_id'] . '-' . $element['#usage_type'] . '-r',
  1339. );
  1340. }
  1341. $uploader_settings = array(
  1342. 'table_id' => '#tripal-html5-file-upload-table-' . $type,
  1343. 'submit_id' => '#tripal-html5-file-upload-submit-' . $type,
  1344. 'category' => $categories,
  1345. 'cardinality' => $cardinality,
  1346. 'target_id' => 'tripal-html5-upload-fid-' . $type,
  1347. 'module' => $module,
  1348. 'allowed_types' => $allowed_types,
  1349. );
  1350. drupal_add_js(array($type_var_name => $uploader_settings), 'setting');
  1351. drupal_add_js(drupal_get_path ('module', 'tripal') . '/theme/js/TripalUploader.js');
  1352. drupal_add_js(drupal_get_path ('module', 'tripal') . '/theme/js/TripalUploadFile.js');
  1353. drupal_add_js(drupal_get_path ('module', 'tripal') . '/theme/js/tripal.file.js');
  1354. return $element;
  1355. }
  1356. /**
  1357. * Implements the validate hook for the html5_file form element.
  1358. */
  1359. function tripal_html5_file_validate($element, &$form_state) {
  1360. $is_required = $element['#required'];
  1361. $name = $element['#name'];
  1362. $name = preg_replace('/[^\w]/', '_', $name);
  1363. $fid = NULL;
  1364. if (is_array($element['#value']) and $array_key_exists($name, $element['#value'])) {
  1365. $fid = $element['#value'][$name];
  1366. }
  1367. // TODO: the fid should just be the $element['#value'] why isn't this
  1368. // working given the tripal_html5_file_value function below.
  1369. if ($is_required and !$fid) {
  1370. form_error($element, t('A file must be provided.'));
  1371. }
  1372. }
  1373. /**
  1374. * Implements hook_value() for the html5_file form element.
  1375. */
  1376. function tripal_html5_file_value($element, $input = FALSE, &$form_state) {
  1377. if ($input) {
  1378. if (is_array($input)) {
  1379. $name = $element['#name'];
  1380. $name = preg_replace('/[^\w]/', '_', $name);
  1381. return $input[$name];
  1382. }
  1383. else {
  1384. return $input;
  1385. }
  1386. }
  1387. }
  1388. /**
  1389. * Implements hook_field_display_alter().
  1390. *
  1391. * @param $display
  1392. * @param $context
  1393. */
  1394. function tripal_field_display_TripalEntity_alter(&$display, $context){
  1395. $field_name = $context['field']['field_name'];
  1396. $bundle = $context['entity']->bundle;
  1397. $bundle_info = tripal_load_bundle_entity(array('name' => $bundle));
  1398. // Hide fields that are empty, but only if the hide_empty_field variable
  1399. // is set to 'hide' for this bundel.
  1400. $hide_variable = tripal_get_bundle_variable('hide_empty_field', $bundle_info->id, 'hide');
  1401. if($hide_variable == 'hide'){
  1402. $item = field_get_items('TripalEntity', $context['entity'], $field_name);
  1403. if($item) {
  1404. $field = field_info_field($field_name);
  1405. if(tripal_field_is_empty($item[0], $field)) {
  1406. // Stop the right rail element from rendering.
  1407. drupal_add_css('.' . $field_name.' {display: none;}', 'inline');
  1408. }
  1409. }
  1410. }
  1411. }
  1412. /**
  1413. * Implements hook_field_group_table_rows_alter().
  1414. *
  1415. * This hook is used for hiding empty rows in a Field Group Table field group.
  1416. *
  1417. * @param $element
  1418. * The field group object.
  1419. * @param $children
  1420. * An array of field names that are contained in the field group.
  1421. */
  1422. function tripal_field_group_table_rows_alter(&$element, &$children) {
  1423. // Iterate through the children of this table field group.
  1424. foreach ($children as $index => $child) {
  1425. if (is_array($element[$child])) {
  1426. $bundle = $element[$child]['#bundle'];
  1427. $bundle_info = tripal_load_bundle_entity(array('name' => $bundle));
  1428. // If the hide empty variable is turned on then remove fields from
  1429. // the field group.
  1430. $hide_variable = tripal_get_bundle_variable('hide_empty_field', $bundle_info->id, 'hide');
  1431. if($hide_variable == 'hide'){
  1432. $items = $element[$child]['#items'];
  1433. // Case #1: there are no items.
  1434. if (count($items) == 0) {
  1435. unset($children[$index]);
  1436. unset($element[$child]);
  1437. }
  1438. // Case #2: there is one item but the value is empty.
  1439. if (count($items) == 1 and array_key_exists('value', $items[0]) and empty($items[0]['value'])) {
  1440. unset($children[$index]);
  1441. unset($element[$child]);
  1442. }
  1443. }
  1444. }
  1445. }
  1446. }