Beispiel #1
0
    function writeModuleDiscussion($Discussion, $Px = 'Bookmark')
    {
        ?>
        <li id="<?php 
        echo "{$Px}_{$Discussion->DiscussionID}";
        ?>
" class="<?php 
        echo CssClass($Discussion);
        ?>
">
   <span class="Options">
      <?php 
        //      echo OptionsList($Discussion);
        echo BookmarkButton($Discussion);
        ?>
   </span>

            <div class="Title"><?php 
        echo anchor(Gdn_Format::text($Discussion->Name, false), DiscussionUrl($Discussion) . ($Discussion->CountCommentWatch > 0 ? '#Item_' . $Discussion->CountCommentWatch : ''), 'DiscussionLink');
        ?>
</div>
            <div class="Meta">
                <?php 
        $Last = new stdClass();
        $Last->UserID = $Discussion->LastUserID;
        $Last->Name = $Discussion->LastName;
        echo NewComments($Discussion);
        echo '<span class="MItem">' . Gdn_Format::date($Discussion->LastDate, 'html') . UserAnchor($Last) . '</span>';
        ?>
            </div>
        </li>
    <?php 
    }
Beispiel #2
0
    function writeModuleDiscussion($Discussion, $Px = 'Bookmark', $showPhotos = false)
    {
        ?>
        <li id="<?php 
        echo "{$Px}_{$Discussion->DiscussionID}";
        ?>
" class="<?php 
        echo CssClass($Discussion);
        ?>
">
            <?php 
        if ($showPhotos) {
            $firstUser = userBuilder($Discussion, 'First');
            echo userPhoto($firstUser, ['LinkClass' => 'IndexPhoto']);
        }
        ?>
   <span class="Options">
      <?php 
        //      echo OptionsList($Discussion);
        echo BookmarkButton($Discussion);
        ?>
   </span>

            <div class="Title"><?php 
        echo anchor(Gdn_Format::text($Discussion->Name, false), DiscussionUrl($Discussion) . ($Discussion->CountCommentWatch > 0 ? '#Item_' . $Discussion->CountCommentWatch : ''), 'DiscussionLink');
        ?>
</div>
            <div class="Meta DiscussionsModuleMeta">
                <?php 
        $Last = new stdClass();
        $Last->UserID = $Discussion->LastUserID;
        $Last->Name = $Discussion->LastName;
        echo NewComments($Discussion);
        $translation = pluralTranslate($Discussion->CountComments, '%s comment html', '%s comments html', t('%s comment'), t('%s comments'));
        echo '<span class="MItem">' . Gdn_Format::date($Discussion->LastDate, 'html') . UserAnchor($Last) . '</span>';
        echo '<span class="MItem CountComments Hidden">' . sprintf($translation, $Discussion->CountComments) . '</span>';
        ?>
            </div>
        </li>
    <?php 
    }
