root/trunk/includes/functions.inc.php

Revision 51, 20.0 KB (checked in by mat, 6 years ago)

Filtre tous les champs pour le FOAF. Pas terrible (copie du tableau tout ca)
mais on verra a faire mieux plus tard, au moins j'utilise une fonction qui
pourra etre re-utilisable.

Line 
1<?php
2/****************************************************** Open .node ***
3 * Description:   
4 * Status:        Stable.
5 * Author:        Alexandre Dath <alexandre@dotnode.com>
6 * $Id$
7 *
8 * Copyright (C) 2005 Alexandre Dath <alexandre@dotnode.com>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software Foundation,
22 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 ******************** http://opensource.ikse.net/projects/dotnode ***/
24
25
26function tr($str)
27{
28//    error_log('TRANSLATE '.$str.' => '._($str));
29    if(trim($str) == '')
30        return '';
31    else
32        return _($str);
33}
34
35function retreive_url_info($url)
36{                       
37        $url = ereg_replace("^/", "", $url);
38        $token = split('/', $url);
39    if(ereg("\.php$", $token[0]))
40        $token[0] = substr($token[0], 0, -4);
41    return array_map('urldecode', $token);
42}
43
44function get_pref_language_array($str_http_languages)
45{
46  $langs = explode(',',$str_http_languages);
47  $qcandidat = 0;
48  $nblang = count($langs);
49
50  for ($i=0; $i<$nblang; $i++)
51  {
52    for ($j=0; $j<count($langs); $j++) {
53      $lang = trim($langs[$j]); // Supprime les espaces avant et après $lang
54      // Lang est de la forme langue;q=valeur
55     
56      if (!strstr($lang, ';') && $qcandidat != 1) {
57        // Si la chaine ne contient pas de valeur de préférence q
58        $candidat = $lang;
59        $qcandidat = 1;
60        $indicecandidat = $j;
61      }
62      else {
63        // On récupère l'indice q
64        $q = ereg_replace('.*;q=(.*)', '\\1', $lang);
65
66        if ($q > $qcandidat) {
67          $candidat = ereg_replace('(.*);.*', '\\1', $lang); ;
68          $qcandidat = $q;
69          $indicecandidat = $j;     
70        }
71      }
72    }
73   
74    $resultat[$i] = $candidat;
75
76    $qcandidat=0;
77    // On supprime la valeur du tableau
78    unset($langs[$indicecandidat]);   
79    $langs = array_values($langs);
80  }
81  return $resultat;
82}
83
84function build_image_path($id, $makedir=false,$ext='png')
85{
86        $elmt[0] = substr($id, 0, 2);
87        if($makedir) @mkdir(PHOTOPATH.'/'.$elmt[0]);
88        $elmt[1] = substr($id, 2, 2);
89        if($makedir) @mkdir(PHOTOPATH.'/'.$elmt[0].'/'.$elmt[1]);
90        return PHOTOPATH.'/'.$elmt[0].'/'.$elmt[1].'/'.$id.'.'.$ext;
91}
92
93function build_thumb_path($id, $makedir=false, $ext='png')
94{
95        $elmt[0] = substr($id, 0, 2);
96        if($makedir) @mkdir(PHOTOPATH.'/thumb/'.$elmt[0]);
97        $elmt[1] = substr($id, 2, 2);
98        if($makedir) @mkdir(PHOTOPATH.'/thumb/'.$elmt[0].'/'.$elmt[1]);
99        return PHOTOPATH.'/thumb/'.$elmt[0].'/'.$elmt[1].'/'.$id.'.'.$ext;
100}
101
102function build_image_url($id, $ext='png')
103{
104        $elmt[0] = substr($id, 0, 2);
105        $elmt[1] = substr($id, 2, 2);
106        return '/photos/'.$elmt[0].'/'.$elmt[1].'/'.$id.'.'.$ext;
107}
108
109function build_thumb_url($id, $ext='png')
110{
111        $elmt[0] = substr($id, 0, 2);
112        $elmt[1] = substr($id, 2, 2);
113        return '/photos/thumb/'.$elmt[0].'/'.$elmt[1].'/'.$id.'.'.$ext;
114}
115
116function build_album_path($id, $id_image, $makedir=false, $ext='png')
117{
118        $elmt[0] = substr($id, 0, 2);
119        if($makedir) @mkdir(ALBUMPATH.'/'.$elmt[0]);
120        $elmt[1] = substr($id, 2, 2);
121        if($makedir) @mkdir(ALBUMPATH.'/'.$elmt[0].'/'.$elmt[1]);
122        return ALBUMPATH.'/'.$elmt[0].'/'.$elmt[1].'/'.$id_image.'.'.$ext;
123}
124
125function build_album_thumb_path($id, $id_image, $makedir=false, $ext='png')
126{
127        $elmt[0] = substr($id, 0, 2);
128        if($makedir) @mkdir(ALBUMPATH.'/thumb/'.$elmt[0]);
129        $elmt[1] = substr($id, 2, 2);
130        if($makedir) @mkdir(ALBUMPATH.'/thumb/'.$elmt[0].'/'.$elmt[1]);
131        return ALBUMPATH.'/thumb/'.$elmt[0].'/'.$elmt[1].'/'.$id_image.'.'.$ext;
132}
133
134
135function build_album_url($id, $id_image, $ext='png')
136{
137        $elmt[0] = substr($id, 0, 2);
138        $elmt[1] = substr($id, 2, 2);
139        return '/albums/'.$elmt[0].'/'.$elmt[1].'/'.$id_image.'.'.$ext;
140}
141
142function build_album_thumb_url($id, $id_image, $ext='png')
143{
144        $elmt[0] = substr($id, 0, 2);
145        $elmt[1] = substr($id, 2, 2);
146        return '/albums/thumb/'.$elmt[0].'/'.$elmt[1].'/'.$id_image.'.'.$ext;
147}
148
149function build_logo_url($id, $id_image, $ext='png')
150{
151        $elmt[0] = substr($id, 0, 2);
152        $elmt[1] = substr($id, 2, 2);
153        return '/comm_logos/'.$elmt[0].'/'.$elmt[1].'/'.$id_image.'.'.$ext;
154}
155
156function build_logo_thumb_url($id, $id_image, $ext='png')
157{
158        $elmt[0] = substr($id, 0, 2);
159        $elmt[1] = substr($id, 2, 2);
160        return '/comm_logos/thumb/'.$elmt[0].'/'.$elmt[1].'/'.$id_image.'.'.$ext;
161}
162
163
164function insert_image_album($id, $width, $height, $format, $caption)
165{
166    global $db;
167//    $caption = $db->quoteSmart($caption);
168    $db->query('INSERT INTO album SET id=?, width=?, height=?, format=?, caption=?, date=NOW()', array($id, $width, $height, $format, $caption));
169    $insert_id = $db->getOne('SELECT LAST_INSERT_ID()');
170
171    $nb_photos = $db->getOne('SELECT COUNT(id) FROM album WHERE id=?', $id);
172        $db->query('UPDATE cache_user SET nb_photos=? WHERE id=?', array($nb_photos, $id));
173
174    return $insert_id;
175}
176
177function count_image_album($id)
178{
179    global $db;
180    $result = $db->query('SELECT id_image FROM album WHERE id=?', $id);
181    return $result->numRows();
182}
183
184function set_acccess_list($id, $post_access)
185{
186    global $db;
187    foreach($post_access as $table_name=>$values)
188    {
189        foreach($values as $field_name=>$field_access)
190        {
191            switch($field_access)
192            {
193            case 'myself':
194            case 'friends':
195            case 'friends_of_friends':
196            case 'members':
197            case 'everyone':
198                $db->query('DELETE FROM access WHERE id=? AND table_name=? AND field=?', array($id, $table_name, $field_name));
199                $db->query('INSERT INTO access SET id=?, table_name=?, field=?, access=?', array($id, $table_name, $field_name, $field_access));
200            }
201        }
202    }
203
204}
205
206function get_access_list($id, $table)
207{
208    global $db;
209    global $access_fields;
210    $accesses = $db->query('SELECT field, access FROM access WHERE id=? AND table_name=?', array($id, $table));
211    $rval = array();
212    if(!DB::isError($accesses ) )
213        while($access = $accesses->fetchRow())
214        {
215            $rval[$access['field']] = $access['access'];
216        }
217    else
218        error_log($_SERVER['HTTP_HOST'].' | '.__FILE__.' | '.$accesses->getUserInfo());
219
220    if(array_key_exists($table, $access_fields) )
221    foreach($access_fields[$table] as $item=>$value)
222    {
223        if(!array_key_exists($item,$rval) )
224            $rval[$item] = $value;
225    }
226    return $rval;
227}
228
229function access_weight($access_str)
230{
231    switch($access_str)
232    {
233    case 'myself':         return 1;   break;
234    case 'friends':         return 2;   break;
235    case 'friends_of_friends':     return 4;   break;
236    case 'everyone':         return 16;  break;
237    case 'members':
238    default:                       return 8;   break;
239    }
240}
241
242// Il faudrait avoir un objet pour gerer les profiles, ca permettrait
243// de gerer ca beaucoup plus facilement/efficacement.
244function filter_table_with_weight($table, $access, $weight)
245{   
246    foreach ($table as $key => $value)
247    {
248        // on a pas ca dans access? dans le doute, on laisse.
249        if (!array_key_exists($key, $access))
250            continue;
251        if (access_weight($access[$key]) < access_weight($weight))
252        {   
253            // on a pas le droit de l'afficher: on le planque.
254            unset($table[$key]);
255        }
256    }
257    return $table;
258}
259
260
261function get_relation_type($my_id, $my_friends_id, $user_id, $user_friends_id)
262{
263    if($user_id == $my_id)
264    {
265        return 'myself';
266    }
267    elseif(in_array($user_id, $my_friends_id) )
268    {
269        return 'friends';
270    }
271    elseif($intermediaire = array_intersect($session['my_friends_id'], $user['friends_id']))
272    {
273        return  'friends_of_friends';
274    }
275    else
276        return 'members';
277}
278
279function translate_list($list, $labels_tab, $separator=',', $separator_out=', ')
280{
281    $translated_thing = array();                                    // declaration du tableau qui va recevoir les chaines traduites
282    $things = explode($separator, $list);                // on separe ce qu'il y a en base dans un tableau $things
283    foreach($things as $thing)                                      // pour chaque elements du SET
284        array_push($translated_thing, _($labels_tab[$thing])); // on ajoute dans le tableau $translated_thing la traduction du label de la valeur, trouvé dans labels.inc.php
285    return implode($separator_out, $translated_thing);                      // on reforme un truc affichable et on le mets dans $value
286}
287
288function get_cache_user_info($id, $fields=null, $update_friends_order=false)
289{
290    global $db;
291    global $labels;
292
293    global $url_id;
294
295    if(is_null($fields))
296        $fields = 'id, login, fname, lname, nick, country, gender, relationship_status, here_for, nb_friends, friends_id, nb_communities, communities_id, nb_fans, nb_bookmarks, nb_blogs, nb_photos, fun, cool, sexy, photo, join_date';
297
298    $info = $db->getRow('SELECT ! FROM cache_user WHERE id=? OR login=? LIMIT 1', array($fields, $id, $id));
299    if(is_array($info))
300    {
301        $info['photo_path'] = build_image_url($info['id']);
302        $info['thumb_path'] = build_thumb_url($info['id']);
303
304        if(array_key_exists('gender', $info) && $info['gender'] != NULL )
305            $info['gender_t'] = translate_list($info['gender'], $labels['profile']['gender']);
306
307        if(array_key_exists('relationship_status', $info) && $info['relationship_status'] != NULL )
308                        $info['relationship_status_t'] = translate_list($info['relationship_status'], $labels['profile']['relationship_status']);
309
310        if(array_key_exists('here_for', $info) && $info['here_for'] != NULL )
311            $info['here_for_t'] = translate_list($info['here_for'], $labels['profile']['here_for']);
312
313        if(array_key_exists('friends_id', $info) && $info['friends_id'] != NULL)
314        {
315            if(strpos($info['friends_id'],','))
316                $info['friends_id'] = explode(',', $info['friends_id']);
317            else
318                $info['friends_id'] = array($info['friends_id']);
319
320            if($update_friends_order && in_array($_SESSION['my_id'], array_values($info['friends_id'])))
321            {
322                $my_offset = array_search($_SESSION['my_id'], $info['friends_id']);
323                array_splice($info['friends_id'], $my_offset, 1);
324                array_unshift($info['friends_id'], $_SESSION['my_id']);
325                $db->query('UPDATE cache_user SET friends_id=? WHERE id=?', array(implode(',',$info['friends_id']), $url_id));
326            }
327
328        }
329        else
330            $info['friends_id'] = array();
331
332        if(array_key_exists('communities_id', $info) && $info['communities_id'] != NULL)
333            if(strpos($info['communities_id'],','))
334                    $info['communities_id'] = explode(',', $info['communities_id']);
335                else
336                    $info['communities_id'] = array($info['communities_id']);
337        else
338            $info['communities_id'] = array();
339        return $info;
340    }
341    else
342        return array('fname'=> _('In jail or deleted'), 'lname'=>'', 'thumb_path' => '/photos/thumb/jail.png', 'photo_path' => '/photos/jail.png' , 'nb_friends' => 0);
343}
344
345function array_key_flip($array)
346{
347    foreach($array as $key=>$value1)
348        foreach($value1 as $key2=> $value)
349            $rval[$key2][$key] = $value;
350    return $rval;
351}
352
353function valid_email($email)
354{
355//        return eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@([0-9a-z](-?[0-9a-z])*\.)+[a-z]{2}([zmuvtg]|fo|me)?$",$email);
356    return eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@([0-9a-z](-?[0-9a-z])*\.)+[a-z]{2,5}$",$email);
357}
358
359function valid_lang($lang)
360{
361    switch($lang)
362    {
363        case 'en_US':
364        case 'en_L33T':
365        case 'fr_FR':
366        case 'es_ES':
367        case 'ja_JP':
368        case 'pt_BR':
369        case 'fa_IR':
370        case 'de_DE':
371        case 'ca_ES':
372            return true;
373        default:
374            return false;
375    }
376}
377
378function normalize_lang($lang)
379{
380    switch($lang)
381    {
382    case 'fr':
383    case 'fr_FR':
384    case 'fr_BE':
385    case 'fr_CA':
386    case 'fr_CH':
387    case 'fr-fr':
388    case 'fr-be':
389        case 'fr-ca':
390        case 'fr-ch':
391    case 'be':
392    case 'ca':
393        $rval = 'fr_FR';
394        break;
395    case 'en':
396    case 'en_GB':
397    case 'en-gb':
398    case 'en_US':
399    case 'en-us':
400    case 'us':
401        $rval = 'en_US';
402        break;
403    case 'br':
404    case 'pt_BR':
405    case 'pt-br':
406        $rval = 'pt_BR';
407        break;
408    case 'pt':
409    case 'pt_PT':
410    case 'pt-pt':
411        $rval = 'pt_PT';
412        break;
413    case 'ja':
414    case 'jp':
415    case 'ja_JP':
416    case 'ja-jp':
417        $rval = 'ja_JP';
418        break;
419
420    case 'fa':
421    case 'fa-ir':
422    case 'fa_IR':
423        $rval = 'fa_IR';
424        break;
425    case 'es':
426    case 'es_ES':
427    case 'es-es':
428        $rval = 'es_ES';
429        break;
430    case 'de':
431    case 'de_DE':
432    case 'de-de':
433    case 'de_CH':
434    case 'de-ch':
435        $rval = 'de_DE';
436        break;
437
438    case 'ca_es':
439    case 'ca-es':
440    case 'ca_AD':
441    case 'ca-ad':
442    case 'ca_ad':
443    case 'ca_ES':
444        $rval = 'ca_ES';
445        break;
446
447    case 'en_L33T':
448        $rval = 'en_L33T';
449        break;
450    default:
451        $rval = null;
452    }
453   
454    return $rval;
455}
456
457include('removeaccents.inc.php');
458
459function label2name($label)
460{
461        $name = strtolower(removeaccents($label));
462        $name = preg_replace("/[^a-z0-9\.]/","-", $name);
463        $name = preg_replace("/^[\-|\.]*/","", $name);
464        $name = preg_replace("/[\-|\.]*$/","", $name);
465        $name = stripslashes($name);
466        $name = preg_replace("/[\-]{2,}/", "-", $name);
467
468        return trim($name);
469}
470
471function is_valid($type, $string)
472{
473    global $labels;
474    switch($type)
475    {
476    case 'login':
477        return valid_login($string);
478        break;
479    case 'email':
480        return valid_email($string);
481        break;
482    case 'lang':
483        return valid_lang($lang);
484        break;
485    case 'user_id':
486        return ereg("[a-f0-9]{32}", $string);
487        break;
488    case 'photo_id':
489        return is_numeric($string);
490        break;
491    case 'metalbum_type':
492        if(in_array($string, array_keys($labels['metalbum']['type'])))
493            return true;
494        else
495            return false;
496        break;
497    case 'metalbum_name':
498        if(strpos($string, '@'))
499        {
500            list($login, $type) = split('@', $string);
501            if(ereg("^[ a-zA-Z0-9\._-]{2,32}$", $login) && is_valid('metalbum_type', $type))
502                return true;
503        }
504        else
505            return false;
506        break;
507    }
508}
509
510function valid_login($login)
511{
512    global $db;
513
514        if(strlen($login)<3)
515                return false;
516
517    $bad_login = array (
518'www', 'mail', 'smtp', 'imap', 'pop', 'pop3', 'mysql', 'home','irc','ircd', 'todo',
519'pede',
520'bsd',
521'udf', 'ump', 'cgt', 'cfdt',
522'club', 'nyrk','asso','all-hp','login','foaf','blog','blogs',
523'jabber', 'icq', 'msn', 'yahoo', 'hotmail', 'wanadoo','free',
524'bug','bugs','debug','dev','wish','xml',
525'wiki','wikini','wikiwiki','dntp',
526'nathalie','nath59','alex','alexx','alexx'
527    );
528
529    $bad_word = array (
530'sql', 'stat',
531'ns[0-9]{1,}', 'dns', 'admin', 'moderat', 'ikse', 'microsoft', 'linux', 'php[1-9]{1,}', 'apple', 'atari', 'amiga', 'beos', 'macos',
532'bite', 'bitte', 'couille', 'sex', 'anal', 'fist', 'condom', 'capote', 'vagin', 'chatte', 'clito', 'cum', 'sperm', 'breast', 'blow', 'sodo', 'sado', 'zoophi', 'cock', 'pussy',
533'connar', 'conar', 'encul', 'homoph', 'lesb', 'gay', 'pute', 'puta', 'fuck', 'pedo', 'pedal', 'batar', 'enfoir', 'salo', 'salau', 'con',
534'facho', 'racist', 'racism', 'arab', 'magreb', 'juif', 'juiv', 'youpin', 'polak', 'bougnoul', 'negr', 'riton',
535'orkut', 'sonet', 'dotnode', 'orcut',
536'mozilla','firefox','firebird','thunderbird'
537    );
538
539        foreach($bad_login as $bad)
540        {       
541                if($login == $bad)
542                        return false;
543        }
544
545    foreach($bad_word as $word)
546    {
547        if(eregi($word, $login))
548            return false;
549    }
550
551    $already_exist = $db->getOne('SELECT COUNT(id) FROM user WHERE login=?', array($login));
552    if($already_exist==1)
553        return false;
554
555        return true;
556}
557
558function login_exist($login)
559{
560    global $db;
561    $id_exist = $db->getOne('SELECT id FROM user WHERE login=?', array($login));
562        if(isset($id_exist))
563                return $id_exist;
564    else
565        return false;
566}
567
568function get_settings($id, $field)
569{
570    return $db->getOne('SELECT  new_friend_approval FROM settings WHERE id=?', array($id));
571}
572
573function active_message($type, $from_str, $id_to, $subject, $message,$id_from=NULL )
574{
575        global $db;
576        $time = time();
577        if($from_str == '')
578                $from_str = $db->getOne('SELECT fname FROM user WHERE id=?', array($id_from));
579
580        $message_values = array(
581                'id' => $id_to,
582        'id_from' => $id_from,
583                'from_str' => $from_str,
584                'type' => $type,
585                'dest' => 'one',
586                'subject' => $subject,
587                'message' => $message,
588                'box' => 'inbox',
589                'date' => $time);
590
591
592        $res = $db->autoExecute('message', $message_values);
593        if(DB::isError($res))
594    {
595        return false;
596                error_log(__FUNCTION__.' | '.$res->getUserInfo());
597    }
598    else
599        return true;
600}
601
602function auto_message($id_from, $id_to, $subject, $message, $dest='one', $from_str='')
603{
604    global $db;
605    $time = time();
606    if($from_str == '')
607        $from_str = $db->getOne('SELECT fname FROM user WHERE id=?', array($id_from));
608
609    switch($dest)
610    {
611    case 'one':
612    case 'friends':
613    case 'friends_of_friends':
614        break;
615    default:
616        $dest = 'one';
617    }
618
619    $message_values = array(
620                'id' => $id_to,
621                'id_from' => $id_from,
622                'from_str' => $from_str,
623                'type' => 'message',
624                'dest' => $dest,
625                'subject' => $subject,
626                'message' => $message,
627                'box' => 'outbox',
628                'date' => $time);
629
630        $res = $db->autoExecute('message', $message_values);
631    if(DB::isError($res))
632    {
633        error_log(__FUNCTION__.' | '.$res->getUserInfo());
634        return false;
635    }
636    else
637        return true;
638}
639
640/* dotMail
641 * params : associative array like this ...
642 *      $params['ReturnPath']
643 *      $params['From']
644 *      $params['To']
645 *      $params['Subject']
646 *      $params['body']
647 *
648 */
649function dotMail($params)
650{
651#    global $_SERVER;
652#    global $_SESSION;
653    extract($params);
654
655    $mime =& Mail::factory('mime', "\n");
656    if($ReturnPath)
657        $param = '-f'.$ReturnPath;
658        $mail =& Mail::factory('mail', $param);
659
660    $mime->setFrom($From);
661    $mime->setSubject($Subject);
662    $mime->setTXTBody($body);
663
664    $hdrs['X-Abuse'] = 'abuse@dotnode.net';
665        $hdrs['X-Mailer'] = 'Ikse.net Robot';
666#         $hdrs['X-Sender-IP'] = $_SERVER['REMOTE_ADDR'];
667#    $hdrs['X-Dotnode-profile'] = "http://'.$config['domain'].'/profile/".$_SESSION['my_id'];
668    $mail_params = array(
669                'head_charset'  => 'UTF-8',
670                'text_charset'  => 'UTF-8',
671                'text_encoding' => '8bit');
672
673    $body = $mime->get($mail_params);
674        $hdrs = $mime->headers($hdrs);
675
676    $rval = $mail->send($To, $hdrs, $body);
677
678        if(!$rval)
679    {
680                error_log(__FUNCTION__.' from: '.$From);
681                error_log(__FUNCTION__.' subject: '.$Subject);
682                error_log(__FUNCTION__." body:\n".$body);
683                error_log(__FUNCTION__.' return_path: '.$ReturnPath);
684        return false;
685        }
686    else
687        return true;
688
689}
690
691function auto_mail($id_from, $id_to, $subject, $body)
692{
693    global $db;
694
695    $from = $db->getRow('SELECT user_contact.email as email, user.fname as fname, user.lname as lname, user.login as login FROM user LEFT JOIN user_contact USING (id) WHERE user.id=?', array($id_from));
696    $to = $db->getRow('SELECT user_contact.email as email, user.fname as fname, user.lname as lname, user.login as login FROM user LEFT JOIN user_contact USING (id) WHERE user.id=?', array($id_to));
697
698    $f_name = addslashes($from['fname'].' '.$from['lname']);
699
700    $mail['From'] = '"'.$f_name.'" <'.$from['email'].'>';
701    $mail['To'] = $to['email'];
702    $mail['Subject'] = '[.node] '.stripslashes($subject);
703    $mail['ReturnPath'] = $from['email'];
704    $mail['body'] = stripslashes($body);
705
706    return dotMail($mail);
707}
708
709function get_setting($id, $field)
710{
711    global $db;
712    return $db->getOne('SELECT ! FROM settings WHERE id=?', array($field, $id));
713}
714
715function get_mysql_soundex($str)
716{
717    global $db;
718    return $db->getOne('SELECT SOUNDEX(?)', stripslashes($str));
719}
720
721function get_karma($id, $karma)
722{
723        global $db;
724        $kres = $db->getRow('SELECT sum( ! ) as total, count( ! ) as nb FROM relation WHERE id_friend=?', array($karma, $karma, $id));
725        if($kres['nb'] > 3)
726    {
727        error_log("$id: $karma=".$kres['total']/$kres['nb']);
728                return $kres['total']/$kres['nb'];
729    }
730        else
731    {
732                return -99;
733    }
734}
735
736function get_status($id)
737{
738    global $db;
739    return $db->getOne('SELECT status FROM user WHERE id=?', array($id));
740}
741
742include('upload_image.inc.php');
743
744?>
Note: See TracBrowser for help on using the browser.