public function MediaCache()
 {
     if ($this->_MediaCache === NULL) {
         $this->CacheAttachedMedia(Gdn::Controller());
     }
     return $this->_MediaCache;
 }
 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();
 }
 private static function InformMessage($Message, $Sprite = 'Check')
 {
     $Controller = Gdn::Controller();
     if ($Controller) {
         $Options = array('Sprite' => $Sprite, 'CssClass' => 'Dismissable AutoDismiss');
         $Controller->InformMessage($Message, $Options);
     }
 }
 public function ToString()
 {
     if (!$this->Data('Discussions')) {
         $this->GetData();
     }
     require_once Gdn::Controller()->FetchViewLocation('helper_functions', 'Discussions', 'Vanilla');
     return parent::ToString();
 }
 /**
  * Set Comment's DateInserted to Discussion's DateLastComment so there's no change.
  */
 public function CommentModel_BeforeUpdateCommentCount_Handler($Sender)
 {
     if (Gdn::Session()->CheckPermission('Garden.Moderation.Manage')) {
         if (Gdn::Controller()->Form->GetFormValue('NoBump')) {
             $Sender->EventArguments['Discussion']['Sink'] = 1;
         }
     }
 }
 public function ToString()
 {
     Gdn::Controller()->EventArguments['NewDiscussionModule'] =& $this;
     Gdn::Controller()->FireEvent('BeforeNewDiscussionButton');
     $HasPermission = Gdn::Session()->CheckPermission('Vanilla.Discussions.Add', TRUE, 'Category', 'any');
     if (!$HasPermission) {
         return '';
     }
     return parent::ToString();
 }
 public function LoadData()
 {
     $UserID = Gdn::Controller()->Data('Profile.UserID', Gdn::Session()->UserID);
     $this->User = Gdn::UserModel()->GetID($UserID);
     $this->Roles = Gdn::UserModel()->GetRoles($UserID)->ResultArray();
     // Hide personal info roles
     if (!CheckPermission('Garden.PersonalInfo.View')) {
         $this->Roles = array_filter($this->Roles, 'RoleModel::FilterPersonalInfo');
     }
 }
 /**
  * Adds "Mark All Viewed" and (conditionally) "Mark Category Viewed" to MeModule menu.
  *
  * @since 2.0
  * @access public
  */
 public function MeModule_FlyoutMenu_Handler($Sender)
 {
     // Add "Mark All Viewed" to menu
     if (Gdn::Session()->IsValid()) {
         echo Wrap(Anchor(Sprite('SpMarkAllViewed') . ' ' . T('Mark All Viewed'), '/discussions/markallviewed'), 'li', array('class' => 'MarkAllViewed'));
         $CategoryID = (int) (empty(Gdn::Controller()->CategoryID) ? 0 : Gdn::Controller()->CategoryID);
         if ($CategoryID > 0) {
             echo Wrap(Anchor(Sprite('SpMarkCategoryViewed') . ' ' . T('Mark Category Viewed'), "/discussions/markcategoryviewed/{$CategoryID}"), 'li', array('class' => 'MarkCategoryViewed'));
         }
     }
 }
 public function SettingsController_Render_Before($Sender)
 {
     $RequestMethod = $Sender->RequestMethod;
     if ($RequestMethod == 'managecategories' || $RequestMethod == 'tagging') {
         $Sender->AddJsFile($this->GetResource('js/refreshcounts.js', FALSE, FALSE));
         //check for any stashed messages from the pre
         $Message = Gdn::Session()->Stash('RefreshCountsMessage');
         if ($Message) {
             //inform
             Gdn::Controller()->InformMessage($Message);
         }
     }
 }
