public function ToString()
 {
     $Session = Gdn::Session();
     $Controller = Gdn::Controller();
     $UserID = $Controller->User->UserID;
     $MemberOptions = array();
     $ProfileOptions = array();
     $Controller->EventArguments['UserID'] = $UserID;
     $Controller->EventArguments['ProfileOptions'] =& $ProfileOptions;
     $Controller->EventArguments['MemberOptions'] =& $MemberOptions;
     if ($Controller->EditMode) {
         return '<div class="ProfileOptions">' . Anchor(T('Back to Profile'), UserUrl($Controller->User), array('class' => 'ProfileButtons')) . '</div>';
         //         $ProfileOptions[] = array('Text' => T('Back to Profile'), 'Url' => UserUrl($Controller->User), 'CssClass' => 'BackToProfile');
     } else {
         // Profile Editing
         if (hasEditProfile($Controller->User->UserID)) {
             $ProfileOptions[] = array('Text' => Sprite('SpEditProfile') . ' ' . T('Edit Profile'), 'Url' => UserUrl($Controller->User, '', 'edit'));
         }
         // Ban/Unban
         $MayBan = CheckPermission('Garden.Moderation.Manage') || CheckPermission('Garden.Users.Edit') || CheckPermission('Moderation.Users.Ban');
         if ($MayBan && $UserID != $Session->UserID) {
             if ($Controller->User->Banned) {
                 $ProfileOptions[] = array('Text' => Sprite('SpBan') . ' ' . T('Unban'), 'Url' => "/user/ban?userid={$UserID}&unban=1", 'CssClass' => 'Popup');
             } elseif (!$Controller->User->Admin) {
                 $ProfileOptions[] = array('Text' => Sprite('SpBan') . ' ' . T('Ban'), 'Url' => "/user/ban?userid={$UserID}", 'CssClass' => 'Popup');
             }
         }
         // Delete content.
         if (CheckPermission('Garden.Moderation.Manage')) {
             $ProfileOptions[] = array('Text' => Sprite('SpDelete') . ' ' . T('Delete Content'), 'Url' => "/user/deletecontent?userid={$UserID}", 'CssClass' => 'Popup');
         }
     }
     return parent::ToString();
 }
Example #2
0
 public function Comment()
 {
     $Session = Gdn::Session();
     $this->Form->SetModel($this->ActivityModel);
     $NewActivityID = 0;
     if ($this->Form->AuthenticatedPostBack()) {
         $Body = $this->Form->GetValue('Body', '');
         $ActivityID = $this->Form->GetValue('ActivityID', '');
         if ($Body != '' && is_numeric($ActivityID) && $ActivityID > 0) {
             $NewActivityID = $this->ActivityModel->Add($Session->UserID, 'ActivityComment', $Body, '', $ActivityID, '', TRUE);
         }
     }
     // Redirect back to the sending location if this isn't an ajax request
     if ($this->_DeliveryType === DELIVERY_TYPE_ALL) {
         Redirect($this->Form->GetValue('Return', Gdn_Url::WebRoot()));
     } else {
         // Load the newly added comment
         $this->Comment = $this->ActivityModel->GetID($NewActivityID);
         $this->Comment->ActivityType .= ' Hidden';
         // Hide it so jquery can reveal it
         // Set it in the appropriate view
         $this->View = 'comment';
         // And render
         $this->Render();
     }
 }
