OPiQuotations  v.03.00.00 — April 5, 2019
index.php
Go to the documentation of this file.
1 <?php /* -*- coding: utf-8 -*- */
2 
3 /** \file index.php
4  * (October 24, 2019)
5  *
6  * \brief
7  * Main page to the Web application OPiCitations
8  * http://www.opimedia.be/OPiCitations/
9  *
10  * Piece of OPiQuotations.
11  * https://bitbucket.org/OPiMedia/opiquotations
12  *
13  * GPLv3 --- Copyright (C) 2014, 2015, 2016, 2017, 2018, 2019 Olivier Pirson
14  * http://www.opimedia.be/
15  *
16  * @package OPiCitations
17  */
18 
19 require_once 'OPiQuotations/log.inc';
20 
21 #DEBUG
22 if (true) {
23  // Development configuration
24  ini_set('display_errors', 'stdout');
25  ini_set('display_startup_errors', 1);
26  ini_set('html_errors', 1);
27 
28  error_reporting(-1);
29 
30  assert_options(ASSERT_ACTIVE, true);
31  assert_options(ASSERT_WARNING, true);
32  assert_options(ASSERT_BAIL, true);
33 }
34 else {
35 #DEBUG_END
36  // Production configuration
37  ini_set('display_errors', 'stderr');
38  ini_set('display_startup_errors', 0);
39  ini_set('html_errors', 0);
40 
41  error_reporting(-1);
42 
43  assert_options(ASSERT_ACTIVE, false);
44  assert_options(ASSERT_WARNING, false);
45  assert_options(ASSERT_BAIL, false);
46 
47  set_error_handler('\OPiQuotations\error_handler');
48 #DEBUG
49 }
50 #DEBUG_END
51 
52 mb_internal_encoding('UTF-8');
53 mb_regex_encoding('UTF-8');
54 mb_http_output('UTF-8');
55 mb_detect_order('UTF-8');
56 
57 
58 function nb_to_nb_page($nb_quotations) { // return the number of pages
59  #DEBUG
60  assert('is_int($nb_quotations) && ($nb_quotations >= 0)');
61  #DEBUG_END
62 
63  global $nb_by_page;
64 
65  return ceil($nb_quotations/$nb_by_page);
66 }
67 
68 
69 function nb_to_offset($nb_quotations) { // return the offset for this page
70  #DEBUG
71  assert('is_int($nb_quotations) && ($nb_quotations >= 0)');
72  #DEBUG_END
73 
74  global $nb_by_page;
75  global $num_page;
76 
77  return $nb_by_page*($num_page - 1);
78 }
79 
80 
81 function s($n) { // adds 's' if plural
82  #DEBUG
83  assert('is_int($n) && ($n >= 0)');
84  #DEBUG_END
85 
86  return ($n >= 2
87  ? 's'
88  : '');
89 }
90 
91 
92 require_once 'OPiQuotations/OPiQuotations.inc';
93 
95 
96 $lists = array('author' => $opiquotations->list_authors(),
97  'nation' => $opiquotations->list_nations(),
98  'subject' => $opiquotations->list_subjects(),
99  'work' => $opiquotations->list_works());
100 
101 $LABELS = array('ids' => 'numéro(s)',
102  'subject' => 'sujet',
103  'text' => 'texte',
104  'translation' => 'traduction',
105  'author' => 'auteur',
106  'work' => '&oelig;uvre',
107  'nation' => 'maxime');
108 $ALL_KEYS = array_merge(array_keys($LABELS), ['id', 'all_marked', 'all', 'page', 'selection']);
109 
110 $SELECTION_LABELS = array('Facebook' => 'Facebook - 1OPiCitationParJour',
111  'Twitter' => 'Twitter - OPiCitationJour',
112  'Web' => 'Web');
113 
114 
116 
119 
120 
121 // GET correct parameters
122 $params = array();
123 
124 foreach ($_GET as $key=>$label) {
125  if (in_array($key, $ALL_KEYS) && !isset($params[$key])) {
126  if ($key === 'page') {
127  if ($label === 'toutes') {
128  $nb_by_page = 999999;
129  }
130  else {
131  $num_page = max(1, (int)$label);
132  }
133  }
134  else {
135  $params[$key] = $_GET[$key];
136  }
137  }
138 }
139 
140 unset($key);
141 unset($ALL_KEYS);
142 
143 foreach (array('all', 'all_marked') as $key) { // cleans values
144  if (isset($_params[$key])) {
145  $params[$key] = null;
146  }
147 }
148 
149 unset($key);
150 
151 foreach ($params as $key=>$value) {
152  if ($value !== null) {
153  $params[$key] = preg_replace('/\.\.\./', '…', # ellipsis
154  preg_replace('/\'/', '’', # apostrophe
155  trim($value)));
156  }
157 }
158 
159 unset($key);
160 unset($value);
161 
162 $param_key = null;
164 
165 if (!empty($params)) { // get the first param
166  reset($params);
167  $param_key = key($params);
168  $param_value = (in_array($param_key, ['all_marked', 'all'])
169  ? null
170  : $params[$param_key]);
171 }
172 
173 
174 // Get quotations
175 $search = null;
176 $param_id = null;
177 
178 if ($param_key === 'id') { // id searched
179  $param_id = (int)$param_value;
180 
181  $quots = $opiquotations->quotations_by_ids([$param_id]);
182  $header = null;
183  $params['ids'] = (string)$param_id;
184 }
185 else if ($param_key === 'ids') { // ids searched
186  // Analyze params
187  $ids = preg_replace('/(^[^0-9]+|[^0-9]+$)/', '', $param_value); // strip left and right
188  $ids = mb_split('[^\-0-9]+', $ids); // split on numbers or ranges (number-number)
189 
190  for ($i = 0; $i < count($ids); $i++) {
191  $id = &$ids[$i];
192  $id = preg_replace('/(^[^0-9]+|[^0-9]+$)/', '', $id); // strip left and right
193 
194  if ($id === '') {
195  $id = '0';
196  }
197 
198  $a = mb_split('-', $id); // split on numbers
199 
200  $id = (int)$a[0];
201 
202  $count_a = count($a);
203  if ($count_a > 1) { // it is a range
204  for ($j = (int)$a[0] + 1; $j <= (int)$a[$count_a - 1]; $j++) {
205  $ids[] = $j;
206  }
207  }
208  }
209 
210  unset($a);
211  unset($i);
212  unset($j);
213  unset($count_a);
214  unset($id);
215 
216  $ids = array_unique($ids, SORT_NUMERIC);
217  sort($ids);
218  if ((count($ids) > 0) && ($ids[0] === 0)) {
219  array_shift($ids);
220  }
221 
222  // Recompose numbers and ranges to display
223  $a = array();
224  $first = null;
225  if (count($ids) > 0) {
226  $first = $ids[0];
227  for ($i = 0; $i < count($ids) - 1; $i++) {
228  if ($ids[$i + 1] !== $ids[$i] + 1) {
229  $a[] = ($first === $ids[$i]
230  ? (string)$first
231  : "$first-$ids[$i]");
232  $first = $ids[$i + 1];
233  }
234  }
235  $a[] = ($first === $ids[$i]
236  ? (string)$first
237  : "$first-$ids[$i]");
238 
239  unset($first);
240  unset($i);
241  }
242 
243  // Query
244  $nb_quotations = $opiquotations->quotations_by_ids_nb($ids);
245  $quots = $opiquotations->quotations_by_ids($ids,
246  $nb_by_page, nb_to_offset($nb_quotations));
247  $header = '<strong>Numéro(s)</strong> '.implode(', ', $a).'&thinsp;: <strong>'.$nb_quotations.'</strong> résultat'.s($nb_quotations);
248  $param_value = implode(',', $a);
249 
250  unset($a);
251 }
252 else if ($param_key === 'subject') { // subject searched
253  $nb_quotations = $opiquotations->quotations_by_subject_nb($param_value);
254  $quots = $opiquotations->quotations_by_subject($param_value,
255  $nb_by_page, nb_to_offset($nb_quotations));
256  $header = '<strong>Sujet</strong> &quot;'.htmlspecialchars($param_value).'&quot;&thinsp;: <strong>'.$nb_quotations.'</strong> résultat'.s($nb_quotations);
258 }
259 else if ($param_key === 'text') { // text searched
260  $nb_quotations = $opiquotations->quotations_by_text_nb($param_value);
261  $quots = $opiquotations->quotations_by_text($param_value,
262  $nb_by_page, nb_to_offset($nb_quotations));
263  $header = '<strong>Texte</strong> &quot;'.htmlspecialchars($param_value).'&quot;&thinsp;: <strong>'.$nb_quotations.'</strong> résultat'.s($nb_quotations);
265 }
266 else if ($param_key === 'author') { // author searched
267  $nb_quotations = $opiquotations->quotations_by_author_nb($param_value);
268  $quots = $opiquotations->quotations_by_author($param_value,
269  $nb_by_page, nb_to_offset($nb_quotations));
270  $header = '<strong>Auteur</strong> &quot;'.htmlspecialchars($param_value).'&quot;&thinsp;: <strong>'.$nb_quotations.'</strong> résultat'.s($nb_quotations);
272 }
273 else if ($param_key === 'work') { // work searched
274  $nb_quotations = $opiquotations->quotations_by_work_nb($param_value);
275  $quots = $opiquotations->quotations_by_work($param_value,
276  $nb_by_page, nb_to_offset($nb_quotations));
277  $header = '<strong>&OElig;uvre</strong> &quot;'.htmlspecialchars($param_value).'&quot;&thinsp;: <strong>'.$nb_quotations.'</strong> résultat'.s($nb_quotations);
279 }
280 else if ($param_key === 'nation') { // nation searched
281  $nb_quotations = $opiquotations->quotations_by_nation_nb($param_value);
282  $quots = $opiquotations->quotations_by_nation($param_value,
283  $nb_by_page, nb_to_offset($nb_quotations));
284  $header = '<strong>Maxime</strong> &quot;'.htmlspecialchars($param_value).'&quot;&thinsp;: <strong>'.$nb_quotations.'</strong> résultat'.s($nb_quotations);
286 }
287 else if ($param_key === 'translation') { // translation searched
288  $nb_quotations = $opiquotations->quotations_by_translation_nb($param_value);
289  $quots = $opiquotations->quotations_by_translation($param_value,
290  $nb_by_page, nb_to_offset($nb_quotations));
291  $header = '<strong>Traduction</strong> &quot;'.htmlspecialchars($param_value).'&quot;&thinsp;: <strong>'.$nb_quotations.'</strong> résultat'.s($nb_quotations);
293 }
294 else if (($param_key === 'selection')
295  && !empty($SELECTION_LABELS[$param_value])) { // selection specified
296  $nb_quotations = $opiquotations->quotations_by_selection_label_nb($SELECTION_LABELS[$param_value]);
297  $quots = $opiquotations->quotations_by_selection_label($SELECTION_LABELS[$param_value],
298  $nb_by_page, nb_to_offset($nb_quotations));
299 
300  $SELECTION_LINKS = array('Facebook' => ' postées sur la page Facebook <strong><a class="icon-Facebook monospace" href="https://www.facebook.com/1OPiCitationParJour">1OPiCitationParJour</a></strong>',
301  'Twitter' => ' postées sur le compte Twitter <strong><a class="icon-Twitter monospace" href="https://twitter.com/OPiCitationJour">@OPiCitationJour</a></strong>',
302  'Web' => ' ayant un lien vers le <strong><a class="icon-Web no-decoration">Web</a></strong>');
303 
304  $header = 'Les <strong>'.$nb_quotations.'</strong> citations'.$SELECTION_LINKS[$param_value];
305 }
306 else if ($param_key === 'all_marked') { // all quotations marked
307  $nb_quotations = $opiquotations->quotations_all_marked_nb();
308  $quots = $opiquotations->quotations_all_marked($nb_by_page, nb_to_offset($nb_quotations));
309  $header = 'Mes <strong>'.$nb_quotations.'</strong> citations <strong class="mark">favorites</strong>';
310 }
311 else if ($param_key === 'all') { // all quotations
312  $nb_quotations = $opiquotations->quotations_all_nb();
313  $quots = $opiquotations->quotations_all($nb_by_page, nb_to_offset($nb_quotations));
314  $header = '<strong>Toutes</strong> les '.$nb_quotations.' citations';
315 }
316 else { // $NB_FOR_RANDOM quotations at random
317  $quots = $opiquotations->quotations_by_random($NB_FOR_RANDOM);
318  $header = '<strong>'.count($quots).'</strong> citations choisies <strong>aléatoirement</strong>';
319 
320  #DEBUG
321  assert('count($quots) === $NB_FOR_RANDOM');
322  #DEBUG_END
323 }
324 
325 
326 // Init other informations
327 $only_one = (count($quots) === 1);
328 
329 $keywords = ['citation', 'citations', 'maxime', 'maximes', 'proverbe', 'proverbes', 'littérature', 'français'];
330 
331 if ($only_one) {
332  $title = 'OPiCitations n°'.$quots[0]->id().' &mdash; Dictionnaire de citations';
333 
334  $desc = 'OPiCitations n°'.$quots[0]->id().' :
335 '.htmlspecialchars($quots[0]->to_text());
336 
337 
338  // Prepare keywords from quotation
339  $i = 0;
340  foreach ([$quots[0]->subject(),
341  ($quots[0]->is_maxim()
342  ? $quots[0]->nation()
343  : $quots[0]->author()), $quots[0]->work()] as $keyword) {
344  if ($keyword !== null) {
345  if ($i < 2) { // if subject, nation/author then also add pieces
346  $a = explode(' ', $keyword);
347  if (count($a) > 1) {
348  $a[] = $keyword;
349  }
350  }
351  else {
352  $a = [$keyword];
353  }
354 
355  foreach ($a as $keyword) {
356  $keywords[] = htmlspecialchars($keyword);
357  }
358 
359  unset($a);
360  }
361 
362  ++$i;
363  }
364 
365  unset($i);
366  unset($keyword);
367 }
368 else {
369  $title = 'OPiCitations &mdash; Dictionnaire de citations';
370 
371  $desc = 'Dictionnaire de citations.';
372 
373  if ($header !== null) {
374  $desc .= '
375 '.strip_tags($header);
376  }
377 }
378 
381 
382 
383 // Set URL
384 $url_site = 'http://'.$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']).'/';
386 
387 if ($only_one) {
388  $url .= '?id='.$quots[0]->id();
389 }
390 else {
391  if ($param_key !== null) {
392  $url .= '?'.$param_key;
393  if ($param_value !== null) {
394  $url .= '='.rawurlencode($param_value);
395  }
396  }
397 }
398 
399 ?><!DOCTYPE html>
400 <html lang="fr">
401  <head>
402  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
403 
404  <meta name="viewport" content="width=device-width, initial-scale=1">
405 
406  <meta name="author" content="Olivier Pirson">
407  <meta name="description" content="<?php echo $desc; ?>">
408  <meta name="keywords" content="<?php echo implode(',', $keywords); ?>">
409  <meta name="keywords" lang="en" content="quotation,quotations,maxim,maxims,proverb,proverbs,literature,French">
410 
411  <title><?php echo $title; ?></title>
412 
413  <link rel="stylesheet" type="text/css" href="/OPiCitations/public/css/style.min.css">
414  <style title="highlight">/* Stylesheet to activate/deactivate highlight with JavaScript. */</style>
415 
416  <script src="/OPiCitations/public/js/OPiQuotations.automatic-min.js" async="async"></script>
417 
418  <link rel="icon" type="image/x-icon" href="/OPiCitations/favicon.ico">
419 
420  <link rel="canonical" href="<?php echo $url; ?>">
421 
422  <meta property="og:image" content="<?php echo $url_site; ?>public/img/OPiQuotations<?php
423 
424 $all_is_maxim = !empty($quots) || ($param_key === 'nation');
425 
426 if ($all_is_maxim) {
427  foreach ($quots as $quot) {
428  if (!$quot->is_maxim()) {
429  $all_is_maxim = false;
430 
431  break;
432  }
433  }
434  if ($all_is_maxim) {
435  echo '-maxim';
436  }
437 }
438 
439 unset($all_is_maxim);
440 
441 ?>-256x256-t.png">
442  <meta property="og:description" content="<?php echo $desc_open_graph; ?>">
443  <meta property="og:title" content="<?php echo $title; ?>">
444  <meta property="og:type" content="website">
445  <meta property="og:url" content="<?php echo $url; ?>">
446 
447  <meta name="msapplication-TileColor" content="#fdfdd0">
448  <meta name="msapplication-square150x150logo" content="/OPiCitations/public/img/OPiQuotations-64x64-t.png">
449  </head>
450  <body>
451  <div id="top"></div>
452 
453  <nav id="lists">
454 <?php
455 
456 foreach ($LABELS as $key=>$label) {
457  if (isset($lists[$key])) {
458  echo '<section id="list-', $key, '" class="list" aria-haspopup="true">
459  <header>
460  <div class="close">&times;</div>
461  <h2><span id="list-', $key, '-nb"></span> ', mb_strtolower($label), 's</h2>
462  </header>
463  <div id="list-', $key, '-container">Chargement&hellip;</div>
464 </section>
465 ';
466  }
467 }
468 
469 unset($key);
470 unset($label);
471 
472 ?>
473  </nav>
474 
475  <nav id="control-panel">
476  <div id="control-panel-right-border"><div><span>&rarr;</span></div><div><span>&rarr;</span></div></div>
477  <div id="control-panel-close" class="close">&times;</div>
478 <!--[if lt IE 9]>
479  <header id="please-don-t-use-IE">
480  <p>Je vous en supplie,<br>utilisez un <i>vrai</i> navigateur&nbsp;!</p>
481  <p>
482  Je préconise
483  <strong><a href="https://www.mozilla.org/fr/firefox/">Firefox</a></strong>.
484  </p>
485  </header>
486 <![endif]-->
487  <form class="big-buttons" action="#">
488  <ul>
489  <li><button onclick="document.location.assign('./'); return false;"><?php echo $NB_FOR_RANDOM; ?> choisies <strong>aléatoirement</strong></button></li>
490  <li><button name="all"><strong>Toutes</strong> les citations</button></li>
491  <li>
492  <div>
493  <ul>
494  <li><button name="selection" value="Web" title="Toutes celles ayant un lien vers le Web"><span></span></button></li>
495  <li><button name="selection" value="Twitter" title="Toutes celles postées sur le compte Twitter"><span>&#10102;</span></button></li>
496  <li><button name="selection" value="Facebook" title="Toutes celles postées sur la page Facebook"><span>&#10102;</span></button></li>
497  <li><button name="all_marked" title="Mes favorites"><span></span></button></li>
498  </ul>
499  </div>
500  </li>
501  </ul>
502  </form>
503  Recherche par
504  <ul id="menu">
505 <?php
506 
507 // HTML form inputs
508 foreach ($LABELS as $key=>$label) {
509  echo ' <li class="', $key, '">
510  <div>
511  '.($key === 'ids'
512  ? ''
513  : 'ou ').'<label for="', $key, '">', $label, '</label>&thinsp;:
514 ';
515  if (isset($lists[$key])) {
516  echo ' <button class="list-open">liste '
517  .(in_array($key, array('author', 'work'))
518  ? 'd&rsquo;'
519  : 'de ').$label.'s</button>
520 ';
521  }
522  echo ' </div>
523  <form action="#">
524  <input id="', $key, '" name="', $key, '" type="search"', (isset($params[$key])
525  ? ' value="'.htmlspecialchars($params[$key]).'"'
526  : null), ($key === 'ids'
527  ? ' placeholder="Ex.: 260 ou 259-261 ou 260,3241"'
528  : ''), '>
529  </form>
530  </li>
531 ';
532 }
533 
534 unset($LABELS);
535 unset($key);
536 unset($label);
537 
538 ?>
539  <li>
540 <?php
541 
542 if ($search !== null && $search !== '') {
543  echo ' <button id="highlight-on-off" title="(Néglige certaines occurences utilisant certains caractères non-alphanumériques.)">Surligner</button>';
544 }
545 
546 ?>
547  <a class="go-bottom" href="#bottom"><span>&darr;</span></a>
548  <a class="go-top" href="#top"><span>&uarr;</span></a>
549  </li>
550  </ul>
551 
552  <footer>
553  <div id="about">
554  <div>
555  <h2 id="about-open">&Agrave; propos de</h2>
556  <div aria-haspopup="true">
557  <div id="about-close" class="close">&times;</div>
558  <h3>
559  <a class="no-decoration no-prefix" href="<?php echo $url_site; ?>">O<span class="surname">Pi</span>Citations</a>
560  </h3>
561  <p class="right">version 03.00.00 &mdash; 24 octobre 2019</p>
562  <div>
563  <p>
564  Ensemble de citations pour l&rsquo;essentiel jadis récoltées par mes soins au hasard de mes lectures.
565  </p>
566  <p>
567  (Accumulées dans un antique programme écrit en AMOS BASIC sur <a href="http://www.opimedia.be/DS/grenier/#Amiga">Amiga</a>,
568  et déjà réutilisées par ce vieux
569  <a href="http://www.opimedia.be/DS/grenier/#enre">programme</a>
570  écrit en C sous M$-DOS.)
571  </p>
572  <p>
573  Vous pouvez me contacter par e-mail pour me signaler toute erreur constatée,
574  ou pour toute autre raison&thinsp;:
575  <a rel="nofollow" class="URL" href="mailto:olivier.pirson.opi@gmail.com?subject=OPiCitations">olivier.pirson.opi@gmail.com</a>
576  </p>
577  <div class="sep">
578  <strong>&#10102;</strong> citation choisie aléatoirement <strong>postée chaque matin</strong>
579  <ul>
580  <li>
581  sur le compte Twitter
582  <a class="icon-Twitter monospace" href="https://twitter.com/OPiCitationJour">@OPiCitationJour</a>
583  </li>
584  <li>
585  sur la page Facebook
586  <a class="icon-Facebook monospace" href="https://www.facebook.com/1OPiCitationParJour">1OPiCitationParJour</a>
587  </li>
588  </ul>
589  </div>
590  <p class="sep">
591  Une version réduite de cette application Web n&rsquo;affichant qu&rsquo;une seule citation
592  (pouvant être utilisée en tant qu&rsquo;<span class="monospace">&lt;iframe&gt;</span>
593  pour l&rsquo;inclure dans une autre page Web)&thinsp;:
594  <strong><a class="one-OPiQuotation" href="une-OPiCitation.php" target="_blank">&#10102;une O<span class="surname">Pi</span>Citation</a></strong>
595  </p>
596  <p class="sep">
597  Application Web écrite en <abbr>PHP</abbr>/MySQL/<abbr>HTML</abbr>5/Sass/JavaScript, sous licence libre <abbr lang="en" title="GNU General Public License">GPL</abbr>.
598  </p>
599  <ul>
600  <li>
601  Sources complètes (avec le fichier de citations) sur Bitbucket&thinsp;:<br>
602  <strong><a lang="en" class="URL" href="https://bitbucket.org/OPiMedia/opiquotations">https://bitbucket.org/OPiMedia/opiquotations</a></strong>
603  </li>
604  <li><strong><a lang="en" href="http://www.opimedia.be/DS/webdev/PHP/OPiQuotations/docs/">Online <abbr>HTML</abbr> documentation</a></strong></li>
605  </ul>
606  <div class="sep ds-jf-opi">
607  D&rsquo;autres citations sur mes sites&thinsp;:
608  <p>
609  <a href="http://www.opimedia.be/DS/citations/"><img src="/OPiCitations/public/img/DS-t.png" width="80" height="34" alt="[DS]"></a>
610  <a href="http://www.opimedia.be/JF/citations/"><img src="/OPiCitations/public/img/JF-t.png" width="41" height="34" alt="[JF]"></a>
611  <a href="http://www.opimedia.be/citations/"><img src="/OPiCitations/public/img/OPi-t.png" width="41" height="34" alt="[OPi]"></a>
612  </p>
613  </div>
614  </div>
615  <p>
616  <a class="donate" href="http://www.opimedia.be/donate/"><img src="/OPiCitations/public/img/Faire-un-don-124x26-t.png" width="124" height="26" alt="[Faire un don]"></a>
617  <a class="opi" href="http://www.opimedia.be/">Olivier <span class="surname">Pirson</span> O<span class="surname">Pi</span></a>
618  </p>
619  </div>
620  </div>
621  </div>
622  </footer>
623  </nav>
624 
625  <main>
626  <h1>
627  <a class="no-decoration no-prefix" href="<?php echo $url_site; ?>"><span>O<span class="surname">Pi</span>Citations</span></a>
628  </h1>
629 
630  <header>
631 <?php
632 
633 if ($header !== null) {
634  echo ' ', $header;
635 }
636 echo '
637  <small>(sur <strong>'.$opiquotations->nb().'</strong> citations)</small>
638  <div class="clear"></div>
639 ';
640 
641 
642 function print_page_links() {
643  global $nb_quotations;
644  global $num_page;
645 
646  $nb_page = nb_to_nb_page($nb_quotations);
647  if ($nb_page < 2) {
648  return;
649  }
650 
651  // Get current params
652  $params = explode('&', $_SERVER['QUERY_STRING']);
653  $count_params = count($params);
654  for ($i = 0; $i < $count_params; ++$i) {
655  if (preg_match('/^page=/', $params[$i])) {
656  unset($params[$i]);
657  }
658  }
659 
660  $params = explode('&', implode('&', $params));
661  $params[] = 'page=toutes';
662 
663  // Print links
664  echo '<div class="page-links">
665  Pages&thinsp;:
666  <ul>
667  <li><a href="?'.implode('&', $params).'">Toutes</a>&thinsp;;</li>
668 ';
669 
670  unset($params[count($params) - 1]);
671  $params = explode('&', implode('&', $params));
672 
673  for ($i = 1; $i <= $nb_page; ++$i) {
674  if ($i >= 2) {
675  if ($i === 2) {
676  $params[] = 'page=2';
677  }
678  else {
679  $params[count($params) - 1] = 'page='.$i;
680  }
681  }
682  echo ($i === $num_page
683  ? '<li class="selected"><a>'.$i.'</a></li>
684 '
685  : '<li><a href="?'.implode('&', $params).'">'.$i.'</a></li>
686 ');
687  }
688 
689  echo ' </ul>
690 </div>
691 ';
692 }
693 
695 
696 ?>
697  </header>
698 <?php
699 
700 // Display quotations
701 foreach ($quots as $quot) {
702  echo $quot->to_html($search, true, null,
703  'h2', 'une-OPiCitation.php',
704  'fr');
705 }
706 
707 unset($quot);
708 
709 ?>
710  </main>
711 
712  <nav id="right-panel" aria-haspopup="true">
713  <a class="go-top" href="#top"><span>&uarr;</span></a>
714  <a class="go-bottom" href="#bottom"><span>&darr;</span></a>
715  </nav>
716 
717  <div id="bottom"></div>
718  </body>
719 </html>
if(!isset($_GET['no-link-OPiQuotations'])) endif
nb_to_nb_page($nb_quotations)
Definition: index.php:58
nb_to_offset($nb_quotations)
Definition: index.php:69
print_page_links()
Definition: index.php:642
if(!empty($params)) $search
Definition: index.php:175
$nb_by_page
Definition: index.php:117
$NB_FOR_RANDOM
Definition: index.php:115
$param_key
Definition: index.php:162
if($quot===null) $title
$params
Definition: index.php:122
$param_value
Definition: index.php:163
$url
Definition: index.php:385
Class to get OPiQuotation and informations from the databse.
$ALL_KEYS
Definition: index.php:108
s($n)
Definition: index.php:81
$keywords
Definition: index.php:329
$header
Definition: index.php:318
$SELECTION_LABELS
Definition: index.php:110
$opiquotations
Definition: index.php:94
$num_page
Definition: index.php:118
$LABELS
Definition: index.php:101
$desc
Definition: index.php:371
if($header !==null) $desc_open_graph
Definition: index.php:379
html_text_cut($html_text, $max_length, $hellip='…', $reduce=true)
If length of $html_text <= $max_length characters then return $html_text, else return $html_text cutt...
$param_id
Definition: index.php:176
$lists
Definition: index.php:96
$url_site
Definition: index.php:384
$only_one
Definition: index.php:327