public function sitesearchAction() { $keyword = $_POST["keyword"]; $logModel = new LogModel(); $logModel->sitesearch($keyword); echo $keyword; }
public static function _($message, $channel = Ajde_Log::CHANNEL_INFO, $level = Ajde_Log::LEVEL_INFORMATIONAL, $description = '', $code = '', $trace = '') { // don't use db writer on db error if (substr_count($message, 'SQLSTATE')) { return false; } $log = new LogModel(); $log->populate(['message' => $message, 'channel' => $channel, 'level' => $level, 'description' => $description, 'code' => $code, 'trace' => $trace, 'request' => self::getRequest(), 'user_agent' => self::getUserAgent(), 'referer' => self::getReferer(), 'ip' => self::getIP()]); return $log->insert(); }
/** * Called before Zend_Controller_Front begins evaluating the * request against its routes. * * @param Zend_Controller_Request_Abstract $request * @return void */ public function routeStartup(Zend_Controller_Request_Abstract $request) { $objLog = new LogModel(); $objLog->updateLog(); /** * Clear log */ if (isset($this->_config['logTime'])) { $objLog->clearLog($this->_config['logTime']); } }
public function renderDefault() { $params = $this->serverRepo->getRunParams($this->selectedServerId); $this->template->address = $this->hostIp . ":" . $params['port']; try { $logModel = new LogModel($params['path'] . 'logs/'); $this->template->logs = LogModel::makeColorful($logModel->getAll()); } catch (UnexpectedValueException $e) { $this->template->logs = array('nic nenalezeno'); } }
public function AjaxAuth() { /* * Connect un utilisateur via une requette Ajax */ // Si une des variable est vide if (empty($_POST['sLogin']) || empty($_POST['sPass'])) { return 1; } // Prépare et envoie la requete SQL $oSql = $this->oPDO->prepare('SELECT AID FROM bo_admin WHERE login=:login AND pass=:pass'); $oSql->bindValue(':login', $_POST['sLogin']); $oSql->bindValue(':pass', $_POST['sPass']); $oSql->execute(); $aResult = $oSql->fetch(PDO::FETCH_ASSOC); // Si aucun résulta ne correspond, erreur 2 if (!$aResult) { // array( UID, LOGIN, PASS, SUCCESS ); LogModel::logThis(1, array('', $_POST['sLogin'], $_POST['sPass'], 0)); return 2; } // Sinon on sauvegarde l'id utilisateur et on retourne 3 $_SESSION['AID'] = $aResult['AID']; // array( UID, LOGIN, PASS, SUCCESS ); LogModel::logThis(1, array($_SESSION['AID'], $_POST['sLogin'], $_POST['sPass'], 1)); return 3; }
/** * Check whether or not the record is spam. * @param string $RecordType By default, this should be one of the following: * - Comment: A comment. * - Discussion: A discussion. * - User: A user registration. * @param array $Data The record data. * @param array $Options Options for fine-tuning this method call. * - Log: Log the record if it is found to be spam. */ public static function IsSpam($RecordType, $Data, $Options = array()) { // Set some information about the user in the data. TouchValue('IPAddress', $Data, Gdn::Request()->IpAddress()); if ($RecordType == 'User') { TouchValue('Username', $Data, $Data['Name']); } else { TouchValue('Username', $Data, Gdn::Session()->User->Name); TouchValue('Email', $Data, Gdn::Session()->User->Email); } $Sp = self::_Instance(); $Sp->EventArguments['RecordType'] = $RecordType; $Sp->EventArguments['Data'] = $Data; $Sp->EventArguments['Options'] = $Options; $Sp->EventArguments['IsSpam'] = FALSE; $Sp->FireEvent('CheckSpam'); $Spam = $Sp->EventArguments['IsSpam']; // Log the spam entry. if ($Spam && GetValue('Log', $Options, TRUE)) { LogModel::Insert('Spam', $RecordType, $Data); } return $Spam; }
/** * Check whether or not the record is spam. * @param string $RecordType By default, this should be one of the following: * - Comment: A comment. * - Discussion: A discussion. * - User: A user registration. * @param array $Data The record data. * @param array $Options Options for fine-tuning this method call. * - Log: Log the record if it is found to be spam. */ public static function IsSpam($RecordType, $Data, $Options = array()) { // Set some information about the user in the data. TouchValue('IPAddress', $Data, Gdn::Request()->IpAddress()); if ($RecordType == 'Registration') { TouchValue('Username', $Data, $Data['Name']); } else { TouchValue('Username', $Data, Gdn::Session()->User->Name); TouchValue('Email', $Data, Gdn::Session()->User->Email); } $Sp = self::_Instance(); $Sp->EventArguments['RecordType'] = $RecordType; $Sp->EventArguments['Data'] =& $Data; $Sp->EventArguments['Options'] =& $Options; $Sp->EventArguments['IsSpam'] = FALSE; $Sp->FireEvent('CheckSpam'); $Spam = $Sp->EventArguments['IsSpam']; // Log the spam entry. if ($Spam && GetValue('Log', $Options, TRUE)) { $LogOptions = array(); switch ($RecordType) { case 'Registration': $LogOptions['GroupBy'] = array('RecordIPAddress'); break; case 'Comment': case 'Discussion': $LogOptions['GroupBy'] = array('RecordID'); break; } LogModel::Insert('Spam', $RecordType, $Data, $LogOptions); } return $Spam; }
protected function createComponentBasicTabella($name) { // asi nepotřebuje komentář :-) $model = new LogModel(); $grid = new Tabella($model->getDataSource(), array('sorting' => 'id_log', 'order' => 'id_log', "onSubmit" => function ($post) { print_r($post); LogModel::save($post, $post['id_log']); })); $grid->addColumn("id_log", "id_log", array("width" => 30)); $grid->addColumn("name_modul", "name_modul", array("width" => 100, "editable" => true)); $grid->addColumn("description", "description", array("width" => 100)); $grid->addColumn("value", "value", array("width" => 100)); $grid->addColumn("query", "query", array("width" => 100)); $grid->addColumn("date", "date", array("width" => 100)); $grid->addColumn("ip", "ip", array("width" => 100)); $this->addComponent($grid, $name); }
/** * Get Activity of a single user. * @param int $user_id id of the specific user * @return object a single object (the result) */ public static function getActivity($user_id) { if (self::$getActivityQuery === null) { self::$getActivityQuery = DatabaseFactory::getFactory()->getConnection()->prepare("SELECT * FROM log WHERE user_id = :user_id "); } self::$getActivityQuery->execute(array(':user_id' => (int) $user_id)); return self::$getActivityQuery->fetchAll(PDO::FETCH_ASSOC); }
/** * Check whether or not the record is spam. * @param string $RecordType By default, this should be one of the following: * - Comment: A comment. * - Discussion: A discussion. * - User: A user registration. * @param array $Data The record data. * @param array $Options Options for fine-tuning this method call. * - Log: Log the record if it is found to be spam. */ public static function IsSpam($RecordType, $Data, $Options = array()) { if (self::$Disabled) { return FALSE; } // Set some information about the user in the data. if ($RecordType == 'Registration') { TouchValue('Username', $Data, $Data['Name']); } else { TouchValue('InsertUserID', $Data, Gdn::Session()->UserID); $User = Gdn::UserModel()->GetID(GetValue('InsertUserID', $Data), DATASET_TYPE_ARRAY); if ($User) { if (GetValue('Verified', $User)) { // The user has been verified and isn't a spammer. return FALSE; } TouchValue('Username', $Data, $User['Name']); TouchValue('Email', $Data, $User['Email']); TouchValue('IPAddress', $Data, $User['LastIPAddress']); } } if (!isset($Data['Body']) && isset($Data['Story'])) { $Data['Body'] = $Data['Story']; } TouchValue('IPAddress', $Data, Gdn::Request()->IpAddress()); $Sp = self::_Instance(); $Sp->EventArguments['RecordType'] = $RecordType; $Sp->EventArguments['Data'] =& $Data; $Sp->EventArguments['Options'] =& $Options; $Sp->EventArguments['IsSpam'] = FALSE; $Sp->FireEvent('CheckSpam'); $Spam = $Sp->EventArguments['IsSpam']; // Log the spam entry. if ($Spam && GetValue('Log', $Options, TRUE)) { $LogOptions = array(); switch ($RecordType) { case 'Registration': $LogOptions['GroupBy'] = array('RecordIPAddress'); break; case 'Comment': case 'Discussion': case 'Activity': case 'ActivityComment': $LogOptions['GroupBy'] = array('RecordID'); break; } LogModel::Insert('Spam', $RecordType, $Data, $LogOptions); } return $Spam; }
/** * 更改密码 */ public function updatepwd() { parent::_initalize(); $systemConfig = $this->systemConfig; $this->assign("systemConfig", $systemConfig); if (IS_POST) { $a_id = $_SESSION[C('USER_AUTH_KEY')]; $oldpwd = trim($_POST['oldpwd']); $oldpwd_md5 = encrypt($oldpwd); $newpwd = trim($_POST['newpwd']); $newpwd_md5 = encrypt($newpwd); $newpwd2 = trim($_POST['newpwd2']); if ($newpwd != $newpwd2) { $this->error("两次输入的密码不一致"); exit; } $mod = M("Admin"); $ainfo = $mod->where("a_id=" . $a_id)->find(); if ($ainfo['a_pwd'] != $oldpwd_md5) { $this->error("原来的密码输入错误"); exit; } //修改密码 $data = array("a_pwd" => $newpwd_md5, "a_pwd_md5" => $newpwd); $res = $mod->where("a_id=" . $a_id)->save($data); if ($res) { $logmod = new LogModel(); $logmod->addlog("修改了[密码]"); $this->success("操作成功"); exit; } else { $this->error("操作失败"); exit; } } $this->display(); }
public function contactMail() { // V�rifie l'adresse mail if (!filter_var($_POST['sMail'], FILTER_VALIDATE_EMAIL)) { return 1; } // V�rifie le t�l�phone $sTel = StrModel::is_NumPortable($_POST['sMobile']); if (!$sTel) { return 2; } if (!StrModel::strMinLen($_POST['sNom'], 2)) { return 3; } // Vérifie le nom if (!StrModel::strMinLen($_POST['sPrenom'], 2)) { return 4; } // Vérifie le prénom if (!StrModel::strMinLen($_POST['sMessage'], 30)) { return 5; } // Vérifie le message // r�cup�ration du mail � contacter if ($_POST['sContact'] == 'commercial') { $sMail = ConfigModel::get(4, 0); $sLogCat = 2; } else { $sMail = ConfigModel::get(3, 0); $sLogCat = 1; } // Formatage du nom / prénom $_POST['sNom'] = strtoupper($_POST['sNom']); $_POST['sPrenom'] = ucfirst(strtolower($_POST['sPrenom'])); $sWho = $_POST['sCivilite'] . ' ' . $_POST['sNom'] . ' ' . $_POST['sPrenom']; // Log l'action LogModel::logThis($sLogCat, array($sMail, $_POST['sMail'], $sWho, $_POST['sLogin'], $sTel, $_POST['sMotif'], $_POST['sMessage'])); // Construit le mail $aMessage = array('Envoyé depuis le formulaire de contact [ ' . $_POST['sContact'] . ' ]', '', 'Date: ' . date('d-m-Y - H:i'), 'Éméteur: ' . $sWho, 'Login: '******'sLogin'], 'Mobile: ' . $sTel, 'Mail: ' . $_POST['sMail'], 'Motif: ' . $_POST['sMotif'], '', 'Message:', '', $_POST['sMessage']); // Envoie le mail if (!$this->sendMail($sWho, $_POST['sMail'], $_POST['sContact'], 'Support ' . $_POST['sContact'], $aMessage)) { return 6; } else { return 7; } }
/** * View spam logs. * * @since 2.0.? * @access public * * @param int $Page Page number. */ public function Spam($Page = '') { $this->Permission('Garden.Moderation.Manage'); list($Offset, $Limit) = OffsetLimit($Page, 10); $this->SetData('Title', T('Spam Queue')); $Where = array('Operation' => array('Spam')); $RecordCount = $this->LogModel->GetCountWhere($Where); $this->SetData('RecordCount', $RecordCount); if ($Offset >= $RecordCount) { $Offset = $RecordCount - $Limit; } $Log = $this->LogModel->GetWhere($Where, 'LogID', 'Desc', $Offset, $Limit); $this->SetData('Log', $Log); if ($this->DeliveryType() == DELIVERY_TYPE_VIEW) { $this->View = 'Table'; } $this->AddSideMenu('dashboard/log/spam'); $this->Render(); }
/** * View spam logs. * * @since 2.0.? * @access public * * @param int $Page Page number. */ public function spam($Page = '') { $this->permission(array('Garden.Moderation.Manage', 'Moderation.Spam.Manage'), false); list($Offset, $Limit) = offsetLimit($Page, 10); $this->setData('Title', t('Spam Queue')); $Where = array('Operation' => array('Spam')); $RecordCount = $this->LogModel->getCountWhere($Where); $this->setData('RecordCount', $RecordCount); if ($Offset >= $RecordCount) { $Offset = $RecordCount - $Limit; } $Log = $this->LogModel->getWhere($Where, 'LogID', 'Desc', $Offset, $Limit); $this->setData('Log', $Log); if ($this->deliveryType() == DELIVERY_TYPE_VIEW) { $this->View = 'Table'; } Gdn_Theme::section('Moderation'); $this->setHighlightRoute('dashboard/log/spam'); $this->render(); }
public function display($viewfile = "") { $this->endtime = microtime(true); $time = round(($this->endtime - $this->begintime) * 1000.0); $this->_view->assign("pagetime", $time); if ($time > 300) { $logModel = new LogModel(); $logModel->slowRequest($time); } if (!empty($viewfile)) { $this->_mainContent->assign("retUrl", $_SERVER['REQUEST_URI']); $this->_view->assign("retUrl", $_SERVER['REQUEST_URI']); $mainContent = $this->_mainContent->fetch($viewfile); $this->_view->assign('mainContent', $mainContent); } else { if ($this->viewFile != "") { $this->_mainContent->assign("retUrl", $_SERVER['REQUEST_URI']); $this->_view->assign("retUrl", $_SERVER['REQUEST_URI']); $mainContent = $this->_mainContent->fetch($this->viewFile); $this->_view->assign('mainContent', $mainContent); } } if (isset($_SESSION['id'])) { $notify = new NotificationModel(); $notifyCount = $notify->unreadCount($_SESSION['id']); $this->_view->assign("notifyCount", $notifyCount); } parent::display(); }
protected function createComponentProductTabella($name) { // ProductModel::repairAllProductSequence(); $id_category = $this->getParam('id_category'); $fluent = ProductModel::getFluent()->orderBy('product_sequence'); if ($id_category) { $fluent->where('id_category = %i', $id_category); } else { $fluent->groupBy('id_product'); } $datasource = $fluent->toDatasource(); $grid = new Tabella($datasource, array('sorting' => 'product_sequence', 'order' => 'product_sequence', 'limit' => 400, "onSuccess" => function ($post) { LogModel::save($post, $post['id_log']); })); $grid->addColumn("Názov", "name", array("width" => 300, "editable" => false)); $grid->addColumn("Cena", "min_price", array("width" => 100, "editable" => false)); $_active = array('' => '', 0 => 'Zakázaný', 1 => 'Povolený'); $grid->addColumn("Akcia", "sale", array("width" => 100, 'type' => Tabella::SELECT, "filter" => array('' => '', 0 => 'nie', 1 => 'áno'), "options" => NULL, "renderer" => function ($row) { $el = NHtml::el("td"); $pom = array('' => '', 0 => 'nie', 1 => 'áno'); return $el->add($pom[$row['sale']]); })); $grid->addColumn("Najpredá.", "our_tip", array("width" => 100, 'type' => Tabella::SELECT, "filter" => array('' => '', 0 => 'nie', 1 => 'áno'), "options" => NULL, "renderer" => function ($row) { $el = NHtml::el("td"); $pom = array('' => '', 0 => 'nie', 1 => 'áno'); return $el->add($pom[$row['our_tip']]); })); $grid->addColumn("_", "active", array("width" => 100, 'type' => Tabella::SELECT, "filter" => $_active, "options" => '', "editable" => false, "renderer" => function ($row) use($_active) { $el = NHtml::el("td"); // print_r($row);exit; /* * link na zmazanie produktu */ $el->add(NHtml::el('a')->href(NEnvironment::getApplication()->getPresenter()->link('deleteProduct!', array('id' => $row->id_product)))->addClass('deleteIcon ajax')->title('Naozaj chcete zmazať položku?')); /* * link na editaciu produktu */ $el->add(NHtml::el('a')->href(NEnvironment::getApplication()->getPresenter()->link('Product:edit', array('id' => $row->id_product)))->addClass('editIcon')); /* * posuvanie - ak sa spusti posubanie, treba vypnut zoradovanie !!! order=>false */ // $el->add( // NHtml::el( 'a' )->href('#')->addClass( 'moveIcon' ) // ->addId( 'index_'.$row['id_product'] ) // ); /* * ikona aktivan polozka, neaktivan polozka */ $span = NHtml::el('span'); if ($row->active) { $span->addClass('activeIcon active'); } else { $span->addClass('unactiveIcon active '); } $el->add($span); return $el; })); // // $grid->addColumn( "", "id_product", // array( "width" => 55, // 'filter'=>null, // 'order'=>false, // "renderer" => function( $row ) { // // return NHtml::el( "td" )->add( // NHtml::el( 'a' )->href( // NEnvironment::getApplication()->getPresenter()->link( 'Product:edit' , array('id'=>$row->id_product)) // ) // ->addClass( 'editIcon' ) // ); // // }) // ); $this->addComponent($grid, $name); }
/** * Delete a comment. * * This is a hard delete that completely removes it from the database. * Events: DeleteComment. * * @since 2.0.0 * @access public * * @param int $CommentID Unique ID of the comment to be deleted. * @param bool Always returns TRUE. */ public function Delete($CommentID) { $this->EventArguments['CommentID'] = $CommentID; // Grab the comment to check on it. $Data = $this->SQL ->Select('c.*, d.LastCommentID, d.DateInserted as DiscussionDateInserted') ->From('Comment c') ->Join('Discussion d', 'c.DiscussionID = d.DiscussionID') ->Where('c.CommentID', $CommentID) ->Get()->FirstRow(DATASET_TYPE_ARRAY); if ($Data) { // If this is the last comment, get the one before and update the LastCommentID field if ($Data['LastCommentID'] == $CommentID) { $OldData = $this->SQL ->Select('c.CommentID, c.InsertUserID, c.DateInserted') ->From('Comment c') ->Where('c.DiscussionID', $Data['DiscussionID']) ->OrderBy('c.DateInserted', 'desc') ->Limit(1, 1) ->Get()->FirstRow(DATASET_TYPE_ARRAY); if (is_array($OldData)) { $this->SQL->Update('Discussion') ->Set('LastCommentID', $OldData['CommentID']) ->Set('LastCommentUserID', $OldData['InsertUserID']) ->Set('DateLastComment', $OldData['DateInserted']) ->Where('DiscussionID', $Data['DiscussionID']) ->Put(); } else { // It was the ONLY comment $this->SQL->Update('Discussion') ->Set('LastCommentID', NULL) ->Set('LastCommentUserID', NULL) ->Set('DateLastComment', $Data['DateInserted']) ->Where('DiscussionID', $Data['DiscussionID']) ->Put(); } } // Decrement the UserDiscussion comment count if the user has seen this comment $Offset = $this->GetOffset($CommentID); $this->SQL->Update('UserDiscussion') ->Set('CountComments', 'CountComments - 1', FALSE) ->Where('DiscussionID', $Data['DiscussionID']) ->Where('CountComments >', $Offset) ->Put(); // Decrement the Discussion's Comment Count $this->SQL->Update('Discussion') ->Set('CountComments', 'CountComments - 1', FALSE) ->Where('DiscussionID', $Data['DiscussionID']) ->Put(); $this->FireEvent('DeleteComment'); // Log the deletion. unset($Data['LastCommentID'], $Data['DiscussionDateInserted']); LogModel::Insert('Delete', 'Comment', $Data); // Delete the comment. $this->SQL->Delete('Comment', array('CommentID' => $CommentID)); // Update the user's comment count $this->UpdateUser($Data['InsertUserID']); } return TRUE; }
/** * 修改状态 * * */ public function statusAction() { $id = $this->getg('id', 0); if (empty($id)) { $this->error('id 不能为空!'); } $status = $this->getg('status', 0); $status = $status ? 0 : 1; // 实例化Model $log = new LogModel(); $row = $log->update(array('id' => $id), array('status' => $status)); if ($row) { $this->error('恭喜,操作成功', 'Message'); } else { $this->error('操作失败'); } }
<?php if (!defined('APPLICATION')) { exit; } $Session = Gdn::session(); $User = $Session->User; $CssClass = ''; if ($this->CssClass) { $CssClass .= ' ' . $this->CssClass; } $DashboardCount = 0; // Spam & Moderation Queue if ($Session->checkPermission(array('Garden.Settings.Manage', 'Garden.Moderation.Manage', 'Moderation.Spam.Manage', 'Moderation.ModerationQueue.Manage'), false)) { $LogModel = new LogModel(); //$SpamCount = $LogModel->GetOperationCount('spam'); $ModerationCount = $LogModel->GetOperationCount('moderate'); $DashboardCount += $ModerationCount; } // Applicant Count if ($Session->checkPermission('Garden.Users.Approve')) { $RoleModel = new RoleModel(); $ApplicantCount = $RoleModel->GetApplicantCount(); $DashboardCount += $ApplicantCount; } else { $ApplicantCount = null; } $this->EventArguments['DashboardCount'] =& $DashboardCount; $this->fireEvent('BeforeFlyoutMenu'); if ($Session->isValid()) { echo '<div class="MeBox' . $CssClass . '">';
public function Save($Data, $Preference = FALSE, $Options = array()) { Trace('ActivityModel->Save()'); $Activity = $Data; $this->_Touch($Activity); if ($Activity['ActivityUserID'] == $Activity['NotifyUserID'] && !GetValue('Force', $Options)) { Trace('Skipping activity because it would notify the user of something they did.'); return; // don't notify users of something they did. } // Check the user's preference. if ($Preference) { list($Popup, $Email) = self::NotificationPreference($Preference, $Activity['NotifyUserID'], 'both'); if ($Popup && !$Activity['Notified']) { $Activity['Notified'] = self::SENT_PENDING; } if ($Email && !$Activity['Emailed']) { $Activity['Emailed'] = self::SENT_PENDING; } if (!$Activity['Notified'] && !$Activity['Emailed'] && !GetValue('Force', $Options)) { Trace("Skipping activity because the user has no preference set."); return; } } $ActivityType = self::GetActivityType($Activity['ActivityType']); $ActivityTypeID = ArrayValue('ActivityTypeID', $ActivityType); if (!$ActivityTypeID) { Trace("There is no {$ActivityType} activity type.", TRACE_WARNING); $ActivityType = self::GetActivityType('Default'); $ActivityTypeID = ArrayValue('ActivityTypeID', $ActivityType); } $Activity['ActivityTypeID'] = $ActivityTypeID; $NotificationInc = 0; if ($Activity['NotifyUserID'] > 0 && $Activity['Notified']) { $NotificationInc = 1; } // Check to see if we are sharing this activity with another one. if ($CommentActivityID = GetValue('CommentActivityID', $Activity['Data'])) { $CommentActivity = $this->GetID($CommentActivityID); $Activity['Data']['CommentNotifyUserID'] = $CommentActivity['NotifyUserID']; } // Make sure this activity isn't a duplicate. if (GetValue('CheckRecord', $Options)) { // Check to see if this record already notified so we don't notify multiple times. $Where = ArrayTranslate($Activity, array('NotifyUserID', 'RecordType', 'RecordID')); $Where['DateUpdated >'] = Gdn_Format::ToDateTime(strtotime('-2 days')); // index hint $CheckActivity = $this->SQL->GetWhere('Activity', $Where)->FirstRow(); if ($CheckActivity) { return FALSE; } } // Check to share the activity. if (GetValue('Share', $Options)) { $this->Share($Activity); } // Group he activity. if ($GroupBy = GetValue('GroupBy', $Options)) { $GroupBy = (array) $GroupBy; $Where = array(); foreach ($GroupBy as $ColumnName) { $Where[$ColumnName] = $Activity[$ColumnName]; } $Where['NotifyUserID'] = $Activity['NotifyUserID']; // Make sure to only group activities by day. $Where['DateInserted >'] = Gdn_Format::ToDateTime(strtotime('-1 day')); // See if there is another activity to group these into. $GroupActivity = $this->SQL->GetWhere('Activity', $Where)->FirstRow(DATASET_TYPE_ARRAY); if ($GroupActivity) { $GroupActivity['Data'] = @unserialize($GroupActivity['Data']); $Activity = $this->MergeActivities($GroupActivity, $Activity); $NotificationInc = 0; } } $Delete = FALSE; if ($Activity['Emailed'] == self::SENT_PENDING) { $this->Email($Activity); $Delete = GetValue('_Delete', $Activity); } $ActivityData = $Activity['Data']; if (isset($Activity['Data']) && is_array($Activity['Data'])) { $Activity['Data'] = serialize($Activity['Data']); } $this->DefineSchema(); $Activity = $this->FilterSchema($Activity); $ActivityID = GetValue('ActivityID', $Activity); if (!$ActivityID) { if (!$Delete) { $this->AddInsertFields($Activity); TouchValue('DateUpdated', $Activity, $Activity['DateInserted']); $this->EventArguments['Activity'] =& $Activity; $this->EventArguments['ActivityID'] = NULL; $this->FireEvent('BeforeSave'); if (count($this->ValidationResults()) > 0) { return FALSE; } if (GetValue('CheckSpam', $Options)) { // Check for spam $Spam = SpamModel::IsSpam('Activity', $Activity); if ($Spam) { return SPAM; } // Check for approval $ApprovalRequired = CheckRestriction('Vanilla.Approval.Require'); if ($ApprovalRequired && !GetValue('Verified', Gdn::Session()->User)) { LogModel::Insert('Pending', 'Activity', $Activity); return UNAPPROVED; } } $ActivityID = $this->SQL->Insert('Activity', $Activity); $Activity['ActivityID'] = $ActivityID; } } else { $Activity['DateUpdated'] = Gdn_Format::ToDateTime(); unset($Activity['ActivityID']); $this->EventArguments['Activity'] =& $Activity; $this->EventArguments['ActivityID'] = $ActivityID; $this->FireEvent('BeforeSave'); if (count($this->ValidationResults()) > 0) { return FALSE; } $this->SQL->Put('Activity', $Activity, array('ActivityID' => $ActivityID)); $Activity['ActivityID'] = $ActivityID; } $Activity['Data'] = $ActivityData; if (isset($CommentActivity)) { $CommentActivity['Data']['SharedActivityID'] = $Activity['ActivityID']; $CommentActivity['Data']['SharedNotifyUserID'] = $Activity['NotifyUserID']; $this->SetField($CommentActivity['ActivityID'], 'Data', $CommentActivity['Data']); } if ($NotificationInc > 0) { $CountNotifications = Gdn::UserModel()->GetID($Activity['NotifyUserID'])->CountNotifications + $NotificationInc; Gdn::UserModel()->SetField($Activity['NotifyUserID'], 'CountNotifications', $CountNotifications); } return $Activity; }
/** * Delete a user's content across many contexts. * * @param int $UserID * @param array $Options * @param array $Content * @return bool|int */ public function deleteContent($UserID, $Options = [], $Content = []) { $Log = val('Log', $Options); if ($Log === true) { $Log = 'Delete'; } $Result = false; // Fire an event so applications can remove their associated user data. $this->EventArguments['UserID'] = $UserID; $this->EventArguments['Options'] = $Options; $this->EventArguments['Content'] =& $Content; $this->fireEvent('BeforeDeleteUser'); $User = $this->getID($UserID, DATASET_TYPE_ARRAY); if (!$Log) { $Content = null; } // Remove invitations $this->getDelete('Invitation', ['InsertUserID' => $UserID], $Content); $this->getDelete('Invitation', ['AcceptedUserID' => $UserID], $Content); // Remove activities $this->getDelete('Activity', ['InsertUserID' => $UserID], $Content); // Remove activity comments. $this->getDelete('ActivityComment', ['InsertUserID' => $UserID], $Content); // Remove comments in moderation queue $this->getDelete('Log', ['RecordUserID' => $UserID, 'Operation' => 'Pending'], $Content); // Clear out information on the user. $this->setField($UserID, ['About' => null, 'Title' => null, 'Location' => null]); if ($Log) { $User['_Data'] = $Content; unset($Content); // in case data gets copied $Result = LogModel::insert($Log, 'User', $User, val('LogOptions', $Options, [])); } return $Result; }
<?php if (!defined('APPLICATION')) { exit; } $Session = Gdn::Session(); $User = $Session->User; $CssClass = ''; if ($this->CssClass) { $CssClass .= ' ' . $this->CssClass; } $DashboardCount = 0; // Spam & Moderation Queue if ($Session->CheckPermission('Garden.Settings.Manage') || $Session->CheckPermission('Garden.Moderation.Manage')) { $LogModel = new LogModel(); $SpamCount = $LogModel->GetOperationCount('spam'); $ModerationCount = $LogModel->GetOperationCount('moderate'); $DashboardCount += $SpamCount + $ModerationCount; } // Applicant Count if ($Session->CheckPermission('Garden.Applicants.Manage')) { $RoleModel = new RoleModel(); $ApplicantCount = $RoleModel->GetApplicantCount(); $DashboardCount += $ApplicantCount; } if ($Session->IsValid()) { echo '<div class="MeBox' . $CssClass . '">'; echo UserPhoto($User); echo '<div class="WhoIs">'; echo UserAnchor($User, 'Username'); echo '<div class="MeMenu">';
/** * * * @return bool|null * @throws Exception */ public function save() { if (!$this->Dirty) { return null; } $this->EventArguments['ConfigDirty'] =& $this->Dirty; $this->EventArguments['ConfigNoSave'] = false; $this->EventArguments['ConfigType'] = $this->Type; $this->EventArguments['ConfigSource'] = $this->Source; $this->EventArguments['ConfigData'] = $this->Settings; $this->fireEvent('BeforeSave'); if ($this->EventArguments['ConfigNoSave']) { $this->Dirty = false; return true; } // Check for and fire callback if one exists if ($this->Callback && is_callable($this->Callback)) { $CallbackOptions = array(); if (!is_array($this->CallbackOptions)) { $this->CallbackOptions = array(); } $CallbackOptions = array_merge($CallbackOptions, $this->CallbackOptions, array('ConfigDirty' => $this->Dirty, 'ConfigType' => $this->Type, 'ConfigSource' => $this->Source, 'ConfigData' => $this->Settings, 'SourceObject' => $this)); $ConfigSaved = call_user_func($this->Callback, $CallbackOptions); if ($ConfigSaved) { $this->Dirty = false; return true; } } switch ($this->Type) { case 'file': if (empty($this->Source)) { trigger_error(errorMessage('You must specify a file path to be saved.', 'Configuration', 'Save'), E_USER_ERROR); } $CheckWrite = $this->Source; if (!file_exists($CheckWrite)) { $CheckWrite = dirname($CheckWrite); } if (!is_writable($CheckWrite)) { throw new Exception(sprintf(t("Unable to write to config file '%s' when saving."), $this->Source)); } $Group = $this->Group; $Data =& $this->Settings; ksort($Data); // Check for the case when the configuration is the group. if (is_array($Data) && count($Data) == 1 && array_key_exists($Group, $Data)) { $Data = $Data[$Group]; } // Do a sanity check on the config save. if ($this->Source == Gdn::config()->defaultPath()) { // Log root config changes try { $LogData = $this->Initial; $LogData['_New'] = $this->Settings; LogModel::insert('Edit', 'Configuration', $LogData); } catch (Exception $Ex) { } if (!isset($Data['Database'])) { if ($Pm = Gdn::pluginManager()) { $Pm->EventArguments['Data'] = $Data; $Pm->EventArguments['Backtrace'] = debug_backtrace(); $Pm->fireEvent('ConfigError'); } return false; } } // Write config data to string format, ready for saving $FileContents = Gdn_Configuration::format($Data, array('VariableName' => $Group, 'WrapPHP' => true, 'ByLine' => true)); if ($FileContents === false) { trigger_error(errorMessage('Failed to define configuration file contents.', 'Configuration', 'Save'), E_USER_ERROR); } // Save to cache if we're into that sort of thing $FileKey = sprintf(Gdn_Configuration::CONFIG_FILE_CACHE_KEY, $this->Source); if ($this->Configuration && $this->Configuration->caching() && Gdn::cache()->type() == Gdn_Cache::CACHE_TYPE_MEMORY && Gdn::cache()->activeEnabled()) { $CachedConfigData = Gdn::cache()->store($FileKey, $Data, array(Gdn_Cache::FEATURE_NOPREFIX => true, Gdn_Cache::FEATURE_EXPIRY => 3600)); } $TmpFile = tempnam(PATH_CONF, 'config'); $Result = false; if (file_put_contents($TmpFile, $FileContents) !== false) { chmod($TmpFile, 0775); $Result = rename($TmpFile, $this->Source); } if ($Result) { if (function_exists('apc_delete_file')) { // This fixes a bug with some configurations of apc. @apc_delete_file($this->Source); } elseif (function_exists('opcache_invalidate')) { @opcache_invalidate($this->Source); } } $this->Dirty = false; return $Result; break; case 'json': case 'array': case 'string': /** * How would these even save? String config data must be handled by * an event hook or callback, if at all. */ $this->Dirty = false; return false; break; } }
/** * * * @return LogModel */ protected static function _Instance() { if (!self::$_Instance) { self::$_Instance = new LogModel(); } return self::$_Instance; }
/** * Delete a comment. * * This is a hard delete that completely removes it from the database. * Events: DeleteComment. * * @since 2.0.0 * @access public * * @param int $CommentID Unique ID of the comment to be deleted. * @param array $Options Additional options for the delete. * @param bool Always returns TRUE. */ public function Delete($CommentID, $Options = array()) { $this->EventArguments['CommentID'] = $CommentID; $Comment = $this->GetID($CommentID, DATASET_TYPE_ARRAY); if (!$Comment) { return FALSE; } // Decrement the UserDiscussion comment count if the user has seen this comment $Offset = $this->GetOffset($CommentID); $this->SQL->Update('UserDiscussion')->Set('CountComments', 'CountComments - 1', FALSE)->Where('DiscussionID', $Comment['DiscussionID'])->Where('CountComments >', $Offset)->Put(); $this->FireEvent('DeleteComment'); // Log the deletion. $Log = GetValue('Log', $Options, 'Delete'); LogModel::Insert($Log, 'Comment', $Comment); // Delete the comment. $this->SQL->Delete('Comment', array('CommentID' => $CommentID)); // Update the comment count $this->UpdateCommentCount($Comment['DiscussionID']); // Update the user's comment count $this->UpdateUser($Comment['InsertUserID']); // Clear the page cache. $this->RemovePageCache($Comment['DiscussionID']); return TRUE; }
/** * * * @param $UserID * @param array $Options * @param array $Content * @return bool|int * @throws Exception */ public function deleteContent($UserID, $Options = array(), $Content = array()) { $Log = val('Log', $Options); if ($Log === true) { $Log = 'Delete'; } $Result = false; // Fire an event so applications can remove their associated user data. $this->EventArguments['UserID'] = $UserID; $this->EventArguments['Options'] = $Options; $this->EventArguments['Content'] =& $Content; $this->fireEvent('BeforeDeleteUser'); $User = $this->getID($UserID, DATASET_TYPE_ARRAY); if (!$Log) { $Content = null; } // Remove photos /*$PhotoData = $this->SQL->select()->from('Photo')->where('InsertUserID', $UserID)->get(); foreach ($PhotoData->result() as $Photo) { @unlink(PATH_UPLOADS.DS.$Photo->Name); } $this->SQL->delete('Photo', array('InsertUserID' => $UserID)); */ // Remove invitations $this->GetDelete('Invitation', array('InsertUserID' => $UserID), $Content); $this->GetDelete('Invitation', array('AcceptedUserID' => $UserID), $Content); // Remove activities $this->GetDelete('Activity', array('InsertUserID' => $UserID), $Content); // Remove activity comments. $this->GetDelete('ActivityComment', array('InsertUserID' => $UserID), $Content); // Remove comments in moderation queue $this->GetDelete('Log', array('RecordUserID' => $UserID, 'Operation' => 'Pending'), $Content); // Clear out information on the user. $this->setField($UserID, array('About' => null, 'Title' => null, 'Location' => null)); if ($Log) { $User['_Data'] = $Content; unset($Content); // in case data gets copied $Result = LogModel::insert($Log, 'User', $User, val('LogOptions', $Options, array())); } return $Result; }
/** * Delete a discussion. Update and/or delete all related data. * * Events: DeleteDiscussion. * * @since 2.0.0 * @access public * * @param int $DiscussionID Unique ID of discussion to delete. * @return bool Always returns TRUE. */ public function delete($DiscussionID, $Options = array()) { // Retrieve the users who have bookmarked this discussion. $BookmarkData = $this->GetBookmarkUsers($DiscussionID); $Data = $this->SQL->select('*')->from('Discussion')->where('DiscussionID', $DiscussionID)->get()->firstRow(DATASET_TYPE_ARRAY); $UserID = false; $CategoryID = false; if ($Data) { $UserID = $Data['InsertUserID']; $CategoryID = $Data['CategoryID']; } // Prep and fire event $this->EventArguments['DiscussionID'] = $DiscussionID; $this->EventArguments['Discussion'] = $Data; $this->fireEvent('DeleteDiscussion'); // Execute deletion of discussion and related bits $this->SQL->delete('Draft', array('DiscussionID' => $DiscussionID)); $Log = val('Log', $Options, true); $LogOptions = val('LogOptions', $Options, array()); if ($Log === true) { $Log = 'Delete'; } LogModel::BeginTransaction(); // Log all of the comment deletes. $Comments = $this->SQL->getWhere('Comment', array('DiscussionID' => $DiscussionID))->resultArray(); if (count($Comments) > 0 && count($Comments) < 50) { // A smaller number of comments should just be stored with the record. $Data['_Data']['Comment'] = $Comments; LogModel::insert($Log, 'Discussion', $Data, $LogOptions); } else { LogModel::insert($Log, 'Discussion', $Data, $LogOptions); foreach ($Comments as $Comment) { LogModel::insert($Log, 'Comment', $Comment, $LogOptions); } } LogModel::EndTransaction(); $this->SQL->delete('Comment', array('DiscussionID' => $DiscussionID)); $this->SQL->delete('Discussion', array('DiscussionID' => $DiscussionID)); $this->SQL->delete('UserDiscussion', array('DiscussionID' => $DiscussionID)); $this->UpdateDiscussionCount($CategoryID); // Get the user's discussion count. $this->UpdateUserDiscussionCount($UserID); // Update bookmark counts for users who had bookmarked this discussion foreach ($BookmarkData->result() as $User) { $this->SetUserBookmarkCount($User->UserID); } return true; }
/** * Increment/decrement discussion scores */ public function DiscussionController_VoteDiscussion_Create($Sender) { // if (!C('Plugins.Voting.Enabled')) // return; $DiscussionID = GetValue(0, $Sender->RequestArgs, 0); $TransientKey = GetValue(1, $Sender->RequestArgs); $VoteType = FALSE; if ($TransientKey == 'voteup' || $TransientKey == 'votedown') { $VoteType = $TransientKey; $TransientKey = GetValue(2, $Sender->RequestArgs); } $Session = Gdn::Session(); $NewUserVote = 0; $Total = 0; if ($Session->IsValid() && $Session->ValidateTransientKey($TransientKey) && $DiscussionID > 0) { $DiscussionModel = new DiscussionModel(); $OldUserVote = $DiscussionModel->GetUserScore($DiscussionID, $Session->UserID); if ($VoteType == 'voteup') { $NewUserVote = 1; } else { if ($VoteType == 'votedown') { $NewUserVote = -1; } else { $NewUserVote = $OldUserVote == 1 ? -1 : 1; } } $FinalVote = intval($OldUserVote) + intval($NewUserVote); // Allow admins to vote unlimited. $AllowVote = $Session->CheckPermission('Garden.Moderation.Manage'); // Only allow users to vote up or down by 1. if (!$AllowVote) { $AllowVote = $FinalVote > -2 && $FinalVote < 2; } if ($AllowVote) { $Total = $DiscussionModel->SetUserScore($DiscussionID, $Session->UserID, $FinalVote); } else { $Discussion = $DiscussionModel->GetID($DiscussionID); $Total = GetValue('Score', $Discussion, 0); $FinalVote = $OldUserVote; } // Move the comment into or out of moderation. if (class_exists('LogModel')) { $Moderate = FALSE; if ($Total <= C('Plugins.Voting.ModThreshold1', -10)) { $LogOptions = array('GroupBy' => array('RecordID')); // Get the comment row. if (isset($Discussion)) { $Data = (array) $Discussion; } else { $Data = (array) $DiscussionModel->GetID($DiscussionID); } if ($Data) { // Get the users that voted the comment down. $OtherUserIDs = $DiscussionModel->SQL->Select('UserID')->From('UserComment')->Where('CommentID', $DiscussionID)->Where('Score <', 0)->Get()->ResultArray(); $OtherUserIDs = array_column($OtherUserIDs, 'UserID'); $LogOptions['OtherUserIDs'] = $OtherUserIDs; // Add the comment to moderation. if ($Total > C('Plugins.Voting.ModThreshold2', -20)) { LogModel::Insert('Moderate', 'Discussion', $Data, $LogOptions); } } $Moderate = TRUE; } if ($Total <= C('Plugins.Voting.ModThreshold2', -20)) { // Remove the comment. $DiscussionModel->Delete($DiscussionID, array('Log' => 'Moderate')); $Sender->InformMessage(sprintf(T('The %s has been removed for moderation.'), T('discussion'))); } elseif ($Moderate) { $Sender->InformMessage(sprintf(T('The %s has been flagged for moderation.'), T('discussion'))); } } } $Sender->DeliveryType(DELIVERY_TYPE_BOOL); $Sender->SetJson('TotalScore', $Total); $Sender->SetJson('FinalVote', $FinalVote); $Sender->Render(); }
/** * Delete a comment. * * This is a hard delete that completely removes it from the database. * Events: DeleteComment, BeforeDeleteComment. * * @since 2.0.0 * @access public * * @param int $CommentID Unique ID of the comment to be deleted. * @param array $Options Additional options for the delete. * @param bool Always returns TRUE. */ public function delete($CommentID, $Options = array()) { $this->EventArguments['CommentID'] = $CommentID; $Comment = $this->getID($CommentID, DATASET_TYPE_ARRAY); if (!$Comment) { return false; } $Discussion = $this->SQL->getWhere('Discussion', array('DiscussionID' => $Comment['DiscussionID']))->firstRow(DATASET_TYPE_ARRAY); // Decrement the UserDiscussion comment count if the user has seen this comment $Offset = $this->GetOffset($CommentID); $this->SQL->update('UserDiscussion')->set('CountComments', 'CountComments - 1', false)->where('DiscussionID', $Comment['DiscussionID'])->where('CountComments >', $Offset)->put(); $this->EventArguments['Discussion'] = $Discussion; $this->fireEvent('DeleteComment'); $this->fireEvent('BeforeDeleteComment'); // Log the deletion. $Log = val('Log', $Options, 'Delete'); LogModel::insert($Log, 'Comment', $Comment, val('LogOptions', $Options, array())); // Delete the comment. $this->SQL->delete('Comment', array('CommentID' => $CommentID)); // Update the comment count $this->UpdateCommentCount($Discussion, array('Slave' => false)); // Update the user's comment count $this->UpdateUser($Comment['InsertUserID']); // Update the category. $Category = CategoryModel::categories(val('CategoryID', $Discussion)); if ($Category && $Category['LastCommentID'] == $CommentID) { $CategoryModel = new CategoryModel(); $CategoryModel->SetRecentPost($Category['CategoryID']); } // Clear the page cache. $this->RemovePageCache($Comment['DiscussionID']); return true; }
public function DeleteContent($UserID, $Options = array(), $Content = array()) { $Log = GetValue('Log', $Options); if ($Log === TRUE) { $Log = 'Delete'; } $Result = FALSE; // Fire an event so applications can remove their associated user data. $this->EventArguments['UserID'] = $UserID; $this->EventArguments['Options'] = $Options; $this->EventArguments['Content'] =& $Content; $this->FireEvent('BeforeDeleteUser'); $User = $this->GetID($UserID, DATASET_TYPE_ARRAY); if (!$Log) { $Content = NULL; } // Remove photos /*$PhotoData = $this->SQL->Select()->From('Photo')->Where('InsertUserID', $UserID)->Get(); foreach ($PhotoData->Result() as $Photo) { @unlink(PATH_UPLOADS.DS.$Photo->Name); } $this->SQL->Delete('Photo', array('InsertUserID' => $UserID)); */ // Remove invitations $this->GetDelete('Invitation', array('InsertUserID' => $UserID), $Content); $this->GetDelete('Invitation', array('AcceptedUserID' => $UserID), $Content); // Remove activities $this->GetDelete('Activity', array('InsertUserID' => $UserID), $Content); // Remove activity comments. $this->GetDelete('ActivityComment', array('InsertUserID' => $UserID), $Content); // Clear out information on the user. $this->SetField($UserID, array('About' => NULL, 'Title' => NULL, 'Location' => NULL)); if ($Log) { $User['_Data'] = $Content; unset($Content); // in case data gets copied $Result = LogModel::Insert($Log, 'User', $User, GetValue('LogOptions', $Options, array())); } return $Result; }