1738 posts How's the surf doing?
  • Power Elite Author: Sold more than $1M on Envato Market
  • Has sold $1M+ on Envato Market and is now a Power Elite Author
  • Achieved the monthly Community Superstar Award
  • Made it to the Authors' Hall of Fame
+6 more
tommusrhodus
says
https://github.com/tommusrhodus/FontAwesome-4.1.0-Class-Names

Thought this might help a few people. There’s likely duplicates in there so feel free to submit a change :)

326 posts
  • Has been part of the Envato Community for over 2 years
  • Has referred 10+ members
  • Has sold $40,000+ on Envato Market
  • Sells items exclusively on Envato Market
+1 more
subsolar
says

Oh great, thanks for sharing, this will sure come in handy!

Bookmarked!

DistinctiveThemes
DistinctiveThemes Recent Posts Threads Started
313 posts
  • Sells items exclusively on Envato Market
  • Has sold $40,000+ on Envato Market
  • Has been part of the Envato Community for over 2 years
  • Contributed a blog post
+3 more
DistinctiveThemes
says

Awesome! Thanks for sharing Tom

1618 posts
  • Made it to the Authors' Hall of Fame
  • Elite Author: Sold more than $75,000 on Envato Market
  • Has been part of the Envato Community for over 6 years
  • Has sold $500,000+ on Envato Market
+6 more
fuelthemes
says

This will come in handy :)

1356 posts
  • Has been part of the Envato Community for over 4 years
  • Has sold $40,000+ on Envato Market
  • Has been a beta tester for an Envato feature
  • Has collected 50+ items on Envato Market
+4 more
Smartik
says
Isn’t it better to update the class name with a single click and save them in DB or a static file?
/**
 * Font Awesome
 *
 * @param string $path font awesomwe css file path
 * @return array
 */
function fontAwesome($path){

    $css = file_get_contents($path);
    $pattern = '/\.(fa-(?:\w+(?:-)?)+):before\s+{\s*content:\s*"(.+)";\s+}/';

    preg_match_all($pattern, $css, $matches, PREG_SET_ORDER);

    $icons = array();
    foreach ($matches as $match) {
        $icons[$match[1]] = $match[2];
    }
    return $icons;

}

// Usage 
// -------------------------------------------------------
$icons = fontAwesome(PATH_TO_CSS . '/font-awesome/css/font-awesome.css');

// this will return an array with the following structure:
// -------------------------------------------------------
array(
...
[fa-glass] => \f000
...
);

// to replace the value with the name class:
// -------------------------------------------------------
$list_i = array();
foreach ($font as $key => $value) {
    $list_i[$key] = $key;
}
//Use it
print_r($list_i);

//To display the name class without prefix and dashes and Uppercase:
// -------------------------------------------------------

//Replace this:
$list_i[$key] = $key;

//with this
$list_i[$key] = ucfirst( str_ireplace(array('fa-', '-'), array('', ' '), $key) );

1738 posts How's the surf doing?
  • Power Elite Author: Sold more than $1M on Envato Market
  • Has sold $1M+ on Envato Market and is now a Power Elite Author
  • Achieved the monthly Community Superstar Award
  • Made it to the Authors' Hall of Fame
+6 more
tommusrhodus
says

@Smartik, honest question, why would that method be better? Not challenging at all, just looking for your insight mate :)

In my case, I pull the list of icons into my theme options and my page builder, so once an icon is chosen it’s saved into an option, or into meta. So the array is only called in certain admin situations anyway and then the value saved by itself.

1356 posts
  • Has been part of the Envato Community for over 4 years
  • Has sold $40,000+ on Envato Market
  • Has been a beta tester for an Envato feature
  • Has collected 50+ items on Envato Market
+4 more
Smartik
says

@Smartik, honest question, why would that method be better? Not challenging at all, just looking for your insight mate :) In my case, I pull the list of icons into my theme options and my page builder, so once an icon is chosen it’s saved into an option, or into meta. So the array is only called in certain admin situations anyway and then the value saved by itself.

Because you don’t have to update that list manually with every update of font awesome. In my example this will run everytime, but you can change it a bit and run it only when you want to update the list or write the array in a static file, or anything else.

It probably is not better, it is more flexible(that’s what I should say), and allow to manipulate the code in many ways. Your code is excelent for what it is intended to do, but I’ve just added another solution that allows to get the code in an easy way. :)

1738 posts How's the surf doing?
  • Power Elite Author: Sold more than $1M on Envato Market
  • Has sold $1M+ on Envato Market and is now a Power Elite Author
  • Achieved the monthly Community Superstar Award
  • Made it to the Authors' Hall of Fame
+6 more
tommusrhodus
says

Because you don’t have to update that list manually with every update of font awesome.

Exactly what I wanted to hear, makes total sense now :)

Cheers mate, that’s an awesome snippet you’ve got there, thanks so much for sharing!

4 posts
  • Sells items exclusively on Envato Market
  • Has been part of the Envato Community for over 1 year
  • Has sold $10,000+ on Envato Market
  • Has referred 1+ members
+1 more
CodeSymbol
says

Thanks for sharing.

by
by
by
by
by
by