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
  • Smarty
    • Cacher
    • Compiler
    • Config
    • Debug
    • PluginsBlock
    • PluginsFilter
    • PluginsFunction
    • PluginsInternal
    • PluginsModifier
    • PluginsModifierCompiler
    • PluginsShared
    • Security
    • Template
    • TemplateResources
  • Swift
    • ByteStream
    • CharacterStream
    • Encoder
    • Events
    • KeyCache
    • Mailer
    • Mime
    • Plugins
    • Transport

Classes

  • Swift_FailoverTransport
  • Swift_LoadBalancedTransport
  • Swift_MailTransport
  • Swift_Plugins_Loggers_ArrayLogger
  • Swift_Plugins_Loggers_EchoLogger
  • Swift_SendmailTransport
  • Swift_SmtpTransport
  • Swift_Transport_AbstractSmtpTransport
  • Swift_Transport_Esmtp_Auth_CramMd5Authenticator
  • Swift_Transport_Esmtp_Auth_LoginAuthenticator
  • Swift_Transport_Esmtp_Auth_PlainAuthenticator
  • Swift_Transport_Esmtp_AuthHandler
  • Swift_Transport_EsmtpTransport
  • Swift_Transport_FailoverTransport
  • Swift_Transport_LoadBalancedTransport
  • Swift_Transport_MailTransport
  • Swift_Transport_SendmailTransport
  • Swift_Transport_SimpleMailInvoker
  • Swift_Transport_StreamBuffer

