user_details.module 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637
  1. <?php
  2. /**
  3. * @file
  4. * Block functions.
  5. *
  6. * Contains all the functions to run the "User Details" blocks.
  7. */
  8. /**
  9. * Implements of hook_help().
  10. *
  11. * Creates a basic help page(accessible from the modules page).
  12. */
  13. function user_details_help($path, $arg) {
  14. $output = '';
  15. switch ($path) {
  16. case "admin/help#user_details":
  17. require_once drupal_get_path('module', 'user_details') .'/user_details_help.inc';
  18. $output = drupal_render(drupal_get_form('user_details_help_form'));
  19. }
  20. return $output;
  21. }
  22. /**
  23. * Implements hook_menu().
  24. */
  25. function user_details_menu() {
  26. $items['admin/config/user-interface/user-details'] = array(
  27. 'title' => 'User Details',
  28. 'description' => 'Configure user Details.',
  29. 'page callback' => 'drupal_get_form',
  30. 'page arguments' => array('user_details_admin_settings'),
  31. 'access arguments' => array('administer site configuration'),
  32. 'type' => MENU_NORMAL_ITEM,
  33. 'file' => 'user_details_admin_settings.inc',
  34. );
  35. return $items;
  36. }
  37. /**
  38. * Implements hook_theme().
  39. *
  40. * Adds the template and variables needed to have the blocks run through a
  41. * template file.
  42. */
  43. function user_details_theme() {
  44. return array(
  45. 'user_details_loggedin' => array(
  46. 'template' => 'templates/user-details-loggedin',
  47. 'variables' => array(
  48. 'user_details_loggedin_avatar' => NULL,
  49. 'user_details_loggedin_points_title' => NULL,
  50. 'user_details_loggedin_points_result' => NULL,
  51. 'user_details_loggedin_joined_title' => NULL,
  52. 'user_details_loggedin_joined_result' => NULL,
  53. 'user_details_loggedin_postcount_title' => NULL,
  54. 'user_details_loggedin_postcount_result' => NULL,
  55. 'user_details_loggedin_rank_title' => NULL,
  56. 'user_details_loggedin_rank_result' => NULL,
  57. 'user_details_loggedin_privatemsg_title' => NULL,
  58. 'user_details_loggedin_privatemsg_result' => NULL,
  59. 'user_details_loggedin_stats_hr' => NULL,
  60. 'user_details_loggedin_frontlink_url' => NULL,
  61. 'user_details_loggedin_frontlink_imgsrc' => NULL,
  62. 'user_details_loggedin_frontlink_imgtitle' => NULL,
  63. 'user_details_loggedin_profilelink_url' => NULL,
  64. 'user_details_loggedin_profilelink_imgsrc' => NULL,
  65. 'user_details_loggedin_profilelink_imgtitle' => NULL,
  66. 'user_details_loggedin_profileeditlink_url' => NULL,
  67. 'user_details_loggedin_profileeditlink_imgsrc' => NULL,
  68. 'user_details_loggedin_profileeditlink_imgtitle' => NULL,
  69. 'user_details_loggedin_privatemsglink_url' => NULL,
  70. 'user_details_loggedin_privatemsglink_imgsrc' => NULL,
  71. 'user_details_loggedin_privatemsglink_imgtitle' => NULL,
  72. 'user_details_loggedin_createlink_url' => NULL,
  73. 'user_details_loggedin_createlink_imgsrc' => NULL,
  74. 'user_details_loggedin_createlink_imgtitle' => NULL,
  75. 'user_details_loggedin_adminlink_url' => NULL,
  76. 'user_details_loggedin_adminlink_imgsrc' => NULL,
  77. 'user_details_loggedin_adminlink_imgtitle' => NULL,
  78. 'user_details_loggedin_panelslink_url' => NULL,
  79. 'user_details_loggedin_panelslink_imgsrc' => NULL,
  80. 'user_details_loggedin_panelslink_imgtitle' => NULL,
  81. 'user_details_loggedin_viewslink_url' => NULL,
  82. 'user_details_loggedin_viewslink_imgsrc' => NULL,
  83. 'user_details_loggedin_viewslink_imgtitle' => NULL,
  84. 'user_details_loggedin_performancelink_url' => NULL,
  85. 'user_details_loggedin_performancelink_imgsrc' => NULL,
  86. 'user_details_loggedin_performancelink_imgtitle' => NULL,
  87. 'user_details_loggedin_logoutlink_url' => NULL,
  88. 'user_details_loggedin_logoutlink_imgsrc' => NULL,
  89. 'user_details_loggedin_logoutlink_imgtitle' => NULL,
  90. 'user_details_loggedin_customlinkone_type' => NULL,
  91. 'user_details_loggedin_customlinkone_url' => NULL,
  92. 'user_details_loggedin_customlinkone_imgsrc' => NULL,
  93. 'user_details_loggedin_customlinkone_imgtitle' => NULL,
  94. 'user_details_loggedin_customlinktwo_url' => NULL,
  95. 'user_details_loggedin_customlinktwo_imgsrc' => NULL,
  96. 'user_details_loggedin_customlinktwo_imgtitle' => NULL,
  97. 'user_details_loggedin_customlinkthree_url' => NULL,
  98. 'user_details_loggedin_customlinkthree_imgsrc' => NULL,
  99. 'user_details_loggedin_customlinkthree_imgtitle' => NULL,
  100. 'user_details_loggedin_customlinkfour_url' => NULL,
  101. 'user_details_loggedin_customlinkfour_imgsrc' => NULL,
  102. 'user_details_loggedin_customlinkfour_imgtitle' => NULL,
  103. 'user_details_loggedin_customlinkfive_url' => NULL,
  104. 'user_details_loggedin_customlinkfive_imgsrc' => NULL,
  105. 'user_details_loggedin_customlinkfive_imgtitle' => NULL,
  106. 'user_details_loggedin_links_hr' => NULL,
  107. 'user_details_loggedin_content' => NULL,
  108. ),
  109. ),
  110. 'user_details_authored' => array(
  111. 'template' => 'templates/user-details-authored',
  112. 'variables' => array(
  113. 'user_details_authored_avatar' => NULL,
  114. 'user_details_authored_joined_title' => NULL,
  115. 'user_details_authored_joined_result' => NULL,
  116. 'user_details_loggedin_postcount_title' => NULL,
  117. 'user_details_loggedin_postcount_result' => NULL,
  118. 'user_details_authored_points_title' => NULL,
  119. 'user_details_authored_points_result' => NULL,
  120. 'user_details_authored_rank_title' => NULL,
  121. 'user_details_authored_rank_result' => NULL,
  122. 'user_details_authored_stats_hr' => NULL,
  123. 'user_details_authored_profilelink_url' => NULL,
  124. 'user_details_authored_profilelink_imgsrc' => NULL,
  125. 'user_details_authored_profilelink_imgtitle' => NULL,
  126. 'user_details_authored_privatemsglink_url' => NULL,
  127. 'user_details_authored_privatemsglink_imgsrc' => NULL,
  128. 'user_details_authored_privatemsglink_imgtitle' => NULL,
  129. 'user_details_authored_links_hr' => NULL,
  130. 'user_details_authored_content' => NULL,
  131. ),
  132. ),
  133. );
  134. }
  135. /**
  136. * Implements hook_block_save().
  137. *
  138. * Sends all the checkbox(options) variables to the database to be stored.
  139. */
  140. function user_details_block_save($delta = '', $edit = array()) {
  141. if ($delta == 'loggedin') {
  142. variable_set('user_details_loggedin_avatar_display', $edit['user_details_loggedin_avatar_display']);
  143. variable_set('user_details_loggedin_points_display', $edit['user_details_loggedin_points_display']);
  144. variable_set('user_details_loggedin_joined_display', $edit['user_details_loggedin_joined_display']);
  145. variable_set('user_details_loggedin_postcount_display', $edit['user_details_loggedin_postcount_display']);
  146. variable_set('user_details_loggedin_rank_display', $edit['user_details_loggedin_rank_display']);
  147. variable_set('user_details_loggedin_stats_hr_display', $edit['user_details_loggedin_stats_hr_display']);
  148. variable_set('user_details_loggedin_privatemsg_display', $edit['user_details_loggedin_privatemsg_display']);
  149. variable_set('user_details_loggedin_frontlink_display', $edit['user_details_loggedin_frontlink_display']);
  150. variable_set('user_details_loggedin_frontlink_imgsrc', $edit['user_details_loggedin_frontlink_imgsrc']);
  151. variable_set('user_details_loggedin_profilelink_display', $edit['user_details_loggedin_profilelink_display']);
  152. variable_set('user_details_loggedin_profilelink_imgsrc', $edit['user_details_loggedin_profilelink_imgsrc']);
  153. variable_set('user_details_loggedin_profileeditlink_display', $edit['user_details_loggedin_profileeditlink_display']);
  154. variable_set('user_details_loggedin_profileeditlink_imgsrc', $edit['user_details_loggedin_profileeditlink_imgsrc']);
  155. variable_set('user_details_loggedin_privatemsglink_display', $edit['user_details_loggedin_privatemsglink_display']);
  156. variable_set('user_details_loggedin_privatemsglink_imgsrc', $edit['user_details_loggedin_privatemsglink_imgsrc']);
  157. variable_set('user_details_loggedin_createlink_display', $edit['user_details_loggedin_createlink_display']);
  158. variable_set('user_details_loggedin_createlink_imgsrc', $edit['user_details_loggedin_createlink_imgsrc']);
  159. variable_set('user_details_loggedin_adminlink_display', $edit['user_details_loggedin_adminlink_display']);
  160. variable_set('user_details_loggedin_adminlink_imgsrc', $edit['user_details_loggedin_adminlink_imgsrc']);
  161. variable_set('user_details_loggedin_panelslink_display', $edit['user_details_loggedin_panelslink_display']);
  162. variable_set('user_details_loggedin_panelslink_imgsrc', $edit['user_details_loggedin_panelslink_imgsrc']);
  163. variable_set('user_details_loggedin_viewslink_display', $edit['user_details_loggedin_panelslink_display']);
  164. variable_set('user_details_loggedin_viewslink_imgsrc', $edit['user_details_loggedin_panelslink_imgsrc']);
  165. variable_set('user_details_loggedin_performancelink_display', $edit['user_details_loggedin_performancelink_display']);
  166. variable_set('user_details_loggedin_performancelink_imgsrc', $edit['user_details_loggedin_performancelink_imgsrc']);
  167. variable_set('user_details_loggedin_logoutlink_display', $edit['user_details_loggedin_logoutlink_display']);
  168. variable_set('user_details_loggedin_logoutlink_imgsrc', $edit['user_details_loggedin_logoutlink_imgsrc']);
  169. variable_set('user_details_loggedin_customlinkone_type', $edit['user_details_loggedin_customlinkone_type']);
  170. variable_set('user_details_loggedin_customlinkone_url', $edit['user_details_loggedin_customlinkone_url']);
  171. variable_set('user_details_loggedin_customlinkone_imgsrc', $edit['user_details_loggedin_customlinkone_imgsrc']);
  172. variable_set('user_details_loggedin_customlinkone_imgtitle', $edit['user_details_loggedin_customlinkone_imgtitle']);
  173. variable_set('user_details_loggedin_customlinktwo_type', $edit['user_details_loggedin_customlinktwo_type']);
  174. variable_set('user_details_loggedin_customlinktwo_url', $edit['user_details_loggedin_customlinktwo_url']);
  175. variable_set('user_details_loggedin_customlinktwo_imgsrc', $edit['user_details_loggedin_customlinktwo_imgsrc']);
  176. variable_set('user_details_loggedin_customlinkthree_type', $edit['user_details_loggedin_customlinkthree_type']);
  177. variable_set('user_details_loggedin_customlinkthree_url', $edit['user_details_loggedin_customlinkthree_url']);
  178. variable_set('user_details_loggedin_customlinkthree_imgsrc', $edit['user_details_loggedin_customlinkthree_imgsrc']);
  179. variable_set('user_details_loggedin_customlinkthree_imgtitle', $edit['user_details_loggedin_customlinkthree_imgtitle']);
  180. variable_set('user_details_loggedin_customlinkfour_type', $edit['user_details_loggedin_customlinkfour_type']);
  181. variable_set('user_details_loggedin_customlinkfour_url', $edit['user_details_loggedin_customlinkfour_url']);
  182. variable_set('user_details_loggedin_customlinkfour_imgsrc', $edit['user_details_loggedin_customlinkfour_imgsrc']);
  183. variable_set('user_details_loggedin_customlinkfour_imgtitle', $edit['user_details_loggedin_customlinkfour_imgtitle']);
  184. variable_set('user_details_loggedin_customlinkfive_type', $edit['user_details_loggedin_customlinkfive_type']);
  185. variable_set('user_details_loggedin_customlinkfive_url', $edit['user_details_loggedin_customlinkfive_url']);
  186. variable_set('user_details_loggedin_customlinkfive_imgsrc', $edit['user_details_loggedin_customlinkfive_imgsrc']);
  187. variable_set('user_details_loggedin_customlinkfive_imgtitle', $edit['user_details_loggedin_customlinkfive_imgtitle']);
  188. variable_set('user_details_loggedin_links_hr_display', $edit['user_details_loggedin_links_hr_display']);
  189. variable_set('user_details_loggedin_content_display', $edit['user_details_loggedin_content_display']);
  190. variable_set('user_details_loggedin_content_amount', $edit['user_details_loggedin_content_amount']);
  191. }
  192. if ($delta == 'authored') {
  193. variable_set('user_details_authored_avatar_display', $edit['user_details_authored_avatar_display']);
  194. variable_set('user_details_authored_points_display', $edit['user_details_authored_points_display']);
  195. variable_set('user_details_authored_joined_display', $edit['user_details_authored_joined_display']);
  196. variable_set('user_details_authored_postcount_display', $edit['user_details_authored_postcount_display']);
  197. variable_set('user_details_authored_rank_display', $edit['user_details_authored_rank_display']);
  198. variable_set('user_details_authored_stats_hr_display', $edit['user_details_authored_stats_hr_display']);
  199. variable_set('user_details_authored_profilelink_display', $edit['user_details_authored_profilelink_display']);
  200. variable_set('user_details_authored_profilelink_imgsrc', $edit['user_details_authored_profilelink_imgsrc']);
  201. variable_set('user_details_authored_privatemsglink_display', $edit['user_details_authored_privatemsglink_display']);
  202. variable_set('user_details_authored_privatemsglink_imgsrc', $edit['user_details_authored_privatemsglink_imgsrc']);
  203. variable_set('user_details_authored_links_hr_display', $edit['user_details_authored_links_hr_display']);
  204. variable_set('user_details_authored_content_display', $edit['user_details_authored_content_display']);
  205. variable_set('user_details_authored_content_amount', $edit['user_details_authored_content_amount']);
  206. }
  207. return;
  208. }
  209. /**
  210. * Implements hook_block_info().
  211. *
  212. * Creates the title of the block for the block list page.
  213. */
  214. function user_details_block_info() {
  215. $blocks['loggedin']['info'] = t('User Details: logged-in user');
  216. $blocks['authored']['info'] = t('User Details: authored user');
  217. return $blocks;
  218. }
  219. /**
  220. * Implements hook_block_view().
  221. *
  222. * Creates the block title and content.
  223. */
  224. function user_details_block_view($delta = '') {
  225. global $user;
  226. if (arg(0) == 'node' && is_numeric(arg(1))) {
  227. $node_load = node_load(arg(1));
  228. $uid = $node_load->uid;
  229. $user_load = user_load($uid);
  230. }
  231. if (arg(0) == 'user' && is_numeric(arg(1))) {
  232. $user_arg = user_load(arg(1));
  233. $uid = $user_arg->uid;
  234. $user_load = user_load($uid);
  235. }
  236. switch ($delta) {
  237. case 'loggedin':
  238. if ($user->uid != 0) {
  239. $block['subject'] = t('%name', array('%name' => $user->name));
  240. $block['content'] = user_details_loggedin_block_content();
  241. return $block;
  242. }
  243. else {
  244. return;
  245. }
  246. case 'authored':
  247. $block['subject'] = t('%name', array('%name' => $user_load->name));
  248. $block['content'] = user_details_authored_block_content();
  249. return $block;
  250. }
  251. }
  252. /**
  253. * Process variables for user-details-loggedin.tpl.php.
  254. *
  255. * This function takes the result of the stored variable(options checkbox) and
  256. * creates a variable result from it.
  257. */
  258. function template_preprocess_user_details_loggedin(&$variables) {
  259. global $user;
  260. $co = $output = NULL;
  261. drupal_add_css(drupal_get_path('module', 'user_details') . '/css/user_details_loggedin.css');
  262. if (variable_get('user_details_loggedin_avatar_display') !=0) {
  263. $variables['user_details_loggedin_avatar'] = theme('user_picture', array('account' => $user));
  264. }
  265. if (variable_get('user_details_loggedin_joined_display') != 0) {
  266. $user_details_loggedin_date = date('c', $user->created);
  267. $variables['user_details_loggedin_joined_title'] = t('Joined');
  268. $variables['user_details_loggedin_joined_result'] = date('M j, Y', strtotime($user_details_loggedin_date));
  269. }
  270. if (variable_get('user_details_loggedin_postcount_display') != 0) {
  271. $user_details_loggedin_postcount_query = db_select('node', 'n');
  272. $user_details_loggedin_postcount_query
  273. ->condition('n.uid', $user->uid, '=')
  274. ->fields('n', array('uid'));
  275. $variables['user_details_loggedin_postcount_title'] = t('Posts');
  276. $variables['user_details_loggedin_postcount_result'] = t('%postcount', array('%postcount' => $user_details_loggedin_postcount_query->countQuery()->execute()->fetchField()));
  277. }
  278. if (variable_get('user_details_loggedin_points_display') !=0 && module_exists('userpoints')) {
  279. $variables['user_details_loggedin_points_title'] = t('!Points', userpoints_translation());
  280. $variables['user_details_loggedin_points_result'] = userpoints_get_current_points($user->uid, 'all');
  281. }
  282. if (variable_get('user_details_loggedin_rank_display') != 0) {
  283. $user_details_loggedin_rank_query = db_select('users_roles');
  284. $user_details_loggedin_rank_query
  285. ->condition('uid', $user->uid, '=')
  286. ->fields('users_roles', array('rid'));
  287. $user_details_loggedin_rank_fetchfield = $user_details_loggedin_rank_query->execute()->fetchField();
  288. if (($user_details_loggedin_rank_fetchfield) == NULL) {
  289. $user_details_loggedin_rank_fetchfield = 2;
  290. }
  291. $user_details_loggedin_rankname_query = db_select('role', 'r');
  292. $user_details_loggedin_rankname_query
  293. ->condition('rid', $user_details_loggedin_rank_fetchfield, '=')
  294. ->fields('r', array('name'));
  295. $user_details_loggedin_rankname_fetchfield = $user_details_loggedin_rankname_query->execute()->fetchField();
  296. $variables['user_details_loggedin_rank_title'] = t('Rank');
  297. $variables['user_details_loggedin_rank_result'] = t('%rank', array('%rank' => $user_details_loggedin_rankname_fetchfield));
  298. }
  299. if (variable_get('user_details_loggedin_privatemsg_display') != 0 && module_exists('privatemsg')) {
  300. $count = privatemsg_unread_count();
  301. $variables['user_details_loggedin_privatemsg_count_title'] = t('New messages');
  302. $variables['user_details_loggedin_privatemsg_count_result'] = t('%rank', array('%rank' => $count));
  303. }
  304. if (variable_get('user_details_loggedin_avatar_display') !=0 && variable_get('user_details_loggedin_stats_hr_display') != 0 || variable_get('user_details_loggedin_joined_display') != 0 && variable_get('user_details_loggedin_stats_hr_display') != 0 || variable_get('user_details_loggedin_postcount_display') != 0 && variable_get('user_details_loggedin_stats_hr_display') != 0 || variable_get('user_details_loggedin_points_display') !=0 && module_exists('userpoints') && variable_get('user_details_loggedin_stats_hr_display') != 0 || variable_get('user_details_loggedin_rank_display') != 0 && variable_get('user_details_loggedin_stats_hr_display') != 0) {
  305. $variables['user_details_loggedin_stats_hr'] = '<hr>';
  306. }
  307. if (variable_get('user_details_loggedin_frontlink_display') != 0) {
  308. $variables['user_details_loggedin_frontlink_url'] = t('/');
  309. $variables['user_details_loggedin_frontlink_imgsrc'] = variable_get('user_details_loggedin_frontlink_imgsrc');
  310. $variables['user_details_loggedin_frontlink_imgtitle'] = t('Front page');
  311. }
  312. if (variable_get('user_details_loggedin_profilelink_display') != 0) {
  313. $variables['user_details_loggedin_profilelink_url'] = t('/user/' . $user->uid);
  314. $variables['user_details_loggedin_profilelink_imgsrc'] = variable_get('user_details_loggedin_profilelink_imgsrc');
  315. $variables['user_details_loggedin_profilelink_imgtitle'] = t('My profile');
  316. }
  317. if (variable_get('user_details_loggedin_profileeditlink_display') != 0) {
  318. $variables['user_details_loggedin_profileeditlink_url'] = t('/user/' . $user->uid . '/edit');
  319. $variables['user_details_loggedin_profileeditlink_imgsrc'] = variable_get('user_details_loggedin_profileeditlink_imgsrc');
  320. $variables['user_details_loggedin_profileeditlink_imgtitle'] = t('Edit my profile');
  321. }
  322. if (variable_get('user_details_loggedin_privatemsglink_display') != 0 && module_exists('privatemsg')) {
  323. $variables['user_details_loggedin_privatemsglink_url'] = t('/messages/' . $user->uid);
  324. $variables['user_details_loggedin_privatemsglink_imgsrc'] = variable_get('user_details_loggedin_privatemsglink_imgsrc');
  325. $variables['user_details_loggedin_privatemsglink_imgtitle'] = t('My private messages');
  326. }
  327. if (variable_get('user_details_loggedin_createlink_display') != 0) {
  328. $variables['user_details_loggedin_createlink_url'] = t('/node/add');
  329. $variables['user_details_loggedin_createlink_imgsrc'] = variable_get('user_details_loggedin_createlink_imgsrc');
  330. $variables['user_details_loggedin_createlink_imgtitle'] = t('Create content');
  331. }
  332. if (variable_get('user_details_loggedin_adminlink_display') != 0 && user_access('administor content')) {
  333. $variables['user_details_loggedin_adminlink_url'] = t('/admin');
  334. $variables['user_details_loggedin_adminlink_imgsrc'] = variable_get('user_details_loggedin_adminlink_imgsrc');
  335. $variables['user_details_loggedin_adminlink_imgtitle'] = t('Admin');
  336. }
  337. if (variable_get('user_details_loggedin_panelslink_display') != 0 && module_exists('panels') && user_access('administor content')) {
  338. $variables['user_details_loggedin_panelslink_url'] = t('/admin/structure/panels');
  339. $variables['user_details_loggedin_panelslink_imgsrc'] = variable_get('user_details_loggedin_panelslink_imgsrc');
  340. $variables['user_details_loggedin_panelslink_imgtitle'] = t('Panels');
  341. }
  342. if (variable_get('user_details_loggedin_viewslink_display') != 0 && module_exists('views') && user_access('administor content')) {
  343. $variables['user_details_loggedin_viewslink_url'] = t('/admin/structure/views');
  344. $variables['user_details_loggedin_viewslink_imgsrc'] = variable_get('user_details_loggedin_viewslink_imgsrc');
  345. $variables['user_details_loggedin_viewslink_imgtitle'] = t('Views');
  346. }
  347. if (variable_get('user_details_loggedin_performancelink_display') != 0 && user_access('administor content')) {
  348. $variables['user_details_loggedin_performancelink_url'] = t('/admin/config/development/performance');
  349. $variables['user_details_loggedin_performancelink_imgsrc'] = variable_get('user_details_loggedin_performancelink_imgsrc');
  350. $variables['user_details_loggedin_performancelink_imgtitle'] = t('Performance');
  351. }
  352. if (variable_get('user_details_loggedin_logoutlink_display') != 0) {
  353. $variables['user_details_loggedin_logoutlink_url'] = t('/user/logout');
  354. $variables['user_details_loggedin_logoutlink_imgsrc'] = variable_get('user_details_loggedin_logoutlink_imgsrc');
  355. $variables['user_details_loggedin_logoutlink_imgtitle'] = t('Logout');
  356. }
  357. if (variable_get('user_details_loggedin_customlinkone_type') != 0) {
  358. $variables['user_details_loggedin_customlinkone_url'] = variable_get('user_details_loggedin_customlinkone_url');
  359. $variables['user_details_loggedin_customlinkone_imgsrc'] = variable_get('user_details_loggedin_customlinkone_imgsrc');
  360. $variables['user_details_loggedin_customlinkone_imgtitle'] = variable_get('user_details_loggedin_customlinkone_imgtitle');
  361. }
  362. if (variable_get('user_details_loggedin_customlinktwo_type') != 0) {
  363. $variables['user_details_loggedin_customlinktwo_url'] = variable_get('user_details_loggedin_customlinktwo_url');
  364. $variables['user_details_loggedin_customlinktwo_imgsrc'] = variable_get('user_details_loggedin_customlinktwo_imgsrc');
  365. $variables['user_details_loggedin_customlinktwo_imgtitle'] = variable_get('user_details_loggedin_customlinktwo_imgtitle');
  366. }
  367. if (variable_get('user_details_loggedin_customlinkthree_type') != 0) {
  368. $variables['user_details_loggedin_customlinkthree_url'] = variable_get('user_details_loggedin_customlinkthree_url');
  369. $variables['user_details_loggedin_customlinkthree_imgsrc'] = variable_get('user_details_loggedin_customlinkthree_imgsrc');
  370. $variables['user_details_loggedin_customlinkthree_imgtitle'] = variable_get('user_details_loggedin_customlinkthree_imgtitle');
  371. }
  372. if (variable_get('user_details_loggedin_customlinkfour_type') != 0) {
  373. $variables['user_details_loggedin_customlinkfour_url'] = variable_get('user_details_loggedin_customlinkfour_url');
  374. $variables['user_details_loggedin_customlinkfour_imgsrc'] = variable_get('user_details_loggedin_customlinkfour_imgsrc');
  375. $variables['user_details_loggedin_customlinkfour_imgtitle'] = variable_get('user_details_loggedin_customlinkfour_imgtitle');
  376. }
  377. if (variable_get('user_details_loggedin_customlinkfive_type') != 0) {
  378. $variables['user_details_loggedin_customlinkfive_url'] = variable_get('user_details_loggedin_customlinkfive_url');
  379. $variables['user_details_loggedin_customlinkfive_imgsrc'] = variable_get('user_details_loggedin_customlinkfive_imgsrc');
  380. $variables['user_details_loggedin_customlinkfive_imgtitle'] = variable_get('user_details_loggedin_customlinkfive_imgtitle');
  381. }
  382. // User links HR
  383. if (variable_get('user_details_loggedin_frontlink_display') != 0 && variable_get('user_details_loggedin_links_hr_display') != 0 || variable_get('user_details_loggedin_profilelink_display') != 0 && variable_get('user_details_loggedin_links_hr_display') != 0 || variable_get('user_details_loggedin_profileeditlink_display') != 0 && variable_get('user_details_loggedin_links_hr_display') != 0 || variable_get('user_details_loggedin_privatemsglink_display') != 0 && module_exists('privatemsg') && variable_get('user_details_loggedin_links_hr_display') != 0 || variable_get('user_details_loggedin_createlink_display') != 0 && variable_get('user_details_loggedin_links_hr_display') != 0 || variable_get('user_details_loggedin_logoutlink_display') != 0 && variable_get('user_details_loggedin_links_hr_display') != 0 || variable_get('user_details_loggedin_customlinkone_type') == 2 && variable_get('user_details_loggedin_links_hr_display') != 0 || variable_get('user_details_loggedin_customlinktwo_type') == 2 && variable_get('user_details_loggedin_links_hr_display') != 0 || variable_get('user_details_loggedin_customlinkthree_type') == 2 && variable_get('user_details_loggedin_links_hr_display') != 0 || variable_get('user_details_loggedin_customlinkfour_type') == 2 && variable_get('user_details_loggedin_links_hr_display') != 0 || variable_get('user_details_loggedin_customlinkfive_type') == 2 && variable_get('user_details_loggedin_links_hr_display') != 0) {
  384. $variables['user_details_loggedin_links_hr'] = '<hr>';
  385. }
  386. // Admin links HR
  387. if (variable_get('user_details_loggedin_adminlink_display') != 0 && variable_get('user_details_loggedin_links_hr_display') != 0 || variable_get('user_details_loggedin_panelslink_display') != 0 && module_exists('panels') && variable_get('user_details_loggedin_links_hr_display') != 0 || variable_get('user_details_loggedin_viewslink_display') != 0 && module_exists('views') && variable_get('user_details_loggedin_links_hr_display') != 0 || variable_get('user_details_loggedin_performancelink_display') != 0 && variable_get('user_details_loggedin_links_hr_display') != 0 || variable_get('user_details_loggedin_customlinkone_type') == 3 && variable_get('user_details_loggedin_links_hr_display') != 0 || variable_get('user_details_loggedin_customlinktwo_type') == 3 && variable_get('user_details_loggedin_links_hr_display') != 0 || variable_get('user_details_loggedin_customlinkthree_type') == 3 && variable_get('user_details_loggedin_links_hr_display') != 0 || variable_get('user_details_loggedin_customlinkfour_type') == 3 && variable_get('user_details_loggedin_links_hr_display') != 0 || variable_get('user_details_loggedin_customlinkfive_type') == 3 && variable_get('user_details_loggedin_links_hr_display') != 0) {
  388. $variables['user_details_loggedin_links_hr'] = '<hr>';
  389. }
  390. if (variable_get('user_details_loggedin_content_amount') !=0 && variable_get('user_details_loggedin_content_display') != 0) {
  391. $user_details_loggedin_content_amount = variable_get('user_details_loggedin_content_amount');
  392. }
  393. if (variable_get('user_details_loggedin_content_display') != 0 && variable_get('user_details_loggedin_content_amount') != 0) {
  394. unset($output);
  395. if ($user->uid) {
  396. // Sql query.
  397. $user_details_loggedin_content_query = db_select('node', 'n');
  398. $user_details_loggedin_content_query
  399. ->condition('n.uid', $user->uid, '=')
  400. ->fields('n', array('created', 'title', 'nid', 'changed', 'type', 'status'))
  401. ->range(0, $user_details_loggedin_content_amount)
  402. ->orderBy('changed', 'DESC');
  403. $user_details_loggedin_content_fetchfield = $user_details_loggedin_content_query->execute();
  404. $output = '';
  405. foreach ($user_details_loggedin_content_fetchfield as $user_details_loggedin_content_node ) {
  406. $co++;
  407. $output .= '<li>';
  408. $output .= l($user_details_loggedin_content_node->title, "node/$user_details_loggedin_content_node->nid");
  409. $output .= '</li>';
  410. }
  411. $output .= '';
  412. // Show only if user have made some content.
  413. if ($co>0) {
  414. $variables['user_details_loggedin_content'] = $output;
  415. }
  416. if ($co == 0) {
  417. $variables['user_details_loggedin_content'] = t('No content to list.');
  418. }
  419. }
  420. }
  421. }
  422. /**
  423. * Process variables for user-details-authored.tpl.php.
  424. *
  425. * This function takes the result of the stored variable(options checkbox) and
  426. * creates a variable result from it.
  427. */
  428. function template_preprocess_user_details_authored(&$variables) {
  429. drupal_add_css(drupal_get_path('module', 'user_details') . '/css/user_details_authored.css');
  430. $img_dir = drupal_get_path('module', 'user_details') . "/images/";
  431. // If the page is a node we need to load the user data from the node ID(nid)
  432. // profile.
  433. $co = $output = NULL;
  434. if (arg(0) == 'node') {
  435. $node_load = node_load(arg(1));
  436. $uid = $node_load->uid;
  437. $user_load = user_load($uid);
  438. }
  439. // If the page is a user profile we need to load the user data from the user profile.
  440. if (arg(0) == 'user') {
  441. $user_arg = user_load(arg(1));
  442. $uid = $user_arg->uid;
  443. $user_load = user_load($uid);
  444. }
  445. if (variable_get('user_details_authored_avatar_display') !=0) {
  446. $variables['user_details_authored_avatar'] = theme('user_picture', array('account' => $user_load));
  447. }
  448. if (variable_get('user_details_authored_joined_display') != 0) {
  449. $user_details_authored_date = date('c', $user_load->created);
  450. $user_details_authored_dateconvert = date('M j, Y', strtotime($user_details_authored_date));
  451. $variables['user_details_authored_joined_title'] = t('Joined');
  452. $variables['user_details_authored_joined_result'] = t('&nbsp;%joined', array('%joined' => $user_details_authored_dateconvert));
  453. }
  454. if (variable_get('user_details_authored_postcount_display') != 0) {
  455. $user_details_authored_postcount_query = db_select('node', 'n');
  456. $user_details_authored_postcount_query
  457. ->condition('n.uid', $user_load->uid, '=')
  458. ->fields('n', array('uid'));
  459. $user_details_authored_postcount_fetchfield = $user_details_authored_postcount_query->countQuery()->execute()->fetchField();
  460. $variables['user_details_authored_postcount_title'] = t('Posts');
  461. $variables['user_details_authored_postcount_result'] = t('%postcount', array('%postcount' => $user_details_authored_postcount_fetchfield));
  462. }
  463. if (variable_get('user_details_authored_points_display') !=0 && module_exists('userpoints')) {
  464. $variables['user_details_authored_points_title'] = t('!Points', userpoints_translation());
  465. $variables['user_details_authored_points_result'] = userpoints_get_current_points($user_load->uid, 'all');
  466. }
  467. if (variable_get('user_details_authored_rank_display') != 0) {
  468. $user_details_authored_rank_query = db_select('users_roles');
  469. $user_details_authored_rank_query
  470. ->condition('uid', $user_load->uid, '=')
  471. ->fields('users_roles', array('rid'));
  472. $user_details_authored_rank_fetchfield = $user_details_authored_rank_query->execute()->fetchField();
  473. if (($user_details_authored_rank_fetchfield) == NULL) {
  474. $user_details_authored_rank_fetchfield = 2;
  475. }
  476. $user_details_authored_rankname_query = db_select('role', 'r');
  477. $user_details_authored_rankname_query
  478. ->condition('rid', $user_details_authored_rank_fetchfield, '=')
  479. ->fields('r', array('name'));
  480. $user_details_authored_rankname_fetchfield = $user_details_authored_rankname_query->execute()->fetchField();
  481. $variables['user_details_authored_rank_title'] = t('Role');
  482. $variables['user_details_authored_rank_result'] = t('%rank', array('%rank' => $user_details_authored_rankname_fetchfield));
  483. }
  484. if (variable_get('user_details_authored_avatar_display') !=0 && variable_get('user_details_authored_stats_hr_display') != 0 || variable_get('user_details_authored_joined_display') != 0 && variable_get('user_details_authored_stats_hr_display') != 0 || variable_get('user_details_authored_postcount_display') != 0 && variable_get('user_details_authored_stats_hr_display') != 0 || variable_get('user_details_authored_points_display') !=0 && module_exists('userpoints') && variable_get('user_details_authored_stats_hr_display') != 0 || variable_get('user_details_authored_rank_display') != 0 && variable_get('user_details_authored_stats_hr_display') != 0) {
  485. $variables['user_details_authored_stats_hr'] = '<hr>';
  486. }
  487. if (variable_get('user_details_authored_profilelink_display') != 0) {
  488. $variables['user_details_authored_profilelink_url'] = t('/user/' . $user_load->uid);
  489. $variables['user_details_authored_profilelink_imgsrc'] = variable_get('user_details_loggedin_profilelink_imgsrc');
  490. $variables['user_details_authored_profilelink_imgtitle'] = t('Author\'s profile');
  491. }
  492. if (variable_get('user_details_authored_privatemsglink_display') != 0 && module_exists('privatemsg')) {
  493. $variables['user_details_authored_privatemsglink_url'] = t('/messages/new/' . $user_load->uid);
  494. $variables['user_details_authored_privatemsglink_imgsrc'] = variable_get('user_details_loggedin_privatemsglink_imgsrc');
  495. $variables['user_details_authored_privatemsglink_imgtitle'] = t('Private message the author');
  496. }
  497. if (variable_get('user_details_authored_profilelink_display') != 0 && variable_get('user_details_authored_links_hr_display') != 0 || variable_get('user_details_authored_privatemsglink_display') != 0 && module_exists('privatemsg') && variable_get('user_details_authored_links_hr_display') != 0) {
  498. $variables['user_details_authored_links_hr'] = '<hr>';
  499. }
  500. if (variable_get('user_details_authored_content_amount') !=0 && variable_get('user_details_authored_content_display') !=0) {
  501. $user_details_authored_content_amount = variable_get('user_details_authored_content_amount');
  502. }
  503. if (variable_get('user_details_authored_content_display') != 0 && variable_get('user_details_authored_content_amount') != 0) {
  504. unset($output);
  505. if ($user_load->uid) {
  506. // Sql query.
  507. $user_details_authored_content_query = db_select('node', 'n');
  508. $user_details_authored_content_query
  509. ->condition('n.uid', $user_load->uid, '=')
  510. ->fields('n', array('created', 'title', 'nid', 'changed', 'type', 'status'))
  511. ->range(0, 3)
  512. ->orderBy('changed', 'DESC');
  513. $user_details_authored_content_fetchfield = $user_details_authored_content_query->execute();
  514. $output = '';
  515. foreach ($user_details_authored_content_fetchfield as $user_details_authored_content_node ) {
  516. $co++;
  517. $output .= '<li>';
  518. $output .= l($user_details_authored_content_node->title, "node/$user_details_authored_content_node->nid");
  519. $output .= '</li>';
  520. }
  521. $output .= '';
  522. if ($co>0) {
  523. $variables['user_details_authored_content'] = $output;
  524. }
  525. if ($co == 0) {
  526. $variables['user_details_authored_content'] = t('No content to list.');
  527. }
  528. }
  529. }
  530. }
  531. /**
  532. * Used to push the variables to the theme layer for the "logged-in" block.
  533. */
  534. function user_details_loggedin_block_content() {
  535. $content = array(
  536. $user_details_loggedin_avatar = 'user_details_loggedin_avatar',
  537. $user_details_loggedin_points_title = 'user_details_loggedin_points_title',
  538. $user_details_loggedin_points_result = 'user_details_loggedin_points_result',
  539. $user_details_loggedin_joined_title = 'user_details_loggedin_joined_title',
  540. $user_details_loggedin_joined_result = 'user_details_loggedin_joined_result',
  541. $user_details_loggedin_postcount_title = 'user_details_loggedin_postcount_title',
  542. $user_details_loggedin_postcount_result = 'user_details_loggedin_postcount_result',
  543. $user_details_loggedin_rank_title = 'user_details_loggedin_rank_title',
  544. $user_details_loggedin_rank_result = 'user_details_loggedin_rank_result',
  545. $user_details_loggedin_privatemsg_count_title = 'user_details_loggedin_privatemsg_title',
  546. $user_details_loggedin_privatemsg_count_result = 'user_details_loggedin_privatemsg_result',
  547. $user_details_loggedin_stats_hr = 'user_details_loggedin_stats_hr',
  548. $user_details_loggedin_frontlink_url = 'user_details_loggedin_profilelink_url',
  549. $user_details_loggedin_frontlink_imgsrc = 'user_details_loggedin_profilelink_imgsrc',
  550. $user_details_loggedin_frontlink_imgtitle = 'user_details_loggedin_profilelink_imgtitle',
  551. $user_details_loggedin_profilelink_url = 'user_details_loggedin_profilelink_url',
  552. $user_details_loggedin_profilelink_imgsrc = 'user_details_loggedin_profilelink_imgsrc',
  553. $user_details_loggedin_profilelink_imgtitle = 'user_details_loggedin_profilelink_imgtitle',
  554. $user_details_loggedin_profileeditlink_url = 'user_details_loggedin_profilelink_url',
  555. $user_details_loggedin_profileeditlink_imgsrc = 'user_details_loggedin_profileeditlink_imgsrc',
  556. $user_details_loggedin_profileeditlink_imgtitle = 'user_details_loggedin_profilelink_imgtitle',
  557. $user_details_loggedin_privatemsglink_url = 'user_details_loggedin_privatemsglink',
  558. $user_details_loggedin_privatemsglink_imgsrc = 'user_details_loggedin_privatemsglink_imgsrc',
  559. $user_details_loggedin_privatemsglink_imgtitle = 'user_details_loggedin_privatemsglinkimgtitle',
  560. $user_details_loggedin_createlink_url = 'user_details_loggedin_createlink_url',
  561. $user_details_loggedin_createlink_imgsrc = 'user_details_loggedin_createlink_imgsrc',
  562. $user_details_loggedin_createlink_imgtitle = 'user_details_loggedin_createlink_imgtitle',
  563. $user_details_loggedin_adminlink_url = 'user_details_loggedin_adminlink_url',
  564. $user_details_loggedin_adminlink_imgsrc = 'user_details_loggedin_adminlink_imgsrc',
  565. $user_details_loggedin_adminlink_imgtitle = 'user_details_loggedin_adminlink_imgtitle',
  566. $user_details_loggedin_panelslink_url = 'user_details_loggedin_panelslink_url',
  567. $user_details_loggedin_panelslink_imgsrc = 'user_details_loggedin_panelslink_imgsrc',
  568. $user_details_loggedin_panelslink_imgtitle = 'user_details_loggedin_panelslink_imgtitle',
  569. $user_details_loggedin_viewslink_url = 'user_details_loggedin_viewslink_url',
  570. $user_details_loggedin_viewslink_imgsrc = 'user_details_loggedin_viewslink_imgsrc',
  571. $user_details_loggedin_viewslink_imgtitle = 'user_details_loggedin_viewslink_imgtitle',
  572. $user_details_loggedin_performancelink_url = 'user_details_loggedin_performancelink_url',
  573. $user_Details_loggedin_performancelink_imgsrc = 'user_details_loggedin_performancelink_imgsrc',
  574. $user_details_loggedin_performancelink_imgtitle = 'user_details_loggedin_performancelink_imgtitle',
  575. $user_details_loggedin_logoutlink_url = 'user_details_loggedin_logoutlink_url',
  576. $user_details_loggedin_logoutlink_imgsrc = 'user_details_loggedin_logoutlink_imgsrc',
  577. $user_details_loggedin_logoutlink_imgtitle = 'user_details_loggedin_logoutlink_imgtitle',
  578. $user_details_loggedin_customlinkone_url = 'user_details_loggedin_customlinkone_url',
  579. $user_details_loggedin_customlinkone_imgsrc = 'user_details_loggedin_customlinkone_imgsrc',
  580. $user_details_loggedin_customlinkone_imgtitle = 'user_details_loggedin_customlinkone_imgtitle',
  581. $user_details_loggedin_customlinktwo_url = 'user_details_loggedin_customlinktwo_url',
  582. $user_details_loggedin_customlinktwo_imgsrc = 'user_details_loggedin_customlinktwo_imgsrc',
  583. $user_details_loggedin_customlinktwo_imgtitle = 'user_details_loggedin_customlinktwo_imgtitle',
  584. $user_details_loggedin_customlinkthree_url = 'user_details_loggedin_customlinkthree_url',
  585. $user_details_loggedin_customlinkthree_imgsrc = 'user_details_loggedin_customlinkthree_imgsrc',
  586. $user_details_loggedin_customlinkthree_imgtitle = 'user_details_loggedin_customlinkthree_imgtitle',
  587. $user_details_loggedin_customlinkfour_url = 'user_details_loggedin_customlinkfour_url',
  588. $user_details_loggedin_customlinkfour_imgsrc = 'user_details_loggedin_customlinkfour_imgsrc',
  589. $user_details_loggedin_customlinkfour_imgtitle = 'user_details_loggedin_customlinkfour_imgtitle',
  590. $user_details_loggedin_customlinkfive_url = 'user_details_loggedin_customlinkfive_url',
  591. $user_details_loggedin_customlinkfive_imgsrc = 'user_details_loggedin_customlinkfive_imgsrc',
  592. $user_details_loggedin_customlinkfive_imgtitle = 'user_details_loggedin_customlinkfive_imgtitle',
  593. $user_details_loggedin_links_hr = 'user_details_loggedin_links_hr',
  594. $user_details_loggedin_content = 'user_details_loggedin_content',
  595. );
  596. $output = theme('user_details_loggedin', $content);
  597. return $output;
  598. }
  599. /**
  600. * Used to push the variables to the theme layer for the "Authored by" block.
  601. */
  602. function user_details_authored_block_content() {
  603. $content = array(
  604. $user_details_authored_avatar = 'user_details_authored_avatar',
  605. $user_details_authored_joined = 'user_details_authored_joined',
  606. $user_details_authored_postcount_title = 'user_details_authored_postcount_title',
  607. $user_details_authored_postcount_result = 'user_details_authored_postcount_result',
  608. $user_details_authored_points_title = 'user_details_authored_points_title',
  609. $user_details_authored_points_result = 'user_details_authored_points_result',
  610. $user_details_authored_rank_title = 'user_details_authored_rank_title',
  611. $user_details_authored_rank_result = 'user_details_authored_rank_result',
  612. $user_details_authored_stats_hr = 'user_details_authored_stats_hr',
  613. $user_details_authored_profilelink_url = 'user_details_authored_profilelink_url',
  614. $user_details_authored_profilelink_imgsrc = 'user_details_authored_profilelink_imgsrc',
  615. $user_details_authored_profilelink_imgtitle = 'user_details_authored_profilelink_imgtitle',
  616. $user_details_authored_privatemsglink_url = 'user_details_authored_privatemsglink',
  617. $user_details_authored_privatemsglink_imgsrc = 'user_details_authored_privatemsglink_imgsrc',
  618. $user_details_authored_privatemsglink_imgtitle = 'user_details_authored_privatemsglinkimgtitle',
  619. $user_details_authored_links_hr = 'user_details_authored_links_hr',
  620. $user_details_authored_content = 'user_details_authored_content',
  621. );
  622. $output = theme('user_details_authored', $content);
  623. return $output;
  624. }