Overview

Packages

  • CONTENIDO
  • Core
    • Authentication
    • Backend
    • Cache
    • CEC
    • Chain
    • ContentType
    • Database
    • Debug
    • Exception
    • Frontend
      • Search
      • URI
      • Util
    • GenericDB
      • Model
    • GUI
      • HTML
    • I18N
    • LayoutHandler
    • Log
    • Security
    • Session
    • Util
    • Validation
    • Versioning
    • XML
  • Module
    • ContentRssCreator
    • ContentSitemapHtml
    • ContentSitemapXml
    • ContentUserForum
    • NavigationTop
    • ScriptCookieDirective
  • 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
  • cApiArticleLanguageVersion
  • cApiArticleLanguageVersionCollection
  • cApiArticleSpecification
  • cApiArticleSpecificationCollection
  • cApiCategory
  • cApiCategoryArticle
  • cApiCategoryArticleCollection
  • cApiCategoryCollection
  • cApiCategoryLanguage
  • cApiCategoryLanguageCollection
  • cApiCategoryTree
  • cApiCategoryTreeCollection
  • cApiClient
  • cApiClientCollection
  • cApiClientLanguage
  • cApiClientLanguageCollection
  • cApiCommunication
  • cApiCommunicationCollection
  • cApiContainer
  • cApiContainerCollection
  • cApiContainerConfiguration
  • cApiContainerConfigurationCollection
  • cApiContent
  • cApiContentCollection
  • cApiContentVersion
  • cApiContentVersionCollection
  • 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
  • cApiMetaTagVersion
  • cApiMetaTagVersionCollection
  • cApiMetaType
  • cApiMetaTypeCollection
  • cApiModule
  • cApiModuleCollection
  • cApiNavMain
  • cApiNavMainCollection
  • cApiNavSub
  • cApiNavSubCollection
  • cApiOnlineUser
  • cApiOnlineUserCollection
  • cApiPathresolveCache
  • cApiPathresolveCacheCollection
  • cApiProperty
  • cApiPropertyCollection
  • cApiRight
  • cApiRightCollection
  • cApiSearchTracking
  • cApiSearchTrackingCollection
  • cApiStat
  • cApiStatCollection
  • cApiSystemProperty
  • cApiSystemPropertyCollection
  • cApiTemplate
  • cApiTemplateCollection
  • cApiTemplateConfiguration
  • cApiTemplateConfigurationCollection
  • cApiType
  • cApiTypeCollection
  • cApiUpload
  • cApiUploadCollection
  • cApiUploadMeta
  • cApiUploadMetaCollection
  • cApiUser
  • cApiUserCollection
  • cApiUserPasswordRequest
  • cApiUserPasswordRequestCollection
  • cApiUserProperty
  • cApiUserPropertyCollection
  • NoteCollection
  • NoteItem
  • TODOCollection
  • TODOItem
  • Overview
  • Package
  • Class
  • Tree
  • Deprecated
  • Todo
  1: <?php
  2: 
  3: /**
  4:  * This file contains the online user collection and item class.
  5:  *
  6:  * @package Core
  7:  * @subpackage GenericDB_Model
  8:  * @author Murat Purc <murat@purc.de>
  9:  * @copyright four for business AG <www.4fb.de>
 10:  * @license http://www.contenido.org/license/LIZENZ.txt
 11:  * @link http://www.4fb.de
 12:  * @link http://www.contenido.org
 13:  */
 14: 
 15: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
 16: 
 17: /**
 18:  * Online user collection
 19:  *
 20:  * @package Core
 21:  * @subpackage GenericDB_Model
 22:  */
 23: class cApiOnlineUserCollection extends ItemCollection {
 24: 
 25:     /**
 26:      * Constructor to create an instance of this class.
 27:      *
 28:      * @param string $select [optional]
 29:      *         where clause to use for selection (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 [optional]
 47:      *         Id of user
 48:      */
 49:     public function startUsersTracking($userId = NULL) {
 50:         global $auth;
 51: 
 52:         $userId = (string) $userId;
 53:         if (empty($userId)) {
 54:             $userId = $auth->auth['uid'];
 55:         }
 56: 
 57:         // Delete all entries being older than defined timeout
 58:         $this->deleteInactiveUser();
 59: 
 60:         $bResult = $this->findUser($userId);
 61:         if ($bResult) {
 62:             // Update the curent user
 63:             $this->updateUser($userId);
 64:         } else {
 65:             // User not found, we can insert the new user
 66:             $this->insertOnlineUser($userId);
 67:         }
 68:     }
 69: 
 70:     /**
 71:      * Insert this user in online_user table
 72:      *
 73:      * @param string $userId
 74:      *         Id of user
 75:      * @return bool
 76:      *         Returns true if successful else false
 77:      */
 78:     public function insertOnlineUser($userId) {
 79:         $oItem = $this->createNewItem((string) $userId);
 80:         if ($oItem) {
 81:             $created = date('Y-m-d H:i:s');
 82:             $oItem->set('lastaccessed', $created);
 83:             $oItem->store();
 84:         }
 85:         return ($oItem) ? true : false;
 86:     }
 87: 
 88:     /**
 89:      * Find the this user if exists in the table 'online_user'
 90:      *
 91:      * @param string $userId
 92:      *         Is the User-Id (get from auth object)
 93:      * @return bool
 94:      *         Returns true if this User is found, else false
 95:      */
 96:     public function findUser($userId) {
 97:         $oUser = new cApiOnlineUser((string) $userId);
 98:         return $oUser->isLoaded();
 99:     }
100: 
101:     /**
102:      * Find all user_ids in the table 'online_user' for get rest information
103:      * from table 'con_user'
104:      *
105:      * @return array
106:      *         Returns array of user-information
107:      */
108:     public function findAllUser() {
109:         // todo use $perm
110:         $aAllUser = array();
111:         $aUser = array();
112:         $sClientName = '';
113: 
114:         // get all user_ids
115:         $this->select();
116:         while (($oItem = $this->next()) !== false) {
117:             $aUser[] = $oItem->get('user_id');
118:         }
119: 
120:         $oClientColl = new cApiClientCollection();
121: 
122:         // get data of those users
123:         $where = "user_id IN ('" . implode("', '", $aUser) . "')";
124:         $oUserColl = new cApiUserCollection();
125:         $oUserColl->select($where);
126:         while (($oItem = $oUserColl->next()) !== false) {
127:             $sClientNames = '';
128:             $userId = $oItem->get('user_id');
129:             $aAllUser[$userId]['realname'] = $oItem->get('realname');
130:             $aAllUser[$userId]['username'] = $oItem->get('username');
131:             $aPerms = explode(',', $oItem->get('perms'));
132: 
133:             if (in_array('sysadmin', $aPerms)) {
134:                 $aAllUser[$userId]['perms'] = 'Systemadministrator';
135:             } else {
136:                 $bIsAdmin = false;
137:                 $iCounter = 0;
138:                 foreach ($aPerms as $sPerm) {
139:                     $aResults = array();
140:                     if (preg_match('/^admin\[(\d+)\]$/', $sPerm, $aResults)) {
141:                         $iClientId = $aResults[1];
142:                         $bIsAdmin = true;
143:                         $sClientName = $oClientColl->getClientname((int) $iClientId);
144:                         if ($iCounter == 0 && $sClientName != '') {
145:                             $sClientNames .= $sClientName;
146:                         } elseif ($sClientName != '') {
147:                             $sClientNames .= ', ' . $sClientName;
148:                         }
149: 
150:                         $aAllUser[$userId]['perms'] = 'Administrator (' . $sClientNames . ')';
151:                         $iCounter++;
152:                     } elseif (preg_match('/^client\[(\d+)\]$/', $sPerm, $aResults) && !$bIsAdmin) {
153:                         $iClientId = $aResults[1];
154:                         $sClientName = $oClientColl->getClientname((int) $iClientId);
155:                         if ($iCounter == 0 && $sClientName != '') {
156:                             $sClientNames .= $sClientName;
157:                         } elseif ($sClientName != '') {
158:                             $sClientNames .= ', ' . $sClientName;
159:                         }
160: 
161:                         $aAllUser[$userId]['perms'] = '(' . $sClientNames . ')';
162:                         $iCounter++;
163:                     }
164:                 }
165:             }
166:         }
167: 
168:         return $aAllUser;
169:     }
170: 
171:     /**
172:      * This function do an update of current timestamp in 'online_user'
173:      *
174:      * @param string $userId
175:      *         Is the User-Id (get from auth object)
176:      * @return bool
177:      *         Returns true if successful, else false
178:      */
179:     public function updateUser($userId) {
180:         $oUser = new cApiOnlineUser((string) $userId);
181:         if ($oUser->isLoaded()) {
182:             $now = date('Y-m-d H:i:s');
183:             $oUser->set('lastaccessed', $now);
184:             return $oUser->store();
185:         }
186:         return false;
187:     }
188: 
189:     /**
190:      * Delete all Contains in the table 'online_user' that is older as
191:      * Backend timeout(currently is $cfg['backend']['timeout'] = 60)
192:      *
193:      * @return bool
194:      *         Returns true if successful else false
195:      */
196:     public function deleteInactiveUser() {
197:         global $cfg;
198:         include_once($cfg['path']['contenido_config'] . 'config.misc.php');
199:         $iSetTimeOut = (int) $cfg['backend']['timeout'];
200:         if ($iSetTimeOut <= 0) {
201:             $iSetTimeOut = 10;
202:         }
203: 
204:         // NOTE: We could delete outdated entries with one query, but deleteing
205:         // one by one
206:         // gives us the possibility to hook (CEC) into each deleted entry.
207:         $where = "DATE_SUB(NOW(), INTERVAL '$iSetTimeOut' Minute) >= `lastaccessed`";
208:         $result = $this->deleteByWhereClause($where);
209:         return ($result > 0) ? true : false;
210:     }
211: 
212:     /**
213:      * Get the number of users from the table 'online_user'
214:      *
215:      * @return int
216:      *         Returns if exists a number of users
217:      */
218:     public function getNumberOfUsers() {
219:         $sql = 'SELECT COUNT(*) AS cnt FROM `%s`';
220:         $result = $this->db->query($sql, $this->table);
221:         $this->_lastSQL = $sql;
222:         if ($result) {
223:             $this->db->nextRecord();
224:             return (int) $this->db->f('cnt');
225:         }
226:         return 0;
227:     }
228: 
229:     /**
230:      * Delete this user from 'online user' table
231:      *
232:      * @param string $userId
233:      *         Is the User-Id (get from auth object)
234:      * @return bool
235:      *         Returns true if successful, else false
236:      */
237:     public function deleteUser($userId) {
238:         return $this->delete((string) $userId);
239:     }
240: }
241: 
242: /**
243:  * Online user item
244:  *
245:  * @package Core
246:  * @subpackage GenericDB_Model
247:  */
248: class cApiOnlineUser extends Item {
249: 
250:     /**
251:      * Constructor to create an instance of this class.
252:      *
253:      * @param mixed $mId [optional]
254:      *         Specifies the ID of item to load
255:      */
256:     public function __construct($mId = false) {
257:         global $cfg;
258:         parent::__construct($cfg['tab']['online_user'], 'user_id');
259:         $this->setFilters(array(), array());
260:         if ($mId !== false) {
261:             $this->loadByPrimaryKey($mId);
262:         }
263:     }
264: }
265: 
CMS CONTENIDO 4.9.11 API documentation generated by ApiGen 2.8.0