Simple Tagging

Started by Fustrate, March 30, 2009, 12:50:59 AM

Previous topic - Next topic

fotografo74

Quote from: Fustrate on April 10, 2009, 10:23:27 AM
I'll try to condense the code and make it more portal-friendly this afternoon... I have to go to work right now :)
Thanks thanks!
Antonio

Samyorn

#41
Hi Fustrate, good Mod, very nice!! :)

I have a question for you: if I want to see the cloud in the topic page with the tags on that?

Fustrate

I've been working on some stuff for the Doc Team, so this kinda got pushed to the side... I'll get to it in the next week or so.
Steven Hoffman
Former Team Member, 2009-2012

Sudhakar Arjunan

Quote from: Fustrate on April 10, 2009, 12:22:39 PM
It's in the one I posted above. Just install that package with an already existing {db_prefix}tags and {db_prefix}tag_logs tables, and it'll convert for you.

I have downloaded the table from my server to localhost smf

Updated both the tables on my localhost.

While installing the package, it said no such table called smf2_tags.

Then i have renamed my uploaded smf_tags to smf2_tags.

And the installation went smooth.

Added a new table called smf_tags by the installer.

And its not converting any tags.
Working on New Mods & Themes for SMF... Will update soon... My Blog page
My Smf forum : Discuss ITAcumens :: My SMF Forum

Fustrate

Quote from: A.SK on April 14, 2009, 04:36:59 AM
Quote from: Fustrate on April 10, 2009, 12:22:39 PM
It's in the one I posted above. Just install that package with an already existing {db_prefix}tags and {db_prefix}tag_logs tables, and it'll convert for you.

I have downloaded the table from my server to localhost smf

Updated both the tables on my localhost.

While installing the package, it said no such table called smf2_tags.

Then i have renamed my uploaded smf_tags to smf2_tags.

And the installation went smooth.

Added a new table called smf_tags by the installer.

And its not converting any tags.
Why did you download and rename and upload the tables? They should've just been left there when you upgraded.
Steven Hoffman
Former Team Member, 2009-2012

fotografo74

