Resource icon

vBulletin Zoints Tag Cloud for vBPortal 1.0.0

Kevin

Code Monkey
Staff member
[ If you are using vBadvanced CMPS then please see this thread. ]

I was asked to create a vBPortal version of the CMPS Tag Cloud module so a little bit later I have a working block ready to go. Note that I have this pegged as version 1.0.0 because I'm new to vBPortal and am not familiar enough with it to have it do some more advanced stuff but this is a good starting point for future revisions (that are already being worked on). Thanks goes out to scotmist for hooking me up with a copy of vBPortal to test with! :cool:

Please let me know if you have any problems or questions that I can address. :smiley:

Step #1 - Create a New Template
  • From your AdminCP select Styles & Templates => Style Manager => {Select your parent style} => Add New Template.
    • Title = vbp_portal_zointstags_tagcloud
    • Template =
      HTML:
      <!-- Zoints Tag Cloud for vBPortal by vBulletinUsers.com -->
      <div align="center" class="smallfont" style="padding: 1em">
      <form action="$vboptions[bburl]/tags/" method="POST">
      <input type="hidden" name="s" value="$session[sessionhash]" />
      <input type="text" class="bginput" name="search" value="" size="<if condition="$mods[modcol]==1">40<else />20</if>" /><if condition="!$mods[modcol]==1"><br /></if>
      <input type="submit" class="button" value="$vbphrase[zointstags_search_tags]"  />
      </form>
      
      <div>
      <br />
      <if condition="$tagcloud">$tagcloud<else />$vbphrase[zointstags_no_tag_found]</if>
      </div>
      
      <if condition="$mod_options['cv_ztp_show_maincloud'] == 1">
      <div align="center">
      <br />
      <a href="$vboptions[bburl]/tags/">[ $vbphrase[zointstags_zoints_tags] ]</a>
      </div>
      </if>
      </div>
      <!-- /Zoints Tag Cloud for vBPortal by vBulletinUsers.com -->

Step #2 - Create a New vBPortal Block
  • Go into your PortalCP and select Block Manager => Default Center Blocks => Add New Block.
    • Block Type = PHP
    • Block Title = Zoints Thread Tags
    • Link =
    • Default Weight = 2
    • Templates = Yes
    • Content =
      Code:
      global $db, $vbphrase;  
      
      $mods['modcol'] = "1";
      $mod_options['cv_ztp_show_maincloud'] = "1";
      $mod_options['cv_ztp_showtags'] = "30";
      $mod_options['cv_ztp_color1'] = "rgb(58, 140, 164)";
      $mod_options['cv_ztp_color2'] = "rgb(115,93,109)";
      $mod_options['cv_ztp_color3'] = "rgb(209,16,16)";
      $mod_options['cv_ztp_color4'] = "rgb(186,33,38)";
      
      // get special phrase groups 
        $phrasegroups = array(
          'forum'
      );
      
      $tagsurl = $vbulletin->options['bburl'] . '/tags';
      switch ($vbulletin->options['zointstags_urltype'])
      {
       # /index.php/
       case 1:
        $tagsurl .= '/index.php';
      
         if (preg_match("#index\.php(/[^/]+/)((\d+)/)?$#i", getenv('REQUEST_URI'), $matches))
         {
          $_REQUEST['tag'] = $_GET['tag'] = $matches[1];
          $_REQUEST['do'] = 'tag';
         }
      
        break;
      
       # url rewrite, add nothing
       case 2:
         if (!empty($_REQUEST['tag']))
         {
          $_REQUEST['do'] = 'tag';
          $_REQUEST['tag'] = utf8_decode($_REQUEST['tag']);
         }
      
        break;
        
       # url param
       default:
        $tagsurl .= '/index.php?tag=';
         if (!empty($_REQUEST['tag']))
         {
          $_REQUEST['do'] = 'tag';
         }
      
        break;
      }
      
      # get visible forumids for permissions
      $visible = array();
      foreach ($vbulletin->forumcache as $forumid => $forum)
      {
       $forumperms = $vbulletin->userinfo['forumpermissions']["$forumid"];
       if ((!($forumperms & $vbulletin->bf_ugp_forumpermissions['canview']) AND !$vbulletin->options['showprivateforums']) OR !$forum['displayorder'] OR !($forum['options'] & $vbulletin->bf_misc_forumoptions['active']))
       {
        continue;
       }
       $visible[] = $forumid;
      }
      
      if (!count($visible))
      {
       $visible = array(0);
      }
      
      if (!$mod_options['cv_ztp_showtags'])
      {
       $mod_options['cv_ztp_showtags'] = 30;
      }
      
      $max = 1;
      $min = 1;
      
      # get the most popular tags to form the cloud
       
      $tags = array();
      
      $_tags = $db->query_read("
        SELECT zoints_tag.tag, COUNT(*) count FROM " . TABLE_PREFIX . "zoints_tag zoints_tag
        LEFT JOIN " . TABLE_PREFIX . "thread thread ON(zoints_tag.threadid = thread.threadid)
        WHERE thread.forumid IN(" . implode(',', $visible) . ")
         " . (!empty($search) ? "AND tag LIKE '%" . $db->escape_string($search) . "%'" : '') . "
         " . (!$vbulletin->options['zointstags_show_autogen'] ? 'AND autogen != 1' : '') . "
        GROUP BY zoints_tag.tag 
        ORDER BY count DESC
        LIMIT " . $mod_options['cv_ztp_showtags']
       );
      
      $count = $db->num_rows($_tags);
      
      while ($tag = $db->fetch_array($_tags))
      {
       $tags[$tag['tag']] = $tag['count'];
       $max = max($tag['count'], $max);
       $min = min($min, $tag['count']);
      }
        
      $max -= $min;
      $max = max(1, $max);
      
      ksort($tags);
      
      $show['zointstags_delete'] = ($vbulletin->userinfo['permissions']['adminpermissions'] & $vbulletin->bf_ugp_adminpermissions['cancontrolpanel'] ? true : false);
       
      $tagcloud = '';
      $firsttag = true;
      
      foreach ($tags as $tag => $count)
      {
       $size = 100 + round(($count-$min) / $max * 100);
         $color = '';
         if ( $size > 100 and $size <= 120 and $mod_options['cv_ztp_color1']) $color='color:' . $mod_options['cv_ztp_color1'];
         if ( $size > 120 and $size <= 140 and $mod_options['cv_ztp_color2']) $color='color:' . $mod_options['cv_ztp_color2'];
         if ( $size > 140 and $size <= 160 and $mod_options['cv_ztp_color3']) $color='color:' . $mod_options['cv_ztp_color3'];
         if ( $size > 160 and $mod_options['cv_ztp_color4']) $color='color:' . $mod_options['cv_ztp_color4'] . '; font-weight:bold';
         if ($color) {
            $size .= '%; ' . $color;
         }
       $tag_clean = str_replace(' ', '-', $tag);  
       eval('$tagcloud .= "' . fetch_template('zointstags_tagcloud_tag') . '";');
       $firsttag = false;
      }
      
      // ### Update the template to have the path qualified ###
      $tagcloud = str_replace('"tags/', '"' . $vbulletin->options['bburl'] . '/tags/', $tagcloud); 
      
      /* ###
             Do any cleanup; this is in case somebody has enabled colors in the portal module but did not
             change the stock template.  We could've made a copy of the 'zointstags_tagcloud_tag' template
             for this module but we believe in trying to use as much of the stock vendor's templates as
             possible (because it makes it easier for subsequent upgrades, etcetera.  If the color options
             are made part of the stock Zoints tag product in the future then we can eliminate all of the
             one-off code in this script.
         ###
      */
      $tagcloud = str_replace(')%"', ')"', $tagcloud); 
      $tagcloud = str_replace('bold%', 'bold', $tagcloud); 
      
      eval('$block_content = "' . fetch_template('vbp_portal_zointstags_tagcloud') . '";');
      
      return $block_content;
    • Limit Result = 0
