Пример #1
0
 function getComments($iId, $iCmtVParentId = 0, $iAuthorId = 0, $sFilter = '', $aOrder = array(), $iStart = 0, $iCount = -1)
 {
     $sFields = $sJoin = "";
     $oVote = $this->_oMain->getVoteObject(0);
     if ($oVote !== false) {
         $aSql = $oVote->getSqlParts($this->_sTable, 'cmt_id');
         $sFields .= $aSql['fields'];
         $sJoin .= $aSql['join'];
     }
     $sWhereParent = '';
     if ((int) $iCmtVParentId >= 0) {
         $sWhereParent = $this->prepare(" AND `{$this->_sTable}`.`cmt_vparent_id` = ?", $iCmtVParentId);
     }
     if (in_array($sFilter, array(BX_CMT_FILTER_FRIENDS, BX_CMT_FILTER_SUBSCRIPTIONS))) {
         bx_import('BxDolConnection');
         $oConnection = BxDolConnection::getObjectInstance($this->_oMain->getConnectionObject($sFilter));
         $aQueryParts = $oConnection->getConnectedContentAsSQLParts($this->_sTable, 'cmt_author_id', $iAuthorId);
         $sJoin .= ' ' . $aQueryParts['join'];
     }
     $sOder = " ORDER BY `{$this->_sTable}`.`cmt_time` ASC";
     if (isset($aOrder['by']) && isset($aOrder['way'])) {
         $aOrder['way'] = strtoupper(in_array($aOrder['way'], array(BX_CMT_ORDER_WAY_ASC, BX_CMT_ORDER_WAY_DESC)) ? $aOrder['way'] : BX_CMT_ORDER_WAY_ASC);
         switch ($aOrder['by']) {
             case BX_CMT_ORDER_BY_DATE:
                 $sOder = " ORDER BY `{$this->_sTable}`.`cmt_time` " . $aOrder['way'];
                 break;
             case BX_CMT_ORDER_BY_POPULAR:
                 $sOder = " ORDER BY `{$this->_sTable}`.`cmt_rate` " . $aOrder['way'];
                 break;
         }
     }
     $sLimit = $iCount != -1 ? $this->prepare(" LIMIT ?, ?", (int) $iStart, (int) $iCount) : '';
     $sQuery = $this->prepare("SELECT\n                `{$this->_sTable}`.`cmt_id`,\n                `{$this->_sTable}`.`cmt_parent_id`,\n                `{$this->_sTable}`.`cmt_vparent_id`,\n                `{$this->_sTable}`.`cmt_object_id`,\n                `{$this->_sTable}`.`cmt_author_id`,\n                `{$this->_sTable}`.`cmt_level`,\n                `{$this->_sTable}`.`cmt_text`,\n                `{$this->_sTable}`.`cmt_replies`,\n                `{$this->_sTable}`.`cmt_time`\n                {$sFields}\n            FROM `{$this->_sTable}`\n            {$sJoin}\n            WHERE `{$this->_sTable}`.`cmt_object_id` = ?" . $sWhereParent . $sOder . $sLimit, $iId);
     return $this->getAll($sQuery);
 }
