Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

how to sort the span elements in meta

jackmaessenjackmaessen ✭✭✭
edited January 2016 in Vanilla 2.0 - 2.8

How can i resort the span elements in the Meta class
The class MItem Category is in my example the last span and i want to bump it up as the first span element in the Meta class

This is the structure i want to achieve:
Discussion title
Discussion Category
Discussion writer with date
Last Comment with date

Comments

  • hgtonighthgtonight ∞ · New Moderator

    You would have to override the writeDiscussion function with your own markup or use JS to reorder the elements.

    Overriding the function is "cleaner" but requires you to check for changes when you update Vanilla.

    Using JS is simpler but will potentially show the reordering to the user.

    I would suggest overriding the function since I hate unnecessary DOM manipulation via JS.

    Search first

    Check out the Documentation! We are always looking for new content and pull requests.

    Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.

  • jackmaessenjackmaessen ✭✭✭
    edited January 2016

    I did modify helper_functions.php in applications/vanilla/views/discussions and it gives me the correct structure. But i feel bad to modify a core file for this, so i was hoping there was another solution to achieve it

    $Sender->fireEvent('AfterCountMeta');
    
                        if ($Sender->data('_ShowCategoryLink', true) && c('Vanilla.Categories.Use') && $Category)
                            echo wrap(Anchor(htmlspecialchars($Discussion->Category), CategoryUrl($Discussion->CategoryUrlCode)), 'span', array('class' => 'MItem Category '.$Category['CssClass']));
                            /* added Discussion author with date */
                            echo '<span class="ShowDiscussionAuthor"> '. T('Author') .': <a href="'.Url('/profile/'.$Discussion->FirstUserID.'/'.urlencode($Discussion->FirstName)).'">'.$Discussion->FirstName.'</a></span>';
                        echo '&nbsp;&nbsp;'.Gdn_Format::Date($Discussion->FirstDate);
    
    
                        if ($Discussion->LastCommentID != '') {
                            /* force a break tag below before span elem*/
                            echo ' <br /><span class="MItem LastCommentBy">'.sprintf(t('Most recent by %1$s'), userAnchor($Last)).'</span> ';
                            echo ' <span class="MItem LastCommentDate">'.Gdn_Format::date($Discussion->LastDate, 'html').'</span>';
                        } else {
                            echo ' <br /><span class="MItem LastCommentBy">'.sprintf(t('Started by %1$s'), userAnchor($First)).'</span> ';
                            echo ' <span class="MItem LastCommentDate">'.Gdn_Format::date($Discussion->FirstDate, 'html');
    
                            if ($Source = val('Source', $Discussion)) {
                                echo ' '.sprintf(t('via %s'), t($Source.' Source', $Source));
                            }
    
                            echo '</span> ';
                        }
    
    
    
                        /* These 2 lines bumped up */
                        /*if ($Sender->data('_ShowCategoryLink', true) && c('Vanilla.Categories.Use') && $Category)
                            echo wrap(Anchor(htmlspecialchars($Discussion->Category), CategoryUrl($Discussion->CategoryUrlCode)), 'span', array('class' => 'MItem Category '.$Category['CssClass']));*/
    
                        $Sender->fireEvent('DiscussionMeta');
    
  • hgtonighthgtonight ∞ · New Moderator
    edited January 2016

    You never, ever, modify core files unless you are comfortable maintaining that forked file.

    Copy the entirety of the writeDiscussion function from /applications/vanilla/views/discussions/helper_functions.php and paste it into /conf/bootstrap.before.php. If the before bootstrap file doesn't exist (it doesn't by default), create it.

    You should have something that looks like this:

    <?php
    
    function writeDiscussion($Discussion, &$Sender, &$Session) {
        $CssClass = CssClass($Discussion);
        $DiscussionUrl = $Discussion->Url;
        $Category = CategoryModel::categories($Discussion->CategoryID);
    
        if ($Session->UserID)
            $DiscussionUrl .= '#latest';
    
        $Sender->EventArguments['DiscussionUrl'] = &$DiscussionUrl;
        $Sender->EventArguments['Discussion'] = &$Discussion;
        $Sender->EventArguments['CssClass'] = &$CssClass;
    
        $First = UserBuilder($Discussion, 'First');
        $Last = UserBuilder($Discussion, 'Last');
        $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;
    
        static $FirstDiscussion = TRUE;
        if (!$FirstDiscussion)
            $Sender->fireEvent('BetweenDiscussion');
        else
            $FirstDiscussion = FALSE;
    
        $Discussion->CountPages = ceil($Discussion->CountComments / $Sender->CountCommentsPerPage);
        ?>
        <li id="Discussion_<?php echo $Discussion->DiscussionID; ?>" class="<?php echo $CssClass; ?>">
            <?php
            if (!property_exists($Sender, 'CanEditDiscussions'))
                $Sender->CanEditDiscussions = val('PermsDiscussionsEdit', CategoryModel::categories($Discussion->CategoryID)) && c('Vanilla.AdminCheckboxes.Use');
    
            $Sender->fireEvent('BeforeDiscussionContent');
    
            //   WriteOptions($Discussion, $Sender, $Session);
            ?>
            <span class="Options">
      <?php
      echo OptionsList($Discussion);
      echo BookmarkButton($Discussion);
      ?>
    </span>
    
            <div class="ItemContent Discussion">
                <div class="Title">
                    <?php
                    echo AdminCheck($Discussion, array('', ' ')).
                        anchor($DiscussionName, $DiscussionUrl);
                    $Sender->fireEvent('AfterDiscussionTitle');
                    ?>
                </div>
                <div class="Meta Meta-Discussion">
                    <?php
                    WriteTags($Discussion);
                    ?>
                    <span class="MItem MCount ViewCount"><?php
                        printf(PluralTranslate($Discussion->CountViews,
                            '%s view html', '%s views html', t('%s view'), t('%s views')),
                            BigPlural($Discussion->CountViews, '%s view'));
                        ?></span>
         <span class="MItem MCount CommentCount"><?php
             printf(PluralTranslate($Discussion->CountComments,
                 '%s comment html', '%s comments html', t('%s comment'), t('%s comments')),
                 BigPlural($Discussion->CountComments, '%s comment'));
             ?></span>
         <span class="MItem MCount DiscussionScore Hidden"><?php
             $Score = $Discussion->Score;
             if ($Score == '') $Score = 0;
             printf(Plural($Score,
                 '%s point', '%s points',
                 BigPlural($Score, '%s point')));
             ?></span>
                    <?php
                    echo NewComments($Discussion);
    
                    $Sender->fireEvent('AfterCountMeta');
    
                    if ($Discussion->LastCommentID != '') {
                        echo ' <span class="MItem LastCommentBy">'.sprintf(t('Most recent by %1$s'), userAnchor($Last)).'</span> ';
                        echo ' <span class="MItem LastCommentDate">'.Gdn_Format::date($Discussion->LastDate, 'html').'</span>';
                    } else {
                        echo ' <span class="MItem LastCommentBy">'.sprintf(t('Started by %1$s'), userAnchor($First)).'</span> ';
                        echo ' <span class="MItem LastCommentDate">'.Gdn_Format::date($Discussion->FirstDate, 'html');
    
                        if ($Source = val('Source', $Discussion)) {
                            echo ' '.sprintf(t('via %s'), t($Source.' Source', $Source));
                        }
    
                        echo '</span> ';
                    }
    
                    if ($Sender->data('_ShowCategoryLink', true) && c('Vanilla.Categories.Use') && $Category)
                        echo wrap(Anchor(htmlspecialchars($Discussion->Category), CategoryUrl($Discussion->CategoryUrlCode)), 'span', array('class' => 'MItem Category '.$Category['CssClass']));
    
                    $Sender->fireEvent('DiscussionMeta');
                    ?>
                </div>
            </div>
            <?php $Sender->fireEvent('AfterDiscussionContent'); ?>
        </li>
    <?php
    }
    

    Now modify that function as you see fit.

    Search first

    Check out the Documentation! We are always looking for new content and pull requests.

    Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.

  • jackmaessenjackmaessen ✭✭✭
    edited January 2016

    I replaced the original helper_functions.php, created bootstrap.before.php and placed it in config folder and works perfect! So this is a great solution without modifying a core file. Thanks very much @hgtonight

Sign In or Register to comment.