Example #3
0
 public function Base_Render_Before(&$Sender)
 {
     // Add menu items.
     $Session = Gdn::Session();
     if ($Sender->Menu) {
         $DiscussionsHome = '/' . Gdn::Config('Vanilla.Discussions.Home', 'discussions');
         $Sender->Menu->AddLink(Gdn::Translate('Discussions'), 'Discussions', $DiscussionsHome, FALSE);
         if ($Session->IsValid()) {
             $Bookmarked = Gdn::Translate('My Bookmarks');
             $CountBookmarks = $Session->User->CountBookmarks;
             if (is_numeric($CountBookmarks) && $CountBookmarks > 0) {
                 $Bookmarked .= '<span>' . $CountBookmarks . '</span>';
             }
             $Sender->Menu->AddLink(Gdn::Translate('Discussions'), '\\' . $Bookmarked, '/discussions/bookmarked', FALSE, array('class' => 'MyBookmarks'));
             $MyDiscussions = Gdn::Translate('My Discussions');
             $CountDiscussions = $Session->User->CountDiscussions;
             if (is_numeric($CountDiscussions) && $CountDiscussions > 0) {
                 $MyDiscussions .= '<span>' . $CountDiscussions . '</span>';
             }
             $Sender->Menu->AddLink(Gdn::Translate('Discussions'), '\\' . $MyDiscussions, '/discussions/mine', FALSE, array('class' => 'MyDiscussions'));
             $MyDrafts = Gdn::Translate('My Drafts');
             $CountDrafts = $Session->User->CountDrafts;
             if (is_numeric($CountDrafts) && $CountDrafts > 0) {
                 $MyDrafts .= '<span>' . $CountDrafts . '</span>';
             }
             $Sender->Menu->AddLink(Gdn::Translate('Discussions'), '\\' . $MyDrafts, '/drafts', FALSE, array('class' => 'MyDrafts'));
         }
         if ($Session->IsValid()) {
             $Sender->Menu->AddLink(Gdn::Translate('Discussions'), 'New Discussion', '/post/discussion', FALSE);
         }
     }
 }
 public function Save($FormPostValues)
 {
     $Session = Gdn::Session();
     // Define the primary key in this model's table.
     $this->DefineSchema();
     // Add & apply any extra validation rules:
     $this->Validation->ApplyRule('Body', 'Required');
     $this->AddInsertFields($FormPostValues);
     // Validate the form posted values
     $MessageID = FALSE;
     if ($this->Validate($FormPostValues)) {
         $Fields = $this->Validation->SchemaValidationFields();
         // All fields on the form that relate to the schema
         $MessageID = $this->SQL->Insert($this->Name, $Fields);
         $ConversationID = ArrayValue('ConversationID', $Fields, 0);
         // Update the conversation's DateUpdated field
         $this->SQL->Update('Conversation')->Set('DateUpdated', Format::ToDateTime())->Set('UpdateUserID', $Session->UserID)->Where('ConversationID', $ConversationID)->Put();
         // NOTE: INCREMENTING COUNTS INSTEAD OF GETTING ACTUAL COUNTS COULD
         // BECOME A PROBLEM. WATCH FOR IT.
         // Update the message counts for all users in the conversation
         $this->SQL->Update('UserConversation')->Set('CountMessages', 'CountMessages + 1', FALSE)->Where('ConversationID', $ConversationID)->Put();
         $this->SQL->Update('UserConversation')->Set('CountNewMessages', 'CountNewMessages + 1', FALSE)->Where('ConversationID', $ConversationID)->Where('UserID <>', $Session->UserID)->Put();
         // Update the CountUnreadConversations count on each user related to the discussion.
         $this->UpdateCountUnreadConversations($ConversationID, $Session->UserID);
         // Update the userconversation records to reflect the most recently
         // added message for all users other than the one that added the
         // message (otherwise they would see their name/message on the
         // conversation list instead of the person they are conversing with).
         $this->SQL->Update('UserConversation')->Set('LastMessageID', $MessageID)->Where('ConversationID', $ConversationID)->Where('UserID <>', $Session->UserID)->Put();
     }
     return $MessageID;
 }
 public function DiscussionModel_BeforeSaveDiscussion_Handler($Sender, &$Args)
 {
     if ($Args['FormPostValues']['InsertUserID'] != Gdn::Session()->UserID) {
         return;
     }
     $this->SetAttributes($Sender, $Args);
 }
Example #6
0
/**
 * A placeholder for future menu items.
 *
 * @param array The parameters passed into the function. This currently takes no parameters.
 * @param Smarty The smarty object rendering the template.
 * @return
 */
function smarty_function_custom_menu($Params, &$Smarty)
{
    $Controller = $Smarty->Controller;
    if (is_object($Menu = GetValue('Menu', $Controller))) {
        $Format = GetValue('format', $Params, Wrap('<a href="%url" class="%class">%text</a>', GetValue('wrap', $Params, 'li')));
        $Result = '';
        foreach ($Menu->Items as $Group) {
            foreach ($Group as $Item) {
                // Make sure the item is a custom item.
                if (GetValueR('Attributes.Standard', $Item)) {
                    continue;
                }
                // Make sure the user has permission for the item.
                if ($Permission = GetValue('Permission', $Item)) {
                    if (!Gdn::Session()->CheckPermission($Permission)) {
                        continue;
                    }
                }
                if (($Url = GetValue('Url', $Item)) && ($Text = GetValue('Text', $Item))) {
                    $Result .= Gdn_Theme::Link($Url, $Text, $Format);
                }
            }
        }
        return $Result;
    }
    return '';
}
/**
 */