Пример #2
0
 public function __construct($aObject, $oTemplate = false)
 {
     parent::__construct($aObject, $oTemplate);
     $CNF = $this->_oModule->_oConfig->CNF;
     $iProfileId = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
     $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
     if ($iProfileId) {
         $this->_oProfile = BxDolProfile::getInstance($iProfileId);
     }
     if (!$this->_oProfile && $iContentId) {
         $this->_oProfile = BxDolProfile::getInstanceByContentAndType($iContentId, $this->MODULE);
     }
     if ($this->_oProfile) {
         $this->_aProfileInfo = $this->_oProfile->getInfo();
         $this->_aContentInfo = $this->_oModule->_oDb->getContentInfoById($this->_aProfileInfo['content_id']);
         $this->addMarkers($this->_aProfileInfo);
         $this->addMarkers(array('profile_id' => $this->_oProfile->id()));
         if (isLogged()) {
             $oConn = BxDolConnection::getObjectInstance('sys_profiles_friends');
             if ($oConn->isConnectedNotMutual(bx_get_logged_profile_id(), $this->_oProfile->id())) {
                 $this->addMarkers(array('title_add_friend' => _t($CNF['T']['menu_item_title_befriend_sent']), 'title_remove_friend' => _t($CNF['T']['menu_item_title_unfriend_cancel_request'])));
             } elseif ($oConn->isConnectedNotMutual($this->_oProfile->id(), bx_get_logged_profile_id())) {
                 $this->addMarkers(array('title_add_friend' => _t($CNF['T']['menu_item_title_befriend_confirm']), 'title_remove_friend' => _t($CNF['T']['menu_item_title_unfriend_reject_request'])));
             } else {
                 $this->addMarkers(array('title_add_friend' => _t($CNF['T']['menu_item_title_befriend']), 'title_remove_friend' => _t($CNF['T']['menu_item_title_unfriend'])));
             }
         }
     }
 }
 protected function _setConnectionsConditions($aParams)
 {
     $oConnection = isset($aParams['object']) ? BxDolConnection::getObjectInstance($aParams['object']) : false;
     if (!$oConnection || !isset($aParams['profile']) || !(int) $aParams['profile']) {
         return false;
     }
     $sContentType = isset($aParams['type']) ? $aParams['type'] : BX_CONNECTIONS_CONTENT_TYPE_CONTENT;
     $isMutual = isset($aParams['mutual']) ? $aParams['mutual'] : false;
     $a = $oConnection->getConnectionsAsCondition($sContentType, 'id', (int) $aParams['profile'], (int) $aParams['profile2'], $isMutual);
     $this->aCurrent['restriction'] = array_merge($this->aCurrent['restriction'], $a['restriction']);
     $this->aCurrent['join'] = array_merge($this->aCurrent['join'], $a['join']);
     return true;
 }
Пример #4
0
 protected function _getSqlPartsEventsList($aParams)
 {
     $sJoinClause = $sWhereClause = "";
     if (isset($aParams['active'])) {
         $sWhereClause .= $this->prepare("AND `{$this->_sTable}`.`active`=? ", (int) $aParams['active']);
     }
     //--- Apply modules or handlers filter
     $sWhereModuleFilter = '';
     if (!empty($aParams['modules']) && is_array($aParams['modules'])) {
         $sWhereModuleFilter = "AND `" . $this->_sTable . "`.`type` IN (" . $this->implode_escape($aParams['modules']) . ") ";
     }
     if ($sWhereModuleFilter == '') {
         $aHidden = $this->_oConfig->getHandlersHidden();
         $sWhereModuleFilter = !empty($aHidden) && is_array($aHidden) ? "AND `" . $this->_sTableHandlers . "`.`id` NOT IN (" . $this->implode_escape($aHidden) . ") " : "";
     }
     if ($sWhereModuleFilter != '') {
         $sWhereClause .= $sWhereModuleFilter;
     }
     //--- Check flag 'New'
     if (!empty($aParams['new']) && !empty($aParams['owner_id'])) {
         $sSql = $this->prepare("SELECT `event_id` FROM `" . $this->_sTableEvt2Usr . "` WHERE `user_id`=? LIMIT 1", (int) $aParams['owner_id']);
         $iId = (int) $this->getOne($sSql);
         $sWhereClause .= $this->prepare("AND `{$this->_sTable}`.`id`>? ", $iId);
     }
     //--- Apply privacy filter
     $oPrivacy = BxDolPrivacy::getObjectInstance($this->_oConfig->getObject('privacy_view'));
     $aQueryParts = $oPrivacy->getContentByGroupAsSQLPart(BX_DOL_PG_ALL);
     $sWhereClause .= $aQueryParts['where'] . " ";
     //--- Check type
     if (!empty($aParams['owner_id'])) {
         switch ($aParams['type']) {
             case BX_BASE_MOD_NTFS_TYPE_OWNER:
                 $sWhereClause .= $this->prepare("AND `{$this->_sTable}`.`owner_id`=? ", $aParams['owner_id']);
                 break;
             case BX_BASE_MOD_NTFS_TYPE_OBJECT_OWNER:
                 $sWhereClause .= $this->prepare("AND `{$this->_sTable}`.`owner_id`<>`{$this->_sTable}`.`object_owner_id` AND `{$this->_sTable}`.`object_owner_id`=? ", $aParams['owner_id']);
                 break;
             case BX_BASE_MOD_NTFS_TYPE_CONNECTIONS:
                 $oConnection = BxDolConnection::getObjectInstance($this->_oConfig->getObject('conn_subscriptions'));
                 $aQueryParts = $oConnection->getConnectedContentAsSQLParts($this->_sPrefix . "events", 'owner_id', $aParams['owner_id']);
                 $sJoinClause .= ' ' . $aQueryParts['join'];
                 break;
         }
     }
     return array($sJoinClause, $sWhereClause);
 }
