function index_text($subj, $body, $msg_id) { /* Remove Stuff In Quotes */ while (preg_match('!<table border="0" align="center" width="90%" cellpadding="3" cellspacing="1"><tr><td class="SmallText"><b>(.*?)</b></td></tr><tr><td class="quote"><br>(.*?)<br></td></tr></table>!is', $body)) { $body = preg_replace('!<table border="0" align="center" width="90%" cellpadding="3" cellspacing="1"><tr><td class="SmallText"><b>(.*?)</b></td></tr><tr><td class="quote"><br>(.*?)<br></td></tr></table>!is', '', $body); } /* this is mostly a hack for php verison < 4.3 because isset(string[bad offset]) returns a warning */ error_reporting(0); if (strncmp($GLOBALS['usr']->lang, 'chinese', 7)) { $cs = array('!\\W!', '!\\s+!'); $cd = array(' ', ' '); reverse_fmt($subj); $subj = trim(preg_replace($cs, $cd, strip_tags(strtolower($subj)))); reverse_fmt($body); $body = trim(preg_replace($cs, $cd, strip_tags(strtolower($body)))); /* build full text index */ $t1 = array_unique(explode(' ', $subj)); $t2 = array_unique(explode(' ', $body)); foreach ($t1 as $v) { if (isset($v[51]) || !isset($v[3])) { continue; } $w1[] = "'" . addslashes($v) . "'"; } if (isset($w1)) { $w2 = $w1; } foreach ($t2 as $v) { if (isset($v[51]) || !isset($v[3])) { continue; } $w2[] = "'" . addslashes($v) . "'"; } } else { /* handling for multibyte languages */ $w1 = mb_word_split($subj); if ($w1) { $w2 = array_merge($w1, mb_word_split($body)); } else { unset($w1); } } if (!$w2) { return; } $w2 = array_unique($w2); if (__dbtype__ == 'mysql') { ins_m('phpgw_fud_search', 'word', $w2); } else { ins_m('phpgw_fud_search', 'word', $w2, 'text'); } /* This allows us to return right away, meaning we don't need to wait * for any locks to be released etc... */ if (__dbtype__ == 'mysql') { $del = 'DELAYED'; } else { $del = ''; } if (isset($w1)) { db_li('INSERT ' . $del . ' INTO phpgw_fud_title_index (word_id, msg_id) SELECT id, ' . $msg_id . ' FROM phpgw_fud_search WHERE word IN(' . implode(',', $w1) . ')', $ef); } db_li('INSERT ' . $del . ' INTO phpgw_fud_index (word_id, msg_id) SELECT id, ' . $msg_id . ' FROM phpgw_fud_search WHERE word IN(' . implode(',', $w2) . ')', $ef); }
function grp_rebuild_cache($user_id = null) { $list = array(); if ($user_id !== null) { $lmt = ' user_id IN(' . implode(',', $user_id) . ') '; } else { $lmt = ''; } /* generate an array of permissions, in the end we end up with 1ist of permissions */ $r = uq("SELECT gm.user_id AS uid, gm.group_members_opt AS gco, gr.resource_id AS rid FROM phpgw_fud_group_members gm INNER JOIN phpgw_fud_group_resources gr ON gr.group_id=gm.group_id WHERE gm.group_members_opt>=65536 AND (gm.group_members_opt & 65536) > 0" . ($lmt ? ' AND ' . $lmt : '')); while ($o = db_rowobj($r)) { foreach ($o as $k => $v) { $o->{$k} = (int) $v; } if (isset($list[$o->rid][$o->uid])) { if ($o->gco & 131072) { $list[$o->rid][$o->uid] |= $o->gco; } else { $list[$o->rid][$o->uid] &= $o->gco; } } else { $list[$o->rid][$o->uid] = $o->gco; } } $tmp_t = "phpgw_fud_gc_" . __request_timestamp__; q("CREATE TEMPORARY TABLE " . $tmp_t . " (a INT, b INT, c INT)"); $tmp = array(); foreach ($list as $k => $v) { foreach ($v as $u => $p) { $tmp[] = $k . ", " . $p . ", " . $u; } } if ($tmp) { if (__dbtype__ == 'mysql') { ins_m($tmp_t, "a,b,c", $tmp, 1); } else { ins_m($tmp_t, "a,b,c", $tmp, "integer, integer, integer"); } } if (!db_locked()) { $ll = 1; db_lock("phpgw_fud_group_cache WRITE"); } q("DELETE FROM phpgw_fud_group_cache" . ($lmt ? ' WHERE ' . $lmt : '')); q("INSERT INTO phpgw_fud_group_cache (resource_id, group_cache_opt, user_id) SELECT a,b,c FROM " . $tmp_t); if (isset($ll)) { db_unlock(); } q("DROP TABLE " . $tmp_t); }