tripal.module 52 KB

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