Example #10
0
 /**
  *
  * @param Gdn_Form $Sender 
  */
 public function Gdn_Form_BeforeBodyBox_Handler($Sender, $Args)
 {
     $this->_AddCLEditor(Gdn::Controller());
     $Format = $Sender->GetValue('Format');
     if ($Format) {
         $Formatter = Gdn::Factory($Format . 'Formatter');
         if ($Formatter && method_exists($Formatter, 'FormatForWysiwyg')) {
             $Body = $Formatter->FormatForWysiwyg($Sender->GetValue('Body'));
             $Sender->SetValue('Body', $Body);
         } elseif (!in_array($Format, array('Html', 'Wysiwyg'))) {
             $Sender->SetValue('Body', Gdn_Format::To($Sender->GetValue('Body'), $Format));
         }
     }
     $Sender->SetValue('Format', 'Wysiwyg');
 }
 public function ToString()
 {
     Gdn::Controller()->EventArguments['NewDiscussionModule'] =& $this;
     Gdn::Controller()->FireEvent('BeforeNewDiscussionButton');
     $HasPermission = Gdn::Session()->CheckPermission('Vanilla.Discussions.Add', TRUE, 'Category', 'any');
     if (!$HasPermission) {
         return '';
     }
     if ($this->QueryString) {
         foreach ($this->Buttons as &$Row) {
             $Row['Url'] .= (strpos($Row['Url'], '?') !== FALSE ? '&' : '?') . $this->QueryString;
         }
     }
     return parent::ToString();
 }
 /**
  * Render the module.
  *
  * @return string
  */
 public function ToString()
 {
     // Set CategoryID if we have one.
     if ($this->CategoryID === NULL) {
         $this->CategoryID = Gdn::Controller()->Data('Category.CategoryID', FALSE);
     }
     // Allow plugins and themes to modify parameters.
     Gdn::Controller()->EventArguments['NewDiscussionModule'] =& $this;
     Gdn::Controller()->FireEvent('BeforeNewDiscussionButton');
     // Make sure the user has the most basic of permissions first.
     $PermissionCategory = CategoryModel::PermissionCategory($this->CategoryID);
     if ($this->CategoryID) {
         $Category = CategoryModel::Categories($this->CategoryID);
         $HasPermission = Gdn::Session()->CheckPermission('Vanilla.Discussions.Add', TRUE, 'Category', GetValue('CategoryID', $PermissionCategory));
     } else {
         $HasPermission = Gdn::Session()->CheckPermission('Vanilla.Discussions.Add', TRUE, 'Category', 'any');
     }
     // Determine if this is a guest & we're using "New Discussion" button as call to action.
     $PrivilegedGuest = $this->ShowGuests && !Gdn::Session()->IsValid();
     // No module for you!
     if (!$HasPermission && !$PrivilegedGuest) {
         return '';
     }
     // Grab the allowed discussion types.
     $DiscussionTypes = CategoryModel::AllowedDiscussionTypes($PermissionCategory);
     foreach ($DiscussionTypes as $Key => $Type) {
         if (isset($Type['AddPermission']) && !Gdn::Session()->CheckPermission($Type['AddPermission'])) {
             unset($DiscussionTypes[$Key]);
             continue;
         }
         // If user !$HasPermission, they are $PrivilegedGuest so redirect to $GuestUrl.
         $Url = $HasPermission ? GetValue('AddUrl', $Type) : $this->GuestUrl;
         if (!$Url) {
             continue;
         }
         if (isset($Category) && $HasPermission) {
             $Url .= '/' . rawurlencode(GetValue('UrlCode', $Category));
         }
         $this->AddButton(T(GetValue('AddText', $Type)), $Url);
     }
     // Add QueryString to URL if one is defined.
     if ($this->QueryString && $HasPermission) {
         foreach ($this->Buttons as &$Row) {
             $Row['Url'] .= (strpos($Row['Url'], '?') !== FALSE ? '&' : '?') . $this->QueryString;
         }
     }
     return parent::ToString();
 }
function ConnectButton($Row)
{
    $c = Gdn::Controller();
    $Connected = GetValue('Connected', $Row);
    $CssClass = $Connected ? 'Active' : 'InActive';
    $ConnectUrl = GetValue('ConnectUrl', $Row);
    $DisconnectUrl = UserUrl($c->User, '', 'Disconnect', array('provider' => $Row['ProviderKey']));
    $Result = '<span class="ActivateSlider ActivateSlider-' . $CssClass . '">';
    if ($Connected) {
        $Result .= Anchor(T('Connected'), $DisconnectUrl, 'Button Primary Hijack');
    } else {
        $Result .= Anchor(T('Connect'), $ConnectUrl, 'Button');
    }
    $Result .= '</span>';
    return $Result;
}
 public function API($Path, $Post = FALSE)
 {
     // Build the url.
     $Url = 'https://graph.facebook.com/' . ltrim($Path, '/');
     $AccessToken = $this->AccessToken();
     if (!$AccessToken) {
         throw new Gdn_UserException("You don't have a valid Facebook connection.");
     }
     if (strpos($Url, '?') === false) {
         $Url .= '?';
     } else {
         $Url .= '&';
     }
     $Url .= 'access_token=' . urlencode($AccessToken);
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_HEADER, false);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
     curl_setopt($ch, CURLOPT_URL, $Url);
     if ($Post !== false) {
         curl_setopt($ch, CURLOPT_POST, true);
         curl_setopt($ch, CURLOPT_POSTFIELDS, $Post);
         Trace("  POST {$Url}");
     } else {
         Trace("  GET  {$Url}");
     }
     $Response = curl_exec($ch);
     $HttpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
     $ContentType = curl_getinfo($ch, CURLINFO_CONTENT_TYPE);
     curl_close($ch);
     Gdn::Controller()->SetJson('Type', $ContentType);
     if (strpos($ContentType, 'javascript') !== FALSE) {
         $Result = json_decode($Response, TRUE);
         if (isset($Result['error'])) {
             Gdn::Dispatcher()->PassData('FacebookResponse', $Result);
             throw new Gdn_UserException($Result['error']['message']);
         }
     } else {
         $Result = $Response;
     }
     return $Result;
 }
