theme.inc 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. <?php
  2. /**
  3. * @file
  4. * Contains various theme functions for Piecemaker API
  5. */
  6. /**
  7. * Themes the actuall Piecemaker element
  8. *
  9. * @param $vars
  10. * An array that contains the handler, key, profile array, and alternate content callback function
  11. */
  12. function theme_piecemaker($vars) {
  13. $settings = &drupal_static('theme_piecemaker_settings');
  14. $ids = &drupal_static(__FUNCTION__, array());
  15. $handler = $vars['handler'];
  16. $key = $vars['key'];
  17. $profile = $vars['profile'];
  18. $alternate_callback = $vars['alternate_callback'];
  19. if (is_object($profile)) {
  20. //Cast the profile to an array to make it easier to use
  21. $profile = (array) $profile;
  22. }
  23. $id = 'piecemaker-' . $handler . '-' . $key;
  24. $i = 0;
  25. while (in_array($id, $ids)) {
  26. //Ensure we have a unique html ID to use.
  27. $id .= '-' . $i;
  28. $i++;
  29. }
  30. //Store this id
  31. $ids[] = $id;
  32. $pm_path = libraries_get_path('piecemaker');
  33. $path = drupal_get_path('module', 'piecemaker');
  34. //Add The JS we need
  35. drupal_add_js($pm_path . '/swfobject/swfobject.js');
  36. drupal_add_js($path . '/js/Piecemaker.js', JS_THEME);
  37. $settings['Piecemaker_URI'] = base_path() . $pm_path;
  38. $settings['Piecemaker'][$id] = array(
  39. 'id' => $id,
  40. 'flashvars' => array(
  41. 'xmlSource' => base_path() . "piecemaker/{$handler}/{$key}/settings.xml",
  42. 'cssSource' => base_path() . $profile['flash_settings']['flashvars']['cssSource'],
  43. ),
  44. 'width' => $profile['flash_settings']['width'],
  45. 'height' => $profile['flash_settings']['height'],
  46. );
  47. $settings['Piecemaker'][$id]['params'] = $profile['flash_settings']['params'];
  48. $alternate = '<p>You do not have flash enabled</p>';
  49. if (function_exists($alternate_callback)) {
  50. $alternate = call_user_func_array($alternate_callback, $vars);
  51. }
  52. $out = "<div id=\"{$id}\" class=\"piecemaker piecemaker-{$handler} piecemaker-{$handler}-{$key}\">
  53. {$alternate}
  54. </div>";
  55. return $out;
  56. }
  57. /**
  58. * Themes the tranistion add/delete protion of the proile form
  59. */
  60. function theme_piecemaker_transition_form($vars) {
  61. $form = $vars['form'];
  62. $tvars['header'] = array(
  63. t('Effect'),
  64. t('Weight'),
  65. t('Pieces'),
  66. t('Time'),
  67. t('Delay'),
  68. t('Depth Offset'),
  69. t('Cube Distance'),
  70. t('Add/Delete')
  71. );
  72. foreach(element_children($form) as $key) {
  73. $row = array();
  74. if ($key === 'add') {
  75. //We need to create a item list that will be appended to the bottom of the form
  76. //since the descriptions are getting too big for the table and break the layout
  77. $head = $tvars['header'];
  78. $items[] = array_shift($head) . ': ' . $form[$key]['Transition']['#description'];
  79. unset($form[$key]['Transition']['#description']);
  80. array_shift($head); //To get rid of the weight column
  81. $items[] = array_shift($head) . ': ' . $form[$key]['Pieces']['#description'];
  82. unset($form[$key]['Pieces']['#description']);
  83. $items[] = array_shift($head) . ': ' . $form[$key]['Time']['#description'];
  84. unset($form[$key]['Time']['#description']);
  85. $items[] = array_shift($head) . ': ' . $form[$key]['Delay']['#description'];
  86. unset($form[$key]['Delay']['#description']);
  87. $items[] = array_shift($head) . ': ' . $form[$key]['DepthOffset']['#description'];
  88. unset($form[$key]['DepthOffset']['#description']);
  89. $items[] = array_shift($head) . ': ' . $form[$key]['CubeDistance']['#description'];
  90. unset($form[$key]['CubeDistance']['#description']);
  91. }
  92. $row[] = drupal_render($form[$key]['Transition']);
  93. $row[] = drupal_render($form[$key]['weight']);
  94. $row[] = drupal_render($form[$key]['Pieces']);
  95. $row[] = drupal_render($form[$key]['Time']);
  96. $row[] = drupal_render($form[$key]['Delay']);
  97. $row[] = drupal_render($form[$key]['DepthOffset']);
  98. $row[] = drupal_render($form[$key]['CubeDistance']);
  99. $row[] = drupal_render($form[$key]['action']);
  100. $tvars['rows'][] = array(
  101. 'data' => $row,
  102. 'class' => array('draggable'),
  103. );
  104. }
  105. $tvars['attributes'] = array(
  106. 'id' => 'piecemaker-transitions',
  107. 'class' => array('no-sticky'),
  108. );
  109. //Sticky headers don't work with draggable tables.
  110. $tvars['sticky'] = FALSE;
  111. $fieldset = array(
  112. '#type' => 'fieldset',
  113. '#title' => 'Field Descriptions',
  114. '#collapsible' => TRUE,
  115. '#collapsed' => TRUE,
  116. );
  117. $fieldset['list']['#markup'] = theme('item_list', array('items' => $items));
  118. drupal_add_tabledrag('piecemaker-transitions', 'order', 'sibling', 'trans-weight');
  119. return theme('table', $tvars) . drupal_render($fieldset);
  120. }
  121. /**
  122. * Themes the flash params protion of the proile form
  123. */
  124. function theme_piecemaker_profile_params($vars) {
  125. $form = $vars['form'];
  126. $add = drupal_render($form['add']);
  127. foreach(element_children($form) as $key) {
  128. $row = array();
  129. $row[] = drupal_render($form[$key]['key']);
  130. $row[] = drupal_render($form[$key]['value']);
  131. $tvars['rows'][] = $row;
  132. }
  133. $tvars['header'] = array(
  134. t('Key'),
  135. t('Value'),
  136. );
  137. $tvars['attributes'] = array(
  138. 'id' => 'piecemaker-params',
  139. );
  140. return theme('table', $tvars) . $add;
  141. }