Thanks Yağız for the PHP block code in SimplePortal 2.2  (http://simpleportal.net/index.php?topic=1958.0)

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

   $context['tags'] = array();

   // A big thank you to Prism Perfect for this code!
   // http://prism-perfect.net/archive/php-tag-cloud-tutorial/

   $result = $smcFunc['db_query']('', '
      SELECT t.tag_name, COUNT(tt.id_tag) AS amount
      FROM {db_prefix}tags AS t
         INNER JOIN {db_prefix}tag_topics AS tt ON (tt.id_tag = t.id_tag)
      GROUP BY tt.id_tag
      LIMIT {int:limit}',
      array(
         'limit' => $modSettings['tags_to_show']
      )
   );

   while ($row = $smcFunc['db_fetch_assoc']($result)) {
      $tags[$row['tag_name']] = $row['amount'];
   }

   $smcFunc['db_free_result']($result);

   // Let's shuffle these puppies up, to make it more fun
   $keys = array_keys($tags);
   shuffle($keys);

   foreach ($keys as $key)
      $context['tags'][$key] = $tags[$key];

   $context['max_size'] = (int) $modSettings['max_tag_percentage'];
   $context['min_size'] = (int) $modSettings['min_tag_percentage'];
   $context['max_qty'] = (int) max(array_values($context['tags']));
   $context['min_qty'] = (int) min(array_values($context['tags']));

   $spread = $context['max_qty'] - $context['min_qty'];
   $spread = ($spread > 0) ? $spread : 1;

   $context['step'] = ($context['max_size'] - $context['min_size']) / $spread;


  // I'm settings this here so that you can change it on a per-theme basis
   $context['tag_colors'] = array(
      '#0AC92B', // Green
      '#CC00FF', // Purple
      '#FF0033', // Red
      '#4D4DFF', // Blue
      '#000000', // Black
   );

   $num_colors = count($context['tag_colors']) - 1;

   echo '
      <table border="0" cellspacing="0" cellpadding="8" align="center" class="tborder" style="width: 60%;">
         <tr class="catbg3">
            <td align="center"><b>', $txt['tags_tag_cloud'], '</b></td>
         </tr>
         <tr>
            <td class="windowbg" style="padding: 1em 2em 1em 2em; text-align: center;">';

   if(!empty($context['tags']))
      foreach ($context['tags'] as $key => $value){
         $color = $context['tag_colors'][mt_rand(0, $num_colors)];
         $size = ceil($context['min_size'] + (($value - $context['min_qty']) * $context['step']));
         // The index is so we can put smaller elements in front, so they won't get swallowed by the big ones.
         $index = abs($size - $context['max_size']);

         echo '<a href="', $scripturl, '?action=tags;name=', urlencode($key), '" style="z-index: ', $index, '; position: relative; font-size: ', $size, '%; color: ', $color, ';" title="', $value, ' ', $txt['tags_tagged_with'], ' ', ucwords($key), '">', str_replace(' ', '&nbsp;', ucwords($key)), '</a>&nbsp;<span class="smalltext">(', $value, ')</span> ';
      }
   else
      echo $txt['tags_none_in_cloud'];

   echo '
            </td>
         </tr>
      </table>';


I put this code in Php block in SP 2.2, no body, no title, i changed

table border="0" cellspacing="0" cellpadding="8" align="center" class="tborder" style="width: 60%;">


to

table border="0" cellspacing="0" cellpadding="8" align="center" class="tborder" style="width: 100%;">


The result:
www.macroforum.org

Thanks!
Antonio

Sudhakar Arjunan

Quote from: Fustrate on April 14, 2009, 04:58:01 AM
Why did you download and rename and upload the tables? They should've just been left there when you upgraded.

From my server to localserver in my system.

Testing the code.

So i have downloaded the two tables name smf_tags and smf_tags_logs from my current server to local system.

Uploaded and tried installing it in my local system for testing.
Working on New Mods & Themes for SMF... Will update soon... My Blog page
My Smf forum : Discuss ITAcumens :: My SMF Forum

Sudhakar Arjunan

Quote from: Fustrate on April 10, 2009, 12:22:39 PM
It's in the one I posted above. Just install that package with an already existing {db_prefix}tags and {db_prefix}tag_logs tables, and it'll convert for you.

Kindly help me out in detail, i need tagging system now.
Working on New Mods & Themes for SMF... Will update soon... My Blog page
My Smf forum : Discuss ITAcumens :: My SMF Forum

Özgür

I have a error

2: Invalid argument supplied for foreach()
File: /home/rockayse/public_html/rk/Sources/Post.php
Line: 594

592:  $raw_tags = explode(',', $_REQUEST['tags']);
593:
==>594: foreach($raw_tags as $tag){
595: $tag = preg_replace("([?!\"':;./\\|&%$#<>*\)\(\[\]{}+=@~`_]+)", "", strtolower($tag));
596:
597: $context['tags'][] = array(

How can i fix?
So Long

Fustrate

did you tag it or leave it empty? Can you attach your Post.php to a post here, so I can try something?
Steven Hoffman
Former Team Member, 2009-2012

Özgür

Yeah. I try tag place empty.
So Long

Sudhakar Arjunan

Hi Fustrate,

Any suggestions for me.

I have all the tags stored by Vbgamer45's Tagging system.

Would like to install your mod, since it has regular update and good support.
Working on New Mods & Themes for SMF... Will update soon... My Blog page
My Smf forum : Discuss ITAcumens :: My SMF Forum

Fustrate

Fixed the error, and maybe fixed the db upgrade script. Want to try? ;)
Steven Hoffman
Former Team Member, 2009-2012

gourav

@Fustrate

I am getting this error on Beta 2 RC1
Table 'gstekinf_forum.tags' doesn't exist
File: /home/gstekinf/public_html/forum/Packages/temp/install.php
Line: 20


I am installing simpale tagging 2nd time after uninsatalling it?
First time i didnt receive any of such error...
Thanks

Fustrate

I found out yesterday how to stop that error... give me a little while, there's a tag cloud SSI function that I also want to write.
Steven Hoffman
Former Team Member, 2009-2012

marcozambi

I have installed and it's functioning smoothly.
Great work!!!!

Just 2 thoughts:
1) I would be extremelyuseful to add a permission to enable only selected groups to add Tags to posts;
2) Please, do not force lowercase to Tags...