Example #15
0
 /**
  * Class constructor
  *
  * @param object $Sender
  */
 public function __construct($Sender = '', $ApplicationFolder = FALSE)
 {
     if (!$Sender) {
         $Sender = Gdn::Controller();
     }
     if (is_object($Sender)) {
         $this->_ApplicationFolder = $Sender->ApplicationFolder;
         $this->_ThemeFolder = $Sender->Theme;
     } else {
         $this->_ApplicationFolder = 'dashboard';
         $this->_ThemeFolder = Gdn::Config('Garden.Theme');
     }
     if ($ApplicationFolder !== FALSE) {
         $this->_ApplicationFolder = $ApplicationFolder;
     }
     if (is_object($Sender)) {
         $this->_Sender = $Sender;
     }
     parent::__construct();
 }
Example #16
0
 function SetMetaTags($Page, $Controller = Null)
 {
     if (!$Controller) {
         $Controller = Gdn::Controller();
     }
     if ($Page->MetaDescription) {
         $Controller->Head->AddTag('meta', array('name' => 'description', 'content' => $Page->MetaDescription, '_sort' => 0));
     }
     if ($Page->MetaKeywords) {
         $Controller->Head->AddTag('meta', array('name' => 'keywords', 'content' => $Page->MetaKeywords, '_sort' => 0));
     }
     if ($Page->MetaRobots) {
         $Controller->Head->AddTag('meta', array('name' => 'robots', 'content' => $Page->MetaRobots, '_sort' => 0));
     }
     if ($Page->MetaTitle) {
         $Controller->Head->Title($Page->MetaTitle);
     }
     $Controller->Head->AddTag('meta', array('http-equiv' => 'content-language', 'content' => Gdn::Locale()->Current()));
     $Controller->Head->AddTag('meta', array('http-equiv' => 'content-type', 'content' => 'text/html; charset=utf-8'));
 }
 public function ToString()
 {
     if ($this->CategoryID === NULL) {
         $this->CategoryID = Gdn::Controller()->Data('Category.CategoryID', FALSE);
     }
     Gdn::Controller()->EventArguments['NewDiscussionModule'] =& $this;
     Gdn::Controller()->FireEvent('BeforeNewDiscussionButton');
     // Make sure the user has the most basic of permissions first.
     $PermissionCategory = CategoryModel::PermissionCategory($this->CategoryID);
     if ($this->CategoryID) {
         $Category = CategoryModel::Categories($this->CategoryID);
         $HasPermission = Gdn::Session()->CheckPermission('Vanilla.Discussions.Add', TRUE, 'Category', GetValue('CategoryID', $PermissionCategory));
     } else {
         $HasPermission = Gdn::Session()->CheckPermission('Vanilla.Discussions.Add', TRUE, 'Category', 'any');
     }
     if (!$HasPermission) {
         return '';
     }
     // Grab the allowed discussion types.
     $DiscussionTypes = CategoryModel::AllowedDiscussionTypes($PermissionCategory);
     foreach ($DiscussionTypes as $Key => $Type) {
         if (isset($Type['AddPermission']) && !Gdn::Session()->CheckPermission($Type['AddPermission'])) {
             unset($DiscussionTypes[$Key]);
             continue;
         }
         $Url = GetValue('AddUrl', $Type);
         if (!$Url) {
             continue;
         }
         if (isset($Category)) {
             $Url .= '/' . rawurlencode(GetValue('UrlCode', $Category));
         }
         $this->AddButton(T(GetValue('AddText', $Type)), $Url);
     }
     if ($this->QueryString) {
         foreach ($this->Buttons as &$Row) {
             $Row['Url'] .= (strpos($Row['Url'], '?') !== FALSE ? '&' : '?') . $this->QueryString;
         }
     }
     return parent::ToString();
 }
 protected function AutoContext($Hint = NULL)
 {
     // If we're already configured, don't auto configure
     if (!is_null($this->ParentID) && is_null($Hint)) {
         return;
     }
     // If no hint was given, determine by environment
     if (is_null($Hint)) {
         if (Gdn::Controller() instanceof Gdn_Controller) {
             $DiscussionID = Gdn::Controller()->Data('Discussion.DiscussionID', NULL);
             $CategoryID = Gdn::Controller()->Data('Category.CategoryID', NULL);
             if ($DiscussionID) {
                 $Hint = 'Discussion';
             } elseif ($CategoryID) {
                 $Hint = 'Category';
             } else {
                 $Hint = 'Global';
             }
         }
     }
     switch ($Hint) {
         case 'Discussion':
             $this->ParentType = 'Discussion';
             $DiscussionID = Gdn::Controller()->Data('Discussion.DiscussionID');
             $this->ParentID = $DiscussionID;
             break;
         case 'Category':
             if ($this->CategorySearch) {
                 $this->ParentType = 'Category';
                 $CategoryID = Gdn::Controller()->Data('Category.CategoryID');
                 $this->ParentID = $CategoryID;
             }
             break;
     }
     if (!$this->ParentID) {
         $this->ParentID = 0;
         $this->ParentType = 'Global';
     }
 }
