'useridmismatch','msg'=>lang('CMSEX_L006')); } $out['uid'] = $ruid; break; case 'test': // alias for check case 'is_locked': // alias for check case 'check': if( !$type ) throw new CmsInvalidDataException(lang('missingparams')); if( $oid ) { $out['lock_id'] = CmsLockOperations::is_locked($type,$oid) ? 1 : 0; } else { $tmp = CmsLockOperations::get_locks($type); if( is_array($tmp) && count($tmp) ) $out['lock_id'] = -1; } break; case 'lock': if( $lifetime < 1 ) break; // do not lock, basically a noop if( !$type || !$oid || !$uid ) throw new CmsInvalidDataException(lang('missingparams')); if( $uid != $ruid ) throw new CmsLockOwnerException(lang('CMSEX_L006')); // see if we can get this lock... if we can, it's just a touch $lock = null; try { $lock = CmsLock::load($type,$oid,$uid); } catch( CmsNoLockException $e ) { // lock doesn't exist, gotta create one. $lock = new CmsLock($type,$oid,$lifetime); } $lock->save(); $out['lock_id'] = $lock['id']; $out['lock_expires'] = $lock['expires']; // and we''re done. break; case 'touch': if( !$type || !$oid || !$uid || $lock_id < 1 ) throw new CmsInvalidDataException(lang('missingparams')); if( $uid != $ruid ) throw new CmsLockOwnerException(lang('CMSEX_L006')); $out['lock_expires'] = CmsLockOperations::touch($lock_id,$type,$oid); break; case 'unlock': if( !$type || !$oid || !$uid || $lock_id < 1 ) throw new CmsInvalidDataException(lang('missingparams')); if( $uid != $ruid ) throw new CmsLockOwnerException(lang('CMSEX_L006')); CmsLockOperations::delete($lock_id,$type,$oid); break; } } catch( CmsNoLockException $e ) { $out['status'] = 'error'; $out['error'] = array('type'=>strtolower(get_class($e)),'msg'=>$e->GetMessage()); } catch( CmsLockException $e ) { $out['status'] = 'error'; $out['error'] = array('type'=>strtolower(get_class($e)),'msg'=>$e->GetMessage()); } catch( Exception $e ) { $out['status'] = 'error'; $out['error'] = array('type'=>'othererror','msg'=>$e->GetMessage()); } if( $out['status'] != 'error' && isset($out['lock_id']) && $out['lock_id'] != 0 ) $out['locked'] = 1; header("Expires: Tue, 01 Jan 2000 00:00:00 GMT"); header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0"); header("Cache-Control: post-check=0, pre-check=0", false); header("Pragma: no-cache"); header('Content-Type: application/json'); echo json_encode($out); exit; # # EOF