$category, 'mode'=>$mode, 'profile_id'=>$profile, ))); } return array('message'=>'Albumregel gespeichert.'); } function bratonien_tools_get_category_tree() { $result = array(); $query = 'SELECT id,name,id_uppercat,status,uppercats,global_rank FROM '.CATEGORIES_TABLE.' ORDER BY global_rank'; foreach (query2array($query) as $category) { $depth = 0; if (!empty($category['uppercats'])) { $depth = max(0, count(explode(',', $category['uppercats'])) - 1); } $category['depth'] = $depth; $category['display_name'] = str_repeat('— ', $depth).$category['name']; $result[] = $category; } return $result; } function bratonien_tools_resolve_album_rule($category_id, array $categories, array $rules, array $defaults) { $by_id = array(); foreach ($categories as $category) { $by_id[(int)$category['id']] = $category; } $category_id = (int)$category_id; $root = $by_id[$category_id] ?? null; $is_private = $root && isset($root['status']) && $root['status'] === 'private'; // Privat ist eine Vererbungsgrenze. Eine direkt auf diesem privaten Album // gesetzte Regel bleibt moeglich, aber Regeln oeffentlicher Eltern duerfen // nicht in ein privates Album hineinvererbt werden. if ($is_private) { if (isset($rules[$category_id])) { $rule = $rules[$category_id]; if ($rule['mode'] === 'disabled') { return array('mode'=>'disabled','profile_id'=>null,'source'=>'album'); } if ($rule['mode'] === 'profile') { return array('mode'=>'profile','profile_id'=>(int)$rule['profile_id'],'source'=>'album'); } } $profile_id = $defaults['private_profile'] ?? null; if (empty($profile_id)) { return array('mode'=>'disabled','profile_id'=>null,'source'=>'global'); } return array('mode'=>'profile','profile_id'=>(int)$profile_id,'source'=>'global'); } $current = $category_id; $visited = array(); while ($current > 0 && isset($by_id[$current]) && !isset($visited[$current])) { $visited[$current] = true; if (isset($rules[$current])) { $rule = $rules[$current]; if ($rule['mode'] === 'disabled') { return array('mode'=>'disabled','profile_id'=>null,'source'=>'album'); } if ($rule['mode'] === 'profile') { return array('mode'=>'profile','profile_id'=>(int)$rule['profile_id'],'source'=>'album'); } } $current = (int)($by_id[$current]['id_uppercat'] ?? 0); } $profile_id = $defaults['public_profile'] ?? null; if (empty($profile_id)) { return array('mode'=>'disabled','profile_id'=>null,'source'=>'global'); } return array('mode'=>'profile','profile_id'=>(int)$profile_id,'source'=>'global'); }