By default, global items display no matter the section we're in. If a section is not specified, the item is added to the SECTION_DEFAULT. If we are in a section without a custom nav, these items will display. We can force the module to display any section menus by setting the currentSections property. Beware, you'll need to handle the user preference saving if you do this. TODO: Handle the dropdown menu case.
상속: extends NavModule
예제 #1
0
 /**
  * @return bool
  * @throws Exception
  */
 public function prepare()
 {
     if (!self::$initStaticFired) {
         self::$initStaticFired = true;
         $this->fireEvent('init');
     }
     if (empty($this->currentSections)) {
         $currentSections = Gdn_Theme::section('', 'get');
         $currentSections = array_map('strtolower', $currentSections);
         $customMenuKeys = array_intersect(array_keys(self::$sectionItems), $currentSections);
         $hasCustomMenu = !empty($customMenuKeys);
         if (!$hasCustomMenu) {
             $currentSections = [self::SECTION_DEFAULT];
         }
         // Add global items
         $currentSections[] = self::SECTION_GLOBAL;
     } else {
         $currentSections = array_map('strtolower', $this->currentSections);
     }
     foreach ($currentSections as $currentSection) {
         if ($section = val(strtolower($currentSection), self::$sectionItems)) {
             $this->addSectionItems($section);
         }
     }
     return parent::prepare();
 }
예제 #2
0
파일: class.hooks.php 프로젝트: R-J/vanilla
 /**
  *
  *
  * @param SiteNavModule $sender
  */
 public function siteNavModule_profile_handler($sender)
 {
     $user = Gdn::controller()->data('Profile');
     $user_id = val('UserID', $user);
     // Show the activity.
     if (c('Garden.Profile.ShowActivities', true)) {
         $sender->addLink('main.activity', array('text' => t('Activity'), 'url' => userUrl($user, '', 'activity'), 'icon' => icon('time')));
     }
     // Display the notifications for the current user.
     if (Gdn::controller()->data('Profile.UserID') == Gdn::session()->UserID) {
         $sender->addLink('main.notifications', array('text' => t('Notifications'), 'url' => userUrl($user, '', 'notifications'), 'icon' => icon('globe'), 'badge' => Gdn::controller()->data('Profile.CountNotifications')));
     }
     // Show the invitations if we're using the invite registration method.
     if (strcasecmp(c('Garden.Registration.Method'), 'invitation') === 0) {
         $sender->addLink('main.invitations', array('text' => t('Invitations'), 'url' => userUrl($user, '', 'invitations'), 'icon' => icon('ticket')));
     }
     // Users can edit their own profiles and moderators can edit any profile.
     if (hasEditProfile($user_id)) {
         $sender->addLink('main.editprofile', array('text' => t('Edit Profile'), 'url' => userUrl($user, '', 'edit'), 'icon' => icon('edit')));
     }
     // Add a stub group for moderation.
     $sender->addGroup('moderation', array('text' => t('Moderation'), 'sort' => 90));
 }
예제 #3
0
 /**
  *
  *
  * @param SiteNavModule $sender
  */
 public function siteNavModule_init_handler($sender)
 {
     // GLOBALS
     // Add a link to the community home.
     $sender->addLinkToGlobals(t('Community Home'), '/', 'main.home', '', -100, array('icon' => 'home'), false);
     $sender->addGroupToGlobals('', 'etc', '', 100);
     $sender->addLinkToGlobalsIf(Gdn::session()->isValid() && IsMobile(), t('Full Site'), '/profile/nomobile', 'etc.nomobile', '', 100, array('icon' => 'resize-full'));
     $sender->addLinkToGlobalsIf(Gdn::session()->isValid(), t('Sign Out'), SignOutUrl(), 'etc.signout', '', 100, array('icon' => 'signout'));
     $sender->addLinkToGlobalsIf(!Gdn::session()->isValid(), t('Sign In'), SigninUrl(), 'etc.signin', '', 100, array('icon' => 'signin'));
     // DEFAULTS
     if (!Gdn::session()->isValid()) {
         return;
     }
     $sender->addLinkIf(Gdn::session()->isValid(), t('Profile'), '/profile', 'main.profile', 'profile', 10, array('icon' => 'user'))->addLinkIf('Garden.Activity.View', t('Activity'), '/activity', 'main.activity', 'activity', 10, array('icon' => 'time'));
     // Add the moderation items.
     $sender->addGroup(t('Moderation'), 'moderation', 'moderation', 90);
     if (Gdn::session()->checkPermission('Garden.Users.Approve')) {
         $RoleModel = new RoleModel();
         $applicant_count = (int) $RoleModel->getApplicantCount();
         if ($applicant_count > 0 || true) {
             $sender->addLink(t('Applicants'), '/user/applicants', 'moderation.applicants', 'applicants', array(), array('icon' => 'user', 'badge' => $applicant_count));
         }
     }
     $sender->addLinkIf('Garden.Moderation.Manage', t('Spam Queue'), '/log/spam', 'moderation.spam', 'spam', array(), array('icon' => 'spam'))->addLinkIf('Garden.Settings.Manage', t('Dashboard'), '/settings', 'etc.dashboard', 'dashboard', array(), array('icon' => 'dashboard'));
     $user = Gdn::controller()->data('Profile');
     $user_id = val('UserID', $user);
     //EDIT PROFILE SECTION
     // Users can edit their own profiles and moderators can edit any profile.
     $sender->addLinkToSectionIf(hasEditProfile($user_id), 'EditProfile', t('Profile'), userUrl($user, '', 'edit'), 'main.editprofile', '', array(), array('icon' => 'edit'))->addLinkToSectionIf('Garden.Users.Edit', 'EditProfile', t('Edit Account'), '/user/edit/' . $user_id, 'main.editaccount', 'Popup', array(), array('icon' => 'cog'))->addLinkToSection('EditProfile', t('Back to Profile'), userUrl($user), 'main.profile', '', 100, array('icon' => 'arrow-left'));
     //PROFILE SECTION
     $sender->addLinkToSectionIf(c('Garden.Profile.ShowActivities', true), 'Profile', t('Activity'), userUrl($user, '', 'activity'), 'main.activity', '', array(), array('icon' => 'time'))->addLinkToSectionIf(Gdn::controller()->data('Profile.UserID') == Gdn::session()->UserID, 'Profile', t('Notifications'), userUrl($user, '', 'notifications'), 'main.notifications', '', array(), array('icon' => 'globe', 'badge' => Gdn::controller()->data('Profile.CountNotifications')))->addLinkToSectionIf(strcasecmp(c('Garden.Registration.Method'), 'invitation') === 0, 'Profile', t('Invitations'), userUrl($user, '', 'invitations'), 'main.invitations', '', array(), array('icon' => 'ticket'))->addLinkToSectionIf(hasEditProfile($user_id), 'Profile', t('Edit Profile'), userUrl($user, '', 'edit'), 'Profile', 'main.editprofile', '', array(), array('icon' => 'edit'));
 }
예제 #4
0
 public function toString()
 {
     if (!self::$initStaticFired) {
         self::$initStaticFired = true;
         $this->fireEvent('init');
     }
     $this->fireAs(get_called_class())->fireEvent('render');
     return parent::toString();
 }