Example #19
0
 /**
  * Adds first crumb and last crumb.
  * 
  */
 public function WrapCrumbs($First = True, $Last = True)
 {
     if (!($First && $Last)) {
         return;
     }
     $GroupFirstItem = array();
     $GroupLastItem = array();
     if ($First != False) {
         $Home = T('Home');
         $FirstItem = array(0 => array('Name' => $Home, 'Url' => '/'));
         $GroupFirstItem = array($Home => $FirstItem);
     }
     if ($Last != False) {
         $Text = Gdn::Controller()->Data('Title');
         //$this->Controller
         //$Text = $this->_Sender->Data('Title');
         $Item = array(0 => array('Name' => $Text, 'Url' => '/'));
         $GroupLastItem = array($Text => $Item);
     }
     $this->Items = $GroupFirstItem + $this->Items + $GroupLastItem;
     $this->bCrumbsWrapped = True;
 }
 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) {
         $ProfileOptions[] = array('Text' => T('Back to Profile'), 'Url' => UserUrl($Controller->User), 'CssClass' => 'BackToProfile');
     } else {
         if ($Controller->User->UserID != $Session->UserID) {
             if ($Session->CheckPermission('Garden.Users.Edit')) {
                 $ProfileOptions[] = array('Text' => Sprite('SpEditProfile') . T('Edit Profile'), 'Url' => UserUrl($Controller->User, '', 'edit'));
             }
         } else {
             if (C('Garden.UserAccount.AllowEdit')) {
                 $ProfileOptions[] = array('Text' => Sprite('SpEditProfile') . T('Edit Profile'), 'Url' => '/profile/edit');
             }
         }
         if ($Session->CheckPermission('Garden.Moderation.Manage') && $UserID != $Session->UserID) {
             // Ban/Unban
             if ($Controller->User->Banned) {
                 $ProfileOptions[] = array('Text' => Sprite('SpBan') . T('Unban'), 'Url' => "/user/ban?userid={$UserID}&unban=1", 'CssClass' => 'Popup');
             } else {
                 $ProfileOptions[] = array('Text' => Sprite('SpBan') . T('Ban'), 'Url' => "/user/ban?userid={$UserID}", 'CssClass' => 'Popup');
             }
             // Delete content.
             if (!$Controller->User->Banned) {
                 $ProfileOptions[] = array('Text' => Sprite('SpDelete') . T('Delete Content'), 'Url' => "/user/deletecontent?userid={$UserID}", 'CssClass' => 'Popup');
             }
         }
     }
     return parent::ToString();
 }
 public function CommentModel_AfterGet_Handler($Sender, $Args)
 {
     // Grab the whispers associated with this discussion.
     $DiscussionID = $Args['DiscussionID'];
     $Comments =& $Args['Comments'];
     $CommentsResult =& $Comments->Result();
     $Whispers = $this->GetWhispers($DiscussionID, $CommentsResult, $Args['Limit'], $Args['Offset']);
     $Whispers->DatasetType($Comments->DatasetType());
     $CommentsResult = $this->MergeWhispers($CommentsResult, $Whispers->Result());
     // Check to see if the whispers are more recent than the last comment in the discussion so that the discussion will update the watch.
     if (isset(Gdn::Controller()->Discussion)) {
         $Discussion =& Gdn::Controller()->Discussion;
         $DateLastComment = Gdn_Format::ToTimestamp(GetValue('DateLastComment', $Discussion));
         foreach ($this->Conversations as $Conversation) {
             if (Gdn_Format::ToTimestamp($Conversation['DateUpdated']) > $DateLastComment) {
                 SetValue('DateLastComment', $Discussion, $Conversation['DateUpdated']);
                 $DateLastComment = Gdn_Format::ToTimestamp($Conversation['DateUpdated']);
             }
         }
     }
 }
 public function ThemeView($View)
 {
     $ThemeViewLoc = CombinePaths(array(PATH_THEMES, Gdn::Controller()->Theme, 'views', $this->GetPluginFolder(FALSE)));
     if (file_exists($ThemeViewLoc . DS . $View . '.php')) {
         $View = $ThemeViewLoc . DS . $View . '.php';
     } else {
         $View = $this->GetView($View . '.php');
     }
     return $View;
 }
 public function DiscussionModel_BeforeGet_Handler($Sender, $Args)
 {
     $Unanswered = Gdn::Controller()->ClassName == 'DiscussionsController' && Gdn::Controller()->RequestMethod == 'unanswered';
     if ($Unanswered) {
         $Args['Wheres']['Type'] = 'Question';
         $Sender->SQL->WhereIn('d.QnA', array('Unanswered', 'Rejected'));
         Gdn::Controller()->Title('Unanswered Questions');
     } elseif ($QnA = Gdn::Request()->Get('qna')) {
         $Args['Wheres']['QnA'] = $QnA;
     }
 }
