PluginProbe
Redirection / 2.4
Redirection v2.4
5.10.0 5.9.0 5.8.1 5.8.0 3.7.2 3.7.3 4.0 4.0.1 4.1 4.1.1 4.2 4.2.1 4.2.2 4.2.3 4.3 4.3.1 4.3.2 4.3.3 4.4 4.4.1 4.4.2 4.5 4.5.1 4.6.2 4.7.1 All 130 releases
redirection / fileio / csv.php

csv.php in Redirection 2.4, at fileio/csv.php

65 lines 1.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 class Red_Csv_File extends Red_FileIO {
4 function export( array $items ) {
5 $filename = 'redirection-'.date_i18n( get_option( 'date_format' ) ).'.csv';
6
7 header( 'Content-Type: text/csv' );
8 header( 'Cache-Control: no-cache, must-revalidate' );
9 header( 'Expires: Mon, 26 Jul 1997 05:00:00 GMT' );
10 header( 'Content-Disposition: attachment; filename="'.$filename.'"' );
11
12 $stdout = fopen( 'php://output', 'w' );
13
14 fputcsv( $stdout, array( 'source', 'target', 'regex', 'type', 'code', 'match', 'hits', 'title' ) );
15
16 foreach ( $items AS $line ) {
17 $csv = array(
18 $line->url,
19 $line->action_data,
20 $line->regex,
21 $line->action_type,
22 $line->action->action_code,
23 $line->match->action->type,
24 $line->last_count,
25 $line->title,
26 );
27
28 fputcsv( $stdout, $csv );
29 }
30 }
31
32 function load( $group, $data, $filename = '' ) {
33 $count = 0;
34 $file = fopen( $filename, 'r' );
35
36 if ( $file ) {
37 while ( ( $csv = fgetcsv( $file, 1000, ',' ) ) ) {
38 if ( $csv[0] != 'source' && $csv[1] != 'target') {
39 Red_Item::create( array(
40 'source' => trim( $csv[0] ),
41 'target' => trim( $csv[1] ),
42 'regex' => $this->is_regex( $csv[0] ),
43 'group' => $group,
44 'match' => 'url',
45 'red_action' => 'url'
46 ) );
47
48 $count++;
49 }
50 }
51 }
52
53 return $count;
54 }
55
56 function is_regex( $url ) {
57 $regex = '()[]$^*';
58
59 if ( strpbrk( $url, $regex ) === false )
60 return false;
61
62 return true;
63 }
64 }
65