OPiQuotations  v.02.00.00 — October 26, 2015
 All Classes Namespaces Files Functions Variables Pages
uneOPiCitation.php
Go to the documentation of this file.
1 <?php /* -*- coding: utf-8 -*- */
2 
3 /** \file uneOPiCitation.php
4  * (October 25, 2015)
5  *
6  * \brief
7  * Little Web application to display one quotation (from OPiCitations)
8  * http://www.opimedia.be/OPiCitations/uneOPiCitation.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 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  if ($quot === null) { // incorrect argument or quotation not founded
75  header('Location: http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF']);
76 
77  exit;
78  }
79 
80  unset($id);
81 }
82 else { // random quotation
83  $quot = $opiquotations->quotations_by_random()[0];
84 }
85 
86 
87 // Init other informations
88 $title = 'une OPiCitations n°'.$quot->id().' &mdash; Dictionnaire de plus de 3000 citations';
89 
90 $desc = 'une OPiCitation n°'.$quot->id().' :
91 '.htmlspecialchars($quot->to_text());
92 
95 
96 
97 // Prepare keywords from quotation
98 $keywords = ['citation', 'citations', 'maxime', 'maximes', 'proverbe', 'proverbes', 'littérature', 'français'];
99 
100 $i = 0;
101 foreach ([$quot->subject(), ($quot->is_maxim()
102  ? $quot->nation()
103  : $quot->author()), $quot->work()] as $keyword) {
104  if ($keyword !== null) {
105  if ($i < 2) { // if subject, nation/author then also add pieces
106  $a = explode(' ', $keyword);
107  if (count($a) > 1) {
108  $a[] = $keyword;
109  }
110  }
111  else {
112  $a = [$keyword];
113  }
114 
115  foreach ($a as $keyword) {
116  $keywords[] = htmlspecialchars($keyword);
117  }
118 
119  unset($a);
120  }
121 
122  ++$i;
123 }
124 
125 unset($i);
126 unset($keyword);
127 
128 
129 // Set URL
130 $url_site = 'http://'.$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']).'/';
131 $url = $url_site.basename($_SERVER['PHP_SELF']).'?id='.$quot->id();
132 
133 ?><!DOCTYPE html>
134 <html lang="fr">
135  <head>
136  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
137 
138  <meta name="viewport" content="width=device-width, initial-scale=1">
139 
140  <meta name="author" content="Olivier Pirson">
141  <meta name="description" content="<?php echo $desc; ?>">
142  <meta name="keywords" content="<?php echo implode(',', $keywords); ?>">
143  <meta name="keywords" lang="en" content="quotation,quotations,maxim,maxims,proverb,proverbs,literature,French">
144 
145  <title><?php echo $title; ?></title>
146 
147  <link rel="stylesheet" type="text/css" href="public/css/oneOPiQuotation.min.css">
148 
149  <script type="text/javascript">window.___gcfg = {lang: 'fr', parsetags: 'explicit'};</script>
150  <script type="text/javascript" src="http://platform.twitter.com/widgets.js" async="async"></script>
151  <script type="text/javascript" src="http://connect.facebook.net/fr_FR/sdk.js" async="async"></script>
152  <script type="text/javascript" src="https://apis.google.com/js/platform.js" async="async"></script>
153  <script type="text/javascript" src="public/js/oneOPiQuotation.automatic-min.js" async="async"></script>
154 
155  <link rel="icon" type="image/x-icon" href="public/img/oneOPiQuotation-32x32.ico">
156 
157  <link rel="canonical" href="<?php echo $url; ?>">
158 
159  <meta property="og:image" content="<?php echo $url_site; ?>public/img/oneOPiQuotation<?php
160 
161 if ($quot->is_maxim()) {
162  echo '-maxim';
163 }
164 
165 ?>-256x256-t.png">
166  <meta property="og:description" content="<?php echo $desc_open_graph; ?>">
167  <meta property="og:title" content="<?php echo $title; ?>">
168  <meta property="og:type" content="website">
169  <meta property="og:url" content="<?php echo $url; ?>">
170 
171  <meta name="msapplication-TileColor" content="#fdfdd0">
172  <meta name="msapplication-square150x150logo" content="public/img/oneOPiQuotation-64x64-t.png">
173  </head>
174  <body>
175  <main>
176 <?php
177 
178 // Display quotation
179 echo $quot->to_html(null, true, '_blank', 'h1');
180 
181 
182 // Sharing buttons Twitter, Facebook and Google+
183 $max_length = 140 - 22 - 1; // 22 for length of short url
184 $quot_short = htmlspecialchars($quot->to_text_twitter(null, null, $max_length));
185 
186 echo ' <footer id="sharing-global">
187  Partager cette citation&thinsp;:
188  <ul>
189  <li>
190  <a class="twitter-share-button" href="https://twitter.com/share" data-lang="fr" data-text="', $quot_short, '" data-url="', $url, '"',
191  (mb_strlen($quot_short) + 21 <= $max_length
192  ? ' data-via="OPiCitationJour"' # ' via @OPiCitationJour': length 21
193  : ''), '></a>
194  <li>
195  <div class="fb-like" data-href="', $url, '" data-layout="button_count" data-share="true" data-show-faces="true"></div>
196  <li>
197  <div class="g-plus" data-action="share" data-annotation="bubble" data-href="', $url, '" data-width="120"></div>
198  </ul>
199  </footer>
200 ';
201 
202 ?>
203  </main>
204 <?php if (!isset($_GET['no-link-OPiQuotations'])): ?>
205  <footer>
206  &rarr;
207  <a href="<?php echo $url_site; ?>" target="_blank">D&rsquo;autres citations sur <span>O<span class="surname">Pi</span>Citations</span></a>
208  </footer>
209  </body>
210 <?php endif; ?>
211 </html>