Пример #5
0
 /**
  * get number of received unconfirmed connections (friend requests)
  * @param $sConnectionsObject connections object to get unconfirmed connections from
  * @param $mixedId id to get connections for, if omitted then logged-in profile id is used
  * @return number
  */
 public function serviceGetUnconfirmedConnectionsNum($sConnectionsObject, $mixedId = 0)
 {
     $oConnection = BxDolConnection::getObjectInstance($sConnectionsObject);
     if (!$oConnection) {
         return 0;
     }
     if (!$mixedId) {
         $mixedId = bx_get_logged_profile_id();
     }
     $i = 0;
     $a = $oConnection->getConnectedInitiators($mixedId, 0);
     // get received friend requests
     foreach ($a as $iId) {
         if (BxDolProfile::getInstance($iId)) {
             ++$i;
         }
     }
     return $i;
 }
Пример #6
0
 protected function _checkAllowedConnect(&$aDataEntry, $isPerformAction, $sObjConnection, $isMutual, $isInvertResult, $isSwap = false)
 {
     if (!$this->_iProfileId) {
         return _t('_sys_txt_access_denied');
     }
     $CNF =& $this->_oConfig->CNF;
     $oProfile = BxDolProfile::getInstanceByContentAndType($aDataEntry[$CNF['FIELD_ID']], $this->_aModule['name']);
     if (!$oProfile || $oProfile->id() == $this->_iProfileId) {
         return _t('_sys_txt_access_denied');
     }
     $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;
 }
