====== WvdS.DokuWiki.If Plugin ====== **Plugin:** wvdsif\\ **Version:** 1.0.0\\ **Namespace:** ''lib/plugins/wvdsif/''\\ **Author:** Wolfgang van der Stille \\ **License:** GPL 2 ---- ===== Definition ===== The **wvdsif** plugin enables conditional content display based on user groups or browser language. It provides two tag types: '''' for group-based display and '''' for language-based display. ===== Use Cases ===== * **Permission-based Content** - Different content for guests, users, admins * **Multilingual Landing Pages** - Language-specific greetings and content * **Admin Sections** - Hidden links visible only to administrators * **Fallback Content** - Default content when no language matches * **VIP Areas** - Exclusive content for specific groups ---- ===== Syntax ===== ==== ifgroup - By User Group ==== Content for this group Content for multiple groups ==== iflang - By Browser Language ==== Content for this language Content for multiple languages Fallback content (always displayed) ---- ===== Parameters ===== ==== ifgroup Parameters ==== ^ Parameter ^ Type ^ Description ^ | ''guest'' | predefined | Not logged-in visitors | | ''user'' | predefined | All logged-in users | | ''admin'' | predefined | Administrators | | ''[groupname]'' | custom | Any group defined in DokuWiki | ==== iflang Parameters ==== ^ Parameter ^ Type ^ Description ^ | ''de'' | ISO 639-1 | German | | ''en'' | ISO 639-1 | English | | ''sl'' | ISO 639-1 | Slovenian | | ''fr'' | ISO 639-1 | French | | ''es'' | ISO 639-1 | Spanish | | ''it'' | ISO 639-1 | Italian | | ''*'' | Wildcard | All languages (fallback) | ---- ===== Examples ===== ==== Example 1: Guests vs. Logged-in ==== **Requirement:** Different greeting for guests and logged-in users. ===== Welcome! ===== Please [[?do=login|log in]] for full access. ===== Welcome Back! ===== You have access to all documentation. **Result:** * Not logged in: Shows login prompt * Logged in: Shows welcome message ==== Example 2: Admin Section ==== **Requirement:** Admin links visible only to administrators. ===== Administration ===== * [[admin:dashboard|Dashboard]] * [[admin:users|Manage Users]] * [[admin:plugins|Manage Plugins]] * [[admin:config|Configuration]] **Result:** * Admin: Sees all admin links * Other users: Block is invisible ==== Example 3: Multilingual Landing Page ==== **Requirement:** Greeting in the visitor's browser language. ===== Willkommen ===== Dies ist unsere Wissensdatenbank auf Deutsch. ===== Welcome ===== This is our knowledge base in English. ===== Dobrodošli ===== To je naša baza znanja v slovenščini. ===== Welcome ===== Please select your language above. **Result:** * Browser set to German: Shows German block * Browser set to English: Shows English block * Browser set to Slovenian: Shows Slovenian block * Other languages: Shows fallback block ==== Example 4: Multilingual Error Page ==== **Requirement:** 404 page in the visitor's language. ===== Seite nicht gefunden ===== Die angeforderte Seite existiert nicht. [[start|Zurück zur Startseite]] ===== Page Not Found ===== The requested page does not exist. [[start|Back to homepage]] ===== Error 404 ===== Page not found. [[start|Home]] ==== Example 5: VIP Content ==== **Requirement:** Premium content only for VIP members. ===== Exclusive Area ===== Here you'll find premium documentation and advanced tutorials. * [[premium:advanced|Advanced Features]] * [[premium:tutorials|Exclusive Tutorials]] ===== Premium Area ===== This area is reserved for VIP members. [[contact|Request Upgrade]] ==== Example 6: Combined Conditions ==== **Requirement:** Multiple groups in a sidebar. ~~NOCACHE~~ ===== Navigation ===== * [[start|Home]] * [[docs:index|Documentation]] * [[internal:index|Internal Area]] * [[admin:index|Administration]] * [[?do=login|Log In]] ---- ===== How It Works ===== ==== Processing Pipeline ==== 1. Tag Detection └── Finds all ... and ... tags 2. Condition Check ├── ifgroup: Checks $_SERVER['REMOTE_USER'] and group membership └── iflang: Checks Accept-Language header 3. Content Filtering ├── Condition met: Content is displayed └── Condition not met: Content is removed 4. Wildcard Processing └── is checked last (only if no other language matches) ==== Language Detection ==== The language is detected from the ''Accept-Language'' HTTP header: Accept-Language: de-DE,de;q=0.9,en;q=0.8 ^^ Primary language: "de" ^ Header Example ^ Detected Language ^ | ''de-DE,de;q=0.9'' | de | | ''en-US,en;q=0.9'' | en | | ''sl-SI,sl;q=0.9'' | sl | | ''fr-FR,en;q=0.5'' | fr | ---- ===== Configuration ===== The plugin requires no special configuration. Group detection uses standard DokuWiki ACL groups. ==== Important Note ==== Pages with '''' or '''' tags should use ''~~NOCACHE~~'' so content is re-rendered on each request. ---- ===== Error Handling ===== ^ Scenario ^ Behavior ^ | Unknown group | Block is not displayed | | Invalid language code | Block is not displayed | | No Accept-Language header | Only ''*'' wildcard is displayed | | Nested tags | Outer tag takes priority | ---- ===== Best Practices ===== * **~~NOCACHE~~** always use when ifgroup/iflang is used * **Fallback with *** provide for iflang * **Define groups clearly** in DokuWiki ACL * **Don't nest** - tags should not be nested inside each other ==== Correct ==== Admin content User content ==== Incorrect ==== Nested content ---- ===== Version History ===== ^ Version ^ Date ^ Changes ^ | 1.0.0 | 2025-01-06 | Initial release | ---- ===== See Also ===== * [[wvdslang]] - Multilingual translations * [[wvdschunk]] - Reusable HTML components * [[flat]] - Template with language switcher ---- ===== Technical Reference ===== ==== Class: syntax_plugin_wvdsif ==== **File:** ''lib/plugins/wvdsif/syntax.php'' ^ Method ^ Description ^ | ''getType()'' | Returns ''substition'' | | ''getSort()'' | Returns ''100'' | | ''connectTo($mode)'' | Registers ifgroup and iflang patterns | | ''handle($match, ...)'' | Parses tag and extracts condition | | ''render($mode, ...)'' | Returns content or empty | ==== Helper Functions ==== ^ Function ^ Description ^ | ''_checkGroup($groups)'' | Checks group membership | | ''_checkLang($langs)'' | Checks language match | | ''_getBrowserLang()'' | Extracts language from Accept-Language | ==== Variables Used ==== ^ Variable ^ Source ^ Description ^ | ''$_SERVER['REMOTE_USER']'' | PHP | Logged-in username | | ''$USERINFO['grps']'' | DokuWiki | User groups array | | ''$_SERVER['HTTP_ACCEPT_LANGUAGE']'' | HTTP | Browser language setting | ---- {{wvds:snippet>wvds_audit_badge}} ~~DISCUSSION~~