https://docs.xmbforum2.com/index.php?title=Permissions:_Best_Practices&feed=atom&action=historyPermissions: Best Practices - Revision history2024-03-28T16:48:43ZRevision history for this page on the wikiMediaWiki 1.40.0https://docs.xmbforum2.com/index.php?title=Permissions:_Best_Practices&diff=291&oldid=prevMiqrogroove at 21:17, 20 April 20212021-04-20T21:17:46Z<p></p>
<table style="background-color: #fff; color: #202122;" data-mw="interface">
<col class="diff-marker" />
<col class="diff-content" />
<col class="diff-marker" />
<col class="diff-content" />
<tr class="diff-title" lang="en">
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">← Older revision</td>
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">Revision as of 14:17, 20 April 2021</td>
</tr><tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l1">Line 1:</td>
<td colspan="2" class="diff-lineno">Line 1:</td></tr>
<tr><td colspan="2" class="diff-side-deleted"></td><td class="diff-marker" data-marker="+"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;">This article discusses changes in the [[Forum Permissions System]].</ins></div></td></tr>
<tr><td colspan="2" class="diff-side-deleted"></td><td class="diff-marker" data-marker="+"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;"></ins></div></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>==Remembering Permission Relationships==</div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>==Remembering Permission Relationships==</div></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br/></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br/></td></tr>
</table>Miqrogroovehttps://docs.xmbforum2.com/index.php?title=Permissions:_Best_Practices&diff=153&oldid=prevMiqrogroove: /* Coding for XMB 1.9.10 */2017-12-27T01:19:24Z<p><span dir="auto"><span class="autocomment">Coding for XMB 1.9.10</span></span></p>
<table style="background-color: #fff; color: #202122;" data-mw="interface">
<col class="diff-marker" />
<col class="diff-content" />
<col class="diff-marker" />
<col class="diff-content" />
<tr class="diff-title" lang="en">
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">← Older revision</td>
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">Revision as of 18:19, 26 December 2017</td>
</tr><tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l49">Line 49:</td>
<td colspan="2" class="diff-lineno">Line 49:</td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>You might have noticed that due to the complexity of the new postperm column format and the function calls needed to check these permissions, it is no longer possible to write a single SQL WHERE command that will limit results to permitted forums. There are two preferred methods for generating a set of permitted forums:</div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>You might have noticed that due to the complexity of the new postperm column format and the function calls needed to check these permissions, it is no longer possible to write a single SQL WHERE command that will limit results to permitted forums. There are two preferred methods for generating a set of permitted forums:</div></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br/></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br/></td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><del style="font-weight: bold; text-decoration: none;"># </del>Make a list. For example, if you query all forums and then loop through them with a structure like while($forum = $db->fetch_array($result)) { checkForumPermissions($forum); ... } then it is pretty simple to make a comma-delimited list of FIDs. That list can be used in a second query like SELECT * FROM xmb_threads WHERE fid IN ($fids)</div></td><td class="diff-marker" data-marker="+"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;">1. </ins>Make a list. For example, if you query all forums and then loop through them with a structure like <ins style="font-weight: bold; text-decoration: none;"><code></ins>while($forum = $db->fetch_array($result)) { checkForumPermissions($forum); ... }<ins style="font-weight: bold; text-decoration: none;"></code> </ins>then it is pretty simple to make a comma-delimited list of FIDs. That list can be used in a second query like <ins style="font-weight: bold; text-decoration: none;"><code></ins>SELECT * FROM xmb_threads WHERE fid IN ($fids)<ins style="font-weight: bold; text-decoration: none;"></code></ins></div></td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><del style="font-weight: bold; text-decoration: none;"># </del>Just use a loop. As in the first method, if you already have the information you need from the first query, then just stick an if statement inside the loop to handle only the permitted forums. The $result array can be used and re-used without querying the forums more than one time.</div></td><td class="diff-marker" data-marker="+"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div> </div></td></tr>
<tr><td colspan="2" class="diff-side-deleted"></td><td class="diff-marker" data-marker="+"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;">2. </ins>Just use a loop. As in the first method, if you already have the information you need from the first query, then just stick an if statement inside the loop to handle only the permitted forums. The $result array can be used and re-used without querying the forums more than one time.</div></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br/></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br/></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>Possibly a future version could include standard functions for generating this list for you.</div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>Possibly a future version could include standard functions for generating this list for you.</div></td></tr>
</table>Miqrogroovehttps://docs.xmbforum2.com/index.php?title=Permissions:_Best_Practices&diff=152&oldid=prevMiqrogroove: /* Coding for XMB 1.9.10 */2017-12-27T01:18:29Z<p><span dir="auto"><span class="autocomment">Coding for XMB 1.9.10</span></span></p>
<table style="background-color: #fff; color: #202122;" data-mw="interface">
<col class="diff-marker" />
<col class="diff-content" />
<col class="diff-marker" />
<col class="diff-content" />
<tr class="diff-title" lang="en">
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">← Older revision</td>
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">Revision as of 18:18, 26 December 2017</td>
</tr><tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l50">Line 50:</td>
<td colspan="2" class="diff-lineno">Line 50:</td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br/></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br/></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div># Make a list. For example, if you query all forums and then loop through them with a structure like while($forum = $db->fetch_array($result)) { checkForumPermissions($forum); ... } then it is pretty simple to make a comma-delimited list of FIDs. That list can be used in a second query like SELECT * FROM xmb_threads WHERE fid IN ($fids)</div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div># Make a list. For example, if you query all forums and then loop through them with a structure like while($forum = $db->fetch_array($result)) { checkForumPermissions($forum); ... } then it is pretty simple to make a comma-delimited list of FIDs. That list can be used in a second query like SELECT * FROM xmb_threads WHERE fid IN ($fids)</div></td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><del style="font-weight: bold; text-decoration: none;"></del></div></td><td colspan="2" class="diff-side-added"></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div># Just use a loop. As in the first method, if you already have the information you need from the first query, then just stick an if statement inside the loop to handle only the permitted forums. The $result array can be used and re-used without querying the forums more than one time.</div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div># Just use a loop. As in the first method, if you already have the information you need from the first query, then just stick an if statement inside the loop to handle only the permitted forums. The $result array can be used and re-used without querying the forums more than one time.</div></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br/></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br/></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>Possibly a future version could include standard functions for generating this list for you.</div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>Possibly a future version could include standard functions for generating this list for you.</div></td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><del style="font-weight: bold; text-decoration: none;"></del></div></td><td colspan="2" class="diff-side-added"></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br/></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br/></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>==Coding for XMB 1.9.11==</div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>==Coding for XMB 1.9.11==</div></td></tr>
</table>Miqrogroovehttps://docs.xmbforum2.com/index.php?title=Permissions:_Best_Practices&diff=151&oldid=prevMiqrogroove at 01:18, 27 December 20172017-12-27T01:18:16Z<p></p>
<table style="background-color: #fff; color: #202122;" data-mw="interface">
<col class="diff-marker" />
<col class="diff-content" />
<col class="diff-marker" />
<col class="diff-content" />
<tr class="diff-title" lang="en">
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">← Older revision</td>
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">Revision as of 18:18, 26 December 2017</td>
</tr><tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l49">Line 49:</td>
<td colspan="2" class="diff-lineno">Line 49:</td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>You might have noticed that due to the complexity of the new postperm column format and the function calls needed to check these permissions, it is no longer possible to write a single SQL WHERE command that will limit results to permitted forums. There are two preferred methods for generating a set of permitted forums:</div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>You might have noticed that due to the complexity of the new postperm column format and the function calls needed to check these permissions, it is no longer possible to write a single SQL WHERE command that will limit results to permitted forums. There are two preferred methods for generating a set of permitted forums:</div></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br/></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br/></td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div>#<del style="font-weight: bold; text-decoration: none;">1 </del>Make a list. For example, if you query all forums and then loop through them with a structure like while($forum = $db->fetch_array($result)) { checkForumPermissions($forum); ... } then it is pretty simple to make a comma-delimited list of FIDs. That list can be used in a second query like SELECT * FROM xmb_threads WHERE fid IN ($fids)</div></td><td class="diff-marker" data-marker="+"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div># Make a list. For example, if you query all forums and then loop through them with a structure like while($forum = $db->fetch_array($result)) { checkForumPermissions($forum); ... } then it is pretty simple to make a comma-delimited list of FIDs. That list can be used in a second query like SELECT * FROM xmb_threads WHERE fid IN ($fids)</div></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br/></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br/></td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div>#<del style="font-weight: bold; text-decoration: none;">2 </del>Just use a loop. As in the first method, if you already have the information you need from the first query, then just stick an if statement inside the loop to handle only the permitted forums. The $result array can be used and re-used without querying the forums more than one time.</div></td><td class="diff-marker" data-marker="+"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div># Just use a loop. As in the first method, if you already have the information you need from the first query, then just stick an if statement inside the loop to handle only the permitted forums. The $result array can be used and re-used without querying the forums more than one time.</div></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br/></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br/></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>Possibly a future version could include standard functions for generating this list for you.</div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>Possibly a future version could include standard functions for generating this list for you.</div></td></tr>
</table>Miqrogroovehttps://docs.xmbforum2.com/index.php?title=Permissions:_Best_Practices&diff=150&oldid=prevMiqrogroove: Created page with "==Remembering Permission Relationships== Some unfortunate mistakes were made when the six permissions indexes were designed. You might have noticed one of them already. X_P..."2017-12-27T01:17:41Z<p>Created page with "==Remembering Permission Relationships== Some unfortunate mistakes were made when the six permissions indexes were designed. You might have noticed one of them already. X_P..."</p>
<p><b>New page</b></p><div>==Remembering Permission Relationships==<br />
<br />
Some unfortunate mistakes were made when the six permissions indexes were designed. You might have noticed one of them already. X_PERMS_VIEW and X_PERMS_USERLIST are defined separately. But why? Honestly, there is no good reason for it. The consequence to you, the coder, is that both of these permissions have to be checked every time a forum is accessed.<br />
<br />
The X_PERMS_PASSWORD permission adds another mild annoyance. Even though X_PERMS_VIEW and X_PERMS_USERLIST might be set to TRUE, it is still necessary to make an explicit check of X_PERMS_PASSWORD before allowing the user to see posts inside the forum. There are no plans to change this part of the permissions system, so remember to do this!<br />
<br />
On top of all that, none of these permissions takes into consideration that the forums.status column might be set to 'off', which also must be checked.<br />
<br />
4 and 5 were poor choices for the values of the userlist and password permissions indexes. They are going to be changed to higher values in the next version, which makes it very important to use the named constants instead of hard-coded integers.<br />
<br />
==Coding for XMB 1.9.10==<br />
<br />
The primary mechanism for permissions in 1.9.10 is function checkForumPermissions(). A simple call to this function might look like this:<br />
<br />
<pre><br />
$result = $db->query('SELECT * FROM '.X_PREFIX.'forums WHERE fid=1');<br />
$forum = $db->fetch_array($result);<br />
$perms = checkForumPermissions($forum);<br />
if ($perms[X_PERMS_VIEW]) { //$self is allowed to view $forum }<br />
</pre><br />
<br />
What's important here is that a single boolean permission setting was retrieved using the $forum array and one of the six permissions index constants from header.php, in this case X_PERMS_VIEW.<br />
<br />
If you need to access the set of all permissions for a particular index, this can be done too.<br />
<br />
<pre><br />
$result = $db->query('SELECT * FROM '.X_PREFIX.'forums WHERE fid=1');<br />
$forum = $db->fetch_array($result);<br />
$pp = explode(',', $forum['postperm']);<br />
$perms = $pp[X_PERMS_VIEW];<br />
if ($perms == $status_enum['Guest']) { //$forum has guest-only view perms }<br />
</pre><br />
<br />
Notice that a new array was used, called $status_enum. It is highly recommended that this array should be included with any hacks or mods that will need to use this pattern of code. The $status_enum array will be included in version 1.9.11, so using it now will make the code more forward compatible.<br />
<br />
<pre><br />
$status_enum = array(<br />
'Super Administrator' => 1,<br />
'Administrator' => 2,<br />
'Super Moderator' => 4,<br />
'Moderator' => 8,<br />
'Member' => 16,<br />
'Guest' => 32,<br />
'' => 32,<br />
'Banned' => (1 << 30)<br />
); //$status['Banned'] == 2^30<br />
</pre><br />
<br />
You might have noticed that due to the complexity of the new postperm column format and the function calls needed to check these permissions, it is no longer possible to write a single SQL WHERE command that will limit results to permitted forums. There are two preferred methods for generating a set of permitted forums:<br />
<br />
#1 Make a list. For example, if you query all forums and then loop through them with a structure like while($forum = $db->fetch_array($result)) { checkForumPermissions($forum); ... } then it is pretty simple to make a comma-delimited list of FIDs. That list can be used in a second query like SELECT * FROM xmb_threads WHERE fid IN ($fids)<br />
<br />
#2 Just use a loop. As in the first method, if you already have the information you need from the first query, then just stick an if statement inside the loop to handle only the permitted forums. The $result array can be used and re-used without querying the forums more than one time.<br />
<br />
Possibly a future version could include standard functions for generating this list for you.<br />
<br />
<br />
==Coding for XMB 1.9.11==<br />
<br />
If you followed the best practices for version 1.9.10, then coding for 1.9.11 will be even easier.<br />
<br />
checkForumPermissions() has been expanded to allow for easy permission masquerades. This is an invaluable feature in situations such as when a user is logged in but using a feature that must be always restricted to the Guest permissions set. Now it's as simple as this:<br />
<br />
<pre><br />
$result = $db->query('SELECT * FROM '.X_PREFIX.'forums WHERE fid=1');<br />
$forum = $db->fetch_array($result);<br />
$perms = checkForumPermissions($forum, 'Guest');<br />
if ($perms[X_PERMS_VIEW]) { //Guests are allowed to view $forum }<br />
</pre><br />
<br />
getOneForumPerm() is a new function that eliminates the need to parse the postperm column to obtain the permissions for a particular index. Now it's as simple as this:<br />
<br />
<pre><br />
$result = $db->query('SELECT * FROM '.X_PREFIX.'forums WHERE fid=1');<br />
$forum = $db->fetch_array($result);<br />
$perms = getOneForumPerm($forum, X_PERMS_VIEW);<br />
if ($perms == $status_enum['Guest']) { //$forum has guest-only view perms }<br />
</pre><br />
<br />
Also notice the $status_enum array will always be in global scope starting with version 1.9.11. The array is declared near the top of header.php so that it can even be used in functions.inc.php.<br />
<br />
permittedForums() is a new function that eliminates the headaches of querying and checking permissions on all the forums to create a list. Now it's as simple as this:<br />
<br />
<pre><br />
$forums = permittedForums(forumCache(), 'forum');<br />
foreach($forums as $forum) { //$forum['type'] etc can now be used for each forum }<br />
</pre><br />
<br />
There are also advanced arguments for cool things like building CSV lists of forum IDs.<br />
<br />
<pre><br />
$fids = permittedForums(forumCache(), 'thread', 'csv');<br />
$query = $db->query("SELECT t.* FROM ".X_PREFIX."threads AS t INNER JOIN ".X_PREFIX."forums AS f USING (fid) WHERE f.fid IN ($fids)");<br />
while($thread = $db->fetch_array($query) { //$thread['subject'] etc are available for permitted threads }<br />
</pre></div>Miqrogroove