marcozambi

And after complaining, a little hint.
I have modified the "tag cloud" code for SimplePortal in this way, adding centered text, better lines separation, and removing the additional table. In this way you can simply add this code into a custom PHP code block of S.P. 2.2 and use its Title property if desired.

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

   $context['tags'] = array();

   // A big thank you to Prism Perfect for this code!
   // http://prism-perfect.net/archive/php-tag-cloud-tutorial/

   $result = $smcFunc['db_query']('', '
      SELECT t.tag_name, COUNT(tt.id_tag) AS amount
      FROM {db_prefix}tags AS t
         INNER JOIN {db_prefix}tag_topics AS tt ON (tt.id_tag = t.id_tag)
      GROUP BY tt.id_tag
      LIMIT {int:limit}',
      array(
         'limit' => $modSettings['tags_to_show']
      )
   );

   while ($row = $smcFunc['db_fetch_assoc']($result)) {
      $tags[$row['tag_name']] = $row['amount'];
   }

   $smcFunc['db_free_result']($result);

   // Let's shuffle these puppies up, to make it more fun
   $keys = array_keys($tags);
   shuffle($keys);

   foreach ($keys as $key)
      $context['tags'][$key] = $tags[$key];

   $context['max_size'] = (int) $modSettings['max_tag_percentage'];
   $context['min_size'] = (int) $modSettings['min_tag_percentage'];
   $context['max_qty'] = (int) max(array_values($context['tags']));
   $context['min_qty'] = (int) min(array_values($context['tags']));

   $spread = $context['max_qty'] - $context['min_qty'];
   $spread = ($spread > 0) ? $spread : 1;

   $context['step'] = ($context['max_size'] - $context['min_size']) / $spread;

  // I'm settings this here so that you can change it on a per-theme basis
   $context['tag_colors'] = array(
      '#0AC92B', // Green
      '#CC00FF', // Purple
      '#FF0033', // Red
      '#4D4DFF', // Blue
      '#000000', // Black
   );

   echo "<div style=\"text-align:center;\">";
   $num_colors = count($context['tag_colors']) - 1;
   if(!empty($context['tags']))
      foreach ($context['tags'] as $key => $value){
         $color = $context['tag_colors'][mt_rand(0, $num_colors)];
         $size = ceil($context['min_size'] + (($value - $context['min_qty']) * $context['step']));
         // The index is so we can put smaller elements in front, so they won't get swallowed by the big ones.
         $index = abs($size - $context['max_size']);

         echo '<a href="', $scripturl, '?action=tags;name=', urlencode($key), '" style="line-height:1.1; z-index: ', $index, '; position: relative; font-size: ', $size, '%; color: ', $color, ';" title="', $value, ' ', $txt['tags_tagged_with'], ' ', ucwords($key), '">', str_replace(' ', ' ', ucwords($key)), '</a> <span class="smalltext">(', $value, ')</span> ';
      }
   else
      echo $txt['tags_none_in_cloud'];
echo "</div>";

Sudhakar Arjunan

Quote from: Fustrate on April 25, 2009, 01:27:56 AM
Fixed the error, and maybe fixed the db upgrade script. Want to try? ;)

I have checked all the table . And installed the new version you have attached here.

Even it worked perfectly like what it has to do.

But it had not taken any tags from the existing tags stored by tagging system.
Working on New Mods & Themes for SMF... Will update soon... My Blog page
My Smf forum : Discuss ITAcumens :: My SMF Forum

neilbombd

What's different about this tagging system when compared to the vbgamer one - apart from it being useable on RC1? 

What I really need is a tagging system where people can see who has added which tag to a topic, does this do anything like that?

Fustrate

Alas, it does not show who has added which tag to a topic. I tried to keep this one fairly simple and to the point, without many fancy features.
Steven Hoffman
Former Team Member, 2009-2012

Advertisement: