SimplePortal

Customization => Custom Coding => Topic started by: stikkki on January 10, 2009, 01:57:18 PM

Title: Tags Block
Post by: stikkki on January 10, 2009, 01:57:18 PM
there is a mod for SMF for creating tags -
Tagging System For Topics http://www.simplemachines.org/community/index.php?topic=135761.0

Does anyone know a way of adding these tags into a block so that the tags cloud can be displayed on the portal so that the tags are clickable to direct you to the topics

cheers
Title: Re: Tags Block
Post by: [SiNaN] on February 03, 2009, 07:13:14 AM
For SMF 1.x:

Code: [Select]
global $db_prefix, $modSettings, $context, $scripturl;

$result = db_query("SELECT t.tag AS tag, l.ID_TAG, COUNT(l.ID_TAG) AS quantity
  FROM {$db_prefix}tags as t, {$db_prefix}tags_log as l
  WHERE t.ID_TAG = l.ID_TAG
  GROUP BY l.ID_TAG
  ORDER BY l.ID DESC LIMIT " . $modSettings['smftags_set_cloud_tags_to_show'], __FILE__, __LINE__);

$tags = array();

$tags2 = array();

while ($row = mysql_fetch_array($result))
{
    $tags[$row['tag']] = $row['quantity'];
    $tags2[$row['tag']] = $row['ID_TAG'];
}

if(count($tags2) > 0)
{
$max_size = $modSettings['smftags_set_cloud_max_font_size_precent']; // max font size in %
$min_size = $modSettings['smftags_set_cloud_min_font_size_precent']; // min font size in %

$max_qty = max(array_values($tags));
$min_qty = min(array_values($tags));

$spread = $max_qty - $min_qty;
if (0 == $spread)
{ // we don't want to divide by zero
    $spread = 1;
}

$step = ($max_size - $min_size)/($spread);

$context['poptags'] = '';
$row_count = 0;
foreach ($tags as $key => $value)
{
$row_count++;
    // calculate CSS font-size
    // find the $value in excess of $min_qty
    // multiply by the font-size increment ($size)
    // and add the $min_size set above
    $size = $min_size + (($value - $min_qty) * $step);
    // uncomment if you want sizes in whole %:
    // $size = ceil($size);

    // you'll need to put the link destination in place of the #
    // (assuming your tag links to some sort of details page)
    $context['poptags'] .= '<a href="' . $scripturl . '?action=tags;tagid=' . $tags2[$key] . '" style="font-size: '.$size.'%"';
    // perhaps adjust this title attribute for the things that are tagged
   $context['poptags'] .= ' title="'.$value.' things tagged with '.$key.'"';
   $context['poptags'] .= '>'.$key.'</a> ';
   if ($row_count > $modSettings['smftags_set_cloud_tags_per_row'])
   {
    $context['poptags'] .= '<br />';
    $row_count =0;
   }
    // notice the space at the end of the link
}
}

echo $context['poptags'];

For SMF 2.x:

Code: [Select]
global $smcFunc, $scripturl, $modSettings, $context;

$result = $smcFunc['db_query']('', "
SELECT
t.tag AS tag, l.ID_TAG, COUNT(l.ID_TAG) AS quantity
FROM {db_prefix}tags as t, {db_prefix}tags_log as l WHERE t.ID_TAG = l.ID_TAG
  GROUP BY l.ID_TAG
  ORDER BY l.ID DESC LIMIT " .  $modSettings['smftags_set_cloud_tags_to_show']);

$tags = array();

$tags2 = array();

while ($row = $smcFunc['db_fetch_assoc']($result))
{
    $tags[$row['tag']] = $row['quantity'];
    $tags2[$row['tag']] = $row['ID_TAG'];
}

if (count($tags2) > 0)
{
$max_size = $modSettings['smftags_set_cloud_max_font_size_precent']; // max font size in %
$min_size = $modSettings['smftags_set_cloud_min_font_size_precent']; // min font size in %

$max_qty = max(array_values($tags));
$min_qty = min(array_values($tags));

$spread = $max_qty - $min_qty;
if (0 == $spread)
{ // we don't want to divide by zero
    $spread = 1;
}

// determine the font-size increment
// this is the increase per tag quantity (times used)
$step = ($max_size - $min_size)/($spread);

// loop through our tag array
$context['poptags'] = '';
$row_count = 0;
foreach ($tags as $key => $value)
{
$row_count++;
    // calculate CSS font-size
    // find the $value in excess of $min_qty
    // multiply by the font-size increment ($size)
    // and add the $min_size set above
    $size = $min_size + (($value - $min_qty) * $step);
    // uncomment if you want sizes in whole %:
    // $size = ceil($size);

    // you'll need to put the link destination in place of the #
    // (assuming your tag links to some sort of details page)
    $context['poptags'] .= '<a href="' . $scripturl . '?action=tags;tagid=' . $tags2[$key] . '" style="font-size: '.$size.'%"';
    // perhaps adjust this title attribute for the things that are tagged
   $context['poptags'] .= ' title="'.$value.' things tagged with '.$key.'"';
   $context['poptags'] .= '>'.$key.'</a> ';
   if ($row_count > ($modSettings['smftags_set_cloud_tags_per_row']-1))
   {
    $context['poptags'] .= '<br />';
    $row_count =0;
   }
    // notice the space at the end of the link
}
}

echo $context['poptags'];
Title: Re: Tags Block
Post by: DaRKeN on April 22, 2010, 03:13:27 AM
Hola. Una cosilla, porque al ingresar eso en un bloque PHP de SimplePortal me marca este error:

Error en la Base de Datos
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 5
Archivo: /homepages/38/d283347434/htdocs/darken/foro/Sources/PortalBlocks.php(3444) : eval()'d code
LĂ­nea: 7


SMF: 1.1.11
SP: 2.3.2
Title: Re: Tags Block
Post by: Nathaniel on April 22, 2010, 09:10:02 AM
DaRKeN,
Please use the relevant International Support (http://simpleportal.net/index.php?board=38.0) board.
Title: Re: Tags Block
Post by: DaRKeN on April 23, 2010, 03:03:23 AM
OMG! No me di cuenta, lo siento y muchas gracias por tu paciencia y respuesta.  :)
Title: Re: Tags Block
Post by: Nathaniel on April 23, 2010, 03:41:23 AM
This is an English only support board. Please use English or use the relevant International Support (http://simpleportal.net/index.php?board=38.0) board.

You will not receive support in a language other than English here.
Title: Re: Tags Block
Post by: ccbtimewiz on April 23, 2010, 05:15:21 PM
Nathaniel, he just said "OMG! I did not realize this. I'm sorry and thank you very much for your patience and response."
Title: Re: Tags Block
Post by: Nathaniel on April 23, 2010, 09:18:05 PM
Nathaniel, he just said "OMG! I did not realize this. I'm sorry and thank you very much for your patience and response."

Thanks for the translation ccb. :) Its a bit hard to tell when its in a language I don't know though. ;)
Title: Re: Tags Block
Post by: ccbtimewiz on April 23, 2010, 11:07:23 PM
Yeah I figured. Hope he finds the right support.
Title: Re: Tags Block
Post by: amko_sa on April 24, 2010, 08:05:34 AM
Why when I click on any tag in tag list, takes me to the my forum page.
Can lead to a topic that contain that word?
I use smf 2 and simple portal 2.3.2.

Code: [Select]
global $smcFunc, $scripturl, $modSettings, $context;

$result = $smcFunc['db_query']('', "
SELECT
t.tag AS tag, l.ID_TAG, COUNT(l.ID_TAG) AS quantity
FROM {db_prefix}tags as t, {db_prefix}tags_log as l WHERE t.ID_TAG = l.ID_TAG
  GROUP BY l.ID_TAG
  ORDER BY l.ID DESC LIMIT " .  $modSettings['smftags_set_cloud_tags_to_show']);

$tags = array();

$tags2 = array();

while ($row = $smcFunc['db_fetch_assoc']($result))
{
    $tags[$row['tag']] = $row['quantity'];
    $tags2[$row['tag']] = $row['ID_TAG'];
}

if (count($tags2) > 0)
{
$max_size = $modSettings['smftags_set_cloud_max_font_size_precent']; // max font size in %
$min_size = $modSettings['smftags_set_cloud_min_font_size_precent']; // min font size in %

$max_qty = max(array_values($tags));
$min_qty = min(array_values($tags));

$spread = $max_qty - $min_qty;
if (0 == $spread)
{ // we don't want to divide by zero
    $spread = 1;
}

// determine the font-size increment
// this is the increase per tag quantity (times used)
$step = ($max_size - $min_size)/($spread);

// loop through our tag array
$context['poptags'] = '';
$row_count = 0;
foreach ($tags as $key => $value)
{
$row_count++;
    // calculate CSS font-size
    // find the $value in excess of $min_qty
    // multiply by the font-size increment ($size)
    // and add the $min_size set above
    $size = $min_size + (($value - $min_qty) * $step);
    // uncomment if you want sizes in whole %:
    // $size = ceil($size);

    // you'll need to put the link destination in place of the #
    // (assuming your tag links to some sort of details page)
    $context['poptags'] .= '<a href="' . $scripturl . '?action=tags;tagid=' . $tags2[$key] . '" style="font-size: '.$size.'%"';
    // perhaps adjust this title attribute for the things that are tagged
   $context['poptags'] .= ' title="'.$value.' things tagged with '.$key.'"';
   $context['poptags'] .= '>'.$key.'</a> ';
   if ($row_count > ($modSettings['smftags_set_cloud_tags_per_row']-1))
   {
    $context['poptags'] .= '<br />';
    $row_count =0;
   }
    // notice the space at the end of the link
}
}

echo $context['poptags'];
Title: Re: Tags Block
Post by: kcmartz on June 07, 2010, 01:43:51 PM
Nathaniel, he just said "OMG! I did not realize this. I'm sorry and thank you very much for your patience and response."

Thanks for the translation ccb. :) Its a bit hard to tell when its in a language I don't know though. ;)
http://translate.google.com will be helpful! I use it alow for one of my friends is learning japanese and I have a japanese board on my website, I use google translate to communicate, and he understands.
Title: Re: Tags Block
Post by: jamiechaos on August 09, 2010, 02:05:09 PM
For SMF 1.x:

(snip: exactly what I was looking for)


Thank you SO MUCH.  May a thousand affectionate hedgehogs descend upon your domicile bearing gifts of gold and chocolate.

-jc
SimplePortal 2.3.8 © 2008-2024, SimplePortal