Пример #7
0
 /**
  * 
  * Connections objects associated with module data. It must be defined which content is associated with the connection.
  * The key is connection object name and value is array (possible array values: type, conn, table, field_id).
  * If 'type' == 'profiles', then it is considered profiles connection and other possible param is 'conn' ('initiator', 'content' or 'both') 
  * If 'type' == 'custom' (or ommited), then other possible params are 'conn', 'table' and 'field_id'
  * @param string $sOperation - operation type.
  */
 protected function actionProcessConnections($sOperation)
 {
     if (!in_array($sOperation, array('uninstall')) || empty($this->_aConfig['connections'])) {
         return BX_DOL_STUDIO_INSTALLER_FAILED;
     }
     foreach ($this->_aConfig['connections'] as $sObjectConnections => $a) {
         $o = BxDolConnection::getObjectInstance($sObjectConnections);
         if (!$o) {
             continue;
         }
         $sFuncSuffix = 'DeleteInitiatorAndContent';
         if (isset($a['conn']) && 'initiator' == $a['conn']) {
             $sFuncSuffix = 'DeleteInitiator';
         } elseif (isset($a['conn']) && 'content' == $a['conn']) {
             $sFuncSuffix = 'DeleteContent';
         }
         if (isset($a['type']) && 'profiles' == $a['type']) {
             $sFunc = 'onModuleProfile' . $sFuncSuffix;
             $o->{$sFunc}($this->_aConfig['name']);
         } else {
             $sFunc = 'onModule' . $sFuncSuffix;
             $o->{$sFunc}($a['table'], $a['field_id']);
         }
     }
     return BX_DOL_STUDIO_INSTALLER_SUCCESS;
 }
 function uninstall($aParams, $bDisable = false)
 {
     // check if module is already waiting while files are deleting
     bx_import('BxDolInstallerUtils');
     if (BxDolInstallerUtils::isModulePendingUninstall($this->_aConfig['home_uri'])) {
         return array('message' => _t('_adm_err_modules_pending_uninstall_already'), 'result' => false);
     }
     // queue for deletion storage files
     $bSetModulePendingUninstall = false;
     foreach ($this->_aStorages as $s) {
         if (($o = BxDolStorage::getObjectInstance($s)) && $o->queueFilesForDeletionFromObject()) {
             $bSetModulePendingUninstall = true;
         }
     }
     // delete comments and queue for deletion comments attachments
     bx_import('BxDolCmts');
     $iFiles = 0;
     BxDolCmts::onModuleUninstall($this->_aConfig['name'], $iFiles);
     if ($iFiles) {
         $bSetModulePendingUninstall = true;
     }
     // if some files were added to the queue, set module as pending uninstall
     if ($bSetModulePendingUninstall) {
         BxDolInstallerUtils::setModulePendingUninstall($this->_aConfig['home_uri']);
         return array('message' => _t('_adm_err_modules_pending_uninstall'), 'result' => false);
     }
     // delete associated connections
     if ($this->_aConnections) {
         bx_import('BxDolConnection');
         foreach ($this->_aConnections as $sObjectConnections => $a) {
             $o = BxDolConnection::getObjectInstance($sObjectConnections);
             if (!$o) {
                 continue;
             }
             $sFuncSuffix = 'DeleteInitiatorAndContent';
             if (isset($a['conn']) && 'initiator' == $a['conn']) {
                 $sFuncSuffix = 'DeleteInitiator';
             } elseif (isset($a['conn']) && 'content' == $a['conn']) {
                 $sFuncSuffix = 'DeleteContent';
             }
             if (isset($a['type']) && 'profiles' == $a['type']) {
                 $sFunc = 'onModuleProfile' . $sFuncSuffix;
                 $o->{$sFunc}($this->_aConfig['name']);
             } else {
                 $sFunc = 'onModule' . $sFuncSuffix;
                 $o->{$sFunc}($a['table'], $a['field_id']);
             }
         }
     }
     return parent::uninstall($aParams, $bDisable);
 }
Пример #9
0
 protected function _getActionAddFriend($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = array())
 {
     if ($this->_bOwner || $aRow['id'] == bx_get_logged_profile_id()) {
         return '';
     }
     bx_import('BxDolConnection');
     $oConn = BxDolConnection::getObjectInstance($this->_sObjectConnections);
     if ($oConn->isConnected($aRow['id'], bx_get_logged_profile_id()) || $oConn->isConnected(bx_get_logged_profile_id(), $aRow['id'])) {
         return '';
     }
     return parent::_getActionDefault($sType, $sKey, $a, $isSmall, $isDisabled, $aRow);
 }
Пример #10
0
<?php

/**
 * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
 * CC-BY License - http://creativecommons.org/licenses/by/3.0/
 *
 * @defgroup    TridentCore Trident Core
 * @{
 */
require_once './inc/header.inc.php';
require_once BX_DIRECTORY_PATH_INC . "design.inc.php";
check_logged();
$sObj = bx_get('obj') ? bx_get('obj') : '';
$sAct = bx_get('act') && preg_match('/^[A-Za-z_]+$/', bx_get('act')) ? bx_get('act') : '';
$sFmt = bx_get('fmt') ? bx_get('fmt') : 'json';
bx_import('BxDolConnection');
$oConn = BxDolConnection::getObjectInstance($sObj);
$sMethod = 'action' . $sAct;
if ($oConn && $sAct && method_exists($oConn, $sMethod)) {
    echo $oConn->outputActionResult($oConn->{$sMethod}(), $sFmt);
    exit;
} else {
    bx_import('BxDolLanguages');
    bx_import('BxDolTemplate');
    $oTemplate = BxDolTemplate::getInstance();
    $oTemplate->displayPageNotFound();
}
/** @} */
Пример #11
0
 public function checkConnections($iOwnerId, $iViewerId)
 {
     bx_import('BxDolConnection');
     return BxDolConnection::getObjectInstance('sys_profiles_friends')->isConnected($iOwnerId, $iViewerId, true);
 }
