Projet

Général

Profil

Paste
Télécharger (5 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / views_pdf / views_pdf.module @ e9f59ce0

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
define('VIEWS_PDF_PHP', (module_exists('php')));
34

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

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

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

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

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

    
68

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

    
84

    
85

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

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

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

    
159
  return $format;
160
}
161

    
162

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

    
170

    
171

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

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

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

    
213

    
214

    
215

    
216