<?php

/**
 * [BEGIN_COT_EXT]
 * Hooks=index.tags
 * [END_COT_EXT]
 */
/**
 * User Categories plugin
 *
 * @package usercategories
 * @version 2.5.0
 * @author CMSWorks Team
 * @copyright Copyright (c) CMSWorks.ru, littledev.ru
 * @license BSD
 */
defined('COT_CODE') or die('Wrong URL.');
require_once cot_incfile('usercategories', 'plug');
$t->assign(array('USERCATEGORIES_CATALOG' => cot_usercategories_tree()));
function cot_usercategories_tree($chosen = '', $parent = '', $template = '', $level = 0)
{
    global $structure, $cfg, $gm, $group;
    global $i18n_notmain, $i18n_locale, $i18n_read;
    $urlparams = array('gm' => $gm, 'group' => $group);
    /* === Hook === */
    foreach (cot_getextplugins('usercategories.tree.first') as $pl) {
        include $pl;
    }
    /* ===== */
    if (empty($structure['usercategories'])) {
        return false;
    }
    if (!is_array($chosen)) {
        $chosen = explode(',', $chosen);
    }
    if (empty($parent)) {
        $i18n_enabled = $i18n_read;
        $children = array();
        foreach ($structure['usercategories'] as $i => $x) {
            if (mb_substr_count($structure['usercategories'][$i]['path'], ".") == 0) {
                $children[] = $i;
            }
        }
    } else {
        $i18n_enabled = $i18n_read && cot_i18n_enabled($parent);
        $children = $structure['usercategories'][$parent]['subcats'];
    }
    if (count($children) == 0) {
        return false;
    }
    $t1 = new XTemplate(cot_tplfile(array('usercategories', 'cattree', $template), 'plug'));
    /* === Hook === */
    foreach (cot_getextplugins('usercategories.tree.main') as $pl) {
        include $pl;
    }
    /* ===== */
    $level++;
    if ($parent) {
        $t1->assign(array("CAT_TITLE" => htmlspecialchars($structure['usercategories'][$parent]['title']), "CAT_DESC" => $structure['usercategories'][$parent]['desc'], "CAT_COUNT" => $structure['usercategories'][$parent]['count'], "CAT_ICON" => $structure['usercategories'][$parent]['icon']));
    }
    $t1->assign(array("CAT_URL" => cot_url("users", $urlparams + array('cat' => $parent)), "CAT_LEVEL" => $level));
    $jj = 0;
    /* === Hook - Part1 : Set === */
    $extp = cot_getextplugins('usercategories.tree.loop');
    /* ===== */
    foreach ($children as $row) {
        $jj++;
        $subcats = $structure['usercategories'][$row]['subcats'];
        $urlparams['cat'] = $row;
        $t1->assign(array("CAT_ROW_CAT" => $row, "CAT_ROW_TITLE" => htmlspecialchars($structure['usercategories'][$row]['title']), "CAT_ROW_DESC" => $structure['usercategories'][$row]['desc'], "CAT_ROW_COUNT" => $structure['usercategories'][$row]['count'], "CAT_ROW_ICON" => $structure['usercategories'][$row]['icon'], "CAT_ROW_URL" => cot_url("users", $urlparams), "CAT_ROW_SELECTED" => is_array($chosen) && in_array($row, $chosen) || !is_array($chosen) && $row == $chosen ? 1 : 0, "CAT_ROW_SUBCAT" => count($subcats) > 0 ? cot_usercategories_tree($chosen, $row, $template, $level) : '', "CAT_ROW_ODDEVEN" => cot_build_oddeven($jj), "CAT_ROW_JJ" => $jj));
        if ($i18n_enabled && $i18n_notmain) {
            $x_i18n = cot_i18n_get_cat($row, $i18n_locale);
            if ($x_i18n) {
                if (!$cfg['plugin']['i18n']['omitmain'] || $i18n_locale != $cfg['defaultlang']) {
                    $urlparams['l'] = $i18n_locale;
                }
                $t1->assign(array('CAT_ROW_URL' => cot_url('users', $urlparams), 'CAT_ROW_TITLE' => $x_i18n['title'], 'CAT_ROW_DESC' => $x_i18n['desc']));
            }
        }
        /* === Hook - Part2 : Include === */
        foreach ($extp as $pl) {
            include $pl;
        }
        /* ===== */
        $t1->parse("MAIN.CAT_ROW");
    }
    if ($jj == 0) {
        return false;
    }
    $t1->parse("MAIN");
    return $t1->text("MAIN");
}
function cot_usercategories_tree($chosen = '', $parent = '', $template = '', $level = 0)
{
    global $structure, $cfg, $gm, $group;
    global $i18n_notmain, $i18n_locale, $i18n_read;
    if (empty($structure['usercategories'])) {
        return false;
    }
    if (!is_array($chosen)) {
        $chosen = explode(',', $chosen);
    }
    if (empty($parent)) {
        $i18n_enabled = $i18n_read;
        $children = array();
        foreach ($structure['usercategories'] as $i => $x) {
            if (mb_substr_count($structure['usercategories'][$i]['path'], ".") == 0) {
                $children[] = $i;
            }
        }
    } else {
        $i18n_enabled = $i18n_read && cot_i18n_enabled($parent);
        $children = cot_structure_children('usercategories', $parent, false, false);
    }
    if (count($children) == 0) {
        return false;
    }
    $t1 = new XTemplate(cot_tplfile(array('usercategories', 'cattree', $template), 'plug'));
    $level++;
    $jj = 0;
    foreach ($children as $row) {
        $jj++;
        $subcats = cot_structure_children('usercategories', $row, false, false);
        $t1->assign(array("CAT_ROW_CAT" => $row, "CAT_ROW_TITLE" => htmlspecialchars($structure['usercategories'][$row]['title']), "CAT_ROW_DESC" => $structure['usercategories'][$row]['desc'], "CAT_ROW_COUNT" => $structure['usercategories'][$row]['count'], "CAT_ROW_ICON" => $structure['usercategories'][$row]['icon'], "CAT_ROW_URL" => cot_url("users", "gm=" . $gm . "&cat=" . $row . "&group=" . $group), "CAT_ROW_SELECTED" => is_array($chosen) && in_array($row, $chosen) || !is_array($chosen) && $row == $chosen ? 1 : 0, "CAT_ROW_SUBCAT" => count($subcats) > 0 ? cot_usercategories_tree($chosen, $row, $template, $level) : '', "CAT_ROW_ODDEVEN" => cot_build_oddeven($jj), "CAT_ROW_JJ" => $jj));
        if ($i18n_enabled && $i18n_notmain) {
            $x_i18n = cot_i18n_get_cat($row, $i18n_locale);
            if ($x_i18n) {
                $urlparams = !$cfg['plugin']['i18n']['omitmain'] || $i18n_locale != $cfg['defaultlang'] ? "gm=" . $gm . "&cat=" . $row . "&group=" . $group . "&l=" . $i18n_locale : "gm=" . $gm . "&cat=" . $row . "&group=" . $group;
                $t1->assign(array('CAT_ROW_URL' => cot_url('users', $urlparams), 'CAT_ROW_TITLE' => $x_i18n['title'], 'CAT_ROW_DESC' => $x_i18n['desc']));
            }
        }
        $t1->parse("MAIN.CAT_ROW");
        if ($parent) {
            $t1->assign(array("CAT_TITLE" => htmlspecialchars($structure['usercategories'][$parent]['title']), "CAT_DESC" => $structure['usercategories'][$parent]['desc'], "CAT_COUNT" => $structure['usercategories'][$parent]['count'], "CAT_ICON" => $structure['usercategories'][$parent]['icon']));
        }
        $t1->assign(array("CAT_URL" => cot_url("users", "gm=" . $gm . "&cat=" . $parent . "&group=" . $group), "CAT_LEVEL" => $level));
    }
    if ($jj == 0) {
        return false;
    }
    $t1->parse("MAIN");
    return $t1->text("MAIN");
}
<?php