Пример #12
0
 /**
  * Delete profile.
  * @param $ID - optional profile id to delete
  * @param $bForceDelete - force deletetion is case of account profile deletion
  * @return false on error, or true on success
  */
 function delete($ID = false, $bForceDelete = false)
 {
     $ID = (int) $ID;
     if (!$ID) {
         $ID = $this->_iProfileID;
     }
     $aProfileInfo = $this->_oQuery->getInfoById($ID);
     if (!$aProfileInfo) {
         return false;
     }
     // delete system profiles (accounts) is not allowed, instead - delete whole account
     if (!$bForceDelete && 'system' == $aProfileInfo['type']) {
         return false;
     }
     // switch profile context if deleted profile is active profile context
     bx_import('BxDolAccount');
     $oAccount = BxDolAccount::getInstance($aProfileInfo['account_id']);
     $aAccountInfo = $oAccount->getInfo();
     if (!$bForceDelete && $ID == $aAccountInfo['profile_id']) {
         $oProfileAccount = BxDolProfile::getInstanceAccountProfile($aProfileInfo['account_id']);
         $oAccount->updateProfileContext($oProfileAccount->id());
     }
     // create system event before deletion
     $isStopDeletion = false;
     bx_alert('profile', 'before_delete', $ID, 0, array('stop_deletion' => &$isStopDeletion));
     if ($isStopDeletion) {
         return false;
     }
     // delete associated comments
     bx_import('BxDolCmts');
     BxDolCmts::onAuthorDelete($ID);
     // delete connections
     bx_import('BxDolConnection');
     $oConn = BxDolConnection::getObjectInstance('sys_profiles_friends');
     $oConn->onDeleteInitiatorAndContent($ID);
     $oConn = BxDolConnection::getObjectInstance('sys_profiles_subscriptions');
     $oConn->onDeleteInitiatorAndContent($ID);
     // delete profile's acl levels
     bx_import('BxDolAcl');
     BxDolAcl::getInstance()->onProfileDelete($ID);
     // delete profile
     if (!$this->_oQuery->delete($ID)) {
         return false;
     }
     // create system event
     bx_alert('profile', 'delete', $ID);
     // unset class instance to prevent creating the instance again
     $this->_iProfileID = 0;
     $sClass = get_class($this) . '_' . $ID;
     unset($GLOBALS['bxDolClasses'][$sClass]);
     return true;
 }
