[SMF] SP - Tag cloud Block - Tagging System

  • 1 Odgovora
  • 1470 Pregleda

0 Članovi i 1 gost pregledaju ovu temu.

NiKooLaa

  • Dont fear the reaper!
  • *
  • 5,405
  • +149/-13
  • Pol: Muškarac
    • dzontra.nikola
    • lastfm
    • opusteniforum
    • dzontra_nikola
    • Dzonny
    • Pogledaj profil
    • Valjevski polumaraton
[SMF] SP - Tag cloud Block - Tagging System
« poslato: April 27, 2013, 23:01:01 »
[SMF] SP - Tag cloud Block - Tagging System

Ukoliko koristite Simple Portal i želite tag cloud, a ujedno koristite Tagging sistem modul sa linka ispod, možete koristiti ovaj kod u php blocku za prikaz tag oblaka:
http://custom.simplemachines.org/mods/index.php?mod=579

global $context, $txt, $mbname,$scripturl, $user_info, $smcFunc,  $modSettings;

  // Tag cloud from www.samo-opusteno.info
$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']);

// here we loop through the results and put them into a simple array:
// $tag['thing1'] = 12;
// $tag['thing2'] = 25;
// etc so we can use all the nifty array functions
// to calculate the font-size of each tag
$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)
{
// change these font sizes if you will
$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 %

// get the largest and smallest array values
$max_qty = max(array_values($tags));
$min_qty = min(array_values($tags));

// find the range of values
$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
}
}


// Find Results
$dbresult = $smcFunc['db_query']('', "
SELECT DISTINCT l.ID_TOPIC, t.num_replies,t.num_views,m.id_member,m.poster_name,m.subject,m.id_topic,m.poster_time, t.id_board
FROM ({db_prefix}tags_log as l,{db_prefix}boards AS b, {db_prefix}topics as t, {db_prefix}messages as m)
WHERE b.ID_BOARD = t.id_board AND l.ID_TOPIC = t.id_topic AND t.approved = 1 AND t.id_first_msg = m.id_msg AND " . $user_info['query_see_board'] . " ORDER BY l.ID DESC LIMIT 20");

$context['tags_topics'] = array();
while ($row = $smcFunc['db_fetch_assoc']($dbresult))
{
$context['tags_topics'][] = array(
'id_member' => $row['id_member'],
'poster_name' => $row['poster_name'],
'subject' => $row['subject'],
'id_topic' => $row['id_topic'],
'poster_time' => $row['poster_time'],
'num_views' => $row['num_views'],
'num_replies' => $row['num_replies'],
);
}
$smcFunc['db_free_result']($dbresult);
echo'
<center>';
if (isset($context['poptags']))
  echo $context['poptags'];
echo'
</center>';
::Za webmastere :: Pravilnik foruma ::Baneri :: Magija
samo-opusteno userbar5
>> Registrujte se kako bi videli sadrzaj celog foruma! Neki delovi foruma nisu vidljivi za goste!<<
[Kako da vidim linkove na forumu??]
VAratonac :: ITcyberCOP

[Reklama]


NiKooLaa

  • Dont fear the reaper!
  • *
  • 5,405
  • +149/-13
  • Pol: Muškarac
    • dzontra.nikola
    • lastfm
    • opusteniforum
    • dzontra_nikola
    • Dzonny
    • Pogledaj profil
    • Valjevski polumaraton
Odg: [SMF] SP - Tag cloud Block - Tagging System
« Odgovor #1 poslato: April 28, 2013, 00:10:57 »
I malo izmenjen kod sa implementovanim efektima "oblaka" koji se okreće, demo:
http://www.goat1000.com/tagcanvas.php

global $context, $txt, $mbname,$scripturl, $user_info, $smcFunc,  $modSettings;

  // Tag cloud from www.samo-opusteno.info
$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']);

// here we loop through the results and put them into a simple array:
// $tag['thing1'] = 12;
// $tag['thing2'] = 25;
// etc. so we can use all the nifty array functions
// to calculate the font-size of each tag
$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)
{
// change these font sizes if you will
$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 %

// get the largest and smallest array values
$max_qty = max(array_values($tags));
$min_qty = min(array_values($tags));

// find the range of values
$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
}
}


// Find Results
$dbresult = $smcFunc['db_query']('', "
SELECT DISTINCT l.ID_TOPIC, t.num_replies,t.num_views,m.id_member,m.poster_name,m.subject,m.id_topic,m.poster_time, t.id_board
FROM ({db_prefix}tags_log as l,{db_prefix}boards AS b, {db_prefix}topics as t, {db_prefix}messages as m)
WHERE b.ID_BOARD = t.id_board AND l.ID_TOPIC = t.id_topic AND t.approved = 1 AND t.id_first_msg = m.id_msg AND " . $user_info['query_see_board'] . " ORDER BY l.ID DESC LIMIT 20");

$context['tags_topics'] = array();
while ($row = $smcFunc['db_fetch_assoc']($dbresult))
{
$context['tags_topics'][] = array(
'id_member' => $row['id_member'],
'poster_name' => $row['poster_name'],
'subject' => $row['subject'],
'id_topic' => $row['id_topic'],
'poster_time' => $row['poster_time'],
'num_views' => $row['num_views'],
'num_replies' => $row['num_replies'],
);
}
$smcFunc['db_free_result']($dbresult);
echo'
<center><div id="myCanvasContainer">
      <canvas width="190" height="300" id="myCanvas">
        <p>Anything in here will be replaced on browsers that support the canvas element</p>
      </canvas>
    </div>
    <div id="tags">';
if (isset($context['poptags']))
  echo $context['poptags'];
echo'
</div></center>';

Takodje, u Index.template.php vaše teme, negde u head tag dodajte:
    <script src="tagcanvas.min.js" type="text/javascript"></script>
    <script type="text/javascript">
      window.onload = function() {
        try {
          TagCanvas.Start('myCanvas','tags',{
            textColour: '#ff0000',
            outlineColour: '#ff00ff',
            reverse: true,
            depth: 0.8,
            maxSpeed: 0.05,
            initial: [0.110, 0.223]
          });
        } catch(e) {
          // something went wrong, hide the canvas container
          document.getElementById('myCanvasContainer').style.display = 'none';
        }
      };
    </script>

I pričaken fajl uploadujte u root.
« Poslednja izmena: April 28, 2013, 00:32:02 od strane NiKooLaa »
::Za webmastere :: Pravilnik foruma ::Baneri :: Magija
samo-opusteno userbar5
>> Registrujte se kako bi videli sadrzaj celog foruma! Neki delovi foruma nisu vidljivi za goste!<<
[Kako da vidim linkove na forumu??]
VAratonac :: ITcyberCOP