A media item usually renders a item with an image, a title, and a description. This modules supports a media item that may have one image, one dropdown menu, any number of buttons, and any number of meta items. There are three views that you can choose to render: media-addon, media-callout, or media-sm. See these variants in the dashboard styleguide.
Since: 2.3
Author: Becky Van Bussel (becky@vanillaforums.com)
Inheritance: extends Gdn_Module
コード例 #1
0
 /**
  * Compiles theme info data into a media module.
  *
  * @param string $themeKey The theme key from the themeinfo array.
  * @param bool $isCurrent Whether the theme is the current theme (if so, adds a little current-theme flag when rendering).
  * @return MediaItemModule A media item representing the theme.
  * @throws Exception
  */
 private function themeInfoToMediaItem($themeKey, $isCurrent = false)
 {
     $themeInfo = Gdn::themeManager()->getThemeInfo($themeKey);
     if (!$themeInfo) {
         throw new Exception(sprintf(t('Theme with key %s not found.'), $themeKey));
     }
     $options = val('Options', $themeInfo, []);
     $iconUrl = val('IconUrl', $themeInfo, val('ScreenshotUrl', $themeInfo, "applications/dashboard/design/images/theme-placeholder.svg"));
     $themeName = val('Name', $themeInfo, val('Index', $themeInfo, $themeKey));
     $themeUrl = val('ThemeUrl', $themeInfo, '');
     $description = val('Description', $themeInfo, '');
     $version = val('Version', $themeInfo, '');
     $newVersion = val('NewVersion', $themeInfo, '');
     $attr = [];
     if ($isCurrent) {
         $attr['class'] = 'media-callout-grey-bg';
     }
     $media = new MediaItemModule($themeName, $themeUrl, $description, 'div', $attr);
     $media->setView('media-callout');
     $media->addOption('has-options', !empty($options));
     $media->addOption('has-upgrade', $newVersion != '' && version_compare($newVersion, $version, '>'));
     $media->addOption('new-version', val('NewVersion', $themeInfo, ''));
     $media->setImage($iconUrl);
     if ($isCurrent) {
         $media->addOption('is-current', $isCurrent);
     }
     // Meta
     // Add author meta
     $author = val('Author', $themeInfo, '');
     $authorUrl = val('AuthorUrl', $themeInfo, '');
     $media->addMetaIf($author != '', '<span class="media-meta author">' . sprintf('Created by %s', $authorUrl != '' ? anchor($author, $authorUrl) : $author) . '</span>');
     // Add version meta
     $version = val('Version', $themeInfo, '');
     $media->addMetaIf($version != '', '<span class="media-meta version">' . sprintf(t('Version %s'), $version) . '</span>');
     // Add requirements meta
     $requirements = val('RequiredApplications', $themeInfo, []);
     $required = [];
     $requiredString = '';
     if (!empty($requirements)) {
         foreach ($requirements as $requirement => $versionInfo) {
             $required[] = printf(t('%1$s Version %2$s'), $requirement, $versionInfo);
         }
     }
     if (!empty($required)) {
         $requiredString .= '<span class="media-meta requirements">' . t('Requires: ') . implode(', ', $required) . '</span>';
     }
     $media->addMetaIf($requiredString != '', $requiredString);
     return $media;
 }
コード例 #2
0
ファイル: users.php プロジェクト: vanilla/vanilla
<?php

