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 inuse collection and item class.
  4:  *
  5:  * @package          Core
  6:  * @subpackage       GenericDB_Model
  7:  * @version          SVN Revision $Rev:$
  8:  *
  9:  * @author           Timo Hummel
 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:  * Class InUse Class for In-Use management
 20:  *
 21:  * @package Core
 22:  * @subpackage GenericDB_Model
 23:  */
 24: class cApiInUseCollection extends ItemCollection {
 25: 
 26:     /**
 27:      * Constructor Function
 28:      */
 29:     public function __construct() {
 30:         global $cfg;
 31:         parent::__construct($cfg['tab']['inuse'], 'idinuse');
 32:         $this->_setItemClass('cApiInUse');
 33:     }
 34: 
 35:     /**
 36:      * Marks a specific object as "in use". Note that items are released when
 37:      * the session is destroyed. Currently, the following types are defined and
 38:      * approved as internal CONTENIDO standard: - article - module - layout -
 39:      * template
 40:      *
 41:      * @param string $type Specifies the type to mark.
 42:      * @param mixed $objectid Specifies the object ID
 43:      * @param string $session Specifies the session for which the "in use" mark
 44:      *            is valid
 45:      * @param string $user Specifies the user which requested the in-use flag
 46:      * @return cApiInUse|NULL
 47:      */
 48:     public function markInUse($type, $objectid, $session, $user) {
 49:         $type = $type;
 50:         $objectid = $objectid;
 51:         $session = $session;
 52:         $user = $user;
 53: 
 54:         $this->select("type='" . $this->escape($type) . "' AND objectid='" . $this->escape($objectid) . "'");
 55: 
 56:         $newitem = NULL;
 57:         if (!$this->next()) {
 58:             $newitem = $this->createNewItem();
 59:             $newitem->set('type', $type);
 60:             $newitem->set('objectid', $objectid);
 61:             $newitem->set('session', $session);
 62:             $newitem->set('userid', $user);
 63:             $newitem->set('timestamp', time());
 64:             $newitem->store();
 65:         }
 66:         return $newitem;
 67:     }
 68: 
 69:     /**
 70:      * Removes the "in use" mark from a specific object.
 71:      *
 72:      * @param string $type Specifies the type to de-mark.
 73:      * @param mixed $objectid Specifies the object ID
 74:      * @param string $session Specifies the session for which the "in use" mark
 75:      *            is valid
 76:      */
 77:     public function removeMark($type, $objectid, $session) {
 78:         $type = $this->escape($type);
 79:         $objectid = $this->escape($objectid);
 80:         $session = $this->escape($session);
 81: 
 82:         $this->select("type='" . $type . "' AND objectid='" . $objectid . "' AND session='" . $session . "'");
 83: 
 84:         if (($obj = $this->next()) !== false) {
 85:             // Remove entry
 86:             $this->delete($obj->get('idinuse'));
 87:             unset($obj);
 88:         }
 89:     }
 90: 
 91:     /**
 92:      * Removes all marks for a specific type and session
 93:      *
 94:      * @param string $type Specifies the type to de-mark.
 95:      * @param string $session Specifies the session for which the "in use" mark
 96:      *            is valid
 97:      */
 98:     public function removeTypeMarks($type, $session) {
 99:         $type = $this->escape($type);
100:         $session = $this->escape($session);
101: 
102:         $this->select("type='" . $type . "' AND session='" . $session . "'");
103: 
104:         while (($obj = $this->next()) !== false) {
105:             // Remove entry
106:             $this->delete($obj->get('idinuse'));
107:             unset($obj);
108:         }
109:     }
110: 
111:     /**
112:      * Removes the mark for a specific item
113:      *
114:      * @param string $type Specifies the type to de-mark.
115:      * @param string $itemid Specifies the item
116:      */
117:     public function removeItemMarks($type, $itemid) {
118:         $type = $this->escape($type);
119:         $itemid = $this->escape($itemid);
120: 
121:         $this->select("type='" . $type . "' AND objectid='" . $itemid . "'");
122: 
123:         while (($obj = $this->next()) !== false) {
124:             // Remove entry
125:             $this->delete($obj->get('idinuse'));
126:             unset($obj);
127:         }
128:     }
129: 
130:     /**
131:      * Removes all in-use marks for a specific userId
132:      *
133:      * @param string $userId Specifies the user
134:      */
135:     public function removeUserMarks($userId) {
136:         $userId = $this->escape($userId);
137:         $this->select("userid='" . $userId . "'");
138: 
139:         while (($obj = $this->next()) !== false) {
140:             // Remove entry
141:             $this->delete($obj->get('idinuse'));
142:             unset($obj);
143:         }
144:     }
145: 
146:     /**
147:      * Removes all inuse entries which are older than the inuse timeout
148:      */
149:     public function removeOldMarks() {
150:         $cfg = cRegistry::getConfig();
151:         $expire = time() - $cfg['inuse']['lifetime'];
152: 
153:         $this->select("timestamp < " . $expire);
154: 
155:         while (($obj = $this->next()) !== false) {
156:             // Remove entry
157:             $this->delete($obj->get('idinuse'));
158:             unset($obj);
159:         }
160:     }
161: 
162:     /**
163:      * Removes all in-use marks for a specific session.
164:      *
165:      * @param string $session Specifies the session for which the "in use" marks
166:      *            should be removed
167:      */
168:     public function removeSessionMarks($session) {
169:         $session = $this->escape($session);
170:         $this->select("session='" . $session . "'");
171: 
172:         while (($obj = $this->next()) !== false) {
173:             // Remove entry
174:             $this->delete($obj->get('idinuse'));
175:             unset($obj);
176:         }
177:     }
178: 
179:     /**
180:      * Checks if a specific item is marked
181:      *
182:      * @param string $type Specifies the type to de-mark.
183:      * @param mixed $objectid Specifies the object ID
184:      * @return cApiInUse bool false if it's not in use or returns the object if
185:      *         it is.
186:      */
187:     public function checkMark($type, $objectid) {
188:         $type = $this->escape($type);
189:         $objectid = $this->escape($objectid);
190: 
191:         $this->select("type='" . $type . "' AND objectid='" . $objectid . "'");
192: 
193:         if (($obj = $this->next()) !== false) {
194:             return $obj;
195:         } else {
196:             return false;
197:         }
198:     }
199: 
200:     /**
201:      * Checks and marks if not marked. Example: Check for "idmod", also return a
202:      * lock message: list($inUse, $message) = $col->checkAndMark("idmod",
203:      * $idmod, true, i18n("Module is in use by %s (%s)")); Example 2: Check for
204:      * "idmod", don't return a lock message $inUse = $col->checkAndMark("idmod",
205:      * $idmod);
206:      *
207:      * @param string $type Specifies the type to de-mark.
208:      * @param mixed $objectid Specifies the object ID
209:      * @param bool $returnWarning If true, also returns an error message if in
210:      *            use
211:      * @param string $warningTemplate String to fill with the template (%s as
212:      *            placeholder, first %s is the username, second is the real
213:      *            name)
214:      * @param bool $allowOverride True if the user can override the lock
215:      * @param string $location Value to append to the override lock button
216:      * @return bool array returnWarning is false, returns a bool value wether
217:      *         the object is locked. If returnWarning is true, returns a 2 item
218:      *         array (bool inUse, string errormessage).
219:      */
220:     public function checkAndMark($type, $objectid, $returnWarning = false, $warningTemplate = '', $allowOverride = false, $location = '') {
221:         global $sess, $auth, $notification, $area, $frame, $perm;
222: 
223:         if ((($obj = $this->checkMark($type, $objectid)) === false) || ($auth->auth['uid'] == $obj->get('userid'))) {
224:             $this->markInUse($type, $objectid, $sess->id, $auth->auth['uid']);
225:             $inUse = false;
226:             $disabled = '';
227:             $noti = '';
228:         } else {
229:             if ($returnWarning == true) {
230:                 $vuser = new cApiUser($obj->get('userid'));
231:                 $inUseUser = $vuser->getField('username');
232:                 $inUseUserRealName = $vuser->getField('realname');
233: 
234:                 $message = sprintf($warningTemplate, $inUseUser, $inUseUserRealName);
235: 
236:                 if ($allowOverride == true && ($auth->auth['uid'] == $obj->get('userid') || $perm->have_perm())) {
237:                     $alt = i18n("Click here if you want to override the lock");
238: 
239:                     $link = $sess->url($location . "&overridetype=" . $type . "&overrideid=" . $objectid);
240: 
241:                     $warnmessage = i18n("Do you really want to override the lock?");
242:                     $script = "javascript:if (window.confirm('" . $warnmessage . "') == true) { window.location.href  = '" . $link . "';}";
243:                     $override = '<br><br><a alt="' . $alt . '" title="' . $alt . '" href="' . $script . '" class="standard">[' . i18n("Override lock") . ']</a> <a href="javascript://" class="standard" onclick="elem = document.getElementById(\'contenido_notification\'); elem.style.display=\'none\'">[' . i18n("Hide notification") . ']</a>';
244:                 } else {
245:                     $override = '';
246:                 }
247: 
248:                 if (!is_object($notification)) {
249:                     $notification = new cGuiNotification();
250:                 }
251: 
252:                 $noti = $notification->returnMessageBox('warning', $message . $override, 0);
253:                 $inUse = true;
254:             }
255:         }
256: 
257:         if ($returnWarning == true) {
258:             return (array(
259:                     $inUse,
260:                     $noti
261:             ));
262:         } else {
263:             return $inUse;
264:         }
265:     }
266: 
267: }
268: 
269: /**
270:  * Class cApiInUse Class for a single in-use item
271:  *
272:  * @package Core
273:  * @subpackage GenericDB_Model
274:  */
275: class cApiInUse extends Item {
276: 
277:     /**
278:      * Constructor Function
279:      *
280:      * @param mixed $mId Specifies the ID of item to load
281:      */
282:     public function __construct($mId = false) {
283:         global $cfg;
284:         parent::__construct($cfg['tab']['inuse'], 'idinuse');
285:         if ($mId !== false) {
286:             $this->loadByPrimaryKey($mId);
287:         }
288:     }
289: 
290: }
291: 
CMS CONTENIDO 4.9.7 API documentation generated by ApiGen