-
Notifications
You must be signed in to change notification settings - Fork 2
/
export.php
98 lines (86 loc) · 2.68 KB
/
export.php
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
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
include "/home/baumuin/public_html/twitediens.tk/includes/init_sql.php";
include('/home/baumuin/public_html/twitediens.tk/includes/functions.php');
function mysqli_field_name($result, $field_offset)
{
$properties = mysqli_fetch_field_direct($result, $field_offset);
return is_object($properties) ? $properties->name : null;
}
//Atslēgvārds?
if (isset($_GET['atslegvards']) && strlen($_GET['atslegvards']) > 0){
$vards = urldecode($_GET['atslegvards']);
$tlvards = translit($vards);
$tl2vards = translit2($vards);
if (isset($_GET['nevards']) && strlen($_GET['nevards']) > 0){
$nevards = urldecode($_GET['nevards']);
$NOTLIKE = " AND text NOT LIKE '%$nevards%' ";
}else{
$NOTLIKE = "";
}
//Vīr.dz. <=> Siev.dz.
if(substr($vards, -1) == "s"){
$svards = substr($vards, 0, -1)."a";
$tlsvards = translit($svards);
$tl2svards = translit2($svards);
$SELECT="OR text LIKE '%$svards%'
OR text LIKE '%$tlsvards%'
OR text LIKE '%$tl2svards%'
";
}elseif(substr($vards, -1) == "a"){
$svards = substr($vards, 0, -1)."s";
$tlsvards = translit($svards);
$tl2svards = translit2($svards);
$SELECT="OR text LIKE '%$svards%'
OR text LIKE '%$tlsvards%'
OR text LIKE '%$tl2svards%'
";
}else{
$SELECT="";
}
//Iz DB
$qry = "SELECT distinct `text`, `id`, `screen_name`, `created_at`, `geo`, `emo`, `quoted_id` FROM `tweets`
where (`text` LIKE '%$vards%'
OR text LIKE '%$tlvards%'
OR text LIKE '%$tl2vards%'
".$SELECT.")".$NOTLIKE." group by tweets.text
order by `created_at` desc";
$export = mysqli_query ( $connection, $qry ) or die ( "Sql error : " . mysqli_error( ) );
$fields = mysqli_num_fields ( $export );
$header = "";
$data = "";
for ( $i = 0; $i < $fields; $i++ )
{
$header .= mysqli_field_name( $export , $i ) . "\t";
}
while( $row = mysqli_fetch_row( $export ) )
{
$line = '';
foreach( $row as $value )
{
if ( ( !isset( $value ) ) || ( $value == "" ) )
{
$value = "\t";
}
else
{
$value = str_replace( '"' , '""' , $value );
$value = '"' . $value . '"' . "\t";
}
$line .= $value;
}
$data .= trim( $line ) . "\n";
}
$data = str_replace( "\r" , "" , $data );
if ( $data == "" )
{
$data = "\n(0) Records Found!\n";
}
header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename=meklesanas-rezultati-".$vards.".xls");
header("Pragma: no-cache");
header("Expires: 0");
print "$header\n$data";
}