if (!defined('APPLICATION')) {
    exit;
}
$Alt = false;
$Session = Gdn::session();
$EditUser = $Session->checkPermission('Garden.Users.Edit');
$DeleteUser = $Session->checkPermission('Garden.Users.Delete');
$ViewPersonalInfo = $Session->checkPermission('Garden.PersonalInfo.View');
foreach ($this->UserData->result() as $User) {
    $Alt = !$Alt;
    $userBlock = new MediaItemModule(val('Name', $User), userUrl($User));
    $userBlock->setView('media-sm')->setImage(userPhotoUrl($User))->addMetaIf($ViewPersonalInfo, Gdn_Format::email($User->Email));
    ?>
    <tr id="<?php 
    echo "UserID_{$User->UserID}";
    ?>
"<?php 
    echo $Alt ? ' class="Alt"' : '';
    ?>
        data-userid="<?php 
    echo $User->UserID;
    ?>
">
        <!--      <td class="CheckboxCell"><input type="checkbox" name="LogID[]" value="<?php 
    echo $User->UserID;
    ?>
" /></td>-->
        <td>
            <?php 
コード例 #3
0
ファイル: helper_functions.php プロジェクト: vanilla/vanilla
/**
 * Converts addon info into a media item.
 *
 * @param $addonName
 * @param $addonInfo
 * @param $isEnabled
 * @param $addonType
 * @param $filter
 */
function writeAddonMedia($addonName, $addonInfo, $isEnabled, $addonType, $filter)
{
    $capitalCaseSheme = new \Vanilla\Utility\CapitalCaseScheme();
    $addonInfo = $capitalCaseSheme->convertArrayKeys($addonInfo, ['RegisterPermissions']);
    $screenName = Gdn_Format::display(val('Name', $addonInfo, $addonName));
    $description = Gdn_Format::html(t(val('Name', $addonInfo, $addonName) . ' Description', val('Description', $addonInfo, '')));
    $id = Gdn_Format::url($addonName) . '-addon';
    $media = new MediaItemModule($screenName, '', $description, 'li', ['id' => $id]);
    $media->setView('media-addon');
    // Icon
    $addon = Gdn::addonManager()->lookupAddon($addonName);
    $iconPath = '';
    if ($addon) {
        $iconPath = $addon->getIcon();
    }
    if (!$iconPath) {
        $iconPath = val('IconUrl', $addonInfo, 'applications/dashboard/design/images/addon-placeholder.png');
    }
    $media->setImage($iconPath);
    // Settings button
    $settingsUrl = $isEnabled ? val('SettingsUrl', $addonInfo, '') : '';
    $settingsPopupClass = val('UsePopupSettings', $addonInfo, true) ? ' js-modal' : '';
    if ($settingsUrl != '') {
        $attr['class'] = 'btn btn-icon-border' . $settingsPopupClass;
        $attr['aria-label'] = sprintf(t('Settings for %s'), $screenName);
        $attr['data-reload-page-on-save'] = false;
        $media->addButton(dashboardSymbol('settings'), $settingsUrl, $attr);
    }
    // Toggle
    if ($addonType === 'locales') {
        $action = $isEnabled ? 'disable' : 'enable';
    } else {
        $action = $filter;
    }
    if ($isEnabled) {
        $label = sprintf(t('Disable %s'), $screenName);
    } else {
        $label = sprintf(t('Enable %s'), $screenName);
    }
    $url = '/settings/' . $addonType . '/' . $action . '/' . $addonName;
    $media->setToggle(slugify($addonName), $isEnabled, $url, $label);
    // Meta
    $info = [];
    // Requirements
    $requiredApplications = val('RequiredApplications', $addonInfo, false);
    $requiredPlugins = val('RequiredPlugins', $addonInfo, false);
    $requirements = [];
    if (is_array($requiredApplications)) {
        foreach ($requiredApplications as $requiredApplication => $versionInfo) {
            $requirements[] = sprintf(t('%1$s Version %2$s'), $requiredApplication, $versionInfo);
        }
    }
    if (is_array($requiredPlugins)) {
        foreach ($requiredPlugins as $requiredPlugin => $versionInfo) {
            $requirements[] = sprintf(t('%1$s Version %2$s'), $requiredPlugin, $versionInfo);
        }
    }
    if (!empty($requirements)) {
        $requirementsMeta = sprintf(t('Requires: %s'), implode(', ', $requirements));
        $info[] = $requirementsMeta;
    }
    // Authors
    $author = val('Author', $addonInfo, '');
    $authors = [];
    // Check if singular author is set
    if ($author) {
        $authorUrl = val('AuthorUrl', $addonInfo, '');
        if ($authorUrl) {
            $authors[] = anchor($author, $authorUrl);
        } else {
            $authors[] = $author;
        }
    }
    // Check for multiple authors
    foreach (val('Authors', $addonInfo, []) as $author) {
        if (val('Homepage', $author)) {
            $authors[] = anchor(val('Name', $author), val('Homepage', $author));
        } else {
            $authors[] = val('Name', $author);
        }
    }
    if ($authors) {
        $authors = implode(', ', $authors);
        $info[] = sprintf(t('Created by %s'), $authors);
    }
    // Version Info
    $version = Gdn_Format::display(val('Version', $addonInfo, ''));
    $newVersion = val('NewVersion', $addonInfo, '');
    $upgrade = $newVersion != '' && version_compare($newVersion, $version, '>');
    if ($version != '') {
        $info[] = sprintf(t('Version %s'), $version);
    }
    $pluginUrl = val('PluginUrl', $addonInfo, '');
    if ($upgrade && $pluginUrl) {
        $info[] = anchor(printf(t('%1$s version %2$s is available.'), $screenName, $newVersion), combinePaths(array($pluginUrl, 'find', urlencode($screenName)), '/'));
    }
    if ($pluginUrl != '') {
        $info[] = anchor(t('Visit Site'), $pluginUrl);
    }
    // Extra meta in addon array
    if ($meta = val('Meta', $addonInfo)) {
        foreach ($meta as $key => $value) {
            if (is_numeric($key)) {
                $info[] = $value;
            } else {
                $info[] = t($key) . ': ' . $value;
            }
        }
    }
    $media->setMeta($info);
    echo $media;
}
コード例 #4
0
ファイル: admin.master.php プロジェクト: vanilla/vanilla
$this->renderAsset('Symbols');
// TODO: Pull this asset out elsewhere
Gdn_Theme::assetBegin('DashboardUserDropDown');
$user = Gdn::session()->User;
$rm = new RoleModel();
$roles = $rm->getByUserID(val('UserID', $user))->resultArray();
$roleTitlesArray = [];
foreach ($roles as $role) {
    $roleTitlesArray[] = val('Name', $role);
}
$roleTitles = implode(', ', $roleTitlesArray);
/** var UserController $user */
?>
<div class="card card-user">
    <?php 
$userBlock = new MediaItemModule(val('Name', $user), userUrl($user), $roleTitles, '', ['class' => 'card-block']);
$userBlock->setView('media-sm')->setImage(userPhotoUrl($user))->addButton(t('My Profile') . ' ' . dashboardSymbol('external-link', 'icon-11 icon-text'), userUrl($user), ['class' => 'btn btn-sm-rounded btn-secondary padded-top']);
echo $userBlock;
?>
    <div class="list-group list-group-flush">
        <?php 
foreach ($this->data('meList', []) as $meItem) {
    echo anchor(t($meItem['text']) . (val('isExternal', $meItem, true) ? ' ' . dashboardSymbol('external-link') : ''), $meItem['url'], 'list-group-item', ['target' => '_blank']);
}
?>
    </div>
    <div class="card-footer">
        <?php 
echo anchor(t('Sign Out'), signOutUrl(), 'btn btn-secondary Leave');
?>
    </div>
コード例 #5
0
ファイル: index.php プロジェクト: vanilla/vanilla
    exit;
}
?>
<h1><?php 
echo t('Dashboard Home');
?>
</h1>
<?php 
$this->RenderAsset('Messages');
$leaderboard = new TableSummaryModule(t('Active Users'));
$leaderboard->addColumn('users', t('Name'), [], TableSummaryModule::MAIN_CSS_CLASS)->addColumn('count-comments', t('Comments'), ['class' => 'column-xs']);
foreach ($this->ActiveUserData as $userdata) {
    $id = val('UserID', $userdata);
    $user = Gdn::userModel()->getID($id);
    $name = val('Name', $user);
    $userBlock = new MediaItemModule(val('Name', $user), userUrl($user), '', 'div');
    $userBlock->setView('media-sm')->setImage(userPhotoUrl($user))->addMeta(Gdn_Format::date(val('DateLastActive', $user), 'html'));
    $leaderboard->addRow(['users' => $userBlock, 'count-comments' => number_format($user->CountComments)]);
}
?>

