GlisWeb framework
_320.pages.php
Vai alla documentazione di questo file.
1 <?php
2 
55  // scrittura della cache
56  // TODO perché questa cosa viene fatta qui? vedi _320.pages.php
57  /* NOTA 30/01/2019 per ora provo a commentarla, poi vediamo
58  if( $cf['contents']['cacheable']['pages'] == true ) {
59  $cf['contents']['cacheable']['pages'] = false;
60  memcacheWrite( $cf['memcache']['connection'], CONTENTS_PAGES_DATA, $cf['contents']['pages'] );
61  }
62  */
63 
64  // tento di leggere i valori dalla cache
65 #11 $cf['contents']['tree'] = memcacheRead( $cf['memcache']['connection'], CONTENTS_TREE_KEY );
66 #11 $cf['contents']['index'] = memcacheRead( $cf['memcache']['connection'], CONTENTS_INDEX_KEY );
67 #11 $cf['contents']['shortcuts'] = memcacheRead( $cf['memcache']['connection'], CONTENTS_SHORTCUTS_KEY );
68 
69  // controllo se la cache è aggiornata in base a $cf['contents']['updated']
70  // TODO
71 
72  // debug
73  // echo '310 STANDARD BEFORE' . PHP_EOL;
74  // print_r( $cf['contents']['pages'][ NULL ] );
75 
76  // elaboro l'albero dei contenuti
77 #11 if( $cf['contents']['tree'] === false || $cf['contents']['index'] === false || $cf['contents']['shortcuts'] === false || defined( 'MEMCACHE_REFRESH' ) ) {
78  if( $cf['contents']['cached'] === false || defined( 'MEMCACHE_REFRESH' ) ) {
79 
80  // inizializzo l'albero
81  $cf['contents']['tree'] = array();
82 
83  // inizializzo l'indice
84  $cf['contents']['index'] = array();
85 
86  // inizializzo le shortcuts
87  $cf['contents']['shortcuts'] = array();
88 
89  // preparo le pagine
90  foreach( $cf['contents']['pages'] as $k => &$v ) {
91 
92  // aggiungo l'id pagina
93  $v['id'] = $k;
94 
95 
96  // controllo preliminare parent
97  if( isset( $v['parent'] ) && is_array( $v['parent'] ) && array_key_exists( 'id', $v['parent'] ) ) {
98 
99 # echo $v['id'].PHP_EOL;
100 
101  // controllo parent
102  if( ! isset( $cf['contents']['pages'][ $v['parent']['id'] ] ) ) { $v['parent']['id'] = NULL; }
103 
104  // imposto l'array dell'albero locale
105  $v['tree'] = array( $k => array() );
106 
107  // aggancio al genitore
108  if( isset( $v['parent']['id'] ) ) {
109  $cf['contents']['pages'][ $v['parent']['id'] ]['children']['id'][] = $k;
110  }
111 
112  // registro la scorciatoia o l'alias
113  if( isset( $v['short'] ) && ! empty( $v['short'] ) ) {
114 # print_r( $v['short'] );
115  foreach( $v['short'] as $short ) {
116  if( ! empty( $short ) ) {
117 # echo 's->'.$short;
118  $cf['contents']['shortcuts'][ $short ] = $v['id'];
119  }
120  }
121 #X } elseif( isset( $v['forced'] ) && ! empty( $v['forced'] ) ) {
122  }
123 
124 /*
125  if( isset( $v['forced'] ) && ! empty( $v['forced'] ) ) {
126 # print_r( $v['forced'] );
127  foreach( $v['forced'] as $forced ) {
128  if( ! empty( $forced ) ) {
129 # echo 'f->'.$forced;
130  $cf['contents']['shortcuts'][ $forced ] = $v['id'];
131  }
132  }
133  }
134 */
135 
136  // per ogni lingua attiva
137  foreach( $cf['localization']['languages'] as $lk => $lv ) {
138 
139  // defaults
140  if( ! isset( $v['title'][ $lk ] ) ) { $v['title'][ $lk ] = NULL; }
141  if( ! isset( $v['h1'][ $lk ] ) ) { $v['h1'][ $lk ] = NULL; }
142 
143  // stabilisco quale chiave usare per il rewrite
144  if( ! isset( $v['rewrited'] ) || ! is_array( $v['rewrited'] ) || ! array_key_exists( $lk, $v['rewrited'] ) ) {
145  $v['rewrited'][ $lk ] = string2urlRewrite(
146  ( isset( $v['custom'][ $lk ] ) && ! empty( $v['custom'][ $lk ] ) )
147  ?
148  $v['custom'][ $lk ]
149  :
150  $v['title'][ $lk ]
151  );
152  }
153 
154  // inserisco la pagina corrente nell'indice
155  $cf['contents']['index'][ $lk ][ $v['rewrited'][ $lk ] ][] = $k;
156 
157  // debug
158  // echo $v['rewrited'][ $lk ] . PHP_EOL;
159 
160  }
161 
162  } else {
163 
164  // errore fatale nella struttura delle pagine
165 
166  // log
167  logWrite( 'la pagina ' . $k . ' è malformata e blocca la costruzione della struttura', 'pages', LOG_EMERG );
168 
169  // debug
170  die( 'PAGINA MALFORMATA: ' . $k . ' -> ' . print_r( $v, true ) );
171 
172  }
173 
174  }
175 
176  // debug
177  // echo '310 STANDARD BEFORE - 1' . PHP_EOL;
178  // print_r( $cf['contents']['pages'][ NULL ] );
179 
180  // timer
181  timerCheck( $cf['speed'], ' -> fine preparazione pagine' );
182 
183  // creo l'albero
184  foreach( $cf['contents']['pages'] as $k => &$v ) {
185 
186  // debug
187  // echo $k . PHP_EOL;
188 
189  // controllo se tutti i parent hanno gli stessi menu
190  $menu = array();
191  if( isset( $v['menu'] ) && is_array( $v['menu'] ) ) {
192  $menu = array_keys( $v['menu'] );
193  }
194 
195  // risalgo la struttura per creare il percorso fino alla pagina
196  // TODO a cosa serve questo?!?
197  do {
198  $k = $cf['contents']['pages'][ $k ]['parent']['id'];
199  $v['tree'] = array( $k => $v['tree'] );
200  $v['parents']['id'][] = $k;
201  $v['parents']['h1'][] = $cf['contents']['pages'][ $k ]['h1'];
202  $v['parents']['title'][] = $cf['contents']['pages'][ $k ]['title'];
203  $v['parents']['rewrited'][] = $cf['contents']['pages'][ $k ]['rewrited'];
204  if( isset( $cf['contents']['pages'][ $k ]['menu'] ) && is_array( $cf['contents']['pages'][ $k ]['menu'] ) ) {
205  $parentMenu = array_keys( $cf['contents']['pages'][ $k ]['menu'] );
206  } else {
207  $parentMenu = array();
208  }
209  // TODO questa cosa serve a creare le voci vuote di menù che poi diventano elementi di lista vuoti
210  // in cui nidificare le sotto voci (serve nel caso in cui venga piazzata una voce in un menù a livello
211  // superiore al primo, per evitare che debbano essere creati a mano gli elementi superiori
212  // TUTTAVIA la mia sensazione è che generi inefficenze e in alcuni casi bug (fa apparire voci vuote
213  // in menù dove non ha senso che appaiano...) insomma VA TESTATA E DOCUMENTATA MEGLIO
214  if( is_array( $menu ) && is_array( $parentMenu ) ) {
215  foreach( array_diff( $menu, $parentMenu ) as $manca ) {
216  $cf['contents']['pages'][ $k ]['menu'][ $manca ] = array(
217  'label' => NULL,
218  'priority' => 'AUTO'
219  );
220  }
221  }
222  } while( $k !== NULL );
223 
224  // capovolgo l'array dei parents
225  $v['parents']['id'] = array_reverse( $v['parents']['id'] );
226  $v['parents']['h1'] = array_reverse( $v['parents']['h1'] );
227  $v['parents']['title'] = array_reverse( $v['parents']['title'] );
228  $v['parents']['rewrited'] = array_reverse( $v['parents']['rewrited'] );
229 
230  // aggiungo la pagina corrente al percorso completo della pagina
231  $v['parents']['id'][] = $v['id'];
232  $v['parents']['h1'][] = $v['h1'];
233  $v['parents']['title'][] = $v['title'];
234  $v['parents']['rewrited'][] = $v['rewrited'];
235 
236  // copio i dati del parent
237  $v['parent']['title'] = $cf['contents']['pages'][ $v['parent']['id'] ]['title'];
238  $v['parent']['h1'] = $cf['contents']['pages'][ $v['parent']['id'] ]['h1'];
239  $v['parent']['rewrited'] = $cf['contents']['pages'][ $v['parent']['id'] ]['rewrited'];
240 
241  }
242 
243  // debug
244  // echo '310 STANDARD BEFORE - 2' . PHP_EOL;
245  // print_r( $cf['contents']['pages'][ NULL ] );
246 
247  // timer
248  timerCheck( $cf['speed'], ' -> fine costruzione albero' );
249 
250  // creo i path
251  foreach( $cf['contents']['pages'] as $k => &$v ) {
252 
253  // per ogni lingua attiva
254  foreach( $cf['localization']['languages'] as $lk => $lv ) {
255 
256  // colonna
257  $col = array_column( $v['parents']['rewrited'], $lk );
258 
259  // colonna pulita
260  $tcol = trimArray( $col );
261 
262  // percorso
263  $path = implode( '/', $tcol ) . ( ( ! empty( $tcol ) ) ? '.' . $lk . '.html' : NULL );
264 
265  // calcolo il percorso della pagina corrente
266  if( isset( $v['forced'][ $lk ] ) ) {
267  $v['path'][ $lk ] = NULL;
268  } else {
269  $v['path'][ $lk ] = $cf['site']['root'] . $path;
270  }
271 
272  // calcolo l'URL della pagina corrente
273  if( isset( $v['forced'][ $lk ] ) ) {
274  $v['url'][ $lk ] = $v['forced'][ $lk ];
275  } else {
276 // TODO anziché usare genericamente $cf['site']['url'], usare (se specificato) il dominio specifico per la lingua del ciclo corrente
277 // NOTA dovrebbe essere valorizzato ad es. $cf['site']['default']['urls']['it-IT'][PROD] (o qualcosa di simile?)
278  $v['url'][ $lk ] = $cf['site']['url'] . $path;
279 #L $v['url'][ $lk ] = $cf['site']['url'][ $lk ] . $path;
280  }
281 
282  }
283 
284  // aggiungo il percorso della pagina corrente all'albero
285  $cf['contents']['tree'] = array_replace_recursive( $cf['contents']['tree'], $v['tree'] );
286 
287  }
288 
289  // aggiungo i path dei parent
290  foreach( $cf['contents']['pages'] as $k => &$v ) {
291 
292  // risalgo la struttura per creare il percorso fino alla pagina
293  do {
294  $k = $cf['contents']['pages'][ $k ]['parent']['id'];
295  $v['parents']['path'][] = $cf['contents']['pages'][ $k ]['path'];
296  } while( $k !== NULL );
297 
298  // capovolgo l'array dei parents
299  $v['parents']['path'] = array_reverse( $v['parents']['path'] );
300 
301  // aggiungo la pagina corrente al percorso completo della pagina
302  $v['parents']['path'][] = $v['path'];
303 
304  // copio i dati del parent
305  $v['parent']['path'] = $cf['contents']['pages'][ $v['parent']['id'] ]['path'];
306 
307  }
308 
309  // scrittura della cache
310 #11 memcacheWrite( $cf['memcache']['connection'], CONTENTS_TREE_KEY, $cf['contents']['tree'] );
311 #11 memcacheWrite( $cf['memcache']['connection'], CONTENTS_INDEX_KEY, $cf['contents']['index'] );
312 #11 memcacheWrite( $cf['memcache']['connection'], CONTENTS_SHORTCUTS_KEY, $cf['contents']['shortcuts'] );
313 # memcacheWrite( $cf['memcache']['connection'], CONTENTS_PAGES_KEY, $cf['contents']['pages'] );
314 #11 $cf['pages']['cacheable'] = true;
315 
316 #11 } else {
317 
318 # // lettura delle pagine dalla cache
319 # $cf['contents']['pages'] = memcacheRead( $cf['memcache']['connection'], CONTENTS_PAGES_KEY );
320 #11 $cf['pages']['cacheable'] = false;
321 
322  // log
323 #11 logWrite( 'contents (pages, tree e index) letti dalla cache', 'memcache', LOG_INFO );
324 
325  // timer
326  timerCheck( $cf['speed'], ' -> fine generazione dei path dei parent' );
327 
328  }
329 
330  // debug
331  // echo '310 STANDARD' . PHP_EOL;
332  // memcacheDelete( $cf['memcache']['connection'], CONTENTS_TREE_KEY );
333  // memcacheDelete( $cf['memcache']['connection'], CONTENTS_INDEX_KEY );
334  // memcacheDelete( $cf['memcache']['connection'], CONTENTS_PAGES_KEY );
335  // print_r( $cf['localization']['language'] );
336  // print_r( $cf['contents']['index'] );
337  // print_r( $cf['contents']['pages']['licenza']['content'] );
338  // echo $cf['contents']['updated'];
339  // print_r( $cf['contents']['pages'] );
340  // print_r( $cf['contents']['pages'][ NULL ] );
341 
342 ?>
string2urlRewrite( $t)
sostituisce i caratteri in modo da rendere una stringa utilizzabile in un url
$lk
Definition: _collation.php:45
logWrite( $m, $f='site', $l=LOG_NOTICE, $d=DIRECTORY_LOG, $t=CURRENT_LOG_LEVEL, $s=SITE_STATUS)
scrive un messaggio nei log del sito
Definition: _log.utils.php:48
$cf['ricerca']['template']
Definition: _030.common.php:7
trimArray(&$ar, $limit=0)
timerCheck(&$a, $c)