Example #24
0
?>
<div class="DataListWrap">
<h1 class="H">
   <?php 
echo $this->Participants;
if ($this->Data('Conversation.Subject')) {
    echo Bullet(' ') . '<span class="Gloss">' . htmlspecialchars($this->Data('Conversation.Subject')) . '</span>';
}
?>
</h1>
<?php 
if ($this->Data('Conversation.Type')) {
    $this->FireEvent('Conversation' . str_replace('_', '', $this->Data('Conversation.Type')));
}
if ($this->Data('_HasDeletedUsers')) {
    echo '<div class="Info">', T('One or more users have left this conversation.', 'One or more users have left this conversation. They won\'t receive any more messages unless you add them back in to the conversation.'), '</div>';
}
$this->FireEvent('BeforeConversation');
echo $this->Pager->ToString('less');
?>
<ul class="DataList MessageList Conversation">
   <?php 
$MessagesViewLocation = $this->FetchViewLocation('messages');
include $MessagesViewLocation;
?>
</ul>
</div>
<?php 
echo $this->Pager->ToString();
echo Gdn::Controller()->FetchView('addmessage');
         <tr>
            <td class="<?php 
        echo "Depth_{$Category['Depth']}";
        ?>
"><?php 
        echo $Category['Name'];
        ?>
</td>
            <td class="PrefCheckBox"><?php 
        echo Gdn::Controller()->Form->CheckBox("Email.NewDiscussion.{$CategoryID}", '', array('value' => 1));
        ?>
</td>
            <td class="PrefCheckBox"><?php 
        echo Gdn::Controller()->Form->CheckBox("Popup.NewDiscussion.{$CategoryID}", '', array('value' => 1));
        ?>
</td>
            <td class="PrefCheckBox"><?php 
        echo Gdn::Controller()->Form->CheckBox("Email.NewComment.{$CategoryID}", '', array('value' => 1));
        ?>
</td>
            <td class="PrefCheckBox"><?php 
        echo Gdn::Controller()->Form->CheckBox("Popup.NewComment.{$CategoryID}", '', array('value' => 1));
        ?>
</td>
         </tr>
      <?php 
    }
}
?>
   </tbody>
