Просмотр исходного кода

#53 - removing prof.inc.php, cleaning up design.inc.php and profiles.inc.php

Alex Trofimov 12 лет назад
Родитель
Сommit
cca24f7d7f
3 измененных файлов с 83 добавлено и 127 удалено
  1. 8 5
      inc/design.inc.php
  2. 0 79
      inc/prof.inc.php
  3. 75 43
      inc/profiles.inc.php

+ 8 - 5
inc/design.inc.php

@@ -1,10 +1,11 @@
-<?php
+<?php defined('BX_DOL') or defined('BX_DOL_INSTALL') or die('hack attempt');
 /**
- * @package     Dolphin Core
- * @copyright   Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
- * @license     CC-BY - http://creativecommons.org/licenses/by/3.0/
+ * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
+ * CC-BY License - http://creativecommons.org/licenses/by/3.0/
+ *
+ * @defgroup    DolphinCore Dolphin Core
+ * @{
  */
-defined('BX_DOL') or die('hack attempt');
 
 /**
  * design box with content only - no borders, no background, no caption
@@ -151,3 +152,5 @@ bx_import('BxDolAlerts');
 $oZ = new BxDolAlerts('system', 'design_included', 0);
 $oZ->alert();
 
+/** @} */ 
+

+ 0 - 79
inc/prof.inc.php