Interfaces

  • Swift_Plugins_Logger
  • Swift_Plugins_Pop_Pop3Exception
  • Swift_Transport
  • Swift_Transport_Esmtp_Authenticator
  • Swift_Transport_EsmtpHandler
  • Swift_Transport_IoBuffer
  • Swift_Transport_MailInvoker
  • Swift_Transport_SmtpAgent
  • Swift_TransportException
  • Overview
  • Package
  • Function
  • Todo
  • Download
  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:      * Create a new collection of items.
 28:      *
 29:      * @param string $select where clause to use for selection (see
 30:      *        ItemCollection::select())
 31:      */
 32:     public function __construct($select = false) {
 33:         global $cfg;
 34:         parent::__construct($cfg['tab']['online_user'], 'user_id');
 35:         $this->_setItemClass('cApiOnlineUser');
 36:         if ($select !== false) {
 37:             $this->select($select);
 38:         }
 39:     }
 40: 
 41:     /**
 42:      * Start the User Tracking:
 43:      * 1) First delete all inactive users with timelimit is off
 44:      * 2) If find user in the table, do update
 45:      * 3) Else there is no current user do insert new user
 46:      *
 47:      * @param string $userId 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 Id of user
 74:      * @return bool Returns true if successful else false
 75:      */
 76:     public function insertOnlineUser($userId) {
 77:         $oItem = $this->createNewItem((string) $userId);
 78:         if ($oItem) {
 79:             $created = date('Y-m-d H:i:s');
 80:             $oItem->set('lastaccessed', $created);
 81:             $oItem->store();
 82:         }
 83:         return ($oItem) ? true : false;
 84:     }
 85: 
 86:     /**
 87:      * Find the this user if exists in the table 'online_user'
 88:      *
 89:      * @param string $userId Is the User-Id (get from auth object)
 90:      * @return bool Returns true if this User is found, else false
 91:      */
 92:     public function findUser($userId) {
 93:         $oUser = new cApiOnlineUser((string) $userId);
 94:         return ($oUser->isLoaded());
 95:     }
 96: 
 97:     /**
 98:      * Find all user_ids in the table 'online_user' for get rest information
 99:      * from
100:      * table 'con_user'
101:      *
102:      * @return array Returns array of user-information
103:      */
104:     public function findAllUser() {
105:         // todo use $perm
106:         $aAllUser = array();
107:         $aUser = array();
108:         $sClientName = '';
109: 
110:         // get all user_ids
111:         $this->select();
112:         while (($oItem = $this->next()) !== false) {
113:             $aUser[] = $oItem->get('user_id');
114:         }
115: 
116:         $oClientColl = new cApiClientCollection();
117: 
118:         // get data of those users
119:         $where = "user_id IN ('" . implode("', '", $aUser) . "')";
120:         $oUserColl = new cApiUserCollection();
121:         $oUserColl->select($where);
122:         while (($oItem = $oUserColl->next()) !== false) {
123:             $sClientNames = '';
124:             $userId = $oItem->get('user_id');
125:             $aAllUser[$userId]['realname'] = $oItem->get('realname');
126:             $aAllUser[$userId]['username'] = $oItem->get('username');
127:             $aPerms = explode(',', $oItem->get('perms'));
128: 
129:             if (in_array('sysadmin', $aPerms)) {
130:                 $aAllUser[$userId]['perms'] = 'Systemadministrator';
131:             } else {
132:                 $bIsAdmin = false;
133:                 $iCounter = 0;
134:                 foreach ($aPerms as $sPerm) {
135:                     $aResults = array();
136:                     if (preg_match('/^admin\[(\d+)\]$/', $sPerm, $aResults)) {
137:                         $iClientId = $aResults[1];
138:                         $bIsAdmin = true;
139:                         $sClientName = $oClientColl->getClientname((int) $iClientId);
140:                         if ($iCounter == 0 && $sClientName != '') {
141:                             $sClientNames .= $sClientName;
142:                         } elseif ($sClientName != '') {
143:                             $sClientNames .= ', ' . $sClientName;
144:                         }
145: 
146:                         $aAllUser[$userId]['perms'] = 'Administrator (' . $sClientNames . ')';
147:                         $iCounter++;
148:                     } elseif (preg_match('/^client\[(\d+)\]$/', $sPerm, $aResults) && !$bIsAdmin) {
149:                         $iClientId = $aResults[1];
150:                         $sClientName = $oClientColl->getClientname((int) $iClientId);
151:                         if ($iCounter == 0 && $sClientName != '') {
152:                             $sClientNames .= $sClientName;
153:                         } elseif ($sClientName != '') {
154:                             $sClientNames .= ', ' . $sClientName;
155:                         }
156: 
157:                         $aAllUser[$userId]['perms'] = '(' . $sClientNames . ')';
158:                         $iCounter++;
159:                     }
160:                 }
161:             }
162:         }
163: 
164:         return $aAllUser;
165:     }
166: 
167:     /**
168:      * This function do an update of current timestamp in 'online_user'
169:      *
170:      * @param string $userId Is the User-Id (get from auth object)
171:      * @return bool Returns true if successful, else false
172:      */
173:     public function updateUser($userId) {
174:         $oUser = new cApiOnlineUser((string) $userId);
175:         if ($oUser->isLoaded()) {
176:             $now = date('Y-m-d H:i:s');
177:             $oUser->set('lastaccessed', $now);
178:             return $oUser->store();
179:         }
180:         return false;
181:     }
182: 
183:     /**
184:      * Delete all Contains in the table 'online_user' that is older as
185:      * Backend timeout(currently is $cfg['backend']['timeout'] = 60)
186:      *
187:      * @return bool Returns true if successful else false
188:      */
189:     public function deleteInactiveUser() {
190:         global $cfg;
191:         include_once($cfg['path']['contenido_config'] . 'config.misc.php');
192:         $iSetTimeOut = (int) $cfg['backend']['timeout'];
193:         if ($iSetTimeOut <= 0) {
194:             $iSetTimeOut = 10;
195:         }
196: 
197:         // NOTE: We could delete outdated entries with one query, but deleteing
198:         // one by one
199:         // gives us the possibility to hook (CEC) into each deleted entry.
200:         $where = "DATE_SUB(NOW(), INTERVAL '$iSetTimeOut' Minute) >= `lastaccessed`";
201:         $result = $this->deleteByWhereClause($where);
202:         return ($result > 0) ? true : false;
203:     }
204: 
205:     /**
206:      * Get the number of users from the table 'online_user'
207:      *
208:      * @return int Returns if exists a number of users
209:      */
210:     public function getNumberOfUsers() {
211:         $sql = 'SELECT COUNT(*) AS cnt FROM `%s`';
212:         $result = $this->db->query($sql, $this->table);
213:         $this->_lastSQL = $sql;
214:         if ($result) {
215:             $this->db->nextRecord();
216:             return (int) $this->db->f('cnt');
217:         }
218:         return 0;
219:     }
220: 
221:     /**
222:      * Delete this user from 'online user' table
223:      *
224:      * @param string $userId Is the User-Id (get from auth object)
225:      * @return bool Returns true if successful, else false
226:      */
227:     public function deleteUser($userId) {
228:         return $this->delete((string) $userId);
229:     }
230: }
231: 
232: /**
233:  * Online user item
234:  *
235:  * @package Core
236:  * @subpackage GenericDB_Model
237:  */
238: class cApiOnlineUser extends Item {
239: 
240:     /**
241:      * Constructor function
242:      *
243:      * @param mixed $mId Specifies the ID of item to load
244:      */
245:     public function __construct($mId = false) {
246:         global $cfg;
247:         parent::__construct($cfg['tab']['online_user'], 'user_id');
248:         $this->setFilters(array(), array());
249:         if ($mId !== false) {
250:             $this->loadByPrimaryKey($mId);
251:         }
252:     }
253: }
254: 
CMS CONTENIDO 4.9.7 API documentation generated by ApiGen