function smarty_function_signin_link($Params, &$Smarty)
{
    if (!Gdn::Session()->IsValid()) {
        $Wrap = GetValue('wrap', $Params, 'li');
        return Gdn_Theme::Link('signinout', GetValue('text', $Params, ''), GetValue('format', $Params, Wrap('<a href="%url" rel="nofollow" class="%class">%text</a>', $Wrap)), $Params);
    }
}
 /**
  * Award a badge to a user and record some activity
  *
  * @param int $BadgeID
  * @param int $UserID This is the user that should get the award
  * @param int $InsertUserID This is the user that gave the award
  * @param string $Reason This is the reason the giver gave with the award
  */
 public function Award($BadgeID, $UserID, $InsertUserID = NULL, $Reason = '')
 {
     $Badge = Yaga::BadgeModel()->GetByID($BadgeID);
     if (!empty($Badge)) {
         if (!$this->Exists($UserID, $BadgeID)) {
             $this->SQL->Insert('BadgeAward', array('BadgeID' => $BadgeID, 'UserID' => $UserID, 'InsertUserID' => $InsertUserID, 'Reason' => $Reason, 'DateInserted' => date(DATE_ISO8601)));
             // Record the points for this badge
             UserModel::GivePoints($UserID, $Badge->AwardValue, 'Badge');
             // Increment the user's badge count
             $this->SQL->Update('User')->Set('CountBadges', 'CountBadges + 1', FALSE)->Where('UserID', $UserID)->Put();
             if (is_null($InsertUserID)) {
                 $InsertUserID = Gdn::Session()->UserID;
             }
             // Record some activity
             $ActivityModel = new ActivityModel();
             $Activity = array('ActivityType' => 'BadgeAward', 'ActivityUserID' => $UserID, 'RegardingUserID' => $InsertUserID, 'Photo' => $Badge->Photo, 'RecordType' => 'Badge', 'RecordID' => $BadgeID, 'Route' => '/badges/detail/' . $Badge->BadgeID . '/' . Gdn_Format::Url($Badge->Name), 'HeadlineFormat' => T('Yaga.Badge.EarnedHeadlineFormat'), 'Data' => array('Name' => $Badge->Name), 'Story' => $Badge->Description);
             // Create a public record
             $ActivityModel->Queue($Activity, FALSE);
             // TODO: enable the grouped notifications after issue #1776 is resolved , array('GroupBy' => 'Route'));
             // Notify the user of the award
             $Activity['NotifyUserID'] = $UserID;
             $ActivityModel->Queue($Activity, 'BadgeAward', array('Force' => TRUE));
             // Actually save the activity
             $ActivityModel->SaveQueue();
             $this->EventArguments['UserID'] = $UserID;
             $this->FireEvent('AfterBadgeAward');
         }
     }
 }
 public function ToString()
 {
     if (!Gdn::Session()->IsValid() && C('Garden.Modules.ShowGuestModule')) {
         return parent::ToString();
     }
     return '';
 }
 protected function _CacheOnlineUserss(&$Sender)
 {
     //logic taken from Who's Online plugin
     $SQL = Gdn::SQL();
     // $this->_OnlineUsers = $SQL
     // insert or update entry into table
     $Session = Gdn::Session();
     $Invisible = $Invisible ? 1 : 0;
     if ($Session->UserID) {
         $SQL->Replace('Whosonline', array('UserID' => $Session->UserID, 'Timestamp' => Gdn_Format::ToDateTime(), 'Invisible' => $Invisible), array('UserID' => $Session->UserID));
     }
     $Frequency = C('WhosOnline.Frequency', 4);
     $History = time() - $Frequency;
     $SQL->Select('u.UserID, u.Name, w.Timestamp, w.Invisible')->From('Whosonline w')->Join('User u', 'w.UserID = u.UserID')->Where('w.Timestamp >=', date('Y-m-d H:i:s', $History))->OrderBy('u.Name');
     if (!$Session->CheckPermission('Plugins.WhosOnline.ViewHidden')) {
         $SQL->Where('w.Invisible', 0);
     }
     $OnlineUsers = $SQL->Get();
     $arrOnline = array();
     if ($OnlineUsers->NumRows() > 0) {
         foreach ($OnlineUsers->Result() as $User) {
             $arrOnline[] = $User->UserID;
         }
     }
     $Sender->SetData('Plugin-OnlineUsers-Marker', $arrOnline);
 }
 /**
  * Delete a single draft.
  *
  * Redirects user back to Index unless DeliveryType is set.
  * 
  * @since 2.0.0
  * @access public
  * 
  * @param int $DraftID Unique ID of draft to be deleted.
  * @param string $TransientKey Single-use hash to prove intent.
  */
 public function Delete($DraftID = '', $TransientKey = '')
 {
     $Form = Gdn::Factory('Form');
     $Session = Gdn::Session();
     if (is_numeric($DraftID) && $DraftID > 0 && $Session->UserID > 0 && $Session->ValidateTransientKey($TransientKey)) {
         // Delete the draft
         $Draft = $this->DraftModel->GetID($DraftID);
         if ($Draft && !$this->DraftModel->Delete($DraftID)) {
             $Form->AddError('Failed to delete discussion');
         }
     } else {
         // Log an error
         $Form->AddError('ErrPermission');
     }
     // Redirect
     if ($this->_DeliveryType === DELIVERY_TYPE_ALL) {
         $Target = GetIncomingValue('Target', '/vanilla/drafts');
         Redirect($Target);
     }
     // Return any errors
     if ($Form->ErrorCount() > 0) {
         $this->SetJson('ErrorMessage', $Form->Errors());
     }
     // Render default view
     $this->Render();
 }
