----------------- [ Index ] -----------------
----------------- [ Introduction ] -----------------With this mod you'll be able hide categories and/or set a password.
Hidden categories will not be visible anywhere on the site and can be accessed only by a direct link to it. By default once such category opened, it will become visible for the visitor, meaning it will not be hidden anymore for that particular visitor. This behavior can be changed.
If a category
password protected, only it's name will be visible to the visitors (assuming visitor has "view category" permissions). Once visitor open it or open an image from such category, a prompt to enter the password will be showed instead. When the submitted password accepted, the category become fully accessible to the visitor, based on it's permissions. The submitted passwords are stored in the database for each member or in sessions for guests.
All subcategories inherit "hidden" and "password" settings from it's parent category.
If you have a request or suggestion, make sure you visit
Tweaks section, it might be already there
----------------- [ How to use ] -----------------Once this mod is installed, you should see two new options when edit or create new category.
----------------- [ Demo ] -----------------You can see how it works
here. You can click on "reset cat password" link on left to reset entered password and visited hidden categories.
----------------- [ Changed files ] -----------------global.phpdetails.phpcategories.phpincludes/auth.phpincludes/page_header.phpincludes/sessions.phpadmin/categories.phplang/<your language>/main.php----------------- [ New files ] -----------------install_catpashid.phpincludes/
catpass.phptemplates/
<your template>/
catpass.html
----------------- [ Installation ] -----------------Step 1Download
attached package. Extract files and upload them to your 4images folder, preserving this tree structure:
install_catpashid.phpincludes/
catpass.phptemplates/
<your template>/
catpass.html
Step 2Execute
install_catpashid.php by typing in your browser's address bar:
http://
yourdomain/4images/
install_catpashid.php
Step 3Open
global.phpFind:
$sql = "SELECT cat_id, cat_name, cat_description, cat_parent_id, cat_hits, cat_order, auth_viewcat, auth_viewimage, auth_download, auth_upload, auth_directupload, auth_vote, auth_sendpostcard, auth_readcomment, auth_postcommentReplace it with:
$sql = "SELECT cat_id, cat_name, cat_description, cat_parent_id, cat_hits, cat_order, auth_viewcat, auth_viewimage, auth_download, auth_upload, auth_directupload, auth_vote, auth_sendpostcard, auth_readcomment, auth_postcomment, cat_password, cat_hide
(or simply add
, cat_password, cat_hide at the end of that line)
Step 4Open
details.phpFind:
$cat_id = (isset($image_row['cat_id'])) ? $image_row['cat_id'] : 0;
Insert
BELOW:
cat_unhide($cat_id);
Step 4.1 Find:
if (!check_permission("auth_viewcat", $cat_id) || !check_permission("auth_viewimage", $cat_id) || !$image_row) {
redirect($url);
}Insert
BELOW:
$txt_clickstream = get_category_path($cat_id,1).$config['category_separator'].format_text($image_row['image_name'], 2).$config['category_separator'];
include(ROOT_PATH."includes/catpass.php");
Step 5Open
categories.phpFind:
$user_access = get_permission();
Insert
BELOW:
cat_unhide($cat_id);
Step 5.1 Find:
if (!$cat_id || !isset($cat_cache[$cat_id]) || !check_permission("auth_viewcat", $cat_id)) {
redirect("index.php");
}
Insert
BELOW:
include(ROOT_PATH."includes/catpass.php");
Step 6Open
includes/auth.phpFind:
function check_permission($type, $cat_id = 0) {
Replace it with:
function cat_unhide($cat_id, $save = 1)
{
global $cat_cache, $site_sess, $user_info, $site_db, $cat_parent_cache;
if (!isset($cat_cache[$cat_id]))
return;
if (isset($cat_cache[$cat_id]['auth_viewcat_backup']))
$cat_cache[$cat_id]['auth_viewcat'] = $cat_cache[$cat_id]['auth_viewcat_backup'];
$cat_subcat_ids = get_auth_subcat_ids($cat_id, $cat_id, $cat_parent_cache);
if (isset($cat_subcat_ids[$cat_id]))
{
foreach ($cat_subcat_ids[$cat_id] as $key2 => $val2)
{
if ($cat_cache[$val2]['auth_viewcat'] < $cat_cache[$cat_id]['auth_viewcat']
&& (!$cat_cache[$val2]['cat_hide']
|| ($cat_cache[$val2]['cat_hide'] && isset($user_info['cat_hide'][$val2]))))
{
$cat_cache[$val2]['auth_viewcat'] = $cat_cache[$cat_id]['auth_viewcat'];
}
}
}
if ($cat_cache[$cat_id]['cat_hide'])
{
if (isset($user_info['cat_hide'][$cat_id]))
return;
$user_info['cat_hide'][$cat_id] = "";
if (!$save)
return;
if ($user_info['cat_hide_db'])
{
$sql = "UPDATE ".USERS_TABLE." SET cat_hide = '".implode("|", array_keys($user_info['cat_hide']))."' WHERE ".get_user_table_field("", "user_id")." = ".$user_info['user_id'];
$site_db->query($sql);
}
else
{
$site_sess->set_session_var("cathide", implode("|", array_keys($user_info['cat_hide'])));
}
}
else
{
if ($cat_cache[$cat_id]['cat_parent_id'] != 0)
{
//uncomment next line if you want unhide parent category when opened child category.
// cat_unhide($cat_cache[$cat_id]['cat_parent_id'], $save);
}
}
}
function cat_pass_check($cat_id)
{
global $user_info, $site_sess, $cat_cache;
if ($user_info['user_level'] == ADMIN)
return true;
if (isset($cat_cache[$cat_id]['cat_password_id']))
$cat_id = $cat_cache[$cat_id]['cat_password_id'];
if (!isset($cat_cache[$cat_id]['cat_password']) || !$cat_cache[$cat_id]['cat_password'])
return true;
return (isset($user_info['cat_password'][$cat_id]) && $cat_cache[$cat_id]['cat_password'] == $user_info['cat_password'][$cat_id]) ? true : false;
}
function check_permission($type, $cat_id = 0) {
global $user_info, $cat_cache;
if (!_check_permission($type, $cat_id) && $cat_cache[$cat_id][$type] != 999)
{
return false;
}
if ($type != "auth_viewcat")
{
return true;
}
if ($user_info['user_level'] != ADMIN && $cat_cache[$cat_id][$type] == 999)
{
return false;
}
return true;
}
function _check_permission($type, $cat_id = 0) {
Step 6.1 Find:
if ($val['auth_viewcat'] != AUTH_ALL) {
Replace it with:
if ($val['cat_hide'] && !isset($user_info['cat_hide'][$key]))
{
$cat_cache[$key]['auth_viewcat_backup'] = $val['auth_viewcat'];
$cat_cache[$key]['auth_viewcat'] = $val['auth_viewcat'] = 999;
}
if ($val['auth_viewcat'] != AUTH_ALL || $val['cat_password']) {
Step 6.2 Find:
foreach ($cat_subcat_ids[$key] as $key2 => $val2) {
Insert
BELOW:
if (!$cat_cache[$val2]['cat_password'] && $cat_cache[$key]['cat_password']) //all subcategories also should obbey cat password from parent
{
$cat_cache[$val2]['cat_password'] = $cat_cache[$key]['cat_password'];
$cat_cache[$val2]['cat_password_id'] = (isset($cat_cache[$key]['cat_password_id'])) ? $cat_cache[$key]['cat_password_id'] : $key;
}
if ($val['auth_viewcat'] == 999)
{
if ($cat_cache[$val2]['cat_hide'] && isset($user_info['cat_hide'][$val2]) && $cat_cache[$val2]['auth_viewcat'] < $cat_cache[$key]['auth_viewcat'])
{
$cat_cache[$val2]['auth_viewcat'] = $cat_cache[$key]['auth_viewcat_backup'];
continue;
}
$cat_cache[$val2]['auth_viewcat_backup'] = $cat_cache[$key]['auth_viewcat_backup'];
}
Step 6.3 Find:
if (!check_permission($type, $key)) {
Replace it with:
if (!check_permission($type, $key) || !cat_pass_check($key)) {
Step 7Open
includes/page_header.phpFind:
if (check_permission("auth_viewcat", $key)) {
Replace it with:
if (check_permission("auth_viewcat", $key) && cat_pass_check($key)) {
Step 8
Open includes/sessions.php
Find:$user_info = $site_sess->return_user_info();
Insert BELOW:
$user_info['cat_password_db'] = true; //set to false to use only sessions to store passwords
$user_info['cat_hide_db'] = true; //set to false to use only sessions to store visited hidden categories
if ($user_info['user_level'] == GUEST || !isset($user_info['cat_password']) || ($user_info['user_level'] != GUEST && !$user_info['cat_password_db']))
{
$cat_pass = trim($site_sess->get_session_var("catpass"));
$user_info['cat_password_db'] = false;
}
else
{
$cat_pass = $user_info['cat_password'];
$user_info['cat_password_db'] = true;
}
$user_info['cat_password'] = array();
$cat_pass = explode("|", $cat_pass);
foreach($cat_pass as $key)
{
$val = explode(",", $key);
if (count($val) > 1 && $val[0] = (int)$val[0])
$user_info['cat_password'][$val[0]] = $val[1];
}
if ($user_info['user_level'] == GUEST || !isset($user_info['cat_hide']) || ($user_info['user_level'] != GUEST && !$user_info['cat_hide_db']))
{
$cat_hide = trim($site_sess->get_session_var("cathide"));
$user_info['cat_hide_db'] = false;
}
else
{
$cat_hide = $user_info['cat_hide'];
$user_info['cat_hide_db'] = true;
}
$user_info['cat_hide'] = array();
$cat_hide = explode("|", $cat_hide);
foreach($cat_hide as $key)
{
if ($key = (int)$key)
$user_info['cat_hide'][$key] = "";
}
Step 9Open
admin/categories.phpFind two (2) times:
$auth_postcomment = $HTTP_POST_VARS['auth_postcomment'];
Insert
BELOW each:
$cat_password = un_htmlspecialchars(trim($HTTP_POST_VARS['cat_password']));
$cat_hide = intval($HTTP_POST_VARS['cat_hide']);
Step 9.1 Find:
$sql = "INSERT INTO ".CATEGORIES_TABLE."
(cat_name, cat_description, cat_parent_id, cat_order, auth_viewcat, auth_viewimage, auth_download, auth_upload, auth_directupload, auth_vote, auth_sendpostcard, auth_readcomment, auth_postcomment)
VALUES
('$cat_name', '$cat_description', $cat_parent_id, $cat_order, $auth_viewcat, $auth_viewimage, $auth_download, $auth_upload, $auth_directupload, $auth_vote, $auth_sendpostcard, $auth_readcomment, $auth_postcomment)";
Replace it with:
$sql = "INSERT INTO ".CATEGORIES_TABLE."
(cat_name, cat_description, cat_parent_id, cat_order, auth_viewcat, auth_viewimage, auth_download, auth_upload, auth_directupload, auth_vote, auth_sendpostcard, auth_readcomment, auth_postcomment, cat_password, cat_hide)
VALUES
('$cat_name', '$cat_description', $cat_parent_id, $cat_order, $auth_viewcat, $auth_viewimage, $auth_download, $auth_upload, $auth_directupload, $auth_vote, $auth_sendpostcard, $auth_readcomment, $auth_postcomment, '$cat_password', $cat_hide)";
Step 9.2 Find:
show_table_separator($permission_headline, 2);
Insert
ABOVE:
show_radio_row($lang['cat_hide'], "cat_hide", 0);
show_input_row($lang['cat_password'], "cat_password", "", $textinput_size);
Step 9.3 Find:
SET cat_name = '$cat_name', cat_description = '$cat_description', cat_parent_id = $cat_parent_id, cat_order = $cat_order, cat_hits = $cat_hits, auth_viewcat = $auth_viewcat, auth_viewimage = $auth_viewimage, auth_download = $auth_download, auth_upload = $auth_upload, auth_directupload = $auth_directupload, auth_vote = $auth_vote, auth_sendpostcard = $auth_sendpostcard, auth_readcomment = $auth_readcomment, auth_postcomment = $auth_postcomment
Replace it with:
SET cat_name = '$cat_name', cat_description = '$cat_description', cat_parent_id = $cat_parent_id, cat_order = $cat_order, cat_hits = $cat_hits, auth_viewcat = $auth_viewcat, auth_viewimage = $auth_viewimage, auth_download = $auth_download, auth_upload = $auth_upload, auth_directupload = $auth_directupload, auth_vote = $auth_vote, auth_sendpostcard = $auth_sendpostcard, auth_readcomment = $auth_readcomment, auth_postcomment = $auth_postcomment, cat_password = '$cat_password', cat_hide = $cat_hide
Step 9.4 Find:
$sql = "SELECT cat_name, cat_description, cat_parent_id, cat_hits, cat_order, auth_viewcat, auth_viewimage, auth_download, auth_upload, auth_directupload, auth_vote, auth_sendpostcard, auth_readcomment, auth_postcomment
Replace it with:
$sql = "SELECT cat_name, cat_description, cat_parent_id, cat_hits, cat_order, auth_viewcat, auth_viewimage, auth_download, auth_upload, auth_directupload, auth_vote, auth_sendpostcard, auth_readcomment, auth_postcomment, cat_password, cat_hide
Step 9.5 Find:
show_input_row($lang['field_hits'], "cat_hits", $cat_row['cat_hits'], 5);
Insert
BELOW:
show_radio_row($lang['cat_hide'], "cat_hide", $cat_row['cat_hide']);
show_input_row($lang['cat_password'], "cat_password", $cat_row['cat_password'], $textinput_size);
Step 9.6 Find:
show_text_link($lang['add_subcategory'], "categories.php?action=addcat&cat_parent_id=".$cats['cat_id']);Insert
below:
if ($cats['cat_hide'] || $cats['cat_password'])
{
echo " <b>(";
if ($cats['cat_hide'])
{
echo $lang['cat_hidden'];
}
if ($cats['cat_password'])
{
echo (($cats['cat_hide']) ? ", " : "").$lang['cat_password2'];
}
echo ")</b>";
}
Step 9.7 Find two times:
$sql = "SELECT cat_id, cat_name, cat_description, cat_parent_id, cat_hits, cat_order, auth_viewcat, auth_viewimage, auth_download, auth_upload, auth_directupload, auth_vote, auth_sendpostcard, auth_readcomment, auth_postcommentReplace both with:
$sql = "SELECT cat_id, cat_name, cat_description, cat_parent_id, cat_hits, cat_order, auth_viewcat, auth_viewimage, auth_download, auth_upload, auth_directupload, auth_vote, auth_sendpostcard, auth_readcomment, auth_postcomment, cat_hide, cat_password
Step 10 Open
lang/<your language>/main.phpAt the end,
ABOVE closing
?> insert:
$lang['cat_hide'] = "Hidden";
$lang['cat_password'] = "Category password";
$lang['cat_password_msg'] = "This category is password protected.<br />Please enter the password";
$lang['cat_password_error'] = "You have entered incorrect password";
$lang['cat_hidden'] = "hidden";
$lang['cat_password2'] = "password";
Tweaks and
version history in the next reply.