The resulting Tagcloud is no shuffled. 2.6.3

Please report bugs here!

Moderator: Thorsten

Post Reply
UTAKA
Posts: 37
Joined: Sun Jan 24, 2010 8:01 am
Location: phpmyfaq-jp.org
Contact:

The resulting Tagcloud is no shuffled. 2.6.3

Post by UTAKA » Sat Mar 20, 2010 10:11 am

The resulting Tagcloud is no shuffled. 2.6.3
Ex.
http://faq.phpmyfaq.de/content/1/9/en/a ... ework.html

Tags :"Firefox Internet Explorer MySQL PHP phpMyFAQ Safari" is no shuffled.

I checked "www.php.net". I found
"5.2.10 The resulting array of keys is no longer shuffled"
array_rand() have bug.
http://www.php.net/manual/en/function.array-rand.php


array_rand($data, count($data)) don't work
I use shuffle(),and work!

Code: Select all

#
####--- Open ------------------------
#

/inc/Utils.php

#
##--- Find ------------------------
# About Line231 

    public static function shuffleData($data)
    {
        $shuffled_data = array();
        if (is_array($data)) {
            if (count($data) > 1) {
               $randomized_keys = array_rand($data, count($data));
#
#--- Replace With ------------------------
# 

    public static function shuffleData($data)
    {
        $shuffled_data = array();
        if (is_array($data)) {
            if (count($data) > 1) {
                $randomized_keys = array_keys($data); 
                shuffle($randomized_keys);  
###########################
and. /inc/Tags.php

This code is simpler .

Code: Select all

#
###--- OPEN ---------------------
#

/inc/Tags.php

#
## --- Find ---------------------
# About Line108

        $numberOfItems = $limit ? PMF_TAGS_CLOUD_RESULT_SET_SIZE : $this->db->num_rows($result);
        if (isset($allTags) && ($numberOfItems < count($allTags))) {
        	$keys = array_keys($allTags);
        	for ($n = 0; $n < $numberOfItems; $n++) {
                $valid = false;
                while (!$valid) {
                    $rand = array_rand($keys);
                    if (isset($allTags[$rand])) {
                        $valid       = true;
                        $tags[$rand] = $allTags[$rand];
                        unset($keys[$rand]);
                    }
                }
            }
        } else {
            $tags = PMF_Utils::shuffleData($allTags);
        }

#
##  ---- Replase with -----------------
#

        $numberOfItems = $limit ? PMF_TAGS_CLOUD_RESULT_SET_SIZE : $this->db->num_rows($result);

        if (isset($allTags) && ($numberOfItems < count($allTags))) {
			$keys = array_keys($allTags); 
			shuffle($keys); 
            foreach($keys as $current_key) {
                $tags[$current_key] = $allTags[$current_key];
            }
			$tags = array_slice($tags,0,$numberOfItems);
        } else {
            $tags = PMF_Utils::shuffleData($allTags);
        }

########################
---------------------------------------
Sorry...I am not good at English.
http://www.phpmyfaq-jp.org
---------------------------------------

Thorsten
Posts: 14539
Joined: Tue Sep 25, 2001 11:14 am
Location: #phpmyfaq
Contact:

Re: The resulting Tagcloud is no shuffled. 2.6.3

Post by Thorsten » Mon Apr 05, 2010 7:14 am

Hi,

thanks for the hint and the patch, it's fixed for 2.6.4.

bye
Thorsten
phpMyFAQ Maintainer and Lead Developer
amazon.de Wishlist

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests