OPiQuotations  v.03.00.00 — April 5, 2019
OPiQuotations-sharing.php
Go to the documentation of this file.
1 <?php /* -*- coding: utf-8 -*- */
2 
3 /** \file OPiQuotations-sharing.php
4  * (April 5, 2019)
5  *
6  * \brief
7  * Return list of sharing buttons in a HTML format.
8  *
9  * Piece of OPiQuotations.
10  * https://bitbucket.org/OPiMedia/opiquotations
11  *
12  * GPLv3 --- Copyright (C) 2016, 2017, 2018, 2019 Olivier Pirson
13  * http://www.opimedia.be/
14  *
15  * @package OPiCitations
16  */
17 
18 if (!isset($_GET['id'])) {
19  return;
20 }
21 
22 
23 require_once 'OPiQuotations/log.inc';
24 
25 #DEBUG
26 if (true) {
27  // Development configuration
28  ini_set('display_errors', 'stdout');
29  ini_set('display_startup_errors', 1);
30  ini_set('html_errors', 1);
31 
32  error_reporting(-1);
33 
34  assert_options(ASSERT_ACTIVE, true);
35  assert_options(ASSERT_WARNING, true);
36  assert_options(ASSERT_BAIL, true);
37 }
38 else {
39 #DEBUG_END
40  // Production configuration
41  ini_set('display_errors', 'stderr');
42  ini_set('display_startup_errors', 0);
43  ini_set('html_errors', 0);
44 
45  error_reporting(-1);
46 
47  assert_options(ASSERT_ACTIVE, false);
48  assert_options(ASSERT_WARNING, false);
49  assert_options(ASSERT_BAIL, false);
50 
51  set_error_handler('\OPiQuotations\error_handler');
52 #DEBUG
53 }
54 #DEBUG_END
55 
56 mb_internal_encoding('UTF-8');
57 mb_regex_encoding('UTF-8');
58 mb_http_output('UTF-8');
59 mb_detect_order('UTF-8');
60 
61 
62 require_once 'OPiQuotations/OPiQuotations.inc';
63 
65 
66 
67 $id = (int)$_GET['id'];
68 $quot = $opiquotations->quotation_by_id($id);
69 if ($quot === null) {
70  return;
71 }
72 $url = 'http://www.opimedia.be/OPiCitations/?id='.$id;
73 
75 $max_length = $twitter_max_length - 23 - 1; // 23 for length of short url
76 $quot_short = $quot->to_text_twitter(null, null, $max_length);
77 $quot_short_length = mb_strlen($quot_short) + 24;
78 $quot_short .= ' '.$url;
79 
81 
82 $encoded_quot_all = rawurlencode($quot->to_text(true, 'fr', $url, true, array('Web')));
83 $encoded_title = rawurlencode('OPiCitation n°'.$id
84  .(!$quot->is_maxim() && $quot->author()
85  ? ' ('.$quot->author().')'
86  : ($quot->is_maxim() && $quot->nation()
87  ? ' (nation '.$quot->nation().')'
88  : '')));
89 $encoded_url = rawurlencode($url);
90 
91 unset($id);
92 unset($quot);
93 unset($url);
94 
95 // e-mail, diaspora*, Facebook, LinkedIn, Twitter
96 ?>
97 <li>
98  <a rel="nofollow" href="/OPiCitations/public/php/simple-diaspora-sharing-button/selectpod.php?title=<?php
99 echo $encoded_title;
100 ?>&amp;url=<?php
101 echo $encoded_url;
102 ?>&amp;notes=<?php
103 echo $encoded_quot_all.rawurlencode('
104 ');
105 ?>" target="_blank" title="Partager sur diaspora*"><img src="/OPiCitations/public/img/diaspora-t.png" width="32" height="32" alt="Partager sur diaspora*"></a>
106 </li>
107 <li>
108  <a rel="nofollow" href="mailto:?subject=<?php
109 echo $encoded_title;
110 ?>&amp;body=<?php
111 echo $encoded_quot_all.rawurlencode('
112 ');
113 ?>" title="Envoyer par e-mail"><img src="/OPiCitations/public/img/sharing/Email-t.png" width="32" height="32" alt="Envoyer par e-mail"></a>
114 </li>
115 <li>
116  <a rel="nofollow" href="https://www.facebook.com/sharer/sharer.php?u=<?php
117 echo $encoded_url;
118 ?>" target="_blank" title="Partager sur Facebook"><img src="/OPiCitations/public/img/sharing/Facebook-t.png" width="32" height="32" alt="Partager sur Facebook"></a>
119 </li>
120 <li>
121  <a rel="nofollow" href="https://www.linkedin.com/shareArticle?mini=true&amp;title=<?php
122 echo $encoded_title;
123 ?>&amp;url=<?php
124 echo $encoded_url;
125 ?>&amp;source=<?php
126 echo $encoded_url;
127 ?>&amp;summary=<?php
128 echo $encoded_quot_all;
129 ?>" target="_blank" title="Partager sur LinkedIn"><img src="/OPiCitations/public/img/sharing/LinkedIn-t.png" width="32" height="32" alt="Partager sur LinkedIn"></a>
130 </li>
131 <li>
132  <a rel="nofollow" href="https://twitter.com/intent/tweet?text=<?php
133 echo $encoded_quot_short;
134 if ($quot_short_length + 21 <= $twitter_max_length) {
135  echo '&amp;via=OPiCitationJour'; # ' via @OPiCitationJour': length 21
136 }
137 ?>" target="_blank" title="Tweeter"><img src="/OPiCitations/public/img/sharing/Twitter-t.png" width="32" height="32" alt="Tweeter"></a>
138 </li>
139 <?php
140 
141 #DEBUG
142 if (true) {
143  echo '<li style="background-color:#f0f0f0; border:1px solid black; left:-3em; position:absolute; top:-1em; z-index:10001" onclick="this.style.display=\'none\';"><pre style="margin:0">
144 ';
145  echo '<div style="border-bottom:1px solid black">title: ';
146  var_dump($encoded_title);
147  echo '</div><div style="border-bottom:1px solid black">URL: ';
148  var_dump($encoded_url);
149  echo '</div><div style="border-bottom:1px solid black">short:<br>';
150  var_dump($encoded_quot_short);
151  echo '</div><div style="border-bottom:1px solid black">text:<br>';
152  var_dump($encoded_quot_all);
153  echo '</div></pre></li>
154 ';
155  echo '<li style="background-color:white; border:1px solid black; left:-3em; position:absolute; top:-2em; z-index:10002" onclick="this.style.display=\'none\';"><pre style="margin:0">
156 ';
157  echo '<div style="border-bottom:1px solid black">title: ';
158  var_dump(rawurldecode($encoded_title));
159  echo '</div><div style="border-bottom:1px solid black">URL: ';
160  var_dump(rawurldecode($encoded_url));
161  echo '</div><div style="border-bottom:1px solid black">short:<br>';
162  var_dump(rawurldecode($encoded_quot_short));
163  echo '</div><div style="border-bottom:1px solid black">short normalized:<br>';
164  $encoded_quot_short_normalized = Normalizer::normalize($quot_short, Normalizer::FORM_C);
165  var_dump($encoded_quot_short_normalized);
166  echo '</div><div style="border-bottom:1px solid black">text:<br>';
167  var_dump(rawurldecode($encoded_quot_all));
168  echo '</div></pre></li>
169 ';
170 }
171 #DEBUG_END
172 
173 ?>
174 <li class="close" onclick="sharingClose(this); return false;">&times;</li>
if($quot===null) $url
Class to get OPiQuotation and informations from the databse.