tripal.module 53 KB

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