Пример #1
0
 /**
  * Get signature of site when send email out
  * @param $aUser
  * @return string
  */
 private function _getSignature($aUser)
 {
     $sSignature = Phpfox::getParam('core.mail_signature');
     if (Phpfox::isPhrase($sSignature)) {
         return Phpfox::getPhrase($sSignature, array(), false, null, $aUser['language_id']);
     } else {
         return $sSignature;
     }
 }
Пример #2
0
 public function get($aConds = array(), $sSort = 'm.time_updated DESC', $iPage = '', $iLimit = '', $bIsSentbox = false, $bIsTrash = false)
 {
     $aRows = array();
     $aInputs = array('unread', 'read');
     if (Phpfox::getParam('mail.threaded_mail_conversation')) {
         $iArchiveId = $bIsTrash ? 1 : 0;
     }
     $bIsTextSearch = false;
     if (Phpfox::getParam('mail.threaded_mail_conversation')) {
         if (!defined('PHPFOX_IS_PRIVATE_MAIL')) {
             $this->database()->select('COUNT(*)');
             if ($bIsSentbox) {
                 $this->database()->where('th.user_id = ' . (int) Phpfox::getUserId() . ' AND th.is_archive = 0 AND th.is_sent = 1');
             } else {
                 $this->database()->where('th.user_id = ' . (int) Phpfox::getUserId() . ' AND th.is_archive = ' . (int) $iArchiveId . '');
             }
         } else {
             $this->database()->select('COUNT(DISTINCT t.thread_id)');
             $aNewCond = array();
             if (count($aConds)) {
                 foreach ($aConds as $sCond) {
                     if (preg_match('/AND mt.text LIKE \'%(.*)%\'/i', $sCond, $aTextMatch)) {
                         $bIsTextSearch = true;
                         $aNewCond[] = $sCond;
                     }
                 }
             }
         }
         if ($bIsTextSearch) {
             $iCnt = $this->database()->from(Phpfox::getT('mail_thread_text'), 'mt')->join(Phpfox::getT('mail_thread'), 't', 't.thread_id = mt.thread_id')->where($aNewCond)->execute('getSlaveField');
         } else {
             $iCnt = $this->database()->from(Phpfox::getT('mail_thread_user'), 'th')->join(Phpfox::getT('mail_thread'), 't', 't.thread_id = th.thread_id')->execute('getSlaveField');
         }
     } else {
         $iCnt = $this->database()->select('COUNT(*)')->from($this->_sTable, 'm')->join(Phpfox::getT('mail_text'), 'mt', 'mt.mail_id = m.mail_id')->leftjoin(Phpfox::getT('user'), 'u', 'u.user_id ' . (!$bIsSentbox ? '= m.owner_user_id' : '= m.viewer_user_id'))->where($aConds)->execute('getSlaveField');
     }
     if ($iCnt) {
         ($sPlugin = Phpfox_Plugin::get('mail.service_mail_get')) ? eval($sPlugin) : false;
         if (Phpfox::getParam('mail.threaded_mail_conversation')) {
             if (!defined('PHPFOX_IS_PRIVATE_MAIL')) {
                 if ($bIsSentbox) {
                     $this->database()->where('th.user_id = ' . (int) Phpfox::getUserId() . ' AND th.is_archive = 0 AND th.is_sent = 1');
                 } else {
                     $this->database()->where('th.user_id = ' . (int) Phpfox::getUserId() . ' AND th.is_archive = ' . (int) $iArchiveId . '');
                 }
             } else {
                 $this->database()->where($aConds);
                 $this->database()->group('th.thread_id');
             }
             if ($bIsTextSearch) {
                 $aRows = $this->database()->select('th.*, mt.text AS preview, mt.time_stamp, mt.user_id AS last_user_id')->from(Phpfox::getT('mail_thread_text'), 'mt')->join(Phpfox::getT('mail_thread_user'), 'th', 'th.user_id = mt.user_id')->join(Phpfox::getT('mail_thread'), 't', 't.thread_id = mt.thread_id')->join(Phpfox::getT('user'), 'u', 'u.user_id = mt.user_id')->limit($iPage, $iLimit, $iCnt)->order('t.time_stamp DESC')->execute('getSlaveRows');
             } else {
                 $aRows = $this->database()->select('th.*, tt.text AS preview, tt.time_stamp, tt.user_id AS last_user_id')->from(Phpfox::getT('mail_thread_user'), 'th')->join(Phpfox::getT('mail_thread'), 't', 't.thread_id = th.thread_id')->join(Phpfox::getT('mail_thread_text'), 'tt', 'tt.message_id = t.last_id')->join(Phpfox::getT('user'), 'u', 'u.user_id = tt.user_id')->limit($iPage, $iLimit, $iCnt)->order('t.time_stamp DESC')->execute('getSlaveRows');
             }
             $aFields = Phpfox::getService('user')->getUserFields();
             foreach ($aRows as $iKey => $aRow) {
                 if (Phpfox::getParam('mail.threaded_mail_conversation')) {
                     $aRows[$iKey]['preview'] = strip_tags($aRow['preview']);
                 }
                 $aRows[$iKey]['viewer_is_new'] = $aRow['is_read'] ? false : true;
                 $aRows[$iKey]['users'] = $this->database()->select('th.is_read, ' . Phpfox::getUserField())->from(Phpfox::getT('mail_thread_user'), 'th')->join(Phpfox::getT('user'), 'u', 'u.user_id = th.user_id')->where('th.thread_id = ' . (int) $aRow['thread_id'])->execute('getSlaveRows');
                 $iUserCnt = 0;
                 foreach ($aRows[$iKey]['users'] as $iUserKey => $aUser) {
                     if (!\Core\Route\Controller::$isApi && !defined('PHPFOX_IS_PRIVATE_MAIL') && $aUser['user_id'] == Phpfox::getUserId()) {
                         unset($aRows[$iKey]['users'][$iUserKey]);
                         continue;
                     }
                     $iUserCnt++;
                     if ($iUserCnt == 1) {
                         foreach ($aFields as $sField) {
                             if ($sField == 'server_id') {
                                 $sField = 'user_server_id';
                             }
                             $aRows[$iKey][$sField] = $aUser[$sField];
                         }
                     }
                     if (!isset($aRows[$iKey]['users_is_read'])) {
                         $aRows[$iKey]['users_is_read'] = array();
                     }
                     if ($aUser['is_read']) {
                         $aRows[$iKey]['users_is_read'][] = $aUser;
                     }
                 }
                 if (!$iUserCnt) {
                     unset($aRows[$iKey]);
                 }
             }
         } else {
             if ($bIsTrash) {
                 $this->database()->select(Phpfox::getUserField('u2', 'other_') . ', ')->join(Phpfox::getT('user'), 'u2', 'u2.user_id = m.viewer_user_id');
             }
             $aRows = $this->database()->select('m.*, ' . Phpfox::getUserField())->from($this->_sTable, 'm')->join(Phpfox::getT('mail_text'), 'mt', 'mt.mail_id = m.mail_id')->leftjoin(Phpfox::getT('user'), 'u', 'u.user_id ' . (!$bIsSentbox ? '= m.owner_user_id' : '= m.viewer_user_id'))->where($aConds)->limit($iPage, $iLimit, $iCnt)->order($sSort)->execute('getSlaveRows');
             if (!$bIsSentbox) {
                 foreach ($aRows as $iKey => $aRow) {
                     if ($aRow['viewer_is_new']) {
                         $aInputs['unread'][] = $aRow['mail_id'];
                     } else {
                         $aInputs['read'][] = $aRow['mail_id'];
                     }
                 }
             }
         }
     }
     //thread name
     if (Phpfox::getParam('mail.threaded_mail_conversation')) {
         foreach ($aRows as $iKey => $aRow) {
             $iCntUser = 0;
             $sThreadName = '';
             $iCut = 0;
             foreach ($aRow['users'] as $aUser) {
                 $sMore = \Phpfox_Parse_Output::instance()->shorten($aUser['full_name'], 30, '...');
                 if (strlen($sThreadName . $sMore) < 45) {
                     $sThreadName .= $sMore;
                     $iCut++;
                 }
                 $iCntUser++;
                 if ($iCntUser == $iCut && count($aRow['users']) > 1) {
                     $sThreadName .= ', ';
                 }
             }
             if ($iCntUser > $iCut) {
                 if (Phpfox::isPhrase('mail.and_number_other')) {
                     $sThreadName .= ' ' . Phpfox::getPhrase('mail.and_number_other', array('number' => $iCntUser - $iCut)) . ($iCntUser - $iCut > 1 ? 's' : '');
                 } else {
                     $sThreadName .= ' and ' . ($iCntUser - $iCut) . ' other' . ($iCntUser - $iCut > 1 ? 's' : '');
                 }
             }
             $aRows[$iKey]['thread_name'] = $sThreadName;
         }
     }
     return array($iCnt, $aRows, $aInputs);
 }