@@ -1,79 +0,0 @@
-<?php
-/**
- * @package     Dolphin Core
- * @copyright   Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
- * @license     CC-BY - http://creativecommons.org/licenses/by/3.0/
- */
-defined('BX_DOL') or die('hack attempt');
-
-define('BX_SYS_PRE_VALUES_TABLE', 'sys_pre_values');
-
-
-$oCache = BxDolDb::getInstance()->getDbCacheObject();
-$GLOBALS['aPreValues'] = $oCache->getData(BxDolDb::getInstance()->genDbCacheKey('sys_pre_values'));
-if (null === $GLOBALS['aPreValues'])
-    compilePreValues();
-
-
-function getPreKeys () {
-    return BxDolDb::getInstance()->fromCache('sys_prevalues_keys', 'getAll', "SELECT DISTINCT `Key` FROM `" . BX_SYS_PRE_VALUES_TABLE . "`");
-}
-
-function getPreValues ($sKey, $aFields = array()) {
-    $sFields = "*";
-    if (is_array($aFields) && !empty($aFields)) {
-        foreach ($aFields as $sValue)
-            $sFields .= "`$sValue`, ";
-        $sFields = trim($sFields, ', ');
-    }
-
-    $oDb = BxDolDb::getInstance();
-    $sQuery = $oDb->prepare("SELECT $sFields FROM `" . BX_SYS_PRE_VALUES_TABLE ."`
-                WHERE `Key` = ?
-                ORDER BY `Order` ASC", $sKey);
-    return $oDb->getAllWithKey($sQuery, 'Value');
-}
-
-function getPreValuesCount ($sKey) {
-    $oDb = BxDolDb::getInstance();
-    $sQuery = $oDb->prepare("SELECT COUNT(*) FROM `" . BX_SYS_PRE_VALUES_TABLE . "` WHERE `Key` = ?", $sKey);
-    return $oDb->getOne($sQuery);
-}
-
-function compilePreValues() {
-
-    BxDolDb::getInstance()->cleanCache('sys_prevalues_keys');
-
-    $aPreValues = array ();
-    $aKeys = getPreKeys();
-
-    foreach ($aKeys as $aKey) {
-
-        $sKey = $aKey['Key'];
-        $aPreValues[$sKey] = array ();
-
-        $aRows = getPreValues($sKey);
-        foreach ($aRows as $aRow) {
-
-            $aPreValues[$sKey][$aRow['Value']] = array ();
-
-            foreach ($aRow as $sValKey => $sValue) {
-                if ($sValKey == 'Key' or $sValKey == 'Value' or $sValKey == 'Order')
-                    continue; //skip key, value and order. they already used
-
-                if (!strlen($sValue))
-                    continue; //skip empty values
-
-                $aPreValues[$sKey][$aRow['Value']][$sValKey] = $sValue;
-            }
-
-        }
-
-    }
-
-    $oCache = BxDolDb::getInstance()->getDbCacheObject();
-    $oCache->setData (BxDolDb::getInstance()->genDbCacheKey('sys_pre_values'), $aPreValues);
-
-    $GLOBALS['aPreValues'] = $aPreValues;
-}
-

+ 75 - 43
inc/profiles.inc.php

@@ -1,44 +1,60 @@
-<?php
+<?php defined('BX_DOL') or defined('BX_DOL_INSTALL') or die('hack attempt');
 /**
- * @package     Dolphin Core
- * @copyright   Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
- * @license     CC-BY - http://creativecommons.org/licenses/by/3.0/
+ * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
+ * CC-BY License - http://creativecommons.org/licenses/by/3.0/
+ *
+ * @defgroup    DolphinCore Dolphin Core
+ * @{
  */
-defined('BX_DOL') or die('hack attempt');
 
 /**
- * It is needed to check whether user is logged in or not
+ * @return corrently logged in profile id
  */
-function isLogged() {
+function bx_get_logged_profile_id () 
+{
+    bx_import('BxDolProfile');
+    $o = BxDolProfile::getInstance();
+    return $o ? $o->id() : false;
+}
+
+/**
+ * @return true if user is logged in
+ */
+function isLogged() 
+{
     return getLoggedId() != 0;
 }
 
 /**
- * It returns logged in account id
+ * @return logged in account id
  */
-function getLoggedId() {
+function getLoggedId() 
+{
     return isset($_COOKIE['memberID']) && (!empty($GLOBALS['logged']['member']) || !empty($GLOBALS['logged']['admin'])) ? (int)$_COOKIE['memberID'] : 0;
 }
 
 /**
- * It returns logged in account password
+ * @return logged in account password
  */
-function getLoggedPassword() {
+function getLoggedPassword() 
+{
     return isset($_COOKIE['memberPassword']) && ($GLOBALS['logged']['member'] || $GLOBALS['logged']['admin']) ? $_COOKIE['memberPassword'] : '';
 }
 
 /**
- * It checks if account is member.
+ * It checks if account role is member.
  */
-function isMember($iId = 0) {
+function isMember($iId = 0) 
+{
     return isRole(BX_DOL_ROLE_MEMBER, $iId);
 }
 
 if (!function_exists("isAdmin")) {
     /**
-     * It checks if account is admin.
+     * @return true if account is admin
      */
-    function isAdmin($iId = 0) {
+    function isAdmin($iId = 0) 
+    {
         if (!$iId && isset($GLOBALS['logged']['admin']) && $GLOBALS['logged']['admin']) // easier check for currently logged in user
             return true;
         return isRole(BX_DOL_ROLE_ADMIN, $iId);
@@ -46,10 +62,13 @@ if (!function_exists("isAdmin")) {
 }
 
 /**
- * It checks account's role
+ * Check user role
+ * @param $iRole role to check user for
+ * @param $iId optional account id, if it isn't specified then curently logged in account is used
+ * @return true if user is in the provided role
  */
-function isRole($iRole, $iId = 0) {
-
+function isRole($iRole, $iId = 0) 
+{
     if (!(int)$iId)
         $iId = getLoggedId();
 
@@ -69,7 +88,13 @@ function isRole($iRole, $iId = 0) {
     return true;
 }
 
-function bx_login($iId, $bRememberMe = false) {
+/**
+ * Login user by setting necessary cookies
+ * @param $iId account id
+ * @return false if id isn't correct or array of user info if user was logged in
+ */
+function bx_login($iId, $bRememberMe = false) 
+{
     bx_import('BxDolAccountQuery');
     $oAccountQuery = BxDolAccountQuery::getInstance();
 
@@ -96,7 +121,11 @@ function bx_login($iId, $bRememberMe = false) {
     return $oAccountQuery->getInfoById($iId);
 }
 
-function bx_logout($bNotify = true) {
+/**
+ * Logout user by removing cookies
+ */
+function bx_logout($bNotify = true) 
+{
     if ($bNotify && isMember())
         bx_alert('account', 'logout', (int)$_COOKIE['memberID']);
 
@@ -113,14 +142,16 @@ function bx_logout($bNotify = true) {
 	BxDolSession::getInstance()->destroy();
 }
 
-function check_logged() {
-
+/**
+ * Check if user is logged in (necessary cookies are present) and set some global variables
+ */
+function check_logged() 
+{
     $aAccTypes = array(
        BX_DOL_ROLE_ADMIN => 'admin',
        BX_DOL_ROLE_MEMBER => 'member'
     );
 
-
     $sID = isset($_COOKIE['memberID']) ? bx_process_input($_COOKIE['memberID']) : false;
     $sPassword = isset($_COOKIE['memberPassword']) ? bx_process_input($_COOKIE['memberPassword']) : false;
 
@@ -138,11 +169,11 @@ function check_logged() {
 
 
 /**
- * check unencrypted password
+ * Check unencrypted password
  * @return empty string on success or error string on error
  */
-function bx_check_password($sLogin, $sPassword, $iRole = BX_DOL_ROLE_MEMBER) {
-
+function bx_check_password($sLogin, $sPassword, $iRole = BX_DOL_ROLE_MEMBER) 
+{
     bx_import('BxDolAccount');
     $oAccount = BxDolAccount::getInstance($sLogin);        
     if (!$oAccount) {
@@ -168,11 +199,11 @@ function bx_check_password($sLogin, $sPassword, $iRole = BX_DOL_ROLE_MEMBER) {
 
 
 /**
- * check encrypted password (ex., from Cookie)
+ * Check encrypted password (ex., from Cookie)
  * @return empty string on success or error string on error
  */
-function bx_check_login($iID, $sPassword, $iRole = BX_DOL_ROLE_MEMBER) {
-
+function bx_check_login($iID, $sPassword, $iRole = BX_DOL_ROLE_MEMBER) 
+{
     bx_import('BxDolAccount');
     $oAccount = BxDolAccount::getInstance((int)$iID);
 
@@ -199,8 +230,12 @@ function bx_check_login($iID, $sPassword, $iRole = BX_DOL_ROLE_MEMBER) {
     return '';
 }
 
-function bx_require_authentication ($bStudio = false) {
-
+/**
+ * Declare that content is require user authoriztion and display login form if user isn't logged in
+ * @param $bStudio require webmaster authorization
+ */
+function bx_require_authentication ($bStudio = false) 
+{
     $iRole = BX_DOL_ROLE_MEMBER;
     if ($bStudio)
         $iRole = BX_DOL_ROLE_ADMIN;
@@ -217,8 +252,13 @@ function bx_require_authentication ($bStudio = false) {
 
 
 
-function bx_login_form($bStudio = false, $bAjaxMode = false) {
-
+/**
+ * Display login form and exit
+ * @param $bStudio display login form for studio
+ * @param $bAjaxMode login form displayed via AJAX
+ */
+function bx_login_form($bStudio = false, $bAjaxMode = false) 
+{
     if ($bStudio == 1) {
         bx_import("BxTemplStudioFunctions");
         BxTemplStudioFunctions::getInstance()->getLoginForm();
@@ -240,15 +280,7 @@ function bx_login_form($bStudio = false, $bAjaxMode = false) {
     exit;
 }
 
-
-/**
- * get corrently logged in profile id
- */
-function bx_get_logged_profile_id () {
-    bx_import('BxDolProfile');
-    $o = BxDolProfile::getInstance();
-    return $o ? $o->id() : false;
-}
-
 check_logged();
 
+/** @} */ 
+