/**
 * [BEGIN_COT_EXT]
 * Hooks=users.tags
 * [END_COT_EXT]
 */
/**
 * User Categories plugin
 *
 * @package usercategories
 * @version 2.5.0
 * @author CMSWorks Team
 * @copyright Copyright (c) CMSWorks.ru, littledev.ru
 * @license BSD
 */
defined('COT_CODE') or die('Wrong URL.');
require_once cot_incfile('usercategories', 'plug');
$t->assign(array('SEARCH_CAT' => cot_usercategories_selectcat($cat, 'cat'), 'USERCATEGORIES_CATALOG' => cot_usercategories_tree($cat)));
if (!empty($cat) && is_array($structure['usercategories'][$cat])) {
    foreach ($structure['usercategories'][$cat] as $field => $val) {
        $t->assign('CAT' . strtoupper($field), $val);
    }
}
<?php

/**
 * [BEGIN_COT_EXT]
 * Hooks=users.tags
 * [END_COT_EXT]
 */
/**
 * User Categories plugin
 *
 * @package usercategories
 * @version 2.5.0
 * @author CMSWorks Team
 * @copyright Copyright (c) CMSWorks.ru, littledev.ru
 * @license BSD
 */
defined('COT_CODE') or die('Wrong URL.');
require_once cot_incfile('usercategories', 'plug');
$t->assign(array('SEARCH_CAT' => cot_usercategories_selectcat($cat, 'cat'), 'USERCATEGORIES_CATALOG' => cot_usercategories_tree($cat), 'CATTITLE' => !empty($cat) ? $structure['usercategories'][$cat]['title'] : '', 'CATDESC' => !empty($cat) ? $structure['usercategories'][$cat]['desc'] : ''));