Example #12
0
 public function Edit($Reference = 0, $ParentID = '')
 {
     $Session = Gdn::Session();
     $Model = new SectionModel();
     $this->Form->SetModel($Model);
     if ($ParentID) {
         $this->Form->AddHidden('ParentID', $ParentID);
     }
     $Section = False;
     if ($Reference) {
         $Section = $Model->GetID($Reference);
         if (!IsContentOwner($Section, 'Candy.Sections.Edit')) {
             $Section = False;
         }
         if ($Section) {
             $this->Form->AddHidden('SectionID', $Section->SectionID);
             $this->Form->SetData($Section);
         }
     }
     if (!$Section) {
         $this->Permission('Candy.Sections.Add');
     }
     if ($this->Form->AuthenticatedPostBack()) {
         $this->Form->Save($Section);
         if ($this->Form->ErrorCount() == 0) {
             $this->InformMessage(T('Saved'), array('Sprite' => 'Check', 'CssClass' => 'Dismissable AutoDismiss'));
         }
     }
     $this->Title(ConcatSep(' - ', T('Section'), GetValue('Name', $Section)));
     $this->Render();
 }
 /**
  * Add 'sink' option to new discussion form.
  */
 public function PostController_DiscussionFormOptions_Handler($Sender)
 {
     $Session = Gdn::Session();
     if ($Session->CheckPermission('Vanilla.Discussions.Sink')) {
         $Sender->EventArguments['Options'] .= '<li>' . $Sender->Form->CheckBox('Sink', T('Sink'), array('value' => '1')) . '</li>';
     }
 }
   /**
    * 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;
   }
 /**
  * Update user's AllViewed datetime.
  */
 function UserModel_UpdateAllViewed_Create(&$Sender)
 {
     if (!C('Plugins.AllViewed.Enabled')) {
         return;
     }
     // Only for members
     $Session = Gdn::Session();
     if (!$Session->IsValid()) {
         return;
     }
     $UserID = $Session->User->UserID;
     // Can only activate on yourself
     // Validity check (in case UserID passed from elsewhere some day)
     $UserID = (int) $UserID;
     if (!$UserID) {
         throw new Exception('A valid UserId is required.');
     }
     // Update User timestamp
     $Sender->SQL->Update('User')->Set('DateAllViewed', Gdn_Format::ToDateTime());
     $Sender->SQL->Where('UserID', $UserID)->Put();
     // Update CountComments = 0
     $Sender->SQL->Update('UserDiscussion')->Set('CountComments', 0);
     // Hack to avoid massive update query
     $Sender->SQL->Where('UserID', $UserID)->Put();
     // Set in current session
     $Session->User->DateAllViewed = Gdn_Format::ToDateTime();
 }
