cis_shortcodes.module

  1. cis7 sites/all/modules/elmsln_contrib/cis_connector/modules/cis_shortcodes/cis_shortcodes.module
  2. cle7 sites/all/modules/elmsln_contrib/cis_connector/modules/cis_shortcodes/cis_shortcodes.module
  3. ecd7 sites/all/modules/elmsln_contrib/cis_connector/modules/cis_shortcodes/cis_shortcodes.module
  4. elmsmedia7 sites/all/modules/elmsln_contrib/cis_connector/modules/cis_shortcodes/cis_shortcodes.module
  5. harmony7 sites/all/modules/elmsln_contrib/cis_connector/modules/cis_shortcodes/cis_shortcodes.module
  6. icor7 sites/all/modules/elmsln_contrib/cis_connector/modules/cis_shortcodes/cis_shortcodes.module
  7. meedjum_blog7 sites/all/modules/elmsln_contrib/cis_connector/modules/cis_shortcodes/cis_shortcodes.module
  8. mooc7 sites/all/modules/elmsln_contrib/cis_connector/modules/cis_shortcodes/cis_shortcodes.module

Handle shortcode generation for use in sites running cis_filter.

Functions

Namesort descending Description
cis_shortcodes_entity_view Implements hook_entity_view().
cis_shortcodes_permission Implements hook_permission().
_cis_shortcodes_add_js Helper function to ensure js is added with form element.
_cis_shortcodes_build_code Helper to return a built code from properties

Constants

Namesort descending Description
CIS_SHORTCODES_API_REV @file Handle shortcode generation for use in sites running cis_filter.

File

sites/all/modules/elmsln_contrib/cis_connector/modules/cis_shortcodes/cis_shortcodes.module
View source
  1. <?php
  2. /**
  3. * @file
  4. * Handle shortcode generation for use in sites running cis_filter.
  5. */
  6. define('CIS_SHORTCODES_API_REV', 1);
  7. /**
  8. * Implements hook_permission().
  9. */
  10. function cis_shortcodes_permission() {
  11. return array(
  12. 'view cis shortcode' => array(
  13. 'title' => t('View CIS Shortcode'),
  14. 'description' => t('View shortcodes provided on entity displays'),
  15. ),
  16. );
  17. }
  18. /**
  19. * Implements hook_entity_view().
  20. */
  21. function cis_shortcodes_entity_view($entity, $type, $view_mode, $langcode) {
  22. $links = array();
  23. // only add embed methods on full view with access
  24. if ($view_mode == 'full' && user_access('view cis shortcode')) {
  25. // pick a nice default title for common entity types
  26. $title = '';
  27. switch ($type) {
  28. case 'node':
  29. $title = $entity->title;
  30. break;
  31. case 'user':
  32. case 'taxonomy_term':
  33. $title = $entity->name;
  34. break;
  35. }
  36. // load info so we know what the key id is
  37. $type_info = entity_get_info($type);
  38. // build properties array for rendering
  39. $properties = array(
  40. 'rev' => CIS_SHORTCODES_API_REV,
  41. 'tool' => variable_get('install_profile', ''),
  42. 'item' => $entity->{$type_info['entity keys']['id']},
  43. );
  44. // only append type for non-node entities
  45. if ($type != 'node') {
  46. $properties['entity_type'] = $type;
  47. }
  48. // establish the fieldset container for shortcodes
  49. $field['cis_shortcodes'] = array(
  50. '#type' => 'fieldset',
  51. '#collapsed' => FALSE,
  52. '#collapsible' => TRUE,
  53. '#title' => t('Short Codes to embed'),
  54. '#weight' => -10,
  55. );
  56. if (module_exists('entity_iframe') && _entity_iframe_view_iframe($type, $entity->{$type_info['entity keys']['id']})) {
  57. $field['cis_shortcodes']['cis_shortcodes_embed'] = array(
  58. '#title' => t('Shortcode direct iframe'),
  59. '#attributes' => array('class' => array('cis_shortcodes_embed')),
  60. '#value' => _cis_shortcodes_build_code($properties),
  61. '#type' => 'textfield',
  62. '#pre_render' => array('_cis_shortcodes_add_js'),
  63. '#weight' => 1,
  64. );
  65. }
  66. $properties['render'] = 'link';
  67. if (isset($type_info['bundle keys']['bundle']) && !empty($entity->{$type_info['bundle keys']['bundle']})) {
  68. $field_list = field_info_instances($type, $entity->{$type_info['bundle keys']['bundle']});
  69. }
  70. else if (isset($type_info['entity keys']['bundle']) && !empty($entity->{$type_info['entity keys']['bundle']})){
  71. $field_list = field_info_instances($type, $entity->{$type_info['entity keys']['bundle']});
  72. }
  73. else {
  74. // skip this, we don't have info about this type
  75. $field_list = array();
  76. }
  77. foreach ($field_list as $fname => $fproperties) {
  78. // check for things with uri's, if first item is, all are
  79. if (isset($entity->{$fname}) && isset($entity->{$fname}['und'][0]['uri'])) {
  80. foreach ($entity->{$fname}['und'] as $item_key => $item) {
  81. $properties['field'] = $fname;
  82. if ($type == 'node') {
  83. $properties['text'] = t('Download @title', array('@title' => $title));
  84. }
  85. else {
  86. $properties['text'] = t('Download');
  87. }
  88. $properties['delta'] = $item_key;
  89. $field['cis_shortcodes']['cis_shortcodes_link_' . $fname . '_' . $item_key] = array(
  90. '#title' => t('@field field: direct link', array('@field' => $fproperties['label'])),
  91. '#attributes' => array('class' => array('cis_shortcodes_embed')),
  92. '#value' => _cis_shortcodes_build_code($properties),
  93. '#type' => 'textfield',
  94. '#weight' => 3,
  95. );
  96. // special case for uri's that are images
  97. if (isset($item['filemime']) && strpos($item['filemime'], 'image') === 0) {
  98. $properties['item_type'] = 'image';
  99. // support custom title and alt text in the code
  100. if (!empty($item['title'])) {
  101. $properties['text'] = $title;
  102. }
  103. else {
  104. $properties['text'] = $title;
  105. }
  106. if (!empty($item['alt'])) {
  107. $properties['alt'] = $item['alt'];
  108. }
  109. else {
  110. $properties['alt'] = $title;
  111. }
  112. // use image as it was uploaded for defaults
  113. $properties['width'] = $item['width'];
  114. $properties['height'] = $item['height'];
  115. $properties['delta'] = $item_key;
  116. $field['cis_shortcodes']['cis_shortcodes_link_' . $fname . '_' . $item_key] = array(
  117. '#title' => t('@field field: Render image', array('@field' => $fproperties['label'])),
  118. '#attributes' => array('class' => array('cis_shortcodes_embed')),
  119. '#value' => _cis_shortcodes_build_code($properties),
  120. '#type' => 'textfield',
  121. '#weight' => 3,
  122. );
  123. }
  124. }
  125. }
  126. }
  127. // check for unique tag capabilities
  128. if (isset($entity->field_cis_tag) && isset($entity->field_cis_tag['und'])) {
  129. // reset property array
  130. $properties = array(
  131. 'rev' => CIS_SHORTCODES_API_REV,
  132. 'tool' => variable_get('install_profile', ''),
  133. 'item' => $entity->{$type_info['entity keys']['id']},
  134. );
  135. // only append type for non-node entities
  136. if ($type != 'node') {
  137. $properties['entity_type'] = $type;
  138. }
  139. $properties['item'] = $entity->field_cis_tag['und'][0]['value'];
  140. $properties['item_type'] = 'tag';
  141. if (module_exists('entity_iframe') && _entity_iframe_view_iframe($type, $entity->{$type_info['entity keys']['id']})) {
  142. $field['cis_shortcodes']['cis_shortcodes_tag_iframe'] = array(
  143. '#title' => t('Shortcode tagged iframe'),
  144. '#attributes' => array('class' => array('cis_shortcodes_embed')),
  145. '#value' => _cis_shortcodes_build_code($properties),
  146. '#type' => 'textfield',
  147. '#weight' => 2,
  148. );
  149. }
  150. $properties['render'] = 'link';
  151. $field['cis_shortcodes']['cis_shortcodes_tag_link'] = array(
  152. '#title' => t('Shortcode tagged link'),
  153. '#attributes' => array('class' => array('cis_shortcodes_embed')),
  154. '#value' => _cis_shortcodes_build_code($properties),
  155. '#type' => 'textfield',
  156. '#weight' => 4,
  157. );
  158. }
  159. // only render if we actually have data to display
  160. if (count($field['cis_shortcodes']) > 5) {
  161. $entity->content['cis_shortcodes'] = array(
  162. '#markup' => drupal_render($field),
  163. '#weight' => 100,
  164. );
  165. }
  166. }
  167. }
  168. /**
  169. * Helper function to ensure js is added with form element.
  170. */
  171. function _cis_shortcodes_add_js($form) {
  172. // add js as we know we'll have a code on the page
  173. drupal_add_js(drupal_get_path('module', 'cis_shortcodes') . '/cis_shortcodes.js');
  174. return $form;
  175. }
  176. /**
  177. * Helper to return a built code from properties
  178. *
  179. * @param $properties
  180. * a keyed array of properties used to generate a shortcode.
  181. * @return string
  182. * a string representation of the properties as a shortcode.
  183. */
  184. function _cis_shortcodes_build_code($properties) {
  185. $ary = array();
  186. foreach ($properties as $key => $val) {
  187. $ary[] = $key . '=' . $val;
  188. }
  189. return '[ciscode|' . implode('|', $ary) . ']';
  190. }
Error | ELMSLN API

Error

×

Error message

  • Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/elmsln_community/api.elmsln.org/includes/common.inc:2791) in drupal_send_headers() (line 1499 of /var/www/html/elmsln_community/api.elmsln.org/includes/bootstrap.inc).
  • Error: Call to undefined function apc_delete() in DrupalAPCCache->clear() (line 289 of /var/www/html/elmsln_community/api.elmsln.org/sites/all/modules/apc/drupal_apc_cache.inc).
The website encountered an unexpected error. Please try again later.