PageRenderTime 26ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/profiles/drupal_commons/themes/commons_roots/template.php

https://bitbucket.org/postal/stratv2
PHP | 383 lines | 294 code | 38 blank | 51 comment | 64 complexity | 2acd809353dcb47c540d392bc4cb424d MD5 | raw file
Possible License(s): BSD-3-Clause, GPL-2.0, LGPL-2.1
  1. <?php
  2. // $Id: template.php 8021 2010-10-19 13:01:34Z sheena $
  3. /**
  4. * Breadcrumb themeing
  5. */
  6. function commons_roots_breadcrumb($breadcrumb) {
  7. if (!empty($breadcrumb)) {
  8. return '<div class="breadcrumb">'. implode(' > ', $breadcrumb) .'</div>';
  9. }
  10. }
  11. /**
  12. * Node preprocessing
  13. */
  14. function commons_roots_preprocess_node(&$vars) {
  15. // Only build custom submitted information if it was first available
  16. // If it's not, that indicates that it's been turned off for this
  17. // node type
  18. if ($vars['submitted']) {
  19. // Load the node author
  20. $author = user_load($vars['node']->uid);
  21. // Author picture
  22. if (theme_get_setting('toggle_node_user_picture')) {
  23. $picture = $vars['picture'];
  24. unset($vars['picture']);
  25. $submitted = ($author->uid && user_access('access user profiles')) ? l($picture, "user/{$author->uid}", array('html' => TRUE)) : $picture;
  26. }
  27. // Author information
  28. $submitted .= '<span class="submitted-by">';
  29. $submitted .= t('Submitted by !name', array('!name' => theme('username', $author)));
  30. $submitted .= '</span>';
  31. // User points
  32. if ($author->uid && module_exists('userpoints')) {
  33. $points = userpoints_get_current_points($author->uid);
  34. $submitted .= '<span class="userpoints-value" title="' . t('!val user points', array('!val' => $points)) . '">';
  35. $submitted .= "({$points})";
  36. $submitted .= '</span>';
  37. }
  38. // User badges
  39. if ($author->uid && module_exists('user_badges')) {
  40. if (is_array($author->badges)) {
  41. foreach ($author->badges as $badge) {
  42. $badges[] = theme('user_badge', $badge, $author);
  43. }
  44. }
  45. if (!empty($badges)) {
  46. $submitted .= theme('user_badge_group', $badges);
  47. }
  48. }
  49. // Created time
  50. $submitted .= '<span class="submitted-on">';
  51. $submitted .= format_date($vars['node']->created);
  52. $submitted .= '</span>';
  53. $vars['submitted'] = $submitted;
  54. }
  55. }
  56. /**
  57. * Page preprocessing
  58. */
  59. function commons_roots_preprocess_page(&$vars) {
  60. // Format the footer message
  61. // We do this here instead of in page.tpl.php because
  62. // we need a formatted message to pass along to the
  63. // same theme function as the $footer in order to have
  64. // them nested together
  65. if (isset($vars['footer_message']) && strlen($vars['footer_message'])) {
  66. $markup = '';
  67. $markup .= '<div id="footer-message" class="footer-message">';
  68. $markup .= '<div id="footer-message-inner" class="footer-message-inner inner">';
  69. $markup .= $vars['footer_message'];
  70. $markup .= '</div><!-- /footer-message-inner -->';
  71. $markup .= '</div><!-- /footer-message -->';
  72. $vars['footer_message'] = $markup;
  73. }
  74. }
  75. /**
  76. * Comment preprocessing
  77. */
  78. function commons_roots_preprocess_comment(&$vars) {
  79. global $user;
  80. static $comment_odd = TRUE; // Comment is odd or even
  81. // Build array of handy comment classes
  82. $comment_classes = array();
  83. $comment_classes[] = $comment_odd ? 'odd' : 'even';
  84. $comment_odd = !$comment_odd;
  85. $comment_classes[] = ($vars['comment']->status == COMMENT_NOT_PUBLISHED) ? 'comment-unpublished' : ''; // Comment is unpublished
  86. $comment_classes[] = ($vars['comment']->new) ? 'comment-new' : ''; // Comment is new
  87. $comment_classes[] = ($vars['comment']->uid == 0) ? 'comment-by-anon' : ''; // Comment is by anonymous user
  88. $comment_classes[] = ($user->uid && $vars['comment']->uid == $user->uid) ? 'comment-mine' : ''; // Comment is by current user
  89. $node = node_load($vars['comment']->nid); // Comment is by node author
  90. $vars['author_comment'] = ($vars['comment']->uid == $node->uid) ? TRUE : FALSE;
  91. $comment_classes[] = ($vars['author_comment']) ? 'comment-by-author' : '';
  92. $comment_classes = array_filter($comment_classes); // Remove empty elements
  93. $vars['comment_classes'] = implode(' ', $comment_classes); // Create class list separated by spaces
  94. // Date & author
  95. $ago = t('!interval ago', array('!interval' => format_interval(time() - $vars['comment']->timestamp)));
  96. $submitted_by = '<span class="comment-name">' . theme('username', $vars['comment']) . '</span>';
  97. $submitted_by .= '<span class="comment-date">' . $ago . '</span>'; // Format date as small, medium, or large
  98. $vars['submitted'] = $submitted_by;
  99. // Picture
  100. if (theme_get_setting('toggle_comment_user_picture')) {
  101. if (!$vars['comment']->picture && (variable_get('user_picture_default', '') != '')) {
  102. $vars['comment']->picture = variable_get('user_picture_default', '');
  103. }
  104. if ($vars['comment']->picture) {
  105. $picture = theme_imagecache('user_picture_meta', $vars['comment']->picture, $vars['comment']->name, $vars['comment']->name);
  106. if (user_access('access user profiles')) {
  107. $vars['comment']->picture = l($picture, "user/{$vars['comment']->uid}", array('html' => TRUE));
  108. }
  109. else {
  110. $vars['comment']->picture = $picture;
  111. }
  112. }
  113. }
  114. else {
  115. unset($vars['comment']);
  116. }
  117. }
  118. /**
  119. * Profile preprocessing
  120. */
  121. function commons_roots_preprocess_user_profile_item(&$vars) {
  122. // Separate userpoints value from the edit links
  123. if ($vars['title'] == 'Points') {
  124. $userpoints = explode(' - ', $vars['value']);
  125. $vars['value'] = '<span class="points">' . $userpoints[0] . '</span><span class="edit-links">' . $userpoints[1] . '</span>';
  126. unset($vars['title']);
  127. }
  128. }
  129. /**
  130. * Implementation of theme_shoutbox_post()
  131. */
  132. function commons_roots_shoutbox_post($shout, $links = array(), $alter_row_color=TRUE) {
  133. global $user;
  134. // Gather moderation links
  135. if ($links) {
  136. foreach ($links as $link) {
  137. $linkattributes = $link['linkattributes'];
  138. $link_html = '<img src="'. $link['img'] .'" width="'. $link['img_width'] .'" height="'. $link['img_height'] .'" alt="'. $link['title'] .'" class="shoutbox-imglink"/>';
  139. $link_url = 'shout/'. $shout->shout_id .'/'. $link['action'];
  140. $img_links = l($link_html, $link_url, array('html' => TRUE, 'query' => array('destination' => drupal_get_path_alias($_GET['q'])))) . $img_links;
  141. }
  142. }
  143. // Generate user name with link
  144. $user_name = shoutbox_get_user_link($shout);
  145. // Generate title attribute
  146. $title = t('Posted !date at !time by !name', array('!date' => format_date($shout->created, 'custom', 'm/d/y'), '!time' => format_date($shout->created, 'custom', 'h:ia'), '!name' => $shout->nick));
  147. // Add to the shout classes
  148. $shout_classes = array();
  149. $shout_classes[] = 'shoutbox-msg';
  150. // Check for moderation
  151. if ($shout->moderate == 1) {
  152. $shout_classes[] = 'shoutbox-unpublished';
  153. $approval_message = '&nbsp;(' . t('This shout is waiting for approval by a moderator.') . ')';
  154. }
  155. // Check for specific user class
  156. $user_classes = array();
  157. $user_classes[] = 'shoutbox-user-name';
  158. if ($shout->uid == $user->uid) {
  159. $user_classes[] = 'shoutbox-current-user-name';
  160. }
  161. else if ($shout->uid == 0) {
  162. $user_classes[] = 'shoutbox-anonymous-user';
  163. }
  164. // Load user image and format
  165. $author_picture ='';
  166. $shout_author = user_load($shout->uid);
  167. if (!$shout_author->picture && variable_get('user_picture_default', '')) {
  168. $shout_author->picture = variable_get('user_picture_default', '');
  169. }
  170. if ($shout_author->picture) {
  171. $author_picture = theme_imagecache('user_picture_meta', $shout_author->picture, $shout_author->name, $shout_author->name);
  172. }
  173. // Time format
  174. $format = variable_get('shoutbox_time_format', 'ago');
  175. switch ($format) {
  176. case 'ago';
  177. $submitted = t('!interval ago', array('!interval' => format_interval(time() - $shout->created)));
  178. break;
  179. case 'small':
  180. case 'medium':
  181. case 'large':
  182. $submitted = format_date($shout->created, $format);
  183. break;
  184. }
  185. // Build the post
  186. $post = '';
  187. $post .= '<div class="' . implode(' ', $shout_classes) . '" title="' . $title . '">';
  188. $post .= '<div class="shoutbox-admin-links">' . $img_links . '</div>';
  189. $post .= '<div class="shoutbox-post-info">' . $author_picture;
  190. $post .= '<span class="shoutbox-user-name ' . implode(' ', $user_classes) . '">'. $user_name . '</span>';
  191. $post .= '<span class="shoutbox-msg-time">' . $submitted . '</span>';
  192. $post .= '</div>';
  193. $post .= '<div class="shout-message">' . $shout->shout . $approval_message . '</div>';
  194. $post .= '</div>' . "\n";
  195. return $post;
  196. }
  197. function commons_roots_item_list($items = array(), $title = NULL, $type = 'ul', $attributes = NULL) {
  198. $output = '<div class="item-list">';
  199. if (isset($title)) {
  200. $output .= '<h3>'. $title .'</h3>';
  201. }
  202. if (!empty($items)) {
  203. $output .= "<$type". drupal_attributes($attributes) .'>';
  204. $num_items = count($items);
  205. $c = $num_items;
  206. foreach ($items as $i => $item) {
  207. $c--;
  208. $attributes = array();
  209. $children = array();
  210. if (is_array($item)) {
  211. foreach ($item as $key => $value) {
  212. if ($key == 'data') {
  213. $data = $value;
  214. }
  215. elseif ($key == 'children') {
  216. $children = $value;
  217. }
  218. else {
  219. $attributes[$key] = $value;
  220. }
  221. }
  222. }
  223. else {
  224. $data = $item;
  225. }
  226. if (!is_numeric($i)) {
  227. if (count($children) > 0) {
  228. $data .= theme_item_list($children, NULL, $type, $attributes); // Render nested list
  229. }
  230. if ($c == $num_items - 1) {
  231. $attributes['class'] = empty($attributes['class']) ? 'first' : ($attributes['class'] .' first');
  232. }
  233. if ($c == 0) {
  234. $attributes['class'] = empty($attributes['class']) ? 'last' : ($attributes['class'] .' last');
  235. }
  236. $attributes['class'] .= ' ' . ($c % 2 ? 'even' : 'odd');
  237. $output .= '<li'. drupal_attributes($attributes) .'>'. $data ."</li>\n";
  238. }
  239. else {
  240. if (count($children) > 0) {
  241. $data .= theme_item_list($children, NULL, $type, $attributes); // Render nested list
  242. }
  243. if ($i == 0) {
  244. $attributes['class'] = empty($attributes['class']) ? 'first' : ($attributes['class'] .' first');
  245. }
  246. if ($i == $num_items - 1) {
  247. $attributes['class'] = empty($attributes['class']) ? 'last' : ($attributes['class'] .' last');
  248. }
  249. $attributes['class'] .= ' ' . ($i % 2 ? 'even' : 'odd');
  250. $output .= '<li'. drupal_attributes($attributes) .'>'. $data ."</li>\n";
  251. }
  252. }
  253. $output .= "</$type>";
  254. }
  255. $output .= '</div>';
  256. return $output;
  257. }
  258. function commons_roots_preprocess_block($variables) {
  259. $variables['template_files'][] = 'block-'.$variables['block']->region.'-'.$variables['block']->module;
  260. $variables['template_files'][] = 'block-'.$variables['block']->region.'-'.$variables['block']->module.'-'.$variables['block']->delta;
  261. }
  262. function commons_roots_thumb_user_picture ($picture, $imagecache_preset, $user_name, $user_uid) {
  263. if (!isset($picture) || $picture == '') {
  264. $picture = variable_get('user_picture_default', '');
  265. }
  266. $img = theme('imagecache', $imagecache_preset, $picture, $user_name, $user_name);
  267. if (user_access('access user profiles')) {
  268. return l($img, "user/{$user_uid}", array('html' => TRUE));
  269. }
  270. else {
  271. return $img;
  272. }
  273. }
  274. /**
  275. * Theme a box
  276. */
  277. function commons_roots_boxes_box($block) {
  278. $output = "<div id='boxes-box-" . $block['delta'] . "' class='boxes-box" . (!empty($block['editing']) ? ' boxes-box-editing' : '') . "'>";
  279. $output .= '<div class="boxes-box-content">' . $block['content'] . '</div>';
  280. // Remove the box controls and editing portion because it doesn't
  281. // currently work with WYSIWYG
  282. $output .= '</div>';
  283. return $output;
  284. }
  285. function commons_roots_user_relationships_request_relationship_direct_link($relate_to, $relationship_type) {
  286. $string = t("Become %name's %rel_name", array('%name' => $relate_to->name, '%rel_name' => ur_tt("user_relationships:rtid:$relationship_type->rtid:name", $relationship_type->name), '%rel_plural_name' => ur_tt("user_relationships:rtid:$relationship_type->rtid:plural_name", $relationship_type->plural_name)));
  287. $class = 'user_relationships_popup_link';
  288. if ($relationship_type->name == 'follower') {
  289. $string = t('Follow');
  290. $class .= ' follow-link';
  291. }
  292. return l(
  293. $string,
  294. "relationship/{$relate_to->uid}/request/{$relationship_type->rtid}",
  295. array(
  296. 'query' => drupal_get_destination(),
  297. 'html' => TRUE,
  298. 'attributes' => array('class' => $class),
  299. )
  300. );
  301. }
  302. function commons_roots_user_relationships_remove_link($viewer, $relationship) {
  303. $path = "user/{$viewer->uid}/relationships/{$relationship->rid}/remove";
  304. $options = array(
  305. 'title' => array('title' => t('Remove')),
  306. 'query' => drupal_get_destination(),
  307. 'attributes' => array('class' => 'user_relationships_popup_link'),
  308. );
  309. if ($relationship->name == 'follower') {
  310. $options['attributes']['class'] .= ' follow-link';
  311. $output = l(
  312. t('Unfollow'),
  313. $path,
  314. $options);
  315. } else {
  316. $output = t('%relationship_name (!remove_link)', array(
  317. '%relationship_name' => ur_tt("user_relationships:rtid:$relationship->rtid:name", $relationship->name) . ($relationship->is_oneway ? ($relationship->requester_id == $viewer->uid ? t(' (You to Them)') : t(' (Them to You)')) : NULL),
  318. '!remove_link' => l(
  319. t('Remove'),
  320. $path,
  321. $options),
  322. ));
  323. }
  324. return $output;
  325. }
  326. /**
  327. * This handles the logic of whether or not there should be a recipient link so
  328. * that non-user recipient_links will be displayed.
  329. */
  330. function commons_roots_preprocess_facebook_status_item(&$vars) {
  331. $status = $vars['status'];
  332. // Remove the recipient link if it is the recipient is the sender.
  333. if ($status->type == 'user' && $status->sender == $status->recipient) {
  334. unset($vars['recipient_link']);
  335. }
  336. }
  337. function commons_roots_search_theme_form($form) {
  338. return '<div id="search" class="container-inline">' . drupal_render($form) . '</div>';
  339. }