</table>
Example #26
0
    function WriteEmbedCommentForm()
    {
        $Session = Gdn::Session();
        $Controller = Gdn::Controller();
        $Discussion = $Controller->Data('Discussion');
        if ($Discussion && $Discussion->Closed == '1') {
            ?>
   <div class="Foot Closed">
      <div class="Note Closed"><?php 
            echo T('This discussion has been closed.');
            ?>
</div>
   </div>
   <?php 
        } else {
            ?>
   <h2><?php 
            echo T('Leave a comment');
            ?>
</h2>
   <div class="MessageForm CommentForm EmbedCommentForm">
      <?php 
            echo $Controller->Form->Open();
            echo $Controller->Form->Errors();
            echo Wrap($Controller->Form->TextBox('Body', array('MultiLine' => TRUE)), 'div', array('class' => 'TextBoxWrapper'));
            echo "<div class=\"Buttons\">\n";
            $AllowSigninPopup = C('Garden.SignIn.Popup');
            $Attributes = array('tabindex' => '-1');
            $ReturnUrl = Gdn::Request()->PathAndQuery();
            if ($Session->IsValid()) {
                $AuthenticationUrl = Gdn::Authenticator()->SignOutUrl($ReturnUrl);
                echo Wrap(sprintf(T('Commenting as %1$s (%2$s)', 'Commenting as %1$s <span class="SignOutWrap">(%2$s)</span>'), Gdn_Format::Text($Session->User->Name), Anchor(T('Sign Out'), $AuthenticationUrl, 'SignOut', $Attributes)), 'div', array('class' => 'Author'));
                echo $Controller->Form->Button('Post Comment', array('class' => 'Button CommentButton'));
            } else {
                $AuthenticationUrl = SignInUrl($ReturnUrl);
                if ($AllowSigninPopup) {
                    $CssClass = 'SignInPopup Button Stash';
                } else {
                    $CssClass = 'Button Stash';
                }
                echo Anchor(T('Comment As ...'), $AuthenticationUrl, $CssClass, $Attributes);
            }
            echo "</div>\n";
            echo $Controller->Form->Close();
            ?>
   </div>
   <?php 
        }
    }
Example #27
0
<?php

if (!defined('APPLICATION')) {
    exit;
}
echo '<div class="BoxButtons BoxNewDiscussion">';
$Text = T('Start a New Discussion', 'New Discussion');
$UrlCode = GetValue('UrlCode', GetValue('Category', $Data), '');
$Url = '/post/discussion/' . $UrlCode;
$Css = 'Button Primary Action NewDiscussion';
$Css .= strpos($this->CssClass, 'Big') !== FALSE ? ' BigButton' : '';
if (count($this->Buttons) == 0) {
    echo Anchor($Text, $Url, $Css);
} else {
    // Make the core button action be the first item in the button group.
    array_unshift($this->Buttons, array('Text' => $Text, 'Url' => $Url));
    echo ButtonGroup($this->Buttons, $this->CssClass, $this->DefaultButton);
}
Gdn::Controller()->FireEvent('AfterNewDiscussionButton');
echo '</div>';
Example #28
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::Session()->NewVisit()) {
         Gdn::UserModel()->FireEvent('Visit');
     }
     // Move this up to allow pre-routing
     $this->FireEvent('BeforeDispatch');
     // By default, all requests can be blocked by UpdateMode/PrivateCommunity
     $CanBlock = self::BLOCK_ANY;
     try {
         $BlockExceptions = array('/^utility(\\/.*)?$/' => self::BLOCK_NEVER, '/^plugin(\\/.*)?$/' => self::BLOCK_NEVER, '/^sso(\\/.*)?$/' => self::BLOCK_NEVER, '/^discussions\\/getcommentcounts/' => self::BLOCK_NEVER, '/^entry(\\/.*)?$/' => self::BLOCK_PERMISSION, '/^user\\/usernameavailable(\\/.*)?$/' => self::BLOCK_PERMISSION, '/^user\\/emailavailable(\\/.*)?$/' => self::BLOCK_PERMISSION, '/^home\\/termsofservice(\\/.*)?$/' => self::BLOCK_PERMISSION);
         $this->EventArguments['BlockExceptions'] =& $BlockExceptions;
         $this->FireEvent('BeforeBlockDetect');
         $PathRequest = Gdn::Request()->Path();
         foreach ($BlockExceptions as $BlockException => $BlockLevel) {
             if (preg_match($BlockException, $PathRequest)) {
                 throw new Exception("Block detected - {$BlockException}", $BlockLevel);
             }
         }
         // Never block an admin
         if (Gdn::Session()->CheckPermission('Garden.Settings.Manage')) {
             throw new Exception("Block detected", self::BLOCK_NEVER);
         }
         if (Gdn::Session()->IsValid()) {
             throw new Exception("Block detected", self::BLOCK_PERMISSION);
         }
     } catch (Exception $e) {
         // BlockLevel
         //  TRUE = Block any time
         //  FALSE = Absolutely no blocking
         //  NULL = Block for permissions (e.g. PrivateCommunity)
         $CanBlock = $e->getCode();
     }
     // If we're in updatemode and arent explicitly prevented from blocking, block
     if (Gdn::Config('Garden.UpdateMode', FALSE) && $CanBlock > self::BLOCK_NEVER) {
         $Request->WithURI(Gdn::Router()->GetDestination('UpdateMode'));
     }
     // Analze the request AFTER checking for update mode.
     $this->AnalyzeRequest($Request);
     $this->FireEvent('AfterAnalyzeRequest');
     // If we're in updatemode and can block, redirect to signin
     if (C('Garden.PrivateCommunity') && $CanBlock > self::BLOCK_PERMISSION) {
         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();
         Gdn::Controller($Controller);
         $this->EventArguments['Controller'] =& $Controller;
         $this->FireEvent('AfterControllerCreate');
         // 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;
         }
         // Pass along any data.
         if (is_array($this->_Data)) {
             $Controller->Data = $this->_Data;
         }
         // Set up a default controller method in case one isn't defined.
         $ControllerMethod = str_replace('_', '', $this->ControllerMethod);
         $Controller->OriginalRequestMethod = $ControllerMethod;
         // Take enabled plugins into account, as well
         $PluginReplacement = Gdn::PluginManager()->HasNewMethod($this->ControllerName(), $this->ControllerMethod);
         if (!$PluginReplacement && ($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';
                 $PluginReplacement = 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));
         // Set special controller method options for REST APIs.
         $Controller->Initialize();
         $this->EventArguments['Controller'] =& $Controller;
         $this->FireEvent('AfterControllerInit');
         // Call the requested method on the controller - error out if not defined.
         if ($PluginReplacement) {
             // Set the application folder to the plugin's key.
             //            $PluginInfo = Gdn::PluginManager()->GetPluginInfo($PluginReplacement, Gdn_PluginManager::ACCESS_CLASSNAME);
             //            if ($PluginInfo) {
             //               $Controller->ApplicationFolder = 'plugins/'.GetValue('Index', $PluginInfo);
             //            }
             // Reflect the args for the method.
             $Callback = Gdn::PluginManager()->GetCallback($Controller->ControllerName, $ControllerMethod);
             // Augment the arguments to the plugin with the sender and these arguments.
             $InputArgs = array_merge(array($Controller), $this->_ControllerMethodArgs, array('Sender' => $Controller, 'Args' => $this->_ControllerMethodArgs));
             //            decho(array_keys($InputArgs), 'InputArgs');
             $Args = ReflectArgs($Callback, $InputArgs, $Request->Get());
             $Controller->ReflectArgs = $Args;
             try {
                 $this->FireEvent('BeforeControllerMethod');
                 Gdn::PluginManager()->CallEventHandlers($Controller, $Controller->ControllerName, $ControllerMethod, 'Before');
                 call_user_func_array($Callback, $Args);
             } catch (Exception $Ex) {
                 $Controller->RenderException($Ex);
             }
         } elseif (method_exists($Controller, $ControllerMethod)) {
             $Args = ReflectArgs(array($Controller, $ControllerMethod), $this->_ControllerMethodArgs, $Request->Get());
             $this->_ControllerMethodArgs = $Args;
             $Controller->ReflectArgs = $Args;
             try {
                 $this->FireEvent('BeforeControllerMethod');
                 Gdn::PluginManager()->CallEventHandlers($Controller, $Controller->ControllerName, $ControllerMethod, 'Before');
                 call_user_func_array(array($Controller, $ControllerMethod), $Args);
             } catch (Exception $Ex) {
                 $Controller->RenderException($Ex);
                 exit;
             }
         } else {
             $this->EventArguments['Handled'] = FALSE;
             $Handled =& $this->EventArguments['Handled'];
             $this->FireEvent('NotFound');
             if (!$Handled) {
                 Gdn::Request()->WithRoute('Default404');
                 return $this->Dispatch();
             } else {
                 return $Handled;
             }
         }
     }
 }
