### Displaying Code Example Source: https://github.com/dragomano/light-portal/wiki/Markdown-addon Use fenced code blocks to display code snippets. This is useful for showing examples of code. ```javascript const example = "hello!"; alert(example); ``` -------------------------------- ### Start Light Portal with Docker Source: https://github.com/dragomano/light-portal/blob/master/README.md Run this command to start the Light Portal environment using Docker Compose. Ensure you are in the '_docker' directory. ```bash cd _docker docker compose up -d ``` -------------------------------- ### TODO List Example Source: https://github.com/dragomano/light-portal/wiki/Markdown-addon Markdown supports TODO lists with checkboxes. This can be used for task tracking. ```markdown - [x] item one - [ ] item two - [ ] item three ``` -------------------------------- ### Basic Plugin Class Structure Source: https://github.com/dragomano/light-portal/wiki/How-to-create-a-plugin This is a basic structure for a Light Portal plugin. It includes the namespace, necessary use statement, class definition extending the base Plugin class, and an example init() method. ```php namespace Bugo\LightPortal\Plugins\PluginName; use Bugo\LightPortal\Plugins\Plugin; class PluginName extends Plugin { public $type = 'plugin_type'; public function init() { echo 'Hello World!'; } } ``` -------------------------------- ### English Plural Forms Source: https://github.com/dragomano/light-portal/wiki/Info-for-translators Example of English plural forms using CLDR syntax for 'months'. Use this for English language files. ```php $txt['lp_months_set'] = '{months, plural, one {a month} other {# months}}'; ``` -------------------------------- ### Polish Plural Forms Source: https://github.com/dragomano/light-portal/wiki/Info-for-translators Example of Polish plural forms using CLDR syntax for 'months', demonstrating four forms: one, few, many, and other. Use this for Polish language files. ```php $txt['lp_months_set'] = '{months, plural, one {1 miesiąc} few {# miesiące} many {# miesięcy} other {# miesiąca}}'; ``` -------------------------------- ### Spanish Plural Forms Source: https://github.com/dragomano/light-portal/wiki/Info-for-translators Example of Spanish plural forms using CLDR syntax for 'months'. Use this for Spanish language files. ```php $txt['lp_months_set'] = '{months, plural, one {un mes} other {# meses}}'; ``` -------------------------------- ### Stop Light Portal with Docker Source: https://github.com/dragomano/light-portal/blob/master/README.md Run this command to stop and remove the Light Portal environment managed by Docker Compose. Ensure you are in the '_docker' directory. ```bash cd _docker docker compose down ``` -------------------------------- ### PHP Class for SEF URLs in Light Portal Source: https://github.com/dragomano/light-portal/wiki/SEF-urls-for-tags-and-categories-(with-SimpleSEF-mod) This class handles the creation and routing of SEF URLs for tags, categories, and promotion topics within the Light Portal mod. It caches category and tag data for performance. ```php categories = cache_get_data('lp_sef_categories', 3600)) === null) { $result = $smcFunc['db_query']('', /** @lang text */ ' SELECT c.category_id, c.slug, t.title FROM {db_prefix}lp_categories AS c LEFT JOIN {db_prefix}lp_translations AS t ON ( c.category_id = t.item_id AND t.type = {literal:category} AND t.lang = {string:lang} ) ORDER BY c.category_id', [ 'lang' => $language, ] ); $this->categories[0] = urlencode('no-category'); while ($row = $smcFunc['db_fetch_assoc']($result)) { $this->categories[$row['category_id']] = $row['slug'] ?: urlencode($smcFunc['strtolower']($row['title'])); } $smcFunc['db_free_result']($result); cache_put_data('lp_sef_categories', $this->categories, 3600); } if (($this->tags = cache_get_data('lp_sef_tags', 3600)) === null) { $result = $smcFunc['db_query']('', /** @lang text */ ' SELECT tag.tag_id, tag.slug, t.title FROM {db_prefix}lp_tags AS tag LEFT JOIN {db_prefix}lp_translations AS t ON ( tag.tag_id = t.item_id AND t.type = {literal:tag} AND t.lang = {string:lang} ) ORDER BY tag.tag_id', [ 'lang' => $language, ] ); while ($row = $smcFunc['db_fetch_assoc']($result)) { $this->tags[$row['tag_id']] = $row['slug'] ?: urlencode($smcFunc['strtolower']($row['title'])); } $smcFunc['db_free_result']($result); cache_put_data('lp_sef_tags', $this->tags, 3600); } } public function create(array $url_params): string { $sefstring2 = $sefstring3 = ''; foreach ($url_params as $key => $value) { if ($value === '') { $sefstring3 .= $key . './'; } else { if ($key === 'sa') { $this->type = $value; $sefstring2 .= $value . '/'; } if ($key === 'id') { if ($this->type === 'categories') { $sefstring2 .= $this->categories[$value] . '/'; } if ($this->type === 'tags') { $sefstring2 .= $this->tags[$value] . '/'; } } if ($key === 't') { if ($this->type === 'promote') { $sefstring2 .= $value . '/'; } } if ($key === 'sort') { $sefstring2 .= 'sort.' . $value . '/'; } if ($key === 'start') { $sefstring2 .= 'start.' . $value . '/'; } } } $sefstring = $sefstring2; $sefstring .= $sefstring3; return $sefstring; } public function route(array $url_params): array { global $smcFunc; $querystring = []; $item = false; if (isset($url_params[1])) { if ($url_params[0] === 'categories') { $item = array_search(urlencode($smcFunc['strtolower']($url_params[1])), $this->categories); } if ($url_params[0] === 'tags') { $item = array_search(urlencode($smcFunc['strtolower']($url_params[1])), $this->tags); } $part = 'sa=' . $url_params[0]; if ($item !== false) { $part .= '&id=' . $item; } if ($url_params[0] === 'promote') { $part .= '&t=' . $url_params[1]; } $temp = []; if (isset($url_params[2])) { $start = explode('.', $url_params[2]); $part .= '&' . $start[0] . '=' . $start[1]; } parse_str($part, $temp); $querystring += $temp; return $querystring; } foreach ($url_params as $part) { $temp = []; if (str_contains($part, '.')) { $part = substr_replace($part, '=', strpos($part, '.'), 1); } if ($url_params[0] === 'categories') { $part = 'sa=categories'; } if ($url_params[0] === 'tags') { $part = 'sa=tags'; } if ($url_params[0] === 'promote') { $part = 'sa=promote'; } parse_str($part, $temp); $querystring += $temp; } return $querystring; } } ``` -------------------------------- ### PHP Page to Preview Block Appearance Source: https://github.com/dragomano/light-portal/wiki/Preview-block-appearance-with-different-classes Use this PHP code to generate an HTML page that displays content blocks with various CSS classes. It iterates through title and content class definitions to create a grid of preview elements. ```php '; $pairs = []; foreach (Utils::$context['lp_all_title_classes'] as $aKey => $aItem) { foreach(Utils::$context['lp_all_content_classes'] as $bKey => $bItem) { echo ' '; } } echo ' '; echo 'Total variants: ', count($pairs); ?> ``` -------------------------------- ### PHP Script to Toggle LightPortal Source: https://github.com/dragomano/light-portal/wiki/How-to-enable-or-disable-the-portal-quickly This PHP script modifies the forum's settings to either include or exclude the LightPortal application file from the `integrate_pre_include1` hook. Run this script via your browser to toggle the portal. ```php $newValue]); ``` -------------------------------- ### JavaScript "Show More" Functionality Source: https://github.com/dragomano/light-portal/wiki/How-to-make-"Show-more"-feature-for-articles This JavaScript function, `show_more_button`, is added to the `FrontPage.template.php` file. It handles the display and hiding of article elements and includes `fadeIn` and `fadeOut` animations. It requires the `lp_frontpage_articles` class for article containers and the `hidden` class for initially concealed items. ```javascript function show_more_button(int $num_items = 8, int $start_elem = 1) { global $txt, $modSettings; echo '
Show more...
'; } ``` -------------------------------- ### Modify Article Data Retrieval Source: https://github.com/dragomano/light-portal/wiki/How-to-make-"Show-more"-feature-for-articles Update the `getTotalCount()` call in `FrontPage.php` to also assign the count to a `$limit` variable. This is a prerequisite for the "Show More" functionality. ```php $data['total'] = $limit = $article->getTotalCount(); ``` -------------------------------- ### Language Name to Locale Mapping Source: https://github.com/dragomano/light-portal/wiki/Migration-Guide-[DRAFT] This map shows the replacement values for language names to their corresponding locale identifiers when migrating from SMF 2.1 to 3.0. Use this to update exported entity files. ```php "english" => "en_US", "russian" => "ru_RU", "italian" => "it_IT", "greek" => "el_GR", "spanish_es" => "es_ES", "spanish_latin" => "es_419", "turkish" => "tr_TR", "german" => "de_DE", etc. ``` -------------------------------- ### Apply "hidden" Class to Article Columns Source: https://github.com/dragomano/light-portal/wiki/How-to-make-"Show-more"-feature-for-articles Add the `hidden` class to the article column div in `FrontPage.template.php`. This ensures that articles are initially hidden and can be revealed by the "Show More" button. ```html