/** * Format the content of a log file. * * @param array $Log The log entry to format. * @return string Returns the formatted log entry. */ public function formatContent($Log) { $Data = $Log['Data']; // TODO: Check for a custom log type handler. switch ($Log['RecordType']) { case 'Activity': $Result = $this->formatKey('Story', $Data); break; case 'Discussion': $Result = '<b>' . $this->formatKey('Name', $Data) . '</b><br />' . $this->formatKey('Body', $Data); break; case 'ActivityComment': case 'Comment': $Result = $this->formatKey('Body', $Data); break; case 'Configuration': $Result = $this->formatConfiguration($Data); break; case 'Registration': case 'User': $Result = $this->formatRecord(['Email', 'Name'], $Data); if ($DiscoveryText = val('DiscoveryText', $Data)) { $Result .= '<br /><b>' . t('Why do you want to join?') . '</b><br />' . Gdn_Format::display($DiscoveryText); } if (val('Banned', $Data)) { $Result .= "<br />" . t('Banned'); } break; default: $Result = ''; } return $Result; }
/** * Format a string using Markdown syntax. Also purifies the output html. * * @param mixed $Mixed An object, array, or string to be formatted. * @return string */ public static function markdown($Mixed) { if (!is_string($Mixed)) { return self::to($Mixed, 'Markdown'); } else { $Formatter = Gdn::factory('HtmlFormatter'); if (is_null($Formatter)) { return Gdn_Format::display($Mixed); } else { require_once PATH_LIBRARY . '/vendors/markdown/Michelf/MarkdownExtra.inc.php'; $Mixed = \Michelf\MarkdownExtra::defaultTransform($Mixed); $Mixed = $Formatter->format($Mixed); $Mixed = Gdn_Format::links($Mixed); $Mixed = Gdn_Format::mentions($Mixed); $Mixed = Emoji::instance()->translateToHtml($Mixed); return $Mixed; } } }
/** * Format a string using Markdown syntax. Also purifies the output HTML. * * @param mixed $Mixed An object, array, or string to be formatted. * @param boolean $Flavored Optional. Parse with Vanilla-flavored settings? Default true * @return string */ public static function markdown($Mixed, $Flavored = true) { if (!is_string($Mixed)) { return self::to($Mixed, 'Markdown'); } else { $Formatter = Gdn::factory('HtmlFormatter'); if (is_null($Formatter)) { return Gdn_Format::display($Mixed); } else { require_once PATH_LIBRARY . '/vendors/markdown/Michelf/MarkdownExtra.inc.php'; $Markdown = new MarkdownVanilla(); // Add Vanilla customizations. if ($Flavored) { $Markdown->addAllFlavor(); } $Mixed = $Markdown->transform($Mixed); $Mixed = $Formatter->format($Mixed); $Mixed = Gdn_Format::processHTML($Mixed); return $Mixed; } } }
/** * 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; }
/** * Format the content of a log file. * * @param array $Log The log entry to format. * @return string Returns the formatted log entry. */ public function formatContent($Log) { $Data = $Log['Data']; $Result = ''; $this->EventArguments['Log'] = $Log; $this->EventArguments['Result'] =& $Result; $this->fireEvent('FormatContent'); if ($Result === '') { switch ($Log['RecordType']) { case 'Activity': $Result = $this->formatKey('Story', $Data); break; case 'Discussion': $Result = '<b>' . $this->formatKey('Name', $Data) . '</b><br />' . $this->formatKey('Body', $Data); break; case 'ActivityComment': case 'Comment': $Result = $this->formatKey('Body', $Data); break; case 'Configuration': $Result = $this->formatConfiguration($Data); break; case 'Registration': case 'User': $Result = $this->formatRecord(['Email', 'Name'], $Data); if ($DiscoveryText = val('DiscoveryText', $Data)) { $Result .= '<br /><b>' . t('Why do you want to join?') . '</b><br />' . Gdn_Format::display($DiscoveryText); } if (val('Banned', $Data)) { $Result .= "<br />" . t('Banned'); } break; } } return $Result; }