Пример #13
0
 protected function _getSqlPartsEventsList($aParams)
 {
     $sJoinClause = $sWhereClause = "";
     if (isset($aParams['active'])) {
         $sWhereClause .= $this->prepare("AND `{$this->_sTable}`.`active`=? ", (int) $aParams['active']);
     }
     //--- Apply filter
     if (isset($aParams['filter'])) {
         $sWhereClause .= $this->_getFilterAddon($aParams['owner_id'], $aParams['filter']);
     }
     //--- Apply timeline
     if (isset($aParams['timeline']) && !empty($aParams['timeline'])) {
         $iYear = (int) $aParams['timeline'];
         $sWhereClause .= $this->prepare("AND `date`<=? ", mktime(23, 59, 59, 12, 31, $iYear));
     }
     //--- Apply modules or handlers filter
     $sWhereModuleFilter = '';
     if (!empty($aParams['modules']) && is_array($aParams['modules'])) {
         $sWhereModuleFilter = "AND `" . $this->_sTable . "`.`type` IN (" . $this->implode_escape($aParams['modules']) . ") ";
     }
     if ($sWhereModuleFilter == '') {
         $aHidden = $this->_oConfig->getHandlersHidden();
         $sWhereModuleFilter = !empty($aHidden) && is_array($aHidden) ? "AND `" . $this->_sTableHandlers . "`.`id` NOT IN (" . $this->implode_escape($aHidden) . ") " : "";
     }
     if ($sWhereModuleFilter != '') {
         $sWhereClause .= $sWhereModuleFilter;
     }
     //--- Check type
     switch ($aParams['type']) {
         case BX_BASE_MOD_NTFS_TYPE_OWNER:
             if (empty($aParams['owner_id'])) {
                 break;
             }
             $sWhereClause .= $this->prepare("AND `{$this->_sTable}`.`owner_id`=? ", $aParams['owner_id']);
             break;
         case BX_BASE_MOD_NTFS_TYPE_CONNECTIONS:
             if (empty($aParams['owner_id'])) {
                 break;
             }
             bx_import('BxDolConnection');
             $oConnection = BxDolConnection::getObjectInstance($this->_oConfig->getObject('conn_subscriptions'));
             $aQueryParts = $oConnection->getConnectedContentAsSQLParts($this->_sPrefix . "events", 'owner_id', $aParams['owner_id']);
             $sJoinClause .= ' ' . $aQueryParts['join'];
             $iUserId = bx_get_logged_profile_id();
             $sCommonPostPrefix = $this->_oConfig->getPrefix('common_post');
             $sWhereClause .= "AND IF(SUBSTRING(`{$this->_sTable}`.`type`, 1, " . strlen($sCommonPostPrefix) . ") = '" . $sCommonPostPrefix . "', `{$this->_sTable}`.`object_id` <> " . $iUserId . ", 1) ";
             break;
         case BX_BASE_MOD_NTFS_TYPE_PUBLIC:
             $sCommonPostPrefix = $this->_oConfig->getPrefix('common_post');
             $sWhereClause .= "AND SUBSTRING(`{$this->_sTable}`.`type`, 1, " . strlen($sCommonPostPrefix) . ") <> '" . $sCommonPostPrefix . "' ";
             break;
     }
     return array($sJoinClause, $sWhereClause);
 }
Пример #14
0
function GenerateData($iMutual = 3, $iOneWay = 1, $sTable, $sType, $sObject)
{
    $oDb = BxDolDb::getInstance();
    bx_import('BxDolConnection');
    $oConnection = BxDolConnection::getObjectInstance($sObject);
    if (!$oConnection) {
        die("'{$sObject}' object is not defined.");
    }
    $oDb->query("TRUNCATE TABLE {$sTable}");
    // get all profiles
    $sQueryOrig = "SELECT * FROM `sys_profiles` WHERE `type` = ? AND `status` = 'active'";
    $sQueryPrepared = $oDb->prepare($sQueryOrig, $sType);
    if (!($aAll = $oDb->getAll($sQueryPrepared))) {
        die($oDb->getErrorMessage());
    }
    foreach ($aAll as $aProfile) {
        // get random profiles to add as connections
        $sQueryOrig = "SELECT * FROM `sys_profiles` WHERE `type` = ? AND `status` = 'active' AND `id` != ? ORDER BY RAND() LIMIT ?";
        $sQueryPrepared = $oDb->prepare($sQueryOrig, $sType, $aProfile['id'], $iMutual + $iOneWay);
        if (!($a = $oDb->getAll($sQueryPrepared))) {
            die($oDb->getErrorMessage());
        }
        $i = 0;
        foreach ($a as $r) {
            echo "{$aProfile['id']} " . ($i < $iMutual ? '&lt;=&gt;' : '=&gt;') . " {$r['id']}  <br />\n";
            if ($i < $iMutual) {
                // mutual
                if (!$oConnection->isConnected($aProfile['id'], $r['id'], true)) {
                    $oConnection->addConnection($aProfile['id'], $r['id']);
                    $oConnection->addConnection($r['id'], $aProfile['id']);
                }
            } elseif ($i >= $iMutual) {
                // one-way
                if (!$oConnection->isConnected($aProfile['id'], $r['id'])) {
                    $oConnection->addConnection($aProfile['id'], $r['id']);
                }
            }
            $i++;
        }
    }
}