47 $subject=null, $nation_author=null, $work=null,
50 $is_misattributed=
false) {
52 assert(
'is_int($id)');
54 assert(
'is_string($text)');
55 assert(
'is_bool($is_maxim)');
56 assert(
'is_bool($is_marked)');
57 assert(
'($translation === null) || is_string($translation)');
58 assert(
'($subject === null) || is_string($subject)');
59 assert(
'($nation_author === null) || is_string($nation_author)');
60 assert(
'($work === null) || is_string($work)');
61 assert(
'($text_lang === null) || is_string($text_lang)');
62 assert(
'($selections === null) || is_array($selections)');
63 assert(
'is_bool($is_misattributed)');
68 $this->text_lang = $text_lang;
69 $this->maxim = $is_maxim;
70 $this->marked = $is_marked;
71 $this->translation = $translation;
72 $this->subject = $subject;
73 $this->misattributed = $is_misattributed;
77 assert(
'$work === null');
80 $this->nation = $nation_author;
83 $this->author = $nation_author;
87 $this->selections = ($selections === null
110 assert(
'is_string($s)');
114 $a = preg_split(
'/(<.*?()>)/', $s, -1, PREG_SPLIT_DELIM_CAPTURE);
117 foreach ($a as &$s) {
118 if (!preg_match(
'/(<.*?()>)/', $s)) {
119 $s = preg_replace(
'/\-/',
120 '<span class="Comme-fix">-</span>', $s);
139 assert(
'is_string($s)');
142 $a = explode(
' ', $s);
145 assert(
'!empty($a)');
148 $a[count($a) - 1] =
'#'.$a[count($a) - 1];
150 return implode(
' ', $a);
168 assert(
'is_string($s)');
169 # assert('preg_match(\'/ $/\', $s) === 0'); // check if no final space 172 $s = preg_replace(
'/<(b|c|i|sub|sup|\/b|\/c|\/i|\/sub|\/sup)>/',
'@@@#$1#@@@', $s);
174 $s = htmlspecialchars($s);
177 $s = preg_replace(
'/@@@#(b|i|sub|sup|\/b|\/i|\/sub|\/sup)#@@@/',
'<$1>', $s);
178 $s = preg_replace(
'/@@@#c#@@@/',
'<span class="block-center">', $s);
179 $s = preg_replace(
'/@@@#c#@@@/',
'<span class="block-center">', $s);
180 $s = preg_replace(
'/@@@#\/c#@@@\n?/',
'</span>', $s);
183 $s = preg_replace(
'/¨(.+)\n?/',
'<span class="block-right">$1</span>', $s);
186 $s = preg_replace(
'/« /',
'« ', $s);
187 $s = preg_replace(
'/ (»|!|\?)/',
' $1', $s);
190 $s = preg_replace(
'/ (:|;)/',
'<span class="nowrap"> $1</span>', $s);
193 $s = preg_replace(
'/(^|\n) /',
'$1  ', $s);
194 $s = preg_replace(
'/ /',
' ', $s);
195 $s = preg_replace(
'/(^|\n) /',
' ', $s);
198 $s = preg_replace(
'/\n/',
'<br>', $s);
201 # assert('preg_match(\'/¨/\', $s) === 0'); // check if no character ¨ 202 # assert('preg_match(\'/\\\'/\', $s) === 0'); // check if no character ' (use ’ instead) 221 assert(
'is_string($s)');
222 assert(
'($search === null) || is_string($search)');
228 $pieces = preg_split(
'/(<.+?()>|&.+?;)/', $s, -1, PREG_SPLIT_DELIM_CAPTURE);
229 foreach ($pieces as &$piece) {
230 if ((preg_match(
'/^<.+>$/', $piece) !== 1) && (preg_match(
'/^&.+;$/', $piece)) !== 1) {
231 $piece = preg_replace(
'/('.preg_quote(
$search,
'/').
')/i',
'<mark>$1</mark>', $piece);
235 return implode($pieces);
257 assert(
'is_string($message)');
258 assert(
'is_string($language)');
261 $DICTIONARY = array(
'Language:' => array(
'fr' =>
'Langue :'),
262 'Share' => array(
'fr' =>
'Partager'),
263 'Associate link:' => array(
'fr' =>
'Lien associé :'),
265 'maxim' => array(
'fr' =>
'maxime'),
267 'Misattributed to' => array(
'fr' =>
'Attribuée de façon erronée à'),
269 'en' => array(
'en' =>
'English',
271 'de' => array(
'en' =>
'German',
273 'el' => array(
'en' =>
'Greek',
275 'es' => array(
'en' =>
'Spanish',
277 'fr' => array(
'en' =>
'French',
279 'la' => array(
'en' =>
'Latin',
281 'nl' => array(
'en' =>
'Dutch',
282 'fr' =>
'néerlandais'),
285 if (empty($DICTIONARY[$message])) {
289 $translations = $DICTIONARY[$message];
291 return (empty($translations[$language])
293 : $translations[$language]);
317 public function id() {
342 return $this->marked;
354 return $this->misattributed;
378 return $this->selections;
404 return $this->subject;
426 return $this->text_lang;
478 $subject_tag=
'h2', $one_OPiQuotation_link=
'une-OPiCitation.php',
481 assert(
'($search === null) || is_string($search)');
482 assert(
'is_bool($add_link)');
483 assert(
'($link_target === null) || is_string($link_target)');
484 assert(
'is_string($subject_tag)');
485 assert(
'is_string($one_OPiQuotation_link)');
486 assert(
'is_string($language)');
489 $html_link_target = ($link_target
490 ?
' target="'.$link_target.
'"' 494 $is_marked = ($this->is_marked()
498 $a = array($this->is_maxim()
499 ?
'<section id="maxim-'.$this->
id().
'" class="maxim'.$is_marked.
'">' 500 :
'<section id="quotation-'.$this->id().
'" class="quotation'.$is_marked.
'">');
509 if ($this->is_marked()) {
510 $a[] =
' <aside class="mark"></aside>';
514 $url =
'http://'.$_SERVER[
'HTTP_HOST'].dirname($_SERVER[
'PHP_SELF']).
'/';
517 $a[] =
' <nav class="id"> 519 ?
' <a href="./?id='.$this->id().
'"'.$html_link_target.
'>'.$this->id().
'</a> 520 <a rel="nofollow" class="one-OPiQuotation" href="'.$one_OPiQuotation_link.
'?id='.$this->id().
'" target="_blank">❶</a> 521 <div class="sharing"><span onclick="sharingOpen(this, '.$this->id().
'); return false;">'.OPiQuotation::_translate_message(
'Share', $language).
'</span></div>' 522 .Selection::_selections_to_html_ul($this->selections(), $link_target)
526 if ($this->subject() !== null) {
527 $html = OPiQuotation::_highlight_html(htmlspecialchars($this->subject()),
$search);
528 $a[] =
' <'.$subject_tag.
' class="subject">' 530 ?
'<a href="./?subject='.rawurlencode($this->subject()).
'"'.$html_link_target.
'>'.$html.
'</a>' 531 : $html).
'</'.$subject_tag.
'>';
534 $a[] =
' <'.$subject_tag.
' class="no-display">' 537 :
'quotation').
'</'.$subject_tag.
'>';
544 $text_lang = ($this->text_lang() === null
546 :
' lang="'.$this->text_lang().
'"');
547 $text_lang_title = ($this->text_lang() === null
549 :
' title="'.OPiQuotation::_translate_message(
'Language:', $language).
' '.OPiQuotation::_translate_message($this->text_lang(), $language).
'"');
551 if ($this->translation() === null) {
552 $a[] =
' <div class="text"'.$text_lang_title.
'><cite'.$text_lang.
'>'.OPiQuotation::_highlight_html(OPiQuotation::_format_correct_html($this->text()),
$search).
'</cite></div>';
555 $a[] =
' <div class="text_translation"> 556 <div class="text"'.$text_lang_title.
'><cite'.$text_lang.
'>'.OPiQuotation::_highlight_html(OPiQuotation::_format_correct_html($this->text()),
$search).
'</cite></div> 557 <div class="translation"><cite>'.OPiQuotation::_highlight_html(OPiQuotation::_format_correct_html($this->translation()),
$search).
'</cite></div> 562 unset($text_lang_title);
568 if ($this->is_maxim()) {
570 assert(
'$this->author() === null');
571 assert(
'$this->work() === null');
574 if ($this->nation() !== null) {
575 $html = OPiQuotation::_highlight_html(htmlspecialchars($this->nation()),
$search);
576 $a[] =
' <div class="nation">' 577 .($this->is_misattributed()
578 ?
'('.OPiQuotation::_translate_message(
'Misattributed to', $language).
') ' 581 ?
'<a href="./?nation='.rawurlencode($this->nation()).
'"'.$html_link_target.
'>'.OPiQuotation::_translate_message(
'maxim', $language).
' '.$html.
'</a>' 582 : OPiQuotation::_translate_message(
'maxim', $language).
' '.$html).
'</div>';
587 assert(
'$this->nation() === null');
590 if ($this->author() !== null) {
591 $html = OPiQuotation::_highlight_html(htmlspecialchars($this->author()),
$search);
592 $a[] =
' <div class="author">' 593 .($this->is_misattributed()
594 ?
'('.OPiQuotation::_translate_message(
'Misattributed to', $language).
') ' 597 ?
'<a href="./?author='.rawurlencode($this->author()).
'"'.$html_link_target.
'>'.$html.
'</a>' 601 if ($this->work() !== null) {
602 $html = OPiQuotation::_highlight_html(htmlspecialchars($this->work()),
$search);
603 $a[] =
' <div class="work">' 605 ?
'<a href="./?work='.rawurlencode($this->work()).
'"'.$html_link_target.
'>'.$html.
'</a>' 614 return OPiQuotation::_add_comme_fix(implode(
' 643 public function to_text($add_hashtags=
false, $language=
'en',
$url=
'', $add_subject=
false, $add_selections=null) {
645 assert(
'is_bool($add_hashtags)');
646 assert(
'is_string($language)');
647 assert(
'is_string($add_url)');
648 assert(
'is_bool($add_subject)');
649 assert(
'($add_selections === null) || is_array($add_selections)');
652 $quot = trim($this->text());
655 $quot = preg_replace(
'/<sub>(.)<\/sub>/',
'_$1',
$quot);
656 $quot = preg_replace(
'/<sub>(.+?)<\/sub>/',
'_{$1}',
$quot);
657 $quot = preg_replace(
'/<sup>(.)<\/sup>/',
'^$1',
$quot);
658 $quot = preg_replace(
'/<sup>(.+?)<\/sup>/',
'^{$1}',
$quot);
660 $quot = preg_replace(
'/<(b|c|i|sub|sup|\/b|\/c|\/i|\/sub|\/sup)>/',
'',
$quot);
663 $quot =
'“'.$quot.
'”';
665 if ($this->translation() !== null) {
666 $translation = trim($this->translation());
668 $translation = preg_replace(
'/<(b|c|i|sub|sup|\/b|\/c|\/i|\/sub|\/sup)>/',
'', $translation);
669 $translation = preg_replace(
'/¨/',
'', $translation);
681 if ($this->is_maxim()) {
682 if ($this->nation() !== null) {
683 $nation = $this->nation();
685 $nation = OPiQuotation::_add_hashtag($nation);
687 if ($this->is_misattributed()) {
688 $nation = OPiQuotation::_translate_message(
'Misattributed to', $language).
' '.$nation;
691 ('.OPiQuotation::_translate_message(
'maxim', $language).
' '.$nation.
')';
695 if ($this->author() !== null) {
696 $author = $this->author();
698 $author = OPiQuotation::_add_hashtag($author);
700 if ($this->is_misattributed()) {
701 $author = OPiQuotation::_translate_message(
'Misattributed to', $language).
' '.$author;
703 if ($this->work() !== null) {
713 else if ($this->work() !== null) {
715 ('.$this->work().
')';
724 if ($add_subject && ($this->subject() !== null)) {
728 :
'').$this->subject();
731 $selections = $this->selections();
732 if (!empty($add_selections) && !empty($selections)) {
733 foreach ($add_selections as $label) {
735 if ($selection->label() === $label) {
737 '.OPiQuotation::_translate_message(
'Associate link:', $language).
' '.$selection->url();
766 assert(
'is_string($url)');
767 assert(
'is_string($language)');
770 return $this->to_text(
true, $language,
$url,
true, $add_selections);
800 assert(
'($url === null) || is_string($url)');
801 assert(
'($short_url_length === null) || is_int($short_url_length)');
802 assert(
'($short_url_length === null) || ($short_url_length >= 0)');
803 assert(
'is_int($max_length)');
804 assert(
'$max_length > 0');
805 assert(
'is_string($language)');
808 $quot = $this->to_text(
true, $language);
821 $subject = ($this->subject() === null
824 #'.$this->subject());
839 return $this->translation;
968 assert(
'is_string($label)');
969 assert(($datetime_utc === null) || $datetime_utc instanceof \DateTime);
970 assert(
'($url === null) || is_string($url)');
973 $this->label = $label;
974 $this->datetime_utc = ($datetime_utc === null
975 ? new \DateTime(
'now',
new \DateTimeZone(
'UTC'))
998 assert(
'is_array($selections)');
999 assert(
'($link_target === null) || is_string($link_target)');
1002 if (count($selections) === 0) {
1008 $a[] = $selection->to_html($link_target);
1012 <ul class="selections"> 1027 return $this->datetime_utc;
1039 return $this->label;
1056 public function to_html($link_target, $tag=
'li') {
1058 assert(
'($link_target === null) || is_string($link_target)');
1059 assert(
'is_string($tag)');
1062 $title = htmlspecialchars($this->label());
1063 if ($this->datetime_utc() >
new \DateTime(
'0000-00-00')) {
1064 $title.=
' — '.htmlspecialchars($this->datetime_utc()->format(
'Y-m-d'));
1067 $content = (preg_match(
'/^Web( (\d+))?/', $this->label())
1071 return '<'.$tag.
' class="'.explode(
' ', $this->label())[0].
'" title="'.
$title.
'">' 1072 .($this->url() === null
1073 ?
'<span>'.$content.
'</span>' 1074 :
'<a rel="nofollow" href="'.$this->url().
'"' 1076 ?
' target="'.$link_target.
'"' 1077 :
'').
'>'.$content.
'</a>')
$author
null or the author of the quotation if is a quotation, else null.
$text
Text of the quotation/maxim.
$work
null or the work of the quotation if is a quotation, else null.
if(!empty($params)) $search
to_html($search=null, $add_link=true, $link_target=null, $subject_tag='h2', $one_OPiQuotation_link='une-OPiCitation.php', $language='en')
Return the complete quotation/maxim in a HTML format.
to_text_twitter($url=null, $short_url_length=null, $max_length=279, $language='en')
Return the quotation/maxim with its author/nation and work in short text format to post to Twitter...
$text_lang
Language of text, in ISO 639-1 code: https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes.
to_text($add_hashtags=false, $language='en', $url='', $add_subject=false, $add_selections=null)
Return the quotation/maxim with its author/nation and work in text format (strip HTML tags <b>...
selections()
Return the list of Selection.
$datetime_utc
date/time of the selection.
static _format_correct_html($s)
Return $s formatted in HTML to be displayed.
text_cut($text, $max_length, $hellip='…', $reduce=true)
If length of $text <= $max_length characters then return $text, else return $text cutted added of $he...
id()
Return the id of the quotation/maxim.
$id
The id of the quotation/maxim (must be > 0).
static _selections_to_html_ul($selections, $link_target=null)
Return the list of selections in a HTML format, in a <ul class="selections"> item.
is_maxim()
Return true if is a maxim (of a possibly nation), false if is a quotation (of a possibly author)...
text_lang()
Return null or the language of the text quotation/maxim.
datetime_utc()
Return the date/time of the selection.
text()
Return the text of the quotation/maxim.
$url
null or URL to the quotation in the application.
$nation
null or the nation of the maxim if is a maxim, else null.
to_html($link_target, $tag='li')
Return the selection in a HTML format. By default in a <li> item.
$subject
null or the subject of the quotation/maxim.
$translation
null or the translation of the quotation/maxim.
is_marked()
Return true if is a marked quotation/maxim, else false.
to_text_facebook($url='', $language='en', $add_selections=null)
Return the quotation/maxim with its author/nation and work in text format to post to Facebook...
$label
Label to identify an application that already chosen a quotation.
static _add_comme_fix($s)
Return $s with each '-' replaced by '<span class"Comme-fix">-</span>' to workaround bug with this cha...
static _add_hashtag($s)
Return $s with an adding '#' character before the last word.
static _translate_message($message, $language)
Return a translation of the message in the language.
$is_marked
true if marked quotation/maxim, else false.
subject()
Return null or the subject of the quotation/maxim.
static _highlight_html($s, $search=null)
If $search !== null then each occurence of $search is surrounded by '<mark>' and '</mark>'.
nation()
Return null or the nation of the maxim.
author()
Return null or the author of the quotation.
is_misattributed()
Return true if is the quotation/maxim is misattributed to its author, else false. ...
selections_add($selection)
Add a Selection to the list.
__construct($id, $text, $is_maxim=false, $is_marked=false, $translation=null, $subject=null, $nation_author=null, $work=null, $text_lang=null, $selections=null, $is_misattributed=false)
Construct a quotation/maxim.
work()
Return null or the work of the quotation.
Class quotation (text, author…) or maxim (text, nation…).
translation()
Return null or the translation of the quotation/maxim.
$is_maxim
true if maxim (of a possibly nation), false if quotation (of an possibly author). ...
__construct($label, $datetime_utc, $url=null)
Construct a selection.
$is_misattributed
true if the quotation/maxim is misattributed to its author, else false.
url()
Return null or URL to the quotation in the application.
label()
Return the label used to identify an application that already chosen a quotation. ...