Plugin Directory

Changeset 1370961


Ignore:
Timestamp:
03/14/2016 08:20:28 PM (10 years ago)
Author:
Dev49.net
Message:

Version 2.2.6:

  • Fixed undeclared variable notice
  • Fixed mbstring extension error
Location:
buddypress-first-letter-avatar
Files:
535 added
2 edited

Legend:

Unmodified
Added
Removed
  • buddypress-first-letter-avatar/trunk/buddypress-first-letter-avatar.php

    r1352138 r1370961  
    88 * Contributors: Dev49.net, DanielAGW
    99 * Description: Set custom avatars for BuddyPress users. The avatar will be the first (or any other) letter of the user's name on a colorful background.
    10  * Version: 2.2.5
     10 * Version: 2.2.6
    1111 * Author: Dev49.net
    1212 * Author URI: http://dev49.net
    1313 * Tags: avatars, comments, buddypress, custom avatar, discussion, change avatar, avatar, custom wordpress avatar, first letter avatar, comment change avatar, wordpress new avatar, avatar, initial avatar
    14  * Requires at least: 4.0
     14 * Requires at least: 4.4
    1515 * Tested up to: 4.4.2
    1616 * Stable tag: trunk
     
    473473
    474474        // get picture filename (and lowercase it) from commenter name:
    475         if (empty($name)){  // if, for some reason, the result is empty, set file_name to default unknown image
     475        if (empty($name)){  // if, for some reason, the name is empty, set file_name to default unknown image
     476
    476477            $file_name = $this->image_unknown;
    477         } else {
     478
     479        } else { // name is not empty, so we can proceed
     480
    478481            $file_name = substr($name, $this->letter_index, 1); // get one letter counting from letter_index
    479482            $file_name = strtolower($file_name); // lowercase it...
    480             $file_name_mb = mb_substr($name, $this->letter_index, 1); // repeat, this time with multibyte functions
    481             $file_name_mb = mb_strtolower($file_name_mb); // and again...
    482         }
    483 
    484         // couple of exceptions:
    485         if ($file_name_mb == 'ą'){
    486             $file_name = 'a';
    487             $file_name_mb = 'a';
    488         } else if ($file_name_mb == 'ć'){
    489             $file_name = 'c';
    490             $file_name_mb = 'c';
    491         } else if ($file_name_mb == 'ę'){
    492             $file_name = 'e';
    493             $file_name_mb = 'e';
    494         } else if ($file_name_mb == 'ń'){
    495             $file_name = 'n';
    496             $file_name_mb = 'n';
    497         } else if ($file_name_mb == 'ó'){
    498             $file_name = 'o';
    499             $file_name_mb = 'o';
    500         } else if ($file_name_mb == 'ś'){
    501             $file_name = 's';
    502             $file_name_mb = 's';
    503         } else if ($file_name_mb == 'ż' || $file_name_mb == 'ź'){
    504             $file_name = 'z';
    505             $file_name_mb = 'z';
    506         }
    507 
    508         // create arrays with allowed character ranges:
    509         $allowed_numbers = range(0, 9);
    510         foreach ($allowed_numbers as $number){ // cast each item to string (strict param of in_array requires same type)
    511             $allowed_numbers[$number] = (string)$number;
    512         }
    513         $allowed_letters_latin = range('a', 'z');
    514         $allowed_letters_cyrillic = range('а', 'ё');
    515         $allowed_letters_arabic = range('آ', 'ی');
    516         // check if the file name meets the requirement; if it doesn't - set it to unknown
    517         $charset_flag = ''; // this will be used to determine whether we are using latin chars, cyrillic chars, arabic chars or numbers
    518         // check whther we are using latin/cyrillic/numbers and set the flag, so we can later act appropriately:
    519         if (in_array($file_name, $allowed_numbers, true)){
    520             $charset_flag = 'number';
    521         } else if (in_array($file_name, $allowed_letters_latin, true)){
    522             $charset_flag = 'latin';
    523         } else if (in_array($file_name, $allowed_letters_cyrillic, true)){
    524             $charset_flag = 'cyrillic';
    525         } else if (in_array($file_name, $allowed_letters_arabic, true)){
    526             $charset_flag = 'arabic';
    527         } else { // for some reason none of the charsets is appropriate
    528             $file_name = $this->image_unknown; // set it to uknknown
    529         }
    530 
    531         if (!empty($charset_flag)){ // if charset_flag is not empty, i.e. flag has been set to latin, number or cyrillic...
    532             switch ($charset_flag){ // run through various options to determine the actual filename for the letter avatar
    533                 case 'number':
    534                     $file_name = 'number_' . $file_name;
    535                     break;
    536                 case 'latin':
    537                     $file_name = 'latin_' . $file_name;
    538                     break;
    539                 case 'cyrillic':
    540                     $temp_array = unpack('V', iconv('UTF-8', 'UCS-4LE', $file_name_mb)); // beautiful one-liner by @bobince from SO - http://stackoverflow.com/a/27444149/4848918
    541                     $unicode_code_point = $temp_array[1];
    542                     $file_name = 'cyrillic_' . $unicode_code_point;
    543                     break;
    544                 case 'arabic':
    545                     $temp_array = unpack('V', iconv('UTF-8', 'UCS-4LE', $file_name_mb));
    546                     $unicode_code_point = $temp_array[1];
    547                     $file_name = 'arabic_' . $unicode_code_point;
    548                     break;
    549                 default:
    550                     $file_name = $this->image_unknown; // set it to uknknown
    551                     break;
    552             }
     483
     484            if (extension_loaded('mbstring')){ // check if mbstring is loaded to allow multibyte string operations
     485                $file_name_mb = mb_substr($name, $this->letter_index, 1); // repeat, this time with multibyte functions
     486                $file_name_mb = mb_strtolower($file_name_mb); // and again...
     487            } else { // mbstring is not loaded - we're not going to worry about it, just use the original string
     488                $file_name_mb = $file_name;
     489            }
     490
     491            // couple of exceptions:
     492            if ($file_name_mb == 'ą'){
     493                $file_name = 'a';
     494                $file_name_mb = 'a';
     495            } else if ($file_name_mb == 'ć'){
     496                $file_name = 'c';
     497                $file_name_mb = 'c';
     498            } else if ($file_name_mb == 'ę'){
     499                $file_name = 'e';
     500                $file_name_mb = 'e';
     501            } else if ($file_name_mb == 'ń'){
     502                $file_name = 'n';
     503                $file_name_mb = 'n';
     504            } else if ($file_name_mb == 'ó'){
     505                $file_name = 'o';
     506                $file_name_mb = 'o';
     507            } else if ($file_name_mb == 'ś'){
     508                $file_name = 's';
     509                $file_name_mb = 's';
     510            } else if ($file_name_mb == 'ż' || $file_name_mb == 'ź'){
     511                $file_name = 'z';
     512                $file_name_mb = 'z';
     513            }
     514
     515            // create arrays with allowed character ranges:
     516            $allowed_numbers = range(0, 9);
     517            foreach ($allowed_numbers as $number){ // cast each item to string (strict param of in_array requires same type)
     518                $allowed_numbers[$number] = (string)$number;
     519            }
     520            $allowed_letters_latin = range('a', 'z');
     521            $allowed_letters_cyrillic = range('а', 'ё');
     522            $allowed_letters_arabic = range('آ', 'ی');
     523            // check if the file name meets the requirement; if it doesn't - set it to unknown
     524            $charset_flag = ''; // this will be used to determine whether we are using latin chars, cyrillic chars, arabic chars or numbers
     525            // check whther we are using latin/cyrillic/numbers and set the flag, so we can later act appropriately:
     526            if (in_array($file_name, $allowed_numbers, true)){
     527                $charset_flag = 'number';
     528            } else if (in_array($file_name, $allowed_letters_latin, true)){
     529                $charset_flag = 'latin';
     530            } else if (in_array($file_name, $allowed_letters_cyrillic, true)){
     531                $charset_flag = 'cyrillic';
     532            } else if (in_array($file_name, $allowed_letters_arabic, true)){
     533                $charset_flag = 'arabic';
     534            } else { // for some reason none of the charsets is appropriate
     535                $file_name = $this->image_unknown; // set it to uknknown
     536            }
     537
     538            if (!empty($charset_flag)){ // if charset_flag is not empty, i.e. flag has been set to latin, number or cyrillic...
     539                switch ($charset_flag){ // run through various options to determine the actual filename for the letter avatar
     540                    case 'number':
     541                        $file_name = 'number_' . $file_name;
     542                        break;
     543                    case 'latin':
     544                        $file_name = 'latin_' . $file_name;
     545                        break;
     546                    case 'cyrillic':
     547                        $temp_array = unpack('V', iconv('UTF-8', 'UCS-4LE', $file_name_mb)); // beautiful one-liner by @bobince from SO - http://stackoverflow.com/a/27444149/4848918
     548                        $unicode_code_point = $temp_array[1];
     549                        $file_name = 'cyrillic_' . $unicode_code_point;
     550                        break;
     551                    case 'arabic':
     552                        $temp_array = unpack('V', iconv('UTF-8', 'UCS-4LE', $file_name_mb));
     553                        $unicode_code_point = $temp_array[1];
     554                        $file_name = 'arabic_' . $unicode_code_point;
     555                        break;
     556                    default:
     557                        $file_name = $this->image_unknown; // set it to uknknown
     558                        break;
     559                }
     560            }
     561
    553562        }
    554563
     
    560569        else $custom_avatar_size = '512';
    561570
    562         // create file path - avatar_uri variable will look something like this:
     571        // create file path - $avatar_uri variable will look something like this:
    563572        // http://yourblog.com/wp-content/plugins/buddypress-first-letter-avatar/images/default/96/k.png):
    564573        $avatar_uri =
  • buddypress-first-letter-avatar/trunk/readme.txt

    r1352138 r1370961  
    11=== BuddyPress First Letter Avatar ===
    22Plugin Name: BuddyPress First Letter Avatar
    3 Version: 2.2.5
     3Version: 2.2.6
    44Plugin URI: http://dev49.net
    55Contributors: Dev49.net, DanielAGW
    66Tags: avatars, comments, buddypress, custom avatar, discussion, change avatar, avatar, custom wordpress avatar, first letter avatar, comment change avatar, wordpress new avatar, avatar, initial avatar
    7 Requires at least: 4.0
     7Requires at least: 4.4
    88Tested up to: 4.4.2
    99Stable tag: trunk
     
    8282
    8383== Changelog ==
     84
     85= 2.2.6 =
     86* Fixed undeclared variable notice
     87* Fixed mbstring extension error
    8488
    8589= 2.2.5 =
     
    159163== Upgrade Notice ==
    160164
     165= 2.2.6 =
     166Fixed minor issues, updated recommended.
     167
    161168= 2.2.5 =
    162169Fixed problem with bbPress and possibly other plugins - update recommended.
Note: See TracChangeset for help on using the changeset viewer.