<div class="summaries">
    <?php 
echo $leaderboard;
?>
</div>
<div class="summaries">
    <div class="ReleasesColumn">
        <div class="table-summary-title"><?php 
echo t('Updates');
?>
コード例 #6
0
ファイル: table.php プロジェクト: vanilla/vanilla
 ?>
             </td>
             <td class="PostType">
                 <?php 
 echo t($RecordLabel);
 ?>
             </td>
             <td class="DateCell">
                 <?php 
 echo Gdn_Format::date($Row['DateInserted'], '%e %b %Y');
 ?>
             </td>
             <td class="PostedByCell"><?php 
 $RecordUser = Gdn::userModel()->getID($Row['RecordUserID'], DATASET_TYPE_ARRAY);
 if ($Row['RecordName']) {
     $userBlock = new MediaItemModule(val('Name', $RecordUser), userUrl($RecordUser));
     $userBlock->setView('media-sm')->addMeta(plural($RecordUser['CountDiscussions'] + $RecordUser['CountComments'], '%s post', '%s posts'))->addMetaIf($RecordUser['Banned'] ? true : false, wrap(t('Banned'), 'span', ['class' => 'text-danger']))->addMetaIf($viewPersonalInfo && val('RecordIPAddress', $Row), iPAnchor($Row['RecordIPAddress']));
     echo $userBlock;
 }
 ?>
             </td>
             <td class="options">
                 <?php 
 if ($Url) {
     $attr = ['title' => t('View Post'), 'aria-label' => t('View Post'), 'class' => 'btn btn-icon btn-icon-sm'];
     echo anchor(dashboardSymbol('external-link', 'icon icon-text'), $Url, '', $attr);
 }
 ?>
             </td>
         </tr>
     <?php 
