Fork me on GitHub



Make donations with PayPal!
Goal: $100.00
Due Date: Oct 31
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00

GitHub Twitter

Learn XOOPS Core

Local Support


XOOPS Code hosted on SourceForge

Cumulus Tag Cloud

- 2 2.5 2.6 4 6 admin Android AntiHarvesting AntiSpam API Apple Battlefield billige Blocks Bootstrap Captcha cell cent chronolabs Clicks Cloud content CĂN demo download Dresses facebook Fat floor Gateway giải Google Guide herre Home Honeypot html5 Human HỘ IP iPhone jQuery Language Law Legal List log Loss module modules Monster new newbb news nhiệt NHÀ online PARK Payment phone PHP Prevention profile project Protector publisher RESIDENCE responsive review Rights Room security Sentry Signatures Signed site Smartphone Smarty Smoking Solution Spam stem Studio support tag tdmcreate The Theme themes tháp User userlog weight xoops Xortify XPayment ZendFramework

New Users

Registering user

# 139414


Welcome to XOOPS!


News archives

Highlighting non-empty alphabet listing in XoopsTube

Posted by Mamba on 2013/6/16 20:40:00 (4523 reads) | Posted on Tutorials
In XoopsTube we have a visual alphabetical listing of videos, so if you would like to see all videos starting with "B" you would click on the image with "B".

Unfortunately, this is not the most user-friendly feature, because we don't know if there is anything under "B".

So we needed to indicate the existence of videos by a changed background icon, as you can see below:

Resized Image

The plan was to:

1) build an array of unique alphabet letters that have videos in the database

2) as we render the alphabet icons, check for each letter/digit if it is also in the above array, and if yes, change the icon image to the green one

XoopsTube renders the images in the function xoopstube_letters() located in /include/functions.php

As first we needed to extract the unique letters from the database and create the array:

$distinctDbLetters_arr = array();
$sql 'SELECT DISTINCT (UPPER(LEFT(title, 1))) AS letter FROM ' $xoopsDB->prefix('xoopstube_videos') ;
    if (
$result $xoopsDB->query($sql)) {
        while (
$row $xoopsDB->fetchArray($result)) {
$distinctDbLetters_arr[] = $row['letter'];

As second, we wanted to check for each alphabet letter and digit to see if it is represented in the database:

if (in_array($ltr$distinctDbLetters_arr)) {
.= '<a class="xoopstube_letters xoopstube_letters_green" href="';
        } else {
.= '<a class="xoopstube_letters" href="';

And we had to create a new class in CSS that would pull the new image:

.xoopstube_letters_green {

Things to do in the future:

- cache the array created in (1), so we don't have to read it every time from the database, and updated it only if a new video is added

The main message from this tutorial is to make our modules more user-friendly by visually indicating status of information.

As always, if somebody has a better way to achieve it, please share it with us!

Printer friendly page Send this story to a friend Create a PDF from the article
Bookmark Me
Bookmark to Google Plus
The comments are owned by the author. We aren't responsible for their content.

Nice addition, thank you!
Published: 2013/6/17 9:18 • Updated: 2013/6/17 9:18
i like tuto like this !!!
Nice work, Mamba and nice Idea !

Just 1 thing : Quote:
XoopsTube renders the images in the function xoopstube_letters() located in /include/functions.php

I think you mean in /modules/xoopstube/include/functions.php
Published: 2013/6/17 9:38 • Updated: 2013/6/17 9:39
I think you mean in /modules/xoopstube/include/functions.php

Yes, that's correct.

I use directories relative to the "user of the service":

Here, I was saying: XoopsTube, so relative to it, it was "/include/functions.php"

If it would be XOOPS itself, then it would be " /modules/xoopstube/include/functions.php"

Thanks for pointing it out.
Published: 2013/6/17 13:45 • Updated: 2013/6/17 13:45
Nice. There are other modules with similar alphabet nav that could benefit from this.
Published: 2013/6/17 21:07 • Updated: 2013/6/17 21:07
Yes, I would love to encapsulate it into a plugin or component, so it could be reused in other modules!
Published: 2013/6/18 0:18 • Updated: 2013/6/18 0:18
In wfdownload i use this...

function wfdownloads_lettersChoice()
// updated starting from this idea
$download_handler xoops_getmodulehandler('download''wfdownloads');
$criteria $download_handler->getActiveCriteria();
$countsByLetters $download_handler->getCounts($criteria);

$letterChoice _MD_WFD_BROWSETOTOPIC "<br />";
$letterChoice .= "[  ";
$alphabet = array ("0""1""2""3""4""5""6""7""8""9""A""B""C""D""E""F""G""H""I""J""K""L""M""N""O""P""Q""R""S""T""U""V""W""X""Y""Z");
$num count($alphabet) - 1;
$counter 0;

$alphabet as $letter) {
$countsByLetters[$letter])) {
$letterChoice .= "<a href='" XOOPS_URL "/modules/wfdownloads/viewcat.php?list=$letter' title='" $countsByLetters[$letter] . "'>$letter</a>";
        } else {
$letterChoice .= "$letter";
        if (
$counter == round($num 2))
$letterChoice .= " ]<br />[ ";
        elseif (
$counter != $num)
$letterChoice .= "&nbsp;|&nbsp;";
$letterChoice .= " ]";

- It uses Xoops Criteria object instead of sql commands
- Activated links/letters has downloads counts as title attribute

- What about languages ​​with non-Latin characters?
Published: 2013/8/5 9:02 • Updated: 2013/8/5 9:02
What about languages ​​with non-Latin characters?

If you look at XoopsTube code, we're getting the Alphabet from the /language/main.php file, where it is defined as a

function getXtubeAlphabet();

so the users will have the buttons in their local language.
Published: 2013/8/5 10:32 • Updated: 2013/8/5 10:32

Published: 2013/8/5 17:30 • Updated: 2013/8/5 17:30
In the future, it should go to a central location, so all modules could use it.
Published: 2013/8/5 23:53 • Updated: 2013/8/5 23:53