コード例 #1
0
ファイル: default.php プロジェクト: ru4/arabbnota
 public function Base_Render_Before(&$Sender)
 {
     $ConfigItem = C('WhosOnline.Location.Show', 'every');
     $Controller = $Sender->ControllerName;
     $Application = $Sender->ApplicationFolder;
     $Session = Gdn::Session();
     // Check if its visible to users
     if (C('WhosOnline.Hide', TRUE) && !$Session->IsValid()) {
         return;
     }
     $ShowOnController = array();
     switch ($ConfigItem) {
         case 'every':
             $ShowOnController = array('discussioncontroller', 'categoriescontroller', 'discussionscontroller', 'profilecontroller', 'activitycontroller');
             break;
         case 'discussion':
         default:
             $ShowOnController = array('discussioncontroller', 'discussionscontroller', 'categoriescontroller');
     }
     if (!InArrayI($Controller, $ShowOnController)) {
         return;
     }
     $UserMetaData = $this->GetUserMeta($Session->UserID, '%');
     include_once PATH_PLUGINS . DS . 'WhosOnline' . DS . 'class.whosonlinemodule.php';
     $WhosOnlineModule = new WhosOnlineModule($Sender);
     $WhosOnlineModule->GetData(ArrayValue('Plugin.WhosOnline.Invisible', $UserMetaData));
     $Sender->AddModule($WhosOnlineModule);
     $Sender->AddJsFile('/plugins/WhosOnline/whosonline.js');
     $Frequency = C('WhosOnline.Frequency', 4);
     if (!is_numeric($Frequency)) {
         $Frequency = 4;
     }
     $Sender->AddDefinition('WhosOnlineFrequency', $Frequency);
 }
コード例 #2
0
ファイル: class.hooks.php プロジェクト: sheldon/Garden
 public function Base_Render_Before(&$Sender)
 {
     $Session = Gdn::Session();
     // Enable theme previewing
     if ($Session->IsValid()) {
         $PreviewThemeFolder = $Session->GetPreference('PreviewThemeFolder', '');
         // echo 'test'.$PreviewThemeFolder;
         if ($PreviewThemeFolder != '') {
             $Sender->Theme = $PreviewThemeFolder;
             $Sender->AddAsset('Content', $Sender->FetchView('previewtheme', 'settingscontroller', 'dashboard'));
             $Sender->AddCssFile('previewtheme.css');
         }
     }
     // Add Message Modules (if necessary)
     $MessageCache = Gdn::Config('Garden.Messages.Cache', array());
     $Location = $Sender->Application . '/' . substr($Sender->ControllerName, 0, -10) . '/' . $Sender->RequestMethod;
     if ($Sender->MasterView != 'empty' && in_array('Base', $MessageCache) || InArrayI($Location, $MessageCache)) {
         $MessageModel = new MessageModel();
         $MessageData = $MessageModel->GetMessagesForLocation($Location);
         foreach ($MessageData as $Message) {
             $MessageModule = new MessageModule($Sender, $Message);
             $Sender->AddModule($MessageModule);
         }
     }
 }
コード例 #3
0
ファイル: default.php プロジェクト: seedbank/old-repo
 public function Base_Render_Before(&$Sender)
 {
     $Controller = $Sender->ControllerName;
     if (!InArrayI($Controller, array('categoriescontroller', 'discussioncontroller', 'discussionscontroller', 'messagescontroller', 'profilecontroller'))) {
         return;
     }
     $RecentActivityModule = new RecentActivityModule($Sender);
     $RecentActivityModule->GetData(10);
     $Sender->addModule($RecentActivityModule);
 }
コード例 #4
0
ファイル: default.php プロジェクト: Nordic-T/Nordic-T
 public function Base_Render_Before($Sender)
 {
     $Controller = $Sender->ControllerName;
     $ShowOnController = array('discussioncontroller', 'categoriescontroller', 'discussionscontroller', 'profilecontroller', 'activitycontroller');
     if (!InArrayI($Controller, $ShowOnController)) {
         return;
     }
     $Sender->AddCssFile('forumdonate.css', 'plugins/ForumDonate');
     $ForumDonateModule = new ForumDonateModule($Sender);
     $Sender->AddModule($ForumDonateModule);
 }
コード例 #5
0
ファイル: default.php プロジェクト: SatiricMan/addons
 /**
  * Call in module here, to have it placed in the panel on every page that 
  * has the panel area. No need to create custom controllers, so this is 
  * good enough for the task. 
  */
 public function Base_Render_Before(&$Sender)
 {
     $Session = Gdn::Session();
     $Controller = $Sender->ControllerName;
     // Only show on these pages
     $ShowOnController = array('discussioncontroller', 'categoriescontroller', 'discussionscontroller', 'profilecontroller', 'activitycontroller');
     // Only display this info to signed in members.
     if ($Session->IsValid() && InArrayI($Controller, $ShowOnController)) {
         $Sender->AddCssFile($this->GetResource('design/countriesonline.css', FALSE, FALSE));
         include_once PATH_PLUGINS . DS . 'CountriesOnline' . DS . 'class.countriesonlinemodule.php';
         $CountriesOnlineModule = new CountriesOnlineModule($Sender);
         $time_threshold = C('Plugin.CountriesOnline.TimeThreshold', $this->default_time_threshold);
         $CountriesOnlineModule->GetData($time_threshold);
         $Sender->AddModule($CountriesOnlineModule);
     }
 }
コード例 #6
0
ファイル: hooks.php プロジェクト: Valooo/Garden
 public function Base_Render_Before(&$Sender)
 {
     // Add menu items.
     $Session = Gdn::Session();
     if ($Sender->Menu) {
         $Sender->Menu->AddLink('Dashboard', 'Dashboard', '/garden/settings', array('Garden.Settings.Manage'));
         $Sender->Menu->AddLink('Dashboard', 'Users', '/user/browse', array('Garden.Users.Add', 'Garden.Users.Edit', 'Garden.Users.Delete'));
         $Sender->Menu->AddLink('Activity', 'Activity', '/activity');
         $Authenticator = Gdn::Authenticator();
         if ($Session->IsValid()) {
             $Sender->Menu->AddLink('SignOut', 'Sign Out', '/entry/leave/{Session_TransientKey}', FALSE, array('class' => 'NonTab'));
             $Notifications = Gdn::Translate('Notifications');
             $CountNotifications = $Session->User->CountNotifications;
             if (is_numeric($CountNotifications) && $CountNotifications > 0) {
                 $Notifications .= '<span>' . $CountNotifications . '</span>';
             }
             $Sender->Menu->AddLink('User', '{Username}', '/profile/{Username}', array('Garden.SignIn.Allow'));
             $Sender->Menu->AddLink('User', '\\' . $Notifications, 'profile/notifications/{Username}');
         } else {
             $Sender->Menu->AddLink('Entry', 'Sign In', $Authenticator->SignInUrl());
         }
     }
     // Enable theme previewing
     if ($Session->IsValid()) {
         $PreviewTheme = $Session->GetPreference('PreviewTheme', '');
         if ($PreviewTheme != '') {
             $Sender->Theme = $PreviewTheme;
         }
     }
     // Add Message Modules (if necessary)
     $MessageCache = Gdn::Config('Garden.Messages.Cache', array());
     $Location = $Sender->Application . '/' . substr($Sender->ControllerName, 0, -10) . '/' . $Sender->RequestMethod;
     if (in_array('Base', $MessageCache) || InArrayI($Location, $MessageCache)) {
         $MessageModel = new Gdn_MessageModel();
         $MessageData = $MessageModel->GetMessagesForLocation($Location);
         foreach ($MessageData as $Message) {
             $MessageModule = new Gdn_MessageModule($Sender, $Message);
             $Sender->AddModule($MessageModule);
         }
     }
 }
コード例 #7
0
ファイル: class.hooks.php プロジェクト: kennyma/Garden
 public function Base_Render_Before(&$Sender)
 {
     $Session = Gdn::Session();
     // Enable theme previewing
     if ($Session->IsValid()) {
         $PreviewThemeFolder = $Session->GetPreference('PreviewThemeFolder', '');
         // echo 'test'.$PreviewThemeFolder;
         if ($PreviewThemeFolder != '') {
             $Sender->Theme = $PreviewThemeFolder;
             $Sender->AddAsset('Content', $Sender->FetchView('previewtheme', 'settingscontroller', 'dashboard'));
             $Sender->AddCssFile('previewtheme.css');
         }
     }
     // Add Message Modules (if necessary)
     $MessageCache = Gdn::Config('Garden.Messages.Cache', array());
     $Location = $Sender->Application . '/' . substr($Sender->ControllerName, 0, -10) . '/' . $Sender->RequestMethod;
     $Exceptions = array('[Base]');
     if ($Sender->MasterView == 'admin') {
         $Exceptions[] = '[Admin]';
     } else {
         if (in_array($Sender->MasterView, array('', 'default'))) {
             $Exceptions[] = '[NonAdmin]';
         }
     }
     if ($Sender->MasterView != 'empty' && ArrayInArray($Exceptions, $MessageCache, FALSE) || InArrayI($Location, $MessageCache)) {
         $MessageModel = new MessageModel();
         $MessageData = $MessageModel->GetMessagesForLocation($Location, $Exceptions);
         foreach ($MessageData as $Message) {
             $MessageModule = new MessageModule($Sender, $Message);
             $Sender->AddModule($MessageModule);
         }
     }
     // If there are applicants, alert admins by showing in the main menu
     if (in_array($Sender->MasterView, array('', 'default')) && $Sender->Menu && C('Garden.Registration.Method') == 'Approval') {
         $CountApplicants = Gdn::UserModel()->GetApplicants()->NumRows();
         if ($CountApplicants > 0) {
             $Sender->Menu->AddLink('Applicants', T('Applicants') . ' <span>' . $CountApplicants . '</span>', '/dashboard/user/applicants', array('Garden.Registration.Manage'));
         }
     }
 }