Step #3 - Activate the New Block
Below the instruction reference the Jig module since that is the default module when you do a fresh install of vBPortal. Your module may be named differently.
  • From your PortalCP select Module Management => Module Manager => Jig => Edit Module.
  • While view the Jig module select Center Column => Edit the block layout.
  • You will see two sections, the top section being blocks that are active in the module and the bottom section being blocks that are inactive in the module. Scroll to the bottom of the bottom section and you should see a new listing titled Zoints Thread Tags. Check the "Insert" box on and then click on the Insert Blocks button at the very bottom.
You're all done! If you go back to your vBPortal page you should now see a new block of Zoints Thread Tags! :D


Regular visitors should see (click on thumb to preview)...
View attachment 53

... while people with permissions to delete tags should see (click on thumb to preview):
View attachment 52
 

Attachments

  • Logged_In_Administrator.jpg
    Logged_In_Administrator.jpg
    41.1 KB · Views: 249
  • Regular_Visitors.jpg
    Regular_Visitors.jpg
    37.3 KB · Views: 249
Just make sure you put it in the center block, it is too wide in either of the side blocks.
Until I get the next version done you can change the "1" in...
Code:
$mods['modcol'] = "1";
... to be "0" or some other number. :smiley: That should let it work in the sidebar fine.
 
Code is included so its possible to add custom templates using the portalcp and will be included in the next release, but meantime you would need to manually add template names. Edit vbportal's global.php (at line 444) and add the template names to $globaltemplates array - you'll see a list of other center bock templates.
Code:
 // templates likely included in every single portal page... $globaltemplates = array_merge($globaltemplates, array(
add your template names to the end of that list.
 
Code is included so its possible to add custom templates using the portalcp and will be included in the next release, but meantime you would need to manually add template names. Edit vbportal's global.php (at line 444) and add the template names to $globaltemplates array - you'll see a list of other center bock templates.
Code:
 // templates likely included in every single portal page... $globaltemplates = array_merge($globaltemplates, array(
add your template names to the end of that list.
Stuart, I'm going through my back catalog of some stuff and before I do the next item is that the recommended way for now of caching the templates?
 
Back
Top