PluginProbe
Redirection / 2.3.5
Redirection v2.3.5
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.3.5, at fileio/csv.php

83 lines 1.8 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 var $id;
5 var $items;
6
7 function collect( $module ) {
8 $this->id = $module->id;
9
10 $items = Red_Item::get_by_module( $module->id );
11
12 if ( count( $items ) > 0 ) {
13 foreach ( $items AS $item ) {
14 $this->items[] = array(
15 'source' => $item->url,
16 'target' => ( $item->action_type == 'url' ? $item->action_data : '' ),
17 'last_count' => $item->last_count
18 );
19 }
20 }
21 }
22
23 function feed( $filename = '', $heading = '' ) {
24 $filename = sprintf( __( 'module_%d.csv', 'redirection' ), $this->id );
25
26 header( 'Content-Type: text/csv' );
27 header( 'Cache-Control: no-cache, must-revalidate' );
28 header( 'Expires: Mon, 26 Jul 1997 05:00:00 GMT' );
29 header( 'Content-Disposition: attachment; filename="'.$filename.'"' );
30
31 if ( count( $this->items ) > 0 ) {
32 echo "source,target,hits\r\n";
33
34 $stdout = fopen( 'php://output', 'w' );
35
36 foreach ( $this->items AS $line ) {
37 fputcsv( $stdout, $line );
38 }
39 }
40 }
41
42 function load( $group, $data, $filename = '' ) {
43 $count = 0;
44 $file = fopen( $filename, 'r' );
45
46 if ( $file ) {
47 while ( ( $csv = fgetcsv( $file, 1000, ',' ) ) ) {
48 if ( $csv[0] != 'source' && $csv[1] != 'target') {
49 Red_Item::create( array(
50 'source' => trim( $csv[0] ),
51 'target' => trim( $csv[1] ),
52 'regex' => $this->is_regex( $csv[0] ),
53 'group' => $group,
54 'match' => 'url',
55 'red_action' => 'url'
56 ) );
57
58 $count++;
59 }
60 }
61 }
62
63 return $count;
64 }
65
66 function is_regex ($url) {
67 $regex = '()[]$^?+';
68 $escape = false;
69
70 for ( $x = 0; $x < strlen( $url ); $x++ ) {
71
72 if ( $url{$x} == '\\' )
73 $escape = true;
74 elseif ( strpos( $regex, $url{$x} ) !== false && !$escape )
75 return true;
76 else
77 $escape = false;
78 }
79
80 return false;
81 }
82 }
83