コード例 #8
0
ファイル: class.upload.php プロジェクト: Beyzie/Garden
 /**
  * Validates the uploaded file. Returns the temporary name of the uploaded file.
  */
 public function ValidateUpload($InputName)
 {
     if (!array_key_exists($InputName, $_FILES) || !is_uploaded_file($_FILES[$InputName]['tmp_name'])) {
         throw new Exception(Gdn::Translate('The file failed to upload.'));
     }
     switch ($_FILES[$InputName]['error']) {
         case 1:
         case 2:
             throw new Exception(Gdn::Translate('The file is too large to be uploaded to this application.'));
             break;
         case 3:
         case 4:
             throw new Exception(Gdn::Translate('The file failed to upload.'));
             break;
         case 6:
             throw new Exception(Gdn::Translate('The temporary upload folder has not been configured.'));
             break;
         case 7:
             throw new Exception(Gdn::Translate('Failed to write the file to disk.'));
             break;
         case 8:
             throw new Exception(Gdn::Translate('The upload was stopped by extension.'));
             break;
     }
     // Check the maxfilesize again just in case the value was spoofed in the form.
     if (filesize($_FILES[$InputName]['tmp_name']) > $this->_MaxFileSize) {
         throw new Exception(Gdn::Translate('The file is too large to be uploaded to this application.'));
     }
     // Make sure that the file extension is allowed
     $Extension = pathinfo($_FILES[$InputName]['name'], PATHINFO_EXTENSION);
     if (!InArrayI($Extension, $this->_AllowedFileExtensions)) {
         throw new Exception(sprintf(Gdn::Translate('You cannot upload files with this extension (%s).'), $Extension));
     }
     // If all validations were successful, return the tmp name/location of the file.
     $this->_UploadedFile = $_FILES[$InputName];
     return $this->_UploadedFile['tmp_name'];
 }
コード例 #9
0
ファイル: default.php プロジェクト: ru4/arabbnota
 public function Base_Render_Before(&$Sender)
 {
     $ConfigItem = Gdn::Config('LatestComment.Location.Show', 'every');
     $Controller = $Sender->ControllerName;
     $Application = $Sender->ApplicationFolder;
     $Session = Gdn::Session();
     $ShowOnController = array();
     switch ($ConfigItem) {
         case 'every':
             $ShowOnController = array('discussioncontroller', 'categoriescontroller', 'discussionscontroller', 'profilecontroller', 'activitycontroller', 'draftscontroller', 'messagescontroller');
             break;
         case 'discussion':
             $ShowOnController = array('discussioncontroller', 'discussionscontroller', 'categoriescontroller', 'draftscontroller');
             break;
         case 'profile':
             $ShowOnController = array('profilecontroller', 'messagescontroller');
             break;
         case 'activity':
             $ShowOnController = array('activitycontroller');
             break;
         default:
             $ShowOnController = array('discussioncontroller', 'categoriescontroller', 'discussionscontroller', 'profilecontroller', 'activitycontroller', 'draftscontroller', 'messagescontroller');
     }
     if (!InArrayI($Controller, $ShowOnController)) {
         return;
     }
     include_once PATH_PLUGINS . DS . 'LatestComment' . DS . 'class.latestcommentmodule.php';
     $LatestCommentModule = new LatestCommentModule($Sender);
     $LatestCommentModule->GetData();
     $Sender->AddModule($LatestCommentModule);
     $Limit = Gdn::Config('LatestComment.Limit', 10);
     if (!is_numeric($Limit)) {
         $Limit = 10;
     }
     $Sender->AddDefinition('LatestComment', $Limit);
 }
コード例 #10
0
ファイル: class.upload.php プロジェクト: rnovino/Garden
 /**
  * Validates the uploaded file. Returns the temporary name of the uploaded file.
  */
 public function ValidateUpload($InputName, $ThrowException = TRUE)
 {
     $Ex = FALSE;
     if (!array_key_exists($InputName, $_FILES) || !is_uploaded_file($_FILES[$InputName]['tmp_name']) && GetValue('error', $_FILES[$InputName], 0) == 0) {
         // Check the content length to see if we exceeded the max post size.
         $ContentLength = Gdn::Request()->GetValueFrom('server', 'CONTENT_LENGTH');
         $MaxPostSize = self::UnformatFileSize(ini_get('post_max_size'));
         if ($ContentLength > $MaxPostSize) {
             $Ex = sprintf(T('Gdn_Upload.Error.MaxPostSize', 'The file is larger than the maximum post size. (%s)'), self::FormatFileSize($MaxPostSize));
         } else {
             $Ex = T('The file failed to upload.');
         }
     } else {
         switch ($_FILES[$InputName]['error']) {
             case 1:
             case 2:
                 $MaxFileSize = self::UnformatFileSize(ini_get('upload_max_filesize'));
                 $Ex = sprintf(T('Gdn_Upload.Error.PhpMaxFileSize', 'The file is larger than the server\'s maximum file size. (%s)'), self::FormatFileSize($MaxFileSize));
                 break;
             case 3:
             case 4:
                 $Ex = T('The file failed to upload.');
                 break;
             case 6:
                 $Ex = T('The temporary upload folder has not been configured.');
                 break;
             case 7:
                 $Ex = T('Failed to write the file to disk.');
                 break;
             case 8:
                 $Ex = T('The upload was stopped by extension.');
                 break;
         }
     }
     $Foo = self::FormatFileSize($this->_MaxFileSize);
     // Check the maxfilesize again just in case the value was spoofed in the form.
     if (!$Ex && $this->_MaxFileSize > 0 && filesize($_FILES[$InputName]['tmp_name']) > $this->_MaxFileSize) {
         $Ex = sprintf(T('Gdn_Upload.Error.MaxFileSize', 'The file is larger than the maximum file size. (%s)'), self::FormatFileSize($this->_MaxFileSize));
     } elseif (!$Ex) {
         // Make sure that the file extension is allowed.
         $Extension = pathinfo($_FILES[$InputName]['name'], PATHINFO_EXTENSION);
         if (!InArrayI($Extension, $this->_AllowedFileExtensions)) {
             $Ex = sprintf(T('You cannot upload files with this extension (%s). Allowed extension(s) are %s.'), $Extension, implode(', ', $this->_AllowedFileExtensions));
         }
     }
     if ($Ex) {
         if ($ThrowException) {
             throw new Gdn_UserException($Ex);
         } else {
             $this->Exception = $Ex;
             return FALSE;
         }
     } else {
         // If all validations were successful, return the tmp name/location of the file.
         $this->_UploadedFile = $_FILES[$InputName];
         return $this->_UploadedFile['tmp_name'];
     }
 }
コード例 #11
0
ファイル: class.form.php プロジェクト: Beyzie/Garden
 /**
  * Returns the xhtml for a text-based input.
  *
  * @param string $FieldName The name of the field that is being displayed/posted with this input. It
  *  should related directly to a field name in $this->_DataArray.
  * @param array $Attributes An associative array of attributes for the input. ie. maxlength, onclick,
  *  class, etc
  * @return string
  */
 public function TextBox($FieldName, $Attributes = FALSE)
 {
     if (!is_array($Attributes)) {
         $Attributes = array();
     }
     $MultiLine = ArrayValueI('MultiLine', $Attributes);
     if ($MultiLine) {
         if (!InArrayI('rows', $Attributes)) {
             $Attributes['rows'] = '6';
         }
         // For xhtml compliance
         if (!InArrayI('cols', $Attributes)) {
             $Attributes['cols'] = '100';
         }
         // For xhtml compliance
     }
     $CssClass = ArrayValueI('class', $Attributes);
     if ($CssClass == FALSE) {
         $Attributes['class'] = $MultiLine ? 'TextBox' : 'InputBox';
     }
     $Return = $MultiLine === TRUE ? '<textarea' : '<input type="text"';
     $Return .= $this->_IDAttribute($FieldName, $Attributes);
     $Return .= $this->_NameAttribute($FieldName, $Attributes);
     $Return .= $MultiLine === TRUE ? '' : $this->_ValueAttribute($FieldName, $Attributes);
     $Return .= $this->_AttributesToString($Attributes);
     $Value = ArrayValueI('value', $Attributes, $this->GetValue($FieldName));
     $Return .= $MultiLine === TRUE ? '>' . htmlentities($Value, ENT_COMPAT, 'UTF-8') . '</textarea>' : ' />';
     return $Return;
 }
