| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418 |
- <?php defined('BX_DOL') or die('hack attempt');
- /**
- * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
- * CC-BY License - http://creativecommons.org/licenses/by/3.0/
- *
- * @defgroup Persons Persons
- * @ingroup DolphinModules
- *
- * @{
- */
- bx_import ('BxDolModule');
- bx_import ('BxDolAcl');
- /**
- * Persons module
- *
- * Basic person profiles.
- */
- class BxPersonsModule extends BxDolModule implements iBxDolProfileService {
- protected $_iProfileId;
- protected $_iAccountId;
- function __construct(&$aModule) {
- parent::__construct($aModule);
- $this->_iProfileId = bx_get_logged_profile_id();
- $this->_iAccountId = getLoggedId();
- }
- // ====== SERVICE METHODS
- public function serviceProfilesSearch ($sTerm, $iLimit) {
- $aRet = array();
- $a = $this->_oDb->searchByTerm($sTerm, $iLimit);
- foreach ($a as $r)
- $aRet[] = array ('label' => $this->serviceProfileName($r['content_id']), 'value' => $r['profile_id']);
- return $aRet;
- }
- public function serviceProfileUnit ($iContentId) {
- return $this->_serviceTemplateFunc('unit', $iContentId);
- }
- public function serviceProfileAvatar ($iContentId) {
- return $this->_serviceTemplateFunc('urlAvatar', $iContentId);
- }
- public function serviceProfileThumb ($iContentId) {
- return $this->_serviceTemplateFunc('thumb', $iContentId);
- }
- public function serviceProfileIcon ($iContentId) {
- return $this->_serviceTemplateFunc('icon', $iContentId);
- }
- protected function _serviceTemplateFunc ($sFunc, $iContentId) {
- if (!$iContentId)
- return false;
- $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
- if (!$aContentInfo)
- return false;
- return $this->_oTemplate->$sFunc($aContentInfo);
- }
- public function serviceProfileName ($iContentId) {
- if (!$iContentId)
- return false;
- $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
- if (!$aContentInfo)
- return false;
- return $aContentInfo[BxPersonsConfig::$FIELD_NAME];
- }
- public function serviceProfileUrl ($iContentId) {
- if (!$iContentId)
- return false;
- $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
- if (!$aContentInfo)
- return false;
- bx_import('BxDolPermalinks');
- return BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=view-persons-profile&id=' . $aContentInfo['id']);
- }
- public function serviceBrowseRecentPersons () {
- return $this->_serviceBrowse ('recent');
- }
- public function serviceBrowseConnections ($iProfileId, $sObjectConnections = 'sys_profiles_friends', $sConnectionsType = 'content', $iMutual = false, $iDesignBox = BX_DB_PADDING_DEF, $iProfileId2 = 0) {
- return $this->_serviceBrowse (
- 'connections',
- array(
- 'object' => $sObjectConnections,
- 'type' => $sConnectionsType,
- 'mutual' => $iMutual,
- 'profile' => (int)$iProfileId,
- 'profile2' => (int)$iProfileId2),
- $iDesignBox
- );
- }
- protected function _serviceBrowse ($sMode, $aParams = false, $iDesignBox = BX_DB_PADDING_DEF) {
- bx_import('SearchResult', $this->_aModule);
- $sClass = $this->_aModule['class_prefix'] . 'SearchResult';
- $o = new $sClass($sMode, $aParams);
- $o->setDesignBoxTemplateId($iDesignBox);
- if ($o->isError)
- return false;
- if ($s = $o->processing())
- return $s;
- else
- return false;
- }
- public function serviceCreateProfile () {
- bx_import('ProfileForms', $this->_aModule);
- $oProfileForms = new BxPersonsProfileForms($this);
- return $oProfileForms->addDataForm();
- }
- public function serviceEditProfile ($iContentId = 0) {
- if (!$iContentId)
- $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
- if (!$iContentId)
- return false;
- bx_import('ProfileForms', $this->_aModule);
- $oProfileForms = new BxPersonsProfileForms($this);
- return $oProfileForms->editDataForm((int)$iContentId);
- }
- public function serviceEditCover ($iContentId = 0) {
- if (!$iContentId)
- $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
- if (!$iContentId)
- return false;
- bx_import('ProfileForms', $this->_aModule);
- $oProfileForms = new BxPersonsProfileForms($this);
- return $oProfileForms->editDataForm((int)$iContentId, 'bx_person_edit_cover');
- }
- public function serviceDeleteProfile ($iContentId = 0) {
- if (!$iContentId)
- $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
- if (!$iContentId)
- return false;
- bx_import('ProfileForms', $this->_aModule);
- $oProfileForms = new BxPersonsProfileForms($this);
- return $oProfileForms->deleteDataForm((int)$iContentId);
- }
- public function serviceProfileInfo ($iContentId = 0) {
- if (!$iContentId)
- $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
- if (!$iContentId)
- return false;
- bx_import('ProfileForms', $this->_aModule);
- $oProfileForms = new BxPersonsProfileForms($this);
- return $oProfileForms->viewDataForm((int)$iContentId);
- }
- public function serviceProfileCover ($iContentId = 0) {
- if (!$iContentId)
- $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
- if (!$iContentId)
- return false;
- $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
- if (!$aContentInfo)
- return false;
- return $this->_oTemplate->cover($aContentInfo);
- }
- public function serviceProfileActions ($iContentId = 0) {
- if (!$iContentId)
- $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
- if (!$iContentId)
- return false;
- bx_import('BxTemplMenu');
- $oMenu = BxTemplMenu::getObjectInstance('bx_persons_view_actions');
- return $oMenu ? $oMenu->getCode() : false;
- }
- public function serviceProfileFriends ($iContentId = 0) {
- if (!$iContentId)
- $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
- if (!$iContentId)
- return false;
- $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
- if (!$aContentInfo)
- return false;
-
- return 'TODO: friends here';
- }
- // ====== ACTION METHODS
- function actionBrowse ($sMode = '') {
- $sMode = bx_process_input($sMode);
- /*
- if ('user' == $sMode || 'my' == $sMode) {
- $aProfile = getProfileInfo ($this->_iProfileId);
- if (0 == strcasecmp($sValue, $aProfile['NickName']) || 'my' == $sMode) {
- $this->_browseMy ($aProfile);
- return;
- }
- }
- if ('tag' == $sMode || 'category' == $sMode)
- $sValue = uri2title($sValue);
- */
- if (CHECK_ACTION_RESULT_ALLOWED !== $this->isAllowedBrowse()) {
- $this->_oTemplate->displayAccessDenied ();
- return;
- }
- bx_import ('SearchResult', $this->_aModule);
- $sClass = $this->_aModule['class_prefix'] . 'SearchResult';
- $o = new $sClass($sMode);
- if ($o->isError) {
- $this->_oTemplate->displayPageNotFound ();
- return;
- }
- if (bx_get('rss')) {
- echo $o->rss();
- exit;
- }
- if (!($s = $o->processing())) {
- $this->_oTemplate->displayNoData ();
- return;
- }
- // TODO: remale to use "pages"
- $this->_oTemplate->addCss ('main.css');
- $oTemplate = BxDolTemplate::getInstance();
- $oTemplate->setPageHeader ($o->aCurrent['title']);
- $oTemplate->setPageNameIndex (BX_PAGE_DEFAULT);
- $oTemplate->setPageContent ('page_main_code', $s);
- $oTemplate->getPageCode();
- }
- // ====== PERMISSION METHODS
- function _checkModeratorAccess ($isPerformAction = false) {
- // check moderator ACL
- $aCheck = checkActionModule($this->_iProfileId, 'edit any person profile', $this->getName(), $isPerformAction);
- return $aCheck[CHECK_ACTION_RESULT] === CHECK_ACTION_RESULT_ALLOWED;
- }
- /**
- * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make "true === " checking.
- */
- function isAllowedView ($aDataEntry, $isPerformAction = false) {
- // moderator and owner always have access
- if ($aDataEntry[BxPersonsConfig::$FIELD_AUTHOR] == $this->_iProfileId || $this->_checkModeratorAccess($isPerformAction))
- return CHECK_ACTION_RESULT_ALLOWED;
- // check ACL
- $aCheck = checkActionModule($this->_iProfileId, 'view person profile', $this->getName(), $isPerformAction);
- if ($aCheck[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
- return $aCheck[CHECK_ACTION_MESSAGE];
- // TODO: check privacy
- return CHECK_ACTION_RESULT_ALLOWED;
- }
- /**
- * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make "true === " checking.
- */
- function isAllowedBrowse () {
- return CHECK_ACTION_RESULT_ALLOWED;
- }
- /**
- * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
- */
- function isAllowedAdd ($isPerformAction = false) {
- // check ACL
- $aCheck = checkActionModule($this->_iProfileId, 'create person profile', $this->getName(), $isPerformAction);
- if ($aCheck[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
- return $aCheck[CHECK_ACTION_MESSAGE];
- return CHECK_ACTION_RESULT_ALLOWED;
- }
- /**
- * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
- */
- function isAllowedEdit ($aDataEntry, $isPerformAction = false) {
- // moderator always has access
- if ($this->_checkModeratorAccess($isPerformAction))
- return CHECK_ACTION_RESULT_ALLOWED;
- // owner (checked by account! not as profile as ususal) always have access
- bx_import('BxDolProfile');
- $oProfileAurhor = BxDolProfile::getInstance($aDataEntry[BxPersonsConfig::$FIELD_AUTHOR]);
- if ($oProfileAurhor->getAccountId() == $this->_iAccountId)
- return CHECK_ACTION_RESULT_ALLOWED;
- return _t('_sys_txt_access_denied');
- }
- /**
- * Check if user can change cover image
- */
- function isAllowedChangeCover ($aDataEntry, $isPerformAction = false) {
- // moderator always has access
- if ($this->_checkModeratorAccess($isPerformAction))
- return CHECK_ACTION_RESULT_ALLOWED;
- // owner (checked by account! not as profile as ususal) always have access
- bx_import('BxDolProfile');
- $oProfileAurhor = BxDolProfile::getInstance($aDataEntry[BxPersonsConfig::$FIELD_AUTHOR]);
- if ($oProfileAurhor->getAccountId() == $this->_iAccountId)
- return CHECK_ACTION_RESULT_ALLOWED;
- return _t('_sys_txt_access_denied');
- }
- /**
- * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
- */
- function isAllowedDelete (&$aDataEntry, $isPerformAction = false) {
- // moderator always has access
- if ($this->_checkModeratorAccess($isPerformAction))
- return CHECK_ACTION_RESULT_ALLOWED;
- // check ACL and owner (checked by account! not as profile as ususal)
- bx_import('BxDolProfile');
- $oProfileAurhor = BxDolProfile::getInstance($aDataEntry[BxPersonsConfig::$FIELD_AUTHOR]);
- $aCheck = checkActionModule($this->_iProfileId, 'delete person profile', $this->getName(), $isPerformAction);
- if ($oProfileAurhor->getAccountId() == $this->_iAccountId && $aCheck[CHECK_ACTION_RESULT] === CHECK_ACTION_RESULT_ALLOWED)
- return CHECK_ACTION_RESULT_ALLOWED;
- return _t('_sys_txt_access_denied');
- }
- /**
- * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
- */
- function isAllowedViewMoreMenu (&$aDataEntry, $isPerformAction = false) {
- bx_import('BxTemplMenu');
- $oMenu = BxTemplMenu::getObjectInstance('bx_persons_view_actions_more');
- if (!$oMenu || !$oMenu->getCode())
- return _t('_sys_txt_access_denied');
- return CHECK_ACTION_RESULT_ALLOWED;
- }
- /**
- * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
- */
- function isAllowedFriendAdd (&$aDataEntry, $isPerformAction = false) {
- return $this->_isAllowedConnect ($aDataEntry, $isPerformAction, 'sys_profiles_friends', true, false);
- }
- /**
- * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
- */
- function isAllowedFriendRemove (&$aDataEntry, $isPerformAction = false) {
- if (CHECK_ACTION_RESULT_ALLOWED === $this->_isAllowedConnect ($aDataEntry, $isPerformAction, 'sys_profiles_friends', false, true, true))
- return CHECK_ACTION_RESULT_ALLOWED;
- return $this->_isAllowedConnect ($aDataEntry, $isPerformAction, 'sys_profiles_friends', false, true, false);
- }
- /**
- * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
- */
- function isAllowedSubscribeAdd (&$aDataEntry, $isPerformAction = false) {
- return $this->_isAllowedConnect ($aDataEntry, $isPerformAction, 'sys_profiles_subscriptions', false, false);
- }
- /**
- * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
- */
- function isAllowedSubscribeRemove (&$aDataEntry, $isPerformAction = false) {
- return $this->_isAllowedConnect ($aDataEntry, $isPerformAction, 'sys_profiles_subscriptions', false, true);
- }
- function _isAllowedConnect (&$aDataEntry, $isPerformAction, $sObjConnection, $isMutual, $isInvertResult, $isSwap = false) {
- if (!$this->_iProfileId)
- return _t('_sys_txt_access_denied');
- $oProfileAuthor = BxDolProfile::getInstance($aDataEntry[BxPersonsConfig::$FIELD_AUTHOR]);
- $oProfile = $oProfileAuthor ? BxDolProfile::getInstanceByContentTypeAccount($aDataEntry[BxPersonsConfig::$FIELD_ID], 'bx_persons', $oProfileAuthor->getAccountId()) : false;
- if (!$oProfile || $oProfile->id() == $this->_iProfileId)
- return _t('_sys_txt_access_denied');
- bx_import('BxDolConnection');
- $oConn = BxDolConnection::getObjectInstance($sObjConnection);
- if ($isSwap)
- $isConnected = $oConn->isConnected($oProfile->id(), $this->_iProfileId, $isMutual);
- else
- $isConnected = $oConn->isConnected($this->_iProfileId, $oProfile->id(), $isMutual);
- if ($isInvertResult)
- $isConnected = !$isConnected;
- return $isConnected ? _t('_sys_txt_access_denied') : CHECK_ACTION_RESULT_ALLOWED;
- }
- }
- /** @} */
|