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