Example #16
0
 /**
  * Emulate a call to index.php?p=$vanilla_module_path
  * Much of this ripped out of Vanilla's index.php
  */
 public function view($segments)
 {
     // if a static asset, return it outright
     $asset = $this->is_static_asset($segments);
     if ($asset) {
         return \Response::make(\File::get($asset))->header('Content-Type', $this->get_content_type($asset));
     }
     // otherwise, dispatch into vanilla
     $user = $this->user;
     $bootstrap = new VanillaBootstrap();
     $bootstrap->call(function () use($user, $segments) {
         // Create the session and stuff the user in
         \Gdn::Authenticator()->SetIdentity($user->getKey(), false);
         \Gdn::Session()->Start(false, false);
         \Gdn::Session()->SetPreference('Authenticator', 'Gdn_Authenticator');
         // Create and configure the dispatcher.
         $Dispatcher = \Gdn::Dispatcher();
         $EnabledApplications = \Gdn::ApplicationManager()->EnabledApplicationFolders();
         $Dispatcher->EnabledApplicationFolders($EnabledApplications);
         $Dispatcher->PassProperty('EnabledApplications', $EnabledApplications);
         // Process the request.
         $Dispatcher->Start();
         $Dispatcher->Dispatch(implode('/', $segments));
     });
 }
 /**
  * Grabs all new notifications and adds them to the sender's inform queue.
  *
  * This method gets called by dashboard's hooks file to display new
  * notifications on every pageload. 
  *
  * @since 2.0.18
  * @access public
  *
  * @param Gdn_Controller $Sender The object calling this method.
  */
 public static function InformNotifications($Sender)
 {
     $Session = Gdn::Session();
     if (!$Session->IsValid()) {
         return;
     }
     $ActivityModel = new ActivityModel();
     // Get five pending notifications.
     $Where = array('NotifyUserID' => Gdn::Session()->UserID, 'Notified' => ActivityModel::SENT_PENDING);
     // If we're in the middle of a visit only get very recent notifications.
     $Where['DateUpdated >'] = Gdn_Format::ToDateTime(strtotime('-5 minutes'));
     $Activities = $ActivityModel->GetWhere($Where, 0, 5)->ResultArray();
     $ActivityIDs = ConsolidateArrayValuesByKey($Activities, 'ActivityID');
     $ActivityModel->SetNotified($ActivityIDs);
     foreach ($Activities as $Activity) {
         if ($Activity['Photo']) {
             $UserPhoto = Anchor(Img($Activity['Photo'], array('class' => 'ProfilePhotoMedium')), $Activity['Url'], 'Icon');
         } else {
             $UserPhoto = '';
         }
         $Excerpt = Gdn_Format::Display($Activity['Story']);
         $ActivityClass = ' Activity-' . $Activity['ActivityType'];
         $Sender->InformMessage($UserPhoto . Wrap($Activity['Headline'], 'div', array('class' => 'Title')) . Wrap($Excerpt, 'div', array('class' => 'Excerpt')), 'Dismissable AutoDismiss' . $ActivityClass . ($UserPhoto == '' ? '' : ' HasIcon'));
     }
 }
 public function AddQuery($Sender, $Options = FALSE)
 {
     if ($Sender->ControllerName == 'discussioncontroller' && isset($Sender->Discussion)) {
         $this->SphinxClient->ResetFilters();
         $this->SphinxClient->ResetGroupBy();
         $this->SphinxClient->SetSortMode(SPH_SORT_RELEVANCE);
         $this->SphinxClient->SetRankingMode(SPH_RANK_WORDCOUNT);
         // Compare which is larger and strip results in the smaller results above in 'Update'
         $limit = $this->Settings['Admin']->LimitRelatedThreadsSidebarDiscussion > $this->Settings['Admin']->LimitRelatedThreadsBottomDiscussion ? $this->Settings['Admin']->LimitRelatedThreadsSidebarDiscussion : $this->Settings['Admin']->LimitRelatedThreadsBottomDiscussion;
         $this->SphinxClient->SetLimits(1, $limit);
         //notice the offset of '1'. This is so don't select current viewed discussion as related
         $Thread = $this->SphinxClient->EscapeString($Sender->Discussion->Name);
         //get the discussion name (thread topic) to search against
         $Query = $this->FieldSearch($this->OperatorOrSearch($Thread), array(SS_FIELD_TITLE));
         //Make sure results respect category permissions depending on user performing search
         $Permissions = Gdn::Session()->GetPermissions();
         // Get user permissions
         $Permissions = $Permissions['Vanilla.Discussions.View'];
         // Only care about 'viewing' permissions
         $this->SphinxClient->SetFilter(SS_ATTR_CATPERMID, $Permissions);
         $QueryIndex = $this->SphinxClient->AddQuery($Query . ' ', $Index = SS_INDEX_DIST, $this->Name);
         $this->Queries[] = array('Name' => $this->Name, 'Index' => $QueryIndex);
         return $this->Queries;
     } else {
         return FALSE;
     }
 }
