88 namespace OPiQuotations;
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);
271 assert(
'is_int($id)');
278 $quots = $this->db->query_quotations(
'WHERE `id`='.(
int)$id.
'');
293 return $this->db->query_quotations(
'',
294 'ORDER BY `text_stripped` COLLATE utf8_unicode_ci');
305 return $this->db->query_quotations(
'WHERE `is_marked`',
306 'ORDER BY `text_stripped` COLLATE utf8_unicode_ci');
320 assert(
'is_string($author)');
323 return $this->db->query_quotations(
'WHERE NOT `is_maxim` AND `author` LIKE \'%'.$this->db->escape($author).
'%\' COLLATE utf8_unicode_ci',
324 'ORDER BY `author`, `text_stripped` COLLATE utf8_unicode_ci');
338 assert(
'is_array($ids)');
341 foreach($ids as &$id) {
343 assert(
'is_int($id)');
352 : $this->db->query_quotations(
'WHERE `id` IN ('.implode(
',', $ids).
')'));
366 assert(
'is_string($nation)');
369 return $this->db->query_quotations(
'WHERE `is_maxim` AND `nation` LIKE \'%'.$this->db->escape($nation).
'%\' COLLATE utf8_unicode_ci',
370 'ORDER BY `nation`, `text_stripped` COLLATE utf8_unicode_ci');
389 assert(
'is_int($nb)');
391 assert(
'($label === null) || is_string($label)');
394 if ($label === null) {
395 return $this->db->query_quotations(
'',
396 'ORDER BY RAND() LIMIT '.(
int)$nb);
399 $label = $this->db->escape($label);
400 $quots = $this->db->query_quotations(
'WHERE `id` NOT IN (SELECT `quotation_id` FROM `_selected_label` WHERE `label` = \''.$label.
'\')
',
401 'ORDER BY RAND() LIMIT
'.(int)$nb);
403 if (!empty($quots)) {
405 foreach ($quots as $quot) {
406 $query[] = '(
'.$quot->id().', \
''.$label.
'\', UTC_TIMESTAMP())
';
408 $query = 'INSERT INTO `_selected_label` (`quotation_id`, `label`, `datetime_utc`) VALUES
412 $this->db->query_insert($query);
428 public function quotations_by_subject($subject) {
430 assert('is_string($subject)
');
433 return $this->db->query_quotations('WHERE `subject` LIKE \
'%'.$this->db->escape($subject).
'%\' COLLATE utf8_unicode_ci',
434 'ORDER BY `subject`, `text_stripped` COLLATE utf8_unicode_ci');
448 assert(
'is_string($text)');
451 return $this->db->query_quotations(
'WHERE `text` LIKE \'%'.$this->db->escape(
$text).
'%\' COLLATE utf8_unicode_ci',
452 'ORDER BY `text_stripped` COLLATE utf8_unicode_ci');
466 assert(
'is_string($translation)');
469 return $this->db->query_quotations(
'WHERE `translation` LIKE \'%'.$this->db->escape($translation).
'%\' COLLATE utf8_unicode_ci',
470 'ORDER BY `translation_stripped` COLLATE utf8_unicode_ci');
484 assert(
'is_string($work)');
487 return $this->db->query_quotations(
'WHERE NOT `is_maxim` AND `work` LIKE \'%'.$this->db->escape($work).
'%\' COLLATE utf8_unicode_ci',
488 'ORDER BY `work`, `text_stripped` COLLATE utf8_unicode_ci');