Overview

Packages

  • Core
    • Authentication
    • Backend
    • Cache
    • CEC
    • Chain
    • ContentType
    • Database
    • Datatype
    • Debug
    • Exception
    • Frontend
      • Search
      • URI
      • Util
    • GenericDB
      • Model
    • GUI
      • HTML
    • I18N
    • LayoutHandler
    • Log
    • Security
    • Session
    • Util
    • Validation
    • Versioning
    • XML
  • Module
    • ContentSitemapHtml
    • ContentSitemapXml
    • ContentUserForum
    • NavigationMain
    • NavigationTop
  • mpAutoloaderClassMap
  • None
  • Plugin
    • ContentAllocation
    • CronjobOverview
    • FormAssistant
    • FrontendLogic
    • FrontendUsers
    • Linkchecker
    • ModRewrite
    • Newsletter
    • Repository
      • FrontendNavigation
      • KeywordDensity
    • SearchSolr
    • SmartyWrapper
    • UrlShortener
    • UserForum
    • Workflow
  • PluginManager
  • Setup
    • Form
    • GUI
    • Helper
      • Environment
      • Filesystem
      • MySQL
      • PHP
    • UpgradeJob

Classes

  • cApiAction
  • cApiActionCollection
  • cApiActionlog
  • cApiActionlogCollection
  • cApiArea
  • cApiAreaCollection
  • cApiArticle
  • cApiArticleCollection
  • cApiArticleLanguage
  • cApiArticleLanguageCollection
  • cApiArticleSpecification
  • cApiArticleSpecificationCollection
  • cApiCategory
  • cApiCategoryArticle
  • cApiCategoryArticleCollection
  • cApiCategoryCollection
  • cApiCategoryLanguage
  • cApiCategoryLanguageCollection
  • cApiCategoryTree
  • cApiCategoryTreeCollection
  • cApiClient
  • cApiClientCollection
  • cApiClientLanguage
  • cApiClientLanguageCollection
  • cApiCommunication
  • cApiCommunicationCollection
  • cApiContainer
  • cApiContainerCollection
  • cApiContainerConfiguration
  • cApiContainerConfigurationCollection
  • cApiContent
  • cApiContentCollection
  • cApiDbfs
  • cApiDbfsCollection
  • cApiFile
  • cApiFileCollection
  • cApiFileInformation
  • cApiFileInformationCollection
  • cApiFrameFile
  • cApiFrameFileCollection
  • cApiFrontendGroup
  • cApiFrontendGroupCollection
  • cApiFrontendGroupMember
  • cApiFrontendGroupMemberCollection
  • cApiFrontendPermission
  • cApiFrontendPermissionCollection
  • cApiFrontendUser
  • cApiFrontendUserCollection
  • cApiGroup
  • cApiGroupCollection
  • cApiGroupMember
  • cApiGroupMemberCollection
  • cApiGroupProperty
  • cApiGroupPropertyCollection
  • cApiInUse
  • cApiInUseCollection
  • cApiIso3166
  • cApiIso3166Collection
  • cApiIso6392
  • cApiIso6392Collection
  • cApiKeyword
  • cApiKeywordCollection
  • cApiLanguage
  • cApiLanguageCollection
  • cApiLayout
  • cApiLayoutCollection
  • cApiMailLog
  • cApiMailLogCollection
  • cApiMailLogSuccess
  • cApiMailLogSuccessCollection
  • cApiMetaTag
  • cApiMetaTagCollection
  • cApiMetaType
  • cApiMetaTypeCollection
  • cApiModule
  • cApiModuleCollection
  • cApiNavMain
  • cApiNavMainCollection
  • cApiNavSub
  • cApiNavSubCollection
  • cApiOnlineUser
  • cApiOnlineUserCollection
  • cApiPathresolveCache
  • cApiPathresolveCacheCollection
  • cApiProperty
  • cApiPropertyCollection
  • cApiRight
  • cApiRightCollection
  • cApiStat
  • cApiStatCollection
  • cApiSystemProperty
  • cApiSystemPropertyCollection
  • cApiTemplate
  • cApiTemplateCollection
  • cApiTemplateConfiguration
  • cApiTemplateConfigurationCollection
  • cApiType
  • cApiTypeCollection
  • cApiUpload
  • cApiUploadCollection
  • cApiUploadMeta
  • cApiUploadMetaCollection
  • cApiUser
  • cApiUserCollection
  • cApiUserProperty
  • cApiUserPropertyCollection
  • NoteCollection
  • NoteItem
  • TODOCollection
  • TODOItem
  • Overview
  • Package
  • Class
  • Tree
  • Deprecated
  • Todo
  1: <?php
  2: /**
  3:  * This file contains the online user collection and item class.
  4:  *
  5:  * @package          Core
  6:  * @subpackage       GenericDB_Model
  7:  * @version          SVN Revision $Rev:$
  8:  *
  9:  * @author           Murat Purc <murat@purc.de>
 10:  * @copyright        four for business AG <www.4fb.de>
 11:  * @license          http://www.contenido.org/license/LIZENZ.txt
 12:  * @link             http://www.4fb.de
 13:  * @link             http://www.contenido.org
 14:  */
 15: 
 16: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
 17: 
 18: /**
 19:  * Online user collection
 20:  *
 21:  * @package Core
 22:  * @subpackage GenericDB_Model
 23:  */
 24: class cApiOnlineUserCollection extends ItemCollection {
 25: 
 26:     /**
 27:      * Constructor function.
 28:      *
 29:      * @param string $select Select statement (see ItemCollection::select())
 30:      */
 31:     public function __construct($select = false) {
 32:         global $cfg;
 33:         parent::__construct($cfg['tab']['online_user'], 'user_id');
 34:         $this->_setItemClass('cApiOnlineUser');
 35:         if ($select !== false) {
 36:             $this->select($select);
 37:         }
 38:     }
 39: 
 40:     /**
 41:      * Start the User Tracking:
 42:      * 1) First delete all inactive users with timelimit is off
 43:      * 2) If find user in the table, do update
 44:      * 3) Else there is no current user do insert new user
 45:      *
 46:      * @param string $userId Id of user
 47:      */
 48:     public function startUsersTracking($userId = null) {
 49:         global $auth;
 50: 
 51:         $userId = (string) $userId;
 52:         if (empty($userId)) {
 53:             $userId = $auth->auth['uid'];
 54:         }
 55: 
 56:         // Delete all entries being older than defined timeout
 57:         $this->deleteInactiveUser();
 58: 
 59:         $bResult = $this->findUser($userId);
 60:         if ($bResult) {
 61:             // Update the curent user
 62:             $this->updateUser($userId);
 63:         } else {
 64:             // User not found, we can insert the new user
 65:             $this->insertOnlineUser($userId);
 66:         }
 67:     }
 68: 
 69:     /**
 70:      * Insert this user in online_user table
 71:      *
 72:      * @param string $userId Id of user
 73:      * @return bool Returns true if successful else false
 74:      */
 75:     public function insertOnlineUser($userId) {
 76:         $oItem = parent::createNewItem((string) $userId);
 77:         if ($oItem) {
 78:             $created = date('Y-m-d H:i:s');
 79:             $oItem->set('lastaccessed', $created);
 80:             $oItem->store();
 81:         }
 82:         return ($oItem)? true : false;
 83:     }
 84: 
 85:     /**
 86:      * Find the this user if exists in the table 'online_user'
 87:      *
 88:      * @param string $userId Is the User-Id (get from auth object)
 89:      * @return bool Returns true if this User is found, else false
 90:      */
 91:     public function findUser($userId) {
 92:         $oUser = new cApiOnlineUser((string) $userId);
 93:         return ($oUser->isLoaded());
 94:     }
 95: 
 96:     /**
 97:      * Find all user_ids in the table 'online_user' for get rest information
 98:      * from
 99:      * table 'con_user'
100:      *
101:      * @return array Returns array of user-information
102:      */
103:     public function findAllUser() {
104:         // todo use $perm
105:         $aAllUser = array();
106:         $aUser = array();
107:         $sClientName = '';
108: 
109:         // get all user_ids
110:         $this->select();
111:         while (($oItem = $this->next()) !== false) {
112:             $aUser[] = $oItem->get('user_id');
113:         }
114: 
115:         $oClientColl = new cApiClientCollection();
116: 
117:         // get data of those users
118:         $where = "user_id IN ('" . implode("', '", $aUser) . "')";
119:         $oUserColl = new cApiUserCollection();
120:         $oUserColl->select($where);
121:         while (($oItem = $oUserColl->next()) !== false) {
122:             $sClientNames = '';
123:             $userId = $oItem->get('user_id');
124:             $aAllUser[$userId]['realname'] = $oItem->get('realname');
125:             $aAllUser[$userId]['username'] = $oItem->get('username');
126:             $aPerms = explode(',', $oItem->get('perms'));
127: 
128:             if (in_array('sysadmin', $aPerms)) {
129:                 $aAllUser[$userId]['perms'] = 'Systemadministrator';
130:             } else {
131:                 $bIsAdmin = false;
132:                 $iCounter = 0;
133:                 foreach ($aPerms as $sPerm) {
134:                     $aResults = array();
135:                     if (preg_match('/^admin\[(\d+)\]$/', $sPerm, $aResults)) {
136:                         $iClientId = $aResults[1];
137:                         $bIsAdmin = true;
138:                         $sClientName = $oClientColl->getClientname((int) $iClientId);
139:                         if ($iCounter == 0 && $sClientName != '') {
140:                             $sClientNames .= $sClientName;
141:                         } elseif ($sClientName != '') {
142:                             $sClientNames .= ', ' . $sClientName;
143:                         }
144: 
145:                         $aAllUser[$userId]['perms'] = 'Administrator (' . $sClientNames . ')';
146:                         $iCounter++;
147:                     } elseif (preg_match('/^client\[(\d+)\]$/', $sPerm, $aResults) && !$bIsAdmin) {
148:                         $iClientId = $aResults[1];
149:                         $sClientName = $oClientColl->getClientname((int) $iClientId);
150:                         if ($iCounter == 0 && $sClientName != '') {
151:                             $sClientNames .= $sClientName;
152:                         } elseif ($sClientName != '') {
153:                             $sClientNames .= ', ' . $sClientName;
154:                         }
155: 
156:                         $aAllUser[$userId]['perms'] = '(' . $sClientNames . ')';
157:                         $iCounter++;
158:                     }
159:                 }
160:             }
161:         }
162: 
163:         return $aAllUser;
164:     }
165: 
166:     /**
167:      * This function do an update of current timestamp in 'online_user'
168:      *
169:      * @param string $userId Is the User-Id (get from auth object)
170:      * @return bool Returns true if successful, else false
171:      */
172:     public function updateUser($userId) {
173:         $oUser = new cApiOnlineUser((string) $userId);
174:         if ($oUser->isLoaded()) {
175:             $now = date('Y-m-d H:i:s');
176:             $oUser->set('lastaccessed', $now);
177:             return $oUser->store();
178:         }
179:         return false;
180:     }
181: 
182:     /**
183:      * Delete all Contains in the table 'online_user' that is older as
184:      * Backend timeout(currently is $cfg['backend']['timeout'] = 60)
185:      *
186:      * @return bool Returns true if successful else false
187:      */
188:     public function deleteInactiveUser() {
189:         global $cfg;
190:         include_once ($cfg['path']['contenido_config'] . 'config.misc.php');
191:         $iSetTimeOut = (int) $cfg['backend']['timeout'];
192:         if ($iSetTimeOut <= 0) {
193:             $iSetTimeOut = 10;
194:         }
195: 
196:         // NOTE: We could delete outdated entries with one query, but deleteing
197:         // one by one
198:         // gives us the possibility to hook (CEC) into each deleted entry.
199:         $where = "DATE_SUB(NOW(), INTERVAL '$iSetTimeOut' Minute) >= `lastaccessed`";
200:         $result = $this->deleteByWhereClause($where);
201:         return ($result > 0)? true : false;
202:     }
203: 
204:     /**
205:      * Get the number of users from the table 'online_user'
206:      *
207:      * @return int Returns if exists a number of users
208:      */
209:     public function getNumberOfUsers() {
210:         $sql = 'SELECT COUNT(*) AS cnt FROM `%s`';
211:         $result = $this->db->query($sql, $this->table);
212:         $this->_lastSQL = $sql;
213:         if ($result) {
214:             $this->db->nextRecord();
215:             return (int) $this->db->f('cnt');
216:         }
217:         return 0;
218:     }
219: 
220:     /**
221:      * Delete this user from 'online user' table
222:      *
223:      * @param string $userId Is the User-Id (get from auth object)
224:      * @return bool Returns true if successful, else false
225:      */
226:     public function deleteUser($userId) {
227:         return $this->delete((string) $userId);
228:     }
229: }
230: 
231: /**
232:  * Online user item
233:  *
234:  * @package Core
235:  * @subpackage GenericDB_Model
236:  */
237: class cApiOnlineUser extends Item {
238: 
239:     /**
240:      * Constructor function
241:      *
242:      * @param mixed $mId Specifies the ID of item to load
243:      */
244:     public function __construct($mId = false) {
245:         global $cfg;
246:         parent::__construct($cfg['tab']['online_user'], 'user_id');
247:         $this->setFilters(array(), array());
248:         if ($mId !== false) {
249:             $this->loadByPrimaryKey($mId);
250:         }
251:     }
252: 
253: }
254: 
CMS CONTENIDO 4.9.0 API documentation generated by ApiGen 2.8.0