Login  |  Register
HTML5 Icon HTML5 Icon HTML5 Icon
TP on Social Media

Recent

Welcome, Guest. Please login or register.
Did you miss your activation email?

August 12, 2022, 09:39:24 AM

Login with username, password and session length
Members
  • Total Members: 3842
  • Latest: Kokoro
Stats
  • Total Posts: 193479
  • Total Topics: 21088
  • Online today: 50
  • Online ever: 1035
  • (November 26, 2020, 04:45:12 AM)
Users Online
Users: 0
Guests: 39
Total: 39

Author Topic: TPTAG Cloud Snippet  (Read 8049 times)

0 Members and 1 Guest are viewing this topic.

Offline kohai.raul

  • Jr. Member
  • **
  • Posts: 19
TPTAG Cloud Snippet
« on: May 25, 2015, 04:08:43 AM »
Hi!!

I'm a new user of TinyPortal. I'm trying to set up the next version of our forum, and just now I'm looking for a Tag Cloud (or snippet) for TPTags module. I don't found at all,  other than for Tagging System Mod in the following thread:

http://www.tinyportal.net/index.php?topic=13744.0

So, I'm trying to "replicate" this snippet exclusively for TPTag module.

By exploring TinyPortal's database structure and considering the thread above, I decided to use the following query, specially for "topics":

Code: [Select]
SELECT t.subtype AS tag, t.subtype AS idtag,COUNT(t.subtype) AS quantity
FROM {db_prefix}tp_variables AS t
        WHERE t.type = 'globaltag_item'
        AND t.value3='tpadmin_topictags'
GROUP BY t.tag
ORDER BY t.tag DESC LIMIT 50

 
So the first snippet that I tried to test (into a TP block) was:

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

$result = $smcFunc['db_query']('','SELECT t.subtype AS tag, t.subtype AS idtag,COUNT(t.subtype) AS quantity
FROM {db_prefix}tp_variables AS t
        WHERE t.type = \'globaltag_item\'
        AND t.value3=\'tpadmin_topictags\'
GROUP BY t.tag
ORDER BY t.tag DESC LIMIT {int:limit}',
array('limit' = 50)
);

$tags = array();
$tags2 = array();

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

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

print_r("Prueba lista tags:".$tags2);

... But obtained NO results!! ... no message :-/

I found traces in logs as the following ones, but I don't know if they're related with my snippet:

Quote

http://develop.fuentedepermacultura.org/index.php?
8: Undefined index: REQUEST_URL
Archivo: /var/www/vhosts/fuentedepermacultura.org/develop/Sources/Subs.php
Línea: 3046

http://develop.fuentedepermacultura.org/index.php?pretty;action=admin&area=packages;sa=installed;be37ac7bc5=a9a12e7142170ca87f4ecc0514dfe207
8: Undefined index: sub_buttons
Archivo: /var/www/vhosts/fuentedepermacultura.org/develop/Themes/default/languages/TPortal.spanish_es.php (body_above sub template - eval?)
Línea: 400


Someone knows what's happening with this snippet and/or logged errors??

I will appreciate your help!! :-)

Looking forward to hearing from you,

-- EXTRA INFO --

Link to my forum: http://foro.fuentedepermacultura.org
SMF version: SMF 2.0.4
TP version: TP 1.107
Default Forum Language: spanish_es
Theme name and version: Reseller Responsive
Browser Name and Version: Firefox 37.0.2 4Ubuntu
Mods installed: View Single Category_2.4; Post Scheduler_1.0.1; External and NoFollow All Links_1.0.0; Downloads System_2.1a; Responsive Curve_1.0 Beta 3; Team Page_4.0.1; Simple Audio Video Embedder_3.1; Additional Topic Authors_0.1.1; Pretty URLs_1.1.2; SMFBlog_2.0; TinyPortal_1.107; Ad Seller Pro_2.5.1a; SMF Links Directory_2.3.2; AdditionalMembergroups_1.02; Optimus Brave_1.8.7; SEO Sitemap_2.2.1; SMF 2.0.4 Update_1.0; SMF 2.0.3 Update_1.0; Hide Tag Special_3.0; Embed BBCode_1.5; Bookmarks_2.5; Stop Spammer_2.3.9; reCAPTCHA for SMF_0.9.8a

