[22246] | 1 | <?php |
---|
| 2 | |
---|
| 3 | define('PHPWG_ROOT_PATH','../../'); |
---|
| 4 | include_once( PHPWG_ROOT_PATH.'include/common.inc.php' ); |
---|
| 5 | |
---|
| 6 | if (!defined('RVAC_ID')) { |
---|
| 7 | set_status_header(501); |
---|
| 8 | exit; |
---|
| 9 | } |
---|
| 10 | |
---|
| 11 | include_once( 'functions.inc.php' ); |
---|
| 12 | |
---|
| 13 | $page['root_path'] = get_absolute_root_url(false); |
---|
| 14 | |
---|
| 15 | $context = @$_REQUEST['context']; |
---|
| 16 | |
---|
| 17 | if (empty($context) || strncmp($context, '$t/',3)) |
---|
| 18 | bad_request("context"); |
---|
| 19 | |
---|
| 20 | $tag_ids = array(); |
---|
| 21 | $tag_url_names = array(); |
---|
| 22 | foreach( explode('/', $context) as $tag_token) |
---|
| 23 | { |
---|
| 24 | if ( $conf['tag_url_style'] != 'tag' and preg_match('/^(\d+)(?:-(.*)|)$/', $tag_token, $matches) ) |
---|
| 25 | { |
---|
| 26 | $tag_ids[] = $matches[1]; |
---|
| 27 | } |
---|
| 28 | else |
---|
| 29 | { |
---|
| 30 | $tag_url_names[] = $tag_token; |
---|
| 31 | } |
---|
| 32 | } |
---|
| 33 | |
---|
| 34 | $context_tags = find_tags($tag_ids, $tag_url_names); |
---|
| 35 | if ( empty($context_tags) ) |
---|
| 36 | { |
---|
| 37 | bad_request('no context content'); |
---|
| 38 | } |
---|
| 39 | |
---|
| 40 | $context_tag_ids = array_map( function($tag) { return $tag['id']; }, $context_tags); |
---|
| 41 | $context_image_ids = get_image_ids_for_tags($context_tag_ids); |
---|
| 42 | |
---|
| 43 | $tags = get_common_tags($context_image_ids, -1, $context_tag_ids); |
---|
| 44 | usort($tags, function($a,$b) { |
---|
| 45 | $d = -$a['counter'] + $b['counter']; |
---|
| 46 | if (!$d) $d = tag_alpha_compare($a,$b); |
---|
| 47 | return $d; |
---|
| 48 | }); |
---|
| 49 | |
---|
| 50 | $suggestions = array(); |
---|
| 51 | foreach($tags as $tag) |
---|
| 52 | { |
---|
| 53 | if ($tag['counter']==count($context_image_ids)) |
---|
| 54 | continue; |
---|
| 55 | $label = $tag['name']; |
---|
| 56 | |
---|
| 57 | $url = $context.'/'; |
---|
| 58 | switch ( $conf['tag_url_style'] ) |
---|
| 59 | { |
---|
| 60 | case 'id': |
---|
| 61 | $url.= $tag['id']; |
---|
| 62 | break; |
---|
| 63 | case 'tag': |
---|
| 64 | if (!is_numeric($tag['url_name']) ) |
---|
| 65 | { |
---|
| 66 | $url.= $tag['url_name']; |
---|
| 67 | break; |
---|
| 68 | } |
---|
| 69 | default: |
---|
| 70 | $url.= $tag['id'].'-'.$tag['url_name']; |
---|
| 71 | } |
---|
| 72 | |
---|
| 73 | $suggestion = array( |
---|
| 74 | 'label' => $label, |
---|
| 75 | 'value' => $url, |
---|
| 76 | 'w' => intval($tag['counter']) |
---|
| 77 | ); |
---|
| 78 | |
---|
| 79 | $q = rvac_normalize($label); |
---|
| 80 | if ($q != strtolower($label)) |
---|
| 81 | $suggestion['q'] = $q; |
---|
| 82 | |
---|
| 83 | $suggestions[] = $suggestion; |
---|
| 84 | } |
---|
| 85 | |
---|
| 86 | |
---|
| 87 | |
---|
| 88 | $ds = str_replace( |
---|
| 89 | array('\\/', '"q":', '"label":', '"value":', '"w":'), |
---|
| 90 | array('/', 'q:', 'label:', 'value:', 'w:'), |
---|
| 91 | json_encode($suggestions)); |
---|
| 92 | |
---|
| 93 | $js = 'RVAC.mergeData({dataSource:'.$ds.', |
---|
| 94 | ctxq:'.json_encode((string)@$_REQUEST['ctxq']).', |
---|
| 95 | ctxl:'.json_encode((string)@$_REQUEST['ctxl']).', |
---|
| 96 | ctxw:'.count($context_image_ids).' |
---|
| 97 | })'; |
---|
| 98 | |
---|
| 99 | echo $js; |
---|
| 100 | |
---|
| 101 | ?> |
---|