OPiQuotations  v.03.00.00 — April 5, 2019
une-OPiCitation.php
Go to the documentation of this file.
1 <?php /* -*- coding: utf-8 -*- */
2 
3 /** \file une-OPiCitation.php
4  * (November 23, 2018)
5  *
6  * \brief
7  * Little Web application to display one quotation (from OPiCitations)
8  * http://www.opimedia.be/OPiCitations/une-OPiCitation.php
9  *
10  * May be used in an iframe to include in another Web page.
11  *
12  * Piece of OPiQuotations.
13  * https://bitbucket.org/OPiMedia/opiquotations
14  *
15  * GPLv3 --- Copyright (C) 2014, 2015, 2016, 2018 Olivier Pirson
16  * http://www.opimedia.be/
17  *
18  * @package OPiCitations
19  */
20 
21 require_once 'OPiQuotations/log.inc';
22 
23 #DEBUG
24 if (true) {
25  // Development configuration
26  ini_set('display_errors', 'stdout');
27  ini_set('display_startup_errors', 1);
28  ini_set('html_errors', 1);
29 
30  error_reporting(-1);
31 
32  assert_options(ASSERT_ACTIVE, true);
33  assert_options(ASSERT_WARNING, true);
34  assert_options(ASSERT_BAIL, true);
35 }
36 else {
37 #DEBUG_END
38  // Production configuration
39  ini_set('display_errors', 'stderr');
40  ini_set('display_startup_errors', 0);
41  ini_set('html_errors', 0);
42 
43  error_reporting(-1);
44 
45  assert_options(ASSERT_ACTIVE, false);
46  assert_options(ASSERT_WARNING, false);
47  assert_options(ASSERT_BAIL, false);
48 
49  set_error_handler('\OPiQuotations\error_handler');
50 #DEBUG
51 }
52 #DEBUG_END
53 
54 mb_internal_encoding('UTF-8');
55 mb_regex_encoding('UTF-8');
56 mb_http_output('UTF-8');
57 mb_detect_order('UTF-8');
58 
59 
60 require_once 'OPiQuotations/OPiQuotations.inc';
61 
63 
64 
65 // Get quotation
66 if (isset($_GET['id'])) { // specific quotation
67  // GET correct id parameter
68  $id = (int)$_GET['id'];
69 
70  $quot = ((string)$id === $_GET['id']
71  ? $opiquotations->quotation_by_id($id)
72  : null);
73 
74  unset($id);
75 }
76 else { // random quotation
77  $quot = $opiquotations->quotation_by_random();
78 }
79 
80 if ($quot === null) { // incorrect argument or quotation not founded
81  header('Location: http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF']);
82  // Warning: possible infinite loop!
83 
84  exit;
85 }
86 
87 
88 // Init other informations
89 $title = 'une OPiCitations n°'.$quot->id().' &mdash; Dictionnaire de citations';
90 
91 $desc = 'une OPiCitation n°'.$quot->id().' :
92 '.htmlspecialchars($quot->to_text());
93 
96 
97 
98 // Prepare keywords from quotation
99 $keywords = ['citation', 'citations', 'maxime', 'maximes', 'proverbe', 'proverbes', 'littérature', 'français'];
100 
101 $i = 0;
102 foreach ([$quot->subject(), ($quot->is_maxim()
103  ? $quot->nation()
104  : $quot->author()), $quot->work()] as $keyword) {
105  if ($keyword !== null) {
106  if ($i < 2) { // if subject, nation/author then also add pieces
107  $a = explode(' ', $keyword);
108  if (count($a) > 1) {
109  $a[] = $keyword;
110  }
111  }
112  else {
113  $a = [$keyword];
114  }
115 
116  foreach ($a as $keyword) {
117  $keywords[] = htmlspecialchars($keyword);
118  }
119 
120  unset($a);
121  }
122 
123  ++$i;
124 }
125 
126 unset($i);
127 unset($keyword);
128 
129 
130 // Set URL
131 $url_site = 'http://'.$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']).'/';
132 $url = $url_site.basename($_SERVER['PHP_SELF']).'?id='.$quot->id();
134 
135 ?><!DOCTYPE html>
136 <html lang="fr">
137  <head>
138  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
139 
140  <meta name="viewport" content="width=device-width, initial-scale=1">
141 
142  <meta name="author" content="Olivier Pirson">
143  <meta name="description" content="<?php echo $desc; ?>">
144  <meta name="keywords" content="<?php echo implode(',', $keywords); ?>">
145  <meta name="keywords" lang="en" content="quotation,quotations,maxim,maxims,proverb,proverbs,literature,French">
146 
147  <title><?php echo $title; ?></title>
148 
149  <link rel="stylesheet" type="text/css" href="/OPiCitations/public/css/one-OPiQuotation.min.css">
150 
151  <script src="/OPiCitations/public/js/one-OPiQuotation.automatic-min.js" async="async"></script>
152 
153  <link rel="icon" type="image/x-icon" href="/OPiCitations/public/img/one-OPiQuotation-32x32.ico">
154 
155  <link rel="canonical" href="<?php echo $url; ?>">
156 
157  <meta property="og:image" content="<?php echo $url_site; ?>public/img/one-OPiQuotation<?php
158 
159 if ($quot->is_maxim()) {
160  echo '-maxim';
161 }
162 
163 ?>-256x256-t.png">
164  <meta property="og:description" content="<?php echo $desc_open_graph; ?>">
165  <meta property="og:title" content="<?php echo $title; ?>">
166  <meta property="og:type" content="website">
167  <meta property="og:url" content="<?php echo $url; ?>">
168 
169  <meta name="msapplication-TileColor" content="#fdfdd0">
170  <meta name="msapplication-square150x150logo" content="/OPiCitations/public/img/one-OPiQuotation-64x64-t.png">
171  </head>
172  <body>
173  <main>
174 <?php
175 
176 // Display quotation
177 echo $quot->to_html(null, true, '_blank',
178  'h1', 'une-OPiCitation.php',
179  'fr');
180 
181 ?>
182  </main>
183 <?php if (!isset($_GET['no-link-OPiQuotations'])): ?>
184  <footer>
185  <a href="<?php echo $url_site; ?>" target="_blank">D&rsquo;autres citations sur <span>O<span class="surname">Pi</span>Citations</span></a>
186  </footer>
187  </body>
188 <?php endif; ?>
189 </html>
if(!isset($_GET['no-link-OPiQuotations'])) endif
$keywords
if($quot===null) $title
$desc_open_graph
Class to get OPiQuotation and informations from the databse.
$url_opicitations
$opiquotations
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...