コード例 #7
0
<?php

if (!defined('APPLICATION')) {
    exit;
}
$userBoard = new TableSummaryModule(t('Active Users'));
$userBoard->addColumn('users', t('Name'), [], TableSummaryModule::MAIN_CSS_CLASS)->addColumn('count-comments', t('Comments'), ['class' => 'column-xs']);
foreach ($this->Data['UserData'] as $userdata) {
    $id = val('UserID', $userdata);
    $user = Gdn::userModel()->getID($id);
    $name = val('Name', $user);
    $userBlock = new MediaItemModule(val('Name', $user), userUrl($user), '', 'div');
    $userBlock->setView('media-sm')->setImage(userPhotoUrl($user))->addMeta(Gdn_Format::date(val('DateLastActive', $user), 'html'));
    $userBoard->addRow(['users' => $userBlock, 'count-comments' => number_format($user->CountComments)]);
}
echo $userBoard;
$discussionBoard = new TableSummaryModule(t('Popular Discussions'));
$discussionBoard->addColumn('discussion', t('Title'), ['class' => 'column-xs'], TableSummaryModule::MAIN_CSS_CLASS)->addColumn('count-comments', t('Comments'), ['class' => 'column-xs'])->addColumn('count-bookmarks', t('Follows'), ['class' => 'column-xs'])->addColumn('count-views', t('Views'), ['class' => 'column-xs']);
foreach ($this->Data['DiscussionData'] as $discussion) {
    $discussionBlock = new MediaItemModule(htmlspecialchars($discussion->Name), DiscussionUrl($discussion), '', 'div');
    $discussionBlock->setView('media-sm')->addMeta(Gdn_Format::date($discussion->DateInserted, 'html'));
    $discussionBoard->addRow(['discussion' => $discussionBlock, 'count-comments' => number_format($discussion->CountComments), 'count-bookmarks' => number_format($discussion->CountBookmarks), 'count-views' => number_format($discussion->CountViews)]);
}
echo $discussionBoard;