Example #19
0
 /**
  * Render options that the user has for this category.
  */
 function GetOptions($Category)
 {
     if (!Gdn::Session()->IsValid()) {
         return;
     }
     $Sender = Gdn::Controller();
     $Result = '';
     $Options = '';
     $CategoryID = GetValue('CategoryID', $Category);
     $Result = '<div class="Options">';
     $TKey = urlencode(Gdn::Session()->TransientKey());
     // Mark category read.
     $Options .= '<li>' . Anchor(T('Mark Read'), "/vanilla/category/markread?categoryid={$CategoryID}&tkey={$TKey}") . '</li>';
     // Follow/Unfollow category.
     if (!GetValue('Following', $Category)) {
         $Options .= '<li>' . Anchor(T('Unhide'), "/vanilla/category/follow?categoryid={$CategoryID}&value=1&tkey={$TKey}") . '</li>';
     } else {
         $Options .= '<li>' . Anchor(T('Hide'), "/vanilla/category/follow?categoryid={$CategoryID}&value=0&tkey={$TKey}") . '</li>';
     }
     // Allow plugins to add options
     $Sender->FireEvent('CategoryOptions');
     if ($Options != '') {
         $Result .= '<span class="ToggleFlyout OptionsMenu">';
         $Result .= '<span class="OptionsTitle">' . T('Options') . '</span>';
         $Result .= '<span class="SpFlyoutHandle"></span>';
         $Result .= '<ul class="Flyout MenuItems">' . $Options . '</ul>';
         $Result .= '</span>';
         $Result .= '</div>';
         return $Result;
     }
 }
Example #20
0
    public function SettingsController_Render_Before(&$Sender)
    {
        // Save the action if editing registration settings
        if (strcasecmp($Sender->RequestMethod, 'registration') == 0 && $Sender->Form->AuthenticatedPostBack() === TRUE) {
            $this->SaveStep('Plugins.GettingStarted.Registration');
        }
        // Save the action if they reviewed plugins
        if (strcasecmp($Sender->RequestMethod, 'plugins') == 0) {
            $this->SaveStep('Plugins.GettingStarted.Plugins');
        }
        // Save the action if they reviewed plugins
        if (strcasecmp($Sender->RequestMethod, 'managecategories') == 0) {
            $this->SaveStep('Plugins.GettingStarted.Categories');
        }
        // Add messages & their css on dashboard
        if (strcasecmp($Sender->RequestMethod, 'index') == 0) {
            $Sender->AddCssFile('plugins/GettingStarted/style.css');
            $Session = Gdn::Session();
            $WelcomeMessage = '<div class="GettingStarted">' . Anchor('×', '/dashboard/plugin/dismissgettingstarted/' . $Session->TransientKey(), 'Dismiss') . "<p>Here's how to get started:</p>" . '<ul>
      <li class="One' . (Gdn::Config('Plugins.GettingStarted.Registration', '0') == '1' ? ' Done' : '') . '">' . Anchor(T('Define how users register for your forum'), '/settings/registration') . '</li>
      <li class="Two' . (Gdn::Config('Plugins.GettingStarted.Plugins', '0') == '1' ? ' Done' : '') . '">' . Anchor(T('Manage your plugins'), 'settings/plugins') . '</li>
      <li class="Three' . (Gdn::Config('Plugins.GettingStarted.Categories', '0') == '1' ? ' Done' : '') . '">' . Anchor(T('Organize your discussion categories'), 'vanilla/settings/managecategories') . '</li>
      <li class="Four' . (Gdn::Config('Plugins.GettingStarted.Profile', '0') == '1' ? ' Done' : '') . '">' . Anchor(T('Customize your profile'), 'profile') . '</li>
      <li class="Five' . (Gdn::Config('Plugins.GettingStarted.Discussion', '0') == '1' ? ' Done' : '') . '">' . Anchor(T('Start your first discussion'), 'post/discussion') . '</li>
   </ul>
</div>';
            $Sender->AddAsset('Messages', $WelcomeMessage, 'WelcomeMessage');
        }
    }
 public function ToString()
 {
     if (!Gdn::Session()->IsValid()) {
         return parent::ToString();
     }
     return '';
 }
 public function GetData($FingerprintUserID, $Fingerprint)
 {
     if (!Gdn::Session()->CheckPermission('Garden.Users.Edit')) {
         return;
     }
     $this->_Data = Gdn::SQL()->Select()->From('User')->Where('Fingerprint', $Fingerprint)->Where('UserID <>', $FingerprintUserID)->Get();
 }
