Exemple #1
0
function search($lang, $arglist = false)
{
    global $search_all, $search_pertinence, $rss_thread;
    $cloud = false;
    if (is_array($arglist)) {
        if (isset($arglist[0])) {
            $cloud = $arglist[0];
        }
    }
    $cloud_id = $cloud_name = false;
    $thread_nocloud = $thread_nosearch = false;
    if ($cloud) {
        $cloud_id = cloud_id($cloud);
        if (!$cloud_id) {
            return run('error/notfound', $lang);
        }
        if ($cloud_id == $rss_thread) {
            if (!user_has_role('administrator')) {
                return run('error/unauthorized', $lang);
            }
        }
        $r = cloud_get($lang, $cloud_id);
        if (!$r) {
            return run('error/notfound', $lang);
        }
        extract($r);
        /* cloud_name cloud_title cloud_action */
        $r = thread_get($lang, $cloud_id);
        if (!$r) {
            return run('error/notfound', $lang);
        }
        extract($r);
        /* thread_type thread_nocloud thread_nosearch */
        if ($thread_type == 'thread' or $thread_nosearch and $thread_nocloud) {
            return run('error/notfound', $lang);
        }
    } else {
        if ($search_all === false) {
            return run('error/notfound', $lang);
        }
        if ($search_all !== true) {
            $thread_nosearch = true;
        }
    }
    $action = 'none';
    if (isset($_POST['search'])) {
        $action = 'search';
    }
    $searchtext = $taglist = false;
    $rsearch = false;
    switch ($action) {
        case 'none':
            if (!empty($arglist['q'])) {
                $searchtext = $arglist['q'];
                $taglist = explode(' ', $searchtext);
            }
            break;
        case 'search':
            if (isset($_POST['searchtext'])) {
                $searchtext = readarg($_POST['searchtext'], true, false);
                // trim but DON'T strip!
                if ($searchtext) {
                    global $search_distance, $search_closest;
                    $taglist = cloud_match($lang, $cloud_id, $searchtext, $search_distance, $search_closest);
                }
            }
            break;
        default:
            break;
    }
    if ($taglist) {
        $rsearch = cloud_search($lang, $cloud_id, $taglist, $search_pertinence);
    }
    $search_title = translate('search:title', $lang);
    $search_url = false;
    $search = $cloud = $title = false;
    if ($rsearch) {
        if (!$thread_nosearch) {
            $search_url = url('search', $lang, $cloud_name);
        }
        if (!$thread_nocloud) {
            $cloud_url = url('search', $lang, $cloud_name);
            $byname = $bycount = $index = true;
            $cloud = build('cloud', $lang, $cloud_url, $cloud_id, false, 30, compact('byname', 'bycount', 'index'));
        }
        $headline_text = $search_title;
        $headline_url = false;
        $headline = compact('headline_text', 'headline_url');
        $title = view('headline', false, $headline);
        $content = build('searchlist', $lang, $rsearch, $taglist);
    } else {
        $headline_text = $cloud_id ? $cloud_title : $search_title;
        $headline_url = false;
        if (!$thread_nosearch) {
            $search_url = url('search', $lang, $cloud_name);
        }
        $cloud_url = url('search', $lang, $cloud_name);
        $headline = compact('headline_text', 'headline_url');
        $title = view('headline', false, $headline);
        $byname = true;
        $bycount = $index = false;
        $content = build('cloud', $lang, $cloud_url, $cloud_id, false, false, compact('byname', 'bycount', 'index'));
    }
    if ($search_url) {
        $search_text = $searchtext;
        $suggest_url = url('suggest', $lang, $cloud_name);
        $search = view('searchinput', $lang, compact('search_url', 'search_text', 'suggest_url'));
    }
    $sidebar = view('sidebar', false, compact('search', 'cloud', 'title'));
    if ($search) {
        $search = compact('search_url', 'search_text', 'suggest_url');
    }
    $banner = build('banner', $lang, compact('headline', 'search'));
    head('title', $cloud_id ? $cloud_title : $search_title);
    head('description', false);
    head('keywords', false);
    head('robots', 'noindex, nofollow');
    $output = layout('standard', compact('banner', 'content', 'sidebar'));
    return $output;
}
Exemple #2
0
require_once 'pdo.php';
$db_url = $scheme . '://test:test@localhost/test';
$db_prefix = 'test_';
$db_debug = true;
db_connect($db_url);
require_once 'models/cloud.inc';
$msecs = microtime(true);
$rss_thread = 1;
$thread_id = 1;
$cloud_id = $thread_id;
$r = cloud_delete($cloud_id);
dump($r);
$r = cloud_create($thread_id);
dump($r);
$lang = 'en';
$r = cloud_get($lang, $cloud_id);
dump($r);
$r = cloud_list_tags($lang, false, false);
dump($r);
$r = cloud_list_tags($lang, $cloud_id, false, false);
dump($r);
$r = cloud_list_tags($lang, $cloud_id, false, true, true);
dump($r);
$node_id = 2;
$r = cloud_list_tags($lang, $cloud_id, $node_id);
dump($r);
$r = cloud_list_tags($lang, $cloud_id, $node_id, true, false, false);
dump($r);
$taglist = array('documentation', 'foobar');
$r = cloud_search($lang, $cloud_id, $taglist);
dump($r);