Beispiel #3
0
    /**
     * Writes a discussion in table row format.
     */
    function writeDiscussionRow($Discussion, $Sender, $Session)
    {
        if (!property_exists($Sender, 'CanEditDiscussions')) {
            $Sender->CanEditDiscussions = val('PermsDiscussionsEdit', CategoryModel::categories($Discussion->CategoryID)) && c('Vanilla.AdminCheckboxes.Use');
        }
        $CssClass = CssClass($Discussion);
        $DiscussionUrl = $Discussion->Url;
        if ($Session->UserID) {
            $DiscussionUrl .= '#latest';
        }
        $Sender->EventArguments['DiscussionUrl'] =& $DiscussionUrl;
        $Sender->EventArguments['Discussion'] =& $Discussion;
        $Sender->EventArguments['CssClass'] =& $CssClass;
        $First = UserBuilder($Discussion, 'First');
        if ($Discussion->LastUserID) {
            $Last = UserBuilder($Discussion, 'Last');
        } else {
            $Last = $First;
        }
        $Sender->EventArguments['FirstUser'] =& $First;
        $Sender->EventArguments['LastUser'] =& $Last;
        $Sender->fireEvent('BeforeDiscussionName');
        $DiscussionName = $Discussion->Name;
        // If there are no word character detected in the title treat it as if it is blank.
        if (!preg_match('/\\w/u', $DiscussionName)) {
            $DiscussionName = t('Blank Discussion Topic');
        }
        $Sender->EventArguments['DiscussionName'] =& $DiscussionName;
        static $FirstDiscussion = true;
        if (!$FirstDiscussion) {
            $Sender->fireEvent('BetweenDiscussion');
        } else {
            $FirstDiscussion = false;
        }
        $Discussion->CountPages = ceil($Discussion->CountComments / $Sender->CountCommentsPerPage);
        $FirstPageUrl = DiscussionUrl($Discussion, 1);
        $LastPageUrl = DiscussionUrl($Discussion, val('CountPages', $Discussion)) . '#latest';
        ?>
        <tr id="Discussion_<?php 
        echo $Discussion->DiscussionID;
        ?>
" class="<?php 
        echo $CssClass;
        ?>
">
            <?php 
        $Sender->fireEvent('BeforeDiscussionContent');
        ?>
            <?php 
        echo AdminCheck($Discussion, array('<td class="CheckBoxColumn"><div class="Wrap">', '</div></td>'));
        ?>
            <td class="DiscussionName">
                <div class="Wrap">
         <span class="Options">
            <?php 
        echo OptionsList($Discussion);
        echo BookmarkButton($Discussion);
        ?>
         </span>
                    <?php 
        $Sender->fireEvent('BeforeDiscussionTitle');
        echo anchor($DiscussionName, $DiscussionUrl, 'Title') . ' ';
        $Sender->fireEvent('AfterDiscussionTitle');
        WriteMiniPager($Discussion);
        echo NewComments($Discussion);
        if ($Sender->data('_ShowCategoryLink', true)) {
            echo CategoryLink($Discussion, ' ' . t('in') . ' ');
        }
        // Other stuff that was in the standard view that you may want to display:
        echo '<div class="Meta Meta-Discussion">';
        WriteTags($Discussion);
        echo '</div>';
        //			if ($Source = val('Source', $Discussion))
        //				echo ' '.sprintf(t('via %s'), t($Source.' Source', $Source));
        //
        ?>
                </div>
            </td>
            <td class="BlockColumn BlockColumn-User FirstUser">
                <div class="Block Wrap">
                    <?php 
        echo userPhoto($First, array('Size' => 'Small'));
        echo userAnchor($First, 'UserLink BlockTitle');
        echo '<div class="Meta">';
        echo anchor(Gdn_Format::date($Discussion->FirstDate, 'html'), $FirstPageUrl, 'CommentDate MItem');
        echo '</div>';
        ?>
                </div>
            </td>
            <td class="BigCount CountComments">
                <div class="Wrap">
                    <?php 
        // Exact Number
        // echo number_format($Discussion->CountComments);
        // Round Number
        echo BigPlural($Discussion->CountComments, '%s comment');
        ?>
                </div>
            </td>
            <td class="BigCount CountViews">
                <div class="Wrap">
                    <?php 
        // Exact Number
        // echo number_format($Discussion->CountViews);
        // Round Number
        echo BigPlural($Discussion->CountViews, '%s view');
        ?>
                </div>
            </td>
            <td class="BlockColumn BlockColumn-User LastUser">
                <div class="Block Wrap">
                    <?php 
        if ($Last) {
            echo userPhoto($Last, array('Size' => 'Small'));
            echo userAnchor($Last, 'UserLink BlockTitle');
            echo '<div class="Meta">';
            echo anchor(Gdn_Format::date($Discussion->LastDate, 'html'), $LastPageUrl, 'CommentDate MItem');
            echo '</div>';
        } else {
            echo '&nbsp;';
        }
        ?>
                </div>
            </td>
        </tr>
    <?php 
    }
    /**
     * Writes a discussion in table row format.
     */
    function WriteDiscussionRow($Discussion, &$Sender, &$Session, $Alt2)
    {
        if (!property_exists($Sender, 'CanEditDiscussions')) {
            $Sender->CanEditDiscussions = GetValue('PermsDiscussionsEdit', CategoryModel::Categories($Discussion->CategoryID)) && C('Vanilla.AdminCheckboxes.Use');
        }
        $CssClass = CssClass($Discussion);
        $DiscussionUrl = $Discussion->Url;
        if ($Session->UserID) {
            $DiscussionUrl .= '#latest';
        }
        $Sender->EventArguments['DiscussionUrl'] =& $DiscussionUrl;
        $Sender->EventArguments['Discussion'] =& $Discussion;
        $Sender->EventArguments['CssClass'] =& $CssClass;
        $First = UserBuilder($Discussion, 'First');
        if ($Discussion->LastUserID) {
            $Last = UserBuilder($Discussion, 'Last');
        } else {
            $Last = $First;
        }
        //   $Sender->EventArguments['FirstUser'] = &$First;
        //   $Sender->EventArguments['LastUser'] = &$Last;
        //
        //   $Sender->FireEvent('BeforeDiscussionName');
        $DiscussionName = $Discussion->Name;
        if ($DiscussionName == '') {
            $DiscussionName = T('Blank Discussion Topic');
        }
        $Sender->EventArguments['DiscussionName'] =& $DiscussionName;
        $Discussion->CountPages = ceil($Discussion->CountComments / $Sender->CountCommentsPerPage);
        $FirstPageUrl = DiscussionUrl($Discussion, 1);
        $LastPageUrl = DiscussionUrl($Discussion, FALSE) . '#latest';
        ?>
<tr id="Discussion_<?php 
        echo $Discussion->DiscussionID;
        ?>
" class="<?php 
        echo $CssClass;
        ?>
">
   <?php 
        echo AdminCheck($Discussion, array('<td class="CheckBoxColumn"><div class="Wrap">', '</div></td>'));
        ?>
	<td class="DiscussionName">
		<div class="Wrap">
         <span class="Options">
            <?php 
        echo OptionsList($Discussion);
        echo BookmarkButton($Discussion);
        ?>
         </span>
			<?php 
        echo Anchor($DiscussionName, $DiscussionUrl, 'Title') . ' ';
        $Sender->FireEvent('AfterDiscussionTitle');
        WriteMiniPager($Discussion);
        echo NewComments($Discussion);
        if ($Sender->Data('_ShowCategoryLink', TRUE)) {
            echo CategoryLink($Discussion, ' ' . T('in') . ' ');
        }
        // Other stuff that was in the standard view that you may want to display:
        echo '<div class="Meta Meta-Discussion">';
        WriteTags($Discussion);
        echo '</div>';
        //			if ($Source = GetValue('Source', $Discussion))
        //				echo ' '.sprintf(T('via %s'), T($Source.' Source', $Source));
        //
        ?>
		</div>
	</td>
	<td class="BlockColumn BlockColumn-User FirstUser">
		<div class="Block Wrap">
			<?php 
        echo UserPhoto($First, array('Size' => 'Small'));
        echo UserAnchor($First, 'UserLink BlockTitle');
        echo '<div class="Meta">';
        echo Anchor(Gdn_Format::Date($Discussion->FirstDate, 'html'), $FirstPageUrl, 'CommentDate MItem');
        echo '</div>';
        ?>
		</div>
   </td>
	<td class="BigCount CountComments">
      <div class="Wrap">
         <?php 
        // Exact Number
        // echo number_format($Discussion->CountComments);
        // Round Number
        echo BigPlural($Discussion->CountComments, '%s comment');
        ?>
      </div>
	</td>
	<td class="BigCount CountViews">
      <div class="Wrap">
         <?php 
        // Exact Number
        // echo number_format($Discussion->CountViews);
        // Round Number
        echo BigPlural($Discussion->CountViews, '%s view');
        ?>
      </div>
	</td>
	<td class="BlockColumn BlockColumn-User LastUser">
		<div class="Block Wrap">
			<?php 
        if ($Last) {
            echo UserPhoto($Last, array('Size' => 'Small'));
            echo UserAnchor($Last, 'UserLink BlockTitle');
            echo '<div class="Meta">';
            echo Anchor(Gdn_Format::Date($Discussion->LastDate, 'html'), $LastPageUrl, 'CommentDate MItem');
            echo '</div>';
        } else {
            echo '&nbsp;';
        }
        ?>
		</div>
	</td>
</tr>
<?php 
    }
 /**
  * Render options that the user has for this discussion.
  */
 function writeOptions($Discussion)
 {
     if (!Gdn::session()->isValid() || !Gdn::controller()->ShowOptions) {
         return;
     }
     echo '<span class="Options">';
     // Options list.
     echo OptionsList($Discussion);
     // Bookmark button.
     echo BookmarkButton($Discussion);
     // Admin check.
     echo AdminCheck($Discussion);
     echo '</span>';
 }
 /**
  * Allows user to bookmark or unbookmark a discussion.
  *
  * If the discussion isn't bookmarked by the user, this bookmarks it.
  * If it is already bookmarked, this unbookmarks it.
  *
  * @since 2.0.0
  * @access public
  *
  * @param int $DiscussionID Unique discussion ID.
  */
 public function Bookmark($DiscussionID)
 {
     // Make sure we are posting back.
     if (!$this->Request->IsAuthenticatedPostBack()) {
         throw PermissionException('Javascript');
     }
     $Session = Gdn::Session();
     if ($Session->UserID == 0) {
         throw PermissionException('SignedIn');
     }
     $Discussion = $this->DiscussionModel->GetID($DiscussionID);
     if (!$Discussion) {
         throw NotFoundException('Discussion');
     }
     $State = $this->DiscussionModel->BookmarkDiscussion($DiscussionID, $Session->UserID, $Discussion);
     // Update the user's bookmark count
     $CountBookmarks = $this->DiscussionModel->SetUserBookmarkCount($Session->UserID);
     $this->JsonTarget('.User-CountBookmarks', (string) $CountBookmarks);
     // Return the appropriate bookmark.
     require_once $this->FetchViewLocation('helper_functions', 'Discussions');
     $Html = BookmarkButton($Discussion);
     //      $this->JsonTarget(".Section-DiscussionList #Discussion_$DiscussionID .Bookmark,.Section-Discussion .PageTitle .Bookmark", $Html, 'ReplaceWith');
     $this->JsonTarget("!element", $Html, 'ReplaceWith');
     // Add the bookmark to the bookmarks module.
     if ($State) {
         // Grab the individual bookmark and send it to the client.
         $Bookmarks = new BookmarkedModule($this);
         if ($CountBookmarks == 1) {
             // When there is only one bookmark we have to get the whole module.
             $Target = '#Panel';
             $Type = 'Append';
             $Bookmarks->GetData();
             $Data = $Bookmarks->ToString();
         } else {
             $Target = '#Bookmark_List';
             $Type = 'Prepend';
             $Loc = $Bookmarks->FetchViewLocation('discussion');
             ob_start();
             include $Loc;
             $Data = ob_get_clean();
         }
         $this->JsonTarget($Target, $Data, $Type);
     } else {
         // Send command to remove bookmark html.
         if ($CountBookmarks == 0) {
             $this->JsonTarget('#Bookmarks', NULL, 'Remove');
         } else {
             $this->JsonTarget('#Bookmark_' . $DiscussionID, NULL, 'Remove');
         }
     }
     $this->Render('Blank', 'Utility', 'Dashboard');
 }
 /**
  * Allows user to bookmark or unbookmark a discussion.
  *
  * If the discussion isn't bookmarked by the user, this bookmarks it.
  * If it is already bookmarked, this unbookmarks it.
  *
  * @since 2.0.0
  * @access public
  *
  * @param int $DiscussionID Unique discussion ID.
  */
 public function Bookmark($DiscussionID = NULL)
 {
     // Make sure we are posting back.
     if (!$this->Request->IsPostBack()) {
         throw PermissionException('Javascript');
     }
     $Session = Gdn::Session();
     if (!$Session->UserID) {
         throw PermissionException('SignedIn');
     }
     // Check the form to see if the data was posted.
     $Form = new Gdn_Form();
     $DiscussionID = $Form->GetFormValue('DiscussionID', $DiscussionID);
     $Bookmark = $Form->GetFormValue('Bookmark', NULL);
     $UserID = $Form->GetFormValue('UserID', $Session->UserID);
     // Check the permission on the user.
     if ($UserID != $Session->UserID) {
         $this->Permission('Garden.Moderation.Manage');
     }
     $Discussion = $this->DiscussionModel->GetID($DiscussionID);
     if (!$Discussion) {
         throw NotFoundException('Discussion');
     }
     $Bookmark = $this->DiscussionModel->Bookmark($DiscussionID, $UserID, $Bookmark);
     // Set the new value for api calls and json targets.
     $this->SetData(array('UserID' => $UserID, 'DiscussionID' => $DiscussionID, 'Bookmarked' => (bool) $Bookmark));
     SetValue('Bookmarked', $Discussion, (int) $Bookmark);
     // Update the user's bookmark count
     $CountBookmarks = $this->DiscussionModel->SetUserBookmarkCount($UserID);
     $this->JsonTarget('.User-CountBookmarks', (string) $CountBookmarks);
     //  Short circuit if this is an api call.
     if ($this->DeliveryType() === DELIVERY_TYPE_DATA) {
         $this->Render('Blank', 'Utility', 'Dashboard');
         return;
     }
     // Return the appropriate bookmark.
     require_once $this->FetchViewLocation('helper_functions', 'Discussions');
     $Html = BookmarkButton($Discussion);
     //      $this->JsonTarget(".Section-DiscussionList #Discussion_$DiscussionID .Bookmark,.Section-Discussion .PageTitle .Bookmark", $Html, 'ReplaceWith');
     $this->JsonTarget("!element", $Html, 'ReplaceWith');
     // Add the bookmark to the bookmarks module.
     if ($Bookmark) {
         // Grab the individual bookmark and send it to the client.
         $Bookmarks = new BookmarkedModule($this);
         if ($CountBookmarks == 1) {
             // When there is only one bookmark we have to get the whole module.
             $Target = '#Panel';
             $Type = 'Append';
             $Bookmarks->GetData();
             $Data = $Bookmarks->ToString();
         } else {
             $Target = '#Bookmark_List';
             $Type = 'Prepend';
             $Loc = $Bookmarks->FetchViewLocation('discussion');
             ob_start();
             include $Loc;
             $Data = ob_get_clean();
         }
         $this->JsonTarget($Target, $Data, $Type);
     } else {
         // Send command to remove bookmark html.
         if ($CountBookmarks == 0) {
             $this->JsonTarget('#Bookmarks', NULL, 'Remove');
         } else {
             $this->JsonTarget('#Bookmark_' . $DiscussionID, NULL, 'Remove');
         }
     }
     $this->Render('Blank', 'Utility', 'Dashboard');
 }