Example #29
0
 /**
  * This is the asynchronous callback
  * 
  * This method is triggerd on every page request via a callback AJAX request
  * so that it may execute asychronously and reduce lag for users. It tracks
  * views, handles registration for new installations, and sends stats every 
  * day as needed.
  * 
  * @return void;
  */
 public function Tick()
 {
     // If we're local and not allowed, or just directly disabled, gtfo
     if (!self::CheckIsEnabled()) {
         return;
     }
     if (Gdn::Session()->CheckPermission('Garden.Settings.Manage')) {
         if (Gdn::Get('Garden.Analytics.Notify', FALSE) !== FALSE) {
             $CallMessage = '<span class="InformSprite Bandaid"></span> ';
             $CallMessage .= sprintf(T("There's a problem with Vanilla Analytics that needs your attention.<br/> Handle it <a href=\"%s\">here &raquo;</a>"), Url('dashboard/statistics'));
             Gdn::Controller()->InformMessage($CallMessage, array('CssClass' => 'HasSprite'));
         }
     }
     // If the config file is not writable, gtfo
     $ConfFile = PATH_LOCAL_CONF . DS . 'config.php';
     if (!is_writable($ConfFile)) {
         return;
     }
     $InstallationID = Gdn::InstallationID();
     // Check if we're registered with the central server already. If not, this request is
     // hijacked and used to perform that task instead of sending stats or recording a tick.
     if (is_null($InstallationID)) {
         $AttemptedRegistration = Gdn::Get('Garden.Analytics.Registering', FALSE);
         // If we last attempted to register less than 60 seconds ago, do nothing. Could still be working.
         if ($AttemptedRegistration !== FALSE && time() - $AttemptedRegistration < 60) {
             return;
         }
         return $this->Register();
     }
     // Add a pageview entry.
     $TimeSlot = date('Ymd');
     $Px = Gdn::Database()->DatabasePrefix;
     try {
         Gdn::Database()->Query("insert into {$Px}AnalyticsLocal (TimeSlot, Views) values (:TimeSlot, 1)\n         on duplicate key update Views = Views+1", array(':TimeSlot' => $TimeSlot));
     } catch (Exception $e) {
         // If we just tried to run the structure, and failed, don't blindly try again.
         // Just disable ourselves quietly.
         if (Gdn::Get('Garden.Analytics.AutoStructure', FALSE)) {
             SaveToConfig('Garden.Analytics.Enabled', FALSE);
             Gdn::Set('Garden.Analytics.AutoStructure', NULL);
             return;
         }
         // If we get here, insert failed. Try proxyconnect to the utility structure
         Gdn::Set('Garden.Analytics.AutoStructure', TRUE);
         ProxyRequest(Url('utility/update', TRUE), 0, FALSE);
     }
     // If we get here and this is true, we successfully ran the auto structure. Remove config flag.
     if (Gdn::Get('Garden.Analytics.AutoStructure', FALSE)) {
         Gdn::Set('Garden.Analytics.AutoStructure', NULL);
     }
     // Fire an event for plugins to track their own stats.
     // TODO: Make this analyze the path and throw a specific event (this event will change in future versions).
     $this->EventArguments['Path'] = Gdn::Request()->Post('Path');
     $this->FireEvent('Tick');
     // If we get here, the installation is registered and we can decide on whether or not to send stats now.
     $LastSentDate = self::LastSentDate();
     if (empty($LastSentDate) || $LastSentDate < date('Ymd', strtotime('-1 day'))) {
         return $this->Stats();
     }
 }
