12 require_once(
'ChSpyResponseContent.php');
13 require_once(
'ChSpyResponseProfiles.php');
14 require_once(
'ChSpySearch.php');
105 $this -> sPathToModule = CH_WSB_URL_ROOT . $this -> _oConfig -> getBaseUri();
111 $this -> sSpyMode = isset(
$_GET[
'mode']) ?
$_GET[
'mode'] :
'global';
115 $this -> iPage = ( isset(
$_GET[
'page']) )
116 ? (
int)
$_GET[
'page']
119 $this -> iPerPage = ( isset(
$_GET[
'per_page']) )
120 ? (
int)
$_GET[
'per_page']
121 : $this -> _oConfig -> iPerPage;
134 header(
'location: ' . CH_WSB_URL_ROOT);
139 $aLanguageKeys = array(
140 'premoderation' =>
_t(
'_ch_spy_admin'),
149 $aMenu[
'ch_spy_main'][
'active'] = 1;
151 $iCategoryId = $this-> _oDb -> getSettingsCategory(
'ch_spy_keep_rows_days');
156 if(isset($_POST[
'save']) && isset($_POST[
'cat'])) {
158 $mixedResult =
$oSettings -> saveChanges($_POST);
164 if($mixedResult !==
true && !
empty($mixedResult))
168 -> parseHtmlByName(
'design_box_content.html', array(
'content' =>
$sResult) );
173 $this -> _oTemplate-> pageCodeAdminStart();
174 echo $this -> _oTemplate -> adminBlock (
$sContent, $aLanguageKeys[
'premoderation']);
175 $this -> _oTemplate->pageCodeAdmin(
_t(
'_ch_spy_module') );
185 $this -> _oDb -> setViewedProfileActivity($this -> iMemberId);
198 $sPageUrl = $this -> sPathToModule;
199 $iLastActivityId = (int) $iLastActivityId;
209 $this -> oSearch -> aCurrent[
'restriction'][
'only_me'][
'value'] =
$iProfileId;
213 case 'friends_events' :
215 if(!$this -> iMemberId ) {
219 $this -> oSearch -> aCurrent[
'join'][] = array(
221 'table' => $this -> _oDb -> sTablePrefix .
'friends_data',
223 'onField' =>
'event_id',
224 'joinFields' => array(),
227 $this -> oSearch -> aCurrent[
'restriction'][
'friends'][
'value'] = $this -> iMemberId;
228 $this -> oSearch -> aCurrent[
'restriction'][
'no_my'][
'value'] = $this -> iMemberId;
229 $this -> oSearch -> aCurrent[
'restriction'][
'over_id'][
'value'] = $iLastActivityId;
231 $sPageUrl .=
'&mode=' . $this -> sSpyMode;
235 $this -> oSearch -> aCurrent[
'restriction'][
'id'] = array(
238 'value' => $iLastActivityId,
243 $aActivites = $this -> oSearch -> getSearchData();
244 $aProccesedActivites = $this ->
_proccesActivites($aActivites,
' style="display:none" ',
true);
247 'events' => $aProccesedActivites,
248 'last_event_id' => $this -> _oDb -> getLastActivityId(
$sType),
252 echo json_encode($aRet);
275 $sPageUrl = $this -> sPathToModule;
276 if(!
empty($this->sSpyMode))
281 'page_ajax' =>
false,
282 'page_url' => $this->_oConfig->getBaseUri(),
283 'profile' => $iProfile
287 $aParams[
'type'] =
$sType;
288 $sPageUrl .=
'&spy_type=' .
$sType;
293 $sOutputCode = $aCode[0];
295 $sOutputCode .= $aCode[2];
309 $this -> _oTemplate -> addJs(
'spy.js');
316 if($this -> sSpyMode ==
'friends_events' &&
$iProfileId) {
317 $iLastActivityId = $this -> _oDb -> getLastFriendsActivityId(
$iProfileId,
$sType);
320 $iLastActivityId = $this -> _oDb -> getLastActivityId(
$sType);
321 $iActivityCount = $this -> _oDb -> getActivityCount(
$sType);
324 $sActive = $bActive ?
'true' :
'false';
327 <script
type=
"text/javascript">
330 oSpy.sPageReceiver =
'{$this -> sPathToModule}';
331 oSpy.iUpdateTime = {$this -> _oConfig -> iUpdateTime};
332 oSpy.sEventsContainer =
'{$this -> sEventsWrapper}';
333 oSpy.sPageMode =
'{$this -> sSpyMode}';
334 oSpy.iLastEventId = {$iLastActivityId};
335 oSpy.iEventsCount = {$iActivityCount};
336 oSpy.iPerPage = {$this -> iPerPage};
337 oSpy.iSlideDown = {$this -> _oConfig -> iSpeedToggleDown};
338 oSpy.iSlideUp = {$this -> _oConfig -> iSpeedToggleUp};
339 oSpy.sActivityType =
'{$sType}';
341 oSpy.bUpdateAllowed = {$sActive};
360 $aToggleItems = array (
361 'all' =>
_t(
'_ch_spy_all_activity' ),
362 'content_activity' =>
_t(
'_ch_spy_content_updates' ),
363 'profiles_activity' =>
_t(
'_ch_spy_profiles_updates' ),
368 if( isset(
$_GET[
'mode']) ) {
369 $sExtraParam =
'&mode=' .
$_GET[
'mode'];
375 $sRequest = (!$sPageUrl) ? $this -> sPathToModule . $sExtraParam : $sPageUrl . $sExtraParam ;
377 foreach( $aToggleItems AS $sKey => $sValue ) {
378 $aTopToggleEllements[$sValue] = array
380 'href' => $sRequest .
'&spy_type=' . $sKey,
382 'active' => ( (isset(
$_GET[
'spy_type']) &&
$_GET[
'spy_type'] == $sKey)
383 || !isset(
$_GET[
'spy_type']) && $sKey ==
'all' ) ?
true :
false,
399 $oResponse -> response(
$oAlert);
405 $oResponse -> response(
$oAlert);
410 $aModules = $sModuleUri ==
'all' ? $this -> _oDb -> getModules() : array($this->_oDb->getModuleByUri($sModuleUri));
418 $this -> _oDb -> insertData($aData);
420 $this -> _oDb -> deleteData($aData);
437 'page_url' => rawurlencode($sPage),
444 $this->sSpyMode =
'friends_events';
446 $sPageUrl =
'viewFriends.php?iUser=' .
$iProfileId;
448 'page_url' => $sPageUrl,
469 $this -> oSearch -> aCurrent[
'restriction'][
'only_me'][
'value'] =
$iProfileId;
470 $this -> oSearch -> aCurrent[
'paginate'][
'limit'] = $this -> _oConfig -> iMemberMenuNotifyCount;
473 $aActivites = $this -> oSearch -> getSearchData();
478 $sOutputCode = $this ->
_proccesActivites($aActivites,
'',
false,
false,
'spy_events_wrapper_menu_member');
479 $sOutputCode .= $this->_oTemplate->parseHtmlByName(
'member_menu_link.html', array(
480 'link' => $this->_oConfig->getBaseUri(),
481 'caption' =>
_t(
'_ch_spy_view_all'),
484 $sOutputCode =
MsgBox(
_t(
'_Empty') );
487 echo $this -> _oTemplate -> addCss(
'spy.css',
true);
503 $iOldCount = (int) $iOldCount;
504 $iNewNotifyCount = 0;
505 $aNotifyMessages = array();
512 $this -> oSearch -> aCurrent[
'restriction'][
'only_me'][
'value'] =
$iProfileId;
513 $this -> oSearch -> aCurrent[
'restriction'][
'type'][
'value'] =
'';
515 $this -> oSearch -> aCurrent[
'restriction'][
'viewed'][
'value'] = array(0);
516 $this -> oSearch -> aCurrent[
'paginate'][
'unlimit'] =
true;
519 $aActivites = $this -> oSearch -> getSearchData();
522 $aActivites = array_reverse($aActivites);
523 $iNewNotifyCount = count($aActivites);
526 if ($iNewNotifyCount > $iOldCount) {
528 for( $i = $iOldCount; $i < $iNewNotifyCount; $i++) {
529 $aTemp[] = $aActivites[$i];
532 $aNotifyMessages[] = array(
533 'message' =>
$oSysTemplate -> parseHtmlByName(
'member_menu_notify_window.html', array(
'message' =>
$sMessage))
540 $sCode =
'var _sRandom = Math.random(); $.get("' . $this -> sPathToModule .
'set_as_read&_random=" + _sRandom);';
542 'count' => $iNewNotifyCount,
543 'messages' => $aNotifyMessages,
544 'onlclick_script' => $aActivites ?
$sCode :
'',
561 $sKey = str_replace(
'{' . $sArrayKey .
'}',
$aParameters[$sArrayKey], $sKey);
580 if(!isset(
$aVars[
'active']))
582 if(!isset(
$aVars[
'dynamic']))
584 if(!isset(
$aVars[
'type']))
586 if(!isset(
$aVars[
'page_ajax']))
587 $aVars[
'page_ajax'] =
true;
588 if(!isset(
$aVars[
'page']))
593 $this -> oSearch -> aCurrent[
'restriction'][
'viewed'][
'value'] =
'';
594 if(
$aVars[
'type'] !=
'all')
597 switch($this->sSpyMode) {
598 case 'friends_events':
599 $this -> oSearch -> aCurrent[
'join'][
'friends_data'] = array(
601 'table' => $this -> _oDb -> sTablePrefix .
'friends_data',
603 'onField' =>
'event_id',
604 'joinFields' => array(),
607 $this -> oSearch -> aCurrent[
'restriction'][
'friends'][
'value'] =
$aVars[
'profile'];
608 $this -> oSearch -> aCurrent[
'restriction'][
'no_my'][
'value'] =
$aVars[
'profile'];
614 $this -> oSearch -> aCurrent[
'restriction'][
'only_me'][
'value'] =
$aVars[
'profile'];
618 $aActivites = $this -> oSearch -> getSearchData();
621 $sOutputCode = $this->_oTemplate->getWrapper($this -> sEventsWrapper, $aActivites ? $sActivites :
MsgBox(
_t(
'_Empty')));
625 if($this -> oSearch -> aCurrent[
'paginate'][
'totalNum'] > $this -> _oConfig -> iPerPage) {
626 $aVars[
'page_url'] .= (strpos(
$aVars[
'page_url'],
'?') ===
false ?
'?' :
'&') .
'type=' .
$aVars[
'type'] .
'&page={page}&per_page={per_page}';
630 $sOnClick =
'return !loadDynamicBlock({id}, \'' .
$aVars[
'page_url'] .
'\')
';
632 $oPaginate = new ChWsbPaginate(array(
633 'page_url
' => $aVars['page_url
'],
634 'count
' => $this -> oSearch -> aCurrent['paginate
']['totalNum
'],
635 'per_page
' => $this -> _oConfig -> iPerPage,
636 'page
' => $aVars['page
'],
637 'on_change_page
' => $sOnClick,
640 $sPaginate = $oPaginate -> getSimplePaginate(null, -1, -1, false);
643 if($aVars['dynamic
'])
644 header('Content-Type: text/html;
charset=utf-8
');
646 $this ->_oTemplate->addCss('spy.css
');
648 //-- check init part --//
649 if($aVars['page
'] == 1)
650 $sOutputCode = $this -> getInitPart($aVars['type'], $aVars['profile
'], $aVars['active
']) . $sOutputCode;
651 return array($sOutputCode, array(), $sPaginate, true);
662 function _proccesActivites($aActivites, $sExtraStyles = '', $inArray = false, $bSetViewed = false, $sExtraCssClass = null)
665 $aProcessedActivites = array();
667 if( is_array($aActivites) ) {
668 foreach($aActivites as $iKey => $aItems) {
669 $aParams = unserialize($aItems['params
']);
672 $this -> _oDb -> setViewed($aItems['id']);
675 // procces activity text;
676 $sActivity = $this -> _parseParameters( _t($aItems['lang_key
']), $aParams );
678 // define activity's sender;
679 if($aItems[
'sender_id']) {
680 $aTemplateKeys = array(
682 'event_caption' => $sActivity,
683 'extra_styles' => $sExtraStyles,
684 'extra_css_class' => $sExtraCssClass,
688 $sTemplateName =
'activity.html';
690 $aTemplateKeys = array(
691 'event_caption' => $sActivity,
692 'extra_styles' => $sExtraStyles,
693 'extra_css_class' => $sExtraCssClass,
697 $sTemplateName =
'non_member_activity.html';
702 $sOutputCode .= $this -> _oTemplate -> parseHtmlByName($sTemplateName, $aTemplateKeys);
704 $aProcessedActivites[] = array(
705 'event' => $this -> _oTemplate -> parseHtmlByName($sTemplateName, $aTemplateKeys),
711 return (!$inArray) ? $sOutputCode : $aProcessedActivites;