HomeHelpTrac

Changeset 15698 for trunk/inc


Ignore:
Timestamp:
11/24/11 03:20:35 (6 months ago)
Author:
Alexander Trofimov
Message:

Accounts and Profiles

Location:
trunk/inc
Files:
2 added
1 deleted
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/inc/classes/BxDolProfile.php

    r15211 r15698  
    1 <? 
     1<?php defined('BX_DOL') or die('hack attempt'); 
     2/** 
     3 * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/ 
     4 * CC-BY License - http://creativecommons.org/licenses/by/3.0/ 
     5 * 
     6 * @defgroup    DolphinCore Dolphin Core 
     7 * @{ 
     8 */ 
    29 
    3 // TODO: decide later what to do with profiles functionality 
    4 // TODO: remove couples 
    5 // TODO: remove profile cache 
    6  
    7 /*************************************************************************** 
    8 *                            Dolphin Smart Community Builder 
    9 *                              ------------------- 
    10 *     begin                : Mon Mar 23 2006 
    11 *     copyright            : (C) 2007 BoonEx Group 
    12 *     website              : http://www.boonex.com 
    13 * This file is part of Dolphin - Smart Community Builder 
    14 * 
    15 * Dolphin is free software; you can redistribute it and/or modify it under 
    16 * the terms of the GNU General Public License as published by the 
    17 * Free Software Foundation; either version 2 of the 
    18 * License, or  any later version. 
    19 * 
    20 * Dolphin is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 
    21 * without even the implied warranty of  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
    22 * See the GNU General Public License for more details. 
    23 * You should have received a copy of the GNU General Public License along with Dolphin, 
    24 * see license.txt file; if not, write to marketing@boonex.com 
    25 ***************************************************************************/ 
    26  
    27 bx_import('BxDolMistake'); 
    2810bx_import('BxDolProfileQuery'); 
    2911 
    30 class BxDolProfile extends BxDolMistake 
    31 { 
     12class BxDolProfile extends BxDol { 
     13 
    3214    var $_iProfileID; 
    33     var $_aProfile; 
    34     var $bCouple; 
    35     var $_iCoupleID; 
    36     var $_aCouple; 
     15    var $_oQuery; 
    3716 
    3817    /** 
    3918     * Constructor 
    40      * 
    41      * @return User 
    4219     */ 
    43     function BxDolProfile( $vProfileID, $bWithEmail = 1 ) 
    44     { 
    45         $this -> _iProfileID = $this -> getID( $vProfileID, $bWithEmail ); 
     20    protected function __construct ($iProfileId) { 
     21        $iProfileId = (int)$iProfileId; 
     22        $sClass = get_class($this) . '_' . $iProfileId; 
     23        if (isset($GLOBALS['bxDolClasses'][$sClass])) 
     24            trigger_error ('Multiple instances are not allowed for the class: ' . get_class($this), E_USER_ERROR); 
     25 
     26        parent::__construct(); 
     27 
     28        $this->_iProfileID = $iProfileId; // since constructor is protected $iProfileId is always valid 
     29        $this->_oQuery = BxDolProfileQuery::getInstance(); 
    4630    } 
    4731 
    4832    /** 
    49      * Enter description here... 
    50      * 
    51      * @param unknown_type $ID 
    52      * @param unknown_type $float 
     33     * Prevent cloning the instance 
    5334     */ 
    54     function getProfileThumbnail( $float ) 
    55     { 
    56         $ret = $this -> getProfileImageUrl( $iProfileID, 0); 
     35    public function __clone() { 
     36        $sClass = get_class($this) . '_' . $this->_iProfileID; 
     37        if (isset($GLOBALS['bxDolClasses'][$sClass])) 
     38            trigger_error('Clone is not allowed for the class: ' . get_class($this), E_USER_ERROR); 
    5739    } 
    5840 
    5941    /** 
    60      * return link to profile image only. 
    61      * 
    62      * @param unknown_type $ID 
    63      * @param unknown_type $imageNum 
     42     * Get singleton instance of the class 
    6443     */ 
    65     function getProfileImageUrl( $imageNum ) 
    66     { 
     44    public static function getInstance($mixedProfileId) { 
    6745 
     46        $iProfileId = self::getID($mixedProfileId); 
     47        if (!$iProfileId) 
     48            return false; 
     49 
     50        $sClass = __CLASS__ . '_' . $iProfileId; 
     51        if (!isset($GLOBALS['bxDolClasses'][$sClass])) 
     52            $GLOBALS['bxDolClasses'][$sClass] = new BxDolProfile($iProfileId); 
     53 
     54        return $GLOBALS['bxDolClasses'][$sClass]; 
    6855    } 
    6956 
    7057    /** 
    71      *  return assoc array of all frofile fields 
     58     * Get profile id 
    7259     */ 
    73     function getProfileData() { 
    74         global $aUser; 
    75  
    76         $bUseCacheSystem = ( getParam('enable_cache_system') == 'on' ) ? true : false; 
    77  
    78         $oPDb = new BxDolProfileQuery(); 
    79         $sProfileCache = BX_DIRECTORY_PATH_CACHE . 'user' . $this -> _iProfileID . '.php'; 
    80         if( $bUseCacheSystem && file_exists( $sProfileCache ) && is_file( $sProfileCache ) ) { 
    81             require_once($sProfileCache); 
    82             $this -> _aProfile = $aUser[$this -> _iProfileID]; 
    83         } else 
    84             $this -> _aProfile = $oPDb -> getProfileDataById( $this -> _iProfileID ); 
    85  
    86  
    87         //get couple data 
    88         if( $this -> _aProfile['Couple'] ) { 
    89             $this -> bCouple = true; 
    90             $this -> _iCoupleID = $this -> _aProfile['Couple']; 
    91  
    92             $sProfileCache = BX_DIRECTORY_PATH_CACHE . 'user' . $this -> _iCoupleID . '.php'; 
    93             if( $bUseCacheSystem && file_exists( $sProfileCache ) && is_file( $sProfileCache ) ) { 
    94                 require_once($sProfileCache); 
    95                 $this -> _aCouple = $aUser[$this -> _iCoupleID]; 
    96             } else 
    97                 $this -> _aCouple = $oPDb -> getProfileDataById( $this -> _iCoupleID ); 
    98         } 
    99  
    100         return $this -> _aProfile; 
     60    public function id() { 
     61        return $this->_oQuery->getIdById($this->_iProfileID); 
    10162    } 
    10263 
    10364    /** 
    104      * Update profile info to database 
    105      * 
    106      * 
    107      * @param int $iUserID 
    108      * @param array $aData 
    109      * where the key of the array is name of database table field 
    110      * 
    111      * example: 
    112      * $aData['Sex'] = 'male'; 
    113      * 
     65     * Get profile info 
    11466     */ 
    115     function updateProfileData( $aData ) 
    116     { 
    117         if( is_array( $aData ) ) 
    118         { 
    119             $sQueryAdd = ''; 
    120             foreach($aData as $key => $value ) 
    121             { 
    122                 $sQueryAdd .= " `$key` = '$value', "; 
    123             } 
    124         } 
    125  
    126         $this -> updateProfileDataFile( $iProfileID ); 
     67    public function getInfo($iProfileId) { 
     68        return $this->_oQuery->getInfoById((int)$iProfileId ? $iAccountId : $this->_iProfileID); 
    12769    } 
    12870 
    12971    /** 
    130      * function create cache data file 
    131      * 
    132      * @param int $iProfileID 
     72     * Validate profile id.  
     73     * @param $s - profile id 
     74     * @return profile id or false if profile was not found 
    13375     */ 
    134     function updateProfileDataFile( $iProfileID ) 
    135     { 
    136  
     76    static public function getID($s) { 
     77        $iId = BxDolProfileQuery::getInstance()->getIdById((int)$s); 
     78        return $iId ? $iId : false; 
    13779    } 
    13880 
    13981    /** 
    140      * Print code for membership status 
    141      * $memberID - member ID 
    142      * $offer_upgrade - will this code be printed at [c]ontrol [p]anel 
    143      * $credits - will print credits status if $credits == 1 
     82     * Delete profile. 
    14483     */ 
    145     function getMembershipStatus( $iPrifileID, $offer_upgrade = true, $credits = 0 ) 
    146     { 
     84    function delete($ID = false) { 
    14785 
    148     } 
     86        $ID = (int)$ID; 
     87        if (!$ID) 
     88            $ID = $this->_iProfileID; 
    14989 
    150     /** 
    151      * Shows how many days, hours, minutes member was onine last time 
    152      * 
    153      * @param  $lastNavTime 
    154      * 
    155      * @return int 
    156      */ 
    157     /*function  getProfileLastOnlinePeriod( $lastNavTime ) 
    158     { 
     90        $aProfileInfo = $this->_oQuery->getInfoById($ID); 
     91        if (!$aProfileInfo) 
     92            return false; 
    15993 
    160     }*/ 
     94        // create system event before deletion 
     95        $isStopDeletion = false; 
     96        bx_alert('profile', 'before_delete', $ID, 0, array('stop_deletion' => &$isStopDeletion)); 
     97        if ($isStopDeletion) 
     98            return false; 
    16199 
     100        // delete associated content  
     101        // TODO: remake deletion of associated content 
     102        $this->_oQuery->res("DELETE FROM `sys_fave_list` WHERE ID = {$ID} OR Profile = {$ID}" ); 
     103        $this->_oQuery->res("DELETE FROM `sys_friend_list` WHERE ID = {$ID} OR Profile = {$ID}"); 
     104        $this->_oQuery->res("DELETE FROM `sys_acl_levels_members` WHERE `IDMember` = {$ID}"); 
     105        $this->_oQuery->res("DELETE FROM `sys_tags` WHERE `ObjID` = {$ID} AND `Type` = 'profile'"); 
    162106 
    163     function getNickName() 
    164     { 
    165         $oProfileQuery = new BxDolProfileQuery(); 
    166         return process_line_output( $oProfileQuery -> getNickName( $this -> _iProfileID ) ); 
    167     } 
     107        // delete profile votings 
     108        bx_import('BxDolVoting'); 
     109        $oVotingProfile = new BxDolVoting ('profile', 0, 0); 
     110        $oVotingProfile->deleteVotings ($ID); 
    168111 
    169     function getPassword() 
    170     { 
     112        // delete profile comments 
     113        bx_import('BxDolCmts'); 
     114        $oCmts = new BxDolCmts('profile', $ID); 
     115        $oCmts->onObjectDelete(); 
     116        // delete all comments in all comments' systems, this user posted 
     117        $oCmts->onAuthorDelete($ID); 
    171118 
    172     } 
     119        // delete profile 
     120        if (!$this->_oQuery->delete($ID)) 
     121            return false; 
    173122 
    174     function getID( $vID, $bWithEmail = 1 ) 
    175     { 
    176         $oPDb = new BxDolProfileQuery(); 
     123        // create system event 
     124        bx_alert('profile', 'delete', $ID); 
    177125 
    178         if ( $bWithEmail ) 
    179         { 
    180             if ( eregi("^[_.0-9a-z-]+@([0-9a-z][0-9a-z-]+.)+[a-z]{2,4}$", $vID) ) 
    181             { 
    182                 $aMail = $oPDb -> getIdByEmail( $vID ); 
    183                 if ( (int)$aMail['ID'] ) 
    184                 { 
    185                     return (int)$aMail['ID']; 
    186                 } 
    187             } 
    188         } 
     126        // unset class instance to prevent creating the instance again 
     127        $sClass = get_class($this) . '_' . $ID; 
     128        unset($GLOBALS['bxDolClasses'][$sClass]); 
    189129 
    190         $iID = (int)$vID; 
    191         if ( strcmp("$vID", "$iID") == 0 ) 
    192         { 
    193             return $iID; 
    194         } 
    195         else 
    196         { 
    197             $aNick = $oPDb -> getIdByNickname( $vID ); 
    198             if ( (int)$aNick['ID'] ) 
    199             { 
    200                 return (int)$aNick['ID']; 
    201             } 
    202         } 
     130        $this->_iProfileID = 0; 
    203131 
    204         return false; 
     132        return true; 
    205133    } 
    206134 
    207135} 
    208 ?> 
     136 
     137/** @} */ 
     138 
  • trunk/inc/classes/BxDolProfileQuery.php

    r15211 r15698  
    1 <?php 
     1<?php defined('BX_DOL') or die('hack attempt'); 
    22/** 
    3  * @package     Dolphin Core 
    4  * @copyright   Copyright (c) BoonEx Pty Limited - http://www.boonex.com/ 
    5  * @license     CC-BY - http://creativecommons.org/licenses/by/3.0/ 
     3 * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/ 
     4 * CC-BY License - http://creativecommons.org/licenses/by/3.0/ 
     5 * 
     6 * @defgroup    DolphinCore Dolphin Core 
     7 * @{ 
    68 */ 
    7 defined('BX_DOL') or die('hack attempt'); 
    89 
    910bx_import('BxDolDb'); 
    1011 
    1112/** 
    12  * All queries related to basic profiles functionality 
     13 * All queries related to profiles 
    1314 */ 
    1415class BxDolProfileQuery extends BxDolDb { 
    1516 
    16     var $_sTable = '`Profiles`'; 
    17  
    18     function BxDolProfileQuery() { 
     17    public function __construct() { 
    1918 
    2019        if (isset($GLOBALS['bxDolClasses'][get_class($this)])) 
    2120            trigger_error ('Multiple instances are not allowed for the class: ' . get_class($this), E_USER_ERROR); 
    2221 
    23         parent::BxDolDb(); 
     22        parent::__construct(); 
    2423    } 
    2524 
     
    4544     * Get profile by specified field name and value. 
    4645     * It is for internal usage only. 
    47      * Use other funtions to get profile info, like getProfileById, getProfileByEmail, etc. 
     46     * Use other funtions to get profile info, like getInfoById, etc. 
    4847     * @param string $sField database field name 
    4948     * @param mixed $sValue database field value 
    5049     * @return array with porfile info 
    5150     */ 
    52     protected function _getProfileDataByField ($sField, $sValue) { 
    53         $sSql = $this->prepare("SELECT * FROM " . $this->_sTable . " WHERE `$sField` = ? LIMIT 1", $sValue); 
    54         return (int)$this->getRow($sSql); 
     51    protected function getProfilesByAccount ($iAccountId) { 
     52        $sSql = $this->prepare("SELECT * FROM `sys_profiles` WHERE `account_id` = ? LIMIT 1", $iAccountId); 
     53        return $this->getAllWithKey($sSql, 'id'); 
     54    } 
     55 
     56    /** 
     57     * Get profile by specified field name and value. 
     58     * It is for internal usage only. 
     59     * Use other funtions to get profile info, like getInfoById, etc. 
     60     * @param string $sField database field name 
     61     * @param mixed $sValue database field value 
     62     * @return array with porfile info 
     63     */ 
     64    protected function _getDataByField ($sField, $sValue) { 
     65        $sSql = $this->prepare("SELECT * FROM `sys_profiles` WHERE `$sField` = ? LIMIT 1", $sValue); 
     66        return $this->getRow($sSql); 
     67    } 
     68 
     69    /** 
     70     * get profile id by id 
     71     */ 
     72    public function getIdById($iId) { 
     73        return (int)$this->_getFieldByField('id', 'id', $iId); 
    5574    } 
    5675 
     
    6079     * @return array with profile info 
    6180     */ 
    62     function getProfileDataById( $iID )    { 
    63         return $this->_getProfileDataByField('ID', (int)$iID); 
    64     } 
    65  
    66     /** 
    67      * @see getProfileIdByEmail 
    68      */ 
    69     function getIdByEmail($sEmail) { 
    70         return $this->getProfileIdByEmail($sEmail); 
    71     } 
    72  
    73     /** 
    74      * Get profile id by email 
    75      * @param string $s search profile by this email string 
    76      * @return profile id 
    77      */ 
    78     public function getProfileIdByEmail ($s) { 
    79         return (int)$this->_getProfileFieldByField('ID', 'Email', $s); 
    80     } 
    81  
    82     /** 
    83      * @see getProfileIdByNickName 
    84      */ 
    85     function getIdByNickname($sNickname) { 
    86         return $this->getProfileIdByNickName($sNickname); 
    87     } 
    88  
    89     /** 
    90      * Get profile id by nickname 
    91      * @param string $s search profile by this nickname string 
    92      * @return profile id 
    93      */ 
    94     public function getProfileIdByNickName ($s) { 
    95         return (int)$this->_getProfileFieldByField('ID', 'NickName', $s); 
    96     } 
    97  
    98     /** 
    99      * Get profile nickname by id 
    100      * @param string $s search profile by this id 
    101      * @return profile nickname 
    102      */ 
    103     function getNickName($iID) { 
    104         return $this->_getProfileFieldByField('NickName', 'ID', (int)$iID); 
    105     } 
    106  
    107     /** 
    108      * Get profile email by id 
    109      * @param string $s search profile by this id 
    110      * @return profile email 
    111      */ 
    112     function getEmail($iID) { 
    113         return $this->_getProfileFieldByField('Email', 'ID', (int)$iID); 
     81    public function getInfoById( $iID )    { 
     82        return $this->_getDataByField('id', (int)$iID); 
    11483    } 
    11584 
     
    11786     * Get profile field by specified field name and value. 
    11887     * In most cases it is for internal usage only. 
    119      * Use other funtions to get profile info, like getProfileIdByEmail, etc. 
     88     * Use other funtions to get profile info, like getIdByEmail, etc. 
    12089     * @param string $sFieldRequested database field name to return 
    12190     * @param string $sFieldSearch database field name to search for 
    12291     * @param mixed $sValue database field value 
    123      * @return profile id 
     92     * @return specified profile field value 
    12493     */ 
    125     protected function _getProfileFieldByField ($sFieldRequested, $sFieldSearch, $sValue) { 
    126         $sSql = $this->prepare("SELECT `$sFieldRequested` FROM " . $this->_sTable . " WHERE `$sFieldSearch` = ? LIMIT 1", $sValue); 
     94    protected function _getFieldByField ($sFieldRequested, $sFieldSearch, $sValue) { 
     95        $sSql = $this->prepare("SELECT `$sFieldRequested` FROM `sys_profiles` WHERE `$sFieldSearch` = ? LIMIT 1", $sValue); 
    12796        return $this->getOne($sSql); 
     97    } 
     98 
     99    /** 
     100     * Update some field by profile id 
     101     * In most cases it is for internal usage only. 
     102     * Use other funtions to get profile info, like updateLogged, etc. 
     103     * @param string $sFieldRequested database field name to return 
     104     * @param string $sFieldSearch database field name to search for 
     105     * @param mixed $sValue database field value 
     106     * @return specified profile field value 
     107     */ 
     108    protected function _updateField ($iId, $sFieldForUpdate, $sValue) { 
     109        $sSql = $this->prepare("UPDATE `sys_profiles` SET `$sFieldForUpdate` = ? WHERE `id` = ? LIMIT 1", $sValue, $iId); 
     110        return $this->query($sSql); 
     111    } 
     112 
     113    /** 
     114     * Delete profile info by id 
     115     * @param int $iID profile id 
     116     * @return affected rows 
     117     */ 
     118    public function delete($iID) { 
     119        $sSql = $this->prepare("DELETE FROM `sys_profiles` WHERE `id` = ? LIMIT 1", $iID); 
     120        return $this->query($sSql); 
    128121    } 
    129122 
    130123} 
    131124 
     125/** @} */ 
     126 
  • trunk/inc/classes/BxDolTemplate.php

    r15484 r15698  
    846846                    //bx_import('BxTemplMemberMenu'); 
    847847                    //$oMemberMenu = new BxTemplMemberMenu(); 
    848                     $sRet = 'TODO: member menu';//$oMemberMenu -> genMemberMenu($iProfileId); 
     848                    $sRet = ''; //$oMemberMenu -> genMemberMenu($iProfileId); // TODO: member menu 
    849849                } 
    850850                break; 
     
    17931793        </div>'; 
    17941794    } 
     1795 
     1796    function getPageCode($oTemplate = null) { 
     1797        if (empty($oTemplate)) 
     1798           $oTemplate = $this; 
     1799 
     1800        header( 'Content-type: text/html; charset=utf-8' ); 
     1801        echo $oTemplate->parsePageByName('page_' . $oTemplate->getPageNameIndex() . '.html', $oTemplate->getPageContent()); 
     1802    } 
    17951803} 
     1804 
  • trunk/inc/design.inc.php

    r15570 r15698  
    66 */ 
    77defined('BX_DOL') or die('hack attempt'); 
    8  
    9 /** 
    10  * Put design progress bar code 
    11  *  $text     - progress bar text 
    12  *  $width    - width of progress bar in pixels 
    13  *  $max_pos  - maximal position of progress bar 
    14  *  $curr_pos - current position of progress bar 
    15  **/ 
    16 function DesignProgressPos( $text, $width, $max_pos, $curr_pos, $progress_num = '1' ) { 
    17     $percent = ( $max_pos ) ? $curr_pos * 100 / $max_pos : $percent = 0; 
    18     return DesignProgress( $text, $width, $percent, $progress_num ); 
    19 } 
    20  
    21 /** 
    22  * TODO: move html to template 
    23  * Put design progress bar code 
    24  *  $text     - progress bar text 
    25  *  $width    - width of progress bar in pixels 
    26  *  $percent  - current position of progress bar in percents 
    27  **/ 
    28 function DesignProgress ( $text, $width, $percent, $progress_num, $id = ''  ) { 
    29     $ret = ""; 
    30     $ret .= '<div class="rate_block" style="width:' . $width . 'px;">'; 
    31         $ret .= '<div class="rate_text"' . ( $id ? " id=\"{$id}_text\"" : '' ) . '>'; 
    32             $ret .= $text; 
    33         $ret .= '</div>'; 
    34         $ret .= '<div class="rate_scale"' . ( $id ? " id=\"{$id}_scale\"" : '' ) . '>'; 
    35             $ret .= '<div' . ( $id ? " id=\"{$id}_bar\"" : '' ) . ' style="position:relative; height:10px; font-size:1px; width:' . round($percent) . '%; background-image:url(' . getTemplateIcon("scale_index_{$progress_num}.gif") . '); background-repeat:repeat-x;"></div>'; 
    36         $ret .= '</div>'; 
    37     $ret .= '</div>'; 
    38  
    39     return $ret; 
    40 } 
    418 
    429/** 
     
    11178 
    11279/** 
     80 * DEPRECATED 
    11381 * Put top code for the page 
    11482 **/ 
    11583function PageCode($oTemplate = null) { 
    116     if(empty($oTemplate)) 
     84    echo "DEPRECATED: function PageCode, use BxDolTemplate::getPageCode instead"; 
     85    if (empty($oTemplate)) 
    11786       $oTemplate = BxDolTemplate::getInstance(); 
    118  
    119     header( 'Content-type: text/html; charset=utf-8' ); 
    120     echo $oTemplate->parsePageByName('page_' . $oTemplate->getPageNameIndex() . '.html', $oTemplate->getPageContent()); 
     87    $oTemplate->getPageCode(); 
    12188} 
    12289 
  • trunk/inc/languages.inc.php

    r15664 r15698  
    127127            $iLangId = 0; 
    128128 
    129         //TODO: Move to some profile management class (module). 
    130         $iProfileId = getLoggedId(); 
    131         $sSql = $oDb->prepare("UPDATE `Profiles` SET `LangID`=? WHERE `ID`=? LIMIT 1", $iLangId, $iProfileId); 
    132         $oDb->query($sSql); 
    133         createUserDataFile($iProfileId); 
     129        $iAccountId = getLoggedId(); 
     130        bx_import('BxDolAccountQuery'); 
     131        $oAccountQuery = BxDolAccountQuery::getInstance(); 
     132        $oAccountQuery->updateLanguage($iAccountId, $iLangId); 
    134133    } 
    135134 
  • trunk/inc/membership_levels.inc.php

    r15632 r15698  
    615615}        
    616616 
     617 
     618 
     619/** 
     620 * Print code for membership status 
     621 * $memberID - member ID 
     622 * $offer_upgrade - will this code be printed at [c]ontrol [p]anel 
     623 */ 
     624function GetMembershipStatus($memberID, $offer_upgrade = true) { 
     625    $ret = ''; 
     626 
     627    $membership_info = getMemberMembershipInfo($memberID); 
     628 
     629    $viewMembershipActions = "<br />(<a onclick=\"javascript:window.open('explanation.php?explain=membership&amp;type=".$membership_info['ID']."', '', 'width=660, height=500, menubar=no, status=no, resizable=no, scrollbars=yes, toolbar=no, location=no');\" href=\"javascript:void(0);\">"._t("_VIEW_MEMBERSHIP_ACTIONS")."</a>)<br />"; 
     630 
     631    // Show colored membership name 
     632    if ( $membership_info['ID'] == MEMBERSHIP_ID_STANDARD ) { 
     633        $ret .= _t( "_MEMBERSHIP_STANDARD" ). $viewMembershipActions; 
     634        if ( $offer_upgrade ) 
     635            $ret .= " ". _t( "_MEMBERSHIP_UPGRADE_FROM_STANDARD" ); 
     636    } else { 
     637        $ret .= "<font color=\"red\">{$membership_info['Name']}</font>$viewMembershipActions"; 
     638 
     639        $days_left = (int)( ($membership_info['DateExpires'] - time()) / (24 * 3600) ); 
     640 
     641        if(!is_null($membership_info['DateExpires'])) { 
     642            $ret .= ( $days_left > 0 ) ? _t( "_MEMBERSHIP_EXPIRES_IN_DAYS", $days_left ) : _t( "_MEMBERSHIP_EXPIRES_TODAY", date( "H:i", $membership_info['DateExpires'] ), date( "H:i" ) ); 
     643        } else { 
     644            $ret.= _t("_MEMBERSHIP_EXPIRES_NEVER"); 
     645        } 
     646    } 
     647    return $ret; 
     648} 
     649 
     650 
     651function mem_expiration_letter( $ID, $membership_name, $expire_days ) { 
     652    $ID = (int)$ID; 
     653 
     654    if ( !$ID ) 
     655        return false; 
     656 
     657    $p_arr = db_arr( "SELECT `Email` FROM `Profiles` WHERE `ID` = $ID", 0 ); 
     658    if ( !$p_arr ) 
     659        return false; 
     660 
     661    bx_import('BxDolEmailTemplates'); 
     662    $rEmailTemplate = new BxDolEmailTemplates(); 
     663    $aTemplate = $rEmailTemplate -> getTemplate( 't_MemExpiration', $ID ) ; 
     664 
     665    $recipient  = $p_arr['Email']; 
     666 
     667    $aPlus = array(); 
     668    $aPlus['MembershipName'] = $membership_name; 
     669    $aPlus['ExpireDays'] = $expire_days; 
     670 
     671    $mail_ret = sendMail( $recipient, $aTemplate['Subject'], $aTemplate['Body'], $ID, $aPlus  ); 
     672 
     673    if ($mail_ret) 
     674        return true; 
     675    else 
     676        return false; 
     677} 
  • trunk/inc/profiles.inc.php

    r15547 r15698  
    88 
    99/** 
    10  * The following functions are needed to check whether user is logged in or not, active or not and get his ID. 
     10 * It is needed to check whether user is logged in or not 
    1111 */ 
    1212function isLogged() { 
    1313    return getLoggedId() != 0; 
    1414} 
    15 function isLoggedActive() { 
    16     return isProfileActive(); 
    17 } 
     15 
     16/** 
     17 * It returns logged in account id 
     18 */ 
    1819function getLoggedId() { 
    1920    return isset($_COOKIE['memberID']) && (!empty($GLOBALS['logged']['member']) || !empty($GLOBALS['logged']['admin'])) ? (int)$_COOKIE['memberID'] : 0; 
    2021} 
     22 
     23/** 
     24 * It returns logged in account password 
     25 */ 
    2126function getLoggedPassword() { 
    2227    return isset($_COOKIE['memberPassword']) && ($GLOBALS['logged']['member'] || $GLOBALS['logged']['admin']) ? $_COOKIE['memberPassword'] : ''; 
     
    2429 
    2530/** 
    26  * The following functions are needed to check the ROLE of user. 
     31 * It checks if account is member. 
    2732 */ 
    2833function isMember($iId = 0) { 
    2934    return isRole(BX_DOL_ROLE_MEMBER, $iId); 
    3035} 
    31 if(!function_exists("isAdmin")) { 
     36 
     37if (!function_exists("isAdmin")) { 
     38    /** 
     39     * It checks if account is admin. 
     40     */ 
    3241    function isAdmin($iId = 0) { 
    3342        return isRole(BX_DOL_ROLE_ADMIN, $iId); 
    3443    } 
    3544} 
    36 function isAffiliate($iId = 0) { 
    37     return isRole(BX_DOL_ROLE_AFFILIATE, $iId); 
    38 } 
    39 function isModerator($iId = 0) { 
    40     return isRole(BX_DOL_ROLE_MODERATOR, $iId); 
    41 } 
     45 
     46/** 
     47 * It checks account's role 
     48 */ 
    4249function isRole($iRole, $iId = 0) { 
    43     $aProfile = getProfileInfo($iId); 
    44     if($aProfile === false) 
    45         return false; 
    46  
    47     if(!((int)$aProfile['Role'] & $iRole)) 
     50 
     51    bx_import('BxDolAccount'); 
     52    $oAccount = BxDolAccount::getInstance($iId); 
     53    if (!$oAccount) 
     54        return false; 
     55 
     56    $aAccountInfo = $oAccount->getInfo(); 
     57 
     58    if (!$aAccountInfo) 
     59        return false; 
     60 
     61    if (!((int)$aAccountInfo['role'] & $iRole)) 
    4862        return false; 
    4963 
     
    5165} 
    5266 
    53 function getID($str, $with_email = 1) { 
    54  
    55     bx_import('BxDolProfileQuery'); 
    56     $oProfileQuery = BxDolProfileQuery::getInstance(); 
    57  
    58     if ($with_email) { 
    59         if ( preg_match("/^[_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,4}$/", $str) ) { 
    60             $iMemberId = (int)$oProfileQuery->getProfileIdByEmail($str); 
    61             if ($iMemberId) 
    62                 return $iMemberId; 
    63         } 
    64     } 
    65  
    66     $iID = (int)$oProfileQuery->getProfileIdByNickName($str); 
    67     if(!$iID) { 
    68         $aProfile = getProfileInfo($str); 
    69         $iID = isset($aProfile['ID']) ? $aProfile['ID'] : 0; 
    70     } 
    71     return $iID; 
    72 } 
    73  
    74 $aUser = array(); //global cache array 
    75  
    76 function ShowZodiacSign( $date ) { 
    77  
    78     if ( $date == "0000-00-00" ) 
    79         return ""; 
    80  
    81     if ( strlen($date) ) { 
    82         $m = substr( $date, -5, 2 ); 
    83         $d = substr( $date, -2, 2 ); 
    84  
    85         switch ( $m ) { 
    86             case '01': if ( $d <= 20 ) $sign = "capricorn"; else $sign = "aquarius"; 
    87                 break; 
    88             case '02': if ( $d <= 20 ) $sign = "aquarius"; else $sign = "pisces"; 
    89                 break; 
    90             case '03': if ( $d <= 20 ) $sign = "pisces"; else $sign = "aries"; 
    91                 break; 
    92             case '04': if ( $d <= 20 ) $sign = "aries"; else $sign = "taurus"; 
    93                 break; 
    94             case '05': if ( $d <= 20 ) $sign = "taurus"; else $sign = "gemini"; 
    95                 break; 
    96             case '06': if ( $d <= 21 ) $sign = "gemini"; else $sign = "cancer"; 
    97                 break; 
    98             case '07': if ( $d <= 22 ) $sign = "cancer"; else $sign = "leo"; 
    99                 break; 
    100             case '08': if ( $d <= 23 ) $sign = "leo"; else $sign = "virgo"; 
    101                 break; 
    102             case '09': if ( $d <= 23 ) $sign = "virgo"; else $sign = "libra"; 
    103                 break; 
    104             case '10': if ( $d <= 23 ) $sign = "libra"; else $sign = "scorpio"; 
    105                 break; 
    106             case '11': if ( $d <= 22 ) $sign = "scorpio"; else $sign = "sagittarius"; 
    107                 break; 
    108             case '12': if ( $d <= 21 ) $sign = "sagittarius"; else $sign = "capricorn"; 
    109         } 
    110  
    111         bx_import('BxDolTemplate'); 
    112         return '<img src="' . BxDolTemplate::getInstance()->getImageUrl($sign . '.png') . '" alt="' . $sign . '" title="' . $sign . '" />'; 
    113     } else { 
    114         return ""; 
    115     } 
    116 } 
    117  
    118 function age( $birth_date ) { 
    119     if ( $birth_date == "0000-00-00" ) 
    120         return _t("_uknown"); 
    121  
    122     $bd = explode( "-", $birth_date ); 
    123     $age = date("Y") - $bd[0] - 1; 
    124  
    125     $arr[1] = "m"; 
    126     $arr[2] = "d"; 
    127  
    128     for ( $i = 1; $arr[$i]; $i++ ) { 
    129         $n = date( $arr[$i] ); 
    130         if ( $n < $bd[$i] ) 
    131             break; 
    132         if ( $n > $bd[$i] ) { 
    133             ++$age; 
    134             break; 
    135         } 
    136     } 
    137  
    138     return $age; 
    139 } 
    140  
    141 /** 
    142  * Print code for membership status 
    143  * $memberID - member ID 
    144  * $offer_upgrade - will this code be printed at [c]ontrol [p]anel 
    145  */ 
    146 function GetMembershipStatus($memberID, $offer_upgrade = true) { 
    147     $ret = ''; 
    148  
    149     $membership_info = getMemberMembershipInfo($memberID); 
    150  
    151     $viewMembershipActions = "<br />(<a onclick=\"javascript:window.open('explanation.php?explain=membership&amp;type=".$membership_info['ID']."', '', 'width=660, height=500, menubar=no, status=no, resizable=no, scrollbars=yes, toolbar=no, location=no');\" href=\"javascript:void(0);\">"._t("_VIEW_MEMBERSHIP_ACTIONS")."</a>)<br />"; 
    152  
    153     // Show colored membership name 
    154     if ( $membership_info['ID'] == MEMBERSHIP_ID_STANDARD ) { 
    155         $ret .= _t( "_MEMBERSHIP_STANDARD" ). $viewMembershipActions; 
    156         if ( $offer_upgrade ) 
    157             $ret .= " ". _t( "_MEMBERSHIP_UPGRADE_FROM_STANDARD" ); 
    158     } else { 
    159         $ret .= "<font color=\"red\">{$membership_info['Name']}</font>$viewMembershipActions"; 
    160  
    161         $days_left = (int)( ($membership_info['DateExpires'] - time()) / (24 * 3600) ); 
    162  
    163         if(!is_null($membership_info['DateExpires'])) { 
    164             $ret .= ( $days_left > 0 ) ? _t( "_MEMBERSHIP_EXPIRES_IN_DAYS", $days_left ) : _t( "_MEMBERSHIP_EXPIRES_TODAY", date( "H:i", $membership_info['DateExpires'] ), date( "H:i" ) ); 
    165         } else { 
    166             $ret.= _t("_MEMBERSHIP_EXPIRES_NEVER"); 
    167         } 
    168     } 
    169     return $ret; 
    170 } 
    171  
    172 function isAutoApproval( $sAction ) { 
    173     $autoApproval_ifPhoto   = ( 'on' == getParam("autoApproval_ifPhoto") ); 
    174     $autoApproval_ifSound   = ( 'on' == getParam("autoApproval_ifSound") ); 
    175     $autoApproval_ifVideo   = ( 'on' == getParam("autoApproval_ifVideo") ); 
    176     $autoApproval_ifProfile = ( 'on' == getParam("autoApproval_ifProfile") ); 
    177     $autoApproval_ifJoin    = ( 'on' == getParam("autoApproval_ifJoin") ); 
    178  
    179     switch ( $sAction ) { 
    180         case 'photo': 
    181             return $autoApproval_ifPhoto; 
    182         case 'sound': 
    183             return $autoApproval_ifSound; 
    184         case 'video': 
    185             return $autoApproval_ifVideo; 
    186         case 'profile': 
    187             return $autoApproval_ifProfile; 
    188         case 'join': 
    189             return $autoApproval_ifJoin; 
    190         default: 
    191             return false; 
    192     } 
    193 } 
    194  
    195 function deleteUserDataFile( $userID ) { 
    196      global $aUser; 
    197  
    198     $bUseCacheSystem = ( getParam('enable_cache_system') == 'on' ) ? true : false; 
    199     if (!$bUseCacheSystem) return false; 
    200  
    201     $userID = (int)$userID; 
    202     $fileName = BX_DIRECTORY_PATH_CACHE . 'user' . $userID . '.php'; 
    203     if( file_exists($fileName) ) { 
    204         unlink($fileName); 
    205     } 
    206 } 
    207  
    208 function createUserDataFile( $userID ) { 
    209     global $aUser; 
    210  
    211     $bUseCacheSystem = ( getParam('enable_cache_system') == 'on' ) ? true : false; 
    212     if (!$bUseCacheSystem) return false; 
    213  
    214     $userID = (int)$userID; 
    215     $fileName = BX_DIRECTORY_PATH_CACHE . 'user' . $userID . '.php'; 
    216     if( $userID > 0 ) { 
    217  
    218         $aPreUser = getProfileInfoDirect ($userID); 
    219  
    220         if( isset( $aPreUser ) and is_array( $aPreUser ) and $aPreUser) { 
    221             $sUser = '<?'; 
    222             $sUser .= "\n\n"; 
    223             $sUser .= '$aUser[' . $userID . '] = array();'; 
    224             $sUser .= "\n"; 
    225             $sUser .= '$aUser[' . $userID . '][\'datafile\'] = true;'; 
    226             $sUser .= "\n"; 
    227  
    228             $replaceWhat = array( '\\',   '\''   ); 
    229             $replaceTo   = array( '\\\\', '\\\'' ); 
    230  
    231             foreach( $aPreUser as $key =>  $value ) 
    232                 $sUser .= '$aUser[' . $userID . '][\'' . $key . '\']' . ' = ' . '\'' . str_replace( $replaceWhat, $replaceTo, $value )  . '\'' . ";\n"; 
    233  
    234             $sUser .= "\n" . '?>'; 
    235  
    236             if( $file = fopen( $fileName, "w" ) ) { 
    237                 fwrite( $file, $sUser ); 
    238                 fclose( $file ); 
    239                 @chmod ($fileName, 0666); 
    240  
    241                 @include( $fileName ); 
    242                 return true; 
    243             } else 
    244                 return false; 
    245         } 
    246     } else 
    247         return false; 
    248 } 
    249  
    250 /** 
    251  * Check whether the requested profile is active or not. 
    252  */ 
    253 function isProfileActive($iId = 0) { 
    254     $aProfile = getProfileInfo($iId); 
    255     if($aProfile === false || empty($aProfile)) 
    256         return false; 
    257  
    258     return $aProfile['Status'] == 'Active'; 
    259 } 
    260 function getProfileInfoDirect ($iProfileID) { 
    261     return BxDolDb::getInstance()->getRow("SELECT * FROM `Profiles` WHERE `ID`='" . $iProfileID . "' LIMIT 1"); 
    262 } 
    263  
    264 function getProfileInfo($iProfileID = 0, $checkActiveStatus = false, $forceCache = false) { 
    265     global $aUser; 
    266  
    267     $iProfileID = !empty($iProfileID) ? (int)$iProfileID : getLoggedId(); 
    268     if(!$iProfileID) 
    269         return false; 
    270  
    271     if(!isset( $aUser[$iProfileID]) || !is_array($aUser[$iProfileID]) || $forceCache) { 
    272         $sCacheFile = BX_DIRECTORY_PATH_CACHE . 'user' . $iProfileID . '.php'; 
    273         if( !file_exists( $sCacheFile ) || $forceCache ) { 
    274             if( !createUserDataFile( $iProfileID ) ) { 
    275                 return getProfileInfoDirect ($iProfileID); 
    276             } 
    277         } 
    278  
    279         @include( $sCacheFile ); 
    280     } 
    281  
    282     if( $checkActiveStatus and $aUser[$iProfileID]['Status'] != 'Active' ) 
    283         return false; 
    284  
    285     return $aUser[$iProfileID]; 
    286 } 
    287  
    288 /* osed only for xmlrpc */ 
    289 function getNewLettersNum( $iID ) { 
    290     $sqlQuery = 
    291     " 
    292         SELECT 
    293             COUNT(`Recipient`) 
    294         FROM 
    295             `sys_messages` 
    296         WHERE 
    297             `Recipient`='$iID' 
    298                 AND 
    299             `New`='1' 
    300                   AND 
    301         NOT FIND_IN_SET('Recipient', `Trash`) 
    302     "; 
    303     return (int)db_value($sqlQuery); 
    304 } 
    305  
    306 /*function for inner using only 
    307     $ID - profile ID 
    308     $iFrStatus - friend status (1 - approved, 0 - wait) 
    309     $iOnline - filter for last nav moment (in minutes) 
    310     $sqlWhere - add sql Conditions, should beginning from AND 
    311 */ 
     67 
     68/** 
     69 * function for inner using only 
     70 * @param $ID - profile ID 
     71 * @param $iFrStatus - friend status (1 - approved, 0 - wait) 
     72 * @param $iOnline - filter for last nav moment (in minutes) 
     73 * @param $sqlWhere - add sql Conditions, should beginning from AND 
     74 */ 
    31275function getFriendNumber($iID, $iFrStatus = 1, $iOnline = 0, $sqlWhere = '') { 
    31376    $sqlAdd = ''; 
     
    399162} 
    400163 
    401 /* 
    402 * The function returns NickName by given ID. If no ID specified, it tryes to get if from _COOKIE['memberID']; 
    403 */ 
    404 function getNickName( $ID = '' ) { 
    405     if ( !$ID && !empty($_COOKIE['memberID']) ) 
    406         $ID = (int)$_COOKIE['memberID']; 
    407  
    408     if ( !$ID ) 
    409         return ''; 
    410  
    411     $arr = getProfileInfo( $ID ); 
    412     return $arr['NickName']; 
    413 } 
    414  
    415 /* 
    416  * The function returns Password by given ID. 
    417  */ 
    418 function getPassword( $ID = '' ) { 
    419     if ( !(int)$ID ) 
    420         return ''; 
    421  
    422     $arr = getProfileInfo( $ID ); 
    423     return $arr['Password']; 
    424 } 
    425  
    426 function getProfileLink( $iID, $sLinkAdd = '' ) { 
    427     $aProfInfo = getProfileInfo( $iID ); 
    428     $iID = ($aProfInfo['Couple'] > 0 && $aProfInfo['ID'] > $aProfInfo['Couple']) ? $aProfInfo['Couple'] : $iID; 
    429  
    430     return (getParam('enable_modrewrite') == 'on') ? BX_DOL_URL_ROOT . getNickName($iID) . ( $sLinkAdd ? "?{$sLinkAdd}" : '' ) : BX_DOL_URL_ROOT . 'profile.php?ID='.$iID . ( $sLinkAdd ? "&{$sLinkAdd}" : '' ); 
    431 } 
    432  
    433164function isLoggedBanned($iCurUserID = 0) { 
    434165    $iCCurUserID = ($iCurUserID>0) ? $iCurUserID : (int)$_COOKIE['memberID']; 
     
    446177    return false; 
    447178} 
     179 
    448180function bx_login($iId, $bRememberMe = false) { 
    449181 
    450     $sPassword = getPassword($iId); 
     182    bx_import('BxDolAccountQuery'); 
     183    $oAccountQuery = BxDolAccountQuery::getInstance(); 
     184 
     185    $sPassword = $oAccountQuery->getPassword($iId); 
     186    if (!$sPassword) 
     187        return false; 
    451188 
    452189    $aUrl = parse_url(BX_DOL_URL_ROOT); 
     
    459196    $_COOKIE['memberPassword'] = $sPassword; 
    460197 
    461     db_res("UPDATE `Profiles` SET `DateLastLogin`=NOW(), `DateLastNav`=NOW() WHERE `ID`='" . $iId . "'"); 
    462     createUserDataFile($iId); 
    463  
    464     require_once(BX_DIRECTORY_PATH_CLASSES . 'BxDolAlerts.php'); 
    465     $oZ = new BxDolAlerts('profile', 'login',  $iId); 
    466     $oZ->alert(); 
    467  
    468     return getProfileInfo($iId); 
    469 } 
     198    $oAccountQuery->updateLoggedIn($iId); 
     199 
     200    bx_alert('account', 'login',  $iId); 
     201 
     202    return $oAccountQuery->getInfoById($iId); 
     203} 
     204 
    470205function bx_logout($bNotify = true) { 
    471     if($bNotify && isMember()) { 
    472         require_once(BX_DIRECTORY_PATH_CLASSES . 'BxDolAlerts.php'); 
    473         $oZ = new BxDolAlerts('profile', 'logout', (int)$_COOKIE['memberID']); 
    474         $oZ->alert(); 
    475     } 
     206    if ($bNotify && isMember()) 
     207        bx_alert('profile', 'logout', (int)$_COOKIE['memberID']); 
    476208 
    477209    $aUrl = parse_url(BX_DOL_URL_ROOT); 
     
    483215    unset($_COOKIE['memberID']); 
    484216    unset($_COOKIE['memberPassword']); 
    485 } 
    486  
    487 function setSearchStartAge($iMin) { 
    488     if ($iMin <= 0) 
    489         return false; 
    490  
    491     BxDolDb::getInstance()->query("update `sys_profile_fields` set `Min` = $iMin where `Name` = 'DateOfBirth'"); 
    492  
    493     require_once(BX_DIRECTORY_PATH_CLASSES . 'BxDolPFM.php'); 
    494     $oCacher = new BxDolPFMCacher(); 
    495     $oCacher -> createCache(); 
    496  
    497     return true; 
    498 } 
    499  
    500 function setSearchEndAge($iMax) { 
    501     if ($iMax <= 0) 
    502         return false; 
    503  
    504     BxDolDb::getInstance()->query("update `sys_profile_fields` set `Max` = $iMax where `Name` = 'DateOfBirth'"); 
    505  
    506     require_once(BX_DIRECTORY_PATH_CLASSES . 'BxDolPFM.php'); 
    507     $oCacher = new BxDolPFMCacher(); 
    508     $oCacher -> createCache(); 
    509  
    510     return true; 
    511217} 
    512218 
     
    518224 
    519225    $bLogged = false; 
    520     foreach($aAccTypes as $iKey => $sValue) 
    521         if($GLOBALS['logged'][$sValue] = member_auth($iKey, false)) { 
     226    foreach ($aAccTypes as $iKey => $sValue) 
     227        if ($GLOBALS['logged'][$sValue] = member_auth($iKey, false)) { 
    522228            $bLogged = true; 
    523229            break; 
    524230        } 
    525231 
    526     if((isset($_COOKIE['memberID']) || isset($_COOKIE['memberPassword'])) && !$bLogged) 
     232    if ((isset($_COOKIE['memberID']) || isset($_COOKIE['memberPassword'])) && !$bLogged) 
    527233        bx_logout(false); 
    528234} 
    529235 
    530 // 0 - member, 1 - admin 
    531 function member_auth($member = 0, $error_handle = true, $bAjx = false) { 
    532  
    533        switch ($member) { 
     236/** 
     237 * @param $member - 0 = member, 1 = admin 
     238 * @param $bHandleError - if set to true (it is true by default) then login form is displayedautomatically if user is not logged in 
     239 * @param $bAjx 
     240 * @return  
     241 */ 
     242function member_auth($member = 0, $bHandleError = true, $bAjx = false) { 
     243 
     244    switch ($member) { 
    534245        case 0: 
    535                $mem        = 'member'; 
    536                $login_page = BX_DOL_URL_ROOT . "member.php"; 
     246            $mem        = 'member'; 
     247            $login_page = BX_DOL_URL_ROOT . "member.php"; 
    537248            $iRole      = BX_DOL_ROLE_MEMBER; 
    538249        break; 
    539250        case 1: 
    540                $mem        = 'admin'; 
    541                $login_page = BX_DOL_URL_STUDIO . "index.php"; 
     251            $mem        = 'admin'; 
     252            $login_page = BX_DOL_URL_STUDIO . "index.php"; 
    542253            $iRole      = BX_DOL_ROLE_ADMIN; 
    543254        break; 
     
    545256 
    546257    if (empty($_COOKIE['memberID']) || !isset($_COOKIE['memberPassword'])) { 
    547         if ($error_handle) { 
     258        if ($bHandleError) { 
    548259            $text = _t("_LOGIN_REQUIRED_AE1"); 
    549260            if ($member == 0) 
     
    551262 
    552263            $bAjxMode = (isset( $_SERVER['HTTP_X_REQUESTED_WITH'] ) and $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest') ? true : false; 
    553             if ($member=1 && $bAjx==true) $bAjxMode = true; 
     264            if ($member=1 && $bAjx==true)  
     265                $bAjxMode = true; 
    554266            login_form($text, $member, $bAjxMode); 
    555267        } 
     
    557269    } 
    558270 
    559     return check_login(bx_process_input($_COOKIE['memberID']), bx_process_input($_COOKIE['memberPassword' ]), $iRole, $error_handle); 
    560 } 
    561  
    562 // check encrypted password (ex., from Cookie) 
    563 function check_login($ID, $passwd, $iRole = BX_DOL_ROLE_MEMBER, $error_handle = true) { 
     271    return check_login(bx_process_input($_COOKIE['memberID']), bx_process_input($_COOKIE['memberPassword' ]), $iRole, $bHandleError); 
     272} 
     273 
     274/** 
     275 * check encrypted password (ex., from Cookie) 
     276 */ 
     277function check_login($ID, $passwd, $iRole = BX_DOL_ROLE_MEMBER, $bHandleError = true) { 
     278 
    564279    $ID = (int)$ID; 
     280 
     281    bx_import('BxDolAccount'); 
     282    $oAccount = BxDolAccount::getInstance($ID); 
     283    if (!$oAccount) { 
     284        if ($bHandleError) 
     285            login_form(_t("_PROFILE_ERR"), $member); 
     286        return false; 
     287    } 
     288 
     289    $aAccountInfo = $oAccount->getInfo(); 
    565290 
    566291    switch ($iRole) { 
     
    569294    } 
    570295 
    571     if (!$ID) { 
    572         if ($error_handle) 
     296    // If no such account available 
     297    if (!$aAccountInfo) { 
     298        if ($bHandleError) 
    573299            login_form(_t("_PROFILE_ERR"), $member); 
    574300        return false; 
    575301    } 
    576302 
    577     $aProfile = getProfileInfo($ID); 
    578  
    579     // If no such members 
    580     if (!$aProfile) { 
    581         if ($error_handle) 
    582             login_form(_t("_PROFILE_ERR"), $member); 
    583         return false; 
    584     } 
    585  
    586303    // If password is incorrect 
    587     if (strcmp($aProfile['Password'], $passwd) != 0) { 
    588         if ($error_handle) 
     304    if (strcmp($aAccountInfo['password'], $passwd) != 0) { 
     305        if ($bHandleError) 
    589306            login_form(_t("_INVALID_PASSWD"), $member); 
    590307        return false; 
    591308    } 
    592309 
    593     if (!((int)$aProfile['Role'] & $iRole)) { 
    594         if ($error_handle) 
     310    if (!((int)$aAccountInfo['role'] & $iRole)) { 
     311        if ($bHandleError) 
    595312          login_form(_t("_INVALID_ROLE"), $member); 
    596313        return false; 
    597314    } 
    598315 
    599     if(((int)$aProfile['Role'] & BX_DOL_ROLE_ADMIN) || ((int)$aProfile['Role'] & BX_DOL_ROLE_MODERATOR)) { 
    600         if( 'on' != getParam('ext_nav_menu_enabled') ) { 
    601             update_date_lastnav($ID); 
    602         } 
    603  
     316    if (isAdmin($aAccountInfo['id'])) 
    604317        return true; 
    605     } 
    606318 
    607319    // if IP is banned 
    608320    if ((2 == getParam('ipBlacklistMode') && bx_is_ip_blocked()) || ('on' == getParam('sys_dnsbl_enable') && bx_is_ip_dns_blacklisted('', 'login'))) { 
    609         if ($error_handle) { 
     321        if ($bHandleError) { 
    610322                bx_import('BxDolTemplate'); 
    611323                $oTemplate = BxDolTemplate::getInstance(); 
     
    618330 
    619331    // if profile is banned 
    620     if (isLoggedBanned($aProfile['ID'])) { 
    621         if ($error_handle) { 
     332    if (isLoggedBanned($aAccountInfo['id'])) { 
     333        if ($bHandleError) { 
    622334            bx_import('BxDolTemplate'); 
    623335            $oTemplate = BxDolTemplate::getInstance(); 
     
    629341    } 
    630342 
    631     if( 'on' != getParam('ext_nav_menu_enabled') ) { 
    632         update_date_lastnav($ID); 
    633     } 
    634  
    635343    return true; 
    636344} 
     
    639347 * check unencrypted password 
    640348 */ 
    641 function check_password($sUsername, $sPassword, $iRole = BX_DOL_ROLE_MEMBER, $error_handle = true) { 
    642     $iId = getID($sUsername); 
    643     if (!$iId) return false; 
    644  
    645     $aUser = getProfileInfo($iId); 
    646     $sPassCheck = encryptUserPwd($sPassword, $aUser['Salt']); 
    647  
    648     return check_login($iId, $sPassCheck, $iRole, $error_handle); 
     349function check_password($sLogin, $sPassword, $iRole = BX_DOL_ROLE_MEMBER, $bHandleError = true) { 
     350 
     351    bx_import('BxDolAccount'); 
     352    $oAccount = BxDolAccount::getInstance($sLogin); 
     353    if (!$oAccount)  
     354        return false; 
     355 
     356    $aAccountInfo = $oAccount->getInfo(); 
     357 
     358    $sPassCheck = encryptUserPwd($sPassword, $aAccountInfo['salt']); 
     359 
     360    return check_login($aAccountInfo['id'], $sPassCheck, $iRole, $bHandleError); 
    649361} 
    650362 
     
    691403    $sEmail = BxDolProfileQuery::getInstance()->getEmail($ID); 
    692404    if (!$sEmail) { 
    693         echo 'aaa' . $sEmail; 
    694405        $ret['ErrorCode'] = 7; 
    695406        return false; 
     
    731442} 
    732443 
    733 function get_user_online_status ($ID) { 
    734     $iOnline = 0; 
    735     if ($ID && is_numeric($ID) ) { 
    736         $aMemberInfo  = getProfileInfo($ID); 
    737         // check user status; 
    738         if ($aMemberInfo['UserStatus'] != 'offline') { 
    739             $oDb = BxDolDb::getInstance(); 
    740             $min = getParam("member_online_time"); 
    741             $sQuery = $oDb->prepare("SELECT count(ID) as count_id FROM Profiles WHERE DateLastNav > SUBDATE(NOW(), INTERVAL ? MINUTE) AND ID=?", $min, $ID); 
    742             $iOnline = $oDb->fromMemory ("member_online_status.$ID.$min", 'getOne', $sQuery); 
    743         } 
    744     } 
    745     return $iOnline; 
    746 } 
    747  
    748444 
    749445/** 
  • trunk/inc/utils.inc.php

    r15682 r15698  
    123123} 
    124124 
    125 /* 
    126  * functions for limiting maximal word length (returned from ash). 
    127  */ 
    128 function WordWrapStr($input, $len = 35) { 
    129     $output = wordwrap($input, $len, " ", true); 
    130     return $output; 
    131 } 
    132125 
    133126/* 
     
    331324} 
    332325 
    333 function process_textarea_output( $text, $maxwordlen = 100 ) { 
    334     return htmlspecialchars_adv( strmaxwordlen( $text, $maxwordlen ) ); 
    335 } 
    336  
    337326function process_text_withlinks_output( $text, $maxwordlen = 100 ) { 
    338327    return nl2br( html_encode( htmlspecialchars_adv( strmaxwordlen( $text, $maxwordlen ) ) ) ); 
     
    13731362} 
    13741363 
     1364/** 
     1365 * Raise an alert 
     1366 * @param string $sType - system type 
     1367 * @param string $sAction - system action 
     1368 * @param int $iObjectId - object id 
     1369 * @param int $iSenderId - sender (action's author) id 
     1370 */ 
     1371function bx_alert($sUnit, $sAction, $iObjectId, $iSender = 0, $aExtras = array()) { 
     1372    $o = new BxDolAlerts($sUnit, $sAction, $iObjectId, $iSender, $aExtras); 
     1373    $o->alert(); 
     1374} 
     1375 
    13751376function getSitesArray ($sLink) { 
    13761377 
Note: See TracChangeset for help on using the changeset viewer.