forked from GetDKAN/recline
-
Notifications
You must be signed in to change notification settings - Fork 1
/
recline.theme.inc
745 lines (683 loc) · 23.5 KB
/
recline.theme.inc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
<?php
/**
* @file
* Recline theme functions.
*/
/**
* File size limit for remote zip files preview.
*
* This is an arbitrary number 600000 = 600kb
* If you need to increase this consider that
* could slow down preview pages loading.
*/
define('MAX_SIZE_PREVIEW_ZIP', 600000);
/**
* Timeout limit for HEAD HTTP requests.
*/
define('RECLINE_REQUEST_TIMEOUT_HEAD', 2);
/**
* Timeout limit for GET HTTP requests.
*/
define('RECLINE_REQUEST_TIMEOUT_GET', 10);
/**
* Returns HTML for an recline field formatter.
*
* @param array $vars
* An associative array containing:
* - item: Associative array of recline field.
*
* @ingroup themeable
*/
function theme_recline_default_formatter($vars) {
$type = null;
$api = FALSE;
// Embedded view doesn't use html.tpl.php template
// so we need to add bootstrap by hand.
if (recline_embedded()) {
$recline_path = libraries_get_path('recline');
drupal_add_js($recline_path . '/vendor/bootstrap/3.2.0/js/bootstrap.js');
drupal_add_css($recline_path . '/vendor/bootstrap/3.2.0/css/bootstrap.css');
}
if (isset($vars['item']['entity']->field_format['und'][0]['tid'])) {
$format = taxonomy_term_load($vars['item']['entity']->field_format['und'][0]['tid']);
$type = $format->name;
}
$default_file = array(
'filemime' => $type,
'filesize' => '',
'filename' => '',
'description' => '',
);
$file = isset($vars['item']['fid']) ? file_load($vars['item']['fid']) : $default_file;
if (is_object($file)) {
$file = (array) $file;
}
if (isset($vars['item']['url'])) {
$api = TRUE;
$url = $vars['item']['url'];
}
elseif (isset($vars['item']['uri'])) {
$url = file_create_url($vars['item']['uri']);
}
elseif (isset($vars['item']['fid'])) {
$url = file_create_url($file['uri']);
}
$file['filename'] = isset($file['filename']) ? $file['filename'] : $url;
$description = isset($file['description']) ? $file['description'] : '';
$output = recline_build_icon($url, $type, $file['filename'], $file['filemime'], $file['filesize'], $description);
//If is a API then return without preview.
if ($api) {
// $output['preview'] = recline_format_link_api($url);
// return drupal_render($output);
//dont know why the two lines of codes above cannot render external resources.
recline_preview_json($url);
}
if (!$type) {
$request = drupal_http_request($url, array('timeout' => RECLINE_REQUEST_TIMEOUT_HEAD, 'method' => 'HEAD'));
// When request fail.
if ($request->code != 200) {
// When a request fail because anything but a 405 (method not allowed)
// or a 400 (bad request) then display a preview unavailable message.
// The 405 error could happen when request something with the HEAD method.
// The HEAD method it's useful when you want to get the remote file
// headers without transfer anything.
if ($request->code != 405 && $request->code != 400) {
$output['preview'] = recline_preview_unavailable();
return drupal_render($output);
}
else {
// If request fail b/c either a 405 or 400 error then we perform
// a new request using GET but setting a timeout to 10 to avoid
// this request get blocked because a big file download.
$request = drupal_http_request($url, array('timeout' => RECLINE_REQUEST_TIMEOUT_GET));
if ($request->code != 200) {
$output['preview'] = recline_preview_unavailable();
return drupal_render($output);
}
}
}
}
// Displaying previews breaks solr indexing.
// @TODO: Create a new display mode from search indexing and remove.
if (isset($vars['item']['entity']->search_api_language)) {
$output['preview'] = recline_preview_unavailable();
return drupal_render($output);
}
switch ($type) {
case 'json':
$output['preview'] = recline_preview_json($url);
break;
case 'csv':
case 'txt':
case 'tsv':
case 'xls':
$output['preview'] = recline_preview_multiview($vars);
break;
case 'geojson':
$output['preview'] = recline_preview_geojson_leaflet($url);
break;
case 'zip':
$filename = FALSE;
if (substr($vars['item']['uri'], 0, 4) != 'http') {
$filename = $vars['item']['uri'];
}
else {
// Make sure we have the information about the remote file.
if (!isset($request)) {
// TODO we probably want to improve this by using the
// GetRemoteFileInfo helper class from dkan_dataset module.
$request = drupal_http_request($url, array('timeout' => RECLINE_REQUEST_TIMEOUT_HEAD, 'method' => 'HEAD'));
}
// Make sure that the request was successful and the target zip file
// does not excced the maximum allowed for previews.
if (isset($request->headers['content-length'])
&& $request->headers['content-length'] < MAX_SIZE_PREVIEW_ZIP) {
$ch = curl_init($url);
$filename = file_directory_temp() . "/tmp-" . rand(100000, 999999) . ".zip";
$fp = fopen($filename, "w");
$ch = curl_init($url);
$filename = file_directory_temp() . '/tmp-' . rand(100000, 999999) . '.zip';
$fp = fopen($filename, 'w');
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_exec($ch);
curl_close($ch);
fclose($fp);
}
}
// If a suitable file is found then passe it threw the preview function,
// else default to unavaiable.
if ($filename) {
$output['preview'] = recline_preview_zip($filename);
}
else {
$output['preview'] = recline_preview_unavailable();
}
break;
case 'html':
if (is_youtube($url)){
$url = convertYoutube($url);
}
$output['preview'] = recline_format_link_api($url);
break;
case 'png':
case 'gif':
case 'jpg':
$output['preview'] = recline_format_image($url);
break;
case 'jpeg':
$output['preview'] = recline_format_image($url);
break;
case 'arcgis':
$output['preview'] = recline_preview_arcgis_feature($url);
break;
case 'rdf':
case 'xml':
$output['preview'] = recline_prettify_xml($url);
break;
case 'pdf':
$output['preview'] = recline_format_link_api($url);
break;
case 'wms':
// We can accept just the bare endpoint or the XML preview.
$parsed = parse_url($url);
$wms_url = $parsed['scheme'] . '://' . $parsed['host'] . $parsed['path'];
// We need the xml preview to get the correct layers.
$service_url = $wms_url . '?request=GetCapabilities&service=WMS';
// If the initial request was sent without the correct endpoint.
if (!isset($request->data) || empty($request->data) || preg_match('/The request not allowed/', $request->data)) {
$request = drupal_http_request($service_url, array('timeout' => RECLINE_REQUEST_TIMEOUT_GET));
}
if ($request->code != 200) {
$output['preview'] = recline_preview_unavailable();
}
try {
$xml = new SimpleXMLElement($request->data);
$titles = array();
$images = array();
if (isset($xml->Capability->Layer->EX_GeographicBoundingBox)) {
$north = "{$xml->Capability->Layer->EX_GeographicBoundingBox->northBoundLatitude}";
$south = "{$xml->Capability->Layer->EX_GeographicBoundingBox->southBoundLatitude}";
$east = "{$xml->Capability->Layer->EX_GeographicBoundingBox->eastBoundLongitude}";
$west = "{$xml->Capability->Layer->EX_GeographicBoundingBox->westBoundLongitude}";
}
else {
$north = variable_get("recline_wms_north_bound", "51.2");
$south = variable_get("recline_wms_south_bound", "29.2");
$east = variable_get("recline_wms_south_bound", "-73.2");
$west = variable_get("recline_wms_south_bound", "-125.5");
}
foreach ($xml->Capability->Layer->Layer as $layer) {
$titles[] = "{$layer->Title}";
if (isset($layer->Style->LegendURL->OnlineResource)) {
$images["{$layer->Title}"] = "{$layer->Style->LegendURL->OnlineResource->attributes('xlink', TRUE)->href}";
}
}
$output['preview'] = recline_preview_wms($wms_url, $titles, $images, $north, $east, $south, $west);
}
catch (Exception $e) {
$output['preview'] = recline_preview_unavailable();
}
break;
default:
$output[] = recline_preview_unavailable();
}
return drupal_render($output);
}
/**
* Previews WMS link.
*/
function recline_preview_wms($url, $titles, $images, $north, $east, $south, $west) {
$items = array();
foreach ($titles as $title) {
if (isset($images[$title])) {
$title = t('<img src="@image" alt="@title legend item"/> @title', array('@title' => $title, '@image' => $images[$title]));
}
$items[] = array(
'data' => $title,
);
}
$output = "var map = L.map('map', {
zoom: 7
});";
drupal_add_js('https://cdn.jsdelivr.net/leaflet/1.0.2/leaflet.js', 'external');
drupal_add_css('https://cdn.jsdelivr.net/leaflet/1.0.2/leaflet.css', 'external');
$output .= "var url = '" . $url . "';";
$output .= "L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png').addTo(map);";
$output .= "var layers = ['" . implode(",", $titles) . "'];";
$output .= "var tiles = L.tileLayer.wms(url, {
layers: layers,
format: 'image/png',
transparent: true,
}).addTo(map);map.fitBounds([['" . $south . "','" . $west . "'],['" . $north . "','" . $east . "']]);";
drupal_add_js($output, array(
'type' => 'inline',
'scope' => 'footer',
'weight' => 5,
));
return array(
'#type' => 'markup',
'#markup' => '<div id="map" style="width: 100%; height: 500px"></div>' . theme('item_list', array(
'items' => $items,
'title' => t("Legend"),
'attributes' => array(
'class' => 'list-inline',
),
)),
);
}
/**
* Formats image.
*/
function recline_format_image($url) {
return array(
'#type' => 'markup',
'#markup' => '<div id="recline-image-preview"><img src="' . $url . '" alt="image preview"/></div>',
);
}
/**
* Builds output for a link of an api.
*/
function recline_format_link_api($url) {
return array(
'iframe' => array(
'#type' => 'html_tag',
'#tag' => 'iframe',
'#attributes' => array(
'src' => $url,
'height' => 600,
'width' => 900,
'style' => '',
),
'#value' => '',
),
);
}
/**
* Provide unavaiable status message.
*/
function recline_preview_unavailable() {
return array(
'#type' => 'markup',
'#markup' => t('Data preview unavailable.'),
'#prefix' => '<div class="messages status">',
'#suffix' => '</div>',
);
}
/**
* Prettify json.
*/
function recline_preview_json($url) {
$parsed_external_url = parse_external_url($url);
if ($parsed_external_url['class'] == 'internal-link'){
$parsed_url = parse_url($url);
$replaced = str_replace('%20', ' ', $parsed_url);
$explode_url = explode('/', $replaced['path']);
$files = file_load_multiple([], ['uri' => 'private://' . $explode_url[3]]);
$fid = reset($files)->fid;
$f = file_load($fid);
$data = file_get_contents($f->uri);
}else{
$response = drupal_http_request($url, array('timeout' => RECLINE_REQUEST_TIMEOUT_GET));
if ($response->code == '200') {
$data = $response->data;
if (is_html($data)) {
$output['preview'] = recline_format_link_api($url);
return drupal_render($output);
}
}
else {
return recline_preview_unavailable();
}
}
$decoded = drupal_json_decode($data);
// When a json is a geojson file then return a geojson preview
// instead of a normal json preview.
$types = array(
'FeatureCollection',
'GeometryCollection',
'Feature',
'Point',
'MultiPoint',
'LineString',
'MultiLineString',
'Polygon',
'MultiPolygon',
);
foreach ($types as $type) {
foreach ($decoded as $key => $value) {
if ($type === $value) {
return recline_preview_geojson_leaflet($url);
}
}
}
libraries_load('jsonview');
drupal_add_js(array('recline' => array('data' => $data)), 'setting');
drupal_add_js(drupal_get_path('module', 'recline') . '/js/jsondataview.js');
$json = array(
'toggle_btn' => array(
'#type' => 'markup',
'#markup' => '<a id="toggle-btn" class="embed-link">Toggle view</a>',
),
'data_json' => array(
'#type' => 'markup',
'#markup' => '<div id="recline-data-json"></div>',
),
);
return $json;
}
/**
* Prettify xml.
*/
function recline_prettify_xml($url) {
$response = drupal_http_request($url, array('timeout' => RECLINE_REQUEST_TIMEOUT_GET));
if ($response->code == '200') {
$data = recline_replace_lt_gt($response->data);
}
else {
return recline_preview_unavailable();
}
drupal_add_library('recline', 'highlight');
drupal_add_js('jQuery(document).ready(function () {hljs.initHighlightingOnLoad();});', 'inline');
$xml = array(
'data_xml' => array(
'#type' => 'markup',
'#markup' => '<div id="recline-xml-preview"><pre><code class="hljs xml">' . $data . '</code></pre></div>',
),
);
return $xml;
}
/**
* Replace angle brackets.
*/
function recline_replace_lt_gt($data) {
$replaced = preg_replace('/</', '<', $data);
return preg_replace('/>/', '>', $replaced);
}
/**
* Preview for arcgis and rest data.
*/
function recline_preview_arcgis_feature($url) {
drupal_add_js('https://cdn.jsdelivr.net/leaflet/1.0.2/leaflet.js', 'external');
drupal_add_js('https:////cdn.jsdelivr.net/leaflet.esri/2.0.0/esri-leaflet.js', 'external');
drupal_add_css('https://cdn.jsdelivr.net/leaflet/1.0.2/leaflet.css', 'external');
drupal_add_css('body { margin:0; padding:0; } #rest-map { position: relative; height: 500px; width: 100%;}', 'inline');
$lat = variable_get('recline_default_lat', "38");
$lon = variable_get('recline_default_lon', "-99");
$module_path = drupal_get_path('module', 'recline');
drupal_add_js(array(
'recline' => array(
'url' => $url,
'lat' => $lat,
'lon' => $lon,
)
),'setting');
drupal_add_js($module_path . '/restdataview.js');
$output = array(
'map' => array(
'#type' => 'markup',
'#markup' => '<div><div id="rest-map"></div></div>',
),
);
return $output;
}
/**
* Returns output for a geojson file using leaflet library.
*/
function recline_preview_geojson_leaflet($url) {
$parsed_external_url = parse_external_url($url);
if ($parsed_external_url['class'] == 'internal-link'){
$parsed_url = parse_url($url);
$replaced = str_replace('%20', ' ', $parsed_url);
$explode_url = explode('/', $replaced['path']);
$files = file_load_multiple([], ['uri' => 'private://' . $explode_url[3]]);
$fid = reset($files)->fid;
$f = file_load($fid);
$geojson = file_get_contents($f->uri);
}else{
$response = drupal_http_request($url);
if ($response->code == '200') {
$geojson = $response->data;
}
else {
return;
}
}
libraries_load('leaflet_markercluster');
$leaflet_imgs = libraries_get_path('recline') . '/vendor/leaflet/1.0.2/images/';
drupal_add_js('L.Icon.Default.imagePath = "/' . $leaflet_imgs . '"', 'inline');
drupal_add_library('leaflet_widget', 'leaflet');
$output = "var dataExtent = " . $geojson;
$output .= "; var map = L.map('map');
L.tileLayer('//{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: 'Map data © <a href=\"http://openstreetmap.org\">OpenStreetMap</a>'
}).addTo(map);
var markers = new L.markerClusterGroup();
var geojson = L.geoJson(dataExtent);
markers.addLayer(geojson);
map.addLayer(markers);
map.fitBounds(geojson.getBounds());";
drupal_add_js($output, array(
'type' => 'inline',
'scope' => 'footer',
'weight' => 5,
));
return array(
'map' => array(
'#type' => 'markup',
'#markup' => '<div id="map" style="height:450px; width:100%"></div>',
),
);
}
/**
* Builds output render array for files if item is an archive.
*/
function recline_preview_zip($uri) {
// List files if item is an archive.
try {
$archiver = archiver_get_archiver($uri);
}
catch (Exception $e) {
return recline_preview_unavailable();
}
if ($archiver) {
$module_path = drupal_get_path('module', 'recline');
drupal_add_css($module_path . '/recline.css');
$output['ziplist'] = array(
'#theme' => 'item_list',
'#prefix' => '<div id="recline-zip-list">',
'#suffix' => '</div>',
'#title' => t('%number files in this archive', array('%number' => count($archiver->listContents()))),
'#items' => $archiver->listContents(),
);
}
elseif ($format == 'zip') {
$archivers_available = implode(', ', array_keys(archiver_get_info()));
drupal_set_message(t('Unable to provide file listing for zip format on this system. Available archiver formats are: %s',
array('%s' => $archivers_available)));
}
return $output;
}
/**
* Builds icon for resource view.
*/
function recline_build_icon($url, $format, $filename, $filemime, $filesize, $description) {
// Set options as per anchor format described at
// http://microformats.org/wiki/file-format-examples
$options = array(
'attributes' => array(
'type' => $filemime . '; length=' . $filesize,
'data-format' => $format,
'class' => array('format-label'),
'title' => check_plain($filename),
),
);
$file = l($filename, $url, $options);
return array(
'download' => array(
'#type' => 'markup',
'#markup' => '<div class="download">' . $file . '</div>',
),
);
}
/**
* Builds output render array for csv files.
*/
function recline_preview_multiview($variables) {
$output = array();
$datastoreStatus = $table = FALSE;
$module_path = drupal_get_path('module', 'recline');
$item = $variables['item'];
// Check problem loading file.
if (!isset($item['uri']) && $item['fid']) {
$file = file_load($item['fid']);
$file = (array) $file;
$item = array_replace($item, $file);
}
$node = $item['entity'];
$embed_markup = theme('recline_embed_button', array('node' => $node));
// See if datastore is loaded, if so, prepare recline to view from it.
if (module_exists('dkan_datastore_api') && module_exists('feeds_flatstore_processor') && function_exists('dkan_datastore_api_get_feeds_source')) {
$source_id = dkan_datastore_api_get_feeds_source($node->nid);
if ($table = feeds_flatstore_processor_table_name($source_id, $node->nid)) {
if (db_table_exists($table)) {
$datastoreStatus = $table;
}
}
}
// Load all the required libraries.
libraries_load('lodash');
libraries_load('backbone');
$recline = libraries_load('recline');
libraries_load('csv');
libraries_load('jsxlsx');
libraries_load('xls');
libraries_load('mustache');
libraries_load('moment');
libraries_load('slickgrid');
libraries_load('leaflet');
libraries_load('flot');
libraries_load('deep_diff');
libraries_load('recline_deeplink');
libraries_load('leaflet_markercluster');
drupal_add_library('system', 'ui.sortable');
drupal_add_js($module_path . '/backend.ckan_get.js');
drupal_add_js($module_path . '/recline.js');
drupal_add_css($module_path . '/recline.css');
$is_remote = !empty($node->field_link_remote_file);
$is_uploaded = !empty($node->field_upload);
$show_all = $is_uploaded && empty($item['map']) && empty($item['grid']) && empty($item['graph']);
if ($show_all || $is_remote || !empty($item['map']) || !empty($item['grid']) || !empty($item['graph']) || !empty($item['embed'])) {
$uuid = isset($node->uuid) ? $node->uuid : FALSE;
$file_path = isset($item['uri']) ? file_create_url($item['uri']) : '';
$delimiter = isset($item['delimiter']) ? $item['delimiter'] : ',';
$real_path = drupal_realpath($item['uri']);
$grid = !$is_remote && !$show_all ? (int) $item['grid'] : 1;
$graph = !$is_remote && !$show_all ? (int) $item['graph'] : 1;
$map = !$is_remote && !$show_all ? (int) $item['map'] : 1;
$embed = !empty($item['embed']) ? (int) $item['embed'] : 0;
if (pathinfo($item['uri'], PATHINFO_EXTENSION) === 'tab') {
$item['filemime'] = 'text/tab-separated-values';
}
$settings['recline'] = array(
'file' => $file_path,
'fileType' => $item['filemime'],
'fileSize' => (file_exists($real_path)) ? filesize($real_path) : 0,
'delimiter' => $delimiter,
'grid' => (int) $grid,
'graph' => (int) $graph,
'map' => (int) $map,
'embed' => (int) $embed,
'uuid' => $uuid,
'datastoreStatus' => $datastoreStatus,
'maxSizePreview' => variable_get('file_size_preview_limit', FILE_SIZE_PREVIEW_LIMIT),
);
drupal_add_js($settings, 'setting');
}
// Necessary to fix https://github.com/mapbox/mapbox.js/issues/339
// Update the leaflet library and test if this bug goes away.
// That will involve a lot of QA but we have to do it a some point.
if ($recline) {
$leaflet_imgs = $recline['library path'] . '/vendor/leaflet/1.0.2/images/';
drupal_add_js('L.Icon.Default.imagePath = "/' . $leaflet_imgs . '"', 'inline');
}
if (!empty($settings['recline']['embed'])) {
$output['embed'] = array(
'#type' => 'markup',
'#markup' => $embed_markup,
);
}
$output['data_explorer'] = array(
'#type' => 'markup',
'#markup' => '<div class="data-explorer-help"><i class="fa fa-info-circle" aria-hidden="true"></i> <strong>Data Preview:</strong> Note that by default the preview only displays up to 100 records. Use the pager to flip through more records or adjust the start and end fields to display the number of records you wish to see.</div><span class="data-explorer"></span>',
);
return $output;
}
/**
* Implements hook_preprocess_HOOK().
*
* Process variables for recline-embed-button.tpl.php.
*/
function template_preprocess_recline_embed_button(&$variables) {
$node = $variables['node'];
$variables['embed_url'] = url('node/' . $node->nid . '/recline-embed', array('absolute' => TRUE));
}
/**
* Returns HTML for an recline field widget.
*
* @param array $variables
* An associative array containing:
* - item: Associative array of recline field.
*
* @ingroup themeable
*/
function theme_recline_widget($variables) {
$element = $variables['element'];
$output = '';
$output .= '<div class="recline-widget form-managed-file clearfix">';
$output .= drupal_render_children($element);
$output .= '</div>';
return $output;
}
/**
* check if the url is external or internal url
*/
function parse_external_url($url = '', $internal_class = 'internal-link', $external_class = 'external-link') {
if (empty($url)) {
return FALSE;
}
$link_url = parse_url($url);
$home_url = parse_url($_SERVER['HTTP_HOST']);
if (empty($link_url['host'])) {
$target = '_self';
$class = $internal_class;
}
elseif ($link_url['host'] == $home_url['host']) {
$target = '_self';
$class = $internal_class;
}
else {
$target = '_blank';
$class = $external_class;
}
$output = [
'class' => $class,
'target' => $target,
'url' => $url,
];
return $output;
}
function is_html($string) {
return preg_match("/<[^<]+>/", $string, $m) != 0;
}
function convertYoutube($string) {
return preg_replace(
"/\s*[a-zA-Z\/\/:\.]*youtu(be.com\/watch\?v=|.be\/)([a-zA-Z0-9\-_]+)([a-zA-Z0-9\/\*\-\_\?\&\;\%\=\.]*)/i",
"https://www.youtube.com/embed/$2",
$string
);
}
function is_youtube($url) {
$youtube_pattern = '/^((?:https?:)?\/\/)?((?:www|m)\.)?((?:youtube\.com|youtu.be))(\/(?:[\w\-]+\?v=|embed\/|v\/)?)([\w\-]+)(\S+)?$/';
return preg_match($youtube_pattern, $url, $matches);
}