コード例 #12
0
ファイル: class.hooks.php プロジェクト: rnovino/Garden
 /**
  *
  * @param Gdn_Controller $Sender
  */
 public function Base_Render_Before($Sender)
 {
     $Session = Gdn::Session();
     // Enable theme previewing
     if ($Session->IsValid()) {
         $PreviewThemeName = $Session->GetPreference('PreviewThemeName', '');
         $PreviewThemeFolder = $Session->GetPreference('PreviewThemeFolder', '');
         if ($PreviewThemeName != '') {
             $Sender->Theme = $PreviewThemeName;
             $Sender->InformMessage(sprintf(T('You are previewing the %s theme.'), Wrap($PreviewThemeName, 'em')) . '<div class="PreviewThemeButtons">' . Anchor(T('Apply'), 'settings/themes/' . $PreviewThemeName . '/' . $Session->TransientKey(), 'PreviewThemeButton') . ' ' . Anchor(T('Cancel'), 'settings/cancelpreview/', 'PreviewThemeButton') . '</div>', 'DoNotDismiss');
         }
     }
     if ($Session->IsValid() && ($EmailKey = Gdn::Session()->GetAttribute('EmailKey'))) {
         $NotifyEmailConfirm = TRUE;
         // If this user was manually moved out of the confirmation role, get rid of their 'awaiting confirmation' flag
         $ConfirmEmailRole = C('Garden.Registration.ConfirmEmailRole', FALSE);
         $UserRoles = array();
         $RoleData = Gdn::UserModel()->GetRoles($Session->UserID);
         if ($RoleData !== FALSE && $RoleData->NumRows() > 0) {
             $UserRoles = ConsolidateArrayValuesByKey($RoleData->Result(DATASET_TYPE_ARRAY), 'RoleID', 'Name');
         }
         if ($ConfirmEmailRole !== FALSE && !array_key_exists($ConfirmEmailRole, $UserRoles)) {
             Gdn::UserModel()->SaveAttribute($Session->UserID, "EmailKey", NULL);
             $NotifyEmailConfirm = FALSE;
         }
         if ($NotifyEmailConfirm) {
             $Message = FormatString(T('You need to confirm your email address.', 'You need to confirm your email address. Click <a href="{/entry/emailconfirmrequest,url}">here</a> to resend the confirmation email.'));
             $Sender->InformMessage($Message, '');
         }
     }
     // Add Message Modules (if necessary)
     $MessageCache = Gdn::Config('Garden.Messages.Cache', array());
     $Location = $Sender->Application . '/' . substr($Sender->ControllerName, 0, -10) . '/' . $Sender->RequestMethod;
     $Exceptions = array('[Base]');
     // 2011-09-09 - mosullivan - No longer allowing messages in dashboard
     //		if ($Sender->MasterView == 'admin')
     //			$Exceptions[] = '[Admin]';
     //		else if (in_array($Sender->MasterView, array('', 'default')))
     if (in_array($Sender->MasterView, array('', 'default'))) {
         $Exceptions[] = '[NonAdmin]';
     }
     // SignIn popup is a special case
     $SignInOnly = $Sender->DeliveryType() == DELIVERY_TYPE_VIEW && $Location == 'Dashboard/entry/signin';
     if ($SignInOnly) {
         $Exceptions = array();
     }
     if ($Sender->MasterView != 'admin' && (GetValue('MessagesLoaded', $Sender) != '1' && $Sender->MasterView != 'empty' && ArrayInArray($Exceptions, $MessageCache, FALSE) || InArrayI($Location, $MessageCache))) {
         $MessageModel = new MessageModel();
         $MessageData = $MessageModel->GetMessagesForLocation($Location, $Exceptions);
         foreach ($MessageData as $Message) {
             $MessageModule = new MessageModule($Sender, $Message);
             if ($SignInOnly) {
                 // Insert special messages even in SignIn popup
                 echo $MessageModule;
             } elseif ($Sender->DeliveryType() == DELIVERY_TYPE_ALL) {
                 $Sender->AddModule($MessageModule);
             }
         }
         $Sender->MessagesLoaded = '1';
         // Fixes a bug where render gets called more than once and messages are loaded/displayed redundantly.
     }
     // If there are applicants, alert admins by showing in the main menu
     if (in_array($Sender->MasterView, array('', 'default')) && $Sender->Menu && C('Garden.Registration.Method') == 'Approval') {
         // $CountApplicants = Gdn::UserModel()->GetApplicantCount();
         // if ($CountApplicants > 0)
         // $Sender->Menu->AddLink('Applicants', T('Applicants').' <span class="Alert">'.$CountApplicants.'</span>', '/dashboard/user/applicants', array('Garden.Applicants.Manage'));
         $Sender->Menu->AddLink('Applicants', T('Applicants'), '/dashboard/user/applicants', array('Garden.Applicants.Manage'));
     }
     if ($Sender->DeliveryType() == DELIVERY_TYPE_ALL) {
         $Gdn_Statistics = Gdn::Factory('Statistics');
         $Gdn_Statistics->Check($Sender);
     }
     // Allow forum embedding
     if (C('Garden.Embed.Allow')) {
         // Record the remote url where the forum is being embedded.
         $RemoteUrl = C('Garden.Embed.RemoteUrl');
         if (!$RemoteUrl) {
             $RemoteUrl = GetIncomingValue('remote');
             if ($RemoteUrl) {
                 SaveToConfig('Garden.Embed.RemoteUrl', $RemoteUrl);
             }
         }
         if ($RemoteUrl) {
             $Sender->AddDefinition('RemoteUrl', $RemoteUrl);
         }
         // Force embedding?
         if (!IsSearchEngine() && !IsMobile()) {
             $Sender->AddDefinition('ForceEmbedForum', C('Garden.Embed.ForceForum') ? '1' : '0');
             $Sender->AddDefinition('ForceEmbedDashboard', C('Garden.Embed.ForceDashboard') ? '1' : '0');
         }
         $Sender->AddDefinition('Path', Gdn::Request()->Path());
         // $Sender->AddDefinition('MasterView', $Sender->MasterView);
         $Sender->AddDefinition('InDashboard', $Sender->MasterView == 'admin' ? '1' : '0');
         $Sender->AddJsFile('js/embed_local.js');
     }
     // Allow return to mobile site
     $ForceNoMobile = Gdn_CookieIdentity::GetCookiePayload('VanillaNoMobile');
     if ($ForceNoMobile !== FALSE && is_array($ForceNoMobile) && in_array('force', $ForceNoMobile)) {
         $Sender->AddAsset('Foot', Wrap(Anchor(T('Back to Mobile Site'), '/profile/nomobile/1'), 'div'), 'MobileLink');
     }
 }
