Develop and Download Open Source Software

Browse CVS Repository

Annotation of /xoonips-library/IRview/metadata_search.php

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.1.1.1 - (hide annotations) (download) (as text) (vendor branch)
Mon Nov 6 01:29:26 2006 UTC (17 years, 5 months ago) by yamaji
Branch: MAIN
CVS Tags: HEAD
Changes since 1.1: +0 -0 lines
File MIME type: application/x-httpd-php
initial import into CVS

1 yamaji 1.1 <?php
2     // $Revision: 1.1.1.1 $ //
3     // ------------------------------------------------------------------------ //
4     // //
5     // OAI-PMH based Institutional Repository Introduction Module //
6     // Copyright (C) 2005 Kazutsuna YAMAJI. All rights reserved. //
7     // //
8     // ------------------------------------------------------------------------ //
9     // This program is free software; you can redistribute it and/or modify //
10     // it under the terms of the GNU General Public License as published by //
11     // the Free Software Foundation; either version 2 of the License, or //
12     // (at your option) any later version. //
13     // //
14     // You may not change or alter any portion of this comment or credits //
15     // of supporting developers from this source code or any supporting //
16     // source code which is considered copyrighted (c) material of the //
17     // original comment or credit authors. //
18     // //
19     // This program is distributed in the hope that it will be useful, //
20     // but WITHOUT ANY WARRANTY; without even the implied warranty of //
21     // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
22     // GNU General Public License for more details. //
23     // //
24     // You should have received a copy of the GNU General Public License //
25     // along with this program; if not, write to the Free Software //
26     // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA //
27     // ------------------------------------------------------------------------ //
28    
29     /**
30     * @param op search, detail
31     * @param meta_keyword ����������������
32     * if ( mbstring ) mbstring.internal_encoding �������� numeric character reference ����������������
33     * else _CHARSET �������� numeric character reference ����������������
34     * @param page, itemcount, orderby
35     * @param repository_id, id
36     */
37    
38     $xoopsOption['pagetype'] = 'user';
39     include '../../mainfile.php';
40    
41     // If not a user, redirect
42     if ( !$xoopsUser ) {
43     redirect_header('index.php',3,_MD_IRVIEW_ACCESS_FORBIDDEN);
44     exit();
45     }
46    
47     $uid = $_SESSION['xoopsUserId'];
48    
49     foreach( array( 'op' => '',
50     'meta_keyword' => '',
51     'start' => 0,
52     'page' => 1,
53     'itemcount' => 20,
54     'repository_id' => 0,
55     'identifier' => 0
56     ) as $k => $v ){
57     if( array_key_exists( $k, $_GET ) ){
58     $$k = $_GET[$k];
59     }else if( array_key_exists( $k, $_POST ) ){
60     $$k = $_POST[$k];
61     }else{
62     $$k = $v;
63     }
64     }
65    
66     $config_handler =& xoops_gethandler('config');
67     $xoopsConfigUser =& $config_handler->getConfigsByCat(XOOPS_CONF_USER);
68     $xoopsOption['template_main'] = 'irview_metadata_search.html';
69     include XOOPS_ROOT_PATH.'/header.php';
70    
71     // http://jp.php.net/manual/ja/function.utf8-decode.php
72     // morris_hirsch at hotmail dot com 19-Aug-2003 01:43��������
73    
74     function numeric_entify_utf8 ($utf8_string) {
75    
76     $out = "";
77     $ns = strlen ($utf8_string);
78     for ($nn = 0; $nn < $ns; $nn++) {
79     $ch = $utf8_string [$nn];
80     $ii = ord ($ch);
81    
82     //1 7 0bbbbbbb (127)
83    
84     if ($ii < 128) $out .= $ch;
85    
86     //2 11 110bbbbb 10bbbbbb (2047)
87    
88     else if ($ii >>5 == 6) {
89     $b1 = ($ii & 31);
90    
91     $nn++;
92     $ch = $utf8_string [$nn];
93     $ii = ord ($ch);
94     $b2 = ($ii & 63);
95    
96     $ii = ($b1 * 64) + $b2;
97    
98     $ent = sprintf ("&#%d;", $ii);
99     $out .= $ent;
100     }
101    
102     //3 16 1110bbbb 10bbbbbb 10bbbbbb
103    
104     else if ($ii >>4 == 14) {
105     $b1 = ($ii & 31);
106    
107     $nn++;
108     $ch = $utf8_string [$nn];
109     $ii = ord ($ch);
110     $b2 = ($ii & 63);
111    
112     $nn++;
113     $ch = $utf8_string [$nn];
114     $ii = ord ($ch);
115     $b3 = ($ii & 63);
116    
117     $ii = ((($b1 * 64) + $b2) * 64) + $b3;
118    
119     $ent = sprintf ("&#%d;", $ii);
120     $out .= $ent;
121     }
122    
123     //4 21 11110bbb 10bbbbbb 10bbbbbb 10bbbbbb
124    
125     else if ($ii >>3 == 30) {
126     $b1 = ($ii & 31);
127    
128     $nn++;
129     $ch = $utf8_string [$nn];
130     $ii = ord ($ch);
131     $b2 = ($ii & 63);
132    
133     $nn++;
134     $ch = $utf8_string [$nn];
135     $ii = ord ($ch);
136     $b3 = ($ii & 63);
137    
138     $nn++;
139     $ch = $utf8_string [$nn];
140     $ii = ord ($ch);
141     $b4 = ($ii & 63);
142    
143     $ii = ((((($b1 * 64) + $b2) * 64) + $b3) * 64) + $b4;
144    
145     $ent = sprintf ("&#%d;", $ii);
146     $out .= $ent;
147     }
148    
149     }
150     return $out;
151     }
152    
153     // http://jp.php.net/manual/ja/function.html-entity-decode.php
154     // php dot net at c dash ovidiu dot tk 18-Mar-2005 05:37 ��������
155     function replace_num_entity($ord)
156     {
157     $ord = $ord[1];
158     if (preg_match('/^x([0-9a-f]+)$/i', $ord, $match))
159     $ord = hexdec($match[1]);
160     else
161     $ord = intval($ord);
162    
163     $no_bytes = 0;
164     $byte = array();
165    
166     if ($ord < 128) return chr($ord);
167     elseif ($ord < 2048) $no_bytes = 2;
168     elseif ($ord < 65536) $no_bytes = 3;
169     elseif ($ord < 1114112) $no_bytes = 4;
170     else return;
171    
172     switch($no_bytes)
173     {
174     case 2: $prefix = array(31, 192); break;
175     case 3: $prefix = array(15, 224); break;
176     case 4: $prefix = array(7, 240);
177     }
178    
179     for ($i = 0; $i < $no_bytes; $i++)
180     $byte[$no_bytes - $i - 1] = (($ord & (63 * pow(2, 6 * $i))) / pow(2, 6 * $i)) & 63 | 128;
181    
182     $byte[0] = ($byte[0] & $prefix[0]) | $prefix[1];
183    
184     $ret = '';
185     for ($i = 0; $i < $no_bytes; $i++)
186     $ret .= chr($byte[$i]);
187    
188     return $ret;
189     }
190    
191     function decode_entities($text) {
192     $text = preg_replace_callback('/&#([0-9a-fx]+);/mi', 'replace_num_entity', $text);
193     return $text;
194     }
195    
196    
197     // utf8 + numeric character reference -> utf8
198     function dec( $str ){
199     // return html_entity_decode ( $str, ENT_QUOTES, 'UTF-8' ); // ����������PHP4.3.8��������������������������
200     return decode_entities( $str );
201     }
202    
203     // utf8 -> numeric character reference
204     function enc( $str ){
205     return numeric_entify_utf8( $str );
206     //return htmlentities( $str, ENT_QUOTES, 'UTF-8' );
207     }
208    
209    
210     $table_data = $xoopsDB->prefix( 'irview_metadata' );
211     $table_repo = $xoopsDB->prefix( 'irview_repositories' );
212     $xoopsTpl->assign( 'op', $op );
213     $xoopsTpl->assign( 'item_count_select', array( 20=>20, 50=>50, 100=>100 ) );
214    
215     // meta_keyword��utf-8����������
216     if ( function_exists( 'mb_convert_encoding') )
217     $meta_keyword = mb_convert_encoding( $meta_keyword, 'UTF-8' ); // mbstring������������������mbstring.internal_encoding����������������mb_convert_string������
218     else
219     $meta_keyword = iconv( 'UTF-8', _CHARSET, $meta_keyword ); // mbstring������������������_CHARSET������������
220    
221     if ( $op == '' ){
222     // ������������
223     }
224     else if ( $op == 'search' ){
225    
226     $keywords = explode( ' ', $meta_keyword );
227     $sql_like = array();
228    
229     foreach ( $keywords as $k ){
230     if ( strlen($k) == 0 ) continue;
231     $k = trim( $k );
232    
233     // \ ->\\, _ -> \\_, % ->\\% ����������
234     $k = str_replace( array( "\\", "_", "%" ), array( "\\\\", "\\_", "\\%" ), $k );
235    
236     // numeric character reference(&#1234;����)��utf-8����������
237     if( ( reset( unpack( "C", dec( $k ) ) ) & 0x80 ) == 0 )
238     $sql_like[] = "+" . addslashes( dec( $k ) ) . "*";
239     else $sql_like[] = "+" . bin2hex( addslashes( dec( $k ) ) ) . "*";
240     }
241    
242     // ������������
243     if ( $page < 1 ) $page = 1;
244     $start = ($page-1)*$itemcount;
245     $sql = "select sql_calc_found_rows identifier, data.repository_id, title from ${table_data} as data, ${table_repo} as repo where repo.enabled=1 AND repo.deleted!=1 AND repo.repository_id=data.repository_id AND match( search_text ) against ('" . implode( ' ', $sql_like ) . "' IN BOOLEAN MODE) order by identifier, data.repository_id limit $itemcount offset $start";
246     $result = $xoopsDB->query( $sql );
247    
248     // ����������
249     $result2 = $xoopsDB->query( "select found_rows()" );
250     list( $total_count ) = $xoopsDB->fetchRow( $result2 );
251    
252     // ��������������������������������
253     $maxpage = ceil( $total_count / $itemcount );
254     if ( $page > $maxpage && $maxpage != 0 ){
255     $page = $maxpage;
256     $start = ($page-1)*$itemcount;
257     $sql = "select sql_calc_found_rows identifier, data.repository_id, title from ${table_data} as data, ${table_repo} as repo where repo.enabled=1 AND repo.deleted!=1 AND repo.repository_id=data.repository_id AND match( search_text ) against ('" . implode( ' ', $sql_like ) . "' IN BOOLEAN MODE) order by identifier, data.repository_id limit $itemcount offset $start";
258     $result = $xoopsDB->query( $sql );
259     }
260    
261     // ������������
262     $items = array();
263     while ( $row = $xoopsDB->fetchRow( $result ) ){
264     $ar = array();
265     list( $ar['identifier'], $ar['repository_id'], $ar['title'] ) = $row;
266     $ar['title'] = enc(nl2br(htmlspecialchars(dec( $ar['title'] ), ENT_QUOTES, 'UTF-8')));
267     $items[] = $ar;
268     }
269    
270     // ��������������������
271     if ( count($items) != 0 ) {
272     $page_no_label = ($start+1) . " - " . ($start+count($items)) . " of $total_count items";
273     //centering current page number(5th of $pages)
274     $pages = array( min( max( 1, $page - 4 ), max( 1, $maxpage - 9 ) ) );
275     for( $i = 1 ; $i < 10 && $pages[ $i - 1 ] < $maxpage; $i++ ){ $pages[ $i ] = $pages[ $i - 1 ] + 1; }
276     $xoopsTpl->assign('pages', $pages );
277     }
278     else
279     $page_no_label = "0 - 0 of $total_count items";
280    
281    
282     $xoopsTpl->assign( 'prevpage', $page - 1 );
283     $xoopsTpl->assign( 'nextpage', $page + 1 );
284     $xoopsTpl->assign( 'maxpage', $maxpage );
285     $xoopsTpl->assign( 'page', $page);
286     $xoopsTpl->assign( 'itemcount', $itemcount);
287     $xoopsTpl->assign( 'page_no_label', $page_no_label );
288     $xoopsTpl->assign( 'meta_keyword', enc(htmlspecialchars(dec( $meta_keyword ), ENT_QUOTES, 'UTF-8')) );
289    
290     $xoopsTpl->assign( 'items', $items );
291     }
292     else if ( $op == 'detail' ){
293     // metadata��DB������������
294     $escIdentifier = addslashes( $identifier );
295     $repository_id = (int)$repository_id;
296     $sql = "select metadata from ${table_data} where identifier='$escIdentifier' and repository_id=$repository_id ";
297     $result = $xoopsDB->query( $sql );
298     list( $metadata ) = $xoopsDB->fetchRow( $result );
299    
300     // metadata����������
301     $index = array(); $vals = array();
302     $xml_parser = xml_parser_create( 'UTF-8' );
303     xml_parser_set_option($xml_parser,XML_OPTION_SKIP_WHITE,1);
304     xml_parse_into_struct($xml_parser,$metadata,$vals,$index);
305     xml_parser_free( $xml_parser );
306    
307     $detail = array();
308     foreach ( $vals as $val ){
309     if ( $val['type'] == 'complete' ){
310     $ar = array();
311     $ar['tag'] = enc(nl2br(htmlspecialchars(dec( $val['tag'] ), ENT_QUOTES, 'UTF-8')));
312     $ar['value'] = enc(nl2br(htmlspecialchars(dec( $val['value'] ), ENT_QUOTES, 'UTF-8')));
313     $pattern = "/(s?https?:\\/\\/[-_.!~*'\\(\\)a-zA-Z0-9;\\/?:\\@&=+\$,%#]+)/"; // http://www.din.or.jp/~ohzaki/perl.htm#httpURL ��������
314     $ar['value'] = preg_replace( $pattern, "<a href='\\1'>\\1</a>", $ar['value'] );
315    
316     $detail[] = $ar;
317     }
318     }
319     //var_dump( $detail );
320     $xoopsTpl->assign( 'detail', $detail );
321     $xoopsTpl->assign( 'identifier', $identifier );
322     $xoopsTpl->assign( 'repository_id', $repository_id );
323     $xoopsTpl->assign( 'page', $page);
324     $xoopsTpl->assign( 'itemcount', $itemcount);
325     $xoopsTpl->assign( 'meta_keyword', enc(htmlspecialchars(dec( $meta_keyword ), ENT_QUOTES, 'UTF-8')) );
326     }
327    
328     include XOOPS_ROOT_PATH.'/footer.php';
329     ?>

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26