index.php
4.7 KB
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
<?php
require_once '1.7.6/Classes/PHPExcel.php';
$objReader = new PHPExcel_Reader_Excel5();
$objReader->setReadDataOnly(true);
$objPHPExcel = $objReader->load( 'catalogo_2015-09-09_ALTERADO_CATEGORIAS.xls' );
$objPHPExcel->setActiveSheetIndex(0);
$slug_categoria = '';
$slug_software = '';
for( $linha = 2; $linha <= 73; $linha++ ){
for( $coluna = 0; $coluna <= 6; $coluna++ ){
if( $coluna == 1 )
$name = $objPHPExcel->getActiveSheet()->getCellByColumnAndRow($coluna, $linha)->getValue();
if( $coluna == 2 )
$description = $objPHPExcel->getActiveSheet()->getCellByColumnAndRow($coluna, $linha)->getValue();
if( $coluna == 3 )
$about = $objPHPExcel->getActiveSheet()->getCellByColumnAndRow($coluna, $linha)->getValue();
if( $coluna == 4 )
$url = $objPHPExcel->getActiveSheet()->getCellByColumnAndRow($coluna, $linha)->getValue();
if( $coluna == 5 )
$image = $objPHPExcel->getActiveSheet()->getCellByColumnAndRow($coluna, $linha)->getValue();
if( $coluna == 6 )
$categoria = $objPHPExcel->getActiveSheet()->getCellByColumnAndRow($coluna, $linha)->getValue();
}
if( !isset( $categorias ) || empty( $categorias ) ) {
$categoria_arr = explode( ',', $categoria );
foreach( $categoria_arr as $cat ) {
$slug_categoria = get_slug( $cat );
$slug_software = get_slug( $name );
$imagem = get_image( $image, $slug_software );
$categorias[] = array(
'id' => '',
'id_check' => $slug_categoria,
'name' => $cat,
'quantity' => '',
'softwares' => array(
array(
'id' => '',
'id_check' => $slug_software,
'name' => $name,
'image' => $imagem,
'imageLarge' => $imagem,
'description' => $description,
'url' => $url,
'about' => $about
),
),
);
}
}
else {
$categoria_arr = explode( ',', $categoria );
foreach( $categoria_arr as $cat ) {
$slug_categoria = get_slug( $cat );
$slug_software = get_slug( $name );
$check = busca_valor_chave( $slug_categoria, 'id_check', $categorias );
$imagem = get_image( $image, $slug_software );
if( !is_bool( $check ) ){
$software = array(
'id' => '',
'id_check' => $slug_software,
'name' => $name,
'image' => $imagem,
'imageLarge' => $imagem,
'description' => $description,
'url' => $url,
'about' => $about
);
array_push( $categorias[$check]['softwares'], $software );
} else {
$m_categorias = array(
'id' => '',
'id_check' => $slug_categoria,
'name' => $cat,
'quantity' => '',
'softwares' => array(
array(
'id' => '',
'id_check' => $slug_software,
'name' => $name,
'image' => $imagem,
'imageLarge' => $imagem,
'description' => $description,
'url' => $url,
'about' => $about
),
),
);
array_push( $categorias, $m_categorias );
}
}
}
}
$i_categoria = 0;
foreach( $categorias as $num_categoria ) {
$categorias[$i_categoria]['id'] = $i_categoria;
$i_software = 0;
foreach ($num_categoria['softwares'] as $num_software) {
$categorias[$i_categoria]['softwares'][$i_software]['id'] = $i_software;
$i_software++;
}
$i_categoria++;
}
$i_categoria = 0;
foreach( $categorias as $num_categoria ) {
$quantity = count( $num_categoria['softwares'] );
$categorias[$i_categoria]['quantity'] = $quantity;
$i_categoria++;
}
echo '<pre>';
// print_r( $categorias );
echo json_encode($categorias);
echo '</pre>';
// Busca valor chave em um array
function busca_valor_chave($valor, $chave, $array){
$i = 0;
foreach ($array as $item){
if (isset($item[$chave]) && $item[$chave] == $valor){
return $i;
}
$i++;
}
return false;
}
// Gerar slug
function get_slug( $text ) {
// replace non letter or digits by -
$text = preg_replace('~[^\\pL\d]+~u', '-', $text);
// trim
$text = trim($text, '-');
// transliterate
$text = iconv('utf-8', 'us-ascii//TRANSLIT', $text);
// lowercase
$text = strtolower($text);
// remove unwanted characters
$text = preg_replace('~[^-\w]+~', '', $text);
if ( empty( $text ) ) {
return 'n-a';
}
return $text;
}
function get_image( $url, $slug ) {
// $extensao = substr( $url, -4 );
$extensao = '.png';
// $check = strpos( $extensao, "." );
// if( $check === false ){
// $extensao = '.' . $extensao;
// }
$caminho_int = 'marcas/' . $slug . $extensao;
// copy($url, $caminho_int);
return $caminho_int;
}