コード例 #13
0
ファイル: upgrade.php プロジェクト: nbudin/Garden
 public function OldIndex($Step = 0)
 {
     $this->Permission('Garden.Data.Import');
     // This permission doesn't exist, so only users with Admin == '1' will succeed.
     $this->AddJsFile('upgrade.js', 'vanilla');
     $Step = is_numeric($Step) && $Step >= 0 && $Step < 20 ? $Step : '';
     $Database = Gdn::Database();
     $Construct = $Database->Structure();
     $PDO = $Database->Connection();
     $SourcePrefix = Gdn::Config('Garden.Import.SourcePrefix', 'LUM_');
     $DestPrefix = Gdn::Config('Database.DatabasePrefix', '');
     if ($Step == 0) {
         $this->View = 'import';
         if ($this->Form->AuthenticatedPostBack()) {
             // Make sure that all of the destination tables exist (assuming that
             // columns are there if tables are there since they were likely just
             // installed moments ago).
             $DbTables = $Database->SQL()->FetchTables();
             $DestTables = explode(',', 'Role,User,UserRole,Conversation,ConversationMessage,UserConversation,Category,Discussion,Comment,UserDiscussion');
             for ($i = 0; $i < count($DestTables); ++$i) {
                 $Table = $DestPrefix . $DestTables[$i];
                 if (!InArrayI($Table, $DbTables)) {
                     $this->Form->AddError('The "' . $Table . '" table is required for import.');
                     break;
                 }
             }
             if ($this->Form->ErrorCount() == 0) {
                 // Make sure that all of the source tables & columns exist.
                 $SourcePrefix = $this->Form->GetFormValue('SourcePrefix');
                 $SourceTables = explode(',', 'Role,User,UserRoleHistory,UserDiscussionWatch,UserBookmark,Category,Discussion,Comment');
                 for ($i = 0; $i < count($SourceTables); ++$i) {
                     $Table = $SourcePrefix . $SourceTables[$i];
                     if (!InArrayI($Table, $DbTables)) {
                         $this->Form->AddError('The "' . $Table . '" source table was not found. Are you sure "' . $SourcePrefix . '" is the correct table prefix for your Vanilla 1 tables?');
                         break;
                     }
                     $Columns = $Database->SQL()->FetchColumns($Table);
                     switch ($SourceTables[$i]) {
                         case 'Role':
                             $RequiredColumns = explode(',', 'RoleID,Name,Description');
                             break;
                         case 'User':
                             $RequiredColumns = explode(',', 'UserID,RoleID,Name,Email,UtilizeEmail,CountVisit,Discovery,DateFirstVisit,DateLastActive,DateFirstVisit,DateLastActive,CountDiscussions,CountComments');
                             break;
                         case 'UserRoleHistory':
                             $RequiredColumns = explode(',', 'UserID,RoleID,AdminUserID,Notes,Date');
                             break;
                         case 'UserDiscussionWatch':
                             $RequiredColumns = explode(',', 'UserID,DiscussionID,CountComments,LastViewed');
                             break;
                         case 'UserBookmark':
                             $RequiredColumns = explode(',', 'UserID,DiscussionID');
                             break;
                         case 'Category':
                             $RequiredColumns = explode(',', 'CategoryID,Name,Description,Priority');
                             break;
                         case 'Discussion':
                             $RequiredColumns = explode(',', 'DiscussionID,CategoryID,AuthUserID,LastUserID,WhisperUserID,Active,Name,CountComments,Closed,Sticky,Sink,DateCreated,DateLastActive');
                             break;
                         case 'Comment':
                             $RequiredColumns = explode(',', 'CommentID,DiscussionID,AuthUserID,EditUserID,WhisperUserID,Deleted,Body,FormatType,DateCreated,DateEdited');
                             break;
                         default:
                             $RequiredColumns = array();
                             break;
                     }
                     if (is_array($RequiredColumns)) {
                         for ($j = 0; $j < count($RequiredColumns); ++$j) {
                             if (!InArrayI($RequiredColumns[$j], $Columns)) {
                                 $this->Form->AddError('The "' . $Table . '" source table does not have the "' . $RequiredColumns[$j] . '" column.');
                                 break;
                             }
                         }
                     }
                 }
             }
             // If there were no errors...
             if ($this->Form->ErrorCount() == 0) {
                 // Save the sourceprefix
                 SaveToConfig('Garden.Import.SourcePrefix', $SourcePrefix);
                 // Proceed with the next step
                 $this->Message = T('<strong>1/19</strong> Checking source & destination tables.');
                 $this->View = 'index';
                 $this->RedirectUrl = Url('/upgrade/1');
                 if ($this->DeliveryType() == DELIVERY_TYPE_ALL) {
                     Redirect('/upgrade/1');
                 }
             }
         }
     } else {
         if ($Step == 1) {
             // 1. Add Import IDs to various tables where necessary
             $Construct->Table('Role')->Column('ImportID', 'int', TRUE, 'key')->Set();
             $Construct->Table('User')->Column('ImportID', 'int', TRUE, 'key')->Set();
             $Construct->Table('Category')->Column('ImportID', 'int', TRUE, 'key')->Set();
             $Construct->Table('Discussion')->Column('ImportID', 'int', TRUE, 'key')->Set();
             $Construct->DatabasePrefix($SourcePrefix);
             $Construct->Table('Comment')->Column('ConversationID', 'int', TRUE, 'key')->Set();
             $Construct->DatabasePrefix($DestPrefix);
             $this->Message = T('<strong>2/19</strong> Preparing tables for import.');
             $this->RedirectUrl = Url('/upgrade/2');
         } else {
             if ($Step == 2) {
                 // 2. Move roles from old database into new one.
                 $RoleModel = new Gdn_RoleModel();
                 // Get the old roles
                 $OldRoles = $Database->Query('select * from ' . $SourcePrefix . 'Role');
                 // Loop through each, inserting if it doesn't exist and updating ImportID if it does
                 foreach ($OldRoles->Result() as $OldRole) {
                     $RoleData = $Database->Query("select * from " . $DestPrefix . "Role where Name = " . $PDO->quote($OldRole->Name));
                     if ($RoleData->NumRows() == 0) {
                         $Role = array();
                         $Role['ImportID'] = $OldRole->RoleID;
                         $Role['Name'] = $OldRole->Name;
                         $Role['Description'] = $OldRole->Description;
                         $RoleModel->Save($Role);
                     } else {
                         $Database->Query("update " . $DestPrefix . "Role set ImportID = '" . $OldRole->RoleID . "' where RoleID = " . $RoleData->FirstRow()->RoleID);
                     }
                 }
                 $this->Message = T('<strong>3/19</strong> Importing roles.');
                 $this->RedirectUrl = Url('/upgrade/3');
             } else {
                 if ($Step == 3) {
                     // 3. Import users
                     $Database->Query("insert into " . $DestPrefix . "User\n         (Name, Password, Email, ShowEmail,    Gender, CountVisits, CountInvitations, InviteUserID, DiscoveryText, Preferences, Permissions, Attributes, DateSetInvitations, DateOfBirth, DateFirstVisit, DateLastActive, DateInserted,   DateUpdated,    HourOffset, About, CountNotifications, CountUnreadConversations, CountDiscussions, CountUnreadDiscussions, CountComments, CountDrafts, CountBookmarks, ImportID) select\n          Name, Password, Email, UtilizeEmail, 'm',    CountVisit,  0,                null,         Discovery,     null,        null,        null,       null,               null,        DateFirstVisit, DateLastActive, DateFirstVisit, DateLastActive, 0,          null,  0,                  0,                        CountDiscussions, 0,                      CountComments, 0,           0,              UserID\n         from " . $SourcePrefix . "User");
                     $this->Message = T('<strong>4/19</strong> Importing users.');
                     $this->RedirectUrl = Url('/upgrade/4');
                 } else {
                     if ($Step == 4) {
                         // 4. Import user role relationships
                         $Database->Query("insert into " . $DestPrefix . "UserRole\n         (UserID, RoleID)\n         select u.UserID, r.RoleID\n         from " . $DestPrefix . "User u\n         inner join " . $SourcePrefix . "User ou\n            on u.ImportID = ou.UserID\n         inner join " . $DestPrefix . "Role r\n            on ou.RoleID = r.ImportID");
                         $this->Message = T('<strong>5/19</strong> Importing user/role relationships.');
                         $this->RedirectUrl = Url('/upgrade/5');
                     } else {
                         if ($Step == 5) {
                             // 5. Import user role history into activity table
                             $Database->Query("insert into " . $DestPrefix . "Activity\n         (ActivityTypeID, ActivityUserID, RegardingUserID, Story, InsertUserID, DateInserted)\n         select 9, au.UserID, nu.UserID, concat('Assigned to ', r.Name, ' Role <blockquote>', rh.Notes, '</blockquote>'), au.UserID, rh.Date\n         from " . $SourcePrefix . "UserRoleHistory rh\n         inner join " . $SourcePrefix . "Role r\n            on rh.RoleID = r.RoleID\n         inner join " . $SourcePrefix . "User u\n            on rh.UserID = u.UserID\n         inner join " . $DestPrefix . "User nu\n            on u.UserID = nu.ImportID\n         inner join " . $DestPrefix . "User au\n            on rh.AdminUserID = au.ImportID\n         order by rh.Date asc");
                             $this->Message = T('<strong>6/19</strong> Importing role histories.');
                             $this->RedirectUrl = Url('/upgrade/6');
                         } else {
                             if ($Step == 6) {
                                 // 6. Update the WhisperUserID on all comments that are within whispered discussions
                                 $Database->Query("update " . $SourcePrefix . "Comment c\n         join " . $SourcePrefix . "Discussion d\n           on c.DiscussionID = d.DiscussionID\n         set c.WhisperUserID = d.WhisperUserID\n         where d.WhisperUserID > 0\n           and c.AuthUserID <> d.WhisperUserID");
                                 $Database->Query("update " . $SourcePrefix . "Comment c\n         join " . $SourcePrefix . "Discussion d\n           on c.DiscussionID = d.DiscussionID\n         set c.WhisperUserID = d.AuthUserID\n         where d.WhisperUserID > 0\n           and c.AuthUserID <> d.AuthUserID");
                                 $this->Message = T('<strong>7/19</strong> Preparing whispers.');
                                 $this->RedirectUrl = Url('/upgrade/7');
                             } else {
                                 if ($Step == 7) {
                                     // 7. Create conversations
                                     $Database->Query("insert into " . $DestPrefix . "Conversation\n         (InsertUserID, DateInserted, UpdateUserID, DateUpdated, Contributors)\n         select AuthUserID, now(), WhisperUserID, now(), ''\n         from " . $SourcePrefix . "Comment\n         where WhisperUserID > 0\n         group by AuthUserID, WhisperUserID");
                                     // 7b. Remove duplicate combinations
                                     $Database->Query("delete " . $DestPrefix . "Conversation c\n         from " . $DestPrefix . "Conversation c\n         join " . $DestPrefix . "Conversation c2\n           on c.InsertUserID = c2.UpdateUserID\n           and c.UpdateUserID = c2.InsertUserID\n         where c.ConversationID > c2.ConversationID");
                                     $this->Message = T('<strong>8/19</strong> Creating conversations.');
                                     $this->RedirectUrl = Url('/upgrade/8');
                                 } else {
                                     if ($Step == 8) {
                                         // 8. Update old comment table with conversation ids
                                         $Database->Query("update " . $SourcePrefix . "Comment cm\n         inner join " . $DestPrefix . "Conversation cn\n           on cm.AuthUserID = cn.InsertUserID\n           and cm.WhisperUserID = cn.UpdateUserID\n         set cm.ConversationID = cn.ConversationID");
                                         $Database->Query("update " . $SourcePrefix . "Comment cm\n         inner join " . $DestPrefix . "Conversation cn\n           on cm.WhisperUserID = cn.InsertUserID\n           and cm.AuthUserID = cn.UpdateUserID\n         set cm.ConversationID = cn.ConversationID");
                                         $this->Message = T('<strong>9/19</strong> Preparing conversations messages.');
                                         $this->RedirectUrl = Url('/upgrade/9');
                                     } else {
                                         if ($Step == 9) {
                                             // 9. Insert whispers as conversation messages
                                             $Database->Query("insert into " . $DestPrefix . "ConversationMessage\n         (ConversationID, Body, InsertUserID, DateInserted)\n         select cm.ConversationID, cm.Body, nu.UserID, cm.DateCreated\n         from " . $SourcePrefix . "Comment cm\n         join " . $SourcePrefix . "User ou\n           on cm.AuthUserID = ou.UserID\n         inner join " . $DestPrefix . "User nu\n           on nu.ImportID = ou.UserID\n         where cm.ConversationID > 0");
                                             $this->Message = T('<strong>10/19</strong> Transforming whispers into conversations.');
                                             $this->RedirectUrl = Url('/upgrade/10');
                                         } else {
                                             if ($Step == 10) {
                                                 // 10. Insert the userconversation records so that messages are linked to conversations
                                                 $Database->Query("insert into " . $DestPrefix . "UserConversation\n         (UserID, ConversationID, CountNewMessages, CountMessages, LastMessageID, DateLastViewed)\n         select InsertUserID, ConversationID, 0, 0, max(MessageID), null\n         from " . $DestPrefix . "ConversationMessage\n         group by InsertUserID, ConversationID");
                                                 $this->Message = T('<strong>11/19</strong> Finalizing whisper messages.');
                                                 $this->RedirectUrl = Url('/upgrade/11');
                                             } else {
                                                 if ($Step == 11) {
                                                     // 11. Update the conversation record fields
                                                     $Database->Query("update " . $DestPrefix . "Conversation c\n         join (\n           select ConversationID, min(MessageID) as FirstMessageID, min(DateInserted) as DateInserted\n           from " . $DestPrefix . "ConversationMessage\n           group by ConversationID\n         ) cm\n           on c.ConversationID = cm.ConversationID\n         set c.FirstMessageID = cm.FirstMessageID,\n           c.DateInserted = cm.DateInserted");
                                                     $Database->Query("update " . $DestPrefix . "Conversation c\n         join (\n           select ConversationID, max(MessageID) as LastMessageID\n           from " . $DestPrefix . "ConversationMessage\n           group by ConversationID\n         ) cm\n           on c.ConversationID = cm.ConversationID\n         join " . $DestPrefix . "ConversationMessage lm\n           on cm.LastMessageID = lm.MessageID\n         set c.UpdateUserID = lm.InsertUserID,\n           c.DateUpdated = lm.DateInserted");
                                                     // Fudge your way back from the messages
                                                     $Database->Query("update " . $DestPrefix . "Conversation c\n         join " . $DestPrefix . "ConversationMessage m\n           on c.FirstMessageID = m.MessageID\n         set c.InsertUserID = m.InsertUserID");
                                                     // Update the UserConversation.LastMessageID records
                                                     // (ie. the last message in a conversation by someone other than the userconversation.userid person)
                                                     $Database->Query("update " . $DestPrefix . "UserConversation uc\n         join (\n           select ConversationID, InsertUserID, max(MessageID) as LastMessageID\n           from " . $DestPrefix . "ConversationMessage\n           group by ConversationID, InsertUserID\n         ) m\n           on uc.ConversationId = m.ConversationID\n           and uc.UserID <> m.InsertUserID\n         set uc.LastMessageID = m.LastMessageID");
                                                     // Update the message count for all users and all conversations
                                                     $Database->Query("update " . $DestPrefix . "UserConversation uc\n         join (\n           select ConversationID, count(MessageID) as CountMessages\n           from " . $DestPrefix . "ConversationMessage\n           group by ConversationID\n         ) m\n           on uc.ConversationID = m.ConversationID\n         set uc.CountMessages = m.CountMessages");
                                                     $this->Message = T('<strong>12/19</strong> Finalizing conversations.');
                                                     $this->RedirectUrl = Url('/upgrade/12');
                                                 } else {
                                                     if ($Step == 12) {
                                                         // 12. Import Categories
                                                         $Database->Query("insert into " . $DestPrefix . "Category\n         (Name, Description, Sort, InsertUserID, UpdateUserID, DateInserted, DateUpdated, ImportID)\n         select left(Name,30), Description, Priority, 1, 1, now(), now(), CategoryID\n         from " . $SourcePrefix . "Category");
                                                         $this->Message = T('<strong>13/19</strong> Importing discussion categories.');
                                                         $this->RedirectUrl = Url('/upgrade/13');
                                                     } else {
                                                         if ($Step == 13) {
                                                             // 13. Import Discussions
                                                             $Database->Query("insert into " . $DestPrefix . "Discussion\n         (ImportID, CategoryID, InsertUserID, UpdateUserID, Name, CountComments, Closed, Announce, Sink, DateInserted, DateUpdated, DateLastComment)\n         select od.DiscussionID, nc.CategoryID, niu.UserID, nuu.UserID, od.Name, od.CountComments, od.Closed, od.Sticky, od.Sink, od.DateCreated, od.DateLastActive, od.DateLastActive\n         from " . $SourcePrefix . "Discussion od\n         join " . $DestPrefix . "Category nc\n            on od.CategoryID = nc.ImportID\n         join " . $DestPrefix . "User niu\n            on od.AuthUserID = niu.ImportID\n         join " . $DestPrefix . "User nuu\n            on od.LastUserID = nuu.ImportID\n         where od.WhisperUserID = 0\n            and od.Active = '1'");
                                                             $this->Message = T('<strong>14/19</strong> Importing discussions.');
                                                             $this->RedirectUrl = Url('/upgrade/14');
                                                         } else {
                                                             if ($Step == 14) {
                                                                 // 14. Import Comments
                                                                 $Database->Query("insert into " . $DestPrefix . "Comment\n         (DiscussionID, InsertUserID, UpdateUserID, Body, Format, DateInserted, DateUpdated)\n         select nd.DiscussionID, niu.UserID, nuu.UserID, Body, case FormatType when 'Text' then 'Display' else FormatType end, oc.DateCreated, oc.DateEdited\n         from " . $SourcePrefix . "Comment oc\n         join " . $DestPrefix . "Discussion nd\n            on oc.DiscussionID = nd.ImportID\n         join " . $DestPrefix . "User niu\n            on oc.AuthUserID = niu.ImportID\n         left join " . $DestPrefix . "User nuu\n            on oc.EditUserID = nuu.ImportID\n         where (oc.WhisperUserID is null or oc.WhisperUserID = 0)\n            and oc.Deleted = '0'");
                                                                 $this->Message = T('<strong>15/19</strong> Importing comments.');
                                                                 $this->RedirectUrl = Url('/upgrade/15');
                                                             } else {
                                                                 if ($Step == 15) {
                                                                     // 15. Update Discussions with first & last comment ids
                                                                     $Database->Query("update " . $DestPrefix . "Discussion d\n         join (\n           select DiscussionID, min(CommentID) as FirstCommentID\n           from " . $DestPrefix . "Comment\n           group by DiscussionID\n         ) c\n           on d.DiscussionID = c.DiscussionID\n         set d.FirstCommentID = c.FirstCommentID");
                                                                     $Database->Query("update " . $DestPrefix . "Discussion d\n         join (\n           select DiscussionID, max(CommentID) as LastCommentID\n           from " . $DestPrefix . "Comment\n           group by DiscussionID\n         ) c\n           on d.DiscussionID = c.DiscussionID\n         set d.LastCommentID = c.LastCommentID");
                                                                     // Update the CountDiscussions column on the category table
                                                                     $Database->Query("update " . $DestPrefix . "Category c\n         join (\n           select CategoryID, count(DiscussionID) as CountDiscussions\n           from " . $DestPrefix . "Discussion\n           group by CategoryID\n         ) cc\n           on c.CategoryID = cc.CategoryID\n         set c.CountDiscussions = cc.CountDiscussions");
                                                                     $this->Message = T('<strong>16/19</strong> Finalizing discussions.');
                                                                     $this->RedirectUrl = Url('/upgrade/16');
                                                                 } else {
                                                                     if ($Step == 16) {
                                                                         // 16. Import UserDiscussion (watch & bookmark data)
                                                                         $Database->Query("insert into " . $DestPrefix . "UserDiscussion\n         (UserID, DiscussionID, CountComments, DateLastViewed, Bookmarked)\n         select nu.UserID, nd.DiscussionID, ow.CountComments, ow.LastViewed, if(isnull(ob.DiscussionID), '0', '1') as Bookmarked\n         from " . $SourcePrefix . "UserDiscussionWatch ow\n         join " . $SourcePrefix . "Discussion od\n            on ow.DiscussionID = od.DiscussionID\n         join " . $DestPrefix . "Discussion nd\n            on od.DiscussionID = nd.ImportID\n         join " . $DestPrefix . "User nu\n            on ow.UserID = nu.ImportID\n         left join " . $SourcePrefix . "UserBookmark ob\n            on ow.DiscussionID = ob.DiscussionID\n            and ow.UserID = ob.UserID\n         where od.Active = '1'");
                                                                         $this->Message = T('<strong>17/19</strong> Importing bookmarks & watch data.');
                                                                         $this->RedirectUrl = Url('/upgrade/17');
                                                                     } else {
                                                                         if ($Step == 17) {
                                                                             // 17. Remove temp columns
                                                                             $Construct->Table('Role')->DropColumn('ImportID');
                                                                             $Construct->Table('User')->DropColumn('ImportID');
                                                                             $Construct->Table('Category')->DropColumn('ImportID');
                                                                             $Construct->Table('Discussion')->DropColumn('ImportID');
                                                                             $Construct->DatabasePrefix($SourcePrefix);
                                                                             $Construct->Table('Comment')->DropColumn('ConversationID');
                                                                             $Construct->DatabasePrefix($DestPrefix);
                                                                             $this->Message = T('<strong>18/19</strong> Removing import structure.');
                                                                             $this->RedirectUrl = Url('/upgrade/18');
                                                                         } else {
                                                                             if ($Step == 18) {
                                                                                 // 18. remove whisperuserids from old comment table where the entire discussion is whispered
                                                                                 $Database->Query("update " . $SourcePrefix . "Comment c\n         inner join " . $SourcePrefix . "Discussion d\n            on c.DiscussionID = d.DiscussionID\n         set c.WhisperUserID = null\n         where d.WhisperUserID > 0");
                                                                                 $this->Message = T('<strong>19/19</strong> Restoring original comment structure.');
                                                                                 $this->RedirectUrl = Url('/upgrade/19');
                                                                             } else {
                                                                                 if ($Step == 19) {
                                                                                     // Finished!
                                                                                     $this->RedirectUrl = 'Finished';
                                                                                     $this->View = 'finished';
                                                                                 }
                                                                             }
                                                                         }
                                                                     }
                                                                 }
                                                             }
                                                         }
                                                     }
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     $this->SetJson('NextUrl', $this->RedirectUrl);
     $this->RedirectUrl = '';
     $this->MasterView = 'setup';
     $this->Render();
 }
コード例 #14
0
ファイル: class.hooks.php プロジェクト: seedbank/old-repo
 /**
  *
  * @param Gdn_Controller $Sender
  */
 public function Base_Render_Before(&$Sender)
 {
     $Session = Gdn::Session();
     // Enable theme previewing
     if ($Session->IsValid()) {
         $PreviewThemeName = $Session->GetPreference('PreviewThemeName', '');
         $PreviewThemeFolder = $Session->GetPreference('PreviewThemeFolder', '');
         if ($PreviewThemeName != '') {
             $Sender->Theme = $PreviewThemeName;
             $Sender->InformMessage(sprintf(T('You are previewing the %s theme.'), Wrap($PreviewThemeName, 'em')) . '<div class="PreviewButtons">' . Anchor(T('Apply'), 'settings/themes/' . $PreviewThemeName . '/' . $Session->TransientKey(), 'PreviewButton') . ' ' . Anchor(T('Cancel'), 'settings/cancelpreview/', 'PreviewButton') . '</div>', 'DoNotDismiss');
         }
     }
     if ($Session->IsValid() && ($EmailKey = Gdn::Session()->GetAttribute('EmailKey'))) {
         $NotifyEmailConfirm = TRUE;
         // If this user was manually moved out of the confirmation role, get rid of their 'awaiting confirmation' flag
         $ConfirmEmailRole = C('Garden.Registration.ConfirmEmailRole', FALSE);
         $UserRoles = array();
         $RoleData = Gdn::UserModel()->GetRoles($Session->UserID);
         if ($RoleData !== FALSE && $RoleData->NumRows() > 0) {
             $UserRoles = ConsolidateArrayValuesByKey($RoleData->Result(DATASET_TYPE_ARRAY), 'RoleID', 'Name');
         }
         if ($ConfirmEmailRole !== FALSE && !array_key_exists($ConfirmEmailRole, $UserRoles)) {
             Gdn::UserModel()->SaveAttribute($Session->UserID, "EmailKey", NULL);
             $NotifyEmailConfirm = FALSE;
         }
         if ($NotifyEmailConfirm) {
             $Message = FormatString(T('You need to confirm your email address.', 'You need to confirm your email address. Click <a href="{/entry/emailconfirmrequest,url}">here</a> to resend the confirmation email.'));
             $Sender->InformMessage($Message, '');
         }
     }
     // Add Message Modules (if necessary)
     $MessageCache = Gdn::Config('Garden.Messages.Cache', array());
     $Location = $Sender->Application . '/' . substr($Sender->ControllerName, 0, -10) . '/' . $Sender->RequestMethod;
     $Exceptions = array('[Base]');
     // 2011-09-09 - mosullivan - No longer allowing messages in dashboard
     //		if ($Sender->MasterView == 'admin')
     //			$Exceptions[] = '[Admin]';
     //		else if (in_array($Sender->MasterView, array('', 'default')))
     if (in_array($Sender->MasterView, array('', 'default'))) {
         $Exceptions[] = '[NonAdmin]';
     }
     if ($Sender->MasterView != 'admin' && (GetValue('MessagesLoaded', $Sender) != '1' && $Sender->MasterView != 'empty' && ArrayInArray($Exceptions, $MessageCache, FALSE) || InArrayI($Location, $MessageCache))) {
         $MessageModel = new MessageModel();
         $MessageData = $MessageModel->GetMessagesForLocation($Location, $Exceptions);
         foreach ($MessageData as $Message) {
             $MessageModule = new MessageModule($Sender, $Message);
             $Sender->AddModule($MessageModule);
         }
         $Sender->MessagesLoaded = '1';
         // Fixes a bug where render gets called more than once and messages are loaded/displayed redundantly.
     }
     // If there are applicants, alert admins by showing in the main menu
     if (in_array($Sender->MasterView, array('', 'default')) && $Sender->Menu && C('Garden.Registration.Method') == 'Approval') {
         $CountApplicants = Gdn::UserModel()->GetApplicantCount();
         if ($CountApplicants > 0) {
             $Sender->Menu->AddLink('Applicants', T('Applicants') . ' <span class="Alert">' . $CountApplicants . '</span>', '/dashboard/user/applicants', array('Garden.Applicants.Manage'));
         }
     }
     if ($Sender->DeliveryType() == DELIVERY_TYPE_ALL) {
         $Gdn_Statistics = Gdn::Factory('Statistics');
         $Gdn_Statistics->Check($Sender);
     }
     // Allow forum embedding
     if (C('Garden.Embed.Allow')) {
         $Sender->AddJsFile('js/embed_local.js');
     }
 }
コード例 #15
0
 /**
  *
  * @param Gdn_Controller $Sender
  */
 public function Base_Render_Before($Sender)
 {
     $Session = Gdn::Session();
     // Enable theme previewing
     if ($Session->IsValid()) {
         $PreviewThemeName = $Session->GetPreference('PreviewThemeName', '');
         $PreviewThemeFolder = $Session->GetPreference('PreviewThemeFolder', '');
         if ($PreviewThemeName != '') {
             $Sender->Theme = $PreviewThemeName;
             $Sender->InformMessage(sprintf(T('You are previewing the %s theme.'), Wrap($PreviewThemeName, 'em')) . '<div class="PreviewThemeButtons">' . Anchor(T('Apply'), 'settings/themes/' . $PreviewThemeName . '/' . $Session->TransientKey(), 'PreviewThemeButton') . ' ' . Anchor(T('Cancel'), 'settings/cancelpreview/', 'PreviewThemeButton') . '</div>', 'DoNotDismiss');
         }
     }
     if ($Session->IsValid()) {
         $ConfirmEmail = C('Garden.Registration.ConfirmEmail', false);
         $Confirmed = GetValue('Confirmed', Gdn::Session()->User, true);
         if ($ConfirmEmail && !$Confirmed) {
             $Message = FormatString(T('You need to confirm your email address.', 'You need to confirm your email address. Click <a href="{/entry/emailconfirmrequest,url}">here</a> to resend the confirmation email.'));
             $Sender->InformMessage($Message, '');
         }
     }
     // Add Message Modules (if necessary)
     $MessageCache = Gdn::Config('Garden.Messages.Cache', array());
     $Location = $Sender->Application . '/' . substr($Sender->ControllerName, 0, -10) . '/' . $Sender->RequestMethod;
     $Exceptions = array('[Base]');
     // 2011-09-09 - mosullivan - No longer allowing messages in dashboard
     //		if ($Sender->MasterView == 'admin')
     //			$Exceptions[] = '[Admin]';
     //		else if (in_array($Sender->MasterView, array('', 'default')))
     if (in_array($Sender->MasterView, array('', 'default'))) {
         $Exceptions[] = '[NonAdmin]';
     }
     // SignIn popup is a special case
     $SignInOnly = $Sender->DeliveryType() == DELIVERY_TYPE_VIEW && $Location == 'Dashboard/entry/signin';
     if ($SignInOnly) {
         $Exceptions = array();
     }
     if ($Sender->MasterView != 'admin' && !$Sender->Data('_NoMessages') && (GetValue('MessagesLoaded', $Sender) != '1' && $Sender->MasterView != 'empty' && ArrayInArray($Exceptions, $MessageCache, FALSE) || InArrayI($Location, $MessageCache))) {
         $MessageModel = new MessageModel();
         $MessageData = $MessageModel->GetMessagesForLocation($Location, $Exceptions, $Sender->Data('Category.CategoryID'));
         foreach ($MessageData as $Message) {
             $MessageModule = new MessageModule($Sender, $Message);
             if ($SignInOnly) {
                 // Insert special messages even in SignIn popup
                 echo $MessageModule;
             } elseif ($Sender->DeliveryType() == DELIVERY_TYPE_ALL) {
                 $Sender->AddModule($MessageModule);
             }
         }
         $Sender->MessagesLoaded = '1';
         // Fixes a bug where render gets called more than once and messages are loaded/displayed redundantly.
     }
     if ($Sender->DeliveryType() == DELIVERY_TYPE_ALL) {
         $Gdn_Statistics = Gdn::Factory('Statistics');
         $Gdn_Statistics->Check($Sender);
     }
     // Allow forum embedding
     if ($Embed = C('Garden.Embed.Allow')) {
         // Record the remote url where the forum is being embedded.
         $RemoteUrl = C('Garden.Embed.RemoteUrl');
         if (!$RemoteUrl) {
             $RemoteUrl = GetIncomingValue('remote');
             if ($RemoteUrl) {
                 SaveToConfig('Garden.Embed.RemoteUrl', $RemoteUrl);
             }
         }
         if ($RemoteUrl) {
             $Sender->AddDefinition('RemoteUrl', $RemoteUrl);
         }
         // Force embedding?
         if (!IsSearchEngine() && !IsMobile() && strtolower($Sender->ControllerName) != 'entry') {
             $Sender->AddDefinition('ForceEmbedForum', C('Garden.Embed.ForceForum') ? '1' : '0');
             $Sender->AddDefinition('ForceEmbedDashboard', C('Garden.Embed.ForceDashboard') ? '1' : '0');
         }
         $Sender->AddDefinition('Path', Gdn::Request()->Path());
         // $Sender->AddDefinition('MasterView', $Sender->MasterView);
         $Sender->AddDefinition('InDashboard', $Sender->MasterView == 'admin' ? '1' : '0');
         if ($Embed === 2) {
             $Sender->AddJsFile('vanilla.embed.local.js');
         } else {
             $Sender->AddJsFile('embed_local.js');
         }
     } else {
         $Sender->SetHeader('X-Frame-Options', 'SAMEORIGIN');
     }
     // Allow return to mobile site
     $ForceNoMobile = Gdn_CookieIdentity::GetCookiePayload('VanillaNoMobile');
     if ($ForceNoMobile !== FALSE && is_array($ForceNoMobile) && in_array('force', $ForceNoMobile)) {
         $Sender->AddAsset('Foot', Wrap(Anchor(T('Back to Mobile Site'), '/profile/nomobile/1'), 'div'), 'MobileLink');
     }
 }
コード例 #16
0
ファイル: class.dispatcher.php プロジェクト: kidmax/Garden
 /**
  * Searches through the /cache/controller_mappings.php file for the requested
  * controller. If it doesn't find it, it searches through the entire
  * application's folders for the requested controller. If it finds the
  * controller, it adds the mapping to /cache/controller_mappings.php so it
  * won't need to search again. If it doesn't find the controller file
  * anywhere, it throws a fatal error.
  *
  * @param boolean $ThrowErrorOnFailure
  * @todo $ThrowErrorOnFailure needs a description.
  */
 private function _FetchController($ThrowErrorOnFailure = FALSE)
 {
     $ControllerWhiteList = $this->EnabledApplicationFolders();
     // Don't include it if it's already been included
     if (!class_exists($this->ControllerName())) {
         $PathParts = array('controllers');
         if ($this->_ControllerFolder != '') {
             $PathParts[] = $this->_ControllerFolder;
         }
         $PathParts[] = strtolower($this->_ControllerName) . '.php';
         $ControllerFileName = CombinePaths($PathParts);
         // Force the mapping to search in the app folder if it was in the request
         if ($this->_ApplicationFolder != '' && InArrayI($this->_ApplicationFolder, $ControllerWhiteList)) {
             // Limit the white list to the specified application folder
             $ControllerWhiteList = array($this->_ApplicationFolder);
         }
         $ControllerPath = Gdn_FileSystem::FindByMapping('controller_mappings.php', 'Controller', PATH_APPLICATIONS, $ControllerWhiteList, $ControllerFileName);
         if ($ControllerPath !== FALSE) {
             // Strip the "Application Folder" from the controller path (this is
             // used by the controller for various purposes. ie. knowing which
             // application to search in for a view file).
             $this->_ApplicationFolder = explode(DS, str_replace(PATH_APPLICATIONS . DS, '', $ControllerPath));
             $this->_ApplicationFolder = $this->_ApplicationFolder[0];
             // Load the application's master controller
             if (!class_exists($this->_ApplicationFolder . 'Controller')) {
                 include CombinePaths(array(PATH_APPLICATIONS, $this->_ApplicationFolder, 'controllers', 'appcontroller.php'));
             }
             // Now load the library (no need to check for existence - couldn't
             // have made it here if it didn't exist).
             include $ControllerPath;
         }
     }
     if (!class_exists($this->ControllerName())) {
         if ($ThrowErrorOnFailure === TRUE) {
             if (ForceBool(Gdn::Config('Garden.Debug'))) {
                 trigger_error(ErrorMessage('Controller not found: ' . $this->ControllerName(), 'Dispatcher', '_FetchController'), E_USER_ERROR);
             } else {
                 // Return a 404 message
                 list($this->_ApplicationFolder, $this->_ControllerName, $this->_ControllerMethod) = explode('/', $this->Routes['Default404']);
                 $ControllerFileName = CombinePaths(array('controllers', strtolower($this->_ControllerName) . '.php'));
                 $ControllerPath = Gdn_FileSystem::FindByMapping('controller_mappings.php', 'Controller', PATH_APPLICATIONS, $ControllerWhiteList, $ControllerFileName);
                 include CombinePaths(array(PATH_APPLICATIONS, $this->_ApplicationFolder, 'controllers', 'appcontroller.php'));
                 include $ControllerPath;
             }
         }
         return FALSE;
     } else {
         return TRUE;
     }
 }
コード例 #17
0
   /**
    * Analyzes the supplied query string and decides how to dispatch the request.
    */
   public function Dispatch($ImportRequest = NULL, $Permanent = TRUE) {
      if ($ImportRequest && is_string($ImportRequest))
         $ImportRequest = Gdn_Request::Create()->FromEnvironment()->WithURI($ImportRequest);
      
      if (is_a($ImportRequest, 'Gdn_Request') && $Permanent) {
         Gdn::Request($ImportRequest);
      }
      
      $Request = is_a($ImportRequest, 'Gdn_Request') ? $ImportRequest : Gdn::Request();
   
      if (Gdn::Config('Garden.UpdateMode', FALSE)) {
         if (!Gdn::Session()->CheckPermission('Garden.Settings.GlobalPrivs')) {
            // Updatemode, and this user is not root admin
            $Request->WithURI(Gdn::Router()->GetDestination('UpdateMode'));
         }
      }
      
      $this->FireEvent('BeforeDispatch');
      $this->AnalyzeRequest($Request);
            
      // Send user to login page if this is a private community (with some minor exceptions)
      if (
         C('Garden.PrivateCommunity')
         && $this->ControllerName() != 'EntryController'
         && !Gdn::Session()->IsValid()
         && !InArrayI($this->ControllerMethod(), array('UsernameAvailable', 'EmailAvailable', 'TermsOfService'))
      ) {
         Redirect('/entry/signin?Target='.urlencode($this->Request));
         exit();
      }

      $ControllerName = $this->ControllerName();
      
      if ($ControllerName != '' && class_exists($ControllerName)) {
         // Create it and call the appropriate method/action
         $Controller = new $ControllerName();
         
         $this->EventArguments['Controller'] =& $Controller;

         // Pass along any assets
         if (is_array($this->_AssetCollection)) {
            foreach ($this->_AssetCollection as $AssetName => $Assets) {
               foreach ($Assets as $Asset) {
                  $Controller->AddAsset($AssetName, $Asset);
               }
            }
         }

         // Instantiate Imported & Uses classes
         $Controller->GetImports();

         // Pass in the syndication method
         $Controller->SyndicationMethod = $this->_SyndicationMethod;

         // Pass along the request
         $Controller->SelfUrl = $this->Request;

         // Pass along any objects
         foreach($this->_PropertyCollection as $Name => $Mixed) {
            $Controller->$Name = $Mixed;
         }

         // Set up a default controller method in case one isn't defined.
         $ControllerMethod = str_replace('_', '', $this->_ControllerMethod);
         $Controller->OriginalRequestMethod = $ControllerMethod;
         
         $this->FireEvent('AfterAnalyzeRequest');
         
         // Take enabled plugins into account, as well
         $PluginManagerHasReplacementMethod = Gdn::PluginManager()->HasNewMethod($this->ControllerName(), $this->_ControllerMethod);
         if (!$PluginManagerHasReplacementMethod && ($this->_ControllerMethod == '' || !method_exists($Controller, $ControllerMethod))) {
            // Check to see if there is an 'x' version of the method.
            if (method_exists($Controller, 'x'.$ControllerMethod)) {
               // $PluginManagerHasReplacementMethod = TRUE;
               $ControllerMethod = 'x'.$ControllerMethod;
            } else {
               if ($this->_ControllerMethod != '')
                  array_unshift($this->_ControllerMethodArgs, $this->_ControllerMethod);
               
               $this->_ControllerMethod = 'Index';
               $ControllerMethod = 'Index';
               
               $PluginManagerHasReplacementMethod = Gdn::PluginManager()->HasNewMethod($this->ControllerName(), $this->_ControllerMethod);
            }
         }
         
         // Pass in the querystring values
         $Controller->ApplicationFolder = $this->_ApplicationFolder;
         $Controller->Application = $this->EnabledApplication();
         $Controller->ControllerFolder = $this->_ControllerFolder;
         $Controller->RequestMethod = $this->_ControllerMethod;
         $Controller->RequestArgs = $this->_ControllerMethodArgs;
         $Controller->Request = $Request;
         $Controller->DeliveryType($Request->GetValue('DeliveryType', $this->_DeliveryType));
         $Controller->DeliveryMethod($Request->GetValue('DeliveryMethod', $this->_DeliveryMethod));
         
         $this->FireEvent('BeforeControllerMethod');

         // Set special controller method options for REST APIs.
         $this->_ReflectControllerArgs($Controller);
         
         Gdn::Controller($Controller);
         $Controller->Initialize();

         // Call the requested method on the controller - error out if not defined.
         if ($PluginManagerHasReplacementMethod || method_exists($Controller, $ControllerMethod)) {
            // call_user_func_array is too slow!!
            //call_user_func_array(array($Controller, $ControllerMethod), $this->_ControllerMethodArgs);
            
            if ($PluginManagerHasReplacementMethod) {
              try {
                 Gdn::PluginManager()->CallNewMethod($Controller, $Controller->ControllerName, $ControllerMethod);
              } catch (Exception $Ex) {
                 $Controller->RenderException($Ex);
              }
            } else { 
              $Args = $this->_ControllerMethodArgs;
              $Count = count($Args);

              try {
                 call_user_func_array(array($Controller, $ControllerMethod), $Args);
              } catch (Exception $Ex) {
                 $Controller->RenderException($Ex);
                 exit();
              }
            }
         } else {
            Gdn::Request()->WithRoute('Default404');
            return $this->Dispatch();
         }
      }
   }
コード例 #18
0
ファイル: class.hooks.php プロジェクト: R-J/vanilla
 /**
  * Fire before every page render.
  *
  * @param Gdn_Controller $Sender
  */
 public function base_render_before($Sender)
 {
     $Session = Gdn::session();
     // Check the statistics.
     if ($Sender->deliveryType() == DELIVERY_TYPE_ALL) {
         Gdn::statistics()->check();
     }
     // Enable theme previewing
     if ($Session->isValid()) {
         $PreviewThemeName = htmlspecialchars($Session->getPreference('PreviewThemeName', ''));
         $PreviewThemeFolder = htmlspecialchars($Session->getPreference('PreviewThemeFolder', ''));
         if ($PreviewThemeName != '') {
             $Sender->Theme = $PreviewThemeName;
             $Sender->informMessage(sprintf(t('You are previewing the %s theme.'), wrap($PreviewThemeName, 'em')) . '<div class="PreviewThemeButtons">' . anchor(t('Apply'), 'settings/themes/' . $PreviewThemeName . '/' . $Session->transientKey(), 'PreviewThemeButton') . ' ' . anchor(t('Cancel'), 'settings/cancelpreview/', 'PreviewThemeButton') . '</div>', 'DoNotDismiss');
         }
     }
     if ($Session->isValid()) {
         $Confirmed = val('Confirmed', Gdn::session()->User, true);
         if (UserModel::requireConfirmEmail() && !$Confirmed) {
             $Message = formatString(t('You need to confirm your email address.', 'You need to confirm your email address. Click <a href="{/entry/emailconfirmrequest,url}">here</a> to resend the confirmation email.'));
             $Sender->informMessage($Message, '');
         }
     }
     // Add Message Modules (if necessary)
     $MessageCache = Gdn::config('Garden.Messages.Cache', array());
     $Location = $Sender->Application . '/' . substr($Sender->ControllerName, 0, -10) . '/' . $Sender->RequestMethod;
     $Exceptions = array('[Base]');
     if (in_array($Sender->MasterView, array('', 'default'))) {
         $Exceptions[] = '[NonAdmin]';
     }
     // SignIn popup is a special case
     $SignInOnly = $Sender->deliveryType() == DELIVERY_TYPE_VIEW && $Location == 'Dashboard/entry/signin';
     if ($SignInOnly) {
         $Exceptions = array();
     }
     if ($Sender->MasterView != 'admin' && !$Sender->data('_NoMessages') && (val('MessagesLoaded', $Sender) != '1' && $Sender->MasterView != 'empty' && ArrayInArray($Exceptions, $MessageCache, false) || InArrayI($Location, $MessageCache))) {
         $MessageModel = new MessageModel();
         $MessageData = $MessageModel->getMessagesForLocation($Location, $Exceptions, $Sender->data('Category.CategoryID'));
         foreach ($MessageData as $Message) {
             $MessageModule = new MessageModule($Sender, $Message);
             if ($SignInOnly) {
                 // Insert special messages even in SignIn popup
                 echo $MessageModule;
             } elseif ($Sender->deliveryType() == DELIVERY_TYPE_ALL) {
                 $Sender->addModule($MessageModule);
             }
         }
         $Sender->MessagesLoaded = '1';
         // Fixes a bug where render gets called more than once and messages are loaded/displayed redundantly.
     }
     if ($Sender->deliveryType() == DELIVERY_TYPE_ALL) {
         $Gdn_Statistics = Gdn::factory('Statistics');
         $Gdn_Statistics->check($Sender);
     }
     // Allow forum embedding
     if ($Embed = c('Garden.Embed.Allow')) {
         // Record the remote url where the forum is being embedded.
         $RemoteUrl = c('Garden.Embed.RemoteUrl');
         if (!$RemoteUrl) {
             $RemoteUrl = GetIncomingValue('remote');
             if ($RemoteUrl) {
                 saveToConfig('Garden.Embed.RemoteUrl', $RemoteUrl);
             }
         }
         if ($RemoteUrl) {
             $Sender->addDefinition('RemoteUrl', $RemoteUrl);
         }
         if ($remoteUrlFormat = c('Garden.Embed.RemoteUrlFormat')) {
             $Sender->addDefinition('RemoteUrlFormat', $remoteUrlFormat);
         }
         // Force embedding?
         if (!IsSearchEngine() && strtolower($Sender->ControllerName) != 'entry') {
             if (IsMobile()) {
                 $forceEmbedForum = c('Garden.Embed.ForceMobile') ? '1' : '0';
             } else {
                 $forceEmbedForum = c('Garden.Embed.ForceForum') ? '1' : '0';
             }
             $Sender->addDefinition('ForceEmbedForum', $forceEmbedForum);
             $Sender->addDefinition('ForceEmbedDashboard', c('Garden.Embed.ForceDashboard') ? '1' : '0');
         }
         $Sender->addDefinition('Path', Gdn::request()->path());
         $get = Gdn::request()->get();
         unset($get['p']);
         // kludge for old index.php?p=/path
         $Sender->addDefinition('Query', http_build_query($get));
         // $Sender->addDefinition('MasterView', $Sender->MasterView);
         $Sender->addDefinition('InDashboard', $Sender->MasterView == 'admin' ? '1' : '0');
         if ($Embed === 2) {
             $Sender->addJsFile('vanilla.embed.local.js');
         } else {
             $Sender->addJsFile('embed_local.js');
         }
     } else {
         $Sender->setHeader('X-Frame-Options', 'SAMEORIGIN');
     }
     // Allow return to mobile site
     $ForceNoMobile = val('X-UA-Device-Force', $_COOKIE);
     if ($ForceNoMobile === 'desktop') {
         $Sender->addAsset('Foot', wrap(Anchor(t('Back to Mobile Site'), '/profile/nomobile/1'), 'div'), 'MobileLink');
     }
     // Allow global translation of TagHint
     $Sender->addDefinition("TagHint", t("TagHint", "Start to type..."));
 }
コード例 #19
0
ファイル: class.hooks.php プロジェクト: vanilla/vanilla
 /**
  * Fire before every page render.
  *
  * @param Gdn_Controller $Sender
  */
 public function base_render_before($Sender)
 {
     $Session = Gdn::session();
     if ($Sender->MasterView == 'admin') {
         if (val('Form', $Sender)) {
             $Sender->Form->setStyles('bootstrap');
         }
         $Sender->CssClass = htmlspecialchars($Sender->CssClass);
         $Sections = Gdn_Theme::section(null, 'get');
         if (is_array($Sections)) {
             foreach ($Sections as $Section) {
                 $Sender->CssClass .= ' Section-' . $Section;
             }
         }
         // Get our plugin nav items.
         $navAdapter = new NestedCollectionAdapter(DashboardNavModule::getDashboardNav());
         $Sender->EventArguments['SideMenu'] = $navAdapter;
         $Sender->fireEvent('GetAppSettingsMenuItems');
         $Sender->removeJsFile('jquery.popup.js');
         $Sender->addJsFile('vendors/jquery.checkall.min.js', 'dashboard');
         $Sender->addJsFile('dashboard.js', 'dashboard');
         $Sender->addJsFile('jquery.expander.js');
         $Sender->addJsFile('settings.js', 'dashboard');
         $Sender->addJsFile('vendors/tether.min.js', 'dashboard');
         $Sender->addJsFile('vendors/bootstrap/util.js', 'dashboard');
         $Sender->addJsFile('vendors/drop.min.js', 'dashboard');
         $Sender->addJsFile('vendors/moment.min.js', 'dashboard');
         $Sender->addJsFile('vendors/daterangepicker.js', 'dashboard');
         $Sender->addJsFile('vendors/bootstrap/tooltip.js', 'dashboard');
         $Sender->addJsFile('vendors/clipboard.min.js', 'dashboard');
         $Sender->addJsFile('vendors/bootstrap/dropdown.js', 'dashboard');
         $Sender->addJsFile('vendors/bootstrap/collapse.js', 'dashboard');
         $Sender->addJsFile('vendors/bootstrap/modal.js', 'dashboard');
         $Sender->addJsFile('vendors/icheck.min.js', 'dashboard');
         $Sender->addJsFile('jquery.tablejenga.js', 'dashboard');
         $Sender->addJsFile('jquery.fluidfixed.js', 'dashboard');
         $Sender->addJsFile('vendors/prettify/prettify.js', 'dashboard');
         $Sender->addJsFile('vendors/ace/ace.js', 'dashboard');
         $Sender->addJsFile('vendors/ace/ext-searchbox.js', 'dashboard');
         $Sender->addCssFile('vendors/tomorrow.css', 'dashboard');
     }
     // Check the statistics.
     if ($Sender->deliveryType() == DELIVERY_TYPE_ALL) {
         Gdn::statistics()->check();
     }
     // Inform user of theme previewing
     if ($Session->isValid()) {
         $PreviewThemeFolder = htmlspecialchars($Session->getPreference('PreviewThemeFolder', ''));
         $PreviewMobileThemeFolder = htmlspecialchars($Session->getPreference('PreviewMobileThemeFolder', ''));
         $PreviewThemeName = htmlspecialchars($Session->getPreference('PreviewThemeName', $PreviewThemeFolder));
         $PreviewMobileThemeName = htmlspecialchars($Session->getPreference('PreviewMobileThemeName', $PreviewMobileThemeFolder));
         if ($PreviewThemeFolder != '') {
             $Sender->informMessage(sprintf(t('You are previewing the %s desktop theme.'), wrap($PreviewThemeName, 'em')) . '<div class="PreviewThemeButtons">' . anchor(t('Apply'), 'settings/themes/' . $PreviewThemeFolder . '/' . $Session->transientKey(), 'PreviewThemeButton') . ' ' . anchor(t('Cancel'), 'settings/cancelpreview/' . $PreviewThemeFolder . '/' . $Session->transientKey(), 'PreviewThemeButton') . '</div>', 'DoNotDismiss');
         }
         if ($PreviewMobileThemeFolder != '') {
             $Sender->informMessage(sprintf(t('You are previewing the %s mobile theme.'), wrap($PreviewMobileThemeName, 'em')) . '<div class="PreviewThemeButtons">' . anchor(t('Apply'), 'settings/mobilethemes/' . $PreviewMobileThemeFolder . '/' . $Session->transientKey(), 'PreviewThemeButton') . ' ' . anchor(t('Cancel'), 'settings/cancelpreview/' . $PreviewMobileThemeFolder . '/' . $Session->transientKey(), 'PreviewThemeButton') . '</div>', 'DoNotDismiss');
         }
     }
     if ($Session->isValid()) {
         $Confirmed = val('Confirmed', Gdn::session()->User, true);
         if (UserModel::requireConfirmEmail() && !$Confirmed) {
             $Message = formatString(t('You need to confirm your email address.', 'You need to confirm your email address. Click <a href="{/entry/emailconfirmrequest,url}">here</a> to resend the confirmation email.'));
             $Sender->informMessage($Message, '');
         }
     }
     // Add Message Modules (if necessary)
     $MessageCache = Gdn::config('Garden.Messages.Cache', array());
     $Location = $Sender->Application . '/' . substr($Sender->ControllerName, 0, -10) . '/' . $Sender->RequestMethod;
     $Exceptions = array('[Base]');
     if (in_array($Sender->MasterView, array('', 'default'))) {
         $Exceptions[] = '[NonAdmin]';
     }
     // SignIn popup is a special case
     $SignInOnly = $Sender->deliveryType() == DELIVERY_TYPE_VIEW && $Location == 'Dashboard/entry/signin';
     if ($SignInOnly) {
         $Exceptions = array();
     }
     if ($Sender->MasterView != 'admin' && !$Sender->data('_NoMessages') && (val('MessagesLoaded', $Sender) != '1' && $Sender->MasterView != 'empty' && ArrayInArray($Exceptions, $MessageCache, false) || InArrayI($Location, $MessageCache))) {
         $MessageModel = new MessageModel();
         $MessageData = $MessageModel->getMessagesForLocation($Location, $Exceptions, $Sender->data('Category.CategoryID'));
         foreach ($MessageData as $Message) {
             $MessageModule = new MessageModule($Sender, $Message);
             if ($SignInOnly) {
                 // Insert special messages even in SignIn popup
                 echo $MessageModule;
             } elseif ($Sender->deliveryType() == DELIVERY_TYPE_ALL) {
                 $Sender->addModule($MessageModule);
             }
         }
         $Sender->MessagesLoaded = '1';
         // Fixes a bug where render gets called more than once and messages are loaded/displayed redundantly.
     }
     if ($Sender->deliveryType() == DELIVERY_TYPE_ALL) {
         $Gdn_Statistics = Gdn::factory('Statistics');
         $Gdn_Statistics->check($Sender);
     }
     // Allow forum embedding
     if ($Embed = c('Garden.Embed.Allow')) {
         // Record the remote url where the forum is being embedded.
         $RemoteUrl = c('Garden.Embed.RemoteUrl');
         if (!$RemoteUrl) {
             $RemoteUrl = GetIncomingValue('remote');
             if ($RemoteUrl) {
                 saveToConfig('Garden.Embed.RemoteUrl', $RemoteUrl);
             }
         }
         if ($RemoteUrl) {
             $Sender->addDefinition('RemoteUrl', $RemoteUrl);
         }
         if ($remoteUrlFormat = c('Garden.Embed.RemoteUrlFormat')) {
             $Sender->addDefinition('RemoteUrlFormat', $remoteUrlFormat);
         }
         // Force embedding?
         if (!IsSearchEngine() && strtolower($Sender->ControllerName) != 'entry') {
             if (IsMobile()) {
                 $forceEmbedForum = c('Garden.Embed.ForceMobile') ? '1' : '0';
             } else {
                 $forceEmbedForum = c('Garden.Embed.ForceForum') ? '1' : '0';
             }
             $Sender->addDefinition('ForceEmbedForum', $forceEmbedForum);
             $Sender->addDefinition('ForceEmbedDashboard', c('Garden.Embed.ForceDashboard') ? '1' : '0');
         }
         $Sender->addDefinition('Path', Gdn::request()->path());
         $get = Gdn::request()->get();
         unset($get['p']);
         // kludge for old index.php?p=/path
         $Sender->addDefinition('Query', http_build_query($get));
         // $Sender->addDefinition('MasterView', $Sender->MasterView);
         $Sender->addDefinition('InDashboard', $Sender->MasterView == 'admin' ? '1' : '0');
         if ($Embed === 2) {
             $Sender->addJsFile('vanilla.embed.local.js');
         } else {
             $Sender->addJsFile('embed_local.js');
         }
     } else {
         $Sender->setHeader('X-Frame-Options', 'SAMEORIGIN');
     }
     // Allow return to mobile site
     $ForceNoMobile = val('X-UA-Device-Force', $_COOKIE);
     if ($ForceNoMobile === 'desktop') {
         $Sender->addAsset('Foot', wrap(Anchor(t('Back to Mobile Site'), '/profile/nomobile/1'), 'div'), 'MobileLink');
     }
     // Allow global translation of TagHint
     $Sender->addDefinition("TagHint", t("TagHint", "Start to type..."));
     // Add symbols.
     if ($Sender->deliveryMethod() === DELIVERY_METHOD_XHTML) {
         $Sender->addAsset('Symbols', $Sender->fetchView('symbols', '', 'Dashboard'));
     }
 }
コード例 #20
0
ファイル: default.php プロジェクト: ru4/arabbnota
 public function Base_Render_Before(&$Sender)
 {
     $ConfigItem = Gdn::Config('TopPosters.Location.Show', 'every');
     $Controller = $Sender->ControllerName;
     $Application = $Sender->ApplicationFolder;
     $Session = Gdn::Session();
     $ShowOnController = array();
     switch ($ConfigItem) {
         case 'every':
             $ShowOnController = array('discussioncontroller', 'categoriescontroller', 'discussionscontroller', 'profilecontroller', 'activitycontroller', 'draftscontroller');
             break;
         case 'discussion':
         default:
             $ShowOnController = array('discussioncontroller', 'discussionscontroller', 'categoriescontroller', 'draftscontroller');
     }
     if (!InArrayI($Controller, $ShowOnController)) {
         return;
     }
     include_once PATH_PLUGINS . DS . 'TopPosters' . DS . 'class.toppostersmodule.php';
     $TopPostersModule = new TopPostersModule($Sender);
     $TopPostersModule->GetData();
     $Sender->AddModule($TopPostersModule);
     $Limit = Gdn::Config('TopPosters.Limit', 4);
     if (!is_numeric($Limit)) {
         $Limit = 4;
     }
     $Sender->AddDefinition('TopPostersLimit', $Limit);
 }