Projet

Général

Profil

Paste
Télécharger (4,95 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / views_pdf / views_pdf.module @ 87dbc3bf

1
<?php
2
/**
3
 * @file
4
 * PDF Views allows the creation of PDF's directly from a view. Without the
5
 * creation of HTML first.
6
 */
7

    
8
/**
9
 * Implements hook_views_api().
10
 */
11
function views_pdf_views_api() {
12
  return array(
13
    'api' => 3,
14
  );
15
}
16

    
17
/**
18
 * Implements hook_theme().
19
 */
20
function views_pdf_theme() {
21
  return array(
22
    'views_pdf_plugin_style_table' => array(
23
      'render element' => 'form',
24
      'file' => 'views_pdf.admin.inc',
25
    ),
26
    'views_pdf_icon' => array(
27
      'render element' => 'form',
28
      'variables' => array('url' => NULL, 'title' => NULL),
29
    ),
30
  );
31
}
32

    
33
/**
34
 * This method can be used to load the PDF library class.
35
 */
36
function views_pdf_get_new_pdf_instance($orientation = 'P', $unit = 'mm', $format = 'A4', $unicode = TRUE, $encoding = 'UTF-8', $diskcache = FALSE) {
37
  _views_pdf_include_pdf_lib();
38
  return new PdfTemplate($orientation, $unit, $format, $unicode, $encoding, $diskcache);
39
}
40

    
41
/**
42
 * Theme function for the PDF icon of appended PDFs.
43
 */
44
function theme_views_pdf_icon($vars) {
45
  $title = $vars['title'];
46
  $path = $vars['path'];
47
  $options = $vars['options'];
48
  $options['html'] = TRUE;
49
  $options['attributes']['class'] = 'pdf-icon';
50

    
51
  $imagePath = drupal_get_path('module', 'views_pdf') . '/images/pdf.png';
52

    
53
  if ($image = theme('image', array('path' => $imagePath, 'title' => $title, 'alt' => $title))) {
54
    return l($image, $path, $options);
55
  }
56
}
57

    
58
/**
59
 * This method can be used to get all available fonts.
60
 */
61
function views_pdf_get_font_list() {
62
  _views_pdf_include_pdf_lib();
63
  return PdfTemplate::getAvailableFontsCleanList();
64
}
65

    
66

    
67
/**
68
 * This function returns the path to a given library.
69
 *
70
 * @param $name Name of the Library
71
 *
72
 */
73
function views_pdf_get_library($name) {
74
    if (function_exists('libraries_get_path')) {
75
      return libraries_get_path($name);
76
    }
77
    else {
78
      return 'sites/all/libraries/' . $name;
79
    }
80
}
81

    
82

    
83

    
84
/**
85
 * This method can be used to get all available templates.
86
 */
87
function views_pdf_get_pdf_templates() {
88
  _views_pdf_include_pdf_lib();
89
  return PdfTemplate::getAvailableTemplates();
90
}
91

    
92
/**
93
 * This method returns all available hyphenation
94
 * patterns (paths to files).
95
 */
96
function views_pdf_get_hyphenations() {
97
  _views_pdf_include_pdf_lib();
98
  return PdfTemplate::getAvailableHyphenatePatterns();
99
}
100

    
101
/**
102
 * This method can be used to return a list of posible page formats.
103
 */
104
function views_pdf_get_page_formats() {
105
  $format['custom'] = t('Custom');
106
  $format['4A0'] = '4A0';
107
  $format['2A0'] = '2A0';
108
  $format['A0'] = 'A0';
109
  $format['A1'] = 'A1';
110
  $format['A2'] = 'A2';
111
  $format['A3'] = 'A3';
112
  $format['A4'] = 'A4';
113
  $format['A5'] = 'A5';
114
  $format['A6'] = 'A6';
115
  $format['A7'] = 'A7';
116
  $format['A8'] = 'A8';
117
  $format['A9'] = 'A9';
118
  $format['A10'] = 'A10';
119
  $format['B0'] = 'B0';
120
  $format['B1'] = 'B1';
121
  $format['B2'] = 'B2';
122
  $format['B3'] = 'B3';
123
  $format['B4'] = 'B4';
124
  $format['B5'] = 'B5';
125
  $format['B6'] = 'B6';
126
  $format['B7'] = 'B7';
127
  $format['B8'] = 'B8';
128
  $format['B9'] = 'B9';
129
  $format['B10'] = 'B10';
130
  $format['C0'] = 'C0';
131
  $format['C1'] = 'C1';
132
  $format['C2'] = 'C2';
133
  $format['C3'] = 'C3';
134
  $format['C4'] = 'C4';
135
  $format['C5'] = 'C5';
136
  $format['C6'] = 'C6';
137
  $format['C7'] = 'C7';
138
  $format['C8'] = 'C8';
139
  $format['C9'] = 'C9';
140
  $format['C10'] = 'C10';
141
  $format['RA0'] = 'RA0';
142
  $format['RA1'] = 'RA1';
143
  $format['RA2'] = 'RA2';
144
  $format['RA3'] = 'RA3';
145
  $format['RA4'] = 'RA4';
146
  $format['SRA0'] = 'SRA0';
147
  $format['SRA1'] = 'SRA1';
148
  $format['SRA2'] = 'SRA2';
149
  $format['SRA3'] = 'SRA3';
150
  $format['SRA4'] = 'SRA4';
151
  $format['LETTER'] = 'LETTER';
152
  $format['LEGAL'] = 'LEGAL';
153
  $format['EXECUTIVE'] = 'EXECUTIVE';
154
  $format['FOLIO'] = 'FOLIO';
155
  $format['MEMO'] = 'MEMO';
156

    
157
  return $format;
158
}
159

    
160

    
161
/**
162
 * Get the PDF class.
163
 */
164
function _views_pdf_include_pdf_lib() {
165
  module_load_include('php', 'views_pdf', 'views_pdf_template');
166
}
167

    
168

    
169

    
170
/**
171
 * For backward compatibilty (< 5.3) we implemented
172
 * this function by our self. If we are in a newer
173
 * environment, then this is obsolete.
174
 *
175
 */
176
if (!function_exists('array_replace_recursive')) {
177
  function array_replace_recursive($array, $array1) {
178
    if (!function_exists('recurse')) {
179
      function recurse($array, $array1) {
180
        foreach ($array1 as $key => $value) {
181
          // Create new key in $array, if it is empty or not an array.
182
          if (!isset($array[$key]) || (isset($array[$key]) && !is_array($array[$key]))) {
183
            $array[$key] = array();
184
          }
185

    
186
          // Overwrite the value in the base array.
187
          if (is_array($value)) {
188
            $value = recurse($array[$key], $value);
189
          }
190
          $array[$key] = $value;
191
        }
192
        return $array;
193
      }
194

    
195
      // Handle the arguments, merge one by one.
196
      $args = func_get_args();
197
      $array = $args[0];
198
      if (!is_array($array)) {
199
        return $array;
200
      }
201
      for ($i = 1; $i < count($args); $i++) {
202
        if (is_array($args[$i])) {
203
          $array = recurse($array, $args[$i]);
204
        }
205
      }
206
      return $array;
207
    }
208
  }
209
}
210

    
211

    
212

    
213

    
214