' . t('@fontawesome is an iconic font designed for use with Bootstrap.', array( '@fontawesome' => FONTAWESOME_NAME, '!fontawesome_url' => FONTAWESOME_URL, '!bootstrap_url' => 'http://getbootstrap.com', )) . '

'; } } /** * Implements hook_libraries_info(). */ function fontawesome_libraries_info() { $libraries[FONTAWESOME_LIBRARY] = array( 'name' => FONTAWESOME_NAME, 'vendor url' => FONTAWESOME_URL, 'download url' => FONTAWESOME_DOWNLOAD_URL, 'version arguments' => array( 'file' => 'css/font-awesome.css', 'pattern' => '/((?:\d+\.?){2,3})/', 'lines' => 10, 'cols' => 14, ), 'files' => array( 'css' => array( 'css/font-awesome.css', ), ), ); return $libraries; } /** * Implements hook_preprocess_html(). * * Purposefully only load on page requests and not hook_init(). This is * required so it does not increase the bootstrap time of Drupal when it isn't * necessary. */ function fontawesome_preprocess_html() { if (variable_get('fontawesome_use_cdn', FALSE)) { drupal_add_css(FONTAWESOME_CDN_URL, array('type' => 'external')); } else { $library = libraries_load(FONTAWESOME_LIBRARY); if (!$library['loaded']) { drupal_set_message($library['error message'] . t('Please make sure that ' . 'fontawesome was download & extracted at sites/all/libraries/fontawesome directory.' . 'Please check README.txt for more details.'), 'warning'); } } } /** * Implements hook_form_FORM_ID_alter(). * * Add a checkbox to Drupal Bandwidth optimization settings in performance page * to provide an option to load CDN version of FontAwesome. */ function fontawesome_form_system_performance_settings_alter(&$form, &$form_state, $form_id) { $form['bandwidth_optimization']['fontawesome_use_cdn'] = array( '#type' => 'checkbox', '#title' => t('Use CDN version of FontAwesome.'), '#default_value' => variable_get('fontawesome_use_cdn', FALSE), ); } /** * Implements hook_icon_providers(). */ function fontawesome_icon_providers() { $providers[FONTAWESOME_LIBRARY] = array( 'title' => FONTAWESOME_NAME, 'url' => FONTAWESOME_URL, ); return $providers; } /** * Implements hook_icon_bundle_configure(). */ function fontawesome_icon_bundle_configure(&$settings, &$form_state, &$complete_form) { $bundle = $form_state['bundle']; if ($bundle['provider'] === FONTAWESOME_LIBRARY) { $settings['tag'] = array( '#type' => 'select', '#title' => t('HTML Markup'), '#description' => t('Choose the HTML markup tag that @fontawesome icons should be created with. Typically, this is a %tag tag, however it can be changed to suite the theme requirements.', array( '@fontawesome' => FONTAWESOME_NAME, '%tag' => '<' . $bundle['settings']['tag'] . '>', )), '#options' => drupal_map_assoc(array('i', 'span', 'div')), '#default_value' => $bundle['settings']['tag'], ); } } /** * Implements hook_preprocess_icon_RENDER_HOOK(). */ function fontawesome_preprocess_icon_sprite(&$variables) { $bundle = &$variables['bundle']; if ($bundle['provider'] === FONTAWESOME_LIBRARY) { // Remove the default "icon" class. $key = array_search('icon', $variables['attributes']['class']); if ($key !== FALSE) { unset($variables['attributes']['class'][$key]); } // Add the necessary FA identifier class. $variables['attributes']['class'][] = FONTAWESOME_PREFIX; // Prepend the icon with the FA prefix (which will be used as the class). $variables['icon'] = FONTAWESOME_PREFIX . '-' . $variables['icon']; } } /** * Implements hook_icon_bundles(). */ function fontawesome_icon_bundles() { $bundles[FONTAWESOME_LIBRARY] = array( 'title' => FONTAWESOME_NAME, 'provider' => FONTAWESOME_LIBRARY, 'render' => 'sprite', 'settings' => array( 'tag' => 'i', ), 'icons' => fontawesome_extract_icons(), ); return $bundles; } /** * Extracts all icons from the CSS file. * * @return array */ function fontawesome_extract_icons() { // If CDN is enabled, get CSS content from the CDN URL if (variable_get('fontawesome_use_cdn', FALSE)) { $url = FONTAWESOME_CDN_URL; // The URL needs to have a schema to work with drupal_http_request if (strpos($url, '//') === 0) { $url = 'http:' . $url; } $request = drupal_http_request($url); $content = !empty($request->data) ? $request->data : ''; } // Otherwise get CSS content from the local library else { $library = libraries_load(FONTAWESOME_LIBRARY); $filepath = DRUPAL_ROOT . '/' . $library['library path'] . '/css/font-awesome.css'; $content = file_exists($filepath) ? file_get_contents($filepath) : ''; } // Parse the CSS content if (preg_match_all('@\.fa-([a-zA-Z0-9-]*?):before@m', $content, $matches)) { $icons = $matches[1]; asort($icons); return drupal_map_assoc($icons); } return array(); }