. // It's licensed under the AFFERO GENERAL PUBLIC LICENSE unless stated otherwise. // You can get copies of the licenses here: // http://www.affero.org/oagpl.html // AFFERO GENERAL PUBLIC LICENSE is also included in the file called "COPYING". function tags_normalize_string($string) { $string = html_entity_decode(trim($string), ENT_COMPAT, 'UTF-8'); $string = preg_replace('/-+/', '-', $string); // Don't allow a sequence of more than a "-" $string = preg_replace('/ +,/', ',', $string); // Avoid errors like " ," $string = preg_replace('/[\n\t\r]+/s', ' ', $string); if (!preg_match('/,/', $string)) { // The user didn't put any comma, we add them $string = preg_replace('/ +/', ', ', $string); } $string = preg_replace('/[\.\,] *$/', "", $string); // Clean strange characteres, there are feed reader (including feedburner) that are just too strict and complain loudly $string = preg_replace('/[<>;"\'\]\[&]/', "", $string); return htmlspecialchars(mb_substr(mb_strtolower($string, 'UTF-8'), 0, 80), ENT_COMPAT, 'UTF-8'); } function tags_insert_string( $id_article, $text, $data = 0 ) { global $db; $text = tags_normalize_string( $text ); if( $data == 0 ) $data = time(); $paraules = preg_split( '/[,]+/', $text ); if( $paraules ) { $db->query( "DELETE FROM etiquetes WHERE id_article = $id_article AND lloc = 'article'"); foreach( $paraules as $paraula ) { $paraula = trim( $paraula ); if( mb_strlen( $paraula ) >= 2 && !isset( $inserted[$paraula] ) && !empty( $paraula ) ) { $db->query( "INSERT INTO etiquetes ( lloc, id_article, paraula, data ) values ( 'article', $id_article, '$paraula', from_unixtime( $data ) )"); $inserted[$paraula] = true; } } return true; } return false; } function tags_get_string( $id_article ) { global $db; $counter = 0; $res = $db->get_col("SELECT paraula FROM etiquetes WHERE id_article = $id_article AND lloc = 'article'"); if( !$res ) return false; $text = ''; foreach( $db->get_col( "SELECT paraula FROM etiquetes WHERE id_article = $id_article AND lloc = 'article'" ) as $paraula ) { if( $counter > 0 ) $text .= ', '; $text .= $paraula; $counter++; } return $text; } mola | strubell.cat

Toni Strubell i Trueta


mola