function get_tag_cloud($min_size, $max_size, $col1, $col2, $limit) { global $phpEx, $user, $config, $phpbb_root_path; $tags = get_board_tags($limit); if (sizeof($tags) > 0) { $min_count = min(array_values($tags)); $max_count = max(array_values($tags)); $spread = $max_count - $min_count; if ($spread == 0) { $spread = 1; } $tag_cloud = ''; $cTools = new ColourTools(); $gradient = $cTools->gradient($col1, $col2, $max_count); foreach ($tags as $tag => $count) { $size = $min_size + ($count - $min_count) * ($max_size - $min_size) / $spread; $tag_param = $tag; if (strpos($tag, ' ') !== false) { $tag_param = '"' . urlencode($tag) . '"'; } $tag_cloud .= ' <a style="font-size:' . $size . 'px; color:#' . $gradient[$count - 1] . ';" href="' . append_sid($phpbb_root_path . 'phpbb_topic_tagging.' . $phpEx, 'mode=search&tag=' . $tag_param) . '">' . $tag . '</a> '; } } else { $tag_cloud = false; } return $tag_cloud; }
function configure() { global $template, $user, $phpEx, $phpbb_admin_path, $config; $submit = isset($_POST['submit']) ? true : false; if ($submit) { $data = request_var('config', array('' => '')); //make sure that the hex codes are preceded by a # char if ($data['ptt_colour1'][0] != '#') { $data['ptt_colour1'] = '#' . $data['ptt_colour1']; } if ($data['ptt_colour2'][0] != '#') { $data['ptt_colour2'] = '#' . $data['ptt_colour2']; } $config_vars = array('vars' => array('ptt_tags' => array('lang' => '', 'validate' => 'int', 'type' => 'text:0:10', 'explain' => false), 'ptt_on' => array('lang' => '', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => false), 'ptt_max_font' => array('lang' => '', 'validate' => 'int', 'type' => 'text:5:5', 'explain' => false), 'ptt_min_font' => array('lang' => '', 'validate' => 'int', 'type' => 'text:5:5', 'explain' => false), 'ptt_colour1' => array('lang' => '', 'validate' => 'string', 'type' => 'text:0:7', 'explain' => false), 'ptt_colour2' => array('lang' => '', 'validate' => 'string', 'type' => 'text:0:7', 'explain' => false), 'ptt_tag_sort' => array('lang' => '', 'validate' => 'string', 'type' => 'text', 'explain' => false))); $error = array(); validate_config_vars($config_vars, $data, $error); $validate = array('ptt_tags' => array('num'), 'ptt_max_font' => array('num'), 'ptt_min_font' => array('num'), 'ptt_colour1' => array('string', false, 4, 7), 'ptt_colour2' => array('string', false, 4, 7)); $error = validate_data($data, $validate); //custom validation $ct = new ColourTools(); if (!is_numeric($data['ptt_tags'])) { $error[] = $user->lang['PTT_TAGS_NOT_NUM']; } if (!is_numeric($data['ptt_max_font'])) { $error[] = $user->lang['PTT_MAX_FONT_NOT_NUM']; } if (!is_numeric($data['ptt_min_font'])) { $error[] = $user->lang['PTT_MIN_FONT_NOT_NUM']; } if (!$ct->check_hex($data['ptt_colour1'])) { $error[] = $user->lang['PTT_ACP_COLOUR1_INVALID']; } if (!$ct->check_hex($data['ptt_colour2'])) { $error[] = $user->lang['PTT_ACP_COLOUR2_INVALID']; } if (!sizeof($error)) { $booleans = array('ptt_on'); foreach ($config_vars['vars'] as $config_name => $null) { $config_value = $data[$config_name]; if (in_array($config_name, $booleans)) { $config_value = $config_value == 'yes' ? 1 : 0; } set_config($config_name, $config_value, false); } $message = $user->lang['PTT_ACP_CONF_UPDATE_SUCCESSFUL']; $link = append_sid("index.php", "i=phpbb_topic_tagging&mode=configure"); meta_refresh(4, $phpbb_admin_path . $link); trigger_error($message . adm_back_link($link)); } $template->assign_vars(array('ERROR' => implode('<br />', $error), 'S_TAGS_ON' => $data['ptt_on'] == 'yes' ? true : false, 'TAG_AMOUNT' => $data['ptt_tags'], 'MAX_SIZE' => $data['ptt_max_font'], 'MIN_SIZE' => $data['ptt_min_font'], 'COLOUR1' => $data['ptt_colour1'], 'COLOUR2' => $data['ptt_colour2'])); $tag_sort_options = array(array('name' => $user->lang['PTT_ACP_TAG_SORT_DEFAULT'], 'value' => 'alphabetical'), array('name' => $user->lang['PTT_ACP_TAG_SORT_POPULAR'], 'value' => 'popular'), array('name' => $user->lang['PTT_ACP_TAG_SORT_RANDOM'], 'value' => 'random')); foreach ($tag_sort_options as $row) { $template->assign_block_vars('tag_sort_options', array('NAME' => $row['name'], 'VALUE' => $row['value'], 'SELECTED' => $config['ptt_tag_sort'] == $row['value'] ? ' selected' : '')); } $this->page_title = 'PTT_ACP_CONFIGURE_TITLE'; $this->tpl_name = 'acp_phpbb_topic_tagging_configure'; } else { $tag_sort_options = array(array('name' => $user->lang['PTT_ACP_TAG_SORT_DEFAULT'], 'value' => 'alphabetical'), array('name' => $user->lang['PTT_ACP_TAG_SORT_POPULAR'], 'value' => 'popular'), array('name' => $user->lang['PTT_ACP_TAG_SORT_RANDOM'], 'value' => 'random')); foreach ($tag_sort_options as $row) { $template->assign_block_vars('tag_sort_options', array('NAME' => $row['name'], 'VALUE' => $row['value'], 'SELECTED' => $config['ptt_tag_sort'] == $row['value'] ? ' selected' : '')); } $template->assign_vars(array('S_TAGS_ON' => $config['ptt_on'] == 1 ? true : false, 'TAG_AMOUNT' => $config['ptt_tags'], 'MAX_SIZE' => $config['ptt_max_font'], 'MIN_SIZE' => $config['ptt_min_font'], 'COLOUR1' => $config['ptt_colour1'], 'COLOUR2' => $config['ptt_colour2'])); $this->page_title = 'PTT_ACP_CONFIGURE_TITLE'; $this->tpl_name = 'acp_phpbb_topic_tagging_configure'; } }