Exemplo n.º 1
0
function Expire_Old_Discussions(&$Context)
{
    // Force proper config values.
    $DaysOld = (int) @$Context->Configuration['Expire.DaysOld'];
    $Action = strtoupper(@$Context->Configuration['Expire.Action']);
    $IgnoreWhispers = (bool) @$Context->Configuration['Expire.IgnoreWhispers'];
    $Now = time();
    $ExpireDate = $Now - $DaysOld * 86400;
    if ($ExpireDate != $Now) {
        $SqlBuilder = $Context->ObjectFactory->NewContextObject($Context, 'SqlBuilder');
        $SqlBuilder->SetMainTable('Discussion', 'd');
        switch ($Action) {
            case 'SINK':
                $SqlBuilder->AddFieldNameValue('Sink', '1');
                break;
            case 'HIDE':
                $SqlBuilder->AddFieldNameValue('Active', '0');
                break;
            case 'CLOSE':
            default:
                $SqlBuilder->AddFieldNameValue('Closed', '1');
                break;
        }
        $SqlBuilder->AddWhere('d', 'Sticky', '', 0, '=');
        $SqlBuilder->AddWhere('d', 'DateLastActive', '', MySqlDateTime($ExpireDate), '<=');
        if (!$IgnoreWhispers) {
            $SqlBuilder->AddWhere('d', 'DateLastWhisper', '', MySqlDateTime($ExpireDate), '<=');
        }
        $Context->Database->Update($SqlBuilder, 'Expire', 'Expire_Old_Discussions', 'An error occurred while expiring old dicussions.');
    }
    // Update the last look time.
    $Context->Configuration['Expire.LastLook'] = 0;
    $SettingsFile = $Context->Configuration['APPLICATION_PATH'] . 'conf/settings.php';
    $SettingsManager = $Context->ObjectFactory->NewContextObject($Context, 'ConfigurationManager');
    $SettingsManager->DefineSetting('Expire.LastLook', $Now, 1);
    $SettingsManager->SaveSettingsToFile($SettingsFile);
    $Context->Configuration['Expire.LastLook'] = $Now;
}
Exemplo n.º 2
0
 function AttachmentsForm(&$Context)
 {
     $this->Name = 'AttachmentsForm';
     $this->ValidActions = array('Attachments', 'ProcessAttachments', 'ImportAttachments');
     $this->Constructor($Context);
     if (!$this->Context->Session->User->Permission('PERMISSION_MANAGE_ATTACHMENTS')) {
         $this->IsPostBack = 0;
     } elseif ($this->IsPostBack) {
         $SettingsFile = $this->Context->Configuration['APPLICATION_PATH'] . 'conf/settings.php';
         $this->ConfigurationManager = $this->Context->ObjectFactory->NewContextObject($this->Context, 'ConfigurationManager');
         if ($this->PostBackAction == 'ProcessAttachments') {
             $this->ConfigurationManager->GetSettingsFromForm($SettingsFile);
             // Checkboxes aren't posted back if unchecked, so make sure that they are saved properly
             $this->DelegateParameters['ConfigurationManager'] =& $this->ConfigurationManager;
             $this->CallDelegate('DefineCheckboxes');
             // And save everything
             if ($this->ConfigurationManager->SaveSettingsToFile($SettingsFile)) {
                 header('location: ' . GetUrl($this->Context->Configuration, 'settings.php', '', '', '', '', 'PostBackAction=Attachments&Success=1'));
             } else {
                 $this->PostBackAction = 'Attachments';
             }
         } elseif ($this->PostBackAction == 'ImportAttachments') {
             $s = $this->Context->ObjectFactory->NewContextObject($this->Context, 'SqlBuilder');
             $s->SetMainTable('Attachment', 'a');
             $s->AddWhere('a', 'MimeType', '', 'import', '=');
             $this->Context->Database->Delete($s, $this->Name, 'ImportAttachments', 'An error occured while deleting imported attachments.');
             $AttachmentManager = $this->Context->ObjectFactory->NewContextObject($this->Context, 'AttachmentManager');
             $Attachment = $this->Context->ObjectFactory->NewObject($this->Context, 'Attachment');
             $ImportPath = ForceIncomingString('AttachmentImportPath', '');
             foreach (glob($ImportPath . '*.*') as $FilePath) {
                 $FileName = basename($FilePath);
                 $CommentID = ForceInt(substr($FileName, 0, strpos($FileName, '.')), 0);
                 if ($CommentID > 0) {
                     $Attachment->Clear();
                     $Attachment->CommentID = $CommentID;
                     $s->Clear();
                     $s->SetMainTable('Comment', 'c');
                     $s->AddSelect(array('DiscussionID', 'AuthUserID'), 'c');
                     $s->AddWhere('c', 'CommentID', '', $CommentID, '=');
                     $ResultSet = $this->Context->Database->Select($s, $this->Name, 'ImportAttachments', 'An error occurred while attempting to retrieve the requested comment.');
                     while ($Row = $this->Context->Database->GetRow($ResultSet)) {
                         $Attachment->DiscussionID = ForceInt(@$Row['DiscussionID'], 0);
                         $Attachment->UserID = ForceInt(@$Row['AuthUserID'], 0);
                     }
                     $Attachment->Title = $FileName;
                     $Attachment->Name = $FileName;
                     $Attachment->Path = $FilePath;
                     $Attachment->Size = filesize($FilePath);
                     $Attachment->MimeType = 'import';
                     $Attachment->DateCreated = MySqlDateTime();
                     $Attachment->DateModified = MySqlDateTime();
                     $AttachmentManager->SaveAttachment($Attachment);
                 }
             }
             // Display normal settings form
             $this->PostBackAction = 'Attachments';
         }
     }
     $this->CallDelegate('Constructor');
 }