Example #23
0
 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);
         }
     }
 }
 public function DiscussionsController_Participated_Create(&$Sender, $Args)
 {
     $Sender->Permission('Garden.SignIn.Allow');
     $Page = GetValue(0, $Args);
     $Limit = GetValue(1, $Args);
     list($Offset, $Limit) = OffsetLimit($Page, Gdn::Config('Vanilla.Discussions.PerPage', 30));
     // Get Discussions
     $DiscussionModel = new DiscussionModel();
     $Sender->DiscussionData = $DiscussionModel->GetParticipated(Gdn::Session()->UserID, $Offset, $Limit);
     $Sender->SetData('Discussions', $Sender->DiscussionData);
     $CountDiscussions = $DiscussionModel->GetCountParticipated(Gdn::Session()->UserID);
     $Sender->SetData('CountDiscussions', $CountDiscussions);
     // Build a pager
     $PagerFactory = new Gdn_PagerFactory();
     $Sender->EventArguments['PagerType'] = 'Pager';
     $Sender->FireEvent('BeforeBuildPager');
     $Sender->Pager = $PagerFactory->GetPager($Sender->EventArguments['PagerType'], $Sender);
     $Sender->Pager->ClientID = 'Pager';
     $Sender->Pager->Configure($Offset, $Limit, $CountDiscussions, 'discussions/participated/%1$s');
     $Sender->FireEvent('AfterBuildPager');
     // Deliver JSON data if necessary
     if ($Sender->DeliveryType() != DELIVERY_TYPE_ALL) {
         $Sender->SetJson('LessRow', $Sender->Pager->ToString('less'));
         $Sender->SetJson('MoreRow', $Sender->Pager->ToString('more'));
         $Sender->View = 'discussions';
     }
     // Add modules
     $Sender->AddModule('NewDiscussionModule');
     $Sender->AddModule('CategoriesModule');
     $BookmarkedModule = new BookmarkedModule($Sender);
     $BookmarkedModule->GetData();
     $Sender->AddModule($BookmarkedModule);
     $Sender->Render($this->GetView('participated.php'));
 }
 public function AddQuery($Sender, $Options = FALSE)
 {
     if ($Sender->ControllerName == 'searchcontroller' && $Options['Landing'] == FALSE && $this->Settings['Admin']->LimitRelatedThreadsMain > 0) {
         $Sanitized = $this->ValidateInputs();
         $this->SphinxClient->ResetFilters();
         $this->SphinxClient->ResetGroupBy();
         $this->SphinxClient->SetSortMode(SPH_SORT_RELEVANCE);
         $this->SphinxClient->SetRankingMode(SPH_RANK_WORDCOUNT);
         $this->SphinxClient->SetLimits(0, $this->Settings['Admin']->LimitRelatedThreadsMain);
         //must first clear any special characters in query string if using the extended syntax
         //@todo probably better to use the 'words' index
         $Query = $this->FieldSearch($this->OperatorOrSearch($this->ClearFromTags($Sanitized['Query'])), array(SS_FIELD_TITLE));
         //echo $Query; die;
         //Make sure results respect category permissions depending on user performing search
         $Permissions = Gdn::Session()->GetPermissions();
         // Get user permissions
         $Permissions = $Permissions['Vanilla.Discussions.View'];
         // Only care about 'viewing' permissions
         $this->SphinxClient->SetFilter(SS_ATTR_CATPERMID, $Permissions);
         $QueryIndex = $this->SphinxClient->AddQuery($Query . ' ', $Index = SS_INDEX_DIST, $this->Name);
         $this->Queries[] = array('Name' => $this->Name, 'Index' => $QueryIndex);
         return $this->Queries;
     } else {
         return FALSE;
     }
 }
 public function ToString()
 {
     $HasPermission = Gdn::Session()->CheckPermission('Vanilla.Discussions.Add', TRUE, 'Category', 'any');
     if ($HasPermission) {
         echo Anchor(T('Ask a Question'), '/post/discussion?Type=Question', 'Button BigButton NewQuestion');
     }
 }
 public function __construct(&$Sender = '')
 {
     $Session = Gdn::Session();
     if (property_exists($Sender, 'Conversation')) {
         $this->Conversation = $Sender->Conversation;
     }
     $this->Form = Gdn::Factory('Form', 'AddPeople');
     // $this->Form->Action = $Sender->SelfUrl;
     // If the form was posted back, check for people to add to the conversation
     if ($this->Form->AuthenticatedPostBack()) {
         $NewRecipientUserIDs = array();
         $NewRecipients = explode(',', $this->Form->GetFormValue('AddPeople', ''));
         $UserModel = Gdn::Factory("UserModel");
         foreach ($NewRecipients as $Name) {
             if (trim($Name) != '') {
                 $User = $UserModel->GetByUsername(trim($Name));
                 if (is_object($User)) {
                     $NewRecipientUserIDs[] = $User->UserID;
                 }
             }
         }
         $Sender->ConversationModel->AddUserToConversation($this->Conversation->ConversationID, $NewRecipientUserIDs);
         // if ($Sender->DeliveryType() == DELIVERY_TYPE_ALL)
         //    Redirect('/messages/'.$this->Conversation->ConversationID);
         $Sender->StatusMessage = T('Your changes were saved.');
         $Sender->RedirectUrl = Url('/messages/' . $this->Conversation->ConversationID);
     }
     $this->_ApplicationFolder = $Sender->Application;
     $this->_ThemeFolder = $Sender->Theme;
 }
