profile_fields.inc 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <?php
  2. if (module_exists('profile') && !(defined('MAINTENANCE_MODE') && MAINTENANCE_MODE == 'update') && !is_null(profile_user_categories())) {
  3. /**
  4. * Plugins are described by creating a $plugin array which will be used
  5. * by the system that includes this file.
  6. */
  7. $plugin = array(
  8. 'single' => TRUE,
  9. 'title' => t('Profile category'),
  10. 'icon' => 'icon_user.png',
  11. 'description' => t('Contents of a single profile category.'),
  12. 'required context' => new ctools_context_required(t('User'), 'user'),
  13. 'category' => t('User'),
  14. 'defaults' => array('category' => '', 'empty' => ''),
  15. 'hook theme' => 'ctools_profile_fields_content_type_theme',
  16. );
  17. }
  18. /**
  19. * 'Render' callback for the 'profile fields' content type.
  20. */
  21. function ctools_profile_fields_content_type_render($subtype, $conf, $panel_args, $context) {
  22. $account = isset($context->data) ? clone $context->data : NULL;
  23. $block = new stdClass();
  24. $block->module = 'profile fields';
  25. if ($account) {
  26. // Get the category from the options
  27. $category = str_replace("_", " ", $conf['category']);
  28. // Set the subject to the name of the category
  29. $block->subject = $category;
  30. // Put all the fields in the category into an array
  31. profile_view_profile($account);
  32. if (is_array($account->content[$category])) {
  33. foreach ($account->content[$category] as $field) {
  34. if (is_array($field['#attributes'])) {
  35. // @todo 'class' is *always* an array now. 04/10/2009 sun
  36. $vars[$field['#attributes']['class']]['title'] = $field['#title'];
  37. $vars[$field['#attributes']['class']]['value'] = $field['#value'];
  38. }
  39. }
  40. }
  41. if (count($vars) == 0) {
  42. // Output the given empty text
  43. $output = $conf['empty'];
  44. }
  45. else {
  46. // Call the theme function with the field vars
  47. $output = theme('profile_fields_pane', $category, $vars);
  48. }
  49. $block->content = $output;
  50. $block->delta = $account->uid;
  51. }
  52. else {
  53. $block->subject = $conf['category'];
  54. $block->content = t('Profile content goes here.');
  55. $block->delta = 'unknown';
  56. }
  57. return $block;
  58. }
  59. /**
  60. * Helper function : build the list of categories for the 'edit' form.
  61. */
  62. function _ctools_profile_fields_options() {
  63. $cat_list = array();
  64. $categories = profile_categories();
  65. foreach ($categories as $key => $value) {
  66. $cat_list[str_replace(" ", "_", $value['name'])] = $value['title'];
  67. }
  68. return $cat_list;
  69. }
  70. /**
  71. * 'Edit' callback for the 'profile fields' content type.
  72. */
  73. function ctools_profile_fields_content_type_edit_form($form, &$form_state) {
  74. $conf = $form_state['conf'];
  75. $form['category'] = array(
  76. '#type' => 'radios',
  77. '#title' => t('Which category'),
  78. '#options' => _ctools_profile_fields_options(),
  79. '#default_value' => $conf['category'],
  80. '#prefix' => '<div class="clearfix no-float">',
  81. '#suffix' => '</div>',
  82. );
  83. $form['empty'] = array(
  84. '#type' => 'textarea',
  85. '#title' => 'Empty text',
  86. '#description' => t('Text to display if category has no data. Note that title will not display unless overridden.'),
  87. '#rows' => 5,
  88. '#default_value' => $conf['empty'],
  89. '#prefix' => '<div class="clearfix no-float">',
  90. '#suffix' => '</div>',
  91. );
  92. return $form;
  93. }
  94. function ctools_profile_fields_content_type_edit_form_submit($form, &$form_state) {
  95. // Copy everything from our defaults.
  96. foreach (array_keys($form_state['plugin']['defaults']) as $key) {
  97. $form_state['conf'][$key] = $form_state['values'][$key];
  98. }
  99. }
  100. /**
  101. * 'Title' callback for the 'profile fields' content type.
  102. */
  103. function ctools_profile_fields_content_type_admin_title($subtype, $conf, $context) {
  104. return t('"@s" profile fields', array('@s' => $conf['category']));
  105. }
  106. function ctools_profile_fields_content_type_theme(&$theme, $plugin) {
  107. $theme['profile_fields_pane'] = array(
  108. 'variables' => array('category' => NULL, 'vars' => NULL),
  109. 'path' => $plugin['path'],
  110. 'template' => 'profile_fields_pane',
  111. );
  112. }