PageRenderTime 50ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/users/layout_users_as_search.php

https://github.com/bernard357/yacs
PHP | 168 lines | 88 code | 35 blank | 45 comment | 37 complexity | 17a7c4f7e4afc27fbe14b4695885ea87 MD5 | raw file
  1. <?php
  2. /**
  3. * layout users for search requests
  4. *
  5. * @see search.php
  6. *
  7. * @author Bernard Paques
  8. * @reference
  9. * @license http://www.gnu.org/copyleft/lesser.txt GNU Lesser General Public License
  10. */
  11. Class Layout_users_as_search extends Layout_interface {
  12. /**
  13. * list users
  14. *
  15. * @param resource the SQL result
  16. * @return array of resulting items ($score, $summary), or NULL
  17. *
  18. * @see skins/layout.php
  19. **/
  20. function layout($result) {
  21. global $context;
  22. // we return an array of array($score, $summary)
  23. $items = array();
  24. // empty list
  25. if(!SQL::count($result))
  26. return $items;
  27. // flag idle users
  28. $idle = gmstrftime('%Y-%m-%d %H:%M:%S', time() - 600);
  29. // process all items in the list
  30. while($item = SQL::fetch($result)) {
  31. // one box at a time
  32. $box = '';
  33. // initialize variables
  34. $prefix = $suffix = $icon = '';
  35. // the url to view this item
  36. $url = Users::get_permalink($item);
  37. // flag profiles updated recently
  38. if($item['create_date'] >= $context['fresh'])
  39. $suffix .= NEW_FLAG;
  40. elseif($item['edit_date'] >= $context['fresh'])
  41. $suffix .= UPDATED_FLAG;
  42. // signal restricted and private articles
  43. if($item['active'] == 'N')
  44. $prefix .= PRIVATE_FLAG;
  45. elseif($item['active'] == 'R')
  46. $prefix .= RESTRICTED_FLAG;
  47. // signal locked profiles
  48. if($item['capability'] == '?')
  49. $prefix .= EXPIRED_FLAG;
  50. // item title
  51. if($item['full_name']) {
  52. $title = ucfirst(Skin::strip($item['full_name'], 10));
  53. $hover = $item['nick_name'];
  54. } else {
  55. $title = ucfirst(Skin::strip($item['nick_name'], 10));
  56. $hover = $item['full_name'];
  57. }
  58. // show contact information
  59. if(Surfer::may_contact())
  60. $suffix .= Users::build_presence($item);
  61. // the introduction
  62. if($item['introduction']) {
  63. if(is_callable(array('codes', 'beautify')))
  64. $suffix .= ' -&nbsp;'.Codes::beautify($item['introduction']);
  65. else
  66. $suffix .= ' -&nbsp;'.$item['introduction'];
  67. }
  68. // display all tags
  69. if($item['tags'])
  70. $suffix .= ' <span class="tags">'.Skin::build_tags($item['tags'], 'user:'.$item['id']).'</span>';
  71. // details
  72. $details = array();
  73. // capability
  74. if($item['capability'] == 'A')
  75. $details[] = i18n::s('Associate');
  76. elseif($item['capability'] == 'S')
  77. $details[] = i18n::s('Subscriber');
  78. else
  79. $details[] = i18n::s('Member');
  80. // creation date
  81. if($item['create_date'])
  82. $details[] = sprintf(i18n::s('registered %s'), Skin::build_date($item['create_date']));
  83. // last login
  84. if($this->layout_variant == 'dates') {
  85. if(isset($item['login_date']) && ($item['login_date'] > NULL_DATE)) {
  86. $address = '';
  87. if($item['login_address'])
  88. $address = ' ('.$item['login_address'].')';
  89. $details[] = sprintf(i18n::s('last login %s'), Skin::build_date($item['login_date']).$address);
  90. } else
  91. $details[] = i18n::s('no login');
  92. }
  93. // last post
  94. if($this->layout_variant == 'dates') {
  95. if(isset($item['post_date']) && ($item['post_date'] > NULL_DATE))
  96. $details[] = sprintf(i18n::s('last post %s'), Skin::build_date($item['post_date']));
  97. }
  98. // posts
  99. if(intval($item['posts']) > 1)
  100. $details[] = sprintf(i18n::s('%d posts'), intval($item['posts']));
  101. if(count($details))
  102. if($this->layout_variant == 'full')
  103. $suffix .= ' <span class="details">('.implode(', ', $details).')</span>';
  104. else
  105. $suffix .= ' <span class="details">'.implode(', ', $details).'</span>';
  106. // flag idle users
  107. if(isset($item['click_date']) && ($item['click_date'] < $idle))
  108. $class = 'idle user';
  109. else
  110. $class = 'user';
  111. // item summary
  112. $box .= $prefix.Skin::build_link($url, $title, 'user').$suffix;
  113. // use the avatar, if any
  114. if(isset($item['avatar_url']) && isset($context['users_with_avatars']) && $context['users_with_avatars'] == 'Y')
  115. $icon = $item['avatar_url'];
  116. // layout this item
  117. if($icon) {
  118. // build the complete HTML element
  119. $icon = '<img src="'.$icon.'" alt="" title="'.encode_field(strip_tags($title)).'" />';
  120. // make it a clickable link
  121. $icon = Skin::build_link($url, $icon, 'basic');
  122. $list = array(array($box, $icon));
  123. $items[] = array($item['score'], Skin::finalize_list($list, 'decorated'));
  124. // put the item in a division
  125. } else
  126. $items[] = array($item['score'], '<div style="margin: 0 0 1em 0">'.$box.'</div>');
  127. }
  128. // end of processing
  129. SQL::free($result);
  130. return $items;
  131. }
  132. }
  133. ?>