Ejemplo n.º 1
0
 /**
  * Post every new registration to HipChat.
  *
  * @param UserModel $sender
  * @param array $args
  */
 public function userModel_afterInsertUser_handler($sender, $args)
 {
     // Determine how to link their name.
     $name = val('Name', $args['InsertFields']);
     if (c('Garden.Registration.Method') == 'Approval') {
         $user = anchor($name, '/user/applicants', '', array('WithDomain' => true));
         $reason = sliceParagraph(val('DiscoveryText', $args['InsertFields']));
         $message = sprintf(t('New member: %1$s (%2$s)'), $user, $reason);
     } else {
         // Use conservative name linking structure.
         $user = anchor($name, '/profile/' . $args['InsertUserID'] . '/' . $name, '', array('WithDomain' => true));
         $message = sprintf(t('New member: %1$s'), $user);
     }
     // Say it.
     HipChat::say($message);
 }
Ejemplo n.º 2
0
 /**
  *
  * @param PostController $Sender
  * @param type $RecordType
  * @param type $ID
  * @throws type
  */
 public function postController_facebook_create($Sender, $RecordType, $ID)
 {
     if (!$this->socialReactions()) {
         throw permissionException();
     }
     $Row = getRecord($RecordType, $ID, true);
     if ($Row) {
         $Message = sliceParagraph(Gdn_Format::plainText($Row['Body'], $Row['Format']), 160);
         if ($this->accessToken() && $Sender->Request->isPostBack()) {
             $R = $this->api('/me/feed', array('link' => $Row['ShareUrl'], 'message' => $Message));
             $Sender->setJson('R', $R);
             $Sender->informMessage(t('Thanks for sharing!'));
         } else {
             $Get = array('app_id' => c('Plugins.Facebook.ApplicationID'), 'link' => $Row['ShareUrl'], 'name' => Gdn_Format::plainText($Row['Name'], 'Text'), 'description' => $Message, 'redirect_uri' => url('/post/shared/facebook', true));
             $Url = 'http://www.facebook.com/dialog/feed?' . http_build_query($Get);
             redirect($Url);
         }
     }
     $Sender->render('Blank', 'Utility', 'Dashboard');
 }
Ejemplo n.º 3
0
/**
 *
 *
 * @param $Str
 * @return mixed|string
 */
