111 assert(
'is_string($html_text)');
112 assert(
'is_int($max_length)');
113 assert(
'is_string($hellip)');
114 assert(
'$max_length >= mb_strlen($hellip)');
115 assert(
'is_bool($reduce)');
121 $i = mb_strrpos($html_text,
'&');
122 if ((
$i !==
false) && (mb_strrpos($html_text,
';',
$i + 1) ===
false)) {
124 $html_text = mb_substr($html_text, 0,
$i).$hellip;
149 assert(
'is_string($text)');
150 assert(
'is_int($max_length)');
151 assert(
'is_string($hellip)');
152 assert(
'$max_length >= mb_strlen($hellip)');
153 assert(
'is_bool($reduce)');
159 $text = preg_replace(
'/\s*\n\s*/',
' 163 $text = preg_replace(
'/[ \t\r\f]+/',
' ',
$text);
185 require_once
'OPiQuotations/Db.inc';
186 require_once
'OPiQuotations/.private/db_login.inc';
188 $this->db =
new Db($db_host, $db_user, $db_password, $db_name);
200 return $this->db->list_to_assoc(
'author');
212 return $this->db->list_to_assoc(
'nation');
223 return $this->db->list_to_assoc(
'subject');
235 return $this->db->list_to_assoc(
'work');
249 public function nb($is_maxim=null) {
251 assert(
'($is_maxim === null) || is_bool($is_maxim)');
254 return $this->db->nb($is_maxim);
274 $data = array($quotation->id(),
275 $this->db->to_string_or_NULL(
$selection->label()),
276 'CONVERT_TZ('.$this->db->to_string(
$selection->datetime_utc()->format(
'Y-m-d H:i:s')).
',\'+00:00\',\'+00:00\')',
277 $this->db->to_string_or_NULL(
$selection->url()));
279 $query =
'INSERT INTO `quotation_selection` (`quotation_id`, `label`, `datetime_utc`, `url`) 280 VALUES ('.implode(
', ', $data).
');';
282 return $this->db->query_insert($query);
299 assert(
'is_int($id)');
306 $quots = $this->db->query_quotations(
'WHERE `id`='.(
int)
$id.
'');
308 return (empty($quots)
328 assert(
'($label === null) || is_string($label)');
331 $quots = $this->quotations_by_random(1, $label);
333 return (empty($quots)
356 assert(
'($limit === null) || (is_int($limit) && ($limit >= 0))');
357 assert(
'($offset === null) || (is_int($offset) && ($offset >= 0))');
360 return $this->db->query_quotations(
'',
361 'ORDER BY `text_stripped` COLLATE utf8_unicode_ci',
373 return $this->db->query_quotations_nb();
394 assert(
'($limit === null) || (is_int($limit) && ($limit >= 0))');
395 assert(
'($offset === null) || (is_int($offset) && ($offset >= 0))');
398 return $this->db->query_quotations(
'WHERE `is_marked`',
399 'ORDER BY `text_stripped` COLLATE utf8_unicode_ci',
411 return $this->db->query_quotations_nb(
'WHERE `is_marked`');
433 assert(
'is_string($author)');
434 assert(
'($limit === null) || (is_int($limit) && ($limit >= 0))');
435 assert(
'($offset === null) || (is_int($offset) && ($offset >= 0))');
438 return $this->db->query_quotations(
'WHERE NOT `is_maxim` AND `author` LIKE \'%'.$this->db->escape($author).
'%\' COLLATE utf8_unicode_ci',
439 'ORDER BY `author`, `text_stripped` COLLATE utf8_unicode_ci',
454 assert(
'is_string($author)');
457 return $this->db->query_quotations_nb(
'WHERE NOT `is_maxim` AND `author` LIKE \'%'.$this->db->escape($author).
'%\' COLLATE utf8_unicode_ci');
479 assert(
'is_array($ids)');
480 assert(
'($limit === null) || (is_int($limit) && ($limit >= 0))');
481 assert(
'($offset === null) || (is_int($offset) && ($offset >= 0))');
484 foreach($ids as &
$id) {
486 assert(
'is_int($id)');
495 : $this->db->query_quotations(
'WHERE `id` IN ('.implode(
',', $ids).
')',
511 assert(
'is_array($ids)');
514 foreach($ids as &
$id) {
516 assert(
'is_int($id)');
525 : $this->db->query_quotations_nb(
'WHERE `id` IN ('.implode(
',', $ids).
')'));
547 assert(
'is_string($nation)');
548 assert(
'($limit === null) || (is_int($limit) && ($limit >= 0))');
549 assert(
'($offset === null) || (is_int($offset) && ($offset >= 0))');
552 return $this->db->query_quotations(
'WHERE `is_maxim` AND `nation` LIKE \'%'.$this->db->escape($nation).
'%\' COLLATE utf8_unicode_ci',
553 'ORDER BY `nation`, `text_stripped` COLLATE utf8_unicode_ci',
568 assert(
'is_string($nation)');
571 return $this->db->query_quotations_nb(
'WHERE `is_maxim` AND `nation` LIKE \'%'.$this->db->escape($nation).
'%\' COLLATE utf8_unicode_ci');
590 assert(
'is_int($nb) && ($limit >= 0)');
592 assert(
'($label === null) || is_string($label)');
595 if ($label === null) {
596 $quots = $this->db->query_quotations(
'',
597 'ORDER BY RAND()', $nb);
600 $label = $this->db->escape($label);
601 $quots = $this->db->query_quotations(
'WHERE `id` NOT IN (SELECT `quotation_id` FROM `quotation_selection` WHERE `label` = \''.$label.
'\')
', 602 'ORDER BY RAND()
', $nb); 625 public function quotations_by_selection_label($label, $limit=null, $offset=null) {
627 assert('is_string($label)
'); 628 assert('($limit === null) || (is_int($limit) && ($limit >= 0))
'); 629 assert('($offset === null) || (is_int($offset) && ($offset >= 0))
'); 632 return $this->db->query_quotations('WHERE `selection_label` =
'.$this->db->to_string($label).' COLLATE utf8_unicode_ci
', 633 'ORDER BY `selection_datetime_utc` DESC, `text_stripped` COLLATE utf8_unicode_ci
', 646 public function quotations_by_selection_label_nb($label) {
648 assert('is_string($label)
'); 651 return $this->db->query_quotations_nb('WHERE `selection_label` =
'.$this->db->to_string($label).' COLLATE utf8_unicode_ci
'); 671 public function quotations_by_subject($subject, $limit=null, $offset=null) {
673 assert('is_string($subject)
'); 676 return $this->db->query_quotations('WHERE `subject` LIKE \
'%'.$this->db->escape($subject).
'%\' COLLATE utf8_unicode_ci',
677 'ORDER BY `subject`, `text_stripped` COLLATE utf8_unicode_ci',
692 assert(
'is_string($subject)');
695 return $this->db->query_quotations_nb(
'WHERE `subject` LIKE \'%'.$this->db->escape($subject).
'%\' COLLATE utf8_unicode_ci');
717 assert(
'is_string($text)');
718 assert(
'($limit === null) || (is_int($limit) && ($limit >= 0))');
719 assert(
'($offset === null) || (is_int($offset) && ($offset >= 0))');
722 return $this->db->query_quotations(
'WHERE `text` LIKE \'%'.$this->db->escape(
$text).
'%\' COLLATE utf8_unicode_ci',
723 'ORDER BY `text_stripped` COLLATE utf8_unicode_ci',
738 assert(
'is_string($text)');
741 return $this->db->query_quotations_nb(
'WHERE `text` LIKE \'%'.$this->db->escape(
$text).
'%\' COLLATE utf8_unicode_ci');
763 assert(
'is_string($translation)');
764 assert(
'($limit === null) || (is_int($limit) && ($limit >= 0))');
765 assert(
'($offset === null) || (is_int($offset) && ($offset >= 0))');
768 return $this->db->query_quotations(
'WHERE `translation` LIKE \'%'.$this->db->escape($translation).
'%\' COLLATE utf8_unicode_ci',
769 'ORDER BY `translation_stripped` COLLATE utf8_unicode_ci',
784 assert(
'is_string($translation)');
787 return $this->db->query_quotations_nb(
'WHERE `translation` LIKE \'%'.$this->db->escape($translation).
'%\' COLLATE utf8_unicode_ci');
809 assert(
'is_string($work)');
810 assert(
'($limit === null) || (is_int($limit) && ($limit >= 0))');
811 assert(
'($offset === null) || (is_int($offset) && ($offset >= 0))');
814 return $this->db->query_quotations(
'WHERE NOT `is_maxim` AND `work` LIKE \'%'.$this->db->escape($work).
'%\' COLLATE utf8_unicode_ci',
815 'ORDER BY `work`, `text_stripped` COLLATE utf8_unicode_ci',
830 assert(
'is_string($work)');
833 return $this->db->query_quotations_nb(
'WHERE NOT `is_maxim` AND `work` LIKE \'%'.$this->db->escape($work).
'%\' COLLATE utf8_unicode_ci');
quotation_by_id($id)
Return the unique quotation/maxim of id $id.
quotations_all_nb()
Return the number of all quotations/maxims.
quotations_by_work_nb($work)
Return the number of all quotations/maxims that are written in work $work.
quotations_by_nation($nation, $limit=null, $offset=null)
Return the list of maxims of nationality $nation.
nb($is_maxim=null)
If $is_maxim === null then return the numbers of quotations/maxims, if $is_maxim === false then retur...
quotation_add_selection($quotation, $selection)
Add the selection to this quotation and updates the DB.
quotations_by_nation_nb($nation)
Return the number of all maxims of nationality $nation.
quotations_by_work($work, $limit, $offset)
Return the list of quotations/maxims that are written in work $work.
__construct()
Connect to the database. See the Db class.
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...
quotation_by_random($label=null)
Return a quotation choose at random. If not available quotation, then return null.
list_nations()
Return a associative table id => array(name, number of use) of elements of the table nation...
quotations_by_author($author, $limit=null, $offset=null)
Return the list of quotations that are written by author $author.
quotations_all($limit=null, $offset=null)
Return the complete list of quotations/maxims.
quotations_by_ids($ids, $limit=null, $offset=null)
Return the list of quotations/maxims of id among $ids.
quotations_by_author_nb($author)
Return the number of all quotations that are written by author $author.
quotations_by_text_nb($text)
Return the number of all quotations/maxims that contains the text $text.
quotations_by_translation_nb($translation)
Return the number of all quotations/maxims with a translation that contains the text $translation...
list_works()
Return a associative table id => array(name, number of use) of elements of the table work...
quotations_by_translation($translation, $limit, $offset)
Return the list of quotations/maxims with a translation that contains the text $translation.
quotations_by_random($nb=1, $label=null)
Return a list of $nb different quotations (if available) choose at random.
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...
list_authors()
Return a associative table id => array(name, number of use) of elements of the table author...
quotations_by_subject_nb($subject)
Return the number of all quotations/maxims of subject $subject.
Class quotation (text, author…) or maxim (text, nation…).
quotations_by_text($text, $limit=null, $offset=null)
Return the list of quotations/maxims that contains the text $text.
quotations_by_ids_nb($ids)
Return the number of all quotations/maxims of id among $ids.
quotations_all_marked_nb()
Return the number of all quotations/maxims that are marked.
quotations_all_marked($limit=null, $offset=null)
Return the list of quotations/maxims that are marked.