Projet

Général

Profil

Révision 74f6bef0

Ajouté par Assos Assos il y a plus de 10 ans

Weekly update of contrib modules

Voir les différences:

drupal7/sites/all/themes/adaptivetheme/at_core/inc/forms/at_core.submit.fonts.inc
5 5
 * Extract font data from form values, send for processing and print
6 6
 * returned data in a CSS file.
7 7
 */
8
function at_core_submit_fonts($values, $theme_name, $path) {
8 9

  
9
// $font_styles_data holds all data for the stylesheet
10
$font_styles_data = array();
10
  // $font_styles_data holds all data for the stylesheet
11
  $font_styles_data = array();
11 12

  
12
// Get the font elements array.
13
$font_elements = font_elements();
13
  // Get the font elements array.
14
  $font_elements = font_elements();
14 15

  
15
// Check if fontyourface is enabled, doing this in the loop will be expensive
16
$font_your_face_enabled = font_your_face_fonts_enabled();
16
  // Check if fontyourface is enabled, doing this in the loop will be expensive
17
  $font_your_face_enabled = font_your_face_fonts_enabled();
17 18

  
18
// Find the right font for each element
19
foreach ($font_elements as $key => $value) {
19
  // Find the right font for each element
20
  foreach ($font_elements as $key => $value) {
20 21

  
21
  // Each item in $font_elements has 3 key value pairs
22
  $element  = $value['element']  ? $value['element'] : '';  // a key to use later
23
  $selector = $value['selector'] ? $value['selector'] : ''; // the selector to use when building the CSS
24
  $setting  = $value['setting']  ? $value['setting'] : '';  // the theme setting used to retrieve the font values
22
    // Each item in $font_elements has 3 key value pairs
23
    $element  = $value['element']  ? $value['element'] : '';  // a key to use later
24
    $selector = $value['selector'] ? $value['selector'] : ''; // the selector to use when building the CSS
25
    $setting  = $value['setting']  ? $value['setting'] : '';  // the theme setting used to retrieve the font values
25 26

  
26
  // Deal with the custom CSS selectors.
27
  if ($selector == 'custom_css' && !empty($values['selectors_css'])) {
28
    $selector = filter_xss($values['selectors_css']); // sanitize user entered data
29
  }
30
  if ($selector == 'custom_css' && empty($values['selectors_css'])) {
31
    $selector = 'ruby ruby'; // Valid but highly unlikely to ever match anything
32
  }
27
    // Deal with the custom CSS selectors.
28
    if ($selector == 'custom_css' && !empty($values['selectors_css'])) {
29
      $selector = filter_xss($values['selectors_css']); // sanitize user entered data
30
    }
31
    if ($selector == 'custom_css' && empty($values['selectors_css'])) {
32
      $selector = 'ruby ruby'; // Valid but highly unlikely to ever match anything
33
    }
33 34

  
34
  // Get the font type if isset, not all font settings have a type
35
  if (isset($values[$setting . '_type'])) {
36
    $font_type = $values[$setting . '_type'];
37
  }
38
  else {
39
    $font_type = '<none>'; // this is an individual "in-content" heading
40
  }
35
    // Get the font type if isset, not all font settings have a type
36
    if (isset($values[$setting . '_type'])) {
37
      $font_type = $values[$setting . '_type'];
38
    }
39
    else {
40
      $font_type = '<none>'; // this is an individual "in-content" heading
41
    }
41 42

  
42
  // Get the font size if isset, not all font settings have size
43
  if (isset($values[$setting . '_size'])) {
44
    $font_size = $values[$setting . '_size'];
45
  }
46
  else {
47
    $font_size = '<none>'; // this is a grouped "in-content" heading or custom selectors
48
  }
43
    // Get the font size if isset, not all font settings have size
44
    if (isset($values[$setting . '_size'])) {
45
      $font_size = $values[$setting . '_size'];
46
    }
47
    else {
48
      $font_size = '<none>'; // this is a grouped "in-content" heading or custom selectors
49
    }
49 50

  
50
  // Get the font value (the font name or family) for the right font type if isset,
51
  // not all font settings have a value
52
  if (isset($values[$setting . (!empty($font_type) ? '_' . $font_type : '')])) {
53
    $font_value = $values[$setting . (!empty($font_type) ? '_' . $font_type : '')];
54
  }
51
    // Get the font value (the font name or family) for the right font type if isset,
52
    // not all font settings have a value
53
    if (isset($values[$setting . (!empty($font_type) ? '_' . $font_type : '')])) {
54
      $font_value = $values[$setting . (!empty($font_type) ? '_' . $font_type : '')];
55
    }
55 56

  
56
  // Initialize the $font_values array variables
57
  $font_values['font_family'] = '';
58
  $font_values['font_size'] = '';
59
  $font_values['font_style'] = '';
60
  $font_values['font_weight'] = '';
57
    // Initialize the $font_values array variables
58
    $font_values['font_family'] = '';
59
    $font_values['font_size'] = '';
60
    $font_values['font_style'] = '';
61
    $font_values['font_weight'] = '';
61 62

  
62
  // Some Content Headings have no type or family, we add these first,
63
  // these are the h1 to h6 settings that only have a size
64
  if ($font_type === '<none>') {
65
    $font_values['font_size'] = $font_size;
63
    // Some Content Headings have no type or family, we add these first,
64
    // these are the h1 to h6 settings that only have a size
65
    if ($font_type === '<none>') {
66
      $font_values['font_size'] = $font_size;
66 67

  
67
    // Add styles to the array for printing into the stylsheet
68
    $font_styles_data[] = at_build_font_families($element, $selector, $font_values);
69
  }
68
      // Add styles to the array for printing into the stylsheet
69
      $font_styles_data[] = at_build_font_families($element, $selector, $font_values);
70
    }
70 71

  
71
  // Websafe Fonts
72
  if ($font_type === '') {
73
    // Get a list of websafe fonts
74
    $websafe_fonts = websafe_fonts_list($element);
75
    // Loop over the websafe fonts list and get a match
76
    foreach ($websafe_fonts as $k => $v) {
77
      if ($k == $font_value) {
78
        $font_family = $v;
72
    // Websafe Fonts
73
    if ($font_type === '') {
74
      // Get a list of websafe fonts
75
      $websafe_fonts = websafe_fonts_list($element);
76
      // Loop over the websafe fonts list and get a match
77
      foreach ($websafe_fonts as $k => $v) {
78
        if ($k == $font_value) {
79
          $font_family = $v;
80
        }
79 81
      }
80
    }
81
    $font_values['font_family'] = $font_family;
82
    $font_values['font_size']   = $font_size;
82
      $font_values['font_family'] = $font_family;
83
      $font_values['font_size']   = $font_size;
83 84

  
84
    // Add styles to the array for printing into the stylsheet
85
    $font_styles_data[] = at_build_font_families($element, $selector, $font_values);
86
  }
85
      // Add styles to the array for printing into the stylsheet
86
      $font_styles_data[] = at_build_font_families($element, $selector, $font_values);
87
    }
87 88

  
88
  // Custom Font stacks (user entered data)
89
  if ($font_type === 'cfs') {
90
    $font_values['font_family'] = drupal_strip_dangerous_protocols($font_value); // sanitize user entered data
91
    $font_values['font_size']   = $font_size;
92
    // Add styles to the array for printing into the stylsheet
93
    $font_styles_data[] = at_build_font_families($element, $selector, $font_values);
94
  }
89
    // Custom Font stacks (user entered data)
90
    if ($font_type === 'cfs') {
91
      $font_values['font_family'] = drupal_strip_dangerous_protocols($font_value); // sanitize user entered data
92
      $font_values['font_size']   = $font_size;
93
      // Add styles to the array for printing into the stylsheet
94
      $font_styles_data[] = at_build_font_families($element, $selector, $font_values);
95
    }
95 96

  
96
  // Google Fonts (user entered data)
97
  if ($font_type === 'gwf') {
98
    $font_value = "'" . $font_value . "'";
99
    $font_values['font_family'] = filter_xss_admin($font_value); // sanitize user entered data
100
    $font_values['font_size']   = $font_size;
97
    // Google Fonts (user entered data)
98
    if ($font_type === 'gwf') {
99
      $font_value = "'" . $font_value . "'";
100
      $font_values['font_family'] = filter_xss_admin($font_value); // sanitize user entered data
101
      $font_values['font_size']   = $font_size;
101 102

  
102
    // Add styles to the array for printing into the stylsheet
103
    $font_styles_data[] = at_build_font_families($element, $selector, $font_values);
104
  }
103
      // Add styles to the array for printing into the stylsheet
104
      $font_styles_data[] = at_build_font_families($element, $selector, $font_values);
105
    }
105 106

  
106
  // Font Your Face
107
  if ($font_your_face_enabled === TRUE) {
108
    if ($font_type === 'fyf') {
109
      // pull the font list, we need to iterate over it
110
      $fyf_fonts = font_your_face_fonts_list($element); // this is a keyed array
111
      // loop over fyf_fonts list and get a match and retrive the font name
112
      foreach ($fyf_fonts as $k => $v) {
113
        if ($k == $font_value) {
114
          $font_value = $v;
107
    // Font Your Face
108
    if ($font_your_face_enabled === TRUE) {
109
      if ($font_type === 'fyf') {
110
        // pull the font list, we need to iterate over it
111
        $fyf_fonts = font_your_face_fonts_list($element); // this is a keyed array
112
        // loop over fyf_fonts list and get a match and retrive the font name
113
        foreach ($fyf_fonts as $k => $v) {
114
          if ($k == $font_value) {
115
            $font_value = $v;
116
          }
115 117
        }
116
      }
117
      // Get the font objects from font-your-face, we need additional data out
118
      // of each object
119
      $enabled_fonts = fontyourface_get_fonts('enabled = 1');
120
      foreach ($enabled_fonts as $font) {
121
        // we need to know if the $font_value matches a $font->name
122
        if ($font_value == $font->name) {
123
          // Now we need a buch of variables to get the font family, style and weight
124
          $font_values['font_family'] = $font->css_family ? $font->css_family : '';
125
          $font_values['font_style']  = $font->css_style  ? $font->css_style  : '';
126
          $font_values['font_weight'] = $font->css_weight ? $font->css_weight : '';
118
        // Get the font objects from font-your-face, we need additional data out
119
        // of each object
120
        $enabled_fonts = fontyourface_get_fonts('enabled = 1');
121
        foreach ($enabled_fonts as $font) {
122
          // we need to know if the $font_value matches a $font->name
123
          if ($font_value == $font->name) {
124
            // Now we need a buch of variables to get the font family, style and weight
125
            $font_values['font_family'] = $font->css_family ? $font->css_family : '';
126
            $font_values['font_style']  = $font->css_style  ? $font->css_style  : '';
127
            $font_values['font_weight'] = $font->css_weight ? $font->css_weight : '';
128
          }
127 129
        }
130
        // Load the font size
131
        $font_values['font_size'] = $font_size;
132
        // Add styles to the array for printing into the stylsheet
133
        $font_styles_data[] = at_build_font_families($element, $selector, $font_values);
128 134
      }
129
      // Load the font size
130
      $font_values['font_size'] = $font_size;
131
      // Add styles to the array for printing into the stylsheet
132
      $font_styles_data[] = at_build_font_families($element, $selector, $font_values);
133 135
    }
134 136
  }
135
}
136 137

  
137
// Output data to file
138
if (!empty($font_styles_data)) {
139
  $font_styles = implode("\n", $font_styles_data);
140
  $font_styles = preg_replace('/^[ \t]*[\r\n]+/m', '', $font_styles);
141
  $file_name = $theme_name . '.fonts.css';
142
  $filepath = "$path/$file_name";
143
  file_unmanaged_save_data($font_styles, $filepath, FILE_EXISTS_REPLACE);
138
  // Output data to file
139
  if (!empty($font_styles_data)) {
140
    $font_styles = implode("\n", $font_styles_data);
141
    $font_styles = preg_replace('/^[ \t]*[\r\n]+/m', '', $font_styles);
142
    $file_name = $theme_name . '.fonts.css';
143
    $filepath = "$path/$file_name";
144
    file_unmanaged_save_data($font_styles, $filepath, FILE_EXISTS_REPLACE);
145
  }
144 146
}

Formats disponibles : Unified diff