getModulePath('', 'action') . 'model.php'); class extactionModel extends actionModel { /** * Get user actions of password change and login since last two xxd poll. * * @param string $action * @access public * @return array */ public function getListSinceLastPoll($action = '') { $lastPoll = date(DT_DATETIME1, strtotime($this->config->xxd->lastPoll . ' - ' . 2 * $this->config->xuanxuan->pollingInterval . ' second')); $actions = array(); if($action === 'changepassword') { $actions = $this->dao->select('t1.id, t1.objectID, t1.date')->from(TABLE_ACTION)->alias('t1') ->leftJoin(TABLE_HISTORY)->alias('t2')->on('t1.id = t2.action') ->leftJoin(TABLE_USER)->alias('t3')->on('t1.objectID = t3.id') ->where('t3.clientStatus')->ne('offline') ->andWhere('t1.objectType')->eq('user') ->andWhere('t2.field')->eq('password') ->andWhere('t1.action')->eq('edited') ->andWhere('t1.date')->gt($lastPoll) ->orderBy('t1.`date`_desc') ->fetchAll(); } elseif($action === 'loginxuanxuan') { $actions = $this->dao->select('id, objectID, date')->from(TABLE_ACTION) ->where('date')->gt($lastPoll) ->andWhere('action')->eq('loginxuanxuan') ->orderBy('`date`_desc') ->fetchAll(); } $uniqueActions = array(); foreach($actions as $action) { $exist = false; foreach($uniqueActions as $uniqueAction) { if($uniqueAction->objectID === $action->objectID) { $exist = true; break; } } if(!$exist) $uniqueActions[] = $action; } return $uniqueActions; } /** * Check log level for action. * * @param string $module * @param object $action * @access public * @return bool */ public function checkLogLevel($module, $action) { $logLevel = (int)zget($this->config->xuanxuan, 'logLevel', 1); $actionLevel = zget($this->config->action->logLevel->{$module}, $action, 0); if($logLevel >= $actionLevel) return true; return false; } public function create($objectType, $objectID, $actionType, $comment = '', $extra = '', $actor = '', $autoDelete = true) { if(strtolower($actionType) == 'reconnectxuanxuan' or strtolower($actionType) == 'loginxuanxuan') { $ip = helper::getRemoteIp(); $last = $this->server->request_time; $this->dao->update(TABLE_USER)->set('visits = visits + 1')->set('ip')->eq($ip)->set('last')->eq($last)->where('account')->eq($actor)->exec(); } if(strtolower($actionType) == 'commented' && empty($comment)) return false; $actor = $actor ? $actor : (!empty($this->app->user->account) ? $this->app->user->account : 'system'); $actionType = strtolower($actionType); $actor = ($actionType == 'openedbysystem' || $actionType == 'closedbysystem') ? '' : $actor; if($actor == 'guest' && $actionType == 'logout') return false; $objectType = str_replace('`', '', $objectType); $extra = (string)$extra; $action = new stdclass(); $action->objectType = strtolower($objectType); $action->objectID = $objectID; $action->actor = $actor; $action->action = $actionType; $action->date = helper::now(); $action->extra = (string)$extra; if(!$this->app->upgrading) $action->vision = $this->config->vision; if($objectType == 'story' && in_array($actionType, array('reviewpassed', 'reviewrejected', 'reviewclarified', 'reviewreverted', 'synctwins'))) $action->actor = $this->lang->action->system; /* 使用purifier处理注解。 */ /* Use purifier to process comment. Fix bug #2683. */ if(empty($comment)) $comment = ''; $action->comment = fixer::stripDataTags($comment); $uid = $this->post->uid; if(is_string($uid)) $uid = array($uid); if(!is_array($uid)) $uid = array(); $this->loadModel('file'); foreach($uid as $value) { $action = $this->file->processImgURL($action, 'comment', $value); if($autoDelete) $this->file->autoDelete($value); } /* 获取对象的产品项目以及执行。 */ /* Get product project and execution for this object. */ $relation = $this->getRelatedFields($action->objectType, $objectID, $actionType, $extra); $action->product = $relation['product']; $action->project = (int)$relation['project']; $action->execution = (int)$relation['execution']; $this->dao->insert(TABLE_ACTION)->data($action)->autoCheck()->exec(); $actionID = $this->dao->lastInsertID(); $hasProductTable = true; $hasRecentTable = true; if($this->app->upgrading) { $fromVersion = $this->loadModel('setting')->getItem('owner=system&module=common§ion=global&key=version'); if(is_numeric($fromVersion[0]) && version_compare($fromVersion, '18.6', '<')) $hasRecentTable = false; if(strpos($fromVersion, 'pro') !== false) $hasRecentTable = false; if(strpos($fromVersion, 'biz') !== false && version_compare($fromVersion, 'biz8.6', '<')) $hasRecentTable = false; if(strpos($fromVersion, 'max') !== false && version_compare($fromVersion, 'max4.6', '<')) $hasRecentTable = false; if(strpos($fromVersion, 'ipd') !== false && version_compare($fromVersion, 'ipd1.0.1', '<')) $hasRecentTable = false; if(is_numeric($fromVersion[0]) && version_compare($fromVersion, '21.7.1', '<=')) $hasProductTable = false; if(strpos($fromVersion, 'pro') !== false) $hasProductTable = false; if(strpos($fromVersion, 'biz') !== false && version_compare($fromVersion, 'biz12.0', '<=')) $hasProductTable = false; if(strpos($fromVersion, 'max') !== false && version_compare($fromVersion, 'max7.0', '<=')) $hasProductTable = false; if(strpos($fromVersion, 'ipd') !== false && version_compare($fromVersion, 'ipd4.0', '<=')) $hasProductTable = false; } if($hasProductTable) { $productIdList = array_filter(explode(',', $action->product)); foreach($productIdList as $productID) $this->dao->insert(TABLE_ACTIONPRODUCT)->set('action')->eq($actionID)->set('product')->eq($productID)->exec(); } if($actionType == 'commented') { $oldAction = new stdclass(); $oldAction->id = $actionID; $newAction = clone $oldAction; $this->file->processFileDiffsForObject('comment', $oldAction, $newAction); if(!empty($newAction->files)) { $action->files = $newAction->files; $this->dao->update(TABLE_ACTION)->set('files')->eq($newAction->files)->where('id')->eq($actionID)->exec(); } $changes = common::createChanges($oldAction, $newAction); if($changes) $this->logHistory($actionID, $changes); } if($hasRecentTable) { $action->id = $actionID; $this->dao->insert(TABLE_ACTIONRECENT)->data($action)->autoCheck()->exec(); } $this->file->updateObjectID($uid, $objectID, $objectType); if(empty($this->app->installing) && empty($this->app->upgrading)) $this->loadModel('message')->send(strtolower($objectType), $objectID, $actionType, $actionID, $actor, $extra); $this->saveIndex($objectType, $objectID, $actionType); $changeFunc = 'after' . ucfirst($objectType); if(method_exists($this, $changeFunc)) call_user_func_array(array($this, $changeFunc), array($action, $actionID)); return $actionID; } //**// }