%title%%count%'
) {
$sort_by = strtoupper($sort_by);
//echo "entramos en la casa del reloj...
";
// *************************************************
// Procesar array para eliminar mínimos y establecer rango
// *************************************************
$count = 0;
foreach ($data_array as $data_loop) {
if (! empty($data_loop)) {
if ($data_loop['count'] >= $min_include) {
// Set the min and max number of cat entries
if ( ( ! isset($count_min) ) or ($data_loop['count'] < $count_min) ) { $count_min = $data_loop['count']; }
if ( ( ! isset($count_max) ) or ($data_loop['count'] > $count_max) ) { $count_max = $data_loop['count']; }
} else {
// Remove array element if the number of posts in this category is smaller than the min value
// We do this now since the number of posts was not available at the beginning of this foreach loop...
unset($data_array[$count]);
}
$count++;
}
}
// *************************************************
// Sort...
// *************************************************
//echo "ordenamos por: ".$sort_by."
";
switch ($sort_by) {
case 'WEIGHT_ASC':
$data_array = cattag_aux_sortmddata($data_array,'count','ASC','num');
break;
case 'WEIGHT_DESC':
$data_array = cattag_aux_sortmddata($data_array,'count','DESC','num');
break;
case 'NAME_ASC':
$data_array = cattag_aux_sortmddata($data_array,'title','ASC','num');
break;
case 'NAME_DESC':
$data_array = cattag_aux_sortmddata($data_array,'title','DESC','num');
break;
case 'RANDOM':
srand(); // en algunas versiones php antiguas, hay que 'plantar' la semilla aleatoria con esta función
shuffle($data_array);
break;
}
// *************************************************
// Scale font
// *************************************************
$spread_current = $count_max - $count_min;
$spread_default = $max_scale - $min_scale;
if ($spread_current <= 0) { $spread_current = 1; };
if ($spread_default <= 0) { $spread_default = 1; }
$scale_factor = $spread_default / $spread_current;
// *************************************************
// Create result
// *************************************************
$result = '';
//echo "FUENTE DEBE ESTAR ENTRE ".$min_scale." y ".$max_scale."
";
//echo "LOS VALORES ESTAN ENTRE ".$count_min." y ".$count_max."
";
//echo "FACTOR ES: ".$scale_factor."
";
foreach ($data_array as $data_loop) {
// font scaling
//echo "(".$data_loop['count']. " - ". $count_min.") * ". $scale_factor . " + " . $min_scale."
";
$final_font = (int) (($data_loop['count'] - $count_min) * $scale_factor + $min_scale);
// Generate output element
$element_loop = str_replace('%link%', $data_loop['link'], $element);
$element_loop = str_replace('%title%', $data_loop['name'], $element_loop);
$element_loop = str_replace('%description%', $data_loop['title'], $element_loop);
$element_loop = str_replace('%count%', $data_loop['count'], $element_loop);
$element_loop = str_replace('%size%', $final_font, $element_loop);
$result .= "\n" . $element_loop ;
}
$result = "\n" . '' . "\n" . $result; // Please do not remove this line.
return $result;
}
//##############################################################################
// Additional functions
//##############################################################################
function cattag_aux_sortmddata($array, $by, $order, $type){
// Sort a one level deep multidimensional array
// Source: http://de2.php.net/manual/de/function.array-multisort.php#61334
// $array: the array you want to sort
// $by: the associative array name that is one level deep
// example: name
// $order: ASC or DESC
// $type: num or str
$sortby = "sort$by"; //This sets up what you are sorting by
$firstval = current($array); //Pulls over the first array
$vals = array_keys($firstval); //Grabs the associate Arrays
foreach ($vals as $init){
$keyname = "sort$init";
$$keyname = array();
}
//This was strange because I had problems adding
//Multiple arrays into a variable variable
//I got it to work by initializing the variable variables as arrays
//Before I went any further
foreach ($array as $key => $row) {
foreach ($vals as $names) {
$keyname = "sort$names";
$test = array();
$test[$key] = $row[$names];
$$keyname = array_merge($$keyname,$test);
}
}
//This will create dynamic mini arrays so that I can perform
//the array multisort with no problem
//Notice the temp array... I had to do that because I
//cannot assign additional array elements to a
//varaiable variable
if ($order == "DESC") {
if ($type == "num") {
array_multisort($$sortby,SORT_DESC, SORT_NUMERIC,$array);
} else {
array_multisort($$sortby,SORT_DESC, SORT_STRING,$array);
}
} else {
if ($type == "num") {
array_multisort($$sortby,SORT_ASC, SORT_NUMERIC,$array);
} else {
array_multisort($$sortby,SORT_ASC, SORT_STRING,$array);
}
}
//This just goed through and asks the additional arguments
//What they are doing and are doing variations of
//the multisort
return $array;
}
?>