Example #28
0
 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;
         }
     }
 }
Example #29
0
 public function GetMessagesForLocation($Location, $Exceptions = array('[Base]'))
 {
     $Session = Gdn::Session();
     $Prefs = $Session->GetPreference('DismissedMessages', array());
     if (count($Prefs) == 0) {
         $Prefs[] = 0;
     }
     $Exceptions = array_map('strtolower', $Exceptions);
     list($Application, $Controller, $Method) = explode('/', strtolower($Location));
     if (Gdn::Cache()->ActiveEnabled()) {
         // Get the messages from the cache.
         $Messages = self::Messages();
         $Result = array();
         foreach ($Messages as $MessageID => $Message) {
             if (in_array($MessageID, $Prefs) || !$Message['Enabled']) {
                 continue;
             }
             $MApplication = strtolower($Message['Application']);
             $MController = strtolower($Message['Controller']);
             $MMethod = strtolower($Message['Method']);
             if (in_array($MController, $Exceptions)) {
                 $Result[] = $Message;
             } elseif ($MApplication == $Application && $MController == $Controller && $MMethod == $Method) {
                 $Result[] = $Message;
             }
         }
         return $Result;
     }
     return $this->SQL->Select()->From('Message')->Where('Enabled', '1')->BeginWhereGroup()->WhereIn('Controller', $Exceptions)->BeginWhereGroup()->OrWhere('Application', $Application)->Where('Controller', $Controller)->Where('Method', $Method)->EndWhereGroup()->EndWhereGroup()->WhereNotIn('MessageID', $Prefs)->OrderBy('Sort', 'asc')->Get()->ResultArray();
 }
Example #30
0
 public function PluginController_LoadUp_Create(&$Sender)
 {
     $Sender->AddSideMenu('dashboard/plugin/loadup');
     $Sender->Permission('Plugins.Garden.LoadUp.Allow');
     if (!property_exists($Sender, 'Form')) {
         $Sender->Form = Gdn::Factory('Form');
     }
     $Sender->AddJsFile('jquery.livequery.js');
     $Sender->AddJsFile('jquery.autogrow.js');
     $Sender->AddJsFile('plugins/LoadUp/loadup.js');
     $Session = Gdn::Session();
     if ($Sender->Form->AuthenticatedPostBack() != False) {
         $UploadTo = $Sender->Form->GetFormValue('UploadTo');
         if (!$UploadTo) {
             $UploadTo = 'uploads/i/' . date('Y') . '/' . date('m');
         }
         $bOverwrite = $Sender->Form->GetFormValue('Overwrite') && $Session->CheckPermission('Plugins.Garden.LoadUp.Overwrite');
         $Options = array('Overwrite' => $bOverwrite, 'WebTarget' => True);
         $UploadedFiles = UploadFile($UploadTo, 'Files', $Options);
         $Sender->Form->SetFormValue('RawData', implode("\n", $UploadedFiles));
         $Sender->Form->SetFormValue('AbsoluteURL', 1);
     }
     $Sender->UploadTo = array('uploads/tmp' => 'uploads/tmp');
     $Sender->View = $this->GetView('index.php');
     $Sender->Title(T('Upload File'));
     $Sender->Render();
 }