Sets the image. The function DOES NOT handle the url()-ing.
public setImage ( string $source = '', string $url = '', string $cssClass = '', string $alt = '' ) : MediaItemModule | ||
$source | string | The image source url. The function DOES NOT handle the url()-ing. |
$url | string | The image anchor link, if the image is an anchor. The function DOES NOT handle the url()-ing. |
$cssClass | string | The CSS class for the image. |
$alt | string | The image alt. |
Résultat | MediaItemModule | $this |
/** * 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; }
/** * 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; }