| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331 |
- <?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 Sites Sites
- * @ingroup DolphinModules
- *
- * @{
- */
- bx_import ('BxDolModule');
- bx_import ('BxDolAcl');
- require_once( BX_DIRECTORY_PATH_PLUGINS . 'Services_JSON.php' );
- define('BX_SITES_ACCOUNT_STATUS_UNCONFIRMED', 'unconfirmed');
- define('BX_SITES_ACCOUNT_STATUS_PENDING', 'pending');
- define('BX_SITES_ACCOUNT_STATUS_TRIAL', 'trial');
- define('BX_SITES_ACCOUNT_STATUS_ACTIVE', 'active');
- define('BX_SITES_ACCOUNT_STATUS_CANCELED', 'canceled');
- define('BX_SITES_ACCOUNT_STATUS_SUSPENDED', 'suspended');
- define('BX_SITES_TRANSACTION_INIT', 'init');
- define('BX_SITES_TRANSACTION_TRIAL', 'trial');
- define('BX_SITES_TRANSACTION_REGULAR', 'regular');
- /**
- * PayPal integration.
- */
- define('BX_SITES_PP_DIRECTORY_PATH_API', BX_DIRECTORY_PATH_MODULES . 'boonex/sites/api/');
- define('BX_SITES_PP_ACTIVATION_INIT_AMOUNT', 'init_amount');
- define('BX_SITES_PP_ACTIVATION_TRIAL_PERIOD', 'trial_period');
- define('BX_SITES_PP_PERIOD_TRIAL', 'Trial');
- define('BX_SITES_PP_PERIOD_REGULAR', 'Regular');
- define('BX_SITES_PP_RPA_CANCEL', 'Cancel');
- define('BX_SITES_PP_RPA_SUSPEND', 'Suspend');
- define('BX_SITES_PP_RPA_REACTIVATE', 'Reactivate');
- /**
- * Sites module
- */
- class BxSitesModule extends BxDolModule
- {
- protected $_iProfileId;
- function __construct(&$aModule)
- {
- parent::__construct($aModule);
- $this->_oConfig->init($this->_oDb);
- $this->_iProfileId = bx_get_logged_profile_id();
- }
- // ====== SERVICE METHODS
- public function serviceIsUsed($sDomain)
- {
- return $this->_oDb->isAccount(array('domain' => $sDomain));
- }
- public function serviceBrowse()
- {
- bx_import('BxDolGrid');
- $oGrid = BxDolGrid::getObjectInstance('bx_sites_browse');
- if(!$oGrid)
- return '';
- return $oGrid->getCode();
- }
- public function serviceSiteCreate()
- {
- bx_import('Forms', $this->_aModule);
- $oForms = new BxSitesForms($this);
- return $oForms->addDataForm();
- }
- public function serviceSiteSubscribe()
- {
- $sToken = bx_process_input(bx_get('token'));
- if($sToken === false)
- return MsgBox(_t('_bx_sites_paypal_err_token_not_found'));
- bx_import('Paypal', $this->_aModule);
- $oPaypal = new BxSitesPaypal($this);
- $sResultMessage = $oPaypal->subscribe($sToken);
- return MsgBox(_t($sResultMessage));
- }
- public function serviceSiteView()
- {
- $iId = bx_process_input(bx_get('id'), BX_DATA_INT);
- if($iId === false)
- return MsgBox(_t('_bx_sites_txt_err_site_is_not_defined'));
- $aAccount = $this->_oDb->getAccount(array('type' => 'id', 'value' => $iId));
- if(empty($aAccount) || !is_array($aAccount))
- return MsgBox(_t('_bx_sites_txt_err_site_is_not_defined'));
- $sMsg = $this->isAllowedView($aAccount);
- if($sMsg !== CHECK_ACTION_RESULT_ALLOWED)
- return MsgBox($sMsg);
- bx_import('BxDolGrid');
- $oGrid = BxDolGrid::getObjectInstance('bx_sites_overview');
- if(!$oGrid)
- return '';
- $oGrid->setAccount($aAccount);
- return array(
- 'title' => $this->getDomain($aAccount['domain']),
- 'content' => $this->_oTemplate->getJs(true) . $oGrid->getCode()
- );
- }
- public function serviceSiteEdit()
- {
- $aParams = $this->getSelectParam();
- if($aParams === false)
- return MsgBox(_t('_bx_sites_txt_err_site_is_not_defined'));
-
- $aAccount = $this->_oDb->getAccount($aParams);
- if(empty($aAccount) || !is_array($aAccount))
- return MsgBox(_t('_bx_sites_txt_err_site_is_not_defined'));
- bx_import('Forms', $this->_aModule);
- $oForms = new BxSitesForms($this);
- return array(
- 'title' => _t('_bx_sites_page_block_title_site_manage') . ' ' . $this->getDomain($aAccount['domain']),
- 'content' => $oForms->editDataForm($aAccount)
- );
- }
- public function serviceSiteDelete($iId = 0)
- {
- if(!$iId)
- $iId = bx_process_input(bx_get('id'), BX_DATA_INT);
- if(!$iId)
- return MsgBox(_t('_bx_sites_txt_err_site_is_not_defined'));
-
- $aAccount = $this->_oDb->getAccount(array('type' => 'id', 'value' => $iId));
- if(empty($aAccount) || !is_array($aAccount))
- return MsgBox(_t('_bx_sites_txt_err_site_is_not_defined'));
- bx_import('Forms', $this->_aModule);
- $oProfileForms = new BxSitesForms($this);
- return array(
- 'title' => _t('_bx_sites_page_block_title_site_delete') . ' ' . $this->getDomain($aAccount['domain']),
- 'content' => $oProfileForms->deleteDataForm($aAccount)
- );
- }
- public function serviceResponse($oAlert)
- {
- if($oAlert->sUnit != 'account' || !in_array($oAlert->sAction, array('login')))
- return;
- bx_import('BxDolSession');
- $sDomain = BxDolSession::getInstance()->getUnsetValue('bx_sites_domain');
- if($sDomain === false)
- return;
- $iAccountId = $this->_oDb->insertAccount(array(
- 'owner_id' => $oAlert->iObject,
- 'domain' => $sDomain,
- 'created' => time(),
- 'status' => BX_SITES_ACCOUNT_STATUS_UNCONFIRMED
- ));
- if(!$iAccountId)
- return;
- $oAccount = $this->getObject('Account');
- $oAccount->onAccountCreated($iAccountId);
- $sUrl = $this->startSubscription($iAccountId);
- header('Location: ' . $sUrl);
- exit;
- }
- // ====== ACTION METHODS
- public function actionIpn()
- {
- $aData = &$_POST;
- foreach($aData as $sKey => $sValue)
- $aData[$sKey] = bx_process_input(trim($sValue));
- if(!isset($aData['txn_type']))
- return;
- bx_import('Paypal', $this->_aModule);
- $oPaypal = new BxSitesPaypal($this);
- $oPaypal->process($aData);
-
- bx_import('Account', $this->_aModule);
- $oAccount = new BxSitesAccount($this);
- if($oPaypal->bProfileCreated) {
- $oAccount->onProfileConfirmed($aData);
- }
- else if($oPaypal->bProfileCanceled) {
- $oAccount->onProfileCanceled($aData);
- }
- else if($oPaypal->bPaymentDone) {
- $oAccount->onPaymentReceived($aData, $oPaypal->fPaymentAmout);
- }
- else if($oPaypal->bPaymentRefund) {
- $oAccount->onPaymentRefunded($aData);
- }
- }
- /*
- * Can be removed if it's not used.
- *
- public function actionReactivate($iId)
- {
- $aResult = array('code' => '1', 'message' => _t('_bx_sites_txt_err_cannot_perform'));
- $sUrl = $this->startSubscription($iId);
- if(!empty($sUrl))
- $aResult = array('code' => '0', 'message' => '', 'redirect' => $sUrl);
- header('Content-Type:text/javascript');
- $oJson = new Services_JSON();
- echo $oJson->encode($aResult);
- }
- */
- // ====== PERMISSION METHODS
- public function isAllowedAdd ($isPerformAction = false)
- {
- $aCheck = checkActionModule($this->_iProfileId, 'create site', $this->getName(), $isPerformAction);
- if ($aCheck[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
- return $aCheck[CHECK_ACTION_MESSAGE];
- return CHECK_ACTION_RESULT_ALLOWED;
- }
- public function isAllowedView ($aDataEntry, $isPerformAction = false)
- {
- // moderator and owner always have access
- if ($aDataEntry[BxSitesConfig::$FIELD_AUTHOR] == $this->_iProfileId || $this->isModeratorAccess($isPerformAction))
- return CHECK_ACTION_RESULT_ALLOWED;
- return _t('_sys_txt_access_denied');
- }
- public function isAllowedEdit ($aDataEntry, $isPerformAction = false)
- {
- // moderator and owner always have access
- if ($aDataEntry[BxSitesConfig::$FIELD_AUTHOR] == $this->_iProfileId || $this->isModeratorAccess($isPerformAction))
- return CHECK_ACTION_RESULT_ALLOWED;
- return _t('_sys_txt_access_denied');
- }
- public function isAllowedDelete (&$aDataEntry, $isPerformAction = false)
- {
- // moderator and owner always have access
- if ($aDataEntry[BxSitesConfig::$FIELD_AUTHOR] == $this->_iProfileId || $this->isModeratorAccess($isPerformAction))
- return CHECK_ACTION_RESULT_ALLOWED;
- return _t('_sys_txt_access_denied');
- }
- public function isModeratorAccess ($isPerformAction = false)
- {
- $aCheck = checkActionModule($this->_iProfileId, 'manage sites', $this->getName(), $isPerformAction);
- return $aCheck[CHECK_ACTION_RESULT] === CHECK_ACTION_RESULT_ALLOWED;
- }
- // ====== COMMON METHODS
- public function getSelectParam()
- {
- $sType = 'id';
- $mixedId = bx_get('id');
- if($mixedId === false) {
- $mixedId = bx_get('sid');
- if($mixedId === false)
- return false;
- $sType = 'profile_sid';
- $mixedId = bx_process_input($mixedId);
- }
- else
- $mixedId = bx_process_input($mixedId, BX_DATA_INT);
- return array('type' => $sType, 'value' => $mixedId);
- }
- public function getDomain($sDomain, $bProtocol = false, $bWww = false)
- {
- $sDomain = sprintf($this->_oConfig->getDomainMask(), $sDomain);
- if($bWww)
- $sDomain = 'www.' . $sDomain;
- if($bProtocol)
- $sDomain = 'http://' . $sDomain;
- return $sDomain;
- }
- public function getObject($sClass)
- {
- return bx_instance('BxSites' . $sClass, array($this), $this->_aModule);
- }
- public function startSubscription($iId)
- {
- $oPaypal = $this->getObject('Paypal');
- return $oPaypal->start($iId);
- }
- public function cancelSubscription($sPpProfileId)
- {
- $oPaypal = $this->getObject('Paypal');
- return $oPaypal->performAction($sPpProfileId);
- }
- }
- /** @} */
|