Example #30
0
 /**
  * Get the path of a view.
  *
  * @param string $View The name of the view.
  * @param string $Controller The name of the controller invoking the view or blank.
  * @param string $Folder The application folder or plugins/plugin folder.
  * @return string|false The path to the view or false if it wasn't found.
  * @deprecated
  */
 function viewLocation($View, $Controller, $Folder)
 {
     deprecated('viewLocation()');
     $Paths = array();
     if (strpos($View, '/') !== false) {
         // This is a path to the view from the root.
         $Paths[] = $View;
     } else {
         $View = strtolower($View);
         $Controller = strtolower(StringEndsWith($Controller, 'Controller', true, true));
         if ($Controller) {
             $Controller = '/' . $Controller;
         }
         $Extensions = array('tpl', 'php');
         // 1. First we check the theme.
         if (Gdn::Controller() && ($Theme = Gdn::Controller()->Theme)) {
             foreach ($Extensions as $Ext) {
                 $Paths[] = PATH_THEMES . "/{$Theme}/views{$Controller}/{$View}.{$Ext}";
             }
         }
         // 2. Then we check the application/plugin.
         if (StringBeginsWith($Folder, 'plugins/')) {
             // This is a plugin view.
             foreach ($Extensions as $Ext) {
                 $Paths[] = PATH_ROOT . "/{$Folder}/views{$Controller}/{$View}.{$Ext}";
             }
         } else {
             // This is an application view.
             $Folder = strtolower($Folder);
             foreach ($Extensions as $Ext) {
                 $Paths[] = PATH_APPLICATIONS . "/{$Folder}/views{$Controller}/{$View}.{$Ext}";
             }
             if ($Folder != 'dashboard' && StringEndsWith($View, '.master')) {
                 // This is a master view that can always fall back to the dashboard.
                 foreach ($Extensions as $Ext) {
                     $Paths[] = PATH_APPLICATIONS . "/dashboard/views{$Controller}/{$View}.{$Ext}";
                 }
             }
         }
     }
     // Now let's search the paths for the view.
     foreach ($Paths as $Path) {
         if (file_exists($Path)) {
             return $Path;
         }
     }
     Trace(array('view' => $View, 'controller' => $Controller, 'folder' => $Folder), 'View');
     Trace($Paths, 'ViewLocation()');
     return false;
 }