function sliceTwitter($Str)
{
    $Elips = '...';
    $Str = preg_replace('`\\s+`', ' ', $Str);
    //         if (function_exists('normalizer_is_normalized')) {
    //            // Slice the string to 119 characters (21 reservered for the url.
    //            if (!normalizer_is_normalized($Message))
    //               $Message = Normalizer::normalize($Message, Normalizer::FORM_D);
    //            $Elips = Normalizer::normalize($Elips, Normalizer::FORM_D);
    //         }
    $Max = 140;
    $LinkLen = 22;
    $Max -= $LinkLen;
    $Str = sliceParagraph($Str, $Max);
    if (strlen($Str) > $Max) {
        $Str = substr($Str, 0, $Max - strlen($Elips)) . $Elips;
    }
    return $Str;
}
 /**
  * Default single discussion display.
  *
  * @since 2.0.0
  * @access public
  *
  * @param int $DiscussionID Unique discussion ID
  * @param string $DiscussionStub URL-safe title slug
  * @param int $Page The current page of comments
  */
 public function index($DiscussionID = '', $DiscussionStub = '', $Page = '')
 {
     // Setup head
     $Session = Gdn::session();
     $this->addJsFile('jquery.autosize.min.js');
     $this->addJsFile('autosave.js');
     $this->addJsFile('discussion.js');
     Gdn_Theme::section('Discussion');
     // Load the discussion record
     $DiscussionID = is_numeric($DiscussionID) && $DiscussionID > 0 ? $DiscussionID : 0;
     if (!array_key_exists('Discussion', $this->Data)) {
         $this->setData('Discussion', $this->DiscussionModel->getID($DiscussionID), true);
     }
     if (!is_object($this->Discussion)) {
         $this->EventArguments['DiscussionID'] = $DiscussionID;
         $this->fireEvent('DiscussionNotFound');
         throw notFoundException('Discussion');
     }
     // Define the query offset & limit.
     $Limit = c('Vanilla.Comments.PerPage', 30);
     $OffsetProvided = $Page != '';
     list($Offset, $Limit) = offsetLimit($Page, $Limit);
     // Check permissions
     $this->permission('Vanilla.Discussions.View', true, 'Category', $this->Discussion->PermissionCategoryID);
     $this->setData('CategoryID', $this->CategoryID = $this->Discussion->CategoryID, true);
     if (strcasecmp(val('Type', $this->Discussion), 'redirect') === 0) {
         $this->redirectDiscussion($this->Discussion);
     }
     $Category = CategoryModel::categories($this->Discussion->CategoryID);
     $this->setData('Category', $Category);
     if ($CategoryCssClass = val('CssClass', $Category)) {
         Gdn_Theme::section($CategoryCssClass);
     }
     $this->setData('Breadcrumbs', CategoryModel::getAncestors($this->CategoryID));
     // Setup
     $this->title($this->Discussion->Name);
     // Actual number of comments, excluding the discussion itself.
     $ActualResponses = $this->Discussion->CountComments;
     $this->Offset = $Offset;
     if (c('Vanilla.Comments.AutoOffset')) {
         //         if ($this->Discussion->CountCommentWatch > 1 && $OffsetProvided == '')
         //            $this->addDefinition('ScrollTo', 'a[name=Item_'.$this->Discussion->CountCommentWatch.']');
         if (!is_numeric($this->Offset) || $this->Offset < 0 || !$OffsetProvided) {
             // Round down to the appropriate offset based on the user's read comments & comments per page
             $CountCommentWatch = $this->Discussion->CountCommentWatch > 0 ? $this->Discussion->CountCommentWatch : 0;
             if ($CountCommentWatch > $ActualResponses) {
                 $CountCommentWatch = $ActualResponses;
             }
             // (((67 comments / 10 perpage) = 6.7) rounded down = 6) * 10 perpage = offset 60;
             $this->Offset = floor($CountCommentWatch / $Limit) * $Limit;
         }
         if ($ActualResponses <= $Limit) {
             $this->Offset = 0;
         }
         if ($this->Offset == $ActualResponses) {
             $this->Offset -= $Limit;
         }
     } else {
         if ($this->Offset == '') {
             $this->Offset = 0;
         }
     }
     if ($this->Offset < 0) {
         $this->Offset = 0;
     }
     $LatestItem = $this->Discussion->CountCommentWatch;
     if ($LatestItem === null) {
         $LatestItem = 0;
     } elseif ($LatestItem < $this->Discussion->CountComments) {
         $LatestItem += 1;
     }
     $this->setData('_LatestItem', $LatestItem);
     // Set the canonical url to have the proper page title.
     $this->canonicalUrl(discussionUrl($this->Discussion, pageNumber($this->Offset, $Limit, 0, false)));
     //      url(ConcatSep('/', 'discussion/'.$this->Discussion->DiscussionID.'/'. Gdn_Format::url($this->Discussion->Name), PageNumber($this->Offset, $Limit, TRUE, Gdn::session()->UserID != 0)), true), Gdn::session()->UserID == 0);
     // Load the comments
     $this->setData('Comments', $this->CommentModel->get($DiscussionID, $Limit, $this->Offset));
     $PageNumber = PageNumber($this->Offset, $Limit);
     $this->setData('Page', $PageNumber);
     $this->_SetOpenGraph();
     include_once PATH_LIBRARY . '/vendors/simplehtmldom/simple_html_dom.php';
     if ($PageNumber == 1) {
         $this->description(sliceParagraph(Gdn_Format::plainText($this->Discussion->Body, $this->Discussion->Format), 160));
         // Add images to head for open graph
         $Dom = str_get_html(Gdn_Format::to($this->Discussion->Body, $this->Discussion->Format));
     } else {
         $this->Data['Title'] .= sprintf(t(' - Page %s'), PageNumber($this->Offset, $Limit));
         $FirstComment = $this->data('Comments')->firstRow();
         $FirstBody = val('Body', $FirstComment);
         $FirstFormat = val('Format', $FirstComment);
         $this->description(sliceParagraph(Gdn_Format::plainText($FirstBody, $FirstFormat), 160));
         // Add images to head for open graph
         $Dom = str_get_html(Gdn_Format::to($FirstBody, $FirstFormat));
     }
     if ($Dom) {
         foreach ($Dom->find('img') as $img) {
             if (isset($img->src)) {
                 $this->image($img->src);
             }
         }
     }
     // Queue notification.
     if ($this->Request->get('new') && c('Vanilla.QueueNotifications')) {
         $this->addDefinition('NotifyNewDiscussion', 1);
     }
     // Make sure to set the user's discussion watch records if this is not an API request.
     if ($this->deliveryType() !== DELIVERY_TYPE_DATA) {
         $this->CommentModel->SetWatch($this->Discussion, $Limit, $this->Offset, $this->Discussion->CountComments);
     }
     // Build a pager
     $PagerFactory = new Gdn_PagerFactory();
     $this->EventArguments['PagerType'] = 'Pager';
     $this->fireEvent('BeforeBuildPager');
     $this->Pager = $PagerFactory->getPager($this->EventArguments['PagerType'], $this);
     $this->Pager->ClientID = 'Pager';
     $this->Pager->configure($this->Offset, $Limit, $ActualResponses, array('DiscussionUrl'));
     $this->Pager->Record = $this->Discussion;
     PagerModule::current($this->Pager);
     $this->fireEvent('AfterBuildPager');
     // Define the form for the comment input
     $this->Form = Gdn::Factory('Form', 'Comment');
     $this->Form->Action = url('/post/comment/');
     $this->DiscussionID = $this->Discussion->DiscussionID;
     $this->Form->addHidden('DiscussionID', $this->DiscussionID);
     $this->Form->addHidden('CommentID', '');
     // Look in the session stash for a comment
     $StashComment = $Session->getPublicStash('CommentForDiscussionID_' . $this->Discussion->DiscussionID);
     if ($StashComment) {
         $this->Form->setValue('Body', $StashComment);
         $this->Form->setFormValue('Body', $StashComment);
     }
     // Retrieve & apply the draft if there is one:
     if (Gdn::session()->UserID) {
         $DraftModel = new DraftModel();
         $Draft = $DraftModel->get($Session->UserID, 0, 1, $this->Discussion->DiscussionID)->firstRow();
         $this->Form->addHidden('DraftID', $Draft ? $Draft->DraftID : '');
         if ($Draft && !$this->Form->isPostBack()) {
             $this->Form->setValue('Body', $Draft->Body);
             $this->Form->setValue('Format', $Draft->Format);
         }
     }
     // Deliver JSON data if necessary
     if ($this->_DeliveryType != DELIVERY_TYPE_ALL) {
         $this->setJson('LessRow', $this->Pager->toString('less'));
         $this->setJson('MoreRow', $this->Pager->toString('more'));
         $this->View = 'comments';
     }
     // Inform moderator of checked comments in this discussion
     $CheckedComments = $Session->getAttribute('CheckedComments', array());
     if (count($CheckedComments) > 0) {
         ModerationController::informCheckedComments($this);
     }
     // Add modules
     $this->addModule('DiscussionFilterModule');
     $this->addModule('NewDiscussionModule');
     $this->addModule('CategoriesModule');
     $this->addModule('BookmarkedModule');
     $this->CanEditComments = Gdn::session()->checkPermission('Vanilla.Comments.Edit', true, 'Category', 'any') && c('Vanilla.AdminCheckboxes.Use');
     // Report the discussion id so js can use it.
     $this->addDefinition('DiscussionID', $DiscussionID);
     $this->addDefinition('Category', $this->data('Category.Name'));
     $this->fireEvent('BeforeDiscussionRender');
     $AttachmentModel = AttachmentModel::instance();
     if (AttachmentModel::enabled()) {
         $AttachmentModel->joinAttachments($this->Data['Discussion'], $this->Data['Comments']);
         $this->fireEvent('FetchAttachmentViews');
         if ($this->deliveryMethod() === DELIVERY_METHOD_XHTML) {
             require_once $this->fetchViewLocation('attachment', 'attachments', 'dashboard');
         }
     }
     $this->render();
 }