-- COMMENT UPDATES --

May, 25

The SQL query has an error. The query should be (tested on phpmyadmin):

Code: [Select]
$query='SELECT t.subtype AS tag, t.subtype AS idtag,COUNT(t.subtype) AS quantity
FROM {$db_prefix}tp_variables AS t
WHERE t.type = \'globaltag_item\' 
AND t.value3=\'tpadmin_topictags\'
GROUP BY t.subtype
ORDER BY t.subtype
DESC LIMIT {int:limit}';

1st - Testing the following code into a block on frontage:

Code: [Select]
global $scripturl, $smcFunc,$db_prefix;

$query='SELECT t.subtype AS tag, t.subtype AS idtag,COUNT(t.subtype) AS quantity
FROM {$db_prefix}tp_variables AS t
WHERE t.type = \'globaltag_item\' 
AND t.value3=\'tpadmin_topictags\'
GROUP BY t.subtype
ORDER BY t.subtype
DESC LIMIT {int:limit}';

print_r($query);

RESULT:  I can read/see the query on webpage

2nd - the second test:

Code: [Select]
global $scripturl, $smcFunc,$db_prefix;

$query='SELECT t.subtype AS tag, t.subtype AS idtag,COUNT(t.subtype) AS quantity
FROM {$db_prefix}tp_variables AS t
WHERE t.type = \'globaltag_item\' 
AND t.value3=\'tpadmin_topictags\'
GROUP BY t.subtype
ORDER BY t.subtype
DESC LIMIT {int:limit}';

print_r($query);

$resultTags = $smcFunc['db_query']('', $query,array('limit' = 50));

print_r($resultTags);

RESULT:
the block content is totally empty!!

Seems it my forum doesn't accept the smcFunc instance????

:-?
« Last Edit: May 25, 2015, 08:26:19 AM by kohai.raul »

Offline kohai.raul

  • Jr. Member
  • **
  • Posts: 19
Re: TPTAG Cloud Snippet
« Reply #1 on: May 28, 2015, 11:28:46 AM »
Hi all!!

Finally, I realized what the error was.

Quote
$result =

 ...
   GROUP BY t.tag
   ORDER BY t.tag DESC LIMIT {int:limit}',
   array('limit' = 50)
);

should be

Quote
array('limit' => 50)

so, an appropiate snippet could be:

Code: [Select]
global $scripturl, $smcFunc,$db_prefix,$db_connection;

$query='SELECT t.subtype AS tag, t.subtype AS idtag,COUNT(t.subtype) AS quantity
FROM {db_prefix}tp_variables AS t
WHERE t.type = \'globaltag_item\' 
AND t.value3=\'tpadmin_topictags\'
GROUP BY t.subtype
ORDER BY t.subtype
DESC LIMIT {int:limit}';

$resultTags = $smcFunc['db_query']('', $query,array('limit' => 50));

$tags = array();
$tags2 = array();

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


if(count($tags2) > 0)
{

$max_size = 250; // max font size in %
$min_size = 100; // 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);

$poptags = '';
$row_count = 0;
foreach ($tags as $key => $value)
{
               $linkcontent="";
$row_count++;
$size = $min_size + (($value - $min_qty) * $step);
// uncomment if you want sizes in whole %:
// $size = ceil($size);

                //THE FOLLOWING LINK ISN'T CORRECT!!!! IS THE ONLY THING I NEED TO 
$linkcontent = '' . $scripturl . '?action=tags;id=' . $tags2[$key] . '" style="font-size: '.$size.'%"';
$linkcontent .= ' title="'.$value.' things tagged with '.$key.'"';
$poptags .= '<a '.$linkcontent.'>'.$key.'</a> ';
if ($row_count > 5)
{
$poptags .= '<br />';
$row_count =0;
}
}
}

echo $poptags;

mysql_free_result($resultTags);


This way I can see the Cloud on frontpage :-) but for now, the generated link for each tag is not correct. .

I need to find out how to generate the appropiate link. How should be the link to load a by-tag page results?

Best Regards,