jeemod.module 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. <?php
  2. /**
  3. * Implements hook_menu().
  4. */
  5. function jeemod_menu() {
  6. $items = array();
  7. $base = array(
  8. 'type' => MENU_CALLBACK,
  9. 'file' => 'jeemod.pages.inc',
  10. );
  11. $items['jee/chapter'] = $base+array(
  12. 'title' => 'jee',
  13. 'page callback' => 'jeemod_chapter',
  14. 'page arguments' => array(2),
  15. 'access callback' => TRUE,
  16. // 'access arguments' => array('use materio search api'),
  17. );
  18. $items['jee/static'] = $base+array(
  19. 'title' => 'jee',
  20. 'page callback' => 'jeemod_static',
  21. // 'page arguments' => array(2),
  22. 'access callback' => TRUE,
  23. // 'access arguments' => array('use materio search api'),
  24. );
  25. return $items;
  26. }
  27. /**
  28. * Implements hook_entity_info_alter().
  29. */
  30. function jeemod_entity_info_alter(&$entity_info) {
  31. $entity_info['node']['view modes']['chapter'] = array(
  32. 'label' => t('chapter'),
  33. 'custom settings' => TRUE,
  34. );
  35. }
  36. /**
  37. * Implements hook_video_embed_field_handlers_alter().
  38. */
  39. function jeemod_video_embed_field_handlers_alter(&$handlers) {
  40. $handlers['vimeo']['function'] = 'jeemod_handle_vimeo';
  41. }
  42. /**
  43. * Wrapper function to allow forcing API to be enabled for Vimeo videos.
  44. */
  45. function jeemod_handle_vimeo($url, $settings) {
  46. // dsm($settings, 'settings');
  47. // dsm($url, 'url');
  48. $settings['api'] = 1;
  49. // $r = db_query("SELECT entity_id FROM {field_data_field_video} WHERE field_video_video_url = :url", array(
  50. // ':url' => $url
  51. // ));
  52. // foreach($r as $result){
  53. // $id = $result->entity_id;
  54. // }
  55. // $id =
  56. // $settings['player_id'] = "video".$id;
  57. // return video_embed_field_handle_vimeo($url, $settings);
  58. // needed to rewrite the whole output here
  59. // https://github.com/jrue/Vimeo-jQuery-API
  60. // Get ID of video from URL
  61. $vid = _video_embed_field_get_vimeo_id($url);
  62. if (!$vid) {
  63. return array(
  64. '#markup' => l($url, $url),
  65. );
  66. }
  67. // Construct the embed code
  68. $settings['portrait'] = 0;
  69. $width = $settings['width'];
  70. $height = $settings['height'];
  71. unset($settings['width']);
  72. unset($settings['height']);
  73. unset($settings['color']);
  74. unset($settings['portrait']);
  75. unset($settings['title']);
  76. unset($settings['byline']);
  77. unset($settings['autoplay']);
  78. unset($settings['loop']);
  79. $settings['player_id'] = "video-".uniqid();
  80. $settings_str = _video_embed_code_get_settings_str($settings);
  81. return array(
  82. '#markup' => '<iframe id="video'.$settings['player_id'].'" width="' . $width . '" height="' . $height . '" src="//player.vimeo.com/video/' . $vid .
  83. '?' . $settings_str . '" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowfullscreen></iframe>',
  84. );
  85. }
  86. /**
  87. * Implements hook_field_formatter_info().
  88. */
  89. function jeemod_field_formatter_info() {
  90. return array(
  91. 'share_butons' => array(
  92. 'label' => t('Share butons (Twitter, Facebook)'),
  93. 'field types' => array('text'),
  94. ),
  95. );
  96. }
  97. /**
  98. * Implements hook_field_formatter_view().
  99. */
  100. function jeemod_field_formatter_view($entity_type, $entity, $field, $instance, $lang_code, $items, $display) {
  101. $element = array();
  102. foreach ($items as $delta => $item) {
  103. $element[$delta] = array(
  104. '#theme' => 'jeemod_share_links',
  105. '#entity' => $entity,
  106. // '#url' => $entity->field_partager['und'][0]['url'],
  107. );
  108. }
  109. return $element;
  110. }
  111. /**
  112. * Implements hook_theme().
  113. */
  114. function jeemod_theme() {
  115. return array(
  116. 'jeemod_share_links' => array(
  117. 'template' => 'jeemod_share_links',
  118. 'variables' => array(
  119. 'entity' => NULL,
  120. // 'url' => NULL,
  121. ),
  122. ),
  123. );
  124. }
  125. function jeemod_preprocess_jeemod_share_links(&$vars){
  126. global $base_url;
  127. // dsm($vars);
  128. $entity = $vars['entity'];
  129. $sitetitle = variable_get('site_name', '');
  130. $nodetitle = $entity->title;
  131. $nodeurl = $base_url . url('node/'.$entity->nid);//$base_url . base_path() . "#principe-" . $entity->nid;
  132. $text = $nodetitle ." | ". $sitetitle . " - " . $nodeurl;
  133. $tags = explode(' ', str_replace('#', '', $entity->field_partager['und'][0]['value']));
  134. // twitter
  135. $vars['twitter_url'] = url("https://twitter.com/intent/tweet", array(
  136. 'absolute'=>true,
  137. 'query'=>array(
  138. // "button_hashtag"=>implode(',',$tags),
  139. "button_hashtag"=>$tags[0],
  140. "text"=>$text,
  141. )
  142. ));
  143. $vars['twitter_title'] = "Twitter $nodetitle";
  144. // face book
  145. $vars['fb_url'] = url("https://www.facebook.com/sharer.php", array(
  146. 'absolute'=>true,
  147. 'query'=>array(
  148. "u"=>$nodeurl,
  149. "t"=>$text,
  150. )
  151. ));
  152. $vars['fb_title'] = "Partager $nodetitle";
  153. // mail
  154. // $vars['mail_url'] = "mailto:?subject=$nodetitle&body=$text";
  155. $vars['mail_url'] = url("mailto:", array(
  156. 'absolute'=>true,
  157. 'query'=>array(
  158. "subject"=>$text,
  159. "body"=>$text,
  160. )
  161. ));
  162. $vars['mail_title'] = "Envoyer par email $nodetitle";
  163. }