Cheetah
ChWsbFriendsPageView.php
Go to the documentation of this file.
1 <?php
2 
8 ch_import( 'ChWsbPageView' );
9 ch_import( 'ChTemplProfileGenerator' );
10 
12 {
13  // consit all necessary data for display members list ;
15 
17  var $oProfile;
18 
19  // link on search profile ;
21 
22  // contains the path to the current page ;
24 
26 
38  {
39  parent::__construct($sPageName);
40  $this -> aDisplayParameters = &$aDisplayParameters;
41  $this -> oSearchProfileTmpl = new ChTemplSearchProfile();
42  $this -> sCurrentPage = 'viewFriends.php';
43 
44  // check member on line time ;
45  $this -> iMemberOnlineTime = (int)getParam('member_online_time');
46  $this -> iProfileID = $iProfileID;
47  $this -> oProfile = new ChTemplProfileGenerator($iProfileID);
48  }
49 
55  {
56  // init some variables ;
57  $sOutputHtml = '';
58  $sEmpty = '';
59  $iIndex = 0;
60 
61  $aUsedTemplates = array (
62  'browse_searched_block.html'
63  );
64 
65  // lang keys ;
66  $sPhotoCaption = _t( '_With photos only' );
67  $sOnlineCaption = _t( '_online only' );
68 
69  // collect the SQL parameters ;
70 
71  $aWhereParam = array();
72  if ( $this -> aDisplayParameters['photos'] )
73  $aWhereParam[] = 'p.`Avatar` <> 0';
74 
75  if ( $this -> aDisplayParameters['online'] )
76  $aWhereParam[] = "(p.`DateLastNav` > SUBDATE(NOW(), INTERVAL " . $this -> iMemberOnlineTime . " MINUTE)) ";
77 
78  $sWhereParam = null;
79  foreach( $aWhereParam AS $sValue )
80  if ( $sValue )
81  $sWhereParam .= ' AND ' . $sValue;
82 
83  $iTotalNum = getFriendNumber($this->iProfileID, 1, 0, $sWhereParam);
84 
85  if( !$iTotalNum ) {
86  $sEmpty = MsgBox( _t('_Empty') );
87  }
88 
89  $iPerPage = $this -> aDisplayParameters['per_page'];
90  $iCurPage = $this -> aDisplayParameters['page'];
91 
92  $sLimitFrom = ( $iCurPage - 1 ) * $iPerPage;
93  $sqlLimit = "LIMIT {$sLimitFrom}, {$iPerPage}";
94 
95  // switch member's template ;
96  $sTemplateName = ($this->aDisplayParameters['mode'] == 'extended') ? 'search_profiles_ext.html' : 'search_profiles_sim.html';
97 
98  // select the sorting parameters ;
99  $sSortParam = 'activity_desc';
100  if ( isset($this -> aDisplayParameters['sort']) ) {
101  switch($this -> aDisplayParameters['sort']) {
102  case 'activity' :
103  $sSortParam = 'activity_desc';
104  break;
105  case 'date_reg' :
106  $sSortParam = 'date_reg_desc';
107  break;
108  case 'rate' :
109  $sSortParam = 'rate';
110  break;
111  default :
112  $this -> aDisplayParameters['sort'] = 'activity';
113  break;
114  }
115  } else
116  $this -> aDisplayParameters['sort'] = 'activity';
117 
118  $aAllFriends = getMyFriendsEx($this->iProfileID, $sWhereParam, $sSortParam, $sqlLimit);
119 
120  $aExtendedCss = array(
121  'ext_css_class' => $this->aDisplayParameters['mode'] == 'extended' ? 'search_filled_block' : ''
122  );
123  foreach ($aAllFriends as $iFriendID => $aFriendsPrm) {
124  $aMemberInfo = getProfileInfo($iFriendID);
125  if($aMemberInfo['Couple']) {
126  $aCoupleInfo = getProfileInfo( $aMemberInfo['Couple'] );
127  $sOutputHtml .= $this -> oSearchProfileTmpl -> PrintSearhResult($aMemberInfo, $aCoupleInfo, ($iIndex % 2 ? $aExtendedCss : array()), $sTemplateName);
128  } else
129  $sOutputHtml .= $this -> oSearchProfileTmpl -> PrintSearhResult($aMemberInfo, array(), ($iIndex % 2 ? $aExtendedCss : array()), $sTemplateName);
130  $iIndex++;
131  }
132 
133  $sOutputHtml .= '<div class="clear_both"></div>';
134 
135  // work with link pagination ;
136  $aGetParams = array('mode', 'iUser', 'photos_only', 'online_only');
137  $sRequest = CH_WSB_URL_ROOT . 'viewFriends.php?';
138  $sRequest .= ch_encode_url_params($_GET, array(), $aGetParams) . 'page={page}&per_page={per_page}&sort={sorting}';
139 
140  // gen pagination block ;
141  $oPaginate = new ChWsbPaginate (
142  array (
143  'page_url' => $sRequest,
144  'count' => $iTotalNum,
145  'per_page' => $iPerPage,
146  'page' => $iCurPage,
147  'sorting' => $this -> aDisplayParameters['sort'],
148  )
149  );
150 
151  $sPagination = $oPaginate -> getPaginate();
152 
153  // ** GENERATE HEADER PART ;
154 
155  // gen per page block ;
156 
157  $sPerPageBlock = $oPaginate -> getPages( $iPerPage );
158 
159  // fill array with sorting params
160  $aSortingParam = array(
161  'activity' => _t('_Latest activity'),
162  'date_reg' => _t('_FieldCaption_DateReg_View'),
163  );
164  if (getParam('votes')) $aSortingParam['rate'] = _t('_Rate');
165 
166  // gen sorting block ( type of : drop down ) ;
167 
168  $sSortBlock = $oPaginate -> getSorting( $aSortingParam );
169 
170  $sRequest = str_replace('{page}', '1', $sRequest);
171  $sRequest = str_replace('{per_page}', $iPerPage, $sRequest);
172  $sRequest = str_replace('{sorting}', $this -> aDisplayParameters['sort'], $sRequest);
173 
174  // init some visible parameters ;
175 
176  $sPhotosChecked = ($this -> aDisplayParameters['photos'])
177  ? 'checked="checked"'
178  : null;
179 
180  $sOnlineChecked = ($this -> aDisplayParameters['online'])
181  ? 'checked="checked"'
182  : null;
183 
184  // link for photos section ;
185 
186  $sPhotoLocation = $this -> getCutParam( 'photos_only', $sRequest);
187 
188  // link for online section ;
189 
190  $sOnlineLocation = $this -> getCutParam( 'online_only', $sRequest);
191 
192  // link for `mode switcher` ;
193 
194  $sModeLocation = $this -> getCutParam( 'mode', $sRequest);
195  $sModeLocation = $this -> getCutParam( 'per_page', $sModeLocation);
196 
197  ch_import('ChWsbMemberInfo');
198  $oMemberInfo = ChWsbMemberInfo::getObjectInstance(getParam('sys_member_info_thumb'));
199 
200  $sTopControls = $GLOBALS['oSysTemplate']->parseHtmlByName('browse_sb_top_controls.html', array(
201  'sort_block' => $sSortBlock,
202  'ch_if:show_with_photos' => array(
203  'condition' => $oMemberInfo->isAvatarSearchAllowed(),
204  'content' => array(
205  'photo_checked' => $sPhotosChecked,
206  'photo_location' => $sPhotoLocation,
207  'photo_caption' => $sPhotoCaption,
208  )
209  ),
210  'online_checked' => $sOnlineChecked,
211  'online_location' => $sOnlineLocation,
212  'online_caption' => $sOnlineCaption,
213  'per_page_block' => $sPerPageBlock
214  ));
215 
216  // build template ;
217  $sOutputHtml = $GLOBALS['oSysTemplate'] -> parseHtmlByName( $aUsedTemplates[0], array (
218  'top_controls' => $sTopControls,
219  'ch_if:show_sim_css' => array (
220  'condition' => $this->aDisplayParameters['mode'] != 'extended',
221  'content' => array()
222  ),
223  'ch_if:show_ext_css' => array (
224  'condition' => $this->aDisplayParameters['mode'] == 'extended',
225  'content' => array()
226  ),
227  'searched_data' => $sOutputHtml,
228  'pagination' => $sPagination,
229  ));
230 
231  // build the toggle block ;
232  $aToggleItems = array
233  (
234  '' => _t( '_Simple' ),
235  'extended' => _t( '_Extended' ),
236  );
237 
238  foreach( $aToggleItems AS $sKey => $sValue ) {
239  $aToggleEllements[$sValue] = array (
240  'href' => $sModeLocation . '&mode=' . $sKey,
241  'dynamic' => true,
242  'active' => ($this -> aDisplayParameters['mode'] == $sKey ),
243  );
244  }
245 
246  return array($sOutputHtml . $sEmpty, $aToggleEllements, array(), true);
247  }
248 
250  {
252 
253  if($this->iProfileID != getLoggedId())
254  return '';
255 
256  ch_import('ChTemplCommunicator');
257  $oCommunicator = new ChTemplCommunicator(array('member_id' => $this->iProfileID));
258 
259  $oSysTemplate->addCss($oCommunicator->getCss());
260  $oSysTemplate->addJs($oCommunicator->getJs());
261  return $oCommunicator->getBlockCode_FriendRequests();
262  }
263 
265  {
266  if($this->iProfileID == getLoggedId())
267  return '';
268 
269  return $this->oProfile->showBlockMutualFriends('', true);
270  }
271 
277  function getCutParam( $sExceptParam, $sString )
278  {
279  return preg_replace( "/(&amp;|&){$sExceptParam}=([a-z0-9\_\-]{1,})/i",'', $sString);
280  }
281 
291  public static function get_member_menu_bubble_online_friends($iMemberId, $iOldCount = 0)
292  {
294 
295  $iMemberId = (int) $iMemberId;
296  $iOldCount = (int) $iOldCount;
297  $iOnlineTime = (int) getParam( "member_online_time" );
298  $iOnlineFriends = 0;
299 
300  $aNotifyMessages = array();
301  $aFriends = array();
302 
303  if ( $iMemberId ) {
304  $sWhereCondition = " AND (p.`DateLastNav` > SUBDATE(NOW(), INTERVAL " . $iOnlineTime . " MINUTE))";
305  if( null != $aFoundFriends = getMyFriendsEx($iMemberId, $sWhereCondition) ) {
306  foreach($aFoundFriends as $iFriendId => $aInfo) {
307  $aFriends[] = array($iFriendId);
308  }
309  }
310 
311  $iOnlineFriends = count($aFriends);
312  // $aFriends = array_reverse($aFriends);
313 
314  // if have some difference;
315  if ( $iOnlineFriends > $iOldCount) {
316  // generate notify messages;
317  for( $i = $iOldCount; $i < $iOnlineFriends; $i++) {
318  $sFriendNickName = getNickName($aFriends[$i][0]);
319  $sProfileLink = getProfileLink($aFriends[$i][0]);
320 
321  $aKeys = array (
322  'sender_thumb' => $oFunctions -> getMemberIcon($aFriends[$i][0], 'left'),
323  'profile_link' => $sProfileLink,
324  'friend_nickname' => $sFriendNickName,
325  'key_on_line' => _t( '_Now online' ),
326  );
327  $sMessage = $oSysTemplate -> parseHtmlByName('view_friends_member_menu_notify_window.html', $aKeys);
328 
329  $aNotifyMessages[] = array(
330  'message' => $oSysTemplate -> parseHtmlByName('member_menu_notify_window.html', array('message' => $sMessage))
331  );
332  }
333  }
334  }
335 
336  $aRetEval = array(
337  'count' => $iOnlineFriends,
338  'messages' => $aNotifyMessages,
339  );
340 
341  return $aRetEval;
342  }
343 
353  public static function get_member_menu_bubble_friend_requests($iMemberId, $iOldCount = 0)
354  {
356 
357  $iMemberId = (int) $iMemberId;
358  $iOldCount = (int) $iOldCount;
359  $iOnlineTime = (int) getParam( "member_online_time" );
360  $iOnlineFriends = 0;
361 
362  $aNotifyMessages = array();
363  $aFriends = array();
364 
365  if ( $iMemberId ) {
366  $sSql = "SELECT `tp`.`ID` FROM `sys_friend_list` AS `tf` LEFT JOIN `Profiles` AS `tp` ON `tf`.`ID`=`tp`.`ID` WHERE `tf`.`Profile`={$iMemberId} AND `tf`.`Check`='0' AND `tp`.`Status`='Active' ORDER BY `tf`.`When`";
367  $aFriends = $GLOBALS['MySQL']->getColumn($sSql);
368 
369  $iOnlineFriends = count($aFriends);
370  if($iOnlineFriends > $iOldCount)
371  for($i = $iOldCount; $i < $iOnlineFriends; $i++) {
372  $aKeys = array (
373  'sender_thumb' => $oFunctions -> getMemberIcon($aFriends[$i], 'left'),
374  'profile_link' => getProfileLink($aFriends[$i]),
375  'friend_nickname' => getNickName($aFriends[$i]),
376  'key_on_line' => _t( '_Now online' ),
377  );
378  $sMessage = $oSysTemplate->parseHtmlByName('view_friends_member_menu_notify_window.html', $aKeys);
379 
380  $aNotifyMessages[] = array(
381  'message' => $oSysTemplate -> parseHtmlByName('member_menu_notify_window.html', array('message' => $sMessage))
382  );
383  }
384  }
385 
386  $aRetEval = array(
387  'count' => $iOnlineFriends,
388  'messages' => $aNotifyMessages,
389  );
390 
391  return $aRetEval;
392  }
393 
400  public static function get_member_menu_friends_list($iMemberId = 0)
401  {
403 
404  $iMemberId = (int) $iMemberId;
405  $iOnlineTime = (int)getParam('member_online_time');
406 
407  // define the member's menu position ;
408  $sExtraMenuPosition = ( isset($_COOKIE['menu_position']) )
409  ? $_COOKIE['menu_position']
410  : getParam( 'ext_nav_menu_top_position' );
411 
412  $aLanguageKeys = array (
413  'requests' => _t( '_Friend Requests' ),
414  'online' => _t( '_Online Friends' ),
415  );
416 
417  // get all friends requests ;
418  $iFriendsRequests = getFriendRequests($iMemberId) ;
419  $iOnlineFriends = getFriendNumber($iMemberId, 1, $iOnlineTime) ;
420 
421  // try to generate member's messages list ;
422 
423  $sWhereParam = "AND p.`DateLastNav` > SUBDATE(NOW(), INTERVAL " . $iOnlineTime . " MINUTE)";
424  $aAllFriends = getMyFriendsEx($iMemberId, $sWhereParam, 'last_nav_desc', "LIMIT 5");
425  $oModuleDb = new ChWsbModuleDb();
426 
427  $sVideoMessengerImgPath = $GLOBALS['oSysTemplate'] -> getIconUrl('video.png');
428  $sMessengerTitle = _t('_Chat');
429 
430  foreach ($aAllFriends as $iFriendID => $aFriendsPrm) {
431  $aMemberInfo = getProfileInfo($iFriendID);
432  $sThumb = $oFunctions -> getMemberIcon($aMemberInfo['ID'], 'none');
433 
434  $sHeadline = ( mb_strlen($aMemberInfo['UserStatusMessage']) > 40 )
435  ? mb_substr($aMemberInfo['UserStatusMessage'], 0, 40) . '...'
436  : $aMemberInfo['UserStatusMessage'];
437 
438  $aFriends[] = array(
439  'profile_link' => getProfileLink($iFriendID),
440  'profile_nick' => $aMemberInfo['NickName'],
441  'profile_id' => $iFriendID,
442  'thumbnail' => $sThumb,
443  'head_line' => $sHeadline,
444 
445  'ch_if:video_messenger' => array (
446  'condition' => ( $oModuleDb -> isModule('messenger') ),
447  'content' => array(
448  'sender_id' => $iMemberId,
449  'sender_passw' => getPassword($iMemberId),
450  'recipient_id' => $iFriendID,
451  'video_img_src' => $sVideoMessengerImgPath,
452  'messenger_title' => $sMessengerTitle,
453  ),
454  ),
455  );
456  }
457 
458  $aExtraSection = array(
459  'friends_request' => $aLanguageKeys['requests'],
460  'request_count' => $iFriendsRequests,
461 
462  'ID' => $iMemberId,
463  'online_friends' => $aLanguageKeys['online'],
464  'online_count' => $iOnlineFriends,
465  );
466 
467  // fill array with needed keys ;
468  $aTemplateKeys = array (
469  'ch_if:menu_position_bottom' => array (
470  'condition' => ( $sExtraMenuPosition == 'bottom' ),
471  'content' => $aExtraSection,
472  ),
473 
474  'ch_if:menu_position_top' => array (
475  'condition' => ( $sExtraMenuPosition == 'top' || $sExtraMenuPosition == 'static' ),
476  'content' => $aExtraSection,
477  ),
478 
479  'ch_repeat:friend_list' => $aFriends,
480  );
481 
482  $sOutputCode = $GLOBALS['oSysTemplate'] -> parseHtmlByName( 'view_friends_member_menu_friends_list.html', $aTemplateKeys );
483  return $sOutputCode;
484  }
485 }
$sMessage
$sMessage
Definition: actions.inc.php:17
$iMemberId
$iMemberId
Definition: profile.php:91
ChWsbMemberInfo\getObjectInstance
static getObjectInstance($sObject)
Definition: ChWsbMemberInfo.php:39
getMyFriendsEx
getMyFriendsEx($iID, $sWhereParam='', $sSortParam='', $sqlLimit='')
Definition: profiles.inc.php:384
$sOutputHtml
$sOutputHtml
Definition: browse.php:86
MsgBox
MsgBox($sText, $iTimer=0)
Definition: design.inc.php:175
$sLimitFrom
$sLimitFrom
Definition: post_mod_crss.php:49
ChWsbFriendsPageView\$oSearchProfileTmpl
$oSearchProfileTmpl
Definition: ChWsbFriendsPageView.php:20
ChWsbPageView
Definition: ChWsbPageView.php:99
ChTemplSearchProfile
Definition: ChTemplSearchProfile.php:11
ChWsbFriendsPageView\getBlockCode_FriendsMutual
getBlockCode_FriendsMutual()
Definition: ChWsbFriendsPageView.php:264
ch_import
ch_import($sClassName, $aModule=array())
Definition: utils.inc.php:1218
$iCurPage
$iCurPage
Definition: post_mod_crss.php:46
ChTemplProfileGenerator
Definition: ChTemplProfileGenerator.php:11
$oCommunicator
$oCommunicator
Definition: communicator.php:68
ChWsbFriendsPageView\getBlockCode_Friends
getBlockCode_Friends()
Definition: ChWsbFriendsPageView.php:54
getPassword
getPassword( $ID='')
Definition: profiles.inc.php:475
php
ChWsbFriendsPageView\get_member_menu_friends_list
static get_member_menu_friends_list($iMemberId=0)
Definition: ChWsbFriendsPageView.php:400
ChWsbModuleDb
Definition: ChWsbModuleDb.php:12
$iPerPage
else $iPerPage
Definition: browse.php:61
$aMemberInfo
$aMemberInfo
Definition: profile_info.php:34
ChWsbFriendsPageView\$iMemberOnlineTime
$iMemberOnlineTime
Definition: ChWsbFriendsPageView.php:25
ChWsbFriendsPageView\get_member_menu_bubble_online_friends
static get_member_menu_bubble_online_friends($iMemberId, $iOldCount=0)
Definition: ChWsbFriendsPageView.php:291
ChWsbFriendsPageView\__construct
__construct($sPageName, &$aDisplayParameters, $iProfileID)
Definition: ChWsbFriendsPageView.php:37
ChWsbFriendsPageView
Definition: ChWsbFriendsPageView.php:12
$oFunctions
$oFunctions
Definition: ChTemplFunctions.php:20
getFriendRequests
getFriendRequests($iID)
Definition: profiles.inc.php:329
$aInfo
$aInfo
Definition: constants.inc.php:21
$_GET
$_GET['debug']
Definition: index.php:67
$iIndex
$iIndex
Definition: bottom_menu_compose.php:142
$oModuleDb
$oModuleDb
Definition: classifieds.php:20
getParam
getParam($sParamName, $bUseCache=true)
Definition: db.inc.php:130
ChWsbFriendsPageView\getCutParam
getCutParam( $sExceptParam, $sString)
Definition: ChWsbFriendsPageView.php:277
getLoggedId
getLoggedId()
Definition: profiles.inc.php:32
getNickName
getNickName( $ID='')
Definition: profiles.inc.php:461
$site
$site['ver']
Definition: version.inc.php:8
ChWsbFriendsPageView\getBlockCode_FriendsRequests
getBlockCode_FriendsRequests()
Definition: ChWsbFriendsPageView.php:249
ChWsbFriendsPageView\get_member_menu_bubble_friend_requests
static get_member_menu_bubble_friend_requests($iMemberId, $iOldCount=0)
Definition: ChWsbFriendsPageView.php:353
ChWsbPaginate
Definition: ChWsbPaginate.php:69
global
if(!defined("GLOBAL_MODULE")) define("GLOBAL_MODULE" global
Definition: header.inc.php:25
ChWsbFriendsPageView\$sCurrentPage
$sCurrentPage
Definition: ChWsbFriendsPageView.php:23
_t
_t($key, $arg0="", $arg1="", $arg2="")
Definition: languages.inc.php:509
getProfileLink
getProfileLink( $iID, $sLinkAdd='')
Definition: profiles.inc.php:484
ChTemplCommunicator
Definition: ChTemplCommunicator.php:11
ChWsbPageView\$sPageName
$sPageName
Definition: ChWsbPageView.php:100
default
Attr AllowedFrameTargets _parent and _top Values should be as validation will be done in a case sensitive manner despite W3C s recommendation XHTML Strict does not permit the target attribute so this directive will have no effect in that doctype XHTML does not enable the Target module by default
Definition: Attr.AllowedFrameTargets.txt:10
ChWsbFriendsPageView\$iProfileID
$iProfileID
Definition: ChWsbFriendsPageView.php:16
getProfileInfo
getProfileInfo($iProfileID=0, $checkActiveStatus=false, $forceCache=false)
Definition: profiles.inc.php:249
ChWsbFriendsPageView\$aDisplayParameters
$aDisplayParameters
Definition: ChWsbFriendsPageView.php:14
$iTotalNum
if(isset($_POST['crsss']) &&is_array($_POST['crsss'])) $iTotalNum
Definition: post_mod_crss.php:40
$oSysTemplate
$oSysTemplate
Definition: params.inc.php:22
getFriendNumber
getFriendNumber($iID, $iFrStatus=1, $iOnline=0, $sqlWhere='')
Definition: profiles.inc.php:301
as
as
Definition: Filter.ExtractStyleBlocks.Escaping.txt:10
ChWsbFriendsPageView\$oProfile
$oProfile
Definition: ChWsbFriendsPageView.php:17
$GLOBALS
$GLOBALS['iAdminPage']
Definition: advanced_settings.php:10
ch_encode_url_params
ch_encode_url_params($a, $aExcludeKeys=array